layerchart 2.0.0-next.1 → 2.0.0-next.3
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.
- package/dist/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +143 -0
- package/dist/components/AnnotationLine.svelte.d.ts +30 -0
- package/dist/components/AnnotationPoint.svelte +119 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +34 -0
- package/dist/components/AnnotationRange.svelte +147 -0
- package/dist/components/AnnotationRange.svelte.d.ts +40 -0
- package/dist/components/Arc.svelte +344 -151
- package/dist/components/Arc.svelte.d.ts +138 -0
- package/dist/components/Area.svelte +165 -149
- package/dist/components/Area.svelte.d.ts +45 -0
- package/dist/components/Axis.svelte +283 -180
- package/dist/components/Axis.svelte.d.ts +117 -0
- package/dist/components/Bar.svelte +166 -107
- package/dist/components/Bar.svelte.d.ts +51 -0
- package/dist/components/Bars.svelte +56 -67
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +42 -12
- package/dist/components/Blur.svelte.d.ts +23 -21
- package/dist/components/Bounds.svelte +49 -19
- package/dist/components/Bounds.svelte.d.ts +24 -50
- package/dist/components/BrushContext.svelte +296 -168
- package/dist/components/BrushContext.svelte.d.ts +97 -65
- package/dist/components/Calendar.svelte +116 -59
- package/dist/components/Calendar.svelte.d.ts +50 -31
- package/dist/components/Chart.svelte +1289 -398
- package/dist/components/Chart.svelte.d.ts +535 -410
- package/dist/components/ChartClipPath.svelte +37 -15
- package/dist/components/ChartClipPath.svelte.d.ts +21 -19
- package/dist/components/Circle.svelte +124 -85
- package/dist/components/Circle.svelte.d.ts +52 -0
- package/dist/components/CircleClipPath.svelte +76 -16
- package/dist/components/CircleClipPath.svelte.d.ts +46 -0
- package/dist/components/ClipPath.svelte +71 -21
- package/dist/components/ClipPath.svelte.d.ts +40 -27
- package/dist/components/ColorRamp.svelte +75 -9
- package/dist/components/ColorRamp.svelte.d.ts +37 -19
- package/dist/components/ComputedStyles.svelte +17 -5
- package/dist/components/ComputedStyles.svelte.d.ts +11 -19
- package/dist/components/Connector.svelte +149 -0
- package/dist/components/Connector.svelte.d.ts +51 -0
- package/dist/components/Dagre.svelte +211 -122
- package/dist/components/Dagre.svelte.d.ts +119 -56
- package/dist/components/ForceSimulation.svelte +215 -90
- package/dist/components/ForceSimulation.svelte.d.ts +82 -35
- package/dist/components/Frame.svelte +33 -13
- package/dist/components/Frame.svelte.d.ts +13 -17
- package/dist/components/GeoCircle.svelte +29 -16
- package/dist/components/GeoCircle.svelte.d.ts +22 -24
- package/dist/components/GeoContext.svelte +113 -72
- package/dist/components/GeoContext.svelte.d.ts +49 -41
- package/dist/components/GeoEdgeFade.svelte +49 -13
- package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
- package/dist/components/GeoPath.svelte +157 -127
- package/dist/components/GeoPath.svelte.d.ts +48 -36
- package/dist/components/GeoPoint.svelte +52 -20
- package/dist/components/GeoPoint.svelte.d.ts +25 -22
- package/dist/components/GeoSpline.svelte +75 -26
- package/dist/components/GeoSpline.svelte.d.ts +29 -20
- package/dist/components/GeoTile.svelte +100 -49
- package/dist/components/GeoTile.svelte.d.ts +38 -23
- package/dist/components/GeoVisible.svelte +17 -9
- package/dist/components/GeoVisible.svelte.d.ts +10 -18
- package/dist/components/Graticule.svelte +30 -14
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +230 -117
- package/dist/components/Grid.svelte.d.ts +71 -0
- package/dist/components/Group.svelte +173 -106
- package/dist/components/Group.svelte.d.ts +81 -0
- package/dist/components/Highlight.svelte +410 -308
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +97 -46
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +127 -47
- package/dist/components/Labels.svelte.d.ts +70 -27
- package/dist/components/Legend.svelte +374 -190
- package/dist/components/Legend.svelte.d.ts +95 -44
- package/dist/components/Line.svelte +163 -125
- package/dist/components/Line.svelte.d.ts +75 -0
- package/dist/components/LinearGradient.svelte +153 -78
- package/dist/components/LinearGradient.svelte.d.ts +66 -31
- package/dist/components/Link.svelte +160 -104
- package/dist/components/Link.svelte.d.ts +54 -0
- package/dist/components/Marker.svelte +100 -39
- package/dist/components/Marker.svelte.d.ts +59 -27
- package/dist/components/MarkerWrapper.svelte +35 -0
- package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
- package/dist/components/MonthPath.svelte +65 -20
- package/dist/components/MonthPath.svelte.d.ts +23 -17
- package/dist/components/MotionPath.svelte +80 -24
- package/dist/components/MotionPath.svelte.d.ts +46 -27
- package/dist/components/Pack.svelte +53 -17
- package/dist/components/Pack.svelte.d.ts +42 -21
- package/dist/components/Partition.svelte +64 -22
- package/dist/components/Partition.svelte.d.ts +49 -26
- package/dist/components/Pattern.svelte +297 -11
- package/dist/components/Pattern.svelte.d.ts +103 -19
- package/dist/components/Pie.svelte +122 -76
- package/dist/components/Pie.svelte.d.ts +65 -51
- package/dist/components/Point.svelte +20 -9
- package/dist/components/Point.svelte.d.ts +16 -20
- package/dist/components/Points.svelte +148 -137
- package/dist/components/Points.svelte.d.ts +45 -34
- package/dist/components/RadialGradient.svelte +143 -70
- package/dist/components/RadialGradient.svelte.d.ts +69 -31
- package/dist/components/Rect.svelte +121 -102
- package/dist/components/Rect.svelte.d.ts +36 -0
- package/dist/components/RectClipPath.svelte +82 -18
- package/dist/components/RectClipPath.svelte.d.ts +55 -0
- package/dist/components/Rule.svelte +107 -63
- package/dist/components/Rule.svelte.d.ts +40 -19
- package/dist/components/Sankey.svelte +132 -55
- package/dist/components/Sankey.svelte.d.ts +61 -31
- package/dist/components/Spline.svelte +281 -218
- package/dist/components/Spline.svelte.d.ts +95 -0
- package/dist/components/Text.svelte +437 -176
- package/dist/components/Text.svelte.d.ts +130 -0
- package/dist/components/Threshold.svelte +48 -16
- package/dist/components/Threshold.svelte.d.ts +29 -31
- package/dist/components/TileImage.svelte +103 -30
- package/dist/components/TileImage.svelte.d.ts +48 -23
- package/dist/components/TransformContext.svelte +365 -171
- package/dist/components/TransformControls.svelte +50 -26
- package/dist/components/TransformControls.svelte.d.ts +27 -19
- package/dist/components/Tree.svelte +74 -33
- package/dist/components/Tree.svelte.d.ts +42 -30
- package/dist/components/Treemap.svelte +119 -42
- package/dist/components/Treemap.svelte.d.ts +75 -27
- package/dist/components/Voronoi.svelte +108 -76
- package/dist/components/Voronoi.svelte.d.ts +40 -41
- package/dist/components/charts/ArcChart.svelte +464 -0
- package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
- package/dist/components/charts/AreaChart.svelte +450 -393
- package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
- package/dist/components/charts/BarChart.svelte +454 -389
- package/dist/components/charts/BarChart.svelte.d.ts +76 -0
- package/dist/components/charts/ChartAnnotations.svelte +37 -0
- package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
- package/dist/components/charts/DefaultTooltip.svelte +60 -0
- package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
- package/dist/components/charts/LineChart.svelte +369 -314
- package/dist/components/charts/LineChart.svelte.d.ts +53 -0
- package/dist/components/charts/PieChart.svelte +458 -316
- package/dist/components/charts/PieChart.svelte.d.ts +137 -353
- package/dist/components/charts/ScatterChart.svelte +334 -296
- package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
- package/dist/components/charts/index.d.ts +8 -0
- package/dist/components/charts/index.js +7 -0
- package/dist/components/charts/types.d.ts +253 -0
- package/dist/components/charts/utils.svelte.d.ts +30 -0
- package/dist/components/charts/utils.svelte.js +55 -0
- package/dist/components/index.d.ts +76 -4
- package/dist/components/index.js +76 -5
- package/dist/components/layout/Canvas.svelte +321 -155
- package/dist/components/layout/Canvas.svelte.d.ts +104 -55
- package/dist/components/layout/Html.svelte +82 -42
- package/dist/components/layout/Html.svelte.d.ts +39 -28
- package/dist/components/layout/Layer.svelte +39 -0
- package/dist/components/layout/Layer.svelte.d.ts +17 -0
- package/dist/components/layout/Svg.svelte +122 -70
- package/dist/components/layout/Svg.svelte.d.ts +53 -34
- package/dist/components/layout/WebGL.svelte +135 -0
- package/dist/components/layout/WebGL.svelte.d.ts +50 -0
- package/dist/components/tooltip/Tooltip.svelte +246 -78
- package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
- package/dist/components/tooltip/TooltipContext.svelte +409 -271
- package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
- package/dist/components/tooltip/TooltipHeader.svelte +100 -11
- package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
- package/dist/components/tooltip/TooltipItem.svelte +167 -27
- package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
- package/dist/components/tooltip/TooltipList.svelte +22 -3
- package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
- package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
- package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
- package/dist/components/tooltip/index.d.ts +6 -0
- package/dist/components/tooltip/index.js +6 -0
- package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
- package/dist/components/tooltip/tooltipMetaContext.js +139 -0
- package/dist/components/types.d.ts +1 -0
- package/dist/components/types.js +1 -0
- package/dist/docs/Blockquote.svelte.d.ts +18 -14
- package/dist/docs/Code.svelte.d.ts +26 -22
- package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
- package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
- package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
- package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
- package/dist/docs/CurveMenuField.svelte +14 -3
- package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
- package/dist/docs/GeoDebug.svelte +47 -42
- package/dist/docs/GeoDebug.svelte.d.ts +4 -16
- package/dist/docs/Header1.svelte.d.ts +27 -16
- package/dist/docs/Json.svelte.d.ts +20 -16
- package/dist/docs/Layout.svelte.d.ts +18 -13
- package/dist/docs/Link.svelte.d.ts +33 -21
- package/dist/docs/PathDataMenuField.svelte +14 -10
- package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
- package/dist/docs/Preview.svelte +20 -7
- package/dist/docs/Preview.svelte.d.ts +12 -22
- package/dist/docs/TilesetField.svelte.d.ts +21 -17
- package/dist/docs/TransformDebug.svelte +5 -6
- package/dist/docs/TransformDebug.svelte.d.ts +18 -14
- package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
- package/dist/types/d3-shape-extentions.d.ts +7 -0
- package/dist/utils/afterTick.d.ts +5 -0
- package/dist/utils/afterTick.js +8 -0
- package/dist/utils/arcText.svelte.d.ts +57 -0
- package/dist/utils/arcText.svelte.js +262 -0
- package/dist/utils/array.d.ts +9 -1
- package/dist/utils/array.js +13 -0
- package/dist/utils/attributes.d.ts +29 -0
- package/dist/utils/attributes.js +40 -0
- package/dist/utils/canvas.js +47 -10
- package/dist/utils/chart.d.ts +78 -0
- package/dist/utils/chart.js +512 -0
- package/dist/utils/color.d.ts +1 -0
- package/dist/utils/color.js +8 -0
- package/dist/utils/common.d.ts +3 -5
- package/dist/utils/common.js +3 -2
- package/dist/utils/connectorUtils.d.ts +21 -0
- package/dist/utils/connectorUtils.js +111 -0
- package/dist/utils/createId.d.ts +7 -0
- package/dist/utils/createId.js +9 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +84 -0
- package/dist/utils/filterObject.d.ts +9 -0
- package/dist/utils/filterObject.js +12 -0
- package/dist/utils/graph/dagre.d.ts +34 -0
- package/dist/utils/graph/dagre.js +78 -0
- package/dist/utils/graph/dagre.test.d.ts +1 -0
- package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
- package/dist/utils/graph/sankey.d.ts +28 -0
- package/dist/utils/{graph.js → graph/sankey.js} +13 -41
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/key.svelte.d.ts +3 -0
- package/dist/utils/key.svelte.js +11 -0
- package/dist/utils/legendPayload.d.ts +7 -0
- package/dist/utils/legendPayload.js +8 -0
- package/dist/utils/motion.svelte.d.ts +140 -0
- package/dist/utils/motion.svelte.js +180 -0
- package/dist/utils/motion.test.d.ts +1 -0
- package/dist/utils/motion.test.js +213 -0
- package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
- package/dist/utils/rect.svelte.js +105 -0
- package/dist/utils/scales.svelte.d.ts +90 -0
- package/dist/utils/{scales.js → scales.svelte.js} +100 -39
- package/dist/utils/stack.d.ts +2 -3
- package/dist/utils/stack.js +1 -1
- package/dist/utils/string.js +87 -0
- package/dist/utils/ticks.d.ts +8 -2
- package/dist/utils/ticks.js +28 -0
- package/dist/utils/ticks.test.d.ts +1 -0
- package/dist/utils/ticks.test.js +67 -0
- package/dist/utils/types.d.ts +81 -0
- package/package.json +21 -19
- package/dist/components/ChartContext.svelte +0 -295
- package/dist/components/ChartContext.svelte.d.ts +0 -139
- package/dist/components/TransformContext.svelte.d.ts +0 -158
- package/dist/stores/motionStore.d.ts +0 -30
- package/dist/stores/motionStore.js +0 -62
- package/dist/utils/graph.d.ts +0 -37
- package/dist/utils/rect.js +0 -107
- package/dist/utils/scales.d.ts +0 -66
- /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
|
@@ -1,91 +1,163 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { Without } from '../utils/types.js';
|
|
4
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
5
|
+
|
|
6
|
+
export type RadialGradientPropsWithoutHTML = {
|
|
7
|
+
/**
|
|
8
|
+
* Unique id for radialGradient
|
|
9
|
+
*/
|
|
10
|
+
id?: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Array array of strings (colors), will equally distributed from 0-100%.
|
|
14
|
+
* If array of tuples, will use first value as the offset, and second as color
|
|
15
|
+
*
|
|
16
|
+
* @default ['var(--tw-gradient-from)', 'var(--tw-gradient-to)']
|
|
17
|
+
*/
|
|
18
|
+
stops?: string[] | [string | number, string][];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The x coordinate of the center of the gradient
|
|
22
|
+
* @default '50%'
|
|
23
|
+
*/
|
|
24
|
+
cx?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The y coordinate of the center of the gradient
|
|
28
|
+
* @default '50%'
|
|
29
|
+
*/
|
|
30
|
+
cy?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The x coordinate of the focal point of the gradient
|
|
34
|
+
* @default cx
|
|
35
|
+
*/
|
|
36
|
+
fx?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The y coordinate of the focal point of the gradient
|
|
40
|
+
* @default cy
|
|
41
|
+
*/
|
|
42
|
+
fy?: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The radius of the gradient
|
|
46
|
+
*/
|
|
47
|
+
r?: string;
|
|
48
|
+
|
|
49
|
+
// TODO: Svelte / Typescript does not know `<radialRadiant fr="...">`
|
|
50
|
+
// fr = '0%';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Indicates how the gradient behaves if it starts or ends inside the bounds
|
|
54
|
+
* of the shape containing the gradient
|
|
55
|
+
*
|
|
56
|
+
* @default 'pad'
|
|
57
|
+
*/
|
|
58
|
+
spreadMethod?: 'pad' | 'reflect' | 'repeat';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Transform attribute for the gradient
|
|
62
|
+
*/
|
|
63
|
+
transform?: string | null;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Define the coordinate system for attributes (i.e. gradientUnits)
|
|
67
|
+
*
|
|
68
|
+
* @default 'objectBoundingBox'
|
|
69
|
+
*/
|
|
70
|
+
units?: 'objectBoundingBox' | 'userSpaceOnUse';
|
|
71
|
+
|
|
72
|
+
children?: Snippet<[{ id: string; gradient: string }]>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Render as a child of the gradient and will opt out of the default stops
|
|
76
|
+
* being rendered.
|
|
77
|
+
*/
|
|
78
|
+
stopsContent?: Snippet;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type RadialGradientProps = RadialGradientPropsWithoutHTML &
|
|
82
|
+
Without<SVGAttributes<SVGRadialGradientElement>, RadialGradientPropsWithoutHTML>;
|
|
83
|
+
</script>
|
|
4
84
|
|
|
85
|
+
<script lang="ts">
|
|
5
86
|
import { getRenderContext } from './Chart.svelte';
|
|
6
|
-
import {
|
|
7
|
-
import { getCanvasContext } from './layout/Canvas.svelte';
|
|
87
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
8
88
|
import { getComputedStyles } from '../utils/canvas.js';
|
|
9
89
|
import { parsePercent } from '../utils/math.js';
|
|
90
|
+
import { getChartContext } from './Chart.svelte';
|
|
91
|
+
import { createId } from '../utils/createId.js';
|
|
92
|
+
import { extractLayerProps, layerClass } from '../utils/attributes.js';
|
|
93
|
+
import { cls } from '@layerstack/tailwind';
|
|
94
|
+
|
|
95
|
+
const uid = $props.id();
|
|
96
|
+
|
|
97
|
+
let {
|
|
98
|
+
id = createId('radialGradient-', uid),
|
|
99
|
+
stops = ['var(--tw-gradient-from)', 'var(--tw-gradient-to)'],
|
|
100
|
+
cx = '50%',
|
|
101
|
+
cy = '50%',
|
|
102
|
+
fx = cx,
|
|
103
|
+
fy = cy,
|
|
104
|
+
r = '50%',
|
|
105
|
+
spreadMethod = 'pad',
|
|
106
|
+
transform = undefined,
|
|
107
|
+
units = 'objectBoundingBox',
|
|
108
|
+
children,
|
|
109
|
+
stopsContent,
|
|
110
|
+
class: className,
|
|
111
|
+
...restProps
|
|
112
|
+
}: RadialGradientProps = $props();
|
|
10
113
|
|
|
11
|
-
/** Unique id for linearGradient */
|
|
12
|
-
export let id: string = uniqueId('radialGradient-');
|
|
13
|
-
|
|
14
|
-
/** Array array of strings (colors), will equally distributed from 0-100%. If array of tuples, will use first value as the offset, and second as color */
|
|
15
|
-
export let stops: string[] | [string | number, string][] = [
|
|
16
|
-
'var(--tw-gradient-from)',
|
|
17
|
-
'var(--tw-gradient-to)',
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
export let cx = '50%';
|
|
21
|
-
export let cy = '50%';
|
|
22
|
-
export let fx = cx;
|
|
23
|
-
export let fy = cy;
|
|
24
|
-
export let r = '50%';
|
|
25
114
|
// TODO: Svelte / Typescript does not know `<radialRadiant fr="...">`
|
|
26
115
|
// export let fr = '0%';
|
|
27
116
|
|
|
28
|
-
|
|
29
|
-
export let spreadMethod: 'pad' | 'reflect' | 'repeat' = 'pad';
|
|
30
|
-
|
|
31
|
-
export let transform: string | null | undefined = undefined;
|
|
32
|
-
|
|
33
|
-
/** Define the coordinate system for attributes (i.e. gradientUnits) */
|
|
34
|
-
export let units: 'objectBoundingBox' | 'userSpaceOnUse' = 'objectBoundingBox';
|
|
35
|
-
|
|
36
|
-
const { width, height, padding } = chartContext();
|
|
117
|
+
const ctx = getChartContext();
|
|
37
118
|
|
|
38
|
-
const
|
|
39
|
-
const canvasContext = getCanvasContext();
|
|
119
|
+
const renderCtx = getRenderContext();
|
|
40
120
|
|
|
41
|
-
let canvasGradient
|
|
121
|
+
let canvasGradient = $state<CanvasGradient>();
|
|
42
122
|
|
|
43
|
-
function render(
|
|
123
|
+
function render(_ctx: CanvasRenderingContext2D) {
|
|
44
124
|
// TODO: Set correct values: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createRadialGradient. See also: LinearGradient
|
|
45
125
|
// TODO: Memoize `createRadialGradient()` (see LinearGradient)
|
|
46
|
-
const gradient =
|
|
126
|
+
const gradient = _ctx.createRadialGradient(0, 0, 0, 0, 0, 0);
|
|
47
127
|
|
|
48
128
|
// Use `getComputedStyles()` to convert each stop (if using CSS variables and/or classes) to color values
|
|
49
|
-
stops.
|
|
129
|
+
for (let i = 0; i < stops.length; i++) {
|
|
130
|
+
const stop = stops[i];
|
|
50
131
|
if (Array.isArray(stop)) {
|
|
51
|
-
const { fill } = getComputedStyles(
|
|
132
|
+
const { fill } = getComputedStyles(_ctx.canvas, {
|
|
52
133
|
styles: { fill: stop[1] },
|
|
53
|
-
classes:
|
|
134
|
+
classes: className,
|
|
54
135
|
});
|
|
55
136
|
gradient.addColorStop(parsePercent(stop[0]), fill);
|
|
56
137
|
} else {
|
|
57
|
-
const { fill } = getComputedStyles(
|
|
138
|
+
const { fill } = getComputedStyles(_ctx.canvas, {
|
|
58
139
|
styles: { fill: stop },
|
|
59
|
-
classes:
|
|
140
|
+
classes: className,
|
|
60
141
|
});
|
|
61
142
|
gradient.addColorStop(i / (stops.length - 1), fill);
|
|
62
143
|
}
|
|
63
|
-
}
|
|
144
|
+
}
|
|
64
145
|
|
|
65
146
|
canvasGradient = gradient;
|
|
66
147
|
}
|
|
67
148
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Redraw when props changes (TODO: styles, class, etc)
|
|
75
|
-
stops && cx && cy && fx && fy && $width && $height;
|
|
76
|
-
canvasContext.invalidate();
|
|
149
|
+
if (renderCtx === 'canvas') {
|
|
150
|
+
registerCanvasComponent({
|
|
151
|
+
name: 'Gradient',
|
|
152
|
+
render,
|
|
153
|
+
deps: () => [stops, cx, cy, fx, fy, ctx.width, ctx.height],
|
|
154
|
+
});
|
|
77
155
|
}
|
|
78
|
-
|
|
79
|
-
onDestroy(() => {
|
|
80
|
-
if (renderContext === 'canvas') {
|
|
81
|
-
canvasUnregister();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
156
|
</script>
|
|
85
157
|
|
|
86
|
-
{#if
|
|
87
|
-
|
|
88
|
-
{:else if
|
|
158
|
+
{#if renderCtx === 'canvas'}
|
|
159
|
+
{@render children?.({ id, gradient: canvasGradient as any })}
|
|
160
|
+
{:else if renderCtx === 'svg'}
|
|
89
161
|
<defs>
|
|
90
162
|
<radialGradient
|
|
91
163
|
{id}
|
|
@@ -97,21 +169,22 @@
|
|
|
97
169
|
{spreadMethod}
|
|
98
170
|
gradientTransform={transform}
|
|
99
171
|
gradientUnits={units}
|
|
100
|
-
{
|
|
172
|
+
{...extractLayerProps({ ...restProps, class: className }, 'radial-gradient')}
|
|
101
173
|
>
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
174
|
+
{#if stopsContent}
|
|
175
|
+
{@render stopsContent()}
|
|
176
|
+
{:else if stops}
|
|
177
|
+
{@const stopClass = cls(layerClass('radial-gradient-stop'), className)}
|
|
178
|
+
{#each stops as stop, i}
|
|
179
|
+
{#if Array.isArray(stop)}
|
|
180
|
+
<stop offset={stop[0]} stop-color={stop[1]} class={stopClass} />
|
|
181
|
+
{:else}
|
|
182
|
+
<stop offset="{i * (100 / (stops.length - 1))}%" stop-color={stop} class={stopClass} />
|
|
183
|
+
{/if}
|
|
184
|
+
{/each}
|
|
185
|
+
{/if}
|
|
113
186
|
</radialGradient>
|
|
114
187
|
</defs>
|
|
115
188
|
|
|
116
|
-
|
|
189
|
+
{@render children?.({ id, gradient: `url(#${id})` })}
|
|
117
190
|
{/if}
|
|
@@ -1,32 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { Without } from '../utils/types.js';
|
|
3
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
4
|
+
export type RadialGradientPropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* Unique id for radialGradient
|
|
7
|
+
*/
|
|
8
|
+
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Array array of strings (colors), will equally distributed from 0-100%.
|
|
11
|
+
* If array of tuples, will use first value as the offset, and second as color
|
|
12
|
+
*
|
|
13
|
+
* @default ['var(--tw-gradient-from)', 'var(--tw-gradient-to)']
|
|
14
|
+
*/
|
|
15
|
+
stops?: string[] | [string | number, string][];
|
|
16
|
+
/**
|
|
17
|
+
* The x coordinate of the center of the gradient
|
|
18
|
+
* @default '50%'
|
|
19
|
+
*/
|
|
20
|
+
cx?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The y coordinate of the center of the gradient
|
|
23
|
+
* @default '50%'
|
|
24
|
+
*/
|
|
25
|
+
cy?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The x coordinate of the focal point of the gradient
|
|
28
|
+
* @default cx
|
|
29
|
+
*/
|
|
30
|
+
fx?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The y coordinate of the focal point of the gradient
|
|
33
|
+
* @default cy
|
|
34
|
+
*/
|
|
35
|
+
fy?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The radius of the gradient
|
|
38
|
+
*/
|
|
39
|
+
r?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Indicates how the gradient behaves if it starts or ends inside the bounds
|
|
42
|
+
* of the shape containing the gradient
|
|
43
|
+
*
|
|
44
|
+
* @default 'pad'
|
|
45
|
+
*/
|
|
46
|
+
spreadMethod?: 'pad' | 'reflect' | 'repeat';
|
|
47
|
+
/**
|
|
48
|
+
* Transform attribute for the gradient
|
|
49
|
+
*/
|
|
50
|
+
transform?: string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Define the coordinate system for attributes (i.e. gradientUnits)
|
|
53
|
+
*
|
|
54
|
+
* @default 'objectBoundingBox'
|
|
55
|
+
*/
|
|
56
|
+
units?: 'objectBoundingBox' | 'userSpaceOnUse';
|
|
57
|
+
children?: Snippet<[{
|
|
58
|
+
id: string;
|
|
59
|
+
gradient: string;
|
|
60
|
+
}]>;
|
|
61
|
+
/**
|
|
62
|
+
* Render as a child of the gradient and will opt out of the default stops
|
|
63
|
+
* being rendered.
|
|
64
|
+
*/
|
|
65
|
+
stopsContent?: Snippet;
|
|
26
66
|
};
|
|
27
|
-
export type RadialGradientProps =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export default
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
67
|
+
export type RadialGradientProps = RadialGradientPropsWithoutHTML & Without<SVGAttributes<SVGRadialGradientElement>, RadialGradientPropsWithoutHTML>;
|
|
68
|
+
declare const RadialGradient: import("svelte").Component<RadialGradientProps, {}, "">;
|
|
69
|
+
type RadialGradient = ReturnType<typeof RadialGradient>;
|
|
70
|
+
export default RadialGradient;
|
|
@@ -1,69 +1,95 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
4
|
+
import { createMotion, parseMotionProp, type MotionProp } from '../utils/motion.svelte.js';
|
|
5
|
+
import { renderRect, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
6
|
+
|
|
7
|
+
export type RectPropsWithoutHTML = {
|
|
8
|
+
/**
|
|
9
|
+
* @default 0
|
|
10
|
+
*/
|
|
11
|
+
x?: number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @default x
|
|
15
|
+
*/
|
|
16
|
+
initialX?: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @default 0
|
|
20
|
+
*/
|
|
21
|
+
y?: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @default y
|
|
25
|
+
*/
|
|
26
|
+
initialY?: number;
|
|
27
|
+
width: number;
|
|
28
|
+
initialWidth?: number;
|
|
29
|
+
height: number;
|
|
30
|
+
initialHeight?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Underlying `<rect>` tag when using <Svg>. Useful for bindings.
|
|
33
|
+
*
|
|
34
|
+
* @bindable
|
|
35
|
+
*/
|
|
36
|
+
ref?: SVGRectElement;
|
|
37
|
+
|
|
38
|
+
motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
|
|
39
|
+
} & CommonStyleProps;
|
|
40
|
+
|
|
41
|
+
export type RectProps = RectPropsWithoutHTML &
|
|
42
|
+
Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML>;
|
|
43
|
+
</script>
|
|
44
|
+
|
|
1
45
|
<script lang="ts">
|
|
2
|
-
import { onDestroy, tick } from 'svelte';
|
|
3
|
-
import type { ClassValue } from 'svelte/elements';
|
|
4
46
|
import { cls } from '@layerstack/tailwind';
|
|
5
|
-
import { objectId } from '@layerstack/utils/object';
|
|
6
47
|
import { merge } from 'lodash-es';
|
|
7
48
|
|
|
8
|
-
import {
|
|
9
|
-
motionStore,
|
|
10
|
-
resolveOptions,
|
|
11
|
-
type SpringOptions,
|
|
12
|
-
type TweenedOptions,
|
|
13
|
-
} from '../stores/motionStore.js';
|
|
14
49
|
import { getRenderContext } from './Chart.svelte';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export let spring: boolean | SpringOptions | { [prop: string]: SpringOptions } = undefined;
|
|
51
|
-
export let tweened: boolean | TweenedOptions | { [prop: string]: TweenedOptions } = undefined;
|
|
52
|
-
|
|
53
|
-
let tweened_x = motionStore(initialX, resolveOptions('x', { spring, tweened }));
|
|
54
|
-
let tweened_y = motionStore(initialY, resolveOptions('y', { spring, tweened }));
|
|
55
|
-
let tweened_width = motionStore(initialWidth, resolveOptions('width', { spring, tweened }));
|
|
56
|
-
let tweened_height = motionStore(initialHeight, resolveOptions('height', { spring, tweened }));
|
|
57
|
-
|
|
58
|
-
$: tick().then(() => {
|
|
59
|
-
tweened_x.set(x);
|
|
60
|
-
tweened_y.set(y);
|
|
61
|
-
tweened_width.set(width);
|
|
62
|
-
tweened_height.set(height);
|
|
50
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
51
|
+
import { createKey } from '../utils/key.svelte.js';
|
|
52
|
+
import { layerClass } from '../utils/attributes.js';
|
|
53
|
+
|
|
54
|
+
let {
|
|
55
|
+
height,
|
|
56
|
+
width,
|
|
57
|
+
x = 0,
|
|
58
|
+
y = 0,
|
|
59
|
+
initialX = x,
|
|
60
|
+
initialY = y,
|
|
61
|
+
fill,
|
|
62
|
+
fillOpacity,
|
|
63
|
+
stroke,
|
|
64
|
+
initialHeight = height,
|
|
65
|
+
initialWidth = width,
|
|
66
|
+
strokeWidth,
|
|
67
|
+
opacity,
|
|
68
|
+
ref: refProp = $bindable(),
|
|
69
|
+
motion,
|
|
70
|
+
class: className,
|
|
71
|
+
onclick,
|
|
72
|
+
ondblclick,
|
|
73
|
+
onpointerenter,
|
|
74
|
+
onpointermove,
|
|
75
|
+
onpointerleave,
|
|
76
|
+
onpointerover,
|
|
77
|
+
onpointerout,
|
|
78
|
+
...restProps
|
|
79
|
+
}: RectProps = $props();
|
|
80
|
+
|
|
81
|
+
let ref = $state<SVGRectElement>();
|
|
82
|
+
|
|
83
|
+
$effect.pre(() => {
|
|
84
|
+
refProp = ref;
|
|
63
85
|
});
|
|
64
86
|
|
|
65
|
-
const
|
|
66
|
-
const
|
|
87
|
+
const motionX = createMotion(initialX, () => x, parseMotionProp(motion, 'x'));
|
|
88
|
+
const motionY = createMotion(initialY, () => y, parseMotionProp(motion, 'y'));
|
|
89
|
+
const motionWidth = createMotion(initialWidth, () => width, parseMotionProp(motion, 'width'));
|
|
90
|
+
const motionHeight = createMotion(initialHeight, () => height, parseMotionProp(motion, 'height'));
|
|
91
|
+
|
|
92
|
+
const renderCtx = getRenderContext();
|
|
67
93
|
|
|
68
94
|
function render(
|
|
69
95
|
ctx: CanvasRenderingContext2D,
|
|
@@ -71,7 +97,12 @@
|
|
|
71
97
|
) {
|
|
72
98
|
renderRect(
|
|
73
99
|
ctx,
|
|
74
|
-
{
|
|
100
|
+
{
|
|
101
|
+
x: motionX.current,
|
|
102
|
+
y: motionY.current,
|
|
103
|
+
width: motionWidth.current,
|
|
104
|
+
height: motionHeight.current,
|
|
105
|
+
},
|
|
75
106
|
styleOverrides
|
|
76
107
|
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
77
108
|
: {
|
|
@@ -82,26 +113,11 @@
|
|
|
82
113
|
}
|
|
83
114
|
|
|
84
115
|
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
$: if (renderContext === 'canvas') {
|
|
89
|
-
// Redraw when props change
|
|
90
|
-
$tweened_x &&
|
|
91
|
-
$tweened_y &&
|
|
92
|
-
$tweened_width &&
|
|
93
|
-
$tweened_height &&
|
|
94
|
-
fillKey &&
|
|
95
|
-
strokeKey &&
|
|
96
|
-
strokeWidth &&
|
|
97
|
-
opacity &&
|
|
98
|
-
className;
|
|
99
|
-
canvasContext.invalidate();
|
|
100
|
-
}
|
|
116
|
+
const fillKey = createKey(() => fill);
|
|
117
|
+
const strokeKey = createKey(() => stroke);
|
|
101
118
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
canvasUnregister = canvasContext.register({
|
|
119
|
+
if (renderCtx === 'canvas') {
|
|
120
|
+
registerCanvasComponent({
|
|
105
121
|
name: 'Rect',
|
|
106
122
|
render,
|
|
107
123
|
events: {
|
|
@@ -113,38 +129,41 @@
|
|
|
113
129
|
pointerover: onpointerover,
|
|
114
130
|
pointerout: onpointerout,
|
|
115
131
|
},
|
|
132
|
+
deps: () => [
|
|
133
|
+
motionX.current,
|
|
134
|
+
motionY.current,
|
|
135
|
+
motionWidth.current,
|
|
136
|
+
motionHeight.current,
|
|
137
|
+
fillKey.current,
|
|
138
|
+
strokeKey.current,
|
|
139
|
+
strokeWidth,
|
|
140
|
+
opacity,
|
|
141
|
+
className,
|
|
142
|
+
],
|
|
116
143
|
});
|
|
117
144
|
}
|
|
118
|
-
|
|
119
|
-
onDestroy(() => {
|
|
120
|
-
if (renderContext === 'canvas') {
|
|
121
|
-
canvasUnregister();
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
145
|
</script>
|
|
125
146
|
|
|
126
|
-
{#if
|
|
127
|
-
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
|
|
128
|
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
147
|
+
{#if renderCtx === 'svg'}
|
|
129
148
|
<rect
|
|
130
|
-
x={
|
|
131
|
-
y={
|
|
132
|
-
width={
|
|
133
|
-
height={
|
|
149
|
+
x={motionX.current}
|
|
150
|
+
y={motionY.current}
|
|
151
|
+
width={motionWidth.current}
|
|
152
|
+
height={motionHeight.current}
|
|
134
153
|
{fill}
|
|
135
154
|
fill-opacity={fillOpacity}
|
|
136
155
|
{stroke}
|
|
137
156
|
stroke-width={strokeWidth}
|
|
138
157
|
{opacity}
|
|
139
|
-
class={cls(fill == null && 'fill-surface-content', className)}
|
|
140
|
-
{
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
bind:this={
|
|
158
|
+
class={cls(layerClass('rect'), fill == null && 'fill-surface-content', className)}
|
|
159
|
+
{...restProps}
|
|
160
|
+
{onclick}
|
|
161
|
+
{ondblclick}
|
|
162
|
+
{onpointerenter}
|
|
163
|
+
{onpointermove}
|
|
164
|
+
{onpointerleave}
|
|
165
|
+
{onpointerover}
|
|
166
|
+
{onpointerout}
|
|
167
|
+
bind:this={ref}
|
|
149
168
|
/>
|
|
150
169
|
{/if}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
2
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
3
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
4
|
+
export type RectPropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* @default 0
|
|
7
|
+
*/
|
|
8
|
+
x?: number;
|
|
9
|
+
/**
|
|
10
|
+
* @default x
|
|
11
|
+
*/
|
|
12
|
+
initialX?: number;
|
|
13
|
+
/**
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
y?: number;
|
|
17
|
+
/**
|
|
18
|
+
* @default y
|
|
19
|
+
*/
|
|
20
|
+
initialY?: number;
|
|
21
|
+
width: number;
|
|
22
|
+
initialWidth?: number;
|
|
23
|
+
height: number;
|
|
24
|
+
initialHeight?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Underlying `<rect>` tag when using <Svg>. Useful for bindings.
|
|
27
|
+
*
|
|
28
|
+
* @bindable
|
|
29
|
+
*/
|
|
30
|
+
ref?: SVGRectElement;
|
|
31
|
+
motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
|
|
32
|
+
} & CommonStyleProps;
|
|
33
|
+
export type RectProps = RectPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML>;
|
|
34
|
+
declare const Rect: import("svelte").Component<RectProps, {}, "ref">;
|
|
35
|
+
type Rect = ReturnType<typeof Rect>;
|
|
36
|
+
export default Rect;
|