Skip to content

Commit c8f998c

Browse files
committed
formatting
1 parent 9a87f2f commit c8f998c

File tree

8 files changed

+77
-73
lines changed

8 files changed

+77
-73
lines changed

src/e2e/basic.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ test("the obfuscation button should work", async ({ page }) => {
8484
let button = page.getByRole("button", { name: "Obfuscated " });
8585
await button.click();
8686
expect(await textbox.locator("p>span.obfuscated").count()).toBeGreaterThan(0);
87-
});
87+
});

src/lib/components/modals/ExportModal.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@
9090
<button
9191
class="rounded-md p-1 text-lg font-medium hover:bg-zinc-900 active:bg-white/10"
9292
onclick={() => {
93-
navigator.clipboard.writeText(editor ? translateMOTD(editor.getJSON()) : "Loading...");
93+
navigator.clipboard.writeText(
94+
editor ? translateMOTD(editor.getJSON()) : "Loading...",
95+
);
9496
recentlyCopied = true;
9597
setTimeout(() => (recentlyCopied = false), 2000);
9698
}}>
9799
<IconCopy />
98100
</button>
99101
<code class="inline-block max-h-56 w-full overflow-auto"
100-
>{editor
101-
? translateMOTD(editor.getJSON()) : "Loading..."}
102+
>{editor ? translateMOTD(editor.getJSON()) : "Loading..."}
102103
</code>
103104
</div>
104105

src/lib/components/modals/FontUploadModal.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
let step = $state(1);
1010
let identifier = $state("");
1111
let fontAlias = $state("");
12-
let fontData: Blob
12+
let fontData: Blob;
1313
1414
async function dropHandler(
1515
e: DragEvent & {
@@ -55,7 +55,7 @@
5555
document.fonts.add(font);
5656
fontAlias = fileName;
5757
await font.load();
58-
fontData = file
58+
fontData = file;
5959
}
6060
step = 2;
6161
}
@@ -64,13 +64,13 @@
6464
fontLUT.set(identifier, fontAlias);
6565
fontUploadModal.close();
6666
step = 1;
67-
68-
const db = await openDataStore()
67+
68+
const db = await openDataStore();
6969
await db.put("fonts", {
7070
alias: fontAlias,
7171
identifier,
72-
data: fontData
73-
})
72+
data: fontData,
73+
});
7474
7575
identifier = "";
7676
fontAlias = "";

src/lib/db.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { openDB } from "idb";
22

33
export async function openDataStore() {
4-
const db = await openDB("dph_data-store", 1, {
5-
upgrade(db, _old, _new, _) {
6-
db.createObjectStore("fonts", {
7-
keyPath: "alias",
8-
});
9-
},
10-
});
4+
const db = await openDB("dph_data-store", 1, {
5+
upgrade(db, _old, _new, _) {
6+
db.createObjectStore("fonts", {
7+
keyPath: "alias",
8+
});
9+
},
10+
});
1111

12-
return db;
12+
return db;
1313
}
14-

src/lib/text/general.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ export const colorMap = [
131131
{ name: "yellow", value: "#FFFF55", code: "e" },
132132
{ name: "green", value: "#55FF55", code: "2" },
133133
{ name: "dark_green", value: "#00AA00", code: "a" },
134-
{ name: "aqua", value: "#55FFFF", code: "b"},
135-
{ name: "dark_aqua", value: "#00AAAA", code: "3"},
136-
{ name: "blue", value: "#5555FF", code: "1"},
137-
{ name: "dark_blue", value: "#0000AA", code: "9"},
138-
{ name: "dark_purple", value: "#AA00AA", code: "d"},
139-
{ name: "light_purple", value: "#FF55FF", code: "5"},
140-
{ name: "white", value: "#FFFFFF", code: "f"},
141-
{ name: "gray", value: "#AAAAAA", code: "7"},
142-
{ name: "dark_gray", value: "#555555", code: "8"},
143-
{ name: "black", value: "#000000", code: "0"},
134+
{ name: "aqua", value: "#55FFFF", code: "b" },
135+
{ name: "dark_aqua", value: "#00AAAA", code: "3" },
136+
{ name: "blue", value: "#5555FF", code: "1" },
137+
{ name: "dark_blue", value: "#0000AA", code: "9" },
138+
{ name: "dark_purple", value: "#AA00AA", code: "d" },
139+
{ name: "light_purple", value: "#FF55FF", code: "5" },
140+
{ name: "white", value: "#FFFFFF", code: "f" },
141+
{ name: "gray", value: "#AAAAAA", code: "7" },
142+
{ name: "dark_gray", value: "#555555", code: "8" },
143+
{ name: "black", value: "#000000", code: "0" },
144144
];

src/lib/text/motd.ts

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { JSONContent } from "@tiptap/core";
2-
import { colorMap, defaultColorLUT, trueMarkOrUndefined, unescapeUnicode } from "./general";
2+
import { colorMap, trueMarkOrUndefined, unescapeUnicode } from "./general";
33

44
function hexToRgb(hex: string): [number, number, number] {
55
hex = hex.replace(/^#/, "");
@@ -50,58 +50,57 @@ export function deltaE(hex1: string, hex2: string): number {
5050
}
5151

5252
const formattingCodes = [
53-
{key: "obfuscated", value: "k"},
54-
{key: "bold", value: "l"},
55-
{key: "strike", value: "m"},
56-
{key: "underline", value: "n"},
57-
{key: "italic", value: "o"},
58-
]
53+
{ key: "obfuscated", value: "k" },
54+
{ key: "bold", value: "l" },
55+
{ key: "strike", value: "m" },
56+
{ key: "underline", value: "n" },
57+
{ key: "italic", value: "o" },
58+
];
5959

6060
export function translateMOTD(c: JSONContent) {
6161
const char = "\\u00a7";
6262
const paragraphs = c.content!;
6363

64-
let data = "";
64+
let data = "";
6565

6666
for (const [i, p] of paragraphs.entries()) {
67-
const content = p.content ?? [];
68-
69-
67+
const content = p.content ?? [];
68+
7069
for (const c of content) {
71-
if (!c.text) {
72-
continue;
73-
}
70+
if (!c.text) {
71+
continue;
72+
}
7473

7574
let lowestDE = 999;
76-
let lowestDEVal = "";
77-
let formatting = ""
75+
let lowestDEVal = "";
76+
let formatting = "";
7877

7978
const color = c.marks?.at(0)?.attrs?.color;
80-
for (const c of colorMap) {
81-
if (!color) {
82-
continue;
83-
}
84-
85-
const dE = deltaE(color, c.value);
86-
if (dE === 0) {
87-
lowestDEVal = `${char}${c.code}`
88-
break;
89-
}
90-
if (dE < lowestDE) {
91-
lowestDE = dE
92-
lowestDEVal = `${char}${c.code}`
93-
}
94-
}
95-
96-
for (const code of formattingCodes) {
97-
if (trueMarkOrUndefined(c, code.key)) {
98-
formatting += `${char}${code.value}`
99-
}
100-
}
101-
102-
data += `${char}r${lowestDEVal}${formatting}${unescapeUnicode(c.text)}`
103-
}
79+
for (const c of colorMap) {
80+
if (!color) {
81+
continue;
82+
}
83+
84+
const dE = deltaE(color, c.value);
85+
if (dE === 0) {
86+
lowestDEVal = `${char}${c.code}`;
87+
break;
88+
}
89+
if (dE < lowestDE) {
90+
lowestDE = dE;
91+
lowestDEVal = `${char}${c.code}`;
92+
}
93+
}
94+
95+
for (const code of formattingCodes) {
96+
if (trueMarkOrUndefined(c, code.key)) {
97+
formatting += `${char}${code.value}`;
98+
}
99+
}
100+
101+
data += `${char}r${lowestDEVal}${formatting}${unescapeUnicode(c.text)}`;
102+
}
104103
if (i < paragraphs.length - 1) data += "\\n";
105-
}
106-
return data
104+
}
105+
return data;
107106
}

src/lib/text/nbt_or_json.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import type {
66
TranslateOptions,
77
} from "$lib/types";
88
import { type JSONContent } from "@tiptap/core";
9-
import { colorMap, defaultColorLUT, isMarkType, trueMarkOrUndefined, unescapeUnicode } from "./general";
9+
import {
10+
defaultColorLUT,
11+
isMarkType,
12+
trueMarkOrUndefined,
13+
unescapeUnicode,
14+
} from "./general";
1015

1116
const styleProps = [
1217
"color",

src/lib/tiptap/extensions/fonts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Extension } from "@tiptap/core";
2-
import { SvelteMap } from "svelte/reactivity"
2+
import { SvelteMap } from "svelte/reactivity";
33

44
export let fontLUT: SvelteMap<string, string> = new SvelteMap();
55

0 commit comments

Comments
 (0)