@umituz/react-native-ai-generation-content 1.90.2 → 1.90.3
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/package.json +1 -1
- package/src/domain/interfaces/app-services-auth.interface.ts +27 -0
- package/src/domain/interfaces/app-services-composite.interface.ts +29 -0
- package/src/domain/interfaces/app-services-optional.interface.ts +42 -0
- package/src/domain/interfaces/app-services.interface.ts +0 -79
- package/src/domains/background/infrastructure/services/job-poller-index.ts +7 -0
- package/src/domains/background/infrastructure/services/job-poller-utils.ts +130 -0
- package/src/domains/background/infrastructure/utils/polling-interval.util.ts +1 -1
- package/src/domains/background/presentation/hooks/use-background-generation.ts +1 -1
- package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +1 -1
- package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +34 -8
- package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +15 -4
- package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +34 -8
- package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +19 -8
- package/src/domains/creations/domain/types/creation-categories.constants.ts +57 -0
- package/src/domains/creations/domain/types/creation-categories.helpers.ts +67 -0
- package/src/domains/creations/domain/types/creation-categories.ts +5 -111
- package/src/domains/creations/presentation/hooks/creation-validators.ts +31 -29
- package/src/domains/creations/presentation/hooks/job-poller-index.ts +10 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.filters.ts +34 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.logger.ts +76 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.stale-handlers.ts +52 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.ts +8 -0
- package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +1 -1
- package/src/domains/creations/presentation-exports.ts +2 -2
- package/src/domains/face-detection/domain/entities/FaceDetection.ts +4 -3
- package/src/domains/face-detection/presentation/hooks/useFaceDetection.ts +24 -21
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-preparation.ts +58 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-prompt.ts +69 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-resolution.ts +77 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple.ts +54 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-index.ts +8 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-scenario.ts +113 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder.ts +7 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/index.ts +20 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/types.ts +44 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-end-logger.ts +18 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-start-logger.ts +57 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-step-logger.ts +106 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/index.ts +8 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/types.ts +49 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils.ts +8 -0
- package/src/domains/generation/infrastructure/flow/flow-store-actions.ts +105 -0
- package/src/domains/generation/infrastructure/flow/flow-store-initial-state.ts +26 -0
- package/src/domains/generation/infrastructure/flow/useFlowStore.ts +4 -116
- package/src/domains/generation/presentation/useAIGeneration.hook.ts +1 -1
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation-strategy-index.ts +7 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.ts +2 -12
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.types.ts +11 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.utils.ts +12 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.strategy.ts +1 -220
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-builder.ts +66 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-extraction.ts +88 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-prompt-builder.ts +75 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-style-enhancements.ts +35 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-strategy-factory.ts +42 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor-index.ts +11 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor.ts +76 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-input-builder.ts +46 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-result-types.ts +17 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-submission.ts +62 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.audio-extractor.ts +27 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.executor.ts +2 -175
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.input-builder.ts +90 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +3 -108
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.types.ts +0 -129
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.validation.ts +136 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/index.ts +39 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/types.ts +37 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/usePhotoUploadStateLogic.ts +142 -0
- package/src/domains/generation/wizard/presentation/hooks/use-video-queue-utils.ts +103 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.handlers.ts +97 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.saver.ts +54 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.ts +22 -87
- package/src/domains/generation/wizard/presentation/hooks/usePhotoUploadState.ts +8 -177
- package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +1 -295
- package/src/domains/generation/wizard/presentation/hooks/useWizardGeneration.ts +1 -1
- package/src/domains/generation/wizard/presentation/hooks/video-queue/index.ts +82 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationCallbacks.ts +120 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationPolling.ts +76 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationRefs.ts +65 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationStart.ts +123 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue-index.ts +9 -0
- package/src/domains/image-to-video/domain/types/image-to-video-state.types.ts +11 -4
- package/src/domains/text-to-image/domain/types/text-to-image.types.ts +44 -22
- package/src/domains/text-to-video/domain/types/request.types.ts +33 -9
- package/src/domains/text-to-video/domain/types/state.types.ts +29 -9
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.handlers.ts +44 -0
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.ts +5 -51
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.types.ts +33 -0
- package/src/infrastructure/services/generation-orchestrator.service.ts +2 -2
- package/src/infrastructure/utils/couple-input-context.ts +13 -0
- package/src/infrastructure/utils/couple-input-index.ts +8 -0
- package/src/infrastructure/utils/couple-input-refiner.ts +101 -0
- package/src/infrastructure/utils/couple-input-resolver.ts +71 -0
- package/src/infrastructure/utils/couple-input-types.ts +14 -0
- package/src/infrastructure/utils/couple-input.util.ts +3 -176
- package/src/infrastructure/utils/photo-generation/photo-preparation.util.ts +1 -1
- package/src/infrastructure/validation/base-validator.ts +1 -27
- package/src/infrastructure/validation/base-validator.types.ts +32 -0
- package/src/presentation/hooks/generation/index.ts +1 -1
- package/src/presentation/hooks/generation/orchestrator-abort-logs.ts +48 -0
- package/src/presentation/hooks/generation/orchestrator-execution-logs.ts +67 -0
- package/src/presentation/hooks/generation/orchestrator-index.ts +14 -0
- package/src/presentation/hooks/generation/orchestrator-start-logs.ts +65 -0
- package/src/presentation/hooks/generation/orchestrator-state-utils.ts +17 -0
- package/src/presentation/hooks/generation/orchestrator-types.ts +55 -0
- package/src/presentation/hooks/generation/orchestrator-utils-index.ts +29 -0
- package/src/presentation/hooks/generation/orchestrator-utils.ts +25 -0
- package/src/presentation/hooks/generation/useDualImageGeneration.ts +1 -1
- package/src/presentation/hooks/generation/useImageGeneration.ts +1 -1
- package/src/presentation/hooks/generation/useVideoGeneration.ts +1 -1
- package/src/shared/hooks/factories/generation-hook-index.ts +12 -0
- package/src/shared/hooks/factories/generation-hook-types.ts +47 -0
- package/src/shared/hooks/factories/generation-hook-utils.ts +94 -0
- package/src/shared/hooks/factories/index.ts +1 -1
- package/src/shared/index.ts +1 -1
- package/src/shared/utils/calculations/aspect-ratio-calculations.ts +30 -0
- package/src/shared/utils/calculations/base64-calculations.ts +26 -0
- package/src/shared/utils/calculations/confidence-calculations.ts +21 -0
- package/src/shared/utils/calculations/cost-calculations-index.ts +43 -0
- package/src/shared/utils/calculations/cost-calculations.ts +25 -0
- package/src/shared/utils/calculations/credit-calculations.ts +37 -0
- package/src/shared/utils/calculations/index.ts +46 -0
- package/src/shared/utils/calculations/math-utilities.ts +32 -0
- package/src/shared/utils/calculations/memory-calculations.ts +33 -0
- package/src/shared/utils/calculations/pagination-calculations.ts +38 -0
- package/src/shared/utils/calculations/percentage-calculations.ts +33 -0
- package/src/shared/utils/calculations/time-calculations.ts +99 -0
- package/src/shared/utils/credit.ts +1 -1
- package/src/shared-kernel/application/hooks/index.ts +8 -0
- package/src/shared-kernel/application/hooks/use-feature-state.ts +107 -0
- package/src/shared-kernel/application/hooks/use-generation-handler.ts +110 -0
- package/src/shared-kernel/base-types/base-callbacks.types.ts +73 -0
- package/src/shared-kernel/base-types/base-feature-state.types.ts +77 -0
- package/src/shared-kernel/base-types/base-generation.types.ts +69 -0
- package/src/shared-kernel/base-types/index.ts +30 -0
- package/src/shared-kernel/domain/base-generation-strategy.ts +146 -0
- package/src/shared-kernel/domain/index.ts +7 -0
- package/src/shared-kernel/index.ts +17 -0
- package/src/shared-kernel/infrastructure/validation/common-validators.ts +126 -0
- package/src/shared-kernel/infrastructure/validation/common-validators.types.ts +33 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.ts +52 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.types.ts +38 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.utils.ts +79 -0
- package/src/shared-kernel/infrastructure/validation/index.ts +28 -0
- package/src/domains/background/infrastructure/services/job-poller.service.ts +0 -234
- package/src/domains/creations/presentation/hooks/useProcessingJobsPoller.ts +0 -256
- package/src/domains/generation/infrastructure/couple-generation-builder.ts +0 -374
- package/src/presentation/hooks/generation/orchestrator.ts +0 -276
- package/src/shared/hooks/factories/createGenerationHook.ts +0 -253
- package/src/shared/utils/calculations.util.ts +0 -366
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type GenerationStatus = "idle" | "checking" | "generating" | "saving" | "success" | "error";
|
|
6
|
+
|
|
7
|
+
export interface GenerationState<T> {
|
|
8
|
+
readonly status: GenerationStatus;
|
|
9
|
+
readonly isGenerating: boolean;
|
|
10
|
+
readonly result: T | null;
|
|
11
|
+
readonly error: GenerationError | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface GenerationError {
|
|
15
|
+
readonly type: "network" | "moderation" | "credits" | "generation" | "save" | "unknown";
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly originalError?: Error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GenerationStrategy<TInput, TResult> {
|
|
21
|
+
readonly execute: (input: TInput, signal?: AbortSignal) => Promise<TResult>;
|
|
22
|
+
readonly save?: (result: TResult, userId: string) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface GenerationConfig {
|
|
26
|
+
readonly userId: string | null;
|
|
27
|
+
readonly alertMessages: {
|
|
28
|
+
readonly networkError?: string;
|
|
29
|
+
readonly moderationError?: string;
|
|
30
|
+
readonly insufficientCredits?: string;
|
|
31
|
+
readonly generationError?: string;
|
|
32
|
+
readonly saveFailed?: string;
|
|
33
|
+
readonly success?: string;
|
|
34
|
+
};
|
|
35
|
+
readonly onSuccess?: (result: unknown) => Promise<void>;
|
|
36
|
+
readonly onError?: (error: GenerationError) => Promise<void>;
|
|
37
|
+
readonly moderation?: {
|
|
38
|
+
readonly enabled?: boolean;
|
|
39
|
+
readonly onWarning?: (warning: string, onProceed: () => void, onCancel: () => void) => void;
|
|
40
|
+
};
|
|
41
|
+
readonly lifecycle?: {
|
|
42
|
+
readonly onStart?: () => void;
|
|
43
|
+
readonly onComplete?: (status: "success" | "error", result?: unknown, error?: GenerationError) => void;
|
|
44
|
+
readonly completeDelay?: number;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface UseGenerationOrchestratorReturn<TInput, TResult> {
|
|
49
|
+
readonly generate: (input: TInput) => Promise<TResult | void>;
|
|
50
|
+
readonly reset: () => void;
|
|
51
|
+
readonly status: GenerationStatus;
|
|
52
|
+
readonly isGenerating: boolean;
|
|
53
|
+
readonly result: TResult | null;
|
|
54
|
+
readonly error: GenerationError | null;
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { getInitialState } from "./orchestrator-state-utils";
|
|
6
|
+
export {
|
|
7
|
+
logGenerationStart,
|
|
8
|
+
logAlreadyGenerating,
|
|
9
|
+
logStateChange,
|
|
10
|
+
logOnlineCheck,
|
|
11
|
+
logModerationStart,
|
|
12
|
+
logExecutionStart,
|
|
13
|
+
} from "./orchestrator-start-logs";
|
|
14
|
+
export {
|
|
15
|
+
logAbortBeforeStart,
|
|
16
|
+
logAbortAfterCompletion,
|
|
17
|
+
logAbortBeforeSave,
|
|
18
|
+
logAbortBeforeSuccess,
|
|
19
|
+
logAborted,
|
|
20
|
+
} from "./orchestrator-abort-logs";
|
|
21
|
+
export {
|
|
22
|
+
logStateGenerating,
|
|
23
|
+
logExecuteCompleted,
|
|
24
|
+
logStateSaving,
|
|
25
|
+
logSaveSuccess,
|
|
26
|
+
logSaveFailed,
|
|
27
|
+
logGenerationSuccess,
|
|
28
|
+
logError,
|
|
29
|
+
} from "./orchestrator-execution-logs";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation Orchestrator - Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
getInitialState,
|
|
7
|
+
logGenerationStart,
|
|
8
|
+
logAlreadyGenerating,
|
|
9
|
+
logStateChange,
|
|
10
|
+
logOnlineCheck,
|
|
11
|
+
logModerationStart,
|
|
12
|
+
logExecutionStart,
|
|
13
|
+
logAbortBeforeStart,
|
|
14
|
+
logStateGenerating,
|
|
15
|
+
logAbortAfterCompletion,
|
|
16
|
+
logExecuteCompleted,
|
|
17
|
+
logAbortBeforeSave,
|
|
18
|
+
logStateSaving,
|
|
19
|
+
logSaveSuccess,
|
|
20
|
+
logSaveFailed,
|
|
21
|
+
logAbortBeforeSuccess,
|
|
22
|
+
logGenerationSuccess,
|
|
23
|
+
logError,
|
|
24
|
+
logAborted,
|
|
25
|
+
} from "./orchestrator-utils-index";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { useState, useCallback, useMemo } from "react";
|
|
7
7
|
import { saveImageToGallery } from "@umituz/react-native-design-system/media";
|
|
8
8
|
import { useAlert } from "@umituz/react-native-design-system/molecules";
|
|
9
|
-
import { useGenerationOrchestrator } from "./orchestrator";
|
|
9
|
+
import { useGenerationOrchestrator } from "./orchestrator-index";
|
|
10
10
|
import { useImagePicker } from "./useImagePicker";
|
|
11
11
|
import { executeMultiImageGeneration } from "../../../infrastructure/services/multi-image-generation.executor";
|
|
12
12
|
import type { GenerationStrategy } from "./types";
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useMemo, useCallback, useRef } from "react";
|
|
7
|
-
import { useGenerationOrchestrator } from "./orchestrator";
|
|
7
|
+
import { useGenerationOrchestrator } from "./orchestrator-index";
|
|
8
8
|
import type { GenerationStrategy } from "./types";
|
|
9
9
|
import { executeImageFeature } from "../../../infrastructure/services";
|
|
10
10
|
import { createCreationsRepository } from "../../../domains/creations/infrastructure/adapters";
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { useMemo, useCallback, useRef } from "react";
|
|
8
|
-
import { useGenerationOrchestrator } from "./orchestrator";
|
|
8
|
+
import { useGenerationOrchestrator } from "./orchestrator-index";
|
|
9
9
|
import type { GenerationStrategy, AlertMessages } from "./types";
|
|
10
10
|
import { executeVideoFeature } from "../../../infrastructure/services";
|
|
11
11
|
import type { VideoFeatureType } from "../../../domain/interfaces";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Generation Hook Factory
|
|
3
|
+
* Creates type-safe generation hooks with error handling, progress tracking, and abort support
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { createGenerationHook, createGenerationHookWithProgress } from "./createGenerationHook";
|
|
7
|
+
export type {
|
|
8
|
+
GenerationState,
|
|
9
|
+
GenerationCallbacks,
|
|
10
|
+
GenerationHookConfig,
|
|
11
|
+
GenerationHookReturn,
|
|
12
|
+
} from "./generation-hook-types";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Generation Hook Factory - Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generation state
|
|
7
|
+
*/
|
|
8
|
+
export interface GenerationState {
|
|
9
|
+
isGenerating: boolean;
|
|
10
|
+
progress: number;
|
|
11
|
+
error: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generation callbacks
|
|
16
|
+
*/
|
|
17
|
+
export interface GenerationCallbacks<TResult> {
|
|
18
|
+
/** Called when generation succeeds */
|
|
19
|
+
onSuccess?: (result: TResult) => void;
|
|
20
|
+
/** Called when generation fails */
|
|
21
|
+
onError?: (error: string) => void;
|
|
22
|
+
/** Called on progress update */
|
|
23
|
+
onProgress?: (progress: number) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generation hook configuration
|
|
28
|
+
*/
|
|
29
|
+
export interface GenerationHookConfig<TRequest, TResult> {
|
|
30
|
+
/** Execute the generation request */
|
|
31
|
+
execute: (request: TRequest, signal?: AbortSignal) => Promise<TResult>;
|
|
32
|
+
/** Optional validation before execution */
|
|
33
|
+
validate?: (request: TRequest) => string | null;
|
|
34
|
+
/** Optional transform for errors */
|
|
35
|
+
transformError?: (error: unknown) => string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generation hook return type
|
|
40
|
+
*/
|
|
41
|
+
export interface GenerationHookReturn<TRequest, TResult> {
|
|
42
|
+
generationState: GenerationState;
|
|
43
|
+
handleGenerate: (request: TRequest) => Promise<TResult | null>;
|
|
44
|
+
setProgress: (progress: number) => void;
|
|
45
|
+
setError: (error: string | null) => void;
|
|
46
|
+
abort: () => void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Generation Hook Factory - Utility Functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { GenerationState } from "./generation-hook-types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Initial generation state
|
|
9
|
+
*/
|
|
10
|
+
export const INITIAL_STATE: GenerationState = {
|
|
11
|
+
isGenerating: false,
|
|
12
|
+
progress: 0,
|
|
13
|
+
error: null,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create abort handler
|
|
18
|
+
*/
|
|
19
|
+
export function createAbortHandler(
|
|
20
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
21
|
+
setGenerationState: React.Dispatch<React.SetStateAction<GenerationState>>
|
|
22
|
+
): () => void {
|
|
23
|
+
return () => {
|
|
24
|
+
abortControllerRef.current?.abort();
|
|
25
|
+
setGenerationState((prev) => ({
|
|
26
|
+
...prev,
|
|
27
|
+
isGenerating: false,
|
|
28
|
+
error: "Generation aborted",
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create progress setter
|
|
35
|
+
*/
|
|
36
|
+
export function createProgressSetter(
|
|
37
|
+
onProgressRef: React.MutableRefObject<((progress: number) => void) | undefined>,
|
|
38
|
+
setGenerationState: React.Dispatch<React.SetStateAction<GenerationState>>,
|
|
39
|
+
isMountedRef: React.MutableRefObject<boolean>
|
|
40
|
+
): (progress: number) => void {
|
|
41
|
+
return (progress: number) => {
|
|
42
|
+
if (!isMountedRef.current) return;
|
|
43
|
+
setGenerationState((prev) => ({ ...prev, progress }));
|
|
44
|
+
onProgressRef.current?.(progress);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create error setter
|
|
50
|
+
*/
|
|
51
|
+
export function createErrorSetter(
|
|
52
|
+
onErrorRef: React.MutableRefObject<((error: string) => void) | undefined>,
|
|
53
|
+
setGenerationState: React.Dispatch<React.SetStateAction<GenerationState>>,
|
|
54
|
+
isMountedRef: React.MutableRefObject<boolean>
|
|
55
|
+
): (error: string | null) => void {
|
|
56
|
+
return (error: string | null) => {
|
|
57
|
+
if (!isMountedRef.current) return;
|
|
58
|
+
setGenerationState((prev) => ({ ...prev, error, isGenerating: false }));
|
|
59
|
+
if (error) {
|
|
60
|
+
onErrorRef.current?.(error);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create cleanup effect
|
|
67
|
+
*/
|
|
68
|
+
export function createCleanupEffect(
|
|
69
|
+
isMountedRef: React.MutableRefObject<boolean>,
|
|
70
|
+
abortControllerRef: React.MutableRefObject<AbortController | null>
|
|
71
|
+
): () => void {
|
|
72
|
+
return () => {
|
|
73
|
+
isMountedRef.current = false;
|
|
74
|
+
abortControllerRef.current?.abort();
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create callback updater effect
|
|
80
|
+
*/
|
|
81
|
+
export function createCallbackUpdater<T>(
|
|
82
|
+
onSuccessRef: React.MutableRefObject<((result: T) => void) | undefined>,
|
|
83
|
+
onErrorRef: React.MutableRefObject<((error: string) => void) | undefined>,
|
|
84
|
+
onProgressRef: React.MutableRefObject<((progress: number) => void) | undefined>,
|
|
85
|
+
callbacks: {
|
|
86
|
+
onSuccess?: (result: T) => void;
|
|
87
|
+
onError?: (error: string) => void;
|
|
88
|
+
onProgress?: (progress: number) => void;
|
|
89
|
+
}
|
|
90
|
+
): void {
|
|
91
|
+
onSuccessRef.current = callbacks.onSuccess;
|
|
92
|
+
onErrorRef.current = callbacks.onError;
|
|
93
|
+
onProgressRef.current = callbacks.onProgress;
|
|
94
|
+
}
|
package/src/shared/index.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aspect Ratio & Dimension Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate aspect ratio from dimensions
|
|
7
|
+
*/
|
|
8
|
+
export function calculateAspectRatio(width: number, height: number): number {
|
|
9
|
+
return width / height;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Calculate height from width and aspect ratio
|
|
14
|
+
*/
|
|
15
|
+
export function calculateHeightFromAspectRatio(
|
|
16
|
+
width: number,
|
|
17
|
+
aspectRatio: number
|
|
18
|
+
): number {
|
|
19
|
+
return Math.round(width / aspectRatio);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Calculate width from height and aspect ratio
|
|
24
|
+
*/
|
|
25
|
+
export function calculateWidthFromAspectRatio(
|
|
26
|
+
height: number,
|
|
27
|
+
aspectRatio: number
|
|
28
|
+
): number {
|
|
29
|
+
return Math.round(height * aspectRatio);
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64 Size Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate base64 size in bytes
|
|
7
|
+
*/
|
|
8
|
+
export function calculateBase64Size(base64: string): number {
|
|
9
|
+
// Remove data URI prefix if present
|
|
10
|
+
const cleanBase64 = base64.replace(/^data:[^;]+;base64,/, "");
|
|
11
|
+
return (cleanBase64.length * 3) / 4;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Calculate base64 size in megabytes
|
|
16
|
+
*/
|
|
17
|
+
export function calculateBase64SizeMB(base64: string): number {
|
|
18
|
+
return calculateBase64Size(base64) / (1024 * 1024);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Calculate if base64 size is within limit
|
|
23
|
+
*/
|
|
24
|
+
export function isBase64SizeWithinLimit(base64: string, maxSizeMB: number): boolean {
|
|
25
|
+
return calculateBase64SizeMB(base64) <= maxSizeMB;
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence Score Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate confidence score from violations with weights
|
|
7
|
+
*/
|
|
8
|
+
export function calculateConfidenceScore(
|
|
9
|
+
violations: readonly { severity: "critical" | "high" | "medium" | "low" }[]
|
|
10
|
+
): number {
|
|
11
|
+
if (violations.length === 0) return 1.0;
|
|
12
|
+
|
|
13
|
+
const weights = { critical: 1.0, high: 0.75, medium: 0.5, low: 0.25 };
|
|
14
|
+
const score = violations.reduce(
|
|
15
|
+
(sum, v) => sum + (weights[v.severity] || 0.25),
|
|
16
|
+
0
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// Normalize by number of violations, capped at 1.0
|
|
20
|
+
return Math.min(1.0, score / Math.max(1, violations.length));
|
|
21
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General Cost & Value Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
calculatePercentage,
|
|
7
|
+
calculateProgress,
|
|
8
|
+
calculateRemaining,
|
|
9
|
+
} from "./percentage-calculations";
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
calculateFilteredCount,
|
|
13
|
+
calculatePaginationSlice,
|
|
14
|
+
calculateHasMore,
|
|
15
|
+
} from "./pagination-calculations";
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
calculateBase64Size,
|
|
19
|
+
calculateBase64SizeMB,
|
|
20
|
+
isBase64SizeWithinLimit,
|
|
21
|
+
} from "./base64-calculations";
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
calculateConfidenceScore,
|
|
25
|
+
} from "./confidence-calculations";
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
calculateAspectRatio,
|
|
29
|
+
calculateHeightFromAspectRatio,
|
|
30
|
+
calculateWidthFromAspectRatio,
|
|
31
|
+
} from "./aspect-ratio-calculations";
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
calculateImageMemoryUsage,
|
|
35
|
+
calculateMemoryMB,
|
|
36
|
+
calculateSafeBatchSize,
|
|
37
|
+
} from "./memory-calculations";
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
clamp,
|
|
41
|
+
lerp,
|
|
42
|
+
mapRange,
|
|
43
|
+
} from "./math-utilities";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General Cost & Value Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
calculatePercentage,
|
|
7
|
+
calculateProgress,
|
|
8
|
+
calculateRemaining,
|
|
9
|
+
calculateFilteredCount,
|
|
10
|
+
calculatePaginationSlice,
|
|
11
|
+
calculateHasMore,
|
|
12
|
+
calculateBase64Size,
|
|
13
|
+
calculateBase64SizeMB,
|
|
14
|
+
isBase64SizeWithinLimit,
|
|
15
|
+
calculateConfidenceScore,
|
|
16
|
+
calculateAspectRatio,
|
|
17
|
+
calculateHeightFromAspectRatio,
|
|
18
|
+
calculateWidthFromAspectRatio,
|
|
19
|
+
calculateImageMemoryUsage,
|
|
20
|
+
calculateMemoryMB,
|
|
21
|
+
calculateSafeBatchSize,
|
|
22
|
+
clamp,
|
|
23
|
+
lerp,
|
|
24
|
+
mapRange,
|
|
25
|
+
} from "./cost-calculations-index";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credit & Cost Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate cost in credits based on duration and resolution
|
|
7
|
+
*/
|
|
8
|
+
export function calculateCredits(
|
|
9
|
+
durationSeconds: number,
|
|
10
|
+
resolutionMultiplier: number = 1,
|
|
11
|
+
baseCost: number = 1
|
|
12
|
+
): number {
|
|
13
|
+
return Math.ceil((durationSeconds / 60) * resolutionMultiplier * baseCost);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Calculate resolution multiplier for credits
|
|
18
|
+
*/
|
|
19
|
+
export function calculateResolutionMultiplier(width: number, height: number): number {
|
|
20
|
+
const totalPixels = width * height;
|
|
21
|
+
const basePixels = 720 * 1280; // HD baseline
|
|
22
|
+
|
|
23
|
+
if (totalPixels <= basePixels) return 1;
|
|
24
|
+
if (totalPixels <= basePixels * 2) return 1.5;
|
|
25
|
+
if (totalPixels <= basePixels * 4) return 2;
|
|
26
|
+
return 3;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Calculate cost to credits conversion
|
|
31
|
+
*/
|
|
32
|
+
export function convertCostToCredits(
|
|
33
|
+
cost: number,
|
|
34
|
+
creditsPerDollar: number = 100
|
|
35
|
+
): number {
|
|
36
|
+
return Math.ceil(cost * creditsPerDollar);
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculation Utilities
|
|
3
|
+
* Centralized calculation operations for better performance and maintainability
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Credit & Cost Calculations
|
|
7
|
+
export {
|
|
8
|
+
calculateCredits,
|
|
9
|
+
calculateResolutionMultiplier,
|
|
10
|
+
convertCostToCredits,
|
|
11
|
+
} from "./credit-calculations";
|
|
12
|
+
|
|
13
|
+
// Time & Duration Calculations
|
|
14
|
+
export {
|
|
15
|
+
calculateAgeMs,
|
|
16
|
+
calculateAgeSeconds,
|
|
17
|
+
calculateAgeMinutes,
|
|
18
|
+
isOlderThan,
|
|
19
|
+
calculateDurationMs,
|
|
20
|
+
formatDuration,
|
|
21
|
+
calculatePollingInterval,
|
|
22
|
+
calculateEstimatedPollingTime,
|
|
23
|
+
} from "./time-calculations";
|
|
24
|
+
|
|
25
|
+
// General Cost & Value Calculations
|
|
26
|
+
export {
|
|
27
|
+
calculatePercentage,
|
|
28
|
+
calculateProgress,
|
|
29
|
+
calculateRemaining,
|
|
30
|
+
calculateFilteredCount,
|
|
31
|
+
calculatePaginationSlice,
|
|
32
|
+
calculateHasMore,
|
|
33
|
+
calculateBase64Size,
|
|
34
|
+
calculateBase64SizeMB,
|
|
35
|
+
isBase64SizeWithinLimit,
|
|
36
|
+
calculateConfidenceScore,
|
|
37
|
+
calculateAspectRatio,
|
|
38
|
+
calculateHeightFromAspectRatio,
|
|
39
|
+
calculateWidthFromAspectRatio,
|
|
40
|
+
calculateImageMemoryUsage,
|
|
41
|
+
calculateMemoryMB,
|
|
42
|
+
calculateSafeBatchSize,
|
|
43
|
+
clamp,
|
|
44
|
+
lerp,
|
|
45
|
+
mapRange,
|
|
46
|
+
} from "./cost-calculations";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General Math Utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Clamp value between min and max
|
|
7
|
+
*/
|
|
8
|
+
export function clamp(value: number, min: number, max: number): number {
|
|
9
|
+
return Math.max(min, Math.min(max, value));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Linear interpolation between two values
|
|
14
|
+
*/
|
|
15
|
+
export function lerp(start: number, end: number, progress: number): number {
|
|
16
|
+
return start + (end - start) * clamp(progress, 0, 1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Map value from one range to another
|
|
21
|
+
*/
|
|
22
|
+
export function mapRange(
|
|
23
|
+
value: number,
|
|
24
|
+
inMin: number,
|
|
25
|
+
inMax: number,
|
|
26
|
+
outMin: number,
|
|
27
|
+
outMax: number
|
|
28
|
+
): number {
|
|
29
|
+
const inRange = inMax - inMin;
|
|
30
|
+
const outRange = outMax - outMin;
|
|
31
|
+
return outMin + ((value - inMin) / inRange) * outRange;
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Usage Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate estimated memory usage for image
|
|
7
|
+
*/
|
|
8
|
+
export function calculateImageMemoryUsage(
|
|
9
|
+
width: number,
|
|
10
|
+
height: number,
|
|
11
|
+
bytesPerPixel: number = 4 // RGBA
|
|
12
|
+
): number {
|
|
13
|
+
return width * height * bytesPerPixel;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Calculate estimated memory usage in MB
|
|
18
|
+
*/
|
|
19
|
+
export function calculateMemoryMB(bytes: number): number {
|
|
20
|
+
return bytes / (1024 * 1024);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Calculate safe batch size for processing
|
|
25
|
+
*/
|
|
26
|
+
export function calculateSafeBatchSize(
|
|
27
|
+
availableMemoryMB: number,
|
|
28
|
+
itemSizeMB: number,
|
|
29
|
+
safetyFactor: number = 0.7
|
|
30
|
+
): number {
|
|
31
|
+
const safeMemory = availableMemoryMB * safetyFactor;
|
|
32
|
+
return Math.max(1, Math.floor(safeMemory / itemSizeMB));
|
|
33
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate filtered count with predicate
|
|
7
|
+
*/
|
|
8
|
+
export function calculateFilteredCount<T>(
|
|
9
|
+
items: readonly T[],
|
|
10
|
+
predicate: (item: T) => boolean
|
|
11
|
+
): number {
|
|
12
|
+
return items.reduce((count, item) => (predicate(item) ? count + 1 : count), 0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Calculate pagination slice
|
|
17
|
+
*/
|
|
18
|
+
export function calculatePaginationSlice(
|
|
19
|
+
totalItems: number,
|
|
20
|
+
page: number,
|
|
21
|
+
pageSize: number
|
|
22
|
+
): { start: number; end: number; count: number } {
|
|
23
|
+
const start = page * pageSize;
|
|
24
|
+
const end = Math.min(start + pageSize, totalItems);
|
|
25
|
+
const count = end - start;
|
|
26
|
+
return { start, end, count };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Calculate if more items exist for pagination
|
|
31
|
+
*/
|
|
32
|
+
export function calculateHasMore(
|
|
33
|
+
currentCount: number,
|
|
34
|
+
currentPage: number,
|
|
35
|
+
pageSize: number
|
|
36
|
+
): boolean {
|
|
37
|
+
return currentCount >= currentPage * pageSize;
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Percentage & Progress Calculations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculate percentage with bounds checking (0-100)
|
|
7
|
+
*/
|
|
8
|
+
export function calculatePercentage(value: number, total: number): number {
|
|
9
|
+
if (total === 0) return 0;
|
|
10
|
+
const percentage = (value / total) * 100;
|
|
11
|
+
return Math.max(0, Math.min(100, percentage));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Calculate progress with min/max bounds
|
|
16
|
+
*/
|
|
17
|
+
export function calculateProgress(
|
|
18
|
+
current: number,
|
|
19
|
+
total: number,
|
|
20
|
+
min: number = 0,
|
|
21
|
+
max: number = 100
|
|
22
|
+
): number {
|
|
23
|
+
if (total === 0) return min;
|
|
24
|
+
const percentage = (current / total) * (max - min) + min;
|
|
25
|
+
return Math.max(min, Math.min(max, percentage));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Calculate remaining percentage
|
|
30
|
+
*/
|
|
31
|
+
export function calculateRemaining(current: number, total: number): number {
|
|
32
|
+
return Math.max(0, total - current);
|
|
33
|
+
}
|