mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 06:44:44 +00:00
Fix compatibility with Node (including loadSVGFromString).
This commit is contained in:
parent
e85045d86a
commit
581d5a54b9
8 changed files with 43 additions and 25 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*! Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */
|
||||
|
||||
var fabric = fabric || { version: "0.8.41" };
|
||||
var fabric = fabric || { version: "0.8.42" };
|
||||
|
||||
if (typeof exports != 'undefined') {
|
||||
exports.fabric = fabric;
|
||||
|
|
|
|||
35
dist/all.js
vendored
35
dist/all.js
vendored
|
|
@ -1,7 +1,7 @@
|
|||
/* build: `node build.js modules=ALL` */
|
||||
/*! Fabric.js Copyright 2008-2012, Printio (Juriy Zaytsev, Maxim Chernyak) */
|
||||
|
||||
var fabric = fabric || { version: "0.8.41" };
|
||||
var fabric = fabric || { version: "0.8.42" };
|
||||
|
||||
if (typeof exports != 'undefined') {
|
||||
exports.fabric = fabric;
|
||||
|
|
@ -2675,7 +2675,7 @@ fabric.util.string = {
|
|||
|
||||
})(this);
|
||||
(function () {
|
||||
|
||||
|
||||
/**
|
||||
* Cross-browser wrapper for setting element's style
|
||||
* @method setStyle
|
||||
|
|
@ -2686,10 +2686,13 @@ fabric.util.string = {
|
|||
*/
|
||||
function setStyle(element, styles) {
|
||||
var elementStyle = element.style, match;
|
||||
if (!elementStyle) {
|
||||
return element;
|
||||
}
|
||||
if (typeof styles === 'string') {
|
||||
element.style.cssText += ';' + styles;
|
||||
return styles.indexOf('opacity') > -1
|
||||
? setOpacity(element, styles.match(/opacity:\s*(\d?\.?\d*)/)[1])
|
||||
return styles.indexOf('opacity') > -1
|
||||
? setOpacity(element, styles.match(/opacity:\s*(\d?\.?\d*)/)[1])
|
||||
: element;
|
||||
}
|
||||
for (var property in styles) {
|
||||
|
|
@ -2697,8 +2700,8 @@ fabric.util.string = {
|
|||
setOpacity(element, styles[property]);
|
||||
}
|
||||
else {
|
||||
var normalizedProperty = (property === 'float' || property === 'cssFloat')
|
||||
? (typeof elementStyle.styleFloat === 'undefined' ? 'cssFloat' : 'styleFloat')
|
||||
var normalizedProperty = (property === 'float' || property === 'cssFloat')
|
||||
? (typeof elementStyle.styleFloat === 'undefined' ? 'cssFloat' : 'styleFloat')
|
||||
: property;
|
||||
elementStyle[normalizedProperty] = styles[property];
|
||||
}
|
||||
|
|
@ -2707,12 +2710,12 @@ fabric.util.string = {
|
|||
}
|
||||
|
||||
var parseEl = fabric.document.createElement('div'),
|
||||
supportsOpacity = typeof parseEl.style.opacity === 'string',
|
||||
supportsOpacity = typeof parseEl.style.opacity === 'string',
|
||||
supportsFilters = typeof parseEl.style.filter === 'string',
|
||||
view = fabric.document.defaultView,
|
||||
supportsGCS = view && typeof view.getComputedStyle !== 'undefined',
|
||||
reOpacity = /alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,
|
||||
|
||||
|
||||
/** @ignore */
|
||||
setOpacity = function (element) { return element; };
|
||||
|
||||
|
|
@ -2742,7 +2745,7 @@ fabric.util.string = {
|
|||
}
|
||||
|
||||
fabric.util.setStyle = setStyle;
|
||||
|
||||
|
||||
})();
|
||||
(function() {
|
||||
|
||||
|
|
@ -5062,6 +5065,8 @@ fabric.util.string = {
|
|||
this.width = parseInt(this.lowerCanvasEl.width, 10) || 0;
|
||||
this.height = parseInt(this.lowerCanvasEl.height, 10) || 0;
|
||||
|
||||
if (!this.lowerCanvasEl.style) return;
|
||||
|
||||
this.lowerCanvasEl.style.width = this.width + 'px';
|
||||
this.lowerCanvasEl.style.height = this.height + 'px';
|
||||
},
|
||||
|
|
@ -13174,10 +13179,14 @@ fabric.Image.filters.GradientTransparency.fromObject = function(object) {
|
|||
fabric.loadSVGFromURL = function(url, callback) {
|
||||
url = url.replace(/^\n\s*/, '').replace(/\?.*$/, '').trim();
|
||||
request(url, '', function(body) {
|
||||
var doc = new DOMParser().parseFromString(body);
|
||||
fabric.parseSVGDocument(doc.documentElement, function(results, options) {
|
||||
callback(results, options);
|
||||
});
|
||||
fabric.loadSVGFromString(body, callback);
|
||||
});
|
||||
};
|
||||
|
||||
fabric.loadSVGFromString = function(string, callback) {
|
||||
var doc = new DOMParser().parseFromString(string);
|
||||
fabric.parseSVGDocument(doc.documentElement, function(results, options) {
|
||||
callback(results, options);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
4
dist/all.min.js
vendored
4
dist/all.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/all.min.js.gz
vendored
BIN
dist/all.min.js.gz
vendored
Binary file not shown.
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "fabric",
|
||||
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.42",
|
||||
"author": "Juriy Zaytsev <kangax@gmail.com>",
|
||||
"keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"],
|
||||
"repository": "git://github.com/kangax/fabric.js",
|
||||
|
|
|
|||
|
|
@ -213,6 +213,8 @@
|
|||
this.width = parseInt(this.lowerCanvasEl.width, 10) || 0;
|
||||
this.height = parseInt(this.lowerCanvasEl.height, 10) || 0;
|
||||
|
||||
if (!this.lowerCanvasEl.style) return;
|
||||
|
||||
this.lowerCanvasEl.style.width = this.width + 'px';
|
||||
this.lowerCanvasEl.style.height = this.height + 'px';
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(function () {
|
||||
|
||||
|
||||
/**
|
||||
* Cross-browser wrapper for setting element's style
|
||||
* @method setStyle
|
||||
|
|
@ -10,10 +10,13 @@
|
|||
*/
|
||||
function setStyle(element, styles) {
|
||||
var elementStyle = element.style, match;
|
||||
if (!elementStyle) {
|
||||
return element;
|
||||
}
|
||||
if (typeof styles === 'string') {
|
||||
element.style.cssText += ';' + styles;
|
||||
return styles.indexOf('opacity') > -1
|
||||
? setOpacity(element, styles.match(/opacity:\s*(\d?\.?\d*)/)[1])
|
||||
return styles.indexOf('opacity') > -1
|
||||
? setOpacity(element, styles.match(/opacity:\s*(\d?\.?\d*)/)[1])
|
||||
: element;
|
||||
}
|
||||
for (var property in styles) {
|
||||
|
|
@ -21,8 +24,8 @@
|
|||
setOpacity(element, styles[property]);
|
||||
}
|
||||
else {
|
||||
var normalizedProperty = (property === 'float' || property === 'cssFloat')
|
||||
? (typeof elementStyle.styleFloat === 'undefined' ? 'cssFloat' : 'styleFloat')
|
||||
var normalizedProperty = (property === 'float' || property === 'cssFloat')
|
||||
? (typeof elementStyle.styleFloat === 'undefined' ? 'cssFloat' : 'styleFloat')
|
||||
: property;
|
||||
elementStyle[normalizedProperty] = styles[property];
|
||||
}
|
||||
|
|
@ -31,12 +34,12 @@
|
|||
}
|
||||
|
||||
var parseEl = fabric.document.createElement('div'),
|
||||
supportsOpacity = typeof parseEl.style.opacity === 'string',
|
||||
supportsOpacity = typeof parseEl.style.opacity === 'string',
|
||||
supportsFilters = typeof parseEl.style.filter === 'string',
|
||||
view = fabric.document.defaultView,
|
||||
supportsGCS = view && typeof view.getComputedStyle !== 'undefined',
|
||||
reOpacity = /alpha\s*\(\s*opacity\s*=\s*([^\)]+)\)/,
|
||||
|
||||
|
||||
/** @ignore */
|
||||
setOpacity = function (element) { return element; };
|
||||
|
||||
|
|
@ -66,5 +69,5 @@
|
|||
}
|
||||
|
||||
fabric.util.setStyle = setStyle;
|
||||
|
||||
|
||||
})();
|
||||
4
test.js
4
test.js
|
|
@ -1,5 +1,9 @@
|
|||
var testrunner = require('qunit');
|
||||
|
||||
testrunner.options.log.summary = false;
|
||||
testrunner.options.log.tests = false;
|
||||
testrunner.options.log.assertions = false;
|
||||
|
||||
testrunner.run({
|
||||
code: "./dist/all.js",
|
||||
tests: [
|
||||
|
|
|
|||
Loading…
Reference in a new issue