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 +2 -0
- package/dist/facebetter.esm.js +64 -163
- package/dist/facebetter.esm.js.map +1 -1
- package/dist/facebetter.js +65 -162
- package/dist/facebetter.js.map +1 -1
- package/package.json +2 -2
package/dist/facebetter.js
CHANGED
|
@@ -140,6 +140,24 @@
|
|
|
140
140
|
Blush: 1 // Blush intensity (0.0: none, 1.0: maximum)
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Lipstick style types
|
|
145
|
+
*/
|
|
146
|
+
const LipstickStyle$1 = {
|
|
147
|
+
Rouge: 0, // Rose red
|
|
148
|
+
Coral: 1, // Coral
|
|
149
|
+
Pink: 2 // Pink
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Blush style types
|
|
154
|
+
*/
|
|
155
|
+
const BlushStyle$1 = {
|
|
156
|
+
Classic: 0, // Classic
|
|
157
|
+
Peach: 1, // Peach
|
|
158
|
+
Rose: 2 // Rose
|
|
159
|
+
};
|
|
160
|
+
|
|
143
161
|
/**
|
|
144
162
|
* Chroma Key parameter enumeration
|
|
145
163
|
*/
|
|
@@ -210,127 +228,16 @@
|
|
|
210
228
|
BackgroundMode: BackgroundMode$1,
|
|
211
229
|
BasicParam: BasicParam$1,
|
|
212
230
|
BeautyType: BeautyType$1,
|
|
231
|
+
BlushStyle: BlushStyle$1,
|
|
213
232
|
ChromaKeyParam: ChromaKeyParam,
|
|
214
233
|
FrameType: FrameType$1,
|
|
234
|
+
LipstickStyle: LipstickStyle$1,
|
|
215
235
|
MakeupParam: MakeupParam$1,
|
|
216
236
|
MirrorMode: MirrorMode$1,
|
|
217
237
|
ReshapeParam: ReshapeParam$1,
|
|
218
238
|
VirtualBackgroundOptions: VirtualBackgroundOptions$1
|
|
219
239
|
});
|
|
220
240
|
|
|
221
|
-
/**
|
|
222
|
-
* Browser localStorage cache for online license JSON (WASM path).
|
|
223
|
-
* Aligns with native: full server response body, TTL from response.timestamp (seconds).
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
/** @type {number} Same semantics as C++ kOnlineLicenseCacheTtlSecs */
|
|
227
|
-
const ONLINE_LICENSE_CACHE_TTL_SEC = 7 * 24 * 3600;
|
|
228
|
-
|
|
229
|
-
const STORAGE_PREFIX = 'facebetter.onlineLicense.v1:';
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @returns {boolean}
|
|
233
|
-
*/
|
|
234
|
-
function isLocalStorageAvailable() {
|
|
235
|
-
try {
|
|
236
|
-
if (typeof globalThis.localStorage === 'undefined') {
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
const k = '__fb_ls_test__';
|
|
240
|
-
globalThis.localStorage.setItem(k, '1');
|
|
241
|
-
globalThis.localStorage.removeItem(k);
|
|
242
|
-
return true;
|
|
243
|
-
} catch {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @param {string} appId
|
|
250
|
-
* @returns {string}
|
|
251
|
-
*/
|
|
252
|
-
function storageKey(appId) {
|
|
253
|
-
return `${STORAGE_PREFIX}${appId}`;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @param {string} responseText
|
|
258
|
-
* @param {string} expectedAppId
|
|
259
|
-
* @returns {{ ok: boolean, ts: number } | null}
|
|
260
|
-
*/
|
|
261
|
-
function parseAndValidateResponse(responseText, expectedAppId) {
|
|
262
|
-
try {
|
|
263
|
-
const o = JSON.parse(responseText);
|
|
264
|
-
if (!o || typeof o !== 'object') {
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
if (o.success !== true) {
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
if (typeof o.app_id !== 'string' || o.app_id !== expectedAppId) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
if (typeof o.timestamp !== 'number' || !Number.isFinite(o.timestamp)) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
return { ok: true, ts: o.timestamp };
|
|
277
|
-
} catch {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Returns cached raw response body if still within TTL, else null.
|
|
284
|
-
* @param {string} appId
|
|
285
|
-
* @returns {string | null}
|
|
286
|
-
*/
|
|
287
|
-
function readOnlineLicenseCache(appId) {
|
|
288
|
-
if (!appId || !isLocalStorageAvailable()) {
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
let raw;
|
|
292
|
-
try {
|
|
293
|
-
raw = globalThis.localStorage.getItem(storageKey(appId));
|
|
294
|
-
} catch {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
if (!raw || typeof raw !== 'string') {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
const meta = parseAndValidateResponse(raw, appId);
|
|
301
|
-
if (!meta) {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
305
|
-
const ts = meta.ts;
|
|
306
|
-
const ageSec = ts <= nowSec ? nowSec - ts : 0;
|
|
307
|
-
if (ageSec > ONLINE_LICENSE_CACHE_TTL_SEC) {
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
return raw;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Persists successful auth response; no-op if storage unavailable or payload invalid.
|
|
315
|
-
* @param {string} appId
|
|
316
|
-
* @param {string} responseText
|
|
317
|
-
* @returns {boolean}
|
|
318
|
-
*/
|
|
319
|
-
function writeOnlineLicenseCache(appId, responseText) {
|
|
320
|
-
if (!appId || !isLocalStorageAvailable() || typeof responseText !== 'string') {
|
|
321
|
-
return false;
|
|
322
|
-
}
|
|
323
|
-
if (!parseAndValidateResponse(responseText, appId)) {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
try {
|
|
327
|
-
globalThis.localStorage.setItem(storageKey(appId), responseText);
|
|
328
|
-
return true;
|
|
329
|
-
} catch {
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
241
|
/**
|
|
335
242
|
* Browser-side console lines aligned with C++ Logger (src/base/logging.cc) Release pattern:
|
|
336
243
|
* [%Y-%m-%d %H:%M:%S.%e] [facebetter] [%l] [%t] - %v
|
|
@@ -561,32 +468,9 @@
|
|
|
561
468
|
};
|
|
562
469
|
}
|
|
563
470
|
|
|
564
|
-
// Setup online auth proxy for WASM
|
|
565
|
-
// 返回 { response, fromCache } 供 WASM 桥区分:仅 fromCache===true 时 C++ 跳过 5 分钟防重放。
|
|
471
|
+
// Setup online auth proxy for WASM(纯在线,失败不回退本地缓存)。
|
|
566
472
|
if (!Module.onOnlineAuth) {
|
|
567
473
|
Module.onOnlineAuth = async (payloadJson) => {
|
|
568
|
-
let appId = '';
|
|
569
|
-
try {
|
|
570
|
-
const p = JSON.parse(payloadJson);
|
|
571
|
-
if (p && typeof p.app_id === 'string') {
|
|
572
|
-
appId = p.app_id;
|
|
573
|
-
}
|
|
574
|
-
} catch {
|
|
575
|
-
// ignore malformed payload
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const authResult = (body, fromCache) =>
|
|
579
|
-
body ? { response: body, fromCache } : '';
|
|
580
|
-
|
|
581
|
-
const cached = appId ? readOnlineLicenseCache(appId) : null;
|
|
582
|
-
if (cached) {
|
|
583
|
-
// 与 C++ 中「disk cache」对应;WASM 侧日志仍显示 online,以这里为准区分是否发 HTTP
|
|
584
|
-
logInfo(
|
|
585
|
-
'Online license: localStorage cache hit (no auth HTTP)'
|
|
586
|
-
);
|
|
587
|
-
return authResult(cached, true);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
474
|
const authUrl = 'https://facebetter.pixpark.net/facebetter/v1/auth';
|
|
591
475
|
logInfo('Online license: requesting auth server');
|
|
592
476
|
try {
|
|
@@ -598,34 +482,17 @@
|
|
|
598
482
|
body: payloadJson,
|
|
599
483
|
});
|
|
600
484
|
if (!response.ok) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
logInfo(
|
|
604
|
-
`Online license: using cache after HTTP error (status ${response.status})`
|
|
605
|
-
);
|
|
606
|
-
} else {
|
|
607
|
-
logWarn(
|
|
608
|
-
`Online license: HTTP ${response.status}, no cache`
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
return authResult(fallback, true);
|
|
485
|
+
logWarn(`Online license: HTTP ${response.status}`);
|
|
486
|
+
return '';
|
|
612
487
|
}
|
|
613
488
|
const text = await response.text();
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
489
|
+
logInfo('Online license: server response ok');
|
|
490
|
+
return text;
|
|
491
|
+
} catch (err) {
|
|
492
|
+
logWarn(
|
|
493
|
+
`Online license: network error${err?.message ? `: ${err.message}` : ''}`
|
|
619
494
|
);
|
|
620
|
-
return
|
|
621
|
-
} catch {
|
|
622
|
-
const fallback = appId ? readOnlineLicenseCache(appId) : null;
|
|
623
|
-
if (fallback) {
|
|
624
|
-
logInfo(
|
|
625
|
-
'Online license: using cache after network error'
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
return authResult(fallback, true);
|
|
495
|
+
return '';
|
|
629
496
|
}
|
|
630
497
|
};
|
|
631
498
|
}
|
|
@@ -838,6 +705,38 @@
|
|
|
838
705
|
this._setBeautyParam('SetBeautyParamMakeup', param, value);
|
|
839
706
|
}
|
|
840
707
|
|
|
708
|
+
/**
|
|
709
|
+
* Sets lipstick style/texture
|
|
710
|
+
* @param {number} style - Style (use LipstickStyle enum, e.g., LipstickStyle.Rouge)
|
|
711
|
+
*/
|
|
712
|
+
setLipstickStyle(style) {
|
|
713
|
+
this._ensureInitialized();
|
|
714
|
+
const Module = this._getWasmModule();
|
|
715
|
+
const result = Module.ccall(
|
|
716
|
+
'SetLipstickStyle',
|
|
717
|
+
'number',
|
|
718
|
+
['number', 'number'],
|
|
719
|
+
[this.enginePtr, style]
|
|
720
|
+
);
|
|
721
|
+
checkResult(result, 'Failed to set lipstick style');
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Sets blush style/texture
|
|
726
|
+
* @param {number} style - Style (use BlushStyle enum, e.g., BlushStyle.Classic)
|
|
727
|
+
*/
|
|
728
|
+
setBlushStyle(style) {
|
|
729
|
+
this._ensureInitialized();
|
|
730
|
+
const Module = this._getWasmModule();
|
|
731
|
+
const result = Module.ccall(
|
|
732
|
+
'SetBlushStyle',
|
|
733
|
+
'number',
|
|
734
|
+
['number', 'number'],
|
|
735
|
+
[this.enginePtr, style]
|
|
736
|
+
);
|
|
737
|
+
checkResult(result, 'Failed to set blush style');
|
|
738
|
+
}
|
|
739
|
+
|
|
841
740
|
/**
|
|
842
741
|
* Sets chroma key parameter
|
|
843
742
|
* @param {number} param - Parameter (use ChromaKeyParam enum, e.g., ChromaKeyParam.Similarity)
|
|
@@ -1836,6 +1735,8 @@
|
|
|
1836
1735
|
const BasicParam = BasicParam$1;
|
|
1837
1736
|
const ReshapeParam = ReshapeParam$1;
|
|
1838
1737
|
const MakeupParam = MakeupParam$1;
|
|
1738
|
+
const LipstickStyle = LipstickStyle$1;
|
|
1739
|
+
const BlushStyle = BlushStyle$1;
|
|
1839
1740
|
const BackgroundMode = BackgroundMode$1;
|
|
1840
1741
|
const FrameType = FrameType$1;
|
|
1841
1742
|
const MirrorMode = MirrorMode$1;
|
|
@@ -1854,9 +1755,11 @@
|
|
|
1854
1755
|
exports.BasicParam = BasicParam;
|
|
1855
1756
|
exports.BeautyEffectEngine = BrowserBeautyEffectEngine;
|
|
1856
1757
|
exports.BeautyType = BeautyType;
|
|
1758
|
+
exports.BlushStyle = BlushStyle;
|
|
1857
1759
|
exports.EngineConfig = EngineConfig;
|
|
1858
1760
|
exports.FacebetterError = FacebetterError;
|
|
1859
1761
|
exports.FrameType = FrameType;
|
|
1762
|
+
exports.LipstickStyle = LipstickStyle;
|
|
1860
1763
|
exports.MakeupParam = MakeupParam;
|
|
1861
1764
|
exports.MirrorMode = MirrorMode;
|
|
1862
1765
|
exports.ReshapeParam = ReshapeParam;
|