{"name":"react-konva","description":"React binding to canvas element via Konva framework","version":"1.5.7-beta","keywords":["react","canvas","jsx","konva"],"bugs":{"url":"https://github.com/lavrton/react-konva/issues"},"licenses":"BSD-3-Clause","main":"react-konva.js","repository":{"type":"git","url":"git+ssh://git@github.com/lavrton/react-konva.git"},"dependencies":{"fbjs":"^0.8.14","react-reconciler":"^0.2.0"},"peerDependencies":{"react":"~16.0.0","konva":"^1.6.3","react-dom":"~16.0.0"},"devDependencies":{"babel-cli":"^6.26.0","babel-core":"^6.25.0","babel-loader":"^7.1.1","babel-preset-es2015":"^6.24.1","babel-preset-react":"^6.24.1","babel-register":"^6.24.1","chai":"^4.1.0","enzyme":"^3.1.0","enzyme-adapter-react-16":"^1.0.3","jsdom":"^11.1.0","konva":"^1.6.3","mocha":"^4.0.1","mocha-headless-chrome":"^1.5.0","react":"^16.1.0-beta","react-dom":"^16.1.0-beta","react-test-renderer":"^16.1.0-beta","sinon":"^4.1.1","webpack":"^3.4.1","webpack-dev-server":"^2.6.1"},"scripts":{"test:compile":"webpack --config ./webpack/webpack.test.config.js --progress --profile --colors","test:run":"mocha-headless-chrome -f test/index.html","test:clean":"rm ./test/tests.bundle.js","test:watch":"webpack-dev-server --config ./webpack/webpack.test.config.js --progress --profile --colors","test":"npm run test:compile && npm run test:run && npm run test:clean","build":"webpack --config ./webpack/webpack.dist.config.js --progress --profile --colors","bundle":"webpack --config ./webpack/webpack.bundle.config.js --progress --profile --colors"},"typings":"react-konva.d.ts","files":["README.md","react-konva.js","react-konva.d.ts"],"gitHead":"bfebc12e4d728b9d4c543fd927e3f801bfeeae98","homepage":"https://github.com/lavrton/react-konva#readme","_id":"react-konva@1.5.7-beta","_npmVersion":"5.5.1","_nodeVersion":"8.4.0","_npmUser":{"name":"lavrton","email":"lavrton@gmail.com"},"dist":{"integrity":"sha512-SWS+pUWXtbpHoXrtWUmC35YOsfXFhAqgLcdicX0E/NMcJpCaWoD+G0tGYTa//7s1I7JYKZPwdZ/AqYs8KaBCSw==","shasum":"e3f71bf2f7b04b2c1255d20b52a3628501688e2a","tarball":"http://registry-npm.ywwl.com/react-konva/download/react-konva-1.5.7-beta.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCXC9aDbp59beoffpPcNfv2uoJTVGy47ofGwk6O68YhyAIgWODJzAsbzlVIQyHZx11rcX3dsr0W50fUZiQQRB+jJb8="}],"size":12173,"noattachment":false,"key":"/react-konva/-/react-konva-1.5.7-beta.tgz"},"maintainers":[{"name":"lavrton","email":"lavrton@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-konva-1.5.7-beta.tgz_1510035542317_0.9206528216600418"},"directories":{},"readme":"<p align=\"center\">\n  <img src=\"https://konvajs.org/img/icon.png\" alt=\"Konva logo\" height=\"60\" />\n</p>\n\n# React Konva\n\n[![Financial Contributors on Open Collective](https://opencollective.com/konva/all/badge.svg?label=financial+contributors)](https://opencollective.com/konva)\n[![npm version](https://badge.fury.io/js/react-konva.svg)](http://badge.fury.io/js/react-konva)\n[![Build Status](https://github.com/konvajs/react-konva/actions/workflows/test.yml/badge.svg)](https://github.com/konvajs/react-konva/actions/workflows/test.yml)\n\nReact Konva provides declarative React components for the [Konva](https://konvajs.org/) 2D canvas scene graph. Use it to build design editors, whiteboards, diagrams, annotations, and other interactive graphics.\n\nReact Konva is MIT licensed. It supports Konva shapes and events. It does not support React Native.\n\n- [React tutorial](https://konvajs.org/docs/react/index.html)\n- [Live demos](https://konvajs.org/docs/sandbox.html)\n- [Konva API](https://konvajs.org/api/Konva.html)\n- [Star the project](https://github.com/konvajs/react-konva)\n\n[![A Konva Transformer around a selected image](https://konvajs.org/assets/demos/image-resize-min.png)](https://konvajs.org/docs/react/Transformer.html)\n\n## Install\n\nReact Konva 19.3 requires React and React DOM `^19.3.0`.\nFor React 19.2, install the latest React Konva 19.2 release.\nFor React 18, install the latest React Konva 18 release.\n\n```bash\nnpm install react-konva konva\n```\n\n## Quick example\n\n```javascript\nimport {useState} from 'react';\nimport {Stage, Layer, Rect} from 'react-konva';\n\nexport default function App() {\n  const [color, setColor] = useState('#00a8e8');\n  return (\n    <Stage width={600} height={400}>\n      <Layer>\n        <Rect\n          x={50} y={50} width={120} height={80}\n          fill={color} draggable\n          onClick={() => setColor(color === '#00a8e8' ? '#ff7a00' : '#00a8e8')}\n        />\n      </Layer>\n    </Stage>\n  );\n}\n```\n\n> **Building a full design editor?** [Polotno](https://polotno.com/?utm_source=konvajs&utm_medium=readme&utm_content=react-konva) is a commercial design editor SDK built on Konva by the Konva maintainers. It ships templates, text editing, and export, so you integrate an editor instead of building one: `npm install polotno`.\n\nTo get more info about `Konva` you can read\n[Konva Overview](https://konvajs.org/docs/overview.html).\n\n`react-konva` follows the Konva API. Learn the Konva scene graph, properties, and events before you add framework-specific patterns.\n\n## Core API\n\n`react-konva` supports Konva shapes with the same names. Event props use React names such as `onClick`, `onTouchMove`, and `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\nimport React, { useEffect, useRef } from 'react';\n\nconst MyShape = () => {\n  const circleRef = useRef();\n\n  useEffect(() => {\n    // log Konva.Circle instance\n    console.log(circleRef.current);\n  }, []);\n\n  return <Circle ref={circleRef} radius={50} fill=\"black\" />;\n};\n```\n\n### React features inside Stage\n\n`useActionState` and `useOptimistic` work inside a `Stage`.\nFragments group Konva children, but Fragment refs remain `null` because the\ncanvas renderer has no DOM Fragment instance.\n\n`ViewTransition` is not supported inside a `Stage`.\nTo animate the Stage's DOM container, place `ViewTransition` around `Stage` in\nthe React DOM tree. Individual Konva shapes have no DOM elements for view transitions.\n\n`useFormStatus` reads the surrounding DOM form's status inside `Stage`.\nPlace error boundaries inside `Stage` and use Konva elements for their fallbacks.\nUncaught canvas errors appear in the console with the error and component stack.\nDOM error boundaries around `Stage` do not catch errors from canvas children.\n\nPlace `Suspense` inside `Stage` to show a Konva fallback for canvas children.\nFor a DOM loading indicator, read the promise in a component above `Stage`.\nThe DOM and canvas use separate React roots, so their Suspense boundaries and\ntransition pending states do not propagate between roots.\n\nActivity and Suspense around `Stage` preserve canvas component state when they\nhide and reveal an existing Stage. An initially hidden Stage creates its canvas\non the first reveal.\n\nReact's `StrictMode` also enables development checks inside `Stage`.\nFor hook coverage and renderer limits, see the [React compatibility matrix](docs/react-compatibility.md).\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 Next.js\n\nKonva 10+ works with Next.js without extra canvas setup. Use a\n[Client Component](https://nextjs.org/docs/app/api-reference/directives/use-client) (`'use client'`).\n\nKonva 9 and earlier need extra setup, such as installing `canvas` or\n[disabling SSR](https://nextjs.org/docs/app/guides/lazy-loading#skipping-ssr) for the canvas component.\n\n### Usage with React Context\n\nComponents inside `Stage` receive React contexts from its parent tree automatically. This behavior is available since `react-konva@18.2.2`.\n\n```jsx\nimport React from 'react';\nimport { Stage, Layer, Rect } from 'react-konva';\n\nconst ThemeContext = React.createContext('red');\n\nfunction ThemedRect() {\n  const fill = React.useContext(ThemeContext);\n  return <Rect width={100} height={100} fill={fill} />;\n}\n\nfunction App() {\n  return (\n    <ThemeContext.Provider value=\"blue\">\n      <Stage width={300} height={200}>\n        <Layer>\n          <ThemedRect />\n        </Layer>\n      </Stage>\n    </ThemeContext.Provider>\n  );\n}\n```\n\n## Event synchronization\n\nWith Konva 10.5+, native input batches ordinary React state updates per Konva\nlistener and commits them before that listener returns, keeping DOM and canvas in sync.\nThis includes drag and transform events. To batch MobX reactions too, pass `runInAction`:\n\n```tsx\nimport { runInAction } from 'mobx';\n\n<Stage eventBatchFunc={runInAction} width={600} height={400}>\n  {/* Existing layers, shapes, and handlers */}\n</Stage>\n```\n\nThe wrapper must call its callback exactly once, synchronously. Older Konva versions\nuse normal React scheduling and ignore this prop. See the [release notes](RELEASE_NOTES.md)\nfor performance and compatibility details.\n\n## Development and tests\n\nRun `npm install` and `npx playwright install chromium` before the tests.\n\n- `npm test` runs browser tests with development and production React, performance counts, package builds, server rendering, and TypeScript checks.\n- `BROWSER=firefox npm test` and `BROWSER=webkit npm test` select other installed Playwright browsers.\n- `npm run test:performance` runs commit and calculation limits with production profiling builds.\n- `npm run test:ssr` checks all built entry points without a DOM or native canvas backend, including imports when the optional event hook is absent.\n- `npm run test:typings` checks the source and consumer examples.\n- `npm run bench:events -- HEAD` compares elapsed interaction time against a commit. See [the benchmark guide](https://github.com/konvajs/react-konva/blob/master/benchmarks/README.md).\n\nAll tests use the latest published Konva. Compatibility tests disable its optional\nhook; they do not install historical versions. CI runs the full suite in Chromium,\nFirefox, and WebKit. A separate job checks minimum React with latest Konva.\nRun development, production, and\nprofiling suites sequentially because they share Vite's dependency cache.\n\nAll interaction regressions run in the regular suite. There is no separate\nexpected-failure command.\n\n## [CHANGELOG](https://github.com/konvajs/react-konva/releases)\n\nSee the [Konva demos](https://konvajs.org/docs/sandbox.html) for more complete examples.\n","publish_time":1510035542431,"_cnpm_publish_time":1510035542431,"dist-tags":{"beta":"19.0.0-1","latest":"19.3.2","legacy":"18.2.16","next":"19.2.0-3"}}