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
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-polaroids";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-pola { position: relative; display: grid; gap: 10px; width: 100%; font-family: var(--bl-font); }
|
|
7
|
+
.bl-pola__table { position: relative; width: 100%; height: var(--bl-h); overflow: hidden; border-radius: var(--bl-radius); background: var(--bl-bg); box-shadow: inset 0 0 0 2px var(--bl-line); touch-action: none; }
|
|
8
|
+
.bl-pola__photo { position: absolute; top: 0; left: 0; box-sizing: border-box; width: var(--bl-pw); margin: 0; padding: var(--bl-frame) var(--bl-frame) 0; border: 0; background: var(--bl-paper); color: var(--bl-ink); font: inherit; text-align: center; cursor: grab; touch-action: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.4)); transition: filter 200ms; outline: none; will-change: transform; }
|
|
9
|
+
.bl-pola__photo[data-held] { cursor: grabbing; filter: drop-shadow(0 22px 18px rgba(0,0,0,0.5)); }
|
|
10
|
+
.bl-pola__photo[data-flying] { filter: drop-shadow(0 14px 12px rgba(0,0,0,0.45)); }
|
|
11
|
+
.bl-pola__photo:focus-visible { box-shadow: 0 0 0 3px var(--bl-accent); }
|
|
12
|
+
.bl-pola__img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #0b0b14; pointer-events: none; user-select: none; }
|
|
13
|
+
.bl-pola__caption { display: block; overflow: hidden; height: var(--bl-caption); line-height: var(--bl-caption); font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
|
|
14
|
+
.bl-pola__bar { display: flex; justify-content: center; gap: 8px; }
|
|
15
|
+
.bl-pola__btn { padding: 7px 14px; border: 0; border-radius: 8px; background: var(--bl-btn); color: var(--bl-btn-ink); font: inherit; font-size: 14px; cursor: pointer; }
|
|
16
|
+
.bl-pola__btn:hover { filter: brightness(1.15); }
|
|
17
|
+
.bl-pola__btn:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 2px; }
|
|
18
|
+
.bl-pola__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
19
|
+
`;
|
|
20
|
+
function useStyles() {
|
|
21
|
+
useInsertionEffect(() => {
|
|
22
|
+
if (typeof document === "undefined") return;
|
|
23
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
24
|
+
style.textContent = CSS;
|
|
25
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
26
|
+
}, []);
|
|
27
|
+
}
|
|
28
|
+
const jitter = (i, salt) => {
|
|
29
|
+
const x = Math.sin((i + 1) * 12.9898 + salt * 78.233) * 43758.5453;
|
|
30
|
+
return x - Math.floor(x) - 0.5;
|
|
31
|
+
};
|
|
32
|
+
function Polaroids({
|
|
33
|
+
photos = [],
|
|
34
|
+
height = 440,
|
|
35
|
+
photoWidth = 160,
|
|
36
|
+
frame = 10,
|
|
37
|
+
captionHeight = 34,
|
|
38
|
+
friction = 3.2,
|
|
39
|
+
bounce = 0.45,
|
|
40
|
+
spin = 1,
|
|
41
|
+
showControls = true,
|
|
42
|
+
scatterLabel = "Scatter",
|
|
43
|
+
tidyLabel = "Tidy up",
|
|
44
|
+
label = "Photo pile",
|
|
45
|
+
radius = 16,
|
|
46
|
+
backgroundColor = "#5d275d",
|
|
47
|
+
paperColor = "#f4f4f4",
|
|
48
|
+
textColor = "#1a1c2c",
|
|
49
|
+
lineColor = "rgba(0,0,0,0.25)",
|
|
50
|
+
accentColor = "#73eff7",
|
|
51
|
+
buttonColor = "#333c57",
|
|
52
|
+
buttonTextColor = "#f4f4f4",
|
|
53
|
+
fontFamily = '"Pixelify Sans", ui-sans-serif, system-ui, sans-serif',
|
|
54
|
+
className = "",
|
|
55
|
+
style
|
|
56
|
+
}) {
|
|
57
|
+
useStyles();
|
|
58
|
+
const tableRef = useRef(null);
|
|
59
|
+
const nodes = useRef([]);
|
|
60
|
+
const api = useRef(null);
|
|
61
|
+
const [order, setOrder] = useState(() => photos.map((_, i) => i));
|
|
62
|
+
const [announce, setAnnounce] = useState("");
|
|
63
|
+
const name = (i) => photos[i]?.caption || photos[i]?.alt || `Photo ${i + 1}`;
|
|
64
|
+
const raise = (i) => setOrder((list) => [...list.filter((j) => j !== i), i]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
setOrder((list) => {
|
|
67
|
+
const kept = list.filter((i) => i < photos.length);
|
|
68
|
+
return [...kept, ...photos.map((_, i) => i).filter((i) => !kept.includes(i))];
|
|
69
|
+
});
|
|
70
|
+
}, [photos.length]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const table = tableRef.current;
|
|
73
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
74
|
+
const count = photos.length;
|
|
75
|
+
let W = table.clientWidth;
|
|
76
|
+
let H = table.clientHeight;
|
|
77
|
+
const size = (i) => ({ w: nodes.current[i]?.offsetWidth || photoWidth, h: nodes.current[i]?.offsetHeight || photoWidth + captionHeight });
|
|
78
|
+
const bodies = Array.from({ length: count }, (_, i) => {
|
|
79
|
+
const { w, h } = size(i);
|
|
80
|
+
return { x: W / 2 - w / 2 + jitter(i, 1) * W * 0.35, y: H / 2 - h / 2 + jitter(i, 2) * H * 0.3, r: jitter(i, 3) * 30, vx: 0, vy: 0, vr: 0, held: false };
|
|
81
|
+
});
|
|
82
|
+
let raf = 0;
|
|
83
|
+
let last = 0;
|
|
84
|
+
const clamp = (i) => {
|
|
85
|
+
const b = bodies[i];
|
|
86
|
+
const { w, h } = size(i);
|
|
87
|
+
let hit = false;
|
|
88
|
+
if (b.x < 0 || b.x > W - w) {
|
|
89
|
+
b.x = Math.max(0, Math.min(W - w, b.x));
|
|
90
|
+
b.vx = -b.vx * bounce;
|
|
91
|
+
b.vr *= 0.7;
|
|
92
|
+
hit = true;
|
|
93
|
+
}
|
|
94
|
+
if (b.y < 0 || b.y > H - h) {
|
|
95
|
+
b.y = Math.max(0, Math.min(H - h, b.y));
|
|
96
|
+
b.vy = -b.vy * bounce;
|
|
97
|
+
b.vr *= 0.7;
|
|
98
|
+
hit = true;
|
|
99
|
+
}
|
|
100
|
+
return hit;
|
|
101
|
+
};
|
|
102
|
+
const place = (i) => {
|
|
103
|
+
const node = nodes.current[i];
|
|
104
|
+
const b = bodies[i];
|
|
105
|
+
if (node) node.style.transform = `translate(${b.x.toFixed(1)}px, ${b.y.toFixed(1)}px) rotate(${b.r.toFixed(2)}deg)`;
|
|
106
|
+
};
|
|
107
|
+
const tick = (now) => {
|
|
108
|
+
const dt = Math.max(0, Math.min(0.05, (now - last) / 1e3));
|
|
109
|
+
last = now;
|
|
110
|
+
const decay = Math.exp(-friction * dt);
|
|
111
|
+
let moving = false;
|
|
112
|
+
bodies.forEach((b, i) => {
|
|
113
|
+
const node = nodes.current[i];
|
|
114
|
+
if (b.held) return;
|
|
115
|
+
b.x += b.vx * dt;
|
|
116
|
+
b.y += b.vy * dt;
|
|
117
|
+
b.r += b.vr * dt;
|
|
118
|
+
b.vx *= decay;
|
|
119
|
+
b.vy *= decay;
|
|
120
|
+
b.vr *= decay;
|
|
121
|
+
clamp(i);
|
|
122
|
+
const flying = Math.hypot(b.vx, b.vy) > 8 || Math.abs(b.vr) > 4;
|
|
123
|
+
if (flying) moving = true;
|
|
124
|
+
else {
|
|
125
|
+
b.vx = 0;
|
|
126
|
+
b.vy = 0;
|
|
127
|
+
b.vr = 0;
|
|
128
|
+
}
|
|
129
|
+
if (node) node.toggleAttribute("data-flying", flying);
|
|
130
|
+
place(i);
|
|
131
|
+
});
|
|
132
|
+
raf = moving ? requestAnimationFrame(tick) : 0;
|
|
133
|
+
};
|
|
134
|
+
const wake = () => {
|
|
135
|
+
if (raf) return;
|
|
136
|
+
last = performance.now();
|
|
137
|
+
raf = requestAnimationFrame(tick);
|
|
138
|
+
};
|
|
139
|
+
const settle = (i) => {
|
|
140
|
+
const b = bodies[i];
|
|
141
|
+
const k = 1 / friction;
|
|
142
|
+
b.x += b.vx * k;
|
|
143
|
+
b.y += b.vy * k;
|
|
144
|
+
b.r += b.vr * k * 0.3;
|
|
145
|
+
b.vx = b.vy = b.vr = 0;
|
|
146
|
+
clamp(i);
|
|
147
|
+
place(i);
|
|
148
|
+
};
|
|
149
|
+
const launch = (i) => reduced ? settle(i) : wake();
|
|
150
|
+
let drag = null;
|
|
151
|
+
const onDown = (event) => {
|
|
152
|
+
const i = nodes.current.indexOf(event.target.closest(".bl-pola__photo"));
|
|
153
|
+
if (i < 0 || event.button > 0) return;
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
const node = nodes.current[i];
|
|
156
|
+
node.focus({ preventScroll: true });
|
|
157
|
+
try {
|
|
158
|
+
node.setPointerCapture(event.pointerId);
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
const rect = table.getBoundingClientRect();
|
|
162
|
+
const b = bodies[i];
|
|
163
|
+
const { w, h } = size(i);
|
|
164
|
+
b.held = true;
|
|
165
|
+
b.vx = b.vy = b.vr = 0;
|
|
166
|
+
node.dataset.held = "";
|
|
167
|
+
drag = { i, id: event.pointerId, rect, dx: event.clientX - rect.left - b.x, dy: event.clientY - rect.top - b.y, gx: event.clientX - rect.left - (b.x + w / 2), gy: event.clientY - rect.top - (b.y + h / 2), samples: [{ x: event.clientX, y: event.clientY, t: event.timeStamp }] };
|
|
168
|
+
raise(i);
|
|
169
|
+
};
|
|
170
|
+
const onMove = (event) => {
|
|
171
|
+
if (!drag || event.pointerId !== drag.id) return;
|
|
172
|
+
const b = bodies[drag.i];
|
|
173
|
+
b.x = event.clientX - drag.rect.left - drag.dx;
|
|
174
|
+
b.y = event.clientY - drag.rect.top - drag.dy;
|
|
175
|
+
clamp(drag.i);
|
|
176
|
+
place(drag.i);
|
|
177
|
+
drag.samples.push({ x: event.clientX, y: event.clientY, t: event.timeStamp });
|
|
178
|
+
while (drag.samples.length > 2 && event.timeStamp - drag.samples[0].t > 80) drag.samples.shift();
|
|
179
|
+
};
|
|
180
|
+
const onUp = (event) => {
|
|
181
|
+
if (!drag || event.pointerId !== drag.id) return;
|
|
182
|
+
const { i, samples, gx, gy } = drag;
|
|
183
|
+
const b = bodies[i];
|
|
184
|
+
const first = samples[0];
|
|
185
|
+
const lastSample = samples[samples.length - 1];
|
|
186
|
+
const span = Math.max(16, lastSample.t - first.t) / 1e3;
|
|
187
|
+
b.vx = (lastSample.x - first.x) / span;
|
|
188
|
+
b.vy = (lastSample.y - first.y) / span;
|
|
189
|
+
b.vr = spin * (gx * b.vy - gy * b.vx) / 900;
|
|
190
|
+
b.held = false;
|
|
191
|
+
delete nodes.current[i].dataset.held;
|
|
192
|
+
drag = null;
|
|
193
|
+
launch(i);
|
|
194
|
+
if (Math.hypot(b.vx, b.vy) > 200) setAnnounce(`${name(i)} tossed.`);
|
|
195
|
+
};
|
|
196
|
+
const onKey = (event) => {
|
|
197
|
+
const i = nodes.current.indexOf(event.target.closest?.(".bl-pola__photo"));
|
|
198
|
+
if (i < 0) return;
|
|
199
|
+
const step = event.shiftKey ? 40 : 10;
|
|
200
|
+
const moves = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] };
|
|
201
|
+
if (moves[event.key]) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
const b = bodies[i];
|
|
204
|
+
b.x += moves[event.key][0];
|
|
205
|
+
b.y += moves[event.key][1];
|
|
206
|
+
clamp(i);
|
|
207
|
+
place(i);
|
|
208
|
+
raise(i);
|
|
209
|
+
setAnnounce(`${name(i)} moved to ${Math.round(b.x)}, ${Math.round(b.y)}.`);
|
|
210
|
+
} else if (event.key === "Enter" || event.key === " ") {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
raise(i);
|
|
213
|
+
setAnnounce(`${name(i)} on top.`);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
api.current = {
|
|
217
|
+
scatter: () => {
|
|
218
|
+
bodies.forEach((b, i) => {
|
|
219
|
+
const a = Math.random() * Math.PI * 2;
|
|
220
|
+
const speed = 600 + Math.random() * 900;
|
|
221
|
+
b.vx = Math.cos(a) * speed;
|
|
222
|
+
b.vy = Math.sin(a) * speed;
|
|
223
|
+
b.vr = (Math.random() - 0.5) * 400 * spin;
|
|
224
|
+
if (reduced) settle(i);
|
|
225
|
+
});
|
|
226
|
+
if (!reduced) wake();
|
|
227
|
+
setAnnounce("Photos scattered.");
|
|
228
|
+
},
|
|
229
|
+
tidy: () => {
|
|
230
|
+
bodies.forEach((b, i) => {
|
|
231
|
+
const { w, h } = size(i);
|
|
232
|
+
b.x = W / 2 - w / 2 + jitter(i, 4) * 16;
|
|
233
|
+
b.y = H / 2 - h / 2 + jitter(i, 5) * 16;
|
|
234
|
+
b.r = jitter(i, 6) * 10;
|
|
235
|
+
b.vx = b.vy = b.vr = 0;
|
|
236
|
+
place(i);
|
|
237
|
+
});
|
|
238
|
+
setAnnounce("Photos stacked in a neat pile.");
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const resize = new ResizeObserver(() => {
|
|
242
|
+
W = table.clientWidth;
|
|
243
|
+
H = table.clientHeight;
|
|
244
|
+
bodies.forEach((_, i) => {
|
|
245
|
+
clamp(i);
|
|
246
|
+
place(i);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
resize.observe(table);
|
|
250
|
+
bodies.forEach((_, i) => place(i));
|
|
251
|
+
table.addEventListener("pointerdown", onDown);
|
|
252
|
+
table.addEventListener("pointermove", onMove);
|
|
253
|
+
table.addEventListener("pointerup", onUp);
|
|
254
|
+
table.addEventListener("pointercancel", onUp);
|
|
255
|
+
table.addEventListener("keydown", onKey);
|
|
256
|
+
return () => {
|
|
257
|
+
cancelAnimationFrame(raf);
|
|
258
|
+
resize.disconnect();
|
|
259
|
+
table.removeEventListener("pointerdown", onDown);
|
|
260
|
+
table.removeEventListener("pointermove", onMove);
|
|
261
|
+
table.removeEventListener("pointerup", onUp);
|
|
262
|
+
table.removeEventListener("pointercancel", onUp);
|
|
263
|
+
table.removeEventListener("keydown", onKey);
|
|
264
|
+
};
|
|
265
|
+
}, [photos.length, photoWidth, frame, captionHeight, friction, bounce, spin]);
|
|
266
|
+
return /* @__PURE__ */ jsxs("div", { className: `bl-pola ${className}`, style: { "--bl-h": `${height}px`, "--bl-pw": `${photoWidth}px`, "--bl-frame": `${frame}px`, "--bl-caption": `${captionHeight}px`, "--bl-radius": `${radius}px`, "--bl-bg": backgroundColor, "--bl-paper": paperColor, "--bl-ink": textColor, "--bl-line": lineColor, "--bl-accent": accentColor, "--bl-btn": buttonColor, "--bl-btn-ink": buttonTextColor, "--bl-font": fontFamily, ...style }, children: [
|
|
267
|
+
/* @__PURE__ */ jsx("div", { ref: tableRef, className: "bl-pola__table", role: "group", "aria-label": label, children: photos.map((photo, i) => /* @__PURE__ */ jsxs(
|
|
268
|
+
"button",
|
|
269
|
+
{
|
|
270
|
+
ref: (node) => {
|
|
271
|
+
nodes.current[i] = node;
|
|
272
|
+
},
|
|
273
|
+
type: "button",
|
|
274
|
+
className: "bl-pola__photo",
|
|
275
|
+
style: { zIndex: order.indexOf(i) + 1 },
|
|
276
|
+
"aria-label": `${name(i)}. Drag to move, arrows to nudge, Enter to bring to the top.`,
|
|
277
|
+
children: [
|
|
278
|
+
/* @__PURE__ */ jsx("img", { className: "bl-pola__img", src: photo.src, alt: "", draggable: false }),
|
|
279
|
+
/* @__PURE__ */ jsx("span", { className: "bl-pola__caption", children: photo.caption })
|
|
280
|
+
]
|
|
281
|
+
},
|
|
282
|
+
photo.src ?? i
|
|
283
|
+
)) }),
|
|
284
|
+
showControls && /* @__PURE__ */ jsxs("div", { className: "bl-pola__bar", children: [
|
|
285
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bl-pola__btn", onClick: () => api.current?.scatter(), children: scatterLabel }),
|
|
286
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "bl-pola__btn", onClick: () => api.current?.tidy(), children: tidyLabel })
|
|
287
|
+
] }),
|
|
288
|
+
/* @__PURE__ */ jsx("span", { className: "bl-pola__sr", "aria-live": "polite", children: announce })
|
|
289
|
+
] });
|
|
290
|
+
}
|
|
291
|
+
export {
|
|
292
|
+
Polaroids as default
|
|
293
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface PressStartProps {
|
|
3
|
+
/** Blinking prompt. */
|
|
4
|
+
text?: string;
|
|
5
|
+
/** Shown after the flash, until `resetAfter`. */
|
|
6
|
+
startedText?: string;
|
|
7
|
+
/** Small line underneath (copyright, version…). Empty to hide. */
|
|
8
|
+
subtext?: string;
|
|
9
|
+
color?: string;
|
|
10
|
+
shadowColor?: string;
|
|
11
|
+
subColor?: string;
|
|
12
|
+
/** Prompt font size, in px. */
|
|
13
|
+
size?: number;
|
|
14
|
+
/** Blink period, in seconds. */
|
|
15
|
+
blinkSpeed?: number;
|
|
16
|
+
/** How long the fast "starting" flash lasts, in ms. */
|
|
17
|
+
flashDuration?: number;
|
|
18
|
+
/** Start on any key press anywhere on the page (ignored while typing in a field). */
|
|
19
|
+
listenGlobally?: boolean;
|
|
20
|
+
/** Return to the prompt after this many ms; 0 to stay started. */
|
|
21
|
+
resetAfter?: number;
|
|
22
|
+
fontFamily?: string;
|
|
23
|
+
/** Called when the flash finishes. */
|
|
24
|
+
onStart?: () => void;
|
|
25
|
+
className?: string;
|
|
26
|
+
style?: CSSProperties;
|
|
27
|
+
}
|
|
28
|
+
export default function PressStart({ text, startedText, subtext, color, shadowColor, subColor, size, blinkSpeed, flashDuration, listenGlobally, resetAfter, fontFamily, onStart, className, style }: PressStartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-press-start";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-press-start {
|
|
7
|
+
display: inline-flex; flex-direction: column; align-items: center; gap: 18px;
|
|
8
|
+
border: 0; background: none; cursor: pointer; padding: 12px 16px;
|
|
9
|
+
font-family: var(--bl-font, "Press Start 2P", ui-monospace, monospace);
|
|
10
|
+
}
|
|
11
|
+
.bl-press-start:focus-visible { outline: 4px solid #41a6f6; outline-offset: 6px; }
|
|
12
|
+
.bl-press-start__text {
|
|
13
|
+
color: var(--bl-color); font-size: var(--bl-size); line-height: 1.2; text-transform: uppercase;
|
|
14
|
+
text-shadow: calc(var(--bl-size) / 6) calc(var(--bl-size) / 6) 0 var(--bl-shadow);
|
|
15
|
+
}
|
|
16
|
+
.bl-press-start[data-state="idle"] .bl-press-start__text { animation: bl-ps-blink var(--bl-blink) steps(1) infinite; }
|
|
17
|
+
.bl-press-start[data-state="starting"] .bl-press-start__text { animation: bl-ps-blink 90ms steps(1) infinite; }
|
|
18
|
+
.bl-press-start__sub { color: var(--bl-sub); font-size: calc(var(--bl-size) * 0.45); letter-spacing: 0.1em; text-transform: uppercase; }
|
|
19
|
+
@keyframes bl-ps-blink { 50% { opacity: 0; } }
|
|
20
|
+
@media (prefers-reduced-motion: reduce) {
|
|
21
|
+
.bl-press-start[data-state] .bl-press-start__text { animation: none; }
|
|
22
|
+
}
|
|
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 PressStart({
|
|
33
|
+
text = "Press start",
|
|
34
|
+
startedText = "Get ready!",
|
|
35
|
+
subtext = "\xA9 2026 Bits Lab",
|
|
36
|
+
color = "#ffcd75",
|
|
37
|
+
shadowColor = "#b13e53",
|
|
38
|
+
subColor = "#94b0c2",
|
|
39
|
+
size = 28,
|
|
40
|
+
blinkSpeed = 1.06,
|
|
41
|
+
flashDuration = 700,
|
|
42
|
+
listenGlobally = true,
|
|
43
|
+
resetAfter = 2500,
|
|
44
|
+
fontFamily,
|
|
45
|
+
onStart,
|
|
46
|
+
className = "",
|
|
47
|
+
style
|
|
48
|
+
}) {
|
|
49
|
+
useStyles();
|
|
50
|
+
const [state, setState] = useState("idle");
|
|
51
|
+
const timers = useRef([]);
|
|
52
|
+
const start = useCallback(() => {
|
|
53
|
+
if (state !== "idle") return;
|
|
54
|
+
setState("starting");
|
|
55
|
+
timers.current.push(
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
setState("started");
|
|
58
|
+
onStart?.();
|
|
59
|
+
if (resetAfter > 0) timers.current.push(setTimeout(() => setState("idle"), resetAfter));
|
|
60
|
+
}, flashDuration)
|
|
61
|
+
);
|
|
62
|
+
}, [state, flashDuration, onStart, resetAfter]);
|
|
63
|
+
useEffect(() => () => timers.current.forEach(clearTimeout), []);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!listenGlobally) return void 0;
|
|
66
|
+
const onKey = (event) => {
|
|
67
|
+
if (event.repeat || event.metaKey || event.ctrlKey || /input|textarea|select/i.test(event.target.tagName) || event.target.isContentEditable) return;
|
|
68
|
+
start();
|
|
69
|
+
};
|
|
70
|
+
window.addEventListener("keydown", onKey);
|
|
71
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
72
|
+
}, [listenGlobally, start]);
|
|
73
|
+
return /* @__PURE__ */ jsxs(
|
|
74
|
+
"button",
|
|
75
|
+
{
|
|
76
|
+
type: "button",
|
|
77
|
+
className: `bl-press-start ${className}`,
|
|
78
|
+
"data-state": state,
|
|
79
|
+
onClick: start,
|
|
80
|
+
"aria-live": "polite",
|
|
81
|
+
style: {
|
|
82
|
+
"--bl-color": color,
|
|
83
|
+
"--bl-shadow": shadowColor,
|
|
84
|
+
"--bl-sub": subColor,
|
|
85
|
+
"--bl-size": `${size}px`,
|
|
86
|
+
"--bl-blink": `${blinkSpeed}s`,
|
|
87
|
+
...fontFamily ? { "--bl-font": fontFamily } : null,
|
|
88
|
+
...style
|
|
89
|
+
},
|
|
90
|
+
children: [
|
|
91
|
+
/* @__PURE__ */ jsx("span", { className: "bl-press-start__text", children: state === "started" ? startedText : text }),
|
|
92
|
+
subtext && /* @__PURE__ */ jsx("span", { className: "bl-press-start__sub", children: subtext })
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
PressStart as default
|
|
99
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
export type BillingPeriod = 'monthly' | 'yearly';
|
|
3
|
+
export interface PricingPlan {
|
|
4
|
+
id?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description?: ReactNode;
|
|
7
|
+
/** Price per month when billed monthly; 0 shows freeLabel. */
|
|
8
|
+
monthly: number;
|
|
9
|
+
/** Price per month when billed yearly. */
|
|
10
|
+
yearly?: number;
|
|
11
|
+
features?: string[];
|
|
12
|
+
/** Button label; omit for no button. */
|
|
13
|
+
cta?: ReactNode;
|
|
14
|
+
featured?: boolean;
|
|
15
|
+
/** Ribbon such as "Most popular". */
|
|
16
|
+
badge?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export interface PricingFlipProps {
|
|
19
|
+
plans?: PricingPlan[];
|
|
20
|
+
period?: BillingPeriod;
|
|
21
|
+
defaultPeriod?: BillingPeriod;
|
|
22
|
+
onPeriodChange?: (period: BillingPeriod) => void;
|
|
23
|
+
onSelect?: (plan: PricingPlan, period: BillingPeriod) => void;
|
|
24
|
+
/** ISO currency code for Intl.NumberFormat. */
|
|
25
|
+
currency?: string;
|
|
26
|
+
locale?: string;
|
|
27
|
+
monthlyLabel?: string;
|
|
28
|
+
yearlyLabel?: string;
|
|
29
|
+
perLabel?: string;
|
|
30
|
+
freeLabel?: string;
|
|
31
|
+
/** Text under the price in yearly mode, given the formatted yearly total. */
|
|
32
|
+
billedYearly?: (total: string) => string;
|
|
33
|
+
/** Max width of the card grid in px. */
|
|
34
|
+
width?: number;
|
|
35
|
+
priceSize?: number;
|
|
36
|
+
backgroundColor?: string;
|
|
37
|
+
cardColor?: string;
|
|
38
|
+
trackColor?: string;
|
|
39
|
+
textColor?: string;
|
|
40
|
+
mutedColor?: string;
|
|
41
|
+
lineColor?: string;
|
|
42
|
+
accentColor?: string;
|
|
43
|
+
onAccentColor?: string;
|
|
44
|
+
saveColor?: string;
|
|
45
|
+
radius?: number;
|
|
46
|
+
fontFamily?: string;
|
|
47
|
+
/** Accessible name of the period switch. */
|
|
48
|
+
label?: string;
|
|
49
|
+
className?: string;
|
|
50
|
+
style?: CSSProperties;
|
|
51
|
+
}
|
|
52
|
+
export default function PricingFlip({ plans, period: controlled, defaultPeriod, onPeriodChange, onSelect, currency, locale, monthlyLabel, yearlyLabel, perLabel, freeLabel, billedYearly, width, priceSize, backgroundColor, cardColor, trackColor, textColor, mutedColor, lineColor, accentColor, onAccentColor, saveColor, radius, fontFamily, label, className, style }: PricingFlipProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-pricing-flip";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-price { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; justify-items: center; width: 100%; color: var(--bl-ink); font-family: var(--bl-font); }
|
|
7
|
+
.bl-price__switch { position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 999px; background: var(--bl-track); box-shadow: inset 0 0 0 1px var(--bl-line); }
|
|
8
|
+
.bl-price__thumb { position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px); border-radius: 999px; background: var(--bl-accent); transition: transform 320ms cubic-bezier(.3,1.35,.5,1); }
|
|
9
|
+
.bl-price__switch[data-yearly] .bl-price__thumb { transform: translateX(100%); }
|
|
10
|
+
.bl-price__opt { position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 18px; border: 0; border-radius: 999px; background: transparent; color: var(--bl-muted); font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: color 200ms; }
|
|
11
|
+
.bl-price__opt[aria-checked="true"] { color: var(--bl-on-accent); }
|
|
12
|
+
.bl-price__opt:focus-visible { outline: 2px solid var(--bl-ink); outline-offset: 2px; }
|
|
13
|
+
.bl-price__save { padding: 2px 7px; border-radius: 999px; background: var(--bl-save); color: var(--bl-on-accent); font-size: 11px; font-weight: 700; transform: scale(0.85); transition: transform 320ms cubic-bezier(.3,1.6,.5,1); }
|
|
14
|
+
.bl-price__switch[data-yearly] .bl-price__save { transform: scale(1.08) rotate(-4deg); }
|
|
15
|
+
.bl-price__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 18px; width: 100%; max-width: var(--bl-w); }
|
|
16
|
+
.bl-price__card { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 24px; border-radius: var(--bl-radius); background: var(--bl-card); box-shadow: 0 0 0 1px var(--bl-line); }
|
|
17
|
+
.bl-price__card[data-featured] { box-shadow: 0 0 0 2px var(--bl-accent), 0 24px 50px -28px var(--bl-accent); }
|
|
18
|
+
.bl-price__badge { position: absolute; top: 0; right: 20px; padding: 4px 10px; border-radius: 999px; background: var(--bl-accent); color: var(--bl-on-accent); font-size: 12px; font-weight: 700; transform: translateY(-50%); }
|
|
19
|
+
.bl-price__name { margin: 0; font-size: 18px; font-weight: 700; }
|
|
20
|
+
.bl-price__desc { margin: -6px 0 0; color: var(--bl-muted); font-size: 14px; line-height: 1.5; }
|
|
21
|
+
.bl-price__amount { display: flex; align-items: baseline; gap: 6px; min-height: 1.2em; }
|
|
22
|
+
.bl-price__figure { display: inline-flex; font-size: var(--bl-size); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
|
|
23
|
+
.bl-price__drum { display: inline-block; width: 1ch; height: 1.1em; overflow: hidden; }
|
|
24
|
+
.bl-price__strip { display: block; transition: transform 640ms cubic-bezier(.25,1.25,.5,1); transition-delay: calc(var(--bl-col) * 45ms); }
|
|
25
|
+
.bl-price__strip > span { display: block; height: 1.1em; text-align: center; }
|
|
26
|
+
.bl-price__per { color: var(--bl-muted); font-size: 14px; }
|
|
27
|
+
.bl-price__billed { min-height: 1.4em; margin: -8px 0 0; color: var(--bl-muted); font-size: 13px; transition: opacity 240ms; }
|
|
28
|
+
.bl-price__billed[data-hidden] { opacity: 0; }
|
|
29
|
+
.bl-price__features { display: grid; gap: 9px; margin: 4px 0 0; padding: 0; list-style: none; font-size: 14px; }
|
|
30
|
+
.bl-price__features li { display: flex; gap: 10px; align-items: flex-start; line-height: 1.45; }
|
|
31
|
+
.bl-price__features svg { flex: 0 0 auto; margin-top: 3px; color: var(--bl-accent); }
|
|
32
|
+
.bl-price__cta { margin-top: auto; padding: 11px 16px; border: 0; border-radius: calc(var(--bl-radius) * 0.6); background: var(--bl-track); color: var(--bl-ink); font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: inset 0 0 0 1px var(--bl-line); }
|
|
33
|
+
.bl-price__card[data-featured] .bl-price__cta { background: var(--bl-accent); color: var(--bl-on-accent); box-shadow: none; }
|
|
34
|
+
.bl-price__cta:hover { filter: brightness(1.12); }
|
|
35
|
+
.bl-price__cta:focus-visible { outline: 2px solid var(--bl-ink); outline-offset: 2px; }
|
|
36
|
+
.bl-price__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
37
|
+
@media (prefers-reduced-motion: reduce) { .bl-price__thumb, .bl-price__strip, .bl-price__save { transition: none; } }
|
|
38
|
+
`;
|
|
39
|
+
function useStyles() {
|
|
40
|
+
useInsertionEffect(() => {
|
|
41
|
+
if (typeof document === "undefined") return;
|
|
42
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
43
|
+
style.textContent = CSS;
|
|
44
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
45
|
+
}, []);
|
|
46
|
+
}
|
|
47
|
+
const DIGITS = Array.from({ length: 10 }, (_, i) => i);
|
|
48
|
+
function RollingPrice({ text }) {
|
|
49
|
+
const chars = [...text];
|
|
50
|
+
return /* @__PURE__ */ jsx("span", { className: "bl-price__figure", "aria-hidden": "true", children: chars.map((ch, i) => {
|
|
51
|
+
const fromRight = chars.length - i;
|
|
52
|
+
if (!/\d/.test(ch)) return /* @__PURE__ */ jsx("span", { children: ch }, `s${fromRight}-${ch}`);
|
|
53
|
+
return /* @__PURE__ */ jsx("span", { className: "bl-price__drum", children: /* @__PURE__ */ jsx("span", { className: "bl-price__strip", style: { transform: `translateY(${-Number(ch) * 1.1}em)`, "--bl-col": fromRight }, children: DIGITS.map((d) => /* @__PURE__ */ jsx("span", { children: d }, d)) }) }, `d${fromRight}`);
|
|
54
|
+
}) });
|
|
55
|
+
}
|
|
56
|
+
const Check = () => /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M2.5 7.5 5.5 10.5 11.5 3.5" }) });
|
|
57
|
+
function PricingFlip({
|
|
58
|
+
plans = [],
|
|
59
|
+
period: controlled,
|
|
60
|
+
defaultPeriod = "monthly",
|
|
61
|
+
onPeriodChange,
|
|
62
|
+
onSelect,
|
|
63
|
+
currency = "USD",
|
|
64
|
+
locale = "en-US",
|
|
65
|
+
monthlyLabel = "Monthly",
|
|
66
|
+
yearlyLabel = "Yearly",
|
|
67
|
+
perLabel = "/mo",
|
|
68
|
+
freeLabel = "Free",
|
|
69
|
+
billedYearly = (total) => `Billed ${total} yearly`,
|
|
70
|
+
width = 1e3,
|
|
71
|
+
priceSize = 44,
|
|
72
|
+
backgroundColor = "#1a1c2c",
|
|
73
|
+
cardColor = "#262b44",
|
|
74
|
+
trackColor = "#0b0b14",
|
|
75
|
+
textColor = "#f4f4f4",
|
|
76
|
+
mutedColor = "#94b0c2",
|
|
77
|
+
lineColor = "#333c57",
|
|
78
|
+
accentColor = "#73eff7",
|
|
79
|
+
onAccentColor = "#0b0b14",
|
|
80
|
+
saveColor = "#ffcd75",
|
|
81
|
+
radius = 18,
|
|
82
|
+
fontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
83
|
+
label = "Billing period",
|
|
84
|
+
className = "",
|
|
85
|
+
style
|
|
86
|
+
}) {
|
|
87
|
+
useStyles();
|
|
88
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
89
|
+
const [inner, setInner] = useState(defaultPeriod);
|
|
90
|
+
const period = controlled ?? inner;
|
|
91
|
+
const yearly = period === "yearly";
|
|
92
|
+
const [announce, setAnnounce] = useState("");
|
|
93
|
+
const optRefs = useRef([]);
|
|
94
|
+
const money = (value) => new Intl.NumberFormat(locale, { style: "currency", currency, maximumFractionDigits: Number.isInteger(value) ? 0 : 2 }).format(value);
|
|
95
|
+
const savings = plans.filter((p) => p.monthly > 0 && p.yearly != null).map((p) => Math.round((1 - p.yearly / p.monthly) * 100));
|
|
96
|
+
const bestSaving = savings.length ? Math.max(...savings) : 0;
|
|
97
|
+
const choose = (next) => {
|
|
98
|
+
if (next === period) return;
|
|
99
|
+
if (controlled === void 0) setInner(next);
|
|
100
|
+
onPeriodChange?.(next);
|
|
101
|
+
setAnnounce(next === "yearly" ? `Showing yearly prices.${bestSaving > 0 ? ` Save up to ${bestSaving}%.` : ""}` : "Showing monthly prices.");
|
|
102
|
+
};
|
|
103
|
+
const onKeyDown = (event) => {
|
|
104
|
+
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) return;
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
const next = yearly ? "monthly" : "yearly";
|
|
107
|
+
choose(next);
|
|
108
|
+
optRefs.current[next === "yearly" ? 1 : 0]?.focus();
|
|
109
|
+
};
|
|
110
|
+
return /* @__PURE__ */ jsxs(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: `bl-price ${className}`,
|
|
114
|
+
style: {
|
|
115
|
+
"--bl-w": `${width}px`,
|
|
116
|
+
"--bl-size": `${priceSize}px`,
|
|
117
|
+
"--bl-radius": `${radius}px`,
|
|
118
|
+
"--bl-bg": backgroundColor,
|
|
119
|
+
"--bl-card": cardColor,
|
|
120
|
+
"--bl-track": trackColor,
|
|
121
|
+
"--bl-ink": textColor,
|
|
122
|
+
"--bl-muted": mutedColor,
|
|
123
|
+
"--bl-line": lineColor,
|
|
124
|
+
"--bl-accent": accentColor,
|
|
125
|
+
"--bl-on-accent": onAccentColor,
|
|
126
|
+
"--bl-save": saveColor,
|
|
127
|
+
"--bl-font": fontFamily,
|
|
128
|
+
...style
|
|
129
|
+
},
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-price__switch", role: "radiogroup", "aria-label": label, "data-yearly": yearly || void 0, children: [
|
|
132
|
+
/* @__PURE__ */ jsx("span", { className: "bl-price__thumb", "aria-hidden": "true" }),
|
|
133
|
+
[
|
|
134
|
+
["monthly", monthlyLabel],
|
|
135
|
+
["yearly", yearlyLabel]
|
|
136
|
+
].map(([value, text], i) => /* @__PURE__ */ jsxs(
|
|
137
|
+
"button",
|
|
138
|
+
{
|
|
139
|
+
ref: (node) => {
|
|
140
|
+
optRefs.current[i] = node;
|
|
141
|
+
},
|
|
142
|
+
type: "button",
|
|
143
|
+
role: "radio",
|
|
144
|
+
className: "bl-price__opt",
|
|
145
|
+
"aria-checked": period === value,
|
|
146
|
+
tabIndex: period === value ? 0 : -1,
|
|
147
|
+
onClick: () => choose(value),
|
|
148
|
+
onKeyDown,
|
|
149
|
+
children: [
|
|
150
|
+
text,
|
|
151
|
+
value === "yearly" && bestSaving > 0 && /* @__PURE__ */ jsxs("span", { className: "bl-price__save", children: [
|
|
152
|
+
"Save ",
|
|
153
|
+
bestSaving,
|
|
154
|
+
"%"
|
|
155
|
+
] })
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
value
|
|
159
|
+
))
|
|
160
|
+
] }),
|
|
161
|
+
/* @__PURE__ */ jsx("div", { className: "bl-price__grid", children: plans.map((plan) => {
|
|
162
|
+
const perMonth = yearly && plan.yearly != null ? plan.yearly : plan.monthly;
|
|
163
|
+
const free = perMonth === 0;
|
|
164
|
+
const shown = free ? freeLabel : money(perMonth);
|
|
165
|
+
const nameId = `${uid}-${plan.id ?? plan.name}`;
|
|
166
|
+
return /* @__PURE__ */ jsxs("section", { className: "bl-price__card", "data-featured": plan.featured || void 0, "aria-labelledby": nameId, children: [
|
|
167
|
+
plan.badge && /* @__PURE__ */ jsx("span", { className: "bl-price__badge", children: plan.badge }),
|
|
168
|
+
/* @__PURE__ */ jsx("h3", { id: nameId, className: "bl-price__name", children: plan.name }),
|
|
169
|
+
plan.description && /* @__PURE__ */ jsx("p", { className: "bl-price__desc", children: plan.description }),
|
|
170
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-price__amount", children: [
|
|
171
|
+
free ? /* @__PURE__ */ jsx("span", { className: "bl-price__figure", "aria-hidden": "true", children: freeLabel }) : /* @__PURE__ */ jsx(RollingPrice, { text: shown }),
|
|
172
|
+
!free && /* @__PURE__ */ jsx("span", { className: "bl-price__per", "aria-hidden": "true", children: perLabel }),
|
|
173
|
+
/* @__PURE__ */ jsx("span", { className: "bl-price__sr", children: free ? freeLabel : `${shown} per month` })
|
|
174
|
+
] }),
|
|
175
|
+
/* @__PURE__ */ jsx("p", { className: "bl-price__billed", "data-hidden": !yearly || free || plan.yearly == null || void 0, children: yearly && !free && plan.yearly != null ? billedYearly(money(plan.yearly * 12)) : "\xA0" }),
|
|
176
|
+
plan.features && plan.features.length > 0 && /* @__PURE__ */ jsx("ul", { className: "bl-price__features", children: plan.features.map((feature) => /* @__PURE__ */ jsxs("li", { children: [
|
|
177
|
+
/* @__PURE__ */ jsx(Check, {}),
|
|
178
|
+
feature
|
|
179
|
+
] }, feature)) }),
|
|
180
|
+
plan.cta && /* @__PURE__ */ jsx("button", { type: "button", className: "bl-price__cta", onClick: () => onSelect?.(plan, period), children: plan.cta })
|
|
181
|
+
] }, plan.id ?? plan.name);
|
|
182
|
+
}) }),
|
|
183
|
+
/* @__PURE__ */ jsx("span", { className: "bl-price__sr", "aria-live": "polite", children: announce })
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
PricingFlip as default
|
|
190
|
+
};
|