untitled-pixi-live2d-engine 1.2.1 → 1.3.0

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/cubism.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("pixi.js"), require("@pixi/sound")) : typeof define === "function" && define.amd ? define(["exports", "pixi.js", "@pixi/sound"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory((global.PIXI = global.PIXI || {}, global.PIXI.live2d = global.PIXI.live2d || {}), global.PIXI, global.PIXI));
3
- })(this, (function(exports2, pixi_js, sound) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("pixi.js")) : typeof define === "function" && define.amd ? define(["exports", "pixi.js"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory((global.PIXI = global.PIXI || {}, global.PIXI.live2d = global.PIXI.live2d || {}), global.PIXI));
3
+ })(this, (function(exports2, pixi_js) {
4
4
  "use strict";var __defProp = Object.defineProperty;
5
5
  var __defProps = Object.defineProperties;
6
6
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -2762,7 +2762,7 @@ var __async = (__this, __arguments, generator) => {
2762
2762
  preserveExpressionOnMotion: true,
2763
2763
  cubism: CubismFrameworkConfig
2764
2764
  };
2765
- const VERSION = "1.2.1";
2765
+ const VERSION = "1.3.0";
2766
2766
  const logger = {
2767
2767
  log(tag, ...messages) {
2768
2768
  if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
@@ -3481,7 +3481,64 @@ var __async = (__this, __arguments, generator) => {
3481
3481
  }
3482
3482
  const TAG$2 = "SoundManager";
3483
3483
  const VOLUME = 0.5;
3484
- sound.sound.disableAutoPause = true;
3484
+ const SOUND_ALIAS_PREFIX = "live2d-sound-";
3485
+ let soundId = 0;
3486
+ let pixiSoundPromise;
3487
+ const configuredLibraries = /* @__PURE__ */ new WeakSet();
3488
+ function configureSoundLibrary(library) {
3489
+ if (!configuredLibraries.has(library)) {
3490
+ try {
3491
+ library.disableAutoPause = true;
3492
+ } catch (e) {
3493
+ logger.warn(TAG$2, "Failed to disable @pixi/sound auto pause.", e);
3494
+ }
3495
+ configuredLibraries.add(library);
3496
+ }
3497
+ return library;
3498
+ }
3499
+ function getGlobalSoundLibrary() {
3500
+ return typeof PIXI !== "undefined" ? PIXI == null ? void 0 : PIXI.sound : void 0;
3501
+ }
3502
+ function resolveSoundLibrary() {
3503
+ return __async(this, null, function* () {
3504
+ const globalLibrary = getGlobalSoundLibrary();
3505
+ if (globalLibrary) {
3506
+ return configureSoundLibrary(globalLibrary);
3507
+ }
3508
+ pixiSoundPromise != null ? pixiSoundPromise : pixiSoundPromise = import("@pixi/sound").then(({ sound }) => configureSoundLibrary(sound)).catch((e) => {
3509
+ logger.warn(
3510
+ TAG$2,
3511
+ "@pixi/sound is not available. Load pixi-sound.js before using motion sounds, speak(), or lip sync.",
3512
+ e
3513
+ );
3514
+ return null;
3515
+ });
3516
+ return pixiSoundPromise;
3517
+ });
3518
+ }
3519
+ function removeSound(library, alias) {
3520
+ try {
3521
+ library.remove(alias);
3522
+ } catch (e) {
3523
+ logger.warn(TAG$2, `Failed to remove sound "${alias}".`, e);
3524
+ }
3525
+ }
3526
+ function destroySound(audio) {
3527
+ try {
3528
+ audio.destroy();
3529
+ } catch (e) {
3530
+ logger.warn(TAG$2, "Failed to destroy audio.", e);
3531
+ }
3532
+ }
3533
+ function getAudioBuffer(audio) {
3534
+ const media = audio.media;
3535
+ const buffer = media.buffer;
3536
+ if (!buffer || typeof buffer !== "object") {
3537
+ return void 0;
3538
+ }
3539
+ const candidate = buffer;
3540
+ return typeof candidate.getChannelData === "function" ? buffer : void 0;
3541
+ }
3485
3542
  class SoundManager {
3486
3543
  /**
3487
3544
  * Global volume that applies to all the sounds.
@@ -3502,22 +3559,47 @@ var __async = (__this, __arguments, generator) => {
3502
3559
  */
3503
3560
  static add(file, onError) {
3504
3561
  return __async(this, null, function* () {
3562
+ let library = null;
3563
+ let alias;
3505
3564
  try {
3565
+ library = yield resolveSoundLibrary();
3566
+ if (!library) {
3567
+ throw new Error("@pixi/sound is not available");
3568
+ }
3569
+ alias = `${SOUND_ALIAS_PREFIX}${soundId++}`;
3570
+ const soundLibrary = library;
3571
+ const soundAlias = alias;
3506
3572
  const task = new Promise((resolve, reject) => {
3507
- const audio = sound.Sound.from({
3573
+ const audio2 = soundLibrary.add(soundAlias, {
3508
3574
  url: file,
3509
3575
  volume: this._volume,
3510
3576
  preload: true,
3511
- loaded: () => {
3512
- if (!(audio.media instanceof sound.webaudio.WebAudioMedia)) {
3577
+ loaded: (error, loadedAudio) => {
3578
+ if (error) {
3579
+ reject(error);
3580
+ return;
3581
+ }
3582
+ const sound = loadedAudio != null ? loadedAudio : audio2;
3583
+ if (!sound) {
3584
+ reject(new Error(`Error: ${file} failed to load`));
3585
+ return;
3586
+ }
3587
+ if (!getAudioBuffer(sound)) {
3513
3588
  reject(new Error(`Error: ${file} is not WebAudioMedia`));
3589
+ return;
3514
3590
  }
3515
- resolve(audio);
3591
+ resolve(sound);
3516
3592
  }
3517
3593
  });
3518
3594
  });
3519
- return yield task;
3595
+ const audio = yield task;
3596
+ this.aliases.set(audio, { alias: soundAlias, library: soundLibrary });
3597
+ this.audios.push(audio);
3598
+ return audio;
3520
3599
  } catch (e) {
3600
+ if (library && alias) {
3601
+ removeSound(library, alias);
3602
+ }
3521
3603
  logger.warn(TAG$2, `Error occurred on "${file}"`, e);
3522
3604
  onError == null ? void 0 : onError(e);
3523
3605
  return null;
@@ -3534,14 +3616,18 @@ var __async = (__this, __arguments, generator) => {
3534
3616
  singleInstance: true,
3535
3617
  complete: () => {
3536
3618
  onFinish == null ? void 0 : onFinish();
3537
- audio.destroy();
3619
+ this.dispose(audio);
3538
3620
  }
3539
3621
  });
3540
3622
  }
3541
3623
  static addAnalyzer(audio, context) {
3542
- const media = audio.media;
3624
+ const buffer = getAudioBuffer(audio);
3625
+ if (!buffer) {
3626
+ logger.warn(TAG$2, "Cannot create audio analyzer because WebAudio media is unavailable.");
3627
+ return void 0;
3628
+ }
3543
3629
  const source = context.createBufferSource();
3544
- source.buffer = media.buffer;
3630
+ source.buffer = buffer;
3545
3631
  const analyser = context.createAnalyser();
3546
3632
  analyser.fftSize = config.fftSize;
3547
3633
  analyser.minDecibels = -90;
@@ -3579,7 +3665,18 @@ var __async = (__this, __arguments, generator) => {
3579
3665
  * @param audio - An audio element.
3580
3666
  */
3581
3667
  static dispose(audio) {
3582
- audio.pause();
3668
+ try {
3669
+ audio.pause();
3670
+ } catch (e) {
3671
+ logger.warn(TAG$2, "Failed to pause audio.", e);
3672
+ }
3673
+ const managedSound = this.aliases.get(audio);
3674
+ if (managedSound) {
3675
+ removeSound(managedSound.library, managedSound.alias);
3676
+ this.aliases.delete(audio);
3677
+ } else {
3678
+ destroySound(audio);
3679
+ }
3583
3680
  remove(this.audios, audio);
3584
3681
  }
3585
3682
  /**
@@ -3603,6 +3700,7 @@ var __async = (__this, __arguments, generator) => {
3603
3700
  __publicField(SoundManager, "audios", []);
3604
3701
  __publicField(SoundManager, "analysers", []);
3605
3702
  __publicField(SoundManager, "contexts", []);
3703
+ __publicField(SoundManager, "aliases", /* @__PURE__ */ new WeakMap());
3606
3704
  __publicField(SoundManager, "_volume", VOLUME);
3607
3705
  var MotionPreloadStrategy = /* @__PURE__ */ ((MotionPreloadStrategy2) => {
3608
3706
  MotionPreloadStrategy2["ALL"] = "ALL";
@@ -3787,7 +3885,7 @@ var __async = (__this, __arguments, generator) => {
3787
3885
  * @returns Promise that resolves with true if the sound is playing, false otherwise.
3788
3886
  */
3789
3887
  speak(_0) {
3790
- return __async(this, arguments, function* (sound2, {
3888
+ return __async(this, arguments, function* (sound, {
3791
3889
  volume = VOLUME,
3792
3890
  expression,
3793
3891
  resetExpression = true,
@@ -3804,16 +3902,16 @@ var __async = (__this, __arguments, generator) => {
3804
3902
  }
3805
3903
  }
3806
3904
  let soundURL;
3807
- const isBase64Content = sound2 && sound2.startsWith("data:");
3808
- if (sound2 && !isBase64Content) {
3905
+ const isBase64Content = sound && sound.startsWith("data:");
3906
+ if (sound && !isBase64Content) {
3809
3907
  const A = document.createElement("a");
3810
- A.href = sound2;
3811
- sound2 = A.href;
3812
- soundURL = sound2;
3908
+ A.href = sound;
3909
+ sound = A.href;
3910
+ soundURL = sound;
3813
3911
  } else {
3814
3912
  soundURL = "data:audio/";
3815
3913
  }
3816
- const file = sound2;
3914
+ const file = sound;
3817
3915
  if (file) {
3818
3916
  try {
3819
3917
  audio = yield SoundManager.add(file, (e, that = this) => {
@@ -3824,6 +3922,9 @@ var __async = (__this, __arguments, generator) => {
3824
3922
  }
3825
3923
  that.currentAudio = void 0;
3826
3924
  });
3925
+ if (!audio) {
3926
+ return false;
3927
+ }
3827
3928
  this.initializeAudio(audio, volume);
3828
3929
  } catch (e) {
3829
3930
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
@@ -3873,17 +3974,19 @@ var __async = (__this, __arguments, generator) => {
3873
3974
  * @param onFinish - Callback when playback finishes.
3874
3975
  * @param onError - Callback when playback errors.
3875
3976
  * @param ignoreParamIds - The ids to be ignored.
3977
+ * @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
3876
3978
  * @return Promise that resolves with true if the motion is successfully started, false otherwise.
3877
3979
  */
3878
3980
  startMotion(_0, _1) {
3879
3981
  return __async(this, arguments, function* (group, index, priority = MotionPriority.NORMAL, {
3880
- sound: sound2 = void 0,
3982
+ sound = void 0,
3881
3983
  volume = VOLUME,
3882
3984
  expression = void 0,
3883
3985
  resetExpression = true,
3884
3986
  onFinish,
3885
3987
  onError,
3886
- ignoreParamIds = []
3988
+ ignoreParamIds = [],
3989
+ loop = void 0
3887
3990
  } = {}) {
3888
3991
  if (this.destroyed) {
3889
3992
  return false;
@@ -3905,12 +4008,12 @@ var __async = (__this, __arguments, generator) => {
3905
4008
  }
3906
4009
  let audio;
3907
4010
  let soundURL;
3908
- const isBase64Content = sound2 && sound2.startsWith("data:");
3909
- if (sound2 && !isBase64Content) {
4011
+ const isBase64Content = sound && sound.startsWith("data:");
4012
+ if (sound && !isBase64Content) {
3910
4013
  const A = document.createElement("a");
3911
- A.href = sound2;
3912
- sound2 = A.href;
3913
- soundURL = sound2;
4014
+ A.href = sound;
4015
+ sound = A.href;
4016
+ soundURL = sound;
3914
4017
  } else {
3915
4018
  soundURL = this.getSoundFile(definition);
3916
4019
  if (soundURL) {
@@ -3928,7 +4031,9 @@ var __async = (__this, __arguments, generator) => {
3928
4031
  }
3929
4032
  that.currentAudio = void 0;
3930
4033
  });
3931
- this.initializeAudio(audio, volume);
4034
+ if (audio) {
4035
+ this.initializeAudio(audio, volume);
4036
+ }
3932
4037
  } catch (e) {
3933
4038
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
3934
4039
  }
@@ -3966,7 +4071,7 @@ var __async = (__this, __arguments, generator) => {
3966
4071
  }
3967
4072
  this.playing = true;
3968
4073
  if (motion) {
3969
- this._startMotion(motion, void 0, ignoreParamIds);
4074
+ this._startMotion(motion, void 0, ignoreParamIds, loop);
3970
4075
  }
3971
4076
  return true;
3972
4077
  });
@@ -3982,16 +4087,18 @@ var __async = (__this, __arguments, generator) => {
3982
4087
  * @param crossOrigin - Cross origin setting.
3983
4088
  * @param onFinish - Callback when playback finishes.
3984
4089
  * @param onError - Callback when playback errors.
4090
+ * @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
3985
4091
  * @return Promise that resolves with true if the motion is successfully started, false otherwise.
3986
4092
  */
3987
4093
  startRandomMotion(_0, _1) {
3988
4094
  return __async(this, arguments, function* (group, priority, {
3989
- sound: sound2,
4095
+ sound,
3990
4096
  volume = VOLUME,
3991
4097
  expression,
3992
4098
  resetExpression = true,
3993
4099
  onFinish,
3994
- onError
4100
+ onError,
4101
+ loop = void 0
3995
4102
  } = {}) {
3996
4103
  var _a, _b;
3997
4104
  if (this.destroyed) {
@@ -4009,12 +4116,13 @@ var __async = (__this, __arguments, generator) => {
4009
4116
  if (availableIndices.length) {
4010
4117
  const index = availableIndices[Math.floor(Math.random() * availableIndices.length)];
4011
4118
  return this.startMotion(group, index, priority, {
4012
- sound: sound2,
4119
+ sound,
4013
4120
  volume,
4014
4121
  expression,
4015
4122
  resetExpression,
4016
4123
  onFinish,
4017
- onError
4124
+ onError,
4125
+ loop
4018
4126
  });
4019
4127
  }
4020
4128
  }
@@ -4133,6 +4241,118 @@ var __async = (__this, __arguments, generator) => {
4133
4241
  return definition;
4134
4242
  }
4135
4243
  }
4244
+ function setScale(matrix, scale) {
4245
+ matrix.a = scale;
4246
+ matrix.b = 0;
4247
+ matrix.c = 0;
4248
+ matrix.d = scale;
4249
+ }
4250
+ function getLayoutEntries(rawLayout) {
4251
+ const entries = [];
4252
+ for (const [key, value] of Object.entries(rawLayout)) {
4253
+ if (typeof value !== "number") {
4254
+ continue;
4255
+ }
4256
+ entries.push([key, value]);
4257
+ }
4258
+ return entries;
4259
+ }
4260
+ function setupLayoutMatrix(matrix, originalWidth, originalHeight, rawLayout) {
4261
+ var _a, _b;
4262
+ const layout = __spreadValues({
4263
+ width: LOGICAL_WIDTH,
4264
+ height: LOGICAL_HEIGHT
4265
+ }, rawLayout);
4266
+ const layoutWidth = (_a = layout.width) != null ? _a : LOGICAL_WIDTH;
4267
+ const layoutHeight = (_b = layout.height) != null ? _b : LOGICAL_HEIGHT;
4268
+ matrix.identity();
4269
+ matrix.scale(layoutWidth / LOGICAL_WIDTH, layoutHeight / LOGICAL_HEIGHT);
4270
+ const width = originalWidth * matrix.a;
4271
+ const height = originalHeight * matrix.d;
4272
+ const offsetX = layout.x !== void 0 && layout.x - layoutWidth / 2 || layout.centerX !== void 0 && layout.centerX || layout.left !== void 0 && layout.left - layoutWidth / 2 || layout.right !== void 0 && layout.right + layoutWidth / 2 || 0;
4273
+ const offsetY = layout.y !== void 0 && layout.y - layoutHeight / 2 || layout.centerY !== void 0 && layout.centerY || layout.top !== void 0 && layout.top - layoutHeight / 2 || layout.bottom !== void 0 && layout.bottom + layoutHeight / 2 || 0;
4274
+ matrix.translate(width * offsetX, -height * offsetY);
4275
+ return {
4276
+ width,
4277
+ height
4278
+ };
4279
+ }
4280
+ function getCubismLayoutWidth(state, aspect) {
4281
+ return LOGICAL_HEIGHT * aspect * state.scale;
4282
+ }
4283
+ function getCubismLayoutHeight(state) {
4284
+ return LOGICAL_HEIGHT * state.scale;
4285
+ }
4286
+ function setCubismWidth(state, aspect, width) {
4287
+ state.scale = width / (LOGICAL_HEIGHT * aspect);
4288
+ }
4289
+ function setCubismHeight(state, height) {
4290
+ state.scale = height / LOGICAL_HEIGHT;
4291
+ }
4292
+ function setCubismX(state, x) {
4293
+ state.x = x;
4294
+ }
4295
+ function setCubismY(state, y) {
4296
+ state.y = y;
4297
+ }
4298
+ function centerCubismX(state, aspect, x) {
4299
+ setCubismX(state, x - getCubismLayoutWidth(state, aspect) / 2);
4300
+ }
4301
+ function centerCubismY(state, y) {
4302
+ setCubismY(state, y - getCubismLayoutHeight(state) / 2);
4303
+ }
4304
+ function rightCubism(state, aspect, x) {
4305
+ setCubismX(state, x - getCubismLayoutWidth(state, aspect));
4306
+ }
4307
+ function bottomCubism(state, y) {
4308
+ setCubismY(state, y - getCubismLayoutHeight(state));
4309
+ }
4310
+ function setupCubismLayoutMatrix(matrix, originalWidth, originalHeight, rawLayout) {
4311
+ if (originalWidth <= 0 || originalHeight <= 0) {
4312
+ matrix.identity();
4313
+ return { width: 0, height: 0 };
4314
+ }
4315
+ const entries = getLayoutEntries(rawLayout);
4316
+ const aspect = originalWidth / originalHeight;
4317
+ const state = { scale: 1, x: 0, y: 0 };
4318
+ for (const [key, value] of entries) {
4319
+ if (key === "width") {
4320
+ setCubismWidth(state, aspect, value);
4321
+ } else if (key === "height") {
4322
+ setCubismHeight(state, value);
4323
+ }
4324
+ }
4325
+ for (const [key, value] of entries) {
4326
+ if (key === "x") {
4327
+ setCubismX(state, value);
4328
+ } else if (key === "y") {
4329
+ setCubismY(state, value);
4330
+ } else if (key === "centerX") {
4331
+ centerCubismX(state, aspect, value);
4332
+ } else if (key === "centerY") {
4333
+ centerCubismY(state, value);
4334
+ } else if (key === "top") {
4335
+ setCubismY(state, value);
4336
+ } else if (key === "bottom") {
4337
+ bottomCubism(state, value);
4338
+ } else if (key === "left") {
4339
+ setCubismX(state, value);
4340
+ } else if (key === "right") {
4341
+ rightCubism(state, aspect, value);
4342
+ }
4343
+ }
4344
+ const pixelsPerLogicalUnit = originalHeight / LOGICAL_HEIGHT;
4345
+ const defaultLogicalHalfWidth = LOGICAL_HEIGHT * aspect / 2;
4346
+ const defaultLogicalHalfHeight = LOGICAL_HEIGHT / 2;
4347
+ matrix.identity();
4348
+ setScale(matrix, state.scale);
4349
+ matrix.tx = pixelsPerLogicalUnit * (state.x + defaultLogicalHalfWidth) - originalWidth * state.scale / 2;
4350
+ matrix.ty = pixelsPerLogicalUnit * (defaultLogicalHalfHeight - state.y) - originalHeight * state.scale / 2;
4351
+ return {
4352
+ width: originalWidth * state.scale,
4353
+ height: originalHeight * state.scale
4354
+ };
4355
+ }
4136
4356
  function normalizeHitAreaDefs(raw, resolveIndex) {
4137
4357
  if (!Array.isArray(raw)) {
4138
4358
  return [];
@@ -4222,19 +4442,14 @@ var __async = (__this, __arguments, generator) => {
4222
4442
  const size = this.getSize();
4223
4443
  self2.originalWidth = size[0];
4224
4444
  self2.originalHeight = size[1];
4225
- const layout = Object.assign(
4226
- {
4227
- width: LOGICAL_WIDTH,
4228
- height: LOGICAL_HEIGHT
4229
- },
4445
+ const bounds = setupLayoutMatrix(
4446
+ this.localTransform,
4447
+ this.originalWidth,
4448
+ this.originalHeight,
4230
4449
  this.getLayout()
4231
4450
  );
4232
- this.localTransform.scale(layout.width / LOGICAL_WIDTH, layout.height / LOGICAL_HEIGHT);
4233
- self2.width = this.originalWidth * this.localTransform.a;
4234
- self2.height = this.originalHeight * this.localTransform.d;
4235
- const offsetX = layout.x !== void 0 && layout.x - layout.width / 2 || layout.centerX !== void 0 && layout.centerX || layout.left !== void 0 && layout.left - layout.width / 2 || layout.right !== void 0 && layout.right + layout.width / 2 || 0;
4236
- const offsetY = layout.y !== void 0 && layout.y - layout.height / 2 || layout.centerY !== void 0 && layout.centerY || layout.top !== void 0 && layout.top - layout.height / 2 || layout.bottom !== void 0 && layout.bottom + layout.height / 2 || 0;
4237
- this.localTransform.translate(this.width * offsetX, -this.height * offsetY);
4451
+ self2.width = bounds.width;
4452
+ self2.height = bounds.height;
4238
4453
  }
4239
4454
  /**
4240
4455
  * Sets up the hit areas by their definitions in settings.
@@ -5750,34 +5965,38 @@ var __async = (__this, __arguments, generator) => {
5750
5965
  * @param [options.resetExpression=true] - Reset the expression to default after the motion is finished.
5751
5966
  * @param [options.onFinish] - Callback function when speaking completes.
5752
5967
  * @param [options.onError] - Callback function when an error occurs.
5968
+ * @param [options.loop] - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
5753
5969
  * @return Promise that resolves with true if the motion is successfully started, with false otherwise.
5754
5970
  */
5755
5971
  motion(_0, _1, _2) {
5756
5972
  return __async(this, arguments, function* (group, index, priority, {
5757
- sound: sound2 = void 0,
5973
+ sound = void 0,
5758
5974
  volume = VOLUME,
5759
5975
  expression = void 0,
5760
5976
  resetExpression = true,
5761
5977
  onFinish,
5762
- onError
5978
+ onError,
5979
+ loop = void 0
5763
5980
  } = {}) {
5764
5981
  if (index === void 0) {
5765
5982
  return this.internalModel.motionManager.startRandomMotion(group, priority, {
5766
- sound: sound2,
5983
+ sound,
5767
5984
  volume,
5768
5985
  expression,
5769
5986
  resetExpression,
5770
5987
  onFinish,
5771
- onError
5988
+ onError,
5989
+ loop
5772
5990
  });
5773
5991
  } else {
5774
5992
  return this.internalModel.motionManager.startMotion(group, index, priority, {
5775
- sound: sound2,
5993
+ sound,
5776
5994
  volume,
5777
5995
  expression,
5778
5996
  resetExpression,
5779
5997
  onFinish,
5780
- onError
5998
+ onError,
5999
+ loop
5781
6000
  });
5782
6001
  }
5783
6002
  });
@@ -5855,14 +6074,14 @@ var __async = (__this, __arguments, generator) => {
5855
6074
  * @param [options.onError] - Callback function when an error occurs.
5856
6075
  * @returns Promise that resolves with true if the sound is playing, false if it's not.
5857
6076
  */
5858
- speak(sound2, {
6077
+ speak(sound, {
5859
6078
  volume = VOLUME,
5860
6079
  expression,
5861
6080
  resetExpression = true,
5862
6081
  onFinish,
5863
6082
  onError
5864
6083
  } = {}) {
5865
- return this.internalModel.motionManager.speak(sound2, {
6084
+ return this.internalModel.motionManager.speak(sound, {
5866
6085
  volume,
5867
6086
  expression,
5868
6087
  resetExpression,
@@ -8636,8 +8855,9 @@ var __async = (__this, __arguments, generator) => {
8636
8855
  isFinished() {
8637
8856
  return this.queueManager.isFinished();
8638
8857
  }
8639
- _startMotion(motion, onFinish, ignoreParamIds) {
8858
+ _startMotion(motion, onFinish, ignoreParamIds, loop) {
8640
8859
  motion.setFinishedMotionHandler(onFinish);
8860
+ motion.setLoop(loop != null ? loop : motion._motionData.loop);
8641
8861
  if (ignoreParamIds && ignoreParamIds.length > 0) {
8642
8862
  const curves = motion._motionData.curves;
8643
8863
  const filtered = createCurveContainer$1(curves);
@@ -8671,6 +8891,7 @@ var __async = (__this, __arguments, generator) => {
8671
8891
  shouldCheckMotionConsistency
8672
8892
  );
8673
8893
  const json = new CubismMotionJson(data, data.byteLength);
8894
+ motion.setLoop(json.isMotionLoop());
8674
8895
  const defaultFadingDuration = (group === this.groups.idle ? config.idleMotionFadingDuration : config.motionFadingDuration) / 1e3;
8675
8896
  if (json.getMotionFadeInTime() === void 0) {
8676
8897
  motion.setFadeInTime(
@@ -8898,8 +9119,9 @@ var __async = (__this, __arguments, generator) => {
8898
9119
  isFinished() {
8899
9120
  return this.queueManager.isFinished();
8900
9121
  }
8901
- _startMotion(motion, onFinish, ignoreParamIds) {
9122
+ _startMotion(motion, onFinish, ignoreParamIds, loop) {
8902
9123
  motion.setFinishedMotionHandler(onFinish);
9124
+ motion.setLoop(loop != null ? loop : motion._motionData.loop);
8903
9125
  if (ignoreParamIds && ignoreParamIds.length > 0) {
8904
9126
  const curves = motion._motionData.curves;
8905
9127
  const filtered = createCurveContainer(curves);
@@ -11359,6 +11581,30 @@ var __async = (__this, __arguments, generator) => {
11359
11581
  const HIGH_PRECISION_MASK_MASKED_VERTEX_THRESHOLD = 4096;
11360
11582
  const HIGH_PRECISION_MASK_VERTEX_RATIO_THRESHOLD = 0.5;
11361
11583
  const HIGH_PRECISION_MASK_VERTEX_RATIO_DRAWABLE_THRESHOLD = 24;
11584
+ const layoutKeyMap = {
11585
+ CenterX: "centerX",
11586
+ centerX: "centerX",
11587
+ center_x: "centerX",
11588
+ CenterY: "centerY",
11589
+ centerY: "centerY",
11590
+ center_y: "centerY",
11591
+ X: "x",
11592
+ x: "x",
11593
+ Y: "y",
11594
+ y: "y",
11595
+ Width: "width",
11596
+ width: "width",
11597
+ Height: "height",
11598
+ height: "height",
11599
+ Top: "top",
11600
+ top: "top",
11601
+ Bottom: "bottom",
11602
+ bottom: "bottom",
11603
+ Left: "left",
11604
+ left: "left",
11605
+ Right: "right",
11606
+ right: "right"
11607
+ };
11362
11608
  function getRequiredMaskRenderTextureCount(model) {
11363
11609
  var _a;
11364
11610
  if (!model.isUsingMasking()) {
@@ -11479,7 +11725,7 @@ var __async = (__this, __arguments, generator) => {
11479
11725
  var _a;
11480
11726
  super.init();
11481
11727
  const eyeBlinkParameters = this.settings.getEyeBlinkParameters();
11482
- if (eyeBlinkParameters.length) {
11728
+ if (this.options.eyeBlink !== false && eyeBlinkParameters.length) {
11483
11729
  const parameterIds = new csmVector();
11484
11730
  for (const parameter of eyeBlinkParameters) {
11485
11731
  parameterIds.pushBack(this.idManager.getId(parameter));
@@ -11541,16 +11787,29 @@ var __async = (__this, __arguments, generator) => {
11541
11787
  const settingsLayout = this.settings.layout;
11542
11788
  if (settingsLayout) {
11543
11789
  for (const [key, value] of Object.entries(settingsLayout)) {
11544
- const commonKey = key.charAt(0).toLowerCase() + key.slice(1);
11545
- layout[commonKey] = value;
11790
+ const commonKey = layoutKeyMap[key];
11791
+ if (commonKey && typeof value === "number") {
11792
+ layout[commonKey] = value;
11793
+ }
11546
11794
  }
11547
11795
  }
11548
11796
  return layout;
11549
11797
  }
11550
11798
  setupLayout() {
11551
- super.setupLayout();
11552
- this.pixelsPerUnit = this.coreModel.getModel().canvasinfo.PixelsPerUnit;
11553
- this.modelTransform.scale(this.pixelsPerUnit, this.pixelsPerUnit).translate(this.originalWidth / 2, this.originalHeight / 2);
11799
+ const self2 = this;
11800
+ const size = this.getSize();
11801
+ self2.originalWidth = size[0];
11802
+ self2.originalHeight = size[1];
11803
+ self2.pixelsPerUnit = this.coreModel.getModel().canvasinfo.PixelsPerUnit;
11804
+ const bounds = setupCubismLayoutMatrix(
11805
+ this.localTransform,
11806
+ this.originalWidth,
11807
+ this.originalHeight,
11808
+ this.getLayout()
11809
+ );
11810
+ self2.width = bounds.width;
11811
+ self2.height = bounds.height;
11812
+ this.modelTransform.identity().scale(this.pixelsPerUnit, this.pixelsPerUnit).translate(this.originalWidth / 2, this.originalHeight / 2);
11554
11813
  }
11555
11814
  updateWebGLContext(gl, glContextID) {
11556
11815
  this.renderer.firstDraw = true;
@@ -12482,18 +12741,26 @@ var __async = (__this, __arguments, generator) => {
12482
12741
  parameters.push(id.getString().s);
12483
12742
  }
12484
12743
  }
12485
- } else if (Array.isArray(this.json.Groups)) {
12744
+ } else {
12745
+ let hasEyeBlinkGroup = false;
12486
12746
  const groups = this.json.Groups;
12487
- for (const group of groups) {
12488
- if ((group == null ? void 0 : group.Name) !== "EyeBlink" || !Array.isArray(group.Ids)) continue;
12489
- for (const entry of group.Ids) {
12490
- if (typeof entry === "string") {
12491
- parameters.push(entry);
12492
- } else if (entry == null ? void 0 : entry.Id) {
12493
- parameters.push(entry.Id);
12747
+ if (Array.isArray(groups)) {
12748
+ for (const group of groups) {
12749
+ if ((group == null ? void 0 : group.Name) !== "EyeBlink") continue;
12750
+ hasEyeBlinkGroup = true;
12751
+ if (!Array.isArray(group.Ids)) continue;
12752
+ for (const entry of group.Ids) {
12753
+ if (typeof entry === "string") {
12754
+ parameters.push(entry);
12755
+ } else if (entry == null ? void 0 : entry.Id) {
12756
+ parameters.push(entry.Id);
12757
+ }
12494
12758
  }
12495
12759
  }
12496
12760
  }
12761
+ if (hasEyeBlinkGroup) {
12762
+ return parameters;
12763
+ }
12497
12764
  }
12498
12765
  return parameters.length ? parameters : [...defaultEyeBlinkParameters];
12499
12766
  }