bss
Advanced tools
Comparing version 1.0.5 to 1.0.6
63
bss.js
@@ -46,3 +46,3 @@ (function (global, factory) { | ||
findWidth(document.documentElement.style) | ||
).filter(function (prop) { return typeof document.documentElement.style[prop] === 'string'; }); | ||
).filter(function (p) { return p.indexOf('-') === -1; }); | ||
@@ -55,2 +55,36 @@ function findWidth(obj) { | ||
var memoize = function (fn, cache) { | ||
if ( cache === void 0 ) cache = {}; | ||
return function (item) { return item in cache | ||
? cache[item] | ||
: cache[item] = fn(item); }; | ||
}; | ||
var stringToObject = memoize(function (string) { | ||
var last = '' | ||
, prev; | ||
return string.replace(/;/g, '\n').split('\n').reduce(function (acc, line) { | ||
line = last + line.trim(); | ||
last = line.endsWith(',') ? line : ''; | ||
if (last) | ||
{ return acc } | ||
if (line.startsWith(',')) { | ||
acc[prev] += line; | ||
return acc | ||
} | ||
var tokens = line.split(/[:\s]/); | ||
if (tokens.length > 1) { | ||
var key = hyphenToCamelCase(tokens.shift().trim()); | ||
prev = shorts[key] || key; | ||
acc[prev] = tokens.filter(function (a) { return a; }).map(function (t) { return addPx(prev, t.trim()); }).join(' '); | ||
} | ||
return acc | ||
}, {}) | ||
}); | ||
var vendorMap = Object.create(null, {}); | ||
@@ -76,10 +110,2 @@ | ||
var memoize = function (fn, cache) { | ||
if ( cache === void 0 ) cache = {}; | ||
return function (item) { return item in cache | ||
? cache[item] | ||
: cache[item] = fn(item); }; | ||
}; | ||
var appendPx = memoize(function (prop) { | ||
@@ -183,15 +209,4 @@ var el = document.createElement('div'); | ||
function stringToObject(string) { | ||
return string.replace(/;/g, '\n').split('\n').reduce(function (acc, line) { | ||
var tokens = line.trim().split(/[: ]/); | ||
if (tokens.length > 1) { | ||
var key = hyphenToCamelCase(tokens.shift().trim()); | ||
acc[shorts[key] || key] = addPx(shorts[key] || key, tokens.join(' ').trim()); | ||
} | ||
return acc | ||
}, {}) | ||
} | ||
function propToString(style, k) { | ||
@@ -385,3 +400,5 @@ return (vendorRegex.test(k) ? '-' : '') | ||
bss.$media = function(value, style) { | ||
this.style['@media ' + value] = parse(style); | ||
if (value) | ||
{ this.style['@media ' + value] = parse(style); } | ||
return chain(this) | ||
@@ -391,3 +408,5 @@ }; | ||
bss.$nest = function(value, style) { | ||
this.style[(value.charAt(0) === ':' ? '' : ' ') + value] = parse(style); | ||
if (value) | ||
{ this.style[value] = parse(style); } | ||
return chain(this) | ||
@@ -394,0 +413,0 @@ }; |
@@ -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";function t(e){return e.hasOwnProperty("width")?e:t(Object.getPrototypeOf(e))}function e(t,e){var n;return"string"==typeof t?"string"==typeof e||"number"==typeof e?(n={},n[t]=e,n):u(t):Array.isArray(t)&&Array.isArray(t.raw)?(arguments[0]={raw:t},u(String.raw.apply(null,arguments))):t.style||function(t){return Object.keys(t).reduce(function(e,n){var r=t[n];return r||0===r||""===r?("content"===n&&'"'!==r.charAt(0)?e[n]='"'+r+'"':e[n in b?b[n]:n]=a(n,r),e):e},{})}(t)}function n(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])}function r(t){return t.slice("-"===t.charAt(0)?1:0).replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})}function i(t){var e=function(t){return t.charAt(0)+(t.match(/([A-Z])/g)||[]).join("").toLowerCase()}(t),n=y[e]&&y[e]!==t?t:e;return m[n]=t,n}function o(t){var e={},n=[],r=!1;return Object.keys(t).forEach(function(i){"@"===i.charAt(0)?n.push(i+"{"+o(t[i])+"}"):" "===i.charAt(0)||":"===i.charAt(0)?n.push(c(".$"+i,t[i])):(e[i]=t[i],r=!0)}),r&&n.unshift(c(".$",e)),n}function c(t,e){return t+"{"+function(t){return Object.keys(t).map(function(e){return function(t,e){return(v.test(e)?"-":"")+function(t){return t.replace(/([A-Z])/g,"-$1").toLowerCase()}(e)+":"+t[e]+";"}(t,e)}).join("")}("string"==typeof e?u(e):e)+"}"}function u(t){return t.replace(/;/g,"\n").split("\n").reduce(function(t,e){var n=e.trim().split(/[: ]/);if(n.length>1){var i=r(n.shift().trim());t[m[i]||i]=a(m[i]||i,n.join(" ").trim())}return t},{})}function a(t,e){return e+(isNaN(e)?"":j(t))}function s(t,e){if($.push(t),x)return A.textContent+=t;w&&w.insertRule(t,arguments.length>1?e:w.cssRules.length)}function f(t,r){return n(f.style,e.apply(null,arguments)),l(f)}function l(t){var e=Object.create(f,{style:{value:t.style}});return t===f&&(f.style={}),e}function h(t){return function(e){return e||0===e?arguments.length>0&&(this.style[t]=1===arguments.length?a(t,e):Array.prototype.slice.call(arguments).map(function(e){return a(t,e)}).join(" ")):delete this.style[t],l(this)}}function p(t,n){if(1===arguments.length)return Object.keys(t).forEach(function(e){return p(e,t[e])});s(c(t,e(n)),0)}function d(t,r){return 1===arguments.length?Object.keys(t).forEach(function(e){return d(e,t[e])}):"object"==typeof r?(delete f[t],void Object.defineProperty(f,t,{get:function(){return n(this.style,e(r)),l(this)}})):void(f[t]=function(){var t=r.apply(null,arguments);return n(this.style,t.style),l(this)})}var y={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"},m=Object.create(null),g=Object.keys(t(document.documentElement.style)).filter(function(t){return"string"==typeof document.documentElement.style[t]}),b=Object.create(null,{}),v=/^(o|O|ms|MS|Ms|moz|Moz|webkit|Webkit|WebKit)([A-Z])/,j=function(t,e){return void 0===e&&(e={}),function(n){return n in e?e[n]:e[n]=t(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:""}),O=window.document,k=Object.create(null,{}),A=O&&O.createElement("style");A&&O.head.appendChild(A);var w=A&&A.sheet,x=!1,$=[],E=0,C="b"+("000"+(46656*Math.random()|0).toString(36)).slice(-3)+("000"+(46656*Math.random()|0).toString(36)).slice(-3),S=0,P={};return f.setDebug=function(t){x=t},f.style={},f.valueOf=function(){return"."+this.class},f.$keyframes=function(t){var e=Object.keys(t).map(function(e){return c(e,t[e].style||t[e])}).join("");if(e in P)return P[e];var n=C+ ++S;return P[e]=n,s("@keyframes "+n+"{"+e+"}"),n},f.getSheet=function(){var t=$.join("");return $=[],t},f.helper=d,f.css=p,f.classPrefix=C,g.forEach(function(t){if(v.test(t)){var e=function(t){return t.charAt(0).toLowerCase()+t.slice(1)}(t.replace(v,"$2"));if(-1===g.indexOf(e))return b[e]=t,void(f[e]=f[i(e)]=h(t))}f[t]=f[i(t)]=h(t)}),f.content=function(t){return this.style.content='"'+t+'"',l(this)},Object.defineProperty(f,"class",{get:function(){return function(t){var e=o(t),n=e.join("");if(n in k)return k[n];var r=C+ ++E;return e.map(function(t){return s(t.replace(/\.\$/,"."+r))}),k[n]=r,r}(this.style)}}),f.$media=function(t,n){return this.style["@media "+t]=e(n),l(this)},f.$nest=function(t,n){return this.style[(":"===t.charAt(0)?"":" ")+t]=e(n),l(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 f["$"+r(t)]=function(n,r){return this.style[":"+t+(r?"("+n+")":"")]=e(r||n),l(this)}}),f.helper("$animate",function(t,e){return f.animation(f.$keyframes(e)+" "+t)}),f}); | ||
!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";function t(e){return e.hasOwnProperty("width")?e:t(Object.getPrototypeOf(e))}function e(t,e){var n;return"string"==typeof t?"string"==typeof e||"number"==typeof e?(n={},n[t]=e,n):b(t):Array.isArray(t)&&Array.isArray(t.raw)?(arguments[0]={raw:t},b(String.raw.apply(null,arguments))):t.style||function(t){return Object.keys(t).reduce(function(e,n){var r=t[n];return r||0===r||""===r?("content"===n&&'"'!==r.charAt(0)?e[n]='"'+r+'"':e[n in v?v[n]:n]=c(n,r),e):e},{})}(t)}function n(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])}function r(t){return t.slice("-"===t.charAt(0)?1:0).replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})}function i(t){var e=function(t){return t.charAt(0)+(t.match(/([A-Z])/g)||[]).join("").toLowerCase()}(t),n=d[e]&&d[e]!==t?t:e;return y[n]=t,n}function o(t){var e={},n=[],r=!1;return Object.keys(t).forEach(function(i){"@"===i.charAt(0)?n.push(i+"{"+o(t[i])+"}"):" "===i.charAt(0)||":"===i.charAt(0)?n.push(u(".$"+i,t[i])):(e[i]=t[i],r=!0)}),r&&n.unshift(u(".$",e)),n}function u(t,e){return t+"{"+function(t){return Object.keys(t).map(function(e){return function(t,e){return(j.test(e)?"-":"")+function(t){return t.replace(/([A-Z])/g,"-$1").toLowerCase()}(e)+":"+t[e]+";"}(t,e)}).join("")}("string"==typeof e?b(e):e)+"}"}function c(t,e){return e+(isNaN(e)?"":O(t))}function a(t,e){if(C.push(t),$)return x.textContent+=t;A&&A.insertRule(t,arguments.length>1?e:A.cssRules.length)}function f(t,r){return n(f.style,e.apply(null,arguments)),s(f)}function s(t){var e=Object.create(f,{style:{value:t.style}});return t===f&&(f.style={}),e}function l(t){return function(e){return e||0===e?arguments.length>0&&(this.style[t]=1===arguments.length?c(t,e):Array.prototype.slice.call(arguments).map(function(e){return c(t,e)}).join(" ")):delete this.style[t],s(this)}}function h(t,n){if(1===arguments.length)return Object.keys(t).forEach(function(e){return h(e,t[e])});a(u(t,e(n)),0)}function p(t,r){return 1===arguments.length?Object.keys(t).forEach(function(e){return p(e,t[e])}):"object"==typeof r?(delete f[t],void Object.defineProperty(f,t,{get:function(){return n(this.style,e(r)),s(this)}})):void(f[t]=function(){var t=r.apply(null,arguments);return n(this.style,t.style),s(this)})}var d={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"},y=Object.create(null),m=Object.keys(t(document.documentElement.style)).filter(function(t){return-1===t.indexOf("-")}),g=function(t,e){return void 0===e&&(e={}),function(n){return n in e?e[n]:e[n]=t(n)}},b=g(function(t){var e,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[e]+=i,t;var o=i.split(/[:\s]/);if(o.length>1){var u=r(o.shift().trim());t[e=y[u]||u]=o.filter(function(t){return t}).map(function(t){return c(e,t.trim())}).join(" ")}return t},{})}),v=Object.create(null,{}),j=/^(o|O|ms|MS|Ms|moz|Moz|webkit|Webkit|WebKit)([A-Z])/,O=g(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:""}),k=window.document,w=Object.create(null,{}),x=k&&k.createElement("style");x&&k.head.appendChild(x);var A=x&&x.sheet,$=!1,C=[],E=0,S="b"+("000"+(46656*Math.random()|0).toString(36)).slice(-3)+("000"+(46656*Math.random()|0).toString(36)).slice(-3),P=0,L={};return f.setDebug=function(t){$=t},f.style={},f.valueOf=function(){return"."+this.class},f.$keyframes=function(t){var e=Object.keys(t).map(function(e){return u(e,t[e].style||t[e])}).join("");if(e in L)return L[e];var n=S+ ++P;return L[e]=n,a("@keyframes "+n+"{"+e+"}"),n},f.getSheet=function(){var t=C.join("");return C=[],t},f.helper=p,f.css=h,f.classPrefix=S,m.forEach(function(t){if(j.test(t)){var e=function(t){return t.charAt(0).toLowerCase()+t.slice(1)}(t.replace(j,"$2"));if(-1===m.indexOf(e))return v[e]=t,void(f[e]=f[i(e)]=l(t))}f[t]=f[i(t)]=l(t)}),f.content=function(t){return this.style.content='"'+t+'"',s(this)},Object.defineProperty(f,"class",{get:function(){return function(t){var e=o(t),n=e.join("");if(n in w)return w[n];var r=S+ ++E;return e.map(function(t){return a(t.replace(/\.\$/,"."+r))}),w[n]=r,r}(this.style)}}),f.$media=function(t,n){return t&&(this.style["@media "+t]=e(n)),s(this)},f.$nest=function(t,n){return t&&(this.style[t]=e(n)),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 f["$"+r(t)]=function(n,r){return this.style[":"+t+(r?"("+n+")":"")]=e(r||n),s(this)}}),f.helper("$animate",function(t,e){return f.animation(f.$keyframes(e)+" "+t)}),f}); | ||
//# sourceMappingURL=bss.min.js.map |
@@ -78,3 +78,5 @@ import keyframes from './keyframes' | ||
bss.$media = function(value, style) { | ||
this.style['@media ' + value] = parse(style) | ||
if (value) | ||
this.style['@media ' + value] = parse(style) | ||
return chain(this) | ||
@@ -84,3 +86,5 @@ } | ||
bss.$nest = function(value, style) { | ||
this.style[(value.charAt(0) === ':' ? '' : ' ') + value] = parse(style) | ||
if (value) | ||
this.style[value] = parse(style) | ||
return chain(this) | ||
@@ -87,0 +91,0 @@ } |
@@ -7,3 +7,3 @@ import popular from './popular' | ||
findWidth(document.documentElement.style) | ||
).filter(prop => typeof document.documentElement.style[prop] === 'string') | ||
).filter(p => p.indexOf('-') === -1) | ||
@@ -16,2 +16,33 @@ function findWidth(obj) { | ||
const memoize = (fn, cache = {}) => item => | ||
item in cache | ||
? cache[item] | ||
: cache[item] = fn(item) | ||
const stringToObject = memoize(string => { | ||
let last = '' | ||
, prev | ||
return string.replace(/;/g, '\n').split('\n').reduce((acc, line) => { | ||
line = last + line.trim() | ||
last = line.endsWith(',') ? line : '' | ||
if (last) | ||
return acc | ||
if (line.startsWith(',')) { | ||
acc[prev] += line | ||
return acc | ||
} | ||
const tokens = line.split(/[:\s]/) | ||
if (tokens.length > 1) { | ||
const key = hyphenToCamelCase(tokens.shift().trim()) | ||
prev = shorts[key] || key | ||
acc[prev] = tokens.filter(a => a).map(t => addPx(prev, t.trim())).join(' ') | ||
} | ||
return acc | ||
}, {}) | ||
}) | ||
export const vendorMap = Object.create(null, {}) | ||
@@ -35,7 +66,2 @@ | ||
const memoize = (fn, cache = {}) => item => | ||
item in cache | ||
? cache[item] | ||
: cache[item] = fn(item) | ||
const appendPx = memoize(prop => { | ||
@@ -143,13 +169,2 @@ const el = document.createElement('div') | ||
function stringToObject(string) { | ||
return string.replace(/;/g, '\n').split('\n').reduce((acc, line) => { | ||
const tokens = line.trim().split(/[: ]/) | ||
if (tokens.length > 1) { | ||
const key = hyphenToCamelCase(tokens.shift().trim()) | ||
acc[shorts[key] || key] = addPx(shorts[key] || key, tokens.join(' ').trim()) | ||
} | ||
return acc | ||
}, {}) | ||
} | ||
export function readClasses(sheet) { | ||
@@ -156,0 +171,0 @@ throw new Error('not implemented') |
{ | ||
"name": "bss", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Better Style Sheets", | ||
@@ -10,2 +10,3 @@ "main": "bss.js", | ||
"prepublish": "npm run build", | ||
"popular": "node scripts/popular", | ||
"build": "rollup -c" | ||
@@ -12,0 +13,0 @@ }, |
@@ -127,3 +127,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)]() | ||
``` js | ||
b.textAlign('green').class // Returns eg. bdp4f3o1 | ||
b.textAlign('center').class // Returns eg. bdp4f3o1 | ||
``` | ||
@@ -135,3 +135,3 @@ | ||
``` js | ||
b.textAlign('green').style // Returns { textAlign: 'green' } | ||
b.textAlign('center').style // Returns { textAlign: 'center' } | ||
``` | ||
@@ -144,3 +144,3 @@ | ||
``` js | ||
'div' + b.textAlign('green') // Returns eg. div.bdp4f3o1 | ||
'div' + b.textAlign('center') // Returns eg. div.bdp4f3o1 | ||
``` | ||
@@ -152,3 +152,3 @@ | ||
`<div class="${ b.textAlign('green') }`"></div>` // Returns eg. <div class="bdp4f3o1"></div> | ||
`<div class="${ b.textAlign('center') }`"></div>` // Returns eg. <div class="bdp4f3o1"></div> | ||
``` | ||
@@ -155,0 +155,0 @@ |
@@ -57,5 +57,11 @@ const o = require('ospec') | ||
o('multiline input', function() { | ||
o(b('t s(1)\n,r(0)').style).deepEquals({ t: 's(1),r(0)' }) | ||
o(b('t s(1),\nr(0)').style).deepEquals({ t: 's(1),r(0)' }) | ||
}) | ||
o('default css properties', function() { | ||
o(b.bc('green').style).deepEquals({ backgroundColor: 'green' }) | ||
o(b.p(20, 10, '50%').style).deepEquals({ padding: '20px 10px 50%' }) | ||
o(b`p 20 10 50%`.style).deepEquals({ padding: '20px 10px 50%' }) | ||
o(b.backgroundColor('red').style).deepEquals({ backgroundColor: 'red' }) | ||
@@ -62,0 +68,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
95624
19
1701
3
1