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,126 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } 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 FOOT = [".XXX.", "XXXXX", "XXXXX", ".XXXX", ".XXX.", ".....", ".XXX.", ".XXX."];
|
|
9
|
+
function footSprite(rgb, cell) {
|
|
10
|
+
const c = document.createElement("canvas");
|
|
11
|
+
c.width = 5 * cell;
|
|
12
|
+
c.height = 8 * cell;
|
|
13
|
+
const g = c.getContext("2d");
|
|
14
|
+
g.fillStyle = `rgb(${rgb.join(",")})`;
|
|
15
|
+
FOOT.forEach((row, y) => [...row].forEach((ch, x) => ch === "X" && g.fillRect(x * cell, y * cell, cell, cell)));
|
|
16
|
+
return c;
|
|
17
|
+
}
|
|
18
|
+
function Footprints({
|
|
19
|
+
children,
|
|
20
|
+
stamps = "feet",
|
|
21
|
+
stride = 34,
|
|
22
|
+
size = 22,
|
|
23
|
+
life = 1600,
|
|
24
|
+
spread = 9,
|
|
25
|
+
jitter = 8,
|
|
26
|
+
max = 60,
|
|
27
|
+
color = "#94b0c2",
|
|
28
|
+
className = "",
|
|
29
|
+
style
|
|
30
|
+
}) {
|
|
31
|
+
const rootRef = useRef(null);
|
|
32
|
+
const canvasRef = useRef(null);
|
|
33
|
+
const stampKey = Array.isArray(stamps) ? stamps.join("|") : stamps;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const root = rootRef.current;
|
|
36
|
+
const canvas = canvasRef.current;
|
|
37
|
+
const ctx = canvas.getContext("2d");
|
|
38
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
39
|
+
const feet = stampKey === "feet";
|
|
40
|
+
const sprites = feet ? [footSprite(hexToRgb(color), 4)] : stampKey.split("|").map((src) => Object.assign(new Image(), { src }));
|
|
41
|
+
const prints = [];
|
|
42
|
+
let W = 0;
|
|
43
|
+
let H = 0;
|
|
44
|
+
let dpr = 1;
|
|
45
|
+
let last = null;
|
|
46
|
+
let count = 0;
|
|
47
|
+
let raf = 0;
|
|
48
|
+
const fit = () => {
|
|
49
|
+
dpr = Math.min(2, window.devicePixelRatio || 1);
|
|
50
|
+
W = root.clientWidth;
|
|
51
|
+
H = root.clientHeight;
|
|
52
|
+
canvas.width = Math.round(W * dpr);
|
|
53
|
+
canvas.height = Math.round(H * dpr);
|
|
54
|
+
};
|
|
55
|
+
const tick = (now) => {
|
|
56
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
57
|
+
ctx.clearRect(0, 0, W, H);
|
|
58
|
+
ctx.imageSmoothingEnabled = false;
|
|
59
|
+
for (let i = prints.length - 1; i >= 0; i--) {
|
|
60
|
+
const p = prints[i];
|
|
61
|
+
const age = (now - p.at) / life;
|
|
62
|
+
if (age >= 1) {
|
|
63
|
+
prints.splice(i, 1);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const pop = reduced ? 1 : age < 0.12 ? 0.6 + age / 0.12 * 0.55 : 1.15 - Math.min(0.15, (age - 0.12) * 0.6);
|
|
67
|
+
const scale = pop * (1 - age * 0.35);
|
|
68
|
+
const img = p.sprite;
|
|
69
|
+
if (!img.width) continue;
|
|
70
|
+
const w = size * scale;
|
|
71
|
+
const h = img.height / img.width * w;
|
|
72
|
+
ctx.save();
|
|
73
|
+
ctx.globalAlpha = Math.min(1, (1 - age) * 1.4);
|
|
74
|
+
ctx.translate(p.x, p.y);
|
|
75
|
+
ctx.rotate(p.angle);
|
|
76
|
+
ctx.drawImage(img, -w / 2, -h / 2, w, h);
|
|
77
|
+
ctx.restore();
|
|
78
|
+
}
|
|
79
|
+
raf = prints.length ? requestAnimationFrame(tick) : 0;
|
|
80
|
+
};
|
|
81
|
+
const onMove = (event) => {
|
|
82
|
+
const r = root.getBoundingClientRect();
|
|
83
|
+
const x = event.clientX - r.left;
|
|
84
|
+
const y = event.clientY - r.top;
|
|
85
|
+
if (!last) {
|
|
86
|
+
last = { x, y };
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const dx = x - last.x;
|
|
90
|
+
const dy = y - last.y;
|
|
91
|
+
const d = Math.hypot(dx, dy);
|
|
92
|
+
if (d < stride) return;
|
|
93
|
+
const heading = Math.atan2(dy, dx);
|
|
94
|
+
const side = feet ? count % 2 ? 1 : -1 : 0;
|
|
95
|
+
const nx = -Math.sin(heading) * spread * side;
|
|
96
|
+
const ny = Math.cos(heading) * spread * side;
|
|
97
|
+
const turn = feet ? heading + Math.PI / 2 : (Math.random() - 0.5) * jitter * Math.PI / 180;
|
|
98
|
+
prints.push({ x: x + nx, y: y + ny, angle: turn, at: performance.now(), sprite: sprites[count % sprites.length] });
|
|
99
|
+
if (prints.length > max) prints.shift();
|
|
100
|
+
count += 1;
|
|
101
|
+
last = { x, y };
|
|
102
|
+
if (!raf) raf = requestAnimationFrame(tick);
|
|
103
|
+
};
|
|
104
|
+
const onLeave = () => {
|
|
105
|
+
last = null;
|
|
106
|
+
};
|
|
107
|
+
fit();
|
|
108
|
+
const resize = new ResizeObserver(fit);
|
|
109
|
+
resize.observe(root);
|
|
110
|
+
root.addEventListener("pointermove", onMove, { passive: true });
|
|
111
|
+
root.addEventListener("pointerleave", onLeave);
|
|
112
|
+
return () => {
|
|
113
|
+
cancelAnimationFrame(raf);
|
|
114
|
+
resize.disconnect();
|
|
115
|
+
root.removeEventListener("pointermove", onMove);
|
|
116
|
+
root.removeEventListener("pointerleave", onLeave);
|
|
117
|
+
};
|
|
118
|
+
}, [stampKey, stride, size, life, spread, jitter, max, color]);
|
|
119
|
+
return /* @__PURE__ */ jsxs("div", { ref: rootRef, className, style: { position: "relative", touchAction: "pan-y", ...style }, children: [
|
|
120
|
+
children,
|
|
121
|
+
/* @__PURE__ */ jsx("canvas", { ref: canvasRef, "aria-hidden": "true", style: { position: "absolute", inset: 0, width: "100%", height: "100%", pointerEvents: "none" } })
|
|
122
|
+
] });
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
Footprints as default
|
|
126
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface FunnelStage {
|
|
3
|
+
label: string;
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export interface FunnelFlowProps {
|
|
7
|
+
/** Top of the funnel first; bar heights scale to the first stage. */
|
|
8
|
+
stages?: FunnelStage[];
|
|
9
|
+
height?: number;
|
|
10
|
+
barWidth?: number;
|
|
11
|
+
particles?: boolean;
|
|
12
|
+
/** Dots per second entering the first band. */
|
|
13
|
+
rate?: number;
|
|
14
|
+
particleSize?: number;
|
|
15
|
+
/** Number and percent formatting. */
|
|
16
|
+
locale?: string;
|
|
17
|
+
/** Accessible name and table caption. */
|
|
18
|
+
label?: string;
|
|
19
|
+
barColor?: string;
|
|
20
|
+
activeColor?: string;
|
|
21
|
+
bandColor?: string;
|
|
22
|
+
bandActiveColor?: string;
|
|
23
|
+
particleColor?: string;
|
|
24
|
+
textColor?: string;
|
|
25
|
+
mutedColor?: string;
|
|
26
|
+
chipColor?: string;
|
|
27
|
+
tooltipColor?: string;
|
|
28
|
+
lineColor?: string;
|
|
29
|
+
accentColor?: string;
|
|
30
|
+
fontFamily?: string;
|
|
31
|
+
className?: string;
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
}
|
|
34
|
+
export default function FunnelFlow({ stages, height, barWidth, particles, rate, particleSize, locale, label, barColor, activeColor, bandColor, bandActiveColor, particleColor, textColor, mutedColor, chipColor, tooltipColor, lineColor, accentColor, fontFamily, className, style }: FunnelFlowProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,267 @@
|
|
|
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-funnel-flow";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-funnel { position: relative; width: 100%; font-family: var(--bl-font); color: var(--bl-ink); }
|
|
7
|
+
.bl-funnel:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 4px; border-radius: 8px; }
|
|
8
|
+
.bl-funnel__svg { display: block; width: 100%; overflow: visible; }
|
|
9
|
+
.bl-funnel__bar { fill: var(--bl-bar); transition: fill 150ms; }
|
|
10
|
+
.bl-funnel__band { fill: var(--bl-band); transition: fill 150ms; }
|
|
11
|
+
.bl-funnel__stage[data-active] .bl-funnel__bar { fill: var(--bl-bar-active); }
|
|
12
|
+
.bl-funnel__stage[data-active] + .bl-funnel__band, .bl-funnel__band[data-active] { fill: var(--bl-band-active); }
|
|
13
|
+
.bl-funnel__hit { fill: transparent; cursor: default; }
|
|
14
|
+
.bl-funnel__label { fill: var(--bl-muted); font-size: 12px; }
|
|
15
|
+
.bl-funnel__value { fill: var(--bl-ink); font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
|
|
16
|
+
.bl-funnel__rate { fill: var(--bl-ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
17
|
+
.bl-funnel__chip { fill: var(--bl-chip); }
|
|
18
|
+
.bl-funnel__dot { fill: var(--bl-particle); }
|
|
19
|
+
.bl-funnel__tip { position: absolute; z-index: 2; top: 0; left: 0; min-width: 140px; padding: 8px 10px; border-radius: 8px; background: var(--bl-tip); color: var(--bl-ink); font-size: 13px; line-height: 1.45; box-shadow: 0 0 0 1px var(--bl-line), 0 10px 24px -10px rgba(0,0,0,0.8); pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); }
|
|
20
|
+
.bl-funnel__tip strong { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
|
|
21
|
+
.bl-funnel__tip span { color: var(--bl-muted); }
|
|
22
|
+
.bl-funnel__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
23
|
+
`;
|
|
24
|
+
function useStyles() {
|
|
25
|
+
useInsertionEffect(() => {
|
|
26
|
+
if (typeof document === "undefined") return;
|
|
27
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
28
|
+
style.textContent = CSS;
|
|
29
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
30
|
+
}, []);
|
|
31
|
+
}
|
|
32
|
+
function FunnelFlow({
|
|
33
|
+
stages = [],
|
|
34
|
+
height = 280,
|
|
35
|
+
barWidth = 18,
|
|
36
|
+
particles = true,
|
|
37
|
+
rate = 40,
|
|
38
|
+
particleSize = 3,
|
|
39
|
+
locale = "en-US",
|
|
40
|
+
label = "Conversion funnel",
|
|
41
|
+
barColor = "#3b5dc9",
|
|
42
|
+
activeColor = "#73eff7",
|
|
43
|
+
bandColor = "rgba(59,93,201,0.22)",
|
|
44
|
+
bandActiveColor = "rgba(115,239,247,0.22)",
|
|
45
|
+
particleColor = "#a5c8ff",
|
|
46
|
+
textColor = "#f4f4f4",
|
|
47
|
+
mutedColor = "#94b0c2",
|
|
48
|
+
chipColor = "#1a1c2c",
|
|
49
|
+
tooltipColor = "#262b44",
|
|
50
|
+
lineColor = "#333c57",
|
|
51
|
+
accentColor = "#73eff7",
|
|
52
|
+
fontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
53
|
+
className = "",
|
|
54
|
+
style
|
|
55
|
+
}) {
|
|
56
|
+
useStyles();
|
|
57
|
+
const rootRef = useRef(null);
|
|
58
|
+
const dotsRef = useRef(null);
|
|
59
|
+
const [width, setWidth] = useState(640);
|
|
60
|
+
const [active, setActive] = useState(-1);
|
|
61
|
+
const count = new Intl.NumberFormat(locale);
|
|
62
|
+
const pct = new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 1 });
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
const root = rootRef.current;
|
|
65
|
+
const measure = () => setWidth(Math.max(240, root.clientWidth));
|
|
66
|
+
measure();
|
|
67
|
+
const resize = new ResizeObserver(measure);
|
|
68
|
+
resize.observe(root);
|
|
69
|
+
return () => resize.disconnect();
|
|
70
|
+
}, []);
|
|
71
|
+
const top = 46;
|
|
72
|
+
const plot = height - top - 8;
|
|
73
|
+
const mid = top + plot / 2;
|
|
74
|
+
const max = Math.max(1, ...stages.map((s) => s.value));
|
|
75
|
+
const n = stages.length;
|
|
76
|
+
const pad = barWidth / 2 + 4;
|
|
77
|
+
const step = n > 1 ? (width - pad * 2) / (n - 1) : 0;
|
|
78
|
+
const geo = stages.map((s, i) => {
|
|
79
|
+
const h = Math.max(2, s.value / max * plot);
|
|
80
|
+
return { x: n > 1 ? pad + i * step : width / 2, h, y0: mid - h / 2, y1: mid + h / 2 };
|
|
81
|
+
});
|
|
82
|
+
const conv = (i) => stages[i].value ? stages[i + 1].value / stages[i].value : 0;
|
|
83
|
+
const geoRef = useRef(geo);
|
|
84
|
+
geoRef.current = geo;
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
const layer = dotsRef.current;
|
|
87
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
88
|
+
if (!particles || reduced || n < 2 || !layer) return void 0;
|
|
89
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
90
|
+
const live = [];
|
|
91
|
+
let visible = true;
|
|
92
|
+
let raf = 0;
|
|
93
|
+
let last = 0;
|
|
94
|
+
let carry = 0;
|
|
95
|
+
const speed = 0.55;
|
|
96
|
+
const spawn = () => {
|
|
97
|
+
const node = document.createElementNS(ns, "circle");
|
|
98
|
+
node.setAttribute("r", String(particleSize));
|
|
99
|
+
node.setAttribute("class", "bl-funnel__dot");
|
|
100
|
+
layer.appendChild(node);
|
|
101
|
+
live.push({ node, band: 0, t: 0, lane: Math.random() - 0.5, drop: null });
|
|
102
|
+
};
|
|
103
|
+
const decide = (p) => {
|
|
104
|
+
p.drop = Math.random() > conv(p.band) ? { at: 0.25 + Math.random() * 0.5, vy: 0, dy: 0 } : null;
|
|
105
|
+
};
|
|
106
|
+
const tick = (now) => {
|
|
107
|
+
const dt = Math.max(0, Math.min(0.05, (now - last) / 1e3));
|
|
108
|
+
last = now;
|
|
109
|
+
carry += rate * dt;
|
|
110
|
+
while (carry >= 1) {
|
|
111
|
+
carry -= 1;
|
|
112
|
+
spawn();
|
|
113
|
+
decide(live[live.length - 1]);
|
|
114
|
+
}
|
|
115
|
+
const g = geoRef.current;
|
|
116
|
+
for (let i = live.length - 1; i >= 0; i--) {
|
|
117
|
+
const p = live[i];
|
|
118
|
+
p.t += speed * dt * (p.drop && p.t > p.drop.at ? 0.4 : 1);
|
|
119
|
+
if (p.t >= 1 && !(p.drop && p.t > p.drop.at)) {
|
|
120
|
+
p.band += 1;
|
|
121
|
+
p.t -= 1;
|
|
122
|
+
if (p.band >= n - 1) {
|
|
123
|
+
p.node.remove();
|
|
124
|
+
live.splice(i, 1);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
decide(p);
|
|
128
|
+
}
|
|
129
|
+
const a = g[p.band];
|
|
130
|
+
const b = g[p.band + 1];
|
|
131
|
+
const e = p.t * p.t * (3 - 2 * p.t);
|
|
132
|
+
const x = a.x + (b.x - a.x) * Math.min(1, p.t);
|
|
133
|
+
const halfH = (a.h + (b.h - a.h) * e) / 2;
|
|
134
|
+
let y = mid + p.lane * halfH * 1.8 * 0.95;
|
|
135
|
+
let opacity = 0.9;
|
|
136
|
+
if (p.drop && p.t > p.drop.at) {
|
|
137
|
+
p.drop.vy += 520 * dt;
|
|
138
|
+
p.drop.dy += p.drop.vy * dt;
|
|
139
|
+
y += p.drop.dy;
|
|
140
|
+
opacity = Math.max(0, 0.9 - p.drop.dy / 90);
|
|
141
|
+
if (opacity <= 0) {
|
|
142
|
+
p.node.remove();
|
|
143
|
+
live.splice(i, 1);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
p.node.setAttribute("cx", x.toFixed(1));
|
|
148
|
+
p.node.setAttribute("cy", y.toFixed(1));
|
|
149
|
+
p.node.setAttribute("opacity", opacity.toFixed(2));
|
|
150
|
+
}
|
|
151
|
+
raf = requestAnimationFrame(tick);
|
|
152
|
+
};
|
|
153
|
+
const start = () => {
|
|
154
|
+
if (raf || !visible || document.hidden) return;
|
|
155
|
+
last = performance.now();
|
|
156
|
+
raf = requestAnimationFrame(tick);
|
|
157
|
+
};
|
|
158
|
+
const stop = () => {
|
|
159
|
+
cancelAnimationFrame(raf);
|
|
160
|
+
raf = 0;
|
|
161
|
+
};
|
|
162
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
163
|
+
visible = entry.isIntersecting;
|
|
164
|
+
if (visible) start();
|
|
165
|
+
else stop();
|
|
166
|
+
});
|
|
167
|
+
observer.observe(layer.ownerSVGElement);
|
|
168
|
+
const onVisibility = () => document.hidden ? stop() : start();
|
|
169
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
170
|
+
start();
|
|
171
|
+
return () => {
|
|
172
|
+
stop();
|
|
173
|
+
observer.disconnect();
|
|
174
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
175
|
+
live.forEach((p) => p.node.remove());
|
|
176
|
+
};
|
|
177
|
+
}, [particles, rate, particleSize, n, stages.map((s) => s.value).join(), height, width]);
|
|
178
|
+
const onKey = (event) => {
|
|
179
|
+
if (!n) return;
|
|
180
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
setActive((a) => Math.min(n - 1, a + 1));
|
|
183
|
+
} else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
setActive((a) => Math.max(0, a < 0 ? 0 : a - 1));
|
|
186
|
+
} else if (event.key === "Home") setActive(0);
|
|
187
|
+
else if (event.key === "End") setActive(n - 1);
|
|
188
|
+
else if (event.key === "Escape") setActive(-1);
|
|
189
|
+
};
|
|
190
|
+
const describe = (i) => `${stages[i].label}: ${count.format(stages[i].value)}${i ? `, ${pct.format(conv(i - 1))} of ${stages[i - 1].label}, ${pct.format(stages[0].value ? stages[i].value / stages[0].value : 0)} of ${stages[0].label}` : ""}`;
|
|
191
|
+
const summary = n > 1 ? `${label}. ${n} stages from ${count.format(stages[0].value)} ${stages[0].label} to ${count.format(stages[n - 1].value)} ${stages[n - 1].label}, ${pct.format(stages[0].value ? stages[n - 1].value / stages[0].value : 0)} overall.` : label;
|
|
192
|
+
const tip = active >= 0 ? geo[active] : null;
|
|
193
|
+
return /* @__PURE__ */ jsxs(
|
|
194
|
+
"div",
|
|
195
|
+
{
|
|
196
|
+
ref: rootRef,
|
|
197
|
+
className: `bl-funnel ${className}`,
|
|
198
|
+
tabIndex: 0,
|
|
199
|
+
role: "group",
|
|
200
|
+
"aria-label": `${summary} Use the arrow keys to read each stage.`,
|
|
201
|
+
onKeyDown: onKey,
|
|
202
|
+
onBlur: () => setActive(-1),
|
|
203
|
+
style: { "--bl-bar": barColor, "--bl-bar-active": activeColor, "--bl-band": bandColor, "--bl-band-active": bandActiveColor, "--bl-particle": particleColor, "--bl-ink": textColor, "--bl-muted": mutedColor, "--bl-chip": chipColor, "--bl-tip": tooltipColor, "--bl-line": lineColor, "--bl-accent": accentColor, "--bl-font": fontFamily, ...style },
|
|
204
|
+
children: [
|
|
205
|
+
/* @__PURE__ */ jsxs("svg", { className: "bl-funnel__svg", width, height, viewBox: `0 0 ${width} ${height}`, "aria-hidden": "true", onPointerLeave: () => setActive(-1), children: [
|
|
206
|
+
geo.map((g, i) => /* @__PURE__ */ jsxs("g", { children: [
|
|
207
|
+
/* @__PURE__ */ jsxs("g", { className: "bl-funnel__stage", "data-active": active === i || void 0, onPointerEnter: () => setActive(i), children: [
|
|
208
|
+
/* @__PURE__ */ jsx("rect", { className: "bl-funnel__hit", x: g.x - Math.max(barWidth, step / 2) / 2, y: 0, width: Math.max(barWidth, step / 2), height }),
|
|
209
|
+
/* @__PURE__ */ jsx("rect", { className: "bl-funnel__bar", x: g.x - barWidth / 2, y: g.y0, width: barWidth, height: g.h, rx: 4 })
|
|
210
|
+
] }),
|
|
211
|
+
i < n - 1 && /* @__PURE__ */ jsx(
|
|
212
|
+
"path",
|
|
213
|
+
{
|
|
214
|
+
className: "bl-funnel__band",
|
|
215
|
+
"data-active": active === i + 1 || void 0,
|
|
216
|
+
d: `M${g.x + barWidth / 2} ${g.y0} C${(g.x + geo[i + 1].x) / 2} ${g.y0} ${(g.x + geo[i + 1].x) / 2} ${geo[i + 1].y0} ${geo[i + 1].x - barWidth / 2} ${geo[i + 1].y0} L${geo[i + 1].x - barWidth / 2} ${geo[i + 1].y1} C${(g.x + geo[i + 1].x) / 2} ${geo[i + 1].y1} ${(g.x + geo[i + 1].x) / 2} ${g.y1} ${g.x + barWidth / 2} ${g.y1}Z`
|
|
217
|
+
}
|
|
218
|
+
)
|
|
219
|
+
] }, `${i}-${stages[i].label}`)),
|
|
220
|
+
/* @__PURE__ */ jsx("g", { ref: dotsRef }),
|
|
221
|
+
geo.map((g, i) => {
|
|
222
|
+
const anchor = n > 1 && i === 0 ? "start" : n > 1 && i === n - 1 ? "end" : "middle";
|
|
223
|
+
const tx = anchor === "start" ? g.x - barWidth / 2 : anchor === "end" ? g.x + barWidth / 2 : g.x;
|
|
224
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
225
|
+
/* @__PURE__ */ jsx("text", { className: "bl-funnel__label", x: tx, y: 14, textAnchor: anchor, children: stages[i].label }),
|
|
226
|
+
/* @__PURE__ */ jsx("text", { className: "bl-funnel__value", x: tx, y: 34, textAnchor: anchor, children: count.format(stages[i].value) })
|
|
227
|
+
] }, `label-${i}`);
|
|
228
|
+
}),
|
|
229
|
+
geo.slice(0, -1).map((g, i) => {
|
|
230
|
+
const cx = (g.x + geo[i + 1].x) / 2;
|
|
231
|
+
return /* @__PURE__ */ jsxs("g", { children: [
|
|
232
|
+
/* @__PURE__ */ jsx("rect", { className: "bl-funnel__chip", x: cx - 26, y: mid - 11, width: 52, height: 22, rx: 11 }),
|
|
233
|
+
/* @__PURE__ */ jsx("text", { className: "bl-funnel__rate", x: cx, y: mid + 4, textAnchor: "middle", children: pct.format(conv(i)) })
|
|
234
|
+
] }, `rate-${i}`);
|
|
235
|
+
})
|
|
236
|
+
] }),
|
|
237
|
+
tip && /* @__PURE__ */ jsxs("div", { className: "bl-funnel__tip", style: { left: Math.min(width - 70, Math.max(70, tip.x)), top: Math.max(56, tip.y0) }, children: [
|
|
238
|
+
/* @__PURE__ */ jsx("span", { children: stages[active].label }),
|
|
239
|
+
/* @__PURE__ */ jsx("strong", { children: count.format(stages[active].value) }),
|
|
240
|
+
active > 0 && /* @__PURE__ */ jsxs("span", { children: [
|
|
241
|
+
pct.format(conv(active - 1)),
|
|
242
|
+
" of previous \xB7 ",
|
|
243
|
+
pct.format(stages[0].value ? stages[active].value / stages[0].value : 0),
|
|
244
|
+
" of total"
|
|
245
|
+
] })
|
|
246
|
+
] }),
|
|
247
|
+
/* @__PURE__ */ jsx("span", { className: "bl-funnel__sr", "aria-live": "polite", children: active >= 0 ? describe(active) : "" }),
|
|
248
|
+
/* @__PURE__ */ jsxs("table", { className: "bl-funnel__sr", children: [
|
|
249
|
+
/* @__PURE__ */ jsx("caption", { children: label }),
|
|
250
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
251
|
+
/* @__PURE__ */ jsx("th", { scope: "col", children: "Stage" }),
|
|
252
|
+
/* @__PURE__ */ jsx("th", { scope: "col", children: "Count" }),
|
|
253
|
+
/* @__PURE__ */ jsx("th", { scope: "col", children: "From previous" })
|
|
254
|
+
] }) }),
|
|
255
|
+
/* @__PURE__ */ jsx("tbody", { children: stages.map((s, i) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
256
|
+
/* @__PURE__ */ jsx("th", { scope: "row", children: s.label }),
|
|
257
|
+
/* @__PURE__ */ jsx("td", { children: count.format(s.value) }),
|
|
258
|
+
/* @__PURE__ */ jsx("td", { children: i ? pct.format(conv(i - 1)) : "-" })
|
|
259
|
+
] }, `${i}-${s.label}`)) })
|
|
260
|
+
] })
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
export {
|
|
266
|
+
FunnelFlow as default
|
|
267
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export interface GameOverStat {
|
|
3
|
+
label: ReactNode;
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export interface GameOverProps {
|
|
7
|
+
title?: string;
|
|
8
|
+
subtitle?: ReactNode;
|
|
9
|
+
/** Rows that tally up one at a time. */
|
|
10
|
+
stats?: GameOverStat[];
|
|
11
|
+
totalLabel?: string;
|
|
12
|
+
/** Defaults to the sum of the stat values. */
|
|
13
|
+
total?: number;
|
|
14
|
+
/** CONTINUE? seconds; 0 turns the countdown off. */
|
|
15
|
+
countdown?: number;
|
|
16
|
+
continueLabel?: string;
|
|
17
|
+
quitLabel?: string;
|
|
18
|
+
/** Shown when the countdown reaches zero. */
|
|
19
|
+
finalMessage?: string;
|
|
20
|
+
onContinue?: () => void;
|
|
21
|
+
onQuit?: () => void;
|
|
22
|
+
onTimeout?: () => void;
|
|
23
|
+
/** Tally time per row in ms. */
|
|
24
|
+
tallyDuration?: number;
|
|
25
|
+
/** Fixed full-screen dialog (Esc quits) instead of filling the parent. */
|
|
26
|
+
fixed?: boolean;
|
|
27
|
+
/** Focus Continue once it appears; defaults to fixed. */
|
|
28
|
+
autoFocus?: boolean;
|
|
29
|
+
/** Change to play it again. */
|
|
30
|
+
replayKey?: string | number;
|
|
31
|
+
minHeight?: number;
|
|
32
|
+
titleSize?: number;
|
|
33
|
+
backgroundColor?: string;
|
|
34
|
+
titleColor?: string;
|
|
35
|
+
textColor?: string;
|
|
36
|
+
mutedColor?: string;
|
|
37
|
+
accentColor?: string;
|
|
38
|
+
lineColor?: string;
|
|
39
|
+
buttonColor?: string;
|
|
40
|
+
buttonTextColor?: string;
|
|
41
|
+
shadowColor?: string;
|
|
42
|
+
fontFamily?: string;
|
|
43
|
+
className?: string;
|
|
44
|
+
style?: CSSProperties;
|
|
45
|
+
}
|
|
46
|
+
export default function GameOver({ title, subtitle, stats, totalLabel, total, countdown, continueLabel, quitLabel, finalMessage, onContinue, onQuit, onTimeout, tallyDuration, fixed, autoFocus, replayKey, minHeight, titleSize, backgroundColor, titleColor, textColor, mutedColor, accentColor, lineColor, buttonColor, buttonTextColor, shadowColor, fontFamily, className, style }: GameOverProps): import("react").JSX.Element;
|
package/dist/GameOver.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useInsertionEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-game-over";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-go { position: relative; display: grid; place-content: center; justify-items: center; gap: 22px; width: 100%; height: 100%; min-height: var(--bl-min-h); padding: 28px 16px; box-sizing: border-box; overflow: hidden; background: var(--bl-bg); color: var(--bl-ink); font-family: var(--bl-font); text-align: center; }
|
|
7
|
+
.bl-go[data-fixed] { position: fixed; inset: 0; z-index: 2000; min-height: 0; }
|
|
8
|
+
.bl-go__title { display: flex; flex-wrap: wrap; justify-content: center; margin: 0; color: var(--bl-title); font-size: var(--bl-title-size); font-weight: 400; line-height: 1.2; text-shadow: 0.08em 0.08em 0 var(--bl-shadow); }
|
|
9
|
+
.bl-go__title span { display: inline-block; animation: bl-go-drop 520ms cubic-bezier(.3,1.5,.5,1) both; animation-delay: calc(var(--i) * 80ms); }
|
|
10
|
+
.bl-go__sub { margin: -8px 0 0; color: var(--bl-muted); font-size: 11px; line-height: 1.6; }
|
|
11
|
+
.bl-go__stats { display: grid; gap: 10px; min-width: min(320px, 100%); margin: 0; font-size: 11px; }
|
|
12
|
+
.bl-go__row { display: flex; justify-content: space-between; gap: 24px; animation: bl-go-in 200ms steps(2) both; }
|
|
13
|
+
.bl-go__row dt { color: var(--bl-muted); }
|
|
14
|
+
.bl-go__row dd { margin: 0; font-variant-numeric: tabular-nums; }
|
|
15
|
+
.bl-go__row[data-total] { padding-top: 10px; border-top: 3px dotted var(--bl-line); color: var(--bl-accent); font-size: 13px; }
|
|
16
|
+
.bl-go__row[data-total] dt { color: inherit; }
|
|
17
|
+
.bl-go__continue { display: grid; gap: 10px; justify-items: center; min-height: 64px; font-size: 13px; }
|
|
18
|
+
.bl-go__count { color: var(--bl-accent); font-size: 32px; animation: bl-go-tick 1s steps(1) both; }
|
|
19
|
+
.bl-go__count[data-low] { color: var(--bl-title); }
|
|
20
|
+
.bl-go__final { color: var(--bl-muted); font-size: 12px; line-height: 1.6; animation: bl-go-in 300ms steps(3) both; }
|
|
21
|
+
.bl-go__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
|
|
22
|
+
.bl-go__btn { padding: 12px 18px; border: 0; background: var(--bl-btn); color: var(--bl-btn-ink); font: inherit; font-size: 11px; text-transform: uppercase; cursor: pointer; box-shadow: 0 0 0 3px var(--bl-shadow), inset -3px -3px 0 rgba(0,0,0,0.3), inset 3px 3px 0 rgba(255,255,255,0.25); }
|
|
23
|
+
.bl-go__btn[data-secondary] { background: transparent; color: var(--bl-ink); box-shadow: 0 0 0 3px var(--bl-line); }
|
|
24
|
+
.bl-go__btn:hover { filter: brightness(1.15); }
|
|
25
|
+
.bl-go__btn:active { transform: translateY(3px); }
|
|
26
|
+
.bl-go__btn:focus-visible { outline: 3px solid var(--bl-accent); outline-offset: 5px; }
|
|
27
|
+
.bl-go__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
28
|
+
@keyframes bl-go-drop { from { opacity: 0; transform: translateY(-1.4em); } }
|
|
29
|
+
@keyframes bl-go-in { from { opacity: 0; } }
|
|
30
|
+
@keyframes bl-go-tick { from { transform: scale(1.5); } 30% { transform: none; } }
|
|
31
|
+
@media (prefers-reduced-motion: reduce) {
|
|
32
|
+
.bl-go__title span, .bl-go__row, .bl-go__count, .bl-go__final { animation: none; }
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
function useStyles() {
|
|
36
|
+
useInsertionEffect(() => {
|
|
37
|
+
if (typeof document === "undefined") return;
|
|
38
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
39
|
+
style.textContent = CSS;
|
|
40
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
41
|
+
}, []);
|
|
42
|
+
}
|
|
43
|
+
const format = (value) => Math.round(value).toLocaleString("en-US");
|
|
44
|
+
function GameOver({
|
|
45
|
+
title = "GAME OVER",
|
|
46
|
+
subtitle,
|
|
47
|
+
stats = [],
|
|
48
|
+
totalLabel = "Total",
|
|
49
|
+
total,
|
|
50
|
+
countdown = 9,
|
|
51
|
+
continueLabel = "Continue",
|
|
52
|
+
quitLabel = "Quit",
|
|
53
|
+
finalMessage = "Thanks for playing!",
|
|
54
|
+
onContinue,
|
|
55
|
+
onQuit,
|
|
56
|
+
onTimeout,
|
|
57
|
+
tallyDuration = 700,
|
|
58
|
+
fixed = false,
|
|
59
|
+
autoFocus = fixed,
|
|
60
|
+
replayKey,
|
|
61
|
+
minHeight = 420,
|
|
62
|
+
titleSize = 40,
|
|
63
|
+
backgroundColor = "#0b0b14",
|
|
64
|
+
titleColor = "#b13e53",
|
|
65
|
+
textColor = "#f4f4f4",
|
|
66
|
+
mutedColor = "#94b0c2",
|
|
67
|
+
accentColor = "#ffcd75",
|
|
68
|
+
lineColor = "#333c57",
|
|
69
|
+
buttonColor = "#38b764",
|
|
70
|
+
buttonTextColor = "#0b0b14",
|
|
71
|
+
shadowColor = "#000000",
|
|
72
|
+
fontFamily = '"Press Start 2P", ui-monospace, monospace',
|
|
73
|
+
className = "",
|
|
74
|
+
style
|
|
75
|
+
}) {
|
|
76
|
+
useStyles();
|
|
77
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
78
|
+
const sum = total ?? stats.reduce((acc, row) => acc + (Number(row.value) || 0), 0);
|
|
79
|
+
const plan = useMemo(() => {
|
|
80
|
+
const titleEnd = [...title].length * 80 + 520;
|
|
81
|
+
const rows2 = [...stats.map((row) => Number(row.value) || 0), sum].map((value, i) => ({ value, start: titleEnd + i * (tallyDuration + 220) }));
|
|
82
|
+
const tallyEnd = titleEnd + rows2.length * (tallyDuration + 220);
|
|
83
|
+
return { rows: rows2, tallyEnd, end: tallyEnd + countdown * 1e3 };
|
|
84
|
+
}, [title, stats, sum, tallyDuration, countdown]);
|
|
85
|
+
const [elapsed, setElapsed] = useState(0);
|
|
86
|
+
const startRef = useRef(0);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
89
|
+
startRef.current = performance.now() - (reduced ? plan.tallyEnd : 0);
|
|
90
|
+
setElapsed(reduced ? plan.tallyEnd : 0);
|
|
91
|
+
let frame = 0;
|
|
92
|
+
const tick = (now) => {
|
|
93
|
+
const t = Math.min(plan.end, now - startRef.current);
|
|
94
|
+
setElapsed(t);
|
|
95
|
+
if (t < plan.end) frame = requestAnimationFrame(tick);
|
|
96
|
+
};
|
|
97
|
+
frame = requestAnimationFrame(tick);
|
|
98
|
+
return () => cancelAnimationFrame(frame);
|
|
99
|
+
}, [plan, replayKey]);
|
|
100
|
+
const tallied = elapsed >= plan.tallyEnd;
|
|
101
|
+
const timedOut = countdown > 0 && elapsed >= plan.end;
|
|
102
|
+
const secondsLeft = Math.max(0, countdown - Math.floor((elapsed - plan.tallyEnd) / 1e3));
|
|
103
|
+
const skipTally = () => {
|
|
104
|
+
if (!tallied) startRef.current = performance.now() - plan.tallyEnd;
|
|
105
|
+
};
|
|
106
|
+
const timeoutRef = useRef(onTimeout);
|
|
107
|
+
timeoutRef.current = onTimeout;
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (timedOut) timeoutRef.current?.();
|
|
110
|
+
}, [timedOut]);
|
|
111
|
+
const continueRef = useRef(null);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (tallied && autoFocus) continueRef.current?.focus({ preventScroll: true });
|
|
114
|
+
}, [tallied, autoFocus]);
|
|
115
|
+
const quitRef = useRef(onQuit);
|
|
116
|
+
quitRef.current = onQuit;
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!fixed) return void 0;
|
|
119
|
+
const onKey = (event) => {
|
|
120
|
+
if (event.key === "Escape") quitRef.current?.();
|
|
121
|
+
};
|
|
122
|
+
window.addEventListener("keydown", onKey);
|
|
123
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
124
|
+
}, [fixed]);
|
|
125
|
+
const rows = plan.rows.map((row) => {
|
|
126
|
+
if (elapsed < row.start) return null;
|
|
127
|
+
const progress = Math.min(1, (elapsed - row.start) / tallyDuration);
|
|
128
|
+
return { shown: row.value * (1 - (1 - progress) ** 3) };
|
|
129
|
+
});
|
|
130
|
+
const totalRow = rows[rows.length - 1];
|
|
131
|
+
return /* @__PURE__ */ jsxs(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: `bl-go ${className}`,
|
|
135
|
+
"data-fixed": fixed || void 0,
|
|
136
|
+
role: fixed ? "dialog" : "region",
|
|
137
|
+
"aria-modal": fixed || void 0,
|
|
138
|
+
"aria-labelledby": `${uid}-title`,
|
|
139
|
+
onClick: skipTally,
|
|
140
|
+
style: {
|
|
141
|
+
"--bl-min-h": `${minHeight}px`,
|
|
142
|
+
"--bl-title-size": `${titleSize}px`,
|
|
143
|
+
"--bl-bg": backgroundColor,
|
|
144
|
+
"--bl-title": titleColor,
|
|
145
|
+
"--bl-ink": textColor,
|
|
146
|
+
"--bl-muted": mutedColor,
|
|
147
|
+
"--bl-accent": accentColor,
|
|
148
|
+
"--bl-line": lineColor,
|
|
149
|
+
"--bl-btn": buttonColor,
|
|
150
|
+
"--bl-btn-ink": buttonTextColor,
|
|
151
|
+
"--bl-shadow": shadowColor,
|
|
152
|
+
"--bl-font": fontFamily,
|
|
153
|
+
...style
|
|
154
|
+
},
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ jsx("h2", { id: `${uid}-title`, className: "bl-go__title", "aria-label": title, children: [...title].map((ch, i) => /* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: { "--i": i }, children: ch === " " ? "\xA0" : ch }, `${replayKey}-${i}`)) }),
|
|
157
|
+
subtitle && /* @__PURE__ */ jsx("p", { className: "bl-go__sub", children: subtitle }),
|
|
158
|
+
(stats.length > 0 || total != null) && /* @__PURE__ */ jsxs("dl", { className: "bl-go__stats", children: [
|
|
159
|
+
stats.map(
|
|
160
|
+
(row, i) => rows[i] ? /* @__PURE__ */ jsxs("div", { className: "bl-go__row", children: [
|
|
161
|
+
/* @__PURE__ */ jsx("dt", { children: row.label }),
|
|
162
|
+
/* @__PURE__ */ jsx("dd", { children: format(rows[i].shown) })
|
|
163
|
+
] }, i) : null
|
|
164
|
+
),
|
|
165
|
+
totalRow && /* @__PURE__ */ jsxs("div", { className: "bl-go__row", "data-total": "", children: [
|
|
166
|
+
/* @__PURE__ */ jsx("dt", { children: totalLabel }),
|
|
167
|
+
/* @__PURE__ */ jsx("dd", { children: format(totalRow.shown) })
|
|
168
|
+
] })
|
|
169
|
+
] }),
|
|
170
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-go__continue", children: [
|
|
171
|
+
tallied && countdown > 0 && !timedOut && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
172
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "CONTINUE?" }),
|
|
173
|
+
/* @__PURE__ */ jsx("span", { className: "bl-go__count", "data-low": secondsLeft <= 3 || void 0, "aria-hidden": "true", children: secondsLeft }, secondsLeft)
|
|
174
|
+
] }),
|
|
175
|
+
timedOut && /* @__PURE__ */ jsx("p", { className: "bl-go__final", children: finalMessage })
|
|
176
|
+
] }),
|
|
177
|
+
tallied && /* @__PURE__ */ jsxs("div", { className: "bl-go__actions", children: [
|
|
178
|
+
/* @__PURE__ */ jsx("button", { ref: continueRef, type: "button", className: "bl-go__btn", onClick: () => onContinue?.(), children: continueLabel }),
|
|
179
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bl-go__btn", "data-secondary": "", onClick: () => onQuit?.(), children: quitLabel })
|
|
180
|
+
] }),
|
|
181
|
+
/* @__PURE__ */ jsxs("p", { className: "bl-go__sr", "aria-live": "polite", children: [
|
|
182
|
+
tallied ? `${totalLabel}: ${format(sum)}.${countdown > 0 && !timedOut ? ` Continue? ${countdown} seconds to decide.` : ""}` : "",
|
|
183
|
+
timedOut ? ` ${finalMessage}` : ""
|
|
184
|
+
] })
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
export {
|
|
190
|
+
GameOver as default
|
|
191
|
+
};
|