diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-05-04 21:35:21 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-05-04 21:35:21 +1000 |
commit | c8cb22863bf8c3ac157f6098be9154908aea9ec2 (patch) | |
tree | b27b1bf6ec4c90bbd0cb335e26bb9ece504285d2 /src/types | |
parent | 59f09a1a2317e57d13bbe8f60e1949cc82199ead (diff) | |
download | svg.js-c8cb22863bf8c3ac157f6098be9154908aea9ec2.tar.gz svg.js-c8cb22863bf8c3ac157f6098be9154908aea9ec2.zip |
Fixed IE Polyfills, got rid of ArrayPolyfill in favour of babels own transforms, updated dependencies, finished tests, removed old es5 tests
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/ArrayPolyfill.js | 36 | ||||
-rw-r--r-- | src/types/List.js | 19 | ||||
-rw-r--r-- | src/types/PathArray.js | 18 | ||||
-rw-r--r-- | src/types/PointArray.js | 26 | ||||
-rw-r--r-- | src/types/SVGArray.js | 27 |
5 files changed, 42 insertions, 84 deletions
diff --git a/src/types/ArrayPolyfill.js b/src/types/ArrayPolyfill.js deleted file mode 100644 index 4d2309f..0000000 --- a/src/types/ArrayPolyfill.js +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint no-new-func: "off" */ -export const subClassArray = (function () { - try { - // try es6 subclassing - return Function('name', 'baseClass', '_constructor', [ - 'baseClass = baseClass || Array', - 'return {', - ' [name]: class extends baseClass {', - ' constructor (...args) {', - ' super(...args)', - ' _constructor && _constructor.apply(this, args)', - ' }', - ' }', - '}[name]' - ].join('\n')) - } catch (e) { - // Use es5 approach - return (name, baseClass = Array, _constructor) => { - const Arr = function () { - baseClass.apply(this, arguments) - _constructor && _constructor.apply(this, arguments) - } - - Arr.prototype = Object.create(baseClass.prototype) - Arr.prototype.constructor = Arr - - Arr.prototype.map = function (fn) { - const arr = new Arr() - arr.push.apply(arr, Array.prototype.map.call(this, fn)) - return arr - } - - return Arr - } - } -})() diff --git a/src/types/List.js b/src/types/List.js index b68e362..197a155 100644 --- a/src/types/List.js +++ b/src/types/List.js @@ -1,16 +1,25 @@ import { extend } from '../utils/adopter.js' -import { subClassArray } from './ArrayPolyfill.js' +// import { subClassArray } from './ArrayPolyfill.js' + +class List extends Array { + constructor (arr = [], ...args) { + super(arr, ...args) + if (typeof arr === 'number') return this + this.length = 0 + this.push(...arr) + } +} -const List = subClassArray('List', Array, function (arr = []) { +/* = subClassArray('List', Array, function (arr = []) { // This catches the case, that native map tries to create an array with new Array(1) if (typeof arr === 'number') return this this.length = 0 this.push(...arr) -}) +}) */ export default List -extend(List, { +extend([ List ], { each (fnOrMethodName, ...args) { if (typeof fnOrMethodName === 'function') { return this.map((el, i, arr) => { @@ -45,5 +54,5 @@ List.extend = function (methods) { return obj }, {}) - extend(List, methods) + extend([ List ], methods) } diff --git a/src/types/PathArray.js b/src/types/PathArray.js index 03fdee3..d9c1eb2 100644 --- a/src/types/PathArray.js +++ b/src/types/PathArray.js @@ -6,17 +6,11 @@ import { numbersWithDots, pathLetters } from '../modules/core/regex.js' -import { extend } from '../utils/adopter.js' -import { subClassArray } from './ArrayPolyfill.js' import Point from './Point.js' import SVGArray from './SVGArray.js' import parser from '../modules/core/parser.js' import Box from './Box.js' -const PathArray = subClassArray('PathArray', SVGArray) - -export default PathArray - export function pathRegReplace (a, b, c, d) { return c + d.replace(dots, ' .') } @@ -130,11 +124,11 @@ for (var i = 0, il = mlhvqtcsaz.length; i < il; ++i) { })(mlhvqtcsaz[i].toUpperCase()) } -extend(PathArray, { +export default class PathArray extends SVGArray { // Convert array to string toString () { return arrayToString(this) - }, + } // Move path string move (x, y) { @@ -175,7 +169,7 @@ extend(PathArray, { } return this - }, + } // Resize path string size (width, height) { @@ -221,7 +215,7 @@ extend(PathArray, { } return this - }, + } // Absolutize and parse path to array parse (array = [ 'M', 0, 0 ]) { @@ -268,11 +262,11 @@ extend(PathArray, { } while (len > index) return result - }, + } // Get bounding box of path bbox () { parser().path.setAttribute('d', this.toString()) return new Box(parser.nodes.path.getBBox()) } -}) +} diff --git a/src/types/PointArray.js b/src/types/PointArray.js index 54df08f..27a2076 100644 --- a/src/types/PointArray.js +++ b/src/types/PointArray.js @@ -1,15 +1,9 @@ import { delimiter } from '../modules/core/regex.js' -import { extend } from '../utils/adopter.js' -import { subClassArray } from './ArrayPolyfill.js' import SVGArray from './SVGArray.js' -import { Matrix } from '../main.js' import Box from './Box.js' +import Matrix from './Matrix.js' -const PointArray = subClassArray('PointArray', SVGArray) - -export default PointArray - -extend(PointArray, { +export default class PointArray extends SVGArray { // Convert array to string toString () { // convert to a poly point string @@ -18,7 +12,7 @@ extend(PointArray, { } return array.join(' ') - }, + } // Convert array to line object toLine () { @@ -28,7 +22,7 @@ extend(PointArray, { x2: this[1][0], y2: this[1][1] } - }, + } // Parse point string and flat array parse (array = [ 0, 0 ]) { @@ -52,11 +46,11 @@ extend(PointArray, { } return points - }, + } transform (m) { return this.clone().transformO(m) - }, + } // transform points with matrix (similar to Point.transform) transformO (m) { @@ -72,7 +66,7 @@ extend(PointArray, { } return this - }, + } // Move point string move (x, y) { @@ -90,7 +84,7 @@ extend(PointArray, { } return this - }, + } // Resize poly string size (width, height) { @@ -104,7 +98,7 @@ extend(PointArray, { } return this - }, + } // Get bounding box of points bbox () { @@ -120,4 +114,4 @@ extend(PointArray, { }) return new Box(minX, minY, maxX - minX, maxY - minY) } -}) +} diff --git a/src/types/SVGArray.js b/src/types/SVGArray.js index 7f27ec4..dafa2d4 100644 --- a/src/types/SVGArray.js +++ b/src/types/SVGArray.js @@ -1,36 +1,33 @@ import { delimiter } from '../modules/core/regex.js' -import { extend } from '../utils/adopter.js' -import { subClassArray } from './ArrayPolyfill.js' -const SVGArray = subClassArray('SVGArray', Array, function (arr) { - this.init(arr) -}) - -export default SVGArray +export default class SVGArray extends Array { + constructor (...args) { + super(...args) + this.init(...args) + } -extend(SVGArray, { init (arr) { // This catches the case, that native map tries to create an array with new Array(1) if (typeof arr === 'number') return this this.length = 0 this.push(...this.parse(arr)) return this - }, + } toArray () { return Array.prototype.concat.apply([], this) - }, + } toString () { return this.join(' ') - }, + } // Flattens the array if needed valueOf () { const ret = [] ret.push(...this) return ret - }, + } // Parse whitespace separated string parse (array = []) { @@ -38,13 +35,13 @@ extend(SVGArray, { if (array instanceof Array) return array return array.trim().split(delimiter).map(parseFloat) - }, + } clone () { return new this.constructor(this) - }, + } toSet () { return new Set(this) } -}) +} |