UNPKG

next-yak

Version:

next-yak is a CSS-in-JS solution tailored for Next.js that seamlessly combines the expressive power of styled-components syntax with efficient build-time extraction of CSS using Next.js's built-in CSS configuration

2 lines 2.92 kB
import{YakThemeProvider as e,useTheme as t,useTheme as n}from"next-yak/context";import r from"react";const i=Symbol(`yak`);function a(...e){let t,n=[];for(let r of e)typeof r==`string`?t=r:typeof r==`function`?n.push(r):typeof r==`object`&&`style`in r&&n.push((e,t,n)=>{for(let t in r.style){let i=r.style[t];typeof i==`function`?n[t]=String(s(e,i)):n[t]=String(i)}});return n.length===0?(e,n)=>(t&&n.add(t),()=>{}):(e,r,i)=>{t&&r.add(t);for(let t=0;t<n.length;t++)o(e,n[t],r,i)}}const o=(e,t,n,r)=>{let i=t(e,n,r);for(;i;){if(typeof i==`function`){i=i(e,n,r);continue}else if(typeof i==`object`&&(`className`in i&&i.className&&n.add(i.className),`style`in i&&i.style))for(let e in i.style)r[e]=i.style[e];break}},s=(e,t)=>{let n=t(e);if(typeof n==`function`)return s(e,n);if(process.env.NODE_ENV===`development`&&typeof n!=`string`&&typeof n!=`number`&&!(n instanceof String))throw Error(`Dynamic CSS functions must return a string or number but returned ${JSON.stringify(n)}\n\nDynamic CSS function: ${t.toString()}\n`);return n},c=(...e)=>{let t=[],n=[];for(let r of e)typeof r==`string`?t.push(...r.split(` `)):typeof r==`function`&&n.push(r);return a(...t.length>0?[(e,n)=>{t.forEach(e=>n.add(e))},...n]:n)},l=(e,...t)=>{if(Array.isArray(e)&&`raw`in e){let n=e[0];for(let r=0;r<t.length;r++){let i=t[r];n+=i&&typeof i==`object`&&`__yak`in i?i.__yak:String(i),n+=e[r+1]}return{__yak:n}}let n=[];for(let e of t)typeof e==`function`&&n.push(e);return n.length===0?{className:``,style:void 0}:(e=>{for(let t=0;t<n.length;t++)u(e,n[t]);return{className:``,style:void 0}})};function u(e,t){let n=new Set,r={},i=t(e,n,r);for(;typeof i==`function`;)i=i(e,n,r);return i}const d=(e,...t)=>``,f={},p=e=>Object.assign(m(e),{attrs:t=>m(e,t)}),m=(e,t)=>{let o=typeof e!=`string`&&i in e,[s,c,l]=o?e[i]:[],u=v(t,c);return(t,...c)=>{let d=a(t,...c),p=y(d,l),m=t=>{let i=u||d.length?n():f,a=`$__attrs`in t?{theme:i,...t}:_({theme:i,...t,$__attrs:!0},u?.({theme:i,...t})),c=new Set(`className`in a?a.className?.split(` `):[]),l={...`style`in a?a.style:{}};`$__runtimeStylesProcessed`in a||(p(a,c,l),a.$__runtimeStylesProcessed=!0),a.className=Array.from(c).join(` `)||void 0,a.style=l;let{theme:m,...g}=a,v=m===i?g:a,y=o?v:h(v);return s?s(y):r.createElement(e,y)};return Object.assign(m,{[i]:[m,u,p]})}},h=e=>{let t={};for(let n in e)!n.startsWith(`$`)&&e[n]!==void 0&&(t[n]=e[n]);return t},g=(e,t)=>{if(!(!e&&!t))return e?t?e+` `+t:e:t},_=(e,t)=>t?(e.className===t.className||!t.className)&&(e.style===t.style||!t.style)?{...e,...t}:{...e,...t,className:g(e.className,t.className),style:{...e.style,...t.style}}:e,v=(e,t)=>{let n=e&&(typeof e==`function`?e:()=>e);return n&&t?e=>{let r=t(e);return _(r,n(_(e,r)))}:n||t},y=(e,t)=>e&&t?(n,r,i)=>{t(n,r,i),e(n,r,i)}:e||t,b=new Proxy(p,{get(e,t){return e(t)}});export{e as YakThemeProvider,c as atoms,l as css,d as keyframes,b as styled,t as useTheme}; //# sourceMappingURL=index.js.map