UNPKG

otion

Version:

Atomic CSS-in-JS with a featherweight runtime

4 lines (3 loc) 4.26 kB
/// <reference types="./bundle.prod.min.d.ts" /> function e(e){for(var t,n=0,r=0,s=e.length;s>=4;++r,s-=4)t=1540483477*(65535&(t=255&e.charCodeAt(r)|(255&e.charCodeAt(++r))<<8|(255&e.charCodeAt(++r))<<16|(255&e.charCodeAt(++r))<<24))+(59797*(t>>>16)<<16),n=1540483477*(65535&(t^=t>>>24))+(59797*(t>>>16)<<16)^1540483477*(65535&n)+(59797*(n>>>16)<<16);switch(s){case 3:n^=(255&e.charCodeAt(r+2))<<16;case 2:n^=(255&e.charCodeAt(r+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(r)))+(59797*(n>>>16)<<16)}return(((n=1540483477*(65535&(n^=n>>>13))+(59797*(n>>>16)<<16))^n>>>15)>>>0).toString(36)}var t=/^(br|hy|us|wr|text-si|scroll-snap-t)/,n=/^(ap|us|tab-|border-e|margin-e|margin-s|padding-e|padding-s|border-sta)/,r=/^(ap|br|hy|us|wr|mas|colu|clip-|box-de|font-k|text-e|font-fe|shape-i|text-or|text-si|border-e|margin-e|margin-s|padding-e|padding-s|border-sta|background-cl|scroll-snap-t|text-decoration-)/,s=/^(pos|background-cl)/,o={};const c="undefined"!=typeof document;function i(){let e=document.getElementById("__otion");return e||(e=document.createElement("style"),e.id="__otion",document.head.appendChild(e))}function a({nonce:e,target:t=i().sheet}){return t.ownerNode.nonce=e,{sheet:t,insert(e,n){try{return t.insertRule(e,n)}catch{return-1}}}}function l({nonce:e,target:t=i()}){return t.nonce=e,{sheet:t.sheet,insert:(e,n)=>(t.insertBefore(document.createTextNode(e),t.childNodes[n]),n)}}const u={insert:()=>0};function f(e){return e.trim().replace(/\s+/g," ")}const d=/^(-|f[lo].*?[^se]$|g.{6,}[^ps]$|z|o[pr]|(-w.{6})?li.*?(t|mp)$|an|(bo|s).{5}im|sca|m.{7}[ds]|ta|c.*?[st]$|wido|ini)/,p=/^(?:(border-(?!w|c|sty)|[tlbr].{2,4}m?$|c.{7}$)|([fl].{5}l|g.{8}$|pl))/,h=new Map([["nk",1],["sited",2],["pty",3],["cus-w",4],["ver",5],["cus",6],["cus-v",7],["tive",8],["sable",9]]);function m(e,t,n){let r=0;if(!("-"===e[1])){const t="-"===e[0]?e.slice(e.indexOf("-",1))+1:e,n=p.exec(t);r=(n?+!!n[1]||-!!n[2]:0)+1;let s=1;for(;s=t.indexOf("-",s)+1;)++r}return r*=2*(t&&h.get(t.slice(3,8))||10),r+=+n,r}function g(e){return"-"+e.toLowerCase()}function y(){let i,l,p,h;function y(e){for(let t=e;t<=72;++t)++h[t]}function b(e,t){if(1===e.type){const{selectorText:n,style:r}=e,[,s,o]=/^..([0-9a-z]+)(:.*)?/.exec(n),c=r[0];c&&y(m(c,o,!!t)),p.set(s,p.size)}else b(e.cssRules[0],!0)}function $(e,t){const n="number"!=typeof t||d.test(e)?f(""+t):t+"px";return l(e,n)}function x(e,t){if("object"!=typeof t)return $(e,t);let n="";return t.forEach(t=>{t&&(n+=";"+$(e,t))}),n.slice(1)}function w(t,n,r,s,o){let c="";for(var a in t){const l=t[a];if(null!=l)if("object"!=typeof l||Array.isArray(l)){const t=a.replace(/^ms|[A-Z]/g,g),u=x(t,l),f="_"+e(n+u),d=r;let b=p.get(f);if(null==b||d){const e=m(t,null==o?"":n.slice(o),!!d);if(null==b||s[e]>b){const t="."+f;i.insert(`${n.slice(0,o)+t+(null!=o?n.slice(o).replace(/&/g,t)+"{":"{")}${u}}${r}`,h[e]),y(e),b=p.size,p.set(f,b),d&&(s[e]=Math.max(s[e],b))}}c+=" "+f}else{let e,t=":"===a[0]||"@"===a[0]||"&"===a[0]?a:f(a).replace(/([([]) | ([)\]])| ?(:) ?/g,"$1$2$3"),i="",u=o;null==u&&(":"===t[0]||"&"===t[0]?(u=n.length,e=t.split(/,(?![^[]*?[^\\]["']\s*?\])/).map(e=>f(e).replace("&",""))):"selectors"===t?t="":"@"!==t[0]&&(t+="{",i="}")),(e||[t]).forEach(e=>{c+=w(l,n+e,i+r,s,u)})}}return c}return{setup(e){i=e.injector||(c?a({}):u),l=e.prefix||((e,c)=>{const i=`${e}:${function(e,t){return s.test(e)?t.replace(/(sticky|text)/,"-webkit-$1, $1"):t}(e,c)}`;let a=i;const l=function(e){return o[e]?o[e]:o[e]=1*t.test(e)|2*n.test(e)|4*r.test(e)}(e);return 1&l&&(a+=";-ms-"+i),2&l&&(a+=";-moz-"+i),4&l&&(a+=";-webkit-"+i),a}),p=new Map,h=new Uint16Array(72)},hydrate(){const{cssRules:e}=i.sheet;for(let t=0,{length:n}=e;t<n;++t){const n=e[t];7===n.type?p.set(n.name,p.size):b(n)}},css:e=>w(e,"","",new Uint16Array(72)).slice(1),keyframes(t){let n;return{toString(){if(!n){let o="";for(var r in t){o+=r+"{";const e=t[r];for(var s in e){const t=e[s];null!=t&&(o+=x(s,t))}o+="}"}n="_"+e(o),p.has(n)||(i.insert(`@keyframes ${n}{${o}}`,p.size),p.set(n,p.size))}return n}}}}}const b=y();b.setup({});const $=b.setup,x=b.hydrate,w=b.css,A=b.keyframes;export{a as CSSOMInjector,l as DOMInjector,u as NoOpInjector,y as createInstance,w as css,x as hydrate,A as keyframes,$ as setup}; //# sourceMappingURL=bundle.prod.min.mjs.map