@mochi-css/vanilla 1.0.1 → 2.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/dist/index.d.ts CHANGED
@@ -55,38 +55,33 @@ declare function createToken(name: string): Token;
55
55
  //#region src/selector.d.ts
56
56
  /**
57
57
  * CSS selector building and manipulation utilities.
58
- * Handles nested selectors (using `&` placeholder) and media queries.
58
+ * Handles nested selectors (using `&` placeholder) and CSS at-rules.
59
59
  * @module selector
60
60
  */
61
61
  /**
62
- * Immutable CSS selector builder that handles nested selectors and media queries.
62
+ * Immutable CSS selector builder that handles nested selectors and CSS at-rules.
63
63
  * Uses the `&` character as a placeholder for parent selector substitution.
64
64
  *
65
65
  * @example
66
66
  * const selector = new MochiSelector(['.button'])
67
67
  * selector.extend('&:hover').cssSelector // '.button:hover'
68
- * selector.wrap('@media (min-width: 768px)').mediaQuery // '@media (min-width: 768px)'
68
+ * selector.wrap('@media (min-width: 768px)').atRules // ['@media (min-width: 768px)']
69
69
  */
70
70
  declare class MochiSelector {
71
71
  private readonly cssSelectors;
72
- private readonly mediaSelectors;
72
+ readonly atRules: string[];
73
73
  /**
74
74
  * Creates a new MochiSelector instance.
75
75
  * @param cssSelectors - Array of CSS selectors (may contain `&` placeholders)
76
- * @param mediaSelectors - Array of media query conditions (without `@media` prefix)
76
+ * @param atRules - Array of full CSS at-rule strings e.g. `"@media (min-width: 768px)"`
77
77
  */
78
- constructor(cssSelectors?: string[], mediaSelectors?: string[]);
78
+ constructor(cssSelectors?: string[], atRules?: string[]);
79
79
  /**
80
80
  * Gets the combined CSS selector string.
81
81
  * Multiple selectors are joined with commas.
82
82
  * @returns The CSS selector, or "*" if no selectors are defined
83
83
  */
84
84
  get cssSelector(): string;
85
- /**
86
- * Gets the combined media query string, if any.
87
- * @returns The full `@media` query string, or undefined if no media conditions
88
- */
89
- get mediaQuery(): string | undefined;
90
85
  /**
91
86
  * Substitutes all `&` placeholders with the given root selector.
92
87
  * @param root - The selector to replace `&` with
@@ -104,13 +99,14 @@ declare class MochiSelector {
104
99
  */
105
100
  extend(child: string): MochiSelector;
106
101
  /**
107
- * Wraps this selector with a media query condition.
108
- * @param mediaQuery - The media query string (starting with `@`)
109
- * @returns A new MochiSelector with the added media condition
102
+ * Wraps this selector with a CSS at-rule.
103
+ * @param atRule - The full at-rule string (e.g. `"@media (min-width: 768px)"`)
104
+ * @returns A new MochiSelector with the added at-rule, or unchanged if not a known at-rule
110
105
  * @example
111
- * selector.wrap('@min-width: 768px') // Adds media query condition
106
+ * selector.wrap('@media (min-width: 768px)') // Adds media query
107
+ * selector.wrap('@container sidebar (min-width: 300px)') // Adds container query
112
108
  */
113
- wrap(mediaQuery: string): MochiSelector;
109
+ wrap(atRule: string): MochiSelector;
114
110
  /**
115
111
  * Splits a comma-separated selector string into individual selectors.
116
112
  * @param selector - The selector string to split
@@ -455,11 +451,15 @@ type PropsWithUnit = PropertyWithUnit & keyof Props;
455
451
  * Converts a kebab-case string to camelCase.
456
452
  */
457
453
 
454
+ /**
455
+ * Checks if a key represents a CSS at-rule (media, container, supports, layer).
456
+ */
457
+ declare function isAtRuleKey(key: string): key is AtRuleKey;
458
458
  /** A nested CSS selector pattern containing the parent reference `&` */
459
459
  type NestedCssSelector = `${string}&${string}`;
460
- /** A CSS media query starting with `@` */
461
- type MediaSelector = `@${string}`;
462
- type NestedStyleKeys = MediaSelector | NestedCssSelector;
460
+ /** A CSS at-rule key for media, container, supports, or layer queries */
461
+ type AtRuleKey = `@media ${string}` | `@container ${string}` | `@supports ${string}` | `@layer ${string}`;
462
+ type NestedStyleKeys = AtRuleKey | NestedCssSelector;
463
463
  /**
464
464
  * Style properties without nesting support.
465
465
  * Includes all standard CSS properties with type-safe value converters,
@@ -468,7 +468,7 @@ type NestedStyleKeys = MediaSelector | NestedCssSelector;
468
468
  * Properties with known units (e.g., width, height, padding) accept numbers
469
469
  * that are automatically converted with their default unit (e.g., px, ms).
470
470
  */
471
- type SimpleStyleProps = { [K in PropsWithUnit]?: CssLike<number | Props[K]> } & { [K in Exclude<keyof Props, PropsWithUnit>]?: CssLike<Props[K]> } & Partial<Record<CssVar, CssLike<string | number>>>;
471
+ type SimpleStyleProps = { [K in PropsWithUnit]?: CssLike<number | Props[K]> } & { [K in Exclude<keyof Props, PropsWithUnit>]?: CssLike<Props[K]> };
472
472
  /**
473
473
  * Full style properties type with support for nested selectors and media queries.
474
474
  * Extends SimpleStyleProps to allow recursive style definitions.
@@ -478,10 +478,10 @@ type SimpleStyleProps = { [K in PropsWithUnit]?: CssLike<number | Props[K]> } &
478
478
  * color: 'blue',
479
479
  * padding: 16,
480
480
  * '&:hover': { color: 'red' },
481
- * '@min-width: 768px': { padding: 24 }
481
+ * '@media (min-width: 768px)': { padding: 24 }
482
482
  * }
483
483
  */
484
- type StyleProps = SimpleStyleProps & { [K in NestedStyleKeys]?: StyleProps | CssLike<string | number> };
484
+ type StyleProps = SimpleStyleProps & { [K in NestedStyleKeys]?: StyleProps | CssLike<string | number> } & Record<string, unknown>;
485
485
  /**
486
486
  * Converts a SimpleStyleProps object to a CSS properties record.
487
487
  * Transforms camelCase property names to kebab-case and applies value converters.
@@ -491,7 +491,7 @@ type StyleProps = SimpleStyleProps & { [K in NestedStyleKeys]?: StyleProps | Css
491
491
  * cssFromProps({ backgroundColor: 'blue', padding: 16 })
492
492
  * // { 'background-color': 'blue', 'padding': '16px' }
493
493
  */
494
- declare function cssFromProps(props: SimpleStyleProps): Record<string, string>;
494
+ declare function cssFromProps(props: SimpleStyleProps & Partial<Record<CssVar, CssLike<number | string>>>): Record<string, string>;
495
495
  //#endregion
496
496
  //#region src/cssObject.d.ts
497
497
  /**
@@ -514,7 +514,8 @@ declare class CssObjectSubBlock {
514
514
  get hash(): string;
515
515
  /**
516
516
  * Converts this block to a CSS string.
517
- * Handles media query wrapping if the selector has media conditions.
517
+ * Handles at-rule wrapping (media, container, supports, layer) if present.
518
+ * Multiple at-rules are nested in order.
518
519
  * @param root - The root selector to substitute for `&`
519
520
  * @returns Formatted CSS string
520
521
  */
@@ -589,7 +590,7 @@ type VariantProps<V extends AllVariants> = {
589
590
  compoundVariants?: CompoundVariant<V>[];
590
591
  };
591
592
  /** Combined type for style props with optional variants */
592
- type MochiCSSProps<V extends AllVariants> = StyleProps & VariantProps<V>;
593
+ type MochiCSSProps<V extends AllVariants> = Omit<StyleProps, "variants" | "compoundVariants" | "defaultVariants"> & VariantProps<V>;
593
594
  /** Utility type to override properties of A with properties of B */
594
595
  type Override<A extends object, B extends object> = B & Omit<A, keyof B>;
595
596
  /** Recursively merges variant types from a tuple, with later types overriding earlier */
@@ -689,6 +690,13 @@ declare class MochiCSS<V extends AllVariants = DefaultVariants> {
689
690
  */
690
691
  static from<V extends AllVariants = DefaultVariants>(object: CSSObject<V>): MochiCSS<V>;
691
692
  }
693
+ /**
694
+ * Merges multiple MochiCSS instances into a single one, combining their
695
+ * class names, variant class names, and default variants.
696
+ * @param instances - The MochiCSS instances to merge
697
+ * @returns A new MochiCSS instance with all styles combined
698
+ */
699
+ declare function mergeMochiCss<V extends AllVariants[]>(instances: MochiCSS<AllVariants>[]): MochiCSS<MergeCSSVariants<V>>;
692
700
  declare function css<V extends AllVariants[]>(...props: { [K in keyof V]: MochiCSSProps<V[K]> | MochiCSS }): MochiCSS<MergeCSSVariants<V>>;
693
701
  //#endregion
694
702
  //#region src/styled.d.ts
@@ -750,5 +758,80 @@ declare class MochiKeyframes {
750
758
  }
751
759
  declare function keyframes(stops: KeyframeStops): MochiKeyframes;
752
760
  //#endregion
753
- export { AllVariants, CSSObject, CompoundVariant, CssLike, CssLikeObject, CssObjectBlock, CssObjectSubBlock, CssVar, CssVarVal, DefaultVariants, type KeyframeStops, KeyframesObject, MergeCSSVariants, MochiCSS, MochiCSSProps, MochiKeyframes, MochiSelector, RefineVariants, type StyleProps, Token, VariantProps, createToken, css, cssFromProps, keyframes, styled };
761
+ //#region src/globalCssObject.d.ts
762
+ type GlobalCssStyles = Record<string, StyleProps>;
763
+ /**
764
+ * CSS object model for global (non-scoped) styles.
765
+ * Accepts a map of CSS selectors to style objects and serializes them
766
+ * as plain CSS rules without class name scoping.
767
+ *
768
+ * @example
769
+ * const obj = new GlobalCssObject({
770
+ * body: { margin: 0 },
771
+ * 'h1': { fontSize: 32 },
772
+ * })
773
+ * obj.asCssString() // "body {\n margin: 0;\n}\n\nh1 {\n font-size: 32px;\n}"
774
+ */
775
+ declare class GlobalCssObject {
776
+ private readonly rules;
777
+ constructor(styles: GlobalCssStyles);
778
+ asCssString(): string;
779
+ }
780
+ //#endregion
781
+ //#region src/globalCss.d.ts
782
+ /**
783
+ * Creates a global CSS definition.
784
+ * Styles are not scoped to any class — they apply to all matching elements.
785
+ *
786
+ * @param styles - Map of CSS selectors to style objects
787
+ *
788
+ * @example
789
+ * globalCss({
790
+ * 'body': { margin: 0, padding: 0 },
791
+ * '*, *::before, *::after': { boxSizing: 'border-box' },
792
+ * })
793
+ */
794
+ declare function globalCss(styles: GlobalCssStyles): void;
795
+ //#endregion
796
+ //#region src/query.d.ts
797
+ interface MediaHelper {
798
+ /** `@media (condition)` */
799
+ (condition: string): AtRuleKey & `@media ${string}`;
800
+ /** `@media (a) and (b) and …` */
801
+ and(...conditions: [string, string, ...string[]]): AtRuleKey & `@media ${string}`;
802
+ /** `@media (a), (b), …` */
803
+ or(...conditions: [string, string, ...string[]]): AtRuleKey & `@media ${string}`;
804
+ /** `@media (prefers-color-scheme: dark)` */
805
+ readonly dark: AtRuleKey & `@media ${string}`;
806
+ /** `@media (prefers-color-scheme: light)` */
807
+ readonly light: AtRuleKey & `@media ${string}`;
808
+ /** `@media (prefers-reduced-motion: no-preference)` */
809
+ readonly motion: AtRuleKey & `@media ${string}`;
810
+ /** `@media print` */
811
+ readonly print: AtRuleKey & `@media ${string}`;
812
+ }
813
+ /** Helper for constructing `@media` at-rule keys. */
814
+ declare const media: MediaHelper;
815
+ interface ContainerHelper {
816
+ /** `@container (condition)` — anonymous container */
817
+ (condition: string): AtRuleKey & `@container ${string}`;
818
+ /** `@container name (condition)` — named container */
819
+ named(name: string, condition: string): AtRuleKey & `@container ${string}`;
820
+ }
821
+ /** Helper for constructing `@container` at-rule keys. */
822
+ declare const container: ContainerHelper;
823
+ interface SupportsHelper {
824
+ /** `@supports (declaration)` */
825
+ (condition: string): AtRuleKey & `@supports ${string}`;
826
+ /** `@supports not (declaration)` */
827
+ not(condition: string): AtRuleKey & `@supports ${string}`;
828
+ /** `@supports (a) and (b) and …` */
829
+ and(...conditions: [string, string, ...string[]]): AtRuleKey & `@supports ${string}`;
830
+ /** `@supports (a) or (b) or …` */
831
+ or(...conditions: [string, string, ...string[]]): AtRuleKey & `@supports ${string}`;
832
+ }
833
+ /** Helper for constructing `@supports` at-rule keys. */
834
+ declare const supports: SupportsHelper;
835
+ //#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 };
754
837
  //# sourceMappingURL=index.d.ts.map