`.
### Props
- `width` (number) - The width of the canvas.
- `height` (number) - The height of the canvas.
- `bind:this` - Binds the Konva.Stage instance to a variable.
- `onclick` - Callback for stage click events.
- `divWrapperProps` (object) - Props to be applied to the wrapper `
`.
### Example
```svelte
```
```
--------------------------------
### Accessing Konva Node with bind:this
Source: https://github.com/konvajs/svelte-konva/blob/master/docs/svelte-konva-v1-migration.md
Access the underlying Konva node using `bind:this` on the component and accessing the `node` property. The `handle` prop has been removed and renamed to `node`.
```diff
```
--------------------------------
### Layer Component
Source: https://context7.com/konvajs/svelte-konva/llms.txt
The `Layer` component represents a drawing layer within the `Stage`. It must be a direct child of `Stage` and supports bindable transform props like `x`, `y`, `rotation`, etc.
```APIDOC
## Layer Component
### Description
The `Layer` component is a drawing layer that must be a direct child of `Stage`. Multiple layers can be used for z-ordering. It supports bindable transform props.
### Props
- `bind:this` - Binds the Konva.Layer instance to a variable.
- `x` (number) - X position of the layer.
- `y` (number) - Y position of the layer.
- `scaleX` (number) - X scale of the layer.
- `scaleY` (number) - Y scale of the layer.
- `rotation` (number) - Rotation of the layer in degrees.
- `skewX` (number) - Skew on the X axis.
- `skewY` (number) - Skew on the Y axis.
### Example
```svelte
```
```
--------------------------------
### Rect Component
Source: https://context7.com/konvajs/svelte-konva/llms.txt
The `Rect` component renders a rectangle shape on the canvas. It accepts all `Konva.Rect` configuration properties as Svelte props and supports bindable transform properties.
```APIDOC
## Rect Component
### Description
Renders a rectangle shape. Accepts all `Konva.Rect` config props and supports bindable transform props.
### Props
- `x` (number) - X position of the rectangle.
- `y` (number) - Y position of the rectangle.
- `width` (number) - Width of the rectangle.
- `height` (number) - Height of the rectangle.
- `fill` (string) - Fill color of the rectangle.
- `stroke` (string) - Stroke color of the rectangle.
- `strokeWidth` (number) - Stroke width of the rectangle.
- `cornerRadius` (number) - Corner radius of the rectangle.
- `draggable` (boolean) - Enables dragging of the rectangle.
- `shadowBlur` (number) - Blur radius of the shadow.
- `shadowColor` (string) - Color of the shadow.
- `ondragend` - Callback for drag end event.
- `bind:x` - Binds the x position.
- `bind:y` - Binds the y position.
### Example
```svelte
console.log('Drag ended', e.target.x())}
/>
```
```
--------------------------------
### Draw Directed Arrows with Arrow in Svelte Konva
Source: https://context7.com/konvajs/svelte-konva/llms.txt
The `Arrow` component uses `points` similar to `Line`, with configurable `pointerLength`, `pointerWidth`, and `pointerAtBeginning` for double-headed arrows.
```svelte
```
--------------------------------
### Disable Automatic Prop Synchronization with `staticConfig`
Source: https://context7.com/konvajs/svelte-konva/llms.txt
Pass `staticConfig` to disable automatic synchronization of bindable props with Konva's internal state on `dragend` and `transformend`. This reduces Svelte reactivity overhead.
```svelte
```
--------------------------------
### Importing and Using Konva Event Types in svelte-konva
Source: https://context7.com/konvajs/svelte-konva/llms.txt
Import Konva event types for precise event handling in your Svelte components. Use KonvaEventHooks to type props for custom wrapper components, ensuring type safety for event callbacks.
```typescript
import type {
KonvaMouseEvent,
KonvaWheelEvent,
KonvaTouchEvent,
KonvaPointerEvent,
KonvaDragTransformEvent,
KonvaEventHooks
} from 'svelte-konva';
// KonvaEventHooks can be used to type a props object for a custom wrapper component
type MyShapeProps = {
x: number;
y: number;
} & KonvaEventHooks;
```
--------------------------------
### Update Config Prop to Individual Props in svelte-konva
Source: https://github.com/konvajs/svelte-konva/blob/master/docs/svelte-konva-v1-migration.md
Migrate from using a single `config` object to individual props for Konva node properties. This change aligns with react-konva's approach.
```html
```
--------------------------------
### Draggable Rectangle with Bound Position in Svelte
Source: https://context7.com/konvajs/svelte-konva/llms.txt
Shows how to create a draggable Rect component in svelte-konva. The x and y properties of the rectangle are bound to Svelte state variables, allowing for two-way data binding. The dragend event is logged to the console.
```svelte
console.log('Drag ended', e.target.x())}
/>
```
--------------------------------
### Pass Props to Wrapper Div in Svelte Konva
Source: https://github.com/konvajs/svelte-konva/blob/master/docs/svelte-konva-v1-migration.md
Use the `divWrapperProps` prop on the `Stage` component to pass attributes like `id` and `class` to the wrapper div. This replaces the previous method of using rest props.
```svelte
```
--------------------------------
### Handle Konva Events with Typed Callbacks
Source: https://context7.com/konvajs/svelte-konva/llms.txt
Use typed `on
` props for all svelte-konva components. The payload is the raw `KonvaEventObject`. Event bubbling can be cancelled by setting `e.cancelBubble = true`.
```svelte
add(`Enter ${e.target.getType()}`)}
onmouseleave={(e: KonvaMouseEvent) => add(`Leave`)}
onclick={(e: KonvaMouseEvent) => add(`Click at ${e.evt.clientX},${e.evt.clientY}`)}
ondblclick={(e: KonvaMouseEvent) => add(`Double-click`)}
ondragstart={(e: KonvaDragTransformEvent) => add(`Drag start`)}
ondragend={(e: KonvaDragTransformEvent) => { add(`Drag end x=${e.target.x().toFixed(0)}`); }}
oncontextmenu={(e: KonvaPointerEvent) => { e.evt.preventDefault(); add('Context menu'); }}
/>
add(`Touch start`)}
ontouchend={(e: KonvaTouchEvent) => add(`Touch end`)}
onpointerclick={(e: KonvaPointerEvent) => {
e.cancelBubble = true; // stop bubbling to Stage
add('Pointer click (bubble stopped)');
}}
/>
{#each log as entry}- {entry}
{/each}
```
--------------------------------
### Cancel Event Bubbling in svelte-konva
Source: https://github.com/konvajs/svelte-konva/blob/master/docs/svelte-konva-v1-migration.md
To cancel event bubbling, set `e.cancelBubble = true` on the event payload. `e.preventDefault()` is no longer supported for this purpose.
```diff
function handleClick(e) {
window.alert(`Clicked on rectangle: ${e.type}`);
- e.preventDefault();
+ e.cancelBubble = true;
}
```
--------------------------------
### Accessing Underlying Konva Node
Source: https://github.com/konvajs/svelte-konva/blob/master/README.md
Access the underlying Konva node of a svelte-konva component using the `node` property. This is useful for direct manipulation or serialization.
```svelte
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.