diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 0ad30524d0f..00000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -name: Bug report -about: Create a report with a reproducible test case in a JSFIDDLE, For anything else use the github DISCUSSIONS feature. Anything different than a bug report will be closed automatically. ---- - - - - - - - -## Version - -5.0.0 - - - - -## Test Case - -- [ ] [Browser Issue Template](https://jsfiddle.net/Lcp2h3nv/) -- [ ] [Node Issue Template](https://codesandbox.io/s/exciting-browser-ytb701) - -## Information about environment - -Nodejs or browser? -Which browsers? - -## Steps To Reproduce - -1. - -
Error Message & Stack Trace

- -```txt - -``` - -

- -## Expected Behavior - -## Actual Behavior - - diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000000..e07b26c180c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,131 @@ +name: ๐Ÿ› Bug Report +description: File a bug report +title: '[Bug]: ' +body: + - type: markdown + attributes: + value: > + Thank you for wanting to create an issue in this repository. + + Before you do, please ensure you are filing the issue in the right + place. + + * If you have a question or if an issue is not right for what you mean + to file use + [Discussions](https://github.com/fabricjs/fabric.js/discussions). + - type: checkboxes + id: terms + attributes: + label: CheckList + description: >- + By submitting this issue, you agree to follow our [Code of + Conduct](https://github.com/fabricjs/fabric.js/CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true + - label: >- + I have read and followed the [Contributing + Guide](https://github.com/fabricjs/fabric.js/CONTRIBUTING.md) + required: true + - label: >- + I have read and followed the [Issue Tracker + Guide](https://github.com/fabricjs/fabric.js/CONTRIBUTING.md#%EF%B8%8F-issue-tracker) + required: true + - label: I have searched and referenced existing issues and discussions + required: true + - label: I am filing a **BUG** report. + required: true + - label: >- + I have managed to reproduce the bug **after** upgrading to the + **latest** version + required: true + - label: I have created an accurate and minimal reproduction + required: true + - type: dropdown + id: _version + attributes: + label: Version + description: >- + If you are working on a version below latest you should upgrade to + latest before filing a bug report, your issue might have been resolved + already. + options: + validations: + required: true + - type: dropdown + id: environments + attributes: + label: In What environments are you experiencing the problem? + description: >- + checkout the [supported + browsers](/README.md#supported-browsersenvironments) + multiple: true + options: + - Firefox + - Chrome + - Safari + - Opera + - Microsoft Edge + - Node.js + - type: dropdown + id: _node_version + attributes: + label: Node Version (if applicable) + description: Provide the version if the bug occurs in Node.js + options: + validations: + required: false + - type: input + id: reproduction_link + attributes: + label: Link To Reproduction + description: > + A good reproduction helps us UNDERSTAND your issue, find the bug and fix + it quickly. + + Take the time and put effort into making your reproduction accurate and + minimal. + + Use the following reproduction templates. + + + - [Browser reproduction template](https://jsfiddle.net/Lcp2h3nv/) + + - [Node reproduction + template](https://codesandbox.io/s/exciting-browser-ytb701) + + + โ›” No reproduction === closed issue โ›” + validations: + required: true + - type: textarea + id: steps + attributes: + label: Steps To Reproduce + value: | + 1. + 2. + 3. + validations: + required: true + - type: textarea + id: expected + attributes: + label: Expected Behavior + validations: + required: true + - type: textarea + id: actual + attributes: + label: Actual Behavior + description: Provide screenshots/screencasts if relevant + validations: + required: true + - type: textarea + id: error + attributes: + label: Error Message & Stack Trace + description: Provide logging outputs/errors if relevant + render: bash + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000000..d2ae3c245b1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,13 @@ +# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser + +blank_issues_enabled: false +contact_links: + - name: Discussions + url: ./discussions + about: Please ask and answer questions here. + - name: GOTCHAS + url: http://fabricjs.com/fabric-gotchas + about: Refer to the list of known pitfalls before assuming a bug. + - name: Security + url: ./Security.md + about: Please report security vulnerabilities here. diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 94% rename from .github/PULL_REQUEST_TEMPLATE/pull_request_template.md rename to .github/PULL_REQUEST_TEMPLATE.md index beeb6678313..dffe48d76f2 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,7 +6,7 @@ about: Creating a PR -[![Build Status](https://secure.travis-ci.org/fabricjs/fabric.js.svg?branch=master)](http://travis-ci.org/#!/kangax/fabric.js) -[![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/kangax/fabric.js/badges/gpa.svg)](https://codeclimate.com/github/kangax/fabric.js) -[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/fabricjs/fabric.js) +[![๐Ÿฉบ](../../actions/workflows/build.yml/badge.svg)](../../actions/workflows/build.yml) +[![๐Ÿงช](../../actions/workflows/tests.yml/badge.svg)](../../actions/workflows/tests.yml) +[![CodeQL](../../actions/workflows/codeql-analysis.yml/badge.svg)](../../actions/workflows/codeql-analysis.yml) + +--- -[![CDNJS version](https://img.shields.io/cdnjs/v/fabric.js.svg)](https://cdnjs.com/libraries/fabric.js) -[![NPM version](https://badge.fury.io/js/fabric.svg)](http://badge.fury.io/js/fabric) +[![cdnjs](https://img.shields.io/cdnjs/v/fabric.js.svg)][cdnjs] +[![jsdelivr](https://data.jsdelivr.com/v1/package/npm/fabric/badge)][jsdelivr] +[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/fabricjs/fabric.js) + +[![NPM](https://badge.fury.io/js/fabric.svg)](http://badge.fury.io/js/fabric) [![Downloads per month](https://img.shields.io/npm/dm/fabric.svg)](https://www.npmjs.org/package/fabric) -[![Bower version](https://badge.fury.io/bo/fabric.svg)](http://badge.fury.io/bo/fabric) +[![Bower](https://badge.fury.io/bo/fabric.svg)](http://badge.fury.io/bo/fabric) + +--- + +[![Sponsor asturur](https://img.shields.io/static/v1?label=Sponsor%20asturur&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/asturur) +[![Sponsor melchiar](https://img.shields.io/static/v1?label=Sponsor%20melchiar&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/melchiar) +[![Sponsor ShaMan123](https://img.shields.io/static/v1?label=Sponsor%20ShaMan123&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/ShaMan123) +[![Patreon](https://img.shields.io/static/v1?label=Patreon&message=%F0%9F%91%8D&logo=Patreon&color=blueviolet)](https://www.patreon.com/fabricJS) + +--- ## Features -- drag-n-drop objects on canvas, -- scale, move, rotate and group objects with mouse, -- use predefined shapes or create custom objects, -- works super-fast with many objects, -- supports JPG, PNG, JSON and SVG formats, -- ready-to-use image filters, -- create animations, -- and much more! - -
- -Introduction -  โ€ข   -Docs -  โ€ข   -Demos -  โ€ข   -Kitchensink -  โ€ข   -Benchmarks -  โ€ข   -Contribution -
- -
+- Out of the box interactions such as scale, move, rotate, skew, group... +- Built in shapes, controls, animations, image filters, gradients, patterns, brushes... +- `JPG`, `PNG`, `JSON` and `SVG` i/o +- Typed and modular +- [Unit tested](CONTRIBUTING.md#%F0%9F%A7%AA%20testing) -## Quick Start +#### Supported Browsers/Environments -``` +| Context | Supported Version | Notes | +| :---------: | :---------------: | ------------------------------- | +| Firefox | โœ”๏ธ | modern version (tbd) | +| Safari | โœ”๏ธ | version >= 10.1 | +| Opera | โœ”๏ธ | chromium based | +| Chrome | โœ”๏ธ | modern version (tbd) | +| Edge | โœ”๏ธ | chromium based | +| Edge Legacy | โŒ | +| IE11 | โŒ | +| Node.js | โœ”๏ธ | [Node.js installation](#nodejs) | + +Fabric.js Does not use transpilation by default, the browser version we support is determined by the level of canvas api we want to use and some js syntax. While JS can be easily transpiled, canvas API can't. + +## Installation + +```bash $ npm install fabric --save +// or +$ yarn add fabric ``` -After this, you can import fabric like so: +```js +// es6 imports +import { fabric } from 'fabric'; -``` -const fabric = require("fabric").fabric; +// or cjs +const fabric = require('fabric').fabric; ``` -Or you can use this instead if your build pipeline supports ES6 imports: +#### Browser -``` -import { fabric } from "fabric"; -``` +[![cdnjs](https://img.shields.io/cdnjs/v/fabric.js.svg)][cdnjs] +[![jsdelivr](https://data.jsdelivr.com/v1/package/npm/fabric/badge)][jsdelivr] -NOTE: If you are using Fabric.js in a Node.js script, you will depend on [node-canvas](https://github.com/Automattic/node-canvas). `node-canvas` is an HTML canvas replacement that works on top of native libraries. Please [follow the instructions](https://github.com/Automattic/node-canvas#compiling) to get it up and running. +See [browser modules][mdn_es6] for using es6 imports in the browser or use a dedicated bundler. -NOTE: es6 imports won't work in browser or with bundlers which expect es6 module like vite. Use commonjs syntax instead. +#### Node.js -## Usage +Fabric.js depends on [node-canvas][node_canvas] for a canvas implementation (`HTMLCanvasElement` replacement) and [jsdom][jsdom] for a `window` implementation on node. +This means that you may encounter `node-canvas` limitations and [bugs][node_canvas_issues]. -### Plain HTML +Follow these [instructions][node_canvas_install] to get `node-canvas` up and running. + +## Quick Start + +
Plain HTML ```html - - + ``` -### ReactJS +
+ +
ReactJS ```tsx -import React, {useEffect, useRef} from 'react' -import {fabric} from 'fabric' +import React, { useEffect, useRef } from 'react'; +import { fabric } from 'fabric'; -const FabricJSCanvas = () => { - const canvasEl = useRef(null) +export const FabricJSCanvas = () => { + const canvasEl = useRef(null); useEffect(() => { const options = { ... }; const canvas = new fabric.Canvas(canvasEl.current, options); @@ -105,184 +128,114 @@ const FabricJSCanvas = () => { updateCanvasContext(canvas); return () => { updateCanvasContext(null); - canvas.dispose() + canvas.dispose(); } }, []); return () }); -export default FabricJSCanvas; -``` - -NOTE: Fabric.js requires a `window` object. - -## Building - -1. Build distribution file **[~77K minified, ~20K gzipped]** - - $ node build.js - - 1.1 Or build a custom distribution file, by passing (comma separated) module names to be included. - - $ node build.js modules=text,serialization,parser - // or - $ node build.js modules=text - // or - $ node build.js modules=parser,text - // etc. - - By default (when none of the modules are specified) only basic functionality is included. - See the list of modules below for more information on each one of them. - Note that default distribution has support for **static canvases** only. - - To get minimal distribution with interactivity, make sure to include corresponding module: - - $ node build.js modules=interaction - - 1.2 You can also include all modules like so: - - $ node build.js modules=ALL - - 1.3 You can exclude a few modules like so: - $ node build.js modules=ALL exclude=gestures,image_filters - -2. Create a minified distribution file - - # Using YUICompressor (default option) - $ node build.js modules=... minifier=yui - - # or Google Closure Compiler - $ node build.js modules=... minifier=closure - -3. Enable AMD support via require.js (requires uglify) - - $ node build.js requirejs modules=... - -4. Create source map file for better productive debugging (requires uglify or google closure compiler).
More information about [source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/). - - $ node build.js sourcemap modules=... - - If you use google closure compiler you have to add `sourceMappingURL` manually at the end of the minified file all.min.js (see issue https://code.google.com/p/closure-compiler/issues/detail?id=941). - - //# sourceMappingURL=fabric.min.js.map - -5. Ensure code guidelines are met (prerequisite: `npm -g install eslint`) - - $ npm run lint && npm run lint_tests - -## Testing - -### 1. Install NPM packages - -``` -$ npm install ``` -### 2. Run tests Chrome and Node (by default): - -``` -$ testem +
+ +
Node.js + +```js +const http = require('http'); +const { fabric } = require('fabric'); + +const port = 8080; + +http + .createServer((req, res) => { + const canvas = new fabric.Canvas(null, { width: 100, height: 100 }); + const rect = new fabric.Rect({ width: 20, height: 50, fill: '#ff0000' }); + const text = new fabric.Text('fabric.js', { fill: 'blue', fontSize: 24 }); + canvas.add(rect, text); + canvas.renderAll(); + if (req.url === '/download') { + res.setHeader('Content-Type', 'image/png'); + res.setHeader('Content-Disposition', 'attachment; filename="fabric.png"'); + canvas.createPNGStream().pipe(res); + } else if (req.url === '/view') { + canvas.createPNGStream().pipe(res); + } else { + const imageData = canvas.toDataURL(); + res.writeHead(200, '', { 'Content-Type': 'text/html' }); + res.write(``); + res.end(); + } + }) + .listen(port, (err) => { + if (err) throw err; + console.log( + `> Ready on http://localhost:${port}, http://localhost:${port}/view, http://localhost:${port}/download` + ); + }); ``` -See testem docs for more info: https://github.com/testem/testem - -## Optional modules - -These are the optional modules that could be specified for inclusion, when building custom version of fabric: - -- **text** โ€” Adds support for static text (`fabric.Text`) -- **itext** โ€” Adds support for interactive text (`fabric.IText`, `fabric.Textbox`) -- **serialization** โ€” Adds support for `loadFromJSON`, `loadFromDatalessJSON`, and `clone` methods on `fabric.Canvas` -- **interaction** โ€” Adds support for interactive features of fabric โ€” selecting/transforming objects/groups via mouse/touch devices. -- **parser** โ€” Adds support for `fabric.parseSVGDocument`, `fabric.loadSVGFromURL`, and `fabric.loadSVGFromString` -- **image_filters** โ€” Adds support for image filters, such as grayscale of white removal. -- **easing** โ€” Adds support for animation easing functions -- **node** โ€” Adds support for running fabric under node.js, with help of [jsdom](https://github.com/tmpvar/jsdom) and [node-canvas](https://github.com/learnboost/node-canvas) libraries. -- **freedrawing** โ€” Adds support for free drawing -- **erasing** โ€” Adds support for object erasing using an eraser brush -- **gestures** โ€” Adds support for multitouch gestures with help of [Event.js](https://github.com/mudcube/Event.js) -- **object_straightening** โ€” Adds support for rotating an object to one of 0, 90, 180, 270, etc. depending on which is angle is closer. -- **animation** โ€” Adds support for animation (`fabric.util.animate`, `fabric.util.requestAnimFrame`, `fabric.Object#animate`, `fabric.Canvas#fxCenterObjectH/#fxCenterObjectV/#fxRemove`) - -Additional flags for build script are: - -- **requirejs** โ€” Makes fabric requirejs AMD-compatible in `dist/fabric.js`. _Note:_ an unminified, requirejs-compatible version is always created in `dist/fabric.require.js` -- **no-strict** โ€” Strips "use strict" directives from source -- **no-svg-export** โ€” Removes svg exporting functionality -- **sourcemap** - Generates a sourceMap file and adds the `sourceMappingURL` (only if uglifyjs is used) to `dist/fabric.min.js` - -For example: - - node build.js modules=ALL exclude=json no-strict no-svg-export +
-## Goals +--- -- Unit tested (1150+ tests at the moment, 79%+ coverage) -- Modular (~60 small ["classes", modules, mixins](http://fabricjs.com/docs/)) -- Cross-browser -- [Fast](https://github.com/kangax/fabric.js/wiki/Focus-on-speed) -- Encapsulated in one object -- No browser sniffing for critical functionality -- Runs under ES5 strict mode -- Runs on a server under [Node.js](http://nodejs.org/) (active stable releases and latest of current) (see [Node.js limitations](https://github.com/kangax/fabric.js/wiki/Fabric-limitations-in-node.js)) -- Follows [Semantic Versioning](http://semver.org/) +## Other Solutions -## Supported browsers +| Project | Description | Demo | +| ------------------------------ | -------------------- | :--: | +| [Three.js][three.js] | 3D graphics | +| [PixiJS][pixijs] | WebGL renderer | +| [Konva][konva] | Similar features | โŒ | +| [Canvas2PDF][canvas2pdf] | PDF renderer | +| [html-to-image][html-to-image] | HTML to image/canvas | -- Firefox 4+ -- Safari 5+ -- Opera 9.64+ -- Chrome (all versions) -- Edge (chromium based, all versions) -- IE11 and Edge legacy, not supported. Fabric up to 5.0 is written with ES5 in mind, but no specific tests are run for those browsers. +## More Resources -You can [run automated unit tests](http://fabricjs.com/test/unit/) right in the browser. +- [Demos on `fabricjs.com`][demos] +- [Fabric.js on `Twitter`][twitter] +- [Fabric.js on `CodeTriage`][code_triage] +- [Fabric.js on `Stack Overflow`][so] +- [Fabric.js on `jsfiddle`][jsfiddles] +- [Fabric.js on `Codepen.io`][codepens] -## More resources +## Credits [![Patreon](https://img.shields.io/static/v1?label=Patreon&message=%F0%9F%91%8D&logo=Patreon&color=blueviolet)](https://www.patreon.com/fabricJS) -- [Fabric.js on Twitter](https://twitter.com/fabricjs) -- [Fabric.js on CodeTriage](https://www.codetriage.com/kangax/fabric.js) -- [Fabric.js on Stackoverflow](https://stackoverflow.com/questions/tagged/fabricjs) -- [Fabric.js on jsfiddle](https://jsfiddle.net/user/fabricjs/fiddles/) -- [Fabric.js on Codepen.io](https://codepen.io/tag/fabricjs) -- [Presentation from BK.js](http://www.slideshare.net/kangax/fabricjs-building-acanvaslibrarybk) -- [Presentation from Falsy Values](http://www.slideshare.net/kangax/fabric-falsy-values-8067834) - -## Credits - -- [@kangax](https://twitter.com/kangax) -- [Andrea Bogazzi](https://twitter.com/AndreaBogazzi) for help with bugs, new features, documentation, GitHub issues -- [melchiar](https://github.com/melchiar) -- [ShaMan123](https://github.com/ShaMan123) +- [kangax][kagnax] +- [asturur][asturur] on [`Twitter`][asturur_twitter] + [![Sponsor asturur](https://img.shields.io/static/v1?label=Sponsor%20asturur&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/asturur) +- [melchiar][melchiar] [![Sponsor melchiar](https://img.shields.io/static/v1?label=Sponsor%20melchiar&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/melchiar) +- [ShaMan123][shaman123] [![Sponsor ShaMan123](https://img.shields.io/static/v1?label=Sponsor%20ShaMan123&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/ShaMan123) - Ernest Delgado for the original idea of [manipulating images on canvas](http://www.ernestdelgado.com/archive/canvas/) - [Maxim "hakunin" Chernyak](http://twitter.com/hakunin) for ideas, and help with various parts of the library throughout its life - [Sergey Nisnevich](http://nisnya.com) for help with geometry logic - [Stefan Kienzle](https://twitter.com/kienzle_s) for help with bugs, features, documentation, GitHub issues - [Shutterstock](http://www.shutterstock.com/jobs) for the time and resources invested in using and improving Fabric.js -- [and all the other GitHub contributors](https://github.com/kangax/fabric.js/graphs/contributors) - -## Sponsor authors - -- https://flattr.com/@kangax -- https://github.com/sponsors/asturur -- https://www.patreon.com/fabricJS - -## MIT License - -Copyright (c) 2008-2015 Printio (Juriy Zaytsev, Maxim Chernyak) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +- [and all the other contributors][contributors] + +[asturur]: https://github.com/asturur +[asturur_twitter]: https://twitter.com/AndreaBogazzi +[canvas2pdf]: https://github.com/joshua-gould/canvas2pdf +[cdnjs]: https://cdnjs.com/libraries/fabric.js +[code_triage]: https://www.codetriage.com/kangax/fabric.js +[codepens]: https://codepen.io/tag/fabricjs +[contributors]: https://github.com/fabricjs/fabric.js/graphs/contributors +[demos]: http://fabricjs.com/demos/ +[gotchas]: http://fabricjs.com/fabric-gotchas +[html-to-image]: https://github.com/bubkoo/html-to-image +[jsdelivr]: https://www.jsdelivr.com/package/npm/fabric +[jsdom]: https://github.com/jsdom/jsdom +[jsfiddles]: https://jsfiddle.net/user/fabricjs/fiddles/ +[kagnax]: https://twitter.com/kangax +[konva]: https://github.com/konvajs/konva +[mdn_es6]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules +[melchiar]: https://github.com/melchiar +[node_canvas]: https://github.com/Automattic/node-canvas +[node_canvas_install]: https://github.com/Automattic/node-canvas#compiling +[node_canvas_issues]: https://github.com/Automattic/node-canvas/issues +[patreon_badge]: https://img.shields.io/static/v1?label=Patreon&message=%F0%9F%91%8D&logo=Patreon&color=blueviolet +[pixijs]: https://github.com/pixijs/pixijs +[shaman123]: https://github.com/ShaMan123 +[so]: https://stackoverflow.com/questions/tagged/fabricjs +[three.js]: https://github.com/mrdoob/three.js/ +[twitter]: https://twitter.com/fabricjs +[website]: http://fabricjs.com/