bits-lab 0.0.0-stage → 0.1.2
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 +57 -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 +58 -4
package/dist/Reveal.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
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-reveal";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-reveal { position: relative; }
|
|
7
|
+
.bl-reveal__part { display: block; transition: opacity var(--bl-dur) cubic-bezier(.2,.8,.2,1), transform var(--bl-dur) cubic-bezier(.2,.8,.2,1), clip-path var(--bl-dur) steps(var(--bl-steps)); transition-delay: calc(var(--bl-delay) + var(--i, 0) * var(--bl-stagger)); }
|
|
8
|
+
.bl-reveal:not([data-shown])[data-effect="fade"] .bl-reveal__part { opacity: 0; }
|
|
9
|
+
.bl-reveal:not([data-shown])[data-effect="rise"] .bl-reveal__part { opacity: 0; transform: translateY(var(--bl-distance)); }
|
|
10
|
+
.bl-reveal:not([data-shown])[data-effect="zoom"] .bl-reveal__part { opacity: 0; transform: scale(0.92); }
|
|
11
|
+
.bl-reveal:not([data-shown])[data-effect="wipe"] .bl-reveal__part { clip-path: inset(0 100% 0 0); }
|
|
12
|
+
.bl-reveal__cover { position: absolute; inset: 0; z-index: 1; display: grid; grid-template-columns: repeat(var(--bl-cols), 1fr); grid-template-rows: repeat(var(--bl-rows), 1fr); pointer-events: none; }
|
|
13
|
+
.bl-reveal__block { background: var(--bl-cover); transition: opacity 1ms linear; transition-delay: calc(var(--bl-delay) + var(--d) * var(--bl-dur)); }
|
|
14
|
+
.bl-reveal[data-shown] .bl-reveal__block { opacity: 0; }
|
|
15
|
+
@media (prefers-reduced-motion: reduce) { .bl-reveal .bl-reveal__part { opacity: 1 !important; transform: none !important; clip-path: none !important; transition: none !important; } .bl-reveal .bl-reveal__cover { display: none; } }
|
|
16
|
+
`;
|
|
17
|
+
function useStyles() {
|
|
18
|
+
useInsertionEffect(() => {
|
|
19
|
+
if (typeof document === "undefined") return;
|
|
20
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
21
|
+
style.textContent = CSS;
|
|
22
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
23
|
+
}, []);
|
|
24
|
+
}
|
|
25
|
+
const scatter = (i) => {
|
|
26
|
+
const x = Math.sin((i + 1) * 91.345) * 47453.13;
|
|
27
|
+
return x - Math.floor(x);
|
|
28
|
+
};
|
|
29
|
+
function Reveal({
|
|
30
|
+
children,
|
|
31
|
+
as: Tag = "div",
|
|
32
|
+
effect = "rise",
|
|
33
|
+
cascade = false,
|
|
34
|
+
trigger = "view",
|
|
35
|
+
once = true,
|
|
36
|
+
threshold = 0.2,
|
|
37
|
+
duration = 600,
|
|
38
|
+
delay = 0,
|
|
39
|
+
stagger = 90,
|
|
40
|
+
distance = 24,
|
|
41
|
+
steps = 8,
|
|
42
|
+
blocks = [8, 5],
|
|
43
|
+
coverColor = "#0b0b14",
|
|
44
|
+
onReveal,
|
|
45
|
+
className = "",
|
|
46
|
+
style
|
|
47
|
+
}) {
|
|
48
|
+
useStyles();
|
|
49
|
+
const rootRef = useRef(null);
|
|
50
|
+
const revealRef = useRef(onReveal);
|
|
51
|
+
revealRef.current = onReveal;
|
|
52
|
+
const [shown, setShown] = useState(false);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (trigger === "mount") {
|
|
55
|
+
const id = requestAnimationFrame(() => requestAnimationFrame(() => setShown(true)));
|
|
56
|
+
return () => cancelAnimationFrame(id);
|
|
57
|
+
}
|
|
58
|
+
const observer = new IntersectionObserver(
|
|
59
|
+
([entry]) => {
|
|
60
|
+
if (entry.isIntersecting) {
|
|
61
|
+
setShown(true);
|
|
62
|
+
if (once) observer.disconnect();
|
|
63
|
+
} else if (!once) setShown(false);
|
|
64
|
+
},
|
|
65
|
+
{ threshold }
|
|
66
|
+
);
|
|
67
|
+
observer.observe(rootRef.current);
|
|
68
|
+
return () => observer.disconnect();
|
|
69
|
+
}, [trigger, once, threshold]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (shown) revealRef.current?.();
|
|
72
|
+
}, [shown]);
|
|
73
|
+
const parts = cascade ? Children.toArray(children) : [children];
|
|
74
|
+
const [cols, rows] = blocks;
|
|
75
|
+
return /* @__PURE__ */ jsxs(
|
|
76
|
+
Tag,
|
|
77
|
+
{
|
|
78
|
+
ref: rootRef,
|
|
79
|
+
className: `bl-reveal ${className}`,
|
|
80
|
+
"data-effect": effect,
|
|
81
|
+
"data-shown": shown || void 0,
|
|
82
|
+
style: { "--bl-dur": `${duration}ms`, "--bl-delay": `${delay}ms`, "--bl-stagger": `${stagger}ms`, "--bl-distance": `${distance}px`, "--bl-steps": steps, "--bl-cols": cols, "--bl-rows": rows, "--bl-cover": coverColor, ...style },
|
|
83
|
+
children: [
|
|
84
|
+
parts.map((part, i) => /* @__PURE__ */ jsx("div", { className: "bl-reveal__part", style: { "--i": i }, children: part }, i)),
|
|
85
|
+
effect === "blocks" && /* @__PURE__ */ jsx("div", { className: "bl-reveal__cover", "aria-hidden": "true", children: Array.from({ length: cols * rows }, (_, i) => /* @__PURE__ */ jsx("span", { className: "bl-reveal__block", style: { "--d": scatter(i).toFixed(3) } }, i)) })
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
Reveal as default
|
|
92
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface Ring {
|
|
3
|
+
value: number;
|
|
4
|
+
/** Defaults to 100. */
|
|
5
|
+
max?: number;
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Overrides the color from `colors`. */
|
|
8
|
+
color?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RingProgressProps {
|
|
11
|
+
/** Outer ring first. Values clamp to 0–max. */
|
|
12
|
+
rings?: Ring[];
|
|
13
|
+
/** Diameter, in px. */
|
|
14
|
+
size?: number;
|
|
15
|
+
/** Ring width, in px. */
|
|
16
|
+
thickness?: number;
|
|
17
|
+
/** Space between rings, in px. */
|
|
18
|
+
gap?: number;
|
|
19
|
+
/** Fill animation length, in ms. */
|
|
20
|
+
duration?: number;
|
|
21
|
+
/** Delay between rings, in ms. */
|
|
22
|
+
stagger?: number;
|
|
23
|
+
/** Where rings start, in degrees (0 = top). */
|
|
24
|
+
startAngle?: number;
|
|
25
|
+
/** Lighter-to-full gradient of each ring's own hue. */
|
|
26
|
+
gradient?: boolean;
|
|
27
|
+
/** Defaults to on for two or more rings. */
|
|
28
|
+
showLegend?: boolean;
|
|
29
|
+
/** Centre caption while nothing is focused. */
|
|
30
|
+
centerLabel?: ReactNode;
|
|
31
|
+
/** Text in the centre and the legend; also read aloud, so it must be plain text. */
|
|
32
|
+
formatValue?: (ring: Ring) => string;
|
|
33
|
+
/** Ring colors in order (the default three are validated for a dark surface). */
|
|
34
|
+
colors?: string[];
|
|
35
|
+
/** Opacity of each ring's track (same hue). */
|
|
36
|
+
trackOpacity?: number;
|
|
37
|
+
textColor?: string;
|
|
38
|
+
mutedColor?: string;
|
|
39
|
+
hoverColor?: string;
|
|
40
|
+
focusColor?: string;
|
|
41
|
+
fontFamily?: string;
|
|
42
|
+
className?: string;
|
|
43
|
+
style?: CSSProperties;
|
|
44
|
+
}
|
|
45
|
+
export default function RingProgress({ rings, size, thickness, gap, duration, stagger, startAngle, gradient, showLegend, centerLabel, formatValue, colors, trackOpacity, textColor, mutedColor, hoverColor, focusColor, fontFamily, className, style }: RingProgressProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useInsertionEffect, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-ring-progress";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-ring { position: relative; display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 22px; max-width: 100%; color: var(--bl-ink); font-family: var(--bl-font); }
|
|
7
|
+
.bl-ring__figure { position: relative; flex: 0 0 auto; width: var(--bl-size); max-width: 100%; aspect-ratio: 1; }
|
|
8
|
+
.bl-ring__figure svg { display: block; width: 100%; height: 100%; overflow: visible; }
|
|
9
|
+
.bl-ring__arc { fill: none; stroke-linecap: round; transition: stroke-dashoffset var(--bl-dur) cubic-bezier(.2,.9,.25,1) var(--bl-delay), opacity 200ms; }
|
|
10
|
+
.bl-ring__track { fill: none; transition: opacity 200ms; }
|
|
11
|
+
/* A zero-length arc would still draw its round caps as a dot, so hide it. */
|
|
12
|
+
.bl-ring .bl-ring__arc[data-empty] { opacity: 0; }
|
|
13
|
+
.bl-ring__hit { fill: none; stroke: transparent; cursor: default; pointer-events: stroke; }
|
|
14
|
+
.bl-ring[data-focus] .bl-ring__layer:not([data-focused]) .bl-ring__arc, .bl-ring[data-focus] .bl-ring__layer:not([data-focused]) .bl-ring__track { opacity: 0.3; }
|
|
15
|
+
.bl-ring__center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
|
|
16
|
+
.bl-ring__value { font-size: var(--bl-value-size); font-weight: 700; line-height: 1.05; }
|
|
17
|
+
.bl-ring__label { margin-top: 4px; color: var(--bl-muted); font-size: 12px; }
|
|
18
|
+
.bl-ring__legend { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
|
|
19
|
+
.bl-ring__item { display: grid; grid-template-columns: 14px auto auto; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; outline: none; cursor: default; }
|
|
20
|
+
.bl-ring__item:hover, .bl-ring__item:focus-visible, .bl-ring__item[data-focused] { background: var(--bl-hover); }
|
|
21
|
+
.bl-ring__item:focus-visible { box-shadow: inset 0 0 0 2px var(--bl-focus); }
|
|
22
|
+
.bl-ring__key { width: 14px; height: 4px; border-radius: 2px; }
|
|
23
|
+
.bl-ring__name { color: var(--bl-muted); font-size: 13px; }
|
|
24
|
+
.bl-ring__num { justify-self: end; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
|
|
25
|
+
@media (prefers-reduced-motion: reduce) { .bl-ring__arc { transition: opacity 200ms; } }
|
|
26
|
+
`;
|
|
27
|
+
function useStyles() {
|
|
28
|
+
useInsertionEffect(() => {
|
|
29
|
+
if (typeof document === "undefined") return;
|
|
30
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
31
|
+
style.textContent = CSS;
|
|
32
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
35
|
+
const DEFAULT_COLORS = ["#3987e5", "#d95926", "#199e70"];
|
|
36
|
+
const percent = (ring) => Math.max(0, Math.min(1, ring.value / (ring.max || 100)));
|
|
37
|
+
const defaultFormat = (ring) => `${Math.round(percent(ring) * 100)}%`;
|
|
38
|
+
function RingProgress({
|
|
39
|
+
rings = [{ value: 72, label: "Progress" }],
|
|
40
|
+
size = 180,
|
|
41
|
+
thickness = 14,
|
|
42
|
+
gap = 6,
|
|
43
|
+
duration = 1100,
|
|
44
|
+
stagger = 120,
|
|
45
|
+
startAngle = 0,
|
|
46
|
+
gradient = true,
|
|
47
|
+
showLegend,
|
|
48
|
+
centerLabel,
|
|
49
|
+
formatValue = defaultFormat,
|
|
50
|
+
colors = DEFAULT_COLORS,
|
|
51
|
+
trackOpacity = 0.18,
|
|
52
|
+
textColor = "#f4f4f4",
|
|
53
|
+
mutedColor = "#94b0c2",
|
|
54
|
+
hoverColor = "rgba(255,255,255,0.06)",
|
|
55
|
+
focusColor = "#73eff7",
|
|
56
|
+
fontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
57
|
+
className = "",
|
|
58
|
+
style
|
|
59
|
+
}) {
|
|
60
|
+
useStyles();
|
|
61
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
62
|
+
const [drawn, setDrawn] = useState(false);
|
|
63
|
+
const [focus, setFocus] = useState(null);
|
|
64
|
+
const legend = showLegend ?? rings.length > 1;
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const timer = setTimeout(() => setDrawn(true), 30);
|
|
67
|
+
return () => clearTimeout(timer);
|
|
68
|
+
}, []);
|
|
69
|
+
const view = 100;
|
|
70
|
+
const center = view / 2;
|
|
71
|
+
const unit = view / size;
|
|
72
|
+
const stroke = thickness * unit;
|
|
73
|
+
const step = (thickness + gap) * unit;
|
|
74
|
+
const shown = focus ?? 0;
|
|
75
|
+
const primary = rings[shown];
|
|
76
|
+
const inner = size - 2 * rings.length * (thickness + gap) + 2 * gap;
|
|
77
|
+
const centerText = primary ? String(formatValue(primary)) : "";
|
|
78
|
+
const valueSize = Math.max(12, Math.min(Math.round(size * 0.17), Math.floor(inner * 0.78 / Math.max(2, centerText.length * 0.62))));
|
|
79
|
+
return /* @__PURE__ */ jsxs(
|
|
80
|
+
"div",
|
|
81
|
+
{
|
|
82
|
+
className: `bl-ring ${className}`,
|
|
83
|
+
"data-focus": focus !== null || void 0,
|
|
84
|
+
style: {
|
|
85
|
+
"--bl-size": `${size}px`,
|
|
86
|
+
"--bl-dur": `${duration}ms`,
|
|
87
|
+
"--bl-ink": textColor,
|
|
88
|
+
"--bl-muted": mutedColor,
|
|
89
|
+
"--bl-hover": hoverColor,
|
|
90
|
+
"--bl-focus": focusColor,
|
|
91
|
+
"--bl-font": fontFamily,
|
|
92
|
+
"--bl-value-size": `${valueSize}px`,
|
|
93
|
+
...style
|
|
94
|
+
},
|
|
95
|
+
children: [
|
|
96
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-ring__figure", children: [
|
|
97
|
+
/* @__PURE__ */ jsxs("svg", { viewBox: `0 0 ${view} ${view}`, "aria-hidden": "true", children: [
|
|
98
|
+
/* @__PURE__ */ jsx("defs", { children: rings.map((ring, i) => {
|
|
99
|
+
const c = ring.color ?? colors[i % colors.length];
|
|
100
|
+
return /* @__PURE__ */ jsxs("linearGradient", { id: `${uid}-g${i}`, x1: "0", y1: "0", x2: "1", y2: "1", children: [
|
|
101
|
+
/* @__PURE__ */ jsx("stop", { offset: "0", style: { stopColor: `color-mix(in srgb, ${c} 70%, white)` } }),
|
|
102
|
+
/* @__PURE__ */ jsx("stop", { offset: "1", style: { stopColor: c } })
|
|
103
|
+
] }, i);
|
|
104
|
+
}) }),
|
|
105
|
+
rings.map((ring, i) => {
|
|
106
|
+
const c = ring.color ?? colors[i % colors.length];
|
|
107
|
+
const r = center - stroke / 2 - i * step;
|
|
108
|
+
if (r <= stroke / 2) return null;
|
|
109
|
+
const circumference = 2 * Math.PI * r;
|
|
110
|
+
const fraction = drawn ? percent(ring) : 0;
|
|
111
|
+
const transform = `rotate(${startAngle - 90} ${center} ${center})`;
|
|
112
|
+
return /* @__PURE__ */ jsxs("g", { className: "bl-ring__layer", "data-focused": focus === i || void 0, onPointerEnter: () => setFocus(i), onPointerLeave: () => setFocus(null), children: [
|
|
113
|
+
/* @__PURE__ */ jsx("circle", { className: "bl-ring__track", cx: center, cy: center, r, stroke: c, strokeOpacity: trackOpacity, strokeWidth: stroke }),
|
|
114
|
+
/* @__PURE__ */ jsx(
|
|
115
|
+
"circle",
|
|
116
|
+
{
|
|
117
|
+
className: "bl-ring__arc",
|
|
118
|
+
cx: center,
|
|
119
|
+
cy: center,
|
|
120
|
+
r,
|
|
121
|
+
stroke: gradient ? `url(#${uid}-g${i})` : c,
|
|
122
|
+
strokeWidth: stroke,
|
|
123
|
+
strokeDasharray: circumference,
|
|
124
|
+
strokeDashoffset: circumference * (1 - fraction),
|
|
125
|
+
transform,
|
|
126
|
+
"data-empty": fraction === 0 || void 0,
|
|
127
|
+
style: { "--bl-delay": `${i * stagger}ms` }
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
/* @__PURE__ */ jsx("circle", { className: "bl-ring__hit", cx: center, cy: center, r, strokeWidth: step })
|
|
131
|
+
] }, i);
|
|
132
|
+
})
|
|
133
|
+
] }),
|
|
134
|
+
primary && /* @__PURE__ */ jsxs("div", { className: "bl-ring__center", children: [
|
|
135
|
+
/* @__PURE__ */ jsx("div", { className: "bl-ring__value", children: formatValue(primary) }),
|
|
136
|
+
/* @__PURE__ */ jsx("div", { className: "bl-ring__label", children: focus === null && centerLabel !== void 0 ? centerLabel : primary.label })
|
|
137
|
+
] })
|
|
138
|
+
] }),
|
|
139
|
+
legend ? /* @__PURE__ */ jsx("ul", { className: "bl-ring__legend", children: rings.map((ring, i) => /* @__PURE__ */ jsxs(
|
|
140
|
+
"li",
|
|
141
|
+
{
|
|
142
|
+
className: "bl-ring__item",
|
|
143
|
+
tabIndex: 0,
|
|
144
|
+
role: "meter",
|
|
145
|
+
"aria-label": ring.label ?? `Ring ${i + 1}`,
|
|
146
|
+
"aria-valuemin": 0,
|
|
147
|
+
"aria-valuemax": ring.max || 100,
|
|
148
|
+
"aria-valuenow": ring.value,
|
|
149
|
+
"aria-valuetext": formatValue(ring),
|
|
150
|
+
"data-focused": focus === i || void 0,
|
|
151
|
+
onPointerEnter: () => setFocus(i),
|
|
152
|
+
onPointerLeave: () => setFocus(null),
|
|
153
|
+
onFocus: () => setFocus(i),
|
|
154
|
+
onBlur: () => setFocus(null),
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ jsx("span", { className: "bl-ring__key", style: { background: ring.color ?? colors[i % colors.length] }, "aria-hidden": "true" }),
|
|
157
|
+
/* @__PURE__ */ jsx("span", { className: "bl-ring__name", children: ring.label ?? `Ring ${i + 1}` }),
|
|
158
|
+
/* @__PURE__ */ jsx("span", { className: "bl-ring__num", children: formatValue(ring) })
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
i
|
|
162
|
+
)) }) : primary && /* @__PURE__ */ jsx(
|
|
163
|
+
"span",
|
|
164
|
+
{
|
|
165
|
+
role: "meter",
|
|
166
|
+
"aria-label": primary.label ?? "Progress",
|
|
167
|
+
"aria-valuemin": 0,
|
|
168
|
+
"aria-valuemax": primary.max || 100,
|
|
169
|
+
"aria-valuenow": primary.value,
|
|
170
|
+
"aria-valuetext": formatValue(primary),
|
|
171
|
+
style: { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)" }
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
RingProgress as default
|
|
180
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface RollingNumberProps {
|
|
3
|
+
/** The number to show. Changes roll each digit to its new place. */
|
|
4
|
+
value?: number;
|
|
5
|
+
/** Start here and roll to `value` when the number scrolls into view. */
|
|
6
|
+
from?: number;
|
|
7
|
+
/** BCP 47 locale for formatting (defaults to the browser's). */
|
|
8
|
+
locale?: string | string[];
|
|
9
|
+
/** Any Intl.NumberFormat options: currency, percent, compact, fraction digits… */
|
|
10
|
+
format?: Intl.NumberFormatOptions;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
suffix?: string;
|
|
13
|
+
/** Roll length, in ms. */
|
|
14
|
+
duration?: number;
|
|
15
|
+
/** Delay added per digit from the left, in ms. */
|
|
16
|
+
stagger?: number;
|
|
17
|
+
/** With `from`, wait until visible before rolling. */
|
|
18
|
+
startOnView?: boolean;
|
|
19
|
+
/** Announce changes politely to screen readers. */
|
|
20
|
+
announce?: boolean;
|
|
21
|
+
/** Digit cell height, in em. */
|
|
22
|
+
lineHeight?: number;
|
|
23
|
+
/** Digit color (defaults to the inherited text color). */
|
|
24
|
+
color?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: CSSProperties;
|
|
27
|
+
}
|
|
28
|
+
export default function RollingNumber({ value, from, locale, format, prefix, suffix, duration, stagger, startOnView, announce, lineHeight, color, className, style }: RollingNumberProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useInsertionEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-rolling-number";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-rn { position: relative; display: inline-flex; align-items: baseline; color: var(--bl-ink); font-variant-numeric: tabular-nums; line-height: var(--bl-lh); white-space: nowrap; }
|
|
7
|
+
.bl-rn__col { position: relative; display: inline-block; height: calc(var(--bl-lh) * 1em); overflow: hidden; }
|
|
8
|
+
.bl-rn__strip { display: flex; flex-direction: column; transform: translateY(calc(var(--bl-digit) * -10%)); transition: transform var(--bl-dur) var(--bl-ease) var(--bl-delay); }
|
|
9
|
+
.bl-rn__strip > span { display: block; height: calc(var(--bl-lh) * 1em); text-align: center; }
|
|
10
|
+
.bl-rn__sym { display: inline-block; }
|
|
11
|
+
.bl-rn__col[data-enter], .bl-rn__sym[data-enter] { animation: bl-rn-in var(--bl-dur) var(--bl-ease); }
|
|
12
|
+
.bl-rn__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
13
|
+
@keyframes bl-rn-in { from { opacity: 0; transform: translateY(40%); } }
|
|
14
|
+
@media (prefers-reduced-motion: reduce) { .bl-rn__strip { transition: none; } .bl-rn__col[data-enter], .bl-rn__sym[data-enter] { animation: none; } }
|
|
15
|
+
`;
|
|
16
|
+
function useStyles() {
|
|
17
|
+
useInsertionEffect(() => {
|
|
18
|
+
if (typeof document === "undefined") return;
|
|
19
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
20
|
+
style.textContent = CSS;
|
|
21
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
22
|
+
}, []);
|
|
23
|
+
}
|
|
24
|
+
const DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
25
|
+
function tokenize(text) {
|
|
26
|
+
const chars = [...text];
|
|
27
|
+
let digitIndex = 0;
|
|
28
|
+
let symbolIndex = 0;
|
|
29
|
+
const tokens = [];
|
|
30
|
+
for (let i = chars.length - 1; i >= 0; i--) {
|
|
31
|
+
const char = chars[i];
|
|
32
|
+
if (char >= "0" && char <= "9") tokens.unshift({ key: `d${digitIndex++}`, digit: Number(char), char });
|
|
33
|
+
else tokens.unshift({ key: `s${symbolIndex++}-${char}`, char });
|
|
34
|
+
}
|
|
35
|
+
return tokens;
|
|
36
|
+
}
|
|
37
|
+
function RollingNumber({
|
|
38
|
+
value = 0,
|
|
39
|
+
from,
|
|
40
|
+
locale,
|
|
41
|
+
format,
|
|
42
|
+
prefix = "",
|
|
43
|
+
suffix = "",
|
|
44
|
+
duration = 900,
|
|
45
|
+
stagger = 40,
|
|
46
|
+
startOnView = true,
|
|
47
|
+
announce = false,
|
|
48
|
+
lineHeight = 1.1,
|
|
49
|
+
color,
|
|
50
|
+
className = "",
|
|
51
|
+
style
|
|
52
|
+
}) {
|
|
53
|
+
useStyles();
|
|
54
|
+
const ref = useRef(null);
|
|
55
|
+
const [shown, setShown] = useState(from ?? value);
|
|
56
|
+
const [started, setStarted] = useState(!startOnView || from === void 0);
|
|
57
|
+
const mounted = useRef(false);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (started) return void 0;
|
|
60
|
+
const node = ref.current;
|
|
61
|
+
if (!node || typeof IntersectionObserver === "undefined") {
|
|
62
|
+
setStarted(true);
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
const observer = new IntersectionObserver(([entry]) => entry.isIntersecting && setStarted(true), { threshold: 0.3 });
|
|
66
|
+
observer.observe(node);
|
|
67
|
+
return () => observer.disconnect();
|
|
68
|
+
}, [started]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!started) return void 0;
|
|
71
|
+
const timer = setTimeout(() => setShown(value), mounted.current ? 0 : 30);
|
|
72
|
+
mounted.current = true;
|
|
73
|
+
return () => clearTimeout(timer);
|
|
74
|
+
}, [value, started]);
|
|
75
|
+
const formatter = useMemo(() => new Intl.NumberFormat(locale, format), [locale, JSON.stringify(format)]);
|
|
76
|
+
const text = `${prefix}${formatter.format(shown)}${suffix}`;
|
|
77
|
+
const tokens = tokenize(text);
|
|
78
|
+
const known = useRef(/* @__PURE__ */ new Set());
|
|
79
|
+
const rendered = tokens.map((token) => {
|
|
80
|
+
const entering = mounted.current && !known.current.has(token.key);
|
|
81
|
+
return { ...token, entering };
|
|
82
|
+
});
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
known.current = new Set(tokens.map((token) => token.key));
|
|
85
|
+
});
|
|
86
|
+
let digitOrder = 0;
|
|
87
|
+
return /* @__PURE__ */ jsxs(
|
|
88
|
+
"span",
|
|
89
|
+
{
|
|
90
|
+
ref,
|
|
91
|
+
className: `bl-rn ${className}`,
|
|
92
|
+
style: { "--bl-lh": lineHeight, "--bl-dur": `${duration}ms`, "--bl-ease": "cubic-bezier(.2,.9,.25,1)", ...color ? { "--bl-ink": color } : { "--bl-ink": "currentColor" }, ...style },
|
|
93
|
+
children: [
|
|
94
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: { display: "inline-flex", alignItems: "baseline" }, children: rendered.map((token) => {
|
|
95
|
+
if (token.digit === void 0) {
|
|
96
|
+
return /* @__PURE__ */ jsx("span", { className: "bl-rn__sym", "data-enter": token.entering || void 0, children: token.char }, token.key);
|
|
97
|
+
}
|
|
98
|
+
const delay = digitOrder++ * stagger;
|
|
99
|
+
return /* @__PURE__ */ jsx("span", { className: "bl-rn__col", "data-enter": token.entering || void 0, children: /* @__PURE__ */ jsx("span", { className: "bl-rn__strip", style: { "--bl-digit": token.digit, "--bl-delay": `${delay}ms` }, children: DIGITS.map((d) => /* @__PURE__ */ jsx("span", { children: d }, d)) }) }, token.key);
|
|
100
|
+
}) }),
|
|
101
|
+
/* @__PURE__ */ jsx("span", { className: "bl-rn__sr", "aria-live": announce ? "polite" : void 0, children: `${prefix}${formatter.format(value)}${suffix}` })
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
RollingNumber as default
|
|
108
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface ScanScopeProps {
|
|
3
|
+
/** A rotating sweep over range rings, or a bar scanning down. */
|
|
4
|
+
mode?: 'radar' | 'line';
|
|
5
|
+
/** A count to scatter, or positions in 0–1 of the area. */
|
|
6
|
+
blips?: number | {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}[];
|
|
10
|
+
/** Seconds per sweep. */
|
|
11
|
+
period?: number;
|
|
12
|
+
/** Length of the fading wake (share of a turn, or of the height). */
|
|
13
|
+
trail?: number;
|
|
14
|
+
rings?: number;
|
|
15
|
+
gridSize?: number;
|
|
16
|
+
pixelSize?: number;
|
|
17
|
+
color?: string;
|
|
18
|
+
blipColor?: string;
|
|
19
|
+
gridColor?: string;
|
|
20
|
+
backgroundColor?: string;
|
|
21
|
+
className?: string;
|
|
22
|
+
style?: CSSProperties;
|
|
23
|
+
}
|
|
24
|
+
export default function ScanScope({ mode, blips, period, trail, rings, gridSize, pixelSize, color, blipColor, gridColor, backgroundColor, className, style }: ScanScopeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,164 @@
|
|
|
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 rgba = ([r, g, b], a) => `rgba(${r},${g},${b},${a})`;
|
|
9
|
+
function ScanScope({
|
|
10
|
+
mode = "radar",
|
|
11
|
+
blips = 9,
|
|
12
|
+
period = 4,
|
|
13
|
+
trail = 0.22,
|
|
14
|
+
rings = 4,
|
|
15
|
+
gridSize = 28,
|
|
16
|
+
pixelSize = 2,
|
|
17
|
+
color = "#38b764",
|
|
18
|
+
blipColor = "#ffcd75",
|
|
19
|
+
gridColor = "#262b44",
|
|
20
|
+
backgroundColor = "#0b0b14",
|
|
21
|
+
className = "",
|
|
22
|
+
style
|
|
23
|
+
}) {
|
|
24
|
+
const canvasRef = useRef(null);
|
|
25
|
+
const blipKey = Array.isArray(blips) ? blips.map((b) => `${b.x},${b.y}`).join(";") : String(blips);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const canvas = canvasRef.current;
|
|
28
|
+
const ctx = canvas.getContext("2d");
|
|
29
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
30
|
+
const beam = hexToRgb(color);
|
|
31
|
+
const dot = hexToRgb(blipColor);
|
|
32
|
+
const grid = hexToRgb(gridColor);
|
|
33
|
+
const points = (Array.isArray(blips) ? blips : Array.from({ length: blips }, (_, i) => ({ x: 0.15 + (Math.sin(i * 91.7) * 0.5 + 0.5) * 0.7, y: 0.15 + (Math.sin(i * 37.3 + 2) * 0.5 + 0.5) * 0.7 }))).map((p) => ({ ...p, litAt: -1e9 }));
|
|
34
|
+
let W = 0;
|
|
35
|
+
let H = 0;
|
|
36
|
+
let dpr = 1;
|
|
37
|
+
let t = 0;
|
|
38
|
+
let raf = 0;
|
|
39
|
+
let last = 0;
|
|
40
|
+
let visible = true;
|
|
41
|
+
let prevSweep = 0;
|
|
42
|
+
const fit = () => {
|
|
43
|
+
dpr = Math.min(2, window.devicePixelRatio || 1);
|
|
44
|
+
W = canvas.clientWidth;
|
|
45
|
+
H = canvas.clientHeight;
|
|
46
|
+
canvas.width = Math.round(W * dpr);
|
|
47
|
+
canvas.height = Math.round(H * dpr);
|
|
48
|
+
};
|
|
49
|
+
const snap = (v) => Math.round(v / pixelSize) * pixelSize;
|
|
50
|
+
const drawGrid = (cx, cy, radius) => {
|
|
51
|
+
ctx.fillStyle = rgba(grid, 1);
|
|
52
|
+
for (let x = snap(W % gridSize / 2); x < W; x += gridSize) for (let y = 0; y < H; y += pixelSize * 2) ctx.fillRect(x, y, 1, pixelSize);
|
|
53
|
+
for (let y = snap(H % gridSize / 2); y < H; y += gridSize) for (let x = 0; x < W; x += pixelSize * 2) ctx.fillRect(x, y, pixelSize, 1);
|
|
54
|
+
if (mode !== "radar") return;
|
|
55
|
+
ctx.fillStyle = rgba(beam, 0.35);
|
|
56
|
+
for (let r = 1; r <= rings; r++) {
|
|
57
|
+
const rr = radius * r / rings;
|
|
58
|
+
const steps = Math.ceil(rr * Math.PI * 2 / (pixelSize * 2));
|
|
59
|
+
for (let k = 0; k < steps; k++) {
|
|
60
|
+
const a = k / steps * Math.PI * 2;
|
|
61
|
+
ctx.fillRect(snap(cx + Math.cos(a) * rr), snap(cy + Math.sin(a) * rr), pixelSize, pixelSize);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const draw = (now) => {
|
|
66
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
67
|
+
ctx.fillStyle = backgroundColor;
|
|
68
|
+
ctx.fillRect(0, 0, W, H);
|
|
69
|
+
const cx = W / 2;
|
|
70
|
+
const cy = H / 2;
|
|
71
|
+
const radius = Math.min(W, H) * 0.46;
|
|
72
|
+
drawGrid(cx, cy, radius);
|
|
73
|
+
const turn = t / period % 1;
|
|
74
|
+
if (!reduced) {
|
|
75
|
+
if (mode === "radar") {
|
|
76
|
+
const slices = 28;
|
|
77
|
+
for (let s = 0; s < slices; s++) {
|
|
78
|
+
const a0 = (turn - trail * (s + 1) / slices) * Math.PI * 2;
|
|
79
|
+
const a1 = (turn - trail * s / slices) * Math.PI * 2;
|
|
80
|
+
ctx.fillStyle = rgba(beam, 0.35 * (1 - s / slices) ** 2);
|
|
81
|
+
ctx.beginPath();
|
|
82
|
+
ctx.moveTo(cx, cy);
|
|
83
|
+
ctx.arc(cx, cy, radius, a0, a1);
|
|
84
|
+
ctx.closePath();
|
|
85
|
+
ctx.fill();
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
const y = turn * H;
|
|
89
|
+
const glow = ctx.createLinearGradient(0, y - H * trail, 0, y);
|
|
90
|
+
glow.addColorStop(0, rgba(beam, 0));
|
|
91
|
+
glow.addColorStop(1, rgba(beam, 0.35));
|
|
92
|
+
ctx.fillStyle = glow;
|
|
93
|
+
ctx.fillRect(0, y - H * trail, W, H * trail);
|
|
94
|
+
ctx.fillStyle = rgba(beam, 0.9);
|
|
95
|
+
ctx.fillRect(0, snap(y), W, pixelSize);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
points.forEach((p) => {
|
|
99
|
+
const x = mode === "radar" ? cx + (p.x - 0.5) * radius * 2 : p.x * W;
|
|
100
|
+
const y = mode === "radar" ? cy + (p.y - 0.5) * radius * 2 : p.y * H;
|
|
101
|
+
if (mode === "radar" && Math.hypot(x - cx, y - cy) > radius) return;
|
|
102
|
+
const age = reduced ? 0 : (now - p.litAt) / (period * 1e3);
|
|
103
|
+
if (age >= 1) return;
|
|
104
|
+
const a = 1 - age;
|
|
105
|
+
const s = pixelSize * 3;
|
|
106
|
+
ctx.fillStyle = rgba(dot, a);
|
|
107
|
+
ctx.fillRect(snap(x) - s / 2, snap(y) - s / 2, s, s);
|
|
108
|
+
if (age < 0.25 && !reduced) {
|
|
109
|
+
const rr = 4 + age / 0.25 * 18;
|
|
110
|
+
ctx.fillStyle = rgba(dot, (1 - age / 0.25) * 0.8);
|
|
111
|
+
const steps = 16;
|
|
112
|
+
for (let k = 0; k < steps; k++) {
|
|
113
|
+
const ang = k / steps * Math.PI * 2;
|
|
114
|
+
ctx.fillRect(snap(x + Math.cos(ang) * rr), snap(y + Math.sin(ang) * rr), pixelSize, pixelSize);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const tick = (now) => {
|
|
120
|
+
t += Math.max(0, Math.min(0.05, (now - last) / 1e3));
|
|
121
|
+
last = now;
|
|
122
|
+
const turn = t / period % 1;
|
|
123
|
+
points.forEach((p) => {
|
|
124
|
+
let at;
|
|
125
|
+
if (mode === "radar") at = (Math.atan2(p.y - 0.5, p.x - 0.5) / (Math.PI * 2) + 1) % 1;
|
|
126
|
+
else at = p.y;
|
|
127
|
+
const crossed = prevSweep <= turn ? at > prevSweep && at <= turn : at > prevSweep || at <= turn;
|
|
128
|
+
if (crossed) p.litAt = now;
|
|
129
|
+
});
|
|
130
|
+
prevSweep = turn;
|
|
131
|
+
draw(now);
|
|
132
|
+
raf = visible && !document.hidden ? requestAnimationFrame(tick) : 0;
|
|
133
|
+
};
|
|
134
|
+
const start = () => {
|
|
135
|
+
if (raf || reduced || !visible || document.hidden) return;
|
|
136
|
+
last = performance.now();
|
|
137
|
+
raf = requestAnimationFrame(tick);
|
|
138
|
+
};
|
|
139
|
+
const resize = new ResizeObserver(() => {
|
|
140
|
+
fit();
|
|
141
|
+
draw(performance.now());
|
|
142
|
+
});
|
|
143
|
+
resize.observe(canvas);
|
|
144
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
145
|
+
visible = entry.isIntersecting;
|
|
146
|
+
start();
|
|
147
|
+
});
|
|
148
|
+
observer.observe(canvas);
|
|
149
|
+
document.addEventListener("visibilitychange", start);
|
|
150
|
+
fit();
|
|
151
|
+
draw(performance.now());
|
|
152
|
+
start();
|
|
153
|
+
return () => {
|
|
154
|
+
cancelAnimationFrame(raf);
|
|
155
|
+
resize.disconnect();
|
|
156
|
+
observer.disconnect();
|
|
157
|
+
document.removeEventListener("visibilitychange", start);
|
|
158
|
+
};
|
|
159
|
+
}, [mode, blipKey, period, trail, rings, gridSize, pixelSize, color, blipColor, gridColor, backgroundColor]);
|
|
160
|
+
return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, "aria-hidden": "true", className, style: { display: "block", width: "100%", height: "100%", background: backgroundColor, ...style } });
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
ScanScope as default
|
|
164
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface ScoreTickerProps {
|
|
3
|
+
/** The score; drums roll forward to it, decreases roll back. */
|
|
4
|
+
value?: number;
|
|
5
|
+
/** Zero-padded width; caps at all nines. */
|
|
6
|
+
digits?: number;
|
|
7
|
+
label?: string;
|
|
8
|
+
/** Shows HI, and beating it flashes NEW HIGH SCORE. */
|
|
9
|
+
highScore?: number;
|
|
10
|
+
/** Above 1, gain popups add "×N COMBO". */
|
|
11
|
+
combo?: number;
|
|
12
|
+
showPopups?: boolean;
|
|
13
|
+
/** Smallest gain that shakes the panel. */
|
|
14
|
+
shakeAt?: number;
|
|
15
|
+
/** Roll time in ms. */
|
|
16
|
+
duration?: number;
|
|
17
|
+
/** Digit size in px. */
|
|
18
|
+
size?: number;
|
|
19
|
+
textColor?: string;
|
|
20
|
+
dimColor?: string;
|
|
21
|
+
mutedColor?: string;
|
|
22
|
+
panelColor?: string;
|
|
23
|
+
edgeColor?: string;
|
|
24
|
+
drumColor?: string;
|
|
25
|
+
accentColor?: string;
|
|
26
|
+
comboColor?: string;
|
|
27
|
+
highColor?: string;
|
|
28
|
+
fontFamily?: string;
|
|
29
|
+
className?: string;
|
|
30
|
+
style?: CSSProperties;
|
|
31
|
+
}
|
|
32
|
+
export default function ScoreTicker({ value, digits, label, highScore, combo, showPopups, shakeAt, duration, size, textColor, dimColor, mutedColor, panelColor, edgeColor, drumColor, accentColor, comboColor, highColor, fontFamily, className, style }: ScoreTickerProps): import("react").JSX.Element;
|