postcss-normalize-repeat-style
Advanced tools
Comparing version 4.0.2 to 5.0.0-rc.0
@@ -1,119 +0,155 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _postcss = require('postcss'); | ||
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser")); | ||
var _postcss2 = _interopRequireDefault(_postcss); | ||
var _cssnanoUtils = require("cssnano-utils"); | ||
var _postcssValueParser = require('postcss-value-parser'); | ||
var _map = _interopRequireDefault(require("./lib/map")); | ||
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments'); | ||
function evenValues(list, index) { | ||
return index % 2 === 0; | ||
} | ||
var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments); | ||
const repeatKeywords = _map.default.map(mapping => mapping[0]); | ||
var _cssnanoUtilGetMatch = require('cssnano-util-get-match'); | ||
const getMatch = (0, _cssnanoUtils.getMatch)(_map.default); | ||
var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch); | ||
function isCommaNode(node) { | ||
return node.type === 'div' && node.value === ','; | ||
} | ||
var _map = require('./lib/map'); | ||
function isVariableFunctionNode(node) { | ||
if (node.type !== 'function') { | ||
return false; | ||
} | ||
var _map2 = _interopRequireDefault(_map); | ||
return ['var', 'env'].includes(node.value.toLowerCase()); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function transform(value) { | ||
const parsed = (0, _postcssValueParser.default)(value); | ||
function evenValues(list, index) { | ||
return index % 2 === 0; | ||
} | ||
if (parsed.nodes.length === 1) { | ||
return value; | ||
} | ||
const repeatKeywords = _map2.default.map(mapping => mapping[0]); | ||
const ranges = []; | ||
let rangeIndex = 0; | ||
let shouldContinue = true; | ||
parsed.nodes.forEach((node, index) => { | ||
// After comma (`,`) follows next background | ||
if (isCommaNode(node)) { | ||
rangeIndex += 1; | ||
shouldContinue = true; | ||
return; | ||
} | ||
const getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default); | ||
if (!shouldContinue) { | ||
return; | ||
} // After separator (`/`) follows `background-size` values | ||
// Avoid them | ||
exports.default = _postcss2.default.plugin('postcss-normalize-repeat-style', () => { | ||
return css => { | ||
const cache = {}; | ||
css.walkDecls(/background(-repeat)?|(-webkit-)?mask-repeat/i, decl => { | ||
const value = decl.value; | ||
if (node.type === 'div' && node.value === '/') { | ||
shouldContinue = false; | ||
return; | ||
} | ||
if (cache[value]) { | ||
decl.value = cache[value]; | ||
if (!ranges[rangeIndex]) { | ||
ranges[rangeIndex] = { | ||
start: null, | ||
end: null | ||
}; | ||
} // Do not try to be processed `var and `env` function inside background | ||
return; | ||
} | ||
const parsed = (0, _postcssValueParser2.default)(value); | ||
if (isVariableFunctionNode(node)) { | ||
shouldContinue = false; | ||
ranges[rangeIndex].start = null; | ||
ranges[rangeIndex].end = null; | ||
return; | ||
} | ||
if (parsed.nodes.length === 1) { | ||
cache[value] = value; | ||
const isRepeatKeyword = node.type === 'word' && repeatKeywords.includes(node.value.toLowerCase()); | ||
return; | ||
} | ||
if (ranges[rangeIndex].start === null && isRepeatKeyword) { | ||
ranges[rangeIndex].start = index; | ||
ranges[rangeIndex].end = index; | ||
return; | ||
} | ||
const args = (0, _cssnanoUtilGetArguments2.default)(parsed); | ||
const relevant = []; | ||
if (ranges[rangeIndex].start !== null) { | ||
if (node.type === 'space') { | ||
return; | ||
} else if (isRepeatKeyword) { | ||
ranges[rangeIndex].end = index; | ||
return; | ||
} | ||
args.forEach(arg => { | ||
relevant.push({ | ||
start: null, | ||
end: null | ||
}); | ||
return; | ||
} | ||
}); | ||
ranges.forEach(range => { | ||
if (range.start === null) { | ||
return; | ||
} | ||
arg.forEach((part, index) => { | ||
const isRepeat = ~repeatKeywords.indexOf(part.value.toLowerCase()); | ||
const len = relevant.length - 1; | ||
const nodes = parsed.nodes.slice(range.start, range.end + 1); | ||
if (relevant[len].start === null && isRepeat) { | ||
relevant[len].start = index; | ||
relevant[len].end = index; | ||
if (nodes.length !== 3) { | ||
return; | ||
} | ||
return; | ||
} | ||
const match = getMatch(nodes.filter(evenValues).map(n => n.value.toLowerCase())); | ||
if (relevant[len].start !== null) { | ||
if (part.type === 'space') { | ||
return; | ||
} else if (isRepeat) { | ||
relevant[len].end = index; | ||
if (match) { | ||
nodes[0].value = match; | ||
nodes[1].value = nodes[2].value = ''; | ||
} | ||
}); | ||
return parsed.toString(); | ||
} | ||
return; | ||
} | ||
function pluginCreator() { | ||
return { | ||
postcssPlugin: 'postcss-normalize-repeat-style', | ||
return; | ||
} | ||
}); | ||
}); | ||
prepare() { | ||
const cache = {}; | ||
return { | ||
OnceExit(css) { | ||
css.walkDecls(/^(background(-repeat)?|(-\w+-)?mask-repeat)$/i, decl => { | ||
const value = decl.value; | ||
relevant.forEach((range, index) => { | ||
if (range.start === null) { | ||
return; | ||
} | ||
if (!value) { | ||
return; | ||
} | ||
const val = args[index].slice(range.start, range.end + 1); | ||
if (cache[value]) { | ||
decl.value = cache[value]; | ||
return; | ||
} | ||
if (val.length !== 3) { | ||
return; | ||
} | ||
const result = transform(value); | ||
decl.value = result; | ||
cache[value] = result; | ||
}); | ||
} | ||
const match = getMatch(val.filter(evenValues).map(n => n.value.toLowerCase())); | ||
}; | ||
} | ||
if (match) { | ||
args[index][range.start].value = match; | ||
args[index][range.start + 1].value = ''; | ||
args[index][range.end].value = ''; | ||
} | ||
}); | ||
}; | ||
} | ||
const result = parsed.toString(); | ||
decl.value = result; | ||
cache[value] = result; | ||
}); | ||
}; | ||
}); | ||
module.exports = exports['default']; | ||
pluginCreator.postcss = true; | ||
var _default = pluginCreator; | ||
exports.default = _default; | ||
module.exports = exports.default; |
@@ -1,7 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = [['repeat-x', ['repeat', 'no-repeat']], ['repeat-y', ['no-repeat', 'repeat']], ['repeat', ['repeat', 'repeat']], ['space', ['space', 'space']], ['round', ['round', 'round']], ['no-repeat', ['no-repeat', 'no-repeat']]]; | ||
module.exports = exports['default']; | ||
exports.default = void 0; | ||
var _default = [['repeat-x', ['repeat', 'no-repeat']], ['repeat-y', ['no-repeat', 'repeat']], ['repeat', ['repeat', 'repeat']], ['space', ['space', 'space']], ['round', ['round', 'round']], ['no-repeat', ['no-repeat', 'no-repeat']]]; | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-normalize-repeat-style", | ||
"version": "4.0.2", | ||
"version": "5.0.0-rc.0", | ||
"description": "Convert two value syntax for repeat-style into one value.", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/" | ||
"prebuild": "del-cli dist", | ||
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"", | ||
"prepublish": "yarn build" | ||
}, | ||
@@ -15,11 +17,5 @@ "files": [ | ||
"dependencies": { | ||
"cssnano-util-get-arguments": "^4.0.0", | ||
"cssnano-util-get-match": "^4.0.0", | ||
"postcss": "^7.0.0", | ||
"postcss-value-parser": "^3.0.0" | ||
"cssnano-utils": "^2.0.0-rc.0", | ||
"postcss-value-parser": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.0.0", | ||
"cross-env": "^5.0.0" | ||
}, | ||
"author": { | ||
@@ -36,4 +32,11 @@ "name": "Ben Briggs", | ||
"engines": { | ||
"node": ">=6.9.0" | ||
} | ||
"node": "^10 || ^12 || >=14.0" | ||
}, | ||
"devDependencies": { | ||
"postcss": "^8.2.1" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.2.1" | ||
}, | ||
"gitHead": "8c16e67a4d24a13ac7e09a36d4faf504196efd0f" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
8307
3
1
6
125
1
1
+ Addedcssnano-utils@^2.0.0-rc.0
+ Addedcssnano-utils@2.0.1(transitive)
+ Addednanoid@3.3.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedpostcss-value-parser@4.2.0(transitive)
+ Addedsource-map-js@1.2.1(transitive)
- Removedcssnano-util-get-arguments@^4.0.0
- Removedcssnano-util-get-match@^4.0.0
- Removedpostcss@^7.0.0
- Removedcssnano-util-get-arguments@4.0.0(transitive)
- Removedcssnano-util-get-match@4.0.0(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedpostcss-value-parser@3.3.1(transitive)
- Removedsource-map@0.6.1(transitive)
Updatedpostcss-value-parser@^4.1.0