postcss-icon
Advanced tools
Comparing version 6.0.9 to 7.0.0-alpha.1
224
lib/index.js
@@ -7,24 +7,12 @@ "use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _postcss = require("postcss"); | ||
var _utils = require("./utils.js"); | ||
var _LazyIconSet = require("./LazyIconSet.js"); | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var _config = require("./config"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var NAME = "postcss-icon"; | ||
exports.default = (0, _postcss.plugin)(NAME, function () { | ||
for (var _len = arguments.length, listIconData = Array(_len), _key = 0; _key < _len; _key++) { | ||
listIconData[_key] = arguments[_key]; | ||
} | ||
if (listIconData.length === 0) { | ||
console.log(`[${NAME}]`, "Error: Options data for the css icon can not be empty!"); | ||
return function (root) { | ||
exports.default = (0, _postcss.plugin)(_config.NAME, options => { | ||
if (!options) { | ||
console.log(`[${_config.NAME}]`, "Error: Options data for the css icon can not be empty!"); | ||
return root => { | ||
walkAtRuleIcon(root, nodeToComment); | ||
@@ -34,23 +22,14 @@ }; | ||
listIconData = listIconData.length === 1 ? Array.isArray(listIconData[0]) ? listIconData[0] : [listIconData[0]] : listIconData; | ||
const lazy = new _LazyIconSet.LazyIconSet(options); | ||
var AllIcons = getMapAllIcons(listIconData); | ||
return (root, result) => { | ||
// Step 1: find all icons in this file | ||
walkAtRuleIcon(root, atRuleIcon => { | ||
const iconAdded = lazy.addIcon({ | ||
root: closestRoot(atRuleIcon), | ||
parent: atRuleIcon.parent, | ||
iconName: clearValue(atRuleIcon.params) | ||
}); | ||
return function (root, result) { | ||
var currentList = new Map(); | ||
// Step 1: find all icons in this file | ||
walkAtRuleIcon(root, function (atRuleIcon) { | ||
var iconName = clearValue(atRuleIcon.params); | ||
if (AllIcons.has(iconName)) { | ||
var rootOrMq = closestRoot(atRuleIcon); | ||
if (!currentList.has(rootOrMq)) { | ||
currentList.set(rootOrMq, new Map()); | ||
} | ||
var rootMap = currentList.get(rootOrMq); | ||
if (!rootMap.get(iconName)) { | ||
rootMap.set(iconName, []); | ||
} | ||
var iconMap = rootMap.get(iconName); | ||
iconMap.push(atRuleIcon.parent); | ||
if (iconAdded) { | ||
atRuleIcon.remove(); | ||
@@ -64,62 +43,6 @@ } else { | ||
// Step 2: Extend all finded icons | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = currentList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _ref = _step.value; | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var rootOrMq = _ref2[0]; | ||
var nodesSet = _ref2[1]; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = nodesSet[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _ref3 = _step2.value; | ||
var _ref4 = _slicedToArray(_ref3, 2); | ||
var iconName = _ref4[0]; | ||
var nodes = _ref4[1]; | ||
processExtend({ | ||
extendRules: AllIcons.get(iconName), | ||
userRules: nodes, | ||
parent: rootOrMq | ||
}); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return lazy.applySet({ | ||
root, | ||
result | ||
}); // return Promise | ||
}; | ||
@@ -134,3 +57,3 @@ }); | ||
function walkAtRuleIcon(root, func) { | ||
root.walkAtRules(function (atRuleIcon) { | ||
root.walkAtRules(atRuleIcon => { | ||
if (atRuleIcon.name && atRuleIcon.name === "icon" || atRuleIcon.name === "icon:") { | ||
@@ -142,95 +65,2 @@ func(atRuleIcon); | ||
function getMapAllIcons(listIconData) { | ||
return listIconData.map(function (_ref5) { | ||
var _ref5$prefix = _ref5.prefix, | ||
prefix = _ref5$prefix === undefined ? "" : _ref5$prefix, | ||
_ref5$data = _ref5.data, | ||
data = _ref5$data === undefined ? {} : _ref5$data; | ||
return prefixIconNames(prefix, data); | ||
}).reduce(function (allIcons, isonSet) { | ||
(0, _utils.objectMap)(isonSet, function (nodes, iconName) { | ||
if (allIcons.has(iconName)) { | ||
console.log(`[${NAME}]`, `Warn: the iconName \`${iconName}\` already declared! Use a different prefix to avoid conflicts.`); | ||
} else { | ||
allIcons.set(iconName, nodes); | ||
} | ||
}); | ||
return allIcons; | ||
}, new Map()); | ||
} | ||
function isOneUseIcon(userRules) { | ||
return userRules.length === 1; | ||
} | ||
function processExtend(_ref6) { | ||
var extendRules = _ref6.extendRules, | ||
userRules = _ref6.userRules, | ||
parent = _ref6.parent; | ||
if (userRules.length !== 0) { | ||
var allSelectors = userRules.map(function (_ref7) { | ||
var selector = _ref7.selector; | ||
return selector; | ||
}); | ||
var tmpRoot = (0, _postcss.parse)(extendRules.join("\n")); | ||
var isOneUseRule = isOneUseIcon(userRules); | ||
var tmpCloner = void 0; | ||
if (isOneUseRule) { | ||
tmpCloner = new TmpContainer({ toNode: userRules[0] }); | ||
} | ||
tmpRoot.walkRules(function (rule) { | ||
if (isOneUseRule && rule.selector === ".extend") { | ||
tmpCloner.addProps(rule); | ||
rule.remove(); | ||
} else { | ||
var extendedSelector = rule.selectors.map(function (selector) { | ||
return allSelectors.map(function (userSelect) { | ||
return selector.replace(/\.extend/g, userSelect.trim()); | ||
}).join(","); | ||
}).join(","); | ||
rule.selector = extendedSelector; | ||
} | ||
}); | ||
if (isOneUseRule) { | ||
tmpCloner.cloneProps(); | ||
} | ||
if (tmpRoot.nodes.length) { | ||
parent.insertBefore(userRules[0], tmpRoot.nodes); | ||
} | ||
} | ||
} | ||
var TmpContainer = function () { | ||
function TmpContainer(_ref8) { | ||
var toNode = _ref8.toNode; | ||
_classCallCheck(this, TmpContainer); | ||
this.toNode = toNode; | ||
this.tmpNodes = []; | ||
} | ||
_createClass(TmpContainer, [{ | ||
key: "addProps", | ||
value: function addProps(fromNode) { | ||
var _tmpNodes; | ||
(_tmpNodes = this.tmpNodes).push.apply(_tmpNodes, _toConsumableArray(fromNode.nodes)); | ||
} | ||
}, { | ||
key: "cloneProps", | ||
value: function cloneProps() { | ||
if (this.tmpNodes.length !== 0) { | ||
var _toNode; | ||
(_toNode = this.toNode).prepend.apply(_toNode, _toConsumableArray(this.tmpNodes)); | ||
} | ||
} | ||
}]); | ||
return TmpContainer; | ||
}(); | ||
function clearValue(val) { | ||
@@ -240,13 +70,3 @@ return val.replace(/['"]/g, ""); | ||
function prefixIconNames(prefix, obj) { | ||
var tmp = {}; | ||
(0, _utils.objectMap)(obj, function (val, key) { | ||
tmp[prefix + key] = val; | ||
}); | ||
return tmp; | ||
} | ||
function closestRoot(_ref9) { | ||
var parent = _ref9.parent; | ||
function closestRoot({ parent }) { | ||
if (parent === undefined) { | ||
@@ -253,0 +73,0 @@ return false; |
{ | ||
"name": "postcss-icon", | ||
"description": "PostCSS plugin which allows you to quickly add styles to css icons", | ||
"version": "6.0.9", | ||
"main": "lib/index.js", | ||
"version": "7.0.0-alpha.1", | ||
"repository": "https://github.com/retyui/postcss-icon", | ||
"author": "David ♥ <vamnemne@gmail.com>", | ||
"author": "retyui <vamnemne@gmail.com>", | ||
"license": "MIT", | ||
"main": "postcss-icon.js", | ||
"files": [ | ||
"lib", | ||
"lib-old" | ||
], | ||
"scripts": { | ||
"lint": "eslint ./**/*.js", | ||
"precompile": "npm run lint", | ||
"compile": "babel src --out-dir lib", | ||
"babel:modern": "cross-env BABEL_ENV=modern babel src --out-dir lib", | ||
"babel:old": "cross-env BABEL_ENV=old babel src --out-dir lib-old", | ||
"clean": "rimraf ./test/test.js ./lib ./lib-old", | ||
"compile": "npm-run-all --parallel babel:* testcompile", | ||
"lint": "eslint ./**/*.js --fix --quiet", | ||
"precompile": "npm-run-all clean lint", | ||
"pretest": "npm run compile", | ||
"test": "mocha --compilers js:babel-register ./test/test.mjs" | ||
"test": "mocha ./test/test.js", | ||
"testcompile": "cross-env BABEL_ENV=old babel test/test.mjs --out-file test/test.js" | ||
}, | ||
"dependencies": { | ||
"postcss": "6" | ||
"fonteditor-core": "^1.0.0", | ||
"mkdirp-promise": "^5.0.1", | ||
"postcss": "^6.0.0", | ||
"regenerator-runtime": "^0.11.1", | ||
"ttf2woff2": "^2.0.0", | ||
"util.promisify": "^1.0.0" | ||
}, | ||
@@ -27,12 +40,20 @@ "devDependencies": { | ||
"chai": "3.5.0", | ||
"cross-env": "^5.1.3", | ||
"eslint": "3.19.0", | ||
"mocha": "3.4.2", | ||
"postcss-merge-rules": "^4.0.0-rc.2" | ||
"npm-run-all": "^4.1.2", | ||
"postcss-icon.font-awesome-v4": "^0.0.1", | ||
"postcss-icon.material-design": "^0.0.2", | ||
"postcss-merge-rules": "^4.0.0-rc.2", | ||
"rimraf": "^2.6.2" | ||
}, | ||
"keywords": [ | ||
"css", | ||
"css-icon", | ||
"postcss", | ||
"css", | ||
"postcss-plugin", | ||
"css-icon" | ||
] | ||
"postcss-plugin" | ||
], | ||
"engines": { | ||
"node": ">= 4.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76312
22
1997
6
15
2
6
2
+ Addedfonteditor-core@^1.0.0
+ Addedmkdirp-promise@^5.0.1
+ Addedregenerator-runtime@^0.11.1
+ Addedttf2woff2@^2.0.0
+ Addedutil.promisify@^1.0.0
+ Addedabbrev@1.1.1(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedaproba@1.2.0(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarray.prototype.reduce@1.0.7(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedblock-stream@0.0.9(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbufferstreams@1.1.3(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedes-abstract@1.23.5(transitive)
+ Addedes-array-method-boxes-properly@1.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfonteditor-core@1.0.5(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfstream@1.0.12(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedgauge@2.7.4(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@1.0.02.0.5(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.63.0.1(transitive)
+ Addedmkdirp-promise@5.0.1(transitive)
+ Addednan@2.22.0(transitive)
+ Addednode-gyp@3.8.0(transitive)
+ Addednopt@3.0.6(transitive)
+ Addednpmlog@4.1.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedobject.getownpropertydescriptors@2.1.8(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpsl@1.10.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsemver@5.3.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedtar@2.2.2(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedttf2woff2@2.0.3(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedutil.promisify@1.1.2(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxmldom@0.1.31(transitive)
Updatedpostcss@^6.0.0