@asiyst/sdk 0.1.27 → 0.1.28

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/index.cjs CHANGED
@@ -97,7 +97,7 @@ var ALL_ACTION_KINDS = [
97
97
  // src/core/constants.ts
98
98
  function resolveSdkVersion() {
99
99
  {
100
- return "0.1.26";
100
+ return "0.1.28";
101
101
  }
102
102
  }
103
103
  var SDK_VERSION = resolveSdkVersion();
@@ -2242,6 +2242,7 @@ var FbxRenderer = class {
2242
2242
  this.canvas.setAttribute("role", "presentation");
2243
2243
  this.canvas.style.opacity = "0";
2244
2244
  this.canvas.style.transition = "opacity 0.25s ease";
2245
+ this.canvas.style.background = "transparent";
2245
2246
  const glContext = this.canvas.getContext("webgl2") || this.canvas.getContext("webgl");
2246
2247
  if (!glContext) {
2247
2248
  throw new Error("WebGLRenderingContext is not available or supported in this browser environment");
@@ -2261,6 +2262,7 @@ var FbxRenderer = class {
2261
2262
  antialias: true,
2262
2263
  powerPreference: "high-performance"
2263
2264
  });
2265
+ this.renderer.setClearColor(0, 0);
2264
2266
  this.renderer.setPixelRatio(Math.min(dpr, 2));
2265
2267
  this.renderer.setSize(width, height, false);
2266
2268
  this.renderer.outputColorSpace = THREE__namespace.SRGBColorSpace;
@@ -2358,13 +2360,23 @@ var FbxRenderer = class {
2358
2360
  this.rawObject = rawObject;
2359
2361
  this.mixer = new THREE__namespace.AnimationMixer(rawObject);
2360
2362
  this.allAnimations = [...modelAnimations];
2361
- if (modelAnimations.length > 0) {
2362
- const idleClip = modelAnimations.find((c) => c.name.toLowerCase().includes("idle")) || modelAnimations[0];
2363
- if (idleClip) {
2364
- this.currentAction = this.mixer.clipAction(idleClip);
2365
- this.currentAction.play();
2363
+ const externalAnims = options?.config?.animations || options?.config?.avatar?.animations || [];
2364
+ if (externalAnims.length > 0) {
2365
+ try {
2366
+ await Promise.race([
2367
+ this.loadExternalAnimations(externalAnims, options?.config?.animation),
2368
+ new Promise((resolve) => setTimeout(resolve, 8e3))
2369
+ ]);
2370
+ } catch (animErr) {
2371
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
2372
+ console.warn("[asiyst] External animation loading notice:", animErr);
2373
+ }
2366
2374
  }
2367
2375
  }
2376
+ this.startInitialIdleAnimation(options?.config);
2377
+ if (this.mixer) {
2378
+ this.mixer.update(0);
2379
+ }
2368
2380
  container.replaceChildren();
2369
2381
  container.appendChild(this.canvas);
2370
2382
  try {
@@ -2380,9 +2392,6 @@ var FbxRenderer = class {
2380
2392
  this.startLoop();
2381
2393
  this.setFacing(this.facing);
2382
2394
  this.setPose(this.currentPose);
2383
- if (options?.config?.animations && options.config.animations.length > 0) {
2384
- void this.loadExternalAnimations(options.config.animations);
2385
- }
2386
2395
  if (typeof window !== "undefined") {
2387
2396
  this.resizeListener = () => this.handleResize();
2388
2397
  window.addEventListener("resize", this.resizeListener);
@@ -2390,7 +2399,7 @@ var FbxRenderer = class {
2390
2399
  return {
2391
2400
  meshCount,
2392
2401
  vertexCount: totalVertices,
2393
- animationCount: modelAnimations.length
2402
+ animationCount: this.allAnimations.length
2394
2403
  };
2395
2404
  }
2396
2405
  setFacing(direction) {
@@ -2401,11 +2410,10 @@ var FbxRenderer = class {
2401
2410
  }
2402
2411
  setPose(pose) {
2403
2412
  this.currentPose = pose;
2404
- if (!this.modelRoot) return;
2405
2413
  if (this.playAnimation(pose)) {
2406
2414
  return;
2407
2415
  }
2408
- if (this.mixer && this.allAnimations.length > 1) {
2416
+ if (this.mixer && this.allAnimations.length > 0) {
2409
2417
  let targetClip;
2410
2418
  if (pose === "speak") {
2411
2419
  targetClip = this.allAnimations.find(
@@ -2416,7 +2424,7 @@ var FbxRenderer = class {
2416
2424
  (c) => c.name.toLowerCase().includes("think")
2417
2425
  );
2418
2426
  } else {
2419
- targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.allAnimations[0];
2427
+ targetClip = this.allAnimations.find((c) => c.name.toLowerCase().includes("idle")) || this.animationMetadataList[0]?.clip || this.allAnimations[0];
2420
2428
  }
2421
2429
  if (targetClip) {
2422
2430
  const newAction = this.mixer.clipAction(targetClip);
@@ -2427,9 +2435,14 @@ var FbxRenderer = class {
2427
2435
  }
2428
2436
  this.currentAction = newAction;
2429
2437
  return;
2438
+ } else if (!this.currentAction?.isRunning()) {
2439
+ this.currentAction?.play();
2440
+ return;
2430
2441
  }
2442
+ return;
2431
2443
  }
2432
2444
  }
2445
+ if (!this.modelRoot) return;
2433
2446
  switch (pose) {
2434
2447
  case "point":
2435
2448
  this.modelRoot.rotation.z = -0.15;
@@ -2455,7 +2468,55 @@ var FbxRenderer = class {
2455
2468
  break;
2456
2469
  }
2457
2470
  }
2458
- async loadExternalAnimations(animations) {
2471
+ startInitialIdleAnimation(config) {
2472
+ if (!this.mixer) return false;
2473
+ const targetQuery = config?.animation?.trim();
2474
+ if (targetQuery && this.playAnimation(targetQuery)) {
2475
+ return true;
2476
+ }
2477
+ const idleByIntent = this.animationMetadataList.find(
2478
+ (m) => m.intent?.toLowerCase() === "idle"
2479
+ );
2480
+ if (idleByIntent && this.playAnimation(idleByIntent.id || idleByIntent.name)) {
2481
+ return true;
2482
+ }
2483
+ const idleByName = this.animationMetadataList.find(
2484
+ (m) => m.name.toLowerCase().includes("idle") || m.clipName && m.clipName.toLowerCase().includes("idle")
2485
+ );
2486
+ if (idleByName && this.playAnimation(idleByName.id || idleByName.name)) {
2487
+ return true;
2488
+ }
2489
+ const embeddedIdle = this.allAnimations.find(
2490
+ (c) => c.name.toLowerCase().includes("idle")
2491
+ );
2492
+ if (embeddedIdle) {
2493
+ const action = this.mixer.clipAction(embeddedIdle);
2494
+ if (this.currentAction !== action) {
2495
+ action.reset().fadeIn(0.25).play();
2496
+ if (this.currentAction) this.currentAction.fadeOut(0.25);
2497
+ this.currentAction = action;
2498
+ }
2499
+ return true;
2500
+ }
2501
+ if (this.animationMetadataList.length > 0) {
2502
+ const firstMeta = this.animationMetadataList[0];
2503
+ if (this.playAnimation(firstMeta.id || firstMeta.name)) {
2504
+ return true;
2505
+ }
2506
+ }
2507
+ if (this.allAnimations.length > 0) {
2508
+ const firstClip = this.allAnimations[0];
2509
+ const action = this.mixer.clipAction(firstClip);
2510
+ if (this.currentAction !== action) {
2511
+ action.reset().fadeIn(0.25).play();
2512
+ if (this.currentAction) this.currentAction.fadeOut(0.25);
2513
+ this.currentAction = action;
2514
+ }
2515
+ return true;
2516
+ }
2517
+ return false;
2518
+ }
2519
+ async loadExternalAnimations(animations, targetAnimationName) {
2459
2520
  if (!this.rawObject || !this.mixer) return;
2460
2521
  for (const anim of animations) {
2461
2522
  if (!anim.assetUrl) continue;
@@ -2493,11 +2554,6 @@ var FbxRenderer = class {
2493
2554
  loopMode: anim.loopMode,
2494
2555
  clip: retargeted
2495
2556
  });
2496
- const animIntent = anim.intent?.toLowerCase();
2497
- const animName = anim.name.toLowerCase();
2498
- if (animIntent === this.currentPose || this.currentPose === "idle" && (animIntent === "idle" || animName === "idle")) {
2499
- this.playAnimation(anim.id || anim.name || this.currentPose, anim.loopMode);
2500
- }
2501
2557
  }
2502
2558
  } catch (err) {
2503
2559
  if (typeof console !== "undefined" && typeof console.warn === "function") {
@@ -2506,37 +2562,66 @@ var FbxRenderer = class {
2506
2562
  }
2507
2563
  }
2508
2564
  }
2565
+ if (this.currentPose === "idle" || targetAnimationName) {
2566
+ this.startInitialIdleAnimation({ animation: targetAnimationName });
2567
+ if (this.mixer) {
2568
+ this.mixer.update(0);
2569
+ }
2570
+ }
2509
2571
  }
2510
2572
  retargetClip(clip, targetObject) {
2511
2573
  const targetNodeNames = /* @__PURE__ */ new Set();
2512
- const boneMap = /* @__PURE__ */ new Map();
2574
+ const boneLookup = /* @__PURE__ */ new Map();
2575
+ const cleanBoneName = (name) => {
2576
+ return name.replace(/^.*[:|/]/, "").replace(/^(mixamorig\d*|bip01|armature|root)[:_ ]?/i, "").replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
2577
+ };
2513
2578
  targetObject.traverse((node) => {
2514
2579
  if (node.name) {
2515
2580
  targetNodeNames.add(node.name);
2516
- const clean = node.name.replace(/^.*[:|/]/, "").toLowerCase();
2517
- boneMap.set(clean, node.name);
2518
- boneMap.set(node.name.toLowerCase(), node.name);
2581
+ const lower = node.name.toLowerCase();
2582
+ const simpleClean = node.name.replace(/^.*[:|/]/, "").toLowerCase();
2583
+ const stripped = cleanBoneName(node.name);
2584
+ if (!boneLookup.has(lower)) boneLookup.set(lower, node.name);
2585
+ if (!boneLookup.has(simpleClean)) boneLookup.set(simpleClean, node.name);
2586
+ if (stripped && !boneLookup.has(stripped)) boneLookup.set(stripped, node.name);
2519
2587
  }
2520
2588
  });
2589
+ const isRootOrHips = (name) => {
2590
+ const clean = cleanBoneName(name);
2591
+ return clean === "hips" || clean === "pelvis" || clean === "root";
2592
+ };
2521
2593
  const validTracks = [];
2522
2594
  for (const track of clip.tracks) {
2523
2595
  const dotIdx = track.name.lastIndexOf(".");
2524
2596
  if (dotIdx === -1) continue;
2525
2597
  const nodePart = track.name.substring(0, dotIdx);
2526
2598
  const propPart = track.name.substring(dotIdx);
2599
+ let matchedNodeName;
2527
2600
  if (targetNodeNames.has(nodePart)) {
2528
- validTracks.push(track);
2601
+ matchedNodeName = nodePart;
2529
2602
  } else {
2530
- const clean = nodePart.replace(/^.*[:|/]/, "").toLowerCase();
2531
- const matched = boneMap.get(clean);
2532
- if (matched) {
2603
+ const lower = nodePart.toLowerCase();
2604
+ const simpleClean = nodePart.replace(/^.*[:|/]/, "").toLowerCase();
2605
+ const stripped = cleanBoneName(nodePart);
2606
+ matchedNodeName = boneLookup.get(lower) || boneLookup.get(simpleClean) || boneLookup.get(stripped);
2607
+ }
2608
+ if (matchedNodeName) {
2609
+ if (propPart.toLowerCase().startsWith(".position") && !isRootOrHips(matchedNodeName)) {
2610
+ continue;
2611
+ }
2612
+ if (matchedNodeName === nodePart) {
2613
+ validTracks.push(track);
2614
+ } else {
2533
2615
  const clonedTrack = track.clone();
2534
- clonedTrack.name = `${matched}${propPart}`;
2616
+ clonedTrack.name = `${matchedNodeName}${propPart}`;
2535
2617
  validTracks.push(clonedTrack);
2536
2618
  }
2537
2619
  }
2538
2620
  }
2539
- if (validTracks.length === 0) {
2621
+ if (validTracks.length === 0 || clip.duration <= 0) {
2622
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
2623
+ console.warn(`[asiyst] External animation "${clip.name}" has no compatible bone tracks for this avatar skeleton.`);
2624
+ }
2540
2625
  return null;
2541
2626
  }
2542
2627
  return new THREE__namespace.AnimationClip(clip.name, clip.duration, validTracks);
@@ -2581,6 +2666,8 @@ var FbxRenderer = class {
2581
2666
  this.currentAction.fadeOut(crossFadeDuration);
2582
2667
  }
2583
2668
  this.currentAction = action;
2669
+ } else if (!action.isRunning()) {
2670
+ action.reset().play();
2584
2671
  }
2585
2672
  return true;
2586
2673
  }
@@ -2721,20 +2808,23 @@ var AVATAR_CSS = `
2721
2808
  transition: left 420ms cubic-bezier(0.22, 1, 0.36, 1), top 420ms cubic-bezier(0.22, 1, 0.36, 1);
2722
2809
  }
2723
2810
  .asiyst-figure {
2724
- border-radius: 28px;
2725
2811
  display: grid;
2726
2812
  place-items: center;
2727
- color: #fff;
2728
- font: 700 14px/1.2 system-ui, sans-serif;
2729
- box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
2730
2813
  position: relative;
2731
- overflow: hidden;
2732
2814
  cursor: pointer;
2733
2815
  border: none;
2734
2816
  padding: 0;
2735
2817
  outline: none;
2818
+ background: transparent;
2819
+ overflow: visible;
2820
+ }
2821
+ .asiyst-figure.asiyst-compact-launcher {
2822
+ border-radius: 28px;
2823
+ color: #fff;
2824
+ font: 700 14px/1.2 system-ui, sans-serif;
2825
+ box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
2826
+ overflow: hidden;
2736
2827
  background: #2563eb;
2737
- transition: width 0.3s ease, height 0.3s ease, background 0.3s ease;
2738
2828
  }
2739
2829
  .asiyst-figure.asiyst-3d-active {
2740
2830
  width: 240px !important;
@@ -2901,7 +2991,7 @@ var AVATAR_CSS = `
2901
2991
  var CssAvatarRenderer = class {
2902
2992
  constructor() {
2903
2993
  this.size = 96;
2904
- this.hidden = false;
2994
+ this.hidden = true;
2905
2995
  this.facing = "right";
2906
2996
  this.pose = "idle";
2907
2997
  this.accentColor = "#2563eb";
@@ -2923,6 +3013,9 @@ var CssAvatarRenderer = class {
2923
3013
  this.root = doc.createElement("div");
2924
3014
  this.root.className = "asiyst-avatar asiyst-animate";
2925
3015
  this.root.setAttribute("role", "img");
3016
+ if (this.hidden) {
3017
+ this.root.style.display = "none";
3018
+ }
2926
3019
  this.nameTagEl = doc.createElement("div");
2927
3020
  this.nameTagEl.className = "asiyst-name-tag";
2928
3021
  const sparkle = doc.createElement("span");
@@ -2985,7 +3078,7 @@ var CssAvatarRenderer = class {
2985
3078
  this.size = config.size;
2986
3079
  this.accentColor = config.theme.accent ?? "#2563eb";
2987
3080
  this.avatarName = config.avatarName;
2988
- const has3dAsset = Boolean(config.assetUrl || config.thumbnailUrl);
3081
+ const has3dAsset = Boolean(config.assetUrl || config.thumbnailUrl || config.avatarId);
2989
3082
  this.has3dAssetConfigured = has3dAsset;
2990
3083
  if (config.assetUrl || config.thumbnailUrl) {
2991
3084
  this.activeAssetUrl = config.assetUrl ?? config.thumbnailUrl ?? void 0;
@@ -3005,10 +3098,14 @@ var CssAvatarRenderer = class {
3005
3098
  if (has3dAsset) {
3006
3099
  if (this.figure) {
3007
3100
  this.figure.classList.add("asiyst-3d-active");
3101
+ this.figure.classList.remove("asiyst-compact-launcher");
3008
3102
  this.figure.style.width = "";
3009
3103
  this.figure.style.height = "";
3010
3104
  this.figure.style.background = "transparent";
3011
3105
  }
3106
+ if (this.nameTagEl) {
3107
+ this.nameTagEl.style.display = this.isAssetLoadedFlag ? "inline-flex" : "none";
3108
+ }
3012
3109
  if (this.chatActionBtn) {
3013
3110
  this.chatActionBtn.style.display = this.isAssetLoadedFlag && !this.isPanelOpen ? "inline-flex" : "none";
3014
3111
  }
@@ -3016,16 +3113,20 @@ var CssAvatarRenderer = class {
3016
3113
  if (this.renderState === "error") {
3017
3114
  this.renderFallback(true);
3018
3115
  } else {
3019
- this.renderLoader();
3116
+ this.viewport.replaceChildren();
3020
3117
  }
3021
3118
  }
3022
3119
  } else {
3023
3120
  if (this.figure) {
3024
3121
  this.figure.classList.remove("asiyst-3d-active");
3122
+ this.figure.classList.add("asiyst-compact-launcher");
3025
3123
  this.figure.style.width = `${config.size}px`;
3026
3124
  this.figure.style.height = `${config.size}px`;
3027
3125
  this.figure.style.background = this.accentColor;
3028
3126
  }
3127
+ if (this.nameTagEl) {
3128
+ this.nameTagEl.style.display = "none";
3129
+ }
3029
3130
  if (this.chatActionBtn) {
3030
3131
  this.chatActionBtn.style.display = "none";
3031
3132
  }
@@ -3057,11 +3158,20 @@ var CssAvatarRenderer = class {
3057
3158
  if (this.figure) {
3058
3159
  this.figure.setAttribute("data-state", "loading");
3059
3160
  this.figure.classList.add("asiyst-3d-active");
3161
+ this.figure.classList.remove("asiyst-compact-launcher");
3060
3162
  this.figure.style.width = "";
3061
3163
  this.figure.style.height = "";
3062
3164
  this.figure.style.background = "transparent";
3063
3165
  }
3064
- this.renderLoader();
3166
+ if (this.nameTagEl) {
3167
+ this.nameTagEl.style.display = "none";
3168
+ }
3169
+ if (this.chatActionBtn) {
3170
+ this.chatActionBtn.style.display = "none";
3171
+ }
3172
+ if (this.viewport) {
3173
+ this.renderLoader();
3174
+ }
3065
3175
  try {
3066
3176
  const asset = await this.assetLoader.load(assetUrl, { timeoutMs: 6e4 });
3067
3177
  await this.renderLoadedAsset(asset, config);
@@ -3072,10 +3182,14 @@ var CssAvatarRenderer = class {
3072
3182
  if (this.figure) {
3073
3183
  this.figure.setAttribute("data-state", "ready");
3074
3184
  this.figure.classList.add("asiyst-3d-active");
3185
+ this.figure.classList.remove("asiyst-compact-launcher");
3075
3186
  this.figure.style.width = "";
3076
3187
  this.figure.style.height = "";
3077
3188
  this.figure.style.background = "transparent";
3078
3189
  }
3190
+ if (this.nameTagEl) {
3191
+ this.nameTagEl.style.display = "inline-flex";
3192
+ }
3079
3193
  if (this.chatActionBtn) {
3080
3194
  this.chatActionBtn.style.display = this.isPanelOpen ? "none" : "inline-flex";
3081
3195
  }
@@ -3088,6 +3202,14 @@ var CssAvatarRenderer = class {
3088
3202
  this.isFallbackFlag = true;
3089
3203
  if (this.figure) {
3090
3204
  this.figure.setAttribute("data-state", "error");
3205
+ this.figure.classList.remove("asiyst-3d-active");
3206
+ this.figure.classList.add("asiyst-compact-launcher");
3207
+ this.figure.style.width = `${this.size}px`;
3208
+ this.figure.style.height = `${this.size}px`;
3209
+ this.figure.style.background = this.accentColor;
3210
+ }
3211
+ if (this.nameTagEl) {
3212
+ this.nameTagEl.style.display = "none";
3091
3213
  }
3092
3214
  if (this.chatActionBtn) {
3093
3215
  this.chatActionBtn.style.display = "none";
@@ -4549,7 +4671,6 @@ var AsiystRuntime = class {
4549
4671
  this.movement.start();
4550
4672
  this.analytics.start();
4551
4673
  this.rescan();
4552
- this.avatar.show();
4553
4674
  const figure = this.renderer.getFigure();
4554
4675
  if (figure) {
4555
4676
  this.figureClickListener = () => this.open();
@@ -4574,7 +4695,6 @@ var AsiystRuntime = class {
4574
4695
  return;
4575
4696
  }
4576
4697
  this.avatar.applyConfig(cfg);
4577
- this.avatar.show();
4578
4698
  this.movement.goToAnchor();
4579
4699
  this.lifecycle.emit("sdk.verification_started", {
4580
4700
  projectId: this.options.projectId,
@@ -4600,7 +4720,15 @@ var AsiystRuntime = class {
4600
4720
  });
4601
4721
  const assetTarget = cfg.assetUrl ?? cfg.thumbnailUrl;
4602
4722
  if (assetTarget) {
4603
- await this.loadAvatarAsset(cfg, assetTarget);
4723
+ try {
4724
+ await this.loadAvatarAsset(cfg, assetTarget);
4725
+ } finally {
4726
+ this.avatar.show();
4727
+ this.movement.goToAnchor();
4728
+ }
4729
+ } else {
4730
+ this.avatar.show();
4731
+ this.movement.goToAnchor();
4604
4732
  }
4605
4733
  this.startConfigRevalidationScheduler();
4606
4734
  }