facebetter 1.4.6 → 1.4.7

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/README.md CHANGED
@@ -127,6 +127,8 @@ processFrame();
127
127
  | `setBasicParam(param, value)` | Adjust skin retouching settings (Smoothing, Whitening, etc.). |
128
128
  | `setReshapeParam(param, value)` | Adjust face reshaping settings (Thinning, Eye Size, etc.). |
129
129
  | `setMakeupParam(param, value)` | Adjust makeup intensity (Lipstick, Blush, etc.). |
130
+ | `setLipstickStyle(style)` | Switch lipstick style (Rouge / Coral / Pink). |
131
+ | `setBlushStyle(style)` | Switch blush style (Classic / Peach / Rose). |
130
132
  | `setFilter(path, intensity)` | Apply a LUT filter with custom intensity. |
131
133
  | `setVirtualBackground(options)` | Configure background blur or image replacement. |
132
134
  | `processImage(source)` | Process an input source (Image, Video, Canvas, or ImageData). |
@@ -134,6 +134,24 @@ const MakeupParam$1 = {
134
134
  Blush: 1 // Blush intensity (0.0: none, 1.0: maximum)
135
135
  };
136
136
 
137
+ /**
138
+ * Lipstick style types
139
+ */
140
+ const LipstickStyle$1 = {
141
+ Rouge: 0, // Rose red
142
+ Coral: 1, // Coral
143
+ Pink: 2 // Pink
144
+ };
145
+
146
+ /**
147
+ * Blush style types
148
+ */
149
+ const BlushStyle$1 = {
150
+ Classic: 0, // Classic
151
+ Peach: 1, // Peach
152
+ Rose: 2 // Rose
153
+ };
154
+
137
155
  /**
138
156
  * Chroma Key parameter enumeration
139
157
  */
@@ -204,127 +222,16 @@ var constants = /*#__PURE__*/Object.freeze({
204
222
  BackgroundMode: BackgroundMode$1,
205
223
  BasicParam: BasicParam$1,
206
224
  BeautyType: BeautyType$1,
225
+ BlushStyle: BlushStyle$1,
207
226
  ChromaKeyParam: ChromaKeyParam$1,
208
227
  FrameType: FrameType$1,
228
+ LipstickStyle: LipstickStyle$1,
209
229
  MakeupParam: MakeupParam$1,
210
230
  MirrorMode: MirrorMode$1,
211
231
  ReshapeParam: ReshapeParam$1,
212
232
  VirtualBackgroundOptions: VirtualBackgroundOptions$1
213
233
  });
214
234
 
215
- /**
216
- * Browser localStorage cache for online license JSON (WASM path).
217
- * Aligns with native: full server response body, TTL from response.timestamp (seconds).
218
- */
219
-
220
- /** @type {number} Same semantics as C++ kOnlineLicenseCacheTtlSecs */
221
- const ONLINE_LICENSE_CACHE_TTL_SEC = 7 * 24 * 3600;
222
-
223
- const STORAGE_PREFIX = 'facebetter.onlineLicense.v1:';
224
-
225
- /**
226
- * @returns {boolean}
227
- */
228
- function isLocalStorageAvailable() {
229
- try {
230
- if (typeof globalThis.localStorage === 'undefined') {
231
- return false;
232
- }
233
- const k = '__fb_ls_test__';
234
- globalThis.localStorage.setItem(k, '1');
235
- globalThis.localStorage.removeItem(k);
236
- return true;
237
- } catch {
238
- return false;
239
- }
240
- }
241
-
242
- /**
243
- * @param {string} appId
244
- * @returns {string}
245
- */
246
- function storageKey(appId) {
247
- return `${STORAGE_PREFIX}${appId}`;
248
- }
249
-
250
- /**
251
- * @param {string} responseText
252
- * @param {string} expectedAppId
253
- * @returns {{ ok: boolean, ts: number } | null}
254
- */
255
- function parseAndValidateResponse(responseText, expectedAppId) {
256
- try {
257
- const o = JSON.parse(responseText);
258
- if (!o || typeof o !== 'object') {
259
- return null;
260
- }
261
- if (o.success !== true) {
262
- return null;
263
- }
264
- if (typeof o.app_id !== 'string' || o.app_id !== expectedAppId) {
265
- return null;
266
- }
267
- if (typeof o.timestamp !== 'number' || !Number.isFinite(o.timestamp)) {
268
- return null;
269
- }
270
- return { ok: true, ts: o.timestamp };
271
- } catch {
272
- return null;
273
- }
274
- }
275
-
276
- /**
277
- * Returns cached raw response body if still within TTL, else null.
278
- * @param {string} appId
279
- * @returns {string | null}
280
- */
281
- function readOnlineLicenseCache(appId) {
282
- if (!appId || !isLocalStorageAvailable()) {
283
- return null;
284
- }
285
- let raw;
286
- try {
287
- raw = globalThis.localStorage.getItem(storageKey(appId));
288
- } catch {
289
- return null;
290
- }
291
- if (!raw || typeof raw !== 'string') {
292
- return null;
293
- }
294
- const meta = parseAndValidateResponse(raw, appId);
295
- if (!meta) {
296
- return null;
297
- }
298
- const nowSec = Math.floor(Date.now() / 1000);
299
- const ts = meta.ts;
300
- const ageSec = ts <= nowSec ? nowSec - ts : 0;
301
- if (ageSec > ONLINE_LICENSE_CACHE_TTL_SEC) {
302
- return null;
303
- }
304
- return raw;
305
- }
306
-
307
- /**
308
- * Persists successful auth response; no-op if storage unavailable or payload invalid.
309
- * @param {string} appId
310
- * @param {string} responseText
311
- * @returns {boolean}
312
- */
313
- function writeOnlineLicenseCache(appId, responseText) {
314
- if (!appId || !isLocalStorageAvailable() || typeof responseText !== 'string') {
315
- return false;
316
- }
317
- if (!parseAndValidateResponse(responseText, appId)) {
318
- return false;
319
- }
320
- try {
321
- globalThis.localStorage.setItem(storageKey(appId), responseText);
322
- return true;
323
- } catch {
324
- return false;
325
- }
326
- }
327
-
328
235
  /**
329
236
  * Browser-side console lines aligned with C++ Logger (src/base/logging.cc) Release pattern:
330
237
  * [%Y-%m-%d %H:%M:%S.%e] [facebetter] [%l] [%t] - %v
@@ -555,32 +462,9 @@ class BeautyEffectEngine {
555
462
  };
556
463
  }
557
464
 
558
- // Setup online auth proxy for WASM (localStorage cache + fetch, same TTL as native).
559
- // 返回 { response, fromCache } 供 WASM 桥区分:仅 fromCache===true 时 C++ 跳过 5 分钟防重放。
465
+ // Setup online auth proxy for WASM(纯在线,失败不回退本地缓存)。
560
466
  if (!Module.onOnlineAuth) {
561
467
  Module.onOnlineAuth = async (payloadJson) => {
562
- let appId = '';
563
- try {
564
- const p = JSON.parse(payloadJson);
565
- if (p && typeof p.app_id === 'string') {
566
- appId = p.app_id;
567
- }
568
- } catch {
569
- // ignore malformed payload
570
- }
571
-
572
- const authResult = (body, fromCache) =>
573
- body ? { response: body, fromCache } : '';
574
-
575
- const cached = appId ? readOnlineLicenseCache(appId) : null;
576
- if (cached) {
577
- // 与 C++ 中「disk cache」对应;WASM 侧日志仍显示 online,以这里为准区分是否发 HTTP
578
- logInfo(
579
- 'Online license: localStorage cache hit (no auth HTTP)'
580
- );
581
- return authResult(cached, true);
582
- }
583
-
584
468
  const authUrl = 'https://facebetter.pixpark.net/facebetter/v1/auth';
585
469
  logInfo('Online license: requesting auth server');
586
470
  try {
@@ -592,34 +476,17 @@ class BeautyEffectEngine {
592
476
  body: payloadJson,
593
477
  });
594
478
  if (!response.ok) {
595
- const fallback = appId ? readOnlineLicenseCache(appId) : null;
596
- if (fallback) {
597
- logInfo(
598
- `Online license: using cache after HTTP error (status ${response.status})`
599
- );
600
- } else {
601
- logWarn(
602
- `Online license: HTTP ${response.status}, no cache`
603
- );
604
- }
605
- return authResult(fallback, true);
479
+ logWarn(`Online license: HTTP ${response.status}`);
480
+ return '';
606
481
  }
607
482
  const text = await response.text();
608
- if (appId && text) {
609
- writeOnlineLicenseCache(appId, text);
610
- }
611
- logInfo(
612
- 'Online license: server response ok, cache updated'
483
+ logInfo('Online license: server response ok');
484
+ return text;
485
+ } catch (err) {
486
+ logWarn(
487
+ `Online license: network error${err?.message ? `: ${err.message}` : ''}`
613
488
  );
614
- return authResult(text, false);
615
- } catch {
616
- const fallback = appId ? readOnlineLicenseCache(appId) : null;
617
- if (fallback) {
618
- logInfo(
619
- 'Online license: using cache after network error'
620
- );
621
- }
622
- return authResult(fallback, true);
489
+ return '';
623
490
  }
624
491
  };
625
492
  }
@@ -832,6 +699,38 @@ class BeautyEffectEngine {
832
699
  this._setBeautyParam('SetBeautyParamMakeup', param, value);
833
700
  }
834
701
 
702
+ /**
703
+ * Sets lipstick style/texture
704
+ * @param {number} style - Style (use LipstickStyle enum, e.g., LipstickStyle.Rouge)
705
+ */
706
+ setLipstickStyle(style) {
707
+ this._ensureInitialized();
708
+ const Module = this._getWasmModule();
709
+ const result = Module.ccall(
710
+ 'SetLipstickStyle',
711
+ 'number',
712
+ ['number', 'number'],
713
+ [this.enginePtr, style]
714
+ );
715
+ checkResult(result, 'Failed to set lipstick style');
716
+ }
717
+
718
+ /**
719
+ * Sets blush style/texture
720
+ * @param {number} style - Style (use BlushStyle enum, e.g., BlushStyle.Classic)
721
+ */
722
+ setBlushStyle(style) {
723
+ this._ensureInitialized();
724
+ const Module = this._getWasmModule();
725
+ const result = Module.ccall(
726
+ 'SetBlushStyle',
727
+ 'number',
728
+ ['number', 'number'],
729
+ [this.enginePtr, style]
730
+ );
731
+ checkResult(result, 'Failed to set blush style');
732
+ }
733
+
835
734
  /**
836
735
  * Sets chroma key parameter
837
736
  * @param {number} param - Parameter (use ChromaKeyParam enum, e.g., ChromaKeyParam.Similarity)
@@ -1728,6 +1627,8 @@ const BeautyType = BeautyType$1;
1728
1627
  const BasicParam = BasicParam$1;
1729
1628
  const ReshapeParam = ReshapeParam$1;
1730
1629
  const MakeupParam = MakeupParam$1;
1630
+ const LipstickStyle = LipstickStyle$1;
1631
+ const BlushStyle = BlushStyle$1;
1731
1632
  const ChromaKeyParam = ChromaKeyParam$1;
1732
1633
  const BackgroundMode = BackgroundMode$1;
1733
1634
  const FrameType = FrameType$1;
@@ -1743,5 +1644,5 @@ var index = {
1743
1644
  loadWasmModule
1744
1645
  };
1745
1646
 
1746
- export { BackgroundMode, BasicParam, ESMBeautyEffectEngine as BeautyEffectEngine, BeautyType, ChromaKeyParam, EngineConfig, FacebetterError, FrameType, MakeupParam, MirrorMode, ReshapeParam, VirtualBackgroundOptions, createBeautyEffectEngine, index as default, getWasmBuffer, getWasmModule, loadWasmModule };
1647
+ export { BackgroundMode, BasicParam, ESMBeautyEffectEngine as BeautyEffectEngine, BeautyType, BlushStyle, ChromaKeyParam, EngineConfig, FacebetterError, FrameType, LipstickStyle, MakeupParam, MirrorMode, ReshapeParam, VirtualBackgroundOptions, createBeautyEffectEngine, index as default, getWasmBuffer, getWasmModule, loadWasmModule };
1747
1648
  //# sourceMappingURL=facebetter.esm.js.map