@mathigon/core
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -405,2 +405,3 @@ "use strict"; | ||
} | ||
/** Adds an event listener for one or more events. */ | ||
on(events, fn) { | ||
@@ -413,2 +414,3 @@ for (const e of words(events)) { | ||
} | ||
/** Adds a one-time event listener to one or more events. */ | ||
one(events, fn) { | ||
@@ -421,2 +423,3 @@ const callback = (e) => { | ||
} | ||
/** Removes an event listener from one or more events. */ | ||
off(events, fn) { | ||
@@ -429,2 +432,3 @@ for (const e of words(events)) { | ||
} | ||
/** Triggers one or more events, and executes all bound event listeners. */ | ||
trigger(events, arg) { | ||
@@ -486,2 +490,3 @@ for (const e of words(events)) { | ||
} | ||
/** Converts this color to a hex string. */ | ||
get hex() { | ||
@@ -492,2 +497,3 @@ const c = [this.r, this.g, this.b].map((x) => pad2(Math.round(x).toString(16))); | ||
} | ||
/** Converts this color to an rgba string. */ | ||
get rgb() { | ||
@@ -497,5 +503,7 @@ const c = [this.r, this.g, this.b].map((x) => Math.round(x)).join(","); | ||
} | ||
/** Get the brightness of this color. */ | ||
get brightness() { | ||
return (this.r * 299 + this.g * 587 + this.g * 114) / 1e3; | ||
} | ||
/** Converts this color to an HSL array. */ | ||
get hsl() { | ||
@@ -524,5 +532,7 @@ const r = this.r / 255; | ||
} | ||
/** Creates a copy of this color. */ | ||
copy() { | ||
return new Color(this.r, this.g, this.b, this.a); | ||
} | ||
// --------------------------------------------------------------------------- | ||
static from(color) { | ||
@@ -540,2 +550,3 @@ if (typeof color !== "string") | ||
} | ||
/** Creates a Color instance from a hex string. */ | ||
static fromHex(hex) { | ||
@@ -568,5 +579,7 @@ hex = hex.replace(shortHexRegex, (_m, r, g, b) => r + r + g + g + b + b); | ||
} | ||
/** Generates a rainbow gradient with a given number of steps. */ | ||
static rainbow(steps) { | ||
return tabulate((x) => getColorAt(rainbow, x / (steps - 1)), steps); | ||
} | ||
/** Generates a rainbow gradient with a given number of steps. */ | ||
static gradient(colors, steps) { | ||
@@ -580,2 +593,3 @@ return tabulate((x) => getColorAt(colors, x / (steps - 1)), steps); | ||
} | ||
/** Linearly interpolates two colors or hex strings. */ | ||
static mix(c1, c2, p = 0.5) { | ||
@@ -582,0 +596,0 @@ c1 = Color.from(c1); |
@@ -331,2 +331,3 @@ // src/utilities.ts | ||
} | ||
/** Adds an event listener for one or more events. */ | ||
on(events, fn) { | ||
@@ -339,2 +340,3 @@ for (const e of words(events)) { | ||
} | ||
/** Adds a one-time event listener to one or more events. */ | ||
one(events, fn) { | ||
@@ -347,2 +349,3 @@ const callback = (e) => { | ||
} | ||
/** Removes an event listener from one or more events. */ | ||
off(events, fn) { | ||
@@ -355,2 +358,3 @@ for (const e of words(events)) { | ||
} | ||
/** Triggers one or more events, and executes all bound event listeners. */ | ||
trigger(events, arg) { | ||
@@ -412,2 +416,3 @@ for (const e of words(events)) { | ||
} | ||
/** Converts this color to a hex string. */ | ||
get hex() { | ||
@@ -418,2 +423,3 @@ const c = [this.r, this.g, this.b].map((x) => pad2(Math.round(x).toString(16))); | ||
} | ||
/** Converts this color to an rgba string. */ | ||
get rgb() { | ||
@@ -423,5 +429,7 @@ const c = [this.r, this.g, this.b].map((x) => Math.round(x)).join(","); | ||
} | ||
/** Get the brightness of this color. */ | ||
get brightness() { | ||
return (this.r * 299 + this.g * 587 + this.g * 114) / 1e3; | ||
} | ||
/** Converts this color to an HSL array. */ | ||
get hsl() { | ||
@@ -450,5 +458,7 @@ const r = this.r / 255; | ||
} | ||
/** Creates a copy of this color. */ | ||
copy() { | ||
return new Color(this.r, this.g, this.b, this.a); | ||
} | ||
// --------------------------------------------------------------------------- | ||
static from(color) { | ||
@@ -466,2 +476,3 @@ if (typeof color !== "string") | ||
} | ||
/** Creates a Color instance from a hex string. */ | ||
static fromHex(hex) { | ||
@@ -494,5 +505,7 @@ hex = hex.replace(shortHexRegex, (_m, r, g, b) => r + r + g + g + b + b); | ||
} | ||
/** Generates a rainbow gradient with a given number of steps. */ | ||
static rainbow(steps) { | ||
return tabulate((x) => getColorAt(rainbow, x / (steps - 1)), steps); | ||
} | ||
/** Generates a rainbow gradient with a given number of steps. */ | ||
static gradient(colors, steps) { | ||
@@ -506,2 +519,3 @@ return tabulate((x) => getColorAt(colors, x / (steps - 1)), steps); | ||
} | ||
/** Linearly interpolates two colors or hex strings. */ | ||
static mix(c1, c2, p = 0.5) { | ||
@@ -508,0 +522,0 @@ c1 = Color.from(c1); |
{ | ||
"name": "@mathigon/core", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"license": "MIT", | ||
@@ -36,12 +36,12 @@ "homepage": "https://mathigon.io/core", | ||
"@types/tape": "4.13.2", | ||
"@typescript-eslint/eslint-plugin": "5.45.0", | ||
"@typescript-eslint/parser": "5.45.0", | ||
"esbuild": "0.15.16", | ||
"eslint": "8.28.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"tape": "5.6.1", | ||
"@typescript-eslint/eslint-plugin": "5.50.0", | ||
"@typescript-eslint/parser": "5.50.0", | ||
"esbuild": "0.17.5", | ||
"eslint": "8.33.0", | ||
"eslint-plugin-import": "2.27.5", | ||
"tape": "5.6.3", | ||
"ts-node": "10.9.1", | ||
"tslib": "2.4.1", | ||
"typescript": "4.9.3" | ||
"tslib": "2.5.0", | ||
"typescript": "4.9.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182469
3954
2804