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,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;
|