diff --git a/bun.lockb b/bun.lockb index bc79cca1..efc39c21 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/deno.lock b/deno.lock index 2c4f10c6..98654ad3 100644 --- a/deno.lock +++ b/deno.lock @@ -33,6 +33,7 @@ "workspace": { "packageJson": { "dependencies": [ + "npm:@biomejs/biome@1.9.4", "npm:@types/bun@^1.1.9", "npm:@types/culori@^2.1.0", "npm:bun@^1.1.34", diff --git a/lib/utils.ts b/lib/utils.ts index 9bddbdb4..c31ba134 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -667,33 +667,37 @@ function luminance( * * For example `'red'` or `'blue-green'`. If the color is achromatic it returns the string `'gray'`. * @param color The color to query its shade or hue family. + * @param [bias=false] Returns the name of the hue family which is biasing the passed in color using the `'lch'` colorspace. If it has no bias it returns `false` on the `bias` property of the returned object. + * :::note + * + * This `bias` parameter replaces the `overtone()` function. + * + ::: + * * @example * * import { family } from 'huetiful-js' console.log(family("#310000")) + // 'red' */ -function family(color?: ColorToken): BiasedHues & ColorFamily { - - if (!achromatic(color)) - - - - - +function family(color?: ColorToken, bias = false): BiasedHues & ColorFamily | { hue: BiasedHues & ColorFamily; bias: false | ColorFamily } { + // @ts-ignore: + const res = !achromatic(color) && hue.find((arr) => { // @ts-ignore: - return hue.find((arr) => { - // @ts-ignore: - const hueRanges = arr.slice(1).flat(1) as number[] - - return inRange(mc("lch.h")(color), min(hueRanges), max(hueRanges)) - })[0]; + const hueRanges = arr.slice(1).flat(1) as number[] + return inRange(mc("lch.h")(color), min(hueRanges), max(hueRanges)) + })[0] || "gray"; // @ts-ignore: - return "gray"; + return bias && { + hue: res, + bias: ((/-/.test(res) && res.split("-")[1]) || false) + } || res + } /** @@ -740,39 +744,6 @@ function temp(color: ColorToken = "cyan"): "cool" | "warm" { ); } -/** - * Returns the name of the hue family which is biasing the passed in color using the `'lch'` colorspace. - * - * * If an achromatic color is passed in it returns the string `'gray'` - * * If the color has no bias it returns `false`. - * @param color The color to query its overtone. - - * @example - * - * import { overtone } from "huetiful-js"; - * -console.log(overtone("fefefe")) -// 'gray' - -console.log(overtone("cyan")) -// 'green' - -console.log(overtone("blue")) -// false - */ -function overtone( - color?: ColorToken, -): ColorFamily | false { - const hueFamily = family(color); - - // We check if the color can be found in the defined ranges - // @ts-ignore: - return ( - (achromatic(color) && "gray") - // @ts-ignore: - || ((/-/.test(hueFamily) && hueFamily.split("-")[1]) || false) - ); -} /** * Returns the complimentary color of the passed in color token. A complimentary color is 180 degrees away on the hue channel. @@ -821,7 +792,7 @@ export { lightness, luminance, mc, - overtone, + temp, token, }; diff --git a/lib/wrappers.ts b/lib/wrappers.ts index a2f61de1..550c4419 100644 --- a/lib/wrappers.ts +++ b/lib/wrappers.ts @@ -35,7 +35,7 @@ import { family, lightness, mc, - overtone, + temp, token, } from "./utils.ts"; @@ -561,7 +561,7 @@ class Color { console.log(color("#310000").family()) // 'red' */ - family(): BiasedHues & ColorFamily { + family(): BiasedHues & ColorFamily | { hue: BiasedHues & ColorFamily; bias: false | ColorFamily } { // @ts-ignore: return this.#setThis(family); @@ -789,27 +789,6 @@ class Color { return this.#setThis(deficiency, options); } - /** - * Returns the name of the hue family which is biasing the passed in color. - * - * * If an achromatic color is passed in it returns the string `'gray'` - * * If the color has no bias it returns `false`. - * - * @example - * - console.log(color("fefefe").overtone()) - // 'gray' - - console.log(color("cyan").overtone()) - // 'green' - - console.log(color("blue").overtone()) - // false - */ - overtone(): ColorFamily { - // @ts-ignore: - return this.#setThis(overtone); - } /** * diff --git a/package.json b/package.json index 1abb132c..91e7a295 100644 --- a/package.json +++ b/package.json @@ -1,52 +1,56 @@ { - "name": "@prjctimg/huetiful", - "version": "3.0.6", - "type": "module", - "main": "./build/huetiful.esm.js", - "browser": "./build/huetiful.min.js", - "jsdelivr": "./build/huetiful.min.js", - "types": "./build/index.d.ts", - "description": "TypeScript utility library for simple 🧮, fast ⏱️ and accessible ♿ color manipulation.", - "dependencies": { - "culori": "^4.0.1" - }, - "devDependencies": { - "@types/bun": "^1.1.9", - "@types/culori": "^2.1.0", - "bun": "^1.1.34", - "tsup": "^8.2.4", - "typescript": "^5.0.2" - }, - "files": [ - "build", - "CHANGELOG.md", - "readme.md", - "contributing.md", - "license" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/prjctimg/huetiful.git" - }, - "keywords": [ - "color", - "stats", - "culori", - "palettes", - "generator", - "utilities", - "manipulation", - "typescript" - ], - "author": "ディーン・タリサイ", - "email": "prjctimg@outlook.com", - "homepage": "https://huetiful-js.com", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/prjctimg/huetiful/issues" - }, - "directories": { - "lib": "lib", - "test": "tests" - } + "name": "@prjctimg/huetiful", + "version": "3.0.6", + "type": "module", + "main": "./build/huetiful.esm.js", + "browser": "./build/huetiful.min.js", + "jsdelivr": "./build/huetiful.min.js", + "types": "./build/index.d.ts", + "description": "TypeScript utility library for simple 🧮, fast ⏱️ and accessible ♿ color manipulation.", + "dependencies": { + "culori": "^4.0.1" + }, + "devDependencies": { + "@biomejs/biome": "1.9.4", + "@types/bun": "^1.1.9", + "@types/culori": "^2.1.0", + "bun": "^1.1.34", + "tsup": "^8.2.4", + "typescript": "^5.0.2" + }, + "files": [ + "build", + "CHANGELOG.md", + "readme.md", + "contributing.md", + "license" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/prjctimg/huetiful.git" + }, + "keywords": [ + "color", + "stats", + "culori", + "palettes", + "generator", + "utilities", + "manipulation", + "typescript" + ], + "author": "ディーン・タリサイ", + "email": "prjctimg@outlook.com", + "homepage": "https://huetiful-js.com", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/prjctimg/huetiful/issues" + }, + "directories": { + "lib": "lib", + "test": "tests" + }, + "trustedDependencies": [ + "@biomejs/biome" + ] } diff --git a/tests/utils.test.ts b/tests/utils.test.ts index b87a717d..7d2ebe56 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -92,9 +92,11 @@ const specs: Spec[] = [{ }, { description: 'gets the hue family of a color token', - params: [str], + params: [str, true], callback: family -} +}, + + ];