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.
Files changed (323) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -2
  3. package/dist/Accordion.d.ts +52 -0
  4. package/dist/Accordion.js +192 -0
  5. package/dist/AchievementToast.d.ts +36 -0
  6. package/dist/AchievementToast.js +162 -0
  7. package/dist/AgentCard.d.ts +41 -0
  8. package/dist/AgentCard.js +168 -0
  9. package/dist/ArcadeButtons.d.ts +23 -0
  10. package/dist/ArcadeButtons.js +169 -0
  11. package/dist/AuroraBands.d.ts +19 -0
  12. package/dist/AuroraBands.js +126 -0
  13. package/dist/AvatarTooltips.d.ts +32 -0
  14. package/dist/AvatarTooltips.js +121 -0
  15. package/dist/BarRace.d.ts +39 -0
  16. package/dist/BarRace.js +227 -0
  17. package/dist/BentoGrid.d.ts +50 -0
  18. package/dist/BentoGrid.js +145 -0
  19. package/dist/BootSequence.d.ts +48 -0
  20. package/dist/BootSequence.js +234 -0
  21. package/dist/BreadcrumbTrail.d.ts +31 -0
  22. package/dist/BreadcrumbTrail.js +181 -0
  23. package/dist/CRTPower.d.ts +30 -0
  24. package/dist/CRTPower.js +142 -0
  25. package/dist/CardDeck.d.ts +29 -0
  26. package/dist/CardDeck.js +154 -0
  27. package/dist/ChangelogTimeline.d.ts +35 -0
  28. package/dist/ChangelogTimeline.js +137 -0
  29. package/dist/ChapterProgress.d.ts +23 -0
  30. package/dist/ChapterProgress.js +211 -0
  31. package/dist/ChatBubbles.d.ts +42 -0
  32. package/dist/ChatBubbles.js +198 -0
  33. package/dist/ChiptuneKit.d.ts +158 -0
  34. package/dist/ChiptuneKit.js +207 -0
  35. package/dist/CipherCard.d.ts +22 -0
  36. package/dist/CipherCard.js +91 -0
  37. package/dist/CloudSky.d.ts +28 -0
  38. package/dist/CloudSky.js +222 -0
  39. package/dist/CodeRain.d.ts +24 -0
  40. package/dist/CodeRain.js +158 -0
  41. package/dist/CodeShowcase.d.ts +50 -0
  42. package/dist/CodeShowcase.js +307 -0
  43. package/dist/ColorDial.d.ts +42 -0
  44. package/dist/ColorDial.js +288 -0
  45. package/dist/CommandPalette.d.ts +59 -0
  46. package/dist/CommandPalette.js +349 -0
  47. package/dist/CompareSlider.d.ts +33 -0
  48. package/dist/CompareSlider.js +152 -0
  49. package/dist/Confetti.d.ts +61 -0
  50. package/dist/Confetti.js +176 -0
  51. package/dist/ConnectBeams.d.ts +39 -0
  52. package/dist/ConnectBeams.js +132 -0
  53. package/dist/ContextOrb.d.ts +34 -0
  54. package/dist/ContextOrb.js +269 -0
  55. package/dist/ContourLines.d.ts +20 -0
  56. package/dist/ContourLines.js +159 -0
  57. package/dist/Coverflow.d.ts +27 -0
  58. package/dist/Coverflow.js +167 -0
  59. package/dist/CursorAttractor.d.ts +21 -0
  60. package/dist/CursorAttractor.js +136 -0
  61. package/dist/CutReveal.d.ts +21 -0
  62. package/dist/CutReveal.js +116 -0
  63. package/dist/DateRange.d.ts +45 -0
  64. package/dist/DateRange.js +327 -0
  65. package/dist/DeviceFrame.d.ts +30 -0
  66. package/dist/DeviceFrame.js +145 -0
  67. package/dist/DiffReveal.d.ts +36 -0
  68. package/dist/DiffReveal.js +247 -0
  69. package/dist/DirectionHover.d.ts +15 -0
  70. package/dist/DirectionHover.js +90 -0
  71. package/dist/Discard.d.ts +18 -0
  72. package/dist/Discard.js +61 -0
  73. package/dist/DitherField.d.ts +15 -0
  74. package/dist/DitherField.js +157 -0
  75. package/dist/DotGlobe.d.ts +48 -0
  76. package/dist/DotGlobe.js +312 -0
  77. package/dist/DotMap.d.ts +47 -0
  78. package/dist/DotMap.js +172 -0
  79. package/dist/DropZone.d.ts +57 -0
  80. package/dist/DropZone.js +304 -0
  81. package/dist/DynamicIsland.d.ts +32 -0
  82. package/dist/DynamicIsland.js +92 -0
  83. package/dist/EdgeFX.d.ts +27 -0
  84. package/dist/EdgeFX.js +98 -0
  85. package/dist/ElasticString.d.ts +22 -0
  86. package/dist/ElasticString.js +127 -0
  87. package/dist/ExpandCard.d.ts +44 -0
  88. package/dist/ExpandCard.js +182 -0
  89. package/dist/FeatureTabs.d.ts +34 -0
  90. package/dist/FeatureTabs.js +169 -0
  91. package/dist/FeedList.d.ts +37 -0
  92. package/dist/FeedList.js +163 -0
  93. package/dist/FlickerGrid.d.ts +29 -0
  94. package/dist/FlickerGrid.js +156 -0
  95. package/dist/FocusGrid.d.ts +20 -0
  96. package/dist/FocusGrid.js +48 -0
  97. package/dist/FocusPull.d.ts +26 -0
  98. package/dist/FocusPull.js +106 -0
  99. package/dist/Footprints.d.ts +24 -0
  100. package/dist/Footprints.js +126 -0
  101. package/dist/FunnelFlow.d.ts +34 -0
  102. package/dist/FunnelFlow.js +267 -0
  103. package/dist/GameOver.d.ts +46 -0
  104. package/dist/GameOver.js +191 -0
  105. package/dist/GaugeMeter.d.ts +38 -0
  106. package/dist/GaugeMeter.js +195 -0
  107. package/dist/GlassPanel.d.ts +27 -0
  108. package/dist/GlassPanel.js +80 -0
  109. package/dist/GrainFX.d.ts +34 -0
  110. package/dist/GrainFX.js +122 -0
  111. package/dist/GravityBox.d.ts +30 -0
  112. package/dist/GravityBox.js +220 -0
  113. package/dist/HealthBar.d.ts +33 -0
  114. package/dist/HealthBar.js +140 -0
  115. package/dist/Heatmap.d.ts +42 -0
  116. package/dist/Heatmap.js +232 -0
  117. package/dist/HexField.d.ts +29 -0
  118. package/dist/HexField.js +188 -0
  119. package/dist/HoldToConfirm.d.ts +29 -0
  120. package/dist/HoldToConfirm.js +163 -0
  121. package/dist/HorizontalTrack.d.ts +28 -0
  122. package/dist/HorizontalTrack.js +195 -0
  123. package/dist/HotbarDock.d.ts +40 -0
  124. package/dist/HotbarDock.js +148 -0
  125. package/dist/InkText.d.ts +27 -0
  126. package/dist/InkText.js +65 -0
  127. package/dist/InlineEdit.d.ts +30 -0
  128. package/dist/InlineEdit.js +198 -0
  129. package/dist/InteractiveGrid.d.ts +25 -0
  130. package/dist/InteractiveGrid.js +194 -0
  131. package/dist/InventoryGrid.d.ts +45 -0
  132. package/dist/InventoryGrid.js +272 -0
  133. package/dist/JellyBlob.d.ts +30 -0
  134. package/dist/JellyBlob.js +209 -0
  135. package/dist/KineticHeadline.d.ts +30 -0
  136. package/dist/KineticHeadline.js +133 -0
  137. package/dist/LavaLamp.d.ts +21 -0
  138. package/dist/LavaLamp.js +133 -0
  139. package/dist/LetterSwap.d.ts +20 -0
  140. package/dist/LetterSwap.js +78 -0
  141. package/dist/LevelMap.d.ts +35 -0
  142. package/dist/LevelMap.js +189 -0
  143. package/dist/LightShafts.d.ts +22 -0
  144. package/dist/LightShafts.js +170 -0
  145. package/dist/LightboxGallery.d.ts +26 -0
  146. package/dist/LightboxGallery.js +327 -0
  147. package/dist/LinkPeek.d.ts +36 -0
  148. package/dist/LinkPeek.js +194 -0
  149. package/dist/LogoOrbit.d.ts +37 -0
  150. package/dist/LogoOrbit.js +117 -0
  151. package/dist/Marquee.d.ts +33 -0
  152. package/dist/Marquee.js +148 -0
  153. package/dist/MarqueeLine.d.ts +33 -0
  154. package/dist/MarqueeLine.js +167 -0
  155. package/dist/MasonryWall.d.ts +13 -0
  156. package/dist/MasonryWall.js +90 -0
  157. package/dist/MegaMenu.d.ts +32 -0
  158. package/dist/MegaMenu.js +280 -0
  159. package/dist/MeteorShower.d.ts +24 -0
  160. package/dist/MeteorShower.js +155 -0
  161. package/dist/Minimap.d.ts +21 -0
  162. package/dist/Minimap.js +236 -0
  163. package/dist/MobileTabBar.d.ts +38 -0
  164. package/dist/MobileTabBar.js +148 -0
  165. package/dist/MorphDialog.d.ts +34 -0
  166. package/dist/MorphDialog.js +199 -0
  167. package/dist/MorphPopover.d.ts +33 -0
  168. package/dist/MorphPopover.js +168 -0
  169. package/dist/MorphWords.d.ts +18 -0
  170. package/dist/MorphWords.js +136 -0
  171. package/dist/OTPInput.d.ts +43 -0
  172. package/dist/OTPInput.js +174 -0
  173. package/dist/OverlayKit.d.ts +97 -0
  174. package/dist/OverlayKit.js +466 -0
  175. package/dist/OverlayMenu.d.ts +32 -0
  176. package/dist/OverlayMenu.js +154 -0
  177. package/dist/ParallaxCollage.d.ts +41 -0
  178. package/dist/ParallaxCollage.js +143 -0
  179. package/dist/PasswordMeter.d.ts +44 -0
  180. package/dist/PasswordMeter.js +165 -0
  181. package/dist/PegBoard.d.ts +26 -0
  182. package/dist/PegBoard.js +184 -0
  183. package/dist/PinCard.d.ts +21 -0
  184. package/dist/PinCard.js +84 -0
  185. package/dist/PixelAvatar.d.ts +33 -0
  186. package/dist/PixelAvatar.js +144 -0
  187. package/dist/PixelButton.d.ts +20 -0
  188. package/dist/PixelButton.js +128 -0
  189. package/dist/PixelExplode.d.ts +31 -0
  190. package/dist/PixelExplode.js +164 -0
  191. package/dist/PixelLoader.d.ts +32 -0
  192. package/dist/PixelLoader.js +142 -0
  193. package/dist/PixelParallax.d.ts +41 -0
  194. package/dist/PixelParallax.js +151 -0
  195. package/dist/PixelSpinners.d.ts +21 -0
  196. package/dist/PixelSpinners.js +110 -0
  197. package/dist/PixelType.d.ts +26 -0
  198. package/dist/PixelType.js +220 -0
  199. package/dist/PointerKit.d.ts +23 -0
  200. package/dist/PointerKit.js +222 -0
  201. package/dist/Polaroids.d.ts +41 -0
  202. package/dist/Polaroids.js +293 -0
  203. package/dist/PressStart.d.ts +28 -0
  204. package/dist/PressStart.js +99 -0
  205. package/dist/PricingFlip.d.ts +52 -0
  206. package/dist/PricingFlip.js +190 -0
  207. package/dist/ProximityType.d.ts +26 -0
  208. package/dist/ProximityType.js +135 -0
  209. package/dist/QuestDialog.d.ts +50 -0
  210. package/dist/QuestDialog.js +204 -0
  211. package/dist/QuestLog.d.ts +39 -0
  212. package/dist/QuestLog.js +214 -0
  213. package/dist/RangeDual.d.ts +34 -0
  214. package/dist/RangeDual.js +238 -0
  215. package/dist/RatingPips.d.ts +25 -0
  216. package/dist/RatingPips.js +129 -0
  217. package/dist/RetroHorizon.d.ts +27 -0
  218. package/dist/RetroHorizon.js +169 -0
  219. package/dist/Reveal.d.ts +30 -0
  220. package/dist/Reveal.js +92 -0
  221. package/dist/RingProgress.d.ts +45 -0
  222. package/dist/RingProgress.js +180 -0
  223. package/dist/RollingNumber.d.ts +28 -0
  224. package/dist/RollingNumber.js +108 -0
  225. package/dist/ScanScope.d.ts +24 -0
  226. package/dist/ScanScope.js +164 -0
  227. package/dist/ScoreTicker.d.ts +32 -0
  228. package/dist/ScoreTicker.js +176 -0
  229. package/dist/ScreenScroller.d.ts +24 -0
  230. package/dist/ScreenScroller.js +138 -0
  231. package/dist/Screensaver.d.ts +31 -0
  232. package/dist/Screensaver.js +221 -0
  233. package/dist/ScrollTilt.d.ts +27 -0
  234. package/dist/ScrollTilt.js +100 -0
  235. package/dist/ScrollTypography.d.ts +26 -0
  236. package/dist/ScrollTypography.js +124 -0
  237. package/dist/ScrollZoom.d.ts +31 -0
  238. package/dist/ScrollZoom.js +123 -0
  239. package/dist/ScrubNumber.d.ts +29 -0
  240. package/dist/ScrubNumber.js +152 -0
  241. package/dist/ShadowStack.d.ts +28 -0
  242. package/dist/ShadowStack.js +116 -0
  243. package/dist/SideRail.d.ts +43 -0
  244. package/dist/SideRail.js +253 -0
  245. package/dist/SignalText.d.ts +25 -0
  246. package/dist/SignalText.js +178 -0
  247. package/dist/SkeletonShimmer.d.ts +18 -0
  248. package/dist/SkeletonShimmer.js +111 -0
  249. package/dist/SketchHighlight.d.ts +27 -0
  250. package/dist/SketchHighlight.js +180 -0
  251. package/dist/SlideTabs.d.ts +40 -0
  252. package/dist/SlideTabs.js +190 -0
  253. package/dist/SmartNavbar.d.ts +48 -0
  254. package/dist/SmartNavbar.js +188 -0
  255. package/dist/SparkChart.d.ts +41 -0
  256. package/dist/SparkChart.js +188 -0
  257. package/dist/Spoiler.d.ts +22 -0
  258. package/dist/Spoiler.js +97 -0
  259. package/dist/SpotlightTour.d.ts +38 -0
  260. package/dist/SpotlightTour.js +231 -0
  261. package/dist/SpringDrawer.d.ts +39 -0
  262. package/dist/SpringDrawer.js +360 -0
  263. package/dist/SpriteAnimator.d.ts +41 -0
  264. package/dist/SpriteAnimator.js +124 -0
  265. package/dist/StatCard.d.ts +43 -0
  266. package/dist/StatCard.js +168 -0
  267. package/dist/StepLoader.d.ts +41 -0
  268. package/dist/StepLoader.js +191 -0
  269. package/dist/StepperForm.d.ts +41 -0
  270. package/dist/StepperForm.js +206 -0
  271. package/dist/StickerBoard.d.ts +39 -0
  272. package/dist/StickerBoard.js +209 -0
  273. package/dist/StickyReveal.d.ts +42 -0
  274. package/dist/StickyReveal.js +181 -0
  275. package/dist/StoryViewer.d.ts +36 -0
  276. package/dist/StoryViewer.js +175 -0
  277. package/dist/StreamingText.d.ts +29 -0
  278. package/dist/StreamingText.js +271 -0
  279. package/dist/SuggestionChips.d.ts +32 -0
  280. package/dist/SuggestionChips.js +96 -0
  281. package/dist/SwipeActions.d.ts +30 -0
  282. package/dist/SwipeActions.js +141 -0
  283. package/dist/TagInput.d.ts +30 -0
  284. package/dist/TagInput.js +284 -0
  285. package/dist/TallyUp.d.ts +38 -0
  286. package/dist/TallyUp.js +157 -0
  287. package/dist/TerminalDemo.d.ts +63 -0
  288. package/dist/TerminalDemo.js +214 -0
  289. package/dist/TestimonialWall.d.ts +35 -0
  290. package/dist/TestimonialWall.js +131 -0
  291. package/dist/TextOnPath.d.ts +36 -0
  292. package/dist/TextOnPath.js +130 -0
  293. package/dist/ThinkingShimmer.d.ts +36 -0
  294. package/dist/ThinkingShimmer.js +132 -0
  295. package/dist/ToastStack.d.ts +62 -0
  296. package/dist/ToastStack.js +289 -0
  297. package/dist/ToggleGroup.d.ts +39 -0
  298. package/dist/ToggleGroup.js +190 -0
  299. package/dist/ToggleKit.d.ts +70 -0
  300. package/dist/ToggleKit.js +229 -0
  301. package/dist/TracingLine.d.ts +24 -0
  302. package/dist/TracingLine.js +139 -0
  303. package/dist/TradingCard.d.ts +30 -0
  304. package/dist/TradingCard.js +147 -0
  305. package/dist/VanishInput.d.ts +34 -0
  306. package/dist/VanishInput.js +190 -0
  307. package/dist/VideoHero.d.ts +32 -0
  308. package/dist/VideoHero.js +207 -0
  309. package/dist/VoiceOrb.d.ts +23 -0
  310. package/dist/VoiceOrb.js +182 -0
  311. package/dist/VoxelTiles.d.ts +38 -0
  312. package/dist/VoxelTiles.js +201 -0
  313. package/dist/WarpField.d.ts +18 -0
  314. package/dist/WarpField.js +160 -0
  315. package/dist/WebcamPixels.d.ts +38 -0
  316. package/dist/WebcamPixels.js +292 -0
  317. package/dist/WheelPicker.d.ts +29 -0
  318. package/dist/WheelPicker.js +199 -0
  319. package/dist/WobbleCard.d.ts +23 -0
  320. package/dist/WobbleCard.js +112 -0
  321. package/dist/index.d.ts +158 -0
  322. package/dist/index.js +159 -0
  323. package/package.json +58 -4
@@ -0,0 +1,247 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useInsertionEffect, useMemo, useRef, useState } from "react";
4
+ const STYLE_ID = "bl-diff-reveal";
5
+ const CSS = `
6
+ .bl-diff { display: grid; gap: 12px; color: var(--bl-ink); font-family: var(--bl-font); }
7
+ .bl-diff__text { margin: 0; font-size: var(--bl-size); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
8
+ .bl-diff__del { border-radius: 4px; transition: opacity 260ms, background-color 260ms; }
9
+ .bl-diff__del[data-phase="strike"] { background: color-mix(in srgb, var(--bl-del) 22%, transparent); color: var(--bl-del); text-decoration: line-through; text-decoration-thickness: 2px; }
10
+ .bl-diff__del[data-phase="gone"] { display: none; }
11
+ .bl-diff__ins { border-radius: 4px; background: color-mix(in srgb, var(--bl-ins) 24%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--bl-ins) 40%, transparent); transition: background-color 900ms, box-shadow 900ms; }
12
+ .bl-diff[data-done] .bl-diff__ins { background: color-mix(in srgb, var(--bl-ins) 10%, transparent); box-shadow: none; }
13
+ .bl-diff[data-settled] .bl-diff__ins { background: transparent; }
14
+ .bl-diff__caret { display: inline-block; width: 2px; height: 1.1em; margin-left: 1px; vertical-align: -0.15em; background: var(--bl-ins); animation: bl-diff-blink 900ms steps(1) infinite; }
15
+ .bl-diff__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--bl-muted); font-size: 13px; }
16
+ .bl-diff__btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 0; border-radius: 999px; background: var(--bl-chip); color: var(--bl-ink); font: inherit; cursor: pointer; }
17
+ .bl-diff__btn:hover { box-shadow: 0 0 0 1px var(--bl-ins); }
18
+ .bl-diff__btn:focus-visible { outline: 2px solid var(--bl-ins); outline-offset: 2px; }
19
+ .bl-diff__btn[aria-pressed="true"] { background: color-mix(in srgb, var(--bl-ins) 22%, var(--bl-chip)); }
20
+ .bl-diff__speeds { display: inline-flex; gap: 4px; }
21
+ .bl-diff__count { margin-left: auto; font-variant-numeric: tabular-nums; }
22
+ .bl-diff__count b { font-weight: 600; }
23
+ .bl-diff__count .bl-diff__plus { color: var(--bl-ins); }
24
+ .bl-diff__count .bl-diff__minus { color: var(--bl-del); }
25
+ .bl-diff__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
26
+ @keyframes bl-diff-blink { 50% { opacity: 0; } }
27
+ @media (prefers-reduced-motion: reduce) { .bl-diff__del, .bl-diff__ins { transition: none; } .bl-diff__caret { animation: 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 diffWords(before, after) {
38
+ const a = before.split(/(\s+)/).filter(Boolean);
39
+ const b = after.split(/(\s+)/).filter(Boolean);
40
+ const ops = [];
41
+ const push = (type, text) => {
42
+ const last = ops[ops.length - 1];
43
+ if (last && last.type === type) last.text += text;
44
+ else ops.push({ type, text });
45
+ };
46
+ if (a.length * b.length > 25e4) {
47
+ push("del", before);
48
+ push("ins", after);
49
+ return ops;
50
+ }
51
+ const lcs = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));
52
+ for (let i2 = a.length - 1; i2 >= 0; i2--) for (let j2 = b.length - 1; j2 >= 0; j2--) lcs[i2][j2] = a[i2] === b[j2] ? lcs[i2 + 1][j2 + 1] + 1 : Math.max(lcs[i2 + 1][j2], lcs[i2][j2 + 1]);
53
+ let i = 0;
54
+ let j = 0;
55
+ while (i < a.length && j < b.length) {
56
+ if (a[i] === b[j]) {
57
+ push("same", a[i]);
58
+ i++;
59
+ j++;
60
+ } else if (lcs[i + 1][j] >= lcs[i][j + 1]) push("del", a[i++]);
61
+ else push("ins", b[j++]);
62
+ }
63
+ while (i < a.length) push("del", a[i++]);
64
+ while (j < b.length) push("ins", b[j++]);
65
+ return tidy(ops);
66
+ }
67
+ function tidy(ops) {
68
+ const out = [];
69
+ let del = "";
70
+ let ins = "";
71
+ const flush = () => {
72
+ if (del) out.push({ type: "del", text: del });
73
+ if (ins) out.push({ type: "ins", text: ins });
74
+ del = "";
75
+ ins = "";
76
+ };
77
+ ops.forEach((op, k) => {
78
+ if (op.type === "del") del += op.text;
79
+ else if (op.type === "ins") ins += op.text;
80
+ else if ((del || ins) && /^\s+$/.test(op.text) && ops[k + 1] && ops[k + 1].type !== "same") {
81
+ del += op.text;
82
+ ins += op.text;
83
+ } else {
84
+ flush();
85
+ out.push(op);
86
+ }
87
+ });
88
+ flush();
89
+ return out;
90
+ }
91
+ const SPEEDS = [0.5, 1, 2];
92
+ const countWords = (text) => text.split(/\s+/).filter(Boolean).length;
93
+ function DiffReveal({
94
+ before = "",
95
+ after = "",
96
+ autoPlay = true,
97
+ threshold = 0.4,
98
+ replayKey,
99
+ charsPerSecond = 45,
100
+ strikeDuration = 520,
101
+ stagger = 220,
102
+ showControls = true,
103
+ onDone,
104
+ as = "p",
105
+ fontSize = 18,
106
+ textColor = "#f4f4f4",
107
+ mutedColor = "#94b0c2",
108
+ chipColor = "#262b44",
109
+ insertColor = "#38b764",
110
+ deleteColor = "#ef7d57",
111
+ fontFamily = "ui-sans-serif, system-ui, sans-serif",
112
+ className = "",
113
+ style
114
+ }) {
115
+ useStyles();
116
+ const ref = useRef(null);
117
+ const ops = useMemo(() => diffWords(before, after), [before, after]);
118
+ const [clock, setClock] = useState(0);
119
+ const [playing, setPlaying] = useState(false);
120
+ const [speed, setSpeed] = useState(1);
121
+ const doneRef = useRef(onDone);
122
+ doneRef.current = onDone;
123
+ const Tag = as;
124
+ const plan = useMemo(() => {
125
+ let d = 0;
126
+ let c = 0;
127
+ const steps = ops.map((op) => {
128
+ if (op.type === "del") {
129
+ const at = d++ * stagger;
130
+ return { strike: at, gone: at + strikeDuration };
131
+ }
132
+ if (op.type === "ins") {
133
+ const start = c;
134
+ c += op.text.length;
135
+ return { start };
136
+ }
137
+ return null;
138
+ });
139
+ const typeAt = d ? (d - 1) * stagger + strikeDuration + 160 : 0;
140
+ const total = typeAt + c / charsPerSecond * 1e3;
141
+ const stats = ops.reduce((s, op) => op.type === "same" ? s : { ...s, [op.type]: s[op.type] + countWords(op.text) }, { ins: 0, del: 0 });
142
+ return { steps, typeAt, total, stats };
143
+ }, [ops, stagger, strikeDuration, charsPerSecond]);
144
+ const done = clock >= plan.total;
145
+ useEffect(() => {
146
+ if (!playing) return void 0;
147
+ let frame = 0;
148
+ let last = performance.now();
149
+ const tick = (now) => {
150
+ const dt = (now - last) * speed;
151
+ last = now;
152
+ setClock((c) => {
153
+ const next = Math.min(plan.total, c + dt);
154
+ if (next >= plan.total) setPlaying(false);
155
+ return next;
156
+ });
157
+ frame = requestAnimationFrame(tick);
158
+ };
159
+ frame = requestAnimationFrame(tick);
160
+ return () => cancelAnimationFrame(frame);
161
+ }, [playing, speed, plan.total]);
162
+ useEffect(() => {
163
+ if (done && clock > 0) doneRef.current?.();
164
+ }, [done, clock]);
165
+ const play = () => {
166
+ if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
167
+ setClock(plan.total);
168
+ return;
169
+ }
170
+ setClock(0);
171
+ setPlaying(true);
172
+ };
173
+ useEffect(() => {
174
+ setPlaying(false);
175
+ setClock(0);
176
+ if (!autoPlay) return void 0;
177
+ const io = new IntersectionObserver(
178
+ ([entry]) => {
179
+ if (!entry.isIntersecting) return;
180
+ io.disconnect();
181
+ play();
182
+ },
183
+ { threshold }
184
+ );
185
+ io.observe(ref.current);
186
+ return () => io.disconnect();
187
+ }, [before, after, replayKey, autoPlay]);
188
+ const typed = Math.max(0, (clock - plan.typeAt) / 1e3 * charsPerSecond);
189
+ const idle = clock === 0 && !playing;
190
+ let caretPlaced = false;
191
+ return /* @__PURE__ */ jsxs(
192
+ "div",
193
+ {
194
+ ref,
195
+ className: `bl-diff ${className}`,
196
+ "data-done": done && clock > 0 || void 0,
197
+ "data-settled": done && clock > 0 && !playing || void 0,
198
+ style: { "--bl-size": `${fontSize}px`, "--bl-ink": textColor, "--bl-muted": mutedColor, "--bl-chip": chipColor, "--bl-ins": insertColor, "--bl-del": deleteColor, "--bl-font": fontFamily, ...style },
199
+ children: [
200
+ /* @__PURE__ */ jsx(Tag, { className: "bl-diff__text", "aria-hidden": "true", children: ops.map((op, i) => {
201
+ if (op.type === "same") return /* @__PURE__ */ jsx("span", { children: op.text }, i);
202
+ const step = plan.steps[i];
203
+ if (op.type === "del") {
204
+ const phase = idle ? "idle" : clock >= step.gone ? "gone" : clock >= step.strike ? "strike" : "idle";
205
+ return /* @__PURE__ */ jsx("span", { className: "bl-diff__del", "data-phase": phase, children: op.text }, i);
206
+ }
207
+ const shown = idle ? 0 : Math.min(op.text.length, Math.floor(typed - step.start));
208
+ if (shown <= 0) return null;
209
+ const caret = !caretPlaced && playing && shown < op.text.length;
210
+ if (caret) caretPlaced = true;
211
+ return /* @__PURE__ */ jsxs("span", { className: "bl-diff__ins", children: [
212
+ op.text.slice(0, shown),
213
+ caret && /* @__PURE__ */ jsx("span", { className: "bl-diff__caret" })
214
+ ] }, i);
215
+ }) }),
216
+ /* @__PURE__ */ jsx("span", { className: "bl-diff__sr", children: after }),
217
+ showControls && /* @__PURE__ */ jsxs("div", { className: "bl-diff__bar", children: [
218
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "bl-diff__btn", onClick: play, children: [
219
+ /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: idle ? /* @__PURE__ */ jsx("path", { d: "M4 2.5v9l7-4.5z", fill: "currentColor" }) : /* @__PURE__ */ jsx("path", { d: "M11.5 5.5A5 5 0 0 0 2.6 4.4M2.5 2v2.5H5M2.5 8.5a5 5 0 0 0 8.9 1.1" }) }),
220
+ idle ? "Play edit" : "Replay"
221
+ ] }),
222
+ /* @__PURE__ */ jsx("span", { className: "bl-diff__speeds", role: "group", "aria-label": "Speed", children: SPEEDS.map((s) => /* @__PURE__ */ jsxs("button", { type: "button", className: "bl-diff__btn", "aria-pressed": speed === s, onClick: () => setSpeed(s), children: [
223
+ s,
224
+ "\xD7"
225
+ ] }, s)) }),
226
+ /* @__PURE__ */ jsxs("span", { className: "bl-diff__count", children: [
227
+ /* @__PURE__ */ jsxs("b", { className: "bl-diff__plus", children: [
228
+ "+",
229
+ plan.stats.ins
230
+ ] }),
231
+ " ",
232
+ /* @__PURE__ */ jsxs("b", { className: "bl-diff__minus", children: [
233
+ "\u2212",
234
+ plan.stats.del
235
+ ] }),
236
+ " words"
237
+ ] })
238
+ ] }),
239
+ /* @__PURE__ */ jsx("span", { className: "bl-diff__sr", "aria-live": "polite", children: done && clock > 0 ? `Edit applied: ${plan.stats.ins} words inserted, ${plan.stats.del} words deleted.` : "" })
240
+ ]
241
+ }
242
+ );
243
+ }
244
+ export {
245
+ DiffReveal as default,
246
+ diffWords
247
+ };
@@ -0,0 +1,15 @@
1
+ import { type ReactNode, type HTMLAttributes } from 'react';
2
+ export interface DirectionHoverProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
3
+ /** The card's base (an image, usually). */
4
+ children?: ReactNode;
5
+ /** Slides in from the edge the pointer entered. */
6
+ overlay?: ReactNode;
7
+ duration?: number;
8
+ /** How much the base zooms while open. */
9
+ zoom?: number;
10
+ radius?: number;
11
+ overlayColor?: string;
12
+ textColor?: string;
13
+ accentColor?: string;
14
+ }
15
+ export default function DirectionHover({ children, overlay, duration, zoom, radius, overlayColor, textColor, accentColor, className, style, ...rest }: DirectionHoverProps): import("react").JSX.Element;
@@ -0,0 +1,90 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useInsertionEffect, useRef, useState } from "react";
4
+ const STYLE_ID = "bl-direction-hover";
5
+ const CSS = `
6
+ .bl-dh { position: relative; overflow: hidden; border-radius: var(--bl-radius); isolation: isolate; outline: none; }
7
+ .bl-dh:focus-visible { box-shadow: 0 0 0 3px var(--bl-accent); }
8
+ .bl-dh__base { display: block; transition: transform var(--bl-dur) cubic-bezier(.2,.9,.25,1); }
9
+ .bl-dh[data-open] .bl-dh__base { transform: scale(var(--bl-zoom)); }
10
+ .bl-dh__overlay { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; justify-content: flex-end; padding: 16px; box-sizing: border-box; background: var(--bl-overlay); color: var(--bl-ink); transform: translate(var(--bl-x, 0), var(--bl-y, 100%)); transition: transform var(--bl-dur) cubic-bezier(.2,.9,.25,1); }
11
+ .bl-dh[data-open] .bl-dh__overlay { transform: translate(0, 0); }
12
+ .bl-dh[data-instant] .bl-dh__overlay { transition: none; }
13
+ @media (prefers-reduced-motion: reduce) { .bl-dh__overlay { transform: none; opacity: 0; transition: opacity 150ms; } .bl-dh[data-open] .bl-dh__overlay { opacity: 1; } .bl-dh__base { transition: none; } }
14
+ `;
15
+ function useStyles() {
16
+ useInsertionEffect(() => {
17
+ if (typeof document === "undefined") return;
18
+ const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
19
+ style.textContent = CSS;
20
+ if (!style.isConnected) document.head.appendChild(style);
21
+ }, []);
22
+ }
23
+ const OFFSETS = { top: ["0", "-100%"], right: ["100%", "0"], bottom: ["0", "100%"], left: ["-100%", "0"] };
24
+ function edgeOf(rect, x, y) {
25
+ const dx = (x - rect.left - rect.width / 2) / (rect.width / 2);
26
+ const dy = (y - rect.top - rect.height / 2) / (rect.height / 2);
27
+ return Math.abs(dx) > Math.abs(dy) ? dx > 0 ? "right" : "left" : dy > 0 ? "bottom" : "top";
28
+ }
29
+ function DirectionHover({
30
+ children,
31
+ overlay,
32
+ duration = 320,
33
+ zoom = 1.06,
34
+ radius = 14,
35
+ overlayColor = "linear-gradient(to top, rgba(11,11,20,0.92), rgba(11,11,20,0.55))",
36
+ textColor = "#f4f4f4",
37
+ accentColor = "#73eff7",
38
+ className = "",
39
+ style,
40
+ ...rest
41
+ }) {
42
+ useStyles();
43
+ const ref = useRef(null);
44
+ const [open, setOpen] = useState(false);
45
+ const [from, setFrom] = useState("bottom");
46
+ const [instant, setInstant] = useState(false);
47
+ const enter = (event) => {
48
+ const side = edgeOf(ref.current.getBoundingClientRect(), event.clientX, event.clientY);
49
+ setInstant(true);
50
+ setFrom(side);
51
+ requestAnimationFrame(
52
+ () => requestAnimationFrame(() => {
53
+ setInstant(false);
54
+ setOpen(true);
55
+ })
56
+ );
57
+ };
58
+ const leave = (event) => {
59
+ setFrom(edgeOf(ref.current.getBoundingClientRect(), event.clientX, event.clientY));
60
+ setOpen(false);
61
+ };
62
+ const [x, y] = OFFSETS[from];
63
+ return /* @__PURE__ */ jsxs(
64
+ "div",
65
+ {
66
+ ref,
67
+ className: `bl-dh ${className}`,
68
+ "data-open": open || void 0,
69
+ "data-instant": instant || void 0,
70
+ onPointerEnter: (event) => event.pointerType === "mouse" && enter(event),
71
+ onPointerLeave: (event) => event.pointerType === "mouse" && leave(event),
72
+ onFocus: () => {
73
+ setFrom("bottom");
74
+ setOpen(true);
75
+ },
76
+ onBlur: (event) => {
77
+ if (!event.currentTarget.contains(event.relatedTarget)) setOpen(false);
78
+ },
79
+ style: { "--bl-x": x, "--bl-y": y, "--bl-dur": `${duration}ms`, "--bl-zoom": zoom, "--bl-radius": `${radius}px`, "--bl-overlay": overlayColor, "--bl-ink": textColor, "--bl-accent": accentColor, ...style },
80
+ ...rest,
81
+ children: [
82
+ /* @__PURE__ */ jsx("div", { className: "bl-dh__base", children }),
83
+ /* @__PURE__ */ jsx("div", { className: "bl-dh__overlay", children: overlay })
84
+ ]
85
+ }
86
+ );
87
+ }
88
+ export {
89
+ DirectionHover as default
90
+ };
@@ -0,0 +1,18 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ export interface DiscardProps {
3
+ /** The thing to throw away. */
4
+ children?: ReactNode;
5
+ /** Set to play the effect. */
6
+ discarded?: boolean;
7
+ /** Falling strips, a balled-up toss, or torn in two. */
8
+ effect?: 'shred' | 'crumple' | 'tear';
9
+ /** Shredder strips. */
10
+ strips?: number;
11
+ /** Effect length in ms. */
12
+ duration?: number;
13
+ /** Called when the effect has finished: remove the content here. */
14
+ onDiscarded?: () => void;
15
+ className?: string;
16
+ style?: CSSProperties;
17
+ }
18
+ export default function Discard({ children, discarded, effect, strips, duration, onDiscarded, className, style }: DiscardProps): import("react").JSX.Element;
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useInsertionEffect, useState } from "react";
4
+ const STYLE_ID = "bl-discard";
5
+ const CSS = `
6
+ .bl-discard { position: relative; }
7
+ .bl-discard__live[data-hidden] { visibility: hidden; }
8
+ .bl-discard__fx { position: absolute; inset: 0; pointer-events: none; }
9
+ .bl-discard__piece { position: absolute; inset: 0; overflow: hidden; }
10
+ .bl-discard[data-effect="shred"] .bl-discard__piece { clip-path: inset(0 calc(100% - var(--r)) 0 var(--l)); animation: bl-discard-strip var(--bl-dur) cubic-bezier(.5,0,.8,.4) both; animation-delay: calc(var(--i) * 25ms); }
11
+ .bl-discard[data-effect="tear"] .bl-discard__piece { clip-path: var(--edge); animation: bl-discard-tear var(--bl-dur) cubic-bezier(.4,0,.7,.5) both; }
12
+ .bl-discard[data-effect="crumple"] .bl-discard__piece { animation: bl-discard-crumple var(--bl-dur) steps(9) both; }
13
+ .bl-discard[data-effect="fade"] .bl-discard__piece { animation: bl-discard-fade var(--bl-dur) ease both; }
14
+ @keyframes bl-discard-strip { 20% { transform: translateY(6%); } to { transform: translateY(160%) rotate(calc(var(--s) * 6deg)); opacity: 0; } }
15
+ @keyframes bl-discard-tear { 25% { transform: translateX(calc(var(--s) * 4%)) rotate(calc(var(--s) * 2deg)); } to { transform: translate(calc(var(--s) * 40%), 70%) rotate(calc(var(--s) * 18deg)); opacity: 0; } }
16
+ @keyframes bl-discard-crumple { 40% { transform: scale(0.55) rotate(-25deg); border-radius: 40%; filter: brightness(0.8) contrast(1.4); } 60% { transform: scale(0.3) rotate(40deg); border-radius: 50%; } to { transform: translate(120%, -60%) scale(0.12) rotate(220deg); border-radius: 50%; opacity: 0; } }
17
+ @keyframes bl-discard-fade { to { opacity: 0; } }
18
+ @media (prefers-reduced-motion: reduce) { .bl-discard .bl-discard__piece { animation: bl-discard-fade 200ms ease both !important; clip-path: none !important; } }
19
+ `;
20
+ function useStyles() {
21
+ useInsertionEffect(() => {
22
+ if (typeof document === "undefined") return;
23
+ const style = document.getElementById(STYLE_ID) ?? Object.assign(document.createElement("style"), { id: STYLE_ID });
24
+ style.textContent = CSS;
25
+ if (!style.isConnected) document.head.appendChild(style);
26
+ }, []);
27
+ }
28
+ function tearEdges(teeth) {
29
+ const zig = Array.from({ length: teeth + 1 }, (_, i) => [50 + (i % 2 ? 4 : -4), i / teeth * 100]);
30
+ const line = zig.map(([x, y]) => `${x}% ${y}%`).join(", ");
31
+ const back = [...zig].reverse().map(([x, y]) => `${x}% ${y}%`).join(", ");
32
+ return [`polygon(0 0, ${line}, 0 100%)`, `polygon(100% 0, 100% 100%, ${back})`];
33
+ }
34
+ function Discard({ children, discarded = false, effect = "shred", strips = 8, duration = 900, onDiscarded, className = "", style }) {
35
+ useStyles();
36
+ const [playing, setPlaying] = useState(false);
37
+ useEffect(() => {
38
+ if (!discarded) {
39
+ setPlaying(false);
40
+ return void 0;
41
+ }
42
+ setPlaying(true);
43
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
44
+ const total = reduced ? 220 : duration + (effect === "shred" ? strips * 25 : 0);
45
+ const id = setTimeout(() => onDiscarded?.(), total);
46
+ return () => clearTimeout(id);
47
+ }, [discarded]);
48
+ let pieces = [];
49
+ if (playing) {
50
+ if (effect === "shred") pieces = Array.from({ length: strips }, (_, i) => ({ "--l": `${i / strips * 100}%`, "--r": `${(i + 1) / strips * 100}%`, "--i": i, "--s": i % 2 ? 1 : -1 }));
51
+ else if (effect === "tear") pieces = tearEdges(10).map((edge, i) => ({ "--edge": edge, "--s": i ? 1 : -1 }));
52
+ else pieces = [{}];
53
+ }
54
+ return /* @__PURE__ */ jsxs("div", { className: `bl-discard ${className}`, "data-effect": effect, style: { "--bl-dur": `${duration}ms`, ...style }, children: [
55
+ /* @__PURE__ */ jsx("div", { className: "bl-discard__live", "data-hidden": playing || void 0, children }),
56
+ playing && /* @__PURE__ */ jsx("div", { className: "bl-discard__fx", "aria-hidden": "true", children: pieces.map((vars, i) => /* @__PURE__ */ jsx("div", { className: "bl-discard__piece", style: vars, children }, i)) })
57
+ ] });
58
+ }
59
+ export {
60
+ Discard as default
61
+ };
@@ -0,0 +1,15 @@
1
+ import { type CSSProperties } from 'react';
2
+ export interface DitherFieldProps {
3
+ /** What moves underneath: drifting clouds, rolling waves or a pulsing ring. */
4
+ pattern?: 'noise' | 'waves' | 'radial';
5
+ /** Two or more colours, darkest first. */
6
+ palette?: string[];
7
+ scale?: number;
8
+ speed?: number;
9
+ pixelSize?: number;
10
+ /** The pointer adds a warm spot. */
11
+ pointer?: boolean;
12
+ className?: string;
13
+ style?: CSSProperties;
14
+ }
15
+ export default function DitherField({ pattern, palette, scale, speed, pixelSize, pointer, className, style }: DitherFieldProps): import("react").JSX.Element;
@@ -0,0 +1,157 @@
1
+ 'use client';
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from "react";
4
+ const hexToRgb = (hex) => {
5
+ const n = parseInt(hex.replace("#", "").replace(/^(.)(.)(.)$/, "$1$1$2$2$3$3"), 16);
6
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
7
+ };
8
+ const BAYER = [0, 32, 8, 40, 2, 34, 10, 42, 48, 16, 56, 24, 50, 18, 58, 26, 12, 44, 4, 36, 14, 46, 6, 38, 60, 28, 52, 20, 62, 30, 54, 22, 3, 35, 11, 43, 1, 33, 9, 41, 51, 19, 59, 27, 49, 17, 57, 25, 15, 47, 7, 39, 13, 45, 5, 37, 63, 31, 55, 23, 61, 29, 53, 21].map((v) => (v + 0.5) / 64);
9
+ const hash = (x, y, z) => {
10
+ let n = Math.imul(x, 374761393) ^ Math.imul(y, 668265263) ^ Math.imul(z, 1440662683);
11
+ n = Math.imul(n ^ n >>> 13, 1274126177);
12
+ return ((n ^ n >>> 16) >>> 0) / 4294967296;
13
+ };
14
+ const fade = (t) => t * t * (3 - 2 * t);
15
+ function noise(x, y, z) {
16
+ const xi = Math.floor(x);
17
+ const yi = Math.floor(y);
18
+ const zi = Math.floor(z);
19
+ const u = fade(x - xi);
20
+ const v = fade(y - yi);
21
+ const w = fade(z - zi);
22
+ const lerp = (a, b, k) => a + (b - a) * k;
23
+ const corner = (dx, dy, dz) => hash(xi + dx, yi + dy, zi + dz);
24
+ return lerp(
25
+ lerp(lerp(corner(0, 0, 0), corner(1, 0, 0), u), lerp(corner(0, 1, 0), corner(1, 1, 0), u), v),
26
+ lerp(lerp(corner(0, 0, 1), corner(1, 0, 1), u), lerp(corner(0, 1, 1), corner(1, 1, 1), u), v),
27
+ w
28
+ );
29
+ }
30
+ function DitherField({
31
+ pattern = "noise",
32
+ palette = ["#1a1c2c", "#5d275d", "#b13e53", "#ef7d57", "#ffcd75"],
33
+ scale = 1,
34
+ speed = 1,
35
+ pixelSize = 3,
36
+ pointer = true,
37
+ className = "",
38
+ style
39
+ }) {
40
+ const canvasRef = useRef(null);
41
+ useEffect(() => {
42
+ const canvas = canvasRef.current;
43
+ const ctx = canvas.getContext("2d");
44
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
45
+ const colors = palette.map(hexToRgb);
46
+ const steps = colors.length - 1;
47
+ const hand = { x: -1, y: -1, glow: 0, on: false };
48
+ let w = 0;
49
+ let h = 0;
50
+ let img = null;
51
+ let t = 0;
52
+ let raf = 0;
53
+ let last = 0;
54
+ let visible = true;
55
+ const fit = () => {
56
+ w = Math.max(1, Math.ceil(canvas.clientWidth / pixelSize));
57
+ h = Math.max(1, Math.ceil(canvas.clientHeight / pixelSize));
58
+ canvas.width = w;
59
+ canvas.height = h;
60
+ img = ctx.createImageData(w, h);
61
+ };
62
+ const value = (x, y) => {
63
+ const u = x / w;
64
+ const v = y / h;
65
+ const k = 3 * scale;
66
+ if (pattern === "waves") return 0.5 + 0.25 * Math.sin(u * k * 4 + Math.sin(v * k * 2 + t * 0.7) * 1.5 + t * 0.5) + 0.25 * Math.sin(v * k * 3 - t * 0.4);
67
+ if (pattern === "radial") {
68
+ const d = Math.hypot(u - 0.5, (v - 0.5) * (h / w)) * 2;
69
+ return 0.5 + 0.5 * Math.cos(d * k * 3 - t * 1.2);
70
+ }
71
+ const n = noise(u * k * 2, v * k * 2 * (h / w), t * 0.25) * 0.65 + noise(u * k * 5, v * k * 5 * (h / w), t * 0.4 + 9) * 0.35;
72
+ return (n - 0.22) / 0.56;
73
+ };
74
+ const frame = () => {
75
+ const d = img.data;
76
+ for (let y = 0; y < h; y++) {
77
+ for (let x = 0; x < w; x++) {
78
+ let v = value(x, y);
79
+ if (hand.glow > 0.01) {
80
+ const dx = (x - hand.x) / w;
81
+ const dy = (y - hand.y) / w;
82
+ v += Math.exp(-(dx * dx + dy * dy) / 0.012) * 0.6 * hand.glow;
83
+ }
84
+ const pos = Math.max(0, Math.min(steps, v * steps));
85
+ const base = Math.min(steps - 1, Math.floor(pos));
86
+ const pick = pos - base > BAYER[(y & 7) * 8 + (x & 7)] ? base + 1 : base;
87
+ const c = colors[pick];
88
+ const i = (y * w + x) * 4;
89
+ d[i] = c[0];
90
+ d[i + 1] = c[1];
91
+ d[i + 2] = c[2];
92
+ d[i + 3] = 255;
93
+ }
94
+ }
95
+ ctx.putImageData(img, 0, 0);
96
+ };
97
+ const tick = (now) => {
98
+ const dt = Math.max(0, Math.min(0.05, (now - last) / 1e3));
99
+ last = now;
100
+ t += dt * speed;
101
+ hand.glow += ((hand.on ? 1 : 0) - hand.glow) * Math.min(1, dt * 5);
102
+ frame();
103
+ raf = visible && !document.hidden ? requestAnimationFrame(tick) : 0;
104
+ };
105
+ const start = () => {
106
+ if (raf || reduced || !visible || document.hidden) return;
107
+ last = performance.now();
108
+ raf = requestAnimationFrame(tick);
109
+ };
110
+ const onMove = (event) => {
111
+ if (!pointer) return;
112
+ const r = canvas.getBoundingClientRect();
113
+ hand.x = (event.clientX - r.left) / r.width * w;
114
+ hand.y = (event.clientY - r.top) / r.height * h;
115
+ hand.on = true;
116
+ if (reduced) {
117
+ hand.glow = 1;
118
+ frame();
119
+ }
120
+ };
121
+ const onLeave = () => {
122
+ hand.on = false;
123
+ if (reduced) {
124
+ hand.glow = 0;
125
+ frame();
126
+ }
127
+ };
128
+ const resize = new ResizeObserver(() => {
129
+ fit();
130
+ frame();
131
+ });
132
+ resize.observe(canvas);
133
+ const observer = new IntersectionObserver(([entry]) => {
134
+ visible = entry.isIntersecting;
135
+ start();
136
+ });
137
+ observer.observe(canvas);
138
+ document.addEventListener("visibilitychange", start);
139
+ canvas.addEventListener("pointermove", onMove);
140
+ canvas.addEventListener("pointerleave", onLeave);
141
+ fit();
142
+ frame();
143
+ start();
144
+ return () => {
145
+ cancelAnimationFrame(raf);
146
+ resize.disconnect();
147
+ observer.disconnect();
148
+ document.removeEventListener("visibilitychange", start);
149
+ canvas.removeEventListener("pointermove", onMove);
150
+ canvas.removeEventListener("pointerleave", onLeave);
151
+ };
152
+ }, [pattern, palette.join(), scale, speed, pixelSize, pointer]);
153
+ return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, "aria-hidden": "true", className, style: { display: "block", width: "100%", height: "100%", background: palette[0], imageRendering: "pixelated", touchAction: "pan-y", ...style } });
154
+ }
155
+ export {
156
+ DitherField as default
157
+ };
@@ -0,0 +1,48 @@
1
+ import { type CSSProperties } from 'react';
2
+ /** [latitude, longitude] in degrees. */
3
+ export type LatLon = [number, number];
4
+ export interface GlobeMarker {
5
+ lat: number;
6
+ lon: number;
7
+ /** Also feeds the globe's accessible description. */
8
+ label?: string;
9
+ color?: string;
10
+ }
11
+ export interface GlobeArc {
12
+ from: LatLon;
13
+ to: LatLon;
14
+ }
15
+ export interface DotGlobeProps {
16
+ /** Max width, in px (the globe is square and shrinks to fit). */
17
+ size?: number;
18
+ /** Fibonacci samples over the whole sphere; roughly a third land on land. */
19
+ dotCount?: number;
20
+ /** Dot scale. */
21
+ dotSize?: number;
22
+ /** Square dots, for a pixel look. */
23
+ square?: boolean;
24
+ dotColor?: string;
25
+ oceanColor?: string;
26
+ glowColor?: string;
27
+ arcColor?: string;
28
+ markerColor?: string;
29
+ markers?: GlobeMarker[];
30
+ /** Great-circle arcs with a traveling comet. Longer arcs fly higher. */
31
+ arcs?: GlobeArc[];
32
+ /** Spin when idle; resumes after a drag settles. */
33
+ autoRotate?: boolean;
34
+ /** Spin speed, in degrees per second. */
35
+ rotateSpeed?: number;
36
+ /** Longitude facing the viewer at start. */
37
+ initialLon?: number;
38
+ /** Latitude tilted toward the viewer at start. */
39
+ initialLat?: number;
40
+ /** Drag with inertia (arrow keys always work when focused). */
41
+ draggable?: boolean;
42
+ /** Accessible name. */
43
+ label?: string;
44
+ className?: string;
45
+ style?: CSSProperties;
46
+ }
47
+ export declare function isLand(lat: number, lon: number): boolean;
48
+ export default function DotGlobe({ size, dotCount, dotSize, square, dotColor, oceanColor, glowColor, arcColor, markerColor, markers, arcs, autoRotate, rotateSpeed, initialLon, initialLat, draggable, label, className, style }: DotGlobeProps): import("react").JSX.Element;