index.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Mask } from "../store/mask";
  2. import { CN_MASKS } from "./cn";
  3. import { type BuiltinMask } from "./typing";
  4. export { type BuiltinMask } from "./typing";
  5. export const BUILTIN_MASK_ID = 100000;
  6. export const BUILTIN_MASK_STORE = {
  7. buildinId: BUILTIN_MASK_ID,
  8. masks: {} as Record<string, BuiltinMask>,
  9. get(id?: string) {
  10. if (!id) return undefined;
  11. return this.masks[id] as Mask | undefined;
  12. },
  13. add(m: BuiltinMask) {
  14. const mask = { ...m, id: this.buildinId++, builtin: true };
  15. this.masks[mask.id] = mask;
  16. return mask;
  17. },
  18. };
  19. export const BUILTIN_MASKS: BuiltinMask[] = CN_MASKS.map(mask => BUILTIN_MASK_STORE.add(mask));
  20. // if (typeof window != "undefined") {
  21. // // run in browser skip in next server
  22. // fetch("/masks.json")
  23. // .then((res) => res.json())
  24. // .catch((error) => {
  25. // console.error("[Fetch] failed to fetch masks", error);
  26. // return { cn: [] };
  27. // })
  28. // .then((masks) => {
  29. // const { cn = [] } = masks;
  30. // return cn.map((m) => {
  31. // BUILTIN_MASKS.push(BUILTIN_MASK_STORE.add(m));
  32. // });
  33. // });
  34. // }