taglib-wasm 0.3.3 → 0.3.9
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/CONTRIBUTING.md +293 -0
- package/NOTICE +34 -0
- package/README.md +122 -511
- package/dist/index.d.ts +132 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +137 -0
- package/dist/index.ts +220 -0
- package/dist/src/constants.d.ts +201 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.ts +227 -0
- package/dist/src/errors.d.ts +89 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.ts +237 -0
- package/dist/src/file-utils.d.ts +205 -0
- package/dist/src/file-utils.d.ts.map +1 -0
- package/dist/src/file-utils.ts +467 -0
- package/dist/src/file.js +47 -0
- package/dist/src/global.d.ts +10 -0
- package/dist/src/mod.d.ts +9 -0
- package/dist/src/mod.d.ts.map +1 -0
- package/dist/src/mod.ts +19 -0
- package/dist/src/simple.d.ts +347 -0
- package/dist/src/simple.d.ts.map +1 -0
- package/dist/src/simple.ts +659 -0
- package/dist/src/taglib.d.ts +502 -0
- package/dist/src/taglib.d.ts.map +1 -0
- package/dist/src/taglib.ts +959 -0
- package/dist/src/types.d.ts +323 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.ts +538 -0
- package/dist/src/utils/file.d.ts +15 -0
- package/dist/src/utils/file.d.ts.map +1 -0
- package/dist/src/utils/file.ts +82 -0
- package/dist/src/utils/write.d.ts +15 -0
- package/dist/src/utils/write.d.ts.map +1 -0
- package/dist/src/utils/write.ts +61 -0
- package/dist/src/wasm-workers.d.ts +33 -0
- package/dist/src/wasm-workers.d.ts.map +1 -0
- package/dist/src/wasm-workers.ts +176 -0
- package/dist/src/wasm.d.ts +97 -0
- package/dist/src/wasm.d.ts.map +1 -0
- package/dist/src/wasm.ts +133 -0
- package/dist/src/web-utils.d.ts +180 -0
- package/dist/src/web-utils.d.ts.map +1 -0
- package/dist/src/web-utils.ts +347 -0
- package/dist/src/workers.d.ts +219 -0
- package/dist/src/workers.d.ts.map +1 -0
- package/dist/src/workers.ts +465 -0
- package/dist/src/write.js +33 -0
- package/dist/taglib-wrapper.d.ts +5 -0
- package/dist/taglib-wrapper.js +14 -0
- package/dist/taglib.wasm +0 -0
- package/index.ts +100 -7
- package/package.json +40 -16
- package/src/errors.ts +237 -0
- package/src/file-utils.ts +467 -0
- package/src/global.d.ts +10 -0
- package/src/simple.ts +399 -84
- package/src/taglib.ts +522 -28
- package/src/types.ts +1 -1
- package/src/utils/file.ts +82 -0
- package/src/utils/write.ts +61 -0
- package/src/wasm-workers.ts +13 -4
- package/src/wasm.ts +1 -1
- package/src/web-utils.ts +347 -0
- package/src/workers.ts +32 -13
- package/build/taglib.js +0 -2407
- package/build/taglib.wasm +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File writing utilities for taglib-wasm
|
|
3
|
+
* Provides cross-runtime support for writing files
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EnvironmentError, FileOperationError } from "../errors.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Write data to a file across different runtimes.
|
|
10
|
+
* Supports Node.js, Deno, and Bun environments.
|
|
11
|
+
*
|
|
12
|
+
* @param path - File path to write to
|
|
13
|
+
* @param data - Data to write (Uint8Array)
|
|
14
|
+
* @throws {FileOperationError} If file write fails
|
|
15
|
+
* @throws {EnvironmentError} If environment doesn't support file writing
|
|
16
|
+
*/
|
|
17
|
+
export async function writeFileData(
|
|
18
|
+
path: string,
|
|
19
|
+
data: Uint8Array,
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
// Deno
|
|
23
|
+
if (typeof Deno !== "undefined") {
|
|
24
|
+
await Deno.writeFile(path, data);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Node.js
|
|
29
|
+
if (
|
|
30
|
+
typeof process !== "undefined" && process.versions &&
|
|
31
|
+
process.versions.node
|
|
32
|
+
) {
|
|
33
|
+
const { writeFile } = await import("fs/promises");
|
|
34
|
+
await writeFile(path, data);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Bun
|
|
39
|
+
if (typeof (globalThis as any).Bun !== "undefined") {
|
|
40
|
+
await (globalThis as any).Bun.write(path, data);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Convert system file errors to FileOperationError
|
|
45
|
+
throw new FileOperationError(
|
|
46
|
+
"write",
|
|
47
|
+
(error as Error).message,
|
|
48
|
+
path
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const env = typeof Deno !== "undefined" ? "Deno" :
|
|
53
|
+
typeof process !== "undefined" ? "Node.js" :
|
|
54
|
+
typeof (globalThis as any).Bun !== "undefined" ? "Bun" :
|
|
55
|
+
"Browser";
|
|
56
|
+
throw new EnvironmentError(
|
|
57
|
+
env,
|
|
58
|
+
"does not support file path writing",
|
|
59
|
+
"filesystem access"
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview WebAssembly module interface for Cloudflare Workers
|
|
3
|
+
*/
|
|
4
|
+
import type { TagLibConfig, TagLibModule } from "./types.ts";
|
|
5
|
+
export type { TagLibModule };
|
|
6
|
+
/**
|
|
7
|
+
* Load and initialize the TagLib WebAssembly module for Cloudflare Workers
|
|
8
|
+
*
|
|
9
|
+
* @param wasmBinary - The WebAssembly binary as Uint8Array
|
|
10
|
+
* @param config - Optional configuration for the Wasm module
|
|
11
|
+
* @returns Promise resolving to initialized TagLib module
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import wasmBinary from "../build/taglib.wasm";
|
|
16
|
+
*
|
|
17
|
+
* const taglib = await loadTagLibModuleForWorkers(wasmBinary);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadTagLibModuleForWorkers(wasmBinary: Uint8Array, config?: TagLibConfig): Promise<TagLibModule>;
|
|
21
|
+
/**
|
|
22
|
+
* Convert a C string pointer to JavaScript string (Workers-compatible)
|
|
23
|
+
*/
|
|
24
|
+
export declare function cStringToJS(module: TagLibModule, ptr: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Convert JavaScript string to C string (Workers-compatible)
|
|
27
|
+
*/
|
|
28
|
+
export declare function jsToCString(module: TagLibModule, str: string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Utility function to check if we're running in Cloudflare Workers
|
|
31
|
+
*/
|
|
32
|
+
export declare function isCloudflareWorkers(): boolean;
|
|
33
|
+
//# sourceMappingURL=wasm-workers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-workers.d.ts","sourceRoot":"","sources":["../../src/wasm-workers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI7D,YAAY,EAAE,YAAY,EAAE,CAAC;AAc7B;;;;;;;;;;;;;GAaG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,UAAU,EACtB,MAAM,GAAE,YAAiB,GACxB,OAAO,CAAC,YAAY,CAAC,CAkEvB;AA4BD;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQrE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAYrE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAS7C"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview WebAssembly module interface for Cloudflare Workers
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { TagLibConfig, TagLibModule } from "./types.ts";
|
|
6
|
+
import { TagLibInitializationError } from "./errors.ts";
|
|
7
|
+
|
|
8
|
+
// Re-export TagLibModule for convenience
|
|
9
|
+
export type { TagLibModule };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Default configuration for taglib-wasm module in Workers environment
|
|
13
|
+
* Reduced memory limits to fit within Workers constraints
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_WORKERS_CONFIG: Required<TagLibConfig> = {
|
|
16
|
+
memory: {
|
|
17
|
+
initial: 8 * 1024 * 1024, // 8MB (reduced from 16MB)
|
|
18
|
+
maximum: 64 * 1024 * 1024, // 64MB (reduced from 256MB)
|
|
19
|
+
},
|
|
20
|
+
debug: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Load and initialize the TagLib WebAssembly module for Cloudflare Workers
|
|
25
|
+
*
|
|
26
|
+
* @param wasmBinary - The WebAssembly binary as Uint8Array
|
|
27
|
+
* @param config - Optional configuration for the Wasm module
|
|
28
|
+
* @returns Promise resolving to initialized TagLib module
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import wasmBinary from "../build/taglib.wasm";
|
|
33
|
+
*
|
|
34
|
+
* const taglib = await loadTagLibModuleForWorkers(wasmBinary);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export async function loadTagLibModuleForWorkers(
|
|
38
|
+
wasmBinary: Uint8Array,
|
|
39
|
+
config: TagLibConfig = {},
|
|
40
|
+
): Promise<TagLibModule> {
|
|
41
|
+
const mergedConfig = { ...DEFAULT_WORKERS_CONFIG, ...config };
|
|
42
|
+
|
|
43
|
+
// Create Emscripten module configuration for Workers
|
|
44
|
+
const moduleConfig = {
|
|
45
|
+
wasmBinary,
|
|
46
|
+
wasmMemory: new WebAssembly.Memory({
|
|
47
|
+
initial: mergedConfig.memory.initial! / (64 * 1024),
|
|
48
|
+
maximum: mergedConfig.memory.maximum! / (64 * 1024),
|
|
49
|
+
}),
|
|
50
|
+
print: mergedConfig.debug ? console.log : () => {},
|
|
51
|
+
printErr: mergedConfig.debug ? console.error : () => {},
|
|
52
|
+
onRuntimeInitialized: () => {
|
|
53
|
+
if (mergedConfig.debug) {
|
|
54
|
+
console.log("taglib-wasm module initialized in Workers");
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
// Workers-specific settings
|
|
58
|
+
locateFile: () => {
|
|
59
|
+
// Return empty string since we're providing wasmBinary directly
|
|
60
|
+
return "";
|
|
61
|
+
},
|
|
62
|
+
// Disable file system access
|
|
63
|
+
noFSInit: true,
|
|
64
|
+
noExitRuntime: true,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
// For Workers, we need to use a modified version of the Emscripten output
|
|
69
|
+
// that doesn't include Node.js/CommonJS dependencies
|
|
70
|
+
const TagLibWasm = await createWorkersCompatibleModule();
|
|
71
|
+
|
|
72
|
+
if (typeof TagLibWasm !== "function") {
|
|
73
|
+
throw new TagLibInitializationError(
|
|
74
|
+
"Failed to load taglib-wasm module for Workers. " +
|
|
75
|
+
"The module may not be properly bundled for the Workers environment.",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const wasmInstance = await TagLibWasm(moduleConfig);
|
|
80
|
+
|
|
81
|
+
// Ensure proper memory arrays are set up
|
|
82
|
+
if (!wasmInstance.HEAPU8) {
|
|
83
|
+
const buffer = wasmInstance.buffer || wasmInstance.wasmMemory?.buffer;
|
|
84
|
+
if (buffer) {
|
|
85
|
+
wasmInstance.HEAPU8 = new Uint8Array(buffer);
|
|
86
|
+
wasmInstance.HEAP8 = new Int8Array(buffer);
|
|
87
|
+
wasmInstance.HEAP16 = new Int16Array(buffer);
|
|
88
|
+
wasmInstance.HEAP32 = new Int32Array(buffer);
|
|
89
|
+
wasmInstance.HEAPU16 = new Uint16Array(buffer);
|
|
90
|
+
wasmInstance.HEAPU32 = new Uint32Array(buffer);
|
|
91
|
+
wasmInstance.HEAPF32 = new Float32Array(buffer);
|
|
92
|
+
wasmInstance.HEAPF64 = new Float64Array(buffer);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return wasmInstance as TagLibModule;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error instanceof TagLibInitializationError) {
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
throw new TagLibInitializationError(
|
|
102
|
+
`Failed to load taglib-wasm for Workers: ${(error as Error).message}`,
|
|
103
|
+
{ error: (error as Error).message },
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Create a Workers-compatible version of the Emscripten module
|
|
110
|
+
* This function loads the Wasm module without Node.js/CommonJS dependencies
|
|
111
|
+
*/
|
|
112
|
+
async function createWorkersCompatibleModule(): Promise<any> {
|
|
113
|
+
// In a real Workers environment, you would typically:
|
|
114
|
+
// 1. Use a build process to create a Workers-compatible version of taglib.js
|
|
115
|
+
// 2. Or inline the essential parts of the Emscripten runtime here
|
|
116
|
+
// 3. Or use dynamic import with proper bundling
|
|
117
|
+
|
|
118
|
+
// For now, we'll attempt to load the existing module with Workers compatibility
|
|
119
|
+
try {
|
|
120
|
+
// Try to import the existing module
|
|
121
|
+
const wasmModule = await import("../build/taglib-wrapper.js");
|
|
122
|
+
return wasmModule.default || wasmModule;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
// If that fails, provide a fallback implementation
|
|
125
|
+
throw new TagLibInitializationError(
|
|
126
|
+
"Workers-compatible Wasm module not available. " +
|
|
127
|
+
"Please build with Workers target or use a bundler that supports Wasm modules. " +
|
|
128
|
+
`Original error: ${(error as Error).message}`,
|
|
129
|
+
{ error: (error as Error).message },
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Convert a C string pointer to JavaScript string (Workers-compatible)
|
|
136
|
+
*/
|
|
137
|
+
export function cStringToJS(module: TagLibModule, ptr: number): string {
|
|
138
|
+
if (ptr === 0) return "";
|
|
139
|
+
|
|
140
|
+
const view = new Uint8Array(module.HEAPU8.buffer, ptr);
|
|
141
|
+
let length = 0;
|
|
142
|
+
while (view[length] !== 0) length++;
|
|
143
|
+
|
|
144
|
+
return new TextDecoder().decode(view.subarray(0, length));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Convert JavaScript string to C string (Workers-compatible)
|
|
149
|
+
*/
|
|
150
|
+
export function jsToCString(module: TagLibModule, str: string): number {
|
|
151
|
+
const encoder = new TextEncoder();
|
|
152
|
+
const bytes = encoder.encode(str + "\0");
|
|
153
|
+
|
|
154
|
+
// Use allocate if available, otherwise use _malloc
|
|
155
|
+
if (module.allocate && module.ALLOC_NORMAL !== undefined) {
|
|
156
|
+
return module.allocate(bytes, module.ALLOC_NORMAL);
|
|
157
|
+
} else {
|
|
158
|
+
const ptr = module._malloc(bytes.length);
|
|
159
|
+
module.HEAPU8.set(bytes, ptr);
|
|
160
|
+
return ptr;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Utility function to check if we're running in Cloudflare Workers
|
|
166
|
+
*/
|
|
167
|
+
export function isCloudflareWorkers(): boolean {
|
|
168
|
+
return (
|
|
169
|
+
typeof globalThis !== "undefined" &&
|
|
170
|
+
typeof globalThis.caches !== "undefined" &&
|
|
171
|
+
typeof globalThis.Request !== "undefined" &&
|
|
172
|
+
typeof globalThis.Response !== "undefined" &&
|
|
173
|
+
typeof (globalThis as any).process === "undefined" &&
|
|
174
|
+
typeof (globalThis as any).Deno === "undefined"
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview WebAssembly module interface types for Emscripten
|
|
3
|
+
*/
|
|
4
|
+
export interface EmscriptenModule {
|
|
5
|
+
HEAP8: Int8Array;
|
|
6
|
+
HEAP16: Int16Array;
|
|
7
|
+
HEAP32: Int32Array;
|
|
8
|
+
HEAPU8: Uint8Array;
|
|
9
|
+
HEAPU16: Uint16Array;
|
|
10
|
+
HEAPU32: Uint32Array;
|
|
11
|
+
HEAPF32: Float32Array;
|
|
12
|
+
HEAPF64: Float64Array;
|
|
13
|
+
_malloc(size: number): number;
|
|
14
|
+
_free(ptr: number): void;
|
|
15
|
+
allocate?(data: number[] | Uint8Array, allocator: number): number;
|
|
16
|
+
ALLOC_NORMAL?: number;
|
|
17
|
+
ccall?(ident: string, returnType: string, argTypes: string[], args: any[]): any;
|
|
18
|
+
cwrap?(ident: string, returnType: string, argTypes: string[]): (...args: any[]) => any;
|
|
19
|
+
FS?: any;
|
|
20
|
+
then?(callback: (module: EmscriptenModule) => void): void;
|
|
21
|
+
onRuntimeInitialized?: () => void;
|
|
22
|
+
}
|
|
23
|
+
export interface FileHandle {
|
|
24
|
+
loadFromBuffer(data: Uint8Array): boolean;
|
|
25
|
+
isValid(): boolean;
|
|
26
|
+
save(): boolean;
|
|
27
|
+
getFormat(): string;
|
|
28
|
+
getProperties(): any;
|
|
29
|
+
setProperties(props: any): void;
|
|
30
|
+
getProperty(key: string): string;
|
|
31
|
+
setProperty(key: string, value: string): void;
|
|
32
|
+
isMP4(): boolean;
|
|
33
|
+
getMP4Item(key: string): string;
|
|
34
|
+
setMP4Item(key: string, value: string): void;
|
|
35
|
+
removeMP4Item(key: string): void;
|
|
36
|
+
getTag(): TagWrapper;
|
|
37
|
+
getAudioProperties(): AudioPropertiesWrapper;
|
|
38
|
+
}
|
|
39
|
+
export interface TagWrapper {
|
|
40
|
+
title(): string;
|
|
41
|
+
artist(): string;
|
|
42
|
+
album(): string;
|
|
43
|
+
comment(): string;
|
|
44
|
+
genre(): string;
|
|
45
|
+
year(): number;
|
|
46
|
+
track(): number;
|
|
47
|
+
setTitle(value: string): void;
|
|
48
|
+
setArtist(value: string): void;
|
|
49
|
+
setAlbum(value: string): void;
|
|
50
|
+
setComment(value: string): void;
|
|
51
|
+
setGenre(value: string): void;
|
|
52
|
+
setYear(value: number): void;
|
|
53
|
+
setTrack(value: number): void;
|
|
54
|
+
}
|
|
55
|
+
export interface AudioPropertiesWrapper {
|
|
56
|
+
lengthInSeconds(): number;
|
|
57
|
+
lengthInMilliseconds(): number;
|
|
58
|
+
bitrate(): number;
|
|
59
|
+
sampleRate(): number;
|
|
60
|
+
channels(): number;
|
|
61
|
+
}
|
|
62
|
+
export interface TagLibModule extends Omit<EmscriptenModule, 'then'> {
|
|
63
|
+
FileHandle: new () => FileHandle;
|
|
64
|
+
TagWrapper: new () => TagWrapper;
|
|
65
|
+
AudioPropertiesWrapper: new () => AudioPropertiesWrapper;
|
|
66
|
+
createFileHandle(): FileHandle;
|
|
67
|
+
_taglib_file_new_from_buffer?(ptr: number, size: number): number;
|
|
68
|
+
_taglib_file_delete?(fileId: number): void;
|
|
69
|
+
_taglib_file_is_valid?(fileId: number): number;
|
|
70
|
+
_taglib_file_format?(fileId: number): number;
|
|
71
|
+
_taglib_file_tag?(fileId: number): number;
|
|
72
|
+
_taglib_file_audioproperties?(fileId: number): number;
|
|
73
|
+
_taglib_file_save?(fileId: number): number;
|
|
74
|
+
_taglib_tag_title?(tagPtr: number): number;
|
|
75
|
+
_taglib_tag_artist?(tagPtr: number): number;
|
|
76
|
+
_taglib_tag_album?(tagPtr: number): number;
|
|
77
|
+
_taglib_tag_comment?(tagPtr: number): number;
|
|
78
|
+
_taglib_tag_genre?(tagPtr: number): number;
|
|
79
|
+
_taglib_tag_year?(tagPtr: number): number;
|
|
80
|
+
_taglib_tag_track?(tagPtr: number): number;
|
|
81
|
+
_taglib_tag_set_title?(tagPtr: number, titlePtr: number): void;
|
|
82
|
+
_taglib_tag_set_artist?(tagPtr: number, artistPtr: number): void;
|
|
83
|
+
_taglib_tag_set_album?(tagPtr: number, albumPtr: number): void;
|
|
84
|
+
_taglib_tag_set_comment?(tagPtr: number, commentPtr: number): void;
|
|
85
|
+
_taglib_tag_set_genre?(tagPtr: number, genrePtr: number): void;
|
|
86
|
+
_taglib_tag_set_year?(tagPtr: number, year: number): void;
|
|
87
|
+
_taglib_tag_set_track?(tagPtr: number, track: number): void;
|
|
88
|
+
_taglib_audioproperties_length?(propsPtr: number): number;
|
|
89
|
+
_taglib_audioproperties_bitrate?(propsPtr: number): number;
|
|
90
|
+
_taglib_audioproperties_samplerate?(propsPtr: number): number;
|
|
91
|
+
_taglib_audioproperties_channels?(propsPtr: number): number;
|
|
92
|
+
}
|
|
93
|
+
export interface WasmModule extends EmscriptenModule {
|
|
94
|
+
FileHandle?: new () => FileHandle;
|
|
95
|
+
createFileHandle?(): FileHandle;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=wasm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../../src/wasm.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,MAAM,WAAW,gBAAgB;IAE/B,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,YAAY,CAAC;IAGtB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,KAAK,CAAC,CACJ,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EA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AAM,GAAG,MAAM,CAAC;IAC1D,+BAA+B,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3D,kCAAkC,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9D,gCAAgC,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7D;AAED,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAElD,UAAU,CAAC,EAAE,UAAU,UAAU,CAAC;IAClC,gBAAgB,CAAC,IAAI,UAAU,CAAC;CACjC"}
|
package/dist/src/wasm.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview WebAssembly module interface types for Emscripten
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Basic Emscripten module interface
|
|
6
|
+
export interface EmscriptenModule {
|
|
7
|
+
// Memory
|
|
8
|
+
HEAP8: Int8Array;
|
|
9
|
+
HEAP16: Int16Array;
|
|
10
|
+
HEAP32: Int32Array;
|
|
11
|
+
HEAPU8: Uint8Array;
|
|
12
|
+
HEAPU16: Uint16Array;
|
|
13
|
+
HEAPU32: Uint32Array;
|
|
14
|
+
HEAPF32: Float32Array;
|
|
15
|
+
HEAPF64: Float64Array;
|
|
16
|
+
|
|
17
|
+
// Memory management
|
|
18
|
+
_malloc(size: number): number;
|
|
19
|
+
_free(ptr: number): void;
|
|
20
|
+
allocate?(data: number[] | Uint8Array, allocator: number): number;
|
|
21
|
+
ALLOC_NORMAL?: number;
|
|
22
|
+
|
|
23
|
+
// String conversion
|
|
24
|
+
ccall?(
|
|
25
|
+
ident: string,
|
|
26
|
+
returnType: string,
|
|
27
|
+
argTypes: string[],
|
|
28
|
+
args: any[],
|
|
29
|
+
): any;
|
|
30
|
+
cwrap?(
|
|
31
|
+
ident: string,
|
|
32
|
+
returnType: string,
|
|
33
|
+
argTypes: string[],
|
|
34
|
+
): (...args: any[]) => any;
|
|
35
|
+
|
|
36
|
+
// File system (if enabled)
|
|
37
|
+
FS?: any;
|
|
38
|
+
|
|
39
|
+
// Runtime
|
|
40
|
+
then?(callback: (module: EmscriptenModule) => void): void;
|
|
41
|
+
onRuntimeInitialized?: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Embind class interfaces
|
|
45
|
+
export interface FileHandle {
|
|
46
|
+
loadFromBuffer(data: Uint8Array): boolean;
|
|
47
|
+
isValid(): boolean;
|
|
48
|
+
save(): boolean;
|
|
49
|
+
getFormat(): string;
|
|
50
|
+
getProperties(): any;
|
|
51
|
+
setProperties(props: any): void;
|
|
52
|
+
getProperty(key: string): string;
|
|
53
|
+
setProperty(key: string, value: string): void;
|
|
54
|
+
isMP4(): boolean;
|
|
55
|
+
getMP4Item(key: string): string;
|
|
56
|
+
setMP4Item(key: string, value: string): void;
|
|
57
|
+
removeMP4Item(key: string): void;
|
|
58
|
+
getTag(): TagWrapper;
|
|
59
|
+
getAudioProperties(): AudioPropertiesWrapper;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface TagWrapper {
|
|
63
|
+
title(): string;
|
|
64
|
+
artist(): string;
|
|
65
|
+
album(): string;
|
|
66
|
+
comment(): string;
|
|
67
|
+
genre(): string;
|
|
68
|
+
year(): number;
|
|
69
|
+
track(): number;
|
|
70
|
+
setTitle(value: string): void;
|
|
71
|
+
setArtist(value: string): void;
|
|
72
|
+
setAlbum(value: string): void;
|
|
73
|
+
setComment(value: string): void;
|
|
74
|
+
setGenre(value: string): void;
|
|
75
|
+
setYear(value: number): void;
|
|
76
|
+
setTrack(value: number): void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface AudioPropertiesWrapper {
|
|
80
|
+
lengthInSeconds(): number;
|
|
81
|
+
lengthInMilliseconds(): number;
|
|
82
|
+
bitrate(): number;
|
|
83
|
+
sampleRate(): number;
|
|
84
|
+
channels(): number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface TagLibModule extends Omit<EmscriptenModule, 'then'> {
|
|
88
|
+
// Embind classes
|
|
89
|
+
FileHandle: new () => FileHandle;
|
|
90
|
+
TagWrapper: new () => TagWrapper;
|
|
91
|
+
AudioPropertiesWrapper: new () => AudioPropertiesWrapper;
|
|
92
|
+
|
|
93
|
+
// Embind functions
|
|
94
|
+
createFileHandle(): FileHandle;
|
|
95
|
+
|
|
96
|
+
// C-style functions (optional - used by Workers API)
|
|
97
|
+
_taglib_file_new_from_buffer?(ptr: number, size: number): number;
|
|
98
|
+
_taglib_file_delete?(fileId: number): void;
|
|
99
|
+
_taglib_file_is_valid?(fileId: number): number;
|
|
100
|
+
_taglib_file_format?(fileId: number): number;
|
|
101
|
+
_taglib_file_tag?(fileId: number): number;
|
|
102
|
+
_taglib_file_audioproperties?(fileId: number): number;
|
|
103
|
+
_taglib_file_save?(fileId: number): number;
|
|
104
|
+
|
|
105
|
+
_taglib_tag_title?(tagPtr: number): number;
|
|
106
|
+
_taglib_tag_artist?(tagPtr: number): number;
|
|
107
|
+
_taglib_tag_album?(tagPtr: number): number;
|
|
108
|
+
_taglib_tag_comment?(tagPtr: number): number;
|
|
109
|
+
_taglib_tag_genre?(tagPtr: number): number;
|
|
110
|
+
_taglib_tag_year?(tagPtr: number): number;
|
|
111
|
+
_taglib_tag_track?(tagPtr: number): number;
|
|
112
|
+
|
|
113
|
+
_taglib_tag_set_title?(tagPtr: number, titlePtr: number): void;
|
|
114
|
+
_taglib_tag_set_artist?(tagPtr: number, artistPtr: number): void;
|
|
115
|
+
_taglib_tag_set_album?(tagPtr: number, albumPtr: number): void;
|
|
116
|
+
_taglib_tag_set_comment?(tagPtr: number, commentPtr: number): void;
|
|
117
|
+
_taglib_tag_set_genre?(tagPtr: number, genrePtr: number): void;
|
|
118
|
+
_taglib_tag_set_year?(tagPtr: number, year: number): void;
|
|
119
|
+
_taglib_tag_set_track?(tagPtr: number, track: number): void;
|
|
120
|
+
|
|
121
|
+
_taglib_audioproperties_length?(propsPtr: number): number;
|
|
122
|
+
_taglib_audioproperties_bitrate?(propsPtr: number): number;
|
|
123
|
+
_taglib_audioproperties_samplerate?(propsPtr: number): number;
|
|
124
|
+
_taglib_audioproperties_channels?(propsPtr: number): number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface WasmModule extends EmscriptenModule {
|
|
128
|
+
// Alias for compatibility
|
|
129
|
+
FileHandle?: new () => FileHandle;
|
|
130
|
+
createFileHandle?(): FileHandle;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Module loading function removed for modular imports
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Web browser utilities for working with cover art in taglib-wasm
|
|
3
|
+
*
|
|
4
|
+
* This module provides browser-specific helpers for integrating taglib-wasm
|
|
5
|
+
* with web applications, including canvas integration and data URL support.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { pictureToDataURL, setCoverArtFromCanvas } from "taglib-wasm/web-utils";
|
|
10
|
+
*
|
|
11
|
+
* // Display cover art in an <img> element
|
|
12
|
+
* const pictures = await readPictures("song.mp3");
|
|
13
|
+
* if (pictures.length > 0) {
|
|
14
|
+
* const dataURL = pictureToDataURL(pictures[0]);
|
|
15
|
+
* document.getElementById('cover').src = dataURL;
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Set cover art from a canvas
|
|
19
|
+
* const canvas = document.getElementById('myCanvas') as HTMLCanvasElement;
|
|
20
|
+
* const modifiedBuffer = await setCoverArtFromCanvas("song.mp3", canvas);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import type { Picture } from "./types.ts";
|
|
24
|
+
import { PictureType } from "./types.ts";
|
|
25
|
+
/**
|
|
26
|
+
* Convert a Picture object to a data URL for display in web browsers
|
|
27
|
+
*
|
|
28
|
+
* @param picture - Picture object from taglib-wasm
|
|
29
|
+
* @returns Data URL string that can be used as src for <img> elements
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const pictures = await readPictures("song.mp3");
|
|
34
|
+
* const imgElement = document.getElementById('coverArt') as HTMLImageElement;
|
|
35
|
+
* imgElement.src = pictureToDataURL(pictures[0]);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function pictureToDataURL(picture: Picture): string;
|
|
39
|
+
/**
|
|
40
|
+
* Convert a data URL to a Picture object
|
|
41
|
+
*
|
|
42
|
+
* @param dataURL - Data URL string (e.g., "data:image/jpeg;base64,...")
|
|
43
|
+
* @param type - Picture type (defaults to FrontCover)
|
|
44
|
+
* @param description - Optional description
|
|
45
|
+
* @returns Picture object
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const dataURL = canvas.toDataURL('image/jpeg');
|
|
50
|
+
* const picture = dataURLToPicture(dataURL, PictureType.FrontCover);
|
|
51
|
+
* const modifiedBuffer = await applyPictures("song.mp3", [picture]);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function dataURLToPicture(dataURL: string, type?: PictureType, description?: string): Picture;
|
|
55
|
+
/**
|
|
56
|
+
* Set cover art from an HTML canvas element
|
|
57
|
+
*
|
|
58
|
+
* @param file - File path, Uint8Array buffer, ArrayBuffer, or File object
|
|
59
|
+
* @param canvas - HTMLCanvasElement containing the image
|
|
60
|
+
* @param options - Options for image format and quality
|
|
61
|
+
* @returns Modified file buffer with cover art from canvas
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const canvas = document.getElementById('albumArt') as HTMLCanvasElement;
|
|
66
|
+
* const modifiedBuffer = await setCoverArtFromCanvas("song.mp3", canvas, {
|
|
67
|
+
* format: 'image/jpeg',
|
|
68
|
+
* quality: 0.9
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function setCoverArtFromCanvas(file: string | Uint8Array | ArrayBuffer | File, canvas: HTMLCanvasElement, options?: {
|
|
73
|
+
format?: 'image/jpeg' | 'image/png' | 'image/webp';
|
|
74
|
+
quality?: number;
|
|
75
|
+
type?: PictureType;
|
|
76
|
+
description?: string;
|
|
77
|
+
}): Promise<Uint8Array>;
|
|
78
|
+
/**
|
|
79
|
+
* Convert canvas to Picture object using blob for better performance
|
|
80
|
+
*
|
|
81
|
+
* This is more efficient than toDataURL for large images as it avoids
|
|
82
|
+
* the base64 encoding/decoding step.
|
|
83
|
+
*
|
|
84
|
+
* @param canvas - HTMLCanvasElement containing the image
|
|
85
|
+
* @param options - Options for image format and quality
|
|
86
|
+
* @returns Promise resolving to Picture object
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const canvas = document.getElementById('albumArt') as HTMLCanvasElement;
|
|
91
|
+
* const picture = await canvasToPicture(canvas, {
|
|
92
|
+
* format: 'image/png',
|
|
93
|
+
* type: PictureType.BackCover
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function canvasToPicture(canvas: HTMLCanvasElement, options?: {
|
|
98
|
+
format?: 'image/jpeg' | 'image/png' | 'image/webp';
|
|
99
|
+
quality?: number;
|
|
100
|
+
type?: PictureType;
|
|
101
|
+
description?: string;
|
|
102
|
+
}): Promise<Picture>;
|
|
103
|
+
/**
|
|
104
|
+
* Load an image file into a Picture object
|
|
105
|
+
*
|
|
106
|
+
* @param file - File object from <input type="file"> or drag-and-drop
|
|
107
|
+
* @param type - Picture type (defaults to FrontCover)
|
|
108
|
+
* @param description - Optional description
|
|
109
|
+
* @returns Promise resolving to Picture object
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // From file input
|
|
114
|
+
* const input = document.getElementById('fileInput') as HTMLInputElement;
|
|
115
|
+
* input.addEventListener('change', async (e) => {
|
|
116
|
+
* const file = e.target.files[0];
|
|
117
|
+
* const picture = await imageFileToPicture(file);
|
|
118
|
+
* const modifiedBuffer = await applyPictures("song.mp3", [picture]);
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function imageFileToPicture(file: File, type?: PictureType, description?: string): Promise<Picture>;
|
|
123
|
+
/**
|
|
124
|
+
* Display a Picture in an HTML img element
|
|
125
|
+
*
|
|
126
|
+
* @param picture - Picture object from taglib-wasm
|
|
127
|
+
* @param imgElement - HTMLImageElement to display the picture in
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const pictures = await readPictures("song.mp3");
|
|
132
|
+
* const img = document.getElementById('coverArt') as HTMLImageElement;
|
|
133
|
+
* displayPicture(pictures[0], img);
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function displayPicture(picture: Picture, imgElement: HTMLImageElement): void;
|
|
137
|
+
/**
|
|
138
|
+
* Create a download link for a Picture
|
|
139
|
+
*
|
|
140
|
+
* @param picture - Picture object to download
|
|
141
|
+
* @param filename - Suggested filename for download
|
|
142
|
+
* @returns Temporary download URL (remember to revoke it after use)
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const pictures = await readPictures("song.mp3");
|
|
147
|
+
* const downloadUrl = createPictureDownloadURL(pictures[0], "cover.jpg");
|
|
148
|
+
*
|
|
149
|
+
* const link = document.createElement('a');
|
|
150
|
+
* link.href = downloadUrl;
|
|
151
|
+
* link.download = "cover.jpg";
|
|
152
|
+
* link.click();
|
|
153
|
+
*
|
|
154
|
+
* // Clean up
|
|
155
|
+
* URL.revokeObjectURL(downloadUrl);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function createPictureDownloadURL(picture: Picture, filename?: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Extract all pictures and create a gallery
|
|
161
|
+
*
|
|
162
|
+
* @param file - Audio file to extract pictures from
|
|
163
|
+
* @param container - HTML element to append gallery items to
|
|
164
|
+
* @param options - Gallery display options
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const galleryDiv = document.getElementById('pictureGallery');
|
|
169
|
+
* await createPictureGallery("song.mp3", galleryDiv, {
|
|
170
|
+
* className: 'album-art',
|
|
171
|
+
* includeDescription: true
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export declare function createPictureGallery(file: string | Uint8Array | ArrayBuffer | File, container: HTMLElement, options?: {
|
|
176
|
+
className?: string;
|
|
177
|
+
includeDescription?: boolean;
|
|
178
|
+
onClick?: (picture: Picture, index: number) => void;
|
|
179
|
+
}): Promise<void>;
|
|
180
|
+
//# sourceMappingURL=web-utils.d.ts.map
|