facebetter 1.0.9 → 1.0.10

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/lib/index.js CHANGED
@@ -1,19 +1,9 @@
1
1
  /**
2
2
  * Node.js CommonJS Entry Point
3
3
  * For require() usage in Node.js
4
+ * Uses facebetter-core npm package for WASM module
4
5
  */
5
6
 
6
- const { readFileSync } = require('fs');
7
- const { join, dirname, resolve } = require('path');
8
-
9
- // Get __dirname equivalent
10
- const __filename = require.resolve('./index.js');
11
- const __dirname = dirname(__filename);
12
-
13
- // WASM files directory - in package dist/ folder
14
- // src/engine/web/lib -> src/engine/web -> dist
15
- const wasmBinDir = resolve(__dirname, '../dist');
16
-
17
7
  // Import ESM module (Node.js 12+ supports import() for CommonJS)
18
8
  let wasmModuleInstance = null;
19
9
  let wasmModulePromise = null;
@@ -29,31 +19,37 @@ async function loadWasmModule(options = {}) {
29
19
 
30
20
  wasmModulePromise = (async () => {
31
21
  try {
32
- // Resolve WASM file paths (use project root directory)
33
- const wasmPath = options.wasmPath || join(wasmBinDir, 'facebetter.wasm');
34
- const wasmJsPath = join(wasmBinDir, 'facebetter_wasm.js');
22
+ let FaceBetterModuleFactory;
35
23
 
36
- // Read WASM binary synchronously
37
- const wasmBinary = readFileSync(wasmPath);
24
+ if (options.wasmPath) {
25
+ // If custom path is provided, use it (for backward compatibility or custom builds)
26
+ const module = await import(options.wasmPath);
27
+ FaceBetterModuleFactory = module.default || module;
28
+ } else {
29
+ // Import from facebetter-core npm package
30
+ const module = await import('facebetter-core');
31
+ FaceBetterModuleFactory = module.default || module.createFaceBetterModule;
32
+ }
38
33
 
39
- // Import the WASM module factory (dynamic import)
40
- const module = await import(wasmJsPath);
41
- const FaceBetterModuleFactory = module.default || module;
34
+ if (!FaceBetterModuleFactory) {
35
+ throw new Error('WASM module does not export createFaceBetterModule function');
36
+ }
42
37
 
43
38
  // Initialize the module
39
+ // With SINGLE_FILE=1, WASM binary and data are embedded in the JS file
44
40
  wasmModuleInstance = await FaceBetterModuleFactory({
45
- wasmBinary,
46
41
  locateFile: (path) => {
47
- if (path.endsWith('.wasm')) {
48
- return wasmPath;
49
- }
50
- if (path.endsWith('.data')) {
51
- return join(wasmBinDir, 'facebetter_wasm.data');
52
- }
42
+ // With SINGLE_FILE=1, Emscripten handles embedded files automatically
43
+ // Custom locateFile is only needed if user provides one
53
44
  return path;
54
- }
45
+ },
46
+ ...options
55
47
  });
56
48
 
49
+ if (!wasmModuleInstance) {
50
+ throw new Error('Failed to initialize WASM module');
51
+ }
52
+
57
53
  wasmModuleInstance.ready = true;
58
54
  return wasmModuleInstance;
59
55
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "facebetter",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
5
  "description": "Face beauty effects SDK with WebAssembly support",
6
6
  "main": "lib/index.js",
@@ -19,8 +19,7 @@
19
19
  "import": "./dist/facebetter.esm.js",
20
20
  "require": "./lib/index.js",
21
21
  "default": "./dist/facebetter.js"
22
- },
23
- "./wasm.js": "./dist/facebetter_wasm.js"
22
+ }
24
23
  },
25
24
  "scripts": {
26
25
  "build": "rollup -c",
@@ -40,6 +39,9 @@
40
39
  ],
41
40
  "author": "",
42
41
  "license": "MIT",
42
+ "dependencies": {
43
+ "facebetter-core": "^1.0.0"
44
+ },
43
45
  "devDependencies": {
44
46
  "@rollup/plugin-commonjs": "^25.0.0",
45
47
  "@rollup/plugin-node-resolve": "^15.0.0",
package/README.md DELETED
@@ -1,167 +0,0 @@
1
- # Facebetter
2
-
3
- Face beauty effects SDK with WebAssembly support. Works in browsers, Node.js, and Electron.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install facebetter
9
- ```
10
-
11
- ## Usage
12
-
13
- ### Browser (`<script>` tag)
14
-
15
- ```html
16
- <script src="node_modules/facebetter/dist/facebetter.js"></script>
17
- <script>
18
- const { BeautyEffectEngine, EngineConfig } = Facebetter;
19
-
20
- const config = new EngineConfig({
21
- appId: 'your-app-id',
22
- appKey: 'your-app-key'
23
- });
24
-
25
- const engine = new BeautyEffectEngine(config);
26
-
27
- await engine.init();
28
-
29
- // Process image
30
- const canvas = document.getElementById('myCanvas');
31
- const processed = engine.processImage(canvas);
32
-
33
- // Draw result
34
- const ctx = canvas.getContext('2d');
35
- ctx.putImageData(processed, 0, 0);
36
- </script>
37
- ```
38
-
39
- ### Vue / React / Vite / Webpack (ES Module)
40
-
41
- ```javascript
42
- import { BeautyEffectEngine, EngineConfig } from 'facebetter';
43
-
44
- const config = new EngineConfig({
45
- appId: 'your-app-id',
46
- appKey: 'your-app-key'
47
- });
48
-
49
- const engine = new BeautyEffectEngine(config);
50
- await engine.init();
51
-
52
- // Process image
53
- const canvas = document.getElementById('myCanvas');
54
- const processed = engine.processImage(canvas);
55
- ```
56
-
57
- **Note for Webpack 5**: Add to `webpack.config.js`:
58
- ```javascript
59
- experiments: {
60
- asyncWebAssembly: true
61
- }
62
- ```
63
-
64
- ### Node.js / Electron Main Process
65
-
66
- ```javascript
67
- // ESM
68
- import { BeautyEffectEngine, EngineConfig } from 'facebetter';
69
-
70
- // Or CommonJS
71
- const { getFacebetter } = require('facebetter');
72
- const { BeautyEffectEngine, EngineConfig } = await getFacebetter();
73
-
74
- const config = new EngineConfig({
75
- licenseJson: '{"your": "license", "json": "here"}' // Must provide licenseJson in Node.js
76
- });
77
-
78
- const engine = new BeautyEffectEngine(config);
79
- await engine.init();
80
-
81
- // Process image (use Uint8ClampedArray or Buffer)
82
- const imageData = new Uint8ClampedArray(width * height * 4);
83
- const processed = engine.processImage(imageData, width, height);
84
- ```
85
-
86
- ## API
87
-
88
- ### EngineConfig
89
-
90
- ```javascript
91
- const config = new EngineConfig({
92
- appId: 'your-app-id', // Required if licenseJson not provided
93
- appKey: 'your-app-key', // Required if licenseJson not provided
94
- licenseJson: '{"..."}' // Optional, if provided appId/appKey not needed
95
- });
96
- ```
97
-
98
- ### BeautyEffectEngine
99
-
100
- ```javascript
101
- const engine = new BeautyEffectEngine(config);
102
-
103
- // Initialize
104
- await engine.init();
105
-
106
- // Set beauty parameters
107
- engine.setBasicParam(BasicParam.Whitening, 0.5);
108
- engine.setReshapeParam(ReshapeParam.FaceThin, 0.3);
109
- engine.setMakeupParam(MakeupParam.Lipstick, 0.4);
110
-
111
- // Process image
112
- const processed = engine.processImage(inputImage);
113
-
114
- // Cleanup
115
- engine.destroy();
116
- ```
117
-
118
- ## Constants
119
-
120
- - `BeautyType`: Basic, Reshape, Makeup, Segmentation
121
- - `BasicParam`: Smoothing, Sharpening, Whitening, Rosiness
122
- - `ReshapeParam`: FaceThin, FaceVShape, EyeSize, etc.
123
- - `MakeupParam`: Lipstick, Blush
124
- - `BackgroundMode`: None, Blur, Image
125
- - `ProcessMode`: Image, Video
126
-
127
- ## Building
128
-
129
- ### Prerequisites
130
-
131
- Before building, ensure you have the C++ build artifacts. When using CMake install, WASM files will be automatically installed to `src/engine/web/dist/`. Otherwise, you need to manually place them there:
132
-
133
- ```
134
- src/engine/web/dist/
135
- ├── facebetter_wasm.js # C++ build artifact (must exist before build)
136
- ├── facebetter_wasm.wasm # C++ build artifact (must exist before build)
137
- └── facebetter_wasm.data # C++ build artifact (must exist before build)
138
- ```
139
-
140
- **Note**: When using `cmake --install`, WASM files are automatically installed to `src/engine/web/dist/`. If building manually, ensure WASM files are in `src/engine/web/dist/` before running `npm run build`.
141
-
142
- ### Build Steps
143
-
144
- ```bash
145
- # 1. Install dependencies
146
- npm install
147
-
148
- # 2. Build all formats
149
- npm run build
150
-
151
- # 3. Build production version (with minification)
152
- npm run build:prod
153
-
154
- # 4. Build development version (with sourcemap)
155
- npm run build:dev
156
- ```
157
-
158
- The build process will:
159
- 1. Build UMD version (`src/engine/web/dist/facebetter.js`) for browser `<script>` tags
160
- 2. Build ESM version (`src/engine/web/dist/facebetter.esm.js`) for Vue/React/Vite
161
-
162
- **Output directory**: All build artifacts are generated in `src/engine/web/dist/` directory, ready for npm publish.
163
-
164
- ## License
165
-
166
- MIT
167
-