From 628c734afb704cbf132a1078f660df05f98e092e Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Wed, 19 Aug 2026 08:06:03 +0300 Subject: [PATCH 1/2] Switch to using `marangi` color management dependency --- package-lock.json | 17 +- packages/color/package.json | 3 +- packages/color/src/core/color.js | 349 ------------------------------- packages/color/src/core/index.js | 2 +- 4 files changed, 19 insertions(+), 352 deletions(-) delete mode 100644 packages/color/src/core/color.js diff --git a/package-lock.json b/package-lock.json index b68f355b..1e9aee9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3879,6 +3879,20 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/marangi": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/marangi/-/marangi-0.2.0.tgz", + "integrity": "sha512-GpEv/SK3IqmLjHQPfc+KhamiyAz2TEHUoSEqP1Hgl0nj82wiN2TPlsFl1AXEbdl1D/h/hSSfJUpe6PBNz47fKg==", + "license": "MIT", + "dependencies": { + "hisabati": "^0.1.0" + } + }, + "node_modules/marangi/node_modules/hisabati": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/hisabati/-/hisabati-0.1.0.tgz", + "integrity": "sha512-hNFi+jZb6yUG4BXArUyRcq9vHqYE1DhOqG+kE5vvOZVRN5+4CPsLbZEz4RYnKPHMsUfb5EtyVERVDUriq4c9Tw==" + }, "node_modules/markdown-it": { "version": "14.1.1", "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz", @@ -5249,7 +5263,8 @@ "@wimaengine/ecs": "0.3.0", "@wimaengine/math": "0.3.0", "@wimaengine/reflect": "0.3.0", - "@wimaengine/type": "0.3.0" + "@wimaengine/type": "0.3.0", + "marangi": "^0.2.0" } }, "packages/command": { diff --git a/packages/color/package.json b/packages/color/package.json index 1f55e2f1..d4615177 100644 --- a/packages/color/package.json +++ b/packages/color/package.json @@ -35,7 +35,8 @@ "@wimaengine/ecs": "0.3.0", "@wimaengine/math": "0.3.0", "@wimaengine/reflect": "0.3.0", - "@wimaengine/type": "0.3.0" + "@wimaengine/type": "0.3.0", + "marangi": "^0.2.0" }, "types": "./dist/index.d.ts" } diff --git a/packages/color/src/core/color.js b/packages/color/src/core/color.js deleted file mode 100644 index 2582efb3..00000000 --- a/packages/color/src/core/color.js +++ /dev/null @@ -1,349 +0,0 @@ -import { lerp } from '@wimaengine/math' - -/** - * A color manipulation class. - */ -export class Color { - - /** - * @type {number} - */ - r - - /** - * @type {number} - */ - b - - /** - * @type {number} - */ - g - - /** - * @type {number} - */ - a - - /** - * @param {number} r - The red channel [0 .. 1]. - * @param {number} g - The green channel [0 .. 1]. - * @param {number} b - The blue channe; [0 .. 1]. - * @param {number} alpha - The alpha channel [0 .. 1]. - */ - constructor(r = 1, g = 1, b = 1, alpha = 1) { - Color.set(r, g, b, alpha, this) - } - - /** - * Set this color to the specified value. - * @param {number} r - Red component [0 .. 255]. - * @param {number} g - Green component [0 .. 255]. - * @param {number} b - Blue component [0 .. 255]. - * @param {number} [alpha=1.0] - Alpha value [0.0 .. 1.0]. - * @returns {this} Reference to this object for method chaining. - */ - set(r, g, b, alpha = 1.0) { - Color.set(r, g, b, alpha, this) - - return this - } - - /** - * Create a new copy of this color object. - * @returns {Color} Reference to the newly cloned object. - */ - clone() { - return Color.copy(this) - } - - /** - * Copy a color object or CSS color into this one. - * @param {Color} color - * @returns {this} Reference to this object for method chaining. - */ - copy(color) { - Color.copy(color, this) - - return this - } - - /** - * Blend this color with the given one using addition. - * - * @param {Color} color - * @returns {this} Reference to this object for method chaining. - */ - add(color) { - Color.add(this, color, this) - - return this - } - - /** - * Darken this color value by 0..1. - * - * @param {number} scale - * @returns {this} Reference to this object for method chaining. - */ - darken(scale) { - Color.darken(this, scale, this) - - return this - } - - /** - * Lighten this color value by 0..1. - * - * @param {number} scale - * @returns {this} Reference to this object for method chaining. - */ - lighten(scale) { - Color.lighten(this, scale, this) - - return this - } - - /** - * Linearly interpolate between this color and the given one. - * @param {Color} color - * @param {number} alpha - With alpha = 0 being this color, and alpha = 1 being the given one. - * @returns {this} Reference to this object for method chaining. - */ - lerp(color, alpha) { - Color.lerp(this, color, alpha) - - return this - } - - /** - * Generate random r,g,b values for this color object. - * @returns {this} - */ - random() { - Color.random(this) - - return this - } - - /** - * @param {number} r - * @param {number} g - * @param {number} b - * @param {number} a - * @param {Color} color - */ - static set(r, g, b, a, color = new Color()) { - color.r = r - color.g = g - color.b = b - color.a = a - - return color - } - - /** - * @param {Color} color - * @param {Color} [out] - */ - static copy(color, out = new Color()) { - return Color.set(color.r, color.g, color.b, color.a, out) - } - - /** - * @param {Color} value - */ - static serialize(value) { - return { - r: value.r, - g: value.g, - b: value.b, - a: value.a - } - } - - /** - * @param {ColorSerial} value - * @param {Color} [out] - */ - static deserialize(value, out = new Color()) { - out.r = value.r - out.g = value.g - out.b = value.b - out.a = value.a - - return out - } - - /** - * @param {unknown} value - * @returns {value is ColorSerial} - */ - static validateSerial(value) { - if (!value || typeof value !== 'object') { - return false - } - - if (!('r' in value) || !('g' in value) || !('b' in value) || !('a' in value)) { - return false - } - - return typeof value.r === 'number' && - typeof value.g === 'number' && - typeof value.b === 'number' && - typeof value.a === 'number' - } - - /** - * @param {Color} color1 - * @param {Color} color2 - * @param {Color} [out] - */ - static add(color1, color2, out = new Color()) { - out.r = color1.r + color2.r - out.g = color1.g + color2.g - out.b = color1.b + color2.b - out.a = (color1.a + color2.a) / 2 - - return out - } - - /** - * @param {Color} color1 - * @param {Color} color2 - * @param {Color} [out] - */ - static subtract(color1, color2, out = new Color()) { - out.r = color1.r - color2.r - out.g = color1.g - color2.g - out.b = color1.b - color2.b - out.a = (color1.a + color2.a) / 2 - - return out - } - - /** - * @param {Color} color - * @param {number} scale - * @param {Color} [out] - */ - static darken(color, scale, out = new Color()) { - out.r = color.r * scale - out.g = color.g * scale - out.b = color.b * scale - out.a = color.a - - return this - } - - /** - * @param {Color} color - * @param {number} scale - * @param {Color} [out] - */ - static lighten(color, scale, out = new Color()) { - out.r = color.r + (1 - color.r) * scale - out.g = color.g + (1 - color.g) * scale - out.b = color.b + (1 - color.b) * scale - out.a = color.a - - return out - } - - /** - * @param {Color} from - * @param {Color} to - * @param {number} t - * @param {Color} out - */ - static lerp(from, to, t, out = new Color()) { - out.r = lerp(from.r, to.r, t) - out.g = lerp(from.g, to.g, t) - out.b = lerp(from.b, to.b, t) - out.a = lerp(from.a, to.a, t) - - return out - } - - /** - * @param {Color} [out] - * @returns {Color} - */ - static random(out = new Color()) { - return Color.set( - Math.random(), - Math.random(), - Math.random(), - 1, - out - ) - } - - /** - * Allows for iteration of components. - * - * @yields {number} - */ - * [Symbol.iterator]() { - yield this.r - yield this.g - yield this.b - yield this.a - } - - /** - * @readonly - * @type {Color} - */ - static BLACK = new Color(0, 0, 0) - - /** - * @readonly - * @type {Color} - */ - static WHITE = new Color(1, 1, 1) - - /** - * @readonly - * @type {Color} - */ - static RED = new Color(1, 0, 0) - - /** - * @readonly - * @type {Color} - */ - static GREEN = new Color(0, 1, 0) - - /** - * @readonly - * @type {Color} - */ - static BLUE = new Color(0, 0, 1) - - /** - * @readonly - * @type {Color} - */ - static YELLOW = new Color(1, 1, 0) - - /** - * @readonly - * @type {Color} - */ - static PURPLE = new Color(1, 0, 1) - - /** - * @readonly - * @type {Color} - */ - static CYAN = new Color(0, 1, 1) -} - -/** - * @typedef ColorSerial - * @property {number} r - * @property {number} g - * @property {number} b - * @property {number} a - */ diff --git a/packages/color/src/core/index.js b/packages/color/src/core/index.js index 1315dbcf..3fdcdb3f 100644 --- a/packages/color/src/core/index.js +++ b/packages/color/src/core/index.js @@ -1 +1 @@ -export * from './color' +export * from 'marangi' From d4ec81e3e920bf6c4621f5805152ed8de41935e6 Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Wed, 19 Aug 2026 08:06:26 +0300 Subject: [PATCH 2/2] Update dependents of color module --- packages/render-core/src/assets/materials/basic.js | 2 +- packages/render-webgl/src/resources/clearcolor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/render-core/src/assets/materials/basic.js b/packages/render-core/src/assets/materials/basic.js index 8dc45f5f..ed8e9703 100644 --- a/packages/render-core/src/assets/materials/basic.js +++ b/packages/render-core/src/assets/materials/basic.js @@ -69,5 +69,5 @@ export class BasicMaterial extends Material { /** * @typedef BasicMaterialSerial - * @property {import('@wimaengine/color').ColorSerial} color + * @property {import('@wimaengine/color').ColorLike} color */ diff --git a/packages/render-webgl/src/resources/clearcolor.js b/packages/render-webgl/src/resources/clearcolor.js index 45973208..0d75d7e4 100644 --- a/packages/render-webgl/src/resources/clearcolor.js +++ b/packages/render-webgl/src/resources/clearcolor.js @@ -13,7 +13,7 @@ export class ClearColor extends Color { } /** - * @param {import('@wimaengine/color').ColorSerial} value + * @param {import('@wimaengine/color').ColorLike} value * @param {ClearColor} [out] */ static deserialize(value, out = new ClearColor()) {