Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cva

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cva - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

110

dist/index.js

@@ -1,3 +0,111 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.cx=exports.cva=exports.compose=exports.defineConfig=void 0;var _clsx=require("clsx");const falsyToString=value=>typeof value==="boolean"?"".concat(value):value===0?"0":value;const defineConfig=options=>{const cx1=function(){for(var _len=arguments.length,inputs=new Array(_len),_key=0;_key<_len;_key++){inputs[_key]=arguments[_key]}var ref,ref1;if(typeof(options===null||options===void 0?void 0:(ref=options.hooks)===null||ref===void 0?void 0:ref["cx:done"])!=="undefined")return options===null||options===void 0?void 0:options.hooks["cx:done"]((0,_clsx).clsx(inputs));if(typeof(options===null||options===void 0?void 0:(ref1=options.hooks)===null||ref1===void 0?void 0:ref1.onComplete)!=="undefined")return options===null||options===void 0?void 0:options.hooks.onComplete((0,_clsx).clsx(inputs));return(0,_clsx).clsx(inputs)};const cva1=config=>{return props=>{var ref;if((config===null||config===void 0?void 0:config.variants)==null)return cx1(config===null||config===void 0?void 0:config.base,props===null||props===void 0?void 0:props.class,props===null||props===void 0?void 0:props.className);const{variants,defaultVariants}=config;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 variantKey=falsyToString(variantProp)||falsyToString(defaultVariantProp);return variants[variant][variantKey]});const defaultsAndProps={...defaultVariants,...props&&Object.entries(props).reduce((acc,param)=>{let[key,value]=param;return typeof value==="undefined"?acc:{...acc,[key]:value}},{})};const getCompoundVariantClassNames=config===null||config===void 0?void 0:(ref=config.compoundVariants)===null||ref===void 0?void 0:ref.reduce((acc,param1)=>{let{class:cvClass,className:cvClassName,...cvConfig}=param1;return Object.entries(cvConfig).every(param=>{let[cvKey,cvSelector]=param;const selector=defaultsAndProps[cvKey];return Array.isArray(cvSelector)?cvSelector.includes(selector):selector===cvSelector})?[...acc,cvClass,cvClassName]:acc},[]);return cx1(config===null||config===void 0?void 0:config.base,getVariantClassNames,getCompoundVariantClassNames,props===null||props===void 0?void 0:props.class,props===null||props===void 0?void 0:props.className)}};const compose1=function(){for(var _len=arguments.length,components=new Array(_len),_key=0;_key<_len;_key++){components[_key]=arguments[_key]}return props=>{const propsWithoutClass=Object.fromEntries(Object.entries(props||{}).filter(param=>{let[key]=param;return!["class","className"].includes(key)}));return cx1(components.map(component=>component(propsWithoutClass)),props===null||props===void 0?void 0:props.class,props===null||props===void 0?void 0:props.className)}};return{compose:compose1,cva:cva1,cx:cx1}};exports.defineConfig=defineConfig;const{compose,cva,cx}=defineConfig();exports.compose=compose;exports.cva=cva;exports.cx=cx
/**
* Copyright 2022 Joe Bell. All rights reserved.
*
* This file is licensed to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
compose: function() {
return compose;
},
cva: function() {
return cva;
},
cx: function() {
return cx;
},
defineConfig: function() {
return defineConfig;
}
});
const _clsx = require("clsx");
/* Exports
============================================ */ const falsyToString = (value)=>typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
const defineConfig = (options)=>{
const cx = function() {
for(var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++){
inputs[_key] = arguments[_key];
}
var _options_hooks, _options_hooks1;
if (typeof (options === null || options === void 0 ? void 0 : (_options_hooks = options.hooks) === null || _options_hooks === void 0 ? void 0 : _options_hooks["cx:done"]) !== "undefined") return options === null || options === void 0 ? void 0 : options.hooks["cx:done"]((0, _clsx.clsx)(inputs));
if (typeof (options === null || options === void 0 ? void 0 : (_options_hooks1 = options.hooks) === null || _options_hooks1 === void 0 ? void 0 : _options_hooks1.onComplete) !== "undefined") return options === null || options === void 0 ? void 0 : options.hooks.onComplete((0, _clsx.clsx)(inputs));
return (0, _clsx.clsx)(inputs);
};
const cva = (config)=>(props)=>{
var _config_compoundVariants;
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(config === null || config === void 0 ? void 0 : config.base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
const { variants, defaultVariants } = config;
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 variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
return variants[variant][variantKey];
});
const defaultsAndProps = {
...defaultVariants,
// remove `undefined` props
...props && Object.entries(props).reduce((acc, param)=>{
let [key, value] = param;
return typeof value === "undefined" ? acc : {
...acc,
[key]: value
};
}, {})
};
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param)=>{
let { class: cvClass, className: cvClassName, ...cvConfig } = param;
return Object.entries(cvConfig).every((param)=>{
let [cvKey, cvSelector] = param;
const selector = defaultsAndProps[cvKey];
return Array.isArray(cvSelector) ? cvSelector.includes(selector) : selector === cvSelector;
}) ? [
...acc,
cvClass,
cvClassName
] : acc;
}, []);
return cx(config === null || config === void 0 ? void 0 : config.base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
};
const compose = function() {
for(var _len = arguments.length, components = new Array(_len), _key = 0; _key < _len; _key++){
components[_key] = arguments[_key];
}
return (props)=>{
const propsWithoutClass = Object.fromEntries(Object.entries(props || {}).filter((param)=>{
let [key] = param;
return ![
"class",
"className"
].includes(key);
}));
return cx(components.map((component)=>component(propsWithoutClass)), props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
};
};
return {
compose,
cva,
cx
};
};
const { compose, cva, cx } = defineConfig();
//# sourceMappingURL=index.js.map

24

package.json
{
"name": "cva",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Class Variance Authority 🧬",

@@ -20,3 +20,3 @@ "keywords": [

"repository": "https://github.com/joe-bell/cva.git",
"funding": "https://joebell.co.uk/sponsors",
"funding": "https://polar.sh/cva",
"license": "Apache-2.0",

@@ -36,16 +36,16 @@ "author": "Joe Bell (https://joebell.co.uk)",

"dependencies": {
"clsx": "2.0.0"
"clsx": "^2.1.1"
},
"devDependencies": {
"@swc/cli": "0.1.57",
"@swc/core": "1.2.198",
"@types/node": "18.11.18",
"@types/react": "18.0.12",
"@types/react-dom": "18.0.5",
"bundlesize": "0.18.1",
"@swc/cli": "0.3.12",
"@swc/core": "1.4.16",
"@types/node": "20.12.7",
"@types/react": "18.2.79",
"@types/react-dom": "18.2.25",
"bundlesize": "0.18.2",
"npm-run-all": "4.1.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"ts-node": "10.8.1",
"typescript": "5.1.3"
"ts-node": "10.9.2",
"typescript": "5.4.5"
},

@@ -67,4 +67,4 @@ "peerDependencies": {

"dev": "jest --config .config/jest.config.ts --watch",
"bundlesize": "pnpm build && bundlesize -f 'dist/*.js' -s 1.2KB"
"bundlesize": "pnpm build && bundlesize -f 'dist/*.js' -s 1.6KB"
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc