layerchart 2.0.0-next.15 → 2.0.0-next.17

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 (33) hide show
  1. package/dist/components/Arc.svelte +2 -2
  2. package/dist/components/Blur.svelte +5 -3
  3. package/dist/components/Blur.svelte.d.ts +2 -5
  4. package/dist/components/Connector.svelte +2 -2
  5. package/dist/components/Connector.svelte.d.ts +1 -1
  6. package/dist/components/Ellipse.svelte +187 -0
  7. package/dist/components/Ellipse.svelte.d.ts +64 -0
  8. package/dist/components/ForceSimulation.svelte +122 -38
  9. package/dist/components/ForceSimulation.svelte.d.ts +58 -23
  10. package/dist/components/GeoPath.svelte +5 -4
  11. package/dist/components/GeoPoint.svelte +1 -2
  12. package/dist/components/GeoSpline.svelte +4 -4
  13. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  14. package/dist/components/MonthPath.svelte +11 -8
  15. package/dist/components/MonthPath.svelte.d.ts +4 -3
  16. package/dist/components/Polygon.svelte +285 -0
  17. package/dist/components/Polygon.svelte.d.ts +115 -0
  18. package/dist/components/Spline.svelte +29 -17
  19. package/dist/components/Spline.svelte.d.ts +12 -4
  20. package/dist/components/Treemap.svelte +63 -26
  21. package/dist/components/Treemap.svelte.d.ts +11 -11
  22. package/dist/components/index.d.ts +4 -0
  23. package/dist/components/index.js +4 -0
  24. package/dist/components/layout/Layer.svelte +6 -4
  25. package/dist/components/layout/Layer.svelte.d.ts +6 -4
  26. package/dist/components/tooltip/TooltipList.svelte +1 -1
  27. package/dist/utils/canvas.js +15 -0
  28. package/dist/utils/path.d.ts +10 -0
  29. package/dist/utils/path.js +30 -0
  30. package/dist/utils/shape.d.ts +43 -0
  31. package/dist/utils/shape.js +59 -0
  32. package/dist/utils/treemap.d.ts +1 -1
  33. package/package.json +1 -1
@@ -1,24 +1,63 @@
1
1
  import { type Force, type Simulation, type SimulationLinkDatum, type SimulationNodeDatum } from 'd3-force';
2
2
  import type { Snippet } from 'svelte';
3
- type Forces = Record<string, Force<any, any>>;
3
+ export type Forces<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = Record<string, Force<NodeDatum, LinkDatum>>;
4
4
  export type Data<TNode = any, TLink = any> = {
5
5
  nodes: TNode[];
6
6
  links?: TLink[];
7
7
  };
8
- export type LinkPosition = Prettify<{
8
+ export type LinkPosition = {
9
9
  x1: number;
10
10
  y1: number;
11
11
  x2: number;
12
12
  y2: number;
13
- }>;
14
- type NodeDatumFor<NodeDatum> = Prettify<NodeDatum & SimulationNodeDatum>;
15
- type LinkDatumFor<NodeDatum, LinkDatum> = Prettify<LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>>;
13
+ };
14
+ export type OnStartEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
15
+ alpha: number;
16
+ alphaTarget: number;
17
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
18
+ };
19
+ export type OnTickEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
20
+ alpha: number;
21
+ alphaTarget: number;
22
+ nodes: NodeDatumFor<NodeDatum>[];
23
+ links: LinkDatumFor<NodeDatum, LinkDatum>[];
24
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
25
+ };
26
+ export type OnEndEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
27
+ alpha: number;
28
+ alphaTarget: number;
29
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
30
+ };
31
+ /**
32
+ * Default initial alpha value of the simulation.
33
+ */
34
+ export declare const DEFAULT_ALPHA: number;
35
+ /**
36
+ * Default target alpha value for the simulation.
37
+ */
38
+ export declare const DEFAULT_ALPHA_TARGET: number;
39
+ /**
40
+ * Default alpha decay rate per tick.
41
+ *
42
+ * Formula: `1 - Math.pow(0.001, 1 / 300)`.
43
+ */
44
+ export declare const DEFAULT_ALPHA_DECAY: number;
45
+ /**
46
+ * Default minimum alpha value at which simulation stops.
47
+ */
48
+ export declare const DEFAULT_ALPHA_MIN: number;
49
+ /**
50
+ * Default velocity decay factor applied to nodes each tick.
51
+ */
52
+ export declare const DEFAULT_VELOCITY_DECAY: number;
53
+ type NodeDatumFor<NodeDatum> = NodeDatum & SimulationNodeDatum;
54
+ type LinkDatumFor<NodeDatum, LinkDatum> = LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>;
16
55
  type SimulationFor<NodeDatum, LinkDatum> = Simulation<NodeDatumFor<NodeDatum>, LinkDatumFor<NodeDatum, LinkDatum>>;
17
- export type ForceSimulationProps<NodeDatum, LinkDatum> = {
56
+ export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
18
57
  /**
19
58
  * Force simulation parameters
20
59
  */
21
- forces: Forces;
60
+ forces: Forces<NodeDatum, LinkDatum>;
22
61
  /**
23
62
  * An object with arrays of nodes and links,
24
63
  * to be used for position calculation.
@@ -26,27 +65,27 @@ export type ForceSimulationProps<NodeDatum, LinkDatum> = {
26
65
  data: Data<NodeDatum, LinkDatum>;
27
66
  /**
28
67
  * Current alpha value of the simulation
29
- * @default 1
68
+ * @default DEFAULT_ALPHA
30
69
  */
31
70
  alpha?: number;
32
71
  /**
33
72
  * Target alpha value for the simulation
34
- * @default 0
73
+ * @default DEFAULT_ALPHA_TARGET
35
74
  */
36
75
  alphaTarget?: number;
37
76
  /**
38
77
  * Alpha decay rate per tick
39
- * @default 1 - Math.pow(0.001, 1 / 300)
78
+ * @default DEFAULT_ALPHA_DECAY
40
79
  */
41
80
  alphaDecay?: number;
42
81
  /**
43
82
  * Minimum alpha value at which simulation stops
44
- * @default 0.01
83
+ * @default DEFAULT_ALPHA_MIN
45
84
  */
46
85
  alphaMin?: number;
47
86
  /**
48
87
  * Velocity decay factor applied to nodes each tick
49
- * @default 0.4
88
+ * @default DEFAULT_VELOCITY_DECAY
50
89
  */
51
90
  velocityDecay?: number;
52
91
  /**
@@ -67,18 +106,15 @@ export type ForceSimulationProps<NodeDatum, LinkDatum> = {
67
106
  /**
68
107
  * Callback function triggered when simulation starts
69
108
  */
70
- onStart?: () => void;
109
+ onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
71
110
  /**
72
111
  * Callback function triggered on each simulation tick
73
112
  */
74
- onTick?: (e: {
75
- alpha: number;
76
- alphaTarget: number;
77
- }) => void;
113
+ onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
78
114
  /**
79
115
  * Callback function triggered when simulation ends
80
116
  */
81
- onEnd?: () => void;
117
+ onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
82
118
  children?: Snippet<[
83
119
  {
84
120
  nodes: NodeDatumFor<NodeDatum>[];
@@ -88,8 +124,7 @@ export type ForceSimulationProps<NodeDatum, LinkDatum> = {
88
124
  }
89
125
  ]>;
90
126
  };
91
- import type { Prettify } from '@layerstack/utils';
92
- declare class __sveltets_Render<NodeDatum, LinkDatum = undefined> {
127
+ declare class __sveltets_Render<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
93
128
  props(): ForceSimulationProps<NodeDatum, LinkDatum>;
94
129
  events(): {};
95
130
  slots(): {};
@@ -97,12 +132,12 @@ declare class __sveltets_Render<NodeDatum, LinkDatum = undefined> {
97
132
  exports(): {};
98
133
  }
99
134
  interface $$IsomorphicComponent {
100
- new <NodeDatum, LinkDatum = undefined>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['events']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['slots']>> & {
135
+ new <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['events']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['slots']>> & {
101
136
  $$bindings?: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['bindings']>;
102
137
  } & ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
103
- <NodeDatum, LinkDatum = undefined>(internal: unknown, props: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']> & {}): ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
138
+ <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(internal: unknown, props: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']> & {}): ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
104
139
  z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
105
140
  }
106
141
  declare const ForceSimulation: $$IsomorphicComponent;
107
- type ForceSimulation<NodeDatum, LinkDatum = undefined> = InstanceType<typeof ForceSimulation<NodeDatum, LinkDatum>>;
142
+ type ForceSimulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = InstanceType<typeof ForceSimulation<NodeDatum, LinkDatum>>;
108
143
  export default ForceSimulation;
@@ -157,10 +157,11 @@
157
157
  name: 'GeoPath',
158
158
  render,
159
159
  events: {
160
- click: _onClick,
161
- pointerenter: _onPointerEnter,
162
- pointermove: _onPointerMove,
163
- pointerleave: _onPointerLeave,
160
+ // Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
161
+ click: onclick ? _onClick : undefined,
162
+ pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
163
+ pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
164
+ pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
164
165
  pointerdown: restProps.onpointerdown,
165
166
  touchmove: restProps.ontouchmove,
166
167
  },
@@ -1,7 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from 'svelte';
3
- import type { SVGAttributes } from 'svelte/elements';
4
- import Circle, { type CircleProps, type CirclePropsWithoutHTML } from './Circle.svelte';
3
+ import Circle, { type CircleProps } from './Circle.svelte';
5
4
  import type { Without } from '../utils/types.js';
6
5
 
7
6
  export type GeoPointPropsWithoutHTML = {
@@ -42,13 +42,13 @@
42
42
  link,
43
43
  loft = 1.0,
44
44
  curve = curveNatural,
45
- splineRef: splineRefProp = $bindable(),
45
+ pathRef: pathRefProp = $bindable(),
46
46
  ...restProps
47
47
  }: GeoSplineProps = $props();
48
48
 
49
- let splineRef = $state<SVGPathElement>();
49
+ let pathRef = $state<SVGPathElement>();
50
50
  $effect.pre(() => {
51
- splineRefProp = splineRef;
51
+ pathRefProp = pathRef;
52
52
  });
53
53
 
54
54
  const geoCtx = getGeoContext();
@@ -76,7 +76,7 @@
76
76
  </script>
77
77
 
78
78
  <Spline
79
- bind:splineRef
79
+ bind:pathRef
80
80
  data={[source, middle, target]}
81
81
  x={(d) => d[0]}
82
82
  y={(d) => d[1]}
@@ -27,6 +27,6 @@ export type GeoSplinePropsWithoutHTML = {
27
27
  curve?: CurveFactory | CurveFactoryLineOnly;
28
28
  };
29
29
  export type GeoSplineProps = GeoSplinePropsWithoutHTML & Without<SplineProps, GeoSplinePropsWithoutHTML>;
30
- declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "splineRef">;
30
+ declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "pathRef">;
31
31
  type GeoSpline = ReturnType<typeof GeoSpline>;
32
32
  export default GeoSpline;
@@ -20,11 +20,13 @@
20
20
  *
21
21
  * @bindable
22
22
  */
23
- ref?: SVGPathElement;
23
+ pathRef?: SVGPathElement;
24
24
  };
25
25
 
26
26
  export type MonthPathProps = MonthPathPropsWithoutHTML &
27
- Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML>;
27
+ // we omit the spline props to avoid conflicts with attribute names since we are
28
+ // passing them through to `<Spline />`
29
+ Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML & SplinePropsWithoutHTML>;
28
30
  </script>
29
31
 
30
32
  <script lang="ts">
@@ -32,18 +34,19 @@
32
34
  import { endOfMonth } from 'date-fns';
33
35
  import { cls } from '@layerstack/tailwind';
34
36
  import { layerClass } from '../utils/attributes.js';
37
+ import Spline, { type SplinePropsWithoutHTML } from './Spline.svelte';
35
38
 
36
39
  let {
37
40
  date,
38
41
  cellSize: cellSizeProp,
39
- ref: refProp = $bindable(),
42
+ pathRef: pathRefProp = $bindable(),
40
43
  class: className,
41
44
  ...restProps
42
45
  }: MonthPathProps = $props();
43
46
 
44
- let ref = $state<SVGPathElement>();
47
+ let pathRef = $state<SVGPathElement>();
45
48
  $effect.pre(() => {
46
- refProp = ref;
49
+ pathRefProp = pathRef;
47
50
  });
48
51
 
49
52
  const cellSize = $derived(
@@ -68,9 +71,9 @@
68
71
  `);
69
72
  </script>
70
73
 
71
- <path
72
- bind:this={ref}
73
- d={pathData}
74
+ <Spline
75
+ bind:pathRef
76
+ {pathData}
74
77
  fill="none"
75
78
  class={cls(layerClass('month-path'), 'stroke-surface-content/20', className)}
76
79
  {...restProps}
@@ -16,9 +16,10 @@ export type MonthPathPropsWithoutHTML = {
16
16
  *
17
17
  * @bindable
18
18
  */
19
- ref?: SVGPathElement;
19
+ pathRef?: SVGPathElement;
20
20
  };
21
- export type MonthPathProps = MonthPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML>;
22
- declare const MonthPath: import("svelte").Component<MonthPathProps, {}, "ref">;
21
+ export type MonthPathProps = MonthPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML & SplinePropsWithoutHTML>;
22
+ import { type SplinePropsWithoutHTML } from './Spline.svelte';
23
+ declare const MonthPath: import("svelte").Component<MonthPathProps, {}, "pathRef">;
23
24
  type MonthPath = ReturnType<typeof MonthPath>;
24
25
  export default MonthPath;
@@ -0,0 +1,285 @@
1
+ <script lang="ts" module>
2
+ import type { CommonStyleProps, Without } from '../utils/types.js';
3
+
4
+ export type PolygonPropsWithoutHTML = {
5
+ /**
6
+ * The center x position of the polygon.
7
+ *
8
+ * @default 0
9
+ */
10
+ cx?: number;
11
+
12
+ /**
13
+ * The initial center x position of the polygon.
14
+ *
15
+ * @default cx
16
+ */
17
+ initialCx?: number;
18
+
19
+ /**
20
+ * The center y position of the polygon.
21
+ *
22
+ * @default 0
23
+ */
24
+ cy?: number;
25
+
26
+ /**
27
+ * The initial center y position of the polygon.
28
+ *
29
+ * @default cy
30
+ */
31
+ initialCy?: number;
32
+
33
+ /**
34
+ * The radius of the polygon.
35
+ *
36
+ * @default 1
37
+ */
38
+ r?: number;
39
+
40
+ /**
41
+ * The initial radius of the polygon.
42
+ *
43
+ * @default r
44
+ */
45
+ initialR?: number;
46
+
47
+ /**
48
+ * The number of points or explicit points to create the polygon.
49
+ *
50
+ * @default 4
51
+ */
52
+ points?: number | { x: number; y: number }[];
53
+
54
+ /**
55
+ * The radius of the curve for rounded corners.
56
+ *
57
+ * @default 0
58
+ */
59
+ cornerRadius?: number;
60
+
61
+ /**
62
+ * The rotation of the polygon.
63
+ *
64
+ * @default 0
65
+ */
66
+ rotate?: number;
67
+
68
+ /**
69
+ * The percent to inset the odd points of the star (<1 inset, >1 outset)
70
+ *
71
+ * @default 0
72
+ */
73
+ inset?: number;
74
+
75
+ /**
76
+ * The horizontal stretch factor of the polygon.
77
+ *
78
+ * @default 1
79
+ */
80
+ scaleX?: number;
81
+
82
+ /**
83
+ * The vertical stretch factor of the polygon.
84
+ *
85
+ * @default 1
86
+ */
87
+ scaleY?: number;
88
+
89
+ /**
90
+ * The skew angle in degrees along the X axis.
91
+ *
92
+ * @default 0
93
+ */
94
+ skewX?: number;
95
+
96
+ /**
97
+ * The skew angle in degrees along the Y axis.
98
+ *
99
+ * @default 0
100
+ */
101
+ skewY?: number;
102
+
103
+ /**
104
+ * The tilt factor for x-coordinates.
105
+ *
106
+ * @default 1
107
+ */
108
+ tiltX?: number;
109
+
110
+ /**
111
+ * The tilt factor for y-coordinates.
112
+ *
113
+ * @default 1
114
+ */
115
+ tiltY?: number;
116
+
117
+ /**
118
+ * A bindable reference to the `<path>` element
119
+ *
120
+ * @bindable
121
+ */
122
+ ref?: SVGPathElement;
123
+
124
+ motion?: MotionProp;
125
+ } & CommonStyleProps;
126
+
127
+ export type PolygonProps = PolygonPropsWithoutHTML &
128
+ Without<SVGAttributes<Element>, PolygonPropsWithoutHTML>;
129
+ </script>
130
+
131
+ <script lang="ts">
132
+ import type { SVGAttributes } from 'svelte/elements';
133
+ import { cls } from '@layerstack/tailwind';
134
+ import { merge } from 'lodash-es';
135
+ import { interpolatePath } from 'd3-interpolate-path';
136
+
137
+ import { getRenderContext } from './Chart.svelte';
138
+ import {
139
+ createMotion,
140
+ extractTweenConfig,
141
+ type MotionProp,
142
+ type ResolvedMotion,
143
+ } from '../utils/motion.svelte.js';
144
+ import { registerCanvasComponent } from './layout/Canvas.svelte';
145
+ import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
146
+ import { createKey } from '../utils/key.svelte.js';
147
+ import { layerClass } from '../utils/attributes.js';
148
+ import { polygon } from '../utils/shape.js';
149
+ import { roundedPolygonPath } from '../utils/path.js';
150
+
151
+ let {
152
+ cx = 0,
153
+ initialCx: initialCxProp,
154
+ cy = 0,
155
+ initialCy: initialCyProp,
156
+ r = 1,
157
+ initialR: initialRProp,
158
+ points = 4,
159
+ cornerRadius = 0,
160
+ rotate = 0,
161
+ inset = 0,
162
+ scaleX = 1,
163
+ scaleY = 1,
164
+ skewX = 0,
165
+ skewY = 0,
166
+ tiltX = 0,
167
+ tiltY = 0,
168
+ motion,
169
+ fill,
170
+ fillOpacity,
171
+ stroke,
172
+ strokeWidth,
173
+ opacity,
174
+ class: className,
175
+ ref: refProp = $bindable(),
176
+ ...restProps
177
+ }: PolygonProps = $props();
178
+
179
+ let ref = $state<SVGPathElement>();
180
+
181
+ $effect.pre(() => {
182
+ refProp = ref;
183
+ });
184
+
185
+ const initialCx = initialCxProp ?? cx;
186
+ const initialCy = initialCyProp ?? cy;
187
+ const initialR = initialRProp ?? r;
188
+
189
+ const motionCx = createMotion(initialCx, () => cx, motion);
190
+ const motionCy = createMotion(initialCy, () => cy, motion);
191
+ const motionR = createMotion(initialR, () => r, motion);
192
+
193
+ let polygonPoints = $derived(
194
+ typeof points === 'number'
195
+ ? polygon({
196
+ cx: motionCx.current,
197
+ cy: motionCy.current,
198
+ count: points,
199
+ radius: motionR.current,
200
+ rotate,
201
+ inset,
202
+ scaleX,
203
+ scaleY,
204
+ skewX,
205
+ skewY,
206
+ tiltX,
207
+ tiltY,
208
+ })
209
+ : points
210
+ );
211
+ let d = $derived(roundedPolygonPath(polygonPoints, cornerRadius));
212
+
213
+ const extractedTween = extractTweenConfig(motion);
214
+
215
+ const tweenedOptions: ResolvedMotion | undefined = extractedTween
216
+ ? {
217
+ type: extractedTween.type,
218
+ options: { interpolate: interpolatePath, ...extractedTween.options },
219
+ }
220
+ : undefined;
221
+
222
+ const tweenedState = createMotion(null, () => d, tweenedOptions);
223
+
224
+ const renderCtx = getRenderContext();
225
+
226
+ function render(
227
+ ctx: CanvasRenderingContext2D,
228
+ styleOverrides: ComputedStylesOptions | undefined
229
+ ) {
230
+ renderPathData(
231
+ ctx,
232
+ tweenedState.current,
233
+ styleOverrides
234
+ ? merge({ styles: { strokeWidth } }, styleOverrides)
235
+ : {
236
+ styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
237
+ classes: cls(layerClass('polygon'), fill == null && 'fill-surface-content', className),
238
+ }
239
+ );
240
+ }
241
+
242
+ // TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
243
+ const fillKey = createKey(() => fill);
244
+ const strokeKey = createKey(() => stroke);
245
+
246
+ if (renderCtx === 'canvas') {
247
+ registerCanvasComponent({
248
+ name: 'Polygon',
249
+ render,
250
+ events: {
251
+ click: restProps.onclick,
252
+ pointerenter: restProps.onpointerenter,
253
+ pointermove: restProps.onpointermove,
254
+ pointerleave: restProps.onpointerleave,
255
+ pointerdown: restProps.onpointerdown,
256
+ pointerover: restProps.onpointerover,
257
+ pointerout: restProps.onpointerout,
258
+ touchmove: restProps.ontouchmove,
259
+ },
260
+ deps: () => [
261
+ fillKey.current,
262
+ fillOpacity,
263
+ strokeKey.current,
264
+ strokeWidth,
265
+ opacity,
266
+ className,
267
+ tweenedState.current,
268
+ ],
269
+ });
270
+ }
271
+ </script>
272
+
273
+ {#if renderCtx === 'svg'}
274
+ <path
275
+ d={tweenedState.current}
276
+ {fill}
277
+ fill-opacity={fillOpacity}
278
+ {stroke}
279
+ stroke-width={strokeWidth}
280
+ {opacity}
281
+ class={cls(layerClass('polygon'), fill == null && 'fill-surface-content', className)}
282
+ {...restProps}
283
+ bind:this={ref}
284
+ />
285
+ {/if}
@@ -0,0 +1,115 @@
1
+ import type { CommonStyleProps, Without } from '../utils/types.js';
2
+ export type PolygonPropsWithoutHTML = {
3
+ /**
4
+ * The center x position of the polygon.
5
+ *
6
+ * @default 0
7
+ */
8
+ cx?: number;
9
+ /**
10
+ * The initial center x position of the polygon.
11
+ *
12
+ * @default cx
13
+ */
14
+ initialCx?: number;
15
+ /**
16
+ * The center y position of the polygon.
17
+ *
18
+ * @default 0
19
+ */
20
+ cy?: number;
21
+ /**
22
+ * The initial center y position of the polygon.
23
+ *
24
+ * @default cy
25
+ */
26
+ initialCy?: number;
27
+ /**
28
+ * The radius of the polygon.
29
+ *
30
+ * @default 1
31
+ */
32
+ r?: number;
33
+ /**
34
+ * The initial radius of the polygon.
35
+ *
36
+ * @default r
37
+ */
38
+ initialR?: number;
39
+ /**
40
+ * The number of points or explicit points to create the polygon.
41
+ *
42
+ * @default 4
43
+ */
44
+ points?: number | {
45
+ x: number;
46
+ y: number;
47
+ }[];
48
+ /**
49
+ * The radius of the curve for rounded corners.
50
+ *
51
+ * @default 0
52
+ */
53
+ cornerRadius?: number;
54
+ /**
55
+ * The rotation of the polygon.
56
+ *
57
+ * @default 0
58
+ */
59
+ rotate?: number;
60
+ /**
61
+ * The percent to inset the odd points of the star (<1 inset, >1 outset)
62
+ *
63
+ * @default 0
64
+ */
65
+ inset?: number;
66
+ /**
67
+ * The horizontal stretch factor of the polygon.
68
+ *
69
+ * @default 1
70
+ */
71
+ scaleX?: number;
72
+ /**
73
+ * The vertical stretch factor of the polygon.
74
+ *
75
+ * @default 1
76
+ */
77
+ scaleY?: number;
78
+ /**
79
+ * The skew angle in degrees along the X axis.
80
+ *
81
+ * @default 0
82
+ */
83
+ skewX?: number;
84
+ /**
85
+ * The skew angle in degrees along the Y axis.
86
+ *
87
+ * @default 0
88
+ */
89
+ skewY?: number;
90
+ /**
91
+ * The tilt factor for x-coordinates.
92
+ *
93
+ * @default 1
94
+ */
95
+ tiltX?: number;
96
+ /**
97
+ * The tilt factor for y-coordinates.
98
+ *
99
+ * @default 1
100
+ */
101
+ tiltY?: number;
102
+ /**
103
+ * A bindable reference to the `<path>` element
104
+ *
105
+ * @bindable
106
+ */
107
+ ref?: SVGPathElement;
108
+ motion?: MotionProp;
109
+ } & CommonStyleProps;
110
+ export type PolygonProps = PolygonPropsWithoutHTML & Without<SVGAttributes<Element>, PolygonPropsWithoutHTML>;
111
+ import type { SVGAttributes } from 'svelte/elements';
112
+ import { type MotionProp } from '../utils/motion.svelte.js';
113
+ declare const Polygon: import("svelte").Component<PolygonProps, {}, "ref">;
114
+ type Polygon = ReturnType<typeof Polygon>;
115
+ export default Polygon;