Publish.
This commit is contained in:
parent
5d2c5c37c3
commit
7f18e0818f
7 changed files with 39 additions and 13 deletions
|
@ -1,8 +1,15 @@
|
|||
"use strict";
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _EliteMatrix_instances, _EliteMatrix_round;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EliteMatrix = void 0;
|
||||
class EliteMatrix {
|
||||
constructor(matrixRed, matrixGreen, matrixBlue) {
|
||||
_EliteMatrix_instances.add(this);
|
||||
this.red = matrixRed;
|
||||
this.green = matrixGreen;
|
||||
this.blue = matrixBlue;
|
||||
|
@ -16,9 +23,12 @@ class EliteMatrix {
|
|||
const green = parseInt(color.slice(3, 5), 16) / 255;
|
||||
const blue = parseInt(color.slice(5, 7), 16) / 255;
|
||||
rgb = [red, green, blue];
|
||||
// Round to 2 decimal places.
|
||||
rgb = rgb.map(n => __classPrivateFieldGet(this, _EliteMatrix_instances, "m", _EliteMatrix_round).call(this, n));
|
||||
}
|
||||
else {
|
||||
rgb = color;
|
||||
// Convert RGB decimal to RGB percent.
|
||||
rgb = color.map(n => __classPrivateFieldGet(this, _EliteMatrix_instances, "m", _EliteMatrix_round).call(this, n / 255));
|
||||
}
|
||||
// Apply matrix filter.
|
||||
let newColor = [];
|
||||
|
@ -29,17 +39,19 @@ class EliteMatrix {
|
|||
this.blue[i] * rgb[2]);
|
||||
i++;
|
||||
}
|
||||
newColor.forEach((n) => {
|
||||
Math.max(Math.min(n, 1), 0);
|
||||
});
|
||||
// Make sure we don't have anything above 1 or below 0.
|
||||
newColor = newColor.map((n) => Math.max(Math.min(n, 1), 0));
|
||||
// Round again.
|
||||
newColor = newColor.map((n) => __classPrivateFieldGet(this, _EliteMatrix_instances, "m", _EliteMatrix_round).call(this, n));
|
||||
// Return the same data type as user put in.
|
||||
if (Array.isArray(color)) {
|
||||
return newColor;
|
||||
return newColor.map(n => Math.round(n * 255));
|
||||
}
|
||||
else {
|
||||
let hex = '#';
|
||||
newColor.forEach((n) => {
|
||||
n *= 255;
|
||||
n = Math.round(n);
|
||||
hex += n.toString(16);
|
||||
});
|
||||
return hex;
|
||||
|
@ -47,3 +59,6 @@ class EliteMatrix {
|
|||
}
|
||||
}
|
||||
exports.EliteMatrix = EliteMatrix;
|
||||
_EliteMatrix_instances = new WeakSet(), _EliteMatrix_round = function _EliteMatrix_round(n) {
|
||||
return Math.round((n + Number.EPSILON) * 100) / 100;
|
||||
};
|
||||
|
|
1
lib/cjs/types/index.d.ts
vendored
1
lib/cjs/types/index.d.ts
vendored
|
@ -1,6 +1,7 @@
|
|||
type matrix = [number, number, number];
|
||||
type rgbColor = [number, number, number];
|
||||
export declare class EliteMatrix {
|
||||
#private;
|
||||
red: matrix;
|
||||
green: matrix;
|
||||
blue: matrix;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,qBAAa,WAAW;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;gBAED,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQtE,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAC,MAAM,GAAG,QAAQ,GAAC,MAAM;CA6CvD"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,qBAAa,WAAW;;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;gBAED,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQtE,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAC,MAAM,GAAG,QAAQ,GAAC,MAAM;CA0DvD"}
|
|
@ -16,9 +16,12 @@ export class EliteMatrix {
|
|||
const green = parseInt(color.slice(3, 5), 16) / 255;
|
||||
const blue = parseInt(color.slice(5, 7), 16) / 255;
|
||||
rgb = [red, green, blue];
|
||||
// Round to 2 decimal places.
|
||||
rgb = rgb.map(n => this.#round(n));
|
||||
}
|
||||
else {
|
||||
rgb = color;
|
||||
// Convert RGB decimal to RGB percent.
|
||||
rgb = color.map(n => this.#round(n / 255));
|
||||
}
|
||||
// Apply matrix filter.
|
||||
let newColor = [];
|
||||
|
@ -29,20 +32,26 @@ export class EliteMatrix {
|
|||
this.blue[i] * rgb[2]);
|
||||
i++;
|
||||
}
|
||||
newColor.forEach((n) => {
|
||||
Math.max(Math.min(n, 1), 0);
|
||||
});
|
||||
// Make sure we don't have anything above 1 or below 0.
|
||||
newColor = newColor.map((n) => Math.max(Math.min(n, 1), 0));
|
||||
// Round again.
|
||||
newColor = newColor.map((n) => this.#round(n));
|
||||
// Return the same data type as user put in.
|
||||
if (Array.isArray(color)) {
|
||||
return newColor;
|
||||
return newColor.map(n => Math.round(n * 255));
|
||||
}
|
||||
else {
|
||||
let hex = '#';
|
||||
newColor.forEach((n) => {
|
||||
n *= 255;
|
||||
n = Math.round(n);
|
||||
hex += n.toString(16);
|
||||
});
|
||||
return hex;
|
||||
}
|
||||
}
|
||||
/* ------------------------------------------------------------------------------ #round ---- */
|
||||
#round(n) {
|
||||
return Math.round((n + Number.EPSILON) * 100) / 100;
|
||||
}
|
||||
}
|
||||
|
|
1
lib/esm/types/index.d.ts
vendored
1
lib/esm/types/index.d.ts
vendored
|
@ -1,6 +1,7 @@
|
|||
type matrix = [number, number, number];
|
||||
type rgbColor = [number, number, number];
|
||||
export declare class EliteMatrix {
|
||||
#private;
|
||||
red: matrix;
|
||||
green: matrix;
|
||||
blue: matrix;
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,qBAAa,WAAW;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;gBAED,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQtE,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAC,MAAM,GAAG,QAAQ,GAAC,MAAM;CA6CvD"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,qBAAa,WAAW;;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;gBAED,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQtE,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAC,MAAM,GAAG,QAAQ,GAAC,MAAM;CA0DvD"}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "elite-matrix",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "A small library for working with the Elite Dangerous color matrix.",
|
||||
"types": "./lib/cjs/types/index.d.ts",
|
||||
"main": "./lib/cjs/index.js",
|
||||
|
|
Loading…
Reference in a new issue