markupr 2.1.8
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/.claude/commands/review-feedback.md +47 -0
- package/.eslintrc.json +35 -0
- package/.github/CODEOWNERS +16 -0
- package/.github/FUNDING.yml +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +56 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +54 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +89 -0
- package/.github/dependabot.yml +70 -0
- package/.github/workflows/ci.yml +184 -0
- package/.github/workflows/deploy-landing.yml +134 -0
- package/.github/workflows/nightly.yml +288 -0
- package/.github/workflows/release.yml +318 -0
- package/CHANGELOG.md +127 -0
- package/CLAUDE.md +137 -0
- package/CODE_OF_CONDUCT.md +9 -0
- package/CONTRIBUTING.md +390 -0
- package/LICENSE +21 -0
- package/PRODUCT_VISION.md +277 -0
- package/README.md +517 -0
- package/SECURITY.md +51 -0
- package/SIGNING_INSTRUCTIONS.md +284 -0
- package/assets/DMG_BACKGROUND_INSTRUCTIONS.md +130 -0
- package/assets/svg-source/dmg-background.svg +70 -0
- package/assets/svg-source/icon.svg +20 -0
- package/assets/svg-source/tray-icon-processing.svg +7 -0
- package/assets/svg-source/tray-icon-recording.svg +7 -0
- package/assets/svg-source/tray-icon.svg +6 -0
- package/assets/tray-complete.png +0 -0
- package/assets/tray-complete@2x.png +0 -0
- package/assets/tray-completeTemplate.png +0 -0
- package/assets/tray-completeTemplate@2x.png +0 -0
- package/assets/tray-error.png +0 -0
- package/assets/tray-error@2x.png +0 -0
- package/assets/tray-errorTemplate.png +0 -0
- package/assets/tray-errorTemplate@2x.png +0 -0
- package/assets/tray-icon-processing.png +0 -0
- package/assets/tray-icon-processing@2x.png +0 -0
- package/assets/tray-icon-processingTemplate.png +0 -0
- package/assets/tray-icon-processingTemplate@2x.png +0 -0
- package/assets/tray-icon-recording.png +0 -0
- package/assets/tray-icon-recording@2x.png +0 -0
- package/assets/tray-icon-recordingTemplate.png +0 -0
- package/assets/tray-icon-recordingTemplate@2x.png +0 -0
- package/assets/tray-icon.png +0 -0
- package/assets/tray-icon@2x.png +0 -0
- package/assets/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/assets/tray-idle.png +0 -0
- package/assets/tray-idle@2x.png +0 -0
- package/assets/tray-idleTemplate.png +0 -0
- package/assets/tray-idleTemplate@2x.png +0 -0
- package/assets/tray-processing-0.png +0 -0
- package/assets/tray-processing-0@2x.png +0 -0
- package/assets/tray-processing-0Template.png +0 -0
- package/assets/tray-processing-0Template@2x.png +0 -0
- package/assets/tray-processing-1.png +0 -0
- package/assets/tray-processing-1@2x.png +0 -0
- package/assets/tray-processing-1Template.png +0 -0
- package/assets/tray-processing-1Template@2x.png +0 -0
- package/assets/tray-processing-2.png +0 -0
- package/assets/tray-processing-2@2x.png +0 -0
- package/assets/tray-processing-2Template.png +0 -0
- package/assets/tray-processing-2Template@2x.png +0 -0
- package/assets/tray-processing-3.png +0 -0
- package/assets/tray-processing-3@2x.png +0 -0
- package/assets/tray-processing-3Template.png +0 -0
- package/assets/tray-processing-3Template@2x.png +0 -0
- package/assets/tray-processing.png +0 -0
- package/assets/tray-processing@2x.png +0 -0
- package/assets/tray-processingTemplate.png +0 -0
- package/assets/tray-processingTemplate@2x.png +0 -0
- package/assets/tray-recording.png +0 -0
- package/assets/tray-recording@2x.png +0 -0
- package/assets/tray-recordingTemplate.png +0 -0
- package/assets/tray-recordingTemplate@2x.png +0 -0
- package/build/DMG_BACKGROUND_SPEC.md +50 -0
- package/build/dmg-background.png +0 -0
- package/build/dmg-background@2x.png +0 -0
- package/build/entitlements.mac.inherit.plist +27 -0
- package/build/entitlements.mac.plist +41 -0
- package/build/favicon-16.png +0 -0
- package/build/favicon-180.png +0 -0
- package/build/favicon-192.png +0 -0
- package/build/favicon-32.png +0 -0
- package/build/favicon-48.png +0 -0
- package/build/favicon-512.png +0 -0
- package/build/favicon-64.png +0 -0
- package/build/icon-128.png +0 -0
- package/build/icon-16.png +0 -0
- package/build/icon-24.png +0 -0
- package/build/icon-256.png +0 -0
- package/build/icon-32.png +0 -0
- package/build/icon-48.png +0 -0
- package/build/icon-64.png +0 -0
- package/build/icon.icns +0 -0
- package/build/icon.ico +0 -0
- package/build/icon.iconset/icon_128x128.png +0 -0
- package/build/icon.iconset/icon_128x128@2x.png +0 -0
- package/build/icon.iconset/icon_16x16.png +0 -0
- package/build/icon.iconset/icon_16x16@2x.png +0 -0
- package/build/icon.iconset/icon_256x256.png +0 -0
- package/build/icon.iconset/icon_256x256@2x.png +0 -0
- package/build/icon.iconset/icon_32x32.png +0 -0
- package/build/icon.iconset/icon_32x32@2x.png +0 -0
- package/build/icon.iconset/icon_512x512.png +0 -0
- package/build/icon.iconset/icon_512x512@2x.png +0 -0
- package/build/icon.png +0 -0
- package/build/installer-header.bmp +0 -0
- package/build/installer-header.png +0 -0
- package/build/installer-sidebar.bmp +0 -0
- package/build/installer-sidebar.png +0 -0
- package/build/installer.nsh +45 -0
- package/build/overlay-processing.png +0 -0
- package/build/overlay-recording.png +0 -0
- package/build/toolbar-record.png +0 -0
- package/build/toolbar-screenshot.png +0 -0
- package/build/toolbar-settings.png +0 -0
- package/build/toolbar-stop.png +0 -0
- package/dist/main/index.mjs +12612 -0
- package/dist/preload/index.mjs +907 -0
- package/dist/renderer/assets/index-CCmUjl9K.js +19495 -0
- package/dist/renderer/assets/index-CUqz_Gs6.css +2270 -0
- package/dist/renderer/index.html +27 -0
- package/docs/AI_AGENT_QUICKSTART.md +42 -0
- package/docs/AI_PIPELINE_DESIGN.md +595 -0
- package/docs/API.md +514 -0
- package/docs/ARCHITECTURE.md +460 -0
- package/docs/CONFIGURATION.md +336 -0
- package/docs/DEVELOPMENT.md +508 -0
- package/docs/EXPORT_FORMATS.md +451 -0
- package/docs/GETTING_STARTED.md +236 -0
- package/docs/KEYBOARD_SHORTCUTS.md +334 -0
- package/docs/TROUBLESHOOTING.md +418 -0
- package/docs/landing/index.html +672 -0
- package/docs/landing/script.js +342 -0
- package/docs/landing/styles.css +1543 -0
- package/electron-builder.yml +140 -0
- package/electron.vite.config.ts +63 -0
- package/package.json +108 -0
- package/railway.json +12 -0
- package/scripts/build.mjs +51 -0
- package/scripts/generate-icons.mjs +314 -0
- package/scripts/generate-installer-images.cjs +253 -0
- package/scripts/generate-tray-icons.mjs +258 -0
- package/scripts/notarize.cjs +180 -0
- package/scripts/one-click-clean-test.sh +147 -0
- package/scripts/postinstall.mjs +36 -0
- package/scripts/setup-markupr.sh +55 -0
- package/setup +17 -0
- package/site/index.html +1835 -0
- package/site/package.json +11 -0
- package/site/railway.json +12 -0
- package/site/server.js +31 -0
- package/src/main/AutoUpdater.ts +392 -0
- package/src/main/CrashRecovery.ts +655 -0
- package/src/main/ErrorHandler.ts +703 -0
- package/src/main/HotkeyManager.ts +399 -0
- package/src/main/MenuManager.ts +529 -0
- package/src/main/PermissionManager.ts +420 -0
- package/src/main/SessionController.ts +1465 -0
- package/src/main/TrayManager.ts +540 -0
- package/src/main/ai/AIPipelineManager.ts +199 -0
- package/src/main/ai/ClaudeAnalyzer.ts +339 -0
- package/src/main/ai/ImageOptimizer.ts +176 -0
- package/src/main/ai/StructuredMarkdownBuilder.ts +379 -0
- package/src/main/ai/index.ts +16 -0
- package/src/main/ai/types.ts +258 -0
- package/src/main/analysis/ClarificationGenerator.ts +385 -0
- package/src/main/analysis/FeedbackAnalyzer.ts +531 -0
- package/src/main/analysis/index.ts +19 -0
- package/src/main/audio/AudioCapture.ts +978 -0
- package/src/main/audio/audioUtils.ts +100 -0
- package/src/main/audio/index.ts +20 -0
- package/src/main/capture/index.ts +1 -0
- package/src/main/index.ts +1693 -0
- package/src/main/ipc/captureHandlers.ts +272 -0
- package/src/main/ipc/index.ts +45 -0
- package/src/main/ipc/outputHandlers.ts +302 -0
- package/src/main/ipc/sessionHandlers.ts +56 -0
- package/src/main/ipc/settingsHandlers.ts +471 -0
- package/src/main/ipc/types.ts +56 -0
- package/src/main/ipc/windowHandlers.ts +277 -0
- package/src/main/output/ClipboardService.ts +369 -0
- package/src/main/output/ExportService.ts +539 -0
- package/src/main/output/FileManager.ts +416 -0
- package/src/main/output/MarkdownGenerator.ts +791 -0
- package/src/main/output/MarkdownPatcher.ts +299 -0
- package/src/main/output/index.ts +186 -0
- package/src/main/output/sessionAdapter.ts +207 -0
- package/src/main/output/templates/html-template.ts +553 -0
- package/src/main/pipeline/FrameExtractor.ts +330 -0
- package/src/main/pipeline/PostProcessor.ts +399 -0
- package/src/main/pipeline/TranscriptAnalyzer.ts +226 -0
- package/src/main/pipeline/index.ts +36 -0
- package/src/main/platform/WindowsTaskbar.ts +600 -0
- package/src/main/platform/index.ts +16 -0
- package/src/main/settings/SettingsManager.ts +730 -0
- package/src/main/settings/index.ts +19 -0
- package/src/main/transcription/ModelDownloadManager.ts +494 -0
- package/src/main/transcription/TierManager.ts +219 -0
- package/src/main/transcription/TranscriptionRecoveryService.ts +340 -0
- package/src/main/transcription/WhisperService.ts +748 -0
- package/src/main/transcription/index.ts +56 -0
- package/src/main/transcription/types.ts +135 -0
- package/src/main/windows/PopoverManager.ts +284 -0
- package/src/main/windows/TaskbarIntegration.ts +452 -0
- package/src/main/windows/index.ts +23 -0
- package/src/preload/index.ts +1047 -0
- package/src/renderer/App.tsx +515 -0
- package/src/renderer/AppWrapper.tsx +28 -0
- package/src/renderer/assets/logo-dark.svg +7 -0
- package/src/renderer/assets/logo.svg +7 -0
- package/src/renderer/audio/AudioCaptureRenderer.ts +454 -0
- package/src/renderer/capture/ScreenRecordingRenderer.ts +492 -0
- package/src/renderer/components/AnnotationOverlay.tsx +836 -0
- package/src/renderer/components/AudioWaveform.tsx +811 -0
- package/src/renderer/components/ClarificationQuestions.tsx +656 -0
- package/src/renderer/components/CountdownTimer.tsx +495 -0
- package/src/renderer/components/CrashRecoveryDialog.tsx +632 -0
- package/src/renderer/components/DonateButton.tsx +127 -0
- package/src/renderer/components/ErrorBoundary.tsx +308 -0
- package/src/renderer/components/ExportDialog.tsx +872 -0
- package/src/renderer/components/HotkeyHint.tsx +261 -0
- package/src/renderer/components/KeyboardShortcuts.tsx +787 -0
- package/src/renderer/components/ModelDownloadDialog.tsx +844 -0
- package/src/renderer/components/Onboarding.tsx +1830 -0
- package/src/renderer/components/ProcessingOverlay.tsx +157 -0
- package/src/renderer/components/RecordingOverlay.tsx +423 -0
- package/src/renderer/components/SessionHistory.tsx +1746 -0
- package/src/renderer/components/SessionReview.tsx +1321 -0
- package/src/renderer/components/SettingsPanel.tsx +217 -0
- package/src/renderer/components/Skeleton.tsx +347 -0
- package/src/renderer/components/StatusIndicator.tsx +86 -0
- package/src/renderer/components/ThemeProvider.tsx +429 -0
- package/src/renderer/components/Tooltip.tsx +370 -0
- package/src/renderer/components/TranscriptionPreview.tsx +183 -0
- package/src/renderer/components/TranscriptionTierSelector.tsx +640 -0
- package/src/renderer/components/UpdateNotification.tsx +377 -0
- package/src/renderer/components/WindowSelector.tsx +947 -0
- package/src/renderer/components/index.ts +99 -0
- package/src/renderer/components/primitives/ApiKeyInput.tsx +98 -0
- package/src/renderer/components/primitives/ColorPicker.tsx +65 -0
- package/src/renderer/components/primitives/DangerButton.tsx +45 -0
- package/src/renderer/components/primitives/DirectoryPicker.tsx +41 -0
- package/src/renderer/components/primitives/Dropdown.tsx +34 -0
- package/src/renderer/components/primitives/KeyRecorder.tsx +117 -0
- package/src/renderer/components/primitives/SettingsSection.tsx +32 -0
- package/src/renderer/components/primitives/Slider.tsx +43 -0
- package/src/renderer/components/primitives/Toggle.tsx +36 -0
- package/src/renderer/components/primitives/index.ts +10 -0
- package/src/renderer/components/settings/AdvancedTab.tsx +174 -0
- package/src/renderer/components/settings/AppearanceTab.tsx +77 -0
- package/src/renderer/components/settings/GeneralTab.tsx +40 -0
- package/src/renderer/components/settings/HotkeysTab.tsx +79 -0
- package/src/renderer/components/settings/RecordingTab.tsx +84 -0
- package/src/renderer/components/settings/index.ts +9 -0
- package/src/renderer/components/settings/settingsStyles.ts +673 -0
- package/src/renderer/components/settings/tabConfig.tsx +85 -0
- package/src/renderer/components/settings/useSettingsPanel.ts +447 -0
- package/src/renderer/contexts/ProcessingContext.tsx +227 -0
- package/src/renderer/contexts/RecordingContext.tsx +683 -0
- package/src/renderer/contexts/UIContext.tsx +326 -0
- package/src/renderer/contexts/index.ts +24 -0
- package/src/renderer/donateMessages.ts +69 -0
- package/src/renderer/hooks/index.ts +75 -0
- package/src/renderer/hooks/useAnimation.tsx +544 -0
- package/src/renderer/hooks/useTheme.ts +313 -0
- package/src/renderer/index.html +26 -0
- package/src/renderer/main.tsx +52 -0
- package/src/renderer/styles/animations.css +1093 -0
- package/src/renderer/styles/app-shell.css +662 -0
- package/src/renderer/styles/globals.css +515 -0
- package/src/renderer/styles/theme.ts +578 -0
- package/src/renderer/types/electron.d.ts +385 -0
- package/src/shared/hotkeys.ts +283 -0
- package/src/shared/types.ts +809 -0
- package/tests/clipboard.test.ts +228 -0
- package/tests/e2e/criticalPaths.test.ts +594 -0
- package/tests/feedbackAnalyzer.test.ts +303 -0
- package/tests/integration/sessionFlow.test.ts +583 -0
- package/tests/markdownGenerator.test.ts +418 -0
- package/tests/output.test.ts +96 -0
- package/tests/setup.ts +486 -0
- package/tests/unit/appIntegration.test.ts +676 -0
- package/tests/unit/appViewState.test.ts +281 -0
- package/tests/unit/audioIpcChannels.test.ts +17 -0
- package/tests/unit/exportService.test.ts +492 -0
- package/tests/unit/hotkeys.test.ts +92 -0
- package/tests/unit/navigationPreload.test.ts +94 -0
- package/tests/unit/onboardingFlow.test.ts +345 -0
- package/tests/unit/permissionManager.test.ts +175 -0
- package/tests/unit/permissionManagerExpanded.test.ts +296 -0
- package/tests/unit/screenRecordingRenderer.test.ts +368 -0
- package/tests/unit/sessionController.test.ts +515 -0
- package/tests/unit/tierManager.test.ts +61 -0
- package/tests/unit/tierManagerExpanded.test.ts +142 -0
- package/tests/unit/transcriptAnalyzer.test.ts +64 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +46 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* markupr - Animation Hooks
|
|
3
|
+
*
|
|
4
|
+
* Programmatic animation utilities for React components.
|
|
5
|
+
* Provides hooks for staggered animations, spring physics,
|
|
6
|
+
* and animation lifecycle management.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
|
10
|
+
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Types
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
export interface AnimationConfig {
|
|
16
|
+
duration?: number;
|
|
17
|
+
delay?: number;
|
|
18
|
+
easing?: string;
|
|
19
|
+
fill?: 'none' | 'forwards' | 'backwards' | 'both';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface StaggerConfig extends AnimationConfig {
|
|
23
|
+
baseDelay?: number;
|
|
24
|
+
staggerDelay?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SpringConfig {
|
|
28
|
+
stiffness?: number;
|
|
29
|
+
damping?: number;
|
|
30
|
+
mass?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AnimatedItem<T> {
|
|
34
|
+
item: T;
|
|
35
|
+
style: React.CSSProperties;
|
|
36
|
+
className?: string;
|
|
37
|
+
index: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type AnimationState = 'idle' | 'entering' | 'entered' | 'exiting' | 'exited';
|
|
41
|
+
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// CSS Variables for Spring Physics
|
|
44
|
+
// ============================================================================
|
|
45
|
+
|
|
46
|
+
// Pre-computed spring curves for common presets
|
|
47
|
+
export const SPRING_PRESETS = {
|
|
48
|
+
// Bouncy, playful feel
|
|
49
|
+
bounce: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
|
|
50
|
+
// Smooth, professional feel
|
|
51
|
+
smooth: 'cubic-bezier(0.16, 1, 0.3, 1)',
|
|
52
|
+
// Quick snap
|
|
53
|
+
snap: 'cubic-bezier(0.68, -0.55, 0.265, 1.55)',
|
|
54
|
+
// Gentle ease
|
|
55
|
+
gentle: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
|
|
56
|
+
// Standard ease out
|
|
57
|
+
easeOut: 'cubic-bezier(0.0, 0, 0.2, 1)',
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
// ============================================================================
|
|
61
|
+
// useStaggeredAnimation Hook
|
|
62
|
+
// ============================================================================
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates staggered animation styles for a list of items.
|
|
66
|
+
* Each item receives a progressively delayed animation.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const animatedItems = useStaggeredAnimation(items, {
|
|
70
|
+
* baseDelay: 100,
|
|
71
|
+
* staggerDelay: 50,
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* return animatedItems.map(({ item, style, index }) => (
|
|
75
|
+
* <div key={index} style={style} className="ff-list-item-enter">
|
|
76
|
+
* {item.name}
|
|
77
|
+
* </div>
|
|
78
|
+
* ));
|
|
79
|
+
*/
|
|
80
|
+
export function useStaggeredAnimation<T>(
|
|
81
|
+
items: T[],
|
|
82
|
+
config: StaggerConfig = {}
|
|
83
|
+
): AnimatedItem<T>[] {
|
|
84
|
+
const {
|
|
85
|
+
baseDelay = 0,
|
|
86
|
+
staggerDelay = 50,
|
|
87
|
+
duration = 250,
|
|
88
|
+
easing = SPRING_PRESETS.smooth,
|
|
89
|
+
fill = 'both',
|
|
90
|
+
} = config;
|
|
91
|
+
|
|
92
|
+
return useMemo(() => {
|
|
93
|
+
return items.map((item, index) => ({
|
|
94
|
+
item,
|
|
95
|
+
index,
|
|
96
|
+
style: {
|
|
97
|
+
animationDelay: `${baseDelay + index * staggerDelay}ms`,
|
|
98
|
+
animationDuration: `${duration}ms`,
|
|
99
|
+
animationTimingFunction: easing,
|
|
100
|
+
animationFillMode: fill,
|
|
101
|
+
},
|
|
102
|
+
className: 'ff-list-item-enter',
|
|
103
|
+
}));
|
|
104
|
+
}, [items, baseDelay, staggerDelay, duration, easing, fill]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// useAnimationState Hook
|
|
109
|
+
// ============================================================================
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Manages enter/exit animation lifecycle.
|
|
113
|
+
* Useful for components that need to animate out before unmounting.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const { state, triggerEnter, triggerExit, shouldRender } = useAnimationState({
|
|
117
|
+
* isVisible: props.open,
|
|
118
|
+
* enterDuration: 250,
|
|
119
|
+
* exitDuration: 150,
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* if (!shouldRender) return null;
|
|
123
|
+
*
|
|
124
|
+
* return (
|
|
125
|
+
* <div className={state === 'entering' ? 'ff-dialog-enter' : 'ff-dialog-exit'}>
|
|
126
|
+
* ...
|
|
127
|
+
* </div>
|
|
128
|
+
* );
|
|
129
|
+
*/
|
|
130
|
+
export function useAnimationState(config: {
|
|
131
|
+
isVisible: boolean;
|
|
132
|
+
enterDuration?: number;
|
|
133
|
+
exitDuration?: number;
|
|
134
|
+
onEntered?: () => void;
|
|
135
|
+
onExited?: () => void;
|
|
136
|
+
}) {
|
|
137
|
+
const {
|
|
138
|
+
isVisible,
|
|
139
|
+
enterDuration = 250,
|
|
140
|
+
exitDuration = 150,
|
|
141
|
+
onEntered,
|
|
142
|
+
onExited,
|
|
143
|
+
} = config;
|
|
144
|
+
|
|
145
|
+
const [state, setState] = useState<AnimationState>(isVisible ? 'entered' : 'exited');
|
|
146
|
+
const timeoutRef = useRef<NodeJS.Timeout>();
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (timeoutRef.current) {
|
|
150
|
+
clearTimeout(timeoutRef.current);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (isVisible) {
|
|
154
|
+
setState('entering');
|
|
155
|
+
timeoutRef.current = setTimeout(() => {
|
|
156
|
+
setState('entered');
|
|
157
|
+
onEntered?.();
|
|
158
|
+
}, enterDuration);
|
|
159
|
+
} else if (state !== 'exited') {
|
|
160
|
+
setState('exiting');
|
|
161
|
+
timeoutRef.current = setTimeout(() => {
|
|
162
|
+
setState('exited');
|
|
163
|
+
onExited?.();
|
|
164
|
+
}, exitDuration);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return () => {
|
|
168
|
+
if (timeoutRef.current) {
|
|
169
|
+
clearTimeout(timeoutRef.current);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}, [isVisible, enterDuration, exitDuration, onEntered, onExited, state]);
|
|
173
|
+
|
|
174
|
+
const triggerEnter = useCallback(() => {
|
|
175
|
+
setState('entering');
|
|
176
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
177
|
+
timeoutRef.current = setTimeout(() => {
|
|
178
|
+
setState('entered');
|
|
179
|
+
onEntered?.();
|
|
180
|
+
}, enterDuration);
|
|
181
|
+
}, [enterDuration, onEntered]);
|
|
182
|
+
|
|
183
|
+
const triggerExit = useCallback(() => {
|
|
184
|
+
setState('exiting');
|
|
185
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
186
|
+
timeoutRef.current = setTimeout(() => {
|
|
187
|
+
setState('exited');
|
|
188
|
+
onExited?.();
|
|
189
|
+
}, exitDuration);
|
|
190
|
+
}, [exitDuration, onExited]);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
state,
|
|
194
|
+
isEntering: state === 'entering',
|
|
195
|
+
isEntered: state === 'entered',
|
|
196
|
+
isExiting: state === 'exiting',
|
|
197
|
+
isExited: state === 'exited',
|
|
198
|
+
shouldRender: state !== 'exited',
|
|
199
|
+
triggerEnter,
|
|
200
|
+
triggerExit,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// useCountAnimation Hook
|
|
206
|
+
// ============================================================================
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Animates a number counting up or down.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* const { displayValue, isAnimating } = useCountAnimation(totalItems, {
|
|
213
|
+
* duration: 500,
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* return <span className={isAnimating ? 'ff-counter-increment' : ''}>{displayValue}</span>;
|
|
217
|
+
*/
|
|
218
|
+
export function useCountAnimation(
|
|
219
|
+
targetValue: number,
|
|
220
|
+
config: { duration?: number; startValue?: number } = {}
|
|
221
|
+
) {
|
|
222
|
+
const { duration = 300, startValue } = config;
|
|
223
|
+
const [displayValue, setDisplayValue] = useState(startValue ?? targetValue);
|
|
224
|
+
const [isAnimating, setIsAnimating] = useState(false);
|
|
225
|
+
const previousValueRef = useRef(targetValue);
|
|
226
|
+
const animationRef = useRef<number>();
|
|
227
|
+
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (targetValue === previousValueRef.current) return;
|
|
230
|
+
|
|
231
|
+
const startVal = previousValueRef.current;
|
|
232
|
+
const diff = targetValue - startVal;
|
|
233
|
+
const startTime = performance.now();
|
|
234
|
+
|
|
235
|
+
setIsAnimating(true);
|
|
236
|
+
|
|
237
|
+
const animate = (currentTime: number) => {
|
|
238
|
+
const elapsed = currentTime - startTime;
|
|
239
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
240
|
+
|
|
241
|
+
// Ease out cubic
|
|
242
|
+
const eased = 1 - Math.pow(1 - progress, 3);
|
|
243
|
+
const currentValue = Math.round(startVal + diff * eased);
|
|
244
|
+
|
|
245
|
+
setDisplayValue(currentValue);
|
|
246
|
+
|
|
247
|
+
if (progress < 1) {
|
|
248
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
249
|
+
} else {
|
|
250
|
+
setIsAnimating(false);
|
|
251
|
+
previousValueRef.current = targetValue;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
256
|
+
|
|
257
|
+
return () => {
|
|
258
|
+
if (animationRef.current) {
|
|
259
|
+
cancelAnimationFrame(animationRef.current);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}, [targetValue, duration]);
|
|
263
|
+
|
|
264
|
+
return { displayValue, isAnimating };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ============================================================================
|
|
268
|
+
// usePulse Hook
|
|
269
|
+
// ============================================================================
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Triggers a one-shot pulse animation.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const { isPulsing, triggerPulse, pulseClassName } = usePulse();
|
|
276
|
+
*
|
|
277
|
+
* <button onClick={() => { save(); triggerPulse(); }} className={pulseClassName}>
|
|
278
|
+
* Save
|
|
279
|
+
* </button>
|
|
280
|
+
*/
|
|
281
|
+
export function usePulse(duration = 300) {
|
|
282
|
+
const [isPulsing, setIsPulsing] = useState(false);
|
|
283
|
+
const timeoutRef = useRef<NodeJS.Timeout>();
|
|
284
|
+
|
|
285
|
+
const triggerPulse = useCallback(() => {
|
|
286
|
+
if (timeoutRef.current) {
|
|
287
|
+
clearTimeout(timeoutRef.current);
|
|
288
|
+
}
|
|
289
|
+
setIsPulsing(true);
|
|
290
|
+
timeoutRef.current = setTimeout(() => {
|
|
291
|
+
setIsPulsing(false);
|
|
292
|
+
}, duration);
|
|
293
|
+
}, [duration]);
|
|
294
|
+
|
|
295
|
+
useEffect(() => {
|
|
296
|
+
return () => {
|
|
297
|
+
if (timeoutRef.current) {
|
|
298
|
+
clearTimeout(timeoutRef.current);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}, []);
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
isPulsing,
|
|
305
|
+
triggerPulse,
|
|
306
|
+
pulseClassName: isPulsing ? 'ff-success-pulse' : '',
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ============================================================================
|
|
311
|
+
// useShake Hook
|
|
312
|
+
// ============================================================================
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Triggers a shake animation for error feedback.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* const { isShaking, triggerShake, shakeClassName } = useShake();
|
|
319
|
+
*
|
|
320
|
+
* if (hasError) {
|
|
321
|
+
* triggerShake();
|
|
322
|
+
* }
|
|
323
|
+
*
|
|
324
|
+
* return <div className={shakeClassName}>...</div>;
|
|
325
|
+
*/
|
|
326
|
+
export function useShake(duration = 500) {
|
|
327
|
+
const [isShaking, setIsShaking] = useState(false);
|
|
328
|
+
const timeoutRef = useRef<NodeJS.Timeout>();
|
|
329
|
+
|
|
330
|
+
const triggerShake = useCallback(() => {
|
|
331
|
+
if (timeoutRef.current) {
|
|
332
|
+
clearTimeout(timeoutRef.current);
|
|
333
|
+
}
|
|
334
|
+
setIsShaking(true);
|
|
335
|
+
timeoutRef.current = setTimeout(() => {
|
|
336
|
+
setIsShaking(false);
|
|
337
|
+
}, duration);
|
|
338
|
+
}, [duration]);
|
|
339
|
+
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
return () => {
|
|
342
|
+
if (timeoutRef.current) {
|
|
343
|
+
clearTimeout(timeoutRef.current);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}, []);
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
isShaking,
|
|
350
|
+
triggerShake,
|
|
351
|
+
shakeClassName: isShaking ? 'ff-error-shake' : '',
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ============================================================================
|
|
356
|
+
// useRipple Hook
|
|
357
|
+
// ============================================================================
|
|
358
|
+
|
|
359
|
+
interface Ripple {
|
|
360
|
+
id: number;
|
|
361
|
+
x: number;
|
|
362
|
+
y: number;
|
|
363
|
+
size: number;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Creates material-design style ripple effects on click.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* const { ripples, createRipple, RippleContainer } = useRipple();
|
|
371
|
+
*
|
|
372
|
+
* return (
|
|
373
|
+
* <button onClick={createRipple} style={{ position: 'relative', overflow: 'hidden' }}>
|
|
374
|
+
* Click me
|
|
375
|
+
* <RippleContainer />
|
|
376
|
+
* </button>
|
|
377
|
+
* );
|
|
378
|
+
*/
|
|
379
|
+
export function useRipple(duration = 600) {
|
|
380
|
+
const [ripples, setRipples] = useState<Ripple[]>([]);
|
|
381
|
+
const nextIdRef = useRef(0);
|
|
382
|
+
|
|
383
|
+
const createRipple = useCallback(
|
|
384
|
+
(event: React.MouseEvent<HTMLElement>) => {
|
|
385
|
+
const element = event.currentTarget;
|
|
386
|
+
const rect = element.getBoundingClientRect();
|
|
387
|
+
|
|
388
|
+
const size = Math.max(rect.width, rect.height) * 2;
|
|
389
|
+
const x = event.clientX - rect.left - size / 2;
|
|
390
|
+
const y = event.clientY - rect.top - size / 2;
|
|
391
|
+
|
|
392
|
+
const newRipple: Ripple = {
|
|
393
|
+
id: nextIdRef.current++,
|
|
394
|
+
x,
|
|
395
|
+
y,
|
|
396
|
+
size,
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
setRipples((prev) => [...prev, newRipple]);
|
|
400
|
+
|
|
401
|
+
setTimeout(() => {
|
|
402
|
+
setRipples((prev) => prev.filter((r) => r.id !== newRipple.id));
|
|
403
|
+
}, duration);
|
|
404
|
+
},
|
|
405
|
+
[duration]
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
const RippleContainer: React.FC = () => (
|
|
409
|
+
<>
|
|
410
|
+
{ripples.map((ripple) => (
|
|
411
|
+
<span
|
|
412
|
+
key={ripple.id}
|
|
413
|
+
className="ff-ripple"
|
|
414
|
+
style={{
|
|
415
|
+
left: ripple.x,
|
|
416
|
+
top: ripple.y,
|
|
417
|
+
width: ripple.size,
|
|
418
|
+
height: ripple.size,
|
|
419
|
+
}}
|
|
420
|
+
/>
|
|
421
|
+
))}
|
|
422
|
+
</>
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
return { ripples, createRipple, RippleContainer };
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// ============================================================================
|
|
429
|
+
// useDelayedRender Hook
|
|
430
|
+
// ============================================================================
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Delays rendering of children to create staggered mount effects.
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* const shouldRender = useDelayedRender(300);
|
|
437
|
+
*
|
|
438
|
+
* return shouldRender ? <HeavyComponent /> : <Skeleton />;
|
|
439
|
+
*/
|
|
440
|
+
export function useDelayedRender(delay: number, initialValue = false): boolean {
|
|
441
|
+
const [shouldRender, setShouldRender] = useState(initialValue);
|
|
442
|
+
|
|
443
|
+
useEffect(() => {
|
|
444
|
+
const timeout = setTimeout(() => {
|
|
445
|
+
setShouldRender(true);
|
|
446
|
+
}, delay);
|
|
447
|
+
|
|
448
|
+
return () => clearTimeout(timeout);
|
|
449
|
+
}, [delay]);
|
|
450
|
+
|
|
451
|
+
return shouldRender;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ============================================================================
|
|
455
|
+
// useAnimatedValue Hook
|
|
456
|
+
// ============================================================================
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Animates a value from one number to another using requestAnimationFrame.
|
|
460
|
+
* Returns current interpolated value.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* const animatedHeight = useAnimatedValue(isExpanded ? 300 : 0, { duration: 300 });
|
|
464
|
+
*
|
|
465
|
+
* return <div style={{ height: animatedHeight }}>...</div>;
|
|
466
|
+
*/
|
|
467
|
+
export function useAnimatedValue(
|
|
468
|
+
targetValue: number,
|
|
469
|
+
config: { duration?: number; easing?: (t: number) => number } = {}
|
|
470
|
+
): number {
|
|
471
|
+
const { duration = 300, easing = (t) => 1 - Math.pow(1 - t, 3) } = config;
|
|
472
|
+
|
|
473
|
+
const [currentValue, setCurrentValue] = useState(targetValue);
|
|
474
|
+
const startValueRef = useRef(targetValue);
|
|
475
|
+
const startTimeRef = useRef<number | null>(null);
|
|
476
|
+
const animationRef = useRef<number>();
|
|
477
|
+
|
|
478
|
+
useEffect(() => {
|
|
479
|
+
if (currentValue === targetValue) return;
|
|
480
|
+
|
|
481
|
+
startValueRef.current = currentValue;
|
|
482
|
+
startTimeRef.current = null;
|
|
483
|
+
|
|
484
|
+
const animate = (time: number) => {
|
|
485
|
+
if (startTimeRef.current === null) {
|
|
486
|
+
startTimeRef.current = time;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const elapsed = time - startTimeRef.current;
|
|
490
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
491
|
+
const easedProgress = easing(progress);
|
|
492
|
+
|
|
493
|
+
const newValue =
|
|
494
|
+
startValueRef.current + (targetValue - startValueRef.current) * easedProgress;
|
|
495
|
+
|
|
496
|
+
setCurrentValue(newValue);
|
|
497
|
+
|
|
498
|
+
if (progress < 1) {
|
|
499
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
504
|
+
|
|
505
|
+
return () => {
|
|
506
|
+
if (animationRef.current) {
|
|
507
|
+
cancelAnimationFrame(animationRef.current);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}, [targetValue, duration, easing, currentValue]);
|
|
511
|
+
|
|
512
|
+
return currentValue;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// ============================================================================
|
|
516
|
+
// useReducedMotion Hook
|
|
517
|
+
// ============================================================================
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Detects user's reduced motion preference.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
524
|
+
*
|
|
525
|
+
* const animationDuration = prefersReducedMotion ? 0 : 300;
|
|
526
|
+
*/
|
|
527
|
+
export function useReducedMotion(): boolean {
|
|
528
|
+
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
|
|
529
|
+
|
|
530
|
+
useEffect(() => {
|
|
531
|
+
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
532
|
+
setPrefersReducedMotion(mediaQuery.matches);
|
|
533
|
+
|
|
534
|
+
const handler = (event: MediaQueryListEvent) => {
|
|
535
|
+
setPrefersReducedMotion(event.matches);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
mediaQuery.addEventListener('change', handler);
|
|
539
|
+
return () => mediaQuery.removeEventListener('change', handler);
|
|
540
|
+
}, []);
|
|
541
|
+
|
|
542
|
+
return prefersReducedMotion;
|
|
543
|
+
}
|
|
544
|
+
|