diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-28 12:57:52 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-28 12:57:52 +0100 |
commit | 58fd0d68bc8b46b23f8cdc65190f08d4e524eb57 (patch) | |
tree | 04247b959cb0517eb4a891c6afbabb734bb892bb /src | |
parent | 08b27426fa631a6200a5423161770acab50403bd (diff) | |
download | svg.js-58fd0d68bc8b46b23f8cdc65190f08d4e524eb57.tar.gz svg.js-58fd0d68bc8b46b23f8cdc65190f08d4e524eb57.zip |
Fix build chain so that we now have multiple builds. Details below:
- svg.js: The esm bundle
- svg.min.js: The bundle for all browsers for maximum support
- svg.node.js: The bundle for node
- polyfill.js: Using svg.min.js requires this polyfill in case the Browser does not understand all of ./config/polyfillList.js
- polyfillIE.js: This is required when you use IE11 (polyfill.js still required)
Please note, that not all test pass for IE11 due to its rounding issues and wrong calculation of bbox.
Also note, that `defaultPrevented` is not working for CustomEvents in IE11.
Diffstat (limited to 'src')
-rw-r--r-- | src/animation/Morphable.js | 9 | ||||
-rw-r--r-- | src/main.js | 1 | ||||
-rw-r--r-- | src/polyfills/children.js | 8 | ||||
-rw-r--r-- | src/polyfills/innerHTML.js | 95 | ||||
-rw-r--r-- | src/utils/adopter.js | 2 | ||||
-rw-r--r-- | src/utils/methods.js | 13 |
6 files changed, 115 insertions, 13 deletions
diff --git a/src/animation/Morphable.js b/src/animation/Morphable.js index a02ba31..4d52066 100644 --- a/src/animation/Morphable.js +++ b/src/animation/Morphable.js @@ -196,7 +196,14 @@ export class ObjectBag { return } - var entries = Object.entries(objOrArr || {}).sort((a, b) => { + objOrArr = objOrArr || {} + var entries = [] + + for (let i in objOrArr) { + entries.push([i, objOrArr[i]]) + } + + entries.sort((a, b) => { return a[0] - b[0] }) diff --git a/src/main.js b/src/main.js index 1ce11f7..8ea3e5d 100644 --- a/src/main.js +++ b/src/main.js @@ -43,6 +43,7 @@ import SVGArray from './types/SVGArray.js' import SVGNumber from './types/SVGNumber.js' import Shape from './elements/Shape.js' import Svg from './elements/Svg.js' +import Symbol from './elements/Symbol.js' import Text from './elements/Text.js' import Tspan from './elements/Tspan.js' import * as defaults from './modules/core/defaults.js' diff --git a/src/polyfills/children.js b/src/polyfills/children.js new file mode 100644 index 0000000..98e9143 --- /dev/null +++ b/src/polyfills/children.js @@ -0,0 +1,8 @@ +import { filter } from '../utils/utils.js' + +// IE11: children does not work for svg nodes +export default function children (node) { + return filter(node.childNodes, function (child) { + return child.nodeType === 1 + }) +} diff --git a/src/polyfills/innerHTML.js b/src/polyfills/innerHTML.js new file mode 100644 index 0000000..4be7f1b --- /dev/null +++ b/src/polyfills/innerHTML.js @@ -0,0 +1,95 @@ +/* globals SVGElement, DOMParser */ + +(function () { + try { + if (SVGElement.prototype.innerHTML) return + } catch (e) { return } + + var serializeXML = function (node, output) { + var nodeType = node.nodeType + if (nodeType === 3) { + output.push(node.textContent.replace(/&/, '&').replace(/</, '<').replace('>', '>')) + } else if (nodeType === 1) { + output.push('<', node.tagName) + if (node.hasAttributes()) { + [].forEach.call(node.attributes, function (attrNode) { + output.push(' ', attrNode.name, '=\'', attrNode.value, '\'') + }) + } + if (node.hasChildNodes()) { + output.push('>'); + [].forEach.call(node.childNodes, function (childNode) { + serializeXML(childNode, output) + }) + output.push('</', node.tagName, '>') + } else { + output.push('/>') + } + } else if (nodeType === 8) { + output.push('<!--', node.nodeValue, '-->') + } + } + + Object.defineProperty(SVGElement.prototype, 'innerHTML', { + get: function () { + var output = [] + var childNode = this.firstChild + while (childNode) { + serializeXML(childNode, output) + childNode = childNode.nextSibling + } + return output.join('') + }, + set: function (markupText) { + while (this.firstChild) { + this.removeChild(this.firstChild) + } + + try { + var dXML = new DOMParser() + dXML.async = false + + var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markupText + '</svg>' + var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement + + var childNode = svgDocElement.firstChild + while (childNode) { + this.appendChild(this.ownerDocument.importNode(childNode, true)) + childNode = childNode.nextSibling + } + } catch (e) { + throw new Error('Can not set innerHTML on node') + }; + } + }) + + Object.defineProperty(SVGElement.prototype, 'outerHTML', { + get: function () { + var output = [] + serializeXML(this, output) + return output.join('') + }, + set: function (markupText) { + while (this.firstChild) { + this.removeChild(this.firstChild) + } + + try { + var dXML = new DOMParser() + dXML.async = false + + var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markupText + '</svg>' + var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement + + var childNode = svgDocElement.firstChild + while (childNode) { + this.parentNode.insertBefore(this.ownerDocument.importNode(childNode, true), this) + // this.appendChild(this.ownerDocument.importNode(childNode, true)); + childNode = childNode.nextSibling + } + } catch (e) { + throw new Error('Can not set outerHTML on node') + }; + } + }) +})() diff --git a/src/utils/adopter.js b/src/utils/adopter.js index 52d589e..a4c60de 100644 --- a/src/utils/adopter.js +++ b/src/utils/adopter.js @@ -5,7 +5,7 @@ import { globals } from '../utils/window.js' import Base from '../types/Base.js' const elements = {} -export const root = Symbol('root') +export const root = '___SYMBOL___ROOT___' // Method for element creation export function makeNode (name) { diff --git a/src/utils/methods.js b/src/utils/methods.js index 70f9329..bf30a1e 100644 --- a/src/utils/methods.js +++ b/src/utils/methods.js @@ -1,5 +1,4 @@ const methods = {} -const constructors = {} const names = [] export function registerMethods (name, m) { @@ -11,8 +10,8 @@ export function registerMethods (name, m) { } if (typeof name === 'object') { - for (let [_name, _m] of Object.entries(name)) { - registerMethods(_name, _m) + for (let _name in name) { + registerMethods(_name, name[_name]) } return } @@ -32,11 +31,3 @@ export function getMethodNames () { export function addMethodNames (_names) { names.push(..._names) } - -export function registerConstructor (name, setup) { - constructors[name] = setup -} - -export function getConstructor (name) { - return constructors[name] ? { setup: constructors[name], name } : {} -} |