mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 14:54:42 +00:00
built-dist
This commit is contained in:
parent
188fed21f5
commit
6c3f18ae1c
4 changed files with 12019 additions and 588 deletions
678
dist/fabric.js
vendored
678
dist/fabric.js
vendored
|
|
@ -1,7 +1,7 @@
|
|||
/* build: `node build.js modules=ALL exclude=gestures minifier=uglifyjs` */
|
||||
/* build: `node build.js modules=ALL exclude=gestures,json minifier=uglifyjs` */
|
||||
/*! Fabric.js Copyright 2008-2015, Printio (Juriy Zaytsev, Maxim Chernyak) */
|
||||
|
||||
var fabric = fabric || { version: "1.6.0" };
|
||||
var fabric = fabric || { version: "1.6.0-rc.1" };
|
||||
if (typeof exports !== 'undefined') {
|
||||
exports.fabric = fabric;
|
||||
}
|
||||
|
|
@ -71,497 +71,6 @@ fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
|
|||
1;
|
||||
|
||||
|
||||
/*
|
||||
json2.js
|
||||
2014-02-04
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, regexp: true */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (typeof JSON !== 'object') {
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function () {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z'
|
||||
: null;
|
||||
};
|
||||
|
||||
String.prototype.toJSON =
|
||||
Number.prototype.toJSON =
|
||||
Boolean.prototype.toJSON = function () {
|
||||
return this.valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
var cx,
|
||||
escapable,
|
||||
gap,
|
||||
indent,
|
||||
meta,
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string'
|
||||
? c
|
||||
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
};
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function'
|
||||
? walk({'': j}, '')
|
||||
: j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
/**
|
||||
|
|
@ -573,12 +82,12 @@ if (typeof JSON !== 'object') {
|
|||
if (!this.__eventListeners[eventName]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var eventListener = this.__eventListeners[eventName];
|
||||
if (handler) {
|
||||
fabric.util.removeFromArray(this.__eventListeners[eventName], handler);
|
||||
eventListener[eventListener.indexOf(handler)] = false;
|
||||
}
|
||||
else {
|
||||
this.__eventListeners[eventName].length = 0;
|
||||
fabric.util.array.fill(eventListener, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -629,7 +138,9 @@ if (typeof JSON !== 'object') {
|
|||
|
||||
// remove all key/value pairs (event name -> event handler)
|
||||
if (arguments.length === 0) {
|
||||
this.__eventListeners = { };
|
||||
for (eventName in this.__eventListeners) {
|
||||
_removeEventListener.call(this, eventName);
|
||||
}
|
||||
}
|
||||
// one object with key/value pairs was passed
|
||||
else if (arguments.length === 1 && typeof arguments[0] === 'object') {
|
||||
|
|
@ -664,9 +175,11 @@ if (typeof JSON !== 'object') {
|
|||
}
|
||||
|
||||
for (var i = 0, len = listenersForEvent.length; i < len; i++) {
|
||||
// avoiding try/catch for perf. reasons
|
||||
listenersForEvent[i].call(this, options || { });
|
||||
listenersForEvent[i] && listenersForEvent[i].call(this, options || { });
|
||||
}
|
||||
this.__eventListeners[eventName] = listenersForEvent.filter(function(value) {
|
||||
return value !== false;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -1956,6 +1469,17 @@ fabric.Collection = {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function fill(array, value) {
|
||||
var k = array.length;
|
||||
while (k--) {
|
||||
array[k] = value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
|
@ -1987,6 +1511,7 @@ fabric.Collection = {
|
|||
* @namespace fabric.util.array
|
||||
*/
|
||||
fabric.util.array = {
|
||||
fill: fill,
|
||||
invoke: invoke,
|
||||
min: min,
|
||||
max: max
|
||||
|
|
@ -3024,7 +2549,13 @@ if (typeof console !== 'undefined') {
|
|||
s = p / 4;
|
||||
}
|
||||
else {
|
||||
s = p / (2 * Math.PI) * Math.asin(c / a);
|
||||
//handle the 0/0 case:
|
||||
if (c === 0 && a === 0) {
|
||||
s = p / (2 * Math.PI) * Math.asin(1);
|
||||
}
|
||||
else {
|
||||
s = p / (2 * Math.PI) * Math.asin(c / a);
|
||||
}
|
||||
}
|
||||
return { a: a, c: c, p: p, s: s };
|
||||
}
|
||||
|
|
@ -3518,11 +3049,11 @@ if (typeof console !== 'undefined') {
|
|||
function _setStrokeFillOpacity(attributes) {
|
||||
for (var attr in colorAttributes) {
|
||||
|
||||
if (typeof attributes[colorAttributes[attr]] === 'undefined') {
|
||||
if (typeof attributes[colorAttributes[attr]] === 'undefined' || attributes[attr] === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!attributes[attr]) {
|
||||
if (typeof attributes[attr] === 'undefined') {
|
||||
if (!fabric.Object.prototype[attr]) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -6703,14 +6234,9 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
|
|||
_setImageSmoothing: function() {
|
||||
var ctx = this.getContext();
|
||||
|
||||
if (typeof ctx.imageSmoothingEnabled !== 'undefined') {
|
||||
ctx.imageSmoothingEnabled = this.imageSmoothingEnabled;
|
||||
return;
|
||||
}
|
||||
ctx.webkitImageSmoothingEnabled = this.imageSmoothingEnabled;
|
||||
ctx.mozImageSmoothingEnabled = this.imageSmoothingEnabled;
|
||||
ctx.msImageSmoothingEnabled = this.imageSmoothingEnabled;
|
||||
ctx.oImageSmoothingEnabled = this.imageSmoothingEnabled;
|
||||
ctx.imageSmoothingEnabled = ctx.imageSmoothingEnabled || ctx.webkitImageSmoothingEnabled
|
||||
|| ctx.mozImageSmoothingEnabled || ctx.msImageSmoothingEnabled || ctx.oImageSmoothingEnabled;
|
||||
ctx.imageSmoothingEnabled = this.imageSmoothingEnabled;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -7181,7 +6707,7 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
|
|||
renderAll: function () {
|
||||
var canvasToDrawOn = this.contextContainer, objsToRender;
|
||||
|
||||
if (this.contextTop && this.selection && !this._groupSelector) {
|
||||
if (this.contextTop && this.selection && !this._groupSelector && !this.isDrawingMode) {
|
||||
this.clearContext(this.contextTop);
|
||||
}
|
||||
|
||||
|
|
@ -9103,16 +8629,19 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
* @private
|
||||
* @param {Number} x pointer's x coordinate
|
||||
* @param {Number} y pointer's y coordinate
|
||||
* @return {Boolean} true if the translation occurred
|
||||
*/
|
||||
_translateObject: function (x, y) {
|
||||
var target = this._currentTransform.target;
|
||||
var transform = this._currentTransform,
|
||||
target = transform.target,
|
||||
newLeft = x - transform.offsetX,
|
||||
newTop = y - transform.offsetY,
|
||||
moveX = !target.get('lockMovementX') && target.left !== newLeft,
|
||||
moveY = !target.get('lockMovementY') && target.top !== newTop;
|
||||
|
||||
if (!target.get('lockMovementX')) {
|
||||
target.set('left', x - this._currentTransform.offsetX);
|
||||
}
|
||||
if (!target.get('lockMovementY')) {
|
||||
target.set('top', y - this._currentTransform.offsetY);
|
||||
}
|
||||
moveX && target.set('left', newLeft);
|
||||
moveY && target.set('top', newTop);
|
||||
return moveX || moveY;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -9156,15 +8685,16 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
* @param {Number} x pointer's x coordinate
|
||||
* @param {Number} y pointer's y coordinate
|
||||
* @param {String} by Either 'x' or 'y'
|
||||
* @return {Boolean} true if the skewing occurred
|
||||
*/
|
||||
_skewObject: function (x, y, by) {
|
||||
var t = this._currentTransform,
|
||||
target = t.target,
|
||||
target = t.target, skewed = false,
|
||||
lockSkewingX = target.get('lockSkewingX'),
|
||||
lockSkewingY = target.get('lockSkewingY');
|
||||
|
||||
if ((lockSkewingX && by === 'x') || (lockSkewingY && by === 'y')) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the constraint point
|
||||
|
|
@ -9178,15 +8708,21 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
|
||||
constraintPosition = target.translateToOriginPoint(center, t.originX, t.originY);
|
||||
// Actually skew the object
|
||||
this._setObjectSkew(actualMouseByOrigin, t, by, dim);
|
||||
skewed = this._setObjectSkew(actualMouseByOrigin, t, by, dim);
|
||||
t.lastX = x;
|
||||
t.lastY = y;
|
||||
// Make sure the constraints apply
|
||||
target.setPositionByOrigin(constraintPosition, t.originX, t.originY);
|
||||
return skewed;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set object skew
|
||||
* @private
|
||||
* @return {Boolean} true if the skewing occurred
|
||||
*/
|
||||
_setObjectSkew: function(localMouse, transform, by, _dim) {
|
||||
var target = transform.target, newValue,
|
||||
var target = transform.target, newValue, skewed = false,
|
||||
skewSign = transform.skewSign, newDim, dimNoSkew,
|
||||
otherBy, _otherBy, _by, newDimMouse, skewX, skewY;
|
||||
|
||||
|
|
@ -9215,12 +8751,14 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
(dimNoSkew[otherBy] / target['scale' + _otherBy]));
|
||||
newValue = fabric.util.radiansToDegrees(newValue);
|
||||
}
|
||||
skewed = target['skew' + _by] !== newValue;
|
||||
target.set('skew' + _by, newValue);
|
||||
if (target['skew' + _otherBy] !== 0) {
|
||||
newDim = target._getTransformedDimensions();
|
||||
newValue = (_dim[otherBy] / newDim[otherBy]) * target['scale' + _otherBy];
|
||||
target.set('scale' + _otherBy, newValue);
|
||||
}
|
||||
return skewed;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -9230,6 +8768,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
* @param {Number} y pointer's y coordinate
|
||||
* @param {String} by Either 'x' or 'y' - specifies dimension constraint by which to scale an object.
|
||||
* When not provided, an object is scaled by both dimensions equally
|
||||
* @return {Boolean} true if the scaling occurred
|
||||
*/
|
||||
_scaleObject: function (x, y, by) {
|
||||
var t = this._currentTransform,
|
||||
|
|
@ -9239,74 +8778,83 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
lockScalingFlip = target.get('lockScalingFlip');
|
||||
|
||||
if (lockScalingX && lockScalingY) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the constraint point
|
||||
var constraintPosition = target.translateToOriginPoint(target.getCenterPoint(), t.originX, t.originY),
|
||||
localMouse = target.toLocalPoint(new fabric.Point(x, y), t.originX, t.originY),
|
||||
dim = target._getTransformedDimensions();
|
||||
dim = target._getTransformedDimensions(), scaled = false;
|
||||
|
||||
this._setLocalMouse(localMouse, t);
|
||||
|
||||
// Actually scale the object
|
||||
this._setObjectScale(localMouse, t, lockScalingX, lockScalingY, by, lockScalingFlip, dim);
|
||||
scaled = this._setObjectScale(localMouse, t, lockScalingX, lockScalingY, by, lockScalingFlip, dim);
|
||||
|
||||
// Make sure the constraints apply
|
||||
target.setPositionByOrigin(constraintPosition, t.originX, t.originY);
|
||||
return scaled;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @return {Boolean} true if the scaling occurred
|
||||
*/
|
||||
_setObjectScale: function(localMouse, transform, lockScalingX, lockScalingY, by, lockScalingFlip, _dim) {
|
||||
var target = transform.target, forbidScalingX = false, forbidScalingY = false;
|
||||
var target = transform.target, forbidScalingX = false, forbidScalingY = false, scaled = false,
|
||||
changeX, changeY, scaleX, scaleY;
|
||||
|
||||
transform.newScaleX = localMouse.x * target.scaleX / _dim.x;
|
||||
transform.newScaleY = localMouse.y * target.scaleY / _dim.y;
|
||||
scaleX = localMouse.x * target.scaleX / _dim.x;
|
||||
scaleY = localMouse.y * target.scaleY / _dim.y;
|
||||
changeX = target.scaleX !== scaleX;
|
||||
changeY = target.scaleY !== scaleY;
|
||||
|
||||
if (lockScalingFlip && transform.newScaleX <= 0 && transform.newScaleX < target.scaleX) {
|
||||
if (lockScalingFlip && scaleX <= 0 && scaleX < target.scaleX) {
|
||||
forbidScalingX = true;
|
||||
}
|
||||
|
||||
if (lockScalingFlip && transform.newScaleY <= 0 && transform.newScaleY < target.scaleY) {
|
||||
if (lockScalingFlip && scaleY <= 0 && scaleY < target.scaleY) {
|
||||
forbidScalingY = true;
|
||||
}
|
||||
|
||||
if (by === 'equally' && !lockScalingX && !lockScalingY) {
|
||||
forbidScalingX || forbidScalingY || this._scaleObjectEqually(localMouse, target, transform, _dim);
|
||||
forbidScalingX || forbidScalingY || (scaled = this._scaleObjectEqually(localMouse, target, transform, _dim));
|
||||
}
|
||||
else if (!by) {
|
||||
forbidScalingX || lockScalingX || target.set('scaleX', transform.newScaleX);
|
||||
forbidScalingY || lockScalingY || target.set('scaleY', transform.newScaleY);
|
||||
forbidScalingX || lockScalingX || (target.set('scaleX', scaleX) && (scaled = scaled || changeX));
|
||||
forbidScalingY || lockScalingY || (target.set('scaleY', scaleY) && (scaled = scaled || changeY));
|
||||
}
|
||||
else if (by === 'x' && !target.get('lockUniScaling')) {
|
||||
forbidScalingX || lockScalingX || target.set('scaleX', transform.newScaleX);
|
||||
forbidScalingX || lockScalingX || (target.set('scaleX', scaleX) && (scaled = scaled || changeX));
|
||||
}
|
||||
else if (by === 'y' && !target.get('lockUniScaling')) {
|
||||
forbidScalingY || lockScalingY || target.set('scaleY', transform.newScaleY);
|
||||
forbidScalingY || lockScalingY || (target.set('scaleY', scaleY) && (scaled = scaled || changeY));
|
||||
}
|
||||
|
||||
transform.newScaleX = scaleX;
|
||||
transform.newScaleY = scaleY;
|
||||
forbidScalingX || forbidScalingY || this._flipObject(transform, by);
|
||||
|
||||
return scaled;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @return {Boolean} true if the scaling occurred
|
||||
*/
|
||||
_scaleObjectEqually: function(localMouse, target, transform, _dim) {
|
||||
|
||||
var dist = localMouse.y + localMouse.x,
|
||||
lastDist = _dim.y * transform.original.scaleY / target.scaleY +
|
||||
_dim.x * transform.original.scaleX / target.scaleX;
|
||||
_dim.x * transform.original.scaleX / target.scaleX,
|
||||
scaled;
|
||||
|
||||
// We use transform.scaleX/Y instead of target.scaleX/Y
|
||||
// because the object may have a min scale and we'll loose the proportions
|
||||
transform.newScaleX = transform.original.scaleX * dist / lastDist;
|
||||
transform.newScaleY = transform.original.scaleY * dist / lastDist;
|
||||
|
||||
scaled = transform.newScaleX !== target.scaleX || transform.newScaleY !== target.scaleY;
|
||||
target.set('scaleX', transform.newScaleX);
|
||||
target.set('scaleY', transform.newScaleY);
|
||||
return scaled;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -9391,13 +8939,14 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
* @private
|
||||
* @param {Number} x pointer's x coordinate
|
||||
* @param {Number} y pointer's y coordinate
|
||||
* @return {Boolean} true if the rotation occurred
|
||||
*/
|
||||
_rotateObject: function (x, y) {
|
||||
|
||||
var t = this._currentTransform;
|
||||
|
||||
if (t.target.get('lockRotation')) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
var lastAngle = atan2(t.ey - t.top, t.ex - t.left),
|
||||
|
|
@ -9410,6 +8959,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
}
|
||||
|
||||
t.target.angle = angle % 360;
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -10243,14 +9793,12 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
}
|
||||
|
||||
target.setCoords();
|
||||
this._restoreOriginXY(target);
|
||||
|
||||
// only fire :modified event if target coordinates were changed during mousedown-mouseup
|
||||
if (this.stateful && target.hasStateChanged()) {
|
||||
if (transform.actionPerformed || (this.stateful && target.hasStateChanged())) {
|
||||
this.fire('object:modified', { target: target });
|
||||
target.fire('modified');
|
||||
}
|
||||
|
||||
this._restoreOriginXY(target);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -10508,6 +10056,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
}
|
||||
}
|
||||
else {
|
||||
|
||||
this._transformObject(e);
|
||||
}
|
||||
|
||||
|
|
@ -10539,37 +10088,32 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
var x = pointer.x,
|
||||
y = pointer.y,
|
||||
target = transform.target,
|
||||
action = transform.action;
|
||||
action = transform.action,
|
||||
actionPerformed = false;
|
||||
|
||||
if (action === 'rotate') {
|
||||
this._rotateObject(x, y);
|
||||
this._fire('rotating', target, e);
|
||||
(actionPerformed = this._rotateObject(x, y)) && this._fire('rotating', target, e);
|
||||
}
|
||||
else if (action === 'scale') {
|
||||
this._onScale(e, transform, x, y);
|
||||
this._fire('scaling', target, e);
|
||||
(actionPerformed = this._onScale(e, transform, x, y)) && this._fire('scaling', target, e);
|
||||
}
|
||||
else if (action === 'scaleX') {
|
||||
this._scaleObject(x, y, 'x');
|
||||
this._fire('scaling', target, e);
|
||||
(actionPerformed = this._scaleObject(x, y, 'x')) && this._fire('scaling', target, e);
|
||||
}
|
||||
else if (action === 'scaleY') {
|
||||
this._scaleObject(x, y, 'y');
|
||||
this._fire('scaling', target, e);
|
||||
(actionPerformed = this._scaleObject(x, y, 'y')) && this._fire('scaling', target, e);
|
||||
}
|
||||
else if (action === 'skewX') {
|
||||
this._skewObject(x, y, 'x');
|
||||
this._fire('skewing', target, e);
|
||||
(actionPerformed = this._skewObject(x, y, 'x')) && this._fire('skewing', target, e);
|
||||
}
|
||||
else if (action === 'skewY') {
|
||||
this._skewObject(x, y, 'y');
|
||||
this._fire('skewing', target, e);
|
||||
(actionPerformed = this._skewObject(x, y, 'y')) && this._fire('skewing', target, e);
|
||||
}
|
||||
else {
|
||||
this._translateObject(x, y);
|
||||
this._fire('moving', target, e);
|
||||
(actionPerformed = this._translateObject(x, y)) && this._fire('moving', target, e);
|
||||
this.setCursor(this.moveCursor);
|
||||
}
|
||||
transform.actionPerformed = actionPerformed;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -10600,13 +10144,14 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
|
||||
/**
|
||||
* @private
|
||||
* @return {Boolean} true if the scaling occurred
|
||||
*/
|
||||
_onScale: function(e, transform, x, y) {
|
||||
// rotate object only if shift key is not pressed
|
||||
// and if it is not a group we are transforming
|
||||
if ((e.shiftKey || this.uniScaleTransform) && !transform.target.get('lockUniScaling')) {
|
||||
transform.currentAction = 'scale';
|
||||
this._scaleObject(x, y);
|
||||
return this._scaleObject(x, y);
|
||||
}
|
||||
else {
|
||||
// Switch from a normal resize to proportional
|
||||
|
|
@ -10615,7 +10160,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
}
|
||||
|
||||
transform.currentAction = 'scaleEqually';
|
||||
this._scaleObject(x, y, 'equally');
|
||||
return this._scaleObject(x, y, 'equally');
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -15701,8 +15246,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
*/
|
||||
_render: function(ctx) {
|
||||
if (!fabric.Polygon.prototype.commonRender.call(this, ctx)) {
|
||||
_render: function(ctx, noTransform) {
|
||||
if (!fabric.Polygon.prototype.commonRender.call(this, ctx, noTransform)) {
|
||||
return;
|
||||
}
|
||||
this._renderFill(ctx);
|
||||
|
|
@ -17998,14 +17543,14 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
* @return {Object} Object representation of an instance
|
||||
*/
|
||||
toObject: function(propertiesToInclude) {
|
||||
var filters = [ ];
|
||||
var filters = [ ], element = this._originalElement;
|
||||
this.filters.forEach(function(filterObj) {
|
||||
if (filterObj) {
|
||||
filters.push(filterObj.toObject());
|
||||
}
|
||||
});
|
||||
var object = extend(this.callSuper('toObject', propertiesToInclude), {
|
||||
src: this._originalElement.src || this._originalElement._src,
|
||||
src: element ? element.src || element._src : '',
|
||||
filters: filters,
|
||||
crossOrigin: this.crossOrigin,
|
||||
alignX: this.alignX,
|
||||
|
|
@ -24835,10 +24380,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
var w = t.width * ((localMouse.x / transform.scaleX) / (t.width + t.strokeWidth));
|
||||
if (w >= t.getMinWidth()) {
|
||||
t.set('width', w);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
setObjectScaleOverridden.call(fabric.Canvas.prototype, localMouse, transform,
|
||||
return setObjectScaleOverridden.call(fabric.Canvas.prototype, localMouse, transform,
|
||||
lockScalingX, lockScalingY, by, lockScalingFlip, _dim);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
23
dist/fabric.min.js
vendored
23
dist/fabric.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/fabric.min.js.gz
vendored
BIN
dist/fabric.min.js.gz
vendored
Binary file not shown.
11906
dist/fabric.require.js
vendored
11906
dist/fabric.require.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue