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,35 @@
1
+ (function() {
2
+
3
+ var slice = Array.prototype.slice,
4
+ apply = Function.prototype.apply,
5
+ Dummy = function() { };
6
+
7
+ if (!Function.prototype.bind) {
8
+ /**
9
+ * Cross-browser approximation of ES5 Function.prototype.bind (not fully spec conforming)
10
+ * @see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind">Function#bind on MDN</a>
11
+ * @param {Object} thisArg Object to bind function to
12
+ * @param {Any[]} [...] Values to pass to a bound function
13
+ * @return {Function}
14
+ */
15
+ Function.prototype.bind = function(thisArg) {
16
+ var fn = this, args = slice.call(arguments, 1), bound;
17
+ if (args.length) {
18
+ bound = function() {
19
+ return apply.call(fn, this instanceof Dummy ? this : thisArg, args.concat(slice.call(arguments)));
20
+ };
21
+ }
22
+ else {
23
+ /** @ignore */
24
+ bound = function() {
25
+ return apply.call(fn, this instanceof Dummy ? this : thisArg, arguments);
26
+ };
27
+ }
28
+ Dummy.prototype = this.prototype;
29
+ bound.prototype = new Dummy();
30
+
31
+ return bound;
32
+ };
33
+ }
34
+
35
+ })();
@@ -0,0 +1,34 @@
1
+ (function(){
2
+
3
+ /**
4
+ * Copies all enumerable properties of one object to another
5
+ * @memberOf fabric.util.object
6
+ * @method extend
7
+ * @param {Object} destination Where to copy to
8
+ * @param {Object} source Where to copy from
9
+ */
10
+ function extend(destination, source) {
11
+ // JScript DontEnum bug is not taken care of
12
+ for (var property in source) {
13
+ destination[property] = source[property];
14
+ }
15
+ return destination;
16
+ }
17
+
18
+ /**
19
+ * Creates an empty object and copies all enumerable properties of another object to it
20
+ * @method clone
21
+ * @memberOf fabric.util.object
22
+ * @param {Object} object Object to clone
23
+ */
24
+ function clone(object) {
25
+ return extend({ }, object);
26
+ }
27
+
28
+ /** @namespace fabric.util.object */
29
+ fabric.util.object = {
30
+ extend: extend,
31
+ clone: clone
32
+ };
33
+
34
+ })();
@@ -0,0 +1,60 @@
1
+ (function() {
2
+
3
+ if (!String.prototype.trim) {
4
+ /**
5
+ * Trims a string (removing whitespace from the beginning and the end)
6
+ * @method trim
7
+ * @see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim">String#trim on MDN</a>
8
+ */
9
+ String.prototype.trim = function () {
10
+ // this trim is not fully ES3 or ES5 compliant, but it should cover most cases for now
11
+ return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '');
12
+ };
13
+ }
14
+
15
+ /**
16
+ * Camelizes a string
17
+ * @memberOf fabric.util.string
18
+ * @method camelize
19
+ * @param {String} string String to camelize
20
+ * @return {String} Camelized version of a string
21
+ */
22
+ function camelize(string) {
23
+ return string.replace(/-+(.)?/g, function(match, character) {
24
+ return character ? character.toUpperCase() : '';
25
+ });
26
+ }
27
+
28
+ /**
29
+ * Capitalizes a string
30
+ * @memberOf fabric.util.string
31
+ * @method capitalize
32
+ * @param {String} string String to capitalize
33
+ * @return {String} Capitalized version of a string
34
+ */
35
+ function capitalize(string) {
36
+ return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
37
+ }
38
+
39
+ /**
40
+ * Escapes XML in a string
41
+ * @memberOf fabric.util.string
42
+ * @method escapeXml
43
+ * @param {String} string String to escape
44
+ * @return {String} Escaped version of a string
45
+ */
46
+ function escapeXml(string) {
47
+ return string.replace(/&/g, '&amp;')
48
+ .replace(/"/g, '&quot;')
49
+ .replace(/'/g, '&apos;')
50
+ .replace(/</g, '&lt;')
51
+ .replace(/>/g, '&gt;');
52
+ }
53
+
54
+ /** @namespace */
55
+ fabric.util.string = {
56
+ camelize: camelize,
57
+ capitalize: capitalize,
58
+ escapeXml: escapeXml
59
+ };
60
+ }());
@@ -0,0 +1,406 @@
1
+ (function() {
2
+
3
+ var sqrt = Math.sqrt,
4
+ atan2 = Math.atan2;
5
+
6
+ /**
7
+ * @namespace
8
+ */
9
+ fabric.util = { };
10
+
11
+ /**
12
+ * Removes value from an array.
13
+ * Presence of value (and its position in an array) is determined via `Array.prototype.indexOf`
14
+ * @static
15
+ * @memberOf fabric.util
16
+ * @method removeFromArray
17
+ * @param {Array} array
18
+ * @param {Any} value
19
+ * @return {Array} original array
20
+ */
21
+ function removeFromArray(array, value) {
22
+ var idx = array.indexOf(value);
23
+ if (idx !== -1) {
24
+ array.splice(idx, 1);
25
+ }
26
+ return array;
27
+ }
28
+
29
+ /**
30
+ * Returns random number between 2 specified ones.
31
+ * @static
32
+ * @method getRandomInt
33
+ * @memberOf fabric.util
34
+ * @param {Number} min lower limit
35
+ * @param {Number} max upper limit
36
+ * @return {Number} random value (between min and max)
37
+ */
38
+ function getRandomInt(min, max) {
39
+ return Math.floor(Math.random() * (max - min + 1)) + min;
40
+ }
41
+
42
+ var PiBy180 = Math.PI / 180;
43
+
44
+ /**
45
+ * Transforms degrees to radians.
46
+ * @static
47
+ * @method degreesToRadians
48
+ * @memberOf fabric.util
49
+ * @param {Number} degrees value in degrees
50
+ * @return {Number} value in radians
51
+ */
52
+ function degreesToRadians(degrees) {
53
+ return degrees * PiBy180;
54
+ }
55
+
56
+ /**
57
+ * Transforms radians to degrees.
58
+ * @static
59
+ * @method radiansToDegrees
60
+ * @memberOf fabric.util
61
+ * @param {Number} radians value in radians
62
+ * @return {Number} value in degrees
63
+ */
64
+ function radiansToDegrees(radians) {
65
+ return radians / PiBy180;
66
+ }
67
+
68
+ /**
69
+ * Rotates `point` around `origin` with `radians`
70
+ * @static
71
+ * @method rotatePoint
72
+ * @memberOf fabric.util
73
+ * @param {fabric.Point} The point to rotate
74
+ * @param {fabric.Point} The origin of the rotation
75
+ * @param {Number} The radians of the angle for the rotation
76
+ * @return {fabric.Point} The new rotated point
77
+ */
78
+ function rotatePoint(point, origin, radians) {
79
+ var sin = Math.sin(radians),
80
+ cos = Math.cos(radians);
81
+
82
+ point.subtractEquals(origin);
83
+
84
+ var rx = point.x * cos - point.y * sin;
85
+ var ry = point.x * sin + point.y * cos;
86
+
87
+ return new fabric.Point(rx, ry).addEquals(origin);
88
+ }
89
+
90
+ /**
91
+ * A wrapper around Number#toFixed, which contrary to native method returns number, not string.
92
+ * @static
93
+ * @method toFixed
94
+ * @memberOf fabric.util
95
+ * @param {Number | String} number number to operate on
96
+ * @param {Number} fractionDigits number of fraction digits to "leave"
97
+ * @return {Number}
98
+ */
99
+ function toFixed(number, fractionDigits) {
100
+ return parseFloat(Number(number).toFixed(fractionDigits));
101
+ }
102
+
103
+ /**
104
+ * Function which always returns `false`.
105
+ * @static
106
+ * @method falseFunction
107
+ * @memberOf fabric.util
108
+ * @return {Boolean}
109
+ */
110
+ function falseFunction() {
111
+ return false;
112
+ }
113
+
114
+ /**
115
+ * Changes value from one to another within certain period of time, invoking callbacks as value is being changed.
116
+ * @method animate
117
+ * @memberOf fabric.util
118
+ * @param {Object} [options] Animation options
119
+ * @param {Function} [options.onChange] Callback; invoked on every value change
120
+ * @param {Function} [options.onComplete] Callback; invoked when value change is completed
121
+ * @param {Number} [options.startValue=0] Starting value
122
+ * @param {Number} [options.endValue=100] Ending value
123
+ * @param {Number} [options.byValue=100] Value to modify the property by
124
+ * @param {Function} [options.easing] Easing function
125
+ * @param {Number} [options.duration=500] Duration of change
126
+ */
127
+ function animate(options) {
128
+
129
+ options || (options = { });
130
+
131
+ var start = +new Date(),
132
+ duration = options.duration || 500,
133
+ finish = start + duration, time,
134
+ onChange = options.onChange || function() { },
135
+ abort = options.abort || function() { return false; },
136
+ easing = options.easing || function(t, b, c, d) {return -c * Math.cos(t/d * (Math.PI/2)) + c + b;},
137
+ startValue = 'startValue' in options ? options.startValue : 0,
138
+ endValue = 'endValue' in options ? options.endValue : 100,
139
+ byValue = options.byValue || endValue - startValue;
140
+
141
+ options.onStart && options.onStart();
142
+
143
+ (function tick() {
144
+ time = +new Date();
145
+ var currentTime = time > finish ? duration : (time - start);
146
+ onChange(easing(currentTime, startValue, byValue, duration));
147
+ if (time > finish || abort()) {
148
+ options.onComplete && options.onComplete();
149
+ return;
150
+ }
151
+ requestAnimFrame(tick);
152
+ })();
153
+ }
154
+
155
+ var _requestAnimFrame = fabric.window.requestAnimationFrame ||
156
+ fabric.window.webkitRequestAnimationFrame ||
157
+ fabric.window.mozRequestAnimationFrame ||
158
+ fabric.window.oRequestAnimationFrame ||
159
+ fabric.window.msRequestAnimationFrame ||
160
+ function(callback) {
161
+ fabric.window.setTimeout(callback, 1000 / 60);
162
+ };
163
+ /**
164
+ * requestAnimationFrame polyfill based on http://paulirish.com/2011/requestanimationframe-for-smart-animating/
165
+ * @method requestAnimFrame
166
+ * @memberOf fabric.util
167
+ * @param {Function} callback Callback to invoke
168
+ * @param {DOMElement} element optional Element to associate with animation
169
+ */
170
+ var requestAnimFrame = function() {
171
+ return _requestAnimFrame.apply(fabric.window, arguments);
172
+ };
173
+
174
+ /**
175
+ * Loads image element from given url and passes it to a callback
176
+ * @method loadImage
177
+ * @memberOf fabric.util
178
+ * @param {String} url URL representing an image
179
+ * @param {Function} callback Callback; invoked with loaded image
180
+ * @param {Any} context optional Context to invoke callback in
181
+ */
182
+ function loadImage(url, callback, context) {
183
+ if (url) {
184
+ var img = new Image();
185
+ /** @ignore */
186
+ img.onload = function () {
187
+ callback && callback.call(context, img);
188
+ img = img.onload = null;
189
+ };
190
+ img.src = url;
191
+ }
192
+ else {
193
+ callback && callback.call(context, url);
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Creates corresponding fabric instances from their object representations
199
+ * @static
200
+ * @memberOf fabric.util
201
+ * @method enlivenObjects
202
+ * @param {Array} objects Objects to enliven
203
+ * @param {Function} callback Callback to invoke when all objects are created
204
+ */
205
+ function enlivenObjects(objects, callback) {
206
+
207
+ function getKlass(type) {
208
+ return fabric[fabric.util.string.camelize(fabric.util.string.capitalize(type))];
209
+ }
210
+
211
+ function onLoaded() {
212
+ if (++numLoadedObjects === numTotalObjects) {
213
+ if (callback) {
214
+ callback(enlivenedObjects);
215
+ }
216
+ }
217
+ }
218
+
219
+ var enlivenedObjects = [ ],
220
+ numLoadedObjects = 0,
221
+ numTotalObjects = objects.length;
222
+
223
+ objects.forEach(function (o, index) {
224
+ if (!o.type) {
225
+ return;
226
+ }
227
+ var klass = getKlass(o.type);
228
+ if (klass.async) {
229
+ klass.fromObject(o, function (o, error) {
230
+ if (!error) {
231
+ enlivenedObjects[index] = o;
232
+ }
233
+ onLoaded();
234
+ });
235
+ }
236
+ else {
237
+ enlivenedObjects[index] = klass.fromObject(o);
238
+ onLoaded();
239
+ }
240
+ });
241
+ }
242
+
243
+ /**
244
+ * Groups SVG elements (usually those retrieved from SVG document)
245
+ * @static
246
+ * @memberOf fabric.util
247
+ * @method groupSVGElements
248
+ * @param {Array} elements SVG elements to group
249
+ * @param {Object} [options] Options object
250
+ * @return {fabric.Object|fabric.PathGroup}
251
+ */
252
+ function groupSVGElements(elements, options, path) {
253
+ var object;
254
+
255
+ if (elements.length > 1) {
256
+ var hasText = elements.some(function(el) { return el.type === 'text'; });
257
+
258
+ if (hasText) {
259
+ object = new fabric.Group([ ], options);
260
+ elements.reverse().forEach(function(obj) {
261
+ if (obj.cx) {
262
+ obj.left = obj.cx;
263
+ }
264
+ if (obj.cy) {
265
+ obj.top = obj.cy;
266
+ }
267
+ object.addWithUpdate(obj);
268
+ });
269
+ }
270
+ else {
271
+ object = new fabric.PathGroup(elements, options);
272
+ }
273
+ }
274
+ else {
275
+ object = elements[0];
276
+ }
277
+
278
+ if (typeof path !== 'undefined') {
279
+ object.setSourcePath(path);
280
+ }
281
+ return object;
282
+ }
283
+
284
+ /**
285
+ * Populates an object with properties of another object
286
+ * @static
287
+ * @memberOf fabric.util
288
+ * @method populateWithProperties
289
+ * @param {Object} source Source object
290
+ * @param {Object} destination Destination object
291
+ * @return {Array} properties Propertie names to include
292
+ */
293
+ function populateWithProperties(source, destination, properties) {
294
+ if (properties && Object.prototype.toString.call(properties) === '[object Array]') {
295
+ for (var i = 0, len = properties.length; i < len; i++) {
296
+ destination[properties[i]] = source[properties[i]];
297
+ }
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Draws a dashed line between two points
303
+ *
304
+ * This method is used to draw dashed line around selection area.
305
+ * See <a href="http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas">dotted stroke in canvas</a>
306
+ *
307
+ * @method drawDashedLine
308
+ * @param ctx {Canvas} context
309
+ * @param x {Number} start x coordinate
310
+ * @param y {Number} start y coordinate
311
+ * @param x2 {Number} end x coordinate
312
+ * @param y2 {Number} end y coordinate
313
+ * @param da {Array} dash array pattern
314
+ */
315
+ function drawDashedLine(ctx, x, y, x2, y2, da) {
316
+ var dx = x2 - x,
317
+ dy = y2 - y,
318
+ len = sqrt(dx*dx + dy*dy),
319
+ rot = atan2(dy, dx),
320
+ dc = da.length,
321
+ di = 0,
322
+ draw = true;
323
+
324
+ ctx.save();
325
+ ctx.translate(x, y);
326
+ ctx.moveTo(0, 0);
327
+ ctx.rotate(rot);
328
+
329
+ x = 0;
330
+ while (len > x) {
331
+ x += da[di++ % dc];
332
+ if (x > len) {
333
+ x = len;
334
+ }
335
+ ctx[draw ? 'lineTo' : 'moveTo'](x, 0);
336
+ draw = !draw;
337
+ }
338
+
339
+ ctx.restore();
340
+ }
341
+
342
+ /**
343
+ * Creates canvas element and initializes it via excanvas if necessary
344
+ * @static
345
+ * @memberOf fabric.util
346
+ * @method createCanvasElement
347
+ * @param {CanvasElement} [canvasEl] optional canvas element to initialize; when not given, element is created implicitly
348
+ * @return {CanvasElement} initialized canvas element
349
+ */
350
+ function createCanvasElement(canvasEl) {
351
+ canvasEl || (canvasEl = fabric.document.createElement('canvas'));
352
+ if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') {
353
+ G_vmlCanvasManager.initElement(canvasEl);
354
+ }
355
+ return canvasEl;
356
+ }
357
+
358
+ /**
359
+ * Creates accessors (getXXX, setXXX) for a "class", based on "stateProperties" array
360
+ * @static
361
+ * @memberOf fabric.util
362
+ * @method createAccessors
363
+ * @param {Object} klass "Class" to create accessors for
364
+ */
365
+ function createAccessors(klass) {
366
+ var proto = klass.prototype;
367
+
368
+ for (var i = proto.stateProperties.length; i--; ) {
369
+
370
+ var propName = proto.stateProperties[i],
371
+ capitalizedPropName = propName.charAt(0).toUpperCase() + propName.slice(1),
372
+ setterName = 'set' + capitalizedPropName,
373
+ getterName = 'get' + capitalizedPropName;
374
+
375
+ // using `new Function` for better introspection
376
+ if (!proto[getterName]) {
377
+ proto[getterName] = (function(property) {
378
+ return new Function('return this.get("' + property + '")');
379
+ })(propName);
380
+ }
381
+ if (!proto[setterName]) {
382
+ proto[setterName] = (function(property) {
383
+ return new Function('value', 'return this.set("' + property + '", value)');
384
+ })(propName);
385
+ }
386
+ }
387
+ }
388
+
389
+ fabric.util.removeFromArray = removeFromArray;
390
+ fabric.util.degreesToRadians = degreesToRadians;
391
+ fabric.util.radiansToDegrees = radiansToDegrees;
392
+ fabric.util.rotatePoint = rotatePoint;
393
+ fabric.util.toFixed = toFixed;
394
+ fabric.util.getRandomInt = getRandomInt;
395
+ fabric.util.falseFunction = falseFunction;
396
+ fabric.util.animate = animate;
397
+ fabric.util.requestAnimFrame = requestAnimFrame;
398
+ fabric.util.loadImage = loadImage;
399
+ fabric.util.enlivenObjects = enlivenObjects;
400
+ fabric.util.groupSVGElements = groupSVGElements;
401
+ fabric.util.populateWithProperties = populateWithProperties;
402
+ fabric.util.drawDashedLine = drawDashedLine;
403
+ fabric.util.createCanvasElement = createCanvasElement;
404
+ fabric.util.createAccessors = createAccessors;
405
+
406
+ })();