flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
14
VISUALIZACION/node_modules/htmlnano/lib/helpers.js
generated
vendored
Executable file
14
VISUALIZACION/node_modules/htmlnano/lib/helpers.js
generated
vendored
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isComment = isComment;
|
||||
exports.isConditionalComment = isConditionalComment;
|
||||
function isComment(content) {
|
||||
return (content || '').trim().search('<!--') === 0;
|
||||
}
|
||||
|
||||
function isConditionalComment(content) {
|
||||
return (content || '').trim().search(/<!--\[if/) === 0;
|
||||
}
|
||||
94
VISUALIZACION/node_modules/htmlnano/lib/htmlnano.js
generated
vendored
Executable file
94
VISUALIZACION/node_modules/htmlnano/lib/htmlnano.js
generated
vendored
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _objectAssign = require('object-assign');
|
||||
|
||||
var _objectAssign2 = _interopRequireDefault(_objectAssign);
|
||||
|
||||
var _posthtml = require('posthtml');
|
||||
|
||||
var _posthtml2 = _interopRequireDefault(_posthtml);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// Array of all enabled modules
|
||||
var defaultOptions = {
|
||||
removeComments: 'safe',
|
||||
removeEmptyAttributes: true,
|
||||
removeRedundantAttributes: false,
|
||||
collapseWhitespace: 'conservative',
|
||||
collapseBooleanAttributes: true,
|
||||
mergeStyles: true,
|
||||
mergeScripts: true,
|
||||
minifyCss: {
|
||||
safe: true
|
||||
},
|
||||
minifyJs: {},
|
||||
minifyJson: {},
|
||||
minifySvg: {},
|
||||
custom: []
|
||||
};
|
||||
|
||||
function htmlnano() {
|
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
|
||||
return function minifier(tree) {
|
||||
options = (0, _objectAssign2.default)({}, defaultOptions, options);
|
||||
var promise = Promise.resolve(tree);
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
var _loop = function _loop() {
|
||||
var moduleName = _step.value;
|
||||
|
||||
if (!options[moduleName]) {
|
||||
// The module is disabled
|
||||
return 'continue';
|
||||
}
|
||||
|
||||
if (defaultOptions[moduleName] === undefined) {
|
||||
throw new Error('Module "' + moduleName + '" is not defined');
|
||||
}
|
||||
|
||||
var module = require('./modules/' + moduleName);
|
||||
promise = promise.then(function (tree) {
|
||||
return module.default(tree, options, options[moduleName]);
|
||||
});
|
||||
};
|
||||
|
||||
for (var _iterator = Object.keys(options)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var _ret = _loop();
|
||||
|
||||
if (_ret === 'continue') continue;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return promise;
|
||||
};
|
||||
}
|
||||
|
||||
htmlnano.process = function (html, options) {
|
||||
return (0, _posthtml2.default)([htmlnano(options)]).process(html);
|
||||
};
|
||||
|
||||
htmlnano.defaultOptions = defaultOptions;
|
||||
|
||||
exports.default = htmlnano;
|
||||
48
VISUALIZACION/node_modules/htmlnano/lib/modules/collapseBooleanAttributes.js
generated
vendored
Executable file
48
VISUALIZACION/node_modules/htmlnano/lib/modules/collapseBooleanAttributes.js
generated
vendored
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = collapseBooleanAttributes;
|
||||
// Source: https://github.com/kangax/html-minifier/issues/63
|
||||
var booleanAttributes = ['allowfullscreen', 'async', 'autofocus', 'autoplay', 'checked', 'compact', 'controls', 'declare', 'default', 'defaultchecked', 'defaultmuted', 'defaultselected', 'defer', 'disabled', 'enabled', 'formnovalidate', 'hidden', 'indeterminate', 'inert', 'ismap', 'itemscope', 'loop', 'multiple', 'muted', 'nohref', 'noresize', 'noshade', 'novalidate', 'nowrap', 'open', 'pauseonexit', 'readonly', 'required', 'reversed', 'scoped', 'seamless', 'selected', 'sortable', 'truespeed', 'typemustmatch', 'visible'];
|
||||
|
||||
var booleanAttributesIndex = {};
|
||||
booleanAttributes.forEach(function (attributeName) {
|
||||
return booleanAttributesIndex[attributeName] = true;
|
||||
});
|
||||
|
||||
function collapseBooleanAttributes(tree) {
|
||||
tree.match({ attrs: true }, function (node) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = Object.keys(node.attrs)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var attrName = _step.value;
|
||||
|
||||
if (booleanAttributesIndex[attrName]) {
|
||||
node.attrs[attrName] = true;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
43
VISUALIZACION/node_modules/htmlnano/lib/modules/collapseWhitespace.js
generated
vendored
Executable file
43
VISUALIZACION/node_modules/htmlnano/lib/modules/collapseWhitespace.js
generated
vendored
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = collapseWhitespace;
|
||||
|
||||
var _helpers = require('../helpers');
|
||||
|
||||
var noWhitespaceCollapseElements = ['script', 'style', 'pre', 'textarea'];
|
||||
|
||||
/** Collapses redundant whitespaces */
|
||||
function collapseWhitespace(tree, options, collapseType) {
|
||||
if (collapseType !== 'conservative' && collapseType !== 'all') {
|
||||
collapseType = 'conservative';
|
||||
}
|
||||
|
||||
tree.forEach(function (node, index) {
|
||||
if (typeof node === 'string' && !(0, _helpers.isComment)(node)) {
|
||||
node = collapseRedundantWhitespaces(node, collapseType, tree.walk !== undefined);
|
||||
}
|
||||
|
||||
var isAllowCollapseWhitespace = noWhitespaceCollapseElements.indexOf(node.tag) === -1;
|
||||
if (node.content && node.content.length && isAllowCollapseWhitespace) {
|
||||
node.content = collapseWhitespace(node.content, options, collapseType);
|
||||
}
|
||||
|
||||
tree[index] = node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
function collapseRedundantWhitespaces(text, collapseType) {
|
||||
var isTopLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
||||
|
||||
text = text && text.length > 0 ? text.replace(/\s+/g, ' ') : '';
|
||||
if (collapseType === 'all' || isTopLevel) {
|
||||
text = text.trim();
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
22
VISUALIZACION/node_modules/htmlnano/lib/modules/custom.js
generated
vendored
Executable file
22
VISUALIZACION/node_modules/htmlnano/lib/modules/custom.js
generated
vendored
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = custom;
|
||||
/** Meta-module that runs custom modules */
|
||||
function custom(tree, options, customModules) {
|
||||
if (!customModules) {
|
||||
return tree;
|
||||
}
|
||||
|
||||
if (!Array.isArray(customModules)) {
|
||||
customModules = [customModules];
|
||||
}
|
||||
|
||||
customModules.forEach(function (customModule) {
|
||||
tree = customModule(tree, options);
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
80
VISUALIZACION/node_modules/htmlnano/lib/modules/mergeScripts.js
generated
vendored
Executable file
80
VISUALIZACION/node_modules/htmlnano/lib/modules/mergeScripts.js
generated
vendored
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = mergeScripts;
|
||||
/* Merge multiple <script> into one */
|
||||
function mergeScripts(tree) {
|
||||
var scriptNodesIndex = {};
|
||||
|
||||
tree.match({ tag: 'script' }, function (node) {
|
||||
var nodeAttrs = node.attrs || {};
|
||||
if (nodeAttrs.src) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var scriptType = nodeAttrs.type || 'text/javascript';
|
||||
if (scriptType !== 'text/javascript' && scriptType !== 'application/javascript') {
|
||||
return node;
|
||||
}
|
||||
|
||||
var scriptKey = JSON.stringify({
|
||||
id: nodeAttrs.id,
|
||||
class: nodeAttrs.class,
|
||||
type: scriptType,
|
||||
defer: nodeAttrs.defer !== undefined,
|
||||
async: nodeAttrs.async !== undefined
|
||||
});
|
||||
if (!scriptNodesIndex[scriptKey]) {
|
||||
scriptNodesIndex[scriptKey] = [];
|
||||
}
|
||||
|
||||
scriptNodesIndex[scriptKey].push(node);
|
||||
return node;
|
||||
});
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
var _loop = function _loop() {
|
||||
var scriptKey = _step.value;
|
||||
|
||||
var scriptNodes = scriptNodesIndex[scriptKey];
|
||||
var lastScriptNode = scriptNodes.pop();
|
||||
scriptNodes.reverse().forEach(function (scriptNode) {
|
||||
var scriptContent = (scriptNode.content || []).join(' ');
|
||||
scriptContent = scriptContent.trim();
|
||||
if (scriptContent.slice(-1) !== ';') {
|
||||
scriptContent += ';';
|
||||
}
|
||||
|
||||
lastScriptNode.content.unshift(scriptContent);
|
||||
|
||||
scriptNode.tag = false;
|
||||
scriptNode.content = [];
|
||||
});
|
||||
};
|
||||
|
||||
for (var _iterator = Object.keys(scriptNodesIndex)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
_loop();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tree;
|
||||
}
|
||||
34
VISUALIZACION/node_modules/htmlnano/lib/modules/mergeStyles.js
generated
vendored
Executable file
34
VISUALIZACION/node_modules/htmlnano/lib/modules/mergeStyles.js
generated
vendored
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = mergeStyles;
|
||||
/* Merge multiple <style> into one */
|
||||
function mergeStyles(tree) {
|
||||
var styleNodes = {};
|
||||
|
||||
tree.match({ tag: 'style' }, function (node) {
|
||||
var nodeAttrs = node.attrs || {};
|
||||
// Skip <style scoped></style>
|
||||
// https://developer.mozilla.org/en/docs/Web/HTML/Element/style
|
||||
if (nodeAttrs.scoped !== undefined) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var styleType = nodeAttrs.type || 'text/css';
|
||||
var styleMedia = nodeAttrs.media || 'all';
|
||||
var styleKey = styleType + '_' + styleMedia;
|
||||
if (styleNodes[styleKey]) {
|
||||
var styleContent = (node.content || []).join(' ');
|
||||
styleNodes[styleKey].content.push(' ' + styleContent);
|
||||
return '';
|
||||
}
|
||||
|
||||
node.content = node.content || [];
|
||||
styleNodes[styleKey] = node;
|
||||
return node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
50
VISUALIZACION/node_modules/htmlnano/lib/modules/minifyCss.js
generated
vendored
Executable file
50
VISUALIZACION/node_modules/htmlnano/lib/modules/minifyCss.js
generated
vendored
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = minifyCss;
|
||||
|
||||
var _cssnano = require('cssnano');
|
||||
|
||||
var _cssnano2 = _interopRequireDefault(_cssnano);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/** Minify CSS with cssnano */
|
||||
function minifyCss(tree, options, cssnanoOptions) {
|
||||
var promises = [];
|
||||
tree.walk(function (node) {
|
||||
if (node.tag === 'style' && node.content && node.content.length) {
|
||||
promises.push(processStyleNode(node, cssnanoOptions));
|
||||
} else if (node.attrs && node.attrs.style) {
|
||||
promises.push(processStyleAttr(node, cssnanoOptions));
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function () {
|
||||
return tree;
|
||||
});
|
||||
}
|
||||
|
||||
function processStyleNode(styleNode, cssnanoOptions) {
|
||||
return _cssnano2.default.process(Array.isArray(styleNode.content) ? styleNode.content.join(' ') : styleNode.content, cssnanoOptions).then(function (result) {
|
||||
return styleNode.content = [result.css];
|
||||
});
|
||||
}
|
||||
|
||||
function processStyleAttr(node, cssnanoOptions) {
|
||||
// CSS "color: red;" is invalid. Therefore it should be wrapped inside some selector:
|
||||
// a{color: red;}
|
||||
var wrapperStart = 'a{';
|
||||
var wrapperEnd = '}';
|
||||
var wrappedStyle = wrapperStart + (node.attrs.style || '') + wrapperEnd;
|
||||
|
||||
return _cssnano2.default.process(wrappedStyle, cssnanoOptions).then(function (result) {
|
||||
var minifiedCss = result.css;
|
||||
// Remove wrapperStart at the start and wrapperEnd at the end of minifiedCss
|
||||
node.attrs.style = minifiedCss.substring(wrapperStart.length, minifiedCss.length - wrapperEnd.length);
|
||||
});
|
||||
}
|
||||
94
VISUALIZACION/node_modules/htmlnano/lib/modules/minifyJs.js
generated
vendored
Executable file
94
VISUALIZACION/node_modules/htmlnano/lib/modules/minifyJs.js
generated
vendored
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = minifyJs;
|
||||
|
||||
var _terser = require('terser');
|
||||
|
||||
var _terser2 = _interopRequireDefault(_terser);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/** Minify JS with Terser */
|
||||
function minifyJs(tree, options, terserOptions) {
|
||||
|
||||
tree.match({ tag: 'script' }, function (node) {
|
||||
var nodeAttrs = node.attrs || {};
|
||||
var mimeType = nodeAttrs.type || 'text/javascript';
|
||||
if (mimeType === 'text/javascript' || mimeType === 'application/javascript') {
|
||||
return processScriptNode(node, terserOptions);
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
tree.match({ attrs: true }, function (node) {
|
||||
return processNodeWithOnAttrs(node, terserOptions);
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
function processScriptNode(scriptNode, terserOptions) {
|
||||
var js = (scriptNode.content || []).join(' ').trim();
|
||||
if (!js) {
|
||||
return scriptNode;
|
||||
}
|
||||
|
||||
var result = _terser2.default.minify(js, terserOptions);
|
||||
if (result.error) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
if (result.code === undefined) {
|
||||
return scriptNode;
|
||||
}
|
||||
|
||||
scriptNode.content = [result.code];
|
||||
|
||||
return scriptNode;
|
||||
}
|
||||
|
||||
function processNodeWithOnAttrs(node, terserOptions) {
|
||||
var jsWrapperStart = 'function _(){';
|
||||
var jsWrapperEnd = '}';
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = Object.keys(node.attrs || {})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var attrName = _step.value;
|
||||
|
||||
if (attrName.search('on') !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// For example onclick="return false" is valid,
|
||||
// but "return false;" is invalid (error: 'return' outside of function)
|
||||
// Therefore the attribute's code should be wrapped inside function:
|
||||
// "function _(){return false;}"
|
||||
var wrappedJs = jsWrapperStart + node.attrs[attrName] + jsWrapperEnd;
|
||||
var wrappedMinifiedJs = _terser2.default.minify(wrappedJs, terserOptions).code;
|
||||
var minifiedJs = wrappedMinifiedJs.substring(jsWrapperStart.length, wrappedMinifiedJs.length - jsWrapperEnd.length);
|
||||
node.attrs[attrName] = minifiedJs;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
27
VISUALIZACION/node_modules/htmlnano/lib/modules/minifyJson.js
generated
vendored
Executable file
27
VISUALIZACION/node_modules/htmlnano/lib/modules/minifyJson.js
generated
vendored
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = minifyJson;
|
||||
/* Minify JSON inside <script> tags */
|
||||
function minifyJson(tree) {
|
||||
// Match all <script> tags which have JSON mime type
|
||||
tree.match({ tag: 'script', attrs: { type: /(\/|\+)json/ } }, function (node) {
|
||||
var content = (node.content || []).join('');
|
||||
if (!content) {
|
||||
return node;
|
||||
}
|
||||
|
||||
try {
|
||||
content = JSON.stringify(JSON.parse(content));
|
||||
} catch (error) {
|
||||
return node;
|
||||
}
|
||||
|
||||
node.content = [content];
|
||||
return node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
40
VISUALIZACION/node_modules/htmlnano/lib/modules/minifySvg.js
generated
vendored
Executable file
40
VISUALIZACION/node_modules/htmlnano/lib/modules/minifySvg.js
generated
vendored
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = minifySvg;
|
||||
|
||||
var _svgo = require('svgo');
|
||||
|
||||
var _svgo2 = _interopRequireDefault(_svgo);
|
||||
|
||||
var _posthtmlRender = require('posthtml-render');
|
||||
|
||||
var _posthtmlRender2 = _interopRequireDefault(_posthtmlRender);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/** Minify SVG with SVGO */
|
||||
function minifySvg(tree, options) {
|
||||
var svgoOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
|
||||
var promises = [];
|
||||
var svgo = new _svgo2.default(svgoOptions);
|
||||
|
||||
tree.match({ tag: 'svg' }, function (node) {
|
||||
var svgStr = (0, _posthtmlRender2.default)(node);
|
||||
var promise = svgo.optimize(svgStr).then(function (result) {
|
||||
node.tag = false;
|
||||
node.attrs = {};
|
||||
node.content = result.data;
|
||||
});
|
||||
promises.push(promise);
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function () {
|
||||
return tree;
|
||||
});
|
||||
}
|
||||
54
VISUALIZACION/node_modules/htmlnano/lib/modules/removeComments.js
generated
vendored
Executable file
54
VISUALIZACION/node_modules/htmlnano/lib/modules/removeComments.js
generated
vendored
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = removeComments;
|
||||
|
||||
var _helpers = require('../helpers');
|
||||
|
||||
/** Removes HTML comments */
|
||||
function removeComments(tree, options, removeType) {
|
||||
if (removeType !== 'all' && removeType !== 'safe') {
|
||||
removeType = 'safe';
|
||||
}
|
||||
|
||||
tree.walk(function (node) {
|
||||
if (node.contents && node.contents.length) {
|
||||
node.contents = node.contents.filter(function (content) {
|
||||
return !isCommentToRemove(content, removeType);
|
||||
});
|
||||
} else if (isCommentToRemove(node, removeType)) {
|
||||
node = '';
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
function isCommentToRemove(text, removeType) {
|
||||
if (typeof text !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(0, _helpers.isComment)(text)) {
|
||||
// Not HTML comment
|
||||
return false;
|
||||
}
|
||||
|
||||
var isNoindex = text === '<!--noindex-->' || text === '<!--/noindex-->';
|
||||
if (removeType === 'safe' && isNoindex) {
|
||||
// Don't remove noindex comments.
|
||||
// See: https://yandex.com/support/webmaster/controlling-robot/html.xml
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Conditional_comment
|
||||
if (removeType === 'safe' && (0, _helpers.isConditionalComment)(text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
33
VISUALIZACION/node_modules/htmlnano/lib/modules/removeEmptyAttributes.js
generated
vendored
Executable file
33
VISUALIZACION/node_modules/htmlnano/lib/modules/removeEmptyAttributes.js
generated
vendored
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = removeEmptyAttributes;
|
||||
// Source: https://www.w3.org/TR/html4/sgml/dtd.html#events (Generic Attributes)
|
||||
var safeToRemoveAttrs = ['id', 'class', 'style', 'title', 'lang', 'dir', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress', 'onkeydown', 'onkeyup'];
|
||||
|
||||
/** Removes empty attributes */
|
||||
function removeEmptyAttributes(tree) {
|
||||
tree.walk(function (node) {
|
||||
if (!node.attrs) {
|
||||
return node;
|
||||
}
|
||||
|
||||
Object.keys(node.attrs).forEach(function (attrName) {
|
||||
var attrNameLower = attrName.toLowerCase();
|
||||
if (safeToRemoveAttrs.indexOf(attrNameLower) === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var attrValue = node.attrs[attrName];
|
||||
if (attrValue === '' || (attrValue || '').match(/^\s+$/)) {
|
||||
delete node.attrs[attrName];
|
||||
}
|
||||
});
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
87
VISUALIZACION/node_modules/htmlnano/lib/modules/removeRedundantAttributes.js
generated
vendored
Executable file
87
VISUALIZACION/node_modules/htmlnano/lib/modules/removeRedundantAttributes.js
generated
vendored
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = removeRedundantAttributes;
|
||||
var redundantAttributes = {
|
||||
'form': {
|
||||
'method': 'get'
|
||||
},
|
||||
|
||||
'input': {
|
||||
'type': 'text'
|
||||
},
|
||||
|
||||
'button': {
|
||||
'type': 'submit'
|
||||
},
|
||||
|
||||
'script': {
|
||||
'language': 'javascript',
|
||||
'type': 'text/javascript',
|
||||
// Remove attribute if the function returns false
|
||||
'charset': function charset(node) {
|
||||
// The charset attribute only really makes sense on “external” SCRIPT elements:
|
||||
// http://perfectionkills.com/optimizing-html/#8_script_charset
|
||||
return node.attrs && !node.attrs.src;
|
||||
}
|
||||
},
|
||||
|
||||
'style': {
|
||||
'media': 'all',
|
||||
'type': 'text/css'
|
||||
},
|
||||
|
||||
'link': {
|
||||
'media': 'all'
|
||||
}
|
||||
};
|
||||
|
||||
/** Removes redundant attributes */
|
||||
function removeRedundantAttributes(tree) {
|
||||
var tags = Object.keys(redundantAttributes);
|
||||
var tagMatchRegExp = new RegExp('^(' + tags.join('|') + ')$');
|
||||
tree.match({ tag: tagMatchRegExp }, function (node) {
|
||||
var tagRedundantAttributes = redundantAttributes[node.tag];
|
||||
node.attrs = node.attrs || {};
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = Object.keys(tagRedundantAttributes)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var redundantAttributeName = _step.value;
|
||||
|
||||
var tagRedundantAttributeValue = tagRedundantAttributes[redundantAttributeName];
|
||||
var isRemove = false;
|
||||
if (typeof tagRedundantAttributeValue === 'function') {
|
||||
isRemove = tagRedundantAttributeValue(node);
|
||||
} else if (node.attrs[redundantAttributeName] === tagRedundantAttributeValue) {
|
||||
isRemove = true;
|
||||
}
|
||||
|
||||
if (isRemove) {
|
||||
delete node.attrs[redundantAttributeName];
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue