@rpxl/recast
Advanced tools
Comparing version 3.1.5 to 4.0.0
@@ -1,4 +0,2 @@ | ||
export type { RecastThemeProps } from "./types.js"; | ||
export type { RecastBaseTheme } from "./types.js"; | ||
export * from "./utils/getRecastClasses.js"; | ||
export { createRecastComponent } from "./createRecastComponent.js"; | ||
export type { RecastWithClassNameProps } from "./types.js"; | ||
export { recast } from "./recast.js"; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRecastComponent = void 0; | ||
__exportStar(require("./utils/getRecastClasses.js"), exports); | ||
var createRecastComponent_js_1 = require("./createRecastComponent.js"); | ||
Object.defineProperty(exports, "createRecastComponent", { enumerable: true, get: function () { return createRecastComponent_js_1.createRecastComponent; } }); | ||
exports.recast = void 0; | ||
var recast_js_1 = require("./recast.js"); | ||
Object.defineProperty(exports, "recast", { enumerable: true, get: function () { return recast_js_1.recast; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,70 +0,91 @@ | ||
export type RecastBaseTheme<B extends string> = Partial<Record<B, string | string[]>>; | ||
export type RecastStyles<BaseTheme, V, M> = { | ||
/** | ||
* Recast utility types | ||
*/ | ||
export type ClassNameRecord = Record<string, string | string[]>; | ||
export type MergeFn = (classes: string | string[], className?: string) => string; | ||
export type Nullish = null | undefined; | ||
export type Leaves<T> = { | ||
[K in keyof T]: T[K]; | ||
}[keyof T]; | ||
export type RecastWithClassNameProps<Props extends { | ||
[K in keyof Props]: string; | ||
}> = { | ||
/** Recast class object properties */ | ||
rcx?: { | ||
[P in keyof Props]?: string; | ||
}; | ||
}; | ||
export type MaybeVariants<V> = keyof V extends Nullish ? "variants" : ""; | ||
export type ExtractModifierProps<M> = { | ||
[K in keyof M]?: boolean; | ||
}; | ||
export type ExtractVariantProps<V> = V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] : never; | ||
} : never; | ||
export type RecastProps<T> = Leaves<T> extends Nullish ? any : { | ||
rcx?: Leaves<T>; | ||
}; | ||
export type RecastStyles<V, M, P> = { | ||
/** Default values for variants and modifiers */ | ||
defaults?: { | ||
/** Variants stuff */ | ||
variants?: Omit<{ | ||
[K in keyof V]?: keyof V[K]; | ||
}, MaybeVariants<V>>; | ||
/** Modifier stuff */ | ||
modifiers?: (keyof M)[]; | ||
}; | ||
base?: BaseTheme; | ||
/** | ||
* Base style properties | ||
* These will be applied. | ||
*/ | ||
base?: keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}; | ||
/** Yadda yadda */ | ||
variants?: { | ||
[K in keyof V]: Record<keyof V[K], BaseTheme>; | ||
[K in keyof V]: Record<keyof V[K], keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}>; | ||
}; | ||
modifiers?: { | ||
[K in keyof M]: BaseTheme; | ||
[K in keyof M]: keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}; | ||
}; | ||
conditionals?: Conditional<BaseTheme, V, M>[]; | ||
conditionals?: { | ||
variants?: V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] | Array<keyof V[K]> : never; | ||
} : never; | ||
modifiers?: keyof M | (keyof M)[]; | ||
className: keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}; | ||
}[]; | ||
}; | ||
export type Nullish = null | undefined; | ||
export type MaybeVariants<V> = keyof V extends Nullish ? "variants" : ""; | ||
export type Defaults<V, M> = { | ||
variants?: Omit<{ | ||
[K in keyof V]?: keyof V[K]; | ||
}, MaybeVariants<V>>; | ||
modifiers?: (keyof M)[]; | ||
}; | ||
export type Variants<BaseTheme, V> = { | ||
[K in keyof V]: Partial<Record<keyof V[K], BaseTheme>>; | ||
}; | ||
export type ExtractVariantProps<V> = V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] : never; | ||
} : never; | ||
export type Modifiers<BaseTheme, M> = { | ||
[K in keyof M]: BaseTheme; | ||
}; | ||
export type ExtractModifierProps<M> = { | ||
[K in keyof M]?: boolean; | ||
}; | ||
export type Conditional<BaseTheme, V, M> = { | ||
variants?: V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] | Array<keyof V[K]> : never; | ||
} : never; | ||
modifiers?: keyof M | (keyof M)[]; | ||
classes: Partial<Record<keyof BaseTheme, string | string[]>>; | ||
}; | ||
export type Conditionals<BaseTheme, V, M> = Conditional<BaseTheme, V, M>[]; | ||
/** | ||
* LOOSLEY TYPED | ||
* Loosley typed for usage as arguments to different utility methods | ||
*/ | ||
export type ClassNameRecord = Record<string, string | string[]>; | ||
export type RecastBaseStyles = Record<string, string | string[]>; | ||
export type RecastConditionalProps = { | ||
variants?: Record<string, string | string[]>; | ||
modifiers?: string | string[]; | ||
classes: Record<string, string | string[]>; | ||
export type RelaxedStyles = { | ||
defaults?: RelaxedDefaults; | ||
base?: RelaxedBase; | ||
variants?: Record<string, Record<string, string | string[] | Record<string, string | string[]>>>; | ||
modifiers?: Record<string, string | string[] | Record<string, string | string[]>>; | ||
conditionals?: RelaxedCondiiton[]; | ||
}; | ||
export type RecastThemeProps = { | ||
themekey?: string; | ||
export type RelaxedDefaults = { | ||
variants?: Record<string, string>; | ||
modifiers?: string[]; | ||
}; | ||
export type Styles = { | ||
defaults?: { | ||
variants?: Record<string, string>; | ||
modifiers?: string[]; | ||
}; | ||
base?: RecastBaseStyles; | ||
variants?: Record<string, Record<string, Record<string, string | string[]>>>; | ||
modifiers?: Record<string, Record<string, string | string[]>>; | ||
conditionals?: Array<RecastConditionalProps>; | ||
export type RelaxedBase = string | string[] | Record<string, string | string[]>; | ||
export type RelaxedCondiiton = { | ||
variants?: Record<string, string | string[]>; | ||
modifiers?: string | string[]; | ||
className: string | string[] | Record<string, string | string[]>; | ||
}; | ||
export type RelaxedRecastStyleProps = { | ||
className: string; | ||
rcx: ClassNameRecord; | ||
}; | ||
export type RelaxedVariantProps = Record<string, string>; | ||
export type RelaxedModifierProps = string[]; |
@@ -1,8 +0,8 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedModifierProps, RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
variants?: RecastThemeProps["variants"]; | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
export declare const getConditionalClasses: ({ theme, variants, modifiers, }: Props) => {}; | ||
export declare const getConditionalClasses: ({ styles, variants, modifiers }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -5,25 +5,29 @@ "use strict"; | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const constants_js_1 = require("../constants.js"); | ||
const validateConditionalModifiers_js_1 = require("./validateConditionalModifiers.js"); | ||
const validateConditionalVariants_js_1 = require("./validateConditionalVariants.js"); | ||
const validateConditionalModifiers_js_1 = require("./validateConditionalModifiers.js"); | ||
const getConditionalClasses = ({ theme = {}, variants = {}, modifiers = [], }) => { | ||
const getConditionalClasses = ({ styles = {}, variants = {}, modifiers = [] }) => { | ||
// If no conditions to check then get out of here | ||
if (!theme.conditionals) | ||
return {}; | ||
const conditionalClasses = theme.conditionals.reduce((acc, curr) => { | ||
if (!styles.conditionals) | ||
return constants_js_1.RECAST_STYLE_PROPS; | ||
const conditionalClasses = styles.conditionals.reduce((acc, condition) => { | ||
const hasConditionalVariants = (0, validateConditionalVariants_js_1.validateConditionalVariants)({ | ||
condition: curr, | ||
condition, | ||
variants, | ||
defaults: theme.defaults?.variants, | ||
defaults: styles.defaults?.variants, | ||
}); | ||
const hasConditionalModifiers = (0, validateConditionalModifiers_js_1.validateConditionalModifiers)({ | ||
condition: curr, | ||
condition, | ||
modifiers, | ||
defaults: theme.defaults?.modifiers, | ||
defaults: styles.defaults?.modifiers, | ||
}); | ||
// Only merge conditional classes if all conditions are met | ||
if (hasConditionalVariants && hasConditionalModifiers) { | ||
return (0, mergeClassNames_js_1.mergeClassNames)(acc, curr.classes); | ||
if (typeof condition.className === "string" || Array.isArray(condition.className)) { | ||
return { className: (0, mergeClassNames_js_1.mergeStringClassNames)(acc.className, condition.className), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: (0, mergeClassNames_js_1.mergeObjectClassNames)(acc.rcx, condition.className) }; | ||
} | ||
return acc; | ||
}, {}); | ||
}, constants_js_1.RECAST_STYLE_PROPS); | ||
return conditionalClasses; | ||
@@ -30,0 +34,0 @@ }; |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedModifierProps, RelaxedStyles } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
styles: RelaxedStyles; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
export declare const getDefaultModifierClasses: ({ theme, modifiers, }: Props) => {}; | ||
export declare const getDefaultModifierClasses: ({ styles, modifiers }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -5,17 +5,19 @@ "use strict"; | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const getDefaultModifierClasses = ({ theme = {}, modifiers = [], }) => { | ||
if (!theme.modifiers) | ||
return {}; | ||
if (theme.defaults?.modifiers) { | ||
const defaultModifierClasses = theme.defaults.modifiers.reduce((acc, curr) => { | ||
if (!modifiers.includes(curr)) { | ||
return (0, mergeClassNames_js_1.mergeClassNames)(acc, theme.modifiers?.[curr]); | ||
} | ||
const constants_js_1 = require("../constants.js"); | ||
const getDefaultModifierClasses = ({ styles = {}, modifiers = [] }) => { | ||
const defaultModifiers = styles.defaults?.modifiers; | ||
if (!defaultModifiers) | ||
return constants_js_1.RECAST_STYLE_PROPS; | ||
return defaultModifiers.reduce((acc, modifier) => { | ||
const defaultModifierStyles = styles.modifiers?.[modifier]; | ||
if (!defaultModifierStyles || modifiers.includes(modifier)) { | ||
return acc; | ||
}, {}); | ||
return defaultModifierClasses; | ||
} | ||
return {}; | ||
} | ||
if (typeof defaultModifierStyles === "string" || Array.isArray(defaultModifierStyles)) { | ||
return { className: (0, mergeClassNames_js_1.mergeStringClassNames)(acc.className, defaultModifierStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: (0, mergeClassNames_js_1.mergeObjectClassNames)(acc.rcx, defaultModifierStyles) }; | ||
}, constants_js_1.RECAST_STYLE_PROPS); | ||
}; | ||
exports.getDefaultModifierClasses = getDefaultModifierClasses; | ||
//# sourceMappingURL=getDefaultModifierClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
variants?: RecastThemeProps["variants"]; | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
}; | ||
export declare const getDefaultVariantClasses: ({ theme, variants, }: Props) => {}; | ||
export declare const getDefaultVariantClasses: ({ styles, variants }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -5,20 +5,21 @@ "use strict"; | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const getDefaultVariantClasses = ({ theme = {}, variants = {}, }) => { | ||
if (!theme.variants) | ||
return {}; | ||
if (theme.defaults?.variants) { | ||
const defaultVariantKeys = Object.keys(theme.defaults.variants); | ||
const defaultVariantClasses = defaultVariantKeys.reduce((acc, curr) => { | ||
if (!variants?.[curr]) { | ||
if (theme.defaults?.variants?.[curr]) { | ||
return (0, mergeClassNames_js_1.mergeClassNames)(acc, theme.variants?.[curr][theme.defaults.variants[curr]]); | ||
} | ||
} | ||
const constants_js_1 = require("../constants.js"); | ||
const getDefaultVariantClasses = ({ styles = {}, variants = {} }) => { | ||
const defaultVariants = styles.defaults?.variants; | ||
if (!defaultVariants) | ||
return constants_js_1.RECAST_STYLE_PROPS; | ||
return Object.keys(defaultVariants).reduce((acc, variant) => { | ||
const defaultVariantStyles = styles.variants?.[variant]?.[defaultVariants[variant]]; | ||
// Don't continue if no default variant styles are | ||
// found or a variant has been set | ||
if (!defaultVariantStyles || variants[variant]) { | ||
return acc; | ||
}, {}); | ||
return defaultVariantClasses; | ||
} | ||
return {}; | ||
} | ||
if (typeof defaultVariantStyles === "string" || Array.isArray(defaultVariantStyles)) { | ||
return { className: (0, mergeClassNames_js_1.mergeStringClassNames)(acc.className, defaultVariantStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: (0, mergeClassNames_js_1.mergeObjectClassNames)(acc.rcx, defaultVariantStyles) }; | ||
}, constants_js_1.RECAST_STYLE_PROPS); | ||
}; | ||
exports.getDefaultVariantClasses = getDefaultVariantClasses; | ||
//# sourceMappingURL=getDefaultVariantClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedModifierProps, RelaxedStyles } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
styles: RelaxedStyles; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
export declare const getModifierClasses: ({ theme, modifiers }: Props) => {}; | ||
export declare const getModifierClasses: ({ styles, modifiers }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -5,11 +5,18 @@ "use strict"; | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const getModifierClasses = ({ theme = {}, modifiers = [] }) => { | ||
if (!theme.modifiers) | ||
return {}; | ||
const modifierClasses = modifiers.reduce((acc, curr) => { | ||
return (0, mergeClassNames_js_1.mergeClassNames)(acc, theme.modifiers?.[curr]); | ||
}, {}); | ||
return modifierClasses; | ||
const constants_js_1 = require("../constants.js"); | ||
const getModifierClasses = ({ styles = {}, modifiers = [] }) => { | ||
if (!styles.modifiers) | ||
return constants_js_1.RECAST_STYLE_PROPS; | ||
return modifiers.reduce((acc, modifier) => { | ||
const modifierStyles = styles.modifiers?.[modifier]; | ||
if (!modifierStyles) { | ||
return acc; | ||
} | ||
if (typeof modifierStyles === "string" || Array.isArray(modifierStyles)) { | ||
return { className: (0, mergeClassNames_js_1.mergeStringClassNames)(acc.className, modifierStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: (0, mergeClassNames_js_1.mergeObjectClassNames)(acc.rcx, modifierStyles) }; | ||
}, constants_js_1.RECAST_STYLE_PROPS); | ||
}; | ||
exports.getModifierClasses = getModifierClasses; | ||
//# sourceMappingURL=getModifierClasses.js.map |
@@ -1,10 +0,12 @@ | ||
import type { RecastBaseStyles, RecastThemeProps } from "../types.js"; | ||
type RecastClasses<K> = Record<keyof K, string> | undefined; | ||
import { RelaxedModifierProps, RelaxedRecastStyleProps, RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type RecastThemeProps = { | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
/** | ||
* Returns an object containing the CSS classes generated from the provided theme, variants, and modifiers. | ||
* @template K - The type of the base styles object. | ||
* @param {RecastThemeProps} props - An object containing the theme key, variants, and modifiers. | ||
* @returns {RecastClasses<K>} - An object containing the generated CSS classes. | ||
* Returns an object containing the CSS classes | ||
* generated from the provided styles, variants, and modifiers. | ||
*/ | ||
export declare const getRecastClasses: <K extends RecastBaseStyles>({ themekey, variants, modifiers, }: RecastThemeProps) => RecastClasses<K>; | ||
export declare function getRecastClasses({ styles, variants, modifiers }: RecastThemeProps): RelaxedRecastStyleProps; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRecastClasses = void 0; | ||
const recastThemeInstance_js_1 = require("../recastThemeInstance.js"); | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const constants_js_1 = require("../constants.js"); | ||
const getBaseClasses_js_1 = require("./getBaseClasses.js"); | ||
const getConditionalClasses_js_1 = require("./getConditionalClasses.js"); | ||
const getDefaultModifierClasses_js_1 = require("./getDefaultModifierClasses.js"); | ||
const getDefaultVariantClasses_js_1 = require("./getDefaultVariantClasses.js"); | ||
const getModifierClasses_js_1 = require("./getModifierClasses.js"); | ||
const getVariantClasses_js_1 = require("./getVariantClasses.js"); | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const getDefaultVariantClasses_js_1 = require("./getDefaultVariantClasses.js"); | ||
const getDefaultModifierClasses_js_1 = require("./getDefaultModifierClasses.js"); | ||
const getConditionalClasses_js_1 = require("./getConditionalClasses.js"); | ||
/** | ||
* Returns an object containing the CSS classes generated from the provided theme, variants, and modifiers. | ||
* @template K - The type of the base styles object. | ||
* @param {RecastThemeProps} props - An object containing the theme key, variants, and modifiers. | ||
* @returns {RecastClasses<K>} - An object containing the generated CSS classes. | ||
* Returns an object containing the CSS classes | ||
* generated from the provided styles, variants, and modifiers. | ||
*/ | ||
const getRecastClasses = ({ themekey, variants, modifiers, }) => { | ||
const theme = (0, recastThemeInstance_js_1.getTheme)(themekey); | ||
const variantClasses = (0, getVariantClasses_js_1.getVariantClasses)({ | ||
theme, | ||
variants, | ||
}); | ||
const defaultVariantClasses = (0, getDefaultVariantClasses_js_1.getDefaultVariantClasses)({ | ||
theme, | ||
variants, | ||
}); | ||
const modifierClasses = (0, getModifierClasses_js_1.getModifierClasses)({ | ||
theme, | ||
modifiers, | ||
}); | ||
const defaultModifierClasses = (0, getDefaultModifierClasses_js_1.getDefaultModifierClasses)({ | ||
theme, | ||
modifiers, | ||
}); | ||
const conditionalClasses = (0, getConditionalClasses_js_1.getConditionalClasses)({ | ||
theme, | ||
variants, | ||
modifiers, | ||
}); | ||
const classes = [ | ||
theme?.base, | ||
function getRecastClasses({ styles, variants, modifiers }) { | ||
const baseClasses = (0, getBaseClasses_js_1.getBaseClasses)({ styles }); | ||
const variantClasses = (0, getVariantClasses_js_1.getVariantClasses)({ styles, variants }); | ||
const defaultVariantClasses = (0, getDefaultVariantClasses_js_1.getDefaultVariantClasses)({ styles, variants }); | ||
const modifierClasses = (0, getModifierClasses_js_1.getModifierClasses)({ styles, modifiers }); | ||
const defaultModifierClasses = (0, getDefaultModifierClasses_js_1.getDefaultModifierClasses)({ styles, modifiers }); | ||
const conditionalClasses = (0, getConditionalClasses_js_1.getConditionalClasses)({ styles, variants, modifiers }); | ||
const result = [ | ||
baseClasses, | ||
variantClasses, | ||
@@ -48,7 +31,10 @@ defaultVariantClasses, | ||
].reduce((acc, curr) => { | ||
return (0, mergeClassNames_js_1.mergeClassNames)(acc, curr); | ||
}, {}); | ||
return classes; | ||
}; | ||
return { | ||
className: (0, mergeClassNames_js_1.mergeStringClassNames)(acc.className, curr.className), | ||
rcx: (0, mergeClassNames_js_1.mergeObjectClassNames)(acc.rcx, curr.rcx), | ||
}; | ||
}, constants_js_1.RECAST_STYLE_PROPS); | ||
return { className: result.className, rcx: result.rcx }; | ||
} | ||
exports.getRecastClasses = getRecastClasses; | ||
//# sourceMappingURL=getRecastClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
variants?: RecastThemeProps["variants"]; | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
}; | ||
export declare const getVariantClasses: ({ theme, variants }: Props) => {}; | ||
export declare const getVariantClasses: ({ styles, variants }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -5,12 +5,18 @@ "use strict"; | ||
const mergeClassNames_js_1 = require("./mergeClassNames.js"); | ||
const getVariantClasses = ({ theme = {}, variants = {} }) => { | ||
if (!theme.variants) | ||
return {}; | ||
const variantKeys = Object.keys(variants); | ||
const variantClasses = variantKeys.reduce((acc, curr) => { | ||
return (0, mergeClassNames_js_1.mergeClassNames)(acc, theme.variants?.[curr][variants[curr]]); | ||
}, {}); | ||
return variantClasses; | ||
const constants_js_1 = require("../constants.js"); | ||
const getVariantClasses = ({ styles = {}, variants = {} }) => { | ||
if (!styles.variants) | ||
return constants_js_1.RECAST_STYLE_PROPS; | ||
return Object.keys(variants).reduce((acc, variant) => { | ||
const variantStyles = styles.variants?.[variant][variants[variant]]; | ||
if (!variantStyles) { | ||
return acc; | ||
} | ||
if (typeof variantStyles === "string" || Array.isArray(variantStyles)) { | ||
return { className: (0, mergeClassNames_js_1.mergeStringClassNames)(acc.className, variantStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: (0, mergeClassNames_js_1.mergeObjectClassNames)(acc.rcx, variantStyles) }; | ||
}, constants_js_1.RECAST_STYLE_PROPS); | ||
}; | ||
exports.getVariantClasses = getVariantClasses; | ||
//# sourceMappingURL=getVariantClasses.js.map |
@@ -17,3 +17,3 @@ import { ClassNameRecord } from "../types.js"; | ||
*/ | ||
export declare const mergeValues: (objValue?: string | string[], value?: string | string[]) => string; | ||
export declare const mergeStringClassNames: (objValue?: string | string[], value?: string | string[]) => string; | ||
/** | ||
@@ -28,2 +28,2 @@ * Merges class names from a target and source object, normalizing and concatenating them. | ||
*/ | ||
export declare const mergeClassNames: (target?: ClassNameRecord, source?: ClassNameRecord) => ClassNameRecord; | ||
export declare const mergeObjectClassNames: (target?: ClassNameRecord, source?: ClassNameRecord) => ClassNameRecord; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mergeClassNames = exports.mergeValues = exports.normalizeValue = void 0; | ||
exports.mergeObjectClassNames = exports.mergeStringClassNames = exports.normalizeValue = void 0; | ||
/** | ||
@@ -24,10 +24,10 @@ * Normalizes the given classes by removing leading and trailing whitespace and joining them with a space. | ||
*/ | ||
const mergeValues = (objValue, value) => { | ||
if (!!objValue && !!value) { | ||
const mergeStringClassNames = (objValue, value) => { | ||
if (objValue && value) { | ||
return `${(0, exports.normalizeValue)(objValue)} ${(0, exports.normalizeValue)(value)}`; | ||
} | ||
else if (!!objValue) { | ||
else if (objValue) { | ||
return (0, exports.normalizeValue)(objValue); | ||
} | ||
else if (!!value) { | ||
else if (value) { | ||
return (0, exports.normalizeValue)(value); | ||
@@ -39,3 +39,3 @@ } | ||
}; | ||
exports.mergeValues = mergeValues; | ||
exports.mergeStringClassNames = mergeStringClassNames; | ||
/** | ||
@@ -50,3 +50,3 @@ * Merges class names from a target and source object, normalizing and concatenating them. | ||
*/ | ||
const mergeClassNames = (target = {}, source = {}) => { | ||
const mergeObjectClassNames = (target = {}, source = {}) => { | ||
/** | ||
@@ -59,19 +59,15 @@ * Normalizes the class names in an object by removing leading and trailing whitespace. | ||
const normalizeTarget = (x) => { | ||
const keys = Object.keys(x); | ||
if (keys?.length) { | ||
return keys.reduce((acc, curr) => { | ||
return { ...acc, [curr]: (0, exports.normalizeValue)(x[curr]) }; | ||
}, {}); | ||
} | ||
return x; | ||
return Object.keys(x).reduce((acc, curr) => { | ||
return { ...acc, [curr]: (0, exports.normalizeValue)(x[curr]) }; | ||
}, {}); | ||
}; | ||
return Object.keys(source).reduce((acc, curr) => { | ||
if (acc[curr] && source[curr]) { | ||
return { ...acc, [curr]: (0, exports.mergeValues)(acc[curr], source[curr]) }; | ||
return Object.entries(source).reduce((acc, [key, value]) => { | ||
if (acc[key] && value) { | ||
return { ...acc, [key]: (0, exports.mergeStringClassNames)(acc[key], value) }; | ||
} | ||
else if (acc[curr]) { | ||
return { ...acc, [curr]: (0, exports.normalizeValue)(acc[curr]) }; | ||
else if (acc[key]) { | ||
return { ...acc, [key]: (0, exports.normalizeValue)(acc[key]) }; | ||
} | ||
else if (source[curr]) { | ||
return { ...acc, [curr]: (0, exports.normalizeValue)(source[curr]) }; | ||
else if (value) { | ||
return { ...acc, [key]: (0, exports.normalizeValue)(value) }; | ||
} | ||
@@ -81,3 +77,3 @@ return acc; | ||
}; | ||
exports.mergeClassNames = mergeClassNames; | ||
exports.mergeObjectClassNames = mergeObjectClassNames; | ||
//# sourceMappingURL=mergeClassNames.js.map |
@@ -1,5 +0,5 @@ | ||
import { RecastConditionalProps, RecastThemeProps } from "../types.js"; | ||
import { RelaxedCondiiton, RelaxedModifierProps } from "../types.js"; | ||
type ValidateConditionProps = { | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
condition: RecastConditionalProps; | ||
modifiers?: RelaxedModifierProps; | ||
condition: RelaxedCondiiton; | ||
defaults?: string[]; | ||
@@ -14,3 +14,3 @@ }; | ||
*/ | ||
export declare const validateConditionalModifiers: ({ condition, modifiers, defaults, }: ValidateConditionProps) => boolean | undefined; | ||
export declare const validateConditionalModifiers: ({ condition, modifiers, defaults }: ValidateConditionProps) => boolean | undefined; | ||
export {}; |
@@ -11,3 +11,3 @@ "use strict"; | ||
*/ | ||
const validateConditionalModifiers = ({ condition, modifiers, defaults, }) => { | ||
const validateConditionalModifiers = ({ condition, modifiers, defaults }) => { | ||
// Always return true if modifier conditions are empty | ||
@@ -14,0 +14,0 @@ if (!condition.modifiers?.length) { |
@@ -1,5 +0,5 @@ | ||
import { RecastConditionalProps, RecastThemeProps } from "../types.js"; | ||
import { RelaxedCondiiton, RelaxedVariantProps } from "../types.js"; | ||
type ValidateConditionProps = { | ||
variants?: RecastThemeProps["variants"]; | ||
condition: RecastConditionalProps; | ||
variants?: RelaxedVariantProps; | ||
condition: RelaxedCondiiton; | ||
defaults?: Record<string, string>; | ||
@@ -14,3 +14,3 @@ }; | ||
*/ | ||
export declare const validateConditionalVariants: ({ condition, variants, defaults, }: ValidateConditionProps) => boolean; | ||
export declare const validateConditionalVariants: ({ condition, variants, defaults }: ValidateConditionProps) => boolean; | ||
export {}; |
@@ -11,3 +11,3 @@ "use strict"; | ||
*/ | ||
const validateConditionalVariants = ({ condition, variants, defaults, }) => { | ||
const validateConditionalVariants = ({ condition, variants, defaults }) => { | ||
const conditionalVariantKeys = Object.keys(condition.variants || {}); | ||
@@ -14,0 +14,0 @@ // Always return true if variant conditions are empty |
@@ -1,4 +0,2 @@ | ||
export type { RecastThemeProps } from "./types.js"; | ||
export type { RecastBaseTheme } from "./types.js"; | ||
export * from "./utils/getRecastClasses.js"; | ||
export { createRecastComponent } from "./createRecastComponent.js"; | ||
export type { RecastWithClassNameProps } from "./types.js"; | ||
export { recast } from "./recast.js"; |
@@ -1,3 +0,2 @@ | ||
export * from "./utils/getRecastClasses.js"; | ||
export { createRecastComponent } from "./createRecastComponent.js"; | ||
export { recast } from "./recast.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,70 +0,91 @@ | ||
export type RecastBaseTheme<B extends string> = Partial<Record<B, string | string[]>>; | ||
export type RecastStyles<BaseTheme, V, M> = { | ||
/** | ||
* Recast utility types | ||
*/ | ||
export type ClassNameRecord = Record<string, string | string[]>; | ||
export type MergeFn = (classes: string | string[], className?: string) => string; | ||
export type Nullish = null | undefined; | ||
export type Leaves<T> = { | ||
[K in keyof T]: T[K]; | ||
}[keyof T]; | ||
export type RecastWithClassNameProps<Props extends { | ||
[K in keyof Props]: string; | ||
}> = { | ||
/** Recast class object properties */ | ||
rcx?: { | ||
[P in keyof Props]?: string; | ||
}; | ||
}; | ||
export type MaybeVariants<V> = keyof V extends Nullish ? "variants" : ""; | ||
export type ExtractModifierProps<M> = { | ||
[K in keyof M]?: boolean; | ||
}; | ||
export type ExtractVariantProps<V> = V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] : never; | ||
} : never; | ||
export type RecastProps<T> = Leaves<T> extends Nullish ? any : { | ||
rcx?: Leaves<T>; | ||
}; | ||
export type RecastStyles<V, M, P> = { | ||
/** Default values for variants and modifiers */ | ||
defaults?: { | ||
/** Variants stuff */ | ||
variants?: Omit<{ | ||
[K in keyof V]?: keyof V[K]; | ||
}, MaybeVariants<V>>; | ||
/** Modifier stuff */ | ||
modifiers?: (keyof M)[]; | ||
}; | ||
base?: BaseTheme; | ||
/** | ||
* Base style properties | ||
* These will be applied. | ||
*/ | ||
base?: keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}; | ||
/** Yadda yadda */ | ||
variants?: { | ||
[K in keyof V]: Record<keyof V[K], BaseTheme>; | ||
[K in keyof V]: Record<keyof V[K], keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}>; | ||
}; | ||
modifiers?: { | ||
[K in keyof M]: BaseTheme; | ||
[K in keyof M]: keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}; | ||
}; | ||
conditionals?: Conditional<BaseTheme, V, M>[]; | ||
conditionals?: { | ||
variants?: V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] | Array<keyof V[K]> : never; | ||
} : never; | ||
modifiers?: keyof M | (keyof M)[]; | ||
className: keyof NonNullable<Leaves<P>> extends Nullish ? string | string[] : string | string[] | { | ||
[K in keyof NonNullable<Leaves<P>>]: string | string[]; | ||
}; | ||
}[]; | ||
}; | ||
export type Nullish = null | undefined; | ||
export type MaybeVariants<V> = keyof V extends Nullish ? "variants" : ""; | ||
export type Defaults<V, M> = { | ||
variants?: Omit<{ | ||
[K in keyof V]?: keyof V[K]; | ||
}, MaybeVariants<V>>; | ||
modifiers?: (keyof M)[]; | ||
}; | ||
export type Variants<BaseTheme, V> = { | ||
[K in keyof V]: Partial<Record<keyof V[K], BaseTheme>>; | ||
}; | ||
export type ExtractVariantProps<V> = V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] : never; | ||
} : never; | ||
export type Modifiers<BaseTheme, M> = { | ||
[K in keyof M]: BaseTheme; | ||
}; | ||
export type ExtractModifierProps<M> = { | ||
[K in keyof M]?: boolean; | ||
}; | ||
export type Conditional<BaseTheme, V, M> = { | ||
variants?: V extends object ? { | ||
[K in keyof V]?: K extends string ? keyof V[K] | Array<keyof V[K]> : never; | ||
} : never; | ||
modifiers?: keyof M | (keyof M)[]; | ||
classes: Partial<Record<keyof BaseTheme, string | string[]>>; | ||
}; | ||
export type Conditionals<BaseTheme, V, M> = Conditional<BaseTheme, V, M>[]; | ||
/** | ||
* LOOSLEY TYPED | ||
* Loosley typed for usage as arguments to different utility methods | ||
*/ | ||
export type ClassNameRecord = Record<string, string | string[]>; | ||
export type RecastBaseStyles = Record<string, string | string[]>; | ||
export type RecastConditionalProps = { | ||
variants?: Record<string, string | string[]>; | ||
modifiers?: string | string[]; | ||
classes: Record<string, string | string[]>; | ||
export type RelaxedStyles = { | ||
defaults?: RelaxedDefaults; | ||
base?: RelaxedBase; | ||
variants?: Record<string, Record<string, string | string[] | Record<string, string | string[]>>>; | ||
modifiers?: Record<string, string | string[] | Record<string, string | string[]>>; | ||
conditionals?: RelaxedCondiiton[]; | ||
}; | ||
export type RecastThemeProps = { | ||
themekey?: string; | ||
export type RelaxedDefaults = { | ||
variants?: Record<string, string>; | ||
modifiers?: string[]; | ||
}; | ||
export type Styles = { | ||
defaults?: { | ||
variants?: Record<string, string>; | ||
modifiers?: string[]; | ||
}; | ||
base?: RecastBaseStyles; | ||
variants?: Record<string, Record<string, Record<string, string | string[]>>>; | ||
modifiers?: Record<string, Record<string, string | string[]>>; | ||
conditionals?: Array<RecastConditionalProps>; | ||
export type RelaxedBase = string | string[] | Record<string, string | string[]>; | ||
export type RelaxedCondiiton = { | ||
variants?: Record<string, string | string[]>; | ||
modifiers?: string | string[]; | ||
className: string | string[] | Record<string, string | string[]>; | ||
}; | ||
export type RelaxedRecastStyleProps = { | ||
className: string; | ||
rcx: ClassNameRecord; | ||
}; | ||
export type RelaxedVariantProps = Record<string, string>; | ||
export type RelaxedModifierProps = string[]; |
@@ -1,8 +0,8 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedModifierProps, RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
variants?: RecastThemeProps["variants"]; | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
export declare const getConditionalClasses: ({ theme, variants, modifiers, }: Props) => {}; | ||
export declare const getConditionalClasses: ({ styles, variants, modifiers }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -1,27 +0,31 @@ | ||
import { mergeClassNames } from "./mergeClassNames.js"; | ||
import { mergeObjectClassNames, mergeStringClassNames } from "./mergeClassNames.js"; | ||
import { RECAST_STYLE_PROPS } from "../constants.js"; | ||
import { validateConditionalModifiers } from "./validateConditionalModifiers.js"; | ||
import { validateConditionalVariants } from "./validateConditionalVariants.js"; | ||
import { validateConditionalModifiers } from "./validateConditionalModifiers.js"; | ||
export const getConditionalClasses = ({ theme = {}, variants = {}, modifiers = [], }) => { | ||
export const getConditionalClasses = ({ styles = {}, variants = {}, modifiers = [] }) => { | ||
// If no conditions to check then get out of here | ||
if (!theme.conditionals) | ||
return {}; | ||
const conditionalClasses = theme.conditionals.reduce((acc, curr) => { | ||
if (!styles.conditionals) | ||
return RECAST_STYLE_PROPS; | ||
const conditionalClasses = styles.conditionals.reduce((acc, condition) => { | ||
const hasConditionalVariants = validateConditionalVariants({ | ||
condition: curr, | ||
condition, | ||
variants, | ||
defaults: theme.defaults?.variants, | ||
defaults: styles.defaults?.variants, | ||
}); | ||
const hasConditionalModifiers = validateConditionalModifiers({ | ||
condition: curr, | ||
condition, | ||
modifiers, | ||
defaults: theme.defaults?.modifiers, | ||
defaults: styles.defaults?.modifiers, | ||
}); | ||
// Only merge conditional classes if all conditions are met | ||
if (hasConditionalVariants && hasConditionalModifiers) { | ||
return mergeClassNames(acc, curr.classes); | ||
if (typeof condition.className === "string" || Array.isArray(condition.className)) { | ||
return { className: mergeStringClassNames(acc.className, condition.className), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: mergeObjectClassNames(acc.rcx, condition.className) }; | ||
} | ||
return acc; | ||
}, {}); | ||
}, RECAST_STYLE_PROPS); | ||
return conditionalClasses; | ||
}; | ||
//# sourceMappingURL=getConditionalClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedModifierProps, RelaxedStyles } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
styles: RelaxedStyles; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
export declare const getDefaultModifierClasses: ({ theme, modifiers, }: Props) => {}; | ||
export declare const getDefaultModifierClasses: ({ styles, modifiers }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -1,16 +0,18 @@ | ||
import { mergeClassNames } from "./mergeClassNames.js"; | ||
export const getDefaultModifierClasses = ({ theme = {}, modifiers = [], }) => { | ||
if (!theme.modifiers) | ||
return {}; | ||
if (theme.defaults?.modifiers) { | ||
const defaultModifierClasses = theme.defaults.modifiers.reduce((acc, curr) => { | ||
if (!modifiers.includes(curr)) { | ||
return mergeClassNames(acc, theme.modifiers?.[curr]); | ||
} | ||
import { mergeObjectClassNames, mergeStringClassNames } from "./mergeClassNames.js"; | ||
import { RECAST_STYLE_PROPS } from "../constants.js"; | ||
export const getDefaultModifierClasses = ({ styles = {}, modifiers = [] }) => { | ||
const defaultModifiers = styles.defaults?.modifiers; | ||
if (!defaultModifiers) | ||
return RECAST_STYLE_PROPS; | ||
return defaultModifiers.reduce((acc, modifier) => { | ||
const defaultModifierStyles = styles.modifiers?.[modifier]; | ||
if (!defaultModifierStyles || modifiers.includes(modifier)) { | ||
return acc; | ||
}, {}); | ||
return defaultModifierClasses; | ||
} | ||
return {}; | ||
} | ||
if (typeof defaultModifierStyles === "string" || Array.isArray(defaultModifierStyles)) { | ||
return { className: mergeStringClassNames(acc.className, defaultModifierStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: mergeObjectClassNames(acc.rcx, defaultModifierStyles) }; | ||
}, RECAST_STYLE_PROPS); | ||
}; | ||
//# sourceMappingURL=getDefaultModifierClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
variants?: RecastThemeProps["variants"]; | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
}; | ||
export declare const getDefaultVariantClasses: ({ theme, variants, }: Props) => {}; | ||
export declare const getDefaultVariantClasses: ({ styles, variants }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -1,19 +0,20 @@ | ||
import { mergeClassNames } from "./mergeClassNames.js"; | ||
export const getDefaultVariantClasses = ({ theme = {}, variants = {}, }) => { | ||
if (!theme.variants) | ||
return {}; | ||
if (theme.defaults?.variants) { | ||
const defaultVariantKeys = Object.keys(theme.defaults.variants); | ||
const defaultVariantClasses = defaultVariantKeys.reduce((acc, curr) => { | ||
if (!variants?.[curr]) { | ||
if (theme.defaults?.variants?.[curr]) { | ||
return mergeClassNames(acc, theme.variants?.[curr][theme.defaults.variants[curr]]); | ||
} | ||
} | ||
import { mergeObjectClassNames, mergeStringClassNames } from "./mergeClassNames.js"; | ||
import { RECAST_STYLE_PROPS } from "../constants.js"; | ||
export const getDefaultVariantClasses = ({ styles = {}, variants = {} }) => { | ||
const defaultVariants = styles.defaults?.variants; | ||
if (!defaultVariants) | ||
return RECAST_STYLE_PROPS; | ||
return Object.keys(defaultVariants).reduce((acc, variant) => { | ||
const defaultVariantStyles = styles.variants?.[variant]?.[defaultVariants[variant]]; | ||
// Don't continue if no default variant styles are | ||
// found or a variant has been set | ||
if (!defaultVariantStyles || variants[variant]) { | ||
return acc; | ||
}, {}); | ||
return defaultVariantClasses; | ||
} | ||
return {}; | ||
} | ||
if (typeof defaultVariantStyles === "string" || Array.isArray(defaultVariantStyles)) { | ||
return { className: mergeStringClassNames(acc.className, defaultVariantStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: mergeObjectClassNames(acc.rcx, defaultVariantStyles) }; | ||
}, RECAST_STYLE_PROPS); | ||
}; | ||
//# sourceMappingURL=getDefaultVariantClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedModifierProps, RelaxedStyles } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
styles: RelaxedStyles; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
export declare const getModifierClasses: ({ theme, modifiers }: Props) => {}; | ||
export declare const getModifierClasses: ({ styles, modifiers }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -1,10 +0,17 @@ | ||
import { mergeClassNames } from "./mergeClassNames.js"; | ||
export const getModifierClasses = ({ theme = {}, modifiers = [] }) => { | ||
if (!theme.modifiers) | ||
return {}; | ||
const modifierClasses = modifiers.reduce((acc, curr) => { | ||
return mergeClassNames(acc, theme.modifiers?.[curr]); | ||
}, {}); | ||
return modifierClasses; | ||
import { mergeObjectClassNames, mergeStringClassNames } from "./mergeClassNames.js"; | ||
import { RECAST_STYLE_PROPS } from "../constants.js"; | ||
export const getModifierClasses = ({ styles = {}, modifiers = [] }) => { | ||
if (!styles.modifiers) | ||
return RECAST_STYLE_PROPS; | ||
return modifiers.reduce((acc, modifier) => { | ||
const modifierStyles = styles.modifiers?.[modifier]; | ||
if (!modifierStyles) { | ||
return acc; | ||
} | ||
if (typeof modifierStyles === "string" || Array.isArray(modifierStyles)) { | ||
return { className: mergeStringClassNames(acc.className, modifierStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: mergeObjectClassNames(acc.rcx, modifierStyles) }; | ||
}, RECAST_STYLE_PROPS); | ||
}; | ||
//# sourceMappingURL=getModifierClasses.js.map |
@@ -1,10 +0,12 @@ | ||
import type { RecastBaseStyles, RecastThemeProps } from "../types.js"; | ||
type RecastClasses<K> = Record<keyof K, string> | undefined; | ||
import { RelaxedModifierProps, RelaxedRecastStyleProps, RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type RecastThemeProps = { | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
modifiers?: RelaxedModifierProps; | ||
}; | ||
/** | ||
* Returns an object containing the CSS classes generated from the provided theme, variants, and modifiers. | ||
* @template K - The type of the base styles object. | ||
* @param {RecastThemeProps} props - An object containing the theme key, variants, and modifiers. | ||
* @returns {RecastClasses<K>} - An object containing the generated CSS classes. | ||
* Returns an object containing the CSS classes | ||
* generated from the provided styles, variants, and modifiers. | ||
*/ | ||
export declare const getRecastClasses: <K extends RecastBaseStyles>({ themekey, variants, modifiers, }: RecastThemeProps) => RecastClasses<K>; | ||
export declare function getRecastClasses({ styles, variants, modifiers }: RecastThemeProps): RelaxedRecastStyleProps; | ||
export {}; |
@@ -1,39 +0,22 @@ | ||
import { getTheme } from "../recastThemeInstance.js"; | ||
import { mergeObjectClassNames, mergeStringClassNames } from "./mergeClassNames.js"; | ||
import { RECAST_STYLE_PROPS } from "../constants.js"; | ||
import { getBaseClasses } from "./getBaseClasses.js"; | ||
import { getConditionalClasses } from "./getConditionalClasses.js"; | ||
import { getDefaultModifierClasses } from "./getDefaultModifierClasses.js"; | ||
import { getDefaultVariantClasses } from "./getDefaultVariantClasses.js"; | ||
import { getModifierClasses } from "./getModifierClasses.js"; | ||
import { getVariantClasses } from "./getVariantClasses.js"; | ||
import { mergeClassNames } from "./mergeClassNames.js"; | ||
import { getDefaultVariantClasses } from "./getDefaultVariantClasses.js"; | ||
import { getDefaultModifierClasses } from "./getDefaultModifierClasses.js"; | ||
import { getConditionalClasses } from "./getConditionalClasses.js"; | ||
/** | ||
* Returns an object containing the CSS classes generated from the provided theme, variants, and modifiers. | ||
* @template K - The type of the base styles object. | ||
* @param {RecastThemeProps} props - An object containing the theme key, variants, and modifiers. | ||
* @returns {RecastClasses<K>} - An object containing the generated CSS classes. | ||
* Returns an object containing the CSS classes | ||
* generated from the provided styles, variants, and modifiers. | ||
*/ | ||
export const getRecastClasses = ({ themekey, variants, modifiers, }) => { | ||
const theme = getTheme(themekey); | ||
const variantClasses = getVariantClasses({ | ||
theme, | ||
variants, | ||
}); | ||
const defaultVariantClasses = getDefaultVariantClasses({ | ||
theme, | ||
variants, | ||
}); | ||
const modifierClasses = getModifierClasses({ | ||
theme, | ||
modifiers, | ||
}); | ||
const defaultModifierClasses = getDefaultModifierClasses({ | ||
theme, | ||
modifiers, | ||
}); | ||
const conditionalClasses = getConditionalClasses({ | ||
theme, | ||
variants, | ||
modifiers, | ||
}); | ||
const classes = [ | ||
theme?.base, | ||
export function getRecastClasses({ styles, variants, modifiers }) { | ||
const baseClasses = getBaseClasses({ styles }); | ||
const variantClasses = getVariantClasses({ styles, variants }); | ||
const defaultVariantClasses = getDefaultVariantClasses({ styles, variants }); | ||
const modifierClasses = getModifierClasses({ styles, modifiers }); | ||
const defaultModifierClasses = getDefaultModifierClasses({ styles, modifiers }); | ||
const conditionalClasses = getConditionalClasses({ styles, variants, modifiers }); | ||
const result = [ | ||
baseClasses, | ||
variantClasses, | ||
@@ -45,6 +28,9 @@ defaultVariantClasses, | ||
].reduce((acc, curr) => { | ||
return mergeClassNames(acc, curr); | ||
}, {}); | ||
return classes; | ||
}; | ||
return { | ||
className: mergeStringClassNames(acc.className, curr.className), | ||
rcx: mergeObjectClassNames(acc.rcx, curr.rcx), | ||
}; | ||
}, RECAST_STYLE_PROPS); | ||
return { className: result.className, rcx: result.rcx }; | ||
} | ||
//# sourceMappingURL=getRecastClasses.js.map |
@@ -1,7 +0,7 @@ | ||
import { RecastThemeProps, Styles } from "../types.js"; | ||
import { RelaxedStyles, RelaxedVariantProps } from "../types.js"; | ||
type Props = { | ||
theme: Styles; | ||
variants?: RecastThemeProps["variants"]; | ||
styles: RelaxedStyles; | ||
variants?: RelaxedVariantProps; | ||
}; | ||
export declare const getVariantClasses: ({ theme, variants }: Props) => {}; | ||
export declare const getVariantClasses: ({ styles, variants }: Props) => import("../types.js").RelaxedRecastStyleProps; | ||
export {}; |
@@ -1,11 +0,17 @@ | ||
import { mergeClassNames } from "./mergeClassNames.js"; | ||
export const getVariantClasses = ({ theme = {}, variants = {} }) => { | ||
if (!theme.variants) | ||
return {}; | ||
const variantKeys = Object.keys(variants); | ||
const variantClasses = variantKeys.reduce((acc, curr) => { | ||
return mergeClassNames(acc, theme.variants?.[curr][variants[curr]]); | ||
}, {}); | ||
return variantClasses; | ||
import { mergeObjectClassNames, mergeStringClassNames } from "./mergeClassNames.js"; | ||
import { RECAST_STYLE_PROPS } from "../constants.js"; | ||
export const getVariantClasses = ({ styles = {}, variants = {} }) => { | ||
if (!styles.variants) | ||
return RECAST_STYLE_PROPS; | ||
return Object.keys(variants).reduce((acc, variant) => { | ||
const variantStyles = styles.variants?.[variant][variants[variant]]; | ||
if (!variantStyles) { | ||
return acc; | ||
} | ||
if (typeof variantStyles === "string" || Array.isArray(variantStyles)) { | ||
return { className: mergeStringClassNames(acc.className, variantStyles), rcx: acc.rcx }; | ||
} | ||
return { className: acc.className, rcx: mergeObjectClassNames(acc.rcx, variantStyles) }; | ||
}, RECAST_STYLE_PROPS); | ||
}; | ||
//# sourceMappingURL=getVariantClasses.js.map |
@@ -17,3 +17,3 @@ import { ClassNameRecord } from "../types.js"; | ||
*/ | ||
export declare const mergeValues: (objValue?: string | string[], value?: string | string[]) => string; | ||
export declare const mergeStringClassNames: (objValue?: string | string[], value?: string | string[]) => string; | ||
/** | ||
@@ -28,2 +28,2 @@ * Merges class names from a target and source object, normalizing and concatenating them. | ||
*/ | ||
export declare const mergeClassNames: (target?: ClassNameRecord, source?: ClassNameRecord) => ClassNameRecord; | ||
export declare const mergeObjectClassNames: (target?: ClassNameRecord, source?: ClassNameRecord) => ClassNameRecord; |
@@ -20,10 +20,10 @@ /** | ||
*/ | ||
export const mergeValues = (objValue, value) => { | ||
if (!!objValue && !!value) { | ||
export const mergeStringClassNames = (objValue, value) => { | ||
if (objValue && value) { | ||
return `${normalizeValue(objValue)} ${normalizeValue(value)}`; | ||
} | ||
else if (!!objValue) { | ||
else if (objValue) { | ||
return normalizeValue(objValue); | ||
} | ||
else if (!!value) { | ||
else if (value) { | ||
return normalizeValue(value); | ||
@@ -44,3 +44,3 @@ } | ||
*/ | ||
export const mergeClassNames = (target = {}, source = {}) => { | ||
export const mergeObjectClassNames = (target = {}, source = {}) => { | ||
/** | ||
@@ -53,19 +53,15 @@ * Normalizes the class names in an object by removing leading and trailing whitespace. | ||
const normalizeTarget = (x) => { | ||
const keys = Object.keys(x); | ||
if (keys?.length) { | ||
return keys.reduce((acc, curr) => { | ||
return { ...acc, [curr]: normalizeValue(x[curr]) }; | ||
}, {}); | ||
} | ||
return x; | ||
return Object.keys(x).reduce((acc, curr) => { | ||
return { ...acc, [curr]: normalizeValue(x[curr]) }; | ||
}, {}); | ||
}; | ||
return Object.keys(source).reduce((acc, curr) => { | ||
if (acc[curr] && source[curr]) { | ||
return { ...acc, [curr]: mergeValues(acc[curr], source[curr]) }; | ||
return Object.entries(source).reduce((acc, [key, value]) => { | ||
if (acc[key] && value) { | ||
return { ...acc, [key]: mergeStringClassNames(acc[key], value) }; | ||
} | ||
else if (acc[curr]) { | ||
return { ...acc, [curr]: normalizeValue(acc[curr]) }; | ||
else if (acc[key]) { | ||
return { ...acc, [key]: normalizeValue(acc[key]) }; | ||
} | ||
else if (source[curr]) { | ||
return { ...acc, [curr]: normalizeValue(source[curr]) }; | ||
else if (value) { | ||
return { ...acc, [key]: normalizeValue(value) }; | ||
} | ||
@@ -72,0 +68,0 @@ return acc; |
@@ -1,5 +0,5 @@ | ||
import { RecastConditionalProps, RecastThemeProps } from "../types.js"; | ||
import { RelaxedCondiiton, RelaxedModifierProps } from "../types.js"; | ||
type ValidateConditionProps = { | ||
modifiers?: RecastThemeProps["modifiers"]; | ||
condition: RecastConditionalProps; | ||
modifiers?: RelaxedModifierProps; | ||
condition: RelaxedCondiiton; | ||
defaults?: string[]; | ||
@@ -14,3 +14,3 @@ }; | ||
*/ | ||
export declare const validateConditionalModifiers: ({ condition, modifiers, defaults, }: ValidateConditionProps) => boolean | undefined; | ||
export declare const validateConditionalModifiers: ({ condition, modifiers, defaults }: ValidateConditionProps) => boolean | undefined; | ||
export {}; |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
export const validateConditionalModifiers = ({ condition, modifiers, defaults, }) => { | ||
export const validateConditionalModifiers = ({ condition, modifiers, defaults }) => { | ||
// Always return true if modifier conditions are empty | ||
@@ -11,0 +11,0 @@ if (!condition.modifiers?.length) { |
@@ -1,5 +0,5 @@ | ||
import { RecastConditionalProps, RecastThemeProps } from "../types.js"; | ||
import { RelaxedCondiiton, RelaxedVariantProps } from "../types.js"; | ||
type ValidateConditionProps = { | ||
variants?: RecastThemeProps["variants"]; | ||
condition: RecastConditionalProps; | ||
variants?: RelaxedVariantProps; | ||
condition: RelaxedCondiiton; | ||
defaults?: Record<string, string>; | ||
@@ -14,3 +14,3 @@ }; | ||
*/ | ||
export declare const validateConditionalVariants: ({ condition, variants, defaults, }: ValidateConditionProps) => boolean; | ||
export declare const validateConditionalVariants: ({ condition, variants, defaults }: ValidateConditionProps) => boolean; | ||
export {}; |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
export const validateConditionalVariants = ({ condition, variants, defaults, }) => { | ||
export const validateConditionalVariants = ({ condition, variants, defaults }) => { | ||
const conditionalVariantKeys = Object.keys(condition.variants || {}); | ||
@@ -11,0 +11,0 @@ // Always return true if variant conditions are empty |
{ | ||
"name": "@rpxl/recast", | ||
"license": "MIT", | ||
"version": "3.1.5", | ||
"version": "4.0.0", | ||
"type": "module", | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"main": "./dist/cjs/index.js", | ||
@@ -33,3 +30,2 @@ "module": "./dist/esm/index.js", | ||
"dist", | ||
"server", | ||
"!**/__tests__/**" | ||
@@ -36,0 +32,0 @@ ], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84870
92
1169
1