@mochi-css/vanilla 2.0.1 → 3.0.0

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 CHANGED
@@ -1,7 +1,8 @@
1
1
  # 🧁 Mochi-CSS/vanilla
2
2
 
3
3
  This package is part of the [Mochi-CSS project](https://github.com/Niikelion/mochi-css).
4
- It provides type-safe CSS-in-JS styling functions with static extraction support, allowing you to write styles in TypeScript that get extracted to plain CSS at build time.
4
+ It provides type-safe CSS-in-JS styling functions with static extraction support,
5
+ allowing you to write styles in TypeScript that get extracted to plain CSS at build time.
5
6
 
6
7
  ## Installation
7
8
 
@@ -45,7 +46,8 @@ const buttonStyles = css(textStyles, {
45
46
 
46
47
  ### `globalCss(styles)`
47
48
 
48
- `globalCss` injects styles into the global scope they are not scoped to any class and apply to all matching elements. Use it for resets, base typography, or any styles that must target plain HTML elements.
49
+ `globalCss` injects styles into the global scope - they are not scoped to any class and apply to all matching elements.
50
+ Use it for resets, base typography, or any styles that must target plain HTML elements.
49
51
 
50
52
  ```ts
51
53
  import { globalCss } from "@mochi-css/vanilla"
@@ -59,10 +61,11 @@ globalCss({
59
61
 
60
62
  ### `styled(component, ...styles)`
61
63
 
62
- `styled` creates a styled component by combining a base element or component with style definitions. It automatically applies the generated class names and forwards variant props.
64
+ `styled` creates a styled component by combining a base element or component with style definitions.
65
+ It automatically applies the generated class names and forwards variant props.
63
66
 
64
67
  ```tsx
65
- import {styled} from "@mochi-css/vanilla"
68
+ import { styled } from "@mochi-css/react"
66
69
 
67
70
  const Button = styled("button", {
68
71
  borderRadius: 10,
@@ -127,7 +130,8 @@ A style definition is either a bundle of styles returned by `css`, or an object
127
130
 
128
131
  ## Nested Selectors
129
132
 
130
- Mochi-CSS supports nested selectors, allowing you to define styles for child elements, pseudo-classes, and pseudo-elements directly within your style definitions.
133
+ Mochi-CSS supports nested selectors, allowing you to define styles for child elements, pseudo-classes,
134
+ and pseudo-elements directly within your style definitions.
131
135
 
132
136
  The `&` character represents the parent selector and must be included in every nested selector:
133
137
 
@@ -400,11 +404,14 @@ const redButtonStyle = css(baseButtonStyle, {
400
404
  })
401
405
  ```
402
406
 
403
- This works, but requires you to either manually select which style to apply in your component logic, or create separate components for each variant.
404
- Mochi-CSS allows you to define variants directly in your style definition and automatically generates the corresponding props for your component.
407
+ This works, but requires you to either manually select which style to apply in your component logic,
408
+ or create separate components for each variant.
409
+ Mochi-CSS allows you to define variants directly in your style definition
410
+ and automatically generates the corresponding props for your component.
405
411
 
406
412
  ```tsx
407
- import {styled, css} from "@mochi-css/vanilla"
413
+ import { css } from "@mochi-css/vanilla"
414
+ import { styled } from "@mochi-css/react"
408
415
 
409
416
  const buttonStyle = css({
410
417
  border: "2px solid black",
@@ -433,13 +440,16 @@ const SomeComponent = () => <div>
433
440
  </div>
434
441
  ```
435
442
 
436
- `defaultVariants` is optional, but specifying defaults for all variants ensures predictable styling when variant props are omitted.
443
+ `defaultVariants` is optional,
444
+ but specifying defaults for all variants ensures predictable styling when variant props are omitted.
437
445
 
438
446
  ## Tokens
439
447
 
440
- Mochi-CSS provides typed wrappers around CSS variables to help with type safety. Tokens ensure that only valid values are assigned to your CSS variables.
448
+ Mochi-CSS provides typed wrappers around CSS variables to help with type safety.
449
+ Tokens ensure that only valid values are assigned to your CSS variables.
441
450
 
442
- Create tokens using the `createToken<T>(name)` function, where `T` is a CSS value type like `CssColorLike`, `CssLengthLike`, or `string`:
451
+ Create tokens using the `createToken<T>(name)` function,
452
+ where `T` is a CSS value type like `CssColorLike`, `CssLengthLike`, or `string`:
443
453
 
444
454
  ```ts
445
455
  import {createToken, css, CssColorLike} from "@mochi-css/vanilla"
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- import { ComponentProps, ComponentType, FC, HTMLElementType } from "react";
2
1
  import { ObsoleteProperties, Properties } from "csstype";
3
2
 
4
3
  //#region src/values/index.d.ts
@@ -450,7 +449,11 @@ type PropsWithUnit = PropertyWithUnit & keyof Props;
450
449
  /**
451
450
  * Converts a kebab-case string to camelCase.
452
451
  */
453
-
452
+ declare function kebabToCamel(str: string): string;
453
+ /**
454
+ * Converts a camelCase string to kebab-case.
455
+ */
456
+ declare function camelToKebab(str: string): string;
454
457
  /**
455
458
  * Checks if a key represents a CSS at-rule (media, container, supports, layer).
456
459
  */
@@ -542,10 +545,11 @@ declare class CssObjectBlock {
542
545
  readonly subBlocks: CssObjectSubBlock[];
543
546
  /**
544
547
  * Creates a new CSS block from style properties.
545
- * Generates a unique class name based on the content hash.
548
+ * Generates a unique class name based on the content hash, or uses the provided class name.
546
549
  * @param styles - The style properties to compile
550
+ * @param className - Optional stable class name; if omitted, a content-hash-based name is generated
547
551
  */
548
- constructor(styles: StyleProps);
552
+ constructor(styles: StyleProps, className?: string);
549
553
  /**
550
554
  * Gets the CSS class selector for this block.
551
555
  */
@@ -632,13 +636,18 @@ declare class CSSObject<V extends AllVariants = DefaultVariants> {
632
636
  /**
633
637
  * Creates a new CSSObject from style props.
634
638
  * Compiles main styles and all variant options into CSS blocks.
639
+ * @param props - Base style props plus variant definitions
640
+ * @param props.variants - Named variant groups, each mapping variant values to style props
641
+ * @param props.defaultVariants - Default value for each variant when none is provided at runtime
642
+ * @param props.compoundVariants - Style props applied when a specific combination of variants is active
643
+ * @param className - Optional stable class name for the main block
635
644
  */
636
645
  constructor({
637
646
  variants,
638
647
  defaultVariants,
639
648
  compoundVariants,
640
649
  ...props
641
- }: MochiCSSProps<V>);
650
+ }: MochiCSSProps<V>, className?: string);
642
651
  /**
643
652
  * Serializes the entire CSS object to a CSS string.
644
653
  * Outputs main block first, then all variant blocks in sorted order.
@@ -648,6 +657,7 @@ declare class CSSObject<V extends AllVariants = DefaultVariants> {
648
657
  }
649
658
  //#endregion
650
659
  //#region src/css.d.ts
660
+ declare function isMochiCSS(value: unknown): value is MochiCSS;
651
661
  /**
652
662
  * Runtime representation of a CSS style definition with variant support.
653
663
  * Holds generated class names and provides methods to compute the final
@@ -666,6 +676,7 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
666
676
  readonly classNames: string[];
667
677
  readonly variantClassNames: { [K in keyof V]: { [P in keyof V[K]]: string } };
668
678
  readonly defaultVariants: Partial<RefineVariants<V>>;
679
+ readonly $$typeof: symbol;
669
680
  /**
670
681
  * Creates a new MochiCSS instance.
671
682
  * @param classNames - Base class names to always include
@@ -681,6 +692,12 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
681
692
  * @returns Combined className string for use in components
682
693
  */
683
694
  variant(props: Partial<RefineVariants<V>>): string;
695
+ /**
696
+ * Returns the CSS selector for this style (e.g. `.abc123`).
697
+ * Useful for targeting this component from another style.
698
+ */
699
+ get selector(): string;
700
+ toString(): string;
684
701
  /**
685
702
  * Creates a MochiCSS instance from a CSSObject.
686
703
  * Extracts class names from the compiled CSS blocks.
@@ -697,46 +714,7 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
697
714
  * @returns A new MochiCSS instance with all styles combined
698
715
  */
699
716
  declare function mergeMochiCss<V extends AllVariants[]>(instances: MochiCSS<AllVariants>[]): MochiCSS<MergeCSSVariants<V>>;
700
- declare function css<V extends AllVariants[]>(...props: { [K in keyof V]: MochiCSSProps<V[K]> | MochiCSS }): MochiCSS<MergeCSSVariants<V>>;
701
- //#endregion
702
- //#region src/styled.d.ts
703
- /** Props added by MochiCSS to styled components */
704
- type MochiProps<V extends AllVariants[]> = {
705
- className?: string;
706
- } & Partial<RefineVariants<MergeCSSVariants<V>>>;
707
- /** Minimal interface for components that accept className */
708
- type Cls = {
709
- className?: string;
710
- };
711
- /**
712
- * Creates a styled React component with CSS-in-JS support and variant props.
713
- * Similar to styled-components or Stitches, but with zero runtime overhead.
714
- *
715
- * @template T - The base element type or component type
716
- * @template V - The variant definitions tuple type
717
- * @param target - The HTML element tag name or React component to style
718
- * @param props - One or more style objects with optional variants
719
- * @returns A React functional component with merged props and variant support
720
- *
721
- * @example
722
- * const Button = styled('button', {
723
- * padding: 8,
724
- * borderRadius: 4,
725
- * variants: {
726
- * size: {
727
- * small: { padding: 4 },
728
- * large: { padding: 16 }
729
- * },
730
- * variant: {
731
- * primary: { backgroundColor: 'blue' },
732
- * secondary: { backgroundColor: 'gray' }
733
- * }
734
- * }
735
- * })
736
- *
737
- * // Usage: <Button size="large" variant="primary">Click me</Button>
738
- */
739
- declare function styled<T extends HTMLElementType | ComponentType<Cls>, V extends AllVariants[]>(target: T, ...props: { [K in keyof V]: MochiCSSProps<V[K]> }): FC<Omit<ComponentProps<T>, keyof MochiProps<V>> & MochiProps<V>>;
717
+ declare function css<V extends AllVariants[]>(...props: { [K in keyof V]: MochiCSSProps<V[K]> | MochiCSS | string }): MochiCSS<MergeCSSVariants<V>>;
740
718
  //#endregion
741
719
  //#region src/keyframesObject.d.ts
742
720
  type KeyframeStops = Record<string, SimpleStyleProps>;
@@ -833,4 +811,28 @@ interface SupportsHelper {
833
811
  /** Helper for constructing `@supports` at-rule keys. */
834
812
  declare const supports: SupportsHelper;
835
813
  //#endregion
836
- export { AllVariants, type AtRuleKey, CSSObject, CompoundVariant, CssLike, CssLikeObject, CssObjectBlock, CssObjectSubBlock, CssVar, CssVarVal, DefaultVariants, GlobalCssObject, type GlobalCssStyles, type KeyframeStops, KeyframesObject, MergeCSSVariants, MochiCSS, MochiCSSProps, MochiKeyframes, MochiSelector, RefineVariants, type StyleProps, Token, VariantProps, container, createToken, css, cssFromProps, globalCss, isAtRuleKey, keyframes, media, mergeMochiCss, styled, supports };
814
+ //#region src/hash.d.ts
815
+ /**
816
+ * Hashing utilities for generating short, deterministic class names.
817
+ * Uses djb2 algorithm for fast string hashing.
818
+ * @module hash
819
+ */
820
+ /**
821
+ * Converts a number to a base-62 string representation.
822
+ * @param num - The number to convert
823
+ * @param maxLength - Optional maximum length of the output string
824
+ * @returns Base-62 encoded string representation of the number
825
+ */
826
+ declare function numberToBase62(num: number, maxLength?: number): string;
827
+ /**
828
+ * Generates a short hash string from input using the djb2 algorithm.
829
+ * Used to create unique, deterministic CSS class names from style content.
830
+ * @param input - The string to hash
831
+ * @param length - Maximum length of the hash output (default: 8)
832
+ * @returns A short, css-safe hash string
833
+ * @example
834
+ * shortHash("color: red;") // Returns something like "A1b2C3d4"
835
+ */
836
+ declare function shortHash(input: string, length?: number): string;
837
+ //#endregion
838
+ export { AllVariants, type AtRuleKey, CSSObject, CompoundVariant, CssLike, CssLikeObject, CssObjectBlock, CssObjectSubBlock, CssVar, CssVarVal, DefaultVariants, GlobalCssObject, type GlobalCssStyles, type KeyframeStops, KeyframesObject, MergeCSSVariants, MochiCSS, MochiCSSProps, MochiKeyframes, MochiSelector, RefineVariants, type StyleProps, Token, VariantProps, camelToKebab, container, createToken, css, cssFromProps, globalCss, isAtRuleKey, isMochiCSS, kebabToCamel, keyframes, media, mergeMochiCss, numberToBase62, shortHash, supports };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ObsoleteProperties, Properties } from "csstype";
2
- import { ComponentProps, ComponentType, FC, HTMLElementType } from "react";
3
2
 
4
3
  //#region src/values/index.d.ts
5
4
  type CssVar = `--${string}`;
@@ -450,7 +449,11 @@ type PropsWithUnit = PropertyWithUnit & keyof Props;
450
449
  /**
451
450
  * Converts a kebab-case string to camelCase.
452
451
  */
453
-
452
+ declare function kebabToCamel(str: string): string;
453
+ /**
454
+ * Converts a camelCase string to kebab-case.
455
+ */
456
+ declare function camelToKebab(str: string): string;
454
457
  /**
455
458
  * Checks if a key represents a CSS at-rule (media, container, supports, layer).
456
459
  */
@@ -542,10 +545,11 @@ declare class CssObjectBlock {
542
545
  readonly subBlocks: CssObjectSubBlock[];
543
546
  /**
544
547
  * Creates a new CSS block from style properties.
545
- * Generates a unique class name based on the content hash.
548
+ * Generates a unique class name based on the content hash, or uses the provided class name.
546
549
  * @param styles - The style properties to compile
550
+ * @param className - Optional stable class name; if omitted, a content-hash-based name is generated
547
551
  */
548
- constructor(styles: StyleProps);
552
+ constructor(styles: StyleProps, className?: string);
549
553
  /**
550
554
  * Gets the CSS class selector for this block.
551
555
  */
@@ -632,13 +636,18 @@ declare class CSSObject<V extends AllVariants = DefaultVariants> {
632
636
  /**
633
637
  * Creates a new CSSObject from style props.
634
638
  * Compiles main styles and all variant options into CSS blocks.
639
+ * @param props - Base style props plus variant definitions
640
+ * @param props.variants - Named variant groups, each mapping variant values to style props
641
+ * @param props.defaultVariants - Default value for each variant when none is provided at runtime
642
+ * @param props.compoundVariants - Style props applied when a specific combination of variants is active
643
+ * @param className - Optional stable class name for the main block
635
644
  */
636
645
  constructor({
637
646
  variants,
638
647
  defaultVariants,
639
648
  compoundVariants,
640
649
  ...props
641
- }: MochiCSSProps<V>);
650
+ }: MochiCSSProps<V>, className?: string);
642
651
  /**
643
652
  * Serializes the entire CSS object to a CSS string.
644
653
  * Outputs main block first, then all variant blocks in sorted order.
@@ -648,6 +657,7 @@ declare class CSSObject<V extends AllVariants = DefaultVariants> {
648
657
  }
649
658
  //#endregion
650
659
  //#region src/css.d.ts
660
+ declare function isMochiCSS(value: unknown): value is MochiCSS;
651
661
  /**
652
662
  * Runtime representation of a CSS style definition with variant support.
653
663
  * Holds generated class names and provides methods to compute the final
@@ -666,6 +676,7 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
666
676
  readonly classNames: string[];
667
677
  readonly variantClassNames: { [K in keyof V]: { [P in keyof V[K]]: string } };
668
678
  readonly defaultVariants: Partial<RefineVariants<V>>;
679
+ readonly $$typeof: symbol;
669
680
  /**
670
681
  * Creates a new MochiCSS instance.
671
682
  * @param classNames - Base class names to always include
@@ -681,6 +692,12 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
681
692
  * @returns Combined className string for use in components
682
693
  */
683
694
  variant(props: Partial<RefineVariants<V>>): string;
695
+ /**
696
+ * Returns the CSS selector for this style (e.g. `.abc123`).
697
+ * Useful for targeting this component from another style.
698
+ */
699
+ get selector(): string;
700
+ toString(): string;
684
701
  /**
685
702
  * Creates a MochiCSS instance from a CSSObject.
686
703
  * Extracts class names from the compiled CSS blocks.
@@ -697,46 +714,7 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
697
714
  * @returns A new MochiCSS instance with all styles combined
698
715
  */
699
716
  declare function mergeMochiCss<V extends AllVariants[]>(instances: MochiCSS<AllVariants>[]): MochiCSS<MergeCSSVariants<V>>;
700
- declare function css<V extends AllVariants[]>(...props: { [K in keyof V]: MochiCSSProps<V[K]> | MochiCSS }): MochiCSS<MergeCSSVariants<V>>;
701
- //#endregion
702
- //#region src/styled.d.ts
703
- /** Props added by MochiCSS to styled components */
704
- type MochiProps<V extends AllVariants[]> = {
705
- className?: string;
706
- } & Partial<RefineVariants<MergeCSSVariants<V>>>;
707
- /** Minimal interface for components that accept className */
708
- type Cls = {
709
- className?: string;
710
- };
711
- /**
712
- * Creates a styled React component with CSS-in-JS support and variant props.
713
- * Similar to styled-components or Stitches, but with zero runtime overhead.
714
- *
715
- * @template T - The base element type or component type
716
- * @template V - The variant definitions tuple type
717
- * @param target - The HTML element tag name or React component to style
718
- * @param props - One or more style objects with optional variants
719
- * @returns A React functional component with merged props and variant support
720
- *
721
- * @example
722
- * const Button = styled('button', {
723
- * padding: 8,
724
- * borderRadius: 4,
725
- * variants: {
726
- * size: {
727
- * small: { padding: 4 },
728
- * large: { padding: 16 }
729
- * },
730
- * variant: {
731
- * primary: { backgroundColor: 'blue' },
732
- * secondary: { backgroundColor: 'gray' }
733
- * }
734
- * }
735
- * })
736
- *
737
- * // Usage: <Button size="large" variant="primary">Click me</Button>
738
- */
739
- declare function styled<T extends HTMLElementType | ComponentType<Cls>, V extends AllVariants[]>(target: T, ...props: { [K in keyof V]: MochiCSSProps<V[K]> }): FC<Omit<ComponentProps<T>, keyof MochiProps<V>> & MochiProps<V>>;
717
+ declare function css<V extends AllVariants[]>(...props: { [K in keyof V]: MochiCSSProps<V[K]> | MochiCSS | string }): MochiCSS<MergeCSSVariants<V>>;
740
718
  //#endregion
741
719
  //#region src/keyframesObject.d.ts
742
720
  type KeyframeStops = Record<string, SimpleStyleProps>;
@@ -833,5 +811,29 @@ interface SupportsHelper {
833
811
  /** Helper for constructing `@supports` at-rule keys. */
834
812
  declare const supports: SupportsHelper;
835
813
  //#endregion
836
- export { AllVariants, type AtRuleKey, CSSObject, CompoundVariant, CssLike, CssLikeObject, CssObjectBlock, CssObjectSubBlock, CssVar, CssVarVal, DefaultVariants, GlobalCssObject, type GlobalCssStyles, type KeyframeStops, KeyframesObject, MergeCSSVariants, MochiCSS, MochiCSSProps, MochiKeyframes, MochiSelector, RefineVariants, type StyleProps, Token, VariantProps, container, createToken, css, cssFromProps, globalCss, isAtRuleKey, keyframes, media, mergeMochiCss, styled, supports };
814
+ //#region src/hash.d.ts
815
+ /**
816
+ * Hashing utilities for generating short, deterministic class names.
817
+ * Uses djb2 algorithm for fast string hashing.
818
+ * @module hash
819
+ */
820
+ /**
821
+ * Converts a number to a base-62 string representation.
822
+ * @param num - The number to convert
823
+ * @param maxLength - Optional maximum length of the output string
824
+ * @returns Base-62 encoded string representation of the number
825
+ */
826
+ declare function numberToBase62(num: number, maxLength?: number): string;
827
+ /**
828
+ * Generates a short hash string from input using the djb2 algorithm.
829
+ * Used to create unique, deterministic CSS class names from style content.
830
+ * @param input - The string to hash
831
+ * @param length - Maximum length of the hash output (default: 8)
832
+ * @returns A short, css-safe hash string
833
+ * @example
834
+ * shortHash("color: red;") // Returns something like "A1b2C3d4"
835
+ */
836
+ declare function shortHash(input: string, length?: number): string;
837
+ //#endregion
838
+ export { AllVariants, type AtRuleKey, CSSObject, CompoundVariant, CssLike, CssLikeObject, CssObjectBlock, CssObjectSubBlock, CssVar, CssVarVal, DefaultVariants, GlobalCssObject, type GlobalCssStyles, type KeyframeStops, KeyframesObject, MergeCSSVariants, MochiCSS, MochiCSSProps, MochiKeyframes, MochiSelector, RefineVariants, type StyleProps, Token, VariantProps, camelToKebab, container, createToken, css, cssFromProps, globalCss, isAtRuleKey, isMochiCSS, kebabToCamel, keyframes, media, mergeMochiCss, numberToBase62, shortHash, supports };
837
839
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -23,8 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  let clsx = require("clsx");
25
25
  clsx = __toESM(clsx);
26
- let react = require("react");
27
- react = __toESM(react);
28
26
 
29
27
  //#region src/token.ts
30
28
  /**
@@ -1156,6 +1154,12 @@ const knownPropertyNames = new Set([
1156
1154
  //#endregion
1157
1155
  //#region src/props.ts
1158
1156
  /**
1157
+ * Converts a kebab-case string to camelCase.
1158
+ */
1159
+ function kebabToCamel(str) {
1160
+ return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
1161
+ }
1162
+ /**
1159
1163
  * Converts a camelCase string to kebab-case.
1160
1164
  */
1161
1165
  function camelToKebab(str) {
@@ -1496,12 +1500,13 @@ var CssObjectBlock = class {
1496
1500
  subBlocks = [];
1497
1501
  /**
1498
1502
  * Creates a new CSS block from style properties.
1499
- * Generates a unique class name based on the content hash.
1503
+ * Generates a unique class name based on the content hash, or uses the provided class name.
1500
1504
  * @param styles - The style properties to compile
1505
+ * @param className - Optional stable class name; if omitted, a content-hash-based name is generated
1501
1506
  */
1502
- constructor(styles) {
1507
+ constructor(styles, className) {
1503
1508
  const blocks = CssObjectSubBlock.fromProps(styles);
1504
- this.className = "c" + shortHash(blocks.map((b) => b.hash).join("+"));
1509
+ this.className = className ?? "c" + shortHash(blocks.map((b) => b.hash).join("+"));
1505
1510
  this.subBlocks = blocks;
1506
1511
  }
1507
1512
  /**
@@ -1549,9 +1554,14 @@ var CSSObject = class {
1549
1554
  /**
1550
1555
  * Creates a new CSSObject from style props.
1551
1556
  * Compiles main styles and all variant options into CSS blocks.
1557
+ * @param props - Base style props plus variant definitions
1558
+ * @param props.variants - Named variant groups, each mapping variant values to style props
1559
+ * @param props.defaultVariants - Default value for each variant when none is provided at runtime
1560
+ * @param props.compoundVariants - Style props applied when a specific combination of variants is active
1561
+ * @param className - Optional stable class name for the main block
1552
1562
  */
1553
- constructor({ variants, defaultVariants, compoundVariants,...props }) {
1554
- this.mainBlock = new CssObjectBlock(props);
1563
+ constructor({ variants, defaultVariants, compoundVariants,...props }, className) {
1564
+ this.mainBlock = new CssObjectBlock(props, className);
1555
1565
  this.variantBlocks = {};
1556
1566
  this.variantDefaults = defaultVariants ?? {};
1557
1567
  this.compoundVariants = [];
@@ -1593,6 +1603,10 @@ var CSSObject = class {
1593
1603
 
1594
1604
  //#endregion
1595
1605
  //#region src/css.ts
1606
+ const MOCHI_CSS_TYPEOF = Symbol.for("mochi-css.MochiCSS");
1607
+ function isMochiCSS(value) {
1608
+ return typeof value === "object" && value !== null && value["$$typeof"] === MOCHI_CSS_TYPEOF;
1609
+ }
1596
1610
  /**
1597
1611
  * Runtime representation of a CSS style definition with variant support.
1598
1612
  * Holds generated class names and provides methods to compute the final
@@ -1608,6 +1622,7 @@ var CSSObject = class {
1608
1622
  * styles.variant({ size: 'large' }) // Returns combined class names
1609
1623
  */
1610
1624
  var MochiCSS = class MochiCSS {
1625
+ $$typeof = MOCHI_CSS_TYPEOF;
1611
1626
  /**
1612
1627
  * Creates a new MochiCSS instance.
1613
1628
  * @param classNames - Base class names to always include
@@ -1641,6 +1656,16 @@ var MochiCSS = class MochiCSS {
1641
1656
  }));
1642
1657
  }
1643
1658
  /**
1659
+ * Returns the CSS selector for this style (e.g. `.abc123`).
1660
+ * Useful for targeting this component from another style.
1661
+ */
1662
+ get selector() {
1663
+ return this.classNames.map((n) => `.${n}`).join();
1664
+ }
1665
+ toString() {
1666
+ return this.selector;
1667
+ }
1668
+ /**
1644
1669
  * Creates a MochiCSS instance from a CSSObject.
1645
1670
  * Extracts class names from the compiled CSS blocks.
1646
1671
  * @template V - The variant definitions type
@@ -1699,51 +1724,18 @@ function mergeMochiCss(instances) {
1699
1724
  function css(...props) {
1700
1725
  const cssToMerge = [];
1701
1726
  for (const p of props) {
1702
- if (p == null || typeof p !== "object") continue;
1727
+ if (p == null) continue;
1728
+ if (typeof p === "string") {
1729
+ cssToMerge.push(new MochiCSS([p], {}, {}));
1730
+ continue;
1731
+ }
1732
+ if (typeof p !== "object") continue;
1703
1733
  if (p instanceof MochiCSS) cssToMerge.push(p);
1704
1734
  else cssToMerge.push(MochiCSS.from(new CSSObject(p)));
1705
1735
  }
1706
1736
  return mergeMochiCss(cssToMerge);
1707
1737
  }
1708
1738
 
1709
- //#endregion
1710
- //#region src/styled.ts
1711
- /**
1712
- * Creates a styled React component with CSS-in-JS support and variant props.
1713
- * Similar to styled-components or Stitches, but with zero runtime overhead.
1714
- *
1715
- * @template T - The base element type or component type
1716
- * @template V - The variant definitions tuple type
1717
- * @param target - The HTML element tag name or React component to style
1718
- * @param props - One or more style objects with optional variants
1719
- * @returns A React functional component with merged props and variant support
1720
- *
1721
- * @example
1722
- * const Button = styled('button', {
1723
- * padding: 8,
1724
- * borderRadius: 4,
1725
- * variants: {
1726
- * size: {
1727
- * small: { padding: 4 },
1728
- * large: { padding: 16 }
1729
- * },
1730
- * variant: {
1731
- * primary: { backgroundColor: 'blue' },
1732
- * secondary: { backgroundColor: 'gray' }
1733
- * }
1734
- * }
1735
- * })
1736
- *
1737
- * // Usage: <Button size="large" variant="primary">Click me</Button>
1738
- */
1739
- function styled(target, ...props) {
1740
- const styles = css(...props);
1741
- return ({ className,...p }) => (0, react.createElement)(target, {
1742
- className: (0, clsx.default)(styles.variant(p), className),
1743
- ...p
1744
- });
1745
- }
1746
-
1747
1739
  //#endregion
1748
1740
  //#region src/keyframesObject.ts
1749
1741
  var KeyframesObject = class KeyframesObject {
@@ -1899,15 +1891,19 @@ exports.MochiCSS = MochiCSS;
1899
1891
  exports.MochiKeyframes = MochiKeyframes;
1900
1892
  exports.MochiSelector = MochiSelector;
1901
1893
  exports.Token = Token;
1894
+ exports.camelToKebab = camelToKebab;
1902
1895
  exports.container = container;
1903
1896
  exports.createToken = createToken;
1904
1897
  exports.css = css;
1905
1898
  exports.cssFromProps = cssFromProps;
1906
1899
  exports.globalCss = globalCss;
1907
1900
  exports.isAtRuleKey = isAtRuleKey;
1901
+ exports.isMochiCSS = isMochiCSS;
1902
+ exports.kebabToCamel = kebabToCamel;
1908
1903
  exports.keyframes = keyframes;
1909
1904
  exports.media = media;
1910
1905
  exports.mergeMochiCss = mergeMochiCss;
1911
- exports.styled = styled;
1906
+ exports.numberToBase62 = numberToBase62;
1907
+ exports.shortHash = shortHash;
1912
1908
  exports.supports = supports;
1913
1909
  //# sourceMappingURL=index.js.map