facebetter 1.0.7 → 1.0.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/dist/facebetter.esm.js +32 -128
- package/dist/facebetter.esm.js.map +1 -1
- package/dist/facebetter.js +45 -66
- package/dist/facebetter.js.map +1 -1
- package/dist/facebetter_wasm.js +14 -1
- package/lib/index.js +38 -153
- package/package.json +1 -2
- package/dist/facebetter_wasm.data +0 -0
- package/dist/facebetter_wasm.wasm +0 -0
package/lib/index.js
CHANGED
|
@@ -1,54 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Node.js Entry Point
|
|
3
|
-
* For Node.js
|
|
4
|
-
* Uses fs.readFileSync for synchronous WASM loading
|
|
2
|
+
* Node.js CommonJS Entry Point
|
|
3
|
+
* For require() usage in Node.js
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
import { BeautyEffectEngine } from '../core/engine.js';
|
|
11
|
-
import { EngineConfig } from '../core/config.js';
|
|
12
|
-
import { FacebetterError } from '../core/errors.js';
|
|
13
|
-
import * as constants from '../core/constants.js';
|
|
6
|
+
const { readFileSync } = require('fs');
|
|
7
|
+
const { join, dirname, resolve } = require('path');
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
// Get __dirname equivalent
|
|
10
|
+
const __filename = require.resolve('./index.js');
|
|
16
11
|
const __dirname = dirname(__filename);
|
|
17
12
|
|
|
18
13
|
// WASM files directory - in package dist/ folder
|
|
19
|
-
// src/engine/web/
|
|
20
|
-
const wasmBinDir = resolve(__dirname, '
|
|
14
|
+
// src/engine/web/lib -> src/engine/web -> dist
|
|
15
|
+
const wasmBinDir = resolve(__dirname, '../dist');
|
|
21
16
|
|
|
22
|
-
// Node.js
|
|
17
|
+
// Import ESM module (Node.js 12+ supports import() for CommonJS)
|
|
23
18
|
let wasmModuleInstance = null;
|
|
24
19
|
let wasmModulePromise = null;
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
* Gets the base path of the current module
|
|
28
|
-
* Node.js equivalent of __dirname
|
|
29
|
-
* @returns {string} Base path of the current module
|
|
30
|
-
*/
|
|
31
|
-
function getModuleBasePath() {
|
|
32
|
-
return __dirname;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Resolves a relative path to absolute path (Node.js version)
|
|
37
|
-
* @param {string} relativePath - Relative path
|
|
38
|
-
* @returns {string} Absolute path
|
|
39
|
-
*/
|
|
40
|
-
function resolvePath(relativePath) {
|
|
41
|
-
return join(__dirname, relativePath);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Loads the WebAssembly module (Node.js version)
|
|
46
|
-
* Uses fs.readFileSync for synchronous loading
|
|
47
|
-
* @param {Object} [options] - Options
|
|
48
|
-
* @param {string} [options.wasmPath] - Custom WASM path (auto-detected if not provided)
|
|
49
|
-
* @returns {Promise<Object>} Promise that resolves with the WASM module
|
|
50
|
-
*/
|
|
51
|
-
export async function loadWasmModule(options = {}) {
|
|
21
|
+
async function loadWasmModule(options = {}) {
|
|
52
22
|
if (wasmModuleInstance) {
|
|
53
23
|
return wasmModuleInstance;
|
|
54
24
|
}
|
|
@@ -66,13 +36,13 @@ export async function loadWasmModule(options = {}) {
|
|
|
66
36
|
// Read WASM binary synchronously
|
|
67
37
|
const wasmBinary = readFileSync(wasmPath);
|
|
68
38
|
|
|
69
|
-
// Import the WASM module factory
|
|
39
|
+
// Import the WASM module factory (dynamic import)
|
|
70
40
|
const module = await import(wasmJsPath);
|
|
71
41
|
const FaceBetterModuleFactory = module.default || module;
|
|
72
42
|
|
|
73
|
-
// Initialize the module
|
|
43
|
+
// Initialize the module
|
|
74
44
|
wasmModuleInstance = await FaceBetterModuleFactory({
|
|
75
|
-
wasmBinary,
|
|
45
|
+
wasmBinary,
|
|
76
46
|
locateFile: (path) => {
|
|
77
47
|
if (path.endsWith('.wasm')) {
|
|
78
48
|
return wasmPath;
|
|
@@ -84,130 +54,45 @@ export async function loadWasmModule(options = {}) {
|
|
|
84
54
|
}
|
|
85
55
|
});
|
|
86
56
|
|
|
87
|
-
if (!wasmModuleInstance) {
|
|
88
|
-
throw new FacebetterError('Failed to initialize WASM module');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
57
|
wasmModuleInstance.ready = true;
|
|
92
58
|
return wasmModuleInstance;
|
|
93
59
|
} catch (e) {
|
|
94
|
-
throw new
|
|
60
|
+
throw new Error(`Failed to load WASM module: ${e.message}`);
|
|
95
61
|
}
|
|
96
62
|
})();
|
|
97
63
|
|
|
98
64
|
return wasmModulePromise;
|
|
99
65
|
}
|
|
100
66
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
export function getWasmModule() {
|
|
107
|
-
if (!wasmModuleInstance) {
|
|
108
|
-
throw new Error('WASM module not loaded. Call loadWasmModule() first or use BeautyEffectEngine.init()');
|
|
109
|
-
}
|
|
110
|
-
return wasmModuleInstance;
|
|
67
|
+
// Re-export from ESM module
|
|
68
|
+
async function getExports() {
|
|
69
|
+
// Import the ESM version
|
|
70
|
+
const esmModule = await import('../src/node/index.js');
|
|
71
|
+
return esmModule;
|
|
111
72
|
}
|
|
112
73
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*/
|
|
117
|
-
export function getWasmBuffer() {
|
|
118
|
-
const Module = getWasmModule();
|
|
119
|
-
|
|
120
|
-
if (Module.buffer) {
|
|
121
|
-
return Module.buffer;
|
|
122
|
-
} else if (Module.HEAPU8 && Module.HEAPU8.buffer) {
|
|
123
|
-
return Module.HEAPU8.buffer;
|
|
124
|
-
} else if (Module.asm && Module.asm.memory) {
|
|
125
|
-
return Module.asm.memory.buffer;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
throw new Error('Unable to access WASM memory buffer');
|
|
129
|
-
}
|
|
74
|
+
// For CommonJS, we need to export a promise or use async exports
|
|
75
|
+
// This is a limitation - Node.js CommonJS doesn't support async exports well
|
|
76
|
+
// Users should use the ESM version or await the exports
|
|
130
77
|
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
throw new FacebetterError('Width and height are required for Node.js');
|
|
138
|
-
}
|
|
139
|
-
// Create a simple object that mimics ImageData
|
|
140
|
-
return {
|
|
141
|
-
data: source,
|
|
142
|
-
width,
|
|
143
|
-
height
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (Buffer.isBuffer(source)) {
|
|
148
|
-
if (width === undefined || height === undefined) {
|
|
149
|
-
throw new FacebetterError('Width and height are required for Node.js');
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
data: new Uint8ClampedArray(source),
|
|
153
|
-
width,
|
|
154
|
-
height
|
|
155
|
-
};
|
|
156
|
-
}
|
|
78
|
+
module.exports = {
|
|
79
|
+
// Export a function that returns the actual exports
|
|
80
|
+
async getFacebetter() {
|
|
81
|
+
const exports = await getExports();
|
|
82
|
+
return exports;
|
|
83
|
+
},
|
|
157
84
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// Node.js doesn't support online auth (no fetch in older versions)
|
|
162
|
-
// Users should provide licenseJson directly
|
|
163
|
-
async function verifyAppKeyOnline(appId, appKey) {
|
|
164
|
-
throw new FacebetterError('Online authentication is not supported in Node.js. Please provide licenseJson directly.');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// No GPU canvas in Node.js
|
|
168
|
-
function ensureGPUPixelCanvas() {
|
|
169
|
-
// No-op for Node.js
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function cleanupGPUPixelCanvas() {
|
|
173
|
-
// No-op for Node.js
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Create platform API
|
|
177
|
-
const platformAPI = {
|
|
178
|
-
loadWasmModule: () => loadWasmModule(),
|
|
179
|
-
getWasmModule,
|
|
180
|
-
getWasmBuffer,
|
|
181
|
-
toImageData,
|
|
182
|
-
verifyAppKeyOnline,
|
|
183
|
-
ensureGPUPixelCanvas,
|
|
184
|
-
cleanupGPUPixelCanvas
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// Export factory function
|
|
188
|
-
export function createBeautyEffectEngine(config) {
|
|
189
|
-
return new BeautyEffectEngine(config, platformAPI);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Export all constants and classes
|
|
193
|
-
export {
|
|
194
|
-
BeautyEffectEngine,
|
|
195
|
-
EngineConfig,
|
|
196
|
-
FacebetterError,
|
|
197
|
-
BeautyType: constants.BeautyType,
|
|
198
|
-
BasicParam: constants.BasicParam,
|
|
199
|
-
ReshapeParam: constants.ReshapeParam,
|
|
200
|
-
MakeupParam: constants.MakeupParam,
|
|
201
|
-
BackgroundMode: constants.BackgroundMode,
|
|
202
|
-
ProcessMode: constants.ProcessMode
|
|
85
|
+
// Export loadWasmModule
|
|
86
|
+
loadWasmModule
|
|
203
87
|
};
|
|
204
88
|
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
89
|
+
// Also try to export synchronously (may not work if module needs async init)
|
|
90
|
+
// This is a workaround for CommonJS compatibility
|
|
91
|
+
let cachedExports = null;
|
|
92
|
+
module.exports.getSync = () => {
|
|
93
|
+
if (!cachedExports) {
|
|
94
|
+
throw new Error('Module not initialized. Use getFacebetter() or loadWasmModule() first.');
|
|
95
|
+
}
|
|
96
|
+
return cachedExports;
|
|
212
97
|
};
|
|
213
98
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "facebetter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Face beauty effects SDK with WebAssembly support",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"require": "./lib/index.js",
|
|
21
21
|
"default": "./dist/facebetter.js"
|
|
22
22
|
},
|
|
23
|
-
"./wasm": "./dist/facebetter.wasm",
|
|
24
23
|
"./wasm.js": "./dist/facebetter_wasm.js"
|
|
25
24
|
},
|
|
26
25
|
"scripts": {
|
|
Binary file
|
|
Binary file
|