fabric-rails 1.0.12 → 1.0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/CHANGELOG.md +16 -0
  2. data/README.md +1 -1
  3. data/lib/fabric/rails/version.rb +2 -2
  4. data/vendor/assets/javascripts/event.js +1909 -0
  5. data/vendor/assets/javascripts/fabric.js +64 -16464
  6. data/vendor/assets/javascripts/fabric/HEADER.js +31 -0
  7. data/vendor/assets/javascripts/fabric/canvas.class.js +1007 -0
  8. data/vendor/assets/javascripts/fabric/canvas_animation.mixin.js +113 -0
  9. data/vendor/assets/javascripts/fabric/canvas_events.mixin.js +482 -0
  10. data/vendor/assets/javascripts/fabric/canvas_gestures.mixin.js +79 -0
  11. data/vendor/assets/javascripts/fabric/canvas_serialization.mixin.js +311 -0
  12. data/vendor/assets/javascripts/fabric/circle.class.js +182 -0
  13. data/vendor/assets/javascripts/fabric/color.class.js +284 -0
  14. data/vendor/assets/javascripts/fabric/ellipse.class.js +169 -0
  15. data/vendor/assets/javascripts/fabric/freedrawing.class.js +256 -0
  16. data/vendor/assets/javascripts/fabric/gradient.class.js +211 -0
  17. data/vendor/assets/javascripts/fabric/group.class.js +556 -0
  18. data/vendor/assets/javascripts/fabric/image.class.js +418 -0
  19. data/vendor/assets/javascripts/fabric/image_filters.js +809 -0
  20. data/vendor/assets/javascripts/fabric/intersection.class.js +178 -0
  21. data/vendor/assets/javascripts/fabric/line.class.js +188 -0
  22. data/vendor/assets/javascripts/fabric/log.js +26 -0
  23. data/vendor/assets/javascripts/fabric/node.js +149 -0
  24. data/vendor/assets/javascripts/fabric/object.class.js +1068 -0
  25. data/vendor/assets/javascripts/fabric/object_geometry.mixin.js +308 -0
  26. data/vendor/assets/javascripts/fabric/object_interactivity.mixin.js +496 -0
  27. data/vendor/assets/javascripts/fabric/object_origin.mixin.js +207 -0
  28. data/vendor/assets/javascripts/fabric/object_straightening.mixin.js +94 -0
  29. data/vendor/assets/javascripts/fabric/observable.mixin.js +91 -0
  30. data/vendor/assets/javascripts/fabric/parser.js +750 -0
  31. data/vendor/assets/javascripts/fabric/path.class.js +794 -0
  32. data/vendor/assets/javascripts/fabric/path_group.class.js +240 -0
  33. data/vendor/assets/javascripts/fabric/pattern.class.js +69 -0
  34. data/vendor/assets/javascripts/fabric/point.class.js +327 -0
  35. data/vendor/assets/javascripts/fabric/polygon.class.js +184 -0
  36. data/vendor/assets/javascripts/fabric/polyline.class.js +157 -0
  37. data/vendor/assets/javascripts/fabric/rect.class.js +298 -0
  38. data/vendor/assets/javascripts/fabric/scout.js +45 -0
  39. data/vendor/assets/javascripts/fabric/shadow.class.js +70 -0
  40. data/vendor/assets/javascripts/fabric/stateful.js +88 -0
  41. data/vendor/assets/javascripts/fabric/static_canvas.class.js +1298 -0
  42. data/vendor/assets/javascripts/fabric/text.class.js +934 -0
  43. data/vendor/assets/javascripts/fabric/triangle.class.js +108 -0
  44. data/vendor/assets/javascripts/fabric/util/anim_ease.js +360 -0
  45. data/vendor/assets/javascripts/fabric/util/dom_event.js +237 -0
  46. data/vendor/assets/javascripts/fabric/util/dom_misc.js +245 -0
  47. data/vendor/assets/javascripts/fabric/util/dom_request.js +72 -0
  48. data/vendor/assets/javascripts/fabric/util/dom_style.js +71 -0
  49. data/vendor/assets/javascripts/fabric/util/lang_array.js +250 -0
  50. data/vendor/assets/javascripts/fabric/util/lang_class.js +97 -0
  51. data/vendor/assets/javascripts/fabric/util/lang_function.js +35 -0
  52. data/vendor/assets/javascripts/fabric/util/lang_object.js +34 -0
  53. data/vendor/assets/javascripts/fabric/util/lang_string.js +60 -0
  54. data/vendor/assets/javascripts/fabric/util/misc.js +406 -0
  55. data/vendor/assets/javascripts/json2.js +491 -0
  56. metadata +53 -2
@@ -0,0 +1,284 @@
1
+ (function(global) {
2
+
3
+ "use strict";
4
+
5
+ var fabric = global.fabric || (global.fabric = { });
6
+
7
+ if (fabric.Color) {
8
+ fabric.warn('fabric.Color is already defined.');
9
+ return;
10
+ }
11
+
12
+ /**
13
+ * Color class
14
+ * The purpose of {@link fabric.Color} is to abstract and encapsulate common color operations;
15
+ * {@link fabric.Color} is a constructor and creates instances of {@link fabric.Color} objects.
16
+ *
17
+ * @class Color
18
+ * @memberOf fabric
19
+ * @param {String} color optional in hex or rgb(a) format
20
+ * @return {fabric.Color} thisArg
21
+ */
22
+ function Color(color) {
23
+ if (!color) {
24
+ this.setSource([0, 0, 0, 1]);
25
+ }
26
+ else {
27
+ this._tryParsingColor(color);
28
+ }
29
+ }
30
+
31
+ fabric.Color = Color;
32
+
33
+ fabric.Color.prototype = /** @scope fabric.Color.prototype */ {
34
+
35
+ /**
36
+ * @private
37
+ * @method _tryParsingColor
38
+ */
39
+ _tryParsingColor: function(color) {
40
+ var source = Color.sourceFromHex(color);
41
+ if (!source) {
42
+ source = Color.sourceFromRgb(color);
43
+ }
44
+ if (source) {
45
+ this.setSource(source);
46
+ }
47
+ },
48
+
49
+ /**
50
+ * Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])
51
+ * @method getSource
52
+ * @return {Array}
53
+ */
54
+ getSource: function() {
55
+ return this._source;
56
+ },
57
+
58
+ /**
59
+ * Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1])
60
+ * @method setSource
61
+ * @param {Array} source
62
+ */
63
+ setSource: function(source) {
64
+ this._source = source;
65
+ },
66
+
67
+ /**
68
+ * Returns color represenation in RGB format
69
+ * @method toRgb
70
+ * @return {String} ex: rgb(0-255,0-255,0-255)
71
+ */
72
+ toRgb: function() {
73
+ var source = this.getSource();
74
+ return 'rgb(' + source[0] + ',' + source[1] + ',' + source[2] + ')';
75
+ },
76
+
77
+ /**
78
+ * Returns color represenation in RGBA format
79
+ * @method toRgba
80
+ * @return {String} ex: rgba(0-255,0-255,0-255,0-1)
81
+ */
82
+ toRgba: function() {
83
+ var source = this.getSource();
84
+ return 'rgba(' + source[0] + ',' + source[1] + ',' + source[2] + ',' + source[3] + ')';
85
+ },
86
+
87
+ /**
88
+ * Returns color represenation in HEX format
89
+ * @method toHex
90
+ * @return {String} ex: FF5555
91
+ */
92
+ toHex: function() {
93
+ var source = this.getSource();
94
+
95
+ var r = source[0].toString(16);
96
+ r = (r.length === 1) ? ('0' + r) : r;
97
+
98
+ var g = source[1].toString(16);
99
+ g = (g.length === 1) ? ('0' + g) : g;
100
+
101
+ var b = source[2].toString(16);
102
+ b = (b.length === 1) ? ('0' + b) : b;
103
+
104
+ return r.toUpperCase() + g.toUpperCase() + b.toUpperCase();
105
+ },
106
+
107
+ /**
108
+ * Gets value of alpha channel for this color
109
+ * @method getAlpha
110
+ * @return {Number} 0-1
111
+ */
112
+ getAlpha: function() {
113
+ return this.getSource()[3];
114
+ },
115
+
116
+ /**
117
+ * Sets value of alpha channel for this color
118
+ * @method setAlpha
119
+ * @param {Number} 0-1
120
+ * @return {fabric.Color} thisArg
121
+ */
122
+ setAlpha: function(alpha) {
123
+ var source = this.getSource();
124
+ source[3] = alpha;
125
+ this.setSource(source);
126
+ return this;
127
+ },
128
+
129
+ /**
130
+ * Transforms color to its grayscale representation
131
+ * @method toGrayscale
132
+ * @return {fabric.Color} thisArg
133
+ */
134
+ toGrayscale: function() {
135
+ var source = this.getSource(),
136
+ average = parseInt((source[0] * 0.3 + source[1] * 0.59 + source[2] * 0.11).toFixed(0), 10),
137
+ currentAlpha = source[3];
138
+ this.setSource([average, average, average, currentAlpha]);
139
+ return this;
140
+ },
141
+
142
+ /**
143
+ * Transforms color to its black and white representation
144
+ * @method toGrayscale
145
+ * @return {fabric.Color} thisArg
146
+ */
147
+ toBlackWhite: function(threshold) {
148
+ var source = this.getSource(),
149
+ average = (source[0] * 0.3 + source[1] * 0.59 + source[2] * 0.11).toFixed(0),
150
+ currentAlpha = source[3];
151
+
152
+ threshold = threshold || 127;
153
+
154
+ average = (Number(average) < Number(threshold)) ? 0 : 255;
155
+ this.setSource([average, average, average, currentAlpha]);
156
+ return this;
157
+ },
158
+
159
+ /**
160
+ * Overlays color with another color
161
+ * @method overlayWith
162
+ * @param {String|fabric.Color} otherColor
163
+ * @return {fabric.Color} thisArg
164
+ */
165
+ overlayWith: function(otherColor) {
166
+ if (!(otherColor instanceof Color)) {
167
+ otherColor = new Color(otherColor);
168
+ }
169
+
170
+ var result = [],
171
+ alpha = this.getAlpha(),
172
+ otherAlpha = 0.5,
173
+ source = this.getSource(),
174
+ otherSource = otherColor.getSource();
175
+
176
+ for (var i = 0; i < 3; i++) {
177
+ result.push(Math.round((source[i] * (1 - otherAlpha)) + (otherSource[i] * otherAlpha)));
178
+ }
179
+
180
+ result[3] = alpha;
181
+ this.setSource(result);
182
+ return this;
183
+ }
184
+ };
185
+
186
+ /**
187
+ * Regex matching color in RGB or RGBA formats (ex: rgb(0, 0, 0), rgb(255, 100, 10, 0.5), rgb(1,1,1))
188
+ * @static
189
+ * @field
190
+ */
191
+ fabric.Color.reRGBa = /^rgba?\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(\d+(?:\.\d+)?))?\)$/;
192
+
193
+ /**
194
+ * Regex matching color in HEX format (ex: #FF5555, 010155, aff)
195
+ * @static
196
+ * @field
197
+ */
198
+ fabric.Color.reHex = /^#?([0-9a-f]{6}|[0-9a-f]{3})$/i;
199
+
200
+ /**
201
+ * Returns new color object, when given a color in RGB format
202
+ * @method fromRgb
203
+ * @param {String} color ex: rgb(0-255,0-255,0-255)
204
+ * @return {fabric.Color}
205
+ */
206
+ fabric.Color.fromRgb = function(color) {
207
+ return Color.fromSource(Color.sourceFromRgb(color));
208
+ };
209
+
210
+ /**
211
+ * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format
212
+ * @method sourceFromRgb
213
+ * @param {String} color ex: rgb(0-255,0-255,0-255)
214
+ * @return {Array} source
215
+ */
216
+ fabric.Color.sourceFromRgb = function(color) {
217
+ var match = color.match(Color.reRGBa);
218
+ if (match) {
219
+ return [
220
+ parseInt(match[1], 10),
221
+ parseInt(match[2], 10),
222
+ parseInt(match[3], 10),
223
+ match[4] ? parseFloat(match[4]) : 1
224
+ ];
225
+ }
226
+ };
227
+
228
+ /**
229
+ * Returns new color object, when given a color in RGBA format
230
+ * @static
231
+ * @function
232
+ * @method fromRgba
233
+ * @param {String} color
234
+ * @return {fabric.Color}
235
+ */
236
+ fabric.Color.fromRgba = Color.fromRgb;
237
+
238
+ /**
239
+ * Returns new color object, when given a color in HEX format
240
+ * @static
241
+ * @method fromHex
242
+ * @return {fabric.Color}
243
+ */
244
+ fabric.Color.fromHex = function(color) {
245
+ return Color.fromSource(Color.sourceFromHex(color));
246
+ };
247
+
248
+ /**
249
+ * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HEX format
250
+ * @static
251
+ * @method sourceFromHex
252
+ * @param {String} color ex: FF5555
253
+ * @return {Array} source
254
+ */
255
+ fabric.Color.sourceFromHex = function(color) {
256
+ if (color.match(Color.reHex)) {
257
+ var value = color.slice(color.indexOf('#') + 1),
258
+ isShortNotation = (value.length === 3),
259
+ r = isShortNotation ? (value.charAt(0) + value.charAt(0)) : value.substring(0, 2),
260
+ g = isShortNotation ? (value.charAt(1) + value.charAt(1)) : value.substring(2, 4),
261
+ b = isShortNotation ? (value.charAt(2) + value.charAt(2)) : value.substring(4, 6);
262
+
263
+ return [
264
+ parseInt(r, 16),
265
+ parseInt(g, 16),
266
+ parseInt(b, 16),
267
+ 1
268
+ ];
269
+ }
270
+ };
271
+
272
+ /**
273
+ * Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5])
274
+ * @static
275
+ * @method fromSource
276
+ * @return {fabric.Color}
277
+ */
278
+ fabric.Color.fromSource = function(source) {
279
+ var oColor = new Color();
280
+ oColor.setSource(source);
281
+ return oColor;
282
+ };
283
+
284
+ })(typeof exports !== 'undefined' ? exports : this);
@@ -0,0 +1,169 @@
1
+ (function(global){
2
+
3
+ "use strict";
4
+
5
+ var fabric = global.fabric || (global.fabric = { }),
6
+ piBy2 = Math.PI * 2,
7
+ extend = fabric.util.object.extend;
8
+
9
+ if (fabric.Ellipse) {
10
+ fabric.warn('fabric.Ellipse is already defined.');
11
+ return;
12
+ }
13
+
14
+ /**
15
+ * Ellipse class
16
+ * @class Ellipse
17
+ * @extends fabric.Object
18
+ */
19
+ fabric.Ellipse = fabric.util.createClass(fabric.Object, /** @scope fabric.Ellipse.prototype */ {
20
+
21
+ /**
22
+ * Type of an object
23
+ * @property
24
+ * @type String
25
+ */
26
+ type: 'ellipse',
27
+
28
+ /**
29
+ * Constructor
30
+ * @method initialize
31
+ * @param {Object} [options] Options object
32
+ * @return {fabric.Ellipse} thisArg
33
+ */
34
+ initialize: function(options) {
35
+ options = options || { };
36
+
37
+ this.callSuper('initialize', options);
38
+
39
+ this.set('rx', options.rx || 0);
40
+ this.set('ry', options.ry || 0);
41
+
42
+ this.set('width', this.get('rx') * 2);
43
+ this.set('height', this.get('ry') * 2);
44
+ },
45
+
46
+ /**
47
+ * Returns object representation of an instance
48
+ * @method toObject
49
+ * @param {Array} propertiesToInclude
50
+ * @return {Object} object representation of an instance
51
+ */
52
+ toObject: function(propertiesToInclude) {
53
+ return extend(this.callSuper('toObject', propertiesToInclude), {
54
+ rx: this.get('rx'),
55
+ ry: this.get('ry')
56
+ });
57
+ },
58
+
59
+ /**
60
+ * Returns svg representation of an instance
61
+ * @method toSVG
62
+ * @return {String} svg representation of an instance
63
+ */
64
+ toSVG: function() {
65
+ return [
66
+ '<ellipse ',
67
+ 'rx="', this.get('rx'), '" ',
68
+ 'ry="', this.get('ry'), '" ',
69
+ 'style="', this.getSvgStyles(), '" ',
70
+ 'transform="', this.getSvgTransform(), '" ',
71
+ '/>'
72
+ ].join('');
73
+ },
74
+
75
+ /**
76
+ * Renders this instance on a given context
77
+ * @method render
78
+ * @param ctx {CanvasRenderingContext2D} context to render on
79
+ * @param noTransform {Boolean} context is not transformed when set to true
80
+ */
81
+ render: function(ctx, noTransform) {
82
+ // do not use `get` for perf. reasons
83
+ if (this.rx === 0 || this.ry === 0) return;
84
+ return this.callSuper('render', ctx, noTransform);
85
+ },
86
+
87
+ /**
88
+ * @private
89
+ * @method _render
90
+ * @param ctx {CanvasRenderingContext2D} context to render on
91
+ */
92
+ _render: function(ctx, noTransform) {
93
+ ctx.beginPath();
94
+ ctx.save();
95
+ ctx.globalAlpha = this.group ? (ctx.globalAlpha * this.opacity) : this.opacity;
96
+ if (this.transformMatrix && this.group) {
97
+ ctx.translate(this.cx, this.cy);
98
+ }
99
+ ctx.transform(1, 0, 0, this.ry/this.rx, 0, 0);
100
+ ctx.arc(noTransform ? this.left : 0, noTransform ? this.top : 0, this.rx, 0, piBy2, false);
101
+ if (this.stroke) {
102
+ ctx.stroke();
103
+ }
104
+ this._removeShadow(ctx);
105
+ if (this.fill) {
106
+ ctx.fill();
107
+ }
108
+ ctx.restore();
109
+ },
110
+
111
+ /**
112
+ * Returns complexity of an instance
113
+ * @method complexity
114
+ * @return {Number} complexity
115
+ */
116
+ complexity: function() {
117
+ return 1;
118
+ }
119
+ });
120
+
121
+ /**
122
+ * List of attribute names to account for when parsing SVG element (used by {@link fabric.Ellipse.fromElement})
123
+ * @static
124
+ * @see http://www.w3.org/TR/SVG/shapes.html#EllipseElement
125
+ */
126
+ fabric.Ellipse.ATTRIBUTE_NAMES = 'cx cy rx ry fill fill-opacity opacity stroke stroke-width transform'.split(' ');
127
+
128
+ /**
129
+ * Returns {@link fabric.Ellipse} instance from an SVG element
130
+ * @static
131
+ * @method fabric.Ellipse.fromElement
132
+ * @param {SVGElement} element Element to parse
133
+ * @param {Object} [options] Options object
134
+ * @return {fabric.Ellipse}
135
+ */
136
+ fabric.Ellipse.fromElement = function(element, options) {
137
+ options || (options = { });
138
+
139
+ var parsedAttributes = fabric.parseAttributes(element, fabric.Ellipse.ATTRIBUTE_NAMES);
140
+ var cx = parsedAttributes.left;
141
+ var cy = parsedAttributes.top;
142
+
143
+ if ('left' in parsedAttributes) {
144
+ parsedAttributes.left -= (options.width / 2) || 0;
145
+ }
146
+ if ('top' in parsedAttributes) {
147
+ parsedAttributes.top -= (options.height / 2) || 0;
148
+ }
149
+
150
+ var ellipse = new fabric.Ellipse(extend(parsedAttributes, options));
151
+
152
+ ellipse.cx = cx || 0;
153
+ ellipse.cy = cy || 0;
154
+
155
+ return ellipse;
156
+ };
157
+
158
+ /**
159
+ * Returns {@link fabric.Ellipse} instance from an object representation
160
+ * @static
161
+ * @method fabric.Ellipse.fromObject
162
+ * @param {Object} object Object to create an instance from
163
+ * @return {fabric.Ellipse}
164
+ */
165
+ fabric.Ellipse.fromObject = function(object) {
166
+ return new fabric.Ellipse(object);
167
+ };
168
+
169
+ })(typeof exports !== 'undefined' ? exports : this);