bits-lab 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +51 -2
- package/dist/Accordion.d.ts +52 -0
- package/dist/Accordion.js +192 -0
- package/dist/AchievementToast.d.ts +36 -0
- package/dist/AchievementToast.js +162 -0
- package/dist/AgentCard.d.ts +41 -0
- package/dist/AgentCard.js +168 -0
- package/dist/ArcadeButtons.d.ts +23 -0
- package/dist/ArcadeButtons.js +169 -0
- package/dist/AuroraBands.d.ts +19 -0
- package/dist/AuroraBands.js +126 -0
- package/dist/AvatarTooltips.d.ts +32 -0
- package/dist/AvatarTooltips.js +121 -0
- package/dist/BarRace.d.ts +39 -0
- package/dist/BarRace.js +227 -0
- package/dist/BentoGrid.d.ts +50 -0
- package/dist/BentoGrid.js +145 -0
- package/dist/BootSequence.d.ts +48 -0
- package/dist/BootSequence.js +234 -0
- package/dist/BreadcrumbTrail.d.ts +31 -0
- package/dist/BreadcrumbTrail.js +181 -0
- package/dist/CRTPower.d.ts +30 -0
- package/dist/CRTPower.js +142 -0
- package/dist/CardDeck.d.ts +29 -0
- package/dist/CardDeck.js +154 -0
- package/dist/ChangelogTimeline.d.ts +35 -0
- package/dist/ChangelogTimeline.js +137 -0
- package/dist/ChapterProgress.d.ts +23 -0
- package/dist/ChapterProgress.js +211 -0
- package/dist/ChatBubbles.d.ts +42 -0
- package/dist/ChatBubbles.js +198 -0
- package/dist/ChiptuneKit.d.ts +158 -0
- package/dist/ChiptuneKit.js +207 -0
- package/dist/CipherCard.d.ts +22 -0
- package/dist/CipherCard.js +91 -0
- package/dist/CloudSky.d.ts +28 -0
- package/dist/CloudSky.js +222 -0
- package/dist/CodeRain.d.ts +24 -0
- package/dist/CodeRain.js +158 -0
- package/dist/CodeShowcase.d.ts +50 -0
- package/dist/CodeShowcase.js +307 -0
- package/dist/ColorDial.d.ts +42 -0
- package/dist/ColorDial.js +288 -0
- package/dist/CommandPalette.d.ts +59 -0
- package/dist/CommandPalette.js +349 -0
- package/dist/CompareSlider.d.ts +33 -0
- package/dist/CompareSlider.js +152 -0
- package/dist/Confetti.d.ts +61 -0
- package/dist/Confetti.js +176 -0
- package/dist/ConnectBeams.d.ts +39 -0
- package/dist/ConnectBeams.js +132 -0
- package/dist/ContextOrb.d.ts +34 -0
- package/dist/ContextOrb.js +269 -0
- package/dist/ContourLines.d.ts +20 -0
- package/dist/ContourLines.js +159 -0
- package/dist/Coverflow.d.ts +27 -0
- package/dist/Coverflow.js +167 -0
- package/dist/CursorAttractor.d.ts +21 -0
- package/dist/CursorAttractor.js +136 -0
- package/dist/CutReveal.d.ts +21 -0
- package/dist/CutReveal.js +116 -0
- package/dist/DateRange.d.ts +45 -0
- package/dist/DateRange.js +327 -0
- package/dist/DeviceFrame.d.ts +30 -0
- package/dist/DeviceFrame.js +145 -0
- package/dist/DiffReveal.d.ts +36 -0
- package/dist/DiffReveal.js +247 -0
- package/dist/DirectionHover.d.ts +15 -0
- package/dist/DirectionHover.js +90 -0
- package/dist/Discard.d.ts +18 -0
- package/dist/Discard.js +61 -0
- package/dist/DitherField.d.ts +15 -0
- package/dist/DitherField.js +157 -0
- package/dist/DotGlobe.d.ts +48 -0
- package/dist/DotGlobe.js +312 -0
- package/dist/DotMap.d.ts +47 -0
- package/dist/DotMap.js +172 -0
- package/dist/DropZone.d.ts +57 -0
- package/dist/DropZone.js +304 -0
- package/dist/DynamicIsland.d.ts +32 -0
- package/dist/DynamicIsland.js +92 -0
- package/dist/EdgeFX.d.ts +27 -0
- package/dist/EdgeFX.js +98 -0
- package/dist/ElasticString.d.ts +22 -0
- package/dist/ElasticString.js +127 -0
- package/dist/ExpandCard.d.ts +44 -0
- package/dist/ExpandCard.js +182 -0
- package/dist/FeatureTabs.d.ts +34 -0
- package/dist/FeatureTabs.js +169 -0
- package/dist/FeedList.d.ts +37 -0
- package/dist/FeedList.js +163 -0
- package/dist/FlickerGrid.d.ts +29 -0
- package/dist/FlickerGrid.js +156 -0
- package/dist/FocusGrid.d.ts +20 -0
- package/dist/FocusGrid.js +48 -0
- package/dist/FocusPull.d.ts +26 -0
- package/dist/FocusPull.js +106 -0
- package/dist/Footprints.d.ts +24 -0
- package/dist/Footprints.js +126 -0
- package/dist/FunnelFlow.d.ts +34 -0
- package/dist/FunnelFlow.js +267 -0
- package/dist/GameOver.d.ts +46 -0
- package/dist/GameOver.js +191 -0
- package/dist/GaugeMeter.d.ts +38 -0
- package/dist/GaugeMeter.js +195 -0
- package/dist/GlassPanel.d.ts +27 -0
- package/dist/GlassPanel.js +80 -0
- package/dist/GrainFX.d.ts +34 -0
- package/dist/GrainFX.js +122 -0
- package/dist/GravityBox.d.ts +30 -0
- package/dist/GravityBox.js +220 -0
- package/dist/HealthBar.d.ts +33 -0
- package/dist/HealthBar.js +140 -0
- package/dist/Heatmap.d.ts +42 -0
- package/dist/Heatmap.js +232 -0
- package/dist/HexField.d.ts +29 -0
- package/dist/HexField.js +188 -0
- package/dist/HoldToConfirm.d.ts +29 -0
- package/dist/HoldToConfirm.js +163 -0
- package/dist/HorizontalTrack.d.ts +28 -0
- package/dist/HorizontalTrack.js +195 -0
- package/dist/HotbarDock.d.ts +40 -0
- package/dist/HotbarDock.js +148 -0
- package/dist/InkText.d.ts +27 -0
- package/dist/InkText.js +65 -0
- package/dist/InlineEdit.d.ts +30 -0
- package/dist/InlineEdit.js +198 -0
- package/dist/InteractiveGrid.d.ts +25 -0
- package/dist/InteractiveGrid.js +194 -0
- package/dist/InventoryGrid.d.ts +45 -0
- package/dist/InventoryGrid.js +272 -0
- package/dist/JellyBlob.d.ts +30 -0
- package/dist/JellyBlob.js +209 -0
- package/dist/KineticHeadline.d.ts +30 -0
- package/dist/KineticHeadline.js +133 -0
- package/dist/LavaLamp.d.ts +21 -0
- package/dist/LavaLamp.js +133 -0
- package/dist/LetterSwap.d.ts +20 -0
- package/dist/LetterSwap.js +78 -0
- package/dist/LevelMap.d.ts +35 -0
- package/dist/LevelMap.js +189 -0
- package/dist/LightShafts.d.ts +22 -0
- package/dist/LightShafts.js +170 -0
- package/dist/LightboxGallery.d.ts +26 -0
- package/dist/LightboxGallery.js +327 -0
- package/dist/LinkPeek.d.ts +36 -0
- package/dist/LinkPeek.js +194 -0
- package/dist/LogoOrbit.d.ts +37 -0
- package/dist/LogoOrbit.js +117 -0
- package/dist/Marquee.d.ts +33 -0
- package/dist/Marquee.js +148 -0
- package/dist/MarqueeLine.d.ts +33 -0
- package/dist/MarqueeLine.js +167 -0
- package/dist/MasonryWall.d.ts +13 -0
- package/dist/MasonryWall.js +90 -0
- package/dist/MegaMenu.d.ts +32 -0
- package/dist/MegaMenu.js +280 -0
- package/dist/MeteorShower.d.ts +24 -0
- package/dist/MeteorShower.js +155 -0
- package/dist/Minimap.d.ts +21 -0
- package/dist/Minimap.js +236 -0
- package/dist/MobileTabBar.d.ts +38 -0
- package/dist/MobileTabBar.js +148 -0
- package/dist/MorphDialog.d.ts +34 -0
- package/dist/MorphDialog.js +199 -0
- package/dist/MorphPopover.d.ts +33 -0
- package/dist/MorphPopover.js +168 -0
- package/dist/MorphWords.d.ts +18 -0
- package/dist/MorphWords.js +136 -0
- package/dist/OTPInput.d.ts +43 -0
- package/dist/OTPInput.js +174 -0
- package/dist/OverlayKit.d.ts +97 -0
- package/dist/OverlayKit.js +466 -0
- package/dist/OverlayMenu.d.ts +32 -0
- package/dist/OverlayMenu.js +154 -0
- package/dist/ParallaxCollage.d.ts +41 -0
- package/dist/ParallaxCollage.js +143 -0
- package/dist/PasswordMeter.d.ts +44 -0
- package/dist/PasswordMeter.js +165 -0
- package/dist/PegBoard.d.ts +26 -0
- package/dist/PegBoard.js +184 -0
- package/dist/PinCard.d.ts +21 -0
- package/dist/PinCard.js +84 -0
- package/dist/PixelAvatar.d.ts +33 -0
- package/dist/PixelAvatar.js +144 -0
- package/dist/PixelButton.d.ts +20 -0
- package/dist/PixelButton.js +128 -0
- package/dist/PixelExplode.d.ts +31 -0
- package/dist/PixelExplode.js +164 -0
- package/dist/PixelLoader.d.ts +32 -0
- package/dist/PixelLoader.js +142 -0
- package/dist/PixelParallax.d.ts +41 -0
- package/dist/PixelParallax.js +151 -0
- package/dist/PixelSpinners.d.ts +21 -0
- package/dist/PixelSpinners.js +110 -0
- package/dist/PixelType.d.ts +26 -0
- package/dist/PixelType.js +220 -0
- package/dist/PointerKit.d.ts +23 -0
- package/dist/PointerKit.js +222 -0
- package/dist/Polaroids.d.ts +41 -0
- package/dist/Polaroids.js +293 -0
- package/dist/PressStart.d.ts +28 -0
- package/dist/PressStart.js +99 -0
- package/dist/PricingFlip.d.ts +52 -0
- package/dist/PricingFlip.js +190 -0
- package/dist/ProximityType.d.ts +26 -0
- package/dist/ProximityType.js +135 -0
- package/dist/QuestDialog.d.ts +50 -0
- package/dist/QuestDialog.js +204 -0
- package/dist/QuestLog.d.ts +39 -0
- package/dist/QuestLog.js +214 -0
- package/dist/RangeDual.d.ts +34 -0
- package/dist/RangeDual.js +238 -0
- package/dist/RatingPips.d.ts +25 -0
- package/dist/RatingPips.js +129 -0
- package/dist/RetroHorizon.d.ts +27 -0
- package/dist/RetroHorizon.js +169 -0
- package/dist/Reveal.d.ts +30 -0
- package/dist/Reveal.js +92 -0
- package/dist/RingProgress.d.ts +45 -0
- package/dist/RingProgress.js +180 -0
- package/dist/RollingNumber.d.ts +28 -0
- package/dist/RollingNumber.js +108 -0
- package/dist/ScanScope.d.ts +24 -0
- package/dist/ScanScope.js +164 -0
- package/dist/ScoreTicker.d.ts +32 -0
- package/dist/ScoreTicker.js +176 -0
- package/dist/ScreenScroller.d.ts +24 -0
- package/dist/ScreenScroller.js +138 -0
- package/dist/Screensaver.d.ts +31 -0
- package/dist/Screensaver.js +221 -0
- package/dist/ScrollTilt.d.ts +27 -0
- package/dist/ScrollTilt.js +100 -0
- package/dist/ScrollTypography.d.ts +26 -0
- package/dist/ScrollTypography.js +124 -0
- package/dist/ScrollZoom.d.ts +31 -0
- package/dist/ScrollZoom.js +123 -0
- package/dist/ScrubNumber.d.ts +29 -0
- package/dist/ScrubNumber.js +152 -0
- package/dist/ShadowStack.d.ts +28 -0
- package/dist/ShadowStack.js +116 -0
- package/dist/SideRail.d.ts +43 -0
- package/dist/SideRail.js +253 -0
- package/dist/SignalText.d.ts +25 -0
- package/dist/SignalText.js +178 -0
- package/dist/SkeletonShimmer.d.ts +18 -0
- package/dist/SkeletonShimmer.js +111 -0
- package/dist/SketchHighlight.d.ts +27 -0
- package/dist/SketchHighlight.js +180 -0
- package/dist/SlideTabs.d.ts +40 -0
- package/dist/SlideTabs.js +190 -0
- package/dist/SmartNavbar.d.ts +48 -0
- package/dist/SmartNavbar.js +188 -0
- package/dist/SparkChart.d.ts +41 -0
- package/dist/SparkChart.js +188 -0
- package/dist/Spoiler.d.ts +22 -0
- package/dist/Spoiler.js +97 -0
- package/dist/SpotlightTour.d.ts +38 -0
- package/dist/SpotlightTour.js +231 -0
- package/dist/SpringDrawer.d.ts +39 -0
- package/dist/SpringDrawer.js +360 -0
- package/dist/SpriteAnimator.d.ts +41 -0
- package/dist/SpriteAnimator.js +124 -0
- package/dist/StatCard.d.ts +43 -0
- package/dist/StatCard.js +168 -0
- package/dist/StepLoader.d.ts +41 -0
- package/dist/StepLoader.js +191 -0
- package/dist/StepperForm.d.ts +41 -0
- package/dist/StepperForm.js +206 -0
- package/dist/StickerBoard.d.ts +39 -0
- package/dist/StickerBoard.js +209 -0
- package/dist/StickyReveal.d.ts +42 -0
- package/dist/StickyReveal.js +181 -0
- package/dist/StoryViewer.d.ts +36 -0
- package/dist/StoryViewer.js +175 -0
- package/dist/StreamingText.d.ts +29 -0
- package/dist/StreamingText.js +271 -0
- package/dist/SuggestionChips.d.ts +32 -0
- package/dist/SuggestionChips.js +96 -0
- package/dist/SwipeActions.d.ts +30 -0
- package/dist/SwipeActions.js +141 -0
- package/dist/TagInput.d.ts +30 -0
- package/dist/TagInput.js +284 -0
- package/dist/TallyUp.d.ts +38 -0
- package/dist/TallyUp.js +157 -0
- package/dist/TerminalDemo.d.ts +63 -0
- package/dist/TerminalDemo.js +214 -0
- package/dist/TestimonialWall.d.ts +35 -0
- package/dist/TestimonialWall.js +131 -0
- package/dist/TextOnPath.d.ts +36 -0
- package/dist/TextOnPath.js +130 -0
- package/dist/ThinkingShimmer.d.ts +36 -0
- package/dist/ThinkingShimmer.js +132 -0
- package/dist/ToastStack.d.ts +62 -0
- package/dist/ToastStack.js +289 -0
- package/dist/ToggleGroup.d.ts +39 -0
- package/dist/ToggleGroup.js +190 -0
- package/dist/ToggleKit.d.ts +70 -0
- package/dist/ToggleKit.js +229 -0
- package/dist/TracingLine.d.ts +24 -0
- package/dist/TracingLine.js +139 -0
- package/dist/TradingCard.d.ts +30 -0
- package/dist/TradingCard.js +147 -0
- package/dist/VanishInput.d.ts +34 -0
- package/dist/VanishInput.js +190 -0
- package/dist/VideoHero.d.ts +32 -0
- package/dist/VideoHero.js +207 -0
- package/dist/VoiceOrb.d.ts +23 -0
- package/dist/VoiceOrb.js +182 -0
- package/dist/VoxelTiles.d.ts +38 -0
- package/dist/VoxelTiles.js +201 -0
- package/dist/WarpField.d.ts +18 -0
- package/dist/WarpField.js +160 -0
- package/dist/WebcamPixels.d.ts +38 -0
- package/dist/WebcamPixels.js +292 -0
- package/dist/WheelPicker.d.ts +29 -0
- package/dist/WheelPicker.js +199 -0
- package/dist/WobbleCard.d.ts +23 -0
- package/dist/WobbleCard.js +112 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +159 -0
- package/package.json +34 -4
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
const hexToRgb = (hex) => {
|
|
5
|
+
const n = parseInt(hex.replace("#", "").replace(/^(.)(.)(.)$/, "$1$1$2$2$3$3"), 16);
|
|
6
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
7
|
+
};
|
|
8
|
+
const hash = (x, y, z) => {
|
|
9
|
+
let n = Math.imul(x, 374761393) ^ Math.imul(y, 668265263) ^ Math.imul(z, 1440662683);
|
|
10
|
+
n = Math.imul(n ^ n >>> 13, 1274126177);
|
|
11
|
+
return ((n ^ n >>> 16) >>> 0) / 4294967296;
|
|
12
|
+
};
|
|
13
|
+
const fade = (t) => t * t * (3 - 2 * t);
|
|
14
|
+
function noise(x, y, z) {
|
|
15
|
+
const xi = Math.floor(x);
|
|
16
|
+
const yi = Math.floor(y);
|
|
17
|
+
const zi = Math.floor(z);
|
|
18
|
+
const u = fade(x - xi);
|
|
19
|
+
const v = fade(y - yi);
|
|
20
|
+
const w = fade(z - zi);
|
|
21
|
+
const lerp = (a, b, k) => a + (b - a) * k;
|
|
22
|
+
const corner = (dx, dy, dz) => hash(xi + dx, yi + dy, zi + dz);
|
|
23
|
+
return lerp(
|
|
24
|
+
lerp(lerp(corner(0, 0, 0), corner(1, 0, 0), u), lerp(corner(0, 1, 0), corner(1, 1, 0), u), v),
|
|
25
|
+
lerp(lerp(corner(0, 0, 1), corner(1, 0, 1), u), lerp(corner(0, 1, 1), corner(1, 1, 1), u), v),
|
|
26
|
+
w
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function ContourLines({
|
|
30
|
+
levels = 14,
|
|
31
|
+
major = 5,
|
|
32
|
+
scale = 1,
|
|
33
|
+
speed = 1,
|
|
34
|
+
pixelSize = 2,
|
|
35
|
+
tint = true,
|
|
36
|
+
pointer = true,
|
|
37
|
+
lineColor = "#73eff7",
|
|
38
|
+
majorColor = "#f4f4f4",
|
|
39
|
+
bandColors = ["#1a1c2c", "#262b44"],
|
|
40
|
+
className = "",
|
|
41
|
+
style
|
|
42
|
+
}) {
|
|
43
|
+
const canvasRef = useRef(null);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const canvas = canvasRef.current;
|
|
46
|
+
const ctx = canvas.getContext("2d");
|
|
47
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
48
|
+
const line = hexToRgb(lineColor);
|
|
49
|
+
const strong = hexToRgb(majorColor);
|
|
50
|
+
const bands = bandColors.map(hexToRgb);
|
|
51
|
+
const hand = { x: -1, y: -1, lift: 0, on: false };
|
|
52
|
+
let w = 0;
|
|
53
|
+
let h = 0;
|
|
54
|
+
let img = null;
|
|
55
|
+
let level = new Int16Array(0);
|
|
56
|
+
let t = 0;
|
|
57
|
+
let raf = 0;
|
|
58
|
+
let last = 0;
|
|
59
|
+
let visible = true;
|
|
60
|
+
const fit = () => {
|
|
61
|
+
w = Math.max(1, Math.ceil(canvas.clientWidth / pixelSize));
|
|
62
|
+
h = Math.max(1, Math.ceil(canvas.clientHeight / pixelSize));
|
|
63
|
+
canvas.width = w;
|
|
64
|
+
canvas.height = h;
|
|
65
|
+
img = ctx.createImageData(w, h);
|
|
66
|
+
level = new Int16Array(w * h);
|
|
67
|
+
};
|
|
68
|
+
const frame = () => {
|
|
69
|
+
const k = 2.2 * scale / Math.max(w, h);
|
|
70
|
+
for (let y = 0; y < h; y++) {
|
|
71
|
+
for (let x = 0; x < w; x++) {
|
|
72
|
+
let v = noise(x * k * 1.6, y * k * 1.6, t * 0.12) * 0.7 + noise(x * k * 4, y * k * 4, t * 0.2 + 5) * 0.3;
|
|
73
|
+
if (hand.lift > 0.01) {
|
|
74
|
+
const dx = (x - hand.x) / w;
|
|
75
|
+
const dy = (y - hand.y) / w;
|
|
76
|
+
v += Math.exp(-(dx * dx + dy * dy) / 0.01) * 0.35 * hand.lift;
|
|
77
|
+
}
|
|
78
|
+
level[y * w + x] = Math.floor(v * levels);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const d = img.data;
|
|
82
|
+
for (let y = 0; y < h; y++) {
|
|
83
|
+
for (let x = 0; x < w; x++) {
|
|
84
|
+
const i = y * w + x;
|
|
85
|
+
const L = level[i];
|
|
86
|
+
const edge = x + 1 < w && level[i + 1] !== L || y + 1 < h && level[i + w] !== L;
|
|
87
|
+
let c;
|
|
88
|
+
if (edge) c = Math.max(L, x + 1 < w ? level[i + 1] : L, y + 1 < h ? level[i + w] : L) % major === 0 ? strong : line;
|
|
89
|
+
else c = tint ? bands[(L % bands.length + bands.length) % bands.length] : bands[0];
|
|
90
|
+
const o = i * 4;
|
|
91
|
+
d[o] = c[0];
|
|
92
|
+
d[o + 1] = c[1];
|
|
93
|
+
d[o + 2] = c[2];
|
|
94
|
+
d[o + 3] = 255;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
ctx.putImageData(img, 0, 0);
|
|
98
|
+
};
|
|
99
|
+
const tick = (now) => {
|
|
100
|
+
const dt = Math.max(0, Math.min(0.05, (now - last) / 1e3));
|
|
101
|
+
last = now;
|
|
102
|
+
t += dt * speed;
|
|
103
|
+
hand.lift += ((hand.on ? 1 : 0) - hand.lift) * Math.min(1, dt * 4);
|
|
104
|
+
frame();
|
|
105
|
+
raf = visible && !document.hidden ? requestAnimationFrame(tick) : 0;
|
|
106
|
+
};
|
|
107
|
+
const start = () => {
|
|
108
|
+
if (raf || reduced || !visible || document.hidden) return;
|
|
109
|
+
last = performance.now();
|
|
110
|
+
raf = requestAnimationFrame(tick);
|
|
111
|
+
};
|
|
112
|
+
const onMove = (event) => {
|
|
113
|
+
if (!pointer) return;
|
|
114
|
+
const r = canvas.getBoundingClientRect();
|
|
115
|
+
hand.x = (event.clientX - r.left) / r.width * w;
|
|
116
|
+
hand.y = (event.clientY - r.top) / r.height * h;
|
|
117
|
+
hand.on = true;
|
|
118
|
+
if (reduced) {
|
|
119
|
+
hand.lift = 1;
|
|
120
|
+
frame();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const onLeave = () => {
|
|
124
|
+
hand.on = false;
|
|
125
|
+
if (reduced) {
|
|
126
|
+
hand.lift = 0;
|
|
127
|
+
frame();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const resize = new ResizeObserver(() => {
|
|
131
|
+
fit();
|
|
132
|
+
frame();
|
|
133
|
+
});
|
|
134
|
+
resize.observe(canvas);
|
|
135
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
136
|
+
visible = entry.isIntersecting;
|
|
137
|
+
start();
|
|
138
|
+
});
|
|
139
|
+
observer.observe(canvas);
|
|
140
|
+
document.addEventListener("visibilitychange", start);
|
|
141
|
+
canvas.addEventListener("pointermove", onMove);
|
|
142
|
+
canvas.addEventListener("pointerleave", onLeave);
|
|
143
|
+
fit();
|
|
144
|
+
frame();
|
|
145
|
+
start();
|
|
146
|
+
return () => {
|
|
147
|
+
cancelAnimationFrame(raf);
|
|
148
|
+
resize.disconnect();
|
|
149
|
+
observer.disconnect();
|
|
150
|
+
document.removeEventListener("visibilitychange", start);
|
|
151
|
+
canvas.removeEventListener("pointermove", onMove);
|
|
152
|
+
canvas.removeEventListener("pointerleave", onLeave);
|
|
153
|
+
};
|
|
154
|
+
}, [levels, major, scale, speed, pixelSize, tint, pointer, lineColor, majorColor, bandColors.join()]);
|
|
155
|
+
return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, "aria-hidden": "true", className, style: { display: "block", width: "100%", height: "100%", background: bandColors[0], imageRendering: "pixelated", touchAction: "pan-y", ...style } });
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
ContourLines as default
|
|
159
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface CoverflowProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
index?: number;
|
|
5
|
+
defaultIndex?: number;
|
|
6
|
+
onChange?: (index: number) => void;
|
|
7
|
+
itemWidth?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
/** Overlap between items (share of the item width). */
|
|
10
|
+
spacing?: number;
|
|
11
|
+
/** How far side items turn, in degrees. */
|
|
12
|
+
angle?: number;
|
|
13
|
+
/** How far side items step back, in px. */
|
|
14
|
+
depth?: number;
|
|
15
|
+
/** Items rendered on each side. */
|
|
16
|
+
range?: number;
|
|
17
|
+
label?: string;
|
|
18
|
+
textColor?: string;
|
|
19
|
+
mutedColor?: string;
|
|
20
|
+
lineColor?: string;
|
|
21
|
+
chipColor?: string;
|
|
22
|
+
accentColor?: string;
|
|
23
|
+
fontFamily?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
}
|
|
27
|
+
export default function Coverflow({ children, index: controlled, defaultIndex, onChange, itemWidth, height, spacing, angle, depth, range, label, textColor, mutedColor, lineColor, chipColor, accentColor, fontFamily, className, style }: CoverflowProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Children, useEffect, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-coverflow";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-cover { display: grid; gap: 14px; justify-items: center; width: 100%; font-family: var(--bl-font); color: var(--bl-ink); }
|
|
7
|
+
.bl-cover__stage { position: relative; width: 100%; height: var(--bl-h); perspective: 1100px; touch-action: pan-y; outline: none; overflow: hidden; }
|
|
8
|
+
.bl-cover__stage:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 4px; border-radius: 12px; }
|
|
9
|
+
.bl-cover__item { position: absolute; top: 50%; left: 50%; width: var(--bl-item); margin-left: calc(var(--bl-item) / -2); transform: translateY(-50%) translateX(calc(var(--o) * var(--bl-item) * var(--bl-spacing))) translateZ(calc(var(--a) * var(--bl-depth) * -1)) rotateY(calc(var(--s) * var(--bl-angle) * -1)); transition: transform 420ms cubic-bezier(.2,.8,.2,1), filter 420ms; transform-style: preserve-3d; cursor: pointer; filter: brightness(calc(1 - var(--a) * 0.18)); }
|
|
10
|
+
.bl-cover__item[data-active] { cursor: default; }
|
|
11
|
+
.bl-cover__stage[data-dragging] .bl-cover__item { transition: none; }
|
|
12
|
+
.bl-cover__floor { position: absolute; left: 10%; right: 10%; bottom: 6%; height: 14%; border-radius: 50%; background: radial-gradient(closest-side, rgba(0,0,0,0.55), transparent); pointer-events: none; }
|
|
13
|
+
.bl-cover__bar { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--bl-muted); }
|
|
14
|
+
.bl-cover__btn { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 10px; background: var(--bl-chip); color: var(--bl-ink); cursor: pointer; }
|
|
15
|
+
.bl-cover__btn:hover { background: var(--bl-line); }
|
|
16
|
+
.bl-cover__btn:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 2px; }
|
|
17
|
+
.bl-cover__btn:disabled { opacity: 0.4; cursor: not-allowed; }
|
|
18
|
+
.bl-cover__count { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
|
|
19
|
+
@media (prefers-reduced-motion: reduce) { .bl-cover__item { transition: none; transform: translateY(-50%) translateX(calc(var(--o) * var(--bl-item) * 1.05)); } }
|
|
20
|
+
`;
|
|
21
|
+
function useStyles() {
|
|
22
|
+
useInsertionEffect(() => {
|
|
23
|
+
if (typeof document === "undefined") return;
|
|
24
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
25
|
+
style.textContent = CSS;
|
|
26
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
29
|
+
const Arrow = ({ flip }) => /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", style: { transform: flip ? "scaleX(-1)" : void 0 }, children: /* @__PURE__ */ jsx("path", { d: "M6 3l5 5-5 5" }) });
|
|
30
|
+
function Coverflow({
|
|
31
|
+
children,
|
|
32
|
+
index: controlled,
|
|
33
|
+
defaultIndex = 0,
|
|
34
|
+
onChange,
|
|
35
|
+
itemWidth = 220,
|
|
36
|
+
height = 320,
|
|
37
|
+
spacing = 0.55,
|
|
38
|
+
angle = 55,
|
|
39
|
+
depth = 120,
|
|
40
|
+
range = 4,
|
|
41
|
+
label = "Gallery",
|
|
42
|
+
textColor = "#f4f4f4",
|
|
43
|
+
mutedColor = "#94b0c2",
|
|
44
|
+
lineColor = "#333c57",
|
|
45
|
+
chipColor = "rgba(255,255,255,0.08)",
|
|
46
|
+
accentColor = "#73eff7",
|
|
47
|
+
fontFamily = "inherit",
|
|
48
|
+
className = "",
|
|
49
|
+
style
|
|
50
|
+
}) {
|
|
51
|
+
useStyles();
|
|
52
|
+
const items = Children.toArray(children);
|
|
53
|
+
const n = items.length;
|
|
54
|
+
const [inner, setInner] = useState(defaultIndex);
|
|
55
|
+
const index = Math.max(0, Math.min(n - 1, controlled ?? inner));
|
|
56
|
+
const [drag, setDrag] = useState(null);
|
|
57
|
+
const stageRef = useRef(null);
|
|
58
|
+
const wheelRef = useRef(0);
|
|
59
|
+
const draggedRef = useRef(false);
|
|
60
|
+
const select = (next) => {
|
|
61
|
+
const clamped = Math.max(0, Math.min(n - 1, next));
|
|
62
|
+
if (clamped === index) return;
|
|
63
|
+
if (controlled === void 0) setInner(clamped);
|
|
64
|
+
onChange?.(clamped);
|
|
65
|
+
};
|
|
66
|
+
const selectRef = useRef(select);
|
|
67
|
+
selectRef.current = select;
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const stage = stageRef.current;
|
|
70
|
+
const onWheel = (event) => {
|
|
71
|
+
const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.shiftKey ? event.deltaY : 0;
|
|
72
|
+
if (!delta) return;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
wheelRef.current += delta;
|
|
75
|
+
if (Math.abs(wheelRef.current) > 60) {
|
|
76
|
+
selectRef.current(index + Math.sign(wheelRef.current));
|
|
77
|
+
wheelRef.current = 0;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
stage.addEventListener("wheel", onWheel, { passive: false });
|
|
81
|
+
return () => stage.removeEventListener("wheel", onWheel);
|
|
82
|
+
}, [index]);
|
|
83
|
+
const onPointerDown = (event) => {
|
|
84
|
+
if (event.button > 0) return;
|
|
85
|
+
setDrag({ x: event.clientX, shift: 0, moved: false });
|
|
86
|
+
};
|
|
87
|
+
const onPointerMove = (event) => {
|
|
88
|
+
if (!drag) return;
|
|
89
|
+
if (!drag.moved && Math.abs(event.clientX - drag.x) > 6) stageRef.current.setPointerCapture?.(event.pointerId);
|
|
90
|
+
setDrag((d) => ({ ...d, shift: (event.clientX - d.x) / (itemWidth * spacing), moved: d.moved || Math.abs(event.clientX - d.x) > 6 }));
|
|
91
|
+
};
|
|
92
|
+
const onPointerUp = () => {
|
|
93
|
+
if (!drag) return;
|
|
94
|
+
draggedRef.current = drag.moved;
|
|
95
|
+
if (drag.moved) select(index - Math.round(drag.shift));
|
|
96
|
+
setDrag(null);
|
|
97
|
+
};
|
|
98
|
+
const onKeyDown = (event) => {
|
|
99
|
+
const moves = { ArrowRight: 1, ArrowLeft: -1, Home: -n, End: n };
|
|
100
|
+
if (moves[event.key] === void 0) return;
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
select(index + moves[event.key]);
|
|
103
|
+
};
|
|
104
|
+
return /* @__PURE__ */ jsxs(
|
|
105
|
+
"div",
|
|
106
|
+
{
|
|
107
|
+
className: `bl-cover ${className}`,
|
|
108
|
+
style: { "--bl-h": `${height}px`, "--bl-item": `${itemWidth}px`, "--bl-spacing": spacing, "--bl-angle": `${angle}deg`, "--bl-depth": `${depth}px`, "--bl-ink": textColor, "--bl-muted": mutedColor, "--bl-line": lineColor, "--bl-chip": chipColor, "--bl-accent": accentColor, "--bl-font": fontFamily, ...style },
|
|
109
|
+
children: [
|
|
110
|
+
/* @__PURE__ */ jsxs(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
ref: stageRef,
|
|
114
|
+
className: "bl-cover__stage",
|
|
115
|
+
role: "group",
|
|
116
|
+
"aria-roledescription": "carousel",
|
|
117
|
+
"aria-label": `${label}: item ${index + 1} of ${n}`,
|
|
118
|
+
tabIndex: 0,
|
|
119
|
+
"data-dragging": drag?.moved || void 0,
|
|
120
|
+
onKeyDown,
|
|
121
|
+
onPointerDown,
|
|
122
|
+
onPointerMove,
|
|
123
|
+
onPointerUp,
|
|
124
|
+
onPointerCancel: onPointerUp,
|
|
125
|
+
children: [
|
|
126
|
+
/* @__PURE__ */ jsx("span", { className: "bl-cover__floor", "aria-hidden": "true" }),
|
|
127
|
+
items.map((item, i) => {
|
|
128
|
+
const o = i - index + (drag?.moved ? drag.shift : 0);
|
|
129
|
+
const a = Math.min(Math.abs(o), range);
|
|
130
|
+
if (Math.abs(o) > range + 1) return null;
|
|
131
|
+
const active = i === index;
|
|
132
|
+
return /* @__PURE__ */ jsx(
|
|
133
|
+
"div",
|
|
134
|
+
{
|
|
135
|
+
className: "bl-cover__item",
|
|
136
|
+
"data-active": active || void 0,
|
|
137
|
+
"aria-hidden": !active || void 0,
|
|
138
|
+
inert: !active || void 0,
|
|
139
|
+
onClick: () => {
|
|
140
|
+
if (draggedRef.current) draggedRef.current = false;
|
|
141
|
+
else select(i);
|
|
142
|
+
},
|
|
143
|
+
style: { "--o": o.toFixed(3), "--a": a.toFixed(3), "--s": Math.max(-1, Math.min(1, o)).toFixed(3), zIndex: 100 - Math.round(a * 10) },
|
|
144
|
+
children: item
|
|
145
|
+
},
|
|
146
|
+
item.key ?? i
|
|
147
|
+
);
|
|
148
|
+
})
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
),
|
|
152
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-cover__bar", children: [
|
|
153
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bl-cover__btn", "aria-label": "Previous", disabled: index === 0, onClick: () => select(index - 1), children: /* @__PURE__ */ jsx(Arrow, { flip: true }) }),
|
|
154
|
+
/* @__PURE__ */ jsxs("span", { className: "bl-cover__count", "aria-live": "polite", children: [
|
|
155
|
+
index + 1,
|
|
156
|
+
" / ",
|
|
157
|
+
n
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bl-cover__btn", "aria-label": "Next", disabled: index === n - 1, onClick: () => select(index + 1), children: /* @__PURE__ */ jsx(Arrow, {}) })
|
|
160
|
+
] })
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
Coverflow as default
|
|
167
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface CursorAttractorProps {
|
|
3
|
+
/** Each child is pulled on its own spring. */
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
mode?: 'attract' | 'repel';
|
|
6
|
+
/** Reach in px from each item's centre. */
|
|
7
|
+
radius?: number;
|
|
8
|
+
/** How hard the pull is (fraction of the distance). */
|
|
9
|
+
strength?: number;
|
|
10
|
+
/** Cap on movement in px. */
|
|
11
|
+
maxShift?: number;
|
|
12
|
+
stiffness?: number;
|
|
13
|
+
damping?: number;
|
|
14
|
+
gap?: number;
|
|
15
|
+
/** Padding around the items; the pointer counts anywhere inside it. */
|
|
16
|
+
padding?: number;
|
|
17
|
+
justify?: 'center' | 'start' | 'end';
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
}
|
|
21
|
+
export default function CursorAttractor({ children, radius, strength, maxShift, mode, stiffness, damping, gap, padding, justify, className, style }: CursorAttractorProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Children, useEffect, useInsertionEffect, useRef } from "react";
|
|
4
|
+
const STYLE_ID = "bl-cursor-attractor";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-attract { display: flex; flex-wrap: wrap; align-items: center; justify-content: var(--bl-justify); gap: var(--bl-gap); padding: var(--bl-pad); touch-action: pan-y; }
|
|
7
|
+
.bl-attract__item { display: inline-block; will-change: transform; }
|
|
8
|
+
`;
|
|
9
|
+
function useStyles() {
|
|
10
|
+
useInsertionEffect(() => {
|
|
11
|
+
if (typeof document === "undefined") return;
|
|
12
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
13
|
+
style.textContent = CSS;
|
|
14
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
15
|
+
}, []);
|
|
16
|
+
}
|
|
17
|
+
function CursorAttractor({
|
|
18
|
+
children,
|
|
19
|
+
radius = 180,
|
|
20
|
+
strength = 0.35,
|
|
21
|
+
maxShift = 36,
|
|
22
|
+
mode = "attract",
|
|
23
|
+
stiffness = 220,
|
|
24
|
+
damping = 13,
|
|
25
|
+
gap = 16,
|
|
26
|
+
padding = 32,
|
|
27
|
+
justify = "center",
|
|
28
|
+
className = "",
|
|
29
|
+
style
|
|
30
|
+
}) {
|
|
31
|
+
useStyles();
|
|
32
|
+
const rootRef = useRef(null);
|
|
33
|
+
const itemRefs = useRef([]);
|
|
34
|
+
const items = Children.toArray(children);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const root = rootRef.current;
|
|
37
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
38
|
+
if (reduced) return;
|
|
39
|
+
const nodes = itemRefs.current.slice(0, items.length).filter(Boolean);
|
|
40
|
+
const state = nodes.map(() => ({ tx: 0, ty: 0, x: 0, y: 0, vx: 0, vy: 0 }));
|
|
41
|
+
let centres = [];
|
|
42
|
+
let frame = 0;
|
|
43
|
+
let last = 0;
|
|
44
|
+
const sign = mode === "repel" ? -1 : 1;
|
|
45
|
+
const measure = () => {
|
|
46
|
+
centres = nodes.map((node, i) => {
|
|
47
|
+
const rect = node.getBoundingClientRect();
|
|
48
|
+
return { x: rect.left + rect.width / 2 - state[i].x, y: rect.top + rect.height / 2 - state[i].y };
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const tick = (now) => {
|
|
52
|
+
const dt = Math.min(0.05, (now - last) / 1e3 || 0.016);
|
|
53
|
+
last = now;
|
|
54
|
+
let moving = false;
|
|
55
|
+
state.forEach((s, i) => {
|
|
56
|
+
for (let t = 0; t < dt; t += 1 / 240) {
|
|
57
|
+
s.vx += (stiffness * (s.tx - s.x) - damping * s.vx) / 240;
|
|
58
|
+
s.vy += (stiffness * (s.ty - s.y) - damping * s.vy) / 240;
|
|
59
|
+
s.x += s.vx / 240;
|
|
60
|
+
s.y += s.vy / 240;
|
|
61
|
+
}
|
|
62
|
+
if (Math.abs(s.tx - s.x) > 0.05 || Math.abs(s.ty - s.y) > 0.05 || Math.abs(s.vx) > 0.5 || Math.abs(s.vy) > 0.5) moving = true;
|
|
63
|
+
else Object.assign(s, { x: s.tx, y: s.ty, vx: 0, vy: 0 });
|
|
64
|
+
nodes[i].style.transform = s.x || s.y ? `translate(${s.x.toFixed(2)}px, ${s.y.toFixed(2)}px)` : "";
|
|
65
|
+
});
|
|
66
|
+
frame = moving ? requestAnimationFrame(tick) : 0;
|
|
67
|
+
};
|
|
68
|
+
const wake = () => {
|
|
69
|
+
if (frame) return;
|
|
70
|
+
last = performance.now();
|
|
71
|
+
frame = requestAnimationFrame(tick);
|
|
72
|
+
};
|
|
73
|
+
const onEnter = () => measure();
|
|
74
|
+
const onMove = (event) => {
|
|
75
|
+
if (!centres.length) measure();
|
|
76
|
+
state.forEach((s, i) => {
|
|
77
|
+
const dx = event.clientX - centres[i].x;
|
|
78
|
+
const dy = event.clientY - centres[i].y;
|
|
79
|
+
const d = Math.hypot(dx, dy);
|
|
80
|
+
if (d >= radius || d === 0) {
|
|
81
|
+
s.tx = 0;
|
|
82
|
+
s.ty = 0;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const pull = strength * (1 - d / radius);
|
|
86
|
+
const len = Math.min(maxShift, d * pull);
|
|
87
|
+
s.tx = sign * dx * len / d;
|
|
88
|
+
s.ty = sign * dy * len / d;
|
|
89
|
+
});
|
|
90
|
+
wake();
|
|
91
|
+
};
|
|
92
|
+
const onLeave = () => {
|
|
93
|
+
state.forEach((s) => {
|
|
94
|
+
s.tx = 0;
|
|
95
|
+
s.ty = 0;
|
|
96
|
+
});
|
|
97
|
+
centres = [];
|
|
98
|
+
wake();
|
|
99
|
+
};
|
|
100
|
+
const onLayout = () => {
|
|
101
|
+
centres = [];
|
|
102
|
+
};
|
|
103
|
+
root.addEventListener("pointerenter", onEnter);
|
|
104
|
+
root.addEventListener("pointermove", onMove);
|
|
105
|
+
root.addEventListener("pointerleave", onLeave);
|
|
106
|
+
root.addEventListener("pointercancel", onLeave);
|
|
107
|
+
window.addEventListener("scroll", onLayout, { passive: true, capture: true });
|
|
108
|
+
window.addEventListener("resize", onLayout);
|
|
109
|
+
return () => {
|
|
110
|
+
cancelAnimationFrame(frame);
|
|
111
|
+
root.removeEventListener("pointerenter", onEnter);
|
|
112
|
+
root.removeEventListener("pointermove", onMove);
|
|
113
|
+
root.removeEventListener("pointerleave", onLeave);
|
|
114
|
+
root.removeEventListener("pointercancel", onLeave);
|
|
115
|
+
window.removeEventListener("scroll", onLayout, { capture: true });
|
|
116
|
+
window.removeEventListener("resize", onLayout);
|
|
117
|
+
nodes.forEach((node) => {
|
|
118
|
+
node.style.transform = "";
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
}, [items.length, radius, strength, maxShift, mode, stiffness, damping]);
|
|
122
|
+
return /* @__PURE__ */ jsx("div", { ref: rootRef, className: `bl-attract ${className}`, style: { "--bl-gap": `${gap}px`, "--bl-pad": `${padding}px`, "--bl-justify": justify === "start" ? "flex-start" : justify === "end" ? "flex-end" : "center", ...style }, children: items.map((child, i) => /* @__PURE__ */ jsx(
|
|
123
|
+
"span",
|
|
124
|
+
{
|
|
125
|
+
ref: (node) => {
|
|
126
|
+
itemRefs.current[i] = node;
|
|
127
|
+
},
|
|
128
|
+
className: "bl-attract__item",
|
|
129
|
+
children: child
|
|
130
|
+
},
|
|
131
|
+
child.key ?? i
|
|
132
|
+
)) });
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
CursorAttractor as default
|
|
136
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CSSProperties, type ElementType } from 'react';
|
|
2
|
+
export interface CutRevealProps {
|
|
3
|
+
text?: string;
|
|
4
|
+
/** Element to render (h1–h6, p…). */
|
|
5
|
+
as?: ElementType;
|
|
6
|
+
/** Width of each cut in px. */
|
|
7
|
+
slice?: number;
|
|
8
|
+
/** The way the strips open. */
|
|
9
|
+
direction?: 'right' | 'left' | 'down' | 'up';
|
|
10
|
+
stagger?: number;
|
|
11
|
+
duration?: number;
|
|
12
|
+
/** How far lines rise as they appear (CSS length). */
|
|
13
|
+
rise?: string;
|
|
14
|
+
/** Share of the element that must be visible to play. */
|
|
15
|
+
threshold?: number;
|
|
16
|
+
/** Change to play again. */
|
|
17
|
+
replayKey?: string | number;
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
}
|
|
21
|
+
export default function CutReveal({ text, as, slice, direction, stagger, duration, rise, threshold, replayKey, className, style }: CutRevealProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useInsertionEffect, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-cut-reveal";
|
|
5
|
+
const CSS = `
|
|
6
|
+
@property --bl-open { syntax: '<number>'; inherits: false; initial-value: 0; }
|
|
7
|
+
.bl-cut { margin: 0; }
|
|
8
|
+
.bl-cut__line { display: block; --bl-open: 0; -webkit-mask-image: repeating-linear-gradient(var(--bl-angle), #000 0 calc(var(--bl-open) * var(--bl-slice)), transparent calc(var(--bl-open) * var(--bl-slice)) var(--bl-slice)); mask-image: repeating-linear-gradient(var(--bl-angle), #000 0 calc(var(--bl-open) * var(--bl-slice)), transparent calc(var(--bl-open) * var(--bl-slice)) var(--bl-slice)); transform: translateY(var(--bl-rise)); opacity: 0.001; }
|
|
9
|
+
.bl-cut[data-state="play"] .bl-cut__line { animation: bl-cut-open var(--bl-dur) cubic-bezier(.2,.9,.25,1) both; animation-delay: calc(var(--i) * var(--bl-stagger)); }
|
|
10
|
+
.bl-cut[data-state="done"] .bl-cut__line { -webkit-mask-image: none; mask-image: none; transform: none; opacity: 1; }
|
|
11
|
+
.bl-cut[data-state="measure"] .bl-cut__line { display: inline; -webkit-mask-image: none; mask-image: none; transform: none; opacity: 0; }
|
|
12
|
+
@keyframes bl-cut-open { to { --bl-open: 1.02; transform: none; opacity: 1; } }
|
|
13
|
+
@media (prefers-reduced-motion: reduce) { .bl-cut .bl-cut__line { animation: none !important; -webkit-mask-image: none; mask-image: none; transform: none; opacity: 1; } }
|
|
14
|
+
`;
|
|
15
|
+
function useStyles() {
|
|
16
|
+
useInsertionEffect(() => {
|
|
17
|
+
if (typeof document === "undefined") return;
|
|
18
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
19
|
+
style.textContent = CSS;
|
|
20
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
21
|
+
}, []);
|
|
22
|
+
}
|
|
23
|
+
function CutReveal({
|
|
24
|
+
text = "",
|
|
25
|
+
as = "p",
|
|
26
|
+
slice = 14,
|
|
27
|
+
direction = "right",
|
|
28
|
+
stagger = 140,
|
|
29
|
+
duration = 900,
|
|
30
|
+
rise = "0.35em",
|
|
31
|
+
threshold = 0.3,
|
|
32
|
+
replayKey,
|
|
33
|
+
className = "",
|
|
34
|
+
style
|
|
35
|
+
}) {
|
|
36
|
+
useStyles();
|
|
37
|
+
const ref = useRef(null);
|
|
38
|
+
const words = text.split(/\s+/).filter(Boolean);
|
|
39
|
+
const [lines, setLines] = useState(null);
|
|
40
|
+
const [state, setState] = useState("measure");
|
|
41
|
+
const width = useRef(0);
|
|
42
|
+
const Tag = as;
|
|
43
|
+
const measure = () => {
|
|
44
|
+
const node = ref.current;
|
|
45
|
+
if (!node) return;
|
|
46
|
+
const spans = [...node.querySelectorAll("[data-word]")];
|
|
47
|
+
const grouped = [];
|
|
48
|
+
let top = null;
|
|
49
|
+
spans.forEach((span, i) => {
|
|
50
|
+
if (top === null || Math.abs(span.offsetTop - top) > 2) {
|
|
51
|
+
grouped.push([]);
|
|
52
|
+
top = span.offsetTop;
|
|
53
|
+
}
|
|
54
|
+
grouped[grouped.length - 1].push(words[i]);
|
|
55
|
+
});
|
|
56
|
+
setLines(grouped.map((line) => line.join(" ")));
|
|
57
|
+
};
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
setLines(null);
|
|
60
|
+
setState("measure");
|
|
61
|
+
}, [text, replayKey]);
|
|
62
|
+
useLayoutEffect(() => {
|
|
63
|
+
if (lines === null) measure();
|
|
64
|
+
}, [lines]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const node = ref.current;
|
|
67
|
+
width.current = node.clientWidth;
|
|
68
|
+
const resize = new ResizeObserver(() => {
|
|
69
|
+
if (Math.abs(node.clientWidth - width.current) < 2) return;
|
|
70
|
+
width.current = node.clientWidth;
|
|
71
|
+
setLines(null);
|
|
72
|
+
});
|
|
73
|
+
resize.observe(node);
|
|
74
|
+
return () => resize.disconnect();
|
|
75
|
+
}, []);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (lines === null || state === "play" || state === "done") return void 0;
|
|
78
|
+
if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
|
|
79
|
+
setState("done");
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
setState("wait");
|
|
83
|
+
const io = new IntersectionObserver(
|
|
84
|
+
([entry]) => {
|
|
85
|
+
if (!entry.isIntersecting) return;
|
|
86
|
+
io.disconnect();
|
|
87
|
+
setState("play");
|
|
88
|
+
},
|
|
89
|
+
{ threshold }
|
|
90
|
+
);
|
|
91
|
+
io.observe(ref.current);
|
|
92
|
+
return () => io.disconnect();
|
|
93
|
+
}, [lines]);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (state !== "play" || !lines) return void 0;
|
|
96
|
+
const timer = setTimeout(() => setState("done"), duration + stagger * lines.length + 50);
|
|
97
|
+
return () => clearTimeout(timer);
|
|
98
|
+
}, [state, lines, duration, stagger]);
|
|
99
|
+
const angle = { right: "90deg", left: "270deg", down: "180deg", up: "0deg" }[direction] ?? "90deg";
|
|
100
|
+
return /* @__PURE__ */ jsx(
|
|
101
|
+
Tag,
|
|
102
|
+
{
|
|
103
|
+
ref,
|
|
104
|
+
className: `bl-cut ${className}`,
|
|
105
|
+
"data-state": lines === null ? "measure" : state === "wait" ? "wait" : state,
|
|
106
|
+
style: { "--bl-slice": `${slice}px`, "--bl-angle": angle, "--bl-stagger": `${stagger}ms`, "--bl-dur": `${duration}ms`, "--bl-rise": rise, ...style },
|
|
107
|
+
children: lines === null ? words.map((word, i) => /* @__PURE__ */ jsxs("span", { "data-word": "", children: [
|
|
108
|
+
word,
|
|
109
|
+
" "
|
|
110
|
+
] }, i)) : lines.map((line, i) => /* @__PURE__ */ jsx("span", { className: "bl-cut__line", style: { "--i": i }, children: line }, `${i}-${line}`))
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
CutReveal as default
|
|
116
|
+
};
|