Comparing version 2.0.2 to 2.0.3
@@ -0,1 +1,4 @@ | ||
### 2.0.3 - 23 Mar. 2016 | ||
* Guard against flipping tokens, e.g: [shadows starting with a color function](https://github.com/MohammadYounes/rtlcss/blob/master/test/data/special.js#L2-L7). | ||
### 2.0.2 - 05 Mar. 2016 | ||
@@ -32,4 +35,4 @@ * Fixes a bug in flipping background with a hex color value (Fixes [#60](https://github.com/MohammadYounes/rtlcss/issues/60)). | ||
* `stringMap`: | ||
* `priority` attribute to control maps execution order. | ||
* `exclusive` attributes, which determines if a map execution should stop iterating over other maps. | ||
* added `priority` attribute to control maps execution order. | ||
* added `exclusive` attribute, which determines if a map execution should stop iterating over other maps. | ||
* dropped 'west-east' map from the default map collection. | ||
@@ -151,3 +154,3 @@ | ||
## 0.2.1 - 20 Mar. 2014 | ||
### 0.2.1 - 20 Mar. 2014 | ||
* Upgrade to [POSTCSS] v0.3.4 | ||
@@ -160,10 +163,10 @@ | ||
## 0.1.3 - 7 Mar. 2014 | ||
### 0.1.3 - 7 Mar. 2014 | ||
* Fix missing include in rules.js | ||
## 0.1.2 - 5 Mar. 2014 | ||
### 0.1.2 - 5 Mar. 2014 | ||
* New option: minify output CSS. | ||
* Updated README.md | ||
## 0.1.1 - 4 Mar. 2014 | ||
### 0.1.1 - 4 Mar. 2014 | ||
* Initial commit. |
@@ -12,2 +12,3 @@ Writing an RTLCSS Plugin | ||
```js | ||
// minimal plugin definition | ||
{ | ||
@@ -70,7 +71,7 @@ 'name': 'sample plugin', | ||
An array of [declaration processors](#declaration-processors) where items are [declaration processor definition object](#declaration-processor-defintion-object). | ||
An array of [declaration processors](#declaration-processors) where items are [declaration processor definition object](#declaration-processor-definition-object). | ||
These are triggered by matching CSS properties against processor `expr` attribute. | ||
```js | ||
'property': [ | ||
'processors': [ | ||
{ | ||
@@ -77,0 +78,0 @@ // triggered via content property |
@@ -196,3 +196,3 @@ 'use strict' | ||
} | ||
var state = context.util.saveFunctions(value) | ||
var state = context.util.guardFunctions(value) | ||
var result = state.value.match(this.cache.match) | ||
@@ -205,3 +205,3 @@ if (result && result.length === 4 && (state.store.length > 0 || result[1] !== result[3])) { | ||
} | ||
return { 'prop': prop, 'value': context.util.restoreFunctions(state) } | ||
return { 'prop': prop, 'value': context.util.unguardFunctions(state) } | ||
} | ||
@@ -252,7 +252,7 @@ }, | ||
} | ||
var state = context.util.saveFunctions(value) | ||
var state = context.util.guardFunctions(value) | ||
state.value = state.value.replace(this.cache.slash, function (m) { | ||
return this.flip(m) | ||
}.bind(this)) | ||
return { 'prop': prop, 'value': context.util.restoreFunctions(state) } | ||
return { 'prop': prop, 'value': context.util.unguardFunctions(state) } | ||
} | ||
@@ -270,7 +270,7 @@ }, | ||
} | ||
var colorSafe = context.util.saveHexColors(value) | ||
var funcSafe = context.util.saveFunctions(colorSafe.value) | ||
var colorSafe = context.util.guardHexColors(value) | ||
var funcSafe = context.util.guardFunctions(colorSafe.value) | ||
funcSafe.value = funcSafe.value.replace(this.cache.replace, function (m) { return context.util.negate(m) }) | ||
colorSafe.value = context.util.restoreFunctions(funcSafe) | ||
return { 'prop': prop, 'value': context.util.restoreHexColors(colorSafe) } | ||
colorSafe.value = context.util.unguardFunctions(funcSafe) | ||
return { 'prop': prop, 'value': context.util.unguardHexColors(colorSafe) } | ||
} | ||
@@ -301,3 +301,3 @@ }, | ||
} else { | ||
var state = context.util.saveFunctions(value) | ||
var state = context.util.guardFunctions(value) | ||
var parts = state.value.match(this.cache.match) | ||
@@ -307,3 +307,3 @@ if (parts && parts.length > 0) { | ||
state.value = state.value.replace(this.cache.match, function () { return parts.shift() }) | ||
value = context.util.restoreFunctions(state) | ||
value = context.util.unguardFunctions(state) | ||
} | ||
@@ -359,6 +359,6 @@ } | ||
} | ||
var state = context.util.saveFunctions(value) | ||
var state = context.util.guardFunctions(value) | ||
return { | ||
'prop': prop, | ||
'value': context.util.restoreFunctions(state, function (v, n) { | ||
'value': context.util.unguardFunctions(state, function (v, n) { | ||
if (n.length) { | ||
@@ -426,4 +426,4 @@ if (n.match(this.cache.matrix3D)) { | ||
} | ||
var colorSafe = context.util.saveHexColors(value) | ||
var funcSafe = context.util.saveFunctions(colorSafe.value) | ||
var colorSafe = context.util.guardHexColors(value) | ||
var funcSafe = context.util.guardFunctions(colorSafe.value) | ||
var parts = funcSafe.value.split(',') | ||
@@ -436,6 +436,6 @@ if (prop.toLowerCase() !== 'background-image') { | ||
funcSafe.value = parts.join(',') | ||
colorSafe.value = context.util.restoreFunctions(funcSafe, this.update.bind(this, context)) | ||
colorSafe.value = context.util.unguardFunctions(funcSafe, this.update.bind(this, context)) | ||
return { | ||
'prop': prop, | ||
'value': context.util.restoreHexColors(colorSafe) | ||
'value': context.util.unguardHexColors(colorSafe) | ||
} | ||
@@ -476,3 +476,3 @@ } | ||
} | ||
var state = context.util.saveFunctions(value) | ||
var state = context.util.guardFunctions(value) | ||
var parts = state.value.split(',') | ||
@@ -485,3 +485,3 @@ for (var x = 0; x < parts.length; x++) { | ||
'prop': prop, | ||
'value': context.util.restoreFunctions(state, this.update.bind(this, context)) | ||
'value': context.util.unguardFunctions(state, this.update.bind(this, context)) | ||
} | ||
@@ -488,0 +488,0 @@ } |
/* | ||
* RTLCSS 2.0.1 https://github.com/MohammadYounes/rtlcss | ||
* RTLCSS 2.0.3 https://github.com/MohammadYounes/rtlcss | ||
* Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL). | ||
@@ -121,5 +121,6 @@ * Copyright 2016 Mohammad Younes. | ||
var raw = node.raws.value && node.raws.value.raw ? node.raws.value.raw : node.value | ||
var commentsLessRawValue = context.util.saveComments(raw) | ||
var pair = directive.action(node.prop, commentsLessRawValue, context) | ||
pair.value = context.util.restoreComments(pair.value) | ||
var state = context.util.saveComments(raw) | ||
var pair = directive.action(node.prop, state.value, context) | ||
state.value = pair.value | ||
pair.value = context.util.restoreComments(state) | ||
if (pair.prop !== node.prop || pair.value !== raw) { | ||
@@ -126,0 +127,0 @@ flipped++ |
108
lib/util.js
'use strict' | ||
var config | ||
var REPLACEMENT_CHARACTER = '\uFFFD' | ||
var REGEX_REPLACEMENT_CHARACTER_PLACEHOLDER = /\uFFFD/ig | ||
var CHAR_COMMENT_REPLACEMENT = '\uFFFD' // � | ||
var CHAR_TOKEN_REPLACEMENT = '\u00A4'// ¤ | ||
var CHAR_TOKEN_START = '\u00AB' // « | ||
var CHAR_TOKEN_END = '\u00BB' // » | ||
var REGEX_COMMENT_REPLACEMENT = new RegExp(CHAR_COMMENT_REPLACEMENT, 'ig') | ||
var REGEX_TOKEN_REPLACEMENT = new RegExp(CHAR_TOKEN_REPLACEMENT, 'ig') | ||
var PATTERN_NUMBER = '\\-?(\\d*?\\.\\d+|\\d+)' | ||
var PATTERN_PLACEHOLDER = '\u00AB\\d+\u00BB' // «offset» | ||
var PATTERN_NUMBER_WITH_CALC = '(calc' + CHAR_TOKEN_REPLACEMENT + ')|(' + PATTERN_NUMBER + ')(?!d\\()' | ||
var PATTERN_TOKEN = CHAR_TOKEN_START + '\\d+:\\d+' + CHAR_TOKEN_END // «offset:index» | ||
var REGEX_COMMENT = /\/\*[^]*?\*\//igm // none-greedy | ||
var REGEX_DIRECTIVE = /\/\*(?:!)?rtl:[^]*?\*\//img | ||
var REGEX_ESCAPE = /[.*+?^${}()|[\]\\]/g | ||
var REGEX_FUNCTION = /\([^\(\)]+\)/i | ||
var REGEX_HEX_COLOR = /#[a-f0-9]{3,6}/ig | ||
var REGEX_COMMENT = /\/\*[^]*?\*\//igm // none-greedy | ||
var REGEX_FUNCTION = /\([^\(\)]+\)/i | ||
var REGEX_TOKEN = new RegExp(PATTERN_PLACEHOLDER + '(\\d+)', 'i') | ||
var REGEX_COMPLEMENT = new RegExp('(calc' + PATTERN_PLACEHOLDER + '\\d+)|(' + PATTERN_NUMBER + ')(?!d\\()', 'i') | ||
var REGEX_NEGATE_ONE = new RegExp('(calc' + PATTERN_PLACEHOLDER + '\\d+)|(' + PATTERN_NUMBER + ')(?!d\\()', 'i') | ||
var REGEX_NEGATE_ALL = new RegExp('(calc' + PATTERN_PLACEHOLDER + '\\d+)|(' + PATTERN_NUMBER + ')(?!d\\()', 'ig') | ||
var REGEX_TOKENS = new RegExp(PATTERN_TOKEN, 'ig') | ||
var REGEX_COMPLEMENT = new RegExp(PATTERN_NUMBER_WITH_CALC, 'i') | ||
var REGEX_NEGATE_ALL = new RegExp(PATTERN_NUMBER_WITH_CALC, 'ig') | ||
var REGEX_NEGATE_ONE = new RegExp(PATTERN_NUMBER_WITH_CALC, 'i') | ||
var DEFAULT_STRING_MAP_OPTIONS = { scope: '*', ignoreCase: true } | ||
@@ -78,29 +88,53 @@ var TOKEN_ID = 0 | ||
}, | ||
comments: [], | ||
saveComments: function (value) { | ||
return value.replace(REGEX_COMMENT, function (c) { this.comments.push(c); return REPLACEMENT_CHARACTER }.bind(this)) | ||
}, | ||
restoreComments: function (value) { | ||
var index = 0 | ||
var result = value.replace(REGEX_REPLACEMENT_CHARACTER_PLACEHOLDER, function () { | ||
return this.comments[index++] | ||
}.bind(this)) | ||
this.comments.length = 0 | ||
return result | ||
}, | ||
negate: function (value) { | ||
return value.replace(REGEX_NEGATE_ONE, function (num) { | ||
return REGEX_TOKEN.test(num) ? num.replace(REGEX_TOKEN, function (m) { return '(-1*' + m + ')' }) : parseFloat(num, 10) * -1 | ||
var state = this.saveTokens(value) | ||
state.value = state.value.replace(REGEX_NEGATE_ONE, function (num) { | ||
return REGEX_TOKEN_REPLACEMENT.test(num) ? num.replace(REGEX_TOKEN_REPLACEMENT, function (m) { return '(-1*' + m + ')' }) : parseFloat(num, 10) * -1 | ||
}) | ||
return this.restoreTokens(state) | ||
}, | ||
negateAll: function (value) { | ||
return value.replace(REGEX_NEGATE_ALL, function (num) { | ||
return REGEX_TOKEN.test(num) ? num.replace(REGEX_TOKEN, function (m) { return '(-1*' + m + ')' }) : parseFloat(num, 10) * -1 | ||
var state = this.saveTokens(value) | ||
state.value = state.value.replace(REGEX_NEGATE_ALL, function (num) { | ||
return REGEX_TOKEN_REPLACEMENT.test(num) ? num.replace(REGEX_TOKEN_REPLACEMENT, function (m) { return '(-1*' + m + ')' }) : parseFloat(num, 10) * -1 | ||
}) | ||
return this.restoreTokens(state) | ||
}, | ||
complement: function (value) { | ||
return value.replace(REGEX_COMPLEMENT, function (num) { | ||
return REGEX_TOKEN.test(num) ? num.replace(REGEX_TOKEN, function (m) { return '(100%-' + m + ')' }) : 100 - parseFloat(num, 10) | ||
var state = this.saveTokens(value) | ||
state.value = state.value.replace(REGEX_COMPLEMENT, function (num) { | ||
return REGEX_TOKEN_REPLACEMENT.test(num) ? num.replace(REGEX_TOKEN_REPLACEMENT, function (m) { return '(100%-' + m + ')' }) : 100 - parseFloat(num, 10) | ||
}) | ||
return this.restoreTokens(state) | ||
}, | ||
save: function (what, who, replacement, restorer) { | ||
var state = { | ||
value: who, | ||
store: [], | ||
replacement: replacement, | ||
restorer: restorer | ||
} | ||
state.value = state.value.replace(what, function (c) { state.store.push(c); return state.replacement }) | ||
return state | ||
}, | ||
restore: function (state) { | ||
var index = 0 | ||
var result = state.value.replace(state.restorer, function () { | ||
return state.store[index++] | ||
}) | ||
state.store.length = 0 | ||
return result | ||
}, | ||
saveComments: function (value) { | ||
return this.save(REGEX_COMMENT, value, CHAR_COMMENT_REPLACEMENT, REGEX_COMMENT_REPLACEMENT) | ||
}, | ||
restoreComments: function (state) { | ||
return this.restore(state) | ||
}, | ||
saveTokens: function (value) { | ||
return this.save(REGEX_TOKENS, value, CHAR_TOKEN_REPLACEMENT, REGEX_TOKEN_REPLACEMENT) | ||
}, | ||
restoreTokens: function (state) { | ||
return this.restore(state) | ||
}, | ||
guard: function (what, who, indexed) { | ||
@@ -111,3 +145,3 @@ var state = { | ||
offset: TOKEN_ID++, | ||
token: '\u00AB' + TOKEN_ID + '\u00BB', | ||
token: CHAR_TOKEN_START + TOKEN_ID, | ||
indexed: indexed === true | ||
@@ -117,6 +151,6 @@ } | ||
while (what.test(state.value)) { | ||
state.value = state.value.replace(what, function (m) { state.store.push(m); return state.token + state.store.length }) | ||
state.value = state.value.replace(what, function (m) { state.store.push(m); return state.token + ':' + state.store.length + CHAR_TOKEN_END }) | ||
} | ||
} else { | ||
state.value = state.value.replace(what, function (m) { state.store.push(m); return state.token }) | ||
state.value = state.value.replace(what, function (m) { state.store.push(m); return state.token + CHAR_TOKEN_END }) | ||
} | ||
@@ -127,3 +161,3 @@ return state | ||
if (state.indexed === true) { | ||
var detokenizer = new RegExp('(\\w*?)' + state.token + '(\\d+)', 'i') | ||
var detokenizer = new RegExp('(\\w*?)' + state.token + ':(\\d+)' + CHAR_TOKEN_END, 'i') | ||
while (detokenizer.test(state.value)) { | ||
@@ -140,3 +174,3 @@ state.value = state.value.replace(detokenizer, function (match, name, index) { | ||
} else { | ||
return state.value.replace(new RegExp('(\\w*?)' + state.token, 'i'), function (match, name) { | ||
return state.value.replace(new RegExp('(\\w*?)' + state.token + CHAR_TOKEN_END, 'i'), function (match, name) { | ||
var value = state.store.shift() | ||
@@ -150,12 +184,12 @@ if (typeof callback === 'function') { | ||
}, | ||
saveHexColors: function (value) { | ||
guardHexColors: function (value) { | ||
return this.guard(REGEX_HEX_COLOR, value, true) | ||
}, | ||
restoreHexColors: function (state, callback) { | ||
unguardHexColors: function (state, callback) { | ||
return this.unguard(state, callback) | ||
}, | ||
saveFunctions: function (value) { | ||
guardFunctions: function (value) { | ||
return this.guard(REGEX_FUNCTION, value, true) | ||
}, | ||
restoreFunctions: function (state, callback) { | ||
unguardFunctions: function (state, callback) { | ||
return this.unguard(state, callback) | ||
@@ -190,3 +224,3 @@ }, | ||
case 'calc': | ||
expression += '|(calc' + PATTERN_PLACEHOLDER + '\\d+)' | ||
expression += '|(calc' + PATTERN_TOKEN + ')' | ||
break | ||
@@ -193,0 +227,0 @@ } |
{ | ||
"author": "Mohammad Younes", | ||
"name": "rtlcss", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Framework for transforming cascading style sheets (CSS) from left-to-right (LTR) to right-to-left (RTL)", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/MohammadYounes/rtlcss/issues?state=open", |
@@ -17,3 +17,4 @@ /* global describe */ | ||
'# RTLCSS (String Map):': require('./data/rtlcss-stringMap.js'), | ||
'# RTLCSS (Plugins):': require('./data/rtlcss-plugins.js') | ||
'# RTLCSS (Plugins):': require('./data/rtlcss-plugins.js'), | ||
'# Special:': require('./data/special.js') | ||
} | ||
@@ -20,0 +21,0 @@ var key |
Sorry, the diff of this file is not supported yet
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
156692
36
2992