konva | HTML5 Canvas JavaScript framework | Graphics library

 by   konvajs TypeScript Version: 9.3.6 License: Non-SPDX

kandi X-RAY | konva Summary

kandi X-RAY | konva Summary

konva is a TypeScript library typically used in User Interface, Graphics, React, WebGL applications. konva has no vulnerabilities and it has medium support. However konva has 20 bugs and it has a Non-SPDX License. You can download it from GitHub.

Konva is an HTML5 Canvas JavaScript framework that enables high performance animations, transitions, node nesting, layering, filtering, caching, event handling for desktop and mobile applications, and much more. You can draw things onto the stage, add event listeners to them, move them, scale them, and rotate them independently from other shapes to support high performance animations, even if your application uses thousands of shapes. Served hot with a side of awesomeness. This repository began as a GitHub fork of ericdrowell/KineticJS.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              konva has a medium active ecosystem.
              It has 9395 star(s) with 812 fork(s). There are 166 watchers for this library.
              There were 8 major release(s) in the last 6 months.
              There are 71 open issues and 1184 have been closed. On average issues are closed in 19 days. There are 4 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of konva is 9.3.6

            kandi-Quality Quality

              konva has 20 bugs (0 blocker, 0 critical, 20 major, 0 minor) and 2 code smells.

            kandi-Security Security

              konva has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              konva code analysis shows 0 unresolved vulnerabilities.
              There are 7 security hotspots that need review.

            kandi-License License

              konva has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              konva releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.
              konva saves you 377 person hours of effort in developing the same functionality from scratch.
              It has 899 lines of code, 0 functions and 141 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed konva and discovered the below as its top functions. This is intended to give you an instant insight into konva implemented functionality, and help decide if they suit your requirements.
            • Filters a Gaussian blur .
            • Returns anchor name
            • Creates a smoothed edge mask .
            • Generate a mask .
            • Creates a background mask based on the background data .
            • Creates a mask .
            • Generate a number valid numbers array
            • Returns a number that is valid number
            • Returns the pixel ratio of the device .
            • Add child nodes to the array .
            Get all kandi verified functions for this library.

            konva Key Features

            No Key Features are available at this moment for konva.

            konva Examples and Code Snippets

            How to handle with images (overflow, draggable area, etc) on Konva js stage?
            JavaScriptdot img1Lines of Code : 116dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            // this data gives the position and size of the frame
            let data = {
              frameGroup: { x: 50, y: 100, width: 800, height: 300, strokeWidth: 10, stroke: 'cyan'},
              fadeImage: {opacity: 0.3}
            }
            
            // add a stage
            let stage = new Konva.Stage({contain
            Can't suppress Konva warnings in Vue
            JavaScriptdot img2Lines of Code : 10dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import Konva from 'konva';
            Konva.showWarnings = false;
            
            import VueKonva from "vue-konva";
            import Konva from "konva";
            Konva.showWarnings = false;
            
            Vue.use(VueKonva);
            Vue.use(Konva);
            
            display shapes where user clicks in react konva
            JavaScriptdot img3Lines of Code : 58dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import React, { Component } from "react";
            import Konva from "konva";
            import { render } from "react-dom";
            import { Stage, Layer, Rect, Text } from "react-konva";
            
            class App extends Component {
              state = {
                cursor: {
                  x: null,
                  
            Calculate degrees of Linear Gradient in Canvas using Konva with React?
            JavaScriptdot img4Lines of Code : 66dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import { Stage, Layer, Rect } from "react-konva"
            
            // linear-gradient(140deg, rgba(165, 142, 251, 1), rgb(233, 191, 248))
            export default function App() {
                const width = window.innerWidth / 1.25 // random width
                const height = window.i
            copy iconCopy
            import { observer } from "mobx-react";
            
            class KonvaComponent extends React.Component {
              // ..
            }
            
            export const Konva = observer(KonvaComponent)
            
            import { observer } from "mobx-react";
            
            @observer
            export class Konva e
            Use Mobx Store's value in React Class Component?
            JavaScriptdot img6Lines of Code : 13dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            export class Konva extends React.Component {
              // ...
            
              static contextType = FrameItContext;
              context!: React.ContextType;
            
              render() {
                const { win } = this.context;
            
                // ...
              }
            }
            
            Rotate a group of shapes containing text whilst keeping text centered and horizontal
            JavaScriptdot img7Lines of Code : 243dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
              // This is the important call ! Cross is the rotation point as illustrated by crosshairs.
              rotateAroundPoint(shape, rotateBy, {x: cross.x(), y: cross.y()});
              
              // The label is a special case because we need to keep the text unrotated.
            Konva.js: [Free drawing & Drag & Zoom] Can't draw correctly with pointer after Drag or Zoom
            JavaScriptdot img8Lines of Code : 176dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            function getRelativePointerPosition(node) {
              // the function will return pointer position relative to the passed node
              var transform = node.getAbsoluteTransform().copy();
              // to detect relative position we need to invert transform
              tra
            How to Upload and load image in Konvajs canvas?
            JavaScriptdot img9Lines of Code : 53dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            // Create the stage and a layer to draw on.
            var stage = new Konva.Stage({
              container: 'canvas-container',
              width: 650,
              height: 300
            });
            
            var layer = new Konva.Layer();
            stage.add(layer);
            stage.draw();
            
            // listen for the file i
            How to connect 2 objects using a line using konvajs in vuejs?
            JavaScriptdot img10Lines of Code : 104dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            
              
                
                  
                    
                    
                    
                  
                  
                
              
            
            
            
            

            Community Discussions

            QUESTION

            How to set a custom Size to exporting image in react-konva?
            Asked 2022-Mar-31 at 12:02

            I have created a responsive stage using react-konva, but I cannot find a way to set a custom size to export the image. usually, right-click and saving the image is working as the size in the window at that time has. I wanted to add a button to download the image, but I couldn't set up a way to do that because I'm new to react hooks, I couldn't find a way to set up the data URL. please kindly refer to this

            ...

            ANSWER

            Answered 2022-Mar-31 at 12:02

            You need to use a ref to the Stage and get the image URL and download it.

            1. In your Canvas component create a ref using createRef.

            Source https://stackoverflow.com/questions/71633768

            QUESTION

            How to handle with images (overflow, draggable area, etc) on Konva js stage?
            Asked 2022-Mar-25 at 10:32

            I am trying to create a stage using konva.js. Basically, I need to add two (at least) or more images on the stage based on some layouts.

            Example:

            I have a layout that splits the stage area verically into two similar groups. Each group has one image.

            Example code:

            ...

            ANSWER

            Answered 2022-Mar-25 at 10:32

            So the way to achieve this is to have a rect defining the frame in which the image will be constrained. Put this into a group and set the clip region of the group to match the position and size of the frame rect. Now add the image to the group. Only the part of the image in the group will be visible.

            As a bonus, if you add a dragBoundFunc to the group you can ensure that an oversized image cannot be dragged beyond frame edges.

            See snippet below (best run full-screen) and editable CodePen here.

            This is, of course, only a single image frame where you have described that you will have say two in your use case. I suggest that you unravel the code then make a class, then you can use as many as required, etc.

            Source https://stackoverflow.com/questions/71479508

            QUESTION

            How to detect a collision between an Image and a Text object using Konva JS
            Asked 2022-Jan-24 at 17:56

            I am trying to build a simple app in which the user drags a word onto the corresponding image. When the user "drops" the word on the image a collision needs to be detected. I have a console.log message which should only log when this happens. Currently my message is logging even when there is no collision. Any ideas where I'm going wrong? Here is my code:

            ...

            ANSWER

            Answered 2022-Jan-24 at 17:56

            First issue: The second parameter you pass to haveIntersection is imgLayer, which is a Konva.Layer obect. Since a layer is the same size as the stage I assume this is always going to return true.

            Second issue: Your haveIntersection() function expects object parameters with x, y, width & height. Passing in Konva objects here/like this is bad practice because they do not have those attributes. This is the case with Konva.Text which has simple neither width not height attrs.

            For x you would refer to shape.x(), width would be shape.width(), etc. You can sometimes get away with passing shape.getAttrs() which provides a plain JS object containing such attrs, but even that is likely to fail as some shapes such as Konva.Image do not have the width or height attrs in the result of getAttrs(). It turns out that Konva.Rect and Konva.Image do have them, meanwhile Konva.text() does not, so you should not rely on this.

            Instead, you should be explicit and pass in a defined object (see snippet code). It pays to be clear about what you intend - libs can add or remove defaults and behaviours over time and if it 'had' worked your code would still have been a possible time bomb.

            As a bonus: A useful technique for case where you have multiple objects to check for collision is to use the stage,find() function. Give the drop-target objects a common name attr and you can search for such objects via stage.find('.name_to_find'). In the snippet I assign the name 'dropimage' to the rects (in replacement for image object so as to avoid image fetching issues here). Then you can iterate the found objects and run the collision detection, etc.

            Lastly, you are using two layers in the code. Each layer has a processing overhead and whilst using multiple layers is a legitimate technique, you should consider whether you need two layers in this simple case. A single layer would do fine.

            Source https://stackoverflow.com/questions/70812820

            QUESTION

            Konva React image not displaying
            Asked 2022-Jan-22 at 21:03

            I have a very simple Konva-react app (I've taken it right out of the docs) and it doesn't work (doesn't display the image) displaying two warnings:

            1. Warning: is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.
            2. Warning: The tag is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter. My Canvas component:
            ...

            ANSWER

            Answered 2022-Jan-22 at 21:03

            You can't simply render Konva components anywhere. You need to create the and a component first, and only then add your component:

            Source https://stackoverflow.com/questions/70816870

            QUESTION

            Creating a custom shape in konva.js using path2d?
            Asked 2021-Nov-15 at 16:25

            Using d3 for some shape calculations, then drawing with Konva.js. Creating a new shape from a svg path string. The shape is drawn, but fillStrokeShape doesn't seem to apply any styles.

            The documentions says:

            We can use the renderer to access the HTML5 Canvas context, and to use special methods like context.fillStrokeShape(shape) which automatically handles filling, stroking, and applying shadows.

            I am guessing this is the case because the path gets drawn using stroke() or fill().

            ...

            ANSWER

            Answered 2021-Nov-15 at 16:25

            See docs of konvajs:

            https://konvajs.org/docs/shapes/Path.html https://konvajs.org/docs/shapes/Custom.html

            I think Path2D is not needed.

            Insert your res in Konva.Path.data

            Source https://stackoverflow.com/questions/69976933

            QUESTION

            Konvajs/Vue-konva add Text/Label to each of the created Rect shape
            Asked 2021-Nov-08 at 17:05

            I am using Konvajs/Vue-Konva within my Vuejs/Nuxt application. Using Konva I am creating the Rect shape dynamically at run time. I would like to know if there is a way to add a Text/Label within each of the shapes. I want to add a name to each of Shape so as to identify each of the Shape separately.

            I have added my code sample here in CodeSandBox.

            Can someone please let me know how can I add the Text/Label to each of the Rect/Shape that has been created using Vue-Konva

            ...

            ANSWER

            Answered 2021-Nov-08 at 17:05

            You can use Konva.Group to organize several shapes into structures.

            Source https://stackoverflow.com/questions/69855544

            QUESTION

            Vue-konva running into error: Must use import to load ES Module
            Asked 2021-Nov-04 at 07:20

            I am trying to implement the Vue-konva into my application by following the documentation here. But I am running into the following error:

            ...

            ANSWER

            Answered 2021-Nov-04 at 07:20

            This one should work fine

            Source https://stackoverflow.com/questions/69811607

            QUESTION

            Using konva on a nodejs backend without konva-node
            Asked 2021-Oct-01 at 16:28

            We are a team of 5 developers working on a video rendering implementation. This implementation consists out of two parts.

            1. A live video preview in the browser using angular + konva.
            2. A node.js (node 14) serverless (AWS lambda container) implementation using konva-node that pipes frames to ffmpeg for rendering a mp4 video in higher quality for later download.

            Both ways are working for us. Now we extracted the parts of the animation that are the same for frontend and backend implementation to an internal library. We imported them in BE and FE. That also works nicely for most parts.

            We noticed here that konva-node is deprecated since a short time. Documentation says to use canvas + konva instead on node.js. But this just doesn't work. If we don't use konva-node we cannot create a stage without a 'container' value. Also we cannot create a raw image buffer anymore, because stage.toCanvas() actually returns a HTMLCanvas, which does not have this functionality.

            • So what does konva-node actually do to konva API?
            • Is node.js still supported after deprecation of konva-node?
            • How can we get toBuffer() and new Stage() functionality without konva-node in node.js?
            backend (konva-node) ...

            ANSWER

            Answered 2021-Sep-27 at 21:36

            So what does konva-node actually do to konva API?

            It slightly patches Konva code to use canvas nodejs library to use 2d canvas API. So, Konva will not use browser DOM API.

            Is node.js still supported after deprecation of konva-node?

            Yes. https://github.com/konvajs/konva#4-nodejs-env

            How can we get toBuffer() and new Stage() functionality without konva-node in node.js?

            You can try to use this:

            Source https://stackoverflow.com/questions/69226326

            QUESTION

            Konva/Canvas Background Blur / Frosted Glass effect
            Asked 2021-Sep-20 at 18:01

            I'm using Konva/Canvas to draw multiple semi-transparent rectangles z-ordered. At the moment, this looks like the right side of the following image.

            Now, I want to achieve something which is called "Frosted Glass Effect" / "Background Blur" which you can see on the left. The idea is that overlapping parts of the rectangles below a semi transparent rectangle will be blurred.

            How to do this in Konva or with plain Canvas?

            ...

            ANSWER

            Answered 2021-Sep-20 at 18:01

            It may be very hard to get this effect using 2D canvas API.

            If you have static shapes, you can try to "cut and copy" a part that you want to blur and apply the effect just on it.

            Another possible solution is to use backdrop-filter from CSS and draw rectangle div over canvas and apply this filter on it, it will blur part of canvas content.

            On the demo, you can try to drag red square to see how "cut and paste" is working.

            And blue square is working in combination of div with CSS filters.

            Source https://stackoverflow.com/questions/69233406

            QUESTION

            Adding zoom to a packed circle visualisation using Konva (Scale and reposition from center)
            Asked 2021-Sep-17 at 14:14

            I'm created a packed circle visualisation using d3 and drawing it using Konva. If you click on a circle within the packed circle visualisation, the viewport should zoom to that circle.

            Each circle has an event handler attached, which gets called on a click event. There I am calculating the value by which to scale the whole visualisation by, and the values by which to reposition the visualisation by.

            I can't quite seem to get the repositioning values correct. The circle on which the click event occurs should be centered in the viewport after scaling it.

            ...

            ANSWER

            Answered 2021-Sep-17 at 14:14

            The task is one of moving the stage position (x, y) so that the center of the target circle is in the middle of the viewport - meaning the HTML canvas element visible bounds.

            PosX = (viewPort.width / 2) - (circle.pos.x * scale) PosY = (viewPort.height/ 2) - (circle.pos.y * scale)

            And using your code that means:

            Source https://stackoverflow.com/questions/69220889

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install konva

            Add DOM definitions into your tsconfig.json:.

            Support

            Konva works in all modern mobile and desktop browsers. A browser need to be capable to run javascript code from ES2015 spec. For older browsers you may need polyfills for missing functions. At the current moment Konva doesn't work in IE11 directly. To make it work you just need to provide some polyfills such as Array.prototype.find, String.prototype.trimLeft, String.prototype.trimRight, Array.from.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i konva

          • CLONE
          • HTTPS

            https://github.com/konvajs/konva.git

          • CLI

            gh repo clone konvajs/konva

          • sshUrl

            git@github.com:konvajs/konva.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link