layerchart 2.0.0-next.0 → 2.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/movable.d.ts +28 -0
- package/dist/actions/movable.js +91 -0
- package/dist/components/AnnotationLine.svelte +155 -0
- package/dist/components/AnnotationLine.svelte.d.ts +28 -0
- package/dist/components/AnnotationPoint.svelte +121 -0
- package/dist/components/AnnotationPoint.svelte.d.ts +32 -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 +287 -174
- package/dist/components/Axis.svelte.d.ts +116 -0
- package/dist/components/Bar.svelte +163 -107
- package/dist/components/Bar.svelte.d.ts +48 -0
- package/dist/components/Bars.svelte +54 -68
- package/dist/components/Bars.svelte.d.ts +27 -0
- package/dist/components/Blur.svelte +31 -7
- 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 +60 -15
- 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 +47 -12
- 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 +28 -13
- package/dist/components/Graticule.svelte.d.ts +11 -52
- package/dist/components/Grid.svelte +226 -114
- package/dist/components/Grid.svelte.d.ts +70 -0
- package/dist/components/Group.svelte +132 -105
- package/dist/components/Group.svelte.d.ts +53 -0
- package/dist/components/Highlight.svelte +409 -307
- package/dist/components/Highlight.svelte.d.ts +107 -0
- package/dist/components/Hull.svelte +96 -45
- package/dist/components/Hull.svelte.d.ts +40 -30
- package/dist/components/Labels.svelte +125 -46
- 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 +105 -62
- 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 +106 -75
- 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 +25 -24
- 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,23 +1,45 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { Without } from '../utils/types.js';
|
|
4
|
+
|
|
5
|
+
export type ChartClipPathPropsWithoutHTML = {
|
|
6
|
+
/**
|
|
7
|
+
* Include padding area (ex. axis)
|
|
8
|
+
*
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
full?: boolean;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Disable clipping (show all)
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
|
|
20
|
+
children?: Snippet;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ChartClipPathProps = ChartClipPathPropsWithoutHTML &
|
|
24
|
+
Without<Omit<RectClipPathProps, 'width' | 'height'>, ChartClipPathPropsWithoutHTML>;
|
|
25
|
+
</script>
|
|
26
|
+
|
|
1
27
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import RectClipPath from './RectClipPath.svelte';
|
|
28
|
+
import { getChartContext } from './Chart.svelte';
|
|
4
29
|
|
|
5
|
-
|
|
30
|
+
import RectClipPath, { type RectClipPathProps } from './RectClipPath.svelte';
|
|
31
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
6
32
|
|
|
7
|
-
|
|
8
|
-
export let full = false;
|
|
33
|
+
let { full = false, disabled = false, ...restProps }: ChartClipPathProps = $props();
|
|
9
34
|
|
|
10
|
-
|
|
11
|
-
export let disabled: boolean = false;
|
|
35
|
+
const ctx = getChartContext();
|
|
12
36
|
</script>
|
|
13
37
|
|
|
14
38
|
<RectClipPath
|
|
15
|
-
x={full &&
|
|
16
|
-
y={full &&
|
|
17
|
-
width={$width + (full ? ($padding?.left ?? 0) + ($padding?.right ?? 0) : 0)}
|
|
18
|
-
height={$height + (full ? ($padding?.top ?? 0) + ($padding?.bottom ?? 0) : 0)}
|
|
39
|
+
x={full && ctx.padding.left ? -ctx.padding.left : 0}
|
|
40
|
+
y={full && ctx.padding.top ? -ctx.padding.top : 0}
|
|
19
41
|
{disabled}
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
height={ctx.height + (full ? (ctx.padding?.top ?? 0) + (ctx.padding?.bottom ?? 0) : 0)}
|
|
43
|
+
width={ctx.width + (full ? (ctx.padding?.left ?? 0) + (ctx.padding?.right ?? 0) : 0)}
|
|
44
|
+
{...extractLayerProps(restProps, 'chart-clip-path')}
|
|
45
|
+
/>
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { Without } from '../utils/types.js';
|
|
3
|
+
export type ChartClipPathPropsWithoutHTML = {
|
|
4
|
+
/**
|
|
5
|
+
* Include padding area (ex. axis)
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
full?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Disable clipping (show all)
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
children?: Snippet;
|
|
14
17
|
};
|
|
15
|
-
export type ChartClipPathProps =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export {};
|
|
18
|
+
export type ChartClipPathProps = ChartClipPathPropsWithoutHTML & Without<Omit<RectClipPathProps, 'width' | 'height'>, ChartClipPathPropsWithoutHTML>;
|
|
19
|
+
import { type RectClipPathProps } from './RectClipPath.svelte';
|
|
20
|
+
declare const ChartClipPath: import("svelte").Component<ChartClipPathProps, {}, "">;
|
|
21
|
+
type ChartClipPath = ReturnType<typeof ChartClipPath>;
|
|
22
|
+
export default ChartClipPath;
|
|
@@ -1,54 +1,108 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
3
|
+
|
|
4
|
+
export type CirclePropsWithoutHTML = {
|
|
5
|
+
/**
|
|
6
|
+
* The center x position of the circle.
|
|
7
|
+
*
|
|
8
|
+
* @default 0
|
|
9
|
+
*/
|
|
10
|
+
cx?: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The initial center x position of the circle.
|
|
14
|
+
*
|
|
15
|
+
* @default cx
|
|
16
|
+
*/
|
|
17
|
+
initialCx?: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The center y position of the circle.
|
|
21
|
+
*
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
cy?: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The initial center y position of the circle.
|
|
28
|
+
*
|
|
29
|
+
* @default cy
|
|
30
|
+
*/
|
|
31
|
+
initialCy?: number;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The radius of the circle.
|
|
35
|
+
*
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
r?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The initial radius of the circle.
|
|
42
|
+
*
|
|
43
|
+
* @default r
|
|
44
|
+
*/
|
|
45
|
+
initialR?: number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A bindable reference to the `<circle>` element
|
|
49
|
+
*
|
|
50
|
+
* @bindable
|
|
51
|
+
*/
|
|
52
|
+
ref?: SVGCircleElement;
|
|
53
|
+
|
|
54
|
+
motion?: MotionProp;
|
|
55
|
+
} & CommonStyleProps;
|
|
56
|
+
|
|
57
|
+
export type CircleProps = CirclePropsWithoutHTML &
|
|
58
|
+
Without<SVGAttributes<Element>, CirclePropsWithoutHTML>;
|
|
59
|
+
</script>
|
|
60
|
+
|
|
1
61
|
<script lang="ts">
|
|
2
|
-
import { onDestroy, tick } from 'svelte';
|
|
3
|
-
import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
|
|
4
62
|
import { cls } from '@layerstack/tailwind';
|
|
5
|
-
import { objectId } from '@layerstack/utils/object';
|
|
6
63
|
import { merge } from 'lodash-es';
|
|
7
64
|
|
|
8
65
|
import { getRenderContext } from './Chart.svelte';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
66
|
+
import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
|
|
67
|
+
import { registerCanvasComponent } from './layout/Canvas.svelte';
|
|
11
68
|
import { renderCircle, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
69
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
70
|
+
import { createKey } from '../utils/key.svelte.js';
|
|
71
|
+
import { layerClass } from '../utils/attributes.js';
|
|
72
|
+
|
|
73
|
+
let {
|
|
74
|
+
cx = 0,
|
|
75
|
+
initialCx: initialCxProp,
|
|
76
|
+
cy = 0,
|
|
77
|
+
initialCy: initialCyProp,
|
|
78
|
+
r = 1,
|
|
79
|
+
initialR: initialRProp,
|
|
80
|
+
motion,
|
|
81
|
+
fill,
|
|
82
|
+
fillOpacity,
|
|
83
|
+
stroke,
|
|
84
|
+
strokeWidth,
|
|
85
|
+
opacity,
|
|
86
|
+
class: className,
|
|
87
|
+
ref: refProp = $bindable(),
|
|
88
|
+
...restProps
|
|
89
|
+
}: CircleProps = $props();
|
|
90
|
+
|
|
91
|
+
let ref = $state<SVGCircleElement>();
|
|
92
|
+
|
|
93
|
+
$effect.pre(() => {
|
|
94
|
+
refProp = ref;
|
|
95
|
+
});
|
|
12
96
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export let cy: number = 0;
|
|
17
|
-
export let initialCy = cy;
|
|
18
|
-
|
|
19
|
-
export let r: number = 1;
|
|
20
|
-
export let initialR = r;
|
|
21
|
-
|
|
22
|
-
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
23
|
-
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
24
|
-
|
|
25
|
-
export let fill: string | undefined = undefined;
|
|
26
|
-
export let fillOpacity: number | undefined = undefined;
|
|
27
|
-
export let stroke: string | undefined = undefined;
|
|
28
|
-
export let strokeWidth: number | undefined = undefined;
|
|
29
|
-
export let opacity: number | undefined = undefined;
|
|
30
|
-
|
|
31
|
-
let className: string | undefined = undefined;
|
|
32
|
-
export { className as class };
|
|
33
|
-
|
|
34
|
-
export let onclick: ((e: MouseEvent) => void) | undefined = undefined;
|
|
35
|
-
export let onpointerdown: ((e: PointerEvent) => void) | undefined = undefined;
|
|
36
|
-
export let onpointerenter: ((e: PointerEvent) => void) | undefined = undefined;
|
|
37
|
-
export let onpointermove: ((e: PointerEvent) => void) | undefined = undefined;
|
|
38
|
-
export let onpointerleave: ((e: PointerEvent) => void) | undefined = undefined;
|
|
39
|
-
|
|
40
|
-
let tweened_cx = motionStore(initialCx, { spring, tweened });
|
|
41
|
-
let tweened_cy = motionStore(initialCy, { spring, tweened });
|
|
42
|
-
let tweened_r = motionStore(initialR, { spring, tweened });
|
|
97
|
+
const initialCx = initialCxProp ?? cx;
|
|
98
|
+
const initialCy = initialCyProp ?? cy;
|
|
99
|
+
const initialR = initialRProp ?? r;
|
|
43
100
|
|
|
44
|
-
|
|
45
|
-
tweened_cx.set(cx);
|
|
46
|
-
tweened_cy.set(cy);
|
|
47
|
-
tweened_r.set(r);
|
|
48
|
-
});
|
|
101
|
+
const renderCtx = getRenderContext();
|
|
49
102
|
|
|
50
|
-
const
|
|
51
|
-
const
|
|
103
|
+
const motionCx = createMotion(initialCx, () => cx, motion);
|
|
104
|
+
const motionCy = createMotion(initialCy, () => cy, motion);
|
|
105
|
+
const motionR = createMotion(initialR, () => r, motion);
|
|
52
106
|
|
|
53
107
|
function render(
|
|
54
108
|
ctx: CanvasRenderingContext2D,
|
|
@@ -56,7 +110,7 @@
|
|
|
56
110
|
) {
|
|
57
111
|
renderCircle(
|
|
58
112
|
ctx,
|
|
59
|
-
{ cx:
|
|
113
|
+
{ cx: motionCx.current, cy: motionCy.current, r: motionR.current },
|
|
60
114
|
styleOverrides
|
|
61
115
|
? merge({ styles: { strokeWidth } }, styleOverrides)
|
|
62
116
|
: {
|
|
@@ -67,62 +121,47 @@
|
|
|
67
121
|
}
|
|
68
122
|
|
|
69
123
|
// TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
$: if (renderContext === 'canvas') {
|
|
74
|
-
// Redraw when props changes
|
|
75
|
-
$tweened_cx &&
|
|
76
|
-
$tweened_cy &&
|
|
77
|
-
$tweened_r &&
|
|
78
|
-
fillKey &&
|
|
79
|
-
fillOpacity &&
|
|
80
|
-
strokeKey &&
|
|
81
|
-
strokeWidth &&
|
|
82
|
-
opacity &&
|
|
83
|
-
className;
|
|
84
|
-
canvasContext.invalidate();
|
|
85
|
-
}
|
|
124
|
+
const fillKey = createKey(() => fill);
|
|
125
|
+
const strokeKey = createKey(() => stroke);
|
|
86
126
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
canvasUnregister = canvasContext.register({
|
|
127
|
+
if (renderCtx === 'canvas') {
|
|
128
|
+
registerCanvasComponent({
|
|
90
129
|
name: 'Circle',
|
|
91
130
|
render,
|
|
92
131
|
events: {
|
|
93
|
-
click: onclick,
|
|
94
|
-
pointerdown: onpointerdown,
|
|
95
|
-
pointerenter: onpointerenter,
|
|
96
|
-
pointermove: onpointermove,
|
|
97
|
-
pointerleave: onpointerleave,
|
|
132
|
+
click: restProps.onclick,
|
|
133
|
+
pointerdown: restProps.onpointerdown,
|
|
134
|
+
pointerenter: restProps.onpointerenter,
|
|
135
|
+
pointermove: restProps.onpointermove,
|
|
136
|
+
pointerleave: restProps.onpointerleave,
|
|
98
137
|
},
|
|
138
|
+
deps: () => [
|
|
139
|
+
motionCx.current,
|
|
140
|
+
motionCy.current,
|
|
141
|
+
motionR.current,
|
|
142
|
+
fillKey.current,
|
|
143
|
+
fillOpacity,
|
|
144
|
+
strokeKey.current,
|
|
145
|
+
strokeWidth,
|
|
146
|
+
opacity,
|
|
147
|
+
className,
|
|
148
|
+
],
|
|
99
149
|
});
|
|
100
150
|
}
|
|
101
|
-
|
|
102
|
-
onDestroy(() => {
|
|
103
|
-
if (renderContext === 'canvas') {
|
|
104
|
-
canvasUnregister();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
151
|
</script>
|
|
108
152
|
|
|
109
|
-
{#if
|
|
110
|
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
153
|
+
{#if renderCtx === 'svg'}
|
|
111
154
|
<circle
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
155
|
+
bind:this={ref}
|
|
156
|
+
cx={motionCx.current}
|
|
157
|
+
cy={motionCy.current}
|
|
158
|
+
r={motionR.current}
|
|
115
159
|
{fill}
|
|
116
160
|
fill-opacity={fillOpacity}
|
|
117
161
|
{stroke}
|
|
118
162
|
stroke-width={strokeWidth}
|
|
119
163
|
{opacity}
|
|
120
|
-
class={cls(fill == null && 'fill-surface-content', className)}
|
|
121
|
-
{
|
|
122
|
-
on:click={onclick}
|
|
123
|
-
on:pointerdown={onpointerdown}
|
|
124
|
-
on:pointerenter={onpointerenter}
|
|
125
|
-
on:pointermove={onpointermove}
|
|
126
|
-
on:pointerleave={onpointerleave}
|
|
164
|
+
class={cls(layerClass('circle'), fill == null && 'fill-surface-content', className)}
|
|
165
|
+
{...restProps}
|
|
127
166
|
/>
|
|
128
167
|
{/if}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CommonStyleProps, Without } from '../utils/types.js';
|
|
2
|
+
export type CirclePropsWithoutHTML = {
|
|
3
|
+
/**
|
|
4
|
+
* The center x position of the circle.
|
|
5
|
+
*
|
|
6
|
+
* @default 0
|
|
7
|
+
*/
|
|
8
|
+
cx?: number;
|
|
9
|
+
/**
|
|
10
|
+
* The initial center x position of the circle.
|
|
11
|
+
*
|
|
12
|
+
* @default cx
|
|
13
|
+
*/
|
|
14
|
+
initialCx?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The center y position of the circle.
|
|
17
|
+
*
|
|
18
|
+
* @default 0
|
|
19
|
+
*/
|
|
20
|
+
cy?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The initial center y position of the circle.
|
|
23
|
+
*
|
|
24
|
+
* @default cy
|
|
25
|
+
*/
|
|
26
|
+
initialCy?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The radius of the circle.
|
|
29
|
+
*
|
|
30
|
+
* @default 1
|
|
31
|
+
*/
|
|
32
|
+
r?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The initial radius of the circle.
|
|
35
|
+
*
|
|
36
|
+
* @default r
|
|
37
|
+
*/
|
|
38
|
+
initialR?: number;
|
|
39
|
+
/**
|
|
40
|
+
* A bindable reference to the `<circle>` element
|
|
41
|
+
*
|
|
42
|
+
* @bindable
|
|
43
|
+
*/
|
|
44
|
+
ref?: SVGCircleElement;
|
|
45
|
+
motion?: MotionProp;
|
|
46
|
+
} & CommonStyleProps;
|
|
47
|
+
export type CircleProps = CirclePropsWithoutHTML & Without<SVGAttributes<Element>, CirclePropsWithoutHTML>;
|
|
48
|
+
import { type MotionProp } from '../utils/motion.svelte.js';
|
|
49
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
50
|
+
declare const Circle: import("svelte").Component<CircleProps, {}, "ref">;
|
|
51
|
+
type Circle = ReturnType<typeof Circle>;
|
|
52
|
+
export default Circle;
|
|
@@ -1,25 +1,85 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { MotionProp } from '../utils/motion.svelte.js';
|
|
3
|
+
import ClipPath, { type ClipPathPropsWithoutHTML } from './ClipPath.svelte';
|
|
4
|
+
|
|
5
|
+
export type CircleClipPathPropsWithoutHTML = {
|
|
6
|
+
/**
|
|
7
|
+
* A unique id for the clipPath.
|
|
8
|
+
*/
|
|
9
|
+
id?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The center x position of the circle.
|
|
13
|
+
*
|
|
14
|
+
* @default 0
|
|
15
|
+
*/
|
|
16
|
+
cx?: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The center y position of the circle.
|
|
20
|
+
*
|
|
21
|
+
* @default 0
|
|
22
|
+
*/
|
|
23
|
+
cy?: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The radius of the circle.
|
|
27
|
+
*
|
|
28
|
+
* @required
|
|
29
|
+
*/
|
|
30
|
+
r: number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether to disable clipping (show all).
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
disabled?: boolean;
|
|
3
38
|
|
|
4
|
-
|
|
39
|
+
/**
|
|
40
|
+
* A bindable reference to the underlying `<circle>` element'
|
|
41
|
+
*
|
|
42
|
+
* @bindable
|
|
43
|
+
*/
|
|
44
|
+
ref?: SVGCircleElement;
|
|
5
45
|
|
|
6
|
-
|
|
46
|
+
/**
|
|
47
|
+
* The children snippet to render content inside the clipPath.
|
|
48
|
+
*/
|
|
49
|
+
children?: ClipPathPropsWithoutHTML['children'];
|
|
50
|
+
|
|
51
|
+
motion?: MotionProp;
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<script lang="ts">
|
|
7
56
|
import Circle from './Circle.svelte';
|
|
57
|
+
import { createId } from '../utils/createId.js';
|
|
58
|
+
import { extractLayerProps } from '../utils/attributes.js';
|
|
59
|
+
|
|
60
|
+
const uid = $props.id();
|
|
8
61
|
|
|
9
|
-
|
|
10
|
-
|
|
62
|
+
let {
|
|
63
|
+
id = createId('clipPath-', uid),
|
|
64
|
+
cx = 0,
|
|
65
|
+
cy = 0,
|
|
66
|
+
r,
|
|
67
|
+
motion,
|
|
68
|
+
disabled = false,
|
|
69
|
+
ref: refProp = $bindable(),
|
|
70
|
+
children,
|
|
71
|
+
...restProps
|
|
72
|
+
}: CircleClipPathPropsWithoutHTML = $props();
|
|
11
73
|
|
|
12
|
-
|
|
13
|
-
export let cy: number = 0;
|
|
14
|
-
export let r: number;
|
|
15
|
-
export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
|
|
16
|
-
export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
|
|
74
|
+
let ref = $state<SVGCircleElement>();
|
|
17
75
|
|
|
18
|
-
|
|
19
|
-
|
|
76
|
+
$effect.pre(() => {
|
|
77
|
+
refProp = ref;
|
|
78
|
+
});
|
|
20
79
|
</script>
|
|
21
80
|
|
|
22
|
-
<ClipPath {id} {disabled}
|
|
23
|
-
|
|
24
|
-
|
|
81
|
+
<ClipPath {id} {disabled} {children}>
|
|
82
|
+
{#snippet clip()}
|
|
83
|
+
<Circle {cx} {cy} {r} {motion} {...extractLayerProps(restProps, 'clip-path-circle')} bind:ref />
|
|
84
|
+
{/snippet}
|
|
25
85
|
</ClipPath>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MotionProp } from '../utils/motion.svelte.js';
|
|
2
|
+
import { type ClipPathPropsWithoutHTML } from './ClipPath.svelte';
|
|
3
|
+
export type CircleClipPathPropsWithoutHTML = {
|
|
4
|
+
/**
|
|
5
|
+
* A unique id for the clipPath.
|
|
6
|
+
*/
|
|
7
|
+
id?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The center x position of the circle.
|
|
10
|
+
*
|
|
11
|
+
* @default 0
|
|
12
|
+
*/
|
|
13
|
+
cx?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The center y position of the circle.
|
|
16
|
+
*
|
|
17
|
+
* @default 0
|
|
18
|
+
*/
|
|
19
|
+
cy?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The radius of the circle.
|
|
22
|
+
*
|
|
23
|
+
* @required
|
|
24
|
+
*/
|
|
25
|
+
r: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to disable clipping (show all).
|
|
28
|
+
*
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* A bindable reference to the underlying `<circle>` element'
|
|
34
|
+
*
|
|
35
|
+
* @bindable
|
|
36
|
+
*/
|
|
37
|
+
ref?: SVGCircleElement;
|
|
38
|
+
/**
|
|
39
|
+
* The children snippet to render content inside the clipPath.
|
|
40
|
+
*/
|
|
41
|
+
children?: ClipPathPropsWithoutHTML['children'];
|
|
42
|
+
motion?: MotionProp;
|
|
43
|
+
};
|
|
44
|
+
declare const CircleClipPath: import("svelte").Component<CircleClipPathPropsWithoutHTML, {}, "ref">;
|
|
45
|
+
type CircleClipPath = ReturnType<typeof CircleClipPath>;
|
|
46
|
+
export default CircleClipPath;
|
|
@@ -1,19 +1,65 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import {
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { createId } from '../utils/createId.js';
|
|
3
|
+
import type { Without } from '../utils/types.js';
|
|
4
|
+
import { layerClass } from '../utils/attributes.js';
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
import type { SVGAttributes } from 'svelte/elements';
|
|
7
|
+
|
|
8
|
+
export type ClipPathPropsWithoutHTML = {
|
|
9
|
+
/**
|
|
10
|
+
* A unique id for the clipPath.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
id?: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Use existing path or shape (by id) for clipPath
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
useId?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether to disable clipping (show all).
|
|
23
|
+
*
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A snippet to insert content into the clipPath.
|
|
30
|
+
* Provides the id for the clipPath as a snippet prop.
|
|
31
|
+
*/
|
|
32
|
+
clip?: Snippet<[{ id: string }]>;
|
|
3
33
|
|
|
4
|
-
|
|
5
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Children to render in the `<g>` element that links to the clipPath (if not disabled).
|
|
36
|
+
* Provides the id, url, and useId for the clipPath as snippet props.
|
|
37
|
+
*/
|
|
38
|
+
children?: Snippet<[{ id: string; url: string; useId?: string }]>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ClipPathProps = ClipPathPropsWithoutHTML &
|
|
42
|
+
Without<SVGAttributes<SVGClipPathElement>, ClipPathPropsWithoutHTML>;
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<script lang="ts">
|
|
46
|
+
const uid = $props.id();
|
|
6
47
|
|
|
7
|
-
|
|
8
|
-
|
|
48
|
+
let {
|
|
49
|
+
id = createId('clipPath-', uid),
|
|
50
|
+
useId,
|
|
51
|
+
disabled = false,
|
|
52
|
+
children,
|
|
53
|
+
clip,
|
|
54
|
+
...restProps
|
|
55
|
+
}: ClipPathPropsWithoutHTML = $props();
|
|
9
56
|
|
|
10
|
-
|
|
11
|
-
export let disabled: boolean = false;
|
|
57
|
+
const url = $derived(`url(#${id})`);
|
|
12
58
|
</script>
|
|
13
59
|
|
|
14
60
|
<defs>
|
|
15
|
-
<clipPath {id} {
|
|
16
|
-
|
|
61
|
+
<clipPath {id} {...restProps}>
|
|
62
|
+
{@render clip?.({ id })}
|
|
17
63
|
|
|
18
64
|
{#if useId}
|
|
19
65
|
<use href="#{useId}" />
|
|
@@ -21,13 +67,12 @@
|
|
|
21
67
|
</clipPath>
|
|
22
68
|
</defs>
|
|
23
69
|
|
|
24
|
-
{#if
|
|
70
|
+
{#if children}
|
|
25
71
|
{#if disabled}
|
|
26
|
-
|
|
72
|
+
{@render children({ id, url, useId })}
|
|
27
73
|
{:else}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<slot {id} url="url(#{id})" {useId} />
|
|
74
|
+
<g style:clip-path={url} class={layerClass('clip-path-g')}>
|
|
75
|
+
{@render children({ id, url, useId })}
|
|
31
76
|
</g>
|
|
32
77
|
{/if}
|
|
33
78
|
{/if}
|