rtl-css-js
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -110,2 +110,20 @@ 'use strict'; | ||
return propertyValueConverters.backgroundPosition(value); | ||
}, | ||
transform: function transform(value) { | ||
// This was copied and modified from CSSJanus: | ||
// https://github.com/cssjanus/cssjanus/blob/4a40f001b1ba35567112d8b8e1d9d95eda4234c3/src/cssjanus.js#L152-L153 | ||
var nonAsciiPattern = '[^\\u0020-\\u007e]'; | ||
var unicodePattern = '(?:(?:\\[0-9a-f]{1,6})(?:\\r\\n|\\s)?)'; | ||
var numPattern = '(?:[0-9]*\\.[0-9]+|[0-9]+)'; | ||
var unitPattern = '(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)'; | ||
var escapePattern = '(?:' + unicodePattern + '|\\\\[^\\r\\n\\f0-9a-f])'; | ||
var nmstartPattern = '(?:[_a-z]|' + nonAsciiPattern + '|' + escapePattern + ')'; | ||
var nmcharPattern = '(?:[_a-z0-9-]|' + nonAsciiPattern + '|' + escapePattern + ')'; | ||
var identPattern = '-?' + nmstartPattern + nmcharPattern + '*'; | ||
var quantPattern = numPattern + '(?:\\s*' + unitPattern + '|' + identPattern + ')?'; | ||
var signedQuantPattern = '((?:-?' + quantPattern + ')|(?:inherit|auto))'; | ||
var translateXRegExp = new RegExp('(translateX\\s*\\(\\s*)' + signedQuantPattern + '(\\s*\\))', 'gi'); | ||
var translateRegExp = new RegExp('(translate\\s*\\(\\s*)' + signedQuantPattern + '((?:\\s*,\\s*' + signedQuantPattern + '){0,1}\\s*\\))', 'gi'); | ||
var translate3dRegExp = new RegExp('(translate3d\\s*\\(\\s*)' + signedQuantPattern + '((?:\\s*,\\s*' + signedQuantPattern + '){0,2}\\s*\\))', 'gi'); | ||
return value.replace(translateXRegExp, calculateNewTranslate).replace(translateRegExp, calculateNewTranslate).replace(translate3dRegExp, calculateNewTranslate); | ||
} | ||
@@ -119,2 +137,4 @@ }; | ||
propertyValueConverters.borderStyle = propertyValueConverters.borderColor; | ||
propertyValueConverters.webkitTransform = propertyValueConverters.transform; | ||
propertyValueConverters.mozTransform = propertyValueConverters.transform; | ||
@@ -271,2 +291,28 @@ // here's our main export! 👋 | ||
/** | ||
* Flip the sign of a CSS value, possibly with a unit. | ||
* | ||
* We can't just negate the value with unary minus due to the units. | ||
* | ||
* @private | ||
* @param {String} value - the original value (for example 77%) | ||
* @return {String} the result (for example -77%) | ||
*/ | ||
function flipSign(value) { | ||
if (parseFloat(value) === 0) { | ||
// Don't mangle zeroes | ||
return value; | ||
} | ||
if (value[0] === '-') { | ||
return value.slice(1); | ||
} | ||
return '-' + value; | ||
} | ||
function calculateNewTranslate(match, prefix, offset, suffix) { | ||
return prefix + flipSign(offset) + suffix; | ||
} | ||
/** | ||
* Takes an array of [keyValue1, keyValue2] pairs and creates an object of {keyValue1: keyValue2, keyValue2: keyValue1} | ||
@@ -273,0 +319,0 @@ * @param {Array} array the array of pairs |
@@ -181,2 +181,20 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
return propertyValueConverters.backgroundPosition(value); | ||
}, | ||
transform: function transform(value) { | ||
// This was copied and modified from CSSJanus: | ||
// https://github.com/cssjanus/cssjanus/blob/4a40f001b1ba35567112d8b8e1d9d95eda4234c3/src/cssjanus.js#L152-L153 | ||
var nonAsciiPattern = '[^\\u0020-\\u007e]'; | ||
var unicodePattern = '(?:(?:\\[0-9a-f]{1,6})(?:\\r\\n|\\s)?)'; | ||
var numPattern = '(?:[0-9]*\\.[0-9]+|[0-9]+)'; | ||
var unitPattern = '(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)'; | ||
var escapePattern = '(?:' + unicodePattern + '|\\\\[^\\r\\n\\f0-9a-f])'; | ||
var nmstartPattern = '(?:[_a-z]|' + nonAsciiPattern + '|' + escapePattern + ')'; | ||
var nmcharPattern = '(?:[_a-z0-9-]|' + nonAsciiPattern + '|' + escapePattern + ')'; | ||
var identPattern = '-?' + nmstartPattern + nmcharPattern + '*'; | ||
var quantPattern = numPattern + '(?:\\s*' + unitPattern + '|' + identPattern + ')?'; | ||
var signedQuantPattern = '((?:-?' + quantPattern + ')|(?:inherit|auto))'; | ||
var translateXRegExp = new RegExp('(translateX\\s*\\(\\s*)' + signedQuantPattern + '(\\s*\\))', 'gi'); | ||
var translateRegExp = new RegExp('(translate\\s*\\(\\s*)' + signedQuantPattern + '((?:\\s*,\\s*' + signedQuantPattern + '){0,1}\\s*\\))', 'gi'); | ||
var translate3dRegExp = new RegExp('(translate3d\\s*\\(\\s*)' + signedQuantPattern + '((?:\\s*,\\s*' + signedQuantPattern + '){0,2}\\s*\\))', 'gi'); | ||
return value.replace(translateXRegExp, calculateNewTranslate).replace(translateRegExp, calculateNewTranslate).replace(translate3dRegExp, calculateNewTranslate); | ||
} | ||
@@ -190,2 +208,4 @@ }; | ||
propertyValueConverters.borderStyle = propertyValueConverters.borderColor; | ||
propertyValueConverters.webkitTransform = propertyValueConverters.transform; | ||
propertyValueConverters.mozTransform = propertyValueConverters.transform; | ||
@@ -342,2 +362,28 @@ // here's our main export! 👋 | ||
/** | ||
* Flip the sign of a CSS value, possibly with a unit. | ||
* | ||
* We can't just negate the value with unary minus due to the units. | ||
* | ||
* @private | ||
* @param {String} value - the original value (for example 77%) | ||
* @return {String} the result (for example -77%) | ||
*/ | ||
function flipSign(value) { | ||
if (parseFloat(value) === 0) { | ||
// Don't mangle zeroes | ||
return value; | ||
} | ||
if (value[0] === '-') { | ||
return value.slice(1); | ||
} | ||
return '-' + value; | ||
} | ||
function calculateNewTranslate(match, prefix, offset, suffix) { | ||
return prefix + flipSign(offset) + suffix; | ||
} | ||
/** | ||
* Takes an array of [keyValue1, keyValue2] pairs and creates an object of {keyValue1: keyValue2, keyValue2: keyValue1} | ||
@@ -344,0 +390,0 @@ * @param {Array} array the array of pairs |
@@ -1,2 +0,2 @@ | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.rtlCSSJS=t():r.rtlCSSJS=t()}(this,function(){return function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){"use strict";var n=e(1);r.exports=n.default;for(var o in n)n.hasOwnProperty(o)&&(r.exports[o]=n[o])},function(r,t){"use strict";function e(r){return Object.keys(r).reduce(function(t,e){var o=r[e];s(o)&&(o=o.trim());var i=n(e,o),u=i.key,a=i.value;return t[u]=a,t},{})}function n(r,t){var e=/\/\*\s?@noflip\s?\*\//.test(t),n=e?r:o(r),u=e?t:i(n,t);return{key:n,value:u}}function o(r){return h[r]||r}function i(r,t){if(null===t||"undefined"==typeof t)return t;if(l(t))return e(t);var n=c(t),o=n?t:t.replace(/ !important.*?$/,""),i=!n&&o.length!==t.length,u=m[r],a=void 0;return a=u?u(o):y[o]||o,i?a+" !important":a}function u(r){return r.replace(/ +/g," ").split(" ").map(function(r){return r.trim()}).filter(Boolean).reduce(function(r,t){var e=r.list,n=r.state,o=(t.match(/\(/g)||[]).length,i=(t.match(/\)/g)||[]).length;return n.parensDepth>0?e[e.length-1]=e[e.length-1]+" "+t:e.push(t),n.parensDepth+=o-i,{list:e,state:n}},{list:[],state:{parensDepth:0}}).list}function a(r){var t=u(r);if(t.length<=3||t.length>4)return r;var e=g(t,4),n=e[0],o=e[1],i=e[2],a=e[3];return[n,a,i,o].join(" ")}function f(r){var t=r.indexOf(".");if(t===-1)r=100-parseFloat(r)+"%";else{var e=r.length-t-2;r=100-parseFloat(r),r=r.toFixed(e)+"%"}return r}function d(r){return r.reduce(function(r,t){var e=g(t,2),n=e[0],o=e[1];return r[n]=o,r[o]=n,r},{})}function c(r){return"number"==typeof r}function l(r){return r&&"object"===("undefined"==typeof r?"undefined":b(r))}function s(r){return"string"==typeof r}function p(r,t){return r.indexOf(t)!==-1}Object.defineProperty(t,"__esModule",{value:!0});var b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},g=function(){function r(r,t){var e=[],n=!0,o=!1,i=void 0;try{for(var u,a=r[Symbol.iterator]();!(n=(u=a.next()).done)&&(e.push(u.value),!t||e.length!==t);n=!0);}catch(r){o=!0,i=r}finally{try{!n&&a.return&&a.return()}finally{if(o)throw i}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return r(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=d([["paddingLeft","paddingRight"],["marginLeft","marginRight"],["left","right"],["borderLeft","borderRight"],["borderLeftColor","borderRightColor"],["borderLeftStyle","borderRightStyle"],["borderLeftWidth","borderRightWidth"],["borderTopLeftRadius","borderTopRightRadius"],["borderBottomLeftRadius","borderBottomRightRadius"]]),y=d([["ltr","rtl"],["left","right"],["w-resize","e-resize"],["sw-resize","se-resize"],["nw-resize","ne-resize"]]),m={padding:function(r){return c(r)?r:a(r)},textShadow:function(r){return r.replace(/(-*)([.|\d]+)/,function(r,t,e){if("0"===e)return r;var n=""===t?"-":"";return""+n+e})},borderColor:function(r){return a(r)},borderRadius:function(r){if(c(r))return r;if(p(r,"/")){var t=r.split("/"),e=g(t,2),n=e[0],o=e[1],i=m.borderRadius(n.trim()),a=m.borderRadius(o.trim());return i+" / "+a}var f=u(r);switch(f.length){case 2:return f.reverse().join(" ");case 4:var d=g(f,4),l=d[0],s=d[1],b=d[2],h=d[3];return[s,l,h,b].join(" ");default:return r}},background:function(r){var t=r.replace(/(url\(.*?\))|(rgba?\(.*?\))|(hsl\(.*?\))|(#[a-fA-F0-9]+)|((^| )(\D)+( |$))/g,"").trim();return r=r.replace(t,m.backgroundPosition(t)),m.backgroundImage(r)},backgroundImage:function(r){return p(r,"url(")?r.replace(/(^|\W|_)((ltr)|(rtl)|(left)|(right))(\W|_|$)/g,function(r,t,e){return r.replace(e,y[e])}):r},backgroundPosition:function(r){return r.replace(/^((-|\d|\.)+%)/,function(r,t){return f(t)}).replace(/(left)|(right)/,function(r){return y[r]})},backgroundPositionX:function(r){return c(r)?r:m.backgroundPosition(r)}};m.margin=m.padding,m.borderWidth=m.padding,m.boxShadow=m.textShadow,m.webkitBoxShadow=m.textShadow,m.mozBoxShadow=m.textShadow,m.borderStyle=m.borderColor,t.default=e}])}); | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.rtlCSSJS=t():r.rtlCSSJS=t()}(this,function(){return function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){"use strict";var n=e(1);r.exports=n.default;for(var o in n)n.hasOwnProperty(o)&&(r.exports[o]=n[o])},function(r,t){"use strict";function e(r){return Object.keys(r).reduce(function(t,e){var o=r[e];g(o)&&(o=o.trim());var i=n(e,o),u=i.key,a=i.value;return t[u]=a,t},{})}function n(r,t){var e=/\/\*\s?@noflip\s?\*\//.test(t),n=e?r:o(r),u=e?t:i(n,t);return{key:n,value:u}}function o(r){return y[r]||r}function i(r,t){if(null===t||"undefined"==typeof t)return t;if(p(t))return e(t);var n=l(t),o=n?t:t.replace(/ !important.*?$/,""),i=!n&&o.length!==t.length,u=x[r],a=void 0;return a=u?u(o):v[o]||o,i?a+" !important":a}function u(r){return r.replace(/ +/g," ").split(" ").map(function(r){return r.trim()}).filter(Boolean).reduce(function(r,t){var e=r.list,n=r.state,o=(t.match(/\(/g)||[]).length,i=(t.match(/\)/g)||[]).length;return n.parensDepth>0?e[e.length-1]=e[e.length-1]+" "+t:e.push(t),n.parensDepth+=o-i,{list:e,state:n}},{list:[],state:{parensDepth:0}}).list}function a(r){var t=u(r);if(t.length<=3||t.length>4)return r;var e=m(t,4),n=e[0],o=e[1],i=e[2],a=e[3];return[n,a,i,o].join(" ")}function f(r){var t=r.indexOf(".");if(t===-1)r=100-parseFloat(r)+"%";else{var e=r.length-t-2;r=100-parseFloat(r),r=r.toFixed(e)+"%"}return r}function s(r){return 0===parseFloat(r)?r:"-"===r[0]?r.slice(1):"-"+r}function c(r,t,e,n){return t+s(e)+n}function d(r){return r.reduce(function(r,t){var e=m(t,2),n=e[0],o=e[1];return r[n]=o,r[o]=n,r},{})}function l(r){return"number"==typeof r}function p(r){return r&&"object"===("undefined"==typeof r?"undefined":b(r))}function g(r){return"string"==typeof r}function h(r,t){return r.indexOf(t)!==-1}Object.defineProperty(t,"__esModule",{value:!0});var b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},m=function(){function r(r,t){var e=[],n=!0,o=!1,i=void 0;try{for(var u,a=r[Symbol.iterator]();!(n=(u=a.next()).done)&&(e.push(u.value),!t||e.length!==t);n=!0);}catch(r){o=!0,i=r}finally{try{!n&&a.return&&a.return()}finally{if(o)throw i}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return r(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),y=d([["paddingLeft","paddingRight"],["marginLeft","marginRight"],["left","right"],["borderLeft","borderRight"],["borderLeftColor","borderRightColor"],["borderLeftStyle","borderRightStyle"],["borderLeftWidth","borderRightWidth"],["borderTopLeftRadius","borderTopRightRadius"],["borderBottomLeftRadius","borderBottomRightRadius"]]),v=d([["ltr","rtl"],["left","right"],["w-resize","e-resize"],["sw-resize","se-resize"],["nw-resize","ne-resize"]]),x={padding:function(r){return l(r)?r:a(r)},textShadow:function(r){return r.replace(/(-*)([.|\d]+)/,function(r,t,e){if("0"===e)return r;var n=""===t?"-":"";return""+n+e})},borderColor:function(r){return a(r)},borderRadius:function(r){if(l(r))return r;if(h(r,"/")){var t=r.split("/"),e=m(t,2),n=e[0],o=e[1],i=x.borderRadius(n.trim()),a=x.borderRadius(o.trim());return i+" / "+a}var f=u(r);switch(f.length){case 2:return f.reverse().join(" ");case 4:var s=m(f,4),c=s[0],d=s[1],p=s[2],g=s[3];return[d,c,g,p].join(" ");default:return r}},background:function(r){var t=r.replace(/(url\(.*?\))|(rgba?\(.*?\))|(hsl\(.*?\))|(#[a-fA-F0-9]+)|((^| )(\D)+( |$))/g,"").trim();return r=r.replace(t,x.backgroundPosition(t)),x.backgroundImage(r)},backgroundImage:function(r){return h(r,"url(")?r.replace(/(^|\W|_)((ltr)|(rtl)|(left)|(right))(\W|_|$)/g,function(r,t,e){return r.replace(e,v[e])}):r},backgroundPosition:function(r){return r.replace(/^((-|\d|\.)+%)/,function(r,t){return f(t)}).replace(/(left)|(right)/,function(r){return v[r]})},backgroundPositionX:function(r){return l(r)?r:x.backgroundPosition(r)},transform:function(r){var t="[^\\u0020-\\u007e]",e="(?:(?:\\[0-9a-f]{1,6})(?:\\r\\n|\\s)?)",n="(?:[0-9]*\\.[0-9]+|[0-9]+)",o="(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)",i="(?:"+e+"|\\\\[^\\r\\n\\f0-9a-f])",u="(?:[_a-z]|"+t+"|"+i+")",a="(?:[_a-z0-9-]|"+t+"|"+i+")",f="-?"+u+a+"*",s=n+"(?:\\s*"+o+"|"+f+")?",d="((?:-?"+s+")|(?:inherit|auto))",l=new RegExp("(translateX\\s*\\(\\s*)"+d+"(\\s*\\))","gi"),p=new RegExp("(translate\\s*\\(\\s*)"+d+"((?:\\s*,\\s*"+d+"){0,1}\\s*\\))","gi"),g=new RegExp("(translate3d\\s*\\(\\s*)"+d+"((?:\\s*,\\s*"+d+"){0,2}\\s*\\))","gi");return r.replace(l,c).replace(p,c).replace(g,c)}};x.margin=x.padding,x.borderWidth=x.padding,x.boxShadow=x.textShadow,x.webkitBoxShadow=x.textShadow,x.mozBoxShadow=x.textShadow,x.borderStyle=x.borderColor,x.webkitTransform=x.transform,x.mozTransform=x.transform,t.default=e}])}); | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "rtl-css-js", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "RTL conversion for CSS in JS objects", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -23,2 +23,4 @@ # rtl-css-js | ||
<a href="https://app.codesponsor.io/link/PKGFLnhDiFvsUA5P4kAXfiPs/kentcdodds/rtl-css-js" rel="nofollow"><img src="https://app.codesponsor.io/embed/PKGFLnhDiFvsUA5P4kAXfiPs/kentcdodds/rtl-css-js.svg" style="width: 888px; height: 68px;" alt="Sponsor" /></a> | ||
## The problem | ||
@@ -25,0 +27,0 @@ |
Sorry, the diff of this file is not supported yet
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
112951
719
141