@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.
@@ -8330,7 +8330,7 @@
8330
8330
  ]);
8331
8331
  if (Object.keys(input).filter((key) => !allowed.has(key)).length > 0 || input.unit === void 0) throw new TypeError("Bubble reveal has unknown or missing properties.");
8332
8332
  const unit = requireUnit(input.unit);
8333
- const delimiters = input.delimiters ?? " \\t\\r\\n";
8333
+ const delimiters = input.delimiters ?? " \r\n";
8334
8334
  if (typeof delimiters !== "string" || delimiters.length === 0) throw new TypeError("Bubble WORD delimiters must be a non-empty string.");
8335
8335
  const showDelimiters = input.showDelimiters ?? false;
8336
8336
  if (typeof showDelimiters !== "boolean") throw new TypeError("Bubble reveal showDelimiters must be boolean.");
@@ -8339,18 +8339,18 @@
8339
8339
  const intervalSeconds = input.intervalSeconds ?? 0;
8340
8340
  if (typeof intervalSeconds !== "number" || !Number.isFinite(intervalSeconds) || intervalSeconds < 0) throw new TypeError("Bubble reveal intervalSeconds must be zero or greater.");
8341
8341
  const sound = input.sound;
8342
- if (sound !== void 0 && (typeof sound !== "string" || sound.trim() === "")) throw new TypeError("Bubble reveal sound must be a non-empty asset name.");
8342
+ if (sound !== void 0 && (typeof sound !== "string" || sound.length === 0)) throw new TypeError("Bubble reveal sound must be a non-empty asset name.");
8343
8343
  return Object.freeze({
8344
8344
  unit,
8345
8345
  delimiters,
8346
8346
  showDelimiters,
8347
8347
  layout,
8348
8348
  intervalSeconds,
8349
- ...sound === void 0 ? {} : { sound: sound.trim() }
8349
+ ...sound === void 0 ? {} : { sound }
8350
8350
  });
8351
8351
  }
8352
8352
  function splitWords(text, delimiters, showDelimiters) {
8353
- const delimiterSet = new Set(graphemes(delimiters));
8353
+ const delimiterSet = new Set(Array.from(delimiters));
8354
8354
  const result = [];
8355
8355
  let current = "";
8356
8356
  for (const character of graphemes(text)) {
@@ -8431,7 +8431,7 @@
8431
8431
  "easeOut",
8432
8432
  "easeInOut"
8433
8433
  ]);
8434
- function isRecord$1(value) {
8434
+ function isRecord$2(value) {
8435
8435
  return typeof value === "object" && value !== null && !Array.isArray(value);
8436
8436
  }
8437
8437
  function requireExactKeys(value, required, optional, label) {
@@ -8444,11 +8444,15 @@
8444
8444
  if (typeof value !== "string" || value.trim().length === 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be a non-empty string.`);
8445
8445
  return value.trim();
8446
8446
  }
8447
+ function requireAssetName(value, label) {
8448
+ if (typeof value !== "string" || value.length === 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be a non-empty string.`);
8449
+ return value;
8450
+ }
8447
8451
  function normalizeAnimation(value, label, minimumFrames) {
8448
- if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8452
+ if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8449
8453
  requireExactKeys(value, ["frames", "frameIntervalSeconds"], [], label);
8450
8454
  if (!Array.isArray(value.frames) || value.frames.length < minimumFrames) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.frames must contain at least ${minimumFrames} image asset name${minimumFrames === 1 ? "" : "s"}.`);
8451
- const frames = Object.freeze(value.frames.map((frame, index) => requireName(frame, `${label}.frames[${index}]`)));
8455
+ const frames = Object.freeze(value.frames.map((frame, index) => requireAssetName(frame, `${label}.frames[${index}]`)));
8452
8456
  const interval = value.frameIntervalSeconds;
8453
8457
  if (typeof interval !== "number" || !Number.isFinite(interval) || interval <= 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.frameIntervalSeconds must be a positive finite number.`);
8454
8458
  return Object.freeze({
@@ -8457,18 +8461,18 @@
8457
8461
  });
8458
8462
  }
8459
8463
  function normalizePortrait(value) {
8460
- if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble portrait must be an object.");
8464
+ if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble portrait must be an object.");
8461
8465
  requireExactKeys(value, ["base"], ["blink", "lipSync"], "Bubble portrait");
8462
8466
  const blink = value.blink === void 0 ? void 0 : normalizeAnimation(value.blink, "Bubble portrait blink", 1);
8463
8467
  const lipSync = value.lipSync === void 0 ? void 0 : normalizeAnimation(value.lipSync, "Bubble portrait lip-sync", 1);
8464
8468
  return Object.freeze({
8465
- base: requireName(value.base, "Bubble portrait base"),
8469
+ base: requireAssetName(value.base, "Bubble portrait base"),
8466
8470
  ...blink === void 0 ? {} : { blink },
8467
8471
  ...lipSync === void 0 ? {} : { lipSync }
8468
8472
  });
8469
8473
  }
8470
8474
  function normalizeMotion(value, label) {
8471
- if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8475
+ if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8472
8476
  requireExactKeys(value, ["name"], [
8473
8477
  "durationSeconds",
8474
8478
  "ease",
@@ -8508,7 +8512,7 @@
8508
8512
  }
8509
8513
  function normalizeAudio(value) {
8510
8514
  if (value === void 0) return void 0;
8511
- if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble audio must be an object.");
8515
+ if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble audio must be an object.");
8512
8516
  requireExactKeys(value, [], [
8513
8517
  "voice",
8514
8518
  "reveal",
@@ -8521,12 +8525,12 @@
8521
8525
  "finish"
8522
8526
  ]) {
8523
8527
  const asset = value[key];
8524
- if (asset !== void 0) result[key] = requireName(asset, `Bubble audio ${key}`);
8528
+ if (asset !== void 0) result[key] = requireAssetName(asset, `Bubble audio ${key}`);
8525
8529
  }
8526
8530
  return Object.freeze(result);
8527
8531
  }
8528
8532
  function normalizeStyle(value) {
8529
- if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
8533
+ if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
8530
8534
  requireExactKeys(value, ["name", "textStyle"], [
8531
8535
  "placement",
8532
8536
  "maxWidth",
@@ -8597,12 +8601,12 @@
8597
8601
  }
8598
8602
  function validateImageResolver(value) {
8599
8603
  if (value === void 0) return void 0;
8600
- if (!isRecord$1(value) || typeof value.applyToTarget !== "function" || typeof value.getMimeType !== "function" || typeof value.isRegistered !== "function") throw new TypeError("Bubble image capability must provide applyToTarget, getMimeType, and isRegistered.");
8604
+ if (!isRecord$2(value) || typeof value.applyToTarget !== "function" || typeof value.getMimeType !== "function" || typeof value.isRegistered !== "function") throw new TypeError("Bubble image capability must provide applyToTarget, getMimeType, and isRegistered.");
8601
8605
  return value;
8602
8606
  }
8603
8607
  function validateAudioCapability(value) {
8604
8608
  if (value === void 0) return void 0;
8605
- if (!isRecord$1(value) || typeof value.playSound !== "function") throw new TypeError("Bubble audio capability must provide playSound.");
8609
+ if (!isRecord$2(value) || typeof value.playSound !== "function") throw new TypeError("Bubble audio capability must provide playSound.");
8606
8610
  if (value.isRegistered !== void 0 && typeof value.isRegistered !== "function") throw new TypeError("Bubble audio capability isRegistered must be a function.");
8607
8611
  if (value.getMimeType !== void 0 && typeof value.getMimeType !== "function") throw new TypeError("Bubble audio capability getMimeType must be a function.");
8608
8612
  return value;
@@ -8611,8 +8615,8 @@
8611
8615
  if (value === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", "Bubble image assets require an image capability. Provide options.imageResolver.");
8612
8616
  return value;
8613
8617
  }
8614
- function validateSvgText(value) {
8615
- if (!isRecord$1(value) || typeof value.setText !== "function" || typeof value.releaseTarget !== "function") throw new TypeError("Bubble SVG Text composition must provide setText and releaseTarget.");
8618
+ function validateTextCapability(value) {
8619
+ if (!isRecord$2(value) || typeof value.setText !== "function" || typeof value.releaseTarget !== "function") throw new TypeError("Bubble text capability must provide setText and releaseTarget.");
8616
8620
  return value;
8617
8621
  }
8618
8622
  function defaultScheduler() {
@@ -8622,19 +8626,19 @@
8622
8626
  });
8623
8627
  }
8624
8628
  function validateScheduler(value) {
8625
- if (!isRecord$1(value) || typeof value.setTimeout !== "function" || typeof value.clearTimeout !== "function") throw new TypeError("Bubble scheduler must provide setTimeout and clearTimeout.");
8629
+ if (!isRecord$2(value) || typeof value.setTimeout !== "function" || typeof value.clearTimeout !== "function") throw new TypeError("Bubble scheduler must provide setTimeout and clearTimeout.");
8626
8630
  return value;
8627
8631
  }
8628
8632
  function validateAssetTarget(value, label) {
8629
- if (!isRecord$1(value) || typeof value.id !== "string" || value.id.length === 0 || typeof value.isStage !== "boolean") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", `${label} must provide id and isStage.`);
8633
+ if (!isRecord$2(value) || typeof value.id !== "string" || value.id.length === 0 || typeof value.isStage !== "boolean") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", `${label} must provide id and isStage.`);
8630
8634
  return value;
8631
8635
  }
8632
8636
  function validateTextTarget(value) {
8633
- if (!isRecord$1(value) || typeof value.drawableID !== "number" || !Number.isInteger(value.drawableID) || value.drawableID < 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", "Bubble text target must provide a non-negative integer drawableID.");
8637
+ if (typeof value !== "object" || value === null) throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", "Bubble text target must be a non-null object.");
8634
8638
  return value;
8635
8639
  }
8636
8640
  function validateSurface(value, style) {
8637
- if (!isRecord$1(value) || !isRecord$1(value.targets) || typeof value.setLayerVisible !== "function" || typeof value.updateStyle !== "function" || typeof value.show !== "function" || typeof value.hide !== "function" || typeof value.dispose !== "function") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", "Bubble surface is invalid.");
8641
+ if (!isRecord$2(value) || !isRecord$2(value.targets) || typeof value.setLayerVisible !== "function" || typeof value.updateStyle !== "function" || typeof value.show !== "function" || typeof value.hide !== "function" || typeof value.dispose !== "function") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", "Bubble surface is invalid.");
8638
8642
  const targets = value.targets;
8639
8643
  validateTextTarget(targets.text);
8640
8644
  const assetTargetIds = /* @__PURE__ */ new Set();
@@ -8745,7 +8749,7 @@
8745
8749
  });
8746
8750
  }
8747
8751
  function normalizeShowInput(value) {
8748
- if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Show bubble input must be an object.");
8752
+ if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Show bubble input must be an object.");
8749
8753
  requireExactKeys(value, [
8750
8754
  "actor",
8751
8755
  "actorKey",
@@ -8774,10 +8778,10 @@
8774
8778
  };
8775
8779
  }
8776
8780
  function createBubbleComposition(options) {
8777
- if (!isRecord$1(options)) throw new TypeError("Bubble composition options must be an object.");
8781
+ if (!isRecord$2(options)) throw new TypeError("Bubble composition options must be an object.");
8778
8782
  const imageResolver = validateImageResolver(options.imageResolver);
8779
8783
  const audio = validateAudioCapability(options.audio);
8780
- const svgText = validateSvgText(options.svgText);
8784
+ const textCapability = validateTextCapability(options.textCapability);
8781
8785
  if (typeof options.createSurface !== "function") throw new TypeError("Bubble composition createSurface must be a function.");
8782
8786
  if (options.onAnimationError !== void 0 && typeof options.onAnimationError !== "function") throw new TypeError("Bubble composition onAnimationError must be a function.");
8783
8787
  const scheduler = validateScheduler(options.scheduler ?? defaultScheduler());
@@ -8891,19 +8895,19 @@
8891
8895
  kind: input.kind,
8892
8896
  style: activeStyle
8893
8897
  })), activeStyle);
8894
- const fullText = formatBubbleText(input.text, activeStyle, svgText);
8898
+ const fullText = formatBubbleText(input.text, activeStyle, textCapability);
8895
8899
  if (reveal?.layout === "RESERVED") {
8896
- svgText.setText({
8900
+ textCapability.setText({
8897
8901
  styleName: activeStyle.textStyle,
8898
8902
  target: surface.targets.text,
8899
8903
  text: fullText
8900
8904
  });
8901
8905
  surface.captureTextLayout?.();
8902
8906
  }
8903
- svgText.setText({
8907
+ textCapability.setText({
8904
8908
  styleName: activeStyle.textStyle,
8905
8909
  target: surface.targets.text,
8906
- text: formatBubbleText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text, activeStyle, svgText)
8910
+ text: formatBubbleText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text, activeStyle, textCapability)
8907
8911
  });
8908
8912
  textOwned = true;
8909
8913
  await primeStyleImages(activeStyle, styleImageResolver, surface);
@@ -8914,10 +8918,10 @@
8914
8918
  const renderVisibleText = async () => {
8915
8919
  if (!surface) return;
8916
8920
  const visible = reveal ? revealedBubbleText(revealChunks, revealedCount) : currentText;
8917
- svgText.setText({
8921
+ textCapability.setText({
8918
8922
  styleName: activeStyle.textStyle,
8919
8923
  target: surface.targets.text,
8920
- text: formatBubbleText(visible, activeStyle, svgText)
8924
+ text: formatBubbleText(visible, activeStyle, textCapability)
8921
8925
  });
8922
8926
  await surface.show();
8923
8927
  };
@@ -8990,10 +8994,10 @@
8990
8994
  revealChunks = splitBubbleText(text, reveal);
8991
8995
  revealedCount = Math.min(1, revealChunks.length);
8992
8996
  if (reveal.layout === "RESERVED") {
8993
- svgText.setText({
8997
+ textCapability.setText({
8994
8998
  styleName: activeStyle.textStyle,
8995
8999
  target: surface.targets.text,
8996
- text: formatBubbleText(text, activeStyle, svgText)
9000
+ text: formatBubbleText(text, activeStyle, textCapability)
8997
9001
  });
8998
9002
  surface.captureTextLayout?.();
8999
9003
  }
@@ -9034,17 +9038,17 @@
9034
9038
  revealedCount = reveal ? Math.min(1, revealChunks.length) : 1;
9035
9039
  stopRevealTimer();
9036
9040
  if (reveal?.layout === "RESERVED") {
9037
- svgText.setText({
9041
+ textCapability.setText({
9038
9042
  styleName: nextStyle.textStyle,
9039
9043
  target: surface.targets.text,
9040
- text: formatBubbleText(currentText, nextStyle, svgText)
9044
+ text: formatBubbleText(currentText, nextStyle, textCapability)
9041
9045
  });
9042
9046
  surface.captureTextLayout?.();
9043
9047
  }
9044
- svgText.setText({
9048
+ textCapability.setText({
9045
9049
  styleName: nextStyle.textStyle,
9046
9050
  target: surface.targets.text,
9047
- text: formatBubbleText(currentText, nextStyle, svgText)
9051
+ text: formatBubbleText(currentText, nextStyle, textCapability)
9048
9052
  });
9049
9053
  createStyleLoops(nextStyle, nextImageResolver, surface);
9050
9054
  await Promise.all([
@@ -9102,10 +9106,10 @@
9102
9106
  revealChunks = splitBubbleText(currentText, reveal);
9103
9107
  revealedCount = Math.min(1, revealChunks.length);
9104
9108
  if (reveal.layout === "RESERVED" && surface) {
9105
- svgText.setText({
9109
+ textCapability.setText({
9106
9110
  styleName: activeStyle.textStyle,
9107
9111
  target: surface.targets.text,
9108
- text: formatBubbleText(currentText, activeStyle, svgText)
9112
+ text: formatBubbleText(currentText, activeStyle, textCapability)
9109
9113
  });
9110
9114
  surface.captureTextLayout?.();
9111
9115
  }
@@ -9201,7 +9205,7 @@
9201
9205
  if (surfaceVisible) await surface?.hide();
9202
9206
  },
9203
9207
  async () => {
9204
- if (textOwned && surface) svgText.releaseTarget(surface.targets.text);
9208
+ if (textOwned && surface) textCapability.releaseTarget(surface.targets.text);
9205
9209
  },
9206
9210
  async () => surface?.dispose()
9207
9211
  ]) try {
@@ -9232,7 +9236,7 @@
9232
9236
  cleanupErrors.push(cleanupError);
9233
9237
  }
9234
9238
  if (textOwned && surface) try {
9235
- svgText.releaseTarget(surface.targets.text);
9239
+ textCapability.releaseTarget(surface.targets.text);
9236
9240
  } catch (cleanupError) {
9237
9241
  cleanupErrors.push(cleanupError);
9238
9242
  }
@@ -9282,6 +9286,37 @@
9282
9286
  });
9283
9287
  }
9284
9288
  //#endregion
9289
+ //#region src/turbowarp-svg-text-adapter.ts
9290
+ function isRecord$1(value) {
9291
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9292
+ }
9293
+ function validateExtension(value) {
9294
+ if (!isRecord$1(value) || typeof value.setText !== "function" || typeof value.releaseTextActor !== "function") throw new TypeError("TurboWarp SVG Text adapter requires setText and releaseTextActor.");
9295
+ return value;
9296
+ }
9297
+ /**
9298
+ * Adapt the TurboWarp SVG Text extension to Bubble's host-neutral text
9299
+ * capability contract.
9300
+ */
9301
+ function createTurboWarpSvgTextCapability(extensionInput) {
9302
+ const extension = validateExtension(extensionInput);
9303
+ return Object.freeze({
9304
+ setText({ styleName, target, text }) {
9305
+ extension.setText({
9306
+ STYLE: styleName,
9307
+ TEXT: text
9308
+ }, { target });
9309
+ },
9310
+ releaseTarget(target) {
9311
+ extension.releaseTextActor(target);
9312
+ },
9313
+ measureText({ styleName, text }) {
9314
+ if (typeof extension.measureText !== "function") throw new Error("TurboWarp SVG Text does not provide text measurement.");
9315
+ return extension.measureText(styleName, text);
9316
+ }
9317
+ });
9318
+ }
9319
+ //#endregion
9285
9320
  //#region src/turbowarp-adapter.ts
9286
9321
  var spriteLayer = "sprite";
9287
9322
  var portraitBoxSize = 96;
@@ -9321,10 +9356,6 @@
9321
9356
  if (!isRecord(value) || typeof value.isLoaded !== "function" || typeof value.getAssetMimeType !== "function" || typeof value.resolveSkin !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "Bubble image assets require an imageResolver capability. Load @kubohiroya/turbowarp-asset-manager or provide options.imageResolver before using image features.");
9322
9357
  return value;
9323
9358
  }
9324
- function requireSvgText(value) {
9325
- if (!isRecord(value) || typeof value.setText !== "function" || typeof value.releaseTextActor !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-003", "Bubble requires SVG Text. Load @kubohiroya/turbowarp-svg-text before using Bubble blocks.");
9326
- return value;
9327
- }
9328
9359
  function targetBounds(target) {
9329
9360
  try {
9330
9361
  const bounds = target.getBoundsForBubble?.();
@@ -9825,7 +9856,13 @@
9825
9856
  const runtime = runtimeInput;
9826
9857
  const renderer = requireRenderer(runtime.renderer);
9827
9858
  const getAssetExtension = () => requireAssetManager(runtime.ext_kubohiroyaassetmanager);
9828
- const svgTextExtension = options.svgText ? null : requireSvgText(runtime.ext_kubohiroyasvgtext);
9859
+ let textCapability;
9860
+ if (options.textCapability !== void 0) textCapability = options.textCapability;
9861
+ else try {
9862
+ textCapability = createTurboWarpSvgTextCapability(runtime.ext_kubohiroyasvgtext);
9863
+ } catch {
9864
+ throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-003", "Bubble requires a text capability. Load @kubohiroya/turbowarp-svg-text or provide options.textCapability before using Bubble blocks.");
9865
+ }
9829
9866
  return createBubbleComposition({
9830
9867
  imageResolver: options.imageResolver ?? {
9831
9868
  isRegistered(name) {
@@ -9857,22 +9894,7 @@
9857
9894
  await method.call(extension, { NAME: name });
9858
9895
  }
9859
9896
  },
9860
- svgText: options.svgText ?? {
9861
- setText({ styleName, target, text }) {
9862
- svgTextExtension?.setText({
9863
- STYLE: styleName,
9864
- TEXT: text
9865
- }, { target });
9866
- },
9867
- releaseTarget(target) {
9868
- svgTextExtension?.releaseTextActor(target);
9869
- },
9870
- measureText({ styleName, text }) {
9871
- const measureText = svgTextExtension?.measureText;
9872
- if (typeof measureText !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-003", "SVG Text does not provide text measurement.");
9873
- return measureText.call(svgTextExtension, styleName, text);
9874
- }
9875
- },
9897
+ textCapability,
9876
9898
  createSurface({ actor, actorKey, style }) {
9877
9899
  if (!isRecord(actor) || typeof actor.id !== "string") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "Bubble actor target is invalid.");
9878
9900
  return createSurface(runtime, actor, actorKey, style, options.scheduler ?? {
@@ -9925,7 +9947,7 @@
9925
9947
  "easeInOut"
9926
9948
  ]);
9927
9949
  var EXTENSION_DOCS_URI = "https://kubohiroya.github.io/turbowarp-bubble/";
9928
- var EXTENSION_VERSION = "0.3.0";
9950
+ var EXTENSION_VERSION = "0.4.0";
9929
9951
  function extensionError(message) {
9930
9952
  const error = /* @__PURE__ */ new Error(`[Bubble] ${message}`);
9931
9953
  Object.defineProperty(error, "code", { value: "BUBBLE-EXTENSION-001" });
@@ -2,6 +2,8 @@ import { type BubblePlacement, type BubblePlacementInput } from "./placement.js"
2
2
  import { type BubbleOffset, type BubbleOffsetInput } from "./actor-transform.js";
3
3
  import { type BubbleVisualStyle } from "./bubble-svg.js";
4
4
  import { type BubbleRevealInput, type BubbleRevealUnit, type NormalizedBubbleReveal } from "./reveal.js";
5
+ import type { BubbleTextCapability, BubbleTextTarget } from "./text-capability.js";
6
+ export type { BubbleTextCapability, BubbleTextTarget, } from "./text-capability.js";
5
7
  export { UnicodeLineBreakProvider, wrapText, type LineBreakOpportunity, type LineBreakProvider, type TextWidthMeasurer, type WrappedTextLayout, type WrappedTextLine, type WrapTextInput, } from "./text-layout.js";
6
8
  export { bubbleBackgroundRegions, bubbleDirectionAliases, bubbleDirectionNames, defaultBubblePlacementInput, normalizeBubblePlacement, type BubbleActorPlacement, type BubbleBackgroundPlacement, type BubbleBackgroundRegion, type BubbleDirectionAlias, type BubbleDirectionName, type BubblePlacement, type BubblePlacementInput, } from "./placement.js";
7
9
  export { actorRelativeBubbleCenter, defaultBubbleDistance, defaultBubbleOffset, defaultBubbleTailLength, normalizeBubbleDistance, normalizeBubbleOffset, normalizeBubbleTailLength, type ActorBounds, type ActorRelativeCenterInput, type BubbleOffset, type BubbleOffsetInput, } from "./actor-transform.js";
@@ -102,21 +104,6 @@ export interface BubbleAudioCapability {
102
104
  readonly isRegistered?: (name: unknown) => boolean;
103
105
  readonly getMimeType?: (name: unknown) => string;
104
106
  }
105
- export interface BubbleTextTarget {
106
- readonly drawableID: number;
107
- }
108
- export interface BubbleSvgText {
109
- readonly setText: (input: {
110
- readonly styleName: string;
111
- readonly target: BubbleTextTarget;
112
- readonly text: string;
113
- }) => void;
114
- readonly releaseTarget: (target: BubbleTextTarget) => void;
115
- readonly measureText?: (input: {
116
- readonly styleName: string;
117
- readonly text: string;
118
- }) => number;
119
- }
120
107
  export interface BubbleSurfaceTargets {
121
108
  readonly text: BubbleTextTarget;
122
109
  readonly portraitBase?: BubbleAssetTarget;
@@ -156,7 +143,7 @@ export interface BubbleAnimationErrorContext {
156
143
  export interface BubbleCompositionOptions {
157
144
  readonly imageResolver?: BubbleImageCapability;
158
145
  readonly audio?: BubbleAudioCapability;
159
- readonly svgText: BubbleSvgText;
146
+ readonly textCapability: BubbleTextCapability;
160
147
  readonly createSurface: BubbleSurfaceFactory;
161
148
  readonly scheduler?: BubbleScheduler;
162
149
  readonly onAnimationError?: (error: unknown, context: BubbleAnimationErrorContext) => void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Opaque host-owned target used by a text capability.
3
+ *
4
+ * The capability may be implemented by TurboWarp SVG Text or by another
5
+ * renderer in a different host environment.
6
+ */
7
+ export type BubbleTextTarget = object;
8
+ /**
9
+ * Text rendering contract consumed by Bubble composition.
10
+ *
11
+ * Bubble owns placement, outer shape, portraits, reveal, and animation. A
12
+ * text adapter owns text styles, SVG/text skin creation, measurement, and
13
+ * target skin release.
14
+ */
15
+ export interface BubbleTextCapability {
16
+ setText(input: {
17
+ readonly styleName: string;
18
+ readonly target: BubbleTextTarget;
19
+ readonly text: string;
20
+ }): void;
21
+ releaseTarget(target: BubbleTextTarget): void;
22
+ measureText?(input: {
23
+ readonly styleName: string;
24
+ readonly text: string;
25
+ }): number;
26
+ }
@@ -1,4 +1,6 @@
1
- import { type BubbleComposition, type BubbleCompositionOptions, type BubbleAudioCapability, type BubbleImageCapability, type BubbleScheduler, type BubbleSvgText } from "./composition.js";
1
+ import { type BubbleComposition, type BubbleCompositionOptions, type BubbleAudioCapability, type BubbleImageCapability, type BubbleScheduler, type BubbleTextCapability } from "./composition.js";
2
+ import { type TurboWarpSvgTextExtension } from "./turbowarp-svg-text-adapter.js";
3
+ export { createSvgTextCompositionCapability, createTurboWarpSvgTextCapability, type TurboWarpSvgTextExtension, } from "./turbowarp-svg-text-adapter.js";
2
4
  export interface TurboWarpBubbleTarget {
3
5
  readonly id: string;
4
6
  readonly isStage: boolean;
@@ -48,16 +50,6 @@ export interface TurboWarpAssetManagerExtension {
48
50
  skinId: number;
49
51
  }>>;
50
52
  }
51
- export interface TurboWarpSvgTextExtension {
52
- setText(args: Readonly<{
53
- STYLE: unknown;
54
- TEXT: unknown;
55
- }>, util: Readonly<{
56
- target: TurboWarpBubbleTarget;
57
- }>): void;
58
- measureText?(styleName: unknown, text: unknown): number;
59
- releaseTextActor(target: TurboWarpBubbleTarget): boolean;
60
- }
61
53
  export interface TurboWarpBubbleRuntime {
62
54
  readonly renderer: TurboWarpBubbleRenderer;
63
55
  readonly ext_kubohiroyaassetmanager?: TurboWarpAssetManagerExtension;
@@ -67,7 +59,7 @@ export interface TurboWarpBubbleRuntime {
67
59
  export interface TurboWarpBubbleCompositionOptions {
68
60
  readonly imageResolver?: BubbleImageCapability;
69
61
  readonly audio?: BubbleAudioCapability;
70
- readonly svgText?: BubbleSvgText;
62
+ readonly textCapability?: BubbleTextCapability;
71
63
  readonly scheduler?: BubbleScheduler;
72
64
  readonly onAnimationError?: BubbleCompositionOptions["onAnimationError"];
73
65
  }
@@ -0,0 +1,21 @@
1
+ import type { BubbleTextCapability } from "./text-capability.js";
2
+ export interface TurboWarpSvgTextExtension {
3
+ setText(args: Readonly<{
4
+ STYLE: unknown;
5
+ TEXT: unknown;
6
+ }>, util: Readonly<{
7
+ target: unknown;
8
+ }>): void;
9
+ measureText?(styleName: unknown, text: unknown): number;
10
+ releaseTextActor(target: unknown): boolean;
11
+ }
12
+ /**
13
+ * Adapt the TurboWarp SVG Text extension to Bubble's host-neutral text
14
+ * capability contract.
15
+ */
16
+ export declare function createTurboWarpSvgTextCapability(extensionInput: unknown): BubbleTextCapability;
17
+ /**
18
+ * Adapt the SVG Text package's composition API to Bubble's text capability.
19
+ * This helper keeps the core package independent from SVG Text's target type.
20
+ */
21
+ export declare function createSvgTextCompositionCapability(compositionInput: unknown): BubbleTextCapability;
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## 1. 必要な拡張機能
8
8
 
9
- 入力待ちを含む完全な例では6つの拡張機能を使います。TurboWarpの拡張機能ライブラリからTemporary Variablesを追加し、選択した機能に必要なカスタム拡張機能を「サンドボックスなしで実行」を許可して読み込みます。文字BubbleにはSVG TextとBubbleが必要です。portrait、lip-sync、continue indicator、フルボイス、表示効果音などのメディアアセットにはAsset Managerが必要です。Async InputとRuntime ExpressionはBubble待機を使う場合だけ必要です。
9
+ 入力待ちを含む完全な例では6つの拡張機能を使います。TurboWarpの拡張機能ライブラリからTemporary Variablesを追加し、選択した機能に必要なカスタム拡張機能を「サンドボックスなしで実行」を許可して読み込みます。Bubbleは文字Bubbleの既定`BubbleTextCapability` adapterとしてSVG Textを使います。portrait、lip-sync、continue indicator、フルボイス、表示効果音などのメディアアセットにはAsset Managerが必要です。Async InputとRuntime ExpressionはBubble待機を使う場合だけ必要です。
10
10
 
11
11
  | 順番 | 拡張機能 | 読み込み先 |
12
12
  | ---: | ------------------------ | -------------------------------------------------------------------------------------------------------- |
@@ -15,9 +15,9 @@
15
15
  | 3 | Runtime Expression 0.3.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-runtime-expression@0.3.0/dist/runtime-expression.js` |
16
16
  | 4 | Asset Manager 0.7.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-asset-manager@0.7.0/dist/asset-manager.js` |
17
17
  | 5 | SVG Text 0.4.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-svg-text@0.4.0/dist/svg-text.js` |
18
- | 6 | Bubble 0.3.0 | npm公開後は`https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.3.0/dist/turbowarp-bubble.js` |
18
+ | 6 | Bubble 0.4.0 | npm公開後は`https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.4.0/dist/turbowarp-bubble.js` |
19
19
 
20
- 開発中のBubbleを試す場合は、このリポジトリの`dist/turbowarp-bubble.js`をローカルカスタム拡張機能として読み込みます。表示時にSVG Textが、画像・メディア機能の使用時にAsset Managerが、待機開始時にAsync InputかRuntime Expressionが見つからなければ、Bubbleは明示的なエラーを返します。
20
+ 開発中のBubbleを試す場合は、このリポジトリの`dist/turbowarp-bubble.js`をローカルカスタム拡張機能として読み込みます。表示時に既定のSVG Text adapterが、画像・メディア機能の使用時にAsset Managerが、待機開始時にAsync InputかRuntime Expressionが見つからなければ、Bubbleは明示的なエラーを返します。低レベルComposition APIでは別のtext capabilityを注入でき、その場合SVG Textは不要です。
21
21
 
22
22
  参考:
23
23
 
@@ -296,7 +296,7 @@ cloneが停止・削除された場合は、そのtargetに属するtimer、SVG
296
296
  | 状況 | 原因と対処 |
297
297
  | ---------------------------------- | ------------------------------------------------------------------------ |
298
298
  | Asset Managerを要求するエラー | 画像・メディアアセットを使う前にAsset Manager 0.7.xを読み込む |
299
- | SVG Textを要求するエラー | SVG Text 0.4.xをサンドボックスなしで読み込む |
299
+ | 既定text adapterを要求するエラー | SVG Text 0.4.xをサンドボックスなしで読み込む |
300
300
  | Async Inputを要求するエラー | Bubble待機より前にAsync Input 0.3.xをサンドボックスなしで読み込む |
301
301
  | Runtime Expressionを要求するエラー | Bubble待機より前にRuntime Expression 0.3.xをサンドボックスなしで読み込む |
302
302
  | `bubble style is not defined` | `define bubble style`を先に実行する。緑の旗の再実行時も再定義する |
@@ -310,7 +310,7 @@ cloneが停止・削除された場合は、そのtargetに属するtimer、SVG
310
310
 
311
311
  ## 13. 自動解放されるタイミング
312
312
 
313
- 次の場合、Bubbleが所有するtimer、SVG Text skin、renderer drawableは自動的に解放されます。
313
+ 次の場合、Bubbleが所有するtimer、text skin、renderer drawableは自動的に解放されます。
314
314
 
315
315
  - `close this bubble`
316
316
  - 同じsprite/cloneで次の`say`または`think`を実行したとき
@@ -6,7 +6,7 @@ This manual explains how to use `turbowarp-bubble` as an unsandboxed TurboWarp c
6
6
 
7
7
  ## 1. Load the required extensions
8
8
 
9
- The complete input-wait example uses six extensions. Add Temporary Variables from TurboWarp's extension library, then load the custom extensions needed by the selected features with **Run without sandbox** enabled. SVG Text and Bubble are required for text bubbles. Asset Manager is required for portrait, lip-sync, continue indicator, voice, and display-sound assets. Async Input and Runtime Expression are required only before using a Bubble wait.
9
+ The complete input-wait example uses six extensions. Add Temporary Variables from TurboWarp's extension library, then load the custom extensions needed by the selected features with **Run without sandbox** enabled. Bubble uses SVG Text as its default `BubbleTextCapability` adapter for text bubbles. Asset Manager is required for portrait, lip-sync, continue indicator, voice, and display-sound assets. Async Input and Runtime Expression are required only before using a Bubble wait.
10
10
 
11
11
  | Order | Extension | URL |
12
12
  | ----: | ------------------------ | ----------------------------------------------------------------------------------------------------------------- |
@@ -15,9 +15,9 @@ The complete input-wait example uses six extensions. Add Temporary Variables fro
15
15
  | 3 | Runtime Expression 0.3.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-runtime-expression@0.3.0/dist/runtime-expression.js` |
16
16
  | 4 | Asset Manager 0.7.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-asset-manager@0.7.0/dist/asset-manager.js` |
17
17
  | 5 | SVG Text 0.4.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-svg-text@0.4.0/dist/svg-text.js` |
18
- | 6 | Bubble 0.3.0 | After npm publication: `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.3.0/dist/turbowarp-bubble.js` |
18
+ | 6 | Bubble 0.4.0 | After npm publication: `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.4.0/dist/turbowarp-bubble.js` |
19
19
 
20
- To try a development build, load this repository's `dist/turbowarp-bubble.js` as a local custom extension. Bubble reports an explicit error if SVG Text is missing when it displays a Bubble, if an image/media feature is used without Asset Manager, or if Async Input or Runtime Expression is missing when it starts a Bubble wait.
20
+ To try a development build, load this repository's `dist/turbowarp-bubble.js` as a local custom extension. Bubble reports an explicit error if the default SVG Text adapter is missing when it displays a Bubble, if an image/media feature is used without Asset Manager, or if Async Input or Runtime Expression is missing when it starts a Bubble wait. The lower-level Composition API can use another text capability and does not require SVG Text.
21
21
 
22
22
  See also:
23
23
 
@@ -296,7 +296,7 @@ When a clone stops or is deleted, timers, SVG Text skins, and renderer drawables
296
296
  | Symptom | Cause and solution |
297
297
  | ------------------------------------ | --------------------------------------------------------------------------- |
298
298
  | Asset Manager required error | Load Asset Manager 0.7.x without sandbox before using image/media assets |
299
- | SVG Text required error | Load SVG Text 0.4.x without sandbox |
299
+ | Default text adapter required error | Load SVG Text 0.4.x without sandbox |
300
300
  | Async Input required error | Load Async Input 0.3.x without sandbox before using the Bubble wait |
301
301
  | Runtime Expression required error | Load Runtime Expression 0.3.x without sandbox before using the Bubble wait |
302
302
  | `bubble style is not defined` | Run `define bubble style` first, including after restarting with green flag |
@@ -310,7 +310,7 @@ When a clone stops or is deleted, timers, SVG Text skins, and renderer drawables
310
310
 
311
311
  ## 13. Automatic cleanup
312
312
 
313
- Bubble automatically releases its owned timers, SVG Text skins, and renderer drawables when:
313
+ Bubble automatically releases its owned timers, text skins, and renderer drawables when:
314
314
 
315
315
  - `close this bubble` runs;
316
316
  - the same sprite or clone runs another `say` or `think`;
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <p>This manual explains how to use <code>turbowarp-bubble</code> as an unsandboxed TurboWarp custom extension. A Bubble combines an SVG body, text, a character portrait, blinking and lip-sync layers, and an animated continue indicator.</p>
72
72
  <p><img src="./assets/block-quick-start.svg" alt="A quick-start block sequence that registers Next1 and Next2 separately, prepares input listeners, then uses Bubble&#39;s integrated wait"></p>
73
73
  <h2 id="requirements">1. Load the required extensions</h2>
74
- <p>The complete input-wait example uses six extensions. Add Temporary Variables from TurboWarp&#39;s extension library, then load the custom extensions needed by the selected features with <strong>Run without sandbox</strong> enabled. SVG Text and Bubble are required for text bubbles. Asset Manager is required for portrait, lip-sync, continue indicator, voice, and display-sound assets. Async Input and Runtime Expression are required only before using a Bubble wait.</p>
74
+ <p>The complete input-wait example uses six extensions. Add Temporary Variables from TurboWarp&#39;s extension library, then load the custom extensions needed by the selected features with <strong>Run without sandbox</strong> enabled. Bubble uses SVG Text as its default <code>BubbleTextCapability</code> adapter for text bubbles. Asset Manager is required for portrait, lip-sync, continue indicator, voice, and display-sound assets. Async Input and Runtime Expression are required only before using a Bubble wait.</p>
75
75
  <table>
76
76
  <thead>
77
77
  <tr>
@@ -107,11 +107,11 @@
107
107
  </tr>
108
108
  <tr>
109
109
  <td align="right">6</td>
110
- <td>Bubble 0.3.0</td>
111
- <td>After npm publication: <code>https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.3.0/dist/turbowarp-bubble.js</code></td>
110
+ <td>Bubble 0.4.0</td>
111
+ <td>After npm publication: <code>https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.4.0/dist/turbowarp-bubble.js</code></td>
112
112
  </tr>
113
113
  </tbody></table>
114
- <p>To try a development build, load this repository&#39;s <code>dist/turbowarp-bubble.js</code> as a local custom extension. Bubble reports an explicit error if SVG Text is missing when it displays a Bubble, if an image/media feature is used without Asset Manager, or if Async Input or Runtime Expression is missing when it starts a Bubble wait.</p>
114
+ <p>To try a development build, load this repository&#39;s <code>dist/turbowarp-bubble.js</code> as a local custom extension. Bubble reports an explicit error if the default SVG Text adapter is missing when it displays a Bubble, if an image/media feature is used without Asset Manager, or if Async Input or Runtime Expression is missing when it starts a Bubble wait. The lower-level Composition API can use another text capability and does not require SVG Text.</p>
115
115
  <p>See also:</p>
116
116
  <ul>
117
117
  <li><a href="https://kubohiroya.github.io/turbowarp-asset-manager/">Asset Manager guide</a></li>
@@ -483,7 +483,7 @@ think [MESSAGE] with bubble style [STYLE]
483
483
  <td>Load Asset Manager 0.7.x without sandbox before using image/media assets</td>
484
484
  </tr>
485
485
  <tr>
486
- <td>SVG Text required error</td>
486
+ <td>Default text adapter required error</td>
487
487
  <td>Load SVG Text 0.4.x without sandbox</td>
488
488
  </tr>
489
489
  <tr>
@@ -528,7 +528,7 @@ think [MESSAGE] with bubble style [STYLE]
528
528
  </tr>
529
529
  </tbody></table>
530
530
  <h2>13. Automatic cleanup</h2>
531
- <p>Bubble automatically releases its owned timers, SVG Text skins, and renderer drawables when:</p>
531
+ <p>Bubble automatically releases its owned timers, text skins, and renderer drawables when:</p>
532
532
  <ul>
533
533
  <li><code>close this bubble</code> runs;</li>
534
534
  <li>the same sprite or clone runs another <code>say</code> or <code>think</code>;</li>