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,34 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export type Ends = [number, number];
|
|
3
|
+
export interface RangeDualProps {
|
|
4
|
+
min?: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
step?: number;
|
|
7
|
+
value?: Ends;
|
|
8
|
+
defaultValue?: Ends;
|
|
9
|
+
onValueChange?: (value: Ends) => void;
|
|
10
|
+
/** Smallest allowed distance between the ends. */
|
|
11
|
+
minGap?: number;
|
|
12
|
+
/** Bin counts drawn behind the track. */
|
|
13
|
+
histogram?: number[];
|
|
14
|
+
/** Text for bubbles, labels and screen readers. */
|
|
15
|
+
format?: (value: number) => string;
|
|
16
|
+
label?: string;
|
|
17
|
+
showInputs?: boolean;
|
|
18
|
+
showScale?: boolean;
|
|
19
|
+
width?: number;
|
|
20
|
+
thumbSize?: number;
|
|
21
|
+
histogramHeight?: number;
|
|
22
|
+
backgroundColor?: string;
|
|
23
|
+
fieldColor?: string;
|
|
24
|
+
textColor?: string;
|
|
25
|
+
mutedColor?: string;
|
|
26
|
+
dimColor?: string;
|
|
27
|
+
trackColor?: string;
|
|
28
|
+
lineColor?: string;
|
|
29
|
+
accentColor?: string;
|
|
30
|
+
fontFamily?: string;
|
|
31
|
+
className?: string;
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
}
|
|
34
|
+
export default function RangeDual({ min, max, step, value, defaultValue, onValueChange, minGap, histogram, format, label, showInputs, showScale, width, thumbSize, histogramHeight, backgroundColor, fieldColor, textColor, mutedColor, dimColor, trackColor, lineColor, accentColor, fontFamily, className, style }: RangeDualProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-range-dual";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-range { width: 100%; max-width: var(--bl-w); padding-top: 34px; font-family: var(--bl-font); color: var(--bl-ink); }
|
|
7
|
+
.bl-range__label { display: block; margin: -34px 0 18px; color: var(--bl-muted); font-size: 13px; font-weight: 600; }
|
|
8
|
+
.bl-range__hist { display: flex; align-items: flex-end; gap: 2px; height: var(--bl-hist-h); padding: 0 calc(var(--bl-thumb) / 2); }
|
|
9
|
+
.bl-range__bar { flex: 1; min-height: 2px; border-radius: 3px 3px 0 0; background: var(--bl-dim); transition: background-color 160ms; }
|
|
10
|
+
.bl-range__bar[data-in] { background: var(--bl-accent); opacity: 0.55; }
|
|
11
|
+
.bl-range__track { position: relative; height: var(--bl-thumb); margin: 0; touch-action: none; cursor: pointer; }
|
|
12
|
+
.bl-range__rail { position: absolute; left: calc(var(--bl-thumb) / 2); right: calc(var(--bl-thumb) / 2); top: 50%; height: 6px; margin-top: -3px; border-radius: 999px; background: var(--bl-track); }
|
|
13
|
+
.bl-range__fill { position: absolute; top: 0; bottom: 0; left: calc(var(--bl-lo) * 100%); right: calc((1 - var(--bl-hi)) * 100%); border-radius: inherit; background: var(--bl-accent); cursor: grab; }
|
|
14
|
+
.bl-range[data-dragging="both"] .bl-range__fill { cursor: grabbing; }
|
|
15
|
+
.bl-range__thumb { position: absolute; top: 0; left: calc(var(--p) * (100% - var(--bl-thumb))); width: var(--bl-thumb); height: var(--bl-thumb); box-sizing: border-box; border-radius: 50%; background: var(--bl-ink); box-shadow: 0 0 0 3px var(--bl-accent), 0 4px 12px rgba(0,0,0,0.4); outline: none; transition: transform 140ms cubic-bezier(.3,1.6,.5,1); }
|
|
16
|
+
.bl-range__thumb:focus-visible { box-shadow: 0 0 0 3px var(--bl-accent), 0 0 0 7px color-mix(in srgb, var(--bl-accent) 35%, transparent); }
|
|
17
|
+
.bl-range__thumb[data-active] { transform: scale(1.18); z-index: 2; }
|
|
18
|
+
.bl-range__tip { position: absolute; left: 50%; bottom: calc(100% + 10px); padding: 3px 8px; border-radius: 6px; background: var(--bl-ink); color: var(--bl-bg); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; transform: translate(-50%, 4px) scale(0.85); opacity: 0; pointer-events: none; transition: opacity 120ms, transform 180ms cubic-bezier(.3,1.6,.5,1); }
|
|
19
|
+
.bl-range__tip::after { content: ""; position: absolute; left: 50%; top: 100%; border: 4px solid transparent; border-top-color: var(--bl-ink); transform: translateX(-50%); }
|
|
20
|
+
.bl-range__track:hover .bl-range__tip, .bl-range__thumb:focus-visible .bl-range__tip, .bl-range__thumb[data-active] .bl-range__tip { opacity: 1; transform: translate(-50%, 0) scale(1); }
|
|
21
|
+
.bl-range__scale { display: flex; justify-content: space-between; margin-top: 8px; color: var(--bl-dim); font-size: 12px; }
|
|
22
|
+
.bl-range__inputs { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
|
|
23
|
+
.bl-range__inputs label { display: grid; flex: 1; gap: 4px; color: var(--bl-muted); font-size: 12px; }
|
|
24
|
+
.bl-range__inputs input { height: 36px; padding: 0 10px; box-sizing: border-box; border: 0; border-radius: 10px; background: var(--bl-field); color: var(--bl-ink); font: inherit; font-size: 14px; font-variant-numeric: tabular-nums; box-shadow: inset 0 0 0 1px var(--bl-line); outline: none; }
|
|
25
|
+
.bl-range__inputs input:focus { box-shadow: inset 0 0 0 2px var(--bl-accent); }
|
|
26
|
+
.bl-range__dash { margin-top: 18px; color: var(--bl-dim); }
|
|
27
|
+
@media (prefers-reduced-motion: reduce) { .bl-range__thumb, .bl-range__tip, .bl-range__bar { transition: none; } }
|
|
28
|
+
`;
|
|
29
|
+
function useStyles() {
|
|
30
|
+
useInsertionEffect(() => {
|
|
31
|
+
if (typeof document === "undefined") return;
|
|
32
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
33
|
+
style.textContent = CSS;
|
|
34
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
35
|
+
}, []);
|
|
36
|
+
}
|
|
37
|
+
function RangeDual({
|
|
38
|
+
min = 0,
|
|
39
|
+
max = 100,
|
|
40
|
+
step = 1,
|
|
41
|
+
value,
|
|
42
|
+
defaultValue,
|
|
43
|
+
onValueChange,
|
|
44
|
+
minGap = 0,
|
|
45
|
+
histogram,
|
|
46
|
+
format = (v) => String(v),
|
|
47
|
+
label = "Range",
|
|
48
|
+
showInputs = true,
|
|
49
|
+
showScale = true,
|
|
50
|
+
width = 460,
|
|
51
|
+
thumbSize = 22,
|
|
52
|
+
histogramHeight = 56,
|
|
53
|
+
backgroundColor = "#1a1c2c",
|
|
54
|
+
fieldColor = "#0b0b14",
|
|
55
|
+
textColor = "#f4f4f4",
|
|
56
|
+
mutedColor = "#94b0c2",
|
|
57
|
+
dimColor = "#566c86",
|
|
58
|
+
trackColor = "#333c57",
|
|
59
|
+
lineColor = "#333c57",
|
|
60
|
+
accentColor = "#73eff7",
|
|
61
|
+
fontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
62
|
+
className = "",
|
|
63
|
+
style
|
|
64
|
+
}) {
|
|
65
|
+
useStyles();
|
|
66
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
67
|
+
const [inner, setInner] = useState(defaultValue ?? [min, max]);
|
|
68
|
+
const [lo, hi] = value ?? inner;
|
|
69
|
+
const [active, setActive] = useState(null);
|
|
70
|
+
const [drafts, setDrafts] = useState(null);
|
|
71
|
+
const trackRef = useRef(null);
|
|
72
|
+
const drag = useRef(null);
|
|
73
|
+
const span = Math.max(1e-9, max - min);
|
|
74
|
+
const snap = (v) => {
|
|
75
|
+
const snapped = Math.round((v - min) / step) * step + min;
|
|
76
|
+
return Math.max(min, Math.min(max, Number(snapped.toFixed(10))));
|
|
77
|
+
};
|
|
78
|
+
const commit = (a, b) => {
|
|
79
|
+
const next = [a, b];
|
|
80
|
+
if (value === void 0) setInner(next);
|
|
81
|
+
onValueChange?.(next);
|
|
82
|
+
};
|
|
83
|
+
const setEnd = (which, raw) => {
|
|
84
|
+
const v = snap(raw);
|
|
85
|
+
if (which === 0) commit(Math.min(v, hi - minGap), hi);
|
|
86
|
+
else commit(lo, Math.max(v, lo + minGap));
|
|
87
|
+
};
|
|
88
|
+
const valueAt = (clientX) => {
|
|
89
|
+
const rect = trackRef.current.getBoundingClientRect();
|
|
90
|
+
const usable = rect.width - thumbSize;
|
|
91
|
+
return min + Math.max(0, Math.min(1, (clientX - rect.left - thumbSize / 2) / usable)) * span;
|
|
92
|
+
};
|
|
93
|
+
const onPointerDown = (event) => {
|
|
94
|
+
if (event.button !== 0) return;
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
const v = valueAt(event.clientX);
|
|
97
|
+
const onFill = event.target.classList.contains("bl-range__fill");
|
|
98
|
+
const nearest = lo === hi ? v > lo ? 1 : 0 : Math.abs(v - lo) <= Math.abs(v - hi) ? 0 : 1;
|
|
99
|
+
const which = onFill ? "both" : nearest;
|
|
100
|
+
drag.current = { which, start: v, lo, hi };
|
|
101
|
+
setActive(which);
|
|
102
|
+
try {
|
|
103
|
+
trackRef.current.setPointerCapture(event.pointerId);
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
if (which !== "both") setEnd(which, v);
|
|
107
|
+
trackRef.current.querySelectorAll(".bl-range__thumb")[which === "both" ? 0 : which]?.focus({ preventScroll: true });
|
|
108
|
+
};
|
|
109
|
+
const onPointerMove = (event) => {
|
|
110
|
+
const d = drag.current;
|
|
111
|
+
if (!d) return;
|
|
112
|
+
const v = valueAt(event.clientX);
|
|
113
|
+
if (d.which === "both") {
|
|
114
|
+
const shift = Math.max(min - d.lo, Math.min(max - d.hi, v - d.start));
|
|
115
|
+
const nextLo = snap(d.lo + shift);
|
|
116
|
+
commit(nextLo, nextLo + (d.hi - d.lo));
|
|
117
|
+
} else setEnd(d.which, v);
|
|
118
|
+
};
|
|
119
|
+
const endDrag = () => {
|
|
120
|
+
drag.current = null;
|
|
121
|
+
setActive(null);
|
|
122
|
+
};
|
|
123
|
+
const onKeyDown = (event, which) => {
|
|
124
|
+
const big = Math.max(step, (max - min) / 10);
|
|
125
|
+
const current = which === 0 ? lo : hi;
|
|
126
|
+
const moves = { ArrowRight: step, ArrowUp: step, ArrowLeft: -step, ArrowDown: -step, PageUp: big, PageDown: -big };
|
|
127
|
+
let next;
|
|
128
|
+
if (event.key in moves) next = current + moves[event.key];
|
|
129
|
+
else if (event.key === "Home") next = which === 0 ? min : lo + minGap;
|
|
130
|
+
else if (event.key === "End") next = which === 0 ? hi - minGap : max;
|
|
131
|
+
else return;
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
setEnd(which, next);
|
|
134
|
+
};
|
|
135
|
+
const p = (v) => (v - min) / span;
|
|
136
|
+
const bins = histogram ?? [];
|
|
137
|
+
const peak = Math.max(1, ...bins);
|
|
138
|
+
const thumb = (which) => {
|
|
139
|
+
const v = which === 0 ? lo : hi;
|
|
140
|
+
return /* @__PURE__ */ jsx(
|
|
141
|
+
"span",
|
|
142
|
+
{
|
|
143
|
+
className: "bl-range__thumb",
|
|
144
|
+
role: "slider",
|
|
145
|
+
tabIndex: 0,
|
|
146
|
+
"aria-label": which === 0 ? `${label} minimum` : `${label} maximum`,
|
|
147
|
+
"aria-valuemin": which === 0 ? min : lo + minGap,
|
|
148
|
+
"aria-valuemax": which === 0 ? hi - minGap : max,
|
|
149
|
+
"aria-valuenow": v,
|
|
150
|
+
"aria-valuetext": format(v),
|
|
151
|
+
"data-active": active === which || active === "both" || void 0,
|
|
152
|
+
style: { "--p": p(v) },
|
|
153
|
+
onKeyDown: (event) => onKeyDown(event, which),
|
|
154
|
+
children: /* @__PURE__ */ jsx("span", { className: "bl-range__tip", "aria-hidden": "true", children: format(v) })
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
const field = (which, name) => /* @__PURE__ */ jsxs("label", { children: [
|
|
159
|
+
name,
|
|
160
|
+
/* @__PURE__ */ jsx(
|
|
161
|
+
"input",
|
|
162
|
+
{
|
|
163
|
+
type: "number",
|
|
164
|
+
inputMode: "decimal",
|
|
165
|
+
min,
|
|
166
|
+
max,
|
|
167
|
+
step,
|
|
168
|
+
value: drafts?.[which] ?? (which === 0 ? lo : hi),
|
|
169
|
+
onChange: (event) => setDrafts((d) => ({ ...d ?? {}, [which]: event.target.value })),
|
|
170
|
+
onBlur: (event) => {
|
|
171
|
+
if (event.target.value !== "") setEnd(which, Number(event.target.value));
|
|
172
|
+
setDrafts(null);
|
|
173
|
+
},
|
|
174
|
+
onKeyDown: (event) => {
|
|
175
|
+
if (event.key === "Enter") event.currentTarget.blur();
|
|
176
|
+
},
|
|
177
|
+
"aria-describedby": `${uid}-label`
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
] });
|
|
181
|
+
return /* @__PURE__ */ jsxs(
|
|
182
|
+
"div",
|
|
183
|
+
{
|
|
184
|
+
className: `bl-range ${className}`,
|
|
185
|
+
role: "group",
|
|
186
|
+
"aria-labelledby": `${uid}-label`,
|
|
187
|
+
"data-dragging": active ?? void 0,
|
|
188
|
+
style: {
|
|
189
|
+
"--bl-w": `${width}px`,
|
|
190
|
+
"--bl-thumb": `${thumbSize}px`,
|
|
191
|
+
"--bl-hist-h": `${histogramHeight}px`,
|
|
192
|
+
"--bl-lo": p(lo),
|
|
193
|
+
"--bl-hi": p(hi),
|
|
194
|
+
"--bl-bg": backgroundColor,
|
|
195
|
+
"--bl-field": fieldColor,
|
|
196
|
+
"--bl-ink": textColor,
|
|
197
|
+
"--bl-muted": mutedColor,
|
|
198
|
+
"--bl-dim": dimColor,
|
|
199
|
+
"--bl-track": trackColor,
|
|
200
|
+
"--bl-line": lineColor,
|
|
201
|
+
"--bl-accent": accentColor,
|
|
202
|
+
"--bl-font": fontFamily,
|
|
203
|
+
...style
|
|
204
|
+
},
|
|
205
|
+
children: [
|
|
206
|
+
/* @__PURE__ */ jsxs("span", { id: `${uid}-label`, className: "bl-range__label", children: [
|
|
207
|
+
label,
|
|
208
|
+
": ",
|
|
209
|
+
format(lo),
|
|
210
|
+
" \u2013 ",
|
|
211
|
+
format(hi)
|
|
212
|
+
] }),
|
|
213
|
+
bins.length > 0 && /* @__PURE__ */ jsx("div", { className: "bl-range__hist", "aria-hidden": "true", children: bins.map((count, i) => {
|
|
214
|
+
const binLo = min + i / bins.length * span;
|
|
215
|
+
const binHi = min + (i + 1) / bins.length * span;
|
|
216
|
+
return /* @__PURE__ */ jsx("span", { className: "bl-range__bar", "data-in": binHi > lo && binLo < hi || void 0, style: { height: `${count / peak * 100}%` } }, i);
|
|
217
|
+
}) }),
|
|
218
|
+
/* @__PURE__ */ jsxs("div", { ref: trackRef, className: "bl-range__track", onPointerDown, onPointerMove, onPointerUp: endDrag, onPointerCancel: endDrag, children: [
|
|
219
|
+
/* @__PURE__ */ jsx("div", { className: "bl-range__rail", children: /* @__PURE__ */ jsx("div", { className: "bl-range__fill" }) }),
|
|
220
|
+
thumb(0),
|
|
221
|
+
thumb(1)
|
|
222
|
+
] }),
|
|
223
|
+
showScale && /* @__PURE__ */ jsxs("div", { className: "bl-range__scale", "aria-hidden": "true", children: [
|
|
224
|
+
/* @__PURE__ */ jsx("span", { children: format(min) }),
|
|
225
|
+
/* @__PURE__ */ jsx("span", { children: format(max) })
|
|
226
|
+
] }),
|
|
227
|
+
showInputs && /* @__PURE__ */ jsxs("div", { className: "bl-range__inputs", children: [
|
|
228
|
+
field(0, "Minimum"),
|
|
229
|
+
/* @__PURE__ */ jsx("span", { className: "bl-range__dash", "aria-hidden": "true", children: "\u2013" }),
|
|
230
|
+
field(1, "Maximum")
|
|
231
|
+
] })
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
export {
|
|
237
|
+
RangeDual as default
|
|
238
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface RatingPipsProps {
|
|
3
|
+
value?: number;
|
|
4
|
+
defaultValue?: number;
|
|
5
|
+
onChange?: (value: number) => void;
|
|
6
|
+
/** How many pips. */
|
|
7
|
+
max?: number;
|
|
8
|
+
allowHalf?: boolean;
|
|
9
|
+
/** Clicking the current value clears it. */
|
|
10
|
+
clearable?: boolean;
|
|
11
|
+
/** A picture of the value instead of an input. */
|
|
12
|
+
readOnly?: boolean;
|
|
13
|
+
icon?: 'heart' | 'star' | 'gem';
|
|
14
|
+
/** Accessible name. */
|
|
15
|
+
label?: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
gap?: number;
|
|
18
|
+
fullColor?: string;
|
|
19
|
+
emptyColor?: string;
|
|
20
|
+
previewColor?: string;
|
|
21
|
+
accentColor?: string;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: CSSProperties;
|
|
24
|
+
}
|
|
25
|
+
export default function RatingPips({ value: controlled, defaultValue, onChange, max, allowHalf, clearable, readOnly, icon, label, size, gap, fullColor, emptyColor, previewColor, accentColor, className, style }: RatingPipsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-rating-pips";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-pips { display: inline-flex; gap: var(--bl-gap); padding: 4px; border-radius: 8px; outline: none; touch-action: manipulation; }
|
|
7
|
+
.bl-pips[data-interactive] { cursor: pointer; }
|
|
8
|
+
.bl-pips:focus-visible { box-shadow: 0 0 0 2px var(--bl-accent); }
|
|
9
|
+
.bl-pips__pip { position: relative; width: var(--bl-size); height: var(--bl-size); }
|
|
10
|
+
.bl-pips__pip svg { position: absolute; inset: 0; width: 100%; height: 100%; shape-rendering: crispEdges; }
|
|
11
|
+
.bl-pips__empty, .bl-pips__full { position: absolute; inset: 0; }
|
|
12
|
+
.bl-pips__empty { color: var(--bl-empty); }
|
|
13
|
+
.bl-pips__full { color: var(--bl-full); clip-path: inset(0 calc(100% - var(--fill) * 100%) 0 0); }
|
|
14
|
+
.bl-pips__pip[data-pop] .bl-pips__full { animation: bl-pips-pop 320ms steps(4); }
|
|
15
|
+
.bl-pips[data-preview] .bl-pips__full { color: var(--bl-preview); }
|
|
16
|
+
@keyframes bl-pips-pop { 40% { transform: scale(1.35) translateY(-12%); } }
|
|
17
|
+
@media (prefers-reduced-motion: reduce) { .bl-pips__pip[data-pop] .bl-pips__full { animation: none; } }
|
|
18
|
+
`;
|
|
19
|
+
function useStyles() {
|
|
20
|
+
useInsertionEffect(() => {
|
|
21
|
+
if (typeof document === "undefined") return;
|
|
22
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
23
|
+
style.textContent = CSS;
|
|
24
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
25
|
+
}, []);
|
|
26
|
+
}
|
|
27
|
+
const ICONS = {
|
|
28
|
+
heart: [".XX..XX.", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", ".XXXXXX.", "..XXXX..", "...XX...", "........"],
|
|
29
|
+
star: ["...XX...", "...XX...", "XXXXXXXX", ".XXXXXX.", "..XXXX..", ".XXXXXX.", ".XX..XX.", "X......X"],
|
|
30
|
+
gem: ["..XXXX..", ".XXXXXX.", "XXXXXXXX", "XXXXXXXX", ".XXXXXX.", "..XXXX..", "...XX...", "........"]
|
|
31
|
+
};
|
|
32
|
+
function Icon({ shape }) {
|
|
33
|
+
const rows = ICONS[shape] ?? ICONS.heart;
|
|
34
|
+
return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 8 8", "aria-hidden": "true", children: [
|
|
35
|
+
rows.map((row, y) => [...row].map((ch, x) => ch === "X" ? /* @__PURE__ */ jsx("rect", { x, y, width: "1", height: "1", fill: "currentColor" }, `${x}-${y}`) : null)),
|
|
36
|
+
/* @__PURE__ */ jsx("rect", { x: "1", y: "1", width: "1", height: "1", fill: "rgba(255,255,255,0.55)" })
|
|
37
|
+
] });
|
|
38
|
+
}
|
|
39
|
+
function RatingPips({
|
|
40
|
+
value: controlled,
|
|
41
|
+
defaultValue = 0,
|
|
42
|
+
onChange,
|
|
43
|
+
max = 5,
|
|
44
|
+
allowHalf = true,
|
|
45
|
+
clearable = true,
|
|
46
|
+
readOnly = false,
|
|
47
|
+
icon = "heart",
|
|
48
|
+
label = "Rating",
|
|
49
|
+
size = 28,
|
|
50
|
+
gap = 4,
|
|
51
|
+
fullColor = "#b13e53",
|
|
52
|
+
emptyColor = "#333c57",
|
|
53
|
+
previewColor = "#ef7d57",
|
|
54
|
+
accentColor = "#73eff7",
|
|
55
|
+
className = "",
|
|
56
|
+
style
|
|
57
|
+
}) {
|
|
58
|
+
useStyles();
|
|
59
|
+
const [inner, setInner] = useState(defaultValue);
|
|
60
|
+
const value = controlled ?? inner;
|
|
61
|
+
const [preview, setPreview] = useState(null);
|
|
62
|
+
const [popFrom, setPopFrom] = useState(-1);
|
|
63
|
+
const [round, setRound] = useState(0);
|
|
64
|
+
const rootRef = useRef(null);
|
|
65
|
+
const step = allowHalf ? 0.5 : 1;
|
|
66
|
+
const shown = preview ?? value;
|
|
67
|
+
const set = (next) => {
|
|
68
|
+
const v = Math.max(0, Math.min(max, next));
|
|
69
|
+
if (v === value) return;
|
|
70
|
+
if (v > value) {
|
|
71
|
+
setPopFrom(Math.floor(value));
|
|
72
|
+
setRound((r) => r + 1);
|
|
73
|
+
}
|
|
74
|
+
if (controlled === void 0) setInner(v);
|
|
75
|
+
onChange?.(v);
|
|
76
|
+
};
|
|
77
|
+
const at = (event) => {
|
|
78
|
+
const pips = [...rootRef.current.querySelectorAll(".bl-pips__pip")];
|
|
79
|
+
for (let i = 0; i < pips.length; i++) {
|
|
80
|
+
const r = pips[i].getBoundingClientRect();
|
|
81
|
+
if (event.clientX <= r.right + gap / 2) return allowHalf && event.clientX < r.left + r.width / 2 ? i + 0.5 : i + 1;
|
|
82
|
+
}
|
|
83
|
+
return max;
|
|
84
|
+
};
|
|
85
|
+
const say = (v) => `${v} of ${max}`;
|
|
86
|
+
if (readOnly) {
|
|
87
|
+
return /* @__PURE__ */ jsx("span", { className: `bl-pips ${className}`, role: "img", "aria-label": `${label}: ${say(value)}`, style: { "--bl-size": `${size}px`, "--bl-gap": `${gap}px`, "--bl-full": fullColor, "--bl-empty": emptyColor, "--bl-preview": previewColor, "--bl-accent": accentColor, ...style }, children: Array.from({ length: max }, (_, i) => /* @__PURE__ */ jsxs("span", { className: "bl-pips__pip", style: { "--fill": Math.max(0, Math.min(1, value - i)) }, children: [
|
|
88
|
+
/* @__PURE__ */ jsx("span", { className: "bl-pips__empty", children: /* @__PURE__ */ jsx(Icon, { shape: icon }) }),
|
|
89
|
+
/* @__PURE__ */ jsx("span", { className: "bl-pips__full", children: /* @__PURE__ */ jsx(Icon, { shape: icon }) })
|
|
90
|
+
] }, i)) });
|
|
91
|
+
}
|
|
92
|
+
return /* @__PURE__ */ jsx(
|
|
93
|
+
"span",
|
|
94
|
+
{
|
|
95
|
+
ref: rootRef,
|
|
96
|
+
className: `bl-pips ${className}`,
|
|
97
|
+
role: "slider",
|
|
98
|
+
tabIndex: 0,
|
|
99
|
+
"aria-label": label,
|
|
100
|
+
"aria-valuemin": 0,
|
|
101
|
+
"aria-valuemax": max,
|
|
102
|
+
"aria-valuenow": value,
|
|
103
|
+
"aria-valuetext": say(value),
|
|
104
|
+
"data-interactive": "",
|
|
105
|
+
"data-preview": preview !== null || void 0,
|
|
106
|
+
onPointerMove: (event) => event.pointerType === "mouse" && setPreview(at(event)),
|
|
107
|
+
onPointerLeave: () => setPreview(null),
|
|
108
|
+
onClick: (event) => {
|
|
109
|
+
const v = at(event);
|
|
110
|
+
set(clearable && v === value ? 0 : v);
|
|
111
|
+
setPreview(null);
|
|
112
|
+
},
|
|
113
|
+
onKeyDown: (event) => {
|
|
114
|
+
const moves = { ArrowRight: step, ArrowUp: step, ArrowLeft: -step, ArrowDown: -step, Home: -max, End: max };
|
|
115
|
+
if (moves[event.key] === void 0) return;
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
set(value + moves[event.key]);
|
|
118
|
+
},
|
|
119
|
+
style: { "--bl-size": `${size}px`, "--bl-gap": `${gap}px`, "--bl-full": fullColor, "--bl-empty": emptyColor, "--bl-preview": previewColor, "--bl-accent": accentColor, ...style },
|
|
120
|
+
children: Array.from({ length: max }, (_, i) => /* @__PURE__ */ jsxs("span", { className: "bl-pips__pip", "data-pop": i >= popFrom && i < value && round > 0 || void 0, style: { "--fill": Math.max(0, Math.min(1, shown - i)) }, children: [
|
|
121
|
+
/* @__PURE__ */ jsx("span", { className: "bl-pips__empty", children: /* @__PURE__ */ jsx(Icon, { shape: icon }) }),
|
|
122
|
+
/* @__PURE__ */ jsx("span", { className: "bl-pips__full", children: /* @__PURE__ */ jsx(Icon, { shape: icon }) })
|
|
123
|
+
] }, `${i}-${i >= popFrom && i < value ? round : 0}`))
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
RatingPips as default
|
|
129
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
export interface RetroHorizonProps {
|
|
3
|
+
/** Grid rows per second rolling toward the viewer; 0 holds still. */
|
|
4
|
+
speed?: number;
|
|
5
|
+
/** Horizon height as a share of the box (0–1). */
|
|
6
|
+
horizon?: number;
|
|
7
|
+
/** Each art pixel becomes this many screen pixels; 1 renders smooth. */
|
|
8
|
+
pixelSize?: number;
|
|
9
|
+
/** Spacing of the vertical grid lines, in art pixels. */
|
|
10
|
+
gridSpacing?: number;
|
|
11
|
+
/** Number of horizontal grid lines. */
|
|
12
|
+
gridLines?: number;
|
|
13
|
+
showSun?: boolean;
|
|
14
|
+
showMountains?: boolean;
|
|
15
|
+
/** Number of stars in the sky. */
|
|
16
|
+
stars?: number;
|
|
17
|
+
skyTop?: string;
|
|
18
|
+
skyBottom?: string;
|
|
19
|
+
sunTop?: string;
|
|
20
|
+
sunBottom?: string;
|
|
21
|
+
mountainColor?: string;
|
|
22
|
+
gridColor?: string;
|
|
23
|
+
floorColor?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
}
|
|
27
|
+
export default function RetroHorizon({ speed, horizon, pixelSize, gridSpacing, gridLines, showSun, showMountains, stars, skyTop, skyBottom, sunTop, sunBottom, mountainColor, gridColor, floorColor, className, style }: RetroHorizonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
function hexToRgb(hex) {
|
|
5
|
+
const v = hex.replace("#", "");
|
|
6
|
+
const full = v.length === 3 ? v.replace(/./g, (c) => c + c) : v.slice(0, 6);
|
|
7
|
+
const n = parseInt(full, 16);
|
|
8
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
9
|
+
}
|
|
10
|
+
const mix = (a, b, t) => {
|
|
11
|
+
const [r1, g1, b1] = hexToRgb(a);
|
|
12
|
+
const [r2, g2, b2] = hexToRgb(b);
|
|
13
|
+
return `rgb(${Math.round(r1 + (r2 - r1) * t)},${Math.round(g1 + (g2 - g1) * t)},${Math.round(b1 + (b2 - b1) * t)})`;
|
|
14
|
+
};
|
|
15
|
+
function seeded(seed) {
|
|
16
|
+
let s = seed;
|
|
17
|
+
return () => {
|
|
18
|
+
s = s * 16807 % 2147483647;
|
|
19
|
+
return s / 2147483647;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function RetroHorizon({
|
|
23
|
+
speed = 1,
|
|
24
|
+
horizon = 0.55,
|
|
25
|
+
pixelSize = 3,
|
|
26
|
+
gridSpacing = 12,
|
|
27
|
+
gridLines = 24,
|
|
28
|
+
showSun = true,
|
|
29
|
+
showMountains = true,
|
|
30
|
+
stars = 60,
|
|
31
|
+
skyTop = "#0b0b14",
|
|
32
|
+
skyBottom = "#5d275d",
|
|
33
|
+
sunTop = "#ffcd75",
|
|
34
|
+
sunBottom = "#b13e53",
|
|
35
|
+
mountainColor = "#1a1c2c",
|
|
36
|
+
gridColor = "#73eff7",
|
|
37
|
+
floorColor = "#0b0b14",
|
|
38
|
+
className = "",
|
|
39
|
+
style
|
|
40
|
+
}) {
|
|
41
|
+
const wrapRef = useRef(null);
|
|
42
|
+
const canvasRef = useRef(null);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const wrap = wrapRef.current;
|
|
45
|
+
const canvas = canvasRef.current;
|
|
46
|
+
const ctx = canvas.getContext("2d");
|
|
47
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
48
|
+
let w = 0;
|
|
49
|
+
let h = 0;
|
|
50
|
+
let frame = 0;
|
|
51
|
+
let visible = true;
|
|
52
|
+
let offset = 0;
|
|
53
|
+
let last = performance.now();
|
|
54
|
+
let starField = [];
|
|
55
|
+
let ridge = [];
|
|
56
|
+
const layout = () => {
|
|
57
|
+
w = Math.max(40, Math.round(wrap.clientWidth / pixelSize));
|
|
58
|
+
h = Math.max(30, Math.round(wrap.clientHeight / pixelSize));
|
|
59
|
+
canvas.width = w;
|
|
60
|
+
canvas.height = h;
|
|
61
|
+
const rand = seeded(7);
|
|
62
|
+
const horizonY = Math.round(h * horizon);
|
|
63
|
+
starField = Array.from({ length: stars }, () => [Math.floor(rand() * w), Math.floor(rand() * horizonY * 0.85), rand()]);
|
|
64
|
+
ridge = [];
|
|
65
|
+
let y = 0;
|
|
66
|
+
for (let x = 0; x < w; x++) {
|
|
67
|
+
y += (rand() - 0.5) * 2.2;
|
|
68
|
+
y = Math.max(-h * 0.12, Math.min(0, y * 0.97));
|
|
69
|
+
ridge.push(Math.round(y));
|
|
70
|
+
}
|
|
71
|
+
draw();
|
|
72
|
+
};
|
|
73
|
+
const draw = () => {
|
|
74
|
+
const horizonY = Math.round(h * horizon);
|
|
75
|
+
const bands = 10;
|
|
76
|
+
for (let i = 0; i < bands; i++) {
|
|
77
|
+
ctx.fillStyle = mix(skyTop, skyBottom, i / (bands - 1));
|
|
78
|
+
ctx.fillRect(0, Math.floor(i / bands * horizonY), w, Math.ceil(horizonY / bands) + 1);
|
|
79
|
+
}
|
|
80
|
+
for (const [x, y, twinkle] of starField) {
|
|
81
|
+
const t = reduced ? 1 : 0.5 + 0.5 * Math.sin(last / 600 + twinkle * 20);
|
|
82
|
+
ctx.fillStyle = `rgba(244,244,244,${0.3 + t * 0.6})`;
|
|
83
|
+
ctx.fillRect(x, y, 1, 1);
|
|
84
|
+
}
|
|
85
|
+
if (showSun) {
|
|
86
|
+
const r = Math.round(Math.min(w, h) * 0.22);
|
|
87
|
+
const cx = Math.round(w / 2);
|
|
88
|
+
const cy = horizonY - Math.round(r * 0.35);
|
|
89
|
+
for (let y = -r; y <= r; y++) {
|
|
90
|
+
const py = cy + y;
|
|
91
|
+
if (py >= horizonY) break;
|
|
92
|
+
const t = (y + r) / (2 * r);
|
|
93
|
+
if (y > 0) {
|
|
94
|
+
const stripe = Math.floor(y / r * 6);
|
|
95
|
+
const gap = 1 + Math.floor(stripe / 2);
|
|
96
|
+
if (y % (gap + 3) < gap) continue;
|
|
97
|
+
}
|
|
98
|
+
const half = Math.round(Math.sqrt(r * r - y * y));
|
|
99
|
+
ctx.fillStyle = mix(sunTop, sunBottom, t);
|
|
100
|
+
ctx.fillRect(cx - half, py, half * 2, 1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (showMountains) {
|
|
104
|
+
ctx.fillStyle = mountainColor;
|
|
105
|
+
ridge.forEach((dy, x) => {
|
|
106
|
+
const peak = Math.round(Math.abs(Math.sin(x * 0.045)) * h * 0.07 + Math.abs(Math.sin(x * 0.13 + 1)) * h * 0.03);
|
|
107
|
+
const top = horizonY - peak + dy;
|
|
108
|
+
ctx.fillRect(x, top, 1, horizonY - top);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
ctx.fillStyle = floorColor;
|
|
112
|
+
ctx.fillRect(0, horizonY, w, h - horizonY);
|
|
113
|
+
ctx.fillStyle = gridColor;
|
|
114
|
+
const depth = h - horizonY;
|
|
115
|
+
for (let i = 0; i < gridLines; i++) {
|
|
116
|
+
const z = (i + offset % 1) / gridLines;
|
|
117
|
+
const y = horizonY + Math.round(Math.pow(z, 2.2) * depth);
|
|
118
|
+
if (y <= horizonY || y >= h) continue;
|
|
119
|
+
ctx.globalAlpha = 0.25 + z * 0.75;
|
|
120
|
+
ctx.fillRect(0, y, w, 1);
|
|
121
|
+
}
|
|
122
|
+
ctx.globalAlpha = 1;
|
|
123
|
+
const vx = w / 2;
|
|
124
|
+
const count = Math.ceil(w / gridSpacing) + 6;
|
|
125
|
+
for (let i = -count; i <= count; i++) {
|
|
126
|
+
const bottomX = vx + i * gridSpacing * 3;
|
|
127
|
+
for (let y = horizonY + 1; y < h; y++) {
|
|
128
|
+
const t = (y - horizonY) / depth;
|
|
129
|
+
const x = Math.round(vx + (bottomX - vx) * t);
|
|
130
|
+
if (x < 0 || x >= w) continue;
|
|
131
|
+
ctx.globalAlpha = 0.2 + t * 0.8;
|
|
132
|
+
ctx.fillRect(x, y, 1, 1);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
ctx.globalAlpha = 1;
|
|
136
|
+
ctx.fillStyle = sunTop;
|
|
137
|
+
ctx.fillRect(0, horizonY, w, 1);
|
|
138
|
+
};
|
|
139
|
+
const tick = (now) => {
|
|
140
|
+
frame = 0;
|
|
141
|
+
const dt = Math.min(0.1, (now - last) / 1e3);
|
|
142
|
+
last = now;
|
|
143
|
+
offset += dt * speed;
|
|
144
|
+
draw();
|
|
145
|
+
if (visible) frame = requestAnimationFrame(tick);
|
|
146
|
+
};
|
|
147
|
+
const resize = new ResizeObserver(layout);
|
|
148
|
+
resize.observe(wrap);
|
|
149
|
+
const io = new IntersectionObserver(([entry]) => {
|
|
150
|
+
visible = entry.isIntersecting;
|
|
151
|
+
if (visible && !frame && !reduced && speed) {
|
|
152
|
+
last = performance.now();
|
|
153
|
+
frame = requestAnimationFrame(tick);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
io.observe(wrap);
|
|
157
|
+
layout();
|
|
158
|
+
if (!reduced && speed) frame = requestAnimationFrame(tick);
|
|
159
|
+
return () => {
|
|
160
|
+
cancelAnimationFrame(frame);
|
|
161
|
+
resize.disconnect();
|
|
162
|
+
io.disconnect();
|
|
163
|
+
};
|
|
164
|
+
}, [speed, horizon, pixelSize, gridSpacing, gridLines, showSun, showMountains, stars, skyTop, skyBottom, sunTop, sunBottom, mountainColor, gridColor, floorColor]);
|
|
165
|
+
return /* @__PURE__ */ jsx("div", { ref: wrapRef, className, style: { position: "relative", width: "100%", height: "100%", overflow: "hidden", ...style }, children: /* @__PURE__ */ jsx("canvas", { ref: canvasRef, "aria-hidden": "true", style: { position: "absolute", inset: 0, width: "100%", height: "100%", imageRendering: pixelSize > 1 ? "pixelated" : "auto" } }) });
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
RetroHorizon as default
|
|
169
|
+
};
|
package/dist/Reveal.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type CSSProperties, type ElementType, type ReactNode } from 'react';
|
|
2
|
+
export interface RevealProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
as?: ElementType;
|
|
5
|
+
/** The entrance; blocks dissolves a grid of cover blocks in a scattered order. */
|
|
6
|
+
effect?: 'fade' | 'rise' | 'zoom' | 'wipe' | 'blocks';
|
|
7
|
+
/** Reveal each direct child in turn. */
|
|
8
|
+
cascade?: boolean;
|
|
9
|
+
trigger?: 'view' | 'mount';
|
|
10
|
+
/** false hides it again when scrolled away. */
|
|
11
|
+
once?: boolean;
|
|
12
|
+
threshold?: number;
|
|
13
|
+
/** In ms. */
|
|
14
|
+
duration?: number;
|
|
15
|
+
delay?: number;
|
|
16
|
+
/** Delay between cascading children, in ms. */
|
|
17
|
+
stagger?: number;
|
|
18
|
+
/** Rise distance in px. */
|
|
19
|
+
distance?: number;
|
|
20
|
+
/** How many steps the wipe takes. */
|
|
21
|
+
steps?: number;
|
|
22
|
+
/** The blocks grid, [columns, rows]. */
|
|
23
|
+
blocks?: [number, number];
|
|
24
|
+
/** Block colour: match the background behind the content. */
|
|
25
|
+
coverColor?: string;
|
|
26
|
+
onReveal?: () => void;
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: CSSProperties;
|
|
29
|
+
}
|
|
30
|
+
export default function Reveal({ children, as: Tag, effect, cascade, trigger, once, threshold, duration, delay, stagger, distance, steps, blocks, coverColor, onReveal, className, style }: RevealProps): import("react").JSX.Element;
|