Comparing version 1.1.4 to 1.1.5
35
bss.js
@@ -82,3 +82,3 @@ (function (global, factory) { | ||
acc[prev] = tokens.filter(function (a) { return a; }).map(function (t) { return addPx(prev, t.trim()); }).join(' '); | ||
acc[prev] = tokens.filter(function (a) { return a; }).reduce(function (acc, t) { return acc + addPx(prev, t.trim()) + ' '; }, '').trim(); | ||
} | ||
@@ -202,3 +202,3 @@ return acc | ||
function stylesToCss(style) { | ||
return Object.keys(style).map(function (k) { return propToString(style, k); }).join('') | ||
return Object.keys(style).reduce(function (acc, k) { return acc + propToString(style, k); }, '') | ||
} | ||
@@ -251,14 +251,14 @@ | ||
function createClass(style) { | ||
var rules = objectToRules(style) | ||
, css = rules.join('');; | ||
var json = JSON.stringify(style); | ||
if (css in classes) | ||
{ return classes[css] } | ||
if (json in classes) | ||
{ return classes[json] } | ||
var className = classPrefix + (++count); | ||
var rules = objectToRules(style) | ||
, className = classPrefix + (++count);; | ||
rules.map(function (rule) { return insert(rule.replace(/\.\$/, '.' + className)); } | ||
); | ||
for(var i = 0; i < rules.length; i++) | ||
{ insert(rules[i].replace(/\.\$/, '.' + className)); } | ||
classes[css] = className; | ||
classes[json] = className; | ||
@@ -272,4 +272,4 @@ return className | ||
function keyframes(props) { | ||
var content = Object.keys(props).map(function (key) { return selectorBlock(key, props[key].style || props[key]); } | ||
).join(''); | ||
var content = Object.keys(props).reduce(function (acc, key) { return acc + selectorBlock(key, props[key].style || props[key]); } | ||
, ''); | ||
@@ -355,8 +355,13 @@ if (content in keyframeCache) | ||
Object.defineProperty(bss, 'valueOf', { | ||
configurable: true, | ||
writable: true, | ||
value: function ValueOf() { | ||
return '.' + this.class | ||
} | ||
}); | ||
bss.style = {}; | ||
setProp('setDebug', setDebug); | ||
setProp('valueOf', function ValueOf() { | ||
return '.' + this.class | ||
}); | ||
@@ -363,0 +368,0 @@ setProp('$keyframes', keyframes); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.b=e()}(this,function(){"use strict";var t={ai:"alignItems",b:"bottom",bc:"backgroundColor",br:"borderRadius",bs:"boxShadow",c:"color",d:"display",f:"float",fd:"flexDirection",ff:"fontFamily",fs:"fontSize",h:"height",jc:"justifyContent",l:"left",ls:"letterSpacing",m:"margin",mb:"marginBottom",ml:"marginLeft",mr:"marginRight",mt:"marginTop",o:"opacity",p:"padding",pb:"paddingBottom",pl:"paddingLeft",pr:"paddingRight",pt:"paddingTop",r:"right",t:"top",ta:"textAlign",td:"textDecoration",tt:"textTransform",w:"width"},e=Object.create(null),n=Object.keys(function t(e){return e.hasOwnProperty("width")?e:t(Object.getPrototypeOf(e))}(document.documentElement.style)).filter(function(t){return-1===t.indexOf("-")});var r=function(t,e){return void 0===e&&(e={}),function(n){return n in e?e[n]:e[n]=t(n)}},i=r(function(t){var n,r="";return t.replace(/;/g,"\n").split("\n").reduce(function(t,i){if(i=r+i.trim(),r=i.endsWith(",")?i:"")return t;if(i.startsWith(","))return t[n]+=i,t;var o=i.split(/[:\s]/);if(o.length>1){var a=f(o.shift().trim());t[n=e[a]||a]=o.filter(function(t){return t}).map(function(t){return p(n,t.trim())}).join(" ")}return t},{})}),o=Object.create(null,{}),a=/^(o|O|ms|MS|Ms|moz|Moz|webkit|Webkit|WebKit)([A-Z])/;function c(t,e){var n,r;return"string"==typeof t?"string"==typeof e||"number"==typeof e?((n={})[t]=e,n):i(t):Array.isArray(t)&&Array.isArray(t.raw)?(arguments[0]={raw:t},i(String.raw.apply(null,arguments))):t.style||(r=t,Object.keys(r).reduce(function(t,e){var n=r[e];return n||0===n||""===n?("content"===e&&'"'!==n.charAt(0)?t[e]='"'+n+'"':t[e in o?o[e]:e]=p(e,n),t):t},{}))}var u=r(function(t){var e=document.createElement("div");try{return e.style[t]="1px",e.style.setProperty(t,"1px"),"1px"===e.style[t].slice(-3)?"px":""}catch(t){return""}},{flex:""});function s(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])}function f(t){return t.slice("-"===t.charAt(0)?1:0).replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})}function l(n){var r,i=(r=n).charAt(0)+(r.match(/([A-Z])/g)||[]).join("").toLowerCase(),o=t[i]&&t[i]!==n?n:i;return e[o]=n,o}function h(t,e){return t+"{"+function(t){return Object.keys(t).map(function(e){return function(t,e){return(a.test(e)?"-":"")+(n=e,n.replace(/([A-Z])/g,"-$1").toLowerCase())+":"+t[e]+";";var n}(t,e)}).join("")}("string"==typeof e?i(e):e)+"}"}function p(t,e){return e+(isNaN(e)?"":u(t))}var d=window.document,y=Object.create(null,{}),m=d&&d.createElement("style");m&&d.head.appendChild(m);var g=m&&m.sheet,b=!1,v=[],j=0,O="b"+("000"+(46656*Math.random()|0).toString(36)).slice(-3)+("000"+(46656*Math.random()|0).toString(36)).slice(-3);function k(t,e){if(v.push(t),b)return m.textContent+=t;g&&g.insertRule(t,arguments.length>1?e:g.cssRules.length)}function A(t){var e=function t(e){var n={},r=[],i=!1;return Object.keys(e).forEach(function(o){"@"===o.charAt(0)?r.push(o+"{"+t(e[o])+"}"):" "===o.charAt(0)||":"===o.charAt(0)?r.push(h(".$"+o,e[o])):(n[o]=e[o],i=!0)}),i&&r.unshift(h(".$",n)),r}(t),n=e.join("");if(n in y)return y[n];var r=O+ ++j;return e.map(function(t){return k(t.replace(/\.\$/,"."+r))}),y[n]=r,r}var w=0,x={};function $(t,e){return s($.style,c.apply(null,arguments)),C($)}function P(t,e){Object.defineProperty($,t,{configurable:!0,value:e})}function C(t){var e=Object.create($,{style:{value:t.style,enumerable:!0}});return t===$&&($.style={}),e}function E(t){return function(e){return e||0===e?arguments.length>0&&(this.style[t]=1===arguments.length?p(t,e):Array.prototype.slice.call(arguments).map(function(e){return p(t,e)}).join(" ")):delete this.style[t],C(this)}}return $.style={},P("setDebug",function(t){b=t}),P("valueOf",function(){return"."+this.class}),P("$keyframes",function(t){var e=Object.keys(t).map(function(e){return h(e,t[e].style||t[e])}).join("");if(e in x)return x[e];var n=O+ ++w;return x[e]=n,k("@keyframes "+n+"{"+e+"}"),n}),P("getSheet",function(){var t=v.join("");return v=[],t}),P("helper",function t(e,n){if(1===arguments.length)return Object.keys(e).forEach(function(n){return t(n,e[n])});delete $[e];"object"==typeof n?Object.defineProperty($,e,{configurable:!0,get:function(){return s(this.style,c(n)),C(this)}}):Object.defineProperty($,e,{configurable:!0,value:function(){var t=n.apply(null,arguments);return s(this.style,t.style),C(this)}})}),P("css",function t(e,n){if(1===arguments.length)return Object.keys(e).forEach(function(n){return t(n,e[n])});k(h(e,c(n)),0)}),P("classPrefix",O),n.forEach(function(t){if(a.test(t)){var e=(r=t.replace(a,"$2")).charAt(0).toLowerCase()+r.slice(1);if(-1===n.indexOf(e))return o[e]=t,P(e,E(t)),void P(l(e),$[e])}var r;P(t,E(t)),P(l(t),$[t])}),P("content",function(t){return this.style.content='"'+t+'"',C(this)}),Object.defineProperty($,"class",{set:function(t){this.__class=t},get:function(){return this.__class||A(this.style)}}),P("$media",function(t,e){return t&&(this.style["@media "+t]=c(e)),C(this)}),P("$nest",function(t,e){return t&&(this.style[(":"===t.charAt(0)?"":" ")+t]=c(e)),C(this)}),["active","any","checked","default","disabled","empty","enabled","first","first-child","first-of-type","fullscreen","focus","hover","indeterminate","in-range","invalid","last-child","last-of-type","left","link","only-child","only-of-type","optional","out-of-range","read-only","read-write","required","right","root","scope","target","valid","visited","dir","lang","not","nth-child","nth-last-child","nth-last-of-type","nth-of-type","after","before","first-letter","first-line","selection","backdrop","placeholder","marker","spelling-error","grammar-error"].forEach(function(t){return P("$"+f(t),function(e,n){return this.style[":"+t+(n?"("+e+")":"")]=c(n||e),C(this)})}),$.helper("$animate",function(t,e){return $.animation($.$keyframes(e)+" "+t)}),$}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.b=e()}(this,function(){"use strict";var t={ai:"alignItems",b:"bottom",bc:"backgroundColor",br:"borderRadius",bs:"boxShadow",c:"color",d:"display",f:"float",fd:"flexDirection",ff:"fontFamily",fs:"fontSize",h:"height",jc:"justifyContent",l:"left",ls:"letterSpacing",m:"margin",mb:"marginBottom",ml:"marginLeft",mr:"marginRight",mt:"marginTop",o:"opacity",p:"padding",pb:"paddingBottom",pl:"paddingLeft",pr:"paddingRight",pt:"paddingTop",r:"right",t:"top",ta:"textAlign",td:"textDecoration",tt:"textTransform",w:"width"},e=Object.create(null),r=Object.keys(function t(e){return e.hasOwnProperty("width")?e:t(Object.getPrototypeOf(e))}(document.documentElement.style)).filter(function(t){return-1===t.indexOf("-")});var n=function(t,e){return void 0===e&&(e={}),function(r){return r in e?e[r]:e[r]=t(r)}},i=n(function(t){var r,n="";return t.replace(/;/g,"\n").split("\n").reduce(function(t,i){if(i=n+i.trim(),n=i.endsWith(",")?i:"")return t;if(i.startsWith(","))return t[r]+=i,t;var o=i.split(/[:\s]/);if(o.length>1){var a=l(o.shift().trim());t[r=e[a]||a]=o.filter(function(t){return t}).reduce(function(t,e){return t+d(r,e.trim())+" "},"").trim()}return t},{})}),o=Object.create(null,{}),a=/^(o|O|ms|MS|Ms|moz|Moz|webkit|Webkit|WebKit)([A-Z])/;function c(t,e){var r,n;return"string"==typeof t?"string"==typeof e||"number"==typeof e?((r={})[t]=e,r):i(t):Array.isArray(t)&&Array.isArray(t.raw)?(arguments[0]={raw:t},i(String.raw.apply(null,arguments))):t.style||(n=t,Object.keys(n).reduce(function(t,e){var r=n[e];return r||0===r||""===r?("content"===e&&'"'!==r.charAt(0)?t[e]='"'+r+'"':t[e in o?o[e]:e]=d(e,r),t):t},{}))}var u=n(function(t){var e=document.createElement("div");try{return e.style[t]="1px",e.style.setProperty(t,"1px"),"1px"===e.style[t].slice(-3)?"px":""}catch(t){return""}},{flex:""});function f(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])}function l(t){return t.slice("-"===t.charAt(0)?1:0).replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})}function s(r){var n,i=(n=r).charAt(0)+(n.match(/([A-Z])/g)||[]).join("").toLowerCase(),o=t[i]&&t[i]!==r?r:i;return e[o]=r,o}function h(t,e){return t+"{"+function(t){return Object.keys(t).reduce(function(e,r){return e+function(t,e){return(a.test(e)?"-":"")+(r=e,r.replace(/([A-Z])/g,"-$1").toLowerCase())+":"+t[e]+";";var r}(t,r)},"")}("string"==typeof e?i(e):e)+"}"}function d(t,e){return e+(isNaN(e)?"":u(t))}var p=window.document,y=Object.create(null,{}),g=p&&p.createElement("style");g&&p.head.appendChild(g);var m=g&&g.sheet,b=!1,v=[],O=0,j="b"+("000"+(46656*Math.random()|0).toString(36)).slice(-3)+("000"+(46656*Math.random()|0).toString(36)).slice(-3);function k(t,e){if(v.push(t),b)return g.textContent+=t;m&&m.insertRule(t,arguments.length>1?e:m.cssRules.length)}function w(t){var e=JSON.stringify(t);if(e in y)return y[e];for(var r=function t(e){var r={},n=[],i=!1;return Object.keys(e).forEach(function(o){"@"===o.charAt(0)?n.push(o+"{"+t(e[o])+"}"):" "===o.charAt(0)||":"===o.charAt(0)?n.push(h(".$"+o,e[o])):(r[o]=e[o],i=!0)}),i&&n.unshift(h(".$",r)),n}(t),n=j+ ++O,i=0;i<r.length;i++)k(r[i].replace(/\.\$/,"."+n));return y[e]=n,n}var A=0,x={};function $(t,e){return f($.style,c.apply(null,arguments)),S($)}function P(t,e){Object.defineProperty($,t,{configurable:!0,value:e})}function S(t){var e=Object.create($,{style:{value:t.style,enumerable:!0}});return t===$&&($.style={}),e}function C(t){return function(e){return e||0===e?arguments.length>0&&(this.style[t]=1===arguments.length?d(t,e):Array.prototype.slice.call(arguments).map(function(e){return d(t,e)}).join(" ")):delete this.style[t],S(this)}}return Object.defineProperty($,"valueOf",{configurable:!0,writable:!0,value:function(){return"."+this.class}}),$.style={},P("setDebug",function(t){b=t}),P("$keyframes",function(t){var e=Object.keys(t).reduce(function(e,r){return e+h(r,t[r].style||t[r])},"");if(e in x)return x[e];var r=j+ ++A;return x[e]=r,k("@keyframes "+r+"{"+e+"}"),r}),P("getSheet",function(){var t=v.join("");return v=[],t}),P("helper",function t(e,r){if(1===arguments.length)return Object.keys(e).forEach(function(r){return t(r,e[r])});delete $[e];"object"==typeof r?Object.defineProperty($,e,{configurable:!0,get:function(){return f(this.style,c(r)),S(this)}}):Object.defineProperty($,e,{configurable:!0,value:function(){var t=r.apply(null,arguments);return f(this.style,t.style),S(this)}})}),P("css",function t(e,r){if(1===arguments.length)return Object.keys(e).forEach(function(r){return t(r,e[r])});k(h(e,c(r)),0)}),P("classPrefix",j),r.forEach(function(t){if(a.test(t)){var e=(n=t.replace(a,"$2")).charAt(0).toLowerCase()+n.slice(1);if(-1===r.indexOf(e))return o[e]=t,P(e,C(t)),void P(s(e),$[e])}var n;P(t,C(t)),P(s(t),$[t])}),P("content",function(t){return this.style.content='"'+t+'"',S(this)}),Object.defineProperty($,"class",{set:function(t){this.__class=t},get:function(){return this.__class||w(this.style)}}),P("$media",function(t,e){return t&&(this.style["@media "+t]=c(e)),S(this)}),P("$nest",function(t,e){return t&&(this.style[(":"===t.charAt(0)?"":" ")+t]=c(e)),S(this)}),["active","any","checked","default","disabled","empty","enabled","first","first-child","first-of-type","fullscreen","focus","hover","indeterminate","in-range","invalid","last-child","last-of-type","left","link","only-child","only-of-type","optional","out-of-range","read-only","read-write","required","right","root","scope","target","valid","visited","dir","lang","not","nth-child","nth-last-child","nth-last-of-type","nth-of-type","after","before","first-letter","first-line","selection","backdrop","placeholder","marker","spelling-error","grammar-error"].forEach(function(t){return P("$"+l(t),function(e,r){return this.style[":"+t+(r?"("+e+")":"")]=c(r||e),S(this)})}),$.helper("$animate",function(t,e){return $.animation($.$keyframes(e)+" "+t)}),$}); | ||
//# sourceMappingURL=bss.min.js.map |
@@ -37,8 +37,13 @@ import keyframes from './keyframes' | ||
Object.defineProperty(bss, 'valueOf', { | ||
configurable: true, | ||
writable: true, | ||
value: function ValueOf() { | ||
return '.' + this.class | ||
} | ||
}) | ||
bss.style = {} | ||
setProp('setDebug', setDebug) | ||
setProp('valueOf', function ValueOf() { | ||
return '.' + this.class | ||
}) | ||
@@ -45,0 +50,0 @@ setProp('$keyframes', keyframes) |
@@ -8,5 +8,5 @@ import { selectorBlock } from './utils' | ||
export default function(props) { | ||
const content = Object.keys(props).map(key => | ||
selectorBlock(key, props[key].style || props[key]) | ||
).join('') | ||
const content = Object.keys(props).reduce((acc, key) => | ||
acc + selectorBlock(key, props[key].style || props[key]) | ||
, '') | ||
@@ -13,0 +13,0 @@ if (content in keyframeCache) |
@@ -41,17 +41,16 @@ import { | ||
export function createClass(style) { | ||
const rules = objectToRules(style) | ||
, css = rules.join('') | ||
const json = JSON.stringify(style) | ||
if (css in classes) | ||
return classes[css] | ||
if (json in classes) | ||
return classes[json] | ||
const className = classPrefix + (++count) | ||
const rules = objectToRules(style) | ||
, className = classPrefix + (++count) | ||
rules.map(rule => | ||
insert(rule.replace(/\.\$/, '.' + className)) | ||
) | ||
for(let i = 0; i < rules.length; i++) | ||
insert(rules[i].replace(/\.\$/, '.' + className)) | ||
classes[css] = className | ||
classes[json] = className | ||
return className | ||
} |
@@ -40,3 +40,3 @@ import popular from './popular' | ||
acc[prev] = tokens.filter(a => a).map(t => addPx(prev, t.trim())).join(' ') | ||
acc[prev] = tokens.filter(a => a).reduce((acc, t) => acc + addPx(prev, t.trim()) + ' ', '').trim() | ||
} | ||
@@ -129,5 +129,5 @@ return acc | ||
export function getStyleSheetText(classes) { | ||
return Object.keys(classes).sort().map(key => { | ||
return key.replace(/CLASS_NAME/g, classes[key]) | ||
}).join('') | ||
return Object.keys(classes).sort().reduce((acc, key) => | ||
acc + key.replace(/CLASS_NAME/g, classes[key]) | ||
, '') | ||
} | ||
@@ -165,3 +165,3 @@ | ||
export function stylesToCss(style) { | ||
return Object.keys(style).map(k => propToString(style, k)).join('') | ||
return Object.keys(style).reduce((acc, k) => acc + propToString(style, k), '') | ||
} | ||
@@ -168,0 +168,0 @@ |
{ | ||
"name": "bss", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Better Style Sheets", | ||
@@ -5,0 +5,0 @@ "main": "bss.js", |
@@ -147,3 +147,3 @@ [![version](https://img.shields.io/npm/v/bss.svg)]() [![gzipped](http://img.badgesize.io/porsager/bss/master/bss.js.svg?compression=gzip&label=gzipped)]() [![license](https://img.shields.io/github/license/porsager/wright.svg)]() | ||
``` | ||
b.valueOf = function() { return b.class + ' ' } | ||
b.valueOf = function() { return this.class + ' ' } | ||
@@ -150,0 +150,0 @@ `<div class="${ b.textAlign('center') }`"></div>` // Returns eg. <div class="bdp4f3o1"></div> |
@@ -134,2 +134,11 @@ const o = require('ospec') | ||
}) | ||
o('Override valueOf', function() { | ||
const newValueOf = function() { | ||
return 'test' | ||
} | ||
b.valueOf = newValueOf | ||
o(b.valueOf).equals(newValueOf) | ||
o('' + b.bc('red')).equals('test') | ||
}) | ||
}) |
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
91960
1233