Run prettier over everything

This commit is contained in:
2025-02-17 18:38:40 -08:00
parent 462f5ce751
commit 5939384b7c
46 changed files with 2315 additions and 1471 deletions

View File

@ -17,11 +17,13 @@ export class Color {
}
static parseHexCode(hexCode: string) {
const regex1 = /#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?/;
const regex2 = /#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})?/;
const regex1 =
/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?/;
const regex2 =
/#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})?/;
let result = regex1.exec(hexCode) ?? regex2.exec(hexCode);
if (result == null) {
throw `could not parse color: ${hexCode}`
throw `could not parse color: ${hexCode}`;
}
let parseGroup = (s: string | undefined): number => {
@ -32,7 +34,7 @@ export class Color {
return 17 * parseInt(s, 16);
}
return parseInt(s, 16);
}
};
return new Color(
parseGroup(result[1]),
parseGroup(result[2]),
@ -42,7 +44,7 @@ export class Color {
}
toStyle(): string {
return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a / 255.0})`
return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a / 255.0})`;
}
}
@ -56,7 +58,7 @@ export class Point {
}
toString(): string {
return `${this.x},${this.y}`
return `${this.x},${this.y}`;
}
offset(other: Point | Size): Point {
@ -109,7 +111,7 @@ export class Size {
}
toString(): string {
return `${this.w}x${this.h}`
return `${this.w}x${this.h}`;
}
}
@ -127,7 +129,12 @@ export class Rect {
}
contains(other: Point) {
return (other.x >= this.top.x && other.y >= this.top.y && other.x < this.top.x + this.size.w && other.y < this.top.y + this.size.h);
return (
other.x >= this.top.x &&
other.y >= this.top.y &&
other.x < this.top.x + this.size.w &&
other.y < this.top.y + this.size.h
);
}
overlaps(other: Rect) {
@ -156,20 +163,20 @@ export class Grid<T> {
for (let y = 0; y < size.h; y++) {
let row = [];
for (let x = 0; x < size.w; x++) {
row.push(cbDefault(new Point(x, y)))
row.push(cbDefault(new Point(x, y)));
}
this.#data.push(row);
}
}
static createGridFromMultilineString(multiline: string): Grid<string> {
let lines = []
let lines = [];
for (let line of multiline.split("\n")) {
let trimmedLine = line.trim();
if (trimmedLine == "") {
continue;
}
lines.push(trimmedLine)
lines.push(trimmedLine);
}
return this.createGridFromStringArray(lines);
}
@ -181,17 +188,14 @@ export class Grid<T> {
let w1 = ary[i].length;
let w2 = ary[i + 1].length;
if (w1 != w2) {
throw `createGridFromStringArray: must be grid-shaped, got ${ary}`
throw `createGridFromStringArray: must be grid-shaped, got ${ary}`;
}
w = w1;
}
return new Grid(
new Size(w, h),
(xy) => {
return ary[xy.y].charAt(xy.x);
}
)
return new Grid(new Size(w, h), (xy) => {
return ary[xy.y].charAt(xy.x);
});
}
static createGridFromJaggedArray<T>(ary: Array<Array<T>>): Grid<T> {
@ -201,17 +205,14 @@ export class Grid<T> {
let w1 = ary[i].length;
let w2 = ary[i + 1].length;
if (w1 != w2) {
throw `createGridFromJaggedArray: must be grid-shaped, got ${ary}`
throw `createGridFromJaggedArray: must be grid-shaped, got ${ary}`;
}
w = w1;
}
return new Grid(
new Size(w, h),
(xy) => {
return ary[xy.y][xy.x];
}
)
return new Grid(new Size(w, h), (xy) => {
return ary[xy.y][xy.x];
});
}
map<T2>(cbCell: (content: T, position: Point) => T2) {
@ -220,10 +221,14 @@ export class Grid<T> {
#checkPosition(position: Point) {
if (
(position.x < 0 || position.x >= this.size.w || Math.floor(position.x) != position.x) ||
(position.y < 0 || position.y >= this.size.h || Math.floor(position.y) != position.y)
position.x < 0 ||
position.x >= this.size.w ||
Math.floor(position.x) != position.x ||
position.y < 0 ||
position.y >= this.size.h ||
Math.floor(position.y) != position.y
) {
throw new Error(`invalid position for ${this.size}: ${position}`)
throw new Error(`invalid position for ${this.size}: ${position}`);
}
}
@ -241,7 +246,7 @@ export class Grid<T> {
export enum AlignX {
Left = 0,
Center = 1,
Right = 2
Right = 2,
}
export enum AlignY {