Skip to content

Commit

Permalink
More consistent formatting across the codebase. (#372)
Browse files Browse the repository at this point in the history
* Add more ESLint recommended rules, and enforce them in CI.

* Additional linting

* Remove eslint comments and relax rules

* Enable typescript-eslint stylistic rules

* Remove eslint changes

* Address review
  • Loading branch information
jgerigmeyer committed Nov 29, 2023
1 parent 7ec8c42 commit 742728d
Show file tree
Hide file tree
Showing 76 changed files with 233 additions and 248 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ root = true

[*]
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
Expand Down
2 changes: 1 addition & 1 deletion apps/convert/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function update () {

output.tBodies[0].innerHTML = ret;
}
};
}

let urlParams = getURLParams();

Expand Down
2 changes: 1 addition & 1 deletion apps/picker-mavo/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ abbr {
}

.color-slider::-moz-range-track {
background: none;
background: none;
}

.color-slider-label {
Expand Down
4 changes: 2 additions & 2 deletions apps/picker/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ abbr {
}

.color-slider::-moz-range-track {
background: none;
background: none;
}

.color-slider-label {
Expand Down Expand Up @@ -228,4 +228,4 @@ details {
color: inherit;
background: none;
border: none;
}
}
8 changes: 4 additions & 4 deletions assets/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ if (current) {
function idify (str) {
// from Mavo.Functions.idify()
return str
.normalize("NFD").replace(/[\u0300-\u036f]/g, "") // Convert accented letters to ASCII
.replace(/[^\w\s-]/g, "") // Remove remaining non-ASCII characters
.trim().replace(/\s+/g, "-") // Convert whitespace to hyphens
.toLowerCase();
.normalize("NFD").replace(/[\u0300-\u036f]/g, "") // Convert accented letters to ASCII
.replace(/[^\w\s-]/g, "") // Remove remaining non-ASCII characters
.trim().replace(/\s+/g, "-") // Convert whitespace to hyphens
.toLowerCase();
}

function makePageToc (pageToc) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (!Color.DEBUGGING) {
"color-green-blue-light": greenBlue(.5).set({"lch.l": 94}),
"color-blue-red-light": blueRed(.5).set({"lch.l": 94}),
};
window.vars = vars;
window.vars = vars;
$.create("style", {
inside: document.head,
textContent: `:root {
Expand Down
2 changes: 1 addition & 1 deletion notebook/color-notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export default class Notebook {
let offset = nodeAtOffset.offsetTop - result.offsetTop
// Prevent overly tall results (e.g. long arrays of colors)
// to make the entire code area super tall
- Math.max(0, result.offsetHeight - 30);
- Math.max(0, result.offsetHeight - 30);

if (offset > 5) {
result.style.marginTop = offset + "px";
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"scripts": {
"test": "npx htest ./test",
"dtslint": "dtslint types",
"dtslint": "dtslint --expectOnly types",
"lint": "eslint . --fix --ext .js --ext .ts --ext .js --ext .cjs",
"build:css": "npx postcss \"**/*.postcss\" --base . --dir . --ext .css --config postcss.config.cjs",
"build:html": "npx @11ty/eleventy --config=.eleventy.cjs",
Expand Down
12 changes: 6 additions & 6 deletions rollup.legacy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const legacyPlugins = [

export default defaultConfig.map(config =>
Object.assign(config, {
output: config.output.map(bundle => ({
...bundle,
file: bundle.file.replace(/\.(?:min\.)?\w+$/, ".legacy$&"),
})),
plugins: [...(config.plugins || []), ...legacyPlugins]
})
output: config.output.map(bundle => ({
...bundle,
file: bundle.file.replace(/\.(?:min\.)?\w+$/, ".legacy$&"),
})),
plugins: [...(config.plugins || []), ...legacyPlugins]
})
);
82 changes: 41 additions & 41 deletions scripts/cat-mat.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import { create, all } from 'mathjs'
const config = {}
const math = create(all, config)
import { create, all } from "mathjs";
const config = {};
const math = create(all, config);

const d50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585]
const d65 = [0.3127 / 0.3290, 1.00000, (1.0 - 0.3127 - 0.3290) / 0.3290]
const d50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
const d65 = [0.3127 / 0.3290, 1.00000, (1.0 - 0.3127 - 0.3290) / 0.3290];

const bradford = [
[0.8951000, 0.2664000, -0.1614000],
[-0.7502000, 1.7135000, 0.0367000],
[0.0389000, -0.0685000, 1.0296000]
]
[ 0.8951000, 0.2664000, -0.1614000 ],
[ -0.7502000, 1.7135000, 0.0367000 ],
[ 0.0389000, -0.0685000, 1.0296000 ]
];

const von_kries = [
[0.4002400, 0.7076000, -0.0808100],
[-0.2263000, 1.1653200, 0.0457000],
[0.0000000, 0.0000000, 0.9182200]
]
[ 0.4002400, 0.7076000, -0.0808100 ],
[ -0.2263000, 1.1653200, 0.0457000 ],
[ 0.0000000, 0.0000000, 0.9182200 ]
];

const cat02 = [
[0.7328000, 0.4296000, -0.1624000],
[-0.7036000, 1.6975000, 0.0061000],
[0.0030000, 0.0136000, 0.9834000]
]
[ 0.7328000, 0.4296000, -0.1624000 ],
[ -0.7036000, 1.6975000, 0.0061000 ],
[ 0.0030000, 0.0136000, 0.9834000 ]
];

const cat16 = [
[ 0.401288, 0.650173, -0.051461 ],
[ -0.250268, 1.204414, 0.045854 ],
[ -0.002079, 0.048952, 0.953127 ]
]

console.log('===== bradford =====')
console.log(bradford)
console.log('===== bradford inverse =====')
console.log(math.inv(bradford))

console.log('===== von kries =====')
console.log(von_kries)
console.log('===== von kries inverse =====')
console.log(math.inv(von_kries))

console.log('===== cat02 =====')
console.log(cat02)
console.log('===== cat02 inverse =====')
console.log(math.inv(cat02))

console.log('===== cat16 =====')
console.log(cat16)
console.log('===== cat16 inverse =====')
console.log(math.inv(cat16))
[ 0.401288, 0.650173, -0.051461 ],
[ -0.250268, 1.204414, 0.045854 ],
[ -0.002079, 0.048952, 0.953127 ]
];

console.log("===== bradford =====");
console.log(bradford);
console.log("===== bradford inverse =====");
console.log(math.inv(bradford));

console.log("===== von kries =====");
console.log(von_kries);
console.log("===== von kries inverse =====");
console.log(math.inv(von_kries));

console.log("===== cat02 =====");
console.log(cat02);
console.log("===== cat02 inverse =====");
console.log(math.inv(cat02));

console.log("===== cat16 =====");
console.log(cat16);
console.log("===== cat16 inverse =====");
console.log(math.inv(cat16));
4 changes: 2 additions & 2 deletions src/CATs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hooks.add("chromatic-adaptation-end", env => {
export function defineCAT ({id, toCone_M, fromCone_M}) {
// Use id, toCone_M, fromCone_M like variables
CATs[id] = arguments[0];
};
}

export function adapt (W1, W2, id = "Bradford") {
// adapt from a source whitepoint or illuminant W1
Expand All @@ -43,7 +43,7 @@ export function adapt (W1, W2, id = "Bradford") {
let adapt_M = multiplyMatrices(method.fromCone_M, scaled_cone_M);
// console.log({scaled_cone_M, adapt_M});
return adapt_M;
};
}

defineCAT({
id: "von Kries",
Expand Down
4 changes: 2 additions & 2 deletions src/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class Color {
for (let id in this.space.coords) {
Object.defineProperty(this, id, {
get: () => this.get(id),
set: value => this.set(id, value)
set: value => this.set(id, value),
});
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ export default class Color {
}
}
}
};
}

Color.defineFunctions({
get,
Expand Down
2 changes: 1 addition & 1 deletion src/contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export default function contrast (background, foreground, o = {}) {
}

throw new TypeError(`Unknown contrast algorithm: ${algorithm}`);
};
}
2 changes: 1 addition & 1 deletion src/contrast/Lstar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export default function contrastLstar (color1, color2) {
let L2 = get(color2, [lab, "l"]);

return Math.abs(L1 - L2);
};
}
2 changes: 1 addition & 1 deletion src/contrast/Michelson.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export default function contrastMichelson (color1, color2) {

let denom = (Y1 + Y2);
return denom === 0 ? 0 : (Y1 - Y2) / denom;
};
}
2 changes: 1 addition & 1 deletion src/contrast/WCAG21.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default function contrastWCAG21 (color1, color2) {
}

return (Y1 + .05) / (Y2 + .05);
};
}
2 changes: 1 addition & 1 deletion src/contrast/Weber.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export default function contrastWeber (color1, color2) {
}

return Y2 === 0 ? max : (Y1 - Y2) / Y2;
};
}
2 changes: 1 addition & 1 deletion src/contrast/deltaPhi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export default function contrastDeltaPhi (color1, color2) {
let contrast = Math.pow(deltaPhiStar, (1 / phi)) * Math.SQRT2 - 40;

return (contrast < 7.5) ? 0.0 : contrast ;
};
}
2 changes: 0 additions & 2 deletions src/defaults.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Global defaults one may want to configure
const hasDOM = typeof document !== "undefined";

export default {
gamut_mapping: "css",
precision: 5,
Expand Down
2 changes: 1 addition & 1 deletion src/deltaE.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export default function deltaE (c1, c2, o = {}) {
}

throw new TypeError(`Unknown deltaE method: ${method}`);
};
}
2 changes: 1 addition & 1 deletion src/deltaE/deltaE2000.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ export default function (color, sample, {kL = 1, kC = 1, kH = 1} = {}) {
dE += RT * (ΔC / (kC * SC)) * (ΔH / (kH * SH));
return Math.sqrt(dE);
// Yay!!!
};
}
2 changes: 1 addition & 1 deletion src/deltaE/deltaE76.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import distance from "../distance.js";

export default function deltaE76 (color, sample) {
return distance(color, sample, "lab");
};
}
2 changes: 1 addition & 1 deletion src/deltaE/deltaECMC.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ export default function (color, sample, {l = 2, c = 1} = {}) {
// dE += (ΔH / SH) ** 2;
return Math.sqrt(dE);
// Yay!!!
};
}
2 changes: 1 addition & 1 deletion src/deltaE/deltaEITP.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export default function (color, sample) {
// per ITU-R BT.2124-0 p.3

return 720 * Math.sqrt((I1 - I2) ** 2 + (0.25 * (T1 -T2) ** 2) + (P1 - P2) ** 2);
};
}
2 changes: 1 addition & 1 deletion src/deltaE/deltaEJz.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export default function (color, sample) {
let ΔH = 2 * Math.sqrt(Cz1 * Cz2) * Math.sin((Δh / 2) * (Math.PI / 180));

return Math.sqrt(ΔJ ** 2 + ΔC ** 2 + ΔH ** 2);
};
}
2 changes: 1 addition & 1 deletion src/deltaE/deltaEOK.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default function (color, sample) {
let Δa = a1 - a2;
let Δb = b1 - b2;
return Math.sqrt(ΔL ** 2 + Δa ** 2 + Δb ** 2);
};
}
1 change: 0 additions & 1 deletion src/display.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isNone, skipNone } from "./util.js";
import ColorSpace from "./space.js";
import defaults from "./defaults.js";
import to from "./to.js";
import serialize from "./serialize.js";
Expand Down
4 changes: 2 additions & 2 deletions src/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default function equals (color1, color2) {
color2 = getColor(color2);

return color1.space === color2.space
&& color1.alpha === color2.alpha
&& color1.coords.every((c, i) => c === color2.coords[i]);
&& color1.alpha === color2.alpha
&& color1.coords.every((c, i) => c === color2.coords[i]);
}
2 changes: 1 addition & 1 deletion src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Hooks {
callback.call(env && env.context? env.context : env, env);
});
}
};
}

/**
* The instance of {@link Hooks} used throughout Color.js
Expand Down
7 changes: 3 additions & 4 deletions src/interpolation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Functions related to color interpolation
*/
import Color from "./color.js";
import ColorSpace from "./space.js";
import {type, interpolate} from "./util.js";
import getColor from "./getColor.js";
Expand Down Expand Up @@ -114,7 +113,7 @@ export function steps (c1, c2, options = {}) {
ret = ret.map(a => a.color);

return ret;
};
}

/**
* Interpolate to color2 and return a function that takes a 0-1 percentage
Expand Down Expand Up @@ -208,11 +207,11 @@ export function range (color1, color2, options = {}) {
}, {
rangeArgs
});
};
}

export function isRange (val) {
return type(val) === "function" && !!val.rangeArgs;
};
}

defaults.interpolationSpace = "lab";

Expand Down
5 changes: 2 additions & 3 deletions src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as util from "./util.js";
import ColorSpace from "./space.js";
import defaults from "./defaults.js";
import getColor from "./getColor.js";
import to from "./to.js";
import checkInGamut from "./inGamut.js";
import toGamut from "./toGamut.js";
import clone from "./clone.js";
Expand All @@ -25,8 +24,8 @@ export default function serialize (color, {

let formatId = format;
format = color.space.getFormat(format)
?? color.space.getFormat("default")
?? ColorSpace.DEFAULT_FORMAT;
?? color.space.getFormat("default")
?? ColorSpace.DEFAULT_FORMAT;

inGamut ||= format.toGamut;

Expand Down
5 changes: 0 additions & 5 deletions src/space-accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ hooks.add("colorspace-init-end", space => {
});

function addSpaceAccessors (id, space) {
// Coordinates can be looked up by both id and name
let coordIds = Object.keys(space.coords);
let coordNames = Object.values(space.coords).map(c => c.name);


let propId = id.replace(/-/g, "_");

Object.defineProperty(Color.prototype, propId, {
Expand Down

0 comments on commit 742728d

Please sign in to comment.