@mochi-css/vanilla 1.1.0 → 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/README.md +145 -94
- package/dist/index.d.mts +67 -27
- package/dist/index.d.ts +67 -26
- package/dist/index.js +861 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +858 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
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
|
|
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
|
|
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)').
|
|
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
|
-
|
|
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
|
|
76
|
+
* @param atRules - Array of full CSS at-rule strings e.g. `"@media (min-width: 768px)"`
|
|
77
77
|
*/
|
|
78
|
-
constructor(cssSelectors?: 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
|
|
108
|
-
* @param
|
|
109
|
-
* @returns A new MochiSelector with the added
|
|
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
|
|
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(
|
|
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
|
|
461
|
-
type
|
|
462
|
-
type NestedStyleKeys =
|
|
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]> }
|
|
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
|
|
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 */
|
|
@@ -792,5 +793,45 @@ declare class GlobalCssObject {
|
|
|
792
793
|
*/
|
|
793
794
|
declare function globalCss(styles: GlobalCssStyles): void;
|
|
794
795
|
//#endregion
|
|
795
|
-
|
|
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 };
|
|
796
837
|
//# sourceMappingURL=index.d.ts.map
|