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,307 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-code-showcase";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-code { width: 100%; max-width: var(--bl-w); margin: 0 auto; overflow: hidden; border-radius: var(--bl-radius); background: var(--bl-bg); color: var(--bl-ink); box-shadow: 0 0 0 1px var(--bl-line), 0 24px 60px -28px rgba(0,0,0,0.8); font-family: var(--bl-ui-font); }
|
|
7
|
+
.bl-code__bar { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 0 10px 0 14px; background: var(--bl-bar); box-shadow: inset 0 -1px 0 var(--bl-line); }
|
|
8
|
+
.bl-code__lights { display: flex; gap: 6px; }
|
|
9
|
+
.bl-code__lights i { width: 10px; height: 10px; border-radius: 50%; background: var(--bl-line); }
|
|
10
|
+
.bl-code__tabs { display: flex; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
|
|
11
|
+
.bl-code__tab { position: relative; flex: 0 0 auto; padding: 11px 12px; border: 0; background: transparent; color: var(--bl-muted); font: inherit; font-size: 13px; cursor: pointer; }
|
|
12
|
+
.bl-code__tab:hover { color: var(--bl-ink); }
|
|
13
|
+
.bl-code__tab[aria-selected="true"] { color: var(--bl-ink); }
|
|
14
|
+
.bl-code__tab::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; border-radius: 2px; background: var(--bl-accent); transform: scaleX(0); transition: transform 240ms cubic-bezier(.2,.9,.25,1); }
|
|
15
|
+
.bl-code__tab[aria-selected="true"]::after { transform: scaleX(1); }
|
|
16
|
+
.bl-code__tab:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: -4px; border-radius: 6px; }
|
|
17
|
+
.bl-code__tab[data-progress]::before { content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; background: color-mix(in srgb, var(--bl-accent) 35%, transparent); transform-origin: left; animation: bl-code-progress var(--bl-auto) linear both; }
|
|
18
|
+
.bl-code[data-hold] .bl-code__tab[data-progress]::before { animation-play-state: paused; }
|
|
19
|
+
.bl-code__copy { flex: 0 0 auto; padding: 5px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--bl-muted); font: inherit; font-size: 12px; cursor: pointer; }
|
|
20
|
+
.bl-code__copy:hover { background: var(--bl-line); color: var(--bl-ink); }
|
|
21
|
+
.bl-code__copy:focus-visible { outline: 2px solid var(--bl-accent); }
|
|
22
|
+
.bl-code__pre { margin: 0; padding: 14px 0; overflow-x: auto; font-family: var(--bl-font); font-size: var(--bl-size); line-height: var(--bl-lh); tab-size: 2; }
|
|
23
|
+
.bl-code__code { display: block; min-width: max-content; }
|
|
24
|
+
.bl-code__line { display: grid; grid-template-columns: 3.2em 1.4em auto; height: var(--bl-lh); overflow: hidden; white-space: pre; padding-right: 18px; }
|
|
25
|
+
.bl-code__num { color: var(--bl-dim); text-align: right; user-select: none; -webkit-user-select: none; }
|
|
26
|
+
.bl-code__sign { color: var(--bl-dim); text-align: center; user-select: none; -webkit-user-select: none; }
|
|
27
|
+
.bl-code__line[data-mark="add"] { background: color-mix(in srgb, var(--bl-add) 14%, transparent); }
|
|
28
|
+
.bl-code__line[data-mark="add"] .bl-code__sign { color: var(--bl-add); }
|
|
29
|
+
.bl-code__line[data-mark="del"] { background: color-mix(in srgb, var(--bl-del) 14%, transparent); }
|
|
30
|
+
.bl-code__line[data-mark="del"] .bl-code__sign { color: var(--bl-del); }
|
|
31
|
+
.bl-code__line[data-mark="del"] .bl-code__text { opacity: 0.7; }
|
|
32
|
+
.bl-code__line[data-focus] { background: color-mix(in srgb, var(--bl-accent) 10%, transparent); box-shadow: inset 2px 0 0 var(--bl-accent); }
|
|
33
|
+
.bl-code[data-reveal="wait"] .bl-code__line { opacity: 0; }
|
|
34
|
+
.bl-code[data-reveal="run"] .bl-code__line { animation: bl-code-reveal 380ms cubic-bezier(.2,.9,.25,1) both; animation-delay: calc(var(--i) * var(--bl-stagger)); }
|
|
35
|
+
.bl-code__line[data-state="out"] { animation: bl-code-out var(--bl-out) cubic-bezier(.4,0,.2,1) both; }
|
|
36
|
+
.bl-code__line[data-state="in"] { animation: bl-code-in var(--bl-in) cubic-bezier(.2,.9,.25,1) var(--bl-out) both; }
|
|
37
|
+
.bl-code .t-k { color: var(--bl-keyword); }
|
|
38
|
+
.bl-code .t-s { color: var(--bl-string); }
|
|
39
|
+
.bl-code .t-c { color: var(--bl-dim); font-style: italic; }
|
|
40
|
+
.bl-code .t-n { color: var(--bl-number); }
|
|
41
|
+
.bl-code .t-t { color: var(--bl-tag); }
|
|
42
|
+
.bl-code .t-f { color: var(--bl-fn); }
|
|
43
|
+
.bl-code__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
44
|
+
@keyframes bl-code-reveal { from { opacity: 0; transform: translateY(6px); } }
|
|
45
|
+
@keyframes bl-code-out { to { height: 0; opacity: 0; transform: translateX(-10px); } }
|
|
46
|
+
@keyframes bl-code-in { from { height: 0; opacity: 0; transform: translateX(10px); } }
|
|
47
|
+
@keyframes bl-code-progress { from { transform: scaleX(0); } }
|
|
48
|
+
@media (prefers-reduced-motion: reduce) {
|
|
49
|
+
.bl-code[data-reveal] .bl-code__line, .bl-code__line[data-state] { animation: none; opacity: 1; }
|
|
50
|
+
.bl-code__tab::after { transition: none; }
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
function useStyles() {
|
|
54
|
+
useInsertionEffect(() => {
|
|
55
|
+
if (typeof document === "undefined") return;
|
|
56
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
57
|
+
style.textContent = CSS;
|
|
58
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
59
|
+
}, []);
|
|
60
|
+
}
|
|
61
|
+
const TOKENS = /(\/\/.*$|#.*$)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|(<\/?[A-Za-z][\w.-]*|\/?>)|\b(import|from|export|default|const|let|var|function|return|if|else|for|while|await|async|new|class|extends|type|interface|as|of|in|true|false|null|undefined|this)\b|\b(\d+(?:\.\d+)?)\b|\b([A-Za-z_$][\w$]*)(?=\()/gm;
|
|
62
|
+
const CLASSES = ["t-c", "t-s", "t-t", "t-k", "t-n", "t-f"];
|
|
63
|
+
function highlight(line) {
|
|
64
|
+
const out = [];
|
|
65
|
+
let last = 0;
|
|
66
|
+
for (const match of line.matchAll(TOKENS)) {
|
|
67
|
+
const index = match.index ?? 0;
|
|
68
|
+
if (index > last) out.push(line.slice(last, index));
|
|
69
|
+
const group = match.slice(1).findIndex(Boolean);
|
|
70
|
+
out.push(
|
|
71
|
+
/* @__PURE__ */ jsx("span", { className: CLASSES[group], children: match[0] }, index)
|
|
72
|
+
);
|
|
73
|
+
last = index + match[0].length;
|
|
74
|
+
}
|
|
75
|
+
if (last < line.length) out.push(line.slice(last));
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
function diffLines(a, b) {
|
|
79
|
+
const dp = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));
|
|
80
|
+
for (let i2 = a.length - 1; i2 >= 0; i2--) {
|
|
81
|
+
for (let j2 = b.length - 1; j2 >= 0; j2--) dp[i2][j2] = a[i2] === b[j2] ? dp[i2 + 1][j2 + 1] + 1 : Math.max(dp[i2 + 1][j2], dp[i2][j2 + 1]);
|
|
82
|
+
}
|
|
83
|
+
const ops = [];
|
|
84
|
+
let i = 0;
|
|
85
|
+
let j = 0;
|
|
86
|
+
while (i < a.length && j < b.length) {
|
|
87
|
+
if (a[i] === b[j]) ops.push({ type: "keep", from: i++, to: j++ });
|
|
88
|
+
else if (dp[i + 1][j] >= dp[i][j + 1]) ops.push({ type: "del", from: i++, to: -1 });
|
|
89
|
+
else ops.push({ type: "add", from: -1, to: j++ });
|
|
90
|
+
}
|
|
91
|
+
while (i < a.length) ops.push({ type: "del", from: i++, to: -1 });
|
|
92
|
+
while (j < b.length) ops.push({ type: "add", from: -1, to: j++ });
|
|
93
|
+
return ops;
|
|
94
|
+
}
|
|
95
|
+
const splitCode = (code) => code.replace(/\n$/, "").split("\n");
|
|
96
|
+
function CodeShowcase({
|
|
97
|
+
files = [],
|
|
98
|
+
defaultFile = 0,
|
|
99
|
+
file: controlled,
|
|
100
|
+
onFileChange,
|
|
101
|
+
autoPlay = 0,
|
|
102
|
+
reveal = true,
|
|
103
|
+
stagger = 45,
|
|
104
|
+
morphDuration = 260,
|
|
105
|
+
showChrome = true,
|
|
106
|
+
showLineNumbers = true,
|
|
107
|
+
copyable = true,
|
|
108
|
+
width = 720,
|
|
109
|
+
fontSize = 14,
|
|
110
|
+
backgroundColor = "#0b0b14",
|
|
111
|
+
barColor = "#1a1c2c",
|
|
112
|
+
textColor = "#f4f4f4",
|
|
113
|
+
mutedColor = "#94b0c2",
|
|
114
|
+
dimColor = "#566c86",
|
|
115
|
+
lineColor = "#333c57",
|
|
116
|
+
accentColor = "#73eff7",
|
|
117
|
+
keywordColor = "#ef7d57",
|
|
118
|
+
stringColor = "#a7f070",
|
|
119
|
+
numberColor = "#ffcd75",
|
|
120
|
+
tagColor = "#41a6f6",
|
|
121
|
+
functionColor = "#73eff7",
|
|
122
|
+
addColor = "#38b764",
|
|
123
|
+
removeColor = "#b13e53",
|
|
124
|
+
radius = 12,
|
|
125
|
+
fontFamily = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
126
|
+
uiFontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
127
|
+
label = "Code example",
|
|
128
|
+
className = "",
|
|
129
|
+
style
|
|
130
|
+
}) {
|
|
131
|
+
useStyles();
|
|
132
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
133
|
+
const [inner, setInner] = useState(defaultFile);
|
|
134
|
+
const active = Math.min(files.length - 1, Math.max(0, controlled ?? inner));
|
|
135
|
+
const nextKey = useRef(0);
|
|
136
|
+
const keyed = (code) => splitCode(code).map((text) => ({ key: nextKey.current++, text, state: "idle" }));
|
|
137
|
+
const [rows, setRows] = useState(() => files[active] ? keyed(files[active].code) : []);
|
|
138
|
+
const [revealState, setRevealState] = useState(reveal ? "wait" : "done");
|
|
139
|
+
const [hold, setHold] = useState(false);
|
|
140
|
+
const [auto, setAuto] = useState(autoPlay > 0);
|
|
141
|
+
const [copied, setCopied] = useState(false);
|
|
142
|
+
const rootRef = useRef(null);
|
|
143
|
+
const tabRefs = useRef([]);
|
|
144
|
+
const shown = useRef(active);
|
|
145
|
+
const rowsRef = useRef(rows);
|
|
146
|
+
rowsRef.current = rows;
|
|
147
|
+
const select = (index, fromUser = true) => {
|
|
148
|
+
if (fromUser) setAuto(false);
|
|
149
|
+
if (controlled === void 0) setInner(index);
|
|
150
|
+
onFileChange?.(index);
|
|
151
|
+
};
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (shown.current === active || !files[active]) return void 0;
|
|
154
|
+
shown.current = active;
|
|
155
|
+
const target = splitCode(files[active].code);
|
|
156
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
157
|
+
const live = rowsRef.current.filter((row) => row.state !== "out");
|
|
158
|
+
const merged = diffLines(live.map((row) => row.text), target).map(
|
|
159
|
+
(op) => op.type === "keep" ? { ...live[op.from], state: "idle" } : op.type === "del" ? { ...live[op.from], state: "out" } : { key: nextKey.current++, text: target[op.to], state: "in" }
|
|
160
|
+
);
|
|
161
|
+
const settled = merged.filter((row) => row.state !== "out").map((row) => ({ ...row, state: "idle" }));
|
|
162
|
+
setRows(reduced ? settled : merged);
|
|
163
|
+
if (reduced) return void 0;
|
|
164
|
+
const timer = setTimeout(() => setRows(settled), morphDuration * 2 + 40);
|
|
165
|
+
return () => clearTimeout(timer);
|
|
166
|
+
}, [active, files]);
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (revealState !== "wait") return void 0;
|
|
169
|
+
const io = new IntersectionObserver(([entry]) => {
|
|
170
|
+
if (!entry.isIntersecting) return;
|
|
171
|
+
io.disconnect();
|
|
172
|
+
setRevealState("run");
|
|
173
|
+
}, { threshold: 0.3 });
|
|
174
|
+
io.observe(rootRef.current);
|
|
175
|
+
return () => io.disconnect();
|
|
176
|
+
}, [revealState]);
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
if (revealState !== "run") return void 0;
|
|
179
|
+
const timer = setTimeout(() => setRevealState("done"), rows.length * stagger + 400);
|
|
180
|
+
return () => clearTimeout(timer);
|
|
181
|
+
}, [revealState]);
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (!auto || hold || autoPlay <= 0 || files.length < 2 || revealState === "wait") return void 0;
|
|
184
|
+
const timer = setTimeout(() => select((active + 1) % files.length, false), autoPlay);
|
|
185
|
+
return () => clearTimeout(timer);
|
|
186
|
+
}, [auto, hold, autoPlay, active, files.length, revealState]);
|
|
187
|
+
const onTabKey = (event, index) => {
|
|
188
|
+
const keys = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: files.length - 1 };
|
|
189
|
+
if (!(event.key in keys)) return;
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
const next = (keys[event.key] + files.length) % files.length;
|
|
192
|
+
select(next);
|
|
193
|
+
tabRefs.current[next]?.focus();
|
|
194
|
+
};
|
|
195
|
+
const file = files[active];
|
|
196
|
+
const copy = async () => {
|
|
197
|
+
if (!file) return;
|
|
198
|
+
const text = file.diff ? splitCode(file.code).filter((line) => !line.startsWith("-")).map((line) => line.replace(/^[+ ]/, "")).join("\n") : file.code;
|
|
199
|
+
try {
|
|
200
|
+
await navigator.clipboard.writeText(text);
|
|
201
|
+
setCopied(true);
|
|
202
|
+
setTimeout(() => setCopied(false), 1600);
|
|
203
|
+
} catch {
|
|
204
|
+
setCopied(false);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const focusLines = new Set(file?.highlight ?? []);
|
|
208
|
+
let number = 0;
|
|
209
|
+
return /* @__PURE__ */ jsxs(
|
|
210
|
+
"div",
|
|
211
|
+
{
|
|
212
|
+
ref: rootRef,
|
|
213
|
+
className: `bl-code ${className}`,
|
|
214
|
+
"data-reveal": revealState === "done" ? void 0 : revealState,
|
|
215
|
+
"data-hold": hold || void 0,
|
|
216
|
+
onPointerEnter: () => setHold(true),
|
|
217
|
+
onPointerLeave: () => setHold(false),
|
|
218
|
+
onFocus: () => setHold(true),
|
|
219
|
+
onBlur: (event) => {
|
|
220
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setHold(false);
|
|
221
|
+
},
|
|
222
|
+
style: {
|
|
223
|
+
"--bl-w": `${width}px`,
|
|
224
|
+
"--bl-size": `${fontSize}px`,
|
|
225
|
+
"--bl-lh": "1.7em",
|
|
226
|
+
"--bl-stagger": `${stagger}ms`,
|
|
227
|
+
"--bl-out": `${morphDuration}ms`,
|
|
228
|
+
"--bl-in": `${morphDuration}ms`,
|
|
229
|
+
"--bl-auto": `${autoPlay}ms`,
|
|
230
|
+
"--bl-radius": `${radius}px`,
|
|
231
|
+
"--bl-bg": backgroundColor,
|
|
232
|
+
"--bl-bar": barColor,
|
|
233
|
+
"--bl-ink": textColor,
|
|
234
|
+
"--bl-muted": mutedColor,
|
|
235
|
+
"--bl-dim": dimColor,
|
|
236
|
+
"--bl-line": lineColor,
|
|
237
|
+
"--bl-accent": accentColor,
|
|
238
|
+
"--bl-keyword": keywordColor,
|
|
239
|
+
"--bl-string": stringColor,
|
|
240
|
+
"--bl-number": numberColor,
|
|
241
|
+
"--bl-tag": tagColor,
|
|
242
|
+
"--bl-fn": functionColor,
|
|
243
|
+
"--bl-add": addColor,
|
|
244
|
+
"--bl-del": removeColor,
|
|
245
|
+
"--bl-font": fontFamily,
|
|
246
|
+
"--bl-ui-font": uiFontFamily,
|
|
247
|
+
...style
|
|
248
|
+
},
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-code__bar", children: [
|
|
251
|
+
showChrome && /* @__PURE__ */ jsxs("span", { className: "bl-code__lights", "aria-hidden": "true", children: [
|
|
252
|
+
/* @__PURE__ */ jsx("i", {}),
|
|
253
|
+
/* @__PURE__ */ jsx("i", {}),
|
|
254
|
+
/* @__PURE__ */ jsx("i", {})
|
|
255
|
+
] }),
|
|
256
|
+
/* @__PURE__ */ jsx("div", { className: "bl-code__tabs", role: "tablist", "aria-label": label, children: files.map((f, i) => /* @__PURE__ */ jsx(
|
|
257
|
+
"button",
|
|
258
|
+
{
|
|
259
|
+
ref: (node) => {
|
|
260
|
+
tabRefs.current[i] = node;
|
|
261
|
+
},
|
|
262
|
+
type: "button",
|
|
263
|
+
role: "tab",
|
|
264
|
+
id: `${uid}-tab-${i}`,
|
|
265
|
+
className: "bl-code__tab",
|
|
266
|
+
"aria-selected": i === active,
|
|
267
|
+
"aria-controls": `${uid}-panel`,
|
|
268
|
+
tabIndex: i === active ? 0 : -1,
|
|
269
|
+
"data-progress": auto && autoPlay > 0 && files.length > 1 && i === active && revealState !== "wait" || void 0,
|
|
270
|
+
onClick: () => select(i),
|
|
271
|
+
onKeyDown: (event) => onTabKey(event, i),
|
|
272
|
+
children: f.name
|
|
273
|
+
},
|
|
274
|
+
f.name
|
|
275
|
+
)) }),
|
|
276
|
+
copyable && /* @__PURE__ */ jsx("button", { type: "button", className: "bl-code__copy", onClick: copy, children: copied ? "Copied" : "Copy" }),
|
|
277
|
+
/* @__PURE__ */ jsx("span", { className: "bl-code__sr", "aria-live": "polite", children: copied ? "Code copied to clipboard" : "" })
|
|
278
|
+
] }),
|
|
279
|
+
/* @__PURE__ */ jsx("pre", { className: "bl-code__pre", id: `${uid}-panel`, role: "tabpanel", "aria-labelledby": `${uid}-tab-${active}`, tabIndex: 0, children: /* @__PURE__ */ jsx("code", { className: "bl-code__code", children: rows.map((row, i) => {
|
|
280
|
+
const mark = file?.diff ? row.text.startsWith("+") ? "add" : row.text.startsWith("-") ? "del" : null : null;
|
|
281
|
+
const text = file?.diff ? row.text.replace(/^[+\- ]/, "") : row.text;
|
|
282
|
+
if (row.state !== "out") number++;
|
|
283
|
+
return /* @__PURE__ */ jsxs(
|
|
284
|
+
"span",
|
|
285
|
+
{
|
|
286
|
+
className: "bl-code__line",
|
|
287
|
+
"data-state": row.state === "idle" ? void 0 : row.state,
|
|
288
|
+
"data-mark": mark ?? void 0,
|
|
289
|
+
"data-focus": row.state !== "out" && focusLines.has(number) || void 0,
|
|
290
|
+
style: { "--i": i },
|
|
291
|
+
children: [
|
|
292
|
+
/* @__PURE__ */ jsx("span", { className: "bl-code__num", "aria-hidden": "true", children: showLineNumbers && row.state !== "out" ? number : "" }),
|
|
293
|
+
/* @__PURE__ */ jsx("span", { className: "bl-code__sign", "aria-hidden": "true", children: mark === "add" ? "+" : mark === "del" ? "\u2212" : "" }),
|
|
294
|
+
/* @__PURE__ */ jsx("span", { className: "bl-code__text", children: highlight(text) }),
|
|
295
|
+
"\n"
|
|
296
|
+
]
|
|
297
|
+
},
|
|
298
|
+
row.key
|
|
299
|
+
);
|
|
300
|
+
}) }) })
|
|
301
|
+
]
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
export {
|
|
306
|
+
CodeShowcase as default
|
|
307
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
EyeDropper: new () => {
|
|
5
|
+
open: () => Promise<{
|
|
6
|
+
sRGBHex: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export type RGB = [number, number, number];
|
|
12
|
+
export interface HSV {
|
|
13
|
+
h: number;
|
|
14
|
+
s: number;
|
|
15
|
+
v: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ColorDialProps {
|
|
18
|
+
/** Hex color; always emitted as #rrggbb. */
|
|
19
|
+
value?: string;
|
|
20
|
+
defaultValue?: string;
|
|
21
|
+
onValueChange?: (hex: string) => void;
|
|
22
|
+
swatches?: string[];
|
|
23
|
+
size?: number;
|
|
24
|
+
ringWidth?: number;
|
|
25
|
+
/** Show the screen eyedropper where supported. */
|
|
26
|
+
eyedropper?: boolean;
|
|
27
|
+
label?: string;
|
|
28
|
+
backgroundColor?: string;
|
|
29
|
+
fieldColor?: string;
|
|
30
|
+
textColor?: string;
|
|
31
|
+
mutedColor?: string;
|
|
32
|
+
lineColor?: string;
|
|
33
|
+
accentColor?: string;
|
|
34
|
+
errorColor?: string;
|
|
35
|
+
fontFamily?: string;
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
}
|
|
39
|
+
export declare function parseHex(text: string): RGB | null;
|
|
40
|
+
export declare function hsvToRgb(h: number, s: number, v: number): RGB;
|
|
41
|
+
export declare function rgbToHsv([r, g, b]: number[]): HSV;
|
|
42
|
+
export default function ColorDial({ value, defaultValue, onValueChange, swatches, size, ringWidth, eyedropper, label, backgroundColor, fieldColor, textColor, mutedColor, lineColor, accentColor, errorColor, fontFamily, className, style }: ColorDialProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useInsertionEffect, useRef, useState } from "react";
|
|
4
|
+
const STYLE_ID = "bl-color-dial";
|
|
5
|
+
const CSS = `
|
|
6
|
+
.bl-dial { display: grid; justify-items: center; gap: 14px; width: min(var(--bl-size), 100%); font-family: var(--bl-font); color: var(--bl-ink); }
|
|
7
|
+
.bl-dial__wheel { position: relative; width: 100%; aspect-ratio: 1; touch-action: none; user-select: none; -webkit-user-select: none; }
|
|
8
|
+
.bl-dial__ring { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--bl-ring) - 1px), #000 calc(100% - var(--bl-ring))); mask: radial-gradient(farthest-side, transparent calc(100% - var(--bl-ring) - 1px), #000 calc(100% - var(--bl-ring))); cursor: crosshair; }
|
|
9
|
+
.bl-dial__square { position: absolute; left: 50%; top: 50%; width: var(--bl-sq); height: var(--bl-sq); border-radius: 8px; background: linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent), hsl(var(--bl-h) 100% 50%); transform: translate(-50%, -50%); cursor: crosshair; }
|
|
10
|
+
.bl-dial__thumb { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: var(--bl-thumb); box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(0,0,0,0.35), 0 4px 10px rgba(0,0,0,0.4); outline: none; transition: transform 140ms cubic-bezier(.3,1.6,.5,1); }
|
|
11
|
+
.bl-dial__thumb:focus-visible { transform: scale(1.25); box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--bl-accent); }
|
|
12
|
+
.bl-dial[data-dragging] .bl-dial__thumb[data-active] { transform: scale(1.25); }
|
|
13
|
+
.bl-dial__row { display: flex; align-items: center; gap: 8px; width: 100%; }
|
|
14
|
+
.bl-dial__preview { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 10px; background: var(--bl-thumb); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15); }
|
|
15
|
+
.bl-dial__hex { flex: 1; min-width: 0; height: 36px; padding: 0 10px; box-sizing: border-box; border: 0; border-radius: 10px; background: var(--bl-field); color: inherit; font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; text-transform: uppercase; box-shadow: inset 0 0 0 1px var(--bl-line); outline: none; }
|
|
16
|
+
.bl-dial__hex:focus { box-shadow: inset 0 0 0 2px var(--bl-accent); }
|
|
17
|
+
.bl-dial__hex[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--bl-error); }
|
|
18
|
+
.bl-dial__btn { flex: 0 0 auto; display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; background: var(--bl-field); color: var(--bl-muted); cursor: pointer; box-shadow: inset 0 0 0 1px var(--bl-line); }
|
|
19
|
+
.bl-dial__btn:hover { color: var(--bl-ink); }
|
|
20
|
+
.bl-dial__btn:focus-visible, .bl-dial__swatch:focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 2px; }
|
|
21
|
+
.bl-dial__swatches { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
|
|
22
|
+
.bl-dial__swatch { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 7px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15); transition: transform 160ms cubic-bezier(.3,1.6,.5,1); }
|
|
23
|
+
.bl-dial__swatch:hover { transform: scale(1.15); }
|
|
24
|
+
.bl-dial__swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bl-bg), 0 0 0 4px var(--bl-ink); }
|
|
25
|
+
@media (prefers-reduced-motion: reduce) { .bl-dial__thumb, .bl-dial__swatch { transition: none; } }
|
|
26
|
+
`;
|
|
27
|
+
function useStyles() {
|
|
28
|
+
useInsertionEffect(() => {
|
|
29
|
+
if (typeof document === "undefined") return;
|
|
30
|
+
const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
|
|
31
|
+
style.textContent = CSS;
|
|
32
|
+
if (!style.isConnected) document.head.appendChild(style);
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
35
|
+
function parseHex(text) {
|
|
36
|
+
const m = String(text).trim().replace(/^#/, "").match(/^([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
37
|
+
if (!m) return null;
|
|
38
|
+
const full = m[1].length === 3 ? m[1].replace(/./g, (c) => c + c) : m[1];
|
|
39
|
+
const n = parseInt(full, 16);
|
|
40
|
+
return [n >> 16 & 255, n >> 8 & 255, n & 255];
|
|
41
|
+
}
|
|
42
|
+
const toHex = ([r, g, b]) => `#${[r, g, b].map((c) => Math.round(c).toString(16).padStart(2, "0")).join("")}`;
|
|
43
|
+
function hsvToRgb(h, s, v) {
|
|
44
|
+
const f = (n) => {
|
|
45
|
+
const k = (n + h / 60) % 6;
|
|
46
|
+
return v * (1 - s * Math.max(0, Math.min(k, 4 - k, 1)));
|
|
47
|
+
};
|
|
48
|
+
return [f(5) * 255, f(3) * 255, f(1) * 255];
|
|
49
|
+
}
|
|
50
|
+
function rgbToHsv([r, g, b]) {
|
|
51
|
+
const [rn, gn, bn] = [r / 255, g / 255, b / 255];
|
|
52
|
+
const max = Math.max(rn, gn, bn);
|
|
53
|
+
const d = max - Math.min(rn, gn, bn);
|
|
54
|
+
let h = 0;
|
|
55
|
+
if (d) h = max === rn ? (gn - bn) / d % 6 : max === gn ? (bn - rn) / d + 2 : (rn - gn) / d + 4;
|
|
56
|
+
return { h: (h * 60 + 360) % 360, s: max ? d / max : 0, v: max };
|
|
57
|
+
}
|
|
58
|
+
const DEFAULT_SWATCHES = ["#1a1c2c", "#5d275d", "#b13e53", "#ef7d57", "#ffcd75", "#a7f070", "#38b764", "#257179", "#29366f", "#3b5dc9", "#41a6f6", "#73eff7", "#f4f4f4", "#94b0c2", "#566c86", "#333c57"];
|
|
59
|
+
function ColorDial({
|
|
60
|
+
value,
|
|
61
|
+
defaultValue = "#73eff7",
|
|
62
|
+
onValueChange,
|
|
63
|
+
swatches = DEFAULT_SWATCHES,
|
|
64
|
+
size = 240,
|
|
65
|
+
ringWidth = 22,
|
|
66
|
+
eyedropper = true,
|
|
67
|
+
label = "Color",
|
|
68
|
+
backgroundColor = "#1a1c2c",
|
|
69
|
+
fieldColor = "#0b0b14",
|
|
70
|
+
textColor = "#f4f4f4",
|
|
71
|
+
mutedColor = "#94b0c2",
|
|
72
|
+
lineColor = "#333c57",
|
|
73
|
+
accentColor = "#73eff7",
|
|
74
|
+
errorColor = "#ef7d57",
|
|
75
|
+
fontFamily = "ui-sans-serif, system-ui, sans-serif",
|
|
76
|
+
className = "",
|
|
77
|
+
style
|
|
78
|
+
}) {
|
|
79
|
+
useStyles();
|
|
80
|
+
const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
81
|
+
const [inner, setInner] = useState(defaultValue);
|
|
82
|
+
const hex = (value ?? inner).toLowerCase();
|
|
83
|
+
const [hsv, setHsv] = useState(() => rgbToHsv(parseHex(hex) ?? [0, 0, 0]));
|
|
84
|
+
const [draft, setDraft] = useState(hex);
|
|
85
|
+
const [dragging, setDragging] = useState(null);
|
|
86
|
+
const [canSample, setCanSample] = useState(false);
|
|
87
|
+
const wheelRef = useRef(null);
|
|
88
|
+
const lastEmitted = useRef(hex);
|
|
89
|
+
useEffect(() => setCanSample(eyedropper && typeof window !== "undefined" && "EyeDropper" in window), [eyedropper]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
setDraft(hex);
|
|
92
|
+
if (hex === lastEmitted.current) return;
|
|
93
|
+
const rgb = parseHex(hex);
|
|
94
|
+
if (!rgb) return;
|
|
95
|
+
const next = rgbToHsv(rgb);
|
|
96
|
+
setHsv((current) => ({ h: next.s === 0 || next.v === 0 ? current.h : next.h, s: next.s, v: next.v }));
|
|
97
|
+
lastEmitted.current = hex;
|
|
98
|
+
}, [hex]);
|
|
99
|
+
const emit = (next) => {
|
|
100
|
+
setHsv(next);
|
|
101
|
+
const out = toHex(hsvToRgb(next.h, next.s, next.v));
|
|
102
|
+
lastEmitted.current = out;
|
|
103
|
+
if (value === void 0) setInner(out);
|
|
104
|
+
onValueChange?.(out);
|
|
105
|
+
};
|
|
106
|
+
const emitRgb = (rgb) => {
|
|
107
|
+
const next = rgbToHsv(rgb);
|
|
108
|
+
emit({ h: next.s === 0 || next.v === 0 ? hsv.h : next.h, s: next.s, v: next.v });
|
|
109
|
+
};
|
|
110
|
+
const ringFrac = ringWidth / size;
|
|
111
|
+
const innerR = 0.5 - ringFrac;
|
|
112
|
+
const sq = Math.SQRT2 * innerR - 0.06;
|
|
113
|
+
const fromPointer = (event, mode) => {
|
|
114
|
+
const rect = wheelRef.current.getBoundingClientRect();
|
|
115
|
+
const x = (event.clientX - rect.left) / rect.width - 0.5;
|
|
116
|
+
const y = (event.clientY - rect.top) / rect.height - 0.5;
|
|
117
|
+
if (mode === "ring") {
|
|
118
|
+
const h = (Math.atan2(y, x) * 180 / Math.PI + 90 + 360) % 360;
|
|
119
|
+
emit({ ...hsv, h });
|
|
120
|
+
} else {
|
|
121
|
+
const s = Math.max(0, Math.min(1, (x + sq / 2) / sq));
|
|
122
|
+
const v = Math.max(0, Math.min(1, 1 - (y + sq / 2) / sq));
|
|
123
|
+
emit({ ...hsv, s, v });
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const onPointerDown = (event) => {
|
|
127
|
+
const rect = wheelRef.current.getBoundingClientRect();
|
|
128
|
+
const x = (event.clientX - rect.left) / rect.width - 0.5;
|
|
129
|
+
const y = (event.clientY - rect.top) / rect.height - 0.5;
|
|
130
|
+
const r = Math.hypot(x, y);
|
|
131
|
+
const mode = r >= innerR - 0.01 && r <= 0.5 ? "ring" : Math.abs(x) <= sq / 2 && Math.abs(y) <= sq / 2 ? "square" : null;
|
|
132
|
+
if (!mode) return;
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
try {
|
|
135
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
setDragging(mode);
|
|
139
|
+
fromPointer(event, mode);
|
|
140
|
+
wheelRef.current.querySelector(`[data-part="${mode}"]`)?.focus({ preventScroll: true });
|
|
141
|
+
};
|
|
142
|
+
const onRingKey = (event) => {
|
|
143
|
+
const step = event.shiftKey ? 10 : 1;
|
|
144
|
+
const delta = { ArrowRight: step, ArrowUp: step, ArrowLeft: -step, ArrowDown: -step }[event.key];
|
|
145
|
+
if (delta === void 0 && event.key !== "Home" && event.key !== "End") return;
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
const h = event.key === "Home" ? 0 : event.key === "End" ? 359 : (hsv.h + delta + 360) % 360;
|
|
148
|
+
emit({ ...hsv, h });
|
|
149
|
+
};
|
|
150
|
+
const onSquareKey = (event) => {
|
|
151
|
+
const step = event.shiftKey ? 0.1 : 0.01;
|
|
152
|
+
const moves = { ArrowRight: ["s", step], ArrowLeft: ["s", -step], ArrowUp: ["v", step], ArrowDown: ["v", -step] };
|
|
153
|
+
const move = moves[event.key];
|
|
154
|
+
if (!move) return;
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
const [axis, delta] = move;
|
|
157
|
+
emit({ ...hsv, [axis]: Math.max(0, Math.min(1, hsv[axis] + delta)) });
|
|
158
|
+
};
|
|
159
|
+
const commitDraft = () => {
|
|
160
|
+
const rgb = parseHex(draft);
|
|
161
|
+
if (rgb) emitRgb(rgb);
|
|
162
|
+
};
|
|
163
|
+
const sample = async () => {
|
|
164
|
+
try {
|
|
165
|
+
const result = await new window.EyeDropper().open();
|
|
166
|
+
const rgb = parseHex(result.sRGBHex);
|
|
167
|
+
if (rgb) emitRgb(rgb);
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const angle = (hsv.h - 90) * Math.PI / 180;
|
|
172
|
+
const ringR = 0.5 - ringFrac / 2;
|
|
173
|
+
const valid = !!parseHex(draft);
|
|
174
|
+
const pct = (n) => Math.round(n * 100);
|
|
175
|
+
return /* @__PURE__ */ jsxs(
|
|
176
|
+
"div",
|
|
177
|
+
{
|
|
178
|
+
className: `bl-dial ${className}`,
|
|
179
|
+
role: "group",
|
|
180
|
+
"aria-label": label,
|
|
181
|
+
"data-dragging": dragging || void 0,
|
|
182
|
+
style: {
|
|
183
|
+
"--bl-size": `${size}px`,
|
|
184
|
+
"--bl-ring": `${ringWidth}px`,
|
|
185
|
+
"--bl-sq": `${sq * 100}%`,
|
|
186
|
+
"--bl-h": hsv.h,
|
|
187
|
+
"--bl-thumb": hex,
|
|
188
|
+
"--bl-bg": backgroundColor,
|
|
189
|
+
"--bl-field": fieldColor,
|
|
190
|
+
"--bl-ink": textColor,
|
|
191
|
+
"--bl-muted": mutedColor,
|
|
192
|
+
"--bl-line": lineColor,
|
|
193
|
+
"--bl-accent": accentColor,
|
|
194
|
+
"--bl-error": errorColor,
|
|
195
|
+
"--bl-font": fontFamily,
|
|
196
|
+
...style
|
|
197
|
+
},
|
|
198
|
+
children: [
|
|
199
|
+
/* @__PURE__ */ jsxs(
|
|
200
|
+
"div",
|
|
201
|
+
{
|
|
202
|
+
ref: wheelRef,
|
|
203
|
+
className: "bl-dial__wheel",
|
|
204
|
+
onPointerDown,
|
|
205
|
+
onPointerMove: (event) => dragging && fromPointer(event, dragging),
|
|
206
|
+
onPointerUp: () => setDragging(null),
|
|
207
|
+
onPointerCancel: () => setDragging(null),
|
|
208
|
+
children: [
|
|
209
|
+
/* @__PURE__ */ jsx("div", { className: "bl-dial__ring", "aria-hidden": "true" }),
|
|
210
|
+
/* @__PURE__ */ jsx("div", { className: "bl-dial__square", "aria-hidden": "true" }),
|
|
211
|
+
/* @__PURE__ */ jsx(
|
|
212
|
+
"span",
|
|
213
|
+
{
|
|
214
|
+
className: "bl-dial__thumb",
|
|
215
|
+
"data-part": "ring",
|
|
216
|
+
"data-active": dragging === "ring" || void 0,
|
|
217
|
+
role: "slider",
|
|
218
|
+
tabIndex: 0,
|
|
219
|
+
"aria-label": "Hue",
|
|
220
|
+
"aria-valuemin": 0,
|
|
221
|
+
"aria-valuemax": 359,
|
|
222
|
+
"aria-valuenow": Math.round(hsv.h),
|
|
223
|
+
"aria-valuetext": `Hue ${Math.round(hsv.h)} degrees`,
|
|
224
|
+
onKeyDown: onRingKey,
|
|
225
|
+
style: { left: `${(0.5 + Math.cos(angle) * ringR) * 100}%`, top: `${(0.5 + Math.sin(angle) * ringR) * 100}%`, background: `hsl(${hsv.h} 100% 50%)` }
|
|
226
|
+
}
|
|
227
|
+
),
|
|
228
|
+
/* @__PURE__ */ jsx(
|
|
229
|
+
"span",
|
|
230
|
+
{
|
|
231
|
+
className: "bl-dial__thumb",
|
|
232
|
+
"data-part": "square",
|
|
233
|
+
"data-active": dragging === "square" || void 0,
|
|
234
|
+
role: "slider",
|
|
235
|
+
tabIndex: 0,
|
|
236
|
+
"aria-label": "Saturation and brightness",
|
|
237
|
+
"aria-valuemin": 0,
|
|
238
|
+
"aria-valuemax": 100,
|
|
239
|
+
"aria-valuenow": pct(hsv.s),
|
|
240
|
+
"aria-valuetext": `Saturation ${pct(hsv.s)}%, brightness ${pct(hsv.v)}%`,
|
|
241
|
+
onKeyDown: onSquareKey,
|
|
242
|
+
style: { left: `${(0.5 - sq / 2 + hsv.s * sq) * 100}%`, top: `${(0.5 - sq / 2 + (1 - hsv.v) * sq) * 100}%` }
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
),
|
|
248
|
+
/* @__PURE__ */ jsxs("div", { className: "bl-dial__row", children: [
|
|
249
|
+
/* @__PURE__ */ jsx("span", { className: "bl-dial__preview", "aria-hidden": "true" }),
|
|
250
|
+
/* @__PURE__ */ jsx(
|
|
251
|
+
"input",
|
|
252
|
+
{
|
|
253
|
+
className: "bl-dial__hex",
|
|
254
|
+
"aria-label": `${label} hex code`,
|
|
255
|
+
"aria-invalid": !valid,
|
|
256
|
+
spellCheck: false,
|
|
257
|
+
value: draft,
|
|
258
|
+
onChange: (event) => setDraft(event.target.value),
|
|
259
|
+
onBlur: commitDraft,
|
|
260
|
+
onKeyDown: (event) => event.key === "Enter" && commitDraft()
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
canSample && /* @__PURE__ */ jsx("button", { type: "button", className: "bl-dial__btn", "aria-label": "Pick a color from the screen", onClick: sample, children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m9.5 3.5 3 3M11 2a1.4 1.4 0 0 1 2 0l1 1a1.4 1.4 0 0 1 0 2l-1.5 1.5-3-3zM8.5 4.5 2.8 10.2 2 14l3.8-.8 5.7-5.7" }) }) })
|
|
264
|
+
] }),
|
|
265
|
+
swatches.length > 0 && /* @__PURE__ */ jsx("ul", { className: "bl-dial__swatches", "aria-label": "Swatches", id: `${uid}-swatches`, children: swatches.map((swatch) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
|
|
266
|
+
"button",
|
|
267
|
+
{
|
|
268
|
+
type: "button",
|
|
269
|
+
className: "bl-dial__swatch",
|
|
270
|
+
"aria-label": swatch,
|
|
271
|
+
"aria-pressed": swatch.toLowerCase() === hex,
|
|
272
|
+
style: { background: swatch },
|
|
273
|
+
onClick: () => {
|
|
274
|
+
const rgb = parseHex(swatch);
|
|
275
|
+
if (rgb) emitRgb(rgb);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
) }, swatch)) })
|
|
279
|
+
]
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
export {
|
|
284
|
+
ColorDial as default,
|
|
285
|
+
hsvToRgb,
|
|
286
|
+
parseHex,
|
|
287
|
+
rgbToHsv
|
|
288
|
+
};
|