{"license":"MIT","name":"react-konva","description":"React binding to canvas element via Konva framework","version":"18.1.0-0","keywords":["react","canvas","jsx","konva"],"bugs":{"url":"https://github.com/konvajs/react-konva/issues"},"main":"lib/ReactKonva.js","module":"es/ReactKonva.js","repository":{"type":"git","url":"git+ssh://git@github.com/konvajs/react-konva.git"},"dependencies":{"react-reconciler":"~0.28.0","scheduler":"^0.22.0"},"targets":{"none":{}},"funding":[{"type":"patreon","url":"https://www.patreon.com/lavrton"},{"type":"opencollective","url":"https://opencollective.com/konva"},{"type":"github","url":"https://github.com/sponsors/lavrton"}],"peerDependencies":{"konva":"^8.0.1 || ^7.2.5","react":">=18.0.0","react-dom":">=18.0.0"},"devDependencies":{"@types/chai":"^4.3.1","@types/mocha":"^9.1.1","@types/react":"18.0.8","chai":"4.3.6","konva":"^8.3.5","mocha-headless-chrome":"^4.0.0","parcel":"^2.5.0","process":"^0.11.10","react":"^18.1.0","react-dom":"^18.1.0","sinon":"^13.0.2","typescript":"^4.6.4","use-image":"^1.0.12","util":"^0.12.4"},"scripts":{"build":" tsc -outDir ./es &&  tsc -module commonjs -outDir ./lib && cp ./ReactKonvaCore.d.ts ./lib && cp ./ReactKonvaCore.d.ts ./es","test:typings":"tsc --noEmit","preversion":"npm test","version":"npm run build","postversion":"","test":"npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security && npm run test:typings","test:build":"parcel build ./test/unit-tests.html --dist-dir test-build --target none --public-url ./ --no-source-maps","test:watch":"rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html"},"typings":"react-konva.d.ts","readme":"# React Konva\n\n[![Build Status](https://travis-ci.org/konvajs/react-konva.svg?branch=master)](https://travis-ci.org/konvajs/react-konva) [![Greenkeeper badge](https://badges.greenkeeper.io/konvajs/react-konva.svg)](https://greenkeeper.io/)\n\n![ReactKonva Logo](https://cloud.githubusercontent.com/assets/1443320/12193428/3bda2fcc-b623-11e5-8319-b1ccfc95eaec.png)\n\nReact Konva is a JavaScript library for drawing complex canvas graphics using\n[React](http://facebook.github.io/react/).\n\nIt provides declarative and reactive bindings to the\n[Konva Framework](http://konvajs.github.io/).\n\n# [OPEN DEMO](https://codesandbox.io/s/5m3nwp787x)\n\nAn attempt to make [React](http://facebook.github.io/react/) work with the HTML5\ncanvas library. The goal is to have similar declarative markup as normal React\nand to have similar data-flow model.\n\n**At the current moment, `react-konva` is not supported in React Native environment.**\n\nCurrently you can use all `Konva` components as React components and all `Konva`\nevents are supported on them in same way as normal browser events are supported.\n\n## Installation\n\n```bash\nnpm install react-konva konva --save\n```\n\n## [Tutorials and Documentation](https://konvajs.github.io/docs/react/)\n\n## Example\n\n```javascript\nimport React, { Component } from 'react';\nimport { render } from 'react-dom';\nimport { Stage, Layer, Rect, Text } from 'react-konva';\nimport Konva from 'konva';\n\nclass ColoredRect extends React.Component {\n  state = {\n    color: 'green'\n  };\n  handleClick = () => {\n    this.setState({\n      color: Konva.Util.getRandomColor()\n    });\n  };\n  render() {\n    return (\n      <Rect\n        x={20}\n        y={20}\n        width={50}\n        height={50}\n        fill={this.state.color}\n        shadowBlur={5}\n        onClick={this.handleClick}\n      />\n    );\n  }\n}\n\nclass App extends Component {\n  render() {\n    // Stage is a div container\n    // Layer is actual canvas element (so you may have several canvases in the stage)\n    // And then we have canvas shapes inside the Layer\n    return (\n      <Stage width={window.innerWidth} height={window.innerHeight}>\n        <Layer>\n          <Text text=\"Try click on rect\" />\n          <ColoredRect />\n        </Layer>\n      </Stage>\n    );\n  }\n}\n\nrender(<App />, document.getElementById('root'));\n```\n\nTo get more info about `Konva` you can read\n[Konva Overview](http://konvajs.github.io/docs/overview.html).\n\n**Actually you don't need to learn `react-konva`. Just learn `Konva` framework, you will understand how to use `react-konva`**\n\n## Core API\n\n`react-konva` supports all shapes, that `Konva` supports with the same names, and also it supports all the same events like `click`, `touchmove`, `dragend`, etc with \"on\" prefix like `onClick`, `onTouchMove`, `onDragEnd`.\n\n### Getting reference to Konva objects\n\nTo get reference of `Konva` instance of a node you can use `ref` property.\n\n```javascript\nclass MyShape extends React.Component {\n  componentDidMount() {\n    // log Konva.Circle instance\n    console.log(this.circle);\n  }\n  render() {\n    return <Circle ref={ref => (this.circle = ref)} radius={50} fill=\"black\" />;\n  }\n}\n```\n\n### Strict mode\n\nBy default `react-konva` works in \"non-strict\" mode. If you changed a property **manually** (or by user action like `drag&drop`) properties of the node will be not matched with properties from `render()`. `react-konva` updates ONLY properties changed in `render()`.\n\nIn strict mode `react-konva` will update all properties of the nodes to the values that you provided in `render()` function, no matter changed they or not.\n\nYou should decide what mode is better in your actual use case.\n\nTo enable strict mode globally you can do this:\n\n```javascript\nimport { useStrictMode } from 'react-konva';\n\nuseStrictMode(true);\n```\n\nOr you can enable it only for some components:\n\n```javascript\n<Rect width={50} height={50} fill=\"black\" _useStrictMode />\n```\n\nTake a look into this example:\n\n```javascript\nimport { Circle } from 'react-konva';\nimport Konva from 'konva';\n\nconst Shape = () => {\n  const [color, setColor] = React.useState();\n\n  return (\n    <Circle\n      x={0}\n      y={0}\n      draggable\n      radius={50}\n      fill={color}\n      onDragEnd={() => {\n        setColor(Konva.Util.getRandomColor());\n      }}\n    />\n  );\n};\n```\n\nThe circle is `draggable` and it changes its color on `dragend` event. In `strict` mode position of the node will be reset back to `{x: 0, y: 0}` (as we defined in render). But in `non-strict` mode the circle will keep its position, because `x` and `y` are not changed in render.\n\n### Minimal bundle\n\nBy default `react-konva` imports full `Konva` version. With all the shapes and all filters. To minimize bundle size you can use minimal core version of `react-konva`:\n\n```javascript\n// load minimal version of 'react-konva`\nimport { Stage, Layer, Rect } from \"react-konva/lib/ReactKonvaCore\";\n\n// minimal version has NO support for core shapes and filters\n// if you want import a shape into Konva namespace you can just do this:\nimport \"konva/lib/shapes/Rect\";\n```\n\nDemo: [https://codesandbox.io/s/6l97wny44z](https://codesandbox.io/s/6l97wny44z)\n\n### Usage with React Context\nDue to a [known issue](https://github.com/facebook/react/issues/13336) with React, Contexts are not accessible by children of the react-konva `Stage` component. If you need to subscribe to a context from within the `Stage`, you need to \"bridge\" the context by creating a `Provider` as a child of the `Stage`. For more info, see [this discussion](https://github.com/konvajs/react-konva/issues/188#issuecomment-478302062) and this [react-redux demo](https://github.com/konvajs/react-konva/issues/311#issuecomment-454411007). Here is an example of bridging the context ([live demo](https://codesandbox.io/s/ykqw8r4r21)):\n```js\nimport React, { Component } from \"react\";\nimport Konva from \"konva\";\nimport { render } from \"react-dom\";\nimport { Stage, Layer, Rect } from \"react-konva\";\n\nconst ThemeContext = React.createContext(\"red\");\n\nconst ThemedRect = () => {\n  const value = React.useContext(ThemeContext);\n  return (\n    <Rect x={20} y={50} width={100} height={100} fill={value} shadowBlur={10} />\n  );\n};\n\nconst Canvas = () => {\n  return (\n    <ThemeContext.Consumer>\n      {value => (\n        <Stage width={window.innerWidth} height={window.innerHeight}>\n          <ThemeContext.Provider value={value}>\n            <Layer>\n              <ThemedRect />\n            </Layer>\n          </ThemeContext.Provider>\n        </Stage>\n      )}\n    </ThemeContext.Consumer>\n  );\n};\n\nclass App extends Component {\n  render() {\n    return (\n      <ThemeContext.Provider value=\"blue\">\n        <Canvas />\n      </ThemeContext.Provider>\n    );\n  }\n}\n```\n\n## Comparisons\n\n### react-konva vs react-canvas\n\n[react-canvas](https://github.com/Flipboard/react-canvas) is a completely\ndifferent react plugin. It allows you to draw DOM-like objects (images, texts)\non canvas element in very performant way. It is NOT about drawing graphics, but\nreact-konva is exactly for drawing complex graphics on `<canvas>` element from\nReact.\n\n### react-konva vs react-art\n\n[react-art](https://github.com/reactjs/react-art) allows you to draw graphics on\na page. It also supports SVG for output. But it has no support of events of\nshapes.\n\n### react-konva vs vanilla canvas\n\nVanilla canvas is faster because when you use `react-konva` you have two layers of abstractions. Konva framework is on top of canvas and React is on top of Konva.\nDepending on the use case this approach can be slow.\nThe purpose of `react-konva` is to reduce the complexity of the application and use well-known declarative way for drawing on canvas.\n\n## [CHANGELOG](https://github.com/konvajs/react-konva/releases)\n\n\n**Note: you can find a lot of demos and examples of using Konva there:\n[http://konvajs.github.io/](http://konvajs.github.io/). Really, just go there and take a look what Konva can do for you. You will be able to do the same with `react-konva` too.**\n\n\n","readmeFilename":"README.md","gitHead":"75378821acfa95227d4a09428fafd3421263d43a","homepage":"https://github.com/konvajs/react-konva#readme","_id":"react-konva@18.1.0-0","_nodeVersion":"16.10.0","_npmVersion":"7.24.0","dist":{"integrity":"sha512-XWld/J2PkTnYq2qAKuF/iIOGJv7o5Q1Z0jngG++BhwHW0BcnoNgToP/Z6hUj/pvWIJKbd5Ka8t7bSdEY35nWuA==","shasum":"8900f9efbcadb70e0a3ea43c06f293600e97faf9","tarball":"http://registry-npm.ywwl.com/react-konva/download/react-konva-18.1.0-0.tgz","fileCount":15,"unpackedSize":57654,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDj7xGGWuYHIkw6qY0RNAPOS3nfC+8jCvYQ8gb8QUIXOgIhAPHBYeWAOVmyPMC98r5vbVxp0Wsjl+pMLLEaj9fwZD0i"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJikN9YACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqTUA/9ElgJ0Q/Lpfu2KhbcpCHoEs1yIm7InqbEuBJSfR0xmax83AEq\r\nNW7Nudkiv3zp3JmljfE7r/1ihdq0wOPq2gmaemWlEnwM+t2foUuC3TcxFh9m\r\n+GRaHW1Mmvbb1GmCdyv3SyVS/N4JuXFZ50j8g7ZHnWJqfYl18ur1C6w9kId9\r\nllTqNCypy4AEehXeBzgd20jauKhFp5GhBTr1o9X5B8Yc4vHXDvfTtwWZD8Uk\r\nDa4TeEKaPX1NhxO2JBAaTDigRg+nSzXI3pW+fGQKBWOvFolVpJ3kpbJI/7Fu\r\n3tkq8PrCb+BJwkbCbeIy/4VykKduIKzCeMAsDwXoJwzFTmy6t670ZbRzVUHd\r\nJKfmSQS8TBen+bSKGr/r0RzuJKJT1u+UF0dM6c/Xyc9KczidY9GRyHCfaNfH\r\nS5XZjlq4C6Sh/xxfuJmKZz+jFkNdhWNQr/mfjns89Hvk0yQ+niW2rvBbAuBs\r\nCn9h11FV9iQVsOidwm+8zEHao/CUonmH8HaMweLZRs8FxGvDNRJGQ+7IrLju\r\nOvfIDr69z50/I+hUNkax6bmMZndVgfGr53JeD4Lf+1rAebwghglHQdzLNEjY\r\nmK6LDnUGBgf98wnk/UdU5y8yBVAHWf6wwohBYO6eaKDw8SpkG1DneMfiMyuN\r\nDR+khuJmZWFnrU5L3DBQPMyFYyYhrHFQwK0=\r\n=fbj1\r\n-----END PGP SIGNATURE-----\r\n","size":11573,"noattachment":false,"key":"/react-konva/-/react-konva-18.1.0-0.tgz"},"_npmUser":{"name":"lavrton","email":"lavrton@gmail.com"},"directories":{},"maintainers":[{"name":"lavrton","email":"lavrton@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-konva_18.1.0-0_1653661528759_0.23136633470340162"},"_hasShrinkwrap":false,"publish_time":1653661528900,"_cnpm_publish_time":1653661528900,"dist-tags":{"beta":"19.0.0-1","latest":"19.3.2","legacy":"18.2.16","next":"19.2.0-3"}}