@bbki.ng/site 1.6.4 → 1.7.1

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.7.1
4
+
5
+ ## 1.7.0
6
+
3
7
  ## 1.6.4
4
8
 
5
9
  ## 1.6.3
package/index.d.ts ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.6.4",
3
+ "version": "1.7.1",
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.3",
19
+ "@bbki.ng/components": "workspace:2.5.4",
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.3",
31
+ "@bbki.ng/stylebase": "workspace:0.4.4",
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",
@@ -58,6 +58,7 @@
58
58
  "ts-jest": "^27.1.1",
59
59
  "typescript": "^4.5.4",
60
60
  "vite": "5.0.0",
61
+ "vite-plugin-glsl": "1.2.1",
61
62
  "vite-plugin-mdx": "^3.5.8",
62
63
  "vite-plugin-pwa": "0.19",
63
64
  "workbox-window": "^6.3.0"
package/src/app.tsx CHANGED
@@ -65,7 +65,6 @@ export const App = () => {
65
65
  return (
66
66
  <SWR>
67
67
  <HotKeyNav>
68
- {/*<Stickers />*/}
69
68
  <GlobalLoadingStateProvider>
70
69
  <Routes>
71
70
  <Route path="/" element={<Layout />}>
@@ -0,0 +1,32 @@
1
+ import React, { useCallback, useEffect } from "react";
2
+ import { Canvas } from "@bbki.ng/components";
3
+ import frag from "./main.frag";
4
+ import vert from "./shader.vert";
5
+ import cls from "classnames";
6
+ import uniforms from "./uniforms";
7
+ import { useRender } from "@/components/effect-layer/hooks/useRender";
8
+
9
+ export const EffectLayer = () => {
10
+ const canvasDefaultCls = cls(
11
+ "fixed",
12
+ "top-0",
13
+ "left-0",
14
+ "h-full",
15
+ "pointer-events-none",
16
+ "w-full",
17
+ "z-[999]"
18
+ );
19
+
20
+ const { onRender } = useRender();
21
+
22
+ return (
23
+ <Canvas
24
+ style={{ opacity: 0.1 }}
25
+ className={canvasDefaultCls}
26
+ uniforms={uniforms}
27
+ fragment={frag}
28
+ vertex={vert}
29
+ onRender={onRender}
30
+ />
31
+ );
32
+ };
@@ -0,0 +1,42 @@
1
+ float rand(vec2 co){
2
+ return fract(
3
+ sin(
4
+ dot(
5
+ co.xy,
6
+ vec2(12.9898, 78.233)
7
+ )
8
+ ) * 43758.5453
9
+ );
10
+ }
11
+
12
+ vec4 grain(vec4 fragColor, vec2 uv){
13
+ vec4 color = fragColor;
14
+ float diff = (rand(uv) - 0.0) * 0.09;
15
+ color.r += diff;
16
+ color.g += diff;
17
+ color.b += diff;
18
+ return color;
19
+ }
20
+
21
+ vec4 randGrain(vec2 uv) {
22
+ vec4 color = vec4(
23
+ rand(uv * abs(sin(uProgress))) * 0.09,
24
+ rand(uv * abs(sin(uProgress))) * 0.09,
25
+ rand(uv * abs(sin(uProgress))) * 0.09,
26
+ rand(uv * abs(sin(uProgress)))
27
+ );
28
+
29
+ vec4 result = grain(color, uv);
30
+ result.a *= 0.8;
31
+
32
+ return result;
33
+ }
34
+
35
+ void drawGrainOnNav(vec2 uv) {
36
+ float navHeight = 64. * uDevicePixelRatio / uResolution.y;
37
+
38
+ if (uv.y <= navHeight) {
39
+ gl_FragColor = randGrain(uv);
40
+ }
41
+ }
42
+
@@ -0,0 +1,19 @@
1
+ import {useCallback, useState} from "react";
2
+ import {useMousePosition} from "@/hooks/use_mouse_position";
3
+
4
+ export const useRender = () => {
5
+ const [inst, setInst] = useState<any>(null)
6
+ const pos = useMousePosition();
7
+
8
+ const onRender = useCallback((p: any) => {
9
+ if (inst === null) {
10
+ setInst(p)
11
+ return;
12
+ }
13
+
14
+ inst.uniforms.uMouse.value[0] = pos.current.x;
15
+ inst.uniforms.uMouse.value[1] = pos.current.y;
16
+ }, [inst]);
17
+
18
+ return { inst, onRender }
19
+ }
@@ -0,0 +1,27 @@
1
+ precision mediump float;
2
+
3
+ uniform vec2 uResolution;
4
+ uniform float uProgress;
5
+ uniform float uDevicePixelRatio;
6
+ uniform vec2 uCenter;
7
+ uniform vec2 uOffset;
8
+
9
+ #define DefaultColor vec4(0.0, 0.0, 0.0, 0.0)
10
+ #define CenterPos uCenter * uDevicePixelRatio / uResolution
11
+
12
+ #include "effects/grain.frag"
13
+ //#include "shapes/circle.frag"
14
+
15
+
16
+ void main() {
17
+ vec2 uv = gl_FragCoord.xy / uResolution;
18
+
19
+ // set default color
20
+ gl_FragColor = DefaultColor;
21
+
22
+ // draw circle on mouse
23
+ // drawCircleUnderMouse(uv, 0.05);
24
+
25
+ // draw grain on nav
26
+ drawGrainOnNav(uv);
27
+ }
@@ -0,0 +1,9 @@
1
+ attribute vec3 aPosition;
2
+
3
+ uniform mat4 uProjectionMatrix;
4
+ uniform mat4 uModelMatrix;
5
+ uniform mat4 uViewMatrix;
6
+
7
+ void main(){
8
+ gl_Position= uProjectionMatrix * uModelMatrix * uViewMatrix * vec4(aPosition, 1.);
9
+ }
@@ -0,0 +1,32 @@
1
+ uniform vec2 uMouse;
2
+
3
+ vec4 sdfCircle(vec2 uv, float r, vec2 center) {
4
+ float x = uv.x;
5
+ float y = uv.y;
6
+
7
+ float d = distance(vec2(x, y), center) - r;
8
+
9
+ return d > 0. ? DefaultColor : vec4(1.0, 0.0, 1.0, 1.0);
10
+ }
11
+
12
+ vec4 sdfSquare(vec2 uv, vec4 rect) {
13
+ float x = uv.x;
14
+ float y = uv.y;
15
+
16
+ float dx = max(abs(x - rect.x) - rect.z, 0.);
17
+ float dy = max(abs(y - rect.y) - rect.w, 0.);
18
+
19
+ float d = max(dx, dy);
20
+
21
+ return d > 0. ? DefaultColor : vec4(1.0, 0.0, 1.0, 1.0);
22
+
23
+ }
24
+
25
+ void drawCircleUnderMouse(vec2 uv, float r) {
26
+ // flip uMouse vertically
27
+ vec2 normalizedMouse = vec2(uMouse.x, uResolution.y - uMouse.y) * uDevicePixelRatio / uResolution;
28
+
29
+ // sdfCircle transition to sdfSquare
30
+
31
+ // gl_FragColor = sdfSquare(uv, vec4(normalizedMouse, 0.1, 0.1));
32
+ }
@@ -0,0 +1,11 @@
1
+ float sdHeart(vec2 p)
2
+ {
3
+ p.x = abs(p.x);
4
+
5
+ if( p.y+p.x>1.0 ) {
6
+ return sqrt(dot2(p-vec2(0.25,0.75))) - sqrt(2.0)/4.0;
7
+ }
8
+
9
+ return sqrt(min(dot2(p-vec2(0.00,1.00)),
10
+ dot2(p-0.5*max(p.x+p.y,0.0)))) * sign(p.x-p.y);
11
+ }
@@ -0,0 +1,32 @@
1
+ export default {
2
+ uResolution: {
3
+ type: "vec2",
4
+ value: [
5
+ Math.min(innerWidth, innerHeight),
6
+ Math.min(innerWidth, innerHeight),
7
+ ],
8
+ },
9
+ uDevicePixelRatio: {
10
+ type: "float",
11
+ value: [devicePixelRatio],
12
+ },
13
+ uOffset: {
14
+ type: "vec2",
15
+ value: [
16
+ (innerWidth / innerHeight) > 1 ? (innerWidth - innerHeight) / 2 : 0,
17
+ (innerWidth / innerHeight) < 1 ? (innerHeight - innerWidth) / 2 : 0,
18
+ ],
19
+ },
20
+ pi: {
21
+ type: "float",
22
+ value: [Math.PI],
23
+ },
24
+ uCenter: {
25
+ type: "vec2",
26
+ value: [innerWidth / 2, innerHeight / 2],
27
+ },
28
+ uMouse: {
29
+ type: "vec2",
30
+ value: [0, 0],
31
+ }
32
+ }
@@ -0,0 +1,17 @@
1
+ import {useEffect, useRef} from "react";
2
+
3
+ export const useMousePosition = () => {
4
+ const posRef = useRef<{x: number, y:number}>({x: 0, y: 0});
5
+ useEffect(() => {
6
+ const updateMousePosition = (e: MouseEvent) => {
7
+ posRef.current = {
8
+ x: e.clientX,
9
+ y: e.clientY,
10
+ };
11
+ };
12
+ window.addEventListener("mousemove", updateMousePosition);
13
+ return () => window.removeEventListener("mousemove", updateMousePosition);
14
+ }, []);
15
+
16
+ return posRef;
17
+ }
package/src/main.tsx CHANGED
@@ -7,6 +7,7 @@ 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 {EffectLayer} from "@/components/effect-layer/EffectLayer";
10
11
 
11
12
  const container = document.getElementById("root") as Element;
12
13
  const root = createRoot(container);
@@ -18,6 +19,7 @@ root.render(
18
19
  <Toaster />
19
20
  <Logger />
20
21
  <ReloadPrompt />
22
+ <EffectLayer />
21
23
  </Router>
22
24
  </React.StrictMode>
23
25
  );
@@ -1,25 +1,28 @@
1
1
  import React from "react";
2
2
  import { CenterLinkList } from "@/components";
3
+ import {EffectLayer} from "@/components/effect-layer/EffectLayer";
3
4
 
4
5
  export const Cover = (props: { className: string }) => {
5
6
  return (
6
- <CenterLinkList
7
- className="select-none"
8
- links={[
9
- {
10
- to: "/projects",
11
- name: "cd ./projects",
12
- },
13
- {
14
- to: "/blog",
15
- name: "cd ./blog",
16
- },
17
- {
18
- to: "/now",
19
- name: "cd ./now",
20
- },
21
- ]}
22
- title=""
23
- />
7
+ <>
8
+ <CenterLinkList
9
+ className="select-none"
10
+ links={[
11
+ {
12
+ to: "/projects",
13
+ name: "cd ./projects",
14
+ },
15
+ {
16
+ to: "/blog",
17
+ name: "cd ./blog",
18
+ },
19
+ {
20
+ to: "/now",
21
+ name: "cd ./now",
22
+ },
23
+ ]}
24
+ title=""
25
+ />
26
+ </>
24
27
  );
25
28
  };
@@ -8,6 +8,7 @@ import { ImageUploader } from "@/components/ImageUploader";
8
8
  import classnames from "classnames";
9
9
  import { ImageRenderer } from "@bbki.ng/components/lib";
10
10
  import { ImgCtxMenu } from "@/components/Img_ctx_menu";
11
+ import {EffectLayer} from "@/components/effect-layer/EffectLayer";
11
12
 
12
13
  const ProjectDetail = () => {
13
14
  const { id } = useParams();
@@ -0,0 +1,8 @@
1
+ declare module '*.frag' {
2
+ const file: string;
3
+ export default file;
4
+ }
5
+ declare module '*.vert' {
6
+ const file: string;
7
+ export default file;
8
+ }
package/vite.config.js CHANGED
@@ -11,6 +11,7 @@ import rehypeSlug from "rehype-slug";
11
11
  import rehypeHighlight from "rehype-highlight";
12
12
  import rehypeAutolinkHeadings from "rehype-autolink-headings";
13
13
  import react from "@vitejs/plugin-react";
14
+ import glsl from 'vite-plugin-glsl';
14
15
 
15
16
  const options = {
16
17
  remarkPlugins: [
@@ -51,6 +52,7 @@ export default defineConfig({
51
52
  plugins: [
52
53
  react(),
53
54
  mdx(options),
55
+ glsl(),
54
56
  VitePWA({
55
57
  injectRegister: "auto",
56
58
  includeAssets: [