diff --git a/lib/css-tools.js b/lib/css-tools.js index a6a343c7..101c093f 100644 --- a/lib/css-tools.js +++ b/lib/css-tools.js @@ -189,8 +189,8 @@ function csstreeToStyleDeclaration(declaration) { * @return {string} CSS string or empty array if no styles are set */ function getCssStr(elem) { - if (elem.content[0].type === 'text' || elem.content[0].type === 'cdata') { - return elem.content[0].value; + if (elem.children[0].type === 'text' || elem.children[0].type === 'cdata') { + return elem.children[0].value; } return ''; } @@ -203,9 +203,9 @@ function getCssStr(elem) { * @return {string} reference to field with CSS */ function setCssStr(elem, css) { - if (elem.content[0].type === 'text' || elem.content[0].type === 'cdata') { - elem.content[0].value = css; - return elem.content[0].value; + if (elem.children[0].type === 'text' || elem.children[0].type === 'cdata') { + elem.children[0].value = css; + return elem.children[0].value; } return css; } diff --git a/lib/style.js b/lib/style.js index c737cf6a..ef4dad0c 100644 --- a/lib/style.js +++ b/lib/style.js @@ -151,7 +151,7 @@ const computeStyle = (node) => { styleNode.attributes.type === '' || styleNode.attributes.type === 'text/css' ) { - const children = styleNode.content || []; + const children = styleNode.children; for (const child of children) { if (child.type === 'text' || child.type === 'cdata') { stylesheet.push(...parseStylesheet(child.value, dynamic)); diff --git a/lib/svgo/css-select-adapter.js b/lib/svgo/css-select-adapter.js index e7e5c394..0d01f06f 100644 --- a/lib/svgo/css-select-adapter.js +++ b/lib/svgo/css-select-adapter.js @@ -23,7 +23,7 @@ const getAttributeValue = (elem, name) => { }; const getChildren = (node) => { - return node.content || []; + return node.children || []; }; const getName = (elemAst) => { @@ -40,8 +40,8 @@ const getSiblings = (elem) => { }; const getText = (node) => { - if (node.content[0].type === 'text' && node.content[0].type === 'cdata') { - return node.content[0].value; + if (node.children[0].type === 'text' && node.children[0].type === 'cdata') { + return node.children[0].value; } return ''; }; diff --git a/lib/svgo/js2svg.js b/lib/svgo/js2svg.js index c1a4997d..1c9cf5c6 100644 --- a/lib/svgo/js2svg.js +++ b/lib/svgo/js2svg.js @@ -93,29 +93,27 @@ function encodeEntity(char) { JS2SVG.prototype.convert = function (data) { var svg = ''; - if (data.content) { - this.indentLevel++; + this.indentLevel++; - data.content.forEach(function (item) { - if (item.type === 'element') { - svg += this.createElem(item); - } - if (item.type === 'text') { - svg += this.createText(item); - } - if (item.type === 'doctype') { - svg += this.createDoctype(item); - } - if (item.type === 'instruction') { - svg += this.createProcInst(item); - } - if (item.type === 'comment') { - svg += this.createComment(item); - } - if (item.type === 'cdata') { - svg += this.createCDATA(item); - } - }, this); + for (const item of data.children) { + if (item.type === 'element') { + svg += this.createElem(item); + } + if (item.type === 'text') { + svg += this.createText(item); + } + if (item.type === 'doctype') { + svg += this.createDoctype(item); + } + if (item.type === 'instruction') { + svg += this.createProcInst(item); + } + if (item.type === 'comment') { + svg += this.createComment(item); + } + if (item.type === 'cdata') { + svg += this.createCDATA(item); + } } this.indentLevel--; @@ -211,7 +209,7 @@ JS2SVG.prototype.createElem = function (data) { } // empty element and short tag - if (data.isEmpty()) { + if (data.children.length === 0) { if (this.config.useShortTags) { return ( this.createIndent() + diff --git a/lib/svgo/jsAPI.js b/lib/svgo/jsAPI.js index b3cf989b..165e0dfe 100644 --- a/lib/svgo/jsAPI.js +++ b/lib/svgo/jsAPI.js @@ -30,7 +30,7 @@ JSAPI.prototype.clone = function () { var nodeData = {}; Object.keys(node).forEach(function (key) { - if (key !== 'class' && key !== 'style' && key !== 'content') { + if (key !== 'class' && key !== 'style' && key !== 'children') { nodeData[key] = node[key]; } }); @@ -49,8 +49,8 @@ JSAPI.prototype.clone = function () { if (node.style) { clonedNode.style = node.style.clone(clonedNode); } - if (node.content) { - clonedNode.content = node.content.map(function (childNode) { + if (node.children) { + clonedNode.children = node.children.map(function (childNode) { var clonedChild = childNode.clone(); clonedChild.parentNode = clonedNode; return clonedChild; @@ -98,7 +98,7 @@ JSAPI.prototype.renameElem = function (name) { * @return {Boolean} */ JSAPI.prototype.isEmpty = function () { - return !this.content || !this.content.length; + return !this.children || !this.children.length; }; /** @@ -116,11 +116,11 @@ JSAPI.prototype.closestElem = function (elemName) { }; /** - * Changes content by removing elements and/or adding new elements. + * Changes children by removing elements and/or adding new elements. * - * @param {Number} start Index at which to start changing the content. + * @param {Number} start Index at which to start changing the children. * @param {Number} n Number of elements to remove. - * @param {Array|Object} [insertion] Elements to add to the content. + * @param {Array|Object} [insertion] Elements to add to the children. * @return {Array} Removed elements. */ JSAPI.prototype.spliceContent = function (start, n, insertion) { @@ -133,7 +133,10 @@ JSAPI.prototype.spliceContent = function (start, n, insertion) { inner.parentNode = this; }, this); - return this.content.splice.apply(this.content, [start, n].concat(insertion)); + return this.children.splice.apply( + this.children, + [start, n].concat(insertion) + ); }; /** diff --git a/lib/svgo/plugins.js b/lib/svgo/plugins.js index f99e7fe9..4e1926cd 100644 --- a/lib/svgo/plugins.js +++ b/lib/svgo/plugins.js @@ -50,9 +50,9 @@ module.exports = function (data, info, plugins) { */ function perItem(data, info, plugins, reverse) { function monkeys(items) { - items.content = items.content.filter(function (item) { + items.children = items.children.filter(function (item) { // reverse pass - if (reverse && item.content) { + if (reverse && item.children) { monkeys(item); } @@ -68,7 +68,7 @@ function perItem(data, info, plugins, reverse) { } // direct pass - if (!reverse && item.content) { + if (!reverse && item.children) { monkeys(item); } diff --git a/lib/svgo/svg2js.js b/lib/svgo/svg2js.js index 5a747290..3005711f 100644 --- a/lib/svgo/svg2js.js +++ b/lib/svgo/svg2js.js @@ -23,13 +23,13 @@ var config = { */ module.exports = function (data) { var sax = SAX.parser(config.strict, config), - root = new JSAPI({ type: 'root', content: [] }), + root = new JSAPI({ type: 'root', children: [] }), current = root, stack = [root]; - function pushToContent(content) { - const wrapped = new JSAPI(content, current); - current.content.push(wrapped); + function pushToContent(node) { + const wrapped = new JSAPI(node, current); + current.children.push(wrapped); return wrapped; } @@ -128,7 +128,7 @@ module.exports = function (data) { } element.attributes = newAttributes; }, - content: [], + children: [], }; element.class = new CSSClassList(element); diff --git a/plugins/addAttributesToSVGElement.js b/plugins/addAttributesToSVGElement.js index 2a3ab0a8..dfe6ce50 100644 --- a/plugins/addAttributesToSVGElement.js +++ b/plugins/addAttributesToSVGElement.js @@ -57,7 +57,7 @@ exports.fn = function (data, params) { } var attributes = params.attributes || [params.attribute], - svg = data.content[0]; + svg = data.children[0]; if (svg.isElem('svg')) { attributes.forEach(function (attribute) { diff --git a/plugins/addClassesToSVGElement.js b/plugins/addClassesToSVGElement.js index c8d195a9..dcecadbe 100644 --- a/plugins/addClassesToSVGElement.js +++ b/plugins/addClassesToSVGElement.js @@ -45,7 +45,7 @@ exports.fn = function (data, params) { } var classNames = params.classNames || [params.className], - svg = data.content[0]; + svg = data.children[0]; if (svg.isElem('svg')) { svg.class.add.apply(svg.class, classNames); diff --git a/plugins/cleanupEnableBackground.js b/plugins/cleanupEnableBackground.js index 399c153d..2369d6c0 100644 --- a/plugins/cleanupEnableBackground.js +++ b/plugins/cleanupEnableBackground.js @@ -60,10 +60,10 @@ exports.fn = function (data) { } function monkeys(items, fn) { - items.content.forEach(function (item) { + items.children.forEach(function (item) { fn(item); - if (item.content) { + if (item.children) { monkeys(item, fn); } }); diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index 83aedf4f..1a7e5558 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -117,13 +117,12 @@ exports.fn = function (data, params) { * @return {Array} output items */ function monkeys(items) { - for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) { - var item = items.content[i]; + for (var i = 0; i < items.children.length && !hasStyleOrScript; i++) { + var item = items.children[i]; // quit if