nhb-toolbox 4.0.51 → 4.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -200,30 +200,28 @@ class Color {
200
200
  /**
201
201
  * @instance Blends the current color with another color based on the given weight.
202
202
  *
203
- * - **NOTE:** *If any of the input colors has opacity (alpha channel), it might be lost from the generated alpha variants of the respective color formats.*
204
- * @param other - The color in any 6 `(Hex, Hex8 RGB, RGBA, HSL or HSLA)` to blend with.
203
+ * - **NOTE:** *If any of the input colors has opacity (alpha channel), it might be lost or distorted from the generated alpha variants of the respective color formats.*
204
+ *
205
+ * @param other - The color in any 6 `(Hex, Hex8 RGB, RGBA, HSL or HSLA)` format to blend with.
205
206
  * @param weight - A number from 0 to 1 indicating the weight of the other color. Defaults to `0.5`.
206
- * - `weight = 0` → only the original color (this)
207
- * - `weight = 1` → only the other color
208
- * - `weight = 0.5` → equal blend between the two
209
- * @returns A new `Color` instance representing the blended result.
207
+ * - `weight = 0` → only the original color.
208
+ * - `weight = 1` → only the other color.
209
+ * - `weight = 0.5` → equal blend between the two.
210
+ * @returns A new `Color` instance representing the blended result, with proper alpha blending.
210
211
  */
211
212
  blendWith(other, weight = 0.5) {
212
213
  const w = Math.max(0, Math.min(1, weight));
213
214
  const converted = new Color(other);
214
215
  const [r1, b1, g1, a1] = (0, helpers_1._extractAlphaColorValues)(this.rgba);
215
216
  const [r2, b2, g2, a2] = (0, helpers_1._extractAlphaColorValues)(converted.rgba);
216
- const alpha = a1 * (1 - w) + a2 * w;
217
- // ! Original code for solid color
218
- // const blended = rgb1.map((c, i) =>
219
- // Math.round(c * (1 - w) + rgb2[i] * w),
220
- // ) as ColorNumbers;
221
- // const blendedRGB = `rgb(${blended[0]}, ${blended[1]}, ${blended[2]})`;
222
- const blendChannel = (c1, c2) => Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
217
+ const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
218
+ const blendChannel = (c1, c2) => {
219
+ return Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
220
+ };
223
221
  const r = blendChannel(r1, r2);
224
222
  const g = blendChannel(g1, g2);
225
223
  const b = blendChannel(b1, b2);
226
- const blended = `rgba(${r}, ${g}, ${b}, ${+alpha.toFixed(2)})`;
224
+ const blended = `rgba(${r}, ${g}, ${b}, ${alpha})`;
227
225
  return new Color(blended);
228
226
  }
229
227
  /**
@@ -130,13 +130,14 @@ export declare class Color {
130
130
  /**
131
131
  * @instance Blends the current color with another color based on the given weight.
132
132
  *
133
- * - **NOTE:** *If any of the input colors has opacity (alpha channel), it might be lost from the generated alpha variants of the respective color formats.*
134
- * @param other - The color in any 6 `(Hex, Hex8 RGB, RGBA, HSL or HSLA)` to blend with.
133
+ * - **NOTE:** *If any of the input colors has opacity (alpha channel), it might be lost or distorted from the generated alpha variants of the respective color formats.*
134
+ *
135
+ * @param other - The color in any 6 `(Hex, Hex8 RGB, RGBA, HSL or HSLA)` format to blend with.
135
136
  * @param weight - A number from 0 to 1 indicating the weight of the other color. Defaults to `0.5`.
136
- * - `weight = 0` → only the original color (this)
137
- * - `weight = 1` → only the other color
138
- * - `weight = 0.5` → equal blend between the two
139
- * @returns A new `Color` instance representing the blended result.
137
+ * - `weight = 0` → only the original color.
138
+ * - `weight = 1` → only the other color.
139
+ * - `weight = 0.5` → equal blend between the two.
140
+ * @returns A new `Color` instance representing the blended result, with proper alpha blending.
140
141
  */
141
142
  blendWith(other: ColorType, weight?: number): Color;
142
143
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../../src/colors/Color.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAEX,SAAS,EAET,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,OAAO,EACP,GAAG,EACH,IAAI,EAEJ,MAAM,EACN,KAAK,EACL,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;GA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instance Blends the current color with another color based on the given weight.
199
199
  *
200
- * - **NOTE:** *If any of the input colors has opacity (alpha channel), it might be lost from the generated alpha variants of the respective color formats.*
201
- * @param other - The color in any 6 `(Hex, Hex8 RGB, RGBA, HSL or HSLA)` to blend with.
200
+ * - **NOTE:** *If any of the input colors has opacity (alpha channel), it might be lost or distorted from the generated alpha variants of the respective color formats.*
201
+ *
202
+ * @param other - The color in any 6 `(Hex, Hex8 RGB, RGBA, HSL or HSLA)` format to blend with.
202
203
  * @param weight - A number from 0 to 1 indicating the weight of the other color. Defaults to `0.5`.
203
- * - `weight = 0` → only the original color (this)
204
- * - `weight = 1` → only the other color
205
- * - `weight = 0.5` → equal blend between the two
206
- * @returns A new `Color` instance representing the blended result.
204
+ * - `weight = 0` → only the original color.
205
+ * - `weight = 1` → only the other color.
206
+ * - `weight = 0.5` → equal blend between the two.
207
+ * @returns A new `Color` instance representing the blended result, with proper alpha blending.
207
208
  */
208
209
  blendWith(other, weight = 0.5) {
209
210
  const w = Math.max(0, Math.min(1, weight));
210
211
  const converted = new Color(other);
211
212
  const [r1, b1, g1, a1] = _extractAlphaColorValues(this.rgba);
212
213
  const [r2, b2, g2, a2] = _extractAlphaColorValues(converted.rgba);
213
- const alpha = a1 * (1 - w) + a2 * w;
214
- // ! Original code for solid color
215
- // const blended = rgb1.map((c, i) =>
216
- // Math.round(c * (1 - w) + rgb2[i] * w),
217
- // ) as ColorNumbers;
218
- // const blendedRGB = `rgb(${blended[0]}, ${blended[1]}, ${blended[2]})`;
219
- const blendChannel = (c1, c2) => Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
214
+ const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
215
+ const blendChannel = (c1, c2) => {
216
+ return Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
217
+ };
220
218
  const r = blendChannel(r1, r2);
221
219
  const g = blendChannel(g1, g2);
222
220
  const b = blendChannel(b1, b2);
223
- const blended = `rgba(${r}, ${g}, ${b}, ${+alpha.toFixed(2)})`;
221
+ const blended = `rgba(${r}, ${g}, ${b}, ${alpha})`;
224
222
  return new Color(blended);
225
223
  }
226
224
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.0.51",
3
+ "version": "4.0.52",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",