UNPKG

stoop

Version:

CSS-in-JS library with type inference, theme creation, and variants support.

14 lines (13 loc) 21.4 kB
import{createContext as C4}from"react";import{createContext as W4}from"react";var YJ=Object.freeze({}),PJ=1e4,XJ=5000,GJ=10,NJ=W4(null),QJ=["colors","opacities","space","radii","sizes","fonts","fontWeights","fontSizes","letterSpacings","shadows","zIndices","transitions"],a={accentColor:"colors",animation:"transitions",animationDelay:"transitions",animationDuration:"transitions",animationTimingFunction:"transitions",backdropFilter:"shadows",background:"colors",backgroundColor:"colors",blockSize:"sizes",border:"colors",borderBlockColor:"colors",borderBlockEndColor:"colors",borderBlockStartColor:"colors",borderBottomColor:"colors",borderBottomLeftRadius:"radii",borderBottomRightRadius:"radii",borderColor:"colors",borderEndEndRadius:"radii",borderEndStartRadius:"radii",borderInlineColor:"colors",borderInlineEndColor:"colors",borderInlineStartColor:"colors",borderLeftColor:"colors",borderRadius:"radii",borderRightColor:"colors",borderStartEndRadius:"radii",borderStartStartRadius:"radii",borderTopColor:"colors",borderTopLeftRadius:"radii",borderTopRightRadius:"radii",bottom:"space",boxShadow:"shadows",caretColor:"colors",color:"colors",columnGap:"space",columnRuleColor:"colors",fill:"colors",filter:"shadows",flexBasis:"sizes",floodColor:"colors",font:"fontSizes",fontFamily:"fonts",fontSize:"fontSizes",fontWeight:"fontWeights",gap:"space",gridColumnGap:"space",gridGap:"space",gridRowGap:"space",height:"sizes",inlineSize:"sizes",inset:"space",insetBlock:"space",insetBlockEnd:"space",insetBlockStart:"space",insetInline:"space",insetInlineEnd:"space",insetInlineStart:"space",left:"space",letterSpacing:"letterSpacings",lightingColor:"colors",margin:"space",marginBlock:"space",marginBlockEnd:"space",marginBlockStart:"space",marginBottom:"space",marginInline:"space",marginInlineEnd:"space",marginInlineStart:"space",marginLeft:"space",marginRight:"space",marginTop:"space",maxBlockSize:"sizes",maxHeight:"sizes",maxInlineSize:"sizes",maxWidth:"sizes",minBlockSize:"sizes",minHeight:"sizes",minInlineSize:"sizes",minWidth:"sizes",opacity:"opacities",outline:"colors",outlineColor:"colors",padding:"space",paddingBlock:"space",paddingBlockEnd:"space",paddingBlockStart:"space",paddingBottom:"space",paddingInline:"space",paddingInlineEnd:"space",paddingInlineStart:"space",paddingLeft:"space",paddingRight:"space",paddingTop:"space",right:"space",rowGap:"space",size:"sizes",stopColor:"colors",stroke:"colors",textDecorationColor:"colors",textEmphasisColor:"colors",textShadow:"shadows",top:"space",transition:"transitions",transitionDelay:"transitions",transitionDuration:"transitions",transitionProperty:"transitions",transitionTimingFunction:"transitions",width:"sizes",zIndex:"zIndices"},t=Symbol.for("stoop.component");function BJ(J){if(!J||typeof J!=="object"||Array.isArray(J))throw new Error("[Stoop] Theme must be a non-null object");let $=J,Z=[];for(let X in $){if(X==="media")continue;if(!QJ.includes(X))Z.push(X)}if(Z.length>0){let X=`[Stoop] Theme contains invalid scales: ${Z.join(", ")}. Only these scales are allowed: ${QJ.join(", ")}`;if(typeof process!=="undefined"&&process.env?.NODE_ENV!=="production")throw new Error(X);console.warn(X)}return J}function C(J){return typeof J==="object"&&J!==null}function D4(J){return typeof J==="object"&&J!==null&&"__isStoopStyled"in J&&"__stoopClassName"in J&&J.__isStoopStyled===!0}function wJ(J){return C(J)&&!D4(J)}function o(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}function xJ(J){return function $(Z){let X=BJ(Z);function q(Y,Q){let G={...Y},W=Object.keys(Q);for(let B of W){let D=Q[B],H=Y[B];if(o(D)&&o(H))G[B]={...H,...D};else if(D!==void 0)G[B]=D}let F=Object.keys(Y);for(let B of F)if(!(B in G))G[B]=Y[B];return G}return q(J,X)}}var gJ=new Map;class UJ extends Map{maxSize;constructor(J){super();this.maxSize=J}get(J){let $=super.get(J);if($!==void 0)super.delete(J),super.set(J,$);return $}set(J,$){if(super.has(J))super.delete(J);else if(this.size>=this.maxSize){let Z=this.keys().next().value;if(Z!==void 0)super.delete(Z)}return super.set(J,$),this}}var p=new UJ(XJ),e=new UJ(XJ);function bJ(J){return gJ.has(J)}function vJ(J){gJ.set(J,J)}function TJ(){if(p.size>XJ){let J=p.keys().next().value;if(J)p.delete(J),e.delete(J)}}function FJ(J){let $=0;for(let Z=0;Z<J.length;Z++){let X=J.charCodeAt(Z);$=($<<5)-$+X,$=$&$}return Math.abs($).toString(36)}function WJ(J){try{return FJ(JSON.stringify(J))}catch{return FJ(String(J))}}function H4(J){return J.replace(/([A-Z])/g,"-$1").toLowerCase()}function h(J){return String(J).replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/'/g,"\\'").replace(/;/g,"\\;").replace(/\n/g,"\\A ").replace(/\r/g,"").replace(/\f/g,"\\C ")}function P(J){let $=J.replace(/[^a-zA-Z0-9\s\-_>+~:.#[\]&@()]/g,"");if(!$.trim()||/^[>+~:.#[\]&@()\s]+$/.test($))return"";return $}function f(J){return J.replace(/[^a-zA-Z0-9-_]/g,"-").replace(/^[\d-]+/,"").replace(/^-+/,"")||"invalid"}function kJ(J){return String(J).replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/'/g,"\\'").replace(/;/g,"\\;").replace(/\n/g,"\\A ").replace(/\r/g,"").replace(/\f/g,"\\C ").replace(/\{/g,"\\7B ").replace(/\}/g,"\\7D ")}function M(J){if(!J)return"";return J.replace(/[^a-zA-Z0-9-_]/g,"").replace(/^[\d-]+/,"").replace(/^-+/,"")||""}function CJ(J){if(!J)return"";return J.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function DJ(J){if(!J||typeof J!=="string")return"";let $=J.replace(/[^a-zA-Z0-9\s():,<>=\-@]/g,"");if(!$.trim()||!/[a-zA-Z]/.test($))return"";return $}function fJ(J){if(!J||typeof J!=="string")return"";let $=J.trim().split(/\s+/),Z=[];for(let X of $){if(!X)continue;let Y=X.replace(/[^a-zA-Z0-9-_]/g,"").replace(/^\d+/,"");if(Y&&/^[a-zA-Z-_]/.test(Y))Z.push(Y)}return Z.join(" ")}function c(J){if(!J||typeof J!=="string")return"";return H4(J).replace(/[^a-zA-Z0-9-]/g,"").replace(/^-+|-+$/g,"").replace(/^\d+/,"")||""}function SJ(J){if(!J||typeof J!=="string")return!1;if(J==="from"||J==="to")return!0;if(/^\d+(\.\d+)?%$/.test(J)){let Z=parseFloat(J);return Z>=0&&Z<=100}return!1}function L4(J){if(J.includes("Color")||J==="fill"||J==="stroke"||J==="accentColor"||J==="caretColor"||J==="border"||J==="outline"||J.includes("background")&&!J.includes("Size")&&!J.includes("Image"))return"colors";if(/^(margin|padding|gap|inset|top|right|bottom|left|rowGap|columnGap|gridGap|gridRowGap|gridColumnGap)/.test(J)||J.includes("Block")||J.includes("Inline"))return"space";if(/(width|height|size|basis)$/i.test(J)||J.includes("BlockSize")||J.includes("InlineSize"))return"sizes";if(J==="fontSize"||J==="font"&&!J.includes("Family"))return"fontSizes";if(J==="fontFamily"||J.includes("FontFamily"))return"fonts";if(J==="fontWeight"||J.includes("FontWeight"))return"fontWeights";if(J==="letterSpacing"||J.includes("LetterSpacing"))return"letterSpacings";if(J.includes("Radius")||J.includes("radius"))return"radii";if(J.includes("Shadow")||J.includes("shadow")||J==="filter"||J==="backdropFilter")return"shadows";if(J==="zIndex"||J.includes("ZIndex")||J.includes("z-index"))return"zIndices";if(J==="opacity"||J.includes("Opacity"))return"opacities";if(J.startsWith("transition")||J.startsWith("animation")||J.includes("Transition")||J.includes("Animation"))return"transitions";return}function dJ(J,$){if($&&J in $)return $[J];if(J in a)return a[J];return L4(J)}var yJ=new WeakMap;function w4(J){let $=yJ.get(J);if($)return $;let Z=new Map;function X(q,Y=[]){let Q=Object.keys(q).sort();for(let G of Q){let W=q[G],F=[...Y,G];if(o(W))X(W,F);else{let B=Z.get(G);if(B)B.push(F);else Z.set(G,[F])}}}X(J);for(let[q,Y]of Z.entries())if(Y.length>1){if(Y.sort((Q,G)=>{let W=Q.length-G.length;if(W!==0)return W;let F=Q.join("."),B=G.join(".");return F.localeCompare(B)}),typeof process!=="undefined"&&process.env?.NODE_ENV!=="production")console.warn(`[Stoop] Ambiguous token "$${q}" found in multiple categories: ${Y.map((Q)=>Q.join(".")).join(", ")}. Using "${Y[0].join(".")}" (deterministic: shorter paths first, then alphabetical). Use full path "$${Y[0].join(".")}" to be explicit.`)}return yJ.set(J,Z),Z}function U4(J,$){let Z=Object.keys(J).filter((q)=>q!=="media"),X=Object.keys($).filter((q)=>q!=="media");if(Z.length!==X.length)return!1;for(let q of Z)if(!(q in $))return!1;return!0}function uJ(J,$){if(J===$)return!0;if(!J||!$)return!1;if(!U4(J,$))return!1;let Z={...J},X={...$};return delete Z.media,delete X.media,JSON.stringify(Z)===JSON.stringify(X)}function RJ(J,$,Z){if(Z&&Z in J){let Y=J[Z];if(Y&&typeof Y==="object"&&!Array.isArray(Y)&&$ in Y)return[Z,$]}let q=w4(J).get($);if(!q||q.length===0)return null;return q[0]}function R4(J,$,Z,X){if(!J.startsWith("$"))return J;let q=J.slice(1);if(q.includes("$")||q.includes("."))return`var(${`--${(q.includes("$")?q.split("$"):q.split(".")).map((B)=>f(B)).join("-")}`})`;if($&&Z){let G=dJ(Z,X);if(G){let F=RJ($,q,G);if(F)return`var(${`--${F.map((H)=>f(H)).join("-")}`})`}let W=RJ($,q);if(W)return`var(${`--${W.map((D)=>f(D)).join("-")}`})`}else if($){let G=RJ($,q);if(G)return`var(${`--${G.map((B)=>f(B)).join("-")}`})`}return`var(${`--${f(q)}`})`}function n(J,$=""){let Z=CJ($),X=Z?`:root[data-stoop="${Z}"]`:":root",q=[];function Y(Q,G=[]){let W=Object.keys(Q).sort();for(let F of W){if(F==="media")continue;let B=Q[F],D=[...G,F];if(o(B))Y(B,D);else{let L=`--${D.map((R)=>f(R)).join("-")}`,O=typeof B==="string"||typeof B==="number"?kJ(B):String(B);q.push(` ${L}: ${O};`)}}}if(Y(J),q.length===0)return"";return`${X} { ${q.join(` `)} }`}function S(J,$,Z,X){if(!J||typeof J!=="object")return J;let q={};for(let Y in J){let Q=J[Y];if(C(Q))q[Y]=S(Q,$,Z,X);else if(typeof Q==="string"&&Q.includes("$")){let G=X||Y;q[Y]=Q.replace(/(calc\()?(-?)(\$[a-zA-Z][a-zA-Z0-9]*(?:\$[a-zA-Z][a-zA-Z0-9]*)?(?:\.[a-zA-Z][a-zA-Z0-9]*)?)/g,(W,F,B,D,H,L)=>{let O=R4(D,$,G,Z),R=L.slice(Math.max(0,H-10),H),A=R.includes("calc(")&&!R.includes(")");if(B==="-"){if(A||F==="calc(")return`${F||""}-${O}`;return`calc(-1 * ${O})`}if(F==="calc(")return`${F}${O}`;return O})}else q[Y]=Q}return q}var AJ=new Map;function g(J){return AJ.has(J)}function N(J,$){AJ.set(J,$)}function HJ(){return new Map(AJ)}var m=[];function JJ(J){if(m.includes(J))return;if(m.length>=PJ)m.shift();m.push(J)}function IJ(){return m.join(` `)}function pJ(J){return m.includes(J)}var U=null,_J=new Map,cJ=new Map,A4=new Map,l=new Map,d=null;if(typeof document!=="undefined")(function J(){if(!U)U=document.createElement("style"),U.setAttribute("data-stoop","stoop"),document.head.appendChild(U)})();function nJ(){if(l.size===0||!U||!U.parentNode){d=null;return}let J=Array.from(l.values()).join(` `);if(!J){l.clear(),d=null;return}let{sheet:$}=U;if($&&$.insertRule&&!J.includes("@")&&!J.includes("&"))try{let X=J.split(/(?<=})\s*(?=\S)/),q=!0;for(let Y of X){let Q=Y.trim();if(Q)try{$.insertRule(Q,$.cssRules.length)}catch{q=!1;break}}if(q){l.clear(),d=null;return}}catch{}let Z=U.textContent||"";U.textContent=Z+(Z?` `:"")+J,l.clear(),d=null}function I4(J,$){if(l.set($,J),!d&&typeof requestAnimationFrame!=="undefined")d=requestAnimationFrame(nJ);else if(!d)nJ()}function KJ(J=""){if(typeof document==="undefined")throw new Error("Cannot access document in SSR context");let $=M(J);if(U){if(U.parentNode)return U;if(U.textContent)try{return document.head.appendChild(U),U}catch{}U=null}return U=document.createElement("style"),U.setAttribute("data-stoop",$||"stoop"),document.head.appendChild(U),U}function OJ(J,$,Z=""){if(!J)return;let X=M(Z),q=`__theme_vars_${X}`;if((cJ.get(q)??null)===J){if((_J.get(q)??null)!==$)_J.set(q,$);return}if(_J.set(q,$),cJ.set(q,J),typeof document==="undefined"){JJ(J);return}let Q=KJ(X),G=Q.textContent||"";if(g(q)){let W=X?`:root[data-stoop="${X}"]`:":root",F=new RegExp(`${W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*\\{[\\s\\S]*?\\}`,"g"),B=G.replace(F,"").trim();Q.textContent=J+(B?` `+B:""),N(q,J)}else Q.textContent=J+(G?` `+G:""),N(q,J)}function mJ(J,$=""){let Z=M($);if(A4.set(Z,J),typeof document!=="undefined"){KJ(Z);let X=n(J,Z);OJ(X,J,Z)}}function _4(J,$,Z=""){if(typeof document==="undefined")return;let X=M(Z);if(U&&U.parentNode){let q=U.textContent||"",Y=J.replace(/\s+/g," ").trim();if(q.replace(/\s+/g," ").trim().includes(Y)){if(!g($))N($,J);return}}try{let q=KJ(X),Y=q.textContent||"",Q=J.replace(/\s+/g," ").trim();if(Y.replace(/\s+/g," ").trim().includes(Q)){if(!g($))N($,J);return}if(!Y){let W=HJ();if(W.size>0){let F=Array.from(W.entries()).filter(([B])=>!B.startsWith("__theme_vars_")&&B!==$).map(([,B])=>B).join(` `);q.textContent=F+(F?` `:"")+J}else q.textContent=J}else I4(J,$);if(!g($))N($,J)}catch{if(!g($))N($,J)}if(!pJ(J))JJ(J)}function lJ(J,$,Z=""){if(g($))return;if(N($,J),bJ(J))return;vJ(J);let X=M(Z);if(U&&U.parentNode)try{let q=U.textContent||"",Y=J.replace(/\s+/g," ").trim();if(q.replace(/\s+/g," ").trim().includes(Y))return}catch{}_4(J,$,X)}function iJ(){return U}function T(J,$="",Z){let X=Z||J;if(typeof document==="undefined"){if(!g(X))N(X,J);JJ(J);return}lJ(J,X,$)}function rJ(J,$,Z=""){OJ(J,$,Z)}function sJ(J,$=""){mJ(J,$)}function aJ(){if(typeof document!=="undefined"){let J=iJ();if(J&&J.parentNode){let $=J.textContent||"";if(!$&&HJ().size>0)return IJ();return $}}return IJ()}function $J(J,$){if(!$||!J||typeof J!=="object")return J;let Z={},X=Object.keys($);for(let q in J){let Y=J[q];if(X.includes(q)&&$[q])try{let Q=$[q](Y);if(Q&&typeof Q==="object")Object.assign(Z,Q)}catch{Z[q]=Y}else if(C(Y))Z[q]=$J(Y,$);else Z[q]=Y}return Z}function O4(J,$){if(typeof J==="symbol"&&J===t)return!0;if(typeof $==="object"&&$!==null&&t in $)return!0;if(typeof J==="string"&&J.startsWith("__STOOP_COMPONENT_"))return!0;return!1}function E4(J,$){if(typeof $==="object"&&$!==null&&"__stoopClassName"in $&&typeof $.__stoopClassName==="string")return $.__stoopClassName;if(typeof J==="string"&&J.startsWith("__STOOP_COMPONENT_"))return J.replace("__STOOP_COMPONENT_","");return""}function x(J,$="",Z=0,X){if(!J||typeof J!=="object")return"";if(Z>GJ)return"";let q="",Y="";for(let G in J){let W=J[G];if(O4(G,W)){let F=E4(G,W);if(!F)continue;let B=P(F);if(!B)continue;let D=`.${B}`,H=wJ(W)?x(W,D,Z+1,X):"";Y+=H;continue}if(wJ(W))if(X&&G in X){let F=DJ(X[G]);if(F){let B=x(W,$,Z+1,X);Y+=`${F} { ${B} }`}}else if(G.startsWith("@")){let F=P(G);if(F){let B=x(W,$,Z+1,X);Y+=`${F} { ${B} }`}}else if(G.includes("&")){let F=P(G);if(F){let B=F.replace(/&/g,$),D=x(W,B,Z+1,X);Y+=D}}else if(G.startsWith(":")){let F=P(G);if(F){let B=`${$}${F}`,D=x(W,B,Z+1,X);Y+=D}}else if(G.includes(" ")||G.includes(">")||G.includes("+")||G.includes("~")){let F=P(G);if(F){let B=`${$} ${F}`,D=x(W,B,Z+1,X);Y+=D}}else{let F=P(G);if(F){let B=$?`${$} ${F}`:F,D=x(W,B,Z+1,X);Y+=D}}else if(W!==void 0){let F=c(G);if(F&&(typeof W==="string"||typeof W==="number")){let B=h(W);q+=`${F}: ${B}; `}}}return(q?`${$} { ${q.trim()}}`:"")+Y}function y(J,$,Z="",X,q,Y){let Q=M(Z),G=$J(J,q),W=S(G,$,Y),F=x(W,"",0,X),B=FJ(F),D=`${Q}:${B}`,H=p.get(D);if(H){let R=e.get(D);if(R)return T(R,Q,D),H;let A=x(W,`.${H}`,0,X);return e.set(D,A),T(A,Q,D),H}let L=Q?`${Q}-${B}`:`css-${B}`,O=x(W,`.${L}`,0,X);return p.set(D,L),e.set(D,O),TJ(),T(O,Q,D),L}function tJ(J,$="",Z,X,q){return function Y(Q){return y(Q,J,$,Z,X,q)}}function eJ(J,$="",Z,X,q){let Y=new Set;return function Q(G){if(typeof document==="undefined")return()=>{};let W=WJ(G);if(Y.has(W))return()=>{};Y.add(W);function F(O,R=0){if(R>GJ)return"";let A="";return Object.entries(O).forEach(([z,_])=>{if(C(_))if(Z&&z in Z){let K=DJ(Z[z]);if(K){let w=F(_,R+1);A+=`${K} { ${w} }`}}else if(z.startsWith("@")){let K=P(z);if(K){let w=F(_,R+1);A+=`${K} { ${w} }`}}else{let K=P(z);if(K){let w=F(_,R+1);A+=`${K} { ${w} }`}}else if(_!==void 0){let K=c(z);if(K&&(typeof _==="string"||typeof _==="number")){let w=h(_);A+=`${K}: ${w}; `}}}),A}let B=M($),D=$J(G,X),H=S(D,J,q),L=F(H);return T(L,B,`__global_${W}`),()=>{Y.delete(W)}}}function M4(J,$,Z,X){let q=`@keyframes ${$} {`,Y=Object.keys(J).sort((Q,G)=>{let W=parseFloat(Q.replace("%","")),F=parseFloat(G.replace("%",""));if(Q==="from")return-1;if(G==="from")return 1;if(Q==="to")return 1;if(G==="to")return-1;return W-F});for(let Q of Y){if(!SJ(Q))continue;let G=J[Q];if(!G||typeof G!=="object")continue;q+=` ${Q} {`;let W=S(G,Z,X);for(let F in W){let B=W[F];if(B!==void 0&&(typeof B==="string"||typeof B==="number")){let D=c(F);if(D){let H=h(B);q+=` ${D}: ${H};`}}}q+=" }"}return q+=" }",q}function J4(J="",$,Z){let X=M(J),q=new Map;return function Y(Q){let G=WJ(Q),W=q.get(G);if(W)return W;let F=G.slice(0,8),B=X?`${X}-${F}`:`stoop-${F}`,D=M4(Q,B,$,Z),H=`__keyframes_${B}`;return T(D,X,H),q.set(G,B),B}}import{createContext as V4,useCallback as EJ,useLayoutEffect as q4,useMemo as MJ,useState as P4}from"react";var $4=new Map;function Z4(J,$=""){let Z=$||"";$4.set(Z,J)}function z4(J=""){let $=J||"";return $4.get($)||null}function j4(J,$=""){let Z=z4($);if(!Z)return J;if(uJ(J,Z))return J;let X={...Z},q=Object.keys(J);for(let Y of q){if(Y==="media")continue;let Q=J[Y],G=Z[Y];if(Q&&typeof Q==="object"&&!Array.isArray(Q)&&G&&typeof G==="object"&&!Array.isArray(G))X[Y]={...G,...Q};else if(Q!==void 0)X[Y]=Q}return X}function LJ(J,$=""){if(typeof document==="undefined")return;let Z=j4(J,$),X=n(Z,$);rJ(X,Z,$)}import{jsxDEV as Y4}from"react/jsx-dev-runtime";function X4(J,$,Z,X=""){let q=V4(null),Y=Object.keys($),Q=Y[0]||"default";function G({attribute:W="data-theme",children:F,defaultTheme:B,storageKey:D="stoop-theme"}){let H=EJ(()=>{if(typeof window==="undefined")return B||Q;try{let w=localStorage.getItem(D);if(w&&$[w])return w}catch{}return B||Q},[B,D]),[L,O]=P4(H),R=MJ(()=>{return $[L]||$[B||Q]||Z},[L,B]);q4(()=>{if(R)LJ(R,X)},[R]),q4(()=>{if(typeof document!=="undefined"&&W)document.documentElement.setAttribute(W,L)},[L,W]);let A=EJ((w)=>{if($[w]){O(w);try{localStorage.setItem(D,w)}catch{}}else if(typeof process!=="undefined"&&process.env?.NODE_ENV!=="production")console.warn(`[Stoop] Theme "${w}" not found. Available themes: ${Y.join(", ")}`)},[D]),z=MJ(()=>({theme:R,themeName:L}),[R,L]),_=EJ(()=>{let V=(Y.indexOf(L)+1)%Y.length,k=Y[V];A(k)},[L,A]),K=MJ(()=>({availableThemes:Y,setTheme:A,theme:R,themeName:L,toggleTheme:_}),[R,L,A,_]);return Y4(J.Provider,{value:z,children:Y4(q.Provider,{value:K,children:F},void 0,!1,void 0,this)},void 0,!1,void 0,this)}return{Provider:G,ThemeManagementContext:q}}import{useMemo as zJ,forwardRef as N4,createElement as x4,useContext as g4}from"react";function G4(J,$,Z){let X=!1,q=[];for(let Y in J){let Q=$[Y];if(Q===void 0)continue;let G=J[Y],W=Q===!0?"true":Q===!1?"false":String(Q);if(G[W])q.push(G[W]),X=!0}return X?Object.assign({},Z,...q):Z}function b4(J){return{__isStoopStyled:!0,__stoopClassName:J,[t]:J,toString:()=>`__STOOP_COMPONENT_${J}`}}function v4(J){return typeof J==="object"&&J!==null&&"__isStoopStyled"in J&&J.__isStoopStyled===!0}function T4(J,$){if(!$)return{elementProps:J,variantProps:{}};let Z=new Set(Object.keys($)),X={},q={};for(let Y in J)if(Z.has(Y))X[Y]=J[Y];else q[Y]=J[Y];return{elementProps:q,variantProps:X}}function Q4(J,$="",Z,X,q,Y){return function Q(G,W,F){let B=W||YJ,D=F;if(W&&"variants"in W&&typeof W.variants==="object"){D=W.variants;let{compoundVariants:A,variants:z,..._}=W;B=_}let H=y(B,J,$,Z,X,q),L;if(typeof G!=="string"&&v4(G))L=G.__stoopClassName;let R=N4(function A(z,_){let{as:K,className:w,css:V,...k}=z,I=K||G,E=V&&typeof V==="object"&&V!==null?V:YJ,{elementProps:b,variantProps:v}=T4(k,D),i=g4(Y||NJ)?.theme||J,qJ=i.media||Z,r=zJ(()=>{if(!D)return"";let j=Object.entries(v);if(j.length===0)return"";return j.sort(([u],[s])=>u.localeCompare(s)).map(([u,s])=>`${u}:${String(s)}`).join("|")},[D,...Object.values(v)]),jJ=zJ(()=>{let j=B;if(D&&r)j=G4(D,v,B);if(E!==YJ)j=Object.assign({},j,E);return j},[r,E]),F4=zJ(()=>{let j=[];if(L)j.push(L);let u=y(jJ,i,$,qJ,X,q);if(u)j.push(u);if(w){let s=typeof w==="string"?w:String(w),VJ=fJ(s);if(VJ)j.push(VJ)}return j.length>0?j.join(" "):void 0},[jJ,i,$,qJ,X,q,w,L]);return x4(I,{...b,className:F4,ref:_})});return R.selector=b4(H),R}}import{useContext as k4}from"react";function B4(J){return function $(){let Z=k4(J);if(!Z)throw new Error("useTheme must be used within a Provider");return Z}}function f4(J){let{media:$,prefix:Z="",theme:X,themeMap:q,utils:Y}=J,Q=M(Z),G=BJ(X),W=G.media||$,F={...a,...q},B=C4(null);Z4(G,Q),sJ(G,Q);let D=tJ(G,Q,W,Y,F),H=xJ(G),L=eJ(G,Q,W,Y,F),O=J4(Q,G,F),R=Q4(G,Q,W,Y,F,B),A=Object.freeze({...G});function z(I){for(let E of I)try{y(E,G,Q,W,Y,F)}catch{}}function _(I){let E;if(typeof I==="string")if(J.themes&&J.themes[I])E=J.themes[I];else{if(typeof process!=="undefined"&&process.env?.NODE_ENV!=="production")console.warn(`[Stoop] Theme "${I}" not found. Available themes: ${J.themes?Object.keys(J.themes).join(", "):"none"}`);return}else E=I;LJ(E,Q)}function K(I){let E=G;if(I)if(typeof I==="string"){if(J.themes&&J.themes[I])E=J.themes[I];else if(typeof process!=="undefined"&&process.env?.NODE_ENV!=="production")console.warn(`[Stoop] Theme "${I}" not found. Using default theme. Available: ${J.themes?Object.keys(J.themes).join(", "):"none"}`)}else E=I;let b="",v=n(E,Q);if(v)b+=v+` `;let ZJ=aJ(),i=Q?`:root[data-stoop="${Q}"]`:":root",qJ=new RegExp(`${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*\\{[^}]*\\}`,"g"),r=ZJ.replace(qJ,"").trim();if(r)b+=(b?` `:"")+r;return b}let w,V;if(J.themes){let I={};for(let[v,ZJ]of Object.entries(J.themes))I[v]=H(ZJ);let{Provider:E,ThemeManagementContext:b}=X4(B,I,G,Q);w=E,V=B4(b)}let k={config:{...J,prefix:Q},createTheme:H,css:D,getCssText:K,globalCss:L,keyframes:O,preloadTheme:_,styled:R,theme:A,warmCache:z};if(w)k.Provider=w;if(V)k.useTheme=V;return k}export{f4 as createStoop};