stoop 0.5.4 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/api/styled.d.ts +13 -3
- package/dist/create-stoop.d.ts +0 -1
- package/dist/index.d.ts +6 -0
- package/dist/{create-stoop.js → index.js} +9 -9
- package/dist/types/index.d.ts +279 -39
- package/dist/types/index.js +2 -0
- package/package.json +6 -23
- package/dist/types/react-polymorphic-types.d.ts +0 -24
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ const Button = styled("button", {
|
|
|
62
62
|
- **Multiple themes** with built-in Provider
|
|
63
63
|
- **Utility functions** for custom CSS transformations
|
|
64
64
|
- **Zero runtime overhead** for theme switching
|
|
65
|
+
- **Zero dependencies** - only React peer dependency
|
|
65
66
|
|
|
66
67
|
## Documentation
|
|
67
68
|
|
package/dist/api/styled.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* and CSS prop merging. Supports component targeting via selector references.
|
|
5
5
|
*/
|
|
6
6
|
import { forwardRef, type Context } from "react";
|
|
7
|
-
import type { CSS,
|
|
7
|
+
import type { CSS, StyledComponentProps, StyledComponentRef, StylableElement, Theme, ThemeContextValue, ThemeScale, UtilityFunction, Variants } from "../types";
|
|
8
8
|
/**
|
|
9
9
|
* Creates a styled component reference for selector targeting.
|
|
10
10
|
*
|
|
@@ -25,10 +25,20 @@ export declare function createStyledComponentRef(className: string): StyledCompo
|
|
|
25
25
|
* @returns Styled component factory function
|
|
26
26
|
*/
|
|
27
27
|
export declare function createStyledFunction(defaultTheme: Theme, prefix?: string, media?: Record<string, string>, utils?: Record<string, UtilityFunction>, themeMap?: Record<string, ThemeScale>, themeContext?: Context<ThemeContextValue | null>): {
|
|
28
|
-
<DefaultElement extends StylableElement, BaseStyles extends
|
|
28
|
+
<DefaultElement extends StylableElement, BaseStyles extends CSS & {
|
|
29
|
+
variants: {
|
|
30
|
+
[Name in string]: {
|
|
31
|
+
[Pair in string]: CSS;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}>(defaultElement: DefaultElement, baseStyles: BaseStyles): ReturnType<typeof forwardRef<unknown, StyledComponentProps<DefaultElement, BaseStyles extends {
|
|
35
|
+
variants: infer V;
|
|
36
|
+
} ? (V extends Variants ? V : {}) : {}>>> & {
|
|
29
37
|
selector: StyledComponentRef;
|
|
30
38
|
};
|
|
31
|
-
<DefaultElement extends StylableElement>(defaultElement: DefaultElement, baseStyles?: CSS
|
|
39
|
+
<DefaultElement extends StylableElement>(defaultElement: DefaultElement, baseStyles?: CSS & {
|
|
40
|
+
variants?: never;
|
|
41
|
+
}): ReturnType<typeof forwardRef<unknown, StyledComponentProps<DefaultElement, {}>>> & {
|
|
32
42
|
selector: StyledComponentRef;
|
|
33
43
|
};
|
|
34
44
|
};
|
package/dist/create-stoop.d.ts
CHANGED
|
@@ -32,5 +32,4 @@ export declare function createStoopBase(config: StoopConfig): {
|
|
|
32
32
|
* @param config - Configuration object containing theme, media queries, utilities, and optional prefix/themeMap
|
|
33
33
|
* @returns StoopInstance with all API functions
|
|
34
34
|
*/
|
|
35
|
-
export type { CSS, Theme, StoopConfig, StoopInstance, UtilityFunction, ThemeScale, DefaultTheme, } from "./types";
|
|
36
35
|
export declare function createStoop(config: StoopConfig): StoopInstance;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for Stoop
|
|
3
|
+
* Re-exports createStoop and all types
|
|
4
|
+
*/
|
|
5
|
+
export { createStoop } from "./create-stoop";
|
|
6
|
+
export type { CSS, ComponentProps, DefaultTheme, StoopConfig, StoopInstance, Theme, ThemeScale, UtilityFunction, VariantProps, StyledComponent, StyledFunction, } from "./types";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var s=Object.freeze({}),a=1e4,kJ=5000,SJ=10,dJ=500,y=1000,uJ=31536000,yJ="/",
|
|
2
|
-
`)}var qJ=new Map;var eJ=new Map;function $0(J="stoop"){if(!
|
|
3
|
-
`+Q).trim()}else break;X=$.indexOf("[data-theme=")}return $.trim()}function q0(J,$="stoop"){if(!J)return;let q=z($),X=`__all_theme_vars_${q}`;if((eJ.get(X)??null)===J)return;if(eJ.set(X,J),!
|
|
1
|
+
var s=Object.freeze({}),a=1e4,kJ=5000,SJ=10,dJ=500,y=1000,uJ=31536000,yJ="/",FJ=["colors","opacities","space","radii","sizes","fonts","fontWeights","fontSizes","lineHeights","letterSpacings","shadows","zIndices","transitions"],m={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",lineHeight:"lineHeights",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");class j 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 q=this.keys().next().value;if(q!==void 0)super.delete(q)}return super.set(J,$),this}}var hJ=new j(kJ),HJ=new j(a);function I(){return typeof window!=="undefined"&&typeof document!=="undefined"&&typeof window.document==="object"&&typeof document.createElement==="function"}function h(){return typeof process!=="undefined"&&process.env?.NODE_ENV==="production"}function e(J){return typeof J==="object"&&J!==null}function o(J){return typeof J==="object"&&J!==null&&"__isStoopStyled"in J&&"__stoopClassName"in J&&J.__isStoopStyled===!0}function JJ(J){return e(J)&&!o(J)}function UJ(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}function $J(J){if(!J||typeof J!=="object"||Array.isArray(J))throw new Error("[Stoop] Theme must be a non-null object");if(h())return J;let $=J,q=[];for(let X in $){if(X==="media")continue;if(!FJ.includes(X))q.push(X)}if(q.length>0){let X=`[Stoop] Theme contains invalid scales: ${q.join(", ")}. Only these scales are allowed: ${FJ.join(", ")}`;throw new Error(X)}return J}function S(J,$){if(!$||!J||typeof J!=="object")return J;let q=Object.keys($),X=!1;for(let Z in J)if(q.includes(Z)){X=!0;break}if(!X)return J;let Y={};for(let Z in J){let G=J[Z];if(q.includes(Z)&&$[Z])try{let D=$[Z](G);if(D&&typeof D==="object")for(let Q in D)Y[Q]=D[Q]}catch{Y[Z]=G}else if(e(G))Y[Z]=S(G,$);else Y[Z]=G}return Y}var LJ=null,cJ=new j(y),nJ=new j(y),pJ=new j(y);function d(J){if(J.length===0)return"0";let $=2166136261,q=16777619,X=$;for(let Y=0;Y<J.length;Y++)X^=J.charCodeAt(Y),X=Math.imul(X,q);return X^=J.length,(X>>>0).toString(36)}function wJ(J){try{return d(JSON.stringify(J))}catch{return d(String(J))}}function mJ(J,$=!1){let X=String(J).replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/'/g,"\\'").replace(/;/g,"\\;").replace(/\n/g,"\\A ").replace(/\r/g,"").replace(/\f/g,"\\C ");if($)X=X.replace(/\{/g,"\\7B ").replace(/\}/g,"\\7D ");return X}function BJ(J){return mJ(J,!1)}function C(J){let $=cJ.get(J);if($!==void 0)return $;let q=J.replace(/[^a-zA-Z0-9\s\-_>+~:.#[\]&@(),]/g,""),X=!q.trim()||/^[>+~:.#[\]&@()\s]+$/.test(q)?"":q;return cJ.set(J,X),X}function T(J){let $=pJ.get(J);if($!==void 0)return $;let Y=J.replace(/[^a-zA-Z0-9-_]/g,"-").replace(/^[\d-]+/,"").replace(/^-+/,"")||"invalid";return pJ.set(J,Y),Y}function oJ(J){return mJ(J,!0)}function z(J){if(!J)return"stoop";return J.replace(/[^a-zA-Z0-9-_]/g,"").replace(/^[\d-]+/,"").replace(/^-+/,"")||"stoop"}function iJ(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 lJ(J){if(!J||typeof J!=="string")return"";let $=nJ.get(J);if($!==void 0)return $;let q=J.trim().split(/\s+/),X=[];for(let Z of q){if(!Z)continue;let D=Z.replace(/[^a-zA-Z0-9-_]/g,"").replace(/^\d+/,"");if(D&&/^[a-zA-Z-_]/.test(D))X.push(D)}let Y=X.join(" ");return nJ.set(J,Y),Y}function rJ(J){if(!J||typeof J!=="string")return!1;if(J==="from"||J==="to")return!0;if(/^\d+(\.\d+)?%$/.test(J)){let q=parseFloat(J);return q>=0&&q<=100}return!1}function sJ(J=""){if(!LJ){let q=":root".replace(/[.*+?^${}()|[\]\\]/g,"\\$&");LJ=new RegExp(`${q}\\s*\\{[\\s\\S]*\\}`)}return LJ}function K0(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 aJ(J,$){if($&&J in $)return $[J];if(J in m)return m[J];return K0(J)}var _J=new Map;function YJ(J){return _J.has(J)}function XJ(J,$){_J.set(J,$)}var AJ=new j(a);function J0(J){if(!AJ.has(J))AJ.set(J,!0)}function tJ(){return Array.from(AJ.keys()).join(`
|
|
2
|
+
`)}var qJ=new Map;var eJ=new Map;function $0(J="stoop"){if(!I())throw new Error("Cannot access document in SSR context");let $=z(J),q=qJ.get($);if(!q||!q.parentNode){let X=document.getElementById("stoop-ssr");if(X){let Y=X.getAttribute("data-stoop");if(!Y||Y===$)return q=X,q.setAttribute("data-stoop",$),qJ.set($,q),q}q=document.createElement("style"),q.setAttribute("data-stoop",$),q.setAttribute("id",`stoop-${$}`),document.head.appendChild(q),qJ.set($,q)}return q}function IJ(J){let $=J,q=sJ("");$=$.replace(q,"").trim();let X=$.indexOf("[data-theme=");while(X!==-1){let Y=$.indexOf("{",X);if(Y===-1)break;let Z=1,G=Y+1;while(G<$.length&&Z>0){if($[G]==="{")Z++;else if($[G]==="}")Z--;G++}if(Z===0){let D=$.substring(0,X).trim(),Q=$.substring(G).trim();$=(D+`
|
|
3
|
+
`+Q).trim()}else break;X=$.indexOf("[data-theme=")}return $.trim()}function q0(J,$="stoop"){if(!J)return;let q=z($),X=`__all_theme_vars_${q}`;if((eJ.get(X)??null)===J)return;if(eJ.set(X,J),!I()){J0(J);return}let Z=$0(q),G=Z.textContent||"",D=G.includes(":root")||G.includes("[data-theme=");if(YJ(X)||D){let Q=IJ(G);Z.textContent=J+(Q?`
|
|
4
4
|
|
|
5
5
|
`+Q:""),XJ(X,J)}else Z.textContent=J+(G?`
|
|
6
6
|
|
|
7
|
-
`+G:""),XJ(X,J)}function V0(J,$,q="stoop"){if(!
|
|
8
|
-
`:"")+J,XJ($,J)}function z0(J,$,q="stoop"){if(YJ($))return;let X=z(q);V0(J,$,X)}function P0(J="stoop"){let $=z(J);return qJ.get($)||null}function j0(){return new Map(_J)}function c(J,$="stoop",q){let X=q||J;if(!
|
|
7
|
+
`+G:""),XJ(X,J)}function V0(J,$,q="stoop"){if(!I())return;let X=z(q);if(YJ($))return;let Y=$0(X),Z=Y.textContent||"";Y.textContent=Z+(Z?`
|
|
8
|
+
`:"")+J,XJ($,J)}function z0(J,$,q="stoop"){if(YJ($))return;let X=z(q);V0(J,$,X)}function P0(J="stoop"){let $=z(J);return qJ.get($)||null}function j0(){return new Map(_J)}function c(J,$="stoop",q){let X=q||J;if(!I()){if(!YJ(X))XJ(X,J);J0(J);return}z0(J,X,$)}function X0(J="stoop"){if(I()){let $=z(J),q=P0($);if(q&&q.parentNode){let X=q.textContent||"";if(!X&&j0().size>0)return tJ();return X}}return tJ()}var x0=/(-?\$[a-zA-Z][a-zA-Z0-9]*(?:\$[a-zA-Z][a-zA-Z0-9]*)?(?:\.[a-zA-Z][a-zA-Z0-9]*)?)/g,Y0=new WeakMap;function OJ(J){let $=Y0.get(J);if($)return $;let q=new Map;function X(Y,Z=[]){let G=Object.keys(Y);for(let D of G){let Q=Y[D],W=[...Z,D];if(UJ(Q))X(Q,W);else{let F=q.get(D);if(F)F.push(W);else q.set(D,[W])}}}X(J);for(let[,Y]of q.entries())if(Y.length>1)Y.sort((Z,G)=>{let D=Z.length-G.length;if(D!==0)return D;let Q=Z.join("."),W=G.join(".");return Q.localeCompare(W)});return Y0.set(J,q),q}function N0(J,$){let q=Object.keys(J).filter((Y)=>Y!=="media"),X=Object.keys($).filter((Y)=>Y!=="media");if(q.length!==X.length)return!1;for(let Y of q)if(!(Y in $))return!1;return!0}function G0(J,$){if(J===$)return!0;if(!J||!$)return!1;if(!N0(J,$))return!1;let q={...J},X={...$};return delete q.media,delete X.media,JSON.stringify(q)===JSON.stringify(X)}function g0(J,$,q){if(q&&q in J){let Z=J[q];if(Z&&typeof Z==="object"&&!Array.isArray(Z)&&$ in Z)return[q,$]}let Y=OJ(J).get($);if(!Y||Y.length===0)return null;return Y[0]}function GJ(J,$,q,X){if(!J.startsWith("$"))return J;let Y=J.slice(1);if(Y.includes("$")||Y.includes("."))return`var(${`--${(Y.includes("$")?Y.split("$"):Y.split(".")).map((F)=>T(F)).join("-")}`})`;if($&&q){let D=aJ(q,X);if(D){let F=g0($,Y,D);if(F)return`var(${`--${F.map((L)=>T(L)).join("-")}`})`}let W=OJ($).get(Y);if(W&&W.length>1){if(!h()){let F=D?`Property "${q}" maps to "${D}" scale, but token not found there. `:`No scale mapping found for property "${q}". `;console.warn(`[Stoop] Ambiguous token "$${Y}" found in multiple categories: ${W.map((U)=>U.join(".")).join(", ")}. ${F}Using "${W[0].join(".")}" (deterministic: shorter paths first, then alphabetical). Use full path "$${W[0].join(".")}" to be explicit.`)}}if(W&&W.length>0){let[F]=W;return`var(${`--${F.map((L)=>T(L)).join("-")}`})`}}else if($){let Q=OJ($).get(Y);if(Q&&Q.length>1){if(!h())console.warn(`[Stoop] Ambiguous token "$${Y}" found in multiple categories: ${Q.map((W)=>W.join(".")).join(", ")}. Using "${Q[0].join(".")}" (deterministic: shorter paths first, then alphabetical). Use full path "$${Q[0].join(".")}" to be explicit, or use with a CSS property for automatic resolution.`)}if(Q&&Q.length>0){let[W]=Q;return`var(${`--${W.map((H)=>T(H)).join("-")}`})`}}return`var(${`--${T(Y)}`})`}function RJ(J,$="stoop",q){let X=q||":root",Y=[];function Z(G,D=[]){let Q=Object.keys(G).sort();for(let W of Q){if(W==="media")continue;let F=G[W],U=[...D,W];if(UJ(F))Z(F,U);else{let L=`--${U.map((w)=>T(w)).join("-")}`,_=typeof F==="string"||typeof F==="number"?oJ(F):String(F);Y.push(` ${L}: ${_};`)}}}if(Z(J),Y.length===0)return"";return`${X} {
|
|
9
9
|
${Y.join(`
|
|
10
10
|
`)}
|
|
11
11
|
}`}function QJ(J,$="stoop",q="data-theme"){let X=[];for(let[Y,Z]of Object.entries(J)){let G=`[${q}="${Y}"]`,D=RJ(Z,$,G);if(D)X.push(D)}return X.join(`
|
|
12
12
|
|
|
13
|
-
`)}function C(J,$,q,X){if(!J||typeof J!=="object")return J;let Y=Object.keys(J),Z=!1;for(let Q of Y){let W=J[Q];if(typeof W==="string"&&W.includes("$")){Z=!0;break}}if(!Z&&!$)return J;let G={},D=!1;for(let Q of Y){let W=J[Q];if(e(W)){let H=C(W,$,q,void 0);if(G[Q]=H,H!==W)D=!0}else if(typeof W==="string"&&W.includes("$")){D=!0;let H=X||Q;if(W.startsWith("$")&&!W.includes(" ")&&!W.includes("calc(")&&W===W.trim())if(W.startsWith("-$")){let U=W.slice(1);if(U.includes(".")||U.includes("$")){let L=U.includes("$")?U.split("$"):U.split("."),_=!1;for(let w=0;w<L.length;w++){let B=L[w];for(let I=0;I<B.length;I++){let A=B.charCodeAt(I);if(!(A>=48&&A<=57||A>=65&&A<=90||A>=97&&A<=122||A===45||A===95)){_=!0;break}}if(_)break}if(_){let B=`--${L.map((I)=>T(I)).join("-")}`;G[Q]=`calc(-1 * var(${B}))`}else{let w=`--${L.join("-")}`;G[Q]=`calc(-1 * var(${w}))`}}else{let L=GJ(U,$,H,q);G[Q]=`calc(-1 * ${L})`}}else{let U=W.slice(1);if(U.includes(".")||U.includes("$")){let L=U.includes("$")?U.split("$"):U.split("."),_=!1;for(let w=0;w<L.length;w++){let B=L[w];for(let I=0;I<B.length;I++){let A=B.charCodeAt(I);if(!(A>=48&&A<=57||A>=65&&A<=90||A>=97&&A<=122||A===45||A===95)){_=!0;break}}if(_)break}if(_){let B=`--${L.map((I)=>T(I)).join("-")}`;G[Q]=`var(${B})`}else{let w=`--${L.join("-")}`;G[Q]=`var(${w})`}}else G[Q]=GJ(W,$,H,q)}else G[Q]=W.replace(x0,(U)=>{if(U.startsWith("-$")){let L=U.slice(1);return`calc(-1 * ${GJ(L,$,H,q)})`}return GJ(U,$,H,q)})}else G[Q]=W}if(!D)return J;return G}var v=new j(y);function v0(J){return J.replace(/([A-Z])/g,"-$1").toLowerCase()}function T0(J){if(J===J.toUpperCase()&&J.length>1)return J.charAt(0)+J.slice(1).toLowerCase();return J}function ZJ(J){if(!J)return"";return J.charAt(0).toLowerCase()+J.slice(1).replace(/([A-Z])/g,"-$1").toLowerCase()}function i(J){if(!J||typeof J!=="string")return"";let $=v.get(J);if($!==void 0)return $;if(/^-[a-z]+-/.test(J))return v.set(J,J),J;let q=T0(J);if(/^[Mm]oz/i.test(q)){if(q.length===3||q.toLowerCase()==="moz")return v.set(J,"-moz"),"-moz";let G=q.match(/^[Mm]oz(.+)$/i);if(G&&G[1]){let[,D]=G,Q=ZJ(D);if(Q){let W=`-moz-${Q}`;return v.set(J,W),W}}}if(/^[Ww]ebkit/i.test(q)){if(q.length===6||q.toLowerCase()==="webkit")return v.set(J,"-webkit"),"-webkit";let G=q.match(/^[Ww]ebkit(.+)$/i);if(G&&G[1]){let[,D]=G,Q=ZJ(D);if(Q){let W=`-webkit-${Q}`;return v.set(J,W),W}}}if(/^[Mm]s/i.test(q)){if(q.length===2||q.toLowerCase()==="ms")return v.set(J,"-ms"),"-ms";let G=q.match(/^[Mm]s(.+)$/i);if(G&&G[1]){let[,D]=G,Q=ZJ(D);if(Q){let W=`-ms-${Q}`;return v.set(J,W),W}}}if(/^O/i.test(q)){if(q.length===1||q.toLowerCase()==="o")return v.set(J,"-o"),"-o";if(/^O[A-Z]/.test(q)){let G=q.substring(1),D=ZJ(G);if(D){let Q=`-o-${D}`;return v.set(J,Q),Q}}}let Z=v0(q).replace(/[^a-zA-Z0-9-]/g,"").replace(/^-+|-+$/g,"").replace(/^\d+/,"")||"";return v.set(J,Z),Z}var f0=new Set(["width","height","min-width","min-height","max-width","max-height","top","right","bottom","left","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","border-width","border-top-width","border-right-width","border-bottom-width","border-left-width","border-radius","border-top-left-radius","border-top-right-radius","border-bottom-left-radius","border-bottom-right-radius","font-size","letter-spacing","word-spacing","text-indent","flex-basis","gap","row-gap","column-gap","grid-template-rows","grid-template-columns","grid-auto-rows","grid-auto-columns","perspective","outline-width","outline-offset","clip","vertical-align","object-position","background-position","background-size","mask-position","mask-size","scroll-margin","scroll-padding","shape-margin"]);function Q0(J){return f0.has(J)}function Z0(J,$){if(typeof $==="string"){if(Q0(J)&&/^-?\d+\.?\d*$/.test($.trim()))return`${$}px`;return $}if(typeof $==="number"&&Q0(J))return`${$}px`;return String($)}function D0(J,$){if(typeof J==="symbol"&&J===t)return!0;if(o($))return!0;if(typeof J==="string"&&J.startsWith("__STOOP_COMPONENT_"))return!0;return!1}function b0(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 K(J,$="",q=0,X){if(!J||typeof J!=="object")return"";if(q>SJ)return"";let Y=[],Z=[],G=$===""?Object.keys(J).sort():Object.keys(J);for(let Q of G){let W=J[Q];if(D0(Q,W)){let H=b0(Q,W);if(!H)continue;let F=b(H);if(!F)continue;let U=$?`${$} .${F}`:`.${F}`,L=JJ(W)?K(W,U,q+1,X):"";if(L)Z.push(L);continue}if(JJ(W))if(X&&Q in X){let H=iJ(X[Q]);if(H){let F=K(W,$,q+1,X);if(F)Z.push(`${H} { ${F} }`)}}else if(Q.startsWith("@")){let H=b(Q);if(H){let F=K(W,$,q+1,X);if(F)Z.push(`${H} { ${F} }`)}}else if(Q.includes("&")){let H=b(Q);if(H){let F=H.split("&");if($.includes(",")){let _=$.split(",").map((B)=>B.trim()).map((B)=>F.join(B)).join(", "),w=K(W,_,q+1,X);if(w)Z.push(w)}else{let U=F.join($),L=K(W,U,q+1,X);if(L)Z.push(L)}}}else if(Q.startsWith(":")){let H=b(Q);if(H){let F=`${$}${H}`,U=K(W,F,q+1,X);if(U)Z.push(U)}}else if(Q.includes(",")){let F=Q.split(",").map((U)=>U.trim()).map((U)=>b(U)).filter((U)=>U);if(F.length>0){let U=F.join(", "),L=K(W,U,q+1,X);if(L)Z.push(L)}}else if(Q.includes(" ")||Q.includes(">")||Q.includes("+")||Q.includes("~")){let H=b(Q);if(H){let U=/^[\s>+~]/.test(H.trim())?`${$}${H}`:`${$} ${H}`,L=K(W,U,q+1,X);if(L)Z.push(L)}}else{let H=b(Q);if(H){let F=$?`${$} ${H}`:H,U=K(W,F,q+1,X);if(U)Z.push(U)}}else if(W!==void 0){let H=i(Q);if(H&&(typeof W==="string"||typeof W==="number")){let F=Z0(H,W);if(H==="content"&&F==="")Y.push(`${H}: "";`);else{let U=BJ(F);Y.push(`${H}: ${U};`)}}}}let D=[];if(Y.length>0)D.push(`${$} { ${Y.join(" ")} }`);return D.push(...Z),D.join("")}function C0(J,$){if(!J||typeof J!=="object")return"";let q=[],X=Object.keys(J).sort();for(let Y of X){let Z=J[Y];if(JJ(Z))return"";if($&&Y in $)return"";if(Y.startsWith("@")||Y.includes("&")||Y.startsWith(":")||Y.includes(" ")||Y.includes(">")||Y.includes("+")||Y.includes("~"))return"";if(Z!==void 0&&!D0(Y,Z)){let G=i(Y);if(G&&(typeof Z==="string"||typeof Z==="number")){let D=Z0(G,Z);if(G==="content"&&D==="")q.push(`${G}: "";`);else{let Q=BJ(D);q.push(`${G}: ${Q};`)}}}}return q.join(" ")}function n(J,$,q="stoop",X,Y,Z){let G=z(q),D=S(J,Y),Q=C(D,$,Z),W=C0(Q,X),H,F;if(W)H=W,F=d(H);else H=K(Q,"",0,X),F=d(H);let U=G?`${G}-${F}`:`css-${F}`,L=`${G}:${U}`,_=UJ.get(L);if(_)return c(_,G,L),U;let w;if(W)w=`.${U} { ${W} }`;else w=K(Q,`.${U}`,0,X);return UJ.set(L,w),hJ.set(L,U),c(w,G,L),U}var W0=new Map;function H0(J,$="stoop"){let q=$||"";W0.set(q,J)}function k0(J="stoop"){let $=J||"";return W0.get($)||null}function MJ(J,$){let q={...J},X=Object.keys($);for(let Y of X){if(Y==="media")continue;let Z=$[Y],G=J[Y];if(Z&&typeof Z==="object"&&!Array.isArray(Z)&&G&&typeof G==="object"&&!Array.isArray(G))q[Y]={...G,...Z};else if(Z!==void 0)q[Y]=Z}return q}function EJ(J,$="stoop"){let q=k0($);if(!q)return J;if(G0(J,q))return J;return MJ(q,J)}function DJ(J,$="stoop",q="data-theme"){if(!O())return;let X={};for(let[Z,G]of Object.entries(J))X[Z]=EJ(G,$);let Y=QJ(X,$,q);q0(Y,$)}function U0(J){return function $(q={}){let X=$J(q);return MJ(J,X)}}function F0(J,$="stoop",q,X,Y){return function Z(G){return n(G,J,$,q,X,Y)}}function S0(J,$,q,X){let Y=`@keyframes ${$} {`,Z=Object.keys(J).sort((G,D)=>{let Q=parseFloat(G.replace("%","")),W=parseFloat(D.replace("%",""));if(G==="from")return-1;if(D==="from")return 1;if(G==="to")return 1;if(D==="to")return-1;return Q-W});for(let G of Z){if(!rJ(G))continue;let D=J[G];if(!D||typeof D!=="object")continue;Y+=` ${G} {`;let Q=C(D,q,X),W=Object.keys(Q).sort();for(let H of W){let F=Q[H];if(F!==void 0&&(typeof F==="string"||typeof F==="number")){let U=i(H);if(U){let L=String(F);Y+=` ${U}: ${L};`}}}Y+=" }"}return Y+=" }",Y}function L0(J="stoop",$,q){let X=z(J),Y=new j(dJ);return function Z(G){let D=wJ(G),Q=Y.get(D);if(Q)return Q;let W=D.slice(0,8),H=X?`${X}-${W}`:`stoop-${W}`,F=S0(G,H,$,q),U=`__keyframes_${H}`;return c(F,X,U),Y.set(D,H),H}}var KJ=new Set;function w0(J,$="stoop",q,X,Y){return function Z(G){let D=wJ(G);if(KJ.has(D))return()=>{};KJ.add(D);let Q=z($),W=S(G,X),H=C(W,J,Y),F=K(H,"",0,q);return c(F,Q,`__global_${D}`),()=>{KJ.delete(D)}}}import{useMemo as WJ,forwardRef as d0,createElement as u0,useContext as y0,createContext as h0}from"react";function c0(J,$,q){let X=[];for(let Z in J){let G=$[Z];if(G===void 0)continue;let D=J[Z],Q=G===!0?"true":G===!1?"false":String(G);if(D[Q])X.push(D[Q])}if(X.length===0)return q;if(X.length===1)return{...q,...X[0]};let Y={...X[0]};for(let Z=1;Z<X.length;Z++)Object.assign(Y,X[Z]);return{...q,...Y}}var VJ=null;function n0(){if(!VJ)VJ=h0(null);return VJ}function p0(J){return{__isStoopStyled:!0,__stoopClassName:J,[t]:J,toString:()=>`__STOOP_COMPONENT_${J}`}}function m0(J){return o(J)}var o0=new Set(["alignContent","alignItems","alignSelf","animation","animationDelay","animationDirection","animationDuration","animationFillMode","animationIterationCount","animationName","animationPlayState","animationTimingFunction","aspectRatio","backdropFilter","backfaceVisibility","background","backgroundAttachment","backgroundBlendMode","backgroundClip","backgroundColor","backgroundImage","backgroundOrigin","backgroundPosition","backgroundRepeat","backgroundSize","border","borderBottom","borderBottomColor","borderBottomLeftRadius","borderBottomRightRadius","borderBottomStyle","borderBottomWidth","borderCollapse","borderColor","borderImage","borderImageOutset","borderImageRepeat","borderImageSlice","borderImageSource","borderImageWidth","borderLeft","borderLeftColor","borderLeftStyle","borderLeftWidth","borderRadius","borderRight","borderRightColor","borderRightStyle","borderRightWidth","borderSpacing","borderStyle","borderTop","borderTopColor","borderTopLeftRadius","borderTopRightRadius","borderTopStyle","borderTopWidth","borderWidth","bottom","boxShadow","boxSizing","captionSide","caretColor","clear","clip","clipPath","color","columnCount","columnFill","columnGap","columnRule","columnRuleColor","columnRuleStyle","columnRuleWidth","columnSpan","columnWidth","columns","content","counterIncrement","counterReset","cursor","direction","display","emptyCells","filter","flex","flexBasis","flexDirection","flexFlow","flexGrow","flexShrink","flexWrap","float","font","fontFamily","fontFeatureSettings","fontKerning","fontLanguageOverride","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontSynthesis","fontVariant","fontVariantAlternates","fontVariantCaps","fontVariantEastAsian","fontVariantLigatures","fontVariantNumeric","fontVariantPosition","fontWeight","gap","grid","gridArea","gridAutoColumns","gridAutoFlow","gridAutoRows","gridColumn","gridColumnEnd","gridColumnGap","gridColumnStart","gridGap","gridRow","gridRowEnd","gridRowGap","gridRowStart","gridTemplate","gridTemplateAreas","gridTemplateColumns","gridTemplateRows","height","hyphens","imageOrientation","imageRendering","imageResolution","imeMode","inlineSize","isolation","justifyContent","justifyItems","justifySelf","left","letterSpacing","lineHeight","listStyle","listStyleImage","listStylePosition","listStyleType","margin","marginBottom","marginLeft","marginRight","marginTop","maxHeight","maxWidth","minHeight","minWidth","objectFit","objectPosition","opacity","order","orphans","outline","outlineColor","outlineOffset","outlineStyle","outlineWidth","overflow","overflowWrap","overflowX","overflowY","padding","paddingBottom","paddingLeft","paddingRight","paddingTop","pageBreakAfter","pageBreakBefore","pageBreakInside","perspective","perspectiveOrigin","placeContent","placeItems","placeSelf","pointerEvents","position","quotes","resize","right","rowGap","scrollBehavior","tabSize","tableLayout","textAlign","textAlignLast","textDecoration","textDecorationColor","textDecorationLine","textDecorationStyle","textIndent","textJustify","textOverflow","textShadow","textTransform","textUnderlinePosition","top","transform","transformOrigin","transformStyle","transition","transitionDelay","transitionDuration","transitionProperty","transitionTimingFunction","unicodeBidi","userSelect","verticalAlign","visibility","whiteSpace","width","wordBreak","wordSpacing","wordWrap","writingMode","zIndex"]);function i0(J){return o0.has(J)}function l0(J,$){let q=$?new Set(Object.keys($)):new Set,X={},Y={},Z={};for(let G in J)if(q.has(G))X[G]=J[G];else if(i0(G))Y[G]=J[G];else Z[G]=J[G];return{cssProps:Y,elementProps:Z,variantProps:X}}function B0(J,$="stoop",q,X,Y,Z){return function G(D,Q){let W=Q||s,H;if(Q&&"variants"in Q&&typeof Q.variants==="object"&&Q.variants!==null&&!Array.isArray(Q.variants)){let B=Q.variants;if(Object.keys(B).length>0&&Object.values(B).every((A)=>typeof A==="object"&&A!==null&&!Array.isArray(A))){H=Q.variants;let{variants:A,...R}=Q;W=R}}let F;if(typeof D!=="string"&&m0(D))F=D.__stoopClassName;let U=d0(function B(I,A){let{as:R,className:x,css:N,...V}=I,f=R||D,g=WJ(()=>N&&typeof N==="object"&&N!==null?N:s,[N]),{cssProps:k,elementProps:M,variantProps:P}=l0(V,H),r=y0(Z||n0())?.theme||J,TJ=r.media?{...q,...r.media}:q,fJ=WJ(()=>{if(!H)return"";let E=Object.entries(P);if(E.length===0)return"";return E.sort(([u],[p])=>u.localeCompare(p)).map(([u,p])=>`${u}:${String(p)}`).join("|")},[P]),bJ=WJ(()=>{let E=W;if(H&&fJ)E=c0(H,P,W);if(Object.keys(k).length>0)E=Object.assign({},E,k);if(g!==s)E=Object.assign({},E,g);return E},[fJ,g,k,W,H,P]),E0=WJ(()=>{let E=[];if(F)E.push(F);let u=n(bJ,r,$,TJ,X,Y);if(u)E.push(u);if(x){let p=typeof x==="string"?x:String(x),CJ=lJ(p);if(CJ)E.push(CJ)}return E.length>0?E.join(" "):void 0},[bJ,x,F,r,$,TJ,X,Y]);return u0(f,{...M,className:E0,ref:A})}),L=d(JSON.stringify(W)),_=`${$}-${L}`,w=U;return w.selector=p0(_),w}}import{createContext as _0,useCallback as O0,useContext as r0,useLayoutEffect as l,useMemo as xJ,useRef as NJ,useState as s0}from"react";function zJ(J){if(!O())return{error:"Not in browser environment",success:!1,value:null};try{return{source:"localStorage",success:!0,value:localStorage.getItem(J)}}catch($){return{error:$ instanceof Error?$.message:"localStorage access failed",success:!1,value:null}}}function PJ(J,$){if(!O())return{error:"Not in browser environment",success:!1,value:void 0};try{return localStorage.setItem(J,$),{success:!0,value:void 0}}catch(q){return{error:q instanceof Error?q.message:"localStorage write failed",success:!1,value:void 0}}}function jJ(J){if(!O())return null;let q=`; ${document.cookie}`.split(`; ${J}=`);if(q.length===2)return q.pop()?.split(";").shift()||null;return null}function A0(J,$,q={}){if(!O())return!1;let{maxAge:X=uJ,path:Y=yJ,secure:Z=!1}=q;try{return document.cookie=`${J}=${$}; path=${Y}; max-age=${X}${Z?"; secure":""}`,!0}catch{return!1}}import{jsx as I0}from"react/jsx-runtime";function gJ(J,$,q){if(!O())return;let X=$?jJ($):null,Y=zJ(q),Z=Y.success?Y.value:null;if(X===J&&Z!==J)PJ(q,J);if(Z===J&&$&&X!==J)A0($,J)}function a0(J,$,q){if(!O())return null;if(J!==void 0){let Z=jJ(J);if(Z&&q[Z])return Z}let X=zJ($),Y=X.success?X.value:null;if(Y&&q[Y])return Y;return null}function R0(J,$,q="stoop",X,Y){let Z=_0(null),G=_0(null),D=Object.keys(J),Q=D[0]||"default",W=X&&Y?Y(X):void 0;function H({attribute:F="data-theme",children:U,cookieKey:L,defaultTheme:_,storageKey:w="stoop-theme"}){let[B,I]=s0(_||Q),A=NJ(!1);l(()=>{if(!O()||A.current)return;let M=a0(L,w,J);if(M){if(gJ(M,L,w),M!==B)I(M)}A.current=!0},[L,w,J]),l(()=>{if(!O())return;let M=(P)=>{if(P.key===w&&P.newValue&&J[P.newValue]&&P.newValue!==B)I(P.newValue),gJ(P.newValue,L,w)};return window.addEventListener("storage",M),()=>{window.removeEventListener("storage",M)}},[w,L,B,J]);let R=xJ(()=>{return J[B]||J[_||Q]||$},[B,_,Q,J,$]),x=NJ(!1),N=NJ(!1);l(()=>{if(!O()||x.current)return;DJ(J,q,F),x.current=!0},[J,q,F]),l(()=>{if(!O()||N.current)return;if(W)W(),N.current=!0},[W]),l(()=>{if(!O())return;if(F)document.documentElement.setAttribute(F,B)},[B,F]);let V=O0((M)=>{if(J[M])I(M),PJ(w,M),gJ(M,L,w);else if(!h())console.warn(`[Stoop] Theme "${M}" not found. Available themes: ${D.join(", ")}`)},[w,L,J,D,B]),f=xJ(()=>({theme:R,themeName:B}),[R,B]),g=O0(()=>{let P=(D.indexOf(B)+1)%D.length,vJ=D[P];V(vJ)},[B,V,D]),k=xJ(()=>({availableThemes:D,setTheme:V,theme:R,themeName:B,toggleTheme:g}),[R,B,V,g]);return I0(Z.Provider,{value:f,children:I0(G.Provider,{value:k,children:U})})}return{Provider:H,ThemeContext:Z,ThemeManagementContext:G}}function M0(J){return function $(){let q=r0(J);if(!q)throw new Error("useTheme must be used within a Provider");return q}}function t0(J){let{globalCss:$,media:q,prefix:X="stoop",theme:Y,themeMap:Z,utils:G}=J,D=z(X),Q=$J(Y),W=Q.media||q,H={...m,...Z};H0(Q,D);let F=F0(Q,D,W,G,H),U=U0(Q),L=w0(Q,D,W,G,H),_=L0(D,Q,H),w=Object.freeze({...Q});function B(R){for(let x of R)try{n(x,Q,D,W,G,H)}catch{}}function I(){if(!J.themes||Object.keys(J.themes).length===0)return;DJ(J.themes,D)}function A(){let R="";if(J.themes&&Object.keys(J.themes).length>0){let V={};for(let[g,k]of Object.entries(J.themes))V[g]=EJ(k,D);let f=QJ(V,D,"data-theme");if(f)R+=f+`
|
|
13
|
+
`)}function b(J,$,q,X){if(!J||typeof J!=="object")return J;let Y=Object.keys(J),Z=!1;for(let Q of Y){let W=J[Q];if(typeof W==="string"&&W.includes("$")){Z=!0;break}}if(!Z&&!$)return J;let G={},D=!1;for(let Q of Y){let W=J[Q];if(e(W)){let F=b(W,$,q,void 0);if(G[Q]=F,F!==W)D=!0}else if(typeof W==="string"&&W.includes("$")){D=!0;let F=X||Q;if(W.startsWith("$")&&!W.includes(" ")&&!W.includes("calc(")&&W===W.trim())if(W.startsWith("-$")){let H=W.slice(1);if(H.includes(".")||H.includes("$")){let L=H.includes("$")?H.split("$"):H.split("."),_=!1;for(let w=0;w<L.length;w++){let B=L[w];for(let O=0;O<B.length;O++){let A=B.charCodeAt(O);if(!(A>=48&&A<=57||A>=65&&A<=90||A>=97&&A<=122||A===45||A===95)){_=!0;break}}if(_)break}if(_){let B=`--${L.map((O)=>T(O)).join("-")}`;G[Q]=`calc(-1 * var(${B}))`}else{let w=`--${L.join("-")}`;G[Q]=`calc(-1 * var(${w}))`}}else{let L=GJ(H,$,F,q);G[Q]=`calc(-1 * ${L})`}}else{let H=W.slice(1);if(H.includes(".")||H.includes("$")){let L=H.includes("$")?H.split("$"):H.split("."),_=!1;for(let w=0;w<L.length;w++){let B=L[w];for(let O=0;O<B.length;O++){let A=B.charCodeAt(O);if(!(A>=48&&A<=57||A>=65&&A<=90||A>=97&&A<=122||A===45||A===95)){_=!0;break}}if(_)break}if(_){let B=`--${L.map((O)=>T(O)).join("-")}`;G[Q]=`var(${B})`}else{let w=`--${L.join("-")}`;G[Q]=`var(${w})`}}else G[Q]=GJ(W,$,F,q)}else G[Q]=W.replace(x0,(H)=>{if(H.startsWith("-$")){let L=H.slice(1);return`calc(-1 * ${GJ(L,$,F,q)})`}return GJ(H,$,F,q)})}else G[Q]=W}if(!D)return J;return G}var v=new j(y);function v0(J){return J.replace(/([A-Z])/g,"-$1").toLowerCase()}function T0(J){if(J===J.toUpperCase()&&J.length>1)return J.charAt(0)+J.slice(1).toLowerCase();return J}function ZJ(J){if(!J)return"";return J.charAt(0).toLowerCase()+J.slice(1).replace(/([A-Z])/g,"-$1").toLowerCase()}function i(J){if(!J||typeof J!=="string")return"";let $=v.get(J);if($!==void 0)return $;if(/^-[a-z]+-/.test(J))return v.set(J,J),J;let q=T0(J);if(/^[Mm]oz/i.test(q)){if(q.length===3||q.toLowerCase()==="moz")return v.set(J,"-moz"),"-moz";let G=q.match(/^[Mm]oz(.+)$/i);if(G&&G[1]){let[,D]=G,Q=ZJ(D);if(Q){let W=`-moz-${Q}`;return v.set(J,W),W}}}if(/^[Ww]ebkit/i.test(q)){if(q.length===6||q.toLowerCase()==="webkit")return v.set(J,"-webkit"),"-webkit";let G=q.match(/^[Ww]ebkit(.+)$/i);if(G&&G[1]){let[,D]=G,Q=ZJ(D);if(Q){let W=`-webkit-${Q}`;return v.set(J,W),W}}}if(/^[Mm]s/i.test(q)){if(q.length===2||q.toLowerCase()==="ms")return v.set(J,"-ms"),"-ms";let G=q.match(/^[Mm]s(.+)$/i);if(G&&G[1]){let[,D]=G,Q=ZJ(D);if(Q){let W=`-ms-${Q}`;return v.set(J,W),W}}}if(/^O/i.test(q)){if(q.length===1||q.toLowerCase()==="o")return v.set(J,"-o"),"-o";if(/^O[A-Z]/.test(q)){let G=q.substring(1),D=ZJ(G);if(D){let Q=`-o-${D}`;return v.set(J,Q),Q}}}let Z=v0(q).replace(/[^a-zA-Z0-9-]/g,"").replace(/^-+|-+$/g,"").replace(/^\d+/,"")||"";return v.set(J,Z),Z}var f0=new Set(["width","height","min-width","min-height","max-width","max-height","top","right","bottom","left","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","border-width","border-top-width","border-right-width","border-bottom-width","border-left-width","border-radius","border-top-left-radius","border-top-right-radius","border-bottom-left-radius","border-bottom-right-radius","font-size","letter-spacing","word-spacing","text-indent","flex-basis","gap","row-gap","column-gap","grid-template-rows","grid-template-columns","grid-auto-rows","grid-auto-columns","perspective","outline-width","outline-offset","clip","vertical-align","object-position","background-position","background-size","mask-position","mask-size","scroll-margin","scroll-padding","shape-margin"]);function Q0(J){return f0.has(J)}function Z0(J,$){if(typeof $==="string"){if(Q0(J)&&/^-?\d+\.?\d*$/.test($.trim()))return`${$}px`;return $}if(typeof $==="number"&&Q0(J))return`${$}px`;return String($)}function D0(J,$){if(typeof J==="symbol"&&J===t)return!0;if(o($))return!0;if(typeof J==="string"&&J.startsWith("__STOOP_COMPONENT_"))return!0;return!1}function C0(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 K(J,$="",q=0,X){if(!J||typeof J!=="object")return"";if(q>SJ)return"";let Y=[],Z=[],G=$===""?Object.keys(J).sort():Object.keys(J);for(let Q of G){let W=J[Q];if(D0(Q,W)){let F=C0(Q,W);if(!F)continue;let U=C(F);if(!U)continue;let H=$?`${$} .${U}`:`.${U}`,L=JJ(W)?K(W,H,q+1,X):"";if(L)Z.push(L);continue}if(JJ(W))if(X&&Q in X){let F=iJ(X[Q]);if(F){let U=K(W,$,q+1,X);if(U)Z.push(`${F} { ${U} }`)}}else if(Q.startsWith("@")){let F=C(Q);if(F){let U=K(W,$,q+1,X);if(U)Z.push(`${F} { ${U} }`)}}else if(Q.includes("&")){let F=C(Q);if(F){let U=F.split("&");if($.includes(",")){let _=$.split(",").map((B)=>B.trim()).map((B)=>U.join(B)).join(", "),w=K(W,_,q+1,X);if(w)Z.push(w)}else{let H=U.join($),L=K(W,H,q+1,X);if(L)Z.push(L)}}}else if(Q.startsWith(":")){let F=C(Q);if(F){let U=`${$}${F}`,H=K(W,U,q+1,X);if(H)Z.push(H)}}else if(Q.includes(",")){let U=Q.split(",").map((H)=>H.trim()).map((H)=>C(H)).filter((H)=>H);if(U.length>0){let H=U.join(", "),L=K(W,H,q+1,X);if(L)Z.push(L)}}else if(Q.includes(" ")||Q.includes(">")||Q.includes("+")||Q.includes("~")){let F=C(Q);if(F){let H=/^[\s>+~]/.test(F.trim())?`${$}${F}`:`${$} ${F}`,L=K(W,H,q+1,X);if(L)Z.push(L)}}else{let F=C(Q);if(F){let U=$?`${$} ${F}`:F,H=K(W,U,q+1,X);if(H)Z.push(H)}}else if(W!==void 0){let F=i(Q);if(F&&(typeof W==="string"||typeof W==="number")){let U=Z0(F,W);if(F==="content"&&U==="")Y.push(`${F}: "";`);else{let H=BJ(U);Y.push(`${F}: ${H};`)}}}}let D=[];if(Y.length>0)D.push(`${$} { ${Y.join(" ")} }`);return D.push(...Z),D.join("")}function b0(J,$){if(!J||typeof J!=="object")return"";let q=[],X=Object.keys(J).sort();for(let Y of X){let Z=J[Y];if(JJ(Z))return"";if($&&Y in $)return"";if(Y.startsWith("@")||Y.includes("&")||Y.startsWith(":")||Y.includes(" ")||Y.includes(">")||Y.includes("+")||Y.includes("~"))return"";if(Z!==void 0&&!D0(Y,Z)){let G=i(Y);if(G&&(typeof Z==="string"||typeof Z==="number")){let D=Z0(G,Z);if(G==="content"&&D==="")q.push(`${G}: "";`);else{let Q=BJ(D);q.push(`${G}: ${Q};`)}}}}return q.join(" ")}function n(J,$,q="stoop",X,Y,Z){let G=z(q),D=S(J,Y),Q=b(D,$,Z),W=b0(Q,X),F,U;if(W)F=W,U=d(F);else F=K(Q,"",0,X),U=d(F);let H=G?`${G}-${U}`:`css-${U}`,L=`${G}:${H}`,_=HJ.get(L);if(_)return c(_,G,L),H;let w;if(W)w=`.${H} { ${W} }`;else w=K(Q,`.${H}`,0,X);return HJ.set(L,w),hJ.set(L,H),c(w,G,L),H}var W0=new Map;function F0(J,$="stoop"){let q=$||"";W0.set(q,J)}function k0(J="stoop"){let $=J||"";return W0.get($)||null}function MJ(J,$){let q={...J},X=Object.keys($);for(let Y of X){if(Y==="media")continue;let Z=$[Y],G=J[Y];if(Z&&typeof Z==="object"&&!Array.isArray(Z)&&G&&typeof G==="object"&&!Array.isArray(G))q[Y]={...G,...Z};else if(Z!==void 0)q[Y]=Z}return q}function EJ(J,$="stoop"){let q=k0($);if(!q)return J;if(G0(J,q))return J;return MJ(q,J)}function DJ(J,$="stoop",q="data-theme"){if(!I())return;let X={};for(let[Z,G]of Object.entries(J))X[Z]=EJ(G,$);let Y=QJ(X,$,q);q0(Y,$)}function H0(J){return function $(q={}){let X=$J(q);return MJ(J,X)}}function U0(J,$="stoop",q,X,Y){return function Z(G){return n(G,J,$,q,X,Y)}}function S0(J,$,q,X){let Y=`@keyframes ${$} {`,Z=Object.keys(J).sort((G,D)=>{let Q=parseFloat(G.replace("%","")),W=parseFloat(D.replace("%",""));if(G==="from")return-1;if(D==="from")return 1;if(G==="to")return 1;if(D==="to")return-1;return Q-W});for(let G of Z){if(!rJ(G))continue;let D=J[G];if(!D||typeof D!=="object")continue;Y+=` ${G} {`;let Q=b(D,q,X),W=Object.keys(Q).sort();for(let F of W){let U=Q[F];if(U!==void 0&&(typeof U==="string"||typeof U==="number")){let H=i(F);if(H){let L=String(U);Y+=` ${H}: ${L};`}}}Y+=" }"}return Y+=" }",Y}function L0(J="stoop",$,q){let X=z(J),Y=new j(dJ);return function Z(G){let D=wJ(G),Q=Y.get(D);if(Q)return Q;let W=D.slice(0,8),F=X?`${X}-${W}`:`stoop-${W}`,U=S0(G,F,$,q),H=`__keyframes_${F}`;return c(U,X,H),Y.set(D,F),F}}var KJ=new Set;function w0(J,$="stoop",q,X,Y){return function Z(G){let D=wJ(G);if(KJ.has(D))return()=>{};KJ.add(D);let Q=z($),W=S(G,X),F=b(W,J,Y),U=K(F,"",0,q);return c(U,Q,`__global_${D}`),()=>{KJ.delete(D)}}}import{useMemo as WJ,forwardRef as d0,createElement as u0,useContext as y0,createContext as h0}from"react";function c0(J,$,q){let X=[];for(let Z in J){let G=$[Z];if(G===void 0)continue;let D=J[Z],Q=G===!0?"true":G===!1?"false":String(G);if(D[Q])X.push(D[Q])}if(X.length===0)return q;if(X.length===1)return{...q,...X[0]};let Y={...X[0]};for(let Z=1;Z<X.length;Z++)Object.assign(Y,X[Z]);return{...q,...Y}}var VJ=null;function n0(){if(!VJ)VJ=h0(null);return VJ}function p0(J){return{__isStoopStyled:!0,__stoopClassName:J,[t]:J,toString:()=>`__STOOP_COMPONENT_${J}`}}function m0(J){return o(J)}var o0=new Set(["alignContent","alignItems","alignSelf","animation","animationDelay","animationDirection","animationDuration","animationFillMode","animationIterationCount","animationName","animationPlayState","animationTimingFunction","aspectRatio","backdropFilter","backfaceVisibility","background","backgroundAttachment","backgroundBlendMode","backgroundClip","backgroundColor","backgroundImage","backgroundOrigin","backgroundPosition","backgroundRepeat","backgroundSize","border","borderBottom","borderBottomColor","borderBottomLeftRadius","borderBottomRightRadius","borderBottomStyle","borderBottomWidth","borderCollapse","borderColor","borderImage","borderImageOutset","borderImageRepeat","borderImageSlice","borderImageSource","borderImageWidth","borderLeft","borderLeftColor","borderLeftStyle","borderLeftWidth","borderRadius","borderRight","borderRightColor","borderRightStyle","borderRightWidth","borderSpacing","borderStyle","borderTop","borderTopColor","borderTopLeftRadius","borderTopRightRadius","borderTopStyle","borderTopWidth","borderWidth","bottom","boxShadow","boxSizing","captionSide","caretColor","clear","clip","clipPath","color","columnCount","columnFill","columnGap","columnRule","columnRuleColor","columnRuleStyle","columnRuleWidth","columnSpan","columnWidth","columns","content","counterIncrement","counterReset","cursor","direction","display","emptyCells","filter","flex","flexBasis","flexDirection","flexFlow","flexGrow","flexShrink","flexWrap","float","font","fontFamily","fontFeatureSettings","fontKerning","fontLanguageOverride","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontSynthesis","fontVariant","fontVariantAlternates","fontVariantCaps","fontVariantEastAsian","fontVariantLigatures","fontVariantNumeric","fontVariantPosition","fontWeight","gap","grid","gridArea","gridAutoColumns","gridAutoFlow","gridAutoRows","gridColumn","gridColumnEnd","gridColumnGap","gridColumnStart","gridGap","gridRow","gridRowEnd","gridRowGap","gridRowStart","gridTemplate","gridTemplateAreas","gridTemplateColumns","gridTemplateRows","height","hyphens","imageOrientation","imageRendering","imageResolution","imeMode","inlineSize","isolation","justifyContent","justifyItems","justifySelf","left","letterSpacing","lineHeight","listStyle","listStyleImage","listStylePosition","listStyleType","margin","marginBottom","marginLeft","marginRight","marginTop","maxHeight","maxWidth","minHeight","minWidth","objectFit","objectPosition","opacity","order","orphans","outline","outlineColor","outlineOffset","outlineStyle","outlineWidth","overflow","overflowWrap","overflowX","overflowY","padding","paddingBottom","paddingLeft","paddingRight","paddingTop","pageBreakAfter","pageBreakBefore","pageBreakInside","perspective","perspectiveOrigin","placeContent","placeItems","placeSelf","pointerEvents","position","quotes","resize","right","rowGap","scrollBehavior","tabSize","tableLayout","textAlign","textAlignLast","textDecoration","textDecorationColor","textDecorationLine","textDecorationStyle","textIndent","textJustify","textOverflow","textShadow","textTransform","textUnderlinePosition","top","transform","transformOrigin","transformStyle","transition","transitionDelay","transitionDuration","transitionProperty","transitionTimingFunction","unicodeBidi","userSelect","verticalAlign","visibility","whiteSpace","width","wordBreak","wordSpacing","wordWrap","writingMode","zIndex"]);function i0(J){return o0.has(J)}function l0(J,$){let q=$?new Set(Object.keys($)):new Set,X={},Y={},Z={};for(let G in J)if(q.has(G))X[G]=J[G];else if(i0(G))Y[G]=J[G];else Z[G]=J[G];return{cssProps:Y,elementProps:Z,variantProps:X}}function B0(J,$="stoop",q,X,Y,Z){return function G(D,Q){let W=Q||s,F;if(Q&&"variants"in Q&&typeof Q.variants==="object"&&Q.variants!==null&&!Array.isArray(Q.variants)){let B=Q.variants;if(Object.keys(B).length>0&&Object.values(B).every((A)=>typeof A==="object"&&A!==null&&!Array.isArray(A))){F=Q.variants;let{variants:A,...R}=Q;W=R}}let U;if(typeof D!=="string"&&m0(D))U=D.__stoopClassName;let H=d0(function B(O,A){let{as:R,className:x,css:N,...V}=O,f=R||D,g=WJ(()=>N&&typeof N==="object"&&N!==null?N:s,[N]),{cssProps:k,elementProps:M,variantProps:P}=l0(V,F),r=y0(Z||n0())?.theme||J,TJ=r.media?{...q,...r.media}:q,fJ=WJ(()=>{if(!F)return"";let E=Object.entries(P);if(E.length===0)return"";return E.sort(([u],[p])=>u.localeCompare(p)).map(([u,p])=>`${u}:${String(p)}`).join("|")},[P]),CJ=WJ(()=>{let E=W;if(F&&fJ)E=c0(F,P,W);if(Object.keys(k).length>0)E=Object.assign({},E,k);if(g!==s)E=Object.assign({},E,g);return E},[fJ,g,k,W,F,P]),E0=WJ(()=>{let E=[];if(U)E.push(U);let u=n(CJ,r,$,TJ,X,Y);if(u)E.push(u);if(x){let p=typeof x==="string"?x:String(x),bJ=lJ(p);if(bJ)E.push(bJ)}return E.length>0?E.join(" "):void 0},[CJ,x,U,r,$,TJ,X,Y]);return u0(f,{...M,className:E0,ref:A})}),L=d(JSON.stringify(W)),_=`${$}-${L}`,w=H;return w.selector=p0(_),w}}import{createContext as _0,useCallback as I0,useContext as r0,useLayoutEffect as l,useMemo as xJ,useRef as NJ,useState as s0}from"react";function zJ(J){if(!I())return{error:"Not in browser environment",success:!1,value:null};try{return{source:"localStorage",success:!0,value:localStorage.getItem(J)}}catch($){return{error:$ instanceof Error?$.message:"localStorage access failed",success:!1,value:null}}}function PJ(J,$){if(!I())return{error:"Not in browser environment",success:!1,value:void 0};try{return localStorage.setItem(J,$),{success:!0,value:void 0}}catch(q){return{error:q instanceof Error?q.message:"localStorage write failed",success:!1,value:void 0}}}function jJ(J){if(!I())return null;let q=`; ${document.cookie}`.split(`; ${J}=`);if(q.length===2)return q.pop()?.split(";").shift()||null;return null}function A0(J,$,q={}){if(!I())return!1;let{maxAge:X=uJ,path:Y=yJ,secure:Z=!1}=q;try{return document.cookie=`${J}=${$}; path=${Y}; max-age=${X}${Z?"; secure":""}`,!0}catch{return!1}}import{jsx as O0}from"react/jsx-runtime";function gJ(J,$,q){if(!I())return;let X=$?jJ($):null,Y=zJ(q),Z=Y.success?Y.value:null;if(X===J&&Z!==J)PJ(q,J);if(Z===J&&$&&X!==J)A0($,J)}function a0(J,$,q){if(!I())return null;if(J!==void 0){let Z=jJ(J);if(Z&&q[Z])return Z}let X=zJ($),Y=X.success?X.value:null;if(Y&&q[Y])return Y;return null}function R0(J,$,q="stoop",X,Y){let Z=_0(null),G=_0(null),D=Object.keys(J),Q=D[0]||"default",W=X&&Y?Y(X):void 0;function F({attribute:U="data-theme",children:H,cookieKey:L,defaultTheme:_,storageKey:w="stoop-theme"}){let[B,O]=s0(_||Q),A=NJ(!1);l(()=>{if(!I()||A.current)return;let M=a0(L,w,J);if(M){if(gJ(M,L,w),M!==B)O(M)}A.current=!0},[L,w,J]),l(()=>{if(!I())return;let M=(P)=>{if(P.key===w&&P.newValue&&J[P.newValue]&&P.newValue!==B)O(P.newValue),gJ(P.newValue,L,w)};return window.addEventListener("storage",M),()=>{window.removeEventListener("storage",M)}},[w,L,B,J]);let R=xJ(()=>{return J[B]||J[_||Q]||$},[B,_,Q,J,$]),x=NJ(!1),N=NJ(!1);l(()=>{if(!I()||x.current)return;DJ(J,q,U),x.current=!0},[J,q,U]),l(()=>{if(!I()||N.current)return;if(W)W(),N.current=!0},[W]),l(()=>{if(!I())return;if(U)document.documentElement.setAttribute(U,B)},[B,U]);let V=I0((M)=>{if(J[M])O(M),PJ(w,M),gJ(M,L,w);else if(!h())console.warn(`[Stoop] Theme "${M}" not found. Available themes: ${D.join(", ")}`)},[w,L,J,D,B]),f=xJ(()=>({theme:R,themeName:B}),[R,B]),g=I0(()=>{let P=(D.indexOf(B)+1)%D.length,vJ=D[P];V(vJ)},[B,V,D]),k=xJ(()=>({availableThemes:D,setTheme:V,theme:R,themeName:B,toggleTheme:g}),[R,B,V,g]);return O0(Z.Provider,{value:f,children:O0(G.Provider,{value:k,children:H})})}return{Provider:F,ThemeContext:Z,ThemeManagementContext:G}}function M0(J){return function $(){let q=r0(J);if(!q)throw new Error("useTheme must be used within a Provider");return q}}function t0(J){let{globalCss:$,media:q,prefix:X="stoop",theme:Y,themeMap:Z,utils:G}=J,D=z(X),Q=$J(Y),W=Q.media||q,F={...m,...Z};F0(Q,D);let U=U0(Q,D,W,G,F),H=H0(Q),L=w0(Q,D,W,G,F),_=L0(D,Q,F),w=Object.freeze({...Q});function B(R){for(let x of R)try{n(x,Q,D,W,G,F)}catch{}}function O(){if(!J.themes||Object.keys(J.themes).length===0)return;DJ(J.themes,D)}function A(){let R="";if(J.themes&&Object.keys(J.themes).length>0){let V={};for(let[g,k]of Object.entries(J.themes))V[g]=EJ(k,D);let f=QJ(V,D,"data-theme");if(f)R+=f+`
|
|
14
14
|
`}else{let V=RJ(Q,D);if(V)R+=V+`
|
|
15
|
-
`}if($){let V=S($,G),f=
|
|
16
|
-
`:"")+g}let x=X0(),N=
|
|
17
|
-
`:"")+N;return R}return{config:{...J,prefix:D},createTheme:
|
|
15
|
+
`}if($){let V=S($,G),f=b(V,Q,F),g=K(f,"",0,W);if(g)R+=(R?`
|
|
16
|
+
`:"")+g}let x=X0(),N=IJ(x).trim();if(N)R+=(R?`
|
|
17
|
+
`:"")+N;return R}return{config:{...J,prefix:D},createTheme:H,css:U,getCssText:A,globalCss:L,globalCssConfig:$,keyframes:_,media:W,mergedThemeMap:F,preloadTheme:O,sanitizedPrefix:D,theme:w,utils:G,validatedTheme:Q,warmCache:B}}function e0(J){let $=t0(J),q,X,Y;if(J.themes){let G={};for(let[F,U]of Object.entries(J.themes))G[F]=$.createTheme(U);let{Provider:D,ThemeContext:Q,ThemeManagementContext:W}=R0(G,$.validatedTheme,$.sanitizedPrefix,$.globalCssConfig,$.globalCss);Y=Q,q=D,X=M0(W)}let Z=B0($.validatedTheme,$.sanitizedPrefix,$.media,$.utils,$.mergedThemeMap,Y);return{config:$.config,createTheme:$.createTheme,css:$.css,getCssText:$.getCssText,globalCss:$.globalCss,keyframes:$.keyframes,preloadTheme:$.preloadTheme,Provider:q,styled:Z,theme:$.theme,useTheme:X,warmCache:$.warmCache}}export{e0 as createStoop};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,45 +2,169 @@
|
|
|
2
2
|
* Core TypeScript type definitions for Stoop.
|
|
3
3
|
* Defines CSS objects, themes, variants, styled components, and instance types.
|
|
4
4
|
*/
|
|
5
|
-
import type { ComponentType, ElementType, JSX, ReactNode } from "react";
|
|
6
|
-
|
|
5
|
+
import type { ComponentType, ElementType, JSX, ReactNode, ForwardRefExoticComponent, ComponentPropsWithRef, ReactElement } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* Remove index signatures from a type, leaving only known properties.
|
|
8
|
+
* Useful for better autocomplete and type inference.
|
|
9
|
+
* Inspired by Stitches' RemoveIndex utility.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type MyType = { foo: string; bar: number; [key: string]: unknown };
|
|
14
|
+
* type Clean = RemoveIndexSignature<MyType>; // { foo: string; bar: number }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type RemoveIndexSignature<T> = {
|
|
18
|
+
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Widen literal types to their base types for more flexible prop types.
|
|
22
|
+
* Allows both literal values and their base types.
|
|
23
|
+
* Inspired by Stitches' Widen utility.
|
|
24
|
+
*
|
|
25
|
+
* **Note:** Currently unused in Stoop - we enforce strict literal types in variants.
|
|
26
|
+
* Available for future use if more flexible prop types are desired.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* type Strict = "sm" | "lg"; // Only accepts "sm" | "lg"
|
|
31
|
+
* type BoolWiden = Widen<"true" | "false">; // boolean | "true" | "false"
|
|
32
|
+
* type NumWiden = Widen<"1" | "2">; // number | "1" | "2"
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export type Widen<T> = T extends "true" ? boolean | T : T extends "false" ? boolean | T : T extends `${number}` ? number | T : T;
|
|
36
|
+
/**
|
|
37
|
+
* Narrowed string type for better type inference in unions.
|
|
38
|
+
* The intersection with Record<never, never> makes it distinct from plain string.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* type Props = { variant: "sm" | "lg" | NarrowString };
|
|
43
|
+
* // Autocomplete shows "sm" | "lg" but also accepts any string
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export type NarrowString = string & Record<never, never>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns a string with the given prefix followed by the given values.
|
|
49
|
+
* Used to generate token names like "$primary" from theme keys.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* type Tokens = Prefixed<"$", "primary" | "secondary">; // "$primary" | "$secondary"
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export type Prefixed<K extends string, T> = `${K}${Extract<T, boolean | number | string>}`;
|
|
57
|
+
/**
|
|
58
|
+
* Generates valid token names for a theme scale.
|
|
59
|
+
* Creates a union of "$tokenName" strings from the keys of a theme scale.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* type Theme = { colors: { primary: string; secondary: string } };
|
|
64
|
+
* type ColorTokens = TokenByScaleName<"colors", Theme>; // "$primary" | "$secondary"
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export type TokenByScaleName<ScaleName extends string, Theme extends DefaultTheme> = ScaleName extends keyof Theme ? Theme[ScaleName] extends Record<string, ThemeScaleValue> ? Prefixed<"$", keyof Theme[ScaleName]> : never : never;
|
|
68
|
+
/**
|
|
69
|
+
* Generates valid token names for a CSS property based on themeMap.
|
|
70
|
+
* Maps the property to a theme scale, then generates tokens for that scale.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* type Theme = { colors: { primary: string } };
|
|
75
|
+
* type ThemeMap = { color: "colors" };
|
|
76
|
+
* type ColorTokens = TokenByPropertyName<"color", Theme, ThemeMap>; // "$primary"
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export type TokenByPropertyName<PropertyName extends string, Theme extends DefaultTheme, ThemeMap extends Record<string, ThemeScale>> = PropertyName extends keyof ThemeMap ? TokenByScaleName<ThemeMap[PropertyName], Theme> : never;
|
|
80
|
+
/**
|
|
81
|
+
* Generates all valid tokens from all theme scales.
|
|
82
|
+
* Creates a union of all "$tokenName" strings from all scales in the theme.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* type Theme = { colors: { primary: string }; space: { small: string } };
|
|
87
|
+
* type AllTokens = AllThemeTokens<Theme>; // "$primary" | "$small"
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export type AllThemeTokens<Theme extends DefaultTheme> = {
|
|
91
|
+
[K in keyof Theme]: K extends ThemeScale ? Theme[K] extends Record<string, ThemeScaleValue> ? Prefixed<"$", keyof Theme[K]> : never : never;
|
|
92
|
+
}[keyof Theme];
|
|
7
93
|
export type CSSPropertyValue = string | number;
|
|
8
94
|
export interface StyledComponentRef {
|
|
9
95
|
readonly __stoopClassName: string;
|
|
10
96
|
readonly __isStoopStyled: true;
|
|
11
97
|
toString(): string;
|
|
12
98
|
}
|
|
13
|
-
|
|
14
|
-
|
|
99
|
+
/**
|
|
100
|
+
* CSS style object interface.
|
|
101
|
+
* Supports nested selectors, media queries, variants, and CSS property values.
|
|
102
|
+
*
|
|
103
|
+
* Property values can be:
|
|
104
|
+
* - Primitives: string | number
|
|
105
|
+
* - Theme tokens: "$tokenName" strings validated against the theme
|
|
106
|
+
* - Nested CSS objects: for pseudo-selectors, media queries, nested selectors
|
|
107
|
+
* - Variants: variant configuration object
|
|
108
|
+
* - Arrays: for multiple values (e.g., multiple box-shadows, transforms)
|
|
109
|
+
* - undefined: for optional properties
|
|
110
|
+
*
|
|
111
|
+
* **Note on `unknown[]`:** Intentionally permissive to support various CSS patterns:
|
|
112
|
+
* - Multiple transforms: `["translateX(10px)", "rotate(45deg)"]`
|
|
113
|
+
* - Multiple box-shadows: `["0 0 10px rgba(0,0,0,0.1)", "inset 0 0 5px white"]`
|
|
114
|
+
* - Vendor prefix values: `["-webkit-line-clamp", "3"]`
|
|
115
|
+
*
|
|
116
|
+
* **Theme Token Validation:**
|
|
117
|
+
* When Theme and ThemeMap are provided, CSS property values are validated:
|
|
118
|
+
* - Known properties accept valid theme tokens (e.g., `color: "$primary"`)
|
|
119
|
+
* - Unknown properties still accept any string (for flexibility)
|
|
120
|
+
* - Tokens are validated against the theme scales via ThemeMap
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const stoop = createStoop({
|
|
125
|
+
* theme: { colors: { primary: "#000" } },
|
|
126
|
+
* themeMap: { color: "colors" }
|
|
127
|
+
* });
|
|
128
|
+
* // color: "$primary" ✅ (valid token)
|
|
129
|
+
* // color: "$invalid" ❌ (TypeScript error)
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export interface CSS<Theme extends DefaultTheme = DefaultTheme, ThemeMap extends Record<string, ThemeScale> = Record<string, ThemeScale>> {
|
|
133
|
+
[property: string]: CSSPropertyValue | (AllThemeTokens<Theme> extends never ? never : AllThemeTokens<Theme>) | CSS<Theme, ThemeMap> | Variants<Theme, ThemeMap> | unknown[] | undefined;
|
|
15
134
|
}
|
|
16
135
|
/**
|
|
17
136
|
* Variants type definition.
|
|
18
|
-
* Uses
|
|
137
|
+
* Uses mapped type to preserve literal types instead of Record which widens them.
|
|
19
138
|
* This allows variant values like "primary" | "secondary" to be preserved as literal types
|
|
20
139
|
* rather than being widened to string.
|
|
21
140
|
*/
|
|
22
|
-
export type Variants = Record<string, Record<string,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
141
|
+
export type Variants<Theme extends DefaultTheme = DefaultTheme, ThemeMap extends Record<string, ThemeScale> = Record<string, ThemeScale>> = {
|
|
142
|
+
[variantName: string]: {
|
|
143
|
+
[variantValue: string]: CSS<Theme, ThemeMap>;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
26
146
|
export type HTMLElements = keyof JSX.IntrinsicElements;
|
|
27
147
|
export type StylableElement = HTMLElements | ElementType;
|
|
28
|
-
export interface StyledBaseProps {
|
|
29
|
-
css?: CSS
|
|
148
|
+
export interface StyledBaseProps<Theme extends DefaultTheme = DefaultTheme, ThemeMap extends Record<string, ThemeScale> = Record<string, ThemeScale>> {
|
|
149
|
+
css?: CSS<Theme, ThemeMap>;
|
|
30
150
|
}
|
|
31
151
|
/**
|
|
32
152
|
* CSS object that includes variants configuration.
|
|
33
153
|
* Used for styled component definitions that combine base styles with variants.
|
|
34
|
-
*
|
|
35
|
-
* when variants are defined inline. This prevents TypeScript from widening literal types.
|
|
154
|
+
* Made generic to preserve exact variant literal types from the input.
|
|
36
155
|
* We exclude variants from the CSS index signature to make it distinct.
|
|
37
156
|
*/
|
|
38
|
-
export type CSSWithVariants = {
|
|
39
|
-
[K in keyof CSS as K extends "variants" ? never : K]: CSS[K];
|
|
157
|
+
export type CSSWithVariants<Theme extends DefaultTheme = DefaultTheme, ThemeMap extends Record<string, ThemeScale> = Record<string, ThemeScale>, V extends Variants<Theme, ThemeMap> = Variants<Theme, ThemeMap>> = {
|
|
158
|
+
[K in keyof CSS<Theme, ThemeMap> as K extends "variants" ? never : K]: CSS<Theme, ThemeMap>[K];
|
|
40
159
|
} & {
|
|
41
|
-
variants:
|
|
160
|
+
variants: V;
|
|
42
161
|
};
|
|
43
|
-
export type UtilityFunction = (value: CSSPropertyValue | CSS | undefined) => CSS
|
|
162
|
+
export type UtilityFunction<Theme extends DefaultTheme = DefaultTheme, ThemeMap extends Record<string, ThemeScale> = Record<string, ThemeScale>> = (value: CSSPropertyValue | CSS<Theme, ThemeMap> | undefined) => CSS<Theme, ThemeMap>;
|
|
163
|
+
/**
|
|
164
|
+
* Theme scale value type - restricts values to primitives.
|
|
165
|
+
* Ensures theme tokens are serializable and valid CSS values.
|
|
166
|
+
*/
|
|
167
|
+
export type ThemeScaleValue = string | number;
|
|
44
168
|
/**
|
|
45
169
|
* Theme scale type - represents valid keys from DefaultTheme.
|
|
46
170
|
* Used for type-safe theme scale references throughout the codebase.
|
|
@@ -50,21 +174,22 @@ export type ThemeScale = keyof DefaultTheme;
|
|
|
50
174
|
* Theme interface - strictly enforces only these 13 approved scales.
|
|
51
175
|
* Custom theme scales are NOT allowed.
|
|
52
176
|
* Media queries are also supported as part of the theme.
|
|
177
|
+
* All scale values must be strings or numbers (primitives only).
|
|
53
178
|
*/
|
|
54
179
|
export interface DefaultTheme {
|
|
55
|
-
colors?: Record<string,
|
|
56
|
-
opacities?: Record<string,
|
|
57
|
-
space?: Record<string,
|
|
58
|
-
radii?: Record<string,
|
|
59
|
-
sizes?: Record<string,
|
|
60
|
-
fonts?: Record<string,
|
|
61
|
-
fontWeights?: Record<string,
|
|
62
|
-
fontSizes?: Record<string,
|
|
63
|
-
lineHeights?: Record<string,
|
|
64
|
-
letterSpacings?: Record<string,
|
|
65
|
-
shadows?: Record<string,
|
|
66
|
-
zIndices?: Record<string,
|
|
67
|
-
transitions?: Record<string,
|
|
180
|
+
colors?: Record<string, ThemeScaleValue>;
|
|
181
|
+
opacities?: Record<string, ThemeScaleValue>;
|
|
182
|
+
space?: Record<string, ThemeScaleValue>;
|
|
183
|
+
radii?: Record<string, ThemeScaleValue>;
|
|
184
|
+
sizes?: Record<string, ThemeScaleValue>;
|
|
185
|
+
fonts?: Record<string, ThemeScaleValue>;
|
|
186
|
+
fontWeights?: Record<string, ThemeScaleValue>;
|
|
187
|
+
fontSizes?: Record<string, ThemeScaleValue>;
|
|
188
|
+
lineHeights?: Record<string, ThemeScaleValue>;
|
|
189
|
+
letterSpacings?: Record<string, ThemeScaleValue>;
|
|
190
|
+
shadows?: Record<string, ThemeScaleValue>;
|
|
191
|
+
zIndices?: Record<string, ThemeScaleValue>;
|
|
192
|
+
transitions?: Record<string, ThemeScaleValue>;
|
|
68
193
|
media?: Record<string, string>;
|
|
69
194
|
}
|
|
70
195
|
/**
|
|
@@ -81,18 +206,66 @@ export interface StoopConfig {
|
|
|
81
206
|
themeMap?: Record<string, ThemeScale>;
|
|
82
207
|
globalCss?: CSS;
|
|
83
208
|
}
|
|
84
|
-
export type VariantKeys<T extends Variants> = keyof T;
|
|
85
209
|
/**
|
|
86
210
|
* Extract the keys from a variant object, preserving literal types.
|
|
87
211
|
* Special handling for boolean variants: if keys are exactly "true" and "false",
|
|
88
212
|
* convert to boolean type. Otherwise, use keyof to preserve literal types.
|
|
213
|
+
*
|
|
214
|
+
* **STRICT MODE:** Unlike Stitches, we do NOT widen to allow any string/number.
|
|
215
|
+
* Only the exact keys defined in the variant are allowed.
|
|
216
|
+
*
|
|
217
|
+
* @see VariantPropsFromConfig - Uses this to build variant props
|
|
218
|
+
* @see Widen - Alternative approach used by Stitches (more permissive)
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* type BoolVariant = { true: CSS; false: CSS };
|
|
223
|
+
* type BoolKeys = ExtractVariantKeys<BoolVariant>; // boolean
|
|
224
|
+
*
|
|
225
|
+
* type SizeVariant = { sm: CSS; lg: CSS };
|
|
226
|
+
* type SizeKeys = ExtractVariantKeys<SizeVariant>; // "sm" | "lg"
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
type ExtractVariantKeys<T, Theme extends DefaultTheme = DefaultTheme, ThemeMap extends Record<string, ThemeScale> = Record<string, ThemeScale>> = T extends Record<string, CSS<Theme, ThemeMap>> ? keyof T extends "true" | "false" ? boolean : keyof T : never;
|
|
230
|
+
/**
|
|
231
|
+
* Converts variant configuration to prop types.
|
|
232
|
+
* All variant props are optional and use exact literal types from the config.
|
|
233
|
+
*
|
|
234
|
+
* @see ExtractVariantKeys - Internal utility used for key extraction
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* type Config = {
|
|
239
|
+
* size: { sm: CSS; lg: CSS };
|
|
240
|
+
* color: { primary: CSS; secondary: CSS };
|
|
241
|
+
* disabled: { true: CSS; false: CSS };
|
|
242
|
+
* };
|
|
243
|
+
* type Props = VariantPropsFromConfig<Config>;
|
|
244
|
+
* // Result: {
|
|
245
|
+
* // size?: "sm" | "lg";
|
|
246
|
+
* // color?: "primary" | "secondary";
|
|
247
|
+
* // disabled?: boolean;
|
|
248
|
+
* // }
|
|
249
|
+
* ```
|
|
89
250
|
*/
|
|
90
|
-
type ExtractVariantKeys<T> = T extends Record<string, CSS> ? keyof T extends "true" | "false" ? boolean : keyof T extends "false" | "true" ? boolean : keyof T : never;
|
|
91
251
|
export type VariantPropsFromConfig<T extends Variants> = {
|
|
92
|
-
[K in
|
|
252
|
+
[K in keyof T]?: ExtractVariantKeys<T[K]>;
|
|
93
253
|
};
|
|
94
|
-
|
|
95
|
-
|
|
254
|
+
/**
|
|
255
|
+
* Base props that all styled components have.
|
|
256
|
+
* Includes className, css prop, and variant props.
|
|
257
|
+
*/
|
|
258
|
+
type StyledOwnProps<VariantsConfig extends Variants> = StyledBaseProps & VariantPropsFromConfig<VariantsConfig>;
|
|
259
|
+
/**
|
|
260
|
+
* Merge utility that properly combines types.
|
|
261
|
+
* Omits conflicting keys from T and adds all of U.
|
|
262
|
+
*/
|
|
263
|
+
type Merge<T, U> = Omit<T, keyof U> & U;
|
|
264
|
+
/**
|
|
265
|
+
* Props for a styled component without the `as` prop polymorphism.
|
|
266
|
+
* Just the base element props + our styled props.
|
|
267
|
+
*/
|
|
268
|
+
export type StyledComponentProps<DefaultElement extends ElementType, VariantsConfig extends Variants = {}> = Merge<DefaultElement extends keyof JSX.IntrinsicElements | ComponentType<any> ? ComponentPropsWithRef<DefaultElement> : {}, StyledOwnProps<VariantsConfig>>;
|
|
96
269
|
export interface ThemeContextValue {
|
|
97
270
|
theme: Theme;
|
|
98
271
|
themeName?: string;
|
|
@@ -207,17 +380,58 @@ export interface AutoPreloadResult {
|
|
|
207
380
|
}
|
|
208
381
|
/**
|
|
209
382
|
* Styled component type - the return type of styled()
|
|
383
|
+
*
|
|
384
|
+
* Note: We use ComponentType for maximum compatibility with React's type system.
|
|
385
|
+
* This ensures styled components work seamlessly with React.ComponentProps,
|
|
386
|
+
* forwardRef, and other React utilities without additional type gymnastics.
|
|
387
|
+
*/
|
|
388
|
+
/**
|
|
389
|
+
* Styled component type with proper polymorphic support.
|
|
390
|
+
* Based on Stitches' approach: uses ForwardRefExoticComponent + call signature overloads
|
|
391
|
+
* to preserve strict variant types without permissive index signatures.
|
|
392
|
+
*
|
|
393
|
+
* This provides:
|
|
394
|
+
* - Strict variant type checking (no extra variant values accepted)
|
|
395
|
+
* - Support for `as` prop to change the underlying element
|
|
396
|
+
* - Proper ref forwarding for both default and `as` elements
|
|
210
397
|
*/
|
|
211
|
-
export
|
|
398
|
+
export interface StyledComponent<DefaultElement extends ElementType, VariantsConfig extends Variants = {}> extends ForwardRefExoticComponent<StyledComponentProps<DefaultElement, VariantsConfig>> {
|
|
399
|
+
/**
|
|
400
|
+
* Call signature without `as` prop - uses default element
|
|
401
|
+
*/
|
|
402
|
+
(props: StyledComponentProps<DefaultElement, VariantsConfig> & {
|
|
403
|
+
as?: never;
|
|
404
|
+
}): ReactElement | null;
|
|
405
|
+
/**
|
|
406
|
+
* Call signature with `as` prop - changes element type
|
|
407
|
+
* Note: ref type is intentionally permissive to avoid conflicts when
|
|
408
|
+
* using refs from hooks that may not match the exact element type.
|
|
409
|
+
*/
|
|
410
|
+
<As extends ElementType = DefaultElement>(props: Merge<As extends keyof JSX.IntrinsicElements | ComponentType<unknown> ? Omit<ComponentPropsWithRef<As>, "ref"> & {
|
|
411
|
+
ref?: unknown;
|
|
412
|
+
} : {}, StyledOwnProps<VariantsConfig> & {
|
|
413
|
+
as?: As;
|
|
414
|
+
}>): ReactElement | null;
|
|
212
415
|
selector: StyledComponentRef;
|
|
213
|
-
}
|
|
416
|
+
}
|
|
214
417
|
/**
|
|
215
418
|
* Styled function type - the main styled() function signature
|
|
216
419
|
* Variants must be embedded in the baseStyles object, matching Stitches API.
|
|
420
|
+
* Overloads are ordered to prefer the variants overload when variants are present.
|
|
217
421
|
*/
|
|
218
422
|
export interface StyledFunction {
|
|
219
|
-
<DefaultElement extends StylableElement, BaseStyles extends
|
|
220
|
-
|
|
423
|
+
<DefaultElement extends StylableElement, BaseStyles extends CSS & {
|
|
424
|
+
variants: {
|
|
425
|
+
[Name in string]: {
|
|
426
|
+
[Pair in string]: CSS;
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
}>(defaultElement: DefaultElement, baseStyles: BaseStyles): StyledComponent<DefaultElement, BaseStyles extends {
|
|
430
|
+
variants: infer V;
|
|
431
|
+
} ? (V extends Variants ? V : {}) : {}>;
|
|
432
|
+
<DefaultElement extends StylableElement>(defaultElement: DefaultElement, baseStyles?: CSS & {
|
|
433
|
+
variants?: never;
|
|
434
|
+
}): StyledComponent<DefaultElement, {}>;
|
|
221
435
|
}
|
|
222
436
|
export interface GetCssTextOptions {
|
|
223
437
|
theme?: Theme;
|
|
@@ -297,4 +511,30 @@ export interface StoopInstance {
|
|
|
297
511
|
*/
|
|
298
512
|
useTheme: () => ThemeManagementContextValue;
|
|
299
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Returns the properties, attributes, and children expected by a component.
|
|
516
|
+
* Use this to extract prop types from styled components.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* const Button = styled('button', { ... });
|
|
521
|
+
* type ButtonProps = ComponentProps<typeof Button>;
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
export type ComponentProps<Component> = Component extends (...args: any[]) => any ? Parameters<Component>[0] : never;
|
|
525
|
+
/**
|
|
526
|
+
* Returns a type that extracts only the variant props from a styled component.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```ts
|
|
530
|
+
* const Button = styled('button', {
|
|
531
|
+
* variants: { size: { sm: {}, lg: {} } }
|
|
532
|
+
* });
|
|
533
|
+
* type ButtonVariants = VariantProps<typeof Button>;
|
|
534
|
+
* // Result: { size?: "sm" | "lg" }
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
export type VariantProps<Component extends {
|
|
538
|
+
selector: any;
|
|
539
|
+
}> = Component extends StyledComponent<any, infer V> ? VariantPropsFromConfig<V> : never;
|
|
300
540
|
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stoop",
|
|
3
3
|
"description": "CSS-in-JS library with type inference, theme creation, and variants support.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"author": "Jackson Dolman <mail@dolmios.com>",
|
|
6
|
-
"main": "./dist/
|
|
7
|
-
"types": "./dist/
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/dolmios/stoop.git"
|
|
@@ -13,48 +13,32 @@
|
|
|
13
13
|
"url": "https://github.com/dolmios/stoop/issues"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/dolmios/stoop#readme",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"react-polymorphic-types": "^2.0.0"
|
|
18
|
-
},
|
|
19
16
|
"devDependencies": {
|
|
20
|
-
"@stitches/stringify": "^1.2.8",
|
|
21
17
|
"@types/node": "^25.0.3",
|
|
22
18
|
"@types/react": "^19.2.7",
|
|
23
19
|
"@types/react-dom": "^19.2.3",
|
|
24
20
|
"bun-types": "^1.3.5",
|
|
25
|
-
"style-object-to-css-string": "^1.1.3",
|
|
26
|
-
"to-css": "^1.2.1",
|
|
27
21
|
"typescript": "^5.9.3"
|
|
28
22
|
},
|
|
29
23
|
"exports": {
|
|
30
24
|
".": {
|
|
31
|
-
"types": "./dist/
|
|
32
|
-
"
|
|
33
|
-
"require": "./dist/create-stoop.js",
|
|
34
|
-
"default": "./dist/create-stoop.js"
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
35
27
|
},
|
|
36
28
|
"./utils/storage": {
|
|
37
29
|
"types": "./dist/utils/storage.d.ts",
|
|
38
|
-
"import": "./dist/utils/storage.js",
|
|
39
|
-
"require": "./dist/utils/storage.js",
|
|
40
30
|
"default": "./dist/utils/storage.js"
|
|
41
31
|
},
|
|
42
32
|
"./types": {
|
|
43
33
|
"types": "./dist/types/index.d.ts",
|
|
44
|
-
"import": "./dist/types/index.js",
|
|
45
|
-
"require": "./dist/types/index.js",
|
|
46
34
|
"default": "./dist/types/index.js"
|
|
47
35
|
},
|
|
48
36
|
"./inject": {
|
|
49
37
|
"types": "./dist/inject.d.ts",
|
|
50
|
-
"import": "./dist/inject.js",
|
|
51
|
-
"require": "./dist/inject.js",
|
|
52
38
|
"default": "./dist/inject.js"
|
|
53
39
|
},
|
|
54
40
|
"./ssr": {
|
|
55
41
|
"types": "./dist/create-stoop-ssr.d.ts",
|
|
56
|
-
"import": "./dist/create-stoop-ssr.js",
|
|
57
|
-
"require": "./dist/create-stoop-ssr.js",
|
|
58
42
|
"default": "./dist/create-stoop-ssr.js"
|
|
59
43
|
}
|
|
60
44
|
},
|
|
@@ -90,8 +74,7 @@
|
|
|
90
74
|
],
|
|
91
75
|
"license": "MIT",
|
|
92
76
|
"peerDependencies": {
|
|
93
|
-
"react": ">=16.8.0"
|
|
94
|
-
"react-dom": ">=16.8.0"
|
|
77
|
+
"react": ">=16.8.0"
|
|
95
78
|
},
|
|
96
79
|
"scripts": {
|
|
97
80
|
"build": "bun run build.ts",
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type declaration for react-polymorphic-types to work around package.json exports issue.
|
|
3
|
-
* Properly extends native element props while preserving custom variant props.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
declare module "react-polymorphic-types" {
|
|
7
|
-
import type { ElementType, ComponentPropsWithRef, ComponentPropsWithoutRef } from "react";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Polymorphic props with ref support.
|
|
11
|
-
* Extends native element props while preserving custom props (like variants).
|
|
12
|
-
* Variant props take precedence over native props with the same name.
|
|
13
|
-
*/
|
|
14
|
-
export type PolymorphicPropsWithRef<OwnProps, DefaultElement extends ElementType> = OwnProps &
|
|
15
|
-
Omit<ComponentPropsWithRef<DefaultElement>, keyof OwnProps>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Polymorphic props without ref support.
|
|
19
|
-
* Extends native element props while preserving custom props (like variants).
|
|
20
|
-
* Variant props take precedence over native props with the same name.
|
|
21
|
-
*/
|
|
22
|
-
export type PolymorphicPropsWithoutRef<OwnProps, DefaultElement extends ElementType> = OwnProps &
|
|
23
|
-
Omit<ComponentPropsWithoutRef<DefaultElement>, keyof OwnProps>;
|
|
24
|
-
}
|