Skip to content

Commit

Permalink
refactor: overtone has been deprecated into an object property in fam…
Browse files Browse the repository at this point in the history
…ily()
  • Loading branch information
xmlwizard committed Dec 17, 2024
1 parent c2eaf67 commit 34fb6c8
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 124 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 20 additions & 49 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,33 +667,37 @@ function luminance<Amount>(
*
* 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

}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -821,7 +792,7 @@ export {
lightness,
luminance,
mc,
overtone,

temp,
token,
};
25 changes: 2 additions & 23 deletions lib/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
family,
lightness,
mc,
overtone,

temp,
token,
} from "./utils.ts";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
*
Expand Down
104 changes: 54 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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": "[email protected]",
"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"
]
}
6 changes: 4 additions & 2 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ const specs: Spec[] = [{
},
{
description: 'gets the hue family of a color token',
params: [str],
params: [str, true],
callback: family
}
},


];


Expand Down

0 comments on commit 34fb6c8

Please sign in to comment.