├── .babelrc ├── .gitignore ├── LICENSE.md ├── README.md ├── dist ├── index.cjs.js └── index.esm.js ├── example.png ├── index.js ├── lib ├── components │ ├── layer.js │ └── stage.js ├── contexts │ └── stage.js ├── shapes │ ├── abstract-shape.js │ ├── arc.js │ ├── circle.js │ ├── image.js │ ├── label.js │ ├── polygon.js │ ├── rectangle.js │ ├── rounded-rectangle.js │ ├── sector.js │ └── text-field.js └── tasks │ ├── arc.js │ ├── common.js │ ├── image.js │ ├── polygon.js │ ├── rectangle.js │ ├── sector.js │ └── text.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── sandbox ├── .babelrc ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ └── index.html ├── src │ ├── examples │ │ ├── Basic.js │ │ ├── PanAndZoom.js │ │ ├── StopEventPropagation.js │ │ └── TextField.js │ ├── index.js │ └── styles │ │ └── App.css └── webpack.config.js └── utils ├── cache.js ├── canvas.js ├── color-incrementer.js ├── distance.js ├── dom.js ├── memoize.js ├── rate-limit.js └── string.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/env", "@babel/preset-react"] 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | .DS_Store -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Claudijo Borovic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React 2D Canvas 2 | 3 | Draw 2D shapes, images and text on an HTML Canvas element using a declarative JSX syntax. The library builds on top of custom elements from the [Web Components standard](https://developer.mozilla.org/en-US/docs/Web/Web_Components). 4 | 5 | React 2D Canvas makes it easy to create simple 2D canvas games by leveraging on the developer ergonomics that [React](https://reactjs.org/) offers. 6 | 7 | React 2D Canvas is lightweight with focus on efficiently producing 2D drawings. Features such as audio, hit detection and animation are not built in. Users of React 2D Canvas are encouraged to incorporate suitable libraries to add auxiliary functionality or roll their own custom solutions as needed. 8 | 9 | ## Table of Content 10 | 11 | * [Change Log](#change-log) 12 | * [Example Usage](#example-usage) 13 | * [Browser Support](#browser-support) 14 | * [API](#api) 15 | * [\](#stage) 16 | * [\](#layer) 17 | * [Shape Components](#shape-components) 18 | * [Event Handlers](#event-handlers) 19 | * [Nesting and Inheritance](#nesting-and-inheritance) 20 | * [\](#rectangle) 21 | * [\](#roundedrectangle) 22 | * [\](#circle) 23 | * [\](#arc) 24 | * [\](#sector) 25 | * [\