rtl-css-js
Advanced tools
Comparing version 1.0.0-beta.4 to 1.0.0
@@ -55,18 +55,35 @@ 'use strict'; | ||
case 2: | ||
return splitValues.reverse().join(' '); | ||
{ | ||
return splitValues.reverse().join(' '); | ||
} | ||
case 4: | ||
// eslint-disable-line no-case-declarations | ||
// feel free to refactor 😈 | ||
var _splitValues = _slicedToArray(splitValues, 4), | ||
topLeft = _splitValues[0], | ||
topRight = _splitValues[1], | ||
bottomRight = _splitValues[2], | ||
bottomLeft = _splitValues[3]; | ||
{ | ||
var _splitValues = _slicedToArray(splitValues, 4), | ||
topLeft = _splitValues[0], | ||
topRight = _splitValues[1], | ||
bottomRight = _splitValues[2], | ||
bottomLeft = _splitValues[3]; | ||
return [topRight, topLeft, bottomLeft, bottomRight].join(' '); | ||
return [topRight, topLeft, bottomLeft, bottomRight].join(' '); | ||
} | ||
default: | ||
return value; | ||
{ | ||
return value; | ||
} | ||
} | ||
}, | ||
background: function background(value) { | ||
// Yeah, this is in need of a refactor 🙃... | ||
// but this property is a tough cookie 🍪 | ||
// get the backgroundPosition out of the string by removing everything that couldn't be the backgroundPosition value | ||
var backgroundPositionValue = value.replace(/(url\(.*?\))|(rgba?\(.*?\))|(hsl\(.*?\))|(#[a-fA-F0-9]+)|((^| )(\D)+( |$))/g, '').trim(); | ||
// replace that backgroundPosition value with the converted version | ||
value = value.replace(backgroundPositionValue, propertyValueConverters.backgroundPosition(backgroundPositionValue)); | ||
// do the backgroundImage value replacing on the whole value (because why not?) | ||
return propertyValueConverters.backgroundImage(value); | ||
}, | ||
backgroundImage: function backgroundImage(value) { | ||
if (!includes(value, 'url(')) { | ||
return value; | ||
} | ||
// sorry for the regex 😞, but basically this replaces _every_ instance of `ltr`, `rtl`, `right`, and `left` with | ||
@@ -101,3 +118,2 @@ // the corresponding opposite. A situation we're accepting here: | ||
propertyValueConverters.borderStyle = propertyValueConverters.borderColor; | ||
propertyValueConverters.background = propertyValueConverters.backgroundImage; | ||
@@ -195,9 +211,5 @@ // here's our main export! 👋 | ||
if (includes(item, '(')) { | ||
state.withinParens = true; | ||
list.push(item); | ||
} else if (state.withinParens) { | ||
if (includes(item, ')')) { | ||
state.withinParens = false; | ||
} | ||
var openParansCount = (item.match(/\(/g) || []).length; | ||
var closedParansCount = (item.match(/\)/g) || []).length; | ||
if (state.parensDepth > 0) { | ||
list[list.length - 1] = list[list.length - 1] + ' ' + item; | ||
@@ -207,4 +219,5 @@ } else { | ||
} | ||
state.parensDepth += openParansCount - closedParansCount; | ||
return { list: list, state: state }; | ||
}, { list: [], state: { withinParens: false } }).list; | ||
}, { list: [], state: { parensDepth: 0 } }).list; | ||
} | ||
@@ -215,3 +228,3 @@ | ||
* @param {String} value - `1px 2px 3px 4px` for example, but also handles cases where there are too few/too many and | ||
* simply returns the value in those cases | ||
* simply returns the value in those cases (which is the correct behavior) | ||
* @return {String} the result - `1px 4px 3px 2px` for example. | ||
@@ -236,2 +249,4 @@ */ | ||
* Takes a percentage for background position and inverts it. | ||
* This was copied and modified from CSSJanus: | ||
* https://github.com/cssjanus/cssjanus/blob/4245f834365f6cfb0239191a151432fb85abab23/src/cssjanus.js#L152-L175 | ||
* @param {String} value - the original value (for example 77%) | ||
@@ -238,0 +253,0 @@ * @return {String} the result (for example 23%) |
@@ -126,18 +126,35 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
case 2: | ||
return splitValues.reverse().join(' '); | ||
{ | ||
return splitValues.reverse().join(' '); | ||
} | ||
case 4: | ||
// eslint-disable-line no-case-declarations | ||
// feel free to refactor 😈 | ||
var _splitValues = _slicedToArray(splitValues, 4), | ||
topLeft = _splitValues[0], | ||
topRight = _splitValues[1], | ||
bottomRight = _splitValues[2], | ||
bottomLeft = _splitValues[3]; | ||
{ | ||
var _splitValues = _slicedToArray(splitValues, 4), | ||
topLeft = _splitValues[0], | ||
topRight = _splitValues[1], | ||
bottomRight = _splitValues[2], | ||
bottomLeft = _splitValues[3]; | ||
return [topRight, topLeft, bottomLeft, bottomRight].join(' '); | ||
return [topRight, topLeft, bottomLeft, bottomRight].join(' '); | ||
} | ||
default: | ||
return value; | ||
{ | ||
return value; | ||
} | ||
} | ||
}, | ||
background: function background(value) { | ||
// Yeah, this is in need of a refactor 🙃... | ||
// but this property is a tough cookie 🍪 | ||
// get the backgroundPosition out of the string by removing everything that couldn't be the backgroundPosition value | ||
var backgroundPositionValue = value.replace(/(url\(.*?\))|(rgba?\(.*?\))|(hsl\(.*?\))|(#[a-fA-F0-9]+)|((^| )(\D)+( |$))/g, '').trim(); | ||
// replace that backgroundPosition value with the converted version | ||
value = value.replace(backgroundPositionValue, propertyValueConverters.backgroundPosition(backgroundPositionValue)); | ||
// do the backgroundImage value replacing on the whole value (because why not?) | ||
return propertyValueConverters.backgroundImage(value); | ||
}, | ||
backgroundImage: function backgroundImage(value) { | ||
if (!includes(value, 'url(')) { | ||
return value; | ||
} | ||
// sorry for the regex 😞, but basically this replaces _every_ instance of `ltr`, `rtl`, `right`, and `left` with | ||
@@ -172,3 +189,2 @@ // the corresponding opposite. A situation we're accepting here: | ||
propertyValueConverters.borderStyle = propertyValueConverters.borderColor; | ||
propertyValueConverters.background = propertyValueConverters.backgroundImage; | ||
@@ -266,9 +282,5 @@ // here's our main export! 👋 | ||
if (includes(item, '(')) { | ||
state.withinParens = true; | ||
list.push(item); | ||
} else if (state.withinParens) { | ||
if (includes(item, ')')) { | ||
state.withinParens = false; | ||
} | ||
var openParansCount = (item.match(/\(/g) || []).length; | ||
var closedParansCount = (item.match(/\)/g) || []).length; | ||
if (state.parensDepth > 0) { | ||
list[list.length - 1] = list[list.length - 1] + ' ' + item; | ||
@@ -278,4 +290,5 @@ } else { | ||
} | ||
state.parensDepth += openParansCount - closedParansCount; | ||
return { list: list, state: state }; | ||
}, { list: [], state: { withinParens: false } }).list; | ||
}, { list: [], state: { parensDepth: 0 } }).list; | ||
} | ||
@@ -286,3 +299,3 @@ | ||
* @param {String} value - `1px 2px 3px 4px` for example, but also handles cases where there are too few/too many and | ||
* simply returns the value in those cases | ||
* simply returns the value in those cases (which is the correct behavior) | ||
* @return {String} the result - `1px 4px 3px 2px` for example. | ||
@@ -307,2 +320,4 @@ */ | ||
* Takes a percentage for background position and inverts it. | ||
* This was copied and modified from CSSJanus: | ||
* https://github.com/cssjanus/cssjanus/blob/4245f834365f6cfb0239191a151432fb85abab23/src/cssjanus.js#L152-L175 | ||
* @param {String} value - the original value (for example 77%) | ||
@@ -309,0 +324,0 @@ * @return {String} the result (for example 23%) |
@@ -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,r[e]),u=i.key,a=i.value;return t[u]=a,t},{})}function n(r,t){var e=o(r),n=i(e,t);return{key:e,value:n}}function o(r){return g[r]||r}function i(r,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;return p(t,"(")?(n.withinParens=!0,e.push(t)):n.withinParens?(p(t,")")&&(n.withinParens=!1),e[e.length-1]=e[e.length-1]+" "+t):e.push(t),{list:e,state:n}},{list:[],state:{withinParens:!1}}).list}function a(r){var t=u(r);if(t.length<=3||t.length>4)return r;var e=h(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=h(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"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},h=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")}}(),g=d([["paddingLeft","paddingRight"],["marginLeft","marginRight"],["left","right"],["borderLeft","borderRight"],["borderLeftColor","borderRightColor"],["borderLeftStyle","borderRightStyle"],["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=h(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=h(f,4),l=d[0],s=d[1],b=d[2],g=d[3];return[s,l,g,b].join(" ");default:return r}},backgroundImage:function(r){return r.replace(/(^|\W|_)((ltr)|(rtl)|(left)|(right))(\W|_|$)/g,function(r,t,e){return r.replace(e,y[e])})},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.borderWidth=m.padding,m.boxShadow=m.textShadow,m.webkitBoxShadow=m.textShadow,m.mozBoxShadow=m.textShadow,m.borderStyle=m.borderColor,m.background=m.backgroundImage,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];s(o)&&(o=o.trim());var i=n(e,r[e]),u=i.key,a=i.value;return t[u]=a,t},{})}function n(r,t){var e=o(r),n=i(e,t);return{key:e,value:n}}function o(r){return h[r]||r}function i(r,t){if(l(t))return e(t);var n=d(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 c(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 d(r){return"number"==typeof r}function l(r){return"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=c([["paddingLeft","paddingRight"],["marginLeft","marginRight"],["left","right"],["borderLeft","borderRight"],["borderLeftColor","borderRightColor"],["borderLeftStyle","borderRightStyle"],["borderTopLeftRadius","borderTopRightRadius"],["borderBottomLeftRadius","borderBottomRightRadius"]]),y=c([["ltr","rtl"],["left","right"],["w-resize","e-resize"],["sw-resize","se-resize"],["nw-resize","ne-resize"]]),m={padding:function(r){return d(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(d(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 c=g(f,4),l=c[0],s=c[1],b=c[2],h=c[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 d(r)?r:m.backgroundPosition(r)}};m.borderWidth=m.padding,m.boxShadow=m.textShadow,m.webkitBoxShadow=m.textShadow,m.mozBoxShadow=m.textShadow,m.borderStyle=m.borderColor,t.default=e}])}); | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "rtl-css-js", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0", | ||
"description": "RTL conversion for CSS in JS objects", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
94896
9
621