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,220 @@
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
+ function PixelType({
9
+ text = "PIXEL",
10
+ effect = "assemble",
11
+ pixelSize = 6,
12
+ gap = 1,
13
+ font = '"Press Start 2P", ui-monospace, monospace',
14
+ rows = 12,
15
+ colors = ["#ffcd75", "#ef7d57", "#b13e53"],
16
+ repel = 70,
17
+ stiffness = 90,
18
+ damping = 11,
19
+ hold = 2400,
20
+ trigger = "view",
21
+ align = "center",
22
+ className = "",
23
+ style
24
+ }) {
25
+ const canvasRef = useRef(null);
26
+ useEffect(() => {
27
+ const canvas = canvasRef.current;
28
+ const ctx = canvas.getContext("2d");
29
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
30
+ const pitch = pixelSize + gap;
31
+ const palette = colors.map(hexToRgb);
32
+ let blocks = [];
33
+ let W = 0;
34
+ let H = 0;
35
+ let gridW = 0;
36
+ let dpr = 1;
37
+ let raf = 0;
38
+ let last = 0;
39
+ let visible = true;
40
+ let started = trigger === "mount";
41
+ let phase = "idle";
42
+ let phaseAt = 0;
43
+ const pointer = { x: -1e4, y: -1e4 };
44
+ const raster = () => {
45
+ const probe = document.createElement("canvas").getContext("2d");
46
+ probe.font = `${rows}px ${font}`;
47
+ const w = Math.ceil(probe.measureText(text).width) + 2;
48
+ const off = document.createElement("canvas");
49
+ off.width = Math.max(1, w);
50
+ off.height = rows + 2;
51
+ const o = off.getContext("2d");
52
+ o.font = `${rows}px ${font}`;
53
+ o.textBaseline = "middle";
54
+ o.fillStyle = "#fff";
55
+ o.fillText(text, 1, (rows + 2) / 2 + 1);
56
+ const data = o.getImageData(0, 0, off.width, off.height).data;
57
+ const cells = [];
58
+ for (let y = 0; y < off.height; y++) for (let x = 0; x < off.width; x++) if (data[(y * off.width + x) * 4 + 3] > 120) cells.push([x, y]);
59
+ return { cells, w: off.width, h: off.height };
60
+ };
61
+ const layout = () => {
62
+ const { cells, w, h } = raster();
63
+ gridW = w * pitch;
64
+ dpr = Math.min(2, window.devicePixelRatio || 1);
65
+ W = canvas.clientWidth;
66
+ H = h * pitch;
67
+ canvas.style.height = `${H}px`;
68
+ canvas.width = Math.round(W * dpr);
69
+ canvas.height = Math.round(H * dpr);
70
+ const ox = align === "start" ? 0 : align === "end" ? W - gridW : (W - gridW) / 2;
71
+ const old = blocks;
72
+ blocks = cells.map(([cx, cy], i) => {
73
+ const hx = ox + cx * pitch;
74
+ const hy = cy * pitch;
75
+ const prev = old[i];
76
+ const color = palette[Math.min(palette.length - 1, Math.floor(cy / h * palette.length))];
77
+ return prev ? { ...prev, hx, hy, color } : { hx, hy, x: hx, y: hy, vx: 0, vy: 0, color, loose: false };
78
+ });
79
+ };
80
+ const scatter = () => {
81
+ blocks.forEach((b) => {
82
+ b.x = Math.random() * W;
83
+ b.y = H + Math.random() * H * 2;
84
+ b.vx = 0;
85
+ b.vy = 0;
86
+ b.loose = false;
87
+ });
88
+ };
89
+ const draw = () => {
90
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
91
+ ctx.clearRect(0, 0, W, H);
92
+ if (!started && !reduced) return;
93
+ blocks.forEach((b) => {
94
+ const [r, g, bl] = b.color;
95
+ ctx.fillStyle = `rgb(${r},${g},${bl})`;
96
+ ctx.fillRect(Math.round(b.x), Math.round(b.y), pixelSize, pixelSize);
97
+ });
98
+ };
99
+ const tick = (now) => {
100
+ const dt = Math.max(0, Math.min(0.033, (now - last) / 1e3));
101
+ last = now;
102
+ if (phase === "holding" && effect === "crumble" && now - phaseAt > hold) {
103
+ phase = "falling";
104
+ phaseAt = now;
105
+ blocks.forEach((b) => {
106
+ b.loose = true;
107
+ b.vx = (Math.random() - 0.5) * 120;
108
+ b.vy = -Math.random() * 160;
109
+ });
110
+ }
111
+ if (phase === "falling" && now - phaseAt > 1400) {
112
+ phase = "forming";
113
+ phaseAt = now;
114
+ blocks.forEach((b) => b.loose = false);
115
+ }
116
+ let moving = false;
117
+ blocks.forEach((b) => {
118
+ if (b.loose) {
119
+ b.vy += 900 * dt;
120
+ b.x += b.vx * dt;
121
+ b.y = Math.min(H * 3, b.y + b.vy * dt);
122
+ moving = true;
123
+ return;
124
+ }
125
+ let tx = b.hx;
126
+ let ty = b.hy;
127
+ const dx = b.x - pointer.x;
128
+ const dy = b.y - pointer.y;
129
+ const d = Math.hypot(dx, dy);
130
+ if (d < repel && d > 0) {
131
+ const push = (1 - d / repel) * repel * 0.6;
132
+ tx += dx / d * push;
133
+ ty += dy / d * push;
134
+ }
135
+ b.vx += (stiffness * (tx - b.x) - damping * b.vx) * dt;
136
+ b.vy += (stiffness * (ty - b.y) - damping * b.vy) * dt;
137
+ b.x += b.vx * dt;
138
+ b.y += b.vy * dt;
139
+ if (Math.abs(tx - b.x) > 0.3 || Math.abs(ty - b.y) > 0.3 || Math.abs(b.vx) > 2 || Math.abs(b.vy) > 2) moving = true;
140
+ else if (tx === b.hx && ty === b.hy) {
141
+ b.x = b.hx;
142
+ b.y = b.hy;
143
+ b.vx = 0;
144
+ b.vy = 0;
145
+ }
146
+ });
147
+ if (phase === "forming" && !moving) {
148
+ phase = "holding";
149
+ phaseAt = now;
150
+ }
151
+ draw();
152
+ const busy = moving || effect === "crumble" && phase !== "idle";
153
+ raf = busy && visible && !document.hidden ? requestAnimationFrame(tick) : 0;
154
+ };
155
+ const wake = () => {
156
+ if (raf || reduced || !visible || document.hidden || !started) return;
157
+ last = performance.now();
158
+ raf = requestAnimationFrame(tick);
159
+ };
160
+ const start = () => {
161
+ started = true;
162
+ if (reduced) return;
163
+ scatter();
164
+ phase = "forming";
165
+ wake();
166
+ };
167
+ const onMove = (event) => {
168
+ const rect = canvas.getBoundingClientRect();
169
+ pointer.x = event.clientX - rect.left;
170
+ pointer.y = event.clientY - rect.top;
171
+ wake();
172
+ };
173
+ const onLeave = () => {
174
+ pointer.x = -1e4;
175
+ pointer.y = -1e4;
176
+ wake();
177
+ };
178
+ const resize = new ResizeObserver(() => {
179
+ layout();
180
+ draw();
181
+ });
182
+ resize.observe(canvas);
183
+ const observer = new IntersectionObserver(([entry]) => {
184
+ visible = entry.isIntersecting;
185
+ if (visible && !started && trigger === "view") start();
186
+ else wake();
187
+ }, { threshold: 0.2 });
188
+ observer.observe(canvas);
189
+ const onVisibility = () => wake();
190
+ document.addEventListener("visibilitychange", onVisibility);
191
+ canvas.addEventListener("pointermove", onMove);
192
+ canvas.addEventListener("pointerleave", onLeave);
193
+ document.fonts?.load(`${rows}px ${font}`).then(() => {
194
+ if (!canvas.isConnected) return;
195
+ blocks = [];
196
+ layout();
197
+ if (started && !reduced) {
198
+ scatter();
199
+ phase = "forming";
200
+ wake();
201
+ }
202
+ draw();
203
+ });
204
+ layout();
205
+ if (started) start();
206
+ draw();
207
+ return () => {
208
+ cancelAnimationFrame(raf);
209
+ resize.disconnect();
210
+ observer.disconnect();
211
+ document.removeEventListener("visibilitychange", onVisibility);
212
+ canvas.removeEventListener("pointermove", onMove);
213
+ canvas.removeEventListener("pointerleave", onLeave);
214
+ };
215
+ }, [text, effect, pixelSize, gap, font, rows, colors.join(), repel, stiffness, damping, hold, trigger, align]);
216
+ return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, role: "img", "aria-label": text, className, style: { display: "block", width: "100%", touchAction: "pan-y", ...style } });
217
+ }
218
+ export {
219
+ PixelType as default
220
+ };
@@ -0,0 +1,23 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ export type PointerMode = 'trail' | 'crosshair' | 'target' | 'sparks' | 'blob';
3
+ export interface PointerKitProps {
4
+ /** The area it covers (ignored by global). */
5
+ children?: ReactNode;
6
+ /** One look or several together. */
7
+ mode?: PointerMode | PointerMode[];
8
+ /** Cover the whole window instead of the children. */
9
+ global?: boolean;
10
+ hideCursor?: boolean;
11
+ color?: string;
12
+ accentColor?: string;
13
+ pixelSize?: number;
14
+ trailLength?: number;
15
+ /** Blob lag: 1 follows exactly, lower lags more. */
16
+ smoothing?: number;
17
+ /** What the target brackets snap to. */
18
+ targets?: string;
19
+ sparkCount?: number;
20
+ className?: string;
21
+ style?: CSSProperties;
22
+ }
23
+ export default function PointerKit({ children, mode, global, hideCursor, color, accentColor, pixelSize, trailLength, smoothing, targets, sparkCount, className, style }: PointerKitProps): import("react").JSX.Element;
@@ -0,0 +1,222 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from "react";
4
+ const hexToRgb = (hex) => {
5
+ const n = parseInt(hex.replace("#", "").replace(/^(.)(.)(.)$/, "$1$1$2$2$3$3"), 16);
6
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
7
+ };
8
+ const rgba = ([r, g, b], a) => `rgba(${r},${g},${b},${a})`;
9
+ const TARGETS = 'a, button, input, select, textarea, [role="button"], [data-pointer-target]';
10
+ function PointerKit({
11
+ children,
12
+ mode = ["trail", "sparks"],
13
+ global = false,
14
+ hideCursor = false,
15
+ color = "#73eff7",
16
+ accentColor = "#ffcd75",
17
+ pixelSize = 6,
18
+ trailLength = 24,
19
+ smoothing = 0.18,
20
+ targets = TARGETS,
21
+ sparkCount = 14,
22
+ className = "",
23
+ style
24
+ }) {
25
+ const rootRef = useRef(null);
26
+ const canvasRef = useRef(null);
27
+ const modes = Array.isArray(mode) ? mode : [mode];
28
+ const key = modes.join(",");
29
+ useEffect(() => {
30
+ const root = rootRef.current;
31
+ const canvas = canvasRef.current;
32
+ const ctx = canvas.getContext("2d");
33
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
34
+ const fine = window.matchMedia?.("(pointer: fine)").matches ?? true;
35
+ const on = new Set(key.split(","));
36
+ if (reduced) ["trail", "blob", "sparks"].forEach((m) => on.delete(m));
37
+ if (!fine) ["trail", "blob", "crosshair", "target"].forEach((m) => on.delete(m));
38
+ const main = hexToRgb(color);
39
+ const accent = hexToRgb(accentColor);
40
+ const area = global ? window : root;
41
+ let W = 0;
42
+ let H = 0;
43
+ let dpr = 1;
44
+ const p = { x: -1e4, y: -1e4, inside: false };
45
+ const blob = { x: -1e4, y: -1e4, vx: 0, vy: 0 };
46
+ const trail = [];
47
+ const sparks = [];
48
+ let box = null;
49
+ let goal = null;
50
+ let raf = 0;
51
+ let last = 0;
52
+ const size = () => {
53
+ dpr = Math.min(2, window.devicePixelRatio || 1);
54
+ W = global ? window.innerWidth : root.clientWidth;
55
+ H = global ? window.innerHeight : root.clientHeight;
56
+ canvas.width = Math.round(W * dpr);
57
+ canvas.height = Math.round(H * dpr);
58
+ };
59
+ const origin = () => global ? { left: 0, top: 0 } : root.getBoundingClientRect();
60
+ const draw = (now) => {
61
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
62
+ ctx.clearRect(0, 0, W, H);
63
+ const snap = (v) => Math.round(v / pixelSize) * pixelSize;
64
+ if (on.has("trail")) {
65
+ trail.forEach((t, i) => {
66
+ const life = 1 - (now - t.at) / (trailLength * 22);
67
+ if (life <= 0) return;
68
+ const s = Math.max(2, pixelSize * life * (i / trail.length + 0.4));
69
+ ctx.fillStyle = rgba(i % 3 === 0 ? accent : main, life * 0.9);
70
+ ctx.fillRect(snap(t.x) - s / 2, snap(t.y) - s / 2, s, s);
71
+ });
72
+ }
73
+ if (on.has("blob") && p.inside) {
74
+ const speed = Math.min(1, Math.hypot(blob.vx, blob.vy) / 40);
75
+ const angle = Math.atan2(blob.vy, blob.vx);
76
+ ctx.save();
77
+ ctx.translate(blob.x, blob.y);
78
+ ctx.rotate(angle);
79
+ ctx.scale(1 + speed * 0.6, 1 - speed * 0.35);
80
+ ctx.fillStyle = rgba(main, 0.35);
81
+ ctx.beginPath();
82
+ ctx.arc(0, 0, pixelSize * 3, 0, Math.PI * 2);
83
+ ctx.fill();
84
+ ctx.restore();
85
+ }
86
+ if (on.has("crosshair") && p.inside) {
87
+ ctx.fillStyle = rgba(main, 0.45);
88
+ const x = Math.round(p.x);
89
+ const y = Math.round(p.y);
90
+ for (let i = 0; i < W; i += pixelSize * 2) if (Math.abs(i - x) > pixelSize * 3) ctx.fillRect(i, y, pixelSize, 1);
91
+ for (let i = 0; i < H; i += pixelSize * 2) if (Math.abs(i - y) > pixelSize * 3) ctx.fillRect(x, i, 1, pixelSize);
92
+ ctx.font = `10px ui-monospace, monospace`;
93
+ ctx.fillStyle = rgba(accent, 0.9);
94
+ ctx.fillText(`${x},${y}`, Math.min(W - 60, x + 10), Math.max(12, y - 8));
95
+ }
96
+ if (on.has("target") && box) {
97
+ const arm = Math.min(14, box.w / 3, box.h / 3);
98
+ ctx.strokeStyle = rgba(accent, box.alpha);
99
+ ctx.lineWidth = 2;
100
+ const corners = [
101
+ [box.x, box.y, 1, 1],
102
+ [box.x + box.w, box.y, -1, 1],
103
+ [box.x, box.y + box.h, 1, -1],
104
+ [box.x + box.w, box.y + box.h, -1, -1]
105
+ ];
106
+ ctx.beginPath();
107
+ corners.forEach(([cx, cy, sx, sy]) => {
108
+ ctx.moveTo(cx, cy + sy * arm);
109
+ ctx.lineTo(cx, cy);
110
+ ctx.lineTo(cx + sx * arm, cy);
111
+ });
112
+ ctx.stroke();
113
+ }
114
+ sparks.forEach((s) => {
115
+ ctx.fillStyle = rgba(s.accent ? accent : main, Math.max(0, s.life));
116
+ ctx.fillRect(snap(s.x), snap(s.y), pixelSize * 0.8, pixelSize * 0.8);
117
+ });
118
+ };
119
+ const tick = (now) => {
120
+ const dt = Math.max(0, Math.min(0.05, (now - last) / 1e3));
121
+ last = now;
122
+ const k = reduced ? 1 : smoothing;
123
+ blob.vx = (p.x - blob.x) * k;
124
+ blob.vy = (p.y - blob.y) * k;
125
+ blob.x += blob.vx;
126
+ blob.y += blob.vy;
127
+ while (trail.length && now - trail[0].at > trailLength * 22) trail.shift();
128
+ for (let i = sparks.length - 1; i >= 0; i--) {
129
+ const s = sparks[i];
130
+ s.vy += 600 * dt;
131
+ s.x += s.vx * dt;
132
+ s.y += s.vy * dt;
133
+ s.life -= dt * 1.6;
134
+ if (s.life <= 0) sparks.splice(i, 1);
135
+ }
136
+ if (on.has("target")) {
137
+ if (goal && !box) box = { ...goal, alpha: 0 };
138
+ if (box) {
139
+ const to = goal ?? box;
140
+ const e = reduced ? 1 : 0.3;
141
+ box.x += (to.x - box.x) * e;
142
+ box.y += (to.y - box.y) * e;
143
+ box.w += (to.w - box.w) * e;
144
+ box.h += (to.h - box.h) * e;
145
+ box.alpha += ((goal ? 1 : 0) - box.alpha) * (reduced ? 1 : 0.25);
146
+ if (!goal && box.alpha < 0.02) box = null;
147
+ }
148
+ }
149
+ draw(now);
150
+ const busy = trail.length || sparks.length || on.has("blob") && Math.hypot(blob.vx, blob.vy) > 0.1 || box && (goal ? Math.abs(goal.x - box.x) + Math.abs(goal.w - box.w) > 0.3 || box.alpha < 0.98 : true);
151
+ raf = busy ? requestAnimationFrame(tick) : 0;
152
+ };
153
+ const wake = () => {
154
+ if (!raf) {
155
+ last = performance.now();
156
+ raf = requestAnimationFrame(tick);
157
+ }
158
+ };
159
+ const onMove = (event) => {
160
+ const o = origin();
161
+ p.x = event.clientX - o.left;
162
+ p.y = event.clientY - o.top;
163
+ p.inside = true;
164
+ if (on.has("trail")) {
165
+ trail.push({ x: p.x, y: p.y, at: performance.now() });
166
+ if (trail.length > trailLength) trail.shift();
167
+ }
168
+ if (on.has("target")) {
169
+ const el = event.target.closest?.(targets);
170
+ if (el && (global || root.contains(el))) {
171
+ const r = el.getBoundingClientRect();
172
+ goal = { x: r.left - o.left - 4, y: r.top - o.top - 4, w: r.width + 8, h: r.height + 8 };
173
+ } else goal = null;
174
+ }
175
+ if (blob.x < -1e3) {
176
+ blob.x = p.x;
177
+ blob.y = p.y;
178
+ }
179
+ wake();
180
+ };
181
+ const onLeave = () => {
182
+ p.inside = false;
183
+ goal = null;
184
+ blob.x = -1e4;
185
+ wake();
186
+ };
187
+ const onDown = (event) => {
188
+ if (!on.has("sparks")) return;
189
+ const o = origin();
190
+ const x = event.clientX - o.left;
191
+ const y = event.clientY - o.top;
192
+ for (let i = 0; i < sparkCount; i++) {
193
+ const a = i / sparkCount * Math.PI * 2 + Math.random() * 0.4;
194
+ const v = 140 + Math.random() * 160;
195
+ sparks.push({ x, y, vx: Math.cos(a) * v, vy: Math.sin(a) * v - 120, life: 1, accent: i % 2 === 0 });
196
+ }
197
+ wake();
198
+ };
199
+ size();
200
+ const resize = new ResizeObserver(size);
201
+ resize.observe(root);
202
+ window.addEventListener("resize", size);
203
+ area.addEventListener("pointermove", onMove, { passive: true });
204
+ area.addEventListener("pointerdown", onDown, { passive: true });
205
+ (global ? document.documentElement : root).addEventListener("pointerleave", onLeave);
206
+ return () => {
207
+ cancelAnimationFrame(raf);
208
+ resize.disconnect();
209
+ window.removeEventListener("resize", size);
210
+ area.removeEventListener("pointermove", onMove);
211
+ area.removeEventListener("pointerdown", onDown);
212
+ (global ? document.documentElement : root).removeEventListener("pointerleave", onLeave);
213
+ };
214
+ }, [key, global, color, accentColor, pixelSize, trailLength, smoothing, targets, sparkCount]);
215
+ return /* @__PURE__ */ jsxs("div", { ref: rootRef, className, style: { position: "relative", cursor: hideCursor ? "none" : void 0, ...style }, children: [
216
+ children,
217
+ /* @__PURE__ */ jsx("canvas", { ref: canvasRef, "aria-hidden": "true", style: { position: global ? "fixed" : "absolute", inset: 0, width: global ? "100vw" : "100%", height: global ? "100vh" : "100%", pointerEvents: "none", zIndex: 2147483e3 } })
218
+ ] });
219
+ }
220
+ export {
221
+ PointerKit as default
222
+ };
@@ -0,0 +1,41 @@
1
+ import { type CSSProperties } from 'react';
2
+ export interface Photo {
3
+ src: string;
4
+ /** Shown under the photo; also names it for screen readers. */
5
+ caption?: string;
6
+ /** Used as the name when there is no caption. */
7
+ alt?: string;
8
+ }
9
+ export interface PolaroidsProps {
10
+ photos?: Photo[];
11
+ /** Table height in px. */
12
+ height?: number;
13
+ photoWidth?: number;
14
+ /** White border around the image, in px. */
15
+ frame?: number;
16
+ captionHeight?: number;
17
+ /** How quickly a throw slows down (per second). */
18
+ friction?: number;
19
+ /** Share of speed kept when bouncing off an edge (0–1). */
20
+ bounce?: number;
21
+ /** How much an off-centre grip spins a thrown photo. */
22
+ spin?: number;
23
+ /** Show the Scatter and Tidy up buttons. */
24
+ showControls?: boolean;
25
+ scatterLabel?: string;
26
+ tidyLabel?: string;
27
+ /** Accessible name of the table. */
28
+ label?: string;
29
+ radius?: number;
30
+ backgroundColor?: string;
31
+ paperColor?: string;
32
+ textColor?: string;
33
+ lineColor?: string;
34
+ accentColor?: string;
35
+ buttonColor?: string;
36
+ buttonTextColor?: string;
37
+ fontFamily?: string;
38
+ className?: string;
39
+ style?: CSSProperties;
40
+ }
41
+ export default function Polaroids({ photos, height, photoWidth, frame, captionHeight, friction, bounce, spin, showControls, scatterLabel, tidyLabel, label, radius, backgroundColor, paperColor, textColor, lineColor, accentColor, buttonColor, buttonTextColor, fontFamily, className, style }: PolaroidsProps): import("react").JSX.Element;