@dash-ui/styles
Version:
A tiny, powerful, framework-agnostic CSS-in-JS library.
3 lines (2 loc) • 5.54 kB
JavaScript
function e(e){for(var t=2166136261,n=0,r=e.length;r>n;++n)t=(t^=e.charCodeAt(n))+(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);return(t>>>0).toString(36)}function t(e,t){var n,r={};return o=>(n=r[o])?n:(n=t(o.replace(S,"$1").replace(g,"{")),r[o]=n=e||isNaN(n[0])?n:"_"+n)}function n(){}function r(e){void 0===e&&(e={});var{key:t="ui",nonce:n,stylisPlugins:r,prefix:a=1,batchInserts:i,speedy:s,container:c=("undefined"!=typeof document?document.head:void 0)}=e,f=new m({prefix:a}),d=new Set,l=new Map,v=new Map,h=o({key:t,container:c,nonce:n,speedy:s,batchInserts:i});if("undefined"!=typeof document){for(var p,y,S=document.querySelectorAll('style[data-cache="'+t+'"]'),g=0,b=d.add.bind(d);g<S.length;g++)null!==(p=(y=S[g]).getAttribute("data-dash"))&&(p.split(" ").forEach(b),c&&y.parentNode!==c&&c.appendChild(y));f.use(r)(u)}var k=function(e,t,n,r){d.has(e)||(d.add(e),w.x=void 0===r?h:r,f(t,n))};return"undefined"==typeof document&&(k=function(e,t,n,r){d.has(e)||(d.add(e),w.x=void 0===r?h:r,l.set(e,f(t,n)))}),{key:t,sheet:h,sheets:{add(e){var t=v.get(e)||{n:0,s:o(h)};return v.set(e,t),t.n++,t.s},delete(e){var t=v.get(e);return t?(1===t.n&&(v.delete(e),t.s.flush()),--t.n):-1},keys:v.keys.bind(v)},stylis:f,insert:k,inserted:d,cache:l}}function o(e){function t(e){return e!==c}var{key:n,container:r,nonce:o,batchInserts:a,speedy:s}=e,u=null,c=null,f=0;if("undefined"!=typeof document)if(f="CSSStyleSheet"in window&&"replace"in CSSStyleSheet.prototype&&"adoptedStyleSheets"in Document.prototype)c=new CSSStyleSheet,document.adoptedStyleSheets=[...document.adoptedStyleSheets,c];else if((u=document.createElement("style")).setAttribute("data-dash",n),o&&u.setAttribute("nonce",o),null==r||r.appendChild(u),!(c=u.sheet))for(var{styleSheets:d}=document,l=0;l<d.length;l++)if(d[l].ownerNode===u){c=d[l];break}return{key:n,nonce:o,container:r,speedy:s,insert(e){var t=()=>{try{c.insertRule(e,c.cssRules.length)}catch(e){}};a?(k.push(t),i()):t()},flush(){u&&u.parentNode?u.parentNode.removeChild(u):f&&(document.adoptedStyleSheets=document.adoptedStyleSheets.filter(t))}}}function a(){for(var e;e=k.shift();)e();b=0,k.length&&i()}function i(){b||(b=1,requestAnimationFrame(a))}function s(e){e&&w.x.insert(e+"}")}function u(e,t,n,r,o,a,i,u,c,f){if(2===e){if(0===u)return t+"/*|*/"}else{if(3===e)return 102===u||112===u?(w.x.insert(n[0]+t),""):t+(0===f?"/*|*/":"");-2===e&&t.split("/*|*/}").forEach(s)}}function c(e){return e()}function f(o){void 0===o&&(o={});var a=o.dash||r(),{key:i,insert:s,sheets:u}=a,f={},p={},y=t(i,o.hash||e),m={variants(e){function t(){var e=n.apply(null,arguments);if(!e)return"";var t=y(e),r=i+"-"+t;return s(t,"."+r,e),r}function n(){var e=arguments,t=e.length;if(1===t&&"object"!=typeof e[0])return a+(o[e[0]]||"");if(t>0){for(var n=a,r=0;t>r;r++){var i=e[r];if("object"!=typeof i)n+=o[i]||"";else if(null!==i)for(var s in i)i[s]&&(n+=o[s]||"")}return n}return a}var r,o={};for(r in e)o[r]=d(e[r],p);var a=o.default||"";return t.styles=e,t.css=n,t},one(){var e=d(l(arguments),p),t=y(e),n=i+"-"+t,r=function(r){return r||void 0===r?(s(t,"."+n,e),n):""};return r.css=function(t){return t||void 0===t?e:""},r},cls(){var e=d(l(arguments),p),t=y(e),n=i+"-"+t;return s(t,"."+n,e),n},lazy(e){function t(t){if(void 0===t)return"";var r="object"==typeof t?JSON.stringify(t):t,o=n.get(r);return void 0===o&&(o=d(e(t),p),n.set(r,o)),o}var n=new Map,r=function(e){var n=t(e);if(!n)return"";var r=y(n),o=i+"-"+r;return s(r,"."+o,n),o};return r.css=t,r},join(){var e="".concat(...Array.prototype.slice.call(arguments)),t=y(e),n=i+"-"+t;return s(t,"."+n,e),n},keyframes(){var e=d(l(arguments),p),t=y(e),n=i+"-"+t;return s(t,"","@keyframes "+n+"{"+e+"}",u.add(t)),n},insertGlobal(){var e=d(l(arguments),p);if(!e)return n;var t=y(e);return s(t,"",e,u.add(t)),function(){!u.delete(t)&&a.inserted.delete(t)}},insertTokens(e,t){void 0===t&&(t=":root");var{css:r,vars:a}=function e(t,n,r){void 0===r&&(r=[]);var o={},a="";for(var i in t){var s=t[i];if("object"==typeof s){var u=e(s,n,r.concat(i));o[i]=u.vars,a+=u.css}else{var c=v(r.length>0?r.join("-")+"-"+i:i).replace(C,"-");o[i]="var("+(c="--"+(1==n||n&&!n[c]?N(c):c))+")",a+=c+":"+s+";"}}return{vars:o,css:a}}(e,o.mangleTokens);return r?(h(p,a),m.insertGlobal(t+"{"+r+"}")):n},insertThemes(e){var t=[];for(var n in e)t.push(m.insertTokens(f[n]=void 0===f[n]?e[n]:h(f[n],e[n]),"."+m.theme(n)));return function(){t.forEach(c)}},theme:e=>i+"-"+e+"-theme",dash:a,hash:y,tokens:p};return Object.defineProperty(m,"tokens",{get:()=>p,configurable:0}),m.insertTokens(o.tokens||A),m.insertThemes(o.themes||A),m}function d(e,t){var n="function"==typeof e?e(t):e;return"object"==typeof n&&null!==n?function e(t){var n="";for(var r in t){var o=t[r];if("object"!=typeof o){var a=45===r.charCodeAt(1);n+=(a?r:v(r))+":"+("number"!=typeof o||y[r]||0===o||a?o:o+"px")+";"}else n+=r+"{"+e(o)+"}"}return n}(n):n||""}function l(e){var t=e[0];return Array.isArray(t)?t.reduce((t,n,r)=>t+n+(e[r+1]||""),""):t}function v(e){var t;return null!==(t=x[e])&&void 0!==t?t:x[e]=e.replace(j,"-$&").toLowerCase()}function h(e,t){for(var n in t){var r=t[n];e[n]="object"==typeof r?h(e[n]||{},r):r}return e}function p(e){return"var(--"+e.replace(/\./g,"-").replace(j,"-$&").toLowerCase()+")"}import y from"@dash-ui/unitless";import m from"@dash-ui/stylis";var S=/(^|[:;,{}\s])\s+|$/g,g=/ +{/g,b=0,k=[],w={x:{insert:n}},A={},j=/[A-Z]|^ms/g,C=/[^\w-]/g,x={},N=t("",e),T=f();export{d as compileStyles,r as createDash,f as createStyles,e as hash,p as pathToToken,o as styleSheet,T as styles};
//# sourceMappingURL=index.mjs.map