Comparing version 4.1.0 to 4.1.1
@@ -251,24 +251,24 @@ 'use strict' | ||
const parts = value.match(this.cache.match) | ||
if (!parts) return value | ||
let i | ||
if (parts) { | ||
switch (parts.length) { | ||
case 2: | ||
i = 1 | ||
if (parts[0] !== parts[1]) { | ||
value = value.replace(this.cache.match, () => parts[i--]) | ||
} | ||
switch (parts.length) { | ||
case 2: | ||
i = 1 | ||
if (parts[0] !== parts[1]) { | ||
value = value.replace(this.cache.match, () => parts[i--]) | ||
} | ||
break | ||
case 3: | ||
// preserve leading whitespace. | ||
value = value.replace(this.cache.white, (m) => `${m + parts[1]} `) | ||
break | ||
case 4: | ||
i = 0 | ||
if (parts[0] !== parts[1] || parts[2] !== parts[3]) { | ||
value = value.replace(this.cache.match, () => parts[(5 - i++) % 4]) | ||
} | ||
break | ||
case 3: | ||
// preserve leading whitespace. | ||
value = value.replace(this.cache.white, (m) => `${m + parts[1]} `) | ||
break | ||
case 4: | ||
i = 0 | ||
if (parts[0] !== parts[1] || parts[2] !== parts[3]) { | ||
value = value.replace(this.cache.match, () => parts[(5 - i++) % 4]) | ||
} | ||
break | ||
} | ||
break | ||
} | ||
@@ -328,4 +328,4 @@ | ||
this.cache = { | ||
match: context.util.regex(['calc', 'percent', 'length'], 'g'), | ||
percent: context.util.regex(['calc', 'percent'], 'i'), | ||
match: context.util.regex(['func', 'percent', 'length'], 'g'), | ||
percent: context.util.regex(['func', 'percent'], 'i'), | ||
length: context.util.regex(['length'], 'gi'), | ||
@@ -384,3 +384,3 @@ xKeyword: /(left|right|center)/i | ||
negatable: /((translate)(x|3d)?|rotate(z|y)?)$/ig, | ||
unit: context.util.regex(['calc', 'number'], 'g'), | ||
unit: context.util.regex(['func', 'number'], 'g'), | ||
matrix: /matrix$/i, | ||
@@ -397,15 +397,16 @@ matrix3D: /matrix3d$/i, | ||
value: context.util.unguardFunctions(state, (v, n) => { | ||
if (n.length) { | ||
if (n.match(this.cache.matrix3D)) { | ||
v = this.flipMatrix3D(v, context) | ||
} else if (n.match(this.cache.matrix)) { | ||
v = this.flipMatrix(v, context) | ||
} else if (n.match(this.cache.rotate3D)) { | ||
v = this.flipRotate3D(v, context) | ||
} else if (n.match(this.cache.skewXY)) { | ||
v = context.util.negateAll(v) | ||
} else if (n.match(this.cache.negatable)) { | ||
v = context.util.negate(v) | ||
} | ||
if (n.length === 0) return v | ||
if (n.match(this.cache.matrix3D)) { | ||
v = this.flipMatrix3D(v, context) | ||
} else if (n.match(this.cache.matrix)) { | ||
v = this.flipMatrix(v, context) | ||
} else if (n.match(this.cache.rotate3D)) { | ||
v = this.flipRotate3D(v, context) | ||
} else if (n.match(this.cache.skewXY)) { | ||
v = context.util.negateAll(v) | ||
} else if (n.match(this.cache.negatable)) { | ||
v = context.util.negate(v) | ||
} | ||
return v | ||
@@ -431,25 +432,25 @@ }) | ||
if (parts && parts.length > 0) { | ||
const keywords = (state.value.match(this.cache.position) || '').length | ||
if (/* edge offsets */ parts.length >= 3 || /* keywords only */ keywords === 2) { | ||
state.value = util.swapLeftRight(state.value) | ||
if (!parts || parts.length === 0) return util.restoreTokens(state) | ||
const keywords = (state.value.match(this.cache.position) || '').length | ||
if (/* edge offsets */ parts.length >= 3 || /* keywords only */ keywords === 2) { | ||
state.value = util.swapLeftRight(state.value) | ||
} else { | ||
if (parts[0] === '0') { | ||
parts[0] = '100%' | ||
} else if (parts[0].match(this.cache.percent)) { | ||
parts[0] = context.util.complement(parts[0]) | ||
} else if (parts[0].match(this.cache.length)) { | ||
if (isPositionX) { | ||
parts[0] = context.util.flipLength(parts[0]) | ||
} else if (parts.length === 1) { // X 50% ==> left X top 50% | ||
parts[0] = `right ${parts[0]} top 50%` | ||
} else if (!keywords && parts.length === 2) { // X Y ==> left X top Y | ||
parts[0] = `right ${parts[0]}` | ||
parts[1] = `top ${parts[1]}` | ||
} | ||
} else { | ||
if (parts[0] === '0') { | ||
parts[0] = '100%' | ||
} else if (parts[0].match(this.cache.percent)) { | ||
parts[0] = context.util.complement(parts[0]) | ||
} else if (parts[0].match(this.cache.length)) { | ||
if (isPositionX) { | ||
parts[0] = context.util.flipLength(parts[0]) | ||
} else if (parts.length === 1) { // X 50% ==> left X top 50% | ||
parts[0] = `right ${parts[0]} top 50%` | ||
} else if (!keywords && parts.length === 2) { // X Y ==> left X top Y | ||
parts[0] = `right ${parts[0]}` | ||
parts[1] = `top ${parts[1]}` | ||
} | ||
} else { | ||
parts[0] = context.util.swapLeftRight(parts[0]) | ||
} | ||
state.value = state.value.replace(this.cache.match, () => parts.shift()) | ||
parts[0] = context.util.swapLeftRight(parts[0]) | ||
} | ||
state.value = state.value.replace(this.cache.match, () => parts.shift()) | ||
} | ||
@@ -474,3 +475,3 @@ | ||
match: context.util.regex(['position', 'percent', 'length', 'calc'], 'ig'), | ||
percent: context.util.regex(['calc', 'percent'], 'i'), | ||
percent: context.util.regex(['func', 'percent'], 'i'), | ||
position: context.util.regex(['position'], 'g'), | ||
@@ -477,0 +478,0 @@ length: context.util.regex(['length'], 'gi'), |
@@ -32,23 +32,22 @@ /** | ||
function shouldProcess (node, result) { | ||
if (!node[processed]) { | ||
let prevent = false | ||
state.walk((current) => { | ||
// check if current directive is expecting this node | ||
if (!current.metadata.blacklist && current.directive.expect[node.type]) { | ||
// perform action and prevent further processing if result equals true | ||
if (current.directive.begin(node, current.metadata, context)) { | ||
prevent = true | ||
} | ||
if (node[processed]) return false | ||
// if should end? end it. | ||
if (current.metadata.end && current.directive.end(node, current.metadata, context)) { | ||
state.pop(current) | ||
} | ||
let prevent = false | ||
state.walk((current) => { | ||
// check if current directive is expecting this node | ||
if (!current.metadata.blacklist && current.directive.expect[node.type]) { | ||
// perform action and prevent further processing if result equals true | ||
if (current.directive.begin(node, current.metadata, context)) { | ||
prevent = true | ||
} | ||
}) | ||
node[processed] = true | ||
return !prevent | ||
} | ||
return false | ||
// if should end? end it. | ||
if (current.metadata.end && current.directive.end(node, current.metadata, context)) { | ||
state.pop(current) | ||
} | ||
} | ||
}) | ||
node[processed] = true | ||
return !prevent | ||
} | ||
@@ -77,122 +76,126 @@ | ||
Comment (node, { result }) { | ||
if (shouldProcess(node)) { | ||
state.parse(node, result, (current) => { | ||
let push = true | ||
if (current.directive === null) { | ||
current.preserve = !context.config.clean | ||
context.util.each(context.config.plugins, (plugin) => { | ||
const blacklist = context.config.blacklist[plugin.name] | ||
if (blacklist && blacklist[current.metadata.name] === true) { | ||
current.metadata.blacklist = true | ||
if (current.metadata.end) { | ||
push = false | ||
} | ||
if (!shouldProcess(node)) return | ||
if (current.metadata.begin) { | ||
result.warn(`directive "${plugin.name}.${current.metadata.name}" is blacklisted.`, { node: current.source }) | ||
} | ||
// break each | ||
return false | ||
state.parse(node, result, (current) => { | ||
let push = true | ||
if (current.directive === null) { | ||
current.preserve = !context.config.clean | ||
context.util.each(context.config.plugins, (plugin) => { | ||
const blacklist = context.config.blacklist[plugin.name] | ||
if (blacklist && blacklist[current.metadata.name] === true) { | ||
current.metadata.blacklist = true | ||
if (current.metadata.end) { | ||
push = false | ||
} | ||
current.directive = plugin.directives.control[current.metadata.name] | ||
if (current.directive) { | ||
// break each | ||
return false | ||
if (current.metadata.begin) { | ||
result.warn(`directive "${plugin.name}.${current.metadata.name}" is blacklisted.`, { node: current.source }) | ||
} | ||
}) | ||
} | ||
if (current.directive) { | ||
if (!current.metadata.begin && current.metadata.end) { | ||
if (current.directive.end(node, current.metadata, context)) { | ||
state.pop(current) | ||
} | ||
// break each | ||
return false | ||
} | ||
push = false | ||
} else if ( | ||
current.directive.expect.self && current.directive.begin(node, current.metadata, context) && | ||
current.metadata.end && current.directive.end(node, current.metadata, context) | ||
) { | ||
push = false | ||
current.directive = plugin.directives.control[current.metadata.name] | ||
if (current.directive) { | ||
// break each | ||
return false | ||
} | ||
} else if (!current.metadata.blacklist) { | ||
}) | ||
} | ||
if (current.directive) { | ||
if (!current.metadata.begin && current.metadata.end) { | ||
if (current.directive.end(node, current.metadata, context)) { | ||
state.pop(current) | ||
} | ||
push = false | ||
result.warn(`unsupported directive "${current.metadata.name}".`, { node: current.source }) | ||
} else if ( | ||
current.directive.expect.self && current.directive.begin(node, current.metadata, context) && | ||
current.metadata.end && current.directive.end(node, current.metadata, context) | ||
) { | ||
push = false | ||
} | ||
} else if (!current.metadata.blacklist) { | ||
push = false | ||
result.warn(`unsupported directive "${current.metadata.name}".`, { node: current.source }) | ||
} | ||
return push | ||
}) | ||
} | ||
return push | ||
}) | ||
}, | ||
Declaration (node, { result }) { | ||
if (shouldProcess(node)) { | ||
// if broken by a matching value directive .. break | ||
if (!context.util.each(context.config.plugins, (plugin) => { | ||
return context.util.each(plugin.directives.value, (directive) => { | ||
const hasRawValue = node.raws.value && node.raws.value.raw | ||
const expr = context.util.regexDirective(directive.name) | ||
if (expr.test(`${node.raws.between}${hasRawValue ? node.raws.value.raw : node.value}${node.important && node.raws.important ? node.raws.important : ''}`)) { | ||
expr.lastIndex = 0 | ||
if (directive.action(node, expr, context)) { | ||
if (context.config.clean) { | ||
node.raws.between = context.util.trimDirective(node.raws.between) | ||
if (node.important && node.raws.important) { | ||
node.raws.important = context.util.trimDirective(node.raws.important) | ||
} | ||
if (!shouldProcess(node)) return | ||
node.value = hasRawValue | ||
? (node.raws.value.raw = context.util.trimDirective(node.raws.value.raw)) | ||
: context.util.trimDirective(node.value) | ||
// if broken by a matching value directive .. break | ||
if (!context.util.each(context.config.plugins, (plugin) => { | ||
return context.util.each(plugin.directives.value, (directive) => { | ||
const hasRawValue = node.raws.value && node.raws.value.raw | ||
const expr = context.util.regexDirective(directive.name) | ||
if (expr.test(`${node.raws.between}${hasRawValue ? node.raws.value.raw : node.value}${node.important && node.raws.important ? node.raws.important : ''}`)) { | ||
expr.lastIndex = 0 | ||
if (directive.action(node, expr, context)) { | ||
if (context.config.clean) { | ||
node.raws.between = context.util.trimDirective(node.raws.between) | ||
if (node.important && node.raws.important) { | ||
node.raws.important = context.util.trimDirective(node.raws.important) | ||
} | ||
flipped++ | ||
// break | ||
return false | ||
node.value = hasRawValue | ||
? (node.raws.value.raw = context.util.trimDirective(node.raws.value.raw)) | ||
: context.util.trimDirective(node.value) | ||
} | ||
} | ||
}) | ||
})) return | ||
// loop over all plugins/property processors | ||
context.util.each(context.config.plugins, (plugin) => { | ||
return context.util.each(plugin.processors, (processor) => { | ||
const alias = context.config.aliases[node.prop] | ||
if ((alias || node.prop).match(processor.expr)) { | ||
const raw = node.raws.value && node.raws.value.raw ? node.raws.value.raw : node.value | ||
const state = context.util.saveComments(raw) | ||
if (context.config.processEnv) { | ||
state.value = context.util.swap(state.value, 'safe-area-inset-left', 'safe-area-inset-right', { ignoreCase: false }) | ||
} | ||
const pair = processor.action(node.prop, state.value, context) | ||
state.value = pair.value | ||
pair.value = context.util.restoreComments(state) | ||
if ((!alias && pair.prop !== node.prop) || pair.value !== raw) { | ||
flipped++ | ||
node.prop = pair.prop | ||
node.value = pair.value | ||
} | ||
// match found, break | ||
flipped++ | ||
// break | ||
return false | ||
} | ||
}) | ||
} | ||
}) | ||
// if last decl, apply auto rename | ||
// decl. may be found inside @rules | ||
if (context.config.autoRename && !flipped && node.parent.type === 'rule' && context.util.isLastOfType(node)) { | ||
const renamed = context.util.applyStringMap(node.parent.selector) | ||
if (context.config.autoRenameStrict === true) { | ||
const pair = toBeRenamed[renamed] | ||
if (pair) { | ||
pair.selector = node.parent.selector | ||
node.parent.selector = renamed | ||
} else { | ||
toBeRenamed[node.parent.selector] = node.parent | ||
})) return | ||
// loop over all plugins/property processors | ||
context.util.each(context.config.plugins, (plugin) => { | ||
return context.util.each(plugin.processors, (processor) => { | ||
const alias = context.config.aliases[node.prop] | ||
if ((alias || node.prop).match(processor.expr)) { | ||
const raw = node.raws.value && node.raws.value.raw ? node.raws.value.raw : node.value | ||
const state = context.util.saveComments(raw) | ||
if (context.config.processEnv) { | ||
state.value = context.util.swap(state.value, 'safe-area-inset-left', 'safe-area-inset-right', { ignoreCase: false }) | ||
} | ||
} else { | ||
node.parent.selector = renamed | ||
const pair = processor.action(node.prop, state.value, context) | ||
state.value = pair.value | ||
pair.value = context.util.restoreComments(state) | ||
if ((!alias && pair.prop !== node.prop) || pair.value !== raw) { | ||
flipped++ | ||
node.prop = pair.prop | ||
node.value = pair.value | ||
} | ||
// match found, break | ||
return false | ||
} | ||
}) | ||
}) | ||
// if last decl, apply auto rename | ||
// decl. may be found inside @rules | ||
if (!(context.config.autoRename && !flipped && node.parent.type === 'rule' && context.util.isLastOfType(node))) { | ||
return | ||
} | ||
const renamed = context.util.applyStringMap(node.parent.selector) | ||
if (context.config.autoRenameStrict === true) { | ||
const pair = toBeRenamed[renamed] | ||
if (pair) { | ||
pair.selector = node.parent.selector | ||
node.parent.selector = renamed | ||
} else { | ||
toBeRenamed[node.parent.selector] = node.parent | ||
} | ||
} else { | ||
node.parent.selector = renamed | ||
} | ||
@@ -205,4 +208,4 @@ }, | ||
for (const key of Object.keys(toBeRenamed)) { | ||
result.warn('renaming skipped due to lack of a matching pair.', { node: toBeRenamed[key] }) | ||
for (const value of Object.values(toBeRenamed)) { | ||
result.warn('renaming skipped due to lack of a matching pair.', { node: value }) | ||
} | ||
@@ -209,0 +212,0 @@ |
@@ -18,24 +18,34 @@ 'use strict' | ||
parse (node, lazyResult, callback) { | ||
const metadata = directiveParser(node) | ||
if (!metadata) return | ||
let current | ||
const metadata = directiveParser(node) | ||
if (metadata) { | ||
if (!metadata.begin && metadata.end) { | ||
this.walk((item) => { | ||
if (metadata.name === item.metadata.name) { | ||
this.pop(item) | ||
current = { metadata, directive: item.directive, source: node, preserve: item.preserve } | ||
return false | ||
if (!metadata.begin && metadata.end) { | ||
this.walk((item) => { | ||
if (metadata.name === item.metadata.name) { | ||
this.pop(item) | ||
current = { | ||
metadata, | ||
directive: item.directive, | ||
source: node, | ||
preserve: item.preserve | ||
} | ||
}) | ||
} else { | ||
current = { metadata, directive: null, source: node, preserve: null } | ||
return false | ||
} | ||
}) | ||
} else { | ||
current = { | ||
metadata, | ||
directive: null, | ||
source: node, | ||
preserve: null | ||
} | ||
} | ||
if (current === undefined) { | ||
lazyResult.warn(`found end "${metadata.name}" without a matching begin.`, { node }) | ||
} else if (callback(current)) { | ||
this.stack.push(current) | ||
} else if (!current.preserve) { | ||
current.source.remove() | ||
} | ||
if (current === undefined) { | ||
lazyResult.warn(`found end "${metadata.name}" without a matching begin.`, { node }) | ||
} else if (callback(current)) { | ||
this.stack.push(current) | ||
} else if (!current.preserve) { | ||
current.source.remove() | ||
} | ||
@@ -42,0 +52,0 @@ }, |
@@ -231,2 +231,5 @@ 'use strict' | ||
break | ||
case 'func': | ||
expression += `|(\\w+${PATTERN_TOKEN})` | ||
break | ||
} | ||
@@ -233,0 +236,0 @@ } |
{ | ||
"author": "Mohammad Younes", | ||
"name": "rtlcss", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Framework for transforming cascading style sheets (CSS) from left-to-right (LTR) to right-to-left (RTL)", | ||
@@ -6,0 +6,0 @@ "homepage": "https://rtlcss.com/", |
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
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
1461
51751