2023-04-26 17:16:21 +00:00
|
|
|
import { Mask } from "../store/mask";
|
|
|
|
import { CN_MASKS } from "./cn";
|
2024-04-11 16:18:15 +00:00
|
|
|
import { TW_MASKS } from "./tw";
|
2023-04-26 17:16:21 +00:00
|
|
|
import { EN_MASKS } from "./en";
|
|
|
|
|
|
|
|
import { type BuiltinMask } from "./typing";
|
|
|
|
export { type BuiltinMask } from "./typing";
|
|
|
|
|
|
|
|
export const BUILTIN_MASK_ID = 100000;
|
|
|
|
|
|
|
|
export const BUILTIN_MASK_STORE = {
|
|
|
|
buildinId: BUILTIN_MASK_ID,
|
2023-07-09 11:37:42 +00:00
|
|
|
masks: {} as Record<string, BuiltinMask>,
|
|
|
|
get(id?: string) {
|
2023-04-26 17:16:21 +00:00
|
|
|
if (!id) return undefined;
|
|
|
|
return this.masks[id] as Mask | undefined;
|
|
|
|
},
|
|
|
|
add(m: BuiltinMask) {
|
2023-05-18 16:59:04 +00:00
|
|
|
const mask = { ...m, id: this.buildinId++, builtin: true };
|
2023-04-26 17:16:21 +00:00
|
|
|
this.masks[mask.id] = mask;
|
|
|
|
return mask;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-07-03 06:09:49 +00:00
|
|
|
export const BUILTIN_MASKS: BuiltinMask[] = [];
|
|
|
|
|
|
|
|
if (typeof window != "undefined") {
|
|
|
|
// run in browser skip in next server
|
|
|
|
fetch("/masks.json")
|
|
|
|
.then((res) => res.json())
|
|
|
|
.catch((error) => {
|
|
|
|
console.error("[Fetch] failed to fetch masks", error);
|
|
|
|
return { cn: [], tw: [], en: [] };
|
|
|
|
})
|
|
|
|
.then((masks) => {
|
|
|
|
const { cn = [], tw = [], en = [] } = masks;
|
|
|
|
return [...cn, ...tw, ...en].map((m) => {
|
|
|
|
BUILTIN_MASKS.push(BUILTIN_MASK_STORE.add(m));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|