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,29 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface HexFieldProps {
|
|
3
|
+
/** Hexagon radius in px. */
|
|
4
|
+
size?: number;
|
|
5
|
+
gap?: number;
|
|
6
|
+
/** Fills its parent by default. */
|
|
7
|
+
height?: number | string;
|
|
8
|
+
baseColor?: string;
|
|
9
|
+
cellColor?: string;
|
|
10
|
+
glowColor?: string;
|
|
11
|
+
rippleColor?: string;
|
|
12
|
+
backgroundColor?: string;
|
|
13
|
+
/** How far the pointer glow reaches, in px. */
|
|
14
|
+
hoverRadius?: number;
|
|
15
|
+
/** Ripple speed in px per second. */
|
|
16
|
+
rippleSpeed?: number;
|
|
17
|
+
rippleWidth?: number;
|
|
18
|
+
/** A slow drifting wave at rest. */
|
|
19
|
+
wave?: boolean;
|
|
20
|
+
/** Render at a third of the resolution for chunky pixels. */
|
|
21
|
+
pixelated?: boolean;
|
|
22
|
+
onRipple?: (at: {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
className?: string;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
}
|
|
29
|
+
export default function HexField({ size, gap, height, baseColor, cellColor, glowColor, rippleColor, backgroundColor, hoverRadius, rippleSpeed, rippleWidth, wave, pixelated, onRipple, className, style }: HexFieldProps): import("react").JSX.Element;
|
package/dist/HexField.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
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 mix = (a, b, t) => a.map((v, i) => Math.round(v + (b[i] - v) * t));
|
|
9
|
+
function HexField({
|
|
10
|
+
size = 22,
|
|
11
|
+
gap = 3,
|
|
12
|
+
height = "100%",
|
|
13
|
+
baseColor = "#1a1c2c",
|
|
14
|
+
cellColor = "#29366f",
|
|
15
|
+
glowColor = "#73eff7",
|
|
16
|
+
rippleColor = "#ffcd75",
|
|
17
|
+
backgroundColor = "#0b0b14",
|
|
18
|
+
hoverRadius = 110,
|
|
19
|
+
rippleSpeed = 420,
|
|
20
|
+
rippleWidth = 70,
|
|
21
|
+
wave = true,
|
|
22
|
+
pixelated = false,
|
|
23
|
+
onRipple,
|
|
24
|
+
className = "",
|
|
25
|
+
style
|
|
26
|
+
}) {
|
|
27
|
+
const canvasRef = useRef(null);
|
|
28
|
+
const rippleRef = useRef(onRipple);
|
|
29
|
+
rippleRef.current = onRipple;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const canvas = canvasRef.current;
|
|
32
|
+
const ctx = canvas.getContext("2d");
|
|
33
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
34
|
+
const base = hexToRgb(cellColor);
|
|
35
|
+
const glow = hexToRgb(glowColor);
|
|
36
|
+
const ripCol = hexToRgb(rippleColor);
|
|
37
|
+
const edge = hexToRgb(baseColor);
|
|
38
|
+
let cells = [];
|
|
39
|
+
let W = 0;
|
|
40
|
+
let H = 0;
|
|
41
|
+
let dpr = 1;
|
|
42
|
+
const pointer = { x: -9999, y: -9999 };
|
|
43
|
+
const ripples = [];
|
|
44
|
+
let flash = null;
|
|
45
|
+
let visible = true;
|
|
46
|
+
let raf = 0;
|
|
47
|
+
let clock = 0;
|
|
48
|
+
let last = 0;
|
|
49
|
+
const layout = () => {
|
|
50
|
+
dpr = pixelated ? 1 / 3 : Math.min(2, window.devicePixelRatio || 1);
|
|
51
|
+
W = canvas.clientWidth;
|
|
52
|
+
H = canvas.clientHeight;
|
|
53
|
+
canvas.width = Math.round(W * dpr);
|
|
54
|
+
canvas.height = Math.round(H * dpr);
|
|
55
|
+
const w = Math.sqrt(3) * size;
|
|
56
|
+
const rowH = size * 1.5;
|
|
57
|
+
cells = [];
|
|
58
|
+
for (let row = -1; row * rowH < H + size; row++) {
|
|
59
|
+
for (let col = -1; col * w < W + w; col++) {
|
|
60
|
+
cells.push({ x: col * w + (row % 2 ? w / 2 : 0), y: row * rowH, lift: 0 });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const hex = (x, y, r) => {
|
|
65
|
+
ctx.beginPath();
|
|
66
|
+
for (let k = 0; k < 6; k++) {
|
|
67
|
+
const a = Math.PI / 3 * k - Math.PI / 2;
|
|
68
|
+
const px = x + Math.cos(a) * r;
|
|
69
|
+
const py = y + Math.sin(a) * r;
|
|
70
|
+
if (k) ctx.lineTo(px, py);
|
|
71
|
+
else ctx.moveTo(px, py);
|
|
72
|
+
}
|
|
73
|
+
ctx.closePath();
|
|
74
|
+
};
|
|
75
|
+
const draw = () => {
|
|
76
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
77
|
+
ctx.clearRect(0, 0, W, H);
|
|
78
|
+
const r = size - gap / 2;
|
|
79
|
+
cells.forEach((cell) => {
|
|
80
|
+
const waveT = wave && !reduced ? (Math.sin(cell.x * 0.012 + cell.y * 0.018 - clock * 1.1) + 1) / 2 : 0.5;
|
|
81
|
+
const d = Math.hypot(cell.x - pointer.x, cell.y - pointer.y);
|
|
82
|
+
const hover = Math.max(0, 1 - d / hoverRadius) ** 1.6;
|
|
83
|
+
let rip = 0;
|
|
84
|
+
ripples.forEach((rp) => {
|
|
85
|
+
const ring = Math.abs(Math.hypot(cell.x - rp.x, cell.y - rp.y) - rp.r);
|
|
86
|
+
rip = Math.max(rip, Math.max(0, 1 - ring / rippleWidth) * rp.strength);
|
|
87
|
+
});
|
|
88
|
+
if (flash) rip = Math.max(rip, Math.max(0, 1 - Math.hypot(cell.x - flash.x, cell.y - flash.y) / (hoverRadius * 1.6)) * flash.strength);
|
|
89
|
+
let rgb = mix(edge, base, 0.45 + waveT * 0.35);
|
|
90
|
+
rgb = mix(rgb, glow, hover * 0.85);
|
|
91
|
+
rgb = mix(rgb, ripCol, rip * 0.9);
|
|
92
|
+
const lift = rip * 3 + hover * 1.5;
|
|
93
|
+
hex(cell.x, cell.y - lift, r * (1 + rip * 0.08));
|
|
94
|
+
ctx.fillStyle = `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`;
|
|
95
|
+
ctx.fill();
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
const tick = (now) => {
|
|
99
|
+
const dt = Math.max(0, Math.min(0.05, (now - last) / 1e3));
|
|
100
|
+
last = now;
|
|
101
|
+
clock += dt;
|
|
102
|
+
const reach = Math.hypot(W, H) + rippleWidth;
|
|
103
|
+
for (let i = ripples.length - 1; i >= 0; i--) {
|
|
104
|
+
const rp = ripples[i];
|
|
105
|
+
rp.r += rippleSpeed * dt;
|
|
106
|
+
rp.strength = Math.max(0, 1 - rp.r / reach);
|
|
107
|
+
if (rp.r > reach) ripples.splice(i, 1);
|
|
108
|
+
}
|
|
109
|
+
draw();
|
|
110
|
+
raf = visible && !document.hidden && (wave || ripples.length || pointer.x > -9999) ? requestAnimationFrame(tick) : 0;
|
|
111
|
+
};
|
|
112
|
+
const start = () => {
|
|
113
|
+
if (raf || reduced || !visible || document.hidden) return;
|
|
114
|
+
last = performance.now();
|
|
115
|
+
raf = requestAnimationFrame(tick);
|
|
116
|
+
};
|
|
117
|
+
const local = (event) => {
|
|
118
|
+
const rect = canvas.getBoundingClientRect();
|
|
119
|
+
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
120
|
+
};
|
|
121
|
+
const onMove = (event) => {
|
|
122
|
+
Object.assign(pointer, local(event));
|
|
123
|
+
if (reduced) draw();
|
|
124
|
+
else start();
|
|
125
|
+
};
|
|
126
|
+
const onLeave = () => {
|
|
127
|
+
pointer.x = -9999;
|
|
128
|
+
pointer.y = -9999;
|
|
129
|
+
if (reduced) draw();
|
|
130
|
+
else start();
|
|
131
|
+
};
|
|
132
|
+
const onDown = (event) => {
|
|
133
|
+
const at = local(event);
|
|
134
|
+
rippleRef.current?.(at);
|
|
135
|
+
if (reduced) {
|
|
136
|
+
flash = { ...at, strength: 1 };
|
|
137
|
+
draw();
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
flash = null;
|
|
140
|
+
draw();
|
|
141
|
+
}, 450);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
ripples.push({ ...at, r: 0, strength: 1 });
|
|
145
|
+
if (ripples.length > 6) ripples.shift();
|
|
146
|
+
start();
|
|
147
|
+
};
|
|
148
|
+
const resize = new ResizeObserver(() => {
|
|
149
|
+
layout();
|
|
150
|
+
draw();
|
|
151
|
+
});
|
|
152
|
+
resize.observe(canvas);
|
|
153
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
154
|
+
visible = entry.isIntersecting;
|
|
155
|
+
start();
|
|
156
|
+
});
|
|
157
|
+
observer.observe(canvas);
|
|
158
|
+
const onVisibility = () => start();
|
|
159
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
160
|
+
canvas.addEventListener("pointermove", onMove);
|
|
161
|
+
canvas.addEventListener("pointerleave", onLeave);
|
|
162
|
+
canvas.addEventListener("pointerdown", onDown);
|
|
163
|
+
layout();
|
|
164
|
+
draw();
|
|
165
|
+
start();
|
|
166
|
+
return () => {
|
|
167
|
+
cancelAnimationFrame(raf);
|
|
168
|
+
resize.disconnect();
|
|
169
|
+
observer.disconnect();
|
|
170
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
171
|
+
canvas.removeEventListener("pointermove", onMove);
|
|
172
|
+
canvas.removeEventListener("pointerleave", onLeave);
|
|
173
|
+
canvas.removeEventListener("pointerdown", onDown);
|
|
174
|
+
};
|
|
175
|
+
}, [size, gap, baseColor, cellColor, glowColor, rippleColor, hoverRadius, rippleSpeed, rippleWidth, wave, pixelated]);
|
|
176
|
+
return /* @__PURE__ */ jsx(
|
|
177
|
+
"canvas",
|
|
178
|
+
{
|
|
179
|
+
ref: canvasRef,
|
|
180
|
+
className,
|
|
181
|
+
"aria-hidden": "true",
|
|
182
|
+
style: { display: "block", width: "100%", height, background: backgroundColor, touchAction: "pan-y", imageRendering: pixelated ? "pixelated" : void 0, ...style }
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
export {
|
|
187
|
+
HexField as default
|
|
188
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface HoldToConfirmProps {
|
|
3
|
+
/** Label while waiting. */
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
/** Label after confirming. */
|
|
6
|
+
doneLabel?: ReactNode;
|
|
7
|
+
/** Called once the fuse burns all the way. */
|
|
8
|
+
onConfirm?: () => void;
|
|
9
|
+
/** Hold time in ms. */
|
|
10
|
+
duration?: number;
|
|
11
|
+
/** How many times faster it rewinds when let go. */
|
|
12
|
+
rewind?: number;
|
|
13
|
+
/** How long the done state shows, in ms. */
|
|
14
|
+
resetAfter?: number;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
radius?: number;
|
|
19
|
+
backgroundColor?: string;
|
|
20
|
+
fillColor?: string;
|
|
21
|
+
fuseColor?: string;
|
|
22
|
+
sparkColor?: string;
|
|
23
|
+
textColor?: string;
|
|
24
|
+
accentColor?: string;
|
|
25
|
+
fontFamily?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
style?: CSSProperties;
|
|
28
|
+
}
|
|
29
|
+
export default function HoldToConfirm({ children, doneLabel, onConfirm, duration, rewind, resetAfter, disabled, width, height, radius, backgroundColor, fillColor, fuseColor, sparkColor, textColor, accentColor, fontFamily, className, style }: HoldToConfirmProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-hold-confirm";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-hold { --p: 0; position: relative; display: inline-grid; place-items: center; min-width: var(--bl-w); height: var(--bl-h); padding: 0 22px; overflow: hidden; border: 0; border-radius: var(--bl-radius); background: var(--bl-bg); color: var(--bl-ink); font: inherit; font-family: var(--bl-font); font-size: 15px; font-weight: 700; cursor: pointer; user-select: none; touch-action: none; box-shadow: inset 0 -4px 0 rgba(0,0,0,0.3); -webkit-tap-highlight-color: transparent; }
|
|
7
|
+
.bl-hold:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 3px; }
|
|
8
|
+
.bl-hold:disabled { cursor: not-allowed; opacity: 0.5; }
|
|
9
|
+
.bl-hold__fill { position: absolute; inset: 0; background: var(--bl-fill); transform: scaleX(var(--p)); transform-origin: left; }
|
|
10
|
+
.bl-hold__fuse { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: repeating-linear-gradient(90deg, var(--bl-fuse) 0 6px, transparent 6px 9px); }
|
|
11
|
+
.bl-hold__spark { position: absolute; bottom: -2px; left: calc(var(--p) * 100%); width: 8px; height: 8px; margin-left: -4px; background: var(--bl-spark); box-shadow: 4px -4px 0 var(--bl-spark), -4px -6px 0 var(--bl-fuse), 2px -10px 0 rgba(255,255,255,0.7); opacity: 0; animation: bl-hold-crackle 120ms steps(2) infinite; }
|
|
12
|
+
.bl-hold[data-state="holding"] .bl-hold__spark { opacity: 1; }
|
|
13
|
+
.bl-hold__label { position: relative; display: inline-flex; align-items: center; gap: 8px; }
|
|
14
|
+
.bl-hold[data-state="done"] { animation: bl-hold-flash 420ms steps(3); }
|
|
15
|
+
.bl-hold__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
16
|
+
@keyframes bl-hold-crackle { 50% { transform: translate(1px, -2px) scale(0.8); } }
|
|
17
|
+
@keyframes bl-hold-flash { 33% { filter: brightness(1.8); } }
|
|
18
|
+
@media (prefers-reduced-motion: reduce) { .bl-hold__spark { display: none; } .bl-hold[data-state="done"] { animation: none; } }
|
|
19
|
+
`;
|
|
20
|
+
function useStyles() {
|
|
21
|
+
useInsertionEffect(() => {
|
|
22
|
+
if (typeof document === "undefined") return;
|
|
23
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
24
|
+
style.textContent = CSS;
|
|
25
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
26
|
+
}, []);
|
|
27
|
+
}
|
|
28
|
+
function HoldToConfirm({
|
|
29
|
+
children = "Hold to delete",
|
|
30
|
+
doneLabel = "Done",
|
|
31
|
+
onConfirm,
|
|
32
|
+
duration = 1200,
|
|
33
|
+
rewind = 2.5,
|
|
34
|
+
resetAfter = 1600,
|
|
35
|
+
disabled = false,
|
|
36
|
+
width = 200,
|
|
37
|
+
height = 52,
|
|
38
|
+
radius = 10,
|
|
39
|
+
backgroundColor = "#333c57",
|
|
40
|
+
fillColor = "#b13e53",
|
|
41
|
+
fuseColor = "#ef7d57",
|
|
42
|
+
sparkColor = "#ffcd75",
|
|
43
|
+
textColor = "#f4f4f4",
|
|
44
|
+
accentColor = "#73eff7",
|
|
45
|
+
fontFamily = "inherit",
|
|
46
|
+
className = "",
|
|
47
|
+
style
|
|
48
|
+
}) {
|
|
49
|
+
useStyles();
|
|
50
|
+
const ref = useRef(null);
|
|
51
|
+
const confirmRef = useRef(onConfirm);
|
|
52
|
+
confirmRef.current = onConfirm;
|
|
53
|
+
const [state, setState] = useState("idle");
|
|
54
|
+
const [announce, setAnnounce] = useState("");
|
|
55
|
+
const held = useRef(false);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const el = ref.current;
|
|
58
|
+
let p = 0;
|
|
59
|
+
let raf = 0;
|
|
60
|
+
let last = 0;
|
|
61
|
+
let done = false;
|
|
62
|
+
let resetTimer = 0;
|
|
63
|
+
const paint = () => el.style.setProperty("--p", p.toFixed(4));
|
|
64
|
+
const tick = (now) => {
|
|
65
|
+
const dt = Math.max(0, Math.min(0.25, (now - last) / 1e3));
|
|
66
|
+
last = now;
|
|
67
|
+
p = held.current ? Math.min(1, p + dt * 1e3 / duration) : Math.max(0, p - dt * 1e3 / duration * rewind);
|
|
68
|
+
paint();
|
|
69
|
+
if (held.current && p >= 1 && !done) {
|
|
70
|
+
done = true;
|
|
71
|
+
held.current = false;
|
|
72
|
+
setState("done");
|
|
73
|
+
setAnnounce(`${typeof doneLabel === "string" ? doneLabel : "Done"}.`);
|
|
74
|
+
confirmRef.current?.();
|
|
75
|
+
resetTimer = setTimeout(() => {
|
|
76
|
+
done = false;
|
|
77
|
+
p = 0;
|
|
78
|
+
paint();
|
|
79
|
+
setState("idle");
|
|
80
|
+
setAnnounce("");
|
|
81
|
+
}, resetAfter);
|
|
82
|
+
raf = 0;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
raf = held.current || p > 0 ? requestAnimationFrame(tick) : 0;
|
|
86
|
+
if (!raf) setState("idle");
|
|
87
|
+
};
|
|
88
|
+
const start = () => {
|
|
89
|
+
if (done || el.disabled) return;
|
|
90
|
+
held.current = true;
|
|
91
|
+
setState("holding");
|
|
92
|
+
if (!raf) {
|
|
93
|
+
last = performance.now();
|
|
94
|
+
raf = requestAnimationFrame(tick);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const stop = () => {
|
|
98
|
+
if (!held.current) return;
|
|
99
|
+
held.current = false;
|
|
100
|
+
if (!raf && p > 0) {
|
|
101
|
+
last = performance.now();
|
|
102
|
+
raf = requestAnimationFrame(tick);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const onDown = (event) => {
|
|
106
|
+
if (event.button > 0) return;
|
|
107
|
+
el.setPointerCapture?.(event.pointerId);
|
|
108
|
+
start();
|
|
109
|
+
};
|
|
110
|
+
const onKeyDown = (event) => {
|
|
111
|
+
if ((event.key === " " || event.key === "Enter") && !event.repeat) {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
start();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const onKeyUp = (event) => {
|
|
117
|
+
if (event.key === " " || event.key === "Enter") stop();
|
|
118
|
+
};
|
|
119
|
+
const onClick = (event) => event.preventDefault();
|
|
120
|
+
el.addEventListener("pointerdown", onDown);
|
|
121
|
+
el.addEventListener("pointerup", stop);
|
|
122
|
+
el.addEventListener("pointercancel", stop);
|
|
123
|
+
el.addEventListener("lostpointercapture", stop);
|
|
124
|
+
el.addEventListener("keydown", onKeyDown);
|
|
125
|
+
el.addEventListener("keyup", onKeyUp);
|
|
126
|
+
el.addEventListener("blur", stop);
|
|
127
|
+
el.addEventListener("click", onClick);
|
|
128
|
+
return () => {
|
|
129
|
+
cancelAnimationFrame(raf);
|
|
130
|
+
clearTimeout(resetTimer);
|
|
131
|
+
el.removeEventListener("pointerdown", onDown);
|
|
132
|
+
el.removeEventListener("pointerup", stop);
|
|
133
|
+
el.removeEventListener("pointercancel", stop);
|
|
134
|
+
el.removeEventListener("lostpointercapture", stop);
|
|
135
|
+
el.removeEventListener("keydown", onKeyDown);
|
|
136
|
+
el.removeEventListener("keyup", onKeyUp);
|
|
137
|
+
el.removeEventListener("blur", stop);
|
|
138
|
+
el.removeEventListener("click", onClick);
|
|
139
|
+
};
|
|
140
|
+
}, [duration, rewind, resetAfter]);
|
|
141
|
+
return /* @__PURE__ */ jsxs(
|
|
142
|
+
"button",
|
|
143
|
+
{
|
|
144
|
+
ref,
|
|
145
|
+
type: "button",
|
|
146
|
+
className: `bl-hold ${className}`,
|
|
147
|
+
"data-state": state,
|
|
148
|
+
disabled,
|
|
149
|
+
style: { "--bl-w": `${width}px`, "--bl-h": `${height}px`, "--bl-radius": `${radius}px`, "--bl-bg": backgroundColor, "--bl-fill": fillColor, "--bl-fuse": fuseColor, "--bl-spark": sparkColor, "--bl-ink": textColor, "--bl-accent": accentColor, "--bl-font": fontFamily, ...style },
|
|
150
|
+
children: [
|
|
151
|
+
/* @__PURE__ */ jsx("span", { className: "bl-hold__fill", "aria-hidden": "true" }),
|
|
152
|
+
/* @__PURE__ */ jsx("span", { className: "bl-hold__fuse", "aria-hidden": "true" }),
|
|
153
|
+
/* @__PURE__ */ jsx("span", { className: "bl-hold__spark", "aria-hidden": "true" }),
|
|
154
|
+
/* @__PURE__ */ jsx("span", { className: "bl-hold__label", children: state === "done" ? doneLabel : children }),
|
|
155
|
+
/* @__PURE__ */ jsx("span", { className: "bl-hold__sr", children: state === "done" ? "" : " (press and hold to confirm)" }),
|
|
156
|
+
/* @__PURE__ */ jsx("span", { className: "bl-hold__sr", "aria-live": "polite", children: announce })
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
HoldToConfirm as default
|
|
163
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface HorizontalTrackProps {
|
|
3
|
+
/** Gallery items. Each becomes a focusable list item. */
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
/** Content pinned above the track. */
|
|
6
|
+
header?: ReactNode;
|
|
7
|
+
/** Item width, in px. */
|
|
8
|
+
itemWidth?: number;
|
|
9
|
+
gap?: number;
|
|
10
|
+
/** Side padding of the track, in px. */
|
|
11
|
+
padding?: number;
|
|
12
|
+
/** Height of the pinned stage. Use the scroll box height when inside one. */
|
|
13
|
+
stageHeight?: string;
|
|
14
|
+
/** After scrolling stops, glide to the nearest item. */
|
|
15
|
+
snap?: boolean;
|
|
16
|
+
/** Counter and progress bar under the track. */
|
|
17
|
+
showProgress?: boolean;
|
|
18
|
+
/** Accessible name of the gallery. */
|
|
19
|
+
label?: string;
|
|
20
|
+
accentColor?: string;
|
|
21
|
+
mutedColor?: string;
|
|
22
|
+
trackColor?: string;
|
|
23
|
+
barRadius?: number;
|
|
24
|
+
fontFamily?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: CSSProperties;
|
|
27
|
+
}
|
|
28
|
+
export default function HorizontalTrack({ children, header, itemWidth, gap, padding, stageHeight, snap, showProgress, label, accentColor, mutedColor, trackColor, barRadius, fontFamily, className, style }: HorizontalTrackProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,195 @@
|
|
|
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-horizontal-track";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-htrack { position: relative; height: var(--bl-len); }
|
|
7
|
+
.bl-htrack__stage { position: sticky; top: 0; height: var(--bl-stage); display: flex; flex-direction: column; justify-content: center; overflow: hidden; }
|
|
8
|
+
.bl-htrack__header { padding: 0 var(--bl-pad); margin-bottom: 20px; }
|
|
9
|
+
.bl-htrack__row { display: flex; gap: var(--bl-gap); width: max-content; padding: 0 var(--bl-pad); transform: translate3d(calc(var(--bl-x) * -1px), 0, 0); will-change: transform; }
|
|
10
|
+
.bl-htrack__item { flex: 0 0 auto; width: var(--bl-item); max-width: calc(100vw - var(--bl-pad) * 2); outline: none; }
|
|
11
|
+
.bl-htrack__item:focus-visible { box-shadow: 0 0 0 3px var(--bl-accent); }
|
|
12
|
+
.bl-htrack__footer { display: flex; align-items: center; gap: 16px; padding: 22px var(--bl-pad) 0; color: var(--bl-muted); font: 600 13px/1 var(--bl-font); font-variant-numeric: tabular-nums; }
|
|
13
|
+
.bl-htrack__bar { flex: 1; height: 4px; border-radius: var(--bl-bar-radius); background: var(--bl-track); overflow: hidden; }
|
|
14
|
+
.bl-htrack__fill { height: 100%; background: var(--bl-accent); transform-origin: left; transform: scaleX(var(--bl-p)); }
|
|
15
|
+
@media (prefers-reduced-motion: reduce) {
|
|
16
|
+
.bl-htrack { height: auto; }
|
|
17
|
+
.bl-htrack__stage { position: relative; height: auto; padding: 32px 0; }
|
|
18
|
+
.bl-htrack__row { transform: none; width: auto; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 12px; }
|
|
19
|
+
.bl-htrack__item { scroll-snap-align: start; }
|
|
20
|
+
.bl-htrack__footer { display: none; }
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
function useStyles() {
|
|
24
|
+
useInsertionEffect(() => {
|
|
25
|
+
if (typeof document === "undefined") return;
|
|
26
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
27
|
+
style.textContent = CSS;
|
|
28
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
29
|
+
}, []);
|
|
30
|
+
}
|
|
31
|
+
function scrollParent(node) {
|
|
32
|
+
for (let el = node?.parentElement; el; el = el.parentElement) {
|
|
33
|
+
if (/(auto|scroll|overlay)/.test(getComputedStyle(el).overflowY) && el.scrollHeight > el.clientHeight) return el;
|
|
34
|
+
}
|
|
35
|
+
return window;
|
|
36
|
+
}
|
|
37
|
+
function HorizontalTrack({
|
|
38
|
+
children,
|
|
39
|
+
header,
|
|
40
|
+
itemWidth = 420,
|
|
41
|
+
gap = 24,
|
|
42
|
+
padding = 48,
|
|
43
|
+
stageHeight = "100vh",
|
|
44
|
+
snap = true,
|
|
45
|
+
showProgress = true,
|
|
46
|
+
label = "Gallery",
|
|
47
|
+
accentColor = "#ffcd75",
|
|
48
|
+
mutedColor = "#94b0c2",
|
|
49
|
+
trackColor = "rgba(148,176,194,0.2)",
|
|
50
|
+
barRadius = 2,
|
|
51
|
+
fontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
52
|
+
className = "",
|
|
53
|
+
style
|
|
54
|
+
}) {
|
|
55
|
+
useStyles();
|
|
56
|
+
const rootRef = useRef(null);
|
|
57
|
+
const stageRef = useRef(null);
|
|
58
|
+
const rowRef = useRef(null);
|
|
59
|
+
const [length, setLength] = useState(null);
|
|
60
|
+
const [current, setCurrent] = useState(0);
|
|
61
|
+
const items = Children.toArray(children);
|
|
62
|
+
const geometry = useRef({ travel: 0, scroller: null });
|
|
63
|
+
const sectionStart = () => {
|
|
64
|
+
const { scroller } = geometry.current;
|
|
65
|
+
const rect = rootRef.current.getBoundingClientRect();
|
|
66
|
+
if (scroller === window) return rect.top + window.scrollY;
|
|
67
|
+
return rect.top - scroller.getBoundingClientRect().top + scroller.scrollTop;
|
|
68
|
+
};
|
|
69
|
+
const scrollTo = (top, smooth = true) => {
|
|
70
|
+
const { scroller } = geometry.current;
|
|
71
|
+
scroller.scrollTo({ top, behavior: smooth ? "smooth" : "auto" });
|
|
72
|
+
};
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const root = rootRef.current;
|
|
75
|
+
const stage = stageRef.current;
|
|
76
|
+
const row = rowRef.current;
|
|
77
|
+
const scroller = scrollParent(root);
|
|
78
|
+
geometry.current.scroller = scroller;
|
|
79
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
80
|
+
if (reduced) return;
|
|
81
|
+
let frame = 0;
|
|
82
|
+
let idle = 0;
|
|
83
|
+
let lastIndex = -1;
|
|
84
|
+
const measure = () => {
|
|
85
|
+
const travel = Math.max(0, row.scrollWidth - stage.clientWidth);
|
|
86
|
+
geometry.current.travel = travel;
|
|
87
|
+
setLength((prev) => prev === travel + stage.clientHeight ? prev : travel + stage.clientHeight);
|
|
88
|
+
};
|
|
89
|
+
const update = () => {
|
|
90
|
+
frame = 0;
|
|
91
|
+
const { travel } = geometry.current;
|
|
92
|
+
const rect = root.getBoundingClientRect();
|
|
93
|
+
const viewTop = scroller === window ? 0 : scroller.getBoundingClientRect().top;
|
|
94
|
+
const progress = travel ? Math.min(1, Math.max(0, (viewTop - rect.top) / travel)) : 0;
|
|
95
|
+
root.style.setProperty("--bl-x", (progress * travel).toFixed(1));
|
|
96
|
+
root.style.setProperty("--bl-p", progress.toFixed(4));
|
|
97
|
+
const step = row.children[1] ? row.children[1].offsetLeft - row.children[0].offsetLeft : 1;
|
|
98
|
+
const index = Math.min(row.children.length - 1, Math.round(progress * travel / step));
|
|
99
|
+
if (index !== lastIndex) {
|
|
100
|
+
lastIndex = index;
|
|
101
|
+
setCurrent(index);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const settle = () => {
|
|
105
|
+
const { travel } = geometry.current;
|
|
106
|
+
const start = sectionStart();
|
|
107
|
+
const offset = (scroller === window ? window.scrollY : scroller.scrollTop) - start;
|
|
108
|
+
if (offset <= 2 || offset >= travel - 2) return;
|
|
109
|
+
const lefts = [...row.children].map((child) => Math.min(travel, child.offsetLeft - row.children[0].offsetLeft));
|
|
110
|
+
const nearest = lefts.reduce((best, x) => Math.abs(x - offset) < Math.abs(best - offset) ? x : best, lefts[0]);
|
|
111
|
+
if (Math.abs(nearest - offset) > 2) scrollTo(start + nearest);
|
|
112
|
+
};
|
|
113
|
+
const onScroll = () => {
|
|
114
|
+
if (!frame) frame = requestAnimationFrame(update);
|
|
115
|
+
if (snap) {
|
|
116
|
+
clearTimeout(idle);
|
|
117
|
+
idle = setTimeout(settle, 140);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const observer = new ResizeObserver(() => {
|
|
121
|
+
measure();
|
|
122
|
+
onScroll();
|
|
123
|
+
});
|
|
124
|
+
observer.observe(stage);
|
|
125
|
+
observer.observe(row);
|
|
126
|
+
measure();
|
|
127
|
+
update();
|
|
128
|
+
scroller.addEventListener("scroll", onScroll, { passive: true });
|
|
129
|
+
window.addEventListener("resize", onScroll);
|
|
130
|
+
return () => {
|
|
131
|
+
cancelAnimationFrame(frame);
|
|
132
|
+
clearTimeout(idle);
|
|
133
|
+
observer.disconnect();
|
|
134
|
+
scroller.removeEventListener("scroll", onScroll);
|
|
135
|
+
window.removeEventListener("resize", onScroll);
|
|
136
|
+
};
|
|
137
|
+
}, [snap, items.length]);
|
|
138
|
+
const onFocus = (event, index) => {
|
|
139
|
+
if (!event.target.matches(":focus-visible")) return;
|
|
140
|
+
const row = rowRef.current;
|
|
141
|
+
const { travel, scroller } = geometry.current;
|
|
142
|
+
if (!scroller || !travel) return;
|
|
143
|
+
const x = Math.min(travel, row.children[index].offsetLeft - row.children[0].offsetLeft);
|
|
144
|
+
scrollTo(sectionStart() + x);
|
|
145
|
+
};
|
|
146
|
+
return /* @__PURE__ */ jsx(
|
|
147
|
+
"section",
|
|
148
|
+
{
|
|
149
|
+
ref: rootRef,
|
|
150
|
+
className: `bl-htrack ${className}`,
|
|
151
|
+
"aria-label": label,
|
|
152
|
+
style: {
|
|
153
|
+
"--bl-len": length == null ? stageHeight : `${length}px`,
|
|
154
|
+
"--bl-stage": stageHeight,
|
|
155
|
+
"--bl-item": `${itemWidth}px`,
|
|
156
|
+
"--bl-gap": `${gap}px`,
|
|
157
|
+
"--bl-pad": `${padding}px`,
|
|
158
|
+
"--bl-accent": accentColor,
|
|
159
|
+
"--bl-muted": mutedColor,
|
|
160
|
+
"--bl-track": trackColor,
|
|
161
|
+
"--bl-bar-radius": `${barRadius}px`,
|
|
162
|
+
"--bl-font": fontFamily,
|
|
163
|
+
"--bl-x": 0,
|
|
164
|
+
"--bl-p": 0,
|
|
165
|
+
...style
|
|
166
|
+
},
|
|
167
|
+
children: /* @__PURE__ */ jsxs("div", { ref: stageRef, className: "bl-htrack__stage", children: [
|
|
168
|
+
header && /* @__PURE__ */ jsx("div", { className: "bl-htrack__header", children: header }),
|
|
169
|
+
/* @__PURE__ */ jsx("div", { ref: rowRef, className: "bl-htrack__row", role: "list", children: items.map((child, index) => /* @__PURE__ */ jsx(
|
|
170
|
+
"div",
|
|
171
|
+
{
|
|
172
|
+
className: "bl-htrack__item",
|
|
173
|
+
role: "listitem",
|
|
174
|
+
tabIndex: 0,
|
|
175
|
+
"aria-label": `${index + 1} of ${items.length}`,
|
|
176
|
+
onFocus: (event) => onFocus(event, index),
|
|
177
|
+
children: child
|
|
178
|
+
},
|
|
179
|
+
child.key ?? index
|
|
180
|
+
)) }),
|
|
181
|
+
showProgress && items.length > 1 && /* @__PURE__ */ jsxs("div", { className: "bl-htrack__footer", "aria-hidden": "true", children: [
|
|
182
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
183
|
+
String(current + 1).padStart(2, "0"),
|
|
184
|
+
" / ",
|
|
185
|
+
String(items.length).padStart(2, "0")
|
|
186
|
+
] }),
|
|
187
|
+
/* @__PURE__ */ jsx("div", { className: "bl-htrack__bar", children: /* @__PURE__ */ jsx("div", { className: "bl-htrack__fill" }) })
|
|
188
|
+
] })
|
|
189
|
+
] })
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
HorizontalTrack as default
|
|
195
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface HotbarItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
/** Stack count shown in the corner. */
|
|
7
|
+
count?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface HotbarDockProps {
|
|
10
|
+
items?: HotbarItem[];
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onChange?: (id: string, item: HotbarItem | undefined) => void;
|
|
14
|
+
/** Size of the slot under the pointer. */
|
|
15
|
+
magnify?: number;
|
|
16
|
+
/** How far the swell reaches, in px. */
|
|
17
|
+
range?: number;
|
|
18
|
+
/** Number keys 1–9 pick a slot (not while typing). */
|
|
19
|
+
hotkeys?: boolean;
|
|
20
|
+
/** Scrolling over the bar cycles the selection. */
|
|
21
|
+
wheel?: boolean;
|
|
22
|
+
label?: string;
|
|
23
|
+
slotSize?: number;
|
|
24
|
+
gap?: number;
|
|
25
|
+
padding?: number;
|
|
26
|
+
radius?: number;
|
|
27
|
+
backgroundColor?: string;
|
|
28
|
+
slotColor?: string;
|
|
29
|
+
hoverColor?: string;
|
|
30
|
+
textColor?: string;
|
|
31
|
+
mutedColor?: string;
|
|
32
|
+
lineColor?: string;
|
|
33
|
+
selectColor?: string;
|
|
34
|
+
accentColor?: string;
|
|
35
|
+
tooltipColor?: string;
|
|
36
|
+
fontFamily?: string;
|
|
37
|
+
className?: string;
|
|
38
|
+
style?: CSSProperties;
|
|
39
|
+
}
|
|
40
|
+
export default function HotbarDock({ items, value, defaultValue, onChange, magnify, range, hotkeys, wheel, label, slotSize, gap, padding, radius, backgroundColor, slotColor, hoverColor, textColor, mutedColor, lineColor, selectColor, accentColor, tooltipColor, fontFamily, className, style }: HotbarDockProps): import("react").JSX.Element;
|