img-upload-kit 0.0.0-stage → 2.0.0
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/CHANGELOG.md +89 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +192 -0
- package/README.md +242 -2
- package/dist/bin.js +1186 -0
- package/dist/bin.js.map +1 -0
- package/dist/blur.cjs +41 -0
- package/dist/blur.cjs.map +1 -0
- package/dist/blur.d.cts +17 -0
- package/dist/blur.d.ts +17 -0
- package/dist/blur.js +41 -0
- package/dist/blur.js.map +1 -0
- package/dist/blurDataUtils-DveBRtqE.d.cts +43 -0
- package/dist/blurDataUtils-yx9Q6HlU.d.ts +43 -0
- package/dist/blurService-D5TpMNji.d.ts +83 -0
- package/dist/blurService-DacwylJx.d.cts +83 -0
- package/dist/chunk-2OVNXHTN.cjs +514 -0
- package/dist/chunk-2OVNXHTN.cjs.map +1 -0
- package/dist/chunk-3ICG2SLL.cjs +135 -0
- package/dist/chunk-3ICG2SLL.cjs.map +1 -0
- package/dist/chunk-4ASFG3KB.js +514 -0
- package/dist/chunk-4ASFG3KB.js.map +1 -0
- package/dist/chunk-AI3JJLSA.js +2370 -0
- package/dist/chunk-AI3JJLSA.js.map +1 -0
- package/dist/chunk-CV23O4YU.js +145 -0
- package/dist/chunk-CV23O4YU.js.map +1 -0
- package/dist/chunk-G7LLSKBV.js +158 -0
- package/dist/chunk-G7LLSKBV.js.map +1 -0
- package/dist/chunk-IB3TEDLR.js +294 -0
- package/dist/chunk-IB3TEDLR.js.map +1 -0
- package/dist/chunk-KJVYWKIG.cjs +158 -0
- package/dist/chunk-KJVYWKIG.cjs.map +1 -0
- package/dist/chunk-NEDBIIE3.cjs +226 -0
- package/dist/chunk-NEDBIIE3.cjs.map +1 -0
- package/dist/chunk-QHU7FUO4.cjs +37 -0
- package/dist/chunk-QHU7FUO4.cjs.map +1 -0
- package/dist/chunk-QQHZJKNA.js +135 -0
- package/dist/chunk-QQHZJKNA.js.map +1 -0
- package/dist/chunk-S2IFAWJK.js +37 -0
- package/dist/chunk-S2IFAWJK.js.map +1 -0
- package/dist/chunk-TT5C7K3Q.js +226 -0
- package/dist/chunk-TT5C7K3Q.js.map +1 -0
- package/dist/chunk-U2TWTEBY.cjs +2370 -0
- package/dist/chunk-U2TWTEBY.cjs.map +1 -0
- package/dist/chunk-WISG74VL.cjs +294 -0
- package/dist/chunk-WISG74VL.cjs.map +1 -0
- package/dist/chunk-YRXXQUDE.cjs +145 -0
- package/dist/chunk-YRXXQUDE.cjs.map +1 -0
- package/dist/cli.cjs +1241 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +99 -0
- package/dist/cli.d.ts +99 -0
- package/dist/cli.js +1194 -0
- package/dist/cli.js.map +1 -0
- package/dist/headless.cjs +27 -0
- package/dist/headless.cjs.map +1 -0
- package/dist/headless.d.cts +4 -0
- package/dist/headless.d.ts +4 -0
- package/dist/headless.js +27 -0
- package/dist/headless.js.map +1 -0
- package/dist/index-BIdnqtW8.d.ts +234 -0
- package/dist/index-Brk_uHs6.d.cts +234 -0
- package/dist/index-CPMlaQsC.d.ts +635 -0
- package/dist/index-DHINe-rA.d.cts +635 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/memoryAdapter-Ck0ccZbF.d.cts +25 -0
- package/dist/memoryAdapter-DxEKaG0b.d.ts +25 -0
- package/dist/placeholders-C4ftwaII.d.ts +5 -0
- package/dist/placeholders-x_3rt65M.d.cts +5 -0
- package/dist/react.cjs +3779 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +476 -0
- package/dist/react.d.ts +476 -0
- package/dist/react.js +3779 -0
- package/dist/react.js.map +1 -0
- package/dist/server-handler.cjs +14 -0
- package/dist/server-handler.cjs.map +1 -0
- package/dist/server-handler.d.cts +3 -0
- package/dist/server-handler.d.ts +3 -0
- package/dist/server-handler.js +14 -0
- package/dist/server-handler.js.map +1 -0
- package/dist/server.cjs +1801 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +142 -0
- package/dist/server.d.ts +142 -0
- package/dist/server.js +1801 -0
- package/dist/server.js.map +1 -0
- package/dist/storage.cjs +447 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +163 -0
- package/dist/storage.d.ts +163 -0
- package/dist/storage.js +447 -0
- package/dist/storage.js.map +1 -0
- package/dist/styles/animated-image.css +112 -0
- package/dist/styles/dropzone-and-tiles.css +247 -0
- package/dist/styles/modals-and-dock.css +248 -0
- package/dist/styles/primitives.css +197 -0
- package/dist/styles/quality-and-inputs.css +184 -0
- package/dist/styles/tokens.css +123 -0
- package/dist/styles.css +1122 -0
- package/dist/types-BrP-o9nd.d.cts +85 -0
- package/dist/types-sZ3KoFQY.d.ts +85 -0
- package/dist/types-yShGNQnW.d.cts +61 -0
- package/dist/types-yShGNQnW.d.ts +61 -0
- package/dist/upload-C5Trd6Dh.d.cts +154 -0
- package/dist/upload-C5Trd6Dh.d.ts +154 -0
- package/package.json +198 -4
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { I as ImageUploadRecord } from './upload-C5Trd6Dh.cjs';
|
|
2
|
+
|
|
3
|
+
interface StorageUploadParams {
|
|
4
|
+
bucket: string;
|
|
5
|
+
path: string;
|
|
6
|
+
data: Buffer | Uint8Array;
|
|
7
|
+
contentType: string;
|
|
8
|
+
upsert?: boolean;
|
|
9
|
+
cacheControl?: string;
|
|
10
|
+
contentHash?: string;
|
|
11
|
+
metadata?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface StorageUploadResult {
|
|
14
|
+
bucket: string;
|
|
15
|
+
path: string;
|
|
16
|
+
url: string;
|
|
17
|
+
}
|
|
18
|
+
interface StorageFileEntry {
|
|
19
|
+
name: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
createdAt?: string;
|
|
22
|
+
size?: number;
|
|
23
|
+
}
|
|
24
|
+
interface StorageListOptions {
|
|
25
|
+
cursor?: string;
|
|
26
|
+
limit?: number;
|
|
27
|
+
}
|
|
28
|
+
type StoragePaginatedListResult = StorageFileEntry[] & {
|
|
29
|
+
items: StorageFileEntry[];
|
|
30
|
+
nextCursor?: string;
|
|
31
|
+
};
|
|
32
|
+
type StorageUploadOptions = StorageUploadParams;
|
|
33
|
+
type StorageFileMetadata = StorageFileEntry;
|
|
34
|
+
type StorageListResult = StoragePaginatedListResult;
|
|
35
|
+
interface StorageAdapter {
|
|
36
|
+
/**
|
|
37
|
+
* Upload optimized image bytes to your storage backend and return its public URL.
|
|
38
|
+
*/
|
|
39
|
+
upload(params: StorageUploadParams): Promise<StorageUploadResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Delete an image from your storage backend by bucket and relative path.
|
|
42
|
+
*/
|
|
43
|
+
delete(bucket: string, path: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional: Check whether an object exists at the given bucket and relative path.
|
|
46
|
+
*/
|
|
47
|
+
exists?(bucket: string, path: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional: Resolve a public URL for a bucket and path.
|
|
50
|
+
*/
|
|
51
|
+
getPublicUrl?(bucket: string, path: string): string | Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional: List files inside a bucket/folder (supports optional cursor/limit pagination).
|
|
54
|
+
*/
|
|
55
|
+
list?(bucket: string, folder?: string, options?: StorageListOptions): Promise<StoragePaginatedListResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Optional: Delete an asset directly from its public URL.
|
|
58
|
+
*/
|
|
59
|
+
deleteByUrl?(url: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Optional: Parse a public storage URL into its bucket and relative path.
|
|
62
|
+
*/
|
|
63
|
+
parseUrl?(url: string): {
|
|
64
|
+
bucket?: string;
|
|
65
|
+
path: string;
|
|
66
|
+
} | null;
|
|
67
|
+
}
|
|
68
|
+
type UploadRecordHook = (record: ImageUploadRecord) => void | Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Attaches non-enumerable `.items` and `.nextCursor` properties to a `StorageFileEntry[]`
|
|
71
|
+
* array so both array callers (`entries.map(...)`) and paginated destructuring callers
|
|
72
|
+
* (`const { items, nextCursor } = await adapter.list(...)`) work seamlessly.
|
|
73
|
+
*/
|
|
74
|
+
declare function toPaginatedListResult(entries: StorageFileEntry[], nextCursor?: string): StoragePaginatedListResult;
|
|
75
|
+
/**
|
|
76
|
+
* Validates that storage metadata keys and values contain only printable ASCII
|
|
77
|
+
* characters (preventing HTTP header/CRLF injection) and do not exceed 2 KB total.
|
|
78
|
+
*/
|
|
79
|
+
declare function validateStorageMetadata(metadata?: Record<string, string>): void;
|
|
80
|
+
/**
|
|
81
|
+
* Type-safe helper for authoring a custom StorageAdapter (S3, R2, Vercel Blob, Firebase, etc.).
|
|
82
|
+
*/
|
|
83
|
+
declare function createStorageAdapter(adapter: StorageAdapter): StorageAdapter;
|
|
84
|
+
|
|
85
|
+
export { type StorageAdapter as S, type UploadRecordHook as U, type StorageListOptions as a, type StoragePaginatedListResult as b, type StorageFileEntry as c, type StorageFileMetadata as d, type StorageListResult as e, type StorageUploadOptions as f, type StorageUploadParams as g, type StorageUploadResult as h, createStorageAdapter as i, toPaginatedListResult as t, validateStorageMetadata as v };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { I as ImageUploadRecord } from './upload-C5Trd6Dh.js';
|
|
2
|
+
|
|
3
|
+
interface StorageUploadParams {
|
|
4
|
+
bucket: string;
|
|
5
|
+
path: string;
|
|
6
|
+
data: Buffer | Uint8Array;
|
|
7
|
+
contentType: string;
|
|
8
|
+
upsert?: boolean;
|
|
9
|
+
cacheControl?: string;
|
|
10
|
+
contentHash?: string;
|
|
11
|
+
metadata?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface StorageUploadResult {
|
|
14
|
+
bucket: string;
|
|
15
|
+
path: string;
|
|
16
|
+
url: string;
|
|
17
|
+
}
|
|
18
|
+
interface StorageFileEntry {
|
|
19
|
+
name: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
createdAt?: string;
|
|
22
|
+
size?: number;
|
|
23
|
+
}
|
|
24
|
+
interface StorageListOptions {
|
|
25
|
+
cursor?: string;
|
|
26
|
+
limit?: number;
|
|
27
|
+
}
|
|
28
|
+
type StoragePaginatedListResult = StorageFileEntry[] & {
|
|
29
|
+
items: StorageFileEntry[];
|
|
30
|
+
nextCursor?: string;
|
|
31
|
+
};
|
|
32
|
+
type StorageUploadOptions = StorageUploadParams;
|
|
33
|
+
type StorageFileMetadata = StorageFileEntry;
|
|
34
|
+
type StorageListResult = StoragePaginatedListResult;
|
|
35
|
+
interface StorageAdapter {
|
|
36
|
+
/**
|
|
37
|
+
* Upload optimized image bytes to your storage backend and return its public URL.
|
|
38
|
+
*/
|
|
39
|
+
upload(params: StorageUploadParams): Promise<StorageUploadResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Delete an image from your storage backend by bucket and relative path.
|
|
42
|
+
*/
|
|
43
|
+
delete(bucket: string, path: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Optional: Check whether an object exists at the given bucket and relative path.
|
|
46
|
+
*/
|
|
47
|
+
exists?(bucket: string, path: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional: Resolve a public URL for a bucket and path.
|
|
50
|
+
*/
|
|
51
|
+
getPublicUrl?(bucket: string, path: string): string | Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Optional: List files inside a bucket/folder (supports optional cursor/limit pagination).
|
|
54
|
+
*/
|
|
55
|
+
list?(bucket: string, folder?: string, options?: StorageListOptions): Promise<StoragePaginatedListResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Optional: Delete an asset directly from its public URL.
|
|
58
|
+
*/
|
|
59
|
+
deleteByUrl?(url: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Optional: Parse a public storage URL into its bucket and relative path.
|
|
62
|
+
*/
|
|
63
|
+
parseUrl?(url: string): {
|
|
64
|
+
bucket?: string;
|
|
65
|
+
path: string;
|
|
66
|
+
} | null;
|
|
67
|
+
}
|
|
68
|
+
type UploadRecordHook = (record: ImageUploadRecord) => void | Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Attaches non-enumerable `.items` and `.nextCursor` properties to a `StorageFileEntry[]`
|
|
71
|
+
* array so both array callers (`entries.map(...)`) and paginated destructuring callers
|
|
72
|
+
* (`const { items, nextCursor } = await adapter.list(...)`) work seamlessly.
|
|
73
|
+
*/
|
|
74
|
+
declare function toPaginatedListResult(entries: StorageFileEntry[], nextCursor?: string): StoragePaginatedListResult;
|
|
75
|
+
/**
|
|
76
|
+
* Validates that storage metadata keys and values contain only printable ASCII
|
|
77
|
+
* characters (preventing HTTP header/CRLF injection) and do not exceed 2 KB total.
|
|
78
|
+
*/
|
|
79
|
+
declare function validateStorageMetadata(metadata?: Record<string, string>): void;
|
|
80
|
+
/**
|
|
81
|
+
* Type-safe helper for authoring a custom StorageAdapter (S3, R2, Vercel Blob, Firebase, etc.).
|
|
82
|
+
*/
|
|
83
|
+
declare function createStorageAdapter(adapter: StorageAdapter): StorageAdapter;
|
|
84
|
+
|
|
85
|
+
export { type StorageAdapter as S, type UploadRecordHook as U, type StorageListOptions as a, type StoragePaginatedListResult as b, type StorageFileEntry as c, type StorageFileMetadata as d, type StorageListResult as e, type StorageUploadOptions as f, type StorageUploadParams as g, type StorageUploadResult as h, createStorageAdapter as i, toPaginatedListResult as t, validateStorageMetadata as v };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type BlurPlaceholderType = 'default' | 'hero' | 'card' | 'thumbnail';
|
|
2
|
+
type BlurSize = 'small' | 'medium';
|
|
3
|
+
interface BlurDataOptions {
|
|
4
|
+
type?: BlurPlaceholderType;
|
|
5
|
+
size?: BlurSize;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
punch?: number;
|
|
9
|
+
}
|
|
10
|
+
interface BlurManifestEntry {
|
|
11
|
+
hash: string;
|
|
12
|
+
variants: {
|
|
13
|
+
small: string;
|
|
14
|
+
medium?: string;
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
color: string;
|
|
18
|
+
width?: number;
|
|
19
|
+
height?: number;
|
|
20
|
+
metadata?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
interface BlurManifestData {
|
|
23
|
+
version: string;
|
|
24
|
+
generatedAt: string;
|
|
25
|
+
totalImages: number;
|
|
26
|
+
processedImages?: number;
|
|
27
|
+
cachedImages?: number;
|
|
28
|
+
failedImages?: number;
|
|
29
|
+
hashes: Record<string, BlurManifestEntry>;
|
|
30
|
+
}
|
|
31
|
+
interface BlurCacheEntry {
|
|
32
|
+
dataUrl: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
}
|
|
35
|
+
interface BlurServiceMetrics {
|
|
36
|
+
totalRequests: number;
|
|
37
|
+
cacheHits: number;
|
|
38
|
+
cacheMisses: number;
|
|
39
|
+
errors: number;
|
|
40
|
+
}
|
|
41
|
+
interface BlurImageSource {
|
|
42
|
+
url?: string;
|
|
43
|
+
blurDataUrl?: string | null;
|
|
44
|
+
blurColor?: string | null;
|
|
45
|
+
blurHash?: string | null;
|
|
46
|
+
altText?: string | null;
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
}
|
|
50
|
+
interface BlurData {
|
|
51
|
+
blurDataUrl: string;
|
|
52
|
+
blurColor: string;
|
|
53
|
+
blurHash?: string;
|
|
54
|
+
hasBlur: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface BlurServiceConfig {
|
|
57
|
+
cacheSize?: number;
|
|
58
|
+
manifest?: BlurManifestData | Record<string, BlurManifestEntry>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type { BlurCacheEntry as B, BlurData as a, BlurDataOptions as b, BlurImageSource as c, BlurManifestData as d, BlurManifestEntry as e, BlurPlaceholderType as f, BlurServiceConfig as g, BlurServiceMetrics as h, BlurSize as i };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type BlurPlaceholderType = 'default' | 'hero' | 'card' | 'thumbnail';
|
|
2
|
+
type BlurSize = 'small' | 'medium';
|
|
3
|
+
interface BlurDataOptions {
|
|
4
|
+
type?: BlurPlaceholderType;
|
|
5
|
+
size?: BlurSize;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
punch?: number;
|
|
9
|
+
}
|
|
10
|
+
interface BlurManifestEntry {
|
|
11
|
+
hash: string;
|
|
12
|
+
variants: {
|
|
13
|
+
small: string;
|
|
14
|
+
medium?: string;
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
color: string;
|
|
18
|
+
width?: number;
|
|
19
|
+
height?: number;
|
|
20
|
+
metadata?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
interface BlurManifestData {
|
|
23
|
+
version: string;
|
|
24
|
+
generatedAt: string;
|
|
25
|
+
totalImages: number;
|
|
26
|
+
processedImages?: number;
|
|
27
|
+
cachedImages?: number;
|
|
28
|
+
failedImages?: number;
|
|
29
|
+
hashes: Record<string, BlurManifestEntry>;
|
|
30
|
+
}
|
|
31
|
+
interface BlurCacheEntry {
|
|
32
|
+
dataUrl: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
}
|
|
35
|
+
interface BlurServiceMetrics {
|
|
36
|
+
totalRequests: number;
|
|
37
|
+
cacheHits: number;
|
|
38
|
+
cacheMisses: number;
|
|
39
|
+
errors: number;
|
|
40
|
+
}
|
|
41
|
+
interface BlurImageSource {
|
|
42
|
+
url?: string;
|
|
43
|
+
blurDataUrl?: string | null;
|
|
44
|
+
blurColor?: string | null;
|
|
45
|
+
blurHash?: string | null;
|
|
46
|
+
altText?: string | null;
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
}
|
|
50
|
+
interface BlurData {
|
|
51
|
+
blurDataUrl: string;
|
|
52
|
+
blurColor: string;
|
|
53
|
+
blurHash?: string;
|
|
54
|
+
hasBlur: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface BlurServiceConfig {
|
|
57
|
+
cacheSize?: number;
|
|
58
|
+
manifest?: BlurManifestData | Record<string, BlurManifestEntry>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type { BlurCacheEntry as B, BlurData as a, BlurDataOptions as b, BlurImageSource as c, BlurManifestData as d, BlurManifestEntry as e, BlurPlaceholderType as f, BlurServiceConfig as g, BlurServiceMetrics as h, BlurSize as i };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
type UploadLocale = 'en' | 'ar';
|
|
2
|
+
type ImageOutputFormat = 'avif' | 'webp' | 'jpeg' | 'png' | 'svg';
|
|
3
|
+
type ExplicitOutputFormat = 'avif' | 'webp' | 'jpeg' | 'png';
|
|
4
|
+
type QualityLevel = 'low' | 'medium' | 'high' | 'maximum';
|
|
5
|
+
interface QualityPreset {
|
|
6
|
+
label: string;
|
|
7
|
+
labelAr: string;
|
|
8
|
+
value: number;
|
|
9
|
+
description: string;
|
|
10
|
+
descriptionAr: string;
|
|
11
|
+
/** Rough fraction of original bytes after modern AVIF/WebP compression */
|
|
12
|
+
compressionRatio: number;
|
|
13
|
+
}
|
|
14
|
+
declare const QUALITY_PRESETS: Record<QualityLevel, QualityPreset>;
|
|
15
|
+
interface ImageDimensions {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Universal visual role presets (project-agnostic).
|
|
22
|
+
* Consumers can define their own presets via `defineUploadPresets` / `createImageUploader({ presets })`
|
|
23
|
+
* or augment `UploadKitRegister` for global type-safety.
|
|
24
|
+
*/
|
|
25
|
+
type StandardPresetName = 'thumbnail' | 'avatar' | 'card' | 'cover' | 'hero' | 'logo' | 'original';
|
|
26
|
+
/**
|
|
27
|
+
* Module augmentation hook for global preset autocomplete across a project:
|
|
28
|
+
* ```ts
|
|
29
|
+
* declare module 'img-upload-kit' {
|
|
30
|
+
* interface UploadKitRegister {
|
|
31
|
+
* presets: 'product-main' | 'product-thumb' | 'user-avatar';
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
interface UploadKitRegister {
|
|
37
|
+
}
|
|
38
|
+
type UploadPresetName = UploadKitRegister extends {
|
|
39
|
+
presets: infer TCustom extends string;
|
|
40
|
+
} ? TCustom : StandardPresetName | (string & {});
|
|
41
|
+
interface UploadPresetConfig {
|
|
42
|
+
/** Target storage bucket for this preset */
|
|
43
|
+
bucket?: string;
|
|
44
|
+
/** Default folder prefix within the bucket (e.g. 'avatars' or 'products/thumbnails') */
|
|
45
|
+
folder?: string;
|
|
46
|
+
/** Maximum bounding box dimensions (aspect ratio preserved, never enlarged) */
|
|
47
|
+
maxDimensions?: ImageDimensions;
|
|
48
|
+
/** Maximum allowed source file size in MB */
|
|
49
|
+
maxSizeMB?: number;
|
|
50
|
+
/** Allowed source MIME types */
|
|
51
|
+
allowedFormats?: string[];
|
|
52
|
+
/** Force a specific output format; omit for smart size-guarded AVIF/WebP optimization */
|
|
53
|
+
outputFormat?: ExplicitOutputFormat;
|
|
54
|
+
/** Default compression quality (1–100) */
|
|
55
|
+
quality?: number;
|
|
56
|
+
/** Recommended UI quality tab for React `<QualitySelector />` */
|
|
57
|
+
recommendedQualityLevel?: QualityLevel;
|
|
58
|
+
/** Optional guidance note shown in `<QualitySelector />` */
|
|
59
|
+
recommendationNote?: {
|
|
60
|
+
en: string;
|
|
61
|
+
ar?: string;
|
|
62
|
+
};
|
|
63
|
+
/** Generate compact BlurHash string alongside WebP LQIP data URL */
|
|
64
|
+
includeBlurHash?: boolean;
|
|
65
|
+
/** Opt-in to allow SVG uploads for this preset (sanitized before storage). Defaults to `false`. */
|
|
66
|
+
allowSvg?: boolean;
|
|
67
|
+
/** Maximum input pixel count allowed by Sharp (defaults to 50 MP = 50,000,000) */
|
|
68
|
+
limitInputPixels?: number;
|
|
69
|
+
/** Responsive variant widths in pixels (e.g. [640, 1024, 1920]); widths >= main image width are skipped */
|
|
70
|
+
variantWidths?: number[];
|
|
71
|
+
/** Optional local directory to mirror uploaded files into */
|
|
72
|
+
mirrorDir?: string;
|
|
73
|
+
/** Optional public URL prefix when `mirrorDir` is used */
|
|
74
|
+
publicUrlBase?: string;
|
|
75
|
+
}
|
|
76
|
+
declare const SVG_MIME_TYPE = "image/svg+xml";
|
|
77
|
+
declare const DEFAULT_ALLOWED_FORMATS: string[];
|
|
78
|
+
declare const RASTER_ALLOWED_FORMATS: string[];
|
|
79
|
+
declare const DEFAULT_IMAGE_DIMENSIONS: ImageDimensions;
|
|
80
|
+
declare const STANDARD_PRESETS: Record<StandardPresetName, UploadPresetConfig>;
|
|
81
|
+
/**
|
|
82
|
+
* Type-safe helper to define project-specific upload presets with full key inference.
|
|
83
|
+
*/
|
|
84
|
+
declare function defineUploadPresets<T extends Record<string, UploadPresetConfig>>(presets: T): T;
|
|
85
|
+
|
|
86
|
+
interface ImageUploadOptions<TPreset extends string = UploadPresetName> {
|
|
87
|
+
/** Optional preset key (e.g. 'avatar', 'hero', or a custom project preset) */
|
|
88
|
+
preset?: TPreset;
|
|
89
|
+
/** Target storage bucket (overrides preset & uploader defaultBucket) */
|
|
90
|
+
bucket?: string;
|
|
91
|
+
/** Target folder path inside the bucket (e.g. 'products/shoes' or 'users/42') */
|
|
92
|
+
folder?: string;
|
|
93
|
+
/** Maximum bounding box dimensions (overrides preset maxDimensions) */
|
|
94
|
+
maxDimensions?: ImageDimensions;
|
|
95
|
+
/** Maximum allowed input size in MB */
|
|
96
|
+
maxSizeMB?: number;
|
|
97
|
+
/** Allowed MIME types */
|
|
98
|
+
allowedFormats?: string[];
|
|
99
|
+
/** Explicit output format; omit for smart size-guarded AVIF/WebP selection */
|
|
100
|
+
outputFormat?: ExplicitOutputFormat;
|
|
101
|
+
/** 1–100 compression quality */
|
|
102
|
+
quality?: number;
|
|
103
|
+
/** Optional custom filename (automatically sanitized) */
|
|
104
|
+
customFilename?: string;
|
|
105
|
+
/** Alt text description for accessibility & SEO */
|
|
106
|
+
altText?: string;
|
|
107
|
+
/** Arbitrary project-specific context/metadata (e.g. { entityId: '42', scope: 'catalog' }) */
|
|
108
|
+
metadata?: Record<string, string>;
|
|
109
|
+
/** Generate compact BlurHash string alongside WebP LQIP data URL */
|
|
110
|
+
includeBlurHash?: boolean;
|
|
111
|
+
/** Opt-in to allow SVG uploads (sanitized before storage). Defaults to `false`. */
|
|
112
|
+
allowSvg?: boolean;
|
|
113
|
+
/** Maximum input pixel count allowed by Sharp (defaults to 50 MP = 50,000,000) */
|
|
114
|
+
limitInputPixels?: number;
|
|
115
|
+
/** Marks `customFilename` as client-supplied (disables upsert and retries with a suffix on collision) */
|
|
116
|
+
isClientFilename?: boolean;
|
|
117
|
+
/** Target widths (px) for responsive image variants (widths >= main output width are skipped) */
|
|
118
|
+
variantWidths?: number[];
|
|
119
|
+
/** Optional AbortSignal to cancel queued or in-flight processing */
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
}
|
|
122
|
+
interface ImageVariant {
|
|
123
|
+
width: number;
|
|
124
|
+
height: number;
|
|
125
|
+
url: string;
|
|
126
|
+
size: number;
|
|
127
|
+
storagePath?: string;
|
|
128
|
+
}
|
|
129
|
+
interface UploadedImageData {
|
|
130
|
+
url: string;
|
|
131
|
+
blurDataUrl: string;
|
|
132
|
+
blurColor: string;
|
|
133
|
+
blurHash?: string;
|
|
134
|
+
altText?: string;
|
|
135
|
+
width: number;
|
|
136
|
+
height: number;
|
|
137
|
+
format: ImageOutputFormat;
|
|
138
|
+
size: number;
|
|
139
|
+
originalSize?: number;
|
|
140
|
+
contentHash: string;
|
|
141
|
+
storagePath?: string;
|
|
142
|
+
bucket?: string;
|
|
143
|
+
preset?: string;
|
|
144
|
+
folder?: string;
|
|
145
|
+
metadata?: Record<string, string>;
|
|
146
|
+
variants?: ImageVariant[];
|
|
147
|
+
srcSet?: string;
|
|
148
|
+
uploadedAt: string;
|
|
149
|
+
}
|
|
150
|
+
interface ImageUploadRecord extends UploadedImageData {
|
|
151
|
+
quality: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { DEFAULT_ALLOWED_FORMATS as D, type ExplicitOutputFormat as E, type ImageUploadRecord as I, type QualityLevel as Q, RASTER_ALLOWED_FORMATS as R, STANDARD_PRESETS as S, type UploadLocale as U, DEFAULT_IMAGE_DIMENSIONS as a, type ImageDimensions as b, type ImageOutputFormat as c, type ImageUploadOptions as d, type ImageVariant as e, QUALITY_PRESETS as f, type QualityPreset as g, SVG_MIME_TYPE as h, type StandardPresetName as i, type UploadKitRegister as j, type UploadPresetConfig as k, type UploadPresetName as l, type UploadedImageData as m, defineUploadPresets as n };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
type UploadLocale = 'en' | 'ar';
|
|
2
|
+
type ImageOutputFormat = 'avif' | 'webp' | 'jpeg' | 'png' | 'svg';
|
|
3
|
+
type ExplicitOutputFormat = 'avif' | 'webp' | 'jpeg' | 'png';
|
|
4
|
+
type QualityLevel = 'low' | 'medium' | 'high' | 'maximum';
|
|
5
|
+
interface QualityPreset {
|
|
6
|
+
label: string;
|
|
7
|
+
labelAr: string;
|
|
8
|
+
value: number;
|
|
9
|
+
description: string;
|
|
10
|
+
descriptionAr: string;
|
|
11
|
+
/** Rough fraction of original bytes after modern AVIF/WebP compression */
|
|
12
|
+
compressionRatio: number;
|
|
13
|
+
}
|
|
14
|
+
declare const QUALITY_PRESETS: Record<QualityLevel, QualityPreset>;
|
|
15
|
+
interface ImageDimensions {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Universal visual role presets (project-agnostic).
|
|
22
|
+
* Consumers can define their own presets via `defineUploadPresets` / `createImageUploader({ presets })`
|
|
23
|
+
* or augment `UploadKitRegister` for global type-safety.
|
|
24
|
+
*/
|
|
25
|
+
type StandardPresetName = 'thumbnail' | 'avatar' | 'card' | 'cover' | 'hero' | 'logo' | 'original';
|
|
26
|
+
/**
|
|
27
|
+
* Module augmentation hook for global preset autocomplete across a project:
|
|
28
|
+
* ```ts
|
|
29
|
+
* declare module 'img-upload-kit' {
|
|
30
|
+
* interface UploadKitRegister {
|
|
31
|
+
* presets: 'product-main' | 'product-thumb' | 'user-avatar';
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
interface UploadKitRegister {
|
|
37
|
+
}
|
|
38
|
+
type UploadPresetName = UploadKitRegister extends {
|
|
39
|
+
presets: infer TCustom extends string;
|
|
40
|
+
} ? TCustom : StandardPresetName | (string & {});
|
|
41
|
+
interface UploadPresetConfig {
|
|
42
|
+
/** Target storage bucket for this preset */
|
|
43
|
+
bucket?: string;
|
|
44
|
+
/** Default folder prefix within the bucket (e.g. 'avatars' or 'products/thumbnails') */
|
|
45
|
+
folder?: string;
|
|
46
|
+
/** Maximum bounding box dimensions (aspect ratio preserved, never enlarged) */
|
|
47
|
+
maxDimensions?: ImageDimensions;
|
|
48
|
+
/** Maximum allowed source file size in MB */
|
|
49
|
+
maxSizeMB?: number;
|
|
50
|
+
/** Allowed source MIME types */
|
|
51
|
+
allowedFormats?: string[];
|
|
52
|
+
/** Force a specific output format; omit for smart size-guarded AVIF/WebP optimization */
|
|
53
|
+
outputFormat?: ExplicitOutputFormat;
|
|
54
|
+
/** Default compression quality (1–100) */
|
|
55
|
+
quality?: number;
|
|
56
|
+
/** Recommended UI quality tab for React `<QualitySelector />` */
|
|
57
|
+
recommendedQualityLevel?: QualityLevel;
|
|
58
|
+
/** Optional guidance note shown in `<QualitySelector />` */
|
|
59
|
+
recommendationNote?: {
|
|
60
|
+
en: string;
|
|
61
|
+
ar?: string;
|
|
62
|
+
};
|
|
63
|
+
/** Generate compact BlurHash string alongside WebP LQIP data URL */
|
|
64
|
+
includeBlurHash?: boolean;
|
|
65
|
+
/** Opt-in to allow SVG uploads for this preset (sanitized before storage). Defaults to `false`. */
|
|
66
|
+
allowSvg?: boolean;
|
|
67
|
+
/** Maximum input pixel count allowed by Sharp (defaults to 50 MP = 50,000,000) */
|
|
68
|
+
limitInputPixels?: number;
|
|
69
|
+
/** Responsive variant widths in pixels (e.g. [640, 1024, 1920]); widths >= main image width are skipped */
|
|
70
|
+
variantWidths?: number[];
|
|
71
|
+
/** Optional local directory to mirror uploaded files into */
|
|
72
|
+
mirrorDir?: string;
|
|
73
|
+
/** Optional public URL prefix when `mirrorDir` is used */
|
|
74
|
+
publicUrlBase?: string;
|
|
75
|
+
}
|
|
76
|
+
declare const SVG_MIME_TYPE = "image/svg+xml";
|
|
77
|
+
declare const DEFAULT_ALLOWED_FORMATS: string[];
|
|
78
|
+
declare const RASTER_ALLOWED_FORMATS: string[];
|
|
79
|
+
declare const DEFAULT_IMAGE_DIMENSIONS: ImageDimensions;
|
|
80
|
+
declare const STANDARD_PRESETS: Record<StandardPresetName, UploadPresetConfig>;
|
|
81
|
+
/**
|
|
82
|
+
* Type-safe helper to define project-specific upload presets with full key inference.
|
|
83
|
+
*/
|
|
84
|
+
declare function defineUploadPresets<T extends Record<string, UploadPresetConfig>>(presets: T): T;
|
|
85
|
+
|
|
86
|
+
interface ImageUploadOptions<TPreset extends string = UploadPresetName> {
|
|
87
|
+
/** Optional preset key (e.g. 'avatar', 'hero', or a custom project preset) */
|
|
88
|
+
preset?: TPreset;
|
|
89
|
+
/** Target storage bucket (overrides preset & uploader defaultBucket) */
|
|
90
|
+
bucket?: string;
|
|
91
|
+
/** Target folder path inside the bucket (e.g. 'products/shoes' or 'users/42') */
|
|
92
|
+
folder?: string;
|
|
93
|
+
/** Maximum bounding box dimensions (overrides preset maxDimensions) */
|
|
94
|
+
maxDimensions?: ImageDimensions;
|
|
95
|
+
/** Maximum allowed input size in MB */
|
|
96
|
+
maxSizeMB?: number;
|
|
97
|
+
/** Allowed MIME types */
|
|
98
|
+
allowedFormats?: string[];
|
|
99
|
+
/** Explicit output format; omit for smart size-guarded AVIF/WebP selection */
|
|
100
|
+
outputFormat?: ExplicitOutputFormat;
|
|
101
|
+
/** 1–100 compression quality */
|
|
102
|
+
quality?: number;
|
|
103
|
+
/** Optional custom filename (automatically sanitized) */
|
|
104
|
+
customFilename?: string;
|
|
105
|
+
/** Alt text description for accessibility & SEO */
|
|
106
|
+
altText?: string;
|
|
107
|
+
/** Arbitrary project-specific context/metadata (e.g. { entityId: '42', scope: 'catalog' }) */
|
|
108
|
+
metadata?: Record<string, string>;
|
|
109
|
+
/** Generate compact BlurHash string alongside WebP LQIP data URL */
|
|
110
|
+
includeBlurHash?: boolean;
|
|
111
|
+
/** Opt-in to allow SVG uploads (sanitized before storage). Defaults to `false`. */
|
|
112
|
+
allowSvg?: boolean;
|
|
113
|
+
/** Maximum input pixel count allowed by Sharp (defaults to 50 MP = 50,000,000) */
|
|
114
|
+
limitInputPixels?: number;
|
|
115
|
+
/** Marks `customFilename` as client-supplied (disables upsert and retries with a suffix on collision) */
|
|
116
|
+
isClientFilename?: boolean;
|
|
117
|
+
/** Target widths (px) for responsive image variants (widths >= main output width are skipped) */
|
|
118
|
+
variantWidths?: number[];
|
|
119
|
+
/** Optional AbortSignal to cancel queued or in-flight processing */
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
}
|
|
122
|
+
interface ImageVariant {
|
|
123
|
+
width: number;
|
|
124
|
+
height: number;
|
|
125
|
+
url: string;
|
|
126
|
+
size: number;
|
|
127
|
+
storagePath?: string;
|
|
128
|
+
}
|
|
129
|
+
interface UploadedImageData {
|
|
130
|
+
url: string;
|
|
131
|
+
blurDataUrl: string;
|
|
132
|
+
blurColor: string;
|
|
133
|
+
blurHash?: string;
|
|
134
|
+
altText?: string;
|
|
135
|
+
width: number;
|
|
136
|
+
height: number;
|
|
137
|
+
format: ImageOutputFormat;
|
|
138
|
+
size: number;
|
|
139
|
+
originalSize?: number;
|
|
140
|
+
contentHash: string;
|
|
141
|
+
storagePath?: string;
|
|
142
|
+
bucket?: string;
|
|
143
|
+
preset?: string;
|
|
144
|
+
folder?: string;
|
|
145
|
+
metadata?: Record<string, string>;
|
|
146
|
+
variants?: ImageVariant[];
|
|
147
|
+
srcSet?: string;
|
|
148
|
+
uploadedAt: string;
|
|
149
|
+
}
|
|
150
|
+
interface ImageUploadRecord extends UploadedImageData {
|
|
151
|
+
quality: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { DEFAULT_ALLOWED_FORMATS as D, type ExplicitOutputFormat as E, type ImageUploadRecord as I, type QualityLevel as Q, RASTER_ALLOWED_FORMATS as R, STANDARD_PRESETS as S, type UploadLocale as U, DEFAULT_IMAGE_DIMENSIONS as a, type ImageDimensions as b, type ImageOutputFormat as c, type ImageUploadOptions as d, type ImageVariant as e, QUALITY_PRESETS as f, type QualityPreset as g, SVG_MIME_TYPE as h, type StandardPresetName as i, type UploadKitRegister as j, type UploadPresetConfig as k, type UploadPresetName as l, type UploadedImageData as m, defineUploadPresets as n };
|