@glitz/core
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -74,4 +74,3 @@ 'use strict'; | ||
} | ||
var uppercaseRegex = /[A-Z]/g; | ||
var prefixRegex = /^(ms|moz|webkit)/; | ||
var hyphenateRegex = /(?:^(ms|moz|webkit))|[A-Z]/g; | ||
var propertyCache = {}; | ||
@@ -81,6 +80,3 @@ function hyphenateProperty(property) { | ||
? propertyCache[property] | ||
: (propertyCache[property] = property | ||
.replace(uppercaseRegex, '-$&') | ||
.replace(prefixRegex, '-$&') | ||
.toLowerCase()); | ||
: (propertyCache[property] = property.replace(hyphenateRegex, '-$&').toLowerCase()); | ||
} | ||
@@ -225,18 +221,15 @@ | ||
var block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
var dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
var existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
var dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
var existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
var className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
else { | ||
var className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
return className; | ||
} | ||
return className; | ||
} | ||
return ''; | ||
}; | ||
@@ -249,17 +242,14 @@ this.injectKeyframes = function (declarationList) { | ||
} | ||
if (blockList) { | ||
var existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
var existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
} | ||
else { | ||
var name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
else { | ||
var name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -280,17 +270,14 @@ this.injectFontFace = function (original) { | ||
var block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
var existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
var existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
var name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
else { | ||
var name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -314,3 +301,3 @@ } | ||
{ | ||
if (value === undefined || value === null || !(isPrimitive(value) || typeof value === 'object')) { | ||
if (value === null || !(value === undefined || isPrimitive(value) || typeof value === 'object')) { | ||
console.error('The style property `%s` was has to be a string, number or object, was %O', property, value); | ||
@@ -328,26 +315,32 @@ } | ||
} | ||
if (isPrimitive(value) || Array.isArray(value) || property === ANIMATION_NAME || property === FONT_FAMILY) { | ||
if (value === undefined || | ||
isPrimitive(value) || | ||
Array.isArray(value) || | ||
property === ANIMATION_NAME || | ||
property === FONT_FAMILY) { | ||
var declarations = getIndex(result, media, pseudo); | ||
if (!(property in declarations)) { | ||
if (property === ANIMATION_NAME && !(isPrimitive(value) || Array.isArray(value))) { | ||
if (transformer) { | ||
var list = {}; | ||
for (var identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
if (typeof value === 'object') { | ||
if (property === ANIMATION_NAME) { | ||
if (transformer) { | ||
var list = {}; | ||
for (var identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
} | ||
value = list; | ||
} | ||
value = list; | ||
value = injector().injectKeyframes(value); | ||
} | ||
value = injector().injectKeyframes(value); | ||
} | ||
if (property === FONT_FAMILY && !isPrimitive(value)) { | ||
var families = [].concat(value); | ||
var names = ''; | ||
for (var _i = 0, families_1 = families; _i < families_1.length; _i++) { | ||
var family = families_1[_i]; | ||
if (names) { | ||
names += ','; | ||
if (property === FONT_FAMILY) { | ||
var families = [].concat(value); | ||
var names = ''; | ||
for (var _i = 0, families_1 = families; _i < families_1.length; _i++) { | ||
var family = families_1[_i]; | ||
if (names) { | ||
names += ','; | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
value = names; | ||
} | ||
value = names; | ||
} | ||
@@ -374,3 +367,4 @@ declarations[property] = value; | ||
var longhandValue = value[extension]; | ||
if (isPrimitive(longhandValue) || | ||
if (longhandValue === undefined || | ||
isPrimitive(longhandValue) || | ||
Array.isArray(longhandValue) || | ||
@@ -410,58 +404,64 @@ // Objects are only valid for `animation.name` and `font.family` | ||
var cache = {}; | ||
var inject = | ||
// Atomic as default | ||
atomic === false | ||
? function (style, media, pseudo) { | ||
var classNames = ''; | ||
var keys = Object.keys(style); | ||
var blocks = {}; | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
var key = keys[i]; | ||
var object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
for (var rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
var inject = atomic === false | ||
? // Non-atomic style | ||
function (style, media, pseudo) { | ||
var classNames = ''; | ||
var keys = Object.keys(style); | ||
var blocks = {}; | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
var key = keys[i]; | ||
if (style[key] === undefined) { | ||
continue; | ||
} | ||
var object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
for (var rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
} | ||
} | ||
return classNames; | ||
} | ||
return classNames; | ||
} | ||
: function (style, media, pseudo) { | ||
var classNames = ''; | ||
var properties = Object.keys(style); | ||
var index = getIndex(cache, media, pseudo); | ||
for (var i = properties.length - 1; i >= 0; i--) { | ||
var property = properties[i]; | ||
var value = style[property]; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
var declaration = (_a = {}, _a[property] = value, _a); | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
var cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
: // Atomic style | ||
function (style, media, pseudo) { | ||
var classNames = ''; | ||
var properties = Object.keys(style); | ||
var index = getIndex(cache, media, pseudo); | ||
for (var i = properties.length - 1; i >= 0; i--) { | ||
var property = properties[i]; | ||
var value = style[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
var className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
var declaration = (_a = {}, _a[property] = value, _a); | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
var cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
continue; | ||
} | ||
var className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
return classNames; | ||
var _a; | ||
}; | ||
return classNames; | ||
var _a; | ||
}; | ||
this.injectStyle = function (styles) { | ||
@@ -554,3 +554,2 @@ var result = {}; | ||
var css = styleElement.textContent; | ||
// console.log(styleElement); | ||
if (css) { | ||
@@ -557,0 +556,0 @@ var rule = void 0; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var e in n)n.hasOwnProperty(e)&&(r[e]=n[e])};function n(n,e){function t(){this.constructor=n}r(n,e),n.prototype=null===e?Object.create(e):(t.prototype=e.prototype,new t)}function e(r){var n,e="";for(n in r){var i=r[n];if("object"==typeof i)for(var o=0,a=i;o<a.length;o++){var f=a[o];e&&(e+=";"),e+=t(n,f)}else e&&(e+=";"),e+=t(n,i)}return e}function t(r,n){return"string"==typeof n||"number"==typeof n?f(r)+":"+n:""}var i=/[A-Z]/g,o=/^(ms|moz|webkit)/,a={};function f(r){return r in a?a[r]:a[r]=r.replace(i,"-$&").replace(o,"-$&").toLowerCase()}function u(r,n){return r+"{"+n+"}"}var c="animationName",s="fontFamily",v=function(){return function(r,n,t,i,o,a,f,c,v,l){this.injectClassName=function(t,i){var a=e(t);if(a){var f=i?n[i]=n[i]||{}:r,u=f[a];if(u)return u;var s=o();return f[a]=s,c&&c(s,a,i),s}return""},this.injectKeyframes=function(r){var n="";for(var i in r)n+=u(i,e(r[i]));if(n){var o=t[n];if(o)return o;var f=a();return t[n]=f,v&&v(f,n),f}return""},this.injectFontFace=function(r){var n,t={};for(n in r)n!==s&&(t[n]=r[n]);var o=e(t);if(o){var a=i[o];if(a)return a;var u=f();return i[o]=u,l&&l(u,o),u}return""}}}(),l="__glitz__",y="$",m="@",p=":",h=function(){return function(r,n,e){var t=function(e,i,o,a){void 0===i&&(i={});for(var f=Object.keys(e),u=f.length-1;u>=0;u--){var v=f[u],l=e[v];if("@keyframes"===v&&(v=c),"@font-face"===v&&(v=s),g(l)||Array.isArray(l)||v===c||v===s){var y=d(i,o,a);if(!(v in y)){if(v===c&&!g(l)&&!Array.isArray(l)){if(n){var h={};for(var j in l)h[j]=n(l[j]);l=h}l=r().injectKeyframes(l)}if(v===s&&!g(l)){for(var _="",x=0,b=[].concat(l);x<b.length;x++){var O=b[x];_&&(_+=","),_+=g(O)?O:r().injectFontFace(O)}l=_}y[v]=l}}else if(v[0]!==m&&v[0]!==p){var A=!0,k={},w=void 0;for(w in l){var C=l[w];if(!(g(C)||Array.isArray(C)||"animation"===v&&"name"===w||"font"===v&&"family"===w)){A=!1;break}"x"!==w?"y"!==w?k[v+w[0].toUpperCase()+w.slice(1)]=C:(k[v+"Top"]=C,k[v+"Bottom"]=C):(k[v+"Left"]=C,k[v+"Right"]=C)}A&&t(k,i,o,a)}else t(l,i,v[0]===m?v:o,v[0]===p?(a||"")+v:a)}return i},i=function(e,t,i){return r(t).injectClassName(n?n(e):e,i)},o={},a=!1===e?function(r,n,e){for(var t="",o=Object.keys(r),f={},u=o.length-1;u>=0;u--){var c=o[u];(c[0]===m||c[0]===p?f:f[y]=f[y]||{})[c]=r[c]}for(var s in f)t+=s===y?" "+i(f[s],n,e):a(f[s],s[0]===m?s.slice(7):n,s[0]===p?s:e);return t}:function(r,n,e){for(var t,f="",u=Object.keys(r),c=d(o,n,e),s=u.length-1;s>=0;s--){var v=u[s],l=r[v];if(v[0]!==m&&v[0]!==p){var y=((t={})[v]=l,t);if(g(l)){var h=c[v]=c[v]||{};if(l in h){f+=" "+h[l];continue}var j=i(y,n,e);f+=" "+(h[l]=j)}else f+=" "+i(y,n,e)}else f+=a(l,v[0]===m?v.slice(7):n,v[0]===p?v:e)}return f};this.injectStyle=function(r){var n={};if(Array.isArray(r))for(var e=r.length-1;e>=0;e--)t(r[e],n);else t(r,n);return a(n).slice(1)}}}();function d(r,n,e){var t=r;return n&&(t=t[n]=t[n]||{}),e?t[e]=t[e]||{}:t}function g(r){return"string"==typeof r||"number"==typeof r}function j(r,n){var e=r.sheet;e.insertRule(n,e.cssRules.length)}function _(r){var n=document.createElement("style");return r&&(n.media=r),n}function x(r,n){return document.head.insertBefore(r,n),r}function b(r){void 0===r&&(r="");var n=0,e=10,t=35,i=1,o=function(){var a=n+e;return a===t&&(e+=9*(t+1),t=Math.pow(36,++i)-1),n++,373===a?o():r+a.toString(36)};return o}var O=/\.([a-z0-9])(:[^{]+)?\{([^}]+)\}/g,A=/@keyframes ([a-z0-9])\{((?:[a-z0-9%]+\{[^}]+\})+)\}/g,k=/@font-face \{(.+);font-family:([^}]+)\}/g,w=function(r){function e(n,e,t,i){var o={},a={},f={},c=n.textContent;if(c){for(var s=void 0;s=O.exec(c);){if(e(),s[2])(a[s[2]]=a[s[2]]||{})[s[3]]=s[1];else o[s[3]]=s[1]}for(;s=A.exec(c);)t(),f[s[2]]=s[1];for(;s=k.exec(c);)i(),f[s[1]]=s[2]}return r.call(this,o,a,f,{},e,t,i,function(r,e,t){var i=function(r,n,e){return void 0===e&&(e=""),"."+u(r+e,n)}(r,e,t);j(n,i)},function(r,e){var t=function(r,n){return"@keyframes "+u(r,n)}(r,e);j(n,t)},function(r,e){var t=function(r,n){return"@font-face {"+n+";font-family:"+r+"}"}(r,e);j(n,t)})||this}return n(e,r),e}(v),C=function(r){function e(n,e){void 0===e&&(e={});var t,i,o=e.prefix,a=b(o),f=b(o),u=b(o),c=e.mediaOrder,s={},v=null,y={};if(t=r.call(this,function(r){if(r){if(y[r])return y[r];var n=s[r]=_(r),e=null;if(c){var t=Object.keys(s).sort(c);v=s[t[0]],e=s[t[t.indexOf(r)+1]]||null}return x(n,e),y[r]=new w(n,a,f,u)}if(i)return i;n=x(_(r),v);return i=new w(n,a,f,u)},e.transformer,e.atomic)||this,"auto"===n&&(n=document.getElementsByClassName(l)),n)for(var m=0,p=n;m<p.length;m++){var h=p[m],d=h.media;d?(v||(v=h),s[d]=h,y[d]=new w(h,a,f,u)):i=new w(h,a,f,u)}return t}return n(e,r),e}(h);function z(r){var n,e="";for(n in r){e&&(e+=" and ");var t=r[n];e+=!0===t?"("+f(n)+")":"("+f(n)+": "+t+")"}return e}exports.default=C,exports.media=function(r,n){return(e={})["@media "+("string"==typeof r?r:z(r))]=n,e;var e},exports.query=z,exports.pseudo=function(r,n){return(e={})[r]=n,e;var e},exports.compose=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return r.reduceRight(function(r,n){return function(e){return n(r(e))}})}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var t in n)n.hasOwnProperty(t)&&(r[t]=n[t])};function n(n,t){function e(){this.constructor=n}r(n,t),n.prototype=null===t?Object.create(t):(e.prototype=t.prototype,new e)}function t(r){var n,t="";for(n in r){var i=r[n];if("object"==typeof i)for(var o=0,f=i;o<f.length;o++){var a=f[o];t&&(t+=";"),t+=e(n,a)}else t&&(t+=";"),t+=e(n,i)}return t}function e(r,n){return"string"==typeof n||"number"==typeof n?f(r)+":"+n:""}var i=/(?:^(ms|moz|webkit))|[A-Z]/g,o={};function f(r){return r in o?o[r]:o[r]=r.replace(i,"-$&").toLowerCase()}function a(r,n){return r+"{"+n+"}"}var u="animationName",c="fontFamily",s=function(){return function(r,n,e,i,o,f,u,s,v,l){this.injectClassName=function(e,i){var f=t(e),a=i?n[i]=n[i]||{}:r,u=a[f];if(u)return u;var c=o();return a[f]=c,s&&s(c,f,i),c},this.injectKeyframes=function(r){var n="";for(var i in r)n+=a(i,t(r[i]));var o=e[n];if(o)return o;var u=f();return e[n]=u,v&&v(u,n),u},this.injectFontFace=function(r){var n,e={};for(n in r)n!==c&&(e[n]=r[n]);var o=t(e),f=i[o];if(f)return f;var a=u();return i[o]=a,l&&l(a,o),a}}}(),v="__glitz__",l="$",y="@",m=":",p=function(){return function(r,n,t){var e=function(t,i,o,f){void 0===i&&(i={});for(var a=Object.keys(t),s=a.length-1;s>=0;s--){var v=a[s],l=t[v];if("@keyframes"===v&&(v=u),"@font-face"===v&&(v=c),void 0===l||h(l)||Array.isArray(l)||v===u||v===c){var p=d(i,o,f);if(!(v in p)){if("object"==typeof l){if(v===u){if(n){var g={};for(var j in l)g[j]=n(l[j]);l=g}l=r().injectKeyframes(l)}if(v===c){for(var _="",b=0,x=[].concat(l);b<x.length;b++){var O=x[b];_&&(_+=","),_+=h(O)?O:r().injectFontFace(O)}l=_}}p[v]=l}}else if(v[0]!==y&&v[0]!==m){var k=!0,w={},A=void 0;for(A in l){var C=l[A];if(!(void 0===C||h(C)||Array.isArray(C)||"animation"===v&&"name"===A||"font"===v&&"family"===A)){k=!1;break}"x"!==A?"y"!==A?w[v+A[0].toUpperCase()+A.slice(1)]=C:(w[v+"Top"]=C,w[v+"Bottom"]=C):(w[v+"Left"]=C,w[v+"Right"]=C)}k&&e(w,i,o,f)}else e(l,i,v[0]===y?v:o,v[0]===m?(f||"")+v:f)}return i},i=function(t,e,i){return r(e).injectClassName(n?n(t):t,i)},o={},f=!1===t?function(r,n,t){for(var e="",o=Object.keys(r),a={},u=o.length-1;u>=0;u--){var c=o[u];void 0!==r[c]&&((c[0]===y||c[0]===m?a:a[l]=a[l]||{})[c]=r[c])}for(var s in a)e+=s===l?" "+i(a[s],n,t):f(a[s],s[0]===y?s.slice(7):n,s[0]===m?s:t);return e}:function(r,n,t){for(var e,a="",u=Object.keys(r),c=d(o,n,t),s=u.length-1;s>=0;s--){var v=u[s],l=r[v];if(void 0!==l)if(v[0]!==y&&v[0]!==m){var p=((e={})[v]=l,e);if(h(l)){var g=c[v]=c[v]||{};if(l in g){a+=" "+g[l];continue}var j=i(p,n,t);a+=" "+(g[l]=j)}else a+=" "+i(p,n,t)}else a+=f(l,v[0]===y?v.slice(7):n,v[0]===m?v:t)}return a};this.injectStyle=function(r){var n={};if(Array.isArray(r))for(var t=r.length-1;t>=0;t--)e(r[t],n);else e(r,n);return f(n).slice(1)}}}();function d(r,n,t){var e=r;return n&&(e=e[n]=e[n]||{}),t?e[t]=e[t]||{}:e}function h(r){return"string"==typeof r||"number"==typeof r}function g(r,n){var t=r.sheet;t.insertRule(n,t.cssRules.length)}function j(r){var n=document.createElement("style");return r&&(n.media=r),n}function _(r,n){return document.head.insertBefore(r,n),r}function b(r){void 0===r&&(r="");var n=0,t=10,e=35,i=1,o=function(){var f=n+t;return f===e&&(t+=9*(e+1),e=Math.pow(36,++i)-1),n++,373===f?o():r+f.toString(36)};return o}var x=/\.([a-z0-9])(:[^{]+)?\{([^}]+)\}/g,O=/@keyframes ([a-z0-9])\{((?:[a-z0-9%]+\{[^}]+\})+)\}/g,k=/@font-face \{(.+);font-family:([^}]+)\}/g,w=function(r){function t(n,t,e,i){var o={},f={},u={},c=n.textContent;if(c){for(var s=void 0;s=x.exec(c);){if(t(),s[2])(f[s[2]]=f[s[2]]||{})[s[3]]=s[1];else o[s[3]]=s[1]}for(;s=O.exec(c);)e(),u[s[2]]=s[1];for(;s=k.exec(c);)i(),u[s[1]]=s[2]}return r.call(this,o,f,u,{},t,e,i,function(r,t,e){var i=function(r,n,t){return void 0===t&&(t=""),"."+a(r+t,n)}(r,t,e);g(n,i)},function(r,t){var e=function(r,n){return"@keyframes "+a(r,n)}(r,t);g(n,e)},function(r,t){var e=function(r,n){return"@font-face {"+n+";font-family:"+r+"}"}(r,t);g(n,e)})||this}return n(t,r),t}(s),A=function(r){function t(n,t){void 0===t&&(t={});var e,i,o=t.prefix,f=b(o),a=b(o),u=b(o),c=t.mediaOrder,s={},l=null,y={};if(e=r.call(this,function(r){if(r){if(y[r])return y[r];var n=s[r]=j(r),t=null;if(c){var e=Object.keys(s).sort(c);l=s[e[0]],t=s[e[e.indexOf(r)+1]]||null}return _(n,t),y[r]=new w(n,f,a,u)}if(i)return i;n=_(j(r),l);return i=new w(n,f,a,u)},t.transformer,t.atomic)||this,"auto"===n&&(n=document.getElementsByClassName(v)),n)for(var m=0,p=n;m<p.length;m++){var d=p[m],h=d.media;h?(l||(l=d),s[h]=d,y[h]=new w(d,f,a,u)):i=new w(d,f,a,u)}return e}return n(t,r),t}(p);function C(r){var n,t="";for(n in r){t&&(t+=" and ");var e=r[n];t+=!0===e?"("+f(n)+")":"("+f(n)+": "+e+")"}return t}exports.default=A,exports.media=function(r,n){return(t={})["@media "+("string"==typeof r?r:C(r))]=n,t;var t},exports.query=C,exports.pseudo=function(r,n){return(t={})[r]=n,t;var t},exports.compose=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return r.reduceRight(function(r,n){return function(t){return n(r(t))}})}; |
@@ -74,4 +74,3 @@ 'use strict'; | ||
} | ||
var uppercaseRegex = /[A-Z]/g; | ||
var prefixRegex = /^(ms|moz|webkit)/; | ||
var hyphenateRegex = /(?:^(ms|moz|webkit))|[A-Z]/g; | ||
var propertyCache = {}; | ||
@@ -81,6 +80,3 @@ function hyphenateProperty(property) { | ||
? propertyCache[property] | ||
: (propertyCache[property] = property | ||
.replace(uppercaseRegex, '-$&') | ||
.replace(prefixRegex, '-$&') | ||
.toLowerCase()); | ||
: (propertyCache[property] = property.replace(hyphenateRegex, '-$&').toLowerCase()); | ||
} | ||
@@ -225,18 +221,15 @@ | ||
var block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
var dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
var existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
var dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
var existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
var className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
else { | ||
var className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
return className; | ||
} | ||
return className; | ||
} | ||
return ''; | ||
}; | ||
@@ -249,17 +242,14 @@ this.injectKeyframes = function (declarationList) { | ||
} | ||
if (blockList) { | ||
var existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
var existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
} | ||
else { | ||
var name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
else { | ||
var name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -280,17 +270,14 @@ this.injectFontFace = function (original) { | ||
var block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
var existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
var existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
var name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
else { | ||
var name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -314,3 +301,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (value === undefined || value === null || !(isPrimitive(value) || typeof value === 'object')) { | ||
if (value === null || !(value === undefined || isPrimitive(value) || typeof value === 'object')) { | ||
console.error('The style property `%s` was has to be a string, number or object, was %O', property, value); | ||
@@ -328,26 +315,32 @@ } | ||
} | ||
if (isPrimitive(value) || Array.isArray(value) || property === ANIMATION_NAME || property === FONT_FAMILY) { | ||
if (value === undefined || | ||
isPrimitive(value) || | ||
Array.isArray(value) || | ||
property === ANIMATION_NAME || | ||
property === FONT_FAMILY) { | ||
var declarations = getIndex(result, media, pseudo); | ||
if (!(property in declarations)) { | ||
if (property === ANIMATION_NAME && !(isPrimitive(value) || Array.isArray(value))) { | ||
if (transformer) { | ||
var list = {}; | ||
for (var identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
if (typeof value === 'object') { | ||
if (property === ANIMATION_NAME) { | ||
if (transformer) { | ||
var list = {}; | ||
for (var identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
} | ||
value = list; | ||
} | ||
value = list; | ||
value = injector().injectKeyframes(value); | ||
} | ||
value = injector().injectKeyframes(value); | ||
} | ||
if (property === FONT_FAMILY && !isPrimitive(value)) { | ||
var families = [].concat(value); | ||
var names = ''; | ||
for (var _i = 0, families_1 = families; _i < families_1.length; _i++) { | ||
var family = families_1[_i]; | ||
if (names) { | ||
names += ','; | ||
if (property === FONT_FAMILY) { | ||
var families = [].concat(value); | ||
var names = ''; | ||
for (var _i = 0, families_1 = families; _i < families_1.length; _i++) { | ||
var family = families_1[_i]; | ||
if (names) { | ||
names += ','; | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
value = names; | ||
} | ||
value = names; | ||
} | ||
@@ -374,3 +367,4 @@ declarations[property] = value; | ||
var longhandValue = value[extension]; | ||
if (isPrimitive(longhandValue) || | ||
if (longhandValue === undefined || | ||
isPrimitive(longhandValue) || | ||
Array.isArray(longhandValue) || | ||
@@ -410,58 +404,64 @@ // Objects are only valid for `animation.name` and `font.family` | ||
var cache = {}; | ||
var inject = | ||
// Atomic as default | ||
atomic === false | ||
? function (style, media, pseudo) { | ||
var classNames = ''; | ||
var keys = Object.keys(style); | ||
var blocks = {}; | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
var key = keys[i]; | ||
var object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
for (var rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
var inject = atomic === false | ||
? // Non-atomic style | ||
function (style, media, pseudo) { | ||
var classNames = ''; | ||
var keys = Object.keys(style); | ||
var blocks = {}; | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
var key = keys[i]; | ||
if (style[key] === undefined) { | ||
continue; | ||
} | ||
var object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
for (var rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
} | ||
} | ||
return classNames; | ||
} | ||
return classNames; | ||
} | ||
: function (style, media, pseudo) { | ||
var classNames = ''; | ||
var properties = Object.keys(style); | ||
var index = getIndex(cache, media, pseudo); | ||
for (var i = properties.length - 1; i >= 0; i--) { | ||
var property = properties[i]; | ||
var value = style[property]; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
var declaration = (_a = {}, _a[property] = value, _a); | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
var cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
: // Atomic style | ||
function (style, media, pseudo) { | ||
var classNames = ''; | ||
var properties = Object.keys(style); | ||
var index = getIndex(cache, media, pseudo); | ||
for (var i = properties.length - 1; i >= 0; i--) { | ||
var property = properties[i]; | ||
var value = style[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
var className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
var declaration = (_a = {}, _a[property] = value, _a); | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
var cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
continue; | ||
} | ||
var className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
return classNames; | ||
var _a; | ||
}; | ||
return classNames; | ||
var _a; | ||
}; | ||
this.injectStyle = function (styles) { | ||
@@ -468,0 +468,0 @@ var result = {}; |
@@ -16,3 +16,2 @@ // tslint:disable no-conditional-assignment | ||
const css = styleElement.textContent; | ||
// console.log(styleElement); | ||
if (css) { | ||
@@ -19,0 +18,0 @@ let rule; |
@@ -15,3 +15,3 @@ import { validateMixingShorthandLonghand } from '../utils/mixing-shorthand-longhand'; | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (value === undefined || value === null || !(isPrimitive(value) || typeof value === 'object')) { | ||
if (value === null || !(value === undefined || isPrimitive(value) || typeof value === 'object')) { | ||
console.error('The style property `%s` was has to be a string, number or object, was %O', property, value); | ||
@@ -29,25 +29,31 @@ } | ||
} | ||
if (isPrimitive(value) || Array.isArray(value) || property === ANIMATION_NAME || property === FONT_FAMILY) { | ||
if (value === undefined || | ||
isPrimitive(value) || | ||
Array.isArray(value) || | ||
property === ANIMATION_NAME || | ||
property === FONT_FAMILY) { | ||
const declarations = getIndex(result, media, pseudo); | ||
if (!(property in declarations)) { | ||
if (property === ANIMATION_NAME && !(isPrimitive(value) || Array.isArray(value))) { | ||
if (transformer) { | ||
const list = {}; | ||
for (const identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
if (typeof value === 'object') { | ||
if (property === ANIMATION_NAME) { | ||
if (transformer) { | ||
const list = {}; | ||
for (const identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
} | ||
value = list; | ||
} | ||
value = list; | ||
value = injector().injectKeyframes(value); | ||
} | ||
value = injector().injectKeyframes(value); | ||
} | ||
if (property === FONT_FAMILY && !isPrimitive(value)) { | ||
const families = [].concat(value); | ||
let names = ''; | ||
for (const family of families) { | ||
if (names) { | ||
names += ','; | ||
if (property === FONT_FAMILY) { | ||
const families = [].concat(value); | ||
let names = ''; | ||
for (const family of families) { | ||
if (names) { | ||
names += ','; | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
value = names; | ||
} | ||
value = names; | ||
} | ||
@@ -74,3 +80,4 @@ declarations[property] = value; | ||
const longhandValue = value[extension]; | ||
if (isPrimitive(longhandValue) || | ||
if (longhandValue === undefined || | ||
isPrimitive(longhandValue) || | ||
Array.isArray(longhandValue) || | ||
@@ -108,57 +115,63 @@ // Objects are only valid for `animation.name` and `font.family` | ||
const cache = {}; | ||
const inject = | ||
// Atomic as default | ||
atomic === false | ||
? (style, media, pseudo) => { | ||
let classNames = ''; | ||
const keys = Object.keys(style); | ||
const blocks = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
const object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
for (const rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
const inject = atomic === false | ||
? // Non-atomic style | ||
(style, media, pseudo) => { | ||
let classNames = ''; | ||
const keys = Object.keys(style); | ||
const blocks = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
if (style[key] === undefined) { | ||
continue; | ||
} | ||
const object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
for (const rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
} | ||
} | ||
return classNames; | ||
} | ||
return classNames; | ||
} | ||
: (style, media, pseudo) => { | ||
let classNames = ''; | ||
const properties = Object.keys(style); | ||
const index = getIndex(cache, media, pseudo); | ||
for (let i = properties.length - 1; i >= 0; i--) { | ||
const property = properties[i]; | ||
const value = style[property]; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
const declaration = { [property]: value }; | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
const cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
: // Atomic style | ||
(style, media, pseudo) => { | ||
let classNames = ''; | ||
const properties = Object.keys(style); | ||
const index = getIndex(cache, media, pseudo); | ||
for (let i = properties.length - 1; i >= 0; i--) { | ||
const property = properties[i]; | ||
const value = style[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
const className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
const declaration = { [property]: value }; | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
const cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
continue; | ||
} | ||
const className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
return classNames; | ||
}; | ||
return classNames; | ||
}; | ||
this.injectStyle = (styles) => { | ||
@@ -165,0 +178,0 @@ const result = {}; |
@@ -9,18 +9,15 @@ import { formatRule } from '../utils/format'; | ||
const block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
const dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
const existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
const dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
const existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
const className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
else { | ||
const className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
return className; | ||
} | ||
return className; | ||
} | ||
return ''; | ||
}; | ||
@@ -33,17 +30,14 @@ this.injectKeyframes = declarationList => { | ||
} | ||
if (blockList) { | ||
const existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
const existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
} | ||
else { | ||
const name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
else { | ||
const name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -64,19 +58,16 @@ this.injectFontFace = original => { | ||
const block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
const existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
const existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
const name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
else { | ||
const name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
} | ||
} |
@@ -43,4 +43,3 @@ export function parseDeclarationBlock(declarations) { | ||
} | ||
const uppercaseRegex = /[A-Z]/g; | ||
const prefixRegex = /^(ms|moz|webkit)/; | ||
const hyphenateRegex = /(?:^(ms|moz|webkit))|[A-Z]/g; | ||
const propertyCache = {}; | ||
@@ -50,6 +49,3 @@ export function hyphenateProperty(property) { | ||
? propertyCache[property] | ||
: (propertyCache[property] = property | ||
.replace(uppercaseRegex, '-$&') | ||
.replace(prefixRegex, '-$&') | ||
.toLowerCase()); | ||
: (propertyCache[property] = property.replace(hyphenateRegex, '-$&').toLowerCase()); | ||
} |
229
jsm/index.js
@@ -43,4 +43,3 @@ function parseDeclarationBlock(declarations) { | ||
} | ||
const uppercaseRegex = /[A-Z]/g; | ||
const prefixRegex = /^(ms|moz|webkit)/; | ||
const hyphenateRegex = /(?:^(ms|moz|webkit))|[A-Z]/g; | ||
const propertyCache = {}; | ||
@@ -50,6 +49,3 @@ function hyphenateProperty(property) { | ||
? propertyCache[property] | ||
: (propertyCache[property] = property | ||
.replace(uppercaseRegex, '-$&') | ||
.replace(prefixRegex, '-$&') | ||
.toLowerCase()); | ||
: (propertyCache[property] = property.replace(hyphenateRegex, '-$&').toLowerCase()); | ||
} | ||
@@ -192,18 +188,15 @@ | ||
const block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
const dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
const existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
const dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
const existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
const className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
else { | ||
const className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
return className; | ||
} | ||
return className; | ||
} | ||
return ''; | ||
}; | ||
@@ -216,17 +209,14 @@ this.injectKeyframes = declarationList => { | ||
} | ||
if (blockList) { | ||
const existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
const existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
} | ||
else { | ||
const name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
else { | ||
const name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -247,17 +237,14 @@ this.injectFontFace = original => { | ||
const block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
const existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
const existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
const name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
else { | ||
const name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -279,3 +266,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (value === undefined || value === null || !(isPrimitive(value) || typeof value === 'object')) { | ||
if (value === null || !(value === undefined || isPrimitive(value) || typeof value === 'object')) { | ||
console.error('The style property `%s` was has to be a string, number or object, was %O', property, value); | ||
@@ -293,25 +280,31 @@ } | ||
} | ||
if (isPrimitive(value) || Array.isArray(value) || property === ANIMATION_NAME || property === FONT_FAMILY) { | ||
if (value === undefined || | ||
isPrimitive(value) || | ||
Array.isArray(value) || | ||
property === ANIMATION_NAME || | ||
property === FONT_FAMILY) { | ||
const declarations = getIndex(result, media, pseudo); | ||
if (!(property in declarations)) { | ||
if (property === ANIMATION_NAME && !(isPrimitive(value) || Array.isArray(value))) { | ||
if (transformer) { | ||
const list = {}; | ||
for (const identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
if (typeof value === 'object') { | ||
if (property === ANIMATION_NAME) { | ||
if (transformer) { | ||
const list = {}; | ||
for (const identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
} | ||
value = list; | ||
} | ||
value = list; | ||
value = injector().injectKeyframes(value); | ||
} | ||
value = injector().injectKeyframes(value); | ||
} | ||
if (property === FONT_FAMILY && !isPrimitive(value)) { | ||
const families = [].concat(value); | ||
let names = ''; | ||
for (const family of families) { | ||
if (names) { | ||
names += ','; | ||
if (property === FONT_FAMILY) { | ||
const families = [].concat(value); | ||
let names = ''; | ||
for (const family of families) { | ||
if (names) { | ||
names += ','; | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
value = names; | ||
} | ||
value = names; | ||
} | ||
@@ -338,3 +331,4 @@ declarations[property] = value; | ||
const longhandValue = value[extension]; | ||
if (isPrimitive(longhandValue) || | ||
if (longhandValue === undefined || | ||
isPrimitive(longhandValue) || | ||
Array.isArray(longhandValue) || | ||
@@ -372,57 +366,63 @@ // Objects are only valid for `animation.name` and `font.family` | ||
const cache = {}; | ||
const inject = | ||
// Atomic as default | ||
atomic === false | ||
? (style, media, pseudo) => { | ||
let classNames = ''; | ||
const keys = Object.keys(style); | ||
const blocks = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
const object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
for (const rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
const inject = atomic === false | ||
? // Non-atomic style | ||
(style, media, pseudo) => { | ||
let classNames = ''; | ||
const keys = Object.keys(style); | ||
const blocks = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
if (style[key] === undefined) { | ||
continue; | ||
} | ||
const object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
for (const rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
} | ||
} | ||
return classNames; | ||
} | ||
return classNames; | ||
} | ||
: (style, media, pseudo) => { | ||
let classNames = ''; | ||
const properties = Object.keys(style); | ||
const index = getIndex(cache, media, pseudo); | ||
for (let i = properties.length - 1; i >= 0; i--) { | ||
const property = properties[i]; | ||
const value = style[property]; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
const declaration = { [property]: value }; | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
const cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
: // Atomic style | ||
(style, media, pseudo) => { | ||
let classNames = ''; | ||
const properties = Object.keys(style); | ||
const index = getIndex(cache, media, pseudo); | ||
for (let i = properties.length - 1; i >= 0; i--) { | ||
const property = properties[i]; | ||
const value = style[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
const className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
const declaration = { [property]: value }; | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
const cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
continue; | ||
} | ||
const className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
return classNames; | ||
}; | ||
return classNames; | ||
}; | ||
this.injectStyle = (styles) => { | ||
@@ -511,3 +511,2 @@ const result = {}; | ||
const css = styleElement.textContent; | ||
// console.log(styleElement); | ||
if (css) { | ||
@@ -514,0 +513,0 @@ let rule; |
@@ -43,4 +43,3 @@ function parseDeclarationBlock(declarations) { | ||
} | ||
const uppercaseRegex = /[A-Z]/g; | ||
const prefixRegex = /^(ms|moz|webkit)/; | ||
const hyphenateRegex = /(?:^(ms|moz|webkit))|[A-Z]/g; | ||
const propertyCache = {}; | ||
@@ -50,6 +49,3 @@ function hyphenateProperty(property) { | ||
? propertyCache[property] | ||
: (propertyCache[property] = property | ||
.replace(uppercaseRegex, '-$&') | ||
.replace(prefixRegex, '-$&') | ||
.toLowerCase()); | ||
: (propertyCache[property] = property.replace(hyphenateRegex, '-$&').toLowerCase()); | ||
} | ||
@@ -192,18 +188,15 @@ | ||
const block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
const dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
const existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
const dictionary = pseudo ? (pseudoDictionary[pseudo] = pseudoDictionary[pseudo] || {}) : plainDictionary; | ||
const existingClassName = dictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
const className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
else { | ||
const className = incrementClassHash(); | ||
dictionary[block] = className; | ||
if (injectNewClassRule) { | ||
injectNewClassRule(className, block, pseudo); | ||
} | ||
return className; | ||
} | ||
return className; | ||
} | ||
return ''; | ||
}; | ||
@@ -216,17 +209,14 @@ this.injectKeyframes = declarationList => { | ||
} | ||
if (blockList) { | ||
const existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
const existingName = keyframesDictionary[blockList]; | ||
if (existingName) { | ||
return existingName; | ||
} | ||
else { | ||
const name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
else { | ||
const name = incrementKeyframesHash(); | ||
keyframesDictionary[blockList] = name; | ||
if (injectNewKeyframesRule) { | ||
injectNewKeyframesRule(name, blockList); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -247,17 +237,14 @@ this.injectFontFace = original => { | ||
const block = parseDeclarationBlock(declarations); | ||
if (block) { | ||
const existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
const existingClassName = fontFaceDictionary[block]; | ||
if (existingClassName) { | ||
return existingClassName; | ||
} | ||
else { | ||
const name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
else { | ||
const name = incrementFontFaceHash(); | ||
fontFaceDictionary[block] = name; | ||
if (injectNewFontFaceRule) { | ||
injectNewFontFaceRule(name, block); | ||
} | ||
return name; | ||
} | ||
return name; | ||
} | ||
return ''; | ||
}; | ||
@@ -279,3 +266,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (value === undefined || value === null || !(isPrimitive(value) || typeof value === 'object')) { | ||
if (value === null || !(value === undefined || isPrimitive(value) || typeof value === 'object')) { | ||
console.error('The style property `%s` was has to be a string, number or object, was %O', property, value); | ||
@@ -293,25 +280,31 @@ } | ||
} | ||
if (isPrimitive(value) || Array.isArray(value) || property === ANIMATION_NAME || property === FONT_FAMILY) { | ||
if (value === undefined || | ||
isPrimitive(value) || | ||
Array.isArray(value) || | ||
property === ANIMATION_NAME || | ||
property === FONT_FAMILY) { | ||
const declarations = getIndex(result, media, pseudo); | ||
if (!(property in declarations)) { | ||
if (property === ANIMATION_NAME && !(isPrimitive(value) || Array.isArray(value))) { | ||
if (transformer) { | ||
const list = {}; | ||
for (const identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
if (typeof value === 'object') { | ||
if (property === ANIMATION_NAME) { | ||
if (transformer) { | ||
const list = {}; | ||
for (const identifier in value) { | ||
list[identifier] = transformer(value[identifier]); | ||
} | ||
value = list; | ||
} | ||
value = list; | ||
value = injector().injectKeyframes(value); | ||
} | ||
value = injector().injectKeyframes(value); | ||
} | ||
if (property === FONT_FAMILY && !isPrimitive(value)) { | ||
const families = [].concat(value); | ||
let names = ''; | ||
for (const family of families) { | ||
if (names) { | ||
names += ','; | ||
if (property === FONT_FAMILY) { | ||
const families = [].concat(value); | ||
let names = ''; | ||
for (const family of families) { | ||
if (names) { | ||
names += ','; | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
} | ||
names += isPrimitive(family) ? family : injector().injectFontFace(family); | ||
value = names; | ||
} | ||
value = names; | ||
} | ||
@@ -338,3 +331,4 @@ declarations[property] = value; | ||
const longhandValue = value[extension]; | ||
if (isPrimitive(longhandValue) || | ||
if (longhandValue === undefined || | ||
isPrimitive(longhandValue) || | ||
Array.isArray(longhandValue) || | ||
@@ -372,57 +366,63 @@ // Objects are only valid for `animation.name` and `font.family` | ||
const cache = {}; | ||
const inject = | ||
// Atomic as default | ||
atomic === false | ||
? (style, media, pseudo) => { | ||
let classNames = ''; | ||
const keys = Object.keys(style); | ||
const blocks = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
const object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
for (const rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
const inject = atomic === false | ||
? // Non-atomic style | ||
(style, media, pseudo) => { | ||
let classNames = ''; | ||
const keys = Object.keys(style); | ||
const blocks = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const key = keys[i]; | ||
if (style[key] === undefined) { | ||
continue; | ||
} | ||
const object = key[0] === MEDIA_IDENTIFIER || key[0] === PSEUDO_IDENTIFIER | ||
? // Media or pseudo | ||
blocks | ||
: // Group declarations | ||
(blocks[NON_ATOMIC_KEY] = blocks[NON_ATOMIC_KEY] || {}); | ||
object[key] = style[key]; | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
for (const rule in blocks) { | ||
if (rule === NON_ATOMIC_KEY) { | ||
classNames += ' ' + injectClassName(blocks[rule], media, pseudo); | ||
} | ||
else { | ||
classNames += inject(blocks[rule], rule[0] === MEDIA_IDENTIFIER ? rule.slice(7) : media, rule[0] === PSEUDO_IDENTIFIER ? rule : pseudo); | ||
} | ||
} | ||
return classNames; | ||
} | ||
return classNames; | ||
} | ||
: (style, media, pseudo) => { | ||
let classNames = ''; | ||
const properties = Object.keys(style); | ||
const index = getIndex(cache, media, pseudo); | ||
for (let i = properties.length - 1; i >= 0; i--) { | ||
const property = properties[i]; | ||
const value = style[property]; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
const declaration = { [property]: value }; | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
const cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
: // Atomic style | ||
(style, media, pseudo) => { | ||
let classNames = ''; | ||
const properties = Object.keys(style); | ||
const index = getIndex(cache, media, pseudo); | ||
for (let i = properties.length - 1; i >= 0; i--) { | ||
const property = properties[i]; | ||
const value = style[property]; | ||
if (value === undefined) { | ||
continue; | ||
} | ||
const className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
// Media or pseudo | ||
if (property[0] === MEDIA_IDENTIFIER || property[0] === PSEUDO_IDENTIFIER) { | ||
classNames += inject(value, property[0] === MEDIA_IDENTIFIER ? property.slice(7) : media, property[0] === PSEUDO_IDENTIFIER ? property : pseudo); | ||
continue; | ||
} | ||
const declaration = { [property]: value }; | ||
if (isPrimitive(value)) { | ||
// Only supports caching of primitive values | ||
const cachedValues = (index[property] = index[property] || {}); | ||
if (value in cachedValues) { | ||
classNames += ' ' + cachedValues[value]; | ||
continue; | ||
} | ||
const className = injectClassName(declaration, media, pseudo); | ||
classNames += ' ' + (cachedValues[value] = className); | ||
continue; | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
// Array | ||
classNames += ' ' + injectClassName(declaration, media, pseudo); | ||
} | ||
return classNames; | ||
}; | ||
return classNames; | ||
}; | ||
this.injectStyle = (styles) => { | ||
@@ -429,0 +429,0 @@ const result = {}; |
{ | ||
"name": "@glitz/core", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "./cjs/index.js", | ||
@@ -14,3 +14,3 @@ "module": "./jsm/index.js", | ||
"dependencies": { | ||
"@glitz/type": "^1.1.2" | ||
"@glitz/type": "^1.1.3" | ||
}, | ||
@@ -17,0 +17,0 @@ "scripts": { |
163710
3394
Updated@glitz/type@^1.1.3