@kubohiroya/turbowarp-bubble 0.3.0 → 0.4.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/README.md CHANGED
@@ -34,7 +34,7 @@ flowchart LR
34
34
 
35
35
  | 領域 | このREADMEで説明する内容 | 現在の公開API |
36
36
  | ----------------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------- |
37
- | 文字描画・改行 | 名前付きstyle、実測幅、`maxWidth`、UAX #14準拠の改行 | 実装済み(SVG Text capability) |
37
+ | 文字描画・改行 | `BubbleTextCapability`、名前付きstyle、実測幅、`maxWidth`、UAX #14準拠の改行 | 実装済み(TurboWarpではSVG Text adapterを標準接続) |
38
38
  | 逐次表示 | `CHARACTER`/`WORD`/`LINE`/`BLOCK`、区切り文字、単位ごとの効果音、finish条件 | 実装済み(`revealNext`/`revealAll`/`finish`、対応ブロック) |
39
39
  | portrait | ベース画像、`blink`、`lip-sync`の独立レイヤー | 実装済み(Asset Manager capability) |
40
40
  | Bubble外形 | `NORMAL`等のvisual style、placement、tail、offset、scale | 実装済み |
@@ -49,22 +49,25 @@ flowchart LR
49
49
 
50
50
  ```mermaid
51
51
  flowchart TB
52
- core[Bubble composition\n外形・配置・ライフサイクル・animation state]
53
- adapter[TurboWarp adapter\nrenderer / runtime / targetへの接続]
54
- text[SVG Text provider\n文字skin・計測・named style]
55
- image[Image capability\nportrait・blink・lip-sync・continue画像]
56
- audio[Audio capability\nvoice・表示単位ごとの効果音]
57
- input[Async Input + Runtime Expression\n入力と待機条件]
58
- extension[TurboWarp extension\nblocks / Scratch target]
59
- adapter --> core
60
- adapter --> text
61
- core -.任意Capability.-> image
62
- core -.任意Capability.-> audio
63
- extension --> core
64
- extension -.optional.-> input
52
+ core["Bubble core\n外形・配置・ライフサイクル・animation state"]
53
+ contract["BubbleTextCapability\nhost-neutralな文字契約"]
54
+ twAdapter["TurboWarp Bubble adapter\nrenderer / runtime / targetへの接続"]
55
+ svgAdapter["SVG Text adapter\nTurboWarpの文字skin・計測"]
56
+ assets["任意のImage / Audio capability\nportrait・lip-sync・音声"]
57
+ input["任意のInput / Expression capability\n入力・待機条件"]
58
+ host["独自Webアプリ / host"]
59
+ extension["TurboWarp extension\nblocks / Scratch target"]
60
+ core -->|"consumes"| contract
61
+ svgAdapter -->|"implements"| contract
62
+ twAdapter -->|"injects"| core
63
+ twAdapter -->|"uses by default"| svgAdapter
64
+ host -->|"injects"| core
65
+ core -."optional".-> assets
66
+ extension --> twAdapter
67
+ extension -."optional".-> input
65
68
  ```
66
69
 
67
- `@kubohiroya/turbowarp-svg-text`は文字のSVG skinと文字幅の測定を担当し、吹き出しの外枠、tail、portraitの配置、表示開始・表示終了animationは担当しません。画像解決、音声再生、入力、条件評価はCapabilityとして切り離し、Asset Manager、Async Input、Runtime Expressionはoptional peer dependencyとして対応機能を使う場合だけ接続します。
70
+ この構成では、Bubble coreが`BubbleTextCapability`というホスト非依存の契約だけを参照します。`@kubohiroya/turbowarp-svg-text`は、その契約をTurboWarpのSVG skin・named style・文字幅計測へ接続するadapterです。吹き出しの外枠、tail、portraitの配置、表示開始・表示終了animationは担当しません。TurboWarp adapterはSVG Text adapterを既定値として解決しますが、Composition APIのhostは別の実装を`textCapability`として注入できます。画像解決、音声再生、入力、条件評価もCapabilityとして切り離し、Asset Manager、Async Input、Runtime Expressionは対応機能を使う場合だけ接続します。
68
71
 
69
72
  ### 逐次表示の単位(CHARACTER / WORD / LINE / BLOCK)
70
73
 
@@ -146,13 +149,14 @@ Asset Managerを音声providerとして接続すると、次の音声を同じ
146
149
  | パッケージ | 責務 |
147
150
  | ------------------------------------------ | ------------------------------------------------------------------------------ |
148
151
  | `@kubohiroya/turbowarp-asset-manager` | 任意のImage/Audio capabilityをTurboWarp assetへ接続(画像解決・音声再生) |
149
- | `@kubohiroya/turbowarp-svg-text` | 名前付き文字styleと、文字列からSVGスキンへの変換 |
152
+ | Bubble core(`composition`) | `BubbleTextCapability`契約、吹き出しsurface、配置、逐次表示、animation |
153
+ | `@kubohiroya/turbowarp-svg-text` | `BubbleTextCapability`をTurboWarpの文字style・SVG skin・計測へ接続するadapter |
150
154
  | `@kubohiroya/turbowarp-async-input` | キー入力・タップをTemporary Variablesのruntime変数へ反映 |
151
155
  | `@kubohiroya/turbowarp-runtime-expression` | runtime変数を参照する安全な待機条件の評価 |
152
156
  | `@kubohiroya/turbowarp-bubble` | 吹き出しsurface、配置、逐次表示、say/think、表情レイヤー、animation、入力待機 |
153
157
  | アプリ/host | 必要に応じたアプリ固有の入力からcomposition APIへの変換 |
154
158
 
155
- Bubbleは依存パッケージを再exportしません。SVG Textは現在の文字描画に必要ですが、画像・音声・入力・条件評価はCapabilityとして差し替えられます。TurboWarp adapterではAsset Managerを自動接続し、Composition APIでは`imageResolver`/`audio`をhostが任意に実装できます。Asset Managerを使う機能は画像だけでなく、フルボイス、タイプライター音、行・段落ごとの効果音などの外部メディアも対象にします。
159
+ Bubbleは依存パッケージを再exportしません。Composition APIは`textCapability`を必須の契約として受け取り、SVG Textに限定されません。TurboWarp adapterだけが`@kubohiroya/turbowarp-svg-text`を既定のadapterとして解決します。画像・音声・入力・条件評価はCapabilityとして差し替えられ、TurboWarp adapterではAsset Managerを遅延接続し、Composition APIでは`imageResolver`/`audio`をhostが任意に実装できます。Asset Managerを使う機能は画像だけでなく、フルボイス、タイプライター音、行・段落ごとの効果音などの外部メディアも対象にします。
156
160
 
157
161
  ### 自動改行と禁則処理の基盤
158
162
 
@@ -193,16 +197,22 @@ standalone機能拡張では、`set bubble visual style`ブロックで形状を
193
197
  ### インストール
194
198
 
195
199
  ```sh
196
- pnpm add @kubohiroya/turbowarp-bubble @kubohiroya/turbowarp-svg-text
200
+ pnpm add @kubohiroya/turbowarp-bubble
197
201
  ```
198
202
 
199
203
  npmを使う場合は同じ依存を次のように追加します。
200
204
 
201
205
  ```sh
202
- npm install @kubohiroya/turbowarp-bubble @kubohiroya/turbowarp-svg-text
206
+ npm install @kubohiroya/turbowarp-bubble
203
207
  ```
204
208
 
205
- 現在のpeer dependency範囲は、SVG Textが`>=0.4.0 <1`、Asset Managerが`>=0.7.0 <1`、Async InputとRuntime Expressionがそれぞれ`>=0.3.0 <1`です。Asset Manager、Async Input、Runtime Expressionはoptional peer dependencyです。
209
+ 現在のpeer dependency範囲は、SVG Textが`>=0.4.0 <1`、Asset Managerが`>=0.7.0 <1`、Async InputとRuntime Expressionがそれぞれ`>=0.3.0 <1`です。4つすべてoptional peer dependencyで、SVG TextはTurboWarp adapterの既定adapterを使う場合だけ必要です。別の`textCapability`を注入するhostはSVG Textをインストールする必要がありません。
210
+
211
+ TurboWarp adapterの既定文字経路を使う場合は、SVG Textを追加します。
212
+
213
+ ```sh
214
+ pnpm add @kubohiroya/turbowarp-svg-text
215
+ ```
206
216
 
207
217
  画像portrait、lip-sync、continue indicator、または音声アセットを使う機能を利用する場合はAsset Managerを追加します。`CONDITION`付きの待機ブロックを使う場合はAsync InputとRuntime Expressionを追加します。
208
218
 
@@ -247,7 +257,7 @@ https://unpkg.com/@kubohiroya/turbowarp-async-input@0.3.0/dist/async-input.js
247
257
  https://unpkg.com/@kubohiroya/turbowarp-runtime-expression@0.3.0/dist/runtime-expression.js
248
258
 
249
259
  # Bubble(必ず最後)
250
- https://unpkg.com/@kubohiroya/turbowarp-bubble@0.3.0/dist/turbowarp-bubble.js
260
+ https://unpkg.com/@kubohiroya/turbowarp-bubble@0.4.0/dist/turbowarp-bubble.js
251
261
  ```
252
262
 
253
263
  TurboWarpのカスタム拡張機能はURLからJavaScriptを読み込むため、初回読み込み時にネットワーク接続が必要です。開発中は、リポジトリをローカルHTTPサーバーで配信して`dist/turbowarp-bubble.js`を指定できます。`file://`で直接開いたファイルや、サンドボックス付きの拡張機能としては動作しません。
@@ -436,23 +446,23 @@ import {
436
446
  createBubbleComposition,
437
447
  type BubbleImageCapability,
438
448
  type BubbleSurfaceFactory,
439
- type BubbleSvgText,
449
+ type BubbleTextCapability,
440
450
  } from "@kubohiroya/turbowarp-bubble/composition";
441
451
 
442
452
  // These are host-owned capabilities. They may be backed by Asset Manager,
443
453
  // another asset service, or local application code.
444
454
  declare const imageResolver: BubbleImageCapability;
445
- declare const svgText: BubbleSvgText;
455
+ declare const textCapability: BubbleTextCapability;
446
456
  declare const bubbleSurfaceHost: BubbleSurfaceFactory;
447
457
 
448
458
  const bubbles = createBubbleComposition({
449
459
  imageResolver,
450
- svgText,
460
+ textCapability,
451
461
  createSurface: bubbleSurfaceHost,
452
462
  });
453
463
  ```
454
464
 
455
- `declare`部分はサンプルを短くするための型宣言です。実際のhostでは、`BubbleSvgText`(文字skinの適用・解放)、`BubbleImageCapability`(画像名の解決)、`BubbleAudioCapability`(音声再生)、`BubbleSurfaceFactory`(外枠・text・portrait各targetの生成)を実装して渡します。TurboWarp runtimeを使う場合は、これらを個別に実装せず`createTurboWarpBubbleComposition(runtime)`を使えます。
465
+ `declare`部分はサンプルを短くするための型宣言です。実際のhostでは、`BubbleTextCapability`(文字skinの適用・計測・解放)、`BubbleImageCapability`(画像名の解決)、`BubbleAudioCapability`(音声再生)、`BubbleSurfaceFactory`(外枠・text・portrait各targetの生成)を実装して渡します。`@kubohiroya/turbowarp-svg-text/composition`を使う場合は、`createSvgTextCompositionCapability(createSvgTextComposition({ runtime }))`で`textCapability`へ変換します。TurboWarp runtimeを使う場合は、これらを個別に実装せず`createTurboWarpBubbleComposition(runtime)`を使えます。
456
466
 
457
467
  テキストだけを表示する場合は、Asset Managerのimport、`createAssetManagerComposition()`、`imageResolver`プロパティをすべて省略できます。Asset Managerは画像だけでなく、フルボイス、タイプライター音、行・段落ごとの効果音を登録・再生するためのメディア経路として利用します。音声付きBubble APIは表示機能と同じ名前付きアセットを使う設計にします。
458
468
 
@@ -460,7 +470,7 @@ const bubbles = createBubbleComposition({
460
470
 
461
471
  surfaceは`updateStyle(style)`も実装し、吹き出しの位置・形状・サイズを更新できるようにします。表示中のBubbleのstyleを変更する場合は、返されたhandleの`updateStyle(style)`を呼び出します。更新後のstyleで画像レイヤーを使う場合、surfaceが対応するtargetをあらかじめ返している必要があります。
462
472
 
463
- - `text`: SVG Textが文字スキンを適用するtarget
473
+ - `text`: `textCapability`が文字スキンを適用するtarget
464
474
  - `portraitBase`: キャラクター表情のベース画像target
465
475
  - `portraitBlink`: 目パチ差分target
466
476
  - `portraitLipSync`: 口パク差分target
@@ -551,7 +561,7 @@ await bubble.finish({
551
561
  await bubble.close();
552
562
  ```
553
563
 
554
- 返されたhandleの`setText(text)`は同じsurface上の本文を更新し、文字送りなどに利用できます。`handle.updateStyle(style)`は表示中のBubbleへstyle変更を即時適用します。同じ`actorKey`へ新しいBubbleを表示すると、以前のBubbleを完全に破棄してから置き換えます。`releaseTarget`、`releaseAll`、`dispose`も、所有するtimer、SVG Text target、surfaceを解放します。composition間で状態は共有しません。
564
+ 返されたhandleの`setText(text)`は同じsurface上の本文を更新し、文字送りなどに利用できます。`handle.updateStyle(style)`は表示中のBubbleへstyle変更を即時適用します。同じ`actorKey`へ新しいBubbleを表示すると、以前のBubbleを完全に破棄してから置き換えます。`releaseTarget`、`releaseAll`、`dispose`も、所有するtimer、text capability target、surfaceを解放します。composition間で状態は共有しません。
555
565
 
556
566
  ## ライセンスとソースコード
557
567
 
@@ -3972,7 +3972,7 @@ function Er(e) {
3972
3972
  "sound"
3973
3973
  ]);
3974
3974
  if (Object.keys(t).filter((e) => !n.has(e)).length > 0 || t.unit === void 0) throw TypeError("Bubble reveal has unknown or missing properties.");
3975
- let r = Tr(t.unit), i = t.delimiters ?? " \\t\\r\\n";
3975
+ let r = Tr(t.unit), i = t.delimiters ?? " \r\n";
3976
3976
  if (typeof i != "string" || i.length === 0) throw TypeError("Bubble WORD delimiters must be a non-empty string.");
3977
3977
  let a = t.showDelimiters ?? !1;
3978
3978
  if (typeof a != "boolean") throw TypeError("Bubble reveal showDelimiters must be boolean.");
@@ -3981,18 +3981,18 @@ function Er(e) {
3981
3981
  let s = t.intervalSeconds ?? 0;
3982
3982
  if (typeof s != "number" || !Number.isFinite(s) || s < 0) throw TypeError("Bubble reveal intervalSeconds must be zero or greater.");
3983
3983
  let c = t.sound;
3984
- if (c !== void 0 && (typeof c != "string" || c.trim() === "")) throw TypeError("Bubble reveal sound must be a non-empty asset name.");
3984
+ if (c !== void 0 && (typeof c != "string" || c.length === 0)) throw TypeError("Bubble reveal sound must be a non-empty asset name.");
3985
3985
  return Object.freeze({
3986
3986
  unit: r,
3987
3987
  delimiters: i,
3988
3988
  showDelimiters: a,
3989
3989
  layout: o,
3990
3990
  intervalSeconds: s,
3991
- ...c === void 0 ? {} : { sound: c.trim() }
3991
+ ...c === void 0 ? {} : { sound: c }
3992
3992
  });
3993
3993
  }
3994
3994
  function Dr(e, t, n) {
3995
- let r = new Set(wr(t)), i = [], a = "";
3995
+ let r = new Set(Array.from(t)), i = [], a = "";
3996
3996
  for (let t of wr(e)) a += t, r.has(t) && ((n || a.slice(0, -t.length).length > 0) && i.push(n ? a : a.slice(0, -t.length)), a = "");
3997
3997
  return a.length > 0 && i.push(a), i.filter((e) => e.length > 0);
3998
3998
  }
@@ -4061,27 +4061,31 @@ function $(e, t) {
4061
4061
  if (typeof e != "string" || e.trim().length === 0) throw new Z("BUBBLE-COMPOSITION-001", `${t} must be a non-empty string.`);
4062
4062
  return e.trim();
4063
4063
  }
4064
- function Fr(e, t, n) {
4064
+ function Fr(e, t) {
4065
+ if (typeof e != "string" || e.length === 0) throw new Z("BUBBLE-COMPOSITION-001", `${t} must be a non-empty string.`);
4066
+ return e;
4067
+ }
4068
+ function Ir(e, t, n) {
4065
4069
  if (!Q(e)) throw new Z("BUBBLE-COMPOSITION-001", `${t} must be an object.`);
4066
4070
  if (Pr(e, ["frames", "frameIntervalSeconds"], [], t), !Array.isArray(e.frames) || e.frames.length < n) throw new Z("BUBBLE-COMPOSITION-001", `${t}.frames must contain at least ${n} image asset name${n === 1 ? "" : "s"}.`);
4067
- let r = Object.freeze(e.frames.map((e, n) => $(e, `${t}.frames[${n}]`))), i = e.frameIntervalSeconds;
4071
+ let r = Object.freeze(e.frames.map((e, n) => Fr(e, `${t}.frames[${n}]`))), i = e.frameIntervalSeconds;
4068
4072
  if (typeof i != "number" || !Number.isFinite(i) || i <= 0) throw new Z("BUBBLE-COMPOSITION-001", `${t}.frameIntervalSeconds must be a positive finite number.`);
4069
4073
  return Object.freeze({
4070
4074
  frames: r,
4071
4075
  frameIntervalSeconds: i
4072
4076
  });
4073
4077
  }
4074
- function Ir(e) {
4078
+ function Lr(e) {
4075
4079
  if (!Q(e)) throw new Z("BUBBLE-COMPOSITION-001", "Bubble portrait must be an object.");
4076
4080
  Pr(e, ["base"], ["blink", "lipSync"], "Bubble portrait");
4077
- let t = e.blink === void 0 ? void 0 : Fr(e.blink, "Bubble portrait blink", 1), n = e.lipSync === void 0 ? void 0 : Fr(e.lipSync, "Bubble portrait lip-sync", 1);
4081
+ let t = e.blink === void 0 ? void 0 : Ir(e.blink, "Bubble portrait blink", 1), n = e.lipSync === void 0 ? void 0 : Ir(e.lipSync, "Bubble portrait lip-sync", 1);
4078
4082
  return Object.freeze({
4079
- base: $(e.base, "Bubble portrait base"),
4083
+ base: Fr(e.base, "Bubble portrait base"),
4080
4084
  ...t === void 0 ? {} : { blink: t },
4081
4085
  ...n === void 0 ? {} : { lipSync: n }
4082
4086
  });
4083
4087
  }
4084
- function Lr(e, t) {
4088
+ function Rr(e, t) {
4085
4089
  if (!Q(e)) throw new Z("BUBBLE-COMPOSITION-001", `${t} must be an object.`);
4086
4090
  if (Pr(e, ["name"], [
4087
4091
  "durationSeconds",
@@ -4115,7 +4119,7 @@ function Lr(e, t) {
4115
4119
  ...l === void 0 ? {} : { visualStyle: l }
4116
4120
  });
4117
4121
  }
4118
- function Rr(e) {
4122
+ function zr(e) {
4119
4123
  if (e === void 0) return;
4120
4124
  if (!Q(e)) throw new Z("BUBBLE-COMPOSITION-001", "Bubble audio must be an object.");
4121
4125
  Pr(e, [], [
@@ -4130,11 +4134,11 @@ function Rr(e) {
4130
4134
  "finish"
4131
4135
  ]) {
4132
4136
  let r = e[n];
4133
- r !== void 0 && (t[n] = $(r, `Bubble audio ${n}`));
4137
+ r !== void 0 && (t[n] = Fr(r, `Bubble audio ${n}`));
4134
4138
  }
4135
4139
  return Object.freeze(t);
4136
4140
  }
4137
- function zr(e) {
4141
+ function Br(e) {
4138
4142
  if (!Q(e)) throw new Z("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
4139
4143
  Pr(e, ["name", "textStyle"], [
4140
4144
  "placement",
@@ -4151,13 +4155,13 @@ function zr(e) {
4151
4155
  "showAnimation",
4152
4156
  "hideAnimation"
4153
4157
  ], "Bubble style");
4154
- let t = e.portrait === void 0 ? void 0 : Ir(e.portrait), n = e.continueIndicator === void 0 ? void 0 : Fr(e.continueIndicator, "Bubble continue indicator", 2), r;
4158
+ let t = e.portrait === void 0 ? void 0 : Lr(e.portrait), n = e.continueIndicator === void 0 ? void 0 : Ir(e.continueIndicator, "Bubble continue indicator", 2), r;
4155
4159
  if (e.reveal !== void 0) try {
4156
4160
  r = Er(e.reveal);
4157
4161
  } catch (e) {
4158
4162
  throw new Z("BUBBLE-COMPOSITION-001", e instanceof Error ? e.message : "Bubble reveal is invalid.");
4159
4163
  }
4160
- let i = Rr(e.audio), a = e.showAnimation === void 0 ? void 0 : Lr(e.showAnimation, "Bubble showAnimation"), o = e.hideAnimation === void 0 ? void 0 : Lr(e.hideAnimation, "Bubble hideAnimation"), s;
4164
+ let i = zr(e.audio), a = e.showAnimation === void 0 ? void 0 : Rr(e.showAnimation, "Bubble showAnimation"), o = e.hideAnimation === void 0 ? void 0 : Rr(e.hideAnimation, "Bubble hideAnimation"), s;
4161
4165
  try {
4162
4166
  s = y(e.placement ?? "up-right");
4163
4167
  } catch (e) {
@@ -4195,13 +4199,13 @@ function zr(e) {
4195
4199
  ...o === void 0 ? {} : { hideAnimation: o }
4196
4200
  });
4197
4201
  }
4198
- function Br(e) {
4202
+ function Vr(e) {
4199
4203
  if (e !== void 0) {
4200
4204
  if (!Q(e) || typeof e.applyToTarget != "function" || typeof e.getMimeType != "function" || typeof e.isRegistered != "function") throw TypeError("Bubble image capability must provide applyToTarget, getMimeType, and isRegistered.");
4201
4205
  return e;
4202
4206
  }
4203
4207
  }
4204
- function Vr(e) {
4208
+ function Hr(e) {
4205
4209
  if (e !== void 0) {
4206
4210
  if (!Q(e) || typeof e.playSound != "function") throw TypeError("Bubble audio capability must provide playSound.");
4207
4211
  if (e.isRegistered !== void 0 && typeof e.isRegistered != "function") throw TypeError("Bubble audio capability isRegistered must be a function.");
@@ -4209,64 +4213,64 @@ function Vr(e) {
4209
4213
  return e;
4210
4214
  }
4211
4215
  }
4212
- function Hr(e) {
4216
+ function Ur(e) {
4213
4217
  if (e === void 0) throw new Z("BUBBLE-COMPOSITION-006", "Bubble image assets require an image capability. Provide options.imageResolver.");
4214
4218
  return e;
4215
4219
  }
4216
- function Ur(e) {
4217
- if (!Q(e) || typeof e.setText != "function" || typeof e.releaseTarget != "function") throw TypeError("Bubble SVG Text composition must provide setText and releaseTarget.");
4220
+ function Wr(e) {
4221
+ if (!Q(e) || typeof e.setText != "function" || typeof e.releaseTarget != "function") throw TypeError("Bubble text capability must provide setText and releaseTarget.");
4218
4222
  return e;
4219
4223
  }
4220
- function Wr() {
4224
+ function Gr() {
4221
4225
  return Object.freeze({
4222
4226
  setTimeout: (e, t) => globalThis.setTimeout(e, t),
4223
4227
  clearTimeout: (e) => globalThis.clearTimeout(e)
4224
4228
  });
4225
4229
  }
4226
- function Gr(e) {
4230
+ function Kr(e) {
4227
4231
  if (!Q(e) || typeof e.setTimeout != "function" || typeof e.clearTimeout != "function") throw TypeError("Bubble scheduler must provide setTimeout and clearTimeout.");
4228
4232
  return e;
4229
4233
  }
4230
- function Kr(e, t) {
4234
+ function qr(e, t) {
4231
4235
  if (!Q(e) || typeof e.id != "string" || e.id.length === 0 || typeof e.isStage != "boolean") throw new Z("BUBBLE-COMPOSITION-004", `${t} must provide id and isStage.`);
4232
4236
  return e;
4233
4237
  }
4234
- function qr(e) {
4235
- if (!Q(e) || typeof e.drawableID != "number" || !Number.isInteger(e.drawableID) || e.drawableID < 0) throw new Z("BUBBLE-COMPOSITION-004", "Bubble text target must provide a non-negative integer drawableID.");
4238
+ function Jr(e) {
4239
+ if (typeof e != "object" || !e) throw new Z("BUBBLE-COMPOSITION-004", "Bubble text target must be a non-null object.");
4236
4240
  return e;
4237
4241
  }
4238
- function Jr(e, t) {
4242
+ function Yr(e, t) {
4239
4243
  if (!Q(e) || !Q(e.targets) || typeof e.setLayerVisible != "function" || typeof e.updateStyle != "function" || typeof e.show != "function" || typeof e.hide != "function" || typeof e.dispose != "function") throw new Z("BUBBLE-COMPOSITION-004", "Bubble surface is invalid.");
4240
4244
  let n = e.targets;
4241
- qr(n.text);
4245
+ Jr(n.text);
4242
4246
  let r = /* @__PURE__ */ new Set(), i = (e, t) => {
4243
4247
  let i = n[e];
4244
4248
  if (!t && i === void 0) return;
4245
- let a = Kr(i, `Bubble surface ${e}`);
4249
+ let a = qr(i, `Bubble surface ${e}`);
4246
4250
  if (r.has(a.id)) throw new Z("BUBBLE-COMPOSITION-004", "Bubble image layers must use distinct target IDs.");
4247
4251
  r.add(a.id);
4248
4252
  };
4249
4253
  return i("portraitBase", t.portrait !== void 0), i("portraitBlink", t.portrait?.blink !== void 0), i("portraitLipSync", t.portrait?.lipSync !== void 0), i("continueIndicator", t.continueIndicator !== void 0), e;
4250
4254
  }
4251
- function Yr(e, t) {
4255
+ function Xr(e, t) {
4252
4256
  if (e === void 0) throw new Z("BUBBLE-COMPOSITION-006", `Bubble image capability is required for: ${t}. Provide options.imageResolver.`);
4253
4257
  if (!e.isRegistered(t)) throw new Z("BUBBLE-COMPOSITION-003", `Bubble image asset is not registered: ${t}`);
4254
4258
  if (!e.getMimeType(t).startsWith("image/")) throw new Z("BUBBLE-COMPOSITION-003", `Bubble asset is not an image: ${t}`);
4255
4259
  }
4256
- function Xr(e, t) {
4260
+ function Zr(e, t) {
4257
4261
  if (e === void 0) throw new Z("BUBBLE-COMPOSITION-006", `Bubble audio assets require an audio capability: ${t}. Provide options.audio.`);
4258
4262
  if (e.isRegistered?.(t) === !1) throw new Z("BUBBLE-COMPOSITION-003", `Bubble audio asset is not registered: ${t}`);
4259
4263
  let n = e.getMimeType?.(t);
4260
4264
  if (n !== void 0 && !n.startsWith("audio/")) throw new Z("BUBBLE-COMPOSITION-003", `Bubble asset is not audio: ${t}`);
4261
4265
  }
4262
- function Zr(e) {
4266
+ function Qr(e) {
4263
4267
  return [...e.portrait === void 0 ? [] : [
4264
4268
  e.portrait.base,
4265
4269
  ...e.portrait.blink?.frames ?? [],
4266
4270
  ...e.portrait.lipSync?.frames ?? []
4267
4271
  ], ...e.continueIndicator?.frames ?? []];
4268
4272
  }
4269
- function Qr(e, t, n) {
4273
+ function $r(e, t, n) {
4270
4274
  if (t.maxWidth === void 0) return e;
4271
4275
  if (typeof n.measureText != "function") throw new Z("BUBBLE-COMPOSITION-007", "Bubble style maxWidth requires the text capability measureText method.");
4272
4276
  return Sr({
@@ -4279,11 +4283,11 @@ function Qr(e, t, n) {
4279
4283
  }) ?? 0
4280
4284
  }).lines.map(({ text: e }) => e).join("\n");
4281
4285
  }
4282
- function $r(e, t) {
4286
+ function ei(e, t) {
4283
4287
  if (e.length === 1) throw e[0];
4284
4288
  if (e.length > 1) throw AggregateError(e, t);
4285
4289
  }
4286
- function ei(e) {
4290
+ function ti(e) {
4287
4291
  let t = !1, n = 0, r = 0, i, a = Promise.resolve(), o = async (t) => {
4288
4292
  let n = e.animation.frames[t];
4289
4293
  n !== void 0 && await e.imageResolver.applyToTarget(n, e.target);
@@ -4318,7 +4322,7 @@ function ei(e) {
4318
4322
  }
4319
4323
  });
4320
4324
  }
4321
- function ti(e) {
4325
+ function ni(e) {
4322
4326
  if (!Q(e)) throw new Z("BUBBLE-COMPOSITION-001", "Show bubble input must be an object.");
4323
4327
  if (Pr(e, [
4324
4328
  "actor",
@@ -4346,12 +4350,12 @@ function ti(e) {
4346
4350
  ...n === void 0 ? {} : { reveal: n }
4347
4351
  };
4348
4352
  }
4349
- function ni(e) {
4353
+ function ri(e) {
4350
4354
  if (!Q(e)) throw TypeError("Bubble composition options must be an object.");
4351
- let t = Br(e.imageResolver), n = Vr(e.audio), r = Ur(e.svgText);
4355
+ let t = Vr(e.imageResolver), n = Hr(e.audio), r = Wr(e.textCapability);
4352
4356
  if (typeof e.createSurface != "function") throw TypeError("Bubble composition createSurface must be a function.");
4353
4357
  if (e.onAnimationError !== void 0 && typeof e.onAnimationError != "function") throw TypeError("Bubble composition onAnimationError must be a function.");
4354
- let i = Gr(e.scheduler ?? Wr()), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = !1, l = () => {
4358
+ let i = Kr(e.scheduler ?? Gr()), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = !1, l = () => {
4355
4359
  if (c) throw new Z("BUBBLE-COMPOSITION-005", "Bubble composition has been disposed.");
4356
4360
  }, u = async (e, t) => {
4357
4361
  let n = (s.get(e) ?? Promise.resolve()).catch(() => void 0).then(t);
@@ -4371,8 +4375,8 @@ function ni(e) {
4371
4375
  reveal: s.reveal
4372
4376
  }));
4373
4377
  let d = s.text, f = (e) => {
4374
- let n = new Set(Zr(e)), r = n.size === 0 ? void 0 : Hr(t);
4375
- for (let e of n) Yr(r, e);
4378
+ let n = new Set(Qr(e)), r = n.size === 0 ? void 0 : Ur(t);
4379
+ for (let e of n) Xr(r, e);
4376
4380
  return r;
4377
4381
  }, p = f(u);
4378
4382
  for (let e of [
@@ -4380,13 +4384,13 @@ function ni(e) {
4380
4384
  u.audio?.reveal,
4381
4385
  u.audio?.finish,
4382
4386
  u.reveal?.sound
4383
- ]) e !== void 0 && Xr(n, e);
4387
+ ]) e !== void 0 && Zr(n, e);
4384
4388
  let m = async (e, t = !1) => {
4385
4389
  e !== void 0 && n !== void 0 && await n.playSound(e, { untilDone: t });
4386
4390
  }, h = async (e, t, n) => {
4387
- let r = Zr(e).length === 0 ? void 0 : Hr(t), i = [];
4391
+ let r = Qr(e).length === 0 ? void 0 : Ur(t), i = [];
4388
4392
  if (e.portrait) {
4389
- let t = Hr(r);
4393
+ let t = Ur(r);
4390
4394
  i.push(Promise.resolve(t.applyToTarget(e.portrait.base, n.targets.portraitBase)));
4391
4395
  let a = e.portrait.blink?.frames[0];
4392
4396
  a !== void 0 && i.push(Promise.resolve(t.applyToTarget(a, n.targets.portraitBlink)));
@@ -4395,33 +4399,33 @@ function ni(e) {
4395
4399
  }
4396
4400
  let a = e.continueIndicator?.frames[0];
4397
4401
  if (a !== void 0) {
4398
- let e = Hr(r);
4402
+ let e = Ur(r);
4399
4403
  i.push(Promise.resolve(e.applyToTarget(a, n.targets.continueIndicator)));
4400
4404
  }
4401
4405
  await Promise.all(i);
4402
4406
  }, g = (t, n, r) => {
4403
- x = t.portrait?.blink === void 0 ? void 0 : ei({
4407
+ x = t.portrait?.blink === void 0 ? void 0 : ti({
4404
4408
  actorKey: s.actorKey,
4405
4409
  layer: "portraitBlink",
4406
4410
  animation: t.portrait.blink,
4407
4411
  target: r.targets.portraitBlink,
4408
- imageResolver: Hr(n),
4412
+ imageResolver: Ur(n),
4409
4413
  scheduler: i,
4410
4414
  ...e.onAnimationError === void 0 ? {} : { onError: e.onAnimationError }
4411
- }), S = t.portrait?.lipSync === void 0 ? void 0 : ei({
4415
+ }), S = t.portrait?.lipSync === void 0 ? void 0 : ti({
4412
4416
  actorKey: s.actorKey,
4413
4417
  layer: "portraitLipSync",
4414
4418
  animation: t.portrait.lipSync,
4415
4419
  target: r.targets.portraitLipSync,
4416
- imageResolver: Hr(n),
4420
+ imageResolver: Ur(n),
4417
4421
  scheduler: i,
4418
4422
  ...e.onAnimationError === void 0 ? {} : { onError: e.onAnimationError }
4419
- }), C = t.continueIndicator === void 0 ? void 0 : ei({
4423
+ }), C = t.continueIndicator === void 0 ? void 0 : ti({
4420
4424
  actorKey: s.actorKey,
4421
4425
  layer: "continueIndicator",
4422
4426
  animation: t.continueIndicator,
4423
4427
  target: r.targets.continueIndicator,
4424
- imageResolver: Hr(n),
4428
+ imageResolver: Ur(n),
4425
4429
  scheduler: i,
4426
4430
  ...e.onAnimationError === void 0 ? {} : { onError: e.onAnimationError }
4427
4431
  });
@@ -4429,13 +4433,13 @@ function ni(e) {
4429
4433
  _ && await _.close();
4430
4434
  let v, y = !1, b = !1, x, S, C, w = u.reveal, T = w ? Or(s.text, w) : Object.freeze([s.text]), E = w ? Math.min(1, T.length) : 1, D, ee = 0;
4431
4435
  try {
4432
- v = Jr(await e.createSurface(Object.freeze({
4436
+ v = Yr(await e.createSurface(Object.freeze({
4433
4437
  actor: s.actor,
4434
4438
  actorKey: s.actorKey,
4435
4439
  kind: s.kind,
4436
4440
  style: u
4437
4441
  })), u);
4438
- let t = Qr(s.text, u, r);
4442
+ let t = $r(s.text, u, r);
4439
4443
  w?.layout === "RESERVED" && (r.setText({
4440
4444
  styleName: u.textStyle,
4441
4445
  target: v.targets.text,
@@ -4443,7 +4447,7 @@ function ni(e) {
4443
4447
  }), v.captureTextLayout?.()), r.setText({
4444
4448
  styleName: u.textStyle,
4445
4449
  target: v.targets.text,
4446
- text: Qr(w ? kr(T, E) : s.text, u, r)
4450
+ text: $r(w ? kr(T, E) : s.text, u, r)
4447
4451
  }), y = !0, await h(u, p, v), g(u, p, v);
4448
4452
  let a = "idle", c = !1, l = Promise.resolve(), _ = async () => {
4449
4453
  if (!v) return;
@@ -4451,7 +4455,7 @@ function ni(e) {
4451
4455
  r.setText({
4452
4456
  styleName: u.textStyle,
4453
4457
  target: v.targets.text,
4454
- text: Qr(e, u, r)
4458
+ text: $r(e, u, r)
4455
4459
  }), await v.show();
4456
4460
  }, O = () => {
4457
4461
  ee += 1, D !== void 0 && i.clearTimeout(D), D = void 0;
@@ -4481,7 +4485,7 @@ function ni(e) {
4481
4485
  v && (O(), d = e, w ? (T = Or(e, w), E = Math.min(1, T.length), w.layout === "RESERVED" && (r.setText({
4482
4486
  styleName: u.textStyle,
4483
4487
  target: v.targets.text,
4484
- text: Qr(e, u, r)
4488
+ text: $r(e, u, r)
4485
4489
  }), v.captureTextLayout?.()), await _(), k()) : await _());
4486
4490
  }), l) : Promise.reject(new Z("BUBBLE-COMPOSITION-001", "Bubble text must be a string."));
4487
4491
  },
@@ -4489,20 +4493,20 @@ function ni(e) {
4489
4493
  if (c) return Promise.reject(new Z("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${s.actorKey}`));
4490
4494
  let t;
4491
4495
  try {
4492
- t = zr(e);
4496
+ t = Br(e);
4493
4497
  } catch (e) {
4494
4498
  return Promise.reject(e);
4495
4499
  }
4496
4500
  return l = l.then(async () => {
4497
4501
  if (!v) return;
4498
- Jr(v, t);
4502
+ Yr(v, t);
4499
4503
  let e = f(t);
4500
4504
  for (let e of [
4501
4505
  t.audio?.voice,
4502
4506
  t.audio?.reveal,
4503
4507
  t.audio?.finish,
4504
4508
  t.reveal?.sound
4505
- ]) e !== void 0 && Xr(n, e);
4509
+ ]) e !== void 0 && Zr(n, e);
4506
4510
  await Promise.all([
4507
4511
  x?.stop(),
4508
4512
  S?.stop(),
@@ -4510,11 +4514,11 @@ function ni(e) {
4510
4514
  ]), await h(t, e, v), await v.updateStyle(t), u = t, w = t.reveal, T = w ? Or(d, w) : Object.freeze([d]), E = w ? Math.min(1, T.length) : 1, O(), w?.layout === "RESERVED" && (r.setText({
4511
4515
  styleName: t.textStyle,
4512
4516
  target: v.targets.text,
4513
- text: Qr(d, t, r)
4517
+ text: $r(d, t, r)
4514
4518
  }), v.captureTextLayout?.()), r.setText({
4515
4519
  styleName: t.textStyle,
4516
4520
  target: v.targets.text,
4517
- text: Qr(d, t, r)
4521
+ text: $r(d, t, r)
4518
4522
  }), g(t, e, v), await Promise.all([
4519
4523
  v.setLayerVisible("portraitBase", t.portrait !== void 0),
4520
4524
  v.setLayerVisible("portraitBlink", t.portrait?.blink !== void 0),
@@ -4550,7 +4554,7 @@ function ni(e) {
4550
4554
  }), T = Or(d, w), E = Math.min(1, T.length), w.layout === "RESERVED" && v && (r.setText({
4551
4555
  styleName: u.textStyle,
4552
4556
  target: v.targets.text,
4553
- text: Qr(d, u, r)
4557
+ text: $r(d, u, r)
4554
4558
  }), v.captureTextLayout?.())), w) for (; await te(););
4555
4559
  let n = e.condition;
4556
4560
  if (n === void 0 && t === 0) {
@@ -4584,7 +4588,7 @@ function ni(e) {
4584
4588
  if (c) return Promise.reject(new Z("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${s.actorKey}`));
4585
4589
  let t;
4586
4590
  try {
4587
- t = Lr(e, "Bubble motion");
4591
+ t = Rr(e, "Bubble motion");
4588
4592
  } catch (e) {
4589
4593
  return Promise.reject(e);
4590
4594
  }
@@ -4627,7 +4631,7 @@ function ni(e) {
4627
4631
  } catch (t) {
4628
4632
  e.push(t);
4629
4633
  }
4630
- o.get(s.actorKey) === j && o.delete(s.actorKey), $r(e, `Failed to close bubble: ${s.actorKey}`);
4634
+ o.get(s.actorKey) === j && o.delete(s.actorKey), ei(e, `Failed to close bubble: ${s.actorKey}`);
4631
4635
  }
4632
4636
  });
4633
4637
  return o.set(s.actorKey, j), k(), u.showAnimation !== void 0 && await j.animate(u.showAnimation), j;
@@ -4659,7 +4663,7 @@ function ni(e) {
4659
4663
  return Object.freeze({
4660
4664
  defineStyle(e) {
4661
4665
  l();
4662
- let t = zr(e);
4666
+ let t = Br(e);
4663
4667
  a.set(t.name, t);
4664
4668
  },
4665
4669
  hasActiveBubble(e) {
@@ -4667,7 +4671,7 @@ function ni(e) {
4667
4671
  },
4668
4672
  async show(e) {
4669
4673
  l();
4670
- let t = ti(e);
4674
+ let t = ni(e);
4671
4675
  return u(t.actorKey, () => d(t));
4672
4676
  },
4673
4677
  releaseTarget(e) {
@@ -4678,15 +4682,15 @@ function ni(e) {
4678
4682
  });
4679
4683
  },
4680
4684
  async releaseAll() {
4681
- l(), await Promise.allSettled([...s.values()]), $r((await Promise.allSettled([...o.values()].map((e) => e.close()))).flatMap((e) => e.status === "rejected" ? [e.reason] : []), "Failed to release all bubbles");
4685
+ l(), await Promise.allSettled([...s.values()]), ei((await Promise.allSettled([...o.values()].map((e) => e.close()))).flatMap((e) => e.status === "rejected" ? [e.reason] : []), "Failed to release all bubbles");
4682
4686
  },
4683
4687
  async dispose() {
4684
4688
  if (c) return;
4685
4689
  c = !0, await Promise.allSettled([...s.values()]);
4686
4690
  let e = await Promise.allSettled([...o.values()].map((e) => e.close()));
4687
- a.clear(), $r(e.flatMap((e) => e.status === "rejected" ? [e.reason] : []), "Failed to dispose bubble composition");
4691
+ a.clear(), ei(e.flatMap((e) => e.status === "rejected" ? [e.reason] : []), "Failed to dispose bubble composition");
4688
4692
  }
4689
4693
  });
4690
4694
  }
4691
4695
  //#endregion
4692
- export { Z as BubbleCompositionError, hr as UnicodeLineBreakProvider, ee as actorRelativeBubbleCenter, d as bubbleBackgroundRegions, be as bubbleBodyCenterOffset, u as bubbleDirectionAliases, l as bubbleDirectionNames, Cr as bubbleRevealUnits, M as bubbleVisualStyles, ni as createBubbleComposition, x as defaultBubbleDistance, C as defaultBubbleOffset, f as defaultBubblePlacementInput, S as defaultBubbleTailLength, T as normalizeBubbleDistance, D as normalizeBubbleOffset, y as normalizeBubblePlacement, Er as normalizeBubbleReveal, E as normalizeBubbleTailLength, Se as renderBubbleSvg, kr as revealedBubbleText, Or as splitBubbleText, Sr as wrapText };
4696
+ export { Z as BubbleCompositionError, hr as UnicodeLineBreakProvider, ee as actorRelativeBubbleCenter, d as bubbleBackgroundRegions, be as bubbleBodyCenterOffset, u as bubbleDirectionAliases, l as bubbleDirectionNames, Cr as bubbleRevealUnits, M as bubbleVisualStyles, ri as createBubbleComposition, x as defaultBubbleDistance, C as defaultBubbleOffset, f as defaultBubblePlacementInput, S as defaultBubbleTailLength, T as normalizeBubbleDistance, D as normalizeBubbleOffset, y as normalizeBubblePlacement, Er as normalizeBubbleReveal, E as normalizeBubbleTailLength, Se as renderBubbleSvg, kr as revealedBubbleText, Or as splitBubbleText, Sr as wrapText };