@bbki.ng/site 1.6.1 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 1.6.3
4
+
5
+ ## 1.6.2
6
+
3
7
  ## 1.6.1
4
8
 
5
9
  ## 1.6.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "url": "git+https://github.com/bbbottle/bbki.ng.git"
17
17
  },
18
18
  "dependencies": {
19
- "@bbki.ng/components": "workspace:2.5.1",
19
+ "@bbki.ng/components": "workspace:2.5.3",
20
20
  "@supabase/supabase-js": "^1.35.4",
21
21
  "classnames": "2.3.1",
22
22
  "react": "^18.0.0",
@@ -28,7 +28,7 @@
28
28
  "swr": "^2.2.5"
29
29
  },
30
30
  "devDependencies": {
31
- "@bbki.ng/stylebase": "workspace:0.4.1",
31
+ "@bbki.ng/stylebase": "workspace:0.4.3",
32
32
  "@mdx-js/mdx": "2.0.0-next.9",
33
33
  "@mdx-js/react": "^1.6.22",
34
34
  "@mdx-js/rollup": "3.0.0",
@@ -1,39 +1,37 @@
1
1
  import { useEffect, useState } from "react";
2
+ import { changeFont } from "@/utils";
3
+ import { FontType } from "@/types/font";
2
4
 
3
5
  export const useFontLoading = () => {
4
6
  const [isFontLoading, setIsFontLoading] = useState(false);
5
7
 
6
8
  const handleFontLoading = () => {
7
9
  setIsFontLoading(true);
10
+ document.fonts.ready.then(() => {
11
+ handleFontLoadingDone();
12
+ });
8
13
  };
9
14
 
10
15
  const handleFontLoadingDone = () => {
11
- // delay 200ms
12
16
  setTimeout(() => {
13
17
  setIsFontLoading(false);
14
18
  }, 500);
15
19
  };
16
20
 
21
+ const handleFontLoadingError = () => {
22
+ setIsFontLoading(false);
23
+ changeFont(FontType.Mono);
24
+ };
25
+
17
26
  useEffect(() => {
18
- document.fonts.onloadingdone = handleFontLoadingDone;
19
- document.fonts.onloadingerror = handleFontLoadingDone;
20
- document.fonts.ready.then(handleFontLoading);
27
+ document.fonts.onloadingerror = handleFontLoadingError;
21
28
  document.fonts.onloading = handleFontLoading;
22
29
 
23
- // check font ready
24
- if (document.fonts.status === "loaded") {
25
- handleFontLoadingDone();
26
- }
27
-
28
- console.log(document.fonts.status);
29
-
30
30
  return () => {
31
- document.fonts.onloadingdone = null;
32
31
  document.fonts.onloadingerror = null;
33
- document.fonts.ready.then(() => {});
34
32
  document.fonts.onloading = null;
35
33
  };
36
- }, [document.fonts.status]);
34
+ }, []);
37
35
 
38
36
  return isFontLoading;
39
37
  };
package/src/main.tsx CHANGED
@@ -7,7 +7,6 @@ import "@bbki.ng/components/style";
7
7
  import App from "./app";
8
8
  import "./main.css";
9
9
  import Logger from "@/components/Logger";
10
- import { AppCtxMenu } from "@/components/app_ctx_menu";
11
10
 
12
11
  const container = document.getElementById("root") as Element;
13
12
  const root = createRoot(container);
@@ -0,0 +1,4 @@
1
+ export enum FontType {
2
+ NotoSerifSC = "noto-serif",
3
+ Mono = "font-mono",
4
+ }
@@ -4,6 +4,7 @@ import { API_ENDPOINT, OSS_ADDRESS } from "@/constants/routes";
4
4
  import { DEFAULT_DELAY } from "@/constants";
5
5
  import useSWR from "swr";
6
6
  import { toast } from "sonner";
7
+ import { FontType } from "@/types/font";
7
8
 
8
9
  type Fetcher = (resource: string, init?: any) => Promise<any>;
9
10
 
@@ -171,3 +172,24 @@ export const confirm = (message: string, exec: () => void) => {
171
172
  },
172
173
  });
173
174
  };
175
+
176
+ export const changeFont = (type: FontType) => {
177
+ const rootDiv = document.getElementById("root");
178
+ if (rootDiv == null) {
179
+ return;
180
+ }
181
+
182
+ if (rootDiv.classList.contains(type)) {
183
+ return;
184
+ }
185
+
186
+ // remove all font type class
187
+ for (const fontType in FontType) {
188
+ rootDiv.classList.remove(fontType);
189
+ }
190
+
191
+ rootDiv.classList.add(type);
192
+
193
+ // save font type to local storage
194
+ localStorage.setItem("font", type);
195
+ };