scripts: replace dark-variant.sh with go scripts/variants

uses regex mostly, resulting in a significantly faster execution (old:
~2s, new: ~31ms). Only matches classList.add/remove and class="..."
(won't touch string literal variables or colours), but these weren't
really used anyway. Supports multi-line classList.add/remove, which was
the reason I wrote this anyway (formatting the codebase introduced some
of these).
This commit is contained in:
Harvey Tindall
2025-12-09 14:28:05 +00:00
parent 817107622a
commit 4a9bac1027
7 changed files with 166 additions and 61 deletions

View File

@@ -472,13 +472,12 @@ export function throttle(callback: () => void, limitMilliseconds: number): () =>
export function SetupCopyButton(
button: HTMLButtonElement,
text: string | (() => string),
baseClass?: string,
baseClasses?: string[],
notif?: string,
) {
if (!notif) notif = window.lang.strings("copied");
if (!baseClass) baseClass = "~info";
if (!baseClasses || baseClasses.length == 0) baseClasses = ["~info", "dark:~d_info"];
// script will probably turn this into multiple
const baseClasses = baseClass.split(" ");
button.type = "button";
button.classList.add("button", ...baseClasses, "@low", "p-1");
button.title = window.lang.strings("copy");
@@ -505,8 +504,8 @@ export function SetupCopyButton(
};
}
export function CopyButton(text: string | (() => string), baseClass?: string, notif?: string): HTMLButtonElement {
export function CopyButton(text: string | (() => string), baseClasses?: string[], notif?: string): HTMLButtonElement {
const button = document.createElement("button");
SetupCopyButton(button, text, baseClass, notif);
SetupCopyButton(button, text, baseClasses, notif);
return button;
}