Comparing version 0.2.5 to 0.3.0
@@ -5,18 +5,28 @@ "use strict"; | ||
}); | ||
exports.cn = cn; | ||
exports.cvax = cvax; | ||
exports.mergeVariants = mergeVariants; | ||
exports.merge = merge; | ||
exports.cx = cx; | ||
var _tailwindMerge = require("tailwind-merge"); | ||
var _lodashIsequal // FIXME: find the way to not to use lodash | ||
= _interopRequireDefault(require("lodash.isequal")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
function _export(target, all) { | ||
for(var name in all)Object.defineProperty(target, name, { | ||
enumerable: true, | ||
get: all[name] | ||
}); | ||
} | ||
_export(exports, { | ||
cx: function() { | ||
return _cx.cx; | ||
}, | ||
mergeVariants: function() { | ||
return _mergevariants.mergeVariants; | ||
}, | ||
cn: function() { | ||
return cn; | ||
}, | ||
cvax: function() { | ||
return cvax; | ||
} | ||
}); | ||
const _tailwindmerge = require("tailwind-merge"); | ||
const _cx = require("./cx"); | ||
const _mergevariants = require("./merge-variants"); | ||
function falsyToString(value) { | ||
if (typeof value === "boolean") { | ||
return "".concat(value); | ||
return `${value}`; | ||
} | ||
@@ -32,15 +42,12 @@ if (typeof value === "number") { | ||
} | ||
return (0, _tailwindMerge).twMerge(cx(inputs)); | ||
return (0, _tailwindmerge.twMerge)((0, _cx.cx)(inputs)); | ||
} | ||
function cvax(config) { | ||
if (config.variants == null) return (props)=>{ | ||
return cx(config === null || config === void 0 ? void 0 : config.base, props === null || props === void 0 ? void 0 : props.className); | ||
}; | ||
if (config.variants == null) return (props)=>(0, _cx.cx)(config?.base, props?.className); | ||
return (props)=>{ | ||
var ref; | ||
const { variants , defaultVariants } = config; | ||
if (!variants) return cx(props === null || props === void 0 ? void 0 : props.className); | ||
if (!variants) return (0, _cx.cx)(props?.className); | ||
const getVariantClassNames = Object.keys(variants).map((variant)=>{ | ||
const variantProp = props === null || props === void 0 ? void 0 : props[variant]; | ||
const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant]; | ||
const variantProp = props?.[variant]; | ||
const defaultVariantProp = defaultVariants?.[variant]; | ||
if (variantProp === null) return null; | ||
@@ -58,4 +65,4 @@ const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp); | ||
}, {}); | ||
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param1; | ||
const getCompoundVariantClassNames = config?.compoundVariants?.reduce((acc, param)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param; | ||
return Object.entries(compoundVariantOptions).every((param)=>{ | ||
@@ -75,167 +82,5 @@ let [key, value] = param; | ||
}, []); | ||
return cx(config === null || config === void 0 ? void 0 : config.base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.className); | ||
return (0, _cx.cx)(config?.base, getVariantClassNames, getCompoundVariantClassNames, props?.className); | ||
}; | ||
} | ||
function mergeVariants(baseVariants, newVariants) { | ||
const base_ = getAbsentKeys(baseVariants); | ||
const new_ = getAbsentKeys(newVariants); | ||
let base = ""; | ||
if (baseVariants.base || newVariants.base) { | ||
base = cn(baseVariants.base, newVariants.base); | ||
} | ||
const variants = getVariants(base_.variants, new_.variants); | ||
const defaultVariants = getDefaultVariants(base_.defaultVariants, new_.defaultVariants); | ||
const compoundVariants = getCompoundVariants(base_.compoundVariants, new_.compoundVariants); | ||
return { | ||
base, | ||
variants, | ||
defaultVariants, | ||
compoundVariants | ||
}; | ||
// return { | ||
// ...(base && { base }), | ||
// ...(Object.keys(variants).length > 0 && { variants }), | ||
// ...(Object.keys(defaultVariants).length > 0 && { defaultVariants }), | ||
// ...(compoundVariants.length > 0 && { compoundVariants }), | ||
// } | ||
} | ||
function getAbsentKeys(config) { | ||
const obj = Object.assign({}, config); | ||
if (!("variants" in config)) Object.assign(obj, { | ||
variants: {} | ||
}); | ||
if (!("defaultVariants" in config)) Object.assign(obj, { | ||
defaultVariants: {} | ||
}); | ||
if (!("compoundVariants" in config)) Object.assign(obj, { | ||
compoundVariants: [] | ||
}); | ||
return obj; | ||
} | ||
function getVariants(baseVariants, newVariants) { | ||
const variants = { | ||
...baseVariants | ||
}; | ||
Object.entries(newVariants).map((param2)=>{ | ||
let [variant, value] = param2; | ||
return Object.entries(value).map((param)=>{ | ||
let [key, classes] = param; | ||
var ref, ref1; | ||
if (!(variant in variants)) Object.assign(variants, { | ||
[variant]: {} | ||
}); | ||
Object.assign(variants[variant], { | ||
[key]: cn((ref = variants) === null || ref === void 0 ? void 0 : (ref1 = ref[variant]) === null || ref1 === void 0 ? void 0 : ref1[key], classes) | ||
}); | ||
}); | ||
}); | ||
return variants; | ||
} | ||
function getDefaultVariants(baseVariants, newVariants) { | ||
return merge(baseVariants, newVariants); | ||
} | ||
// FIXME: make newVariants as first priopity | ||
// TODO: optimize algorithm | ||
function getCompoundVariants(baseVariants, newVariants) { | ||
const arr = [ | ||
...baseVariants, | ||
...newVariants | ||
]; | ||
const markArr = []; | ||
for (const [key, { className , ...rest }] of arr.entries()){ | ||
for(let i = key + 1; i < arr.length; i++){ | ||
const { className , ...arrRest } = arr[i]; | ||
if ((0, _lodashIsequal).default(rest, arrRest)) markArr[i] = null; | ||
} | ||
} | ||
return arr.map((item, index)=>markArr[index] === undefined ? item : null).filter(Boolean); | ||
} | ||
function merge() { | ||
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ | ||
args[_key] = arguments[_key]; | ||
} | ||
return Object.assign({}, ...args.filter(cleanObjects)); | ||
} | ||
function cleanObjects(element) { | ||
if (element === null) return false; | ||
if (Array.isArray(element)) return false; | ||
return Object.keys(element).length !== 0; | ||
} | ||
function cx() { | ||
for(var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++){ | ||
classes[_key] = arguments[_key]; | ||
} | ||
// let tmp, | ||
// x, | ||
// i = 0, | ||
// str = "" | ||
// while (i < classes.length) { | ||
// if ((tmp = classes[i++])) { | ||
// if ((x = toVal(tmp))) { | ||
// str && (str += " ") | ||
// str += x | ||
// } | ||
// } | ||
// } | ||
return classes.flat(Infinity).filter(Boolean).join(" "); | ||
} | ||
function toVal(mix) { | ||
if (!mix) return ""; | ||
if (typeof mix === "string" || typeof mix === "number") { | ||
return mix.toString(); | ||
} | ||
if (Array.isArray(mix)) { | ||
let str = ""; | ||
for (const item of mix){ | ||
if (item) { | ||
str += " " + toVal(item); | ||
} | ||
} | ||
return str; | ||
} | ||
if (typeof mix === "object") { | ||
let str = ""; | ||
for(const key in mix){ | ||
if (mix[key]) { | ||
str += " " + key; | ||
} | ||
} | ||
return str; | ||
} | ||
} | ||
var hasOwn = {}.hasOwnProperty; | ||
function classNames() { | ||
for(var _len = arguments.length, classesArr = new Array(_len), _key = 0; _key < _len; _key++){ | ||
classesArr[_key] = arguments[_key]; | ||
} | ||
var classes = []; | ||
for(var i = 0; i < classesArr.length; i++){ | ||
var arg = classesArr[i]; | ||
if (!arg) continue; | ||
const argType = typeof arg; | ||
if (argType === "string" || argType === "number") { | ||
classes.push(arg); | ||
} else if (Array.isArray(arg)) { | ||
if (arg.length) { | ||
var inner = classNames.apply(null, arg); | ||
if (inner) { | ||
classes.push(inner); | ||
} | ||
} | ||
} else if (argType === "object") { | ||
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) { | ||
classes.push(arg.toString()); | ||
continue; | ||
} | ||
// for (const key in arg) { | ||
// if (hasOwn.call(arg, key) && arg[key]) { | ||
// classes.push(key) | ||
// } | ||
// } | ||
} | ||
} | ||
return classes.join(" "); | ||
} | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,12 +0,15 @@ | ||
import type { ClassProp, ClassValue, CxOptions, CxReturn, OmitUndefined, StringToBoolean } from "./types"; | ||
export declare type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "className">; | ||
import type { ClassProp, ClassValue, OmitUndefined, StringToBoolean } from "./types"; | ||
import { cx } from "./cx"; | ||
export { cx }; | ||
export { mergeVariants } from "./merge-variants"; | ||
export declare function cn(...inputs: ClassValue[]): string; | ||
declare type ConfigSchema = Record<string, Record<string, ClassValue>>; | ||
declare type ConfigVariants<T extends ConfigSchema> = { | ||
export type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "class" | "className">; | ||
export type ConfigSchema = Record<string, Record<string, ClassValue>>; | ||
export type ConfigVariants<T extends ConfigSchema> = { | ||
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null; | ||
}; | ||
declare type ConfigVariantsMulti<T extends ConfigSchema> = { | ||
export type ConfigVariantsMulti<T extends ConfigSchema> = { | ||
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[]; | ||
}; | ||
export declare type Config<T> = T extends ConfigSchema ? { | ||
export type Config<T> = T extends ConfigSchema ? { | ||
base?: ClassValue; | ||
@@ -17,32 +20,3 @@ variants?: T; | ||
} : never; | ||
declare type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp; | ||
type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp; | ||
export declare function cvax<T>(config: Config<T>): (props?: Props<T>) => string; | ||
export declare function mergeVariants<T, U>(baseVariants: Config<T>, newVariants: Config<U>): { | ||
base: string; | ||
variants: import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<[undefined] extends [import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<T, Function | Iterable<unknown>, object> | import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object>] ? never : import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<T, Function | Iterable<unknown>, object> extends infer T_1 ? T_1 extends import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<T, Function | Iterable<unknown>, object> ? T_1 extends import("type-fest/source/internal").UnknownRecord ? import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object> extends infer T_2 ? T_2 extends import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object> ? T_2 extends import("type-fest/source/internal").UnknownRecord ? import("type-fest/source/merge-deep").MergeDeepRecord<T_1, T_2, { | ||
arrayMergeMode: "replace"; | ||
recurseIntoArrays: false; | ||
spreadTopLevelArrays: true; | ||
}> : never : never : never : T_1 extends import("type-fest/source/internal").UnknownArrayOrTuple ? import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object> extends infer T_3 ? T_3 extends import("type-fest/source/conditional-simplify").ConditionalSimplifyDeep<U, Function | Iterable<unknown>, object> ? T_3 extends import("type-fest/source/internal").UnknownArrayOrTuple ? (Exclude<T_1, undefined>[number] | Exclude<T_3, undefined>[number])[] : never : never : never : never : never : never, Function | Iterable<unknown>, object>; | ||
defaultVariants: Identity<Pick<ConfigVariants<T>, Exclude<keyof T, keyof Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>>> & Pick<Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>, Exclude<keyof Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>, OptionalPropertyNames<Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>>>> & Pick<Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>, Exclude<OptionalPropertyNames<Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>>, keyof T>> & SpreadProperties<ConfigVariants<T>, Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>, OptionalPropertyNames<Identity<Pick<ConfigVariants<U>, Exclude<keyof U, never>> & Pick<unknown, never> & SpreadProperties<ConfigVariants<U>, unknown, never>>> & keyof T>>; | ||
compoundVariants: ((T extends ConfigSchema ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp : ClassProp) | (U extends ConfigSchema ? (ConfigVariants<U> | ConfigVariantsMulti<U>) & ClassProp : ClassProp))[]; | ||
}; | ||
export declare function merge<Args extends object[]>(...args: [...Args]): Spread<Args>; | ||
declare type Spread<Args extends readonly [...any]> = Args extends [infer Left, ...infer Right] ? SpreadTwo<Left, Spread<Right>> : unknown; | ||
declare type SpreadTwo<Left, Right> = Identity<Pick<Left, Exclude<keyof Left, keyof Right>> & Pick<Right, Exclude<keyof Right, OptionalPropertyNames<Right>>> & Pick<Right, Exclude<OptionalPropertyNames<Right>, keyof Left>> & SpreadProperties<Left, Right, OptionalPropertyNames<Right> & keyof Left>>; | ||
declare type Identity<T> = T extends infer U ? { | ||
[Key in keyof U]: U[Key]; | ||
} : never; | ||
declare type OptionalPropertyNames<T> = { | ||
[Key in keyof T]-?: {} extends { | ||
[P in Key]: T[Key]; | ||
} ? Key : never; | ||
}[keyof T]; | ||
declare type SpreadProperties<Left, Right, Key extends keyof Left & keyof Right> = { | ||
[P in Key]: Left[P] | Exclude<Right[P], undefined>; | ||
}; | ||
export declare type XClassValue = XClassArray | XClassDictionary | string | number | null | boolean | undefined; | ||
export declare type XClassDictionary = Record<string, any>; | ||
export declare type XClassArray = ClassValue[]; | ||
export declare function cx<T extends CxOptions>(...classes: T): CxReturn; | ||
export {}; |
import { twMerge } from "tailwind-merge"; | ||
import isEqual from "lodash.isequal"; // FIXME: find the way to not to use lodash | ||
import { cx } from "./cx"; | ||
export { cx }; | ||
export { mergeVariants } from "./merge-variants"; | ||
function falsyToString(value) { | ||
if (typeof value === "boolean") { | ||
return "".concat(value); | ||
return `${value}`; | ||
} | ||
@@ -13,3 +15,3 @@ if (typeof value === "number") { | ||
/* cn | ||
============================================ */ export function cn() { | ||
============================================ */ export function cn() { | ||
for(var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++){ | ||
@@ -21,12 +23,9 @@ inputs[_key] = arguments[_key]; | ||
export function cvax(config) { | ||
if (config.variants == null) return (props)=>{ | ||
return cx(config === null || config === void 0 ? void 0 : config.base, props === null || props === void 0 ? void 0 : props.className); | ||
}; | ||
if (config.variants == null) return (props)=>cx(config?.base, props?.className); | ||
return (props)=>{ | ||
var ref; | ||
const { variants , defaultVariants } = config; | ||
if (!variants) return cx(props === null || props === void 0 ? void 0 : props.className); | ||
if (!variants) return cx(props?.className); | ||
const getVariantClassNames = Object.keys(variants).map((variant)=>{ | ||
const variantProp = props === null || props === void 0 ? void 0 : props[variant]; | ||
const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant]; | ||
const variantProp = props?.[variant]; | ||
const defaultVariantProp = defaultVariants?.[variant]; | ||
if (variantProp === null) return null; | ||
@@ -44,4 +43,4 @@ const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp); | ||
}, {}); | ||
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param1; | ||
const getCompoundVariantClassNames = config?.compoundVariants?.reduce((acc, param)=>{ | ||
let { className: cvClassName , ...compoundVariantOptions } = param; | ||
return Object.entries(compoundVariantOptions).every((param)=>{ | ||
@@ -61,170 +60,5 @@ let [key, value] = param; | ||
}, []); | ||
return cx(config === null || config === void 0 ? void 0 : config.base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.className); | ||
return cx(config?.base, getVariantClassNames, getCompoundVariantClassNames, props?.className); | ||
}; | ||
} | ||
/* mergeVariants | ||
============================================ */ // TODO: merge non-tailwind classes?.. | ||
export function mergeVariants(baseVariants, newVariants) { | ||
const base_ = getAbsentKeys(baseVariants); | ||
const new_ = getAbsentKeys(newVariants); | ||
let base = ""; | ||
if (baseVariants.base || newVariants.base) { | ||
base = cn(baseVariants.base, newVariants.base); | ||
} | ||
const variants = getVariants(base_.variants, new_.variants); | ||
const defaultVariants = getDefaultVariants(base_.defaultVariants, new_.defaultVariants); | ||
const compoundVariants = getCompoundVariants(base_.compoundVariants, new_.compoundVariants); | ||
return { | ||
base, | ||
variants, | ||
defaultVariants, | ||
compoundVariants | ||
}; | ||
// return { | ||
// ...(base && { base }), | ||
// ...(Object.keys(variants).length > 0 && { variants }), | ||
// ...(Object.keys(defaultVariants).length > 0 && { defaultVariants }), | ||
// ...(compoundVariants.length > 0 && { compoundVariants }), | ||
// } | ||
} | ||
function getAbsentKeys(config) { | ||
const obj = Object.assign({}, config); | ||
if (!("variants" in config)) Object.assign(obj, { | ||
variants: {} | ||
}); | ||
if (!("defaultVariants" in config)) Object.assign(obj, { | ||
defaultVariants: {} | ||
}); | ||
if (!("compoundVariants" in config)) Object.assign(obj, { | ||
compoundVariants: [] | ||
}); | ||
return obj; | ||
} | ||
function getVariants(baseVariants, newVariants) { | ||
const variants = { | ||
...baseVariants | ||
}; | ||
Object.entries(newVariants).map((param2)=>{ | ||
let [variant, value] = param2; | ||
return Object.entries(value).map((param)=>{ | ||
let [key, classes] = param; | ||
var ref, ref1; | ||
if (!(variant in variants)) Object.assign(variants, { | ||
[variant]: {} | ||
}); | ||
Object.assign(variants[variant], { | ||
[key]: cn((ref = variants) === null || ref === void 0 ? void 0 : (ref1 = ref[variant]) === null || ref1 === void 0 ? void 0 : ref1[key], classes) | ||
}); | ||
}); | ||
}); | ||
return variants; | ||
} | ||
function getDefaultVariants(baseVariants, newVariants) { | ||
return merge(baseVariants, newVariants); | ||
} | ||
// FIXME: make newVariants as first priopity | ||
// TODO: optimize algorithm | ||
function getCompoundVariants(baseVariants, newVariants) { | ||
const arr = [ | ||
...baseVariants, | ||
...newVariants | ||
]; | ||
const markArr = []; | ||
for (const [key, { className , ...rest }] of arr.entries()){ | ||
for(let i = key + 1; i < arr.length; i++){ | ||
const { className , ...arrRest } = arr[i]; | ||
if (isEqual(rest, arrRest)) markArr[i] = null; | ||
} | ||
} | ||
return arr.map((item, index)=>markArr[index] === undefined ? item : null).filter(Boolean); | ||
} | ||
/* merge | ||
============================================ */ export function merge() { | ||
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ | ||
args[_key] = arguments[_key]; | ||
} | ||
return Object.assign({}, ...args.filter(cleanObjects)); | ||
} | ||
function cleanObjects(element) { | ||
if (element === null) return false; | ||
if (Array.isArray(element)) return false; | ||
return Object.keys(element).length !== 0; | ||
} | ||
export function cx() { | ||
for(var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++){ | ||
classes[_key] = arguments[_key]; | ||
} | ||
// let tmp, | ||
// x, | ||
// i = 0, | ||
// str = "" | ||
// while (i < classes.length) { | ||
// if ((tmp = classes[i++])) { | ||
// if ((x = toVal(tmp))) { | ||
// str && (str += " ") | ||
// str += x | ||
// } | ||
// } | ||
// } | ||
return classes.flat(Infinity).filter(Boolean).join(" "); | ||
} | ||
function toVal(mix) { | ||
if (!mix) return ""; | ||
if (typeof mix === "string" || typeof mix === "number") { | ||
return mix.toString(); | ||
} | ||
if (Array.isArray(mix)) { | ||
let str = ""; | ||
for (const item of mix){ | ||
if (item) { | ||
str += " " + toVal(item); | ||
} | ||
} | ||
return str; | ||
} | ||
if (typeof mix === "object") { | ||
let str = ""; | ||
for(const key in mix){ | ||
if (mix[key]) { | ||
str += " " + key; | ||
} | ||
} | ||
return str; | ||
} | ||
} | ||
var hasOwn = {}.hasOwnProperty; | ||
function classNames() { | ||
for(var _len = arguments.length, classesArr = new Array(_len), _key = 0; _key < _len; _key++){ | ||
classesArr[_key] = arguments[_key]; | ||
} | ||
var classes = []; | ||
for(var i = 0; i < classesArr.length; i++){ | ||
var arg = classesArr[i]; | ||
if (!arg) continue; | ||
const argType = typeof arg; | ||
if (argType === "string" || argType === "number") { | ||
classes.push(arg); | ||
} else if (Array.isArray(arg)) { | ||
if (arg.length) { | ||
var inner = classNames.apply(null, arg); | ||
if (inner) { | ||
classes.push(inner); | ||
} | ||
} | ||
} else if (argType === "object") { | ||
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) { | ||
classes.push(arg.toString()); | ||
continue; | ||
} | ||
// for (const key in arg) { | ||
// if (hasOwn.call(arg, key) && arg[key]) { | ||
// classes.push(key) | ||
// } | ||
// } | ||
} | ||
} | ||
return classes.join(" "); | ||
} | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,8 +0,9 @@ | ||
export declare type ClassValue = string | null | undefined | readonly ClassValue[]; | ||
export declare type ClassProp = { | ||
export type ClassPropKey = "class" | "className"; | ||
export type ClassValue = string | null | undefined | ClassValue[]; | ||
export type ClassProp = { | ||
className?: ClassValue | undefined; | ||
}; | ||
export declare type OmitUndefined<T> = T extends undefined ? never : T; | ||
export declare type StringToBoolean<T> = T extends "true" | "false" ? boolean : T; | ||
export declare type CxOptions = ClassValue[]; | ||
export declare type CxReturn = string; | ||
export type OmitUndefined<T> = T extends undefined ? never : T; | ||
export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T; | ||
export type CxOptions = ClassValue[]; | ||
export type CxReturn = string; |
{ | ||
"name": "cvax", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "Customized CVA. fork 'class-variance-authority'", | ||
@@ -19,9 +19,7 @@ "repository": "https://github.com/alexvyber/cvax.git", | ||
"build:tsc": "tsc --project .config/tsconfig.build.json", | ||
"dev-OLD": "jest --config .config/jest.config.ts --watch", | ||
"dev": "vitest", | ||
"prepublishOnly": "pnpm build", | ||
"test": "run-p test:*", | ||
"NO-test:jest": "jest --config .config/jest.config.ts --coverage", | ||
"test:vitest": "vitest", | ||
"NO-test:size": "pnpm build && bundlesize -f 'dist/*.js' -s 1.6KB", | ||
"test:size": "pnpm build && bundlesize -f 'dist/*.js' -s 1KB", | ||
"tsc": "tsc --project tsconfig.json --noEmit" | ||
@@ -31,19 +29,14 @@ }, | ||
"lodash.isequal": "^4.5.0", | ||
"tailwind-merge": "^1.10.0", | ||
"type-fest": "^3.6.1" | ||
"tailwind-merge": "^1.12.0", | ||
"type-fest": "^3.9.0" | ||
}, | ||
"devDependencies": { | ||
"@swc/cli": "0.1.57", | ||
"@swc/core": "1.2.198", | ||
"@swc/cli": "0.1.62", | ||
"@swc/core": "1.3.56", | ||
"@types/lodash.isequal": "^4.5.6", | ||
"@types/node": "18.11.18", | ||
"@types/react": "18.0.12", | ||
"@types/react-dom": "18.0.5", | ||
"jest": "28.1.1", | ||
"bundlesize": "^0.18.1", | ||
"npm-run-all": "4.1.5", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"ts-node": "10.8.1", | ||
"typescript": "4.7.3", | ||
"vitest": "^0.29.1" | ||
"typescript": "5.0.4", | ||
"vitest": "^0.30.1" | ||
}, | ||
@@ -50,0 +43,0 @@ "peerDependencies": { |
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
8
10
13167
210
1
Updatedtailwind-merge@^1.12.0
Updatedtype-fest@^3.9.0