refactor: progressive blur effect (#4607)
* refactor: progressive blur effect * Update packages/internal/components/src/ui/progressive-blur/index.tsx --------- Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -84,7 +84,6 @@
|
||||
"nanoid": "5.1.6",
|
||||
"ofetch": "1.4.1",
|
||||
"plain-shiki": "0.3.1",
|
||||
"progressive-blur": "1.0.0",
|
||||
"re-resizable": "6.11.2",
|
||||
"react": "19.0.0",
|
||||
"react-blurhash": "0.3.0",
|
||||
@@ -133,4 +132,4 @@
|
||||
"react-scan": "0.4.3",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import { getReadonlyRoute } from "@follow/components/atoms/route.js"
|
||||
import { useGlobalFocusableHasScope } from "@follow/components/common/Focusable/hooks.js"
|
||||
import { RootPortal } from "@follow/components/ui/portal/index.js"
|
||||
import { LinearBlur } from "@follow/components/ui/progressive-blur/index.js"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { Routes } from "@follow/constants"
|
||||
import { ELECTRON_BUILD } from "@follow/shared/constants"
|
||||
import { springScrollTo } from "@follow/utils/scroller"
|
||||
import { clsx, cn, getOS } from "@follow/utils/utils"
|
||||
import { m } from "framer-motion"
|
||||
import { LinearBlur } from "progressive-blur"
|
||||
import { isValidElement, useCallback, useEffect, useRef, useState } from "react"
|
||||
import { useHotkeys } from "react-hotkeys-hook"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import * as React from "react"
|
||||
|
||||
interface LinearBlurProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
strength?: number
|
||||
steps?: number
|
||||
falloffPercentage?: number
|
||||
tint?: string
|
||||
side?: "left" | "right" | "top" | "bottom"
|
||||
}
|
||||
|
||||
const oppositeSide = {
|
||||
left: "right",
|
||||
right: "left",
|
||||
top: "bottom",
|
||||
bottom: "top",
|
||||
}
|
||||
|
||||
export function LinearBlur({
|
||||
strength = 64,
|
||||
steps = 8,
|
||||
falloffPercentage = 100,
|
||||
tint = "transparent",
|
||||
side = "top",
|
||||
...props
|
||||
}: LinearBlurProps) {
|
||||
const actualSteps = Math.max(1, steps)
|
||||
const step = falloffPercentage / actualSteps
|
||||
|
||||
const factor = 0.5
|
||||
|
||||
const base = Math.pow(strength / factor, 1 / (actualSteps - 1))
|
||||
|
||||
const mainPercentage = 100 - falloffPercentage
|
||||
|
||||
const getBackdropFilter = (i: number) => `blur(${factor * base ** (actualSteps - i - 1)}px)`
|
||||
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
style={{
|
||||
// This has to be set on the top level element to prevent pointer events
|
||||
pointerEvents: "none",
|
||||
transformOrigin: side,
|
||||
...props.style,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: 0,
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
|
||||
}}
|
||||
>
|
||||
{/* Full blur at 100-falloffPercentage% */}
|
||||
{actualSteps > 1 && (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: 2,
|
||||
inset: 0,
|
||||
mask: `linear-gradient(
|
||||
to ${oppositeSide[side]},
|
||||
rgba(0, 0, 0, 1) ${mainPercentage}%,
|
||||
rgba(0, 0, 0, 1) ${mainPercentage + step}%,
|
||||
rgba(0, 0, 0, 0) ${mainPercentage + step * 2}%
|
||||
)`,
|
||||
backdropFilter: getBackdropFilter(1),
|
||||
WebkitBackdropFilter: getBackdropFilter(1),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{actualSteps > 2 &&
|
||||
Array.from({ length: actualSteps - 2 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: i + 2,
|
||||
inset: 0,
|
||||
mask: `linear-gradient(
|
||||
to ${oppositeSide[side]},
|
||||
rgba(0, 0, 0, 0) ${mainPercentage + i * step}%,
|
||||
rgba(0, 0, 0, 1) ${mainPercentage + (i + 1) * step}%,
|
||||
rgba(0, 0, 0, 1) ${mainPercentage + (i + 2) * step}%,
|
||||
rgba(0, 0, 0, 0) ${mainPercentage + (i + 3) * step}%
|
||||
)`,
|
||||
backdropFilter: getBackdropFilter(i + 2),
|
||||
WebkitBackdropFilter: getBackdropFilter(i + 2),
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
left: 0,
|
||||
top: "-100%",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
boxShadow: `0 0 60px ${tint}, 0 0 100px ${tint}`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Generated
+18
-16
@@ -656,9 +656,6 @@ importers:
|
||||
plain-shiki:
|
||||
specifier: 0.3.1
|
||||
version: 0.3.1(shiki@3.13.0)
|
||||
progressive-blur:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0(react-dom@19.0.0(react@19.0.0))(react@19.0.0)
|
||||
re-resizable:
|
||||
specifier: 6.11.2
|
||||
version: 6.11.2(patch_hash=adb774d32dfdf0ef779d30a8e9e35ba7f3d07706cfe61907db2a53775ea09f23)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)
|
||||
@@ -13750,12 +13747,6 @@ packages:
|
||||
resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
|
||||
progressive-blur@1.0.0:
|
||||
resolution: {integrity: sha512-BZkJJHksqsxt9eJ+bv5ptXyUDa+ZbpOzdGJNJVxFo2qF0u+Y38E1oKWidt6JIaHCM1xk9o8LSjf9TbtHpbx9WQ==}
|
||||
peerDependencies:
|
||||
react: 19.0.0
|
||||
react-dom: 19.0.0
|
||||
|
||||
promise-inflight@1.0.1:
|
||||
resolution: {integrity: sha512-6zWPyEOFaQBJYcGMHBKTKJ3u6TBsnMFOIZSa6ce1e/ZrrsOlnHRHbabMjLiBYKp+n44X9eUI6VUPaukCXHuG4g==}
|
||||
peerDependencies:
|
||||
@@ -23248,7 +23239,7 @@ snapshots:
|
||||
debug: 2.6.9
|
||||
invariant: 2.2.4
|
||||
metro: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
metro-config: 0.82.4(bufferutil@4.0.9)
|
||||
metro-config: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
metro-core: 0.82.4
|
||||
semver: 7.7.3
|
||||
transitivePeerDependencies:
|
||||
@@ -31158,6 +31149,22 @@ snapshots:
|
||||
- supports-color
|
||||
- utf-8-validate
|
||||
|
||||
metro-config@0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5):
|
||||
dependencies:
|
||||
connect: 3.7.0
|
||||
cosmiconfig: 5.2.1
|
||||
flow-enums-runtime: 0.0.6
|
||||
jest-validate: 29.7.0
|
||||
metro: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
metro-cache: 0.82.4
|
||||
metro-core: 0.82.4
|
||||
metro-runtime: 0.82.4
|
||||
transitivePeerDependencies:
|
||||
- bufferutil
|
||||
- supports-color
|
||||
- utf-8-validate
|
||||
optional: true
|
||||
|
||||
metro-core@0.82.4:
|
||||
dependencies:
|
||||
flow-enums-runtime: 0.0.6
|
||||
@@ -31343,7 +31350,7 @@ snapshots:
|
||||
metro-babel-transformer: 0.82.4
|
||||
metro-cache: 0.82.4
|
||||
metro-cache-key: 0.82.4
|
||||
metro-config: 0.82.4(bufferutil@4.0.9)
|
||||
metro-config: 0.82.4(bufferutil@4.0.9)(utf-8-validate@6.0.5)
|
||||
metro-core: 0.82.4
|
||||
metro-file-map: 0.82.4
|
||||
metro-resolver: 0.82.4
|
||||
@@ -32701,11 +32708,6 @@ snapshots:
|
||||
|
||||
progress@2.0.3: {}
|
||||
|
||||
progressive-blur@1.0.0(react-dom@19.0.0(react@19.0.0))(react@19.0.0):
|
||||
dependencies:
|
||||
react: 19.0.0
|
||||
react-dom: 19.0.0(react@19.0.0)
|
||||
|
||||
promise-inflight@1.0.1: {}
|
||||
|
||||
promise-limit@2.7.0: {}
|
||||
|
||||
Reference in New Issue
Block a user