Blame view
app/bower_components/fabric.js/README.md
14.2 KB
6f105dbd5
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
### Fabric <!-- chat, support --> [](https://gitter.im/kangax/fabric.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) <!-- build/coverage status, climate --> [](http://travis-ci.org/#!/kangax/fabric.js) [](https://codeclimate.com/github/kangax/fabric.js) [](https://coveralls.io/r/kangax/fabric.js?branch=master) <!-- npm, bower versions, downloads --> [](http://badge.fury.io/bo/fabric) [](http://badge.fury.io/js/fabric) [](https://www.npmjs.org/package/fabric) <!-- deps status --> [](https://david-dm.org/kangax/fabric.js) [](https://david-dm.org/kangax/fabric.js#info=devDependencies) <!-- bounties, tips --> [](https://www.bountysource.com/trackers/23217-fabric-js?utm_source=23217&utm_medium=shield&utm_campaign=TRACKER_BADGE) [](https://gratipay.com/kangax/) [](https://flattr.com/submit/auto?user_id=kangax&url=http://github.com/kangax/fabric.js&title=Fabric.js&language=&tags=github&category=software) **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**. <a href="http://fabricjs.com/kitchensink" target="_blank"><img src="https://github.com/kangax/fabric.js/raw/master/lib/screenshot.png" style="width:300px;box-shadow:rgba(0,0,0,0.3) 0 0 5px"></a> 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. ### Non-Technical Introduction to Fabric 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](https://github.com/kangax/fabric.js/wiki/Love-Fabric%3F-Help-us-by...) are very much welcome! ### Goals - Unit tested (2400+ tests at the moment) - 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/) (0.8, 0.10, 0.11, 0.12) (see [Node.js limitations](https://github.com/kangax/fabric.js/wiki/Fabric-limitations-in-node.js)) - Follows [Semantic Versioning](http://semver.org/) ### Supported browsers - Firefox 2+ - Safari 3+ - Opera 9.64+ - Chrome (all versions) - IE9, IE10, IE11, Edge #### With help of [Explorer Canvas](http://code.google.com/p/explorercanvas/) - IE8 (incomplete — about 17 failing tests at the moment) - IE7,6 (incomplete - about 27 failing tests at the moment) See [Fabric limitations in Old IE](https://github.com/kangax/fabric.js/wiki/Fabric-limitations-in-oldIE). Note: to properly make old IE work, you will need to add [html5shiv](https://github.com/aFarkas/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](http://code.google.com/p/explorercanvas/) as well. You can [run automated unit tests](http://fabricjs.com/test/unit/) right in the browser. ### History Fabric.js started as a foundation for design editor on [printio.ru](http://printio.ru) — interactive online store with ability to create your own designs. The idea was to create [Javascript-based editor](http://printio.ru/ringer_man_tees/new), 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](http://www.ernestdelgado.com/public-tests/canvasphoto/demo/canvas.html). 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. <h3 id="bower-install">Install with bower</h3> $ bower install fabric <h3 id="npm-install">Install with npm</h3> To install Fabric.js using npm, you must first manually [install Cairo](http://cairographics.org/download/) on your system. Cairo is a system library which powers node-canvas, which Fabric.js relies on. When the installation is complete, you may need to restart your terminal or command prompt before installing fabric. $ npm install fabric --save <h3 id="fabric-building">Building</h3> 1. [Install Node.js](https://github.com/joyent/node/wiki/Installation) 2. 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 3. 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 4. Enable AMD support via require.js (requires uglify) $ node build.js requirejs modules=... 5. Create source map file for better productive debugging (requires uglify or google closure compiler).<br>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 6. Lint source code (prerequisite: `npm -g install jshint`) $ jshint src 7. Ensure code guidelines are met (prerequisite: `npm -g install jscs`) $ jscs src <h3 id="fabric-building">Testing</h3> 1. [Install Node.js](https://github.com/joyent/node/wiki/Installation) 2. [Install NPM, if necessary](https://github.com/npm/npm#super-easy-install) 3. Install NPM packages $ npm install 4. Run test suite Make sure testem is installed $ npm install -g testem Run tests Chrome and Node (by default): $ testem See testem docs for more info: https://github.com/testem/testem ### Demos - [Demos](http://fabricjs.com/demos/) - [Kitchensink demo](http://fabricjs.com/kitchensink) - [Benchmarks](http://fabricjs.com/benchmarks/) [Who's using Fabric?](http://trends.builtwith.com/javascript/FabricJS) ### Documentation Documentation is always available at [http://fabricjs.com/docs/](http://fabricjs.com/docs/). Also see [official 4-part intro series](http://fabricjs.com/articles), [presentation from BK.js](http://www.slideshare.net/kangax/fabricjs-building-acanvaslibrarybk) and [presentation from Falsy Values](http://www.slideshare.net/kangax/fabric-falsy-values-8067834) for an overview of fabric.js, how it works, and its features. ### 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`) - **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 - **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 - **no-es5-compat** - Removes ES5 compat methods (Array.prototype.*, String.prototype.*, Function.prototype.*) - **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 ### Examples of use #### Adding red rectangle to canvas ```html <!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> ``` ### Helping Fabric - [Fabric on Bountysource](https://www.bountysource.com/trackers/23217-fabric-js) - [Fabric on CodeTriage](http://www.codetriage.com/kangax/fabric.js) ### Staying in touch Follow [@fabric.js](http://twitter.com/fabricjs) or [@kangax](http://twitter.com/kangax) on twitter. Questions, suggestions — [fabric.js on Google Groups](http://groups.google.com/group/fabricjs). See [Fabric questions on Stackoverflow](http://stackoverflow.com/questions/tagged/fabricjs), Fabric snippets on [jsfiddle](http://jsfiddle.net/user/fabricjs/fiddles/) or [codepen.io](http://codepen.io/tag/fabricjs). Fabric on [LibKnot](http://libknot.ohmztech.com/). Get help in Fabric's IRC channel — irc://irc.freenode.net/#fabric.js ### Credits - 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 - [And all the other GitHub contributors](https://github.com/kangax/fabric.js/graphs/contributors) ### 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. [](https://bitdeli.com/free "Bitdeli Badge") |