aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-03-16 13:03:35 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-03-16 13:03:35 +0100
commit2e215f1bd2f6a83aee6f27756fc2b11036aaa097 (patch)
tree55ee0c7fce4db4c03f60f8fa2d83273a8f3d1562 /src
parent9bfcbc184ec99631ea7d2b912e79b1edde17a111 (diff)
parentaa8dcdbc571585ce8a957e49271babda88384096 (diff)
downloadsvg.js-2e215f1bd2f6a83aee6f27756fc2b11036aaa097.tar.gz
svg.js-2e215f1bd2f6a83aee6f27756fc2b11036aaa097.zip
Merge branch 'master' into 3.0.0
Conflicts (all resolved): dist/svg.js dist/svg.min.js spec/spec/boxes.js
Diffstat (limited to 'src')
-rw-r--r--src/color.js2
-rw-r--r--src/element.js2
-rw-r--r--src/helpers.js16
-rw-r--r--src/matrix.js2
-rw-r--r--src/pointarray.js4
-rw-r--r--src/regex.js7
-rw-r--r--src/transform.js6
7 files changed, 10 insertions, 29 deletions
diff --git a/src/color.js b/src/color.js
index 25f41d6..9d77d4e 100644
--- a/src/color.js
+++ b/src/color.js
@@ -13,7 +13,7 @@ SVG.Color = function(color) {
if (typeof color === 'string') {
if (SVG.regex.isRgb.test(color)) {
// get rgb values
- match = SVG.regex.rgb.exec(color.replace(/\s/g,''))
+ match = SVG.regex.rgb.exec(color.replace(SVG.regex.whitespace,''))
// parse numeric values
this.r = parseInt(match[1])
diff --git a/src/element.js b/src/element.js
index 37b324c..230aa4b 100644
--- a/src/element.js
+++ b/src/element.js
@@ -125,7 +125,7 @@ SVG.Element = SVG.invent({
, classes: function() {
var attr = this.attr('class')
- return attr == null ? [] : attr.trim().split(/\s+/)
+ return attr == null ? [] : attr.trim().split(SVG.regex.delimiter)
}
// Return true if class exists on the node, false otherwise
, hasClass: function(name) {
diff --git a/src/helpers.js b/src/helpers.js
index 41f9620..744a712 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -109,22 +109,6 @@ function ensureCentre(o, target) {
o.cy = o.cy == null ? target.bbox().cy : o.cy
}
-// Convert string to matrix
-function stringToMatrix(source) {
- // remove matrix wrapper and split to individual numbers
- source = source
- .replace(SVG.regex.whitespace, '')
- .replace(SVG.regex.matrix, '')
- .split(SVG.regex.matrixElements)
-
- // convert string values to floats and convert to a matrix-formatted object
- return arrayToMatrix(
- SVG.utils.map(source, function(n) {
- return parseFloat(n)
- })
- )
-}
-
// PathArray Helpers
function arrayToString(a) {
for (var i = 0, il = a.length, s = ''; i < il; i++) {
diff --git a/src/matrix.js b/src/matrix.js
index 60f3531..970e3be 100644
--- a/src/matrix.js
+++ b/src/matrix.js
@@ -7,7 +7,7 @@ SVG.Matrix = SVG.invent({
source = source instanceof SVG.Element ?
source.matrixify() :
typeof source === 'string' ?
- stringToMatrix(source) :
+ arrayToMatrix(source.split(SVG.regex.delimiter).map(parseFloat)) :
arguments.length == 6 ?
arrayToMatrix([].slice.call(arguments)) :
Array.isArray(source) ?
diff --git a/src/pointarray.js b/src/pointarray.js
index 58166a3..b0a3d54 100644
--- a/src/pointarray.js
+++ b/src/pointarray.js
@@ -53,7 +53,7 @@ SVG.extend(SVG.PointArray, {
}
} else { // Else, it is considered as a string
// parse points
- array = array.trim().split(/[\s,]+/)
+ array = array.trim().split(SVG.regex.delimiter).map(parseFloat)
}
// validate points - https://svgwg.org/svg2-draft/shapes.html#DataTypePoints
@@ -62,7 +62,7 @@ SVG.extend(SVG.PointArray, {
// wrap points in two-tuples and parse points as floats
for(var i = 0, len = array.length; i < len; i = i + 2)
- points.push([ parseFloat(array[i]), parseFloat(array[i+1]) ])
+ points.push([ array[i], array[i+1] ])
return points
}
diff --git a/src/regex.js b/src/regex.js
index c953805..c0ca706 100644
--- a/src/regex.js
+++ b/src/regex.js
@@ -12,11 +12,8 @@ SVG.regex = {
// Parse reference id
, reference: /#([a-z0-9\-_]+)/i
- // Parse matrix wrapper
-, matrix: /matrix\(|\)/g
-
- // Elements of a matrix
-, matrixElements: /,*\s+|,/
+ // splits a transformation chain
+, transforms: /\)\s*,?\s*/
// Whitespace
, whitespace: /\s/g
diff --git a/src/transform.js b/src/transform.js
index 170c205..f2061db 100644
--- a/src/transform.js
+++ b/src/transform.js
@@ -180,12 +180,12 @@ SVG.extend(SVG.Element, {
var matrix = (this.attr('transform') || '')
// split transformations
- .split(/\)\s*,?\s*/).slice(0,-1).map(function(str){
+ .split(SVG.regex.transforms).slice(0,-1).map(function(str){
// generate key => value pairs
var kv = str.trim().split('(')
- return [kv[0], kv[1].split(SVG.regex.matrixElements).map(function(str){ return parseFloat(str) })]
+ return [kv[0], kv[1].split(SVG.regex.delimiter).map(function(str){ return parseFloat(str) })]
})
- // calculate every transformation into one matrix
+ // merge every transformation into one matrix
.reduce(function(matrix, transform){
if(transform[0] == 'matrix') return matrix.multiply(arrayToMatrix(transform[1]))