Git Product home page Git Product logo

svelte-konva's People

Contributors

dependabot[bot] avatar teykey1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

rakataprime

svelte-konva's Issues

Changing order of nodes

I made this demo: https://codesandbox.io/s/festive-germain-1js7yj?file=/App.svelte

In the demo, I am rendering stars from an array. Also I am changing order of stars, to display dragged start on top:

let handleDragStart = e => {
	// save drag element:
	dragItemId = e.detail.target.id();
	// move current element to the top:
	const item = list.find(i => i.id === dragItemId);
	const index = list.indexOf(item);
	list.splice(index, 1);
	list.push(item);
};

But I don't see that on canvas. Does the library support that? Or I am doing something wrong?

Newcomer issues

I have created a new svelte project:

cd my-app
npm install
npm run dev -- --open

Then I installed the svelte-konva and konva libraries.
npm i svelte-konva konva

Then I replaced src/routes/+page.svelte with the code example from the documentation https://konvajs.org/docs/svelte/index.html:

	import { Stage, Layer, Star } from "svelte-konva";

	let width = window.innerWidth;
	let height = window.innerHeight;
	let list = [];
	for (let n = 0; n < 30; n++) {
		list.push({
			id: n.toString(),
			x: Math.random() * width,
			y: Math.random() * height,
			rotation: Math.random() * 180,
			scale: Math.random(),
		});
	}
	let dragItemId = null;

	let handleDragStart = (e) => {
		// save drag element:
		dragItemId = e.detail.target.id();
		// move current element to the top:
		const item = list.find((i) => i.id === dragItemId);
		item.handle.moveToTop();
	};
	let handleDragEnd = (e) => {
		const item = list.find((i) => i.id === dragItemId);
		if (!item) {
			return;
		}
		item.x = e.detail.target.x();
		item.y = e.detail.target.y();
		dragItemId = null;
	};
</script>

<Stage config={{ width, height }}>
	<Layer>
		{#each list as item (item.id)}
			<Star
				config={{
					x: item.x,
					y: item.y,
					rotation: item.rotation,
					id: item.id,
					numPoints: 5,
					innerRadius: 30,
					outerRadius: 50,
					fill: "#89b717",
					opacity: 0.8,
					draggable: true,
					scaleX:
						dragItemId === item.id ? item.scale * 1.2 : item.scale,
					scaleY:
						dragItemId === item.id ? item.scale * 1.2 : item.scale,
					shadowColor: "black",
					shadowBlur: 10,
					shadowOffsetX: dragItemId === item.id ? 15 : 5,
					shadowOffsetY: dragItemId === item.id ? 15 : 5,
					shadowOpacity: 0.6,
				}}
				bind:handle={item.handle}
				on:dragstart={handleDragStart}
				on:dragend={handleDragEnd}
			/>
		{/each}
	</Layer>
</Stage>

This produces the error:

Require stack:
- /Users/een/Repos/lib-svelte-canvas/node_modules/konva/lib/index-node.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
    at Function.Module._load (node:internal/modules/cjs/loader:873:27)
    at Module.require (node:internal/modules/cjs/loader:1100:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (/Users/een/Repos/lib-svelte-canvas/node_modules/konva/lib/index-node.js:4:16)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/een/Repos/lib-svelte-canvas/node_modules/konva/lib/index-node.js'
  ]
}

`TypeError: handle is undefined` when rapidly updating

I am working on a project where I am updating svelte-konva Elements quite frequently.
Sometimes svelte-konva throws the following error.

Uncaught (in promise) TypeError: handle is undefined
    update Circle.svelte:30
    update scheduler.js:115
    flush scheduler.js:79
    promise callback*schedule_update scheduler.js:20
    make_dirty Component.js:81
    ctx Component.js:129
    instance ble-trilateration.svelte:1153
    handleMessage mqtt-client.ts:56
    connect mqtt-client.ts:69
    emit events.js:153
    handlePublish publish.ts:172
    handle index.ts:29
    work client.ts:725
    _write client.ts:749
    writeOrBuffer writable.js:334
    _write writable.js:283
    write writable.js:286
    ondata _stream_readable.js:629
    emit events.js:153
    addChunk _stream_readable.js:279
    readableAddChunk _stream_readable.js:262
    push _stream_readable.js:228
    _forward index.js:172
    onreadable index.js:136
    emit events.js:153
    emitReadable_ readable.js:509
    run browser.js:153
    drainQueue browser.js:123
    setTimeout handler*runTimeout browser.js:41
    nextTick browser.js:143
    emitReadable readable.js:502
    addChunk readable.js:284
    readableAddChunk readable.js:255
    push readable.js:201
    onMessage ws.ts:231

This seems to be caused by handle not always being defined, but nevertheless being used for setting the config attributes when the config changes.
See https://github.com/konvajs/svelte-konva/blob/bf8b5a9e4cea32ba6eb3f453ca4d146d759d9846/src/lib/Circle.svelte#L38C29-L38C29

Unfortunately I cannot provide a minimal reproducible example right now, hopefully later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.