diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-14 18:43:22 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-14 18:43:22 +0100 |
commit | af45360b7b2a8dc3f3eaed553f9544b4318e7348 (patch) | |
tree | 8da54a60d1c23854239996bc5318ccb87e8f1b15 /dist/svg.js | |
parent | 4b6e28689412a3fda9a52f2e665dbc536c87cd8f (diff) | |
download | svg.js-af45360b7b2a8dc3f3eaed553f9544b4318e7348.tar.gz svg.js-af45360b7b2a8dc3f3eaed553f9544b4318e7348.zip |
move most regexe to SVG.regex, fix matrix constructor for string argument
Diffstat (limited to 'dist/svg.js')
-rw-r--r-- | dist/svg.js | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/dist/svg.js b/dist/svg.js index 820d6db..44ebf7e 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -6,7 +6,7 @@ * @copyright Wout Fierens <wout@mick-wout.com> * @license MIT * -* BUILT: Fri Mar 10 2017 09:24:24 GMT+0100 (Mitteleuropäische Zeit) +* BUILT: Tue Mar 14 2017 18:41:25 GMT+0100 (Mitteleuropäische Zeit) */; (function(root, factory) { if (typeof define === 'function' && define.amd) { @@ -190,8 +190,8 @@ SVG.regex = { // Parse matrix wrapper , matrix: /matrix\(|\)/g - // Elements of a matrix -, matrixElements: /,*\s+|,/ + // splits a transformation chain +, transforms: /\)\s*,?\s*/ // Whitespace , whitespace: /\s/g @@ -330,7 +330,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]) @@ -562,7 +562,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 @@ -571,7 +571,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 } @@ -1142,7 +1142,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) { @@ -2343,7 +2343,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) ? @@ -2869,12 +2869,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])) @@ -5349,22 +5349,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++) { |