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

magic-color

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-color - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

215

dist/index.d.ts
import { ColorType, Colors, Opacity, RgbColor, HslColor, HsbColor, LabColor } from '@magic-color/core';
export * from '@magic-color/core';
interface ThemeMetas {
50: string;
100: string;
200: string;
300: string;
400: string;
500: string;
600: string;
700: string;
800: string;
900: string;
950: string;
}
interface Shade {
key: number;
color: string;
}
interface NormalizedShade extends Shade {
delta: number;
lightnessDiff: number;
}
interface BasicColorShades {
id: string;
name: string;
shades: Shade[];
}
interface ClosestColorShades extends BasicColorShades {
shades: NormalizedShade[];
closestShade: NormalizedShade;
closestShadeLightness: NormalizedShade;
}
interface ThemeOptions {
/**
* Output color type
*
* @default same type as input
*/
type?: ColorType;
/**
* Custom render output color
*
* @param meta [name, color]
* @returns [CustomedName, CustomedColor]
*/
render?: (meta: [keyof ThemeMetas, string]) => [string, string];
}
declare function getColorName(color: string): string;
/**
* Generate a theme from a color
*
* @example
* ```ts
* theme('#9955FF')
* =>
{
"50": "#faf7ff",
"100": "#f5eeff",
"200": "#e6d5ff",
"300": "#d6bbff",
"400": "#b888ff",
"500": "#9955ff",
"600": "#8a4de6",
"700": "#5c3399",
"800": "#452673",
"900": "#2e1a4d",
"950": "#1f1133",
}
* ```
*
* @param color string color, if not provided, a random color will be generated
* @param options ThemeOptions
* @returns ThemeMetas
*/
declare function theme(color?: string, options?: ThemeOptions): ThemeMetas;
/**
* Color Hash
* By [Roland Rytz](https://github.com/RolandR)
*
* This function takes a string and returns a color hash.
*
* @param inputString The string to hash
* @returns
*/
declare function hash(inputString: string, type?: ColorType): string;
/**
* Credit to [@Myndex](https://github.com/Myndex) and copy from [apca-w3](https://github.com/Myndex/apca-w3)

@@ -165,12 +77,2 @@ * @see https://github.com/Myndex/apca-w3

/**
* Generate a random color
*
* @param type ColorType, default is 'hex'
* @returns any color type
*/
declare function random(type?: ColorType): string;
declare function valid(color: string): boolean;
interface ColorObject<T extends ColorType> {

@@ -217,4 +119,113 @@ type: T;

clone(): Magicolor<T>;
set(operate: string, value: unknown): void;
set<T extends ColorType>(operate: string, value: unknown): this;
get(operate: string): number;
}
declare function deltaE(a: string, b: string, Kl?: number, Kc?: number, Kh?: number): number;
/**
* Color Hash
* By [Roland Rytz](https://github.com/RolandR)
*
* This function takes a string and returns a color hash.
*
* @param inputString The string to hash
* @returns
*/
declare function hash(inputString: string, type?: ColorType): string;
interface ThemeMetas {
50: string;
100: string;
200: string;
300: string;
400: string;
500: string;
600: string;
700: string;
800: string;
900: string;
950: string;
}
interface Shade {
key: keyof ThemeMetas;
color: string;
}
interface NormalizedShade extends Shade {
delta: number;
lightnessDiff: number;
}
interface HslShade extends Shade {
hsl: [number, number, number];
}
interface BasicColorShades {
id: string;
name: string;
shades: Shade[];
}
interface ClosestColorShades extends BasicColorShades {
shades: NormalizedShade[];
closestShade: NormalizedShade;
closestShadeLightness: NormalizedShade;
}
interface ThemeOptions {
/**
* Output color type
*
* @default same type as input
*/
type?: ColorType;
/**
* Custom render output color
*
* @param meta [name, color]
* @returns [CustomedName, CustomedColor]
*/
render?: (meta: [keyof ThemeMetas, string]) => [string, string];
}
interface GenerateMeta extends BasicColorShades {
shades: HslShade[];
}
declare function getColorName(color: string): string;
/**
* Generate a theme from a color
*
* @example
* ```ts
* theme('#9955FF')
* =>
{
"50": "#faf7ff",
"100": "#f5eeff",
"200": "#e6d5ff",
"300": "#d6bbff",
"400": "#b888ff",
"500": "#9955ff",
"600": "#8a4de6",
"700": "#5c3399",
"800": "#452673",
"900": "#2e1a4d",
"950": "#1f1133",
}
* ```
*
* @param color string color, if not provided, a random color will be generated
* @param options ThemeOptions
* @returns ThemeMetas
*/
declare function theme(color?: string, options?: ThemeOptions): ThemeMetas;
/**
* Generate a random color
*
* @param type ColorType, default is 'hex'
* @returns any color type
*/
declare function random(type?: ColorType): string;
declare const SupportTypes: string[];
declare function valid(color: string): boolean;
interface MagicolorInstance {

@@ -227,3 +238,3 @@ <T extends ColorType>(value: Colors[T] | Record<string, number>, type?: T, alpha?: Opacity): Magicolor<T>;

theme: typeof theme;
getColorName: typeof getColorName;
nameOf: typeof getColorName;
wcag: typeof calcWCAG;

@@ -234,5 +245,7 @@ apca: typeof calcAPCA;

warm: typeof isWarmColor;
supports: typeof SupportTypes;
deltaE: typeof deltaE;
}
declare const mc: MagicolorInstance;
export { type BasicColorShades, type ClosestColorShades, type ColorObject, Magicolor, type ThemeMetas, type ThemeOptions, calcAPCA, calcWCAG, getColorName, getReadableTextColor, hash, isWarmColor, mc, random, reverseAPCA, theme };
export { type BasicColorShades, type ClosestColorShades, type ColorObject, type GenerateMeta, Magicolor, type MagicolorInstance, type ThemeMetas, type ThemeOptions, calcAPCA, calcWCAG, getColorName, getReadableTextColor, hash, isWarmColor, mc, random, reverseAPCA, theme };
{
"name": "magic-color",
"type": "module",
"version": "1.2.2",
"version": "1.3.0",
"description": "Magic color creator.",

@@ -41,8 +41,4 @@ "author": "Chris <hizyyv@gmail.com>",

"dependencies": {
"chroma-js": "^2.6.0",
"@magic-color/core": "1.2.2"
"@magic-color/core": "1.3.0"
},
"devDependencies": {
"@types/chroma-js": "^2.4.4"
},
"scripts": {

@@ -49,0 +45,0 @@ "build": "unbuild",

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