From b1c31462b498ee50e8ed3a88b07ad4a302431d32 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Sun, 13 Jan 2019 13:11:43 +0100 Subject: minor bugfix in bbox and performance changes --- src/elements/Svg.js | 2 +- src/types/Box.js | 17 +++++++++-------- src/types/Color.js | 12 ++++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/elements/Svg.js b/src/elements/Svg.js index 53b488c..f96a5f8 100644 --- a/src/elements/Svg.js +++ b/src/elements/Svg.js @@ -42,7 +42,7 @@ export default class Svg extends Container { defs () { if (!this.isRoot()) return this.root().defs() - return adopt(this.node.getElementsByTagName('defs')[0]) + return adopt(this.node.querySelector('defs')) || this.put(new Defs()) } diff --git a/src/types/Box.js b/src/types/Box.js index 8cbda30..90979d2 100644 --- a/src/types/Box.js +++ b/src/types/Box.js @@ -7,17 +7,18 @@ import Point from './Point.js' import parser from '../modules/core/parser.js' function isNulledBox (box) { - return !box.w && !box.h && !box.x && !box.y + return !box.width && !box.height && !box.x && !box.y } function domContains (node) { - return (globals.document.documentElement.contains || function (node) { - // This is IE - it does not support contains() for top-level SVGs - while (node.parentNode) { - node = node.parentNode - } - return node === document - }).call(globals.document.documentElement, node) + return node === globals.document + || (globals.document.documentElement.contains || function (node) { + // This is IE - it does not support contains() for top-level SVGs + while (node.parentNode) { + node = node.parentNode + } + return node === globals.document + }).call(globals.document.documentElement, node) } export default class Box { diff --git a/src/types/Color.js b/src/types/Color.js index 93ca570..74f20df 100644 --- a/src/types/Color.js +++ b/src/types/Color.js @@ -423,11 +423,11 @@ export default class Color { // Test if given value is a color string static test (color) { - color += '' - return isHex.test(color) || isRgb.test(color) + return (typeof color === 'string') + && (isHex.test(color) || isRgb.test(color)) } - // Test if given value is a rgb object + // Test if given value is an rgb object static isRgb (color) { return color && typeof color.r === 'number' && typeof color.g === 'number' @@ -436,6 +436,10 @@ export default class Color { // Test if given value is a color static isColor (color) { - return this.isRgb(color) || this.test(color) + return color && ( + color instanceof Color + || this.isRgb(color) + || this.test(color) + ) } } -- cgit v1.2.3