tencentcloud-webar 2.0.3-dev.3 → 2.0.3-dev.6

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/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "tencentcloud-webar",
3
- "version": "2.0.3-dev.3",
3
+ "version": "2.0.3-dev.6",
4
4
  "description": "",
5
5
  "main": "build-esm/index.js",
6
+ "types": "types/index.d.ts",
6
7
  "devDependencies": {
7
8
  "@assemblyscript/loader": "^0.19.17",
8
9
  "@babel/core": "^7.17.10",
@@ -0,0 +1,689 @@
1
+ /**
2
+ * tencentcloud-webar SDK Type Declarations
3
+ * @module tencentcloud-webar
4
+ * @version 2.x
5
+ */
6
+
7
+ // ======================== Enums ========================
8
+
9
+ /** Input type enum */
10
+ export enum EntryType {
11
+ CAMERA = 0,
12
+ VIDEO = 1,
13
+ CANVAS = 2,
14
+ IMAGE = 3,
15
+ MEDIA_STREAM = 4,
16
+ }
17
+
18
+ /** Input type constants (equivalent to EntryType) */
19
+ export const ENTRY_TYPES: typeof EntryType;
20
+
21
+ /** Output type enum */
22
+ export enum OUTPUT_TYPES {
23
+ CAMERA = 0,
24
+ VIDEO = 1,
25
+ CANVAS = 2,
26
+ IMAGE = 3,
27
+ MEDIA_STREAM = 4,
28
+ }
29
+
30
+ /** Built-in blend modes */
31
+ export enum BLEND_MODES {
32
+ NORMAL = 0,
33
+ DARKEN = 1,
34
+ MULTIPLY = 2,
35
+ COLOR_BURN = 3,
36
+ LINEAR_BURN = 4,
37
+ LIGHTEN = 5,
38
+ SCREEN = 6,
39
+ COLOR_DODGE = 7,
40
+ LINEAR_DODGE = 8,
41
+ OVERLAY = 9,
42
+ SOFT_LIGHT = 10,
43
+ HARD_LIGHT = 11,
44
+ VIVID_LIGHT = 12,
45
+ LINEAR_LIGHT = 13,
46
+ PIN_LIGHT = 14,
47
+ HARD_MIX = 15,
48
+ DIFFERENCE = 16,
49
+ EXCLUSION = 17,
50
+ SUBSTRACT = 18,
51
+ }
52
+
53
+ // ======================== Type Definitions ========================
54
+
55
+ /** Worker mode */
56
+ export type WorkerMode = "auto" | "enable" | "disable";
57
+
58
+ /** Segmentation accuracy level */
59
+ export type SegmentationLevel = "auto" | 0 | 1 | 2;
60
+
61
+ /** Background type */
62
+ export type BackgroundType = "blur" | "image" | "transparent" | "green" | "video";
63
+
64
+ /** Foreground type */
65
+ export type ForegroundType = "image" | "video";
66
+
67
+ /** 3D attach point value */
68
+ export type AttachPointValue =
69
+ | "normal"
70
+ | "renzhong"
71
+ | "nosetip"
72
+ | "forehead"
73
+ | "nosebridge"
74
+ | "leftear"
75
+ | "rightear";
76
+
77
+ // ======================== Config Interfaces ========================
78
+
79
+ /** Authentication signature data */
80
+ export interface AuthData {
81
+ signature: string;
82
+ timestamp: string | number;
83
+ }
84
+
85
+ /** Authentication config */
86
+ export interface AuthConfig {
87
+ /** License Key */
88
+ licenseKey: string;
89
+ /** Application ID */
90
+ appId: string;
91
+ /** Signature function that returns auth data */
92
+ authFunc: () => Promise<AuthData>;
93
+ }
94
+
95
+ /** Image input config */
96
+ export interface ImageConfig {
97
+ width: number;
98
+ height: number;
99
+ src: HTMLImageElement | string;
100
+ }
101
+
102
+ /** Camera config */
103
+ export interface CameraConfig {
104
+ width: number;
105
+ height: number;
106
+ mirror: boolean;
107
+ frameRate: number;
108
+ }
109
+
110
+ /** Loading indicator config */
111
+ export interface LoadingConfig {
112
+ enable: boolean;
113
+ size?: number;
114
+ lineWidth?: number;
115
+ strokeColor?: number;
116
+ }
117
+
118
+ /** Beautify parameters */
119
+ export interface BeautifyOptions {
120
+ /** Skin whitening, 0-1 */
121
+ whiten?: number;
122
+ /** Skin smoothing, 0-1 */
123
+ dermabrasion?: number;
124
+ /** Dark circle removal */
125
+ darkCircle?: number;
126
+ /** Nasolabial folds removal */
127
+ nasolabialFolds?: number;
128
+ /** Face slimming, 0-1 */
129
+ lift?: number;
130
+ /** Face shaving, 0-1 */
131
+ shave?: number;
132
+ /** Cheekbone adjustment */
133
+ cheekbone?: number;
134
+ /** Head adjustment */
135
+ head?: number;
136
+ /** Eye brightness */
137
+ eyeBrightness?: number;
138
+ /** Lip adjustment */
139
+ lip?: number;
140
+ /** Forehead adjustment */
141
+ forehead?: number;
142
+ /** Nose adjustment */
143
+ nose?: number;
144
+ /** Eye enlargement, 0-1 */
145
+ eye?: number;
146
+ /** Chin adjustment, 0-1 */
147
+ chin?: number;
148
+ /** USM sharpening */
149
+ usm?: number;
150
+ /** Face liquify parameter */
151
+ distort1?: number;
152
+ distortCenter1?: string;
153
+ distortMajorRadius1?: number;
154
+ distortMinorRadius1?: number;
155
+ distort2?: number;
156
+ distortCenter2?: string;
157
+ distortMajorRadius2?: number;
158
+ distortMinorRadius2?: number;
159
+ }
160
+
161
+ /** Beautify options type alias (equivalent to BeautifyOptions) */
162
+ export type BEAUTIFY_OPTIONS = BeautifyOptions;
163
+
164
+ /** Background config */
165
+ export interface BackgroundConfig {
166
+ /** Background type */
167
+ type: BackgroundType;
168
+ /** Image/video path, base64, or remote URL */
169
+ src: string;
170
+ /** Solid color value */
171
+ color: number;
172
+ /** Edge blur */
173
+ edgeBlur?: number;
174
+ }
175
+
176
+ /** Foreground config */
177
+ export interface ForegroundConfig {
178
+ type: ForegroundType;
179
+ /** Image/video path, base64, or remote URL */
180
+ src: string;
181
+ }
182
+
183
+ /** Proxy server config */
184
+ export interface ProxyServerConfig {
185
+ webarProxy?: string;
186
+ staticProxy?: string;
187
+ reportProxy?: string;
188
+ }
189
+
190
+ /** Module enum type */
191
+ export type ModuleEnum =
192
+ | "beautify"
193
+ | "segmentation"
194
+ | "handGesture"
195
+ | "handLandmark"
196
+ | "hair";
197
+
198
+ /** Module config */
199
+ export type ModuleConfig = {
200
+ [key in ModuleEnum]?: boolean;
201
+ } & {
202
+ segmentationLevel?: SegmentationLevel;
203
+ };
204
+
205
+ /** setEffect parameter format */
206
+ export interface SetEffectParam {
207
+ id: string;
208
+ intensity: number;
209
+ filterIntensity: number;
210
+ }
211
+
212
+ /** AR initialization options */
213
+ export interface AROptions {
214
+ width?: number;
215
+ height?: number;
216
+ fps?: number;
217
+ input?: MediaStream | HTMLImageElement | string | ImageConfig;
218
+ inputFrameRate?: number;
219
+ mirror?: boolean;
220
+ output?: HTMLCanvasElement;
221
+ enableLoadingIcon?: boolean;
222
+ loadingIconOptions?: {
223
+ size?: number;
224
+ lineWidth?: number;
225
+ strokeColor?: number;
226
+ };
227
+ beautify?: BeautifyOptions;
228
+ hairColor?: string;
229
+ irisScale?: number;
230
+ worker?: WorkerMode;
231
+ resolution?: number | string;
232
+ avatarSize?: number;
233
+ background?: BackgroundConfig;
234
+ segmentationEdgeBlur?: number;
235
+ enableEdgeOptimization?: boolean;
236
+ }
237
+
238
+ /** Common dynamic config */
239
+ export interface CommonOptions {
240
+ mirror?: boolean;
241
+ }
242
+
243
+ /** Effect list query parameters */
244
+ export interface EffectListParams {
245
+ PageNumber?: number;
246
+ PageSize?: number;
247
+ Version?: string;
248
+ Name?: string;
249
+ Label?: string | string[];
250
+ Type?: string;
251
+ }
252
+
253
+ /** SDK initialization config */
254
+ export interface Config {
255
+ /** Authentication parameters */
256
+ auth: AuthConfig;
257
+ /** Module config */
258
+ module: ModuleConfig;
259
+ /** Proxy server config */
260
+ proxyServer?: ProxyServerConfig;
261
+ /** Input stream or image */
262
+ input?: MediaStream | HTMLImageElement | string | ImageConfig;
263
+ /** Whether to mirror the input */
264
+ mirror?: boolean;
265
+ /** Built-in camera config (used when input is not provided) */
266
+ camera?: CameraConfig;
267
+ /** Beautify parameters */
268
+ beautify?: BeautifyOptions;
269
+ /** Built-in loading indicator config */
270
+ loading?: LoadingConfig;
271
+ /** Output canvas element */
272
+ output?: HTMLCanvasElement;
273
+ /** Render frame rate */
274
+ fps?: number;
275
+ /** Virtual background config */
276
+ background?: BackgroundConfig;
277
+ /** Whether to disable keepalive */
278
+ disableKeepalive?: boolean;
279
+ /** Explicit host domain (for Electron compatibility) */
280
+ domain?: string;
281
+ /** i18n language, e.g. "zh", "en" */
282
+ language?: string;
283
+ /** Whether to detect frame rate */
284
+ detectFps?: boolean;
285
+ /** Log level */
286
+ logLevel?: string;
287
+ /** Whether to initialize data reporting, default true */
288
+ initReport?: boolean;
289
+ /** Report region, e.g. "default", "zh", "sg", "us" */
290
+ reportRegion?: string;
291
+ /** Worker mode */
292
+ worker?: WorkerMode;
293
+ /** Resolution */
294
+ resolution?: number | string;
295
+ /** Avatar size */
296
+ avatarSize?: number;
297
+ }
298
+
299
+ // ======================== Event Types ========================
300
+
301
+ /** SDK event names */
302
+ export type ArSdkEventName =
303
+ | "created"
304
+ | "ready"
305
+ | "error"
306
+ | "warning"
307
+ | "cameraReady"
308
+ | "outputReady"
309
+ | "inputStreamChange"
310
+ | "result"
311
+ | "detectStatusChange"
312
+ | "handGesture"
313
+ | "handSwipeRight"
314
+ | "handSwipeLeft"
315
+ | "renderTickerCall"
316
+ | "detectTickerCall";
317
+
318
+ /** Error event data */
319
+ export interface ArSdkError {
320
+ code: number;
321
+ message: string;
322
+ error?: any;
323
+ }
324
+
325
+ /** Detect status change event data */
326
+ export interface DetectStatusChangeData {
327
+ [key: string]: any;
328
+ }
329
+
330
+ // ======================== LocalPlayer ========================
331
+
332
+ /** Local player */
333
+ export interface LocalPlayer {
334
+ /** Whether the player is alive */
335
+ alive: boolean;
336
+ /** Set mirror mode */
337
+ setMirror(mirror: boolean): void;
338
+ /** Set muted state */
339
+ setMuted(muted: boolean): void;
340
+ /** Update media stream */
341
+ updateStream(stream: MediaStream): void;
342
+ /** Destroy the player */
343
+ destroy(): void;
344
+ }
345
+
346
+ // ======================== ArSdk Main Class ========================
347
+
348
+ /**
349
+ * AR SDK Main Class
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * import { ArSdk, Config } from 'tencentcloud-webar';
354
+ *
355
+ * const config: Config = {
356
+ * auth: {
357
+ * licenseKey: 'your-license-key',
358
+ * appId: 'your-app-id',
359
+ * authFunc: async () => {
360
+ * // Request signature from backend
361
+ * const res = await fetch('/api/get-signature');
362
+ * return res.json(); // { signature, timestamp }
363
+ * },
364
+ * },
365
+ * module: {
366
+ * beautify: true,
367
+ * segmentation: false,
368
+ * },
369
+ * input: mediaStream,
370
+ * };
371
+ *
372
+ * const sdk = new ArSdk(config);
373
+ *
374
+ * sdk.on('ready', () => {
375
+ * sdk.setBeautify({ whiten: 0.5, dermabrasion: 0.5 });
376
+ * });
377
+ *
378
+ * sdk.on('error', (err) => {
379
+ * console.error(err.code, err.message);
380
+ * });
381
+ * ```
382
+ */
383
+ export class ArSdk {
384
+ /** SDK version */
385
+ static readonly sdkVersion: string;
386
+
387
+ /** Check if Avatar feature is supported (requires WebGL2) */
388
+ static isAvatarSupported(): boolean;
389
+
390
+ /** Camera instance (available after cameraReady event) */
391
+ camera: any;
392
+
393
+ /** Whether in lazy initialization mode */
394
+ lazyInit: boolean;
395
+
396
+ constructor(config: Config);
397
+
398
+ // ==================== Event System ====================
399
+
400
+ /**
401
+ * Listen for an event
402
+ * @param name - Event name
403
+ * @param callback - Callback function
404
+ * @returns Listener ID
405
+ */
406
+ on(name: ArSdkEventName | string, callback: (data?: any) => void): number;
407
+
408
+ /**
409
+ * Remove an event listener
410
+ * @param name - Event name
411
+ * @param callback - Original callback function reference
412
+ * @param id - Listener ID (optional)
413
+ */
414
+ off(name: ArSdkEventName | string, callback: (data?: any) => void, id?: number): void;
415
+
416
+ /**
417
+ * Listen for an event once
418
+ * @param name - Event name
419
+ * @param callback - Callback function
420
+ */
421
+ once(name: ArSdkEventName | string, callback: (data?: any) => void): void;
422
+
423
+ /**
424
+ * Check if an event has listeners
425
+ * @param name - Event name
426
+ */
427
+ hasEvent(name: string): boolean;
428
+
429
+ // ==================== Input / Output ====================
430
+
431
+ /** Set input source */
432
+ set input(src: HTMLImageElement | HTMLVideoElement | MediaStream | string | ImageConfig);
433
+
434
+ /** Get current input source */
435
+ get input(): HTMLImageElement | HTMLVideoElement | MediaStream | string | ImageConfig;
436
+
437
+ /**
438
+ * Initialize core in lazy mode
439
+ * @param options - Initialization options
440
+ */
441
+ initCore(options?: {
442
+ input?: MediaStream | HTMLImageElement | string | ImageConfig;
443
+ mirror?: boolean;
444
+ camera?: CameraConfig;
445
+ worker?: WorkerMode;
446
+ resolution?: number | string;
447
+ }): Promise<void>;
448
+
449
+ /**
450
+ * Get output stream
451
+ * @param fps - Output stream frame rate
452
+ * @param type - Output type; defaults to base64 for image, MediaStream for video
453
+ * @returns MediaStream or base64 string
454
+ */
455
+ getOutput(fps?: number, type?: OUTPUT_TYPES): Promise<MediaStream | string>;
456
+
457
+ /**
458
+ * Update input stream (e.g. for switching camera)
459
+ * @param src - New input stream
460
+ * @param stopOldTracks - Whether to stop old media tracks, default true
461
+ * @param updateOutputDestination - Whether to update output destination, default false
462
+ */
463
+ updateInputStream(
464
+ src: MediaStream,
465
+ stopOldTracks?: boolean,
466
+ updateOutputDestination?: boolean
467
+ ): Promise<void>;
468
+
469
+ /**
470
+ * Update input image
471
+ * @param options - AR options
472
+ * @param callback - Completion callback
473
+ */
474
+ updateInputImage(options: AROptions, callback?: (...args: any[]) => any): void;
475
+
476
+ /**
477
+ * Switch input (for console use)
478
+ * @param type - Input type
479
+ * @param options - AR options
480
+ * @param callback - Completion callback
481
+ */
482
+ setInput(type: EntryType, options: AROptions, callback?: (...args: any[]) => any): void;
483
+
484
+ /**
485
+ * Reset core
486
+ * @param input - New input stream (optional)
487
+ */
488
+ resetCore(input?: MediaStream): Promise<void>;
489
+
490
+ // ==================== Effects ====================
491
+
492
+ /**
493
+ * Preload effect resources by effect IDs
494
+ * @param ids - Effect ID or array of IDs
495
+ * @param callback - Success callback
496
+ * @param errCallback - Error callback
497
+ */
498
+ preloadEffectByIds(
499
+ ids: string | string[],
500
+ callback?: (...args: any[]) => any,
501
+ errCallback?: (...args: any[]) => any
502
+ ): void;
503
+
504
+ /**
505
+ * Set effects (makeup / stickers, etc.)
506
+ * @param ids - Effect ID, config object, or array of them
507
+ * @param callback - Success callback
508
+ * @param errCallback - Error callback
509
+ */
510
+ setEffect(
511
+ ids: string | SetEffectParam | (string | SetEffectParam)[],
512
+ callback?: (...args: any[]) => any,
513
+ errCallback?: (...args: any[]) => any
514
+ ): void;
515
+
516
+ // ==================== Beautify / Filter ====================
517
+
518
+ /**
519
+ * Set beautify parameters
520
+ * @param options - Beautify options
521
+ * @param callback - Completion callback
522
+ */
523
+ setBeautify(options: BeautifyOptions, callback?: (...args: any[]) => any): void;
524
+
525
+ /**
526
+ * Set filter
527
+ * @param id - Filter effect ID; pass undefined or "none" to remove filter
528
+ * @param intensity - Filter intensity, default 1
529
+ * @param callback - Success callback
530
+ * @param errCallback - Error callback
531
+ */
532
+ setFilter(
533
+ id?: string,
534
+ intensity?: number,
535
+ callback?: (...args: any[]) => any,
536
+ errCallback?: (...args: any[]) => any
537
+ ): void;
538
+
539
+ /**
540
+ * Set hair color
541
+ * @param color - Color value
542
+ */
543
+ setHairColor(color: string): void;
544
+
545
+ // ==================== Background / Foreground ====================
546
+
547
+ /**
548
+ * Set virtual background
549
+ * @param config - Background config; pass null to remove background
550
+ * @param callback - Completion callback
551
+ */
552
+ setBackground(config: BackgroundConfig | null, callback?: (...args: any[]) => any): Promise<void>;
553
+
554
+ /**
555
+ * Set foreground
556
+ * @param config - Foreground config
557
+ * @param callback - Completion callback
558
+ */
559
+ setForeground(config: ForegroundConfig, callback?: (...args: any[]) => any): Promise<void>;
560
+
561
+ /**
562
+ * Set segmentation accuracy level
563
+ * @param level - Accuracy level
564
+ */
565
+ setSegmentationLevel(level: SegmentationLevel): Promise<void>;
566
+
567
+ // ==================== Avatar ====================
568
+
569
+ /**
570
+ * Set avatar
571
+ * @param configs - Avatar configuration
572
+ * @param callback - Success callback
573
+ * @param errCallback - Error callback
574
+ */
575
+ setAvatar(
576
+ configs?: {
577
+ /** Model URL */
578
+ url?: string;
579
+ /** Effect ID */
580
+ effectId?: string;
581
+ /** Avatar mode */
582
+ mode?: "AR" | "VR";
583
+ [key: string]: any;
584
+ },
585
+ callback?: (...args: any[]) => any,
586
+ errCallback?: (...args: any[]) => any
587
+ ): Promise<void>;
588
+
589
+ // ==================== Configuration ====================
590
+
591
+ /**
592
+ * Set log level
593
+ * @param level - Log level
594
+ */
595
+ setLogLevel(level: string): void;
596
+
597
+ /**
598
+ * Set common config (e.g. mirror)
599
+ * @param data - Common config options
600
+ */
601
+ setCommonConfig(data: CommonOptions): void;
602
+
603
+ /**
604
+ * Dynamically update detection module config
605
+ * @param data - Module config
606
+ */
607
+ setDetectModuleConfig(data: ModuleConfig): void;
608
+
609
+ // ==================== Control ====================
610
+
611
+ /** Resume SDK */
612
+ resume(): Promise<void>;
613
+
614
+ /** Stop SDK */
615
+ stop(): void;
616
+
617
+ /** Disable detection and effects */
618
+ disable(): void;
619
+
620
+ /** Enable detection and effects */
621
+ enable(): void;
622
+
623
+ // ==================== Misc ====================
624
+
625
+ /**
626
+ * Take a photo (returns ImageData)
627
+ */
628
+ takePhoto(): Promise<ImageData>;
629
+
630
+ /**
631
+ * Get effect list
632
+ * @param params - Query parameters
633
+ */
634
+ getEffectList(params?: EffectListParams): Promise<any>;
635
+
636
+ /**
637
+ * Get avatar list
638
+ * @param type - Type: AR or VR
639
+ */
640
+ getAvatarList(type: "AR" | "VR"): Promise<any>;
641
+
642
+ /**
643
+ * Get specific effect info
644
+ * @param effectId - Effect ID
645
+ */
646
+ getEffect(effectId: string): Promise<{ Url: string; [key: string]: any }>;
647
+
648
+ /**
649
+ * Get built-in filter list
650
+ */
651
+ getCommonFilter(): Promise<any>;
652
+
653
+ /**
654
+ * Initialize local player
655
+ * @param domId - DOM element ID to mount the player
656
+ * @returns Player instance
657
+ */
658
+ initLocalPlayer(domId: string): Promise<LocalPlayer>;
659
+
660
+ /**
661
+ * Destroy SDK and release all resources
662
+ * @param options - Destroy options
663
+ * @param options.stopInputStream - Whether to stop input stream tracks, default true
664
+ */
665
+ destroy(options?: { stopInputStream?: boolean }): void;
666
+ }
667
+
668
+ // ======================== Utility Functions ========================
669
+
670
+ /**
671
+ * Check if the current environment supports WebGL
672
+ */
673
+ export function isWebGLSupported(): boolean;
674
+
675
+ /**
676
+ * Check if the current environment supports WebGL2
677
+ */
678
+ export function isWebGL2Supported(): boolean;
679
+
680
+ /**
681
+ * Check if the current environment supports Worker mode
682
+ */
683
+ export function isWorkerAvailable(): boolean;
684
+
685
+ /**
686
+ * Get current device GPU level
687
+ * @returns GPU level, e.g. "high", "middle", "low"
688
+ */
689
+ export function getGPULevel(): string;
package/.babelrc DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"],
3
- "plugins": ["js-logger"],
4
- "compact": false
5
- }
package/babel.config.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env"],
3
- "compact": false
4
- }