Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@behance/fabric
Advanced tools
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
![Gitter](https://badges.gitter.im/Join Chat.svg)
Fabric.js is a framework that makes it easy to work with HTML5 canvas element. It is an interactive object model on top of canvas element. It is also an SVG-to-canvas parser.
Using Fabric.js, you can create and populate objects on canvas; objects like simple geometrical shapes — rectangles, circles, ellipses, polygons, or more complex shapes consisting of hundreds or thousands of simple paths. You can then scale, move, and rotate these objects with the mouse; modify their properties — color, transparency, z-index, etc. You can also manipulate these objects altogether — grouping them with a simple mouse selection.
Fabric.js allows you to easily create simple shapes like rectangles, circles, triangles and other polygons or more complex shapes made up of many paths, onto the HTML <canvas>
element on a webpage using JavaScript. Fabric.js will then allow you to manipulate the size, position and rotation of these objects with a mouse. It’s also possible to change some of the attributes of these objects such as their color, transparency, depth position on the webpage or selecting groups of these objects using the Fabric.js library. Fabric.js will also allow you to convert an SVG image into JavaScript data that can be used for putting it onto the <canvas>
element.
Contributions are very much welcome!
See Fabric limitations in Old IE.
Note: to properly make old IE work, you will need to add html5shiv as a conditional comment in your HEAD, particularly html5shiv-printshiv.js
to allow for children elements:
<!--[if lt IE 9]>
<script src="path/to/your/html5shiv-printshiv.js"></script>
<![endif]-->
Remember to add Explorer Canvas as well.
You can run automated unit tests right in the browser.
Fabric.js started as a foundation for design editor on printio.ru — interactive online store with ability to create your own designs. The idea was to create Javascript-based editor, which would make it easy to manipulate vector shapes and images on T-Shirts. Since performance was one of the most critical requirements, we chose canvas over SVG. While SVG is excellent with static shapes, it's not as performant as canvas when it comes to dynamic manipulation of objects (movement, scaling, rotation, etc.). Fabric.js was heavily inspired by Ernest Delgado's canvas experiment. In fact, code from Ernest's experiment was the foundation of an entire framework. Later, Fabric.js grew into a collection of distinct object types and got an SVG-to-canvas parser.
$ bower install fabric
$ npm install fabric --save
Build distribution file [~77K minified, ~20K gzipped]
$ node build.js
2.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
2.2 You can also include all modules like so:
$ node build.js modules=ALL
2.3 You can exclude a few modules like so:
$ node build.js modules=ALL exclude=gestures,image_filters
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
Enable AMD support via require.js (requires uglify)
$ node build.js requirejs modules=...
Create source map file for better productive debugging (requires uglify or google closure compiler).
More information about source maps.
$ 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
Lint source code (prerequisite: npm -g install jshint
)
$ jshint src
Ensure code guidelines are met (prerequisite: npm -g install jscs
)
$ jscs src
Install NPM packages
$ npm install
Run test suite
$ npm test
Documentation is always available at http://fabricjs.com/docs/.
Also see official 4-part intro series, presentation from BK.js and presentation from Falsy Values for an overview of fabric.js, how it works, and its features.
These are the optional modules that could be specified for inclusion, when building custom version of fabric:
fabric.Text
)fabric.IText
)loadFromJSON
, loadFromDatalessJSON
, and clone
methods on fabric.Canvas
fabric.parseSVGDocument
, fabric.loadSVGFromURL
, and fabric.loadSVGFromString
fabric.util.animate
, fabric.util.requestAnimFrame
, fabric.Object#animate
, fabric.Canvas#fxCenterObjectH/#fxCenterObjectV/#fxRemove
)Additional flags for build script are:
dist/fabric.js
. Note: an unminified, requirejs-compatible version is always created in dist/fabric.require.js
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
<script src="lib/fabric.js"></script>
<script>
var canvas = new fabric.Canvas('canvas');
var rect = new fabric.Rect({
top : 100,
left : 100,
width : 60,
height : 70,
fill : 'red'
});
canvas.add(rect);
</script>
</body>
</html>
Follow @fabric.js or @kangax on twitter.
Questions, suggestions — fabric.js on Google Groups.
See Fabric questions on Stackoverflow, Fabric snippets on jsfiddle or codepen.io.
Fabric on LibKnot.
Get help in Fabric's IRC channel — irc://irc.freenode.net/#fabric.js
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.
FAQs
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
The npm package @behance/fabric receives a total of 3 weekly downloads. As such, @behance/fabric popularity was classified as not popular.
We found that @behance/fabric demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 42 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.