@kubohiroya/turbowarp-bubble 0.2.0 → 0.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.
@@ -225,6 +225,222 @@
225
225
  }
226
226
  }
227
227
  },
228
+ {
229
+ "opcode": "setBubbleReveal",
230
+ "blockType": "COMMAND",
231
+ "text": "set bubble reveal unit [UNIT] every [SECONDS] seconds layout [LAYOUT] for bubble style [STYLE]",
232
+ "description": "Sets CHARACTER, WORD, LINE, or BLOCK sequential reveal. WORD uses the configured delimiters; DYNAMIC reflows as text grows and RESERVED reserves the final text size.",
233
+ "arguments": {
234
+ "UNIT": {
235
+ "type": "STRING",
236
+ "defaultValue": "CHARACTER",
237
+ "menu": "revealUnit"
238
+ },
239
+ "SECONDS": {
240
+ "type": "NUMBER",
241
+ "defaultValue": .05
242
+ },
243
+ "LAYOUT": {
244
+ "type": "STRING",
245
+ "defaultValue": "DYNAMIC",
246
+ "menu": "revealLayout"
247
+ },
248
+ "STYLE": {
249
+ "type": "STRING",
250
+ "defaultValue": "dialogue"
251
+ }
252
+ }
253
+ },
254
+ {
255
+ "opcode": "setBubbleWordDelimiters",
256
+ "blockType": "COMMAND",
257
+ "text": "set bubble word delimiters [DELIMITERS] show [SHOW] for bubble style [STYLE]",
258
+ "description": "Sets the character set used by WORD reveal and chooses whether delimiters remain visible.",
259
+ "arguments": {
260
+ "DELIMITERS": {
261
+ "type": "STRING",
262
+ "defaultValue": " /"
263
+ },
264
+ "SHOW": {
265
+ "type": "STRING",
266
+ "defaultValue": "false",
267
+ "menu": "boolean"
268
+ },
269
+ "STYLE": {
270
+ "type": "STRING",
271
+ "defaultValue": "dialogue"
272
+ }
273
+ }
274
+ },
275
+ {
276
+ "opcode": "setBubbleRevealSound",
277
+ "blockType": "COMMAND",
278
+ "text": "set bubble reveal sound [ASSET] for bubble style [STYLE]",
279
+ "description": "Sets a named audio asset played once per CHARACTER, WORD, LINE, or BLOCK reveal.",
280
+ "arguments": {
281
+ "ASSET": {
282
+ "type": "STRING",
283
+ "defaultValue": "Typewriter"
284
+ },
285
+ "STYLE": {
286
+ "type": "STRING",
287
+ "defaultValue": "dialogue"
288
+ }
289
+ }
290
+ },
291
+ {
292
+ "opcode": "setBubbleVoice",
293
+ "blockType": "COMMAND",
294
+ "text": "set bubble voice [ASSET] for bubble style [STYLE]",
295
+ "description": "Sets the named full-voice audio asset played when the Bubble starts.",
296
+ "arguments": {
297
+ "ASSET": {
298
+ "type": "STRING",
299
+ "defaultValue": "Voice"
300
+ },
301
+ "STYLE": {
302
+ "type": "STRING",
303
+ "defaultValue": "dialogue"
304
+ }
305
+ }
306
+ },
307
+ {
308
+ "opcode": "finishBubbleReveal",
309
+ "blockType": "COMMAND",
310
+ "text": "finish [UNIT] with condition [CONDITION] or timeout after [TIMEOUT] seconds",
311
+ "description": "Reveals the remaining units and waits for the Runtime Expression condition or timeout before completing.",
312
+ "arguments": {
313
+ "UNIT": {
314
+ "type": "STRING",
315
+ "defaultValue": "CHARACTER",
316
+ "menu": "revealUnit"
317
+ },
318
+ "CONDITION": {
319
+ "type": "STRING",
320
+ "defaultValue": "input == \"pressed\""
321
+ },
322
+ "TIMEOUT": {
323
+ "type": "NUMBER",
324
+ "defaultValue": 10
325
+ }
326
+ }
327
+ },
328
+ {
329
+ "opcode": "setBubbleShowAnimation",
330
+ "blockType": "COMMAND",
331
+ "text": "set bubble show animation [MOTION] for [SECONDS] seconds for bubble style [STYLE]",
332
+ "description": "Selects the animation played when a Bubble starts displaying.",
333
+ "arguments": {
334
+ "MOTION": {
335
+ "type": "STRING",
336
+ "defaultValue": "fadeIn",
337
+ "menu": "showMotion"
338
+ },
339
+ "SECONDS": {
340
+ "type": "NUMBER",
341
+ "defaultValue": .2
342
+ },
343
+ "STYLE": {
344
+ "type": "STRING",
345
+ "defaultValue": "dialogue"
346
+ }
347
+ }
348
+ },
349
+ {
350
+ "opcode": "setBubbleHideAnimation",
351
+ "blockType": "COMMAND",
352
+ "text": "set bubble hide animation [MOTION] for [SECONDS] seconds for bubble style [STYLE]",
353
+ "description": "Selects the animation played before a Bubble is closed. It works with both DYNAMIC and RESERVED layout.",
354
+ "arguments": {
355
+ "MOTION": {
356
+ "type": "STRING",
357
+ "defaultValue": "fadeOut",
358
+ "menu": "hideMotion"
359
+ },
360
+ "SECONDS": {
361
+ "type": "NUMBER",
362
+ "defaultValue": .2
363
+ },
364
+ "STYLE": {
365
+ "type": "STRING",
366
+ "defaultValue": "dialogue"
367
+ }
368
+ }
369
+ },
370
+ {
371
+ "opcode": "animateBubble",
372
+ "blockType": "COMMAND",
373
+ "text": "animate this bubble [MOTION]",
374
+ "description": "Plays an immediate display animation such as shake, explode, or a named show/hide motion.",
375
+ "arguments": { "MOTION": {
376
+ "type": "STRING",
377
+ "defaultValue": "shake",
378
+ "menu": "motion"
379
+ } }
380
+ },
381
+ {
382
+ "opcode": "shakeBubble",
383
+ "blockType": "COMMAND",
384
+ "text": "shake this bubble direction [DIRECTION] count [COUNT] ease [EASE]",
385
+ "description": "Shakes the complete Bubble surface, including portrait and text, with an easing selection.",
386
+ "arguments": {
387
+ "DIRECTION": {
388
+ "type": "NUMBER",
389
+ "defaultValue": 90
390
+ },
391
+ "COUNT": {
392
+ "type": "NUMBER",
393
+ "defaultValue": 2
394
+ },
395
+ "EASE": {
396
+ "type": "STRING",
397
+ "defaultValue": "easeInOut",
398
+ "menu": "ease"
399
+ }
400
+ }
401
+ },
402
+ {
403
+ "opcode": "explodeBubble",
404
+ "blockType": "COMMAND",
405
+ "text": "explode this bubble relative scale [SCALE] count [COUNT] ease [EASE]",
406
+ "description": "Changes the complete Bubble surface size by a relative amount for the requested number of cycles.",
407
+ "arguments": {
408
+ "SCALE": {
409
+ "type": "NUMBER",
410
+ "defaultValue": 1.15
411
+ },
412
+ "COUNT": {
413
+ "type": "NUMBER",
414
+ "defaultValue": 2
415
+ },
416
+ "EASE": {
417
+ "type": "STRING",
418
+ "defaultValue": "easeOut",
419
+ "menu": "ease"
420
+ }
421
+ }
422
+ },
423
+ {
424
+ "opcode": "animateBubbleShape",
425
+ "blockType": "COMMAND",
426
+ "text": "animate bubble shape to [VISUAL_STYLE] speed [SPEED] for [SECONDS] seconds",
427
+ "description": "Transitions the Bubble outline to THINKING, DREAMING, YELLING, WAVY, WHISPERING, or another visual style.",
428
+ "arguments": {
429
+ "VISUAL_STYLE": {
430
+ "type": "STRING",
431
+ "defaultValue": "WAVY",
432
+ "menu": "visualStyle"
433
+ },
434
+ "SPEED": {
435
+ "type": "NUMBER",
436
+ "defaultValue": 1
437
+ },
438
+ "SECONDS": {
439
+ "type": "NUMBER",
440
+ "defaultValue": .5
441
+ }
442
+ }
443
+ },
228
444
  {
229
445
  "opcode": "sayWithBubbleStyle",
230
446
  "blockType": "COMMAND",
@@ -346,6 +562,66 @@
346
562
  "awaiting-continue",
347
563
  "idle"
348
564
  ]
565
+ },
566
+ "revealUnit": {
567
+ "acceptReporters": true,
568
+ "items": [
569
+ "CHARACTER",
570
+ "WORD",
571
+ "LINE",
572
+ "BLOCK"
573
+ ]
574
+ },
575
+ "revealLayout": {
576
+ "acceptReporters": true,
577
+ "items": ["DYNAMIC", "RESERVED"]
578
+ },
579
+ "boolean": {
580
+ "acceptReporters": true,
581
+ "items": ["false", "true"]
582
+ },
583
+ "showMotion": {
584
+ "acceptReporters": true,
585
+ "items": [
586
+ "fadeIn",
587
+ "floatIn",
588
+ "zoomIn",
589
+ "riseUp"
590
+ ]
591
+ },
592
+ "hideMotion": {
593
+ "acceptReporters": true,
594
+ "items": [
595
+ "fadeOut",
596
+ "floatOut",
597
+ "zoomOut",
598
+ "sink"
599
+ ]
600
+ },
601
+ "motion": {
602
+ "acceptReporters": true,
603
+ "items": [
604
+ "fadeIn",
605
+ "floatIn",
606
+ "zoomIn",
607
+ "riseUp",
608
+ "fadeOut",
609
+ "floatOut",
610
+ "zoomOut",
611
+ "sink",
612
+ "shake",
613
+ "explode",
614
+ "animateBubbleShape"
615
+ ]
616
+ },
617
+ "ease": {
618
+ "acceptReporters": true,
619
+ "items": [
620
+ "linear",
621
+ "easeIn",
622
+ "easeOut",
623
+ "easeInOut"
624
+ ]
349
625
  }
350
626
  }
351
627
  };
@@ -6049,6 +6325,10 @@
6049
6325
  const direction = normalizeDirection(input.tailDirection);
6050
6326
  const tailLength = normalizeSvgTailLength(input.tailLength ?? svgDefaultTailLength);
6051
6327
  const offset = input.offset === void 0 ? svgDefaultOffset : normalizeSvgOffset(input.offset);
6328
+ const shapeTransition = input.shapeTransition;
6329
+ if (shapeTransition !== void 0) {
6330
+ if (!bubbleVisualStyles.includes(shapeTransition.from) || !bubbleVisualStyles.includes(shapeTransition.to) || !Number.isFinite(shapeTransition.progress) || shapeTransition.progress < 0 || shapeTransition.progress > 1) throw new TypeError("Bubble shape transition is invalid.");
6331
+ }
6052
6332
  const fill = input.fillColor ?? "#fff4cc";
6053
6333
  const border = input.borderColor ?? "#6f5b45";
6054
6334
  const textColor = input.textColor ?? "#25283a";
@@ -6061,8 +6341,10 @@
6061
6341
  y: height / 2
6062
6342
  } : transformedBodyGeometry(roundedRectanglePoints(width, height), width, height, direction, tailLength, offset).bodyCenter;
6063
6343
  const text = input.lines.map((line, index) => `<text x="${textCenter.x}" y="${textCenter.y + (firstBaseline + index * lineHeight - height / 2) * textScale}" text-anchor="middle" fill="${escapeXml(textColor)}" font-family="${escapeXml(fontFamily)}" font-size="${fontSize * textScale}">${escapeXml(line)}</text>`).join("");
6344
+ const body = shapeTransition === void 0 ? renderBody(input.style, width, height, direction, fill, border, tailLength, offset) : `<g opacity="${(1 - shapeTransition.progress).toFixed(4)}">${renderBody(shapeTransition.from, width, height, direction, fill, border, tailLength, offset)}</g><g opacity="${shapeTransition.progress.toFixed(4)}">${renderBody(shapeTransition.to, width, height, direction, fill, border, tailLength, offset)}</g>`;
6064
6345
  const title = escapeXml(input.title ?? `${input.style} bubble`);
6065
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" data-bubble-renderer="canonical" data-bubble-style="${input.style}"><title>${title}</title>${renderBody(input.style, width, height, direction, fill, border, tailLength, offset)}${text}</svg>`;
6346
+ const transitionAttributes = shapeTransition === void 0 ? "" : ` data-bubble-shape-transition-from="${shapeTransition.from}" data-bubble-shape-transition-to="${shapeTransition.to}" data-bubble-shape-transition-progress="${shapeTransition.progress.toFixed(4)}"`;
6347
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" data-bubble-renderer="canonical" data-bubble-style="${input.style}"${transitionAttributes}><title>${title}</title>${body}${text}</svg>`;
6066
6348
  }
6067
6349
  //#endregion
6068
6350
  //#region node_modules/.pnpm/@cto.af+unicode-trie-runtime@3.2.9/node_modules/@cto.af/unicode-trie-runtime/constants.js
@@ -8019,6 +8301,102 @@
8019
8301
  });
8020
8302
  }
8021
8303
  //#endregion
8304
+ //#region src/reveal.ts
8305
+ var bubbleRevealUnits = Object.freeze([
8306
+ "CHARACTER",
8307
+ "WORD",
8308
+ "LINE",
8309
+ "BLOCK"
8310
+ ]);
8311
+ function graphemes(text) {
8312
+ const Segmenter = globalThis.Intl?.Segmenter;
8313
+ if (typeof Segmenter === "function") return [...new Segmenter(void 0, { granularity: "grapheme" }).segment(text)].map(({ segment }) => segment);
8314
+ return Array.from(text);
8315
+ }
8316
+ function requireUnit(value) {
8317
+ if (typeof value !== "string" || !bubbleRevealUnits.includes(value)) throw new TypeError("Bubble reveal unit must be CHARACTER, WORD, LINE, or BLOCK.");
8318
+ return value;
8319
+ }
8320
+ function normalizeBubbleReveal(value) {
8321
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("Bubble reveal must be an object.");
8322
+ const input = value;
8323
+ const allowed = /* @__PURE__ */ new Set([
8324
+ "unit",
8325
+ "delimiters",
8326
+ "showDelimiters",
8327
+ "layout",
8328
+ "intervalSeconds",
8329
+ "sound"
8330
+ ]);
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
+ const unit = requireUnit(input.unit);
8333
+ const delimiters = input.delimiters ?? " \\t\\r\\n";
8334
+ if (typeof delimiters !== "string" || delimiters.length === 0) throw new TypeError("Bubble WORD delimiters must be a non-empty string.");
8335
+ const showDelimiters = input.showDelimiters ?? false;
8336
+ if (typeof showDelimiters !== "boolean") throw new TypeError("Bubble reveal showDelimiters must be boolean.");
8337
+ const layout = input.layout ?? "DYNAMIC";
8338
+ if (layout !== "DYNAMIC" && layout !== "RESERVED") throw new TypeError("Bubble reveal layout must be DYNAMIC or RESERVED.");
8339
+ const intervalSeconds = input.intervalSeconds ?? 0;
8340
+ if (typeof intervalSeconds !== "number" || !Number.isFinite(intervalSeconds) || intervalSeconds < 0) throw new TypeError("Bubble reveal intervalSeconds must be zero or greater.");
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.");
8343
+ return Object.freeze({
8344
+ unit,
8345
+ delimiters,
8346
+ showDelimiters,
8347
+ layout,
8348
+ intervalSeconds,
8349
+ ...sound === void 0 ? {} : { sound: sound.trim() }
8350
+ });
8351
+ }
8352
+ function splitWords(text, delimiters, showDelimiters) {
8353
+ const delimiterSet = new Set(graphemes(delimiters));
8354
+ const result = [];
8355
+ let current = "";
8356
+ for (const character of graphemes(text)) {
8357
+ current += character;
8358
+ if (delimiterSet.has(character)) {
8359
+ if (showDelimiters || current.slice(0, -character.length).length > 0) result.push(showDelimiters ? current : current.slice(0, -character.length));
8360
+ current = "";
8361
+ }
8362
+ }
8363
+ if (current.length > 0) result.push(current);
8364
+ return result.filter((part) => part.length > 0);
8365
+ }
8366
+ /** Returns append-only chunks; joining the first n chunks gives the visible text. */
8367
+ function splitBubbleText(text, reveal) {
8368
+ if (text.length === 0) return Object.freeze([""]);
8369
+ if (reveal.unit === "CHARACTER") return Object.freeze(graphemes(text));
8370
+ if (reveal.unit === "WORD") {
8371
+ const parts = splitWords(text, reveal.delimiters, reveal.showDelimiters);
8372
+ if (reveal.showDelimiters) return Object.freeze(parts);
8373
+ const result = [];
8374
+ let cursor = 0;
8375
+ for (const part of parts) {
8376
+ const index = text.indexOf(part, cursor);
8377
+ if (index < 0) result.push(part);
8378
+ else {
8379
+ result.push(part);
8380
+ cursor = index + part.length;
8381
+ while (cursor < text.length && reveal.delimiters.includes(text[cursor] ?? "")) cursor += 1;
8382
+ }
8383
+ }
8384
+ return Object.freeze(result);
8385
+ }
8386
+ const separator = reveal.unit === "LINE" ? /(?<=\n)/u : /\n{2,}/u;
8387
+ const rawParts = text.split(separator).filter((part) => part.length > 0);
8388
+ if (reveal.unit === "BLOCK") {
8389
+ const separators = [...text.matchAll(/\n{2,}/gu)].map(([match]) => match);
8390
+ const parts = rawParts.map((part, index) => index < separators.length ? `${part}${separators[index] ?? ""}` : part);
8391
+ return Object.freeze(parts.length > 0 ? parts : [text]);
8392
+ }
8393
+ const parts = rawParts;
8394
+ return Object.freeze(parts.length > 0 ? parts : [text]);
8395
+ }
8396
+ function revealedBubbleText(chunks, count) {
8397
+ return chunks.slice(0, Math.max(0, Math.min(count, chunks.length))).join("");
8398
+ }
8399
+ //#endregion
8022
8400
  //#region src/composition.ts
8023
8401
  var BubbleCompositionError = class extends Error {
8024
8402
  constructor(code, message) {
@@ -8034,6 +8412,25 @@
8034
8412
  "talking",
8035
8413
  "awaiting-continue"
8036
8414
  ]);
8415
+ var validMotionNames = /* @__PURE__ */ new Set([
8416
+ "fadeIn",
8417
+ "fadeOut",
8418
+ "floatIn",
8419
+ "floatOut",
8420
+ "zoomIn",
8421
+ "zoomOut",
8422
+ "riseUp",
8423
+ "sink",
8424
+ "shake",
8425
+ "explode",
8426
+ "animateBubbleShape"
8427
+ ]);
8428
+ var validEases = /* @__PURE__ */ new Set([
8429
+ "linear",
8430
+ "easeIn",
8431
+ "easeOut",
8432
+ "easeInOut"
8433
+ ]);
8037
8434
  function isRecord$1(value) {
8038
8435
  return typeof value === "object" && value !== null && !Array.isArray(value);
8039
8436
  }
@@ -8070,6 +8467,64 @@
8070
8467
  ...lipSync === void 0 ? {} : { lipSync }
8071
8468
  });
8072
8469
  }
8470
+ function normalizeMotion(value, label) {
8471
+ if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8472
+ requireExactKeys(value, ["name"], [
8473
+ "durationSeconds",
8474
+ "ease",
8475
+ "direction",
8476
+ "count",
8477
+ "relativeScale",
8478
+ "speed",
8479
+ "visualStyle"
8480
+ ], label);
8481
+ if (!validMotionNames.has(value.name)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.name is not a supported Bubble motion.`);
8482
+ const numberField = (key, minimum, integer = false) => {
8483
+ const candidate = value[key];
8484
+ if (candidate === void 0) return void 0;
8485
+ if (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < minimum || integer && !Number.isInteger(candidate)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.${key} is invalid.`);
8486
+ return candidate;
8487
+ };
8488
+ const durationSeconds = numberField("durationSeconds", 0);
8489
+ const count = numberField("count", 1, true);
8490
+ const relativeScale = numberField("relativeScale", 0);
8491
+ const speed = numberField("speed", 0);
8492
+ const direction = value.direction;
8493
+ if (direction !== void 0 && typeof direction !== "number" && typeof direction !== "string") throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.direction is invalid.`);
8494
+ const ease = value.ease ?? "easeInOut";
8495
+ if (typeof ease !== "string" || !validEases.has(ease)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.ease is invalid.`);
8496
+ const visualStyle = value.visualStyle;
8497
+ if (visualStyle !== void 0 && (typeof visualStyle !== "string" || !bubbleVisualStyles.includes(visualStyle))) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.visualStyle is invalid.`);
8498
+ return Object.freeze({
8499
+ name: value.name,
8500
+ ...durationSeconds === void 0 ? {} : { durationSeconds },
8501
+ ease,
8502
+ ...direction === void 0 ? {} : { direction },
8503
+ ...count === void 0 ? {} : { count },
8504
+ ...relativeScale === void 0 ? {} : { relativeScale },
8505
+ ...speed === void 0 ? {} : { speed },
8506
+ ...visualStyle === void 0 ? {} : { visualStyle }
8507
+ });
8508
+ }
8509
+ function normalizeAudio(value) {
8510
+ if (value === void 0) return void 0;
8511
+ if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble audio must be an object.");
8512
+ requireExactKeys(value, [], [
8513
+ "voice",
8514
+ "reveal",
8515
+ "finish"
8516
+ ], "Bubble audio");
8517
+ const result = {};
8518
+ for (const key of [
8519
+ "voice",
8520
+ "reveal",
8521
+ "finish"
8522
+ ]) {
8523
+ const asset = value[key];
8524
+ if (asset !== void 0) result[key] = requireName(asset, `Bubble audio ${key}`);
8525
+ }
8526
+ return Object.freeze(result);
8527
+ }
8073
8528
  function normalizeStyle(value) {
8074
8529
  if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
8075
8530
  requireExactKeys(value, ["name", "textStyle"], [
@@ -8081,10 +8536,23 @@
8081
8536
  "offset",
8082
8537
  "visualStyle",
8083
8538
  "portrait",
8084
- "continueIndicator"
8539
+ "continueIndicator",
8540
+ "reveal",
8541
+ "audio",
8542
+ "showAnimation",
8543
+ "hideAnimation"
8085
8544
  ], "Bubble style");
8086
8545
  const portrait = value.portrait === void 0 ? void 0 : normalizePortrait(value.portrait);
8087
8546
  const continueIndicator = value.continueIndicator === void 0 ? void 0 : normalizeAnimation(value.continueIndicator, "Bubble continue indicator", 2);
8547
+ let reveal;
8548
+ if (value.reveal !== void 0) try {
8549
+ reveal = normalizeBubbleReveal(value.reveal);
8550
+ } catch (error) {
8551
+ throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", error instanceof Error ? error.message : "Bubble reveal is invalid.");
8552
+ }
8553
+ const audio = normalizeAudio(value.audio);
8554
+ const showAnimation = value.showAnimation === void 0 ? void 0 : normalizeMotion(value.showAnimation, "Bubble showAnimation");
8555
+ const hideAnimation = value.hideAnimation === void 0 ? void 0 : normalizeMotion(value.hideAnimation, "Bubble hideAnimation");
8088
8556
  let placement;
8089
8557
  try {
8090
8558
  placement = normalizeBubblePlacement(value.placement ?? "up-right");
@@ -8120,7 +8588,11 @@
8120
8588
  offset,
8121
8589
  visualStyle,
8122
8590
  ...portrait === void 0 ? {} : { portrait },
8123
- ...continueIndicator === void 0 ? {} : { continueIndicator }
8591
+ ...continueIndicator === void 0 ? {} : { continueIndicator },
8592
+ ...reveal === void 0 ? {} : { reveal },
8593
+ ...audio === void 0 ? {} : { audio },
8594
+ ...showAnimation === void 0 ? {} : { showAnimation },
8595
+ ...hideAnimation === void 0 ? {} : { hideAnimation }
8124
8596
  });
8125
8597
  }
8126
8598
  function validateImageResolver(value) {
@@ -8128,6 +8600,13 @@
8128
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.");
8129
8601
  return value;
8130
8602
  }
8603
+ function validateAudioCapability(value) {
8604
+ 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.");
8606
+ if (value.isRegistered !== void 0 && typeof value.isRegistered !== "function") throw new TypeError("Bubble audio capability isRegistered must be a function.");
8607
+ if (value.getMimeType !== void 0 && typeof value.getMimeType !== "function") throw new TypeError("Bubble audio capability getMimeType must be a function.");
8608
+ return value;
8609
+ }
8131
8610
  function requireImageResolver(value) {
8132
8611
  if (value === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", "Bubble image assets require an image capability. Provide options.imageResolver.");
8133
8612
  return value;
@@ -8177,6 +8656,12 @@
8177
8656
  if (!imageResolver.isRegistered(name)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble image asset is not registered: ${name}`);
8178
8657
  if (!imageResolver.getMimeType(name).startsWith("image/")) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble asset is not an image: ${name}`);
8179
8658
  }
8659
+ function requireAudioAsset(audio, name) {
8660
+ if (audio === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", `Bubble audio assets require an audio capability: ${name}. Provide options.audio.`);
8661
+ if (audio.isRegistered?.(name) === false) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble audio asset is not registered: ${name}`);
8662
+ const mimeType = audio.getMimeType?.(name);
8663
+ if (mimeType !== void 0 && !mimeType.startsWith("audio/")) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble asset is not audio: ${name}`);
8664
+ }
8180
8665
  function styleAssetNames(style) {
8181
8666
  return [...style.portrait === void 0 ? [] : [
8182
8667
  style.portrait.base,
@@ -8267,23 +8752,31 @@
8267
8752
  "kind",
8268
8753
  "text",
8269
8754
  "styleName"
8270
- ], ["animationMode"], "Show bubble input");
8755
+ ], ["animationMode", "reveal"], "Show bubble input");
8271
8756
  if (!validKinds.has(value.kind)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble kind must be say or think.");
8272
8757
  if (typeof value.text !== "string") throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble text must be a string.");
8273
8758
  const animationMode = value.animationMode ?? "talking";
8274
8759
  if (!validAnimationModes$1.has(animationMode)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble animation mode is invalid.");
8760
+ let reveal;
8761
+ if (value.reveal !== void 0) try {
8762
+ reveal = normalizeBubbleReveal(value.reveal);
8763
+ } catch (error) {
8764
+ throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", error instanceof Error ? error.message : "Bubble reveal is invalid.");
8765
+ }
8275
8766
  return {
8276
8767
  actor: value.actor,
8277
8768
  actorKey: requireName(value.actorKey, "Bubble actor key"),
8278
8769
  kind: value.kind,
8279
8770
  text: value.text,
8280
8771
  styleName: requireName(value.styleName, "Bubble style name"),
8281
- animationMode
8772
+ animationMode,
8773
+ ...reveal === void 0 ? {} : { reveal }
8282
8774
  };
8283
8775
  }
8284
8776
  function createBubbleComposition(options) {
8285
8777
  if (!isRecord$1(options)) throw new TypeError("Bubble composition options must be an object.");
8286
8778
  const imageResolver = validateImageResolver(options.imageResolver);
8779
+ const audio = validateAudioCapability(options.audio);
8287
8780
  const svgText = validateSvgText(options.svgText);
8288
8781
  if (typeof options.createSurface !== "function") throw new TypeError("Bubble composition createSurface must be a function.");
8289
8782
  if (options.onAnimationError !== void 0 && typeof options.onAnimationError !== "function") throw new TypeError("Bubble composition onAnimationError must be a function.");
@@ -8309,6 +8802,10 @@
8309
8802
  const style = styles.get(input.styleName);
8310
8803
  if (!style) throw new BubbleCompositionError("BUBBLE-COMPOSITION-002", `Bubble style is not defined: ${input.styleName}`);
8311
8804
  let activeStyle = style;
8805
+ if (input.reveal !== void 0) activeStyle = Object.freeze({
8806
+ ...style,
8807
+ reveal: input.reveal
8808
+ });
8312
8809
  let currentText = input.text;
8313
8810
  const resolveStyleImageCapability = (nextStyle) => {
8314
8811
  const assetNames = new Set(styleAssetNames(nextStyle));
@@ -8317,6 +8814,16 @@
8317
8814
  return nextImageResolver;
8318
8815
  };
8319
8816
  const styleImageResolver = resolveStyleImageCapability(activeStyle);
8817
+ for (const audioAsset of [
8818
+ activeStyle.audio?.voice,
8819
+ activeStyle.audio?.reveal,
8820
+ activeStyle.audio?.finish,
8821
+ activeStyle.reveal?.sound
8822
+ ]) if (audioAsset !== void 0) requireAudioAsset(audio, audioAsset);
8823
+ const playAudio = async (assetName, untilDone = false) => {
8824
+ if (assetName === void 0 || audio === void 0) return;
8825
+ await audio.playSound(assetName, { untilDone });
8826
+ };
8320
8827
  const primeStyleImages = async (nextStyle, nextImageResolver, nextSurface) => {
8321
8828
  const imageCapability = styleAssetNames(nextStyle).length === 0 ? void 0 : requireImageResolver(nextImageResolver);
8322
8829
  const operations = [];
@@ -8372,6 +8879,11 @@
8372
8879
  let blinkLoop;
8373
8880
  let lipSyncLoop;
8374
8881
  let indicatorLoop;
8882
+ let reveal = activeStyle.reveal;
8883
+ let revealChunks = reveal ? splitBubbleText(input.text, reveal) : Object.freeze([input.text]);
8884
+ let revealedCount = reveal ? Math.min(1, revealChunks.length) : 1;
8885
+ let revealTimer;
8886
+ let revealGeneration = 0;
8375
8887
  try {
8376
8888
  surface = validateSurface(await options.createSurface(Object.freeze({
8377
8889
  actor: input.actor,
@@ -8379,10 +8891,19 @@
8379
8891
  kind: input.kind,
8380
8892
  style: activeStyle
8381
8893
  })), activeStyle);
8894
+ const fullText = formatBubbleText(input.text, activeStyle, svgText);
8895
+ if (reveal?.layout === "RESERVED") {
8896
+ svgText.setText({
8897
+ styleName: activeStyle.textStyle,
8898
+ target: surface.targets.text,
8899
+ text: fullText
8900
+ });
8901
+ surface.captureTextLayout?.();
8902
+ }
8382
8903
  svgText.setText({
8383
8904
  styleName: activeStyle.textStyle,
8384
8905
  target: surface.targets.text,
8385
- text: formatBubbleText(input.text, activeStyle, svgText)
8906
+ text: formatBubbleText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text, activeStyle, svgText)
8386
8907
  });
8387
8908
  textOwned = true;
8388
8909
  await primeStyleImages(activeStyle, styleImageResolver, surface);
@@ -8390,6 +8911,38 @@
8390
8911
  let currentAnimationMode = "idle";
8391
8912
  let closed = false;
8392
8913
  let transitionTail = Promise.resolve();
8914
+ const renderVisibleText = async () => {
8915
+ if (!surface) return;
8916
+ const visible = reveal ? revealedBubbleText(revealChunks, revealedCount) : currentText;
8917
+ svgText.setText({
8918
+ styleName: activeStyle.textStyle,
8919
+ target: surface.targets.text,
8920
+ text: formatBubbleText(visible, activeStyle, svgText)
8921
+ });
8922
+ await surface.show();
8923
+ };
8924
+ const stopRevealTimer = () => {
8925
+ revealGeneration += 1;
8926
+ if (revealTimer !== void 0) scheduler.clearTimeout(revealTimer);
8927
+ revealTimer = void 0;
8928
+ };
8929
+ const advanceReveal = async () => {
8930
+ if (!reveal || revealedCount >= revealChunks.length) return false;
8931
+ revealedCount += 1;
8932
+ await renderVisibleText();
8933
+ await playAudio(reveal.sound ?? activeStyle.audio?.reveal);
8934
+ if (revealedCount >= revealChunks.length) stopRevealTimer();
8935
+ return true;
8936
+ };
8937
+ const scheduleReveal = () => {
8938
+ if (!reveal || reveal.intervalSeconds <= 0 || revealedCount >= revealChunks.length) return;
8939
+ const expectedGeneration = revealGeneration;
8940
+ revealTimer = scheduler.setTimeout(() => {
8941
+ revealTimer = void 0;
8942
+ if (closed || expectedGeneration !== revealGeneration) return;
8943
+ transitionTail = transitionTail.then(() => advanceReveal()).then(() => scheduleReveal());
8944
+ }, reveal.intervalSeconds * 1e3);
8945
+ };
8393
8946
  const applyAnimationMode = async (mode) => {
8394
8947
  if (mode === currentAnimationMode) return;
8395
8948
  if (mode === "talking") {
@@ -8416,6 +8969,8 @@
8416
8969
  ]);
8417
8970
  await surface.show();
8418
8971
  surfaceVisible = true;
8972
+ await playAudio(activeStyle.audio?.voice);
8973
+ if (reveal !== void 0) await playAudio(reveal.sound ?? activeStyle.audio?.reveal);
8419
8974
  await blinkLoop?.start({ primed: true });
8420
8975
  await applyAnimationMode(input.animationMode);
8421
8976
  const handle = Object.freeze({
@@ -8429,13 +8984,22 @@
8429
8984
  if (typeof text !== "string") return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble text must be a string."));
8430
8985
  transitionTail = transitionTail.then(async () => {
8431
8986
  if (!surface) return;
8432
- svgText.setText({
8433
- styleName: activeStyle.textStyle,
8434
- target: surface.targets.text,
8435
- text: formatBubbleText(text, activeStyle, svgText)
8436
- });
8987
+ stopRevealTimer();
8437
8988
  currentText = text;
8438
- await surface.show();
8989
+ if (reveal) {
8990
+ revealChunks = splitBubbleText(text, reveal);
8991
+ revealedCount = Math.min(1, revealChunks.length);
8992
+ if (reveal.layout === "RESERVED") {
8993
+ svgText.setText({
8994
+ styleName: activeStyle.textStyle,
8995
+ target: surface.targets.text,
8996
+ text: formatBubbleText(text, activeStyle, svgText)
8997
+ });
8998
+ surface.captureTextLayout?.();
8999
+ }
9000
+ await renderVisibleText();
9001
+ scheduleReveal();
9002
+ } else await renderVisibleText();
8439
9003
  });
8440
9004
  return transitionTail;
8441
9005
  },
@@ -8451,6 +9015,12 @@
8451
9015
  if (!surface) return;
8452
9016
  validateSurface(surface, nextStyle);
8453
9017
  const nextImageResolver = resolveStyleImageCapability(nextStyle);
9018
+ for (const audioAsset of [
9019
+ nextStyle.audio?.voice,
9020
+ nextStyle.audio?.reveal,
9021
+ nextStyle.audio?.finish,
9022
+ nextStyle.reveal?.sound
9023
+ ]) if (audioAsset !== void 0) requireAudioAsset(audio, audioAsset);
8454
9024
  await Promise.all([
8455
9025
  blinkLoop?.stop(),
8456
9026
  lipSyncLoop?.stop(),
@@ -8459,6 +9029,18 @@
8459
9029
  await primeStyleImages(nextStyle, nextImageResolver, surface);
8460
9030
  await surface.updateStyle(nextStyle);
8461
9031
  activeStyle = nextStyle;
9032
+ reveal = nextStyle.reveal;
9033
+ revealChunks = reveal ? splitBubbleText(currentText, reveal) : Object.freeze([currentText]);
9034
+ revealedCount = reveal ? Math.min(1, revealChunks.length) : 1;
9035
+ stopRevealTimer();
9036
+ if (reveal?.layout === "RESERVED") {
9037
+ svgText.setText({
9038
+ styleName: nextStyle.textStyle,
9039
+ target: surface.targets.text,
9040
+ text: formatBubbleText(currentText, nextStyle, svgText)
9041
+ });
9042
+ surface.captureTextLayout?.();
9043
+ }
8462
9044
  svgText.setText({
8463
9045
  styleName: nextStyle.textStyle,
8464
9046
  target: surface.targets.text,
@@ -8475,7 +9057,9 @@
8475
9057
  currentAnimationMode = "idle";
8476
9058
  await blinkLoop?.start({ primed: true });
8477
9059
  await applyAnimationMode(previousMode);
8478
- await surface.show();
9060
+ await renderVisibleText();
9061
+ scheduleReveal();
9062
+ await playAudio(activeStyle.audio?.voice);
8479
9063
  });
8480
9064
  return transitionTail;
8481
9065
  },
@@ -8485,16 +9069,131 @@
8485
9069
  transitionTail = transitionTail.then(() => applyAnimationMode(mode));
8486
9070
  return transitionTail;
8487
9071
  },
9072
+ revealNext() {
9073
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9074
+ let advanced = false;
9075
+ transitionTail = transitionTail.then(async () => {
9076
+ advanced = await advanceReveal();
9077
+ if (advanced) scheduleReveal();
9078
+ });
9079
+ return transitionTail.then(() => advanced);
9080
+ },
9081
+ revealAll() {
9082
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9083
+ transitionTail = transitionTail.then(async () => {
9084
+ stopRevealTimer();
9085
+ if (!reveal) return;
9086
+ while (await advanceReveal());
9087
+ });
9088
+ return transitionTail;
9089
+ },
9090
+ finish(finishInput = {}) {
9091
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9092
+ const timeoutSeconds = finishInput.timeoutSeconds ?? 0;
9093
+ if (!Number.isFinite(timeoutSeconds) || timeoutSeconds < 0) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble finish timeoutSeconds must be zero or greater."));
9094
+ if (finishInput.condition !== void 0 && typeof finishInput.condition !== "function") return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble finish condition must be a function."));
9095
+ transitionTail = transitionTail.then(async () => {
9096
+ stopRevealTimer();
9097
+ if (finishInput.unit !== void 0) {
9098
+ reveal = normalizeBubbleReveal({
9099
+ ...reveal ?? {},
9100
+ unit: finishInput.unit
9101
+ });
9102
+ revealChunks = splitBubbleText(currentText, reveal);
9103
+ revealedCount = Math.min(1, revealChunks.length);
9104
+ if (reveal.layout === "RESERVED" && surface) {
9105
+ svgText.setText({
9106
+ styleName: activeStyle.textStyle,
9107
+ target: surface.targets.text,
9108
+ text: formatBubbleText(currentText, activeStyle, svgText)
9109
+ });
9110
+ surface.captureTextLayout?.();
9111
+ }
9112
+ }
9113
+ if (reveal) while (await advanceReveal());
9114
+ const condition = finishInput.condition;
9115
+ if (condition === void 0 && timeoutSeconds === 0) {
9116
+ await playAudio(activeStyle.audio?.finish);
9117
+ return;
9118
+ }
9119
+ await new Promise((resolve, reject) => {
9120
+ let settled = false;
9121
+ let timeoutHandle;
9122
+ let pollHandle;
9123
+ const settle = () => {
9124
+ if (settled) return;
9125
+ settled = true;
9126
+ if (timeoutHandle !== void 0) scheduler.clearTimeout(timeoutHandle);
9127
+ if (pollHandle !== void 0) scheduler.clearTimeout(pollHandle);
9128
+ playAudio(activeStyle.audio?.finish).then(resolve, reject);
9129
+ };
9130
+ if (timeoutSeconds > 0) timeoutHandle = scheduler.setTimeout(settle, timeoutSeconds * 1e3);
9131
+ if (!condition) return;
9132
+ const poll = () => {
9133
+ let result;
9134
+ try {
9135
+ result = condition();
9136
+ } catch (error) {
9137
+ if (!settled) {
9138
+ settled = true;
9139
+ if (timeoutHandle !== void 0) scheduler.clearTimeout(timeoutHandle);
9140
+ if (pollHandle !== void 0) scheduler.clearTimeout(pollHandle);
9141
+ reject(error);
9142
+ }
9143
+ return;
9144
+ }
9145
+ Promise.resolve(result).then((done) => {
9146
+ if (done) settle();
9147
+ else if (!settled) pollHandle = scheduler.setTimeout(poll, 16);
9148
+ }, (error) => {
9149
+ if (!settled) {
9150
+ settled = true;
9151
+ if (timeoutHandle !== void 0) scheduler.clearTimeout(timeoutHandle);
9152
+ if (pollHandle !== void 0) scheduler.clearTimeout(pollHandle);
9153
+ reject(error);
9154
+ }
9155
+ });
9156
+ };
9157
+ poll();
9158
+ });
9159
+ });
9160
+ return transitionTail;
9161
+ },
9162
+ animate(motion) {
9163
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9164
+ let normalized;
9165
+ try {
9166
+ normalized = normalizeMotion(motion, "Bubble motion");
9167
+ } catch (error) {
9168
+ return Promise.reject(error);
9169
+ }
9170
+ transitionTail = transitionTail.then(async () => {
9171
+ if (normalized.name === "animateBubbleShape" && normalized.visualStyle) {
9172
+ const nextStyle = Object.freeze({
9173
+ ...activeStyle,
9174
+ visualStyle: normalized.visualStyle
9175
+ });
9176
+ await surface?.animate?.(normalized);
9177
+ activeStyle = nextStyle;
9178
+ await surface?.updateStyle(activeStyle);
9179
+ return;
9180
+ }
9181
+ await surface?.animate?.(normalized);
9182
+ });
9183
+ return transitionTail;
9184
+ },
8488
9185
  async close() {
8489
9186
  if (closed) return;
8490
9187
  closed = true;
8491
9188
  const errors = [];
9189
+ stopRevealTimer();
8492
9190
  try {
8493
9191
  await transitionTail;
8494
9192
  } catch (error) {
8495
9193
  errors.push(error);
8496
9194
  }
8497
9195
  for (const operation of [
9196
+ () => activeStyle.hideAnimation === void 0 ? void 0 : surface?.animate?.(activeStyle.hideAnimation),
8498
9197
  () => blinkLoop?.stop(),
8499
9198
  () => lipSyncLoop?.stop(),
8500
9199
  () => indicatorLoop?.stop(),
@@ -8515,8 +9214,11 @@
8515
9214
  }
8516
9215
  });
8517
9216
  active.set(input.actorKey, handle);
9217
+ scheduleReveal();
9218
+ if (activeStyle.showAnimation !== void 0) await handle.animate(activeStyle.showAnimation);
8518
9219
  return handle;
8519
9220
  } catch (error) {
9221
+ active.delete(input.actorKey);
8520
9222
  const cleanupErrors = [];
8521
9223
  const loopResults = await Promise.allSettled([
8522
9224
  blinkLoop?.stop(),
@@ -8653,6 +9355,52 @@
8653
9355
  height
8654
9356
  };
8655
9357
  }
9358
+ function clamp01(value) {
9359
+ return Math.max(0, Math.min(1, value));
9360
+ }
9361
+ function easeProgress(value, ease) {
9362
+ const progress = clamp01(value);
9363
+ switch (ease) {
9364
+ case "linear": return progress;
9365
+ case "easeIn": return progress * progress;
9366
+ case "easeOut": return 1 - (1 - progress) * (1 - progress);
9367
+ case "easeInOut": return progress < .5 ? 2 * progress * progress : 1 - Math.pow(-2 * progress + 2, 2) / 2;
9368
+ default: return progress;
9369
+ }
9370
+ }
9371
+ /**
9372
+ * Drives a motion with the same scheduler used by frame loops and reveal.
9373
+ * The adapter intentionally does not depend on requestAnimationFrame so a
9374
+ * host can provide deterministic time in tests and non-browser runtimes.
9375
+ */
9376
+ function runMotionTimeline(scheduler, durationSeconds, onFrame) {
9377
+ const durationMilliseconds = Math.max(0, durationSeconds * 1e3);
9378
+ if (durationMilliseconds === 0) {
9379
+ onFrame(1);
9380
+ return Promise.resolve();
9381
+ }
9382
+ return new Promise((resolve, reject) => {
9383
+ let elapsed = 0;
9384
+ let timer;
9385
+ const tick = () => {
9386
+ const step = Math.min(16, durationMilliseconds - elapsed);
9387
+ elapsed += step;
9388
+ try {
9389
+ onFrame(clamp01(elapsed / durationMilliseconds));
9390
+ } catch (error) {
9391
+ if (timer !== void 0) scheduler.clearTimeout(timer);
9392
+ reject(error);
9393
+ return;
9394
+ }
9395
+ if (elapsed >= durationMilliseconds) {
9396
+ resolve();
9397
+ return;
9398
+ }
9399
+ timer = scheduler.setTimeout(tick, Math.min(16, durationMilliseconds - elapsed));
9400
+ };
9401
+ timer = scheduler.setTimeout(tick, Math.min(16, durationMilliseconds));
9402
+ });
9403
+ }
8656
9404
  function fitDrawable(renderer, target, boxSize, scaleMultiplier = 1) {
8657
9405
  const native = readSize(renderer, target, {
8658
9406
  width: boxSize,
@@ -8678,7 +9426,7 @@
8678
9426
  const vector = bubbleDirectionVector(direction);
8679
9427
  return (Math.atan2(-vector.x, -vector.y) * 180 / Math.PI % 360 + 360) % 360;
8680
9428
  }
8681
- function createSurface(runtime, actor, actorKey, style) {
9429
+ function createSurface(runtime, actor, actorKey, style, scheduler) {
8682
9430
  const renderer = runtime.renderer;
8683
9431
  const sequence = surfaceSequence;
8684
9432
  surfaceSequence += 1;
@@ -8721,17 +9469,34 @@
8721
9469
  let disposed = false;
8722
9470
  let cachedBodySkinSignature = "";
8723
9471
  let currentStyle = style;
9472
+ let reservedTextSize;
9473
+ const layoutPositions = /* @__PURE__ */ new Map();
9474
+ const layoutScales = /* @__PURE__ */ new Map();
9475
+ let motionTranslation = [0, 0];
9476
+ let motionScaleMultiplier = 1;
9477
+ let motionOpacity = 1;
9478
+ let shapeTransition;
9479
+ const applyMotionTransforms = () => {
9480
+ for (const target of drawables) {
9481
+ const basePosition = layoutPositions.get(target.drawableID);
9482
+ if (basePosition) renderer.updateDrawablePosition(target.drawableID, [basePosition[0] + motionTranslation[0], basePosition[1] + motionTranslation[1]]);
9483
+ const baseScale = layoutScales.get(target.drawableID);
9484
+ if (baseScale) renderer.updateDrawableScale(target.drawableID, [baseScale[0] * motionScaleMultiplier, baseScale[1] * motionScaleMultiplier]);
9485
+ renderer.updateDrawableEffect?.(target.drawableID, "ghost", (1 - motionOpacity) * 100);
9486
+ }
9487
+ };
8724
9488
  const updateVisibility = () => {
8725
9489
  const actorVisible = currentStyle.placement.basis === "background" || actor.visible !== false;
8726
- renderer.updateDrawableVisible(body.drawableID, surfaceVisible && actorVisible && currentStyle.visualStyle !== "NO_BUBBLE");
8727
- renderer.updateDrawableVisible(text.drawableID, surfaceVisible && actorVisible);
8728
- for (const [layer, target] of layerTargets) renderer.updateDrawableVisible(target.drawableID, surfaceVisible && actorVisible && (layerVisibility.get(layer) ?? false));
9490
+ renderer.updateDrawableVisible(body.drawableID, surfaceVisible && actorVisible && currentStyle.visualStyle !== "NO_BUBBLE" && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9491
+ renderer.updateDrawableVisible(text.drawableID, surfaceVisible && actorVisible && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9492
+ for (const [layer, target] of layerTargets) renderer.updateDrawableVisible(target.drawableID, surfaceVisible && actorVisible && (layerVisibility.get(layer) ?? false) && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9493
+ applyMotionTransforms();
8729
9494
  runtime.requestRedraw?.();
8730
9495
  };
8731
9496
  const position = () => {
8732
9497
  if (disposed) return;
8733
9498
  const scaleMultiplier = currentStyle.placement.basis === "actor" ? currentStyle.offset.scalePercent / 100 : 1;
8734
- const nativeTextSize = readSize(renderer, text, {
9499
+ const nativeTextSize = reservedTextSize ?? readSize(renderer, text, {
8735
9500
  width: 180,
8736
9501
  height: 48
8737
9502
  });
@@ -8819,7 +9584,8 @@
8819
9584
  tailLength: currentStyle.tailLength,
8820
9585
  viewportExtraX,
8821
9586
  viewportExtraY,
8822
- visualStyle: currentStyle.visualStyle
9587
+ visualStyle: currentStyle.visualStyle,
9588
+ shapeTransition
8823
9589
  });
8824
9590
  if (nextBodySkinSignature !== cachedBodySkinSignature) {
8825
9591
  const expanded = expandSvgViewport(renderBubbleSvg({
@@ -8830,7 +9596,8 @@
8830
9596
  tailDirection,
8831
9597
  tailLength: currentStyle.tailLength,
8832
9598
  offset: bodyOffset,
8833
- title: `${currentStyle.name} Bubble body`
9599
+ title: `${currentStyle.name} Bubble body`,
9600
+ ...shapeTransition === void 0 ? {} : { shapeTransition }
8834
9601
  }), baseBubbleWidth, baseBubbleHeight, viewportExtraX, viewportExtraY);
8835
9602
  const nextSkinId = renderer.createSVGSkin(expanded);
8836
9603
  if (!Number.isInteger(nextSkinId) || nextSkinId < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "TurboWarp did not create the Bubble body SVG skin.");
@@ -8857,6 +9624,23 @@
8857
9624
  ]) if (target) renderer.updateDrawablePosition(target.drawableID, [portraitX, centerY]);
8858
9625
  renderer.updateDrawablePosition(text.drawableID, [textX, centerY]);
8859
9626
  if (continueIndicator) renderer.updateDrawablePosition(continueIndicator.drawableID, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
9627
+ const remember = (target, positionValue) => {
9628
+ if (!target) return;
9629
+ layoutPositions.set(target.drawableID, positionValue);
9630
+ };
9631
+ remember(body, [centerX - bodyCenterOffset.x, centerY + bodyCenterOffset.y]);
9632
+ remember(text, [textX, centerY]);
9633
+ remember(portraitBase, [portraitX, centerY]);
9634
+ remember(portraitBlink, [portraitX, centerY]);
9635
+ remember(portraitLipSync, [portraitX, centerY]);
9636
+ layoutScales.set(body.drawableID, [100, 100]);
9637
+ layoutScales.set(text.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9638
+ if (portraitBase) layoutScales.set(portraitBase.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9639
+ if (portraitBlink) layoutScales.set(portraitBlink.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9640
+ if (portraitLipSync) layoutScales.set(portraitLipSync.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9641
+ if (continueIndicator) layoutScales.set(continueIndicator.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9642
+ if (continueIndicator) remember(continueIndicator, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
9643
+ applyMotionTransforms();
8860
9644
  updateVisibility();
8861
9645
  };
8862
9646
  const originalVisualChange = actor.onTargetVisualChange;
@@ -8876,12 +9660,138 @@
8876
9660
  if (disposed) return;
8877
9661
  const wasActorRelative = currentStyle.placement.basis === "actor";
8878
9662
  currentStyle = nextStyle;
9663
+ motionTranslation = [0, 0];
9664
+ motionScaleMultiplier = 1;
9665
+ motionOpacity = 1;
9666
+ shapeTransition = void 0;
9667
+ if (nextStyle.reveal?.layout !== "RESERVED") reservedTextSize = void 0;
8879
9668
  const isActorRelative = currentStyle.placement.basis === "actor";
8880
9669
  if (wasActorRelative && !isActorRelative) {
8881
9670
  if (actor.onTargetVisualChange === visualChangeHook) actor.onTargetVisualChange = originalVisualChange ?? null;
8882
9671
  } else if (!wasActorRelative && isActorRelative) actor.onTargetVisualChange = visualChangeHook;
8883
9672
  position();
8884
9673
  },
9674
+ captureTextLayout() {
9675
+ if (disposed) return;
9676
+ reservedTextSize = readSize(renderer, text, {
9677
+ width: 180,
9678
+ height: 48
9679
+ });
9680
+ position();
9681
+ },
9682
+ clearTextLayout() {
9683
+ reservedTextSize = void 0;
9684
+ position();
9685
+ },
9686
+ async animate(motion) {
9687
+ if (disposed) return;
9688
+ const durationSeconds = Math.max(0, motion.durationSeconds ?? 0);
9689
+ const setFrame = () => {
9690
+ if (disposed) return;
9691
+ applyMotionTransforms();
9692
+ updateVisibility();
9693
+ };
9694
+ const eased = (progress) => easeProgress(progress, motion.ease ?? "easeInOut");
9695
+ if (motion.name === "fadeIn" || motion.name === "floatIn" || motion.name === "zoomIn" || motion.name === "riseUp") {
9696
+ surfaceVisible = true;
9697
+ const startingTranslation = motion.name === "floatIn" || motion.name === "riseUp" ? [0, 16] : [0, 0];
9698
+ const startingScale = motion.name === "zoomIn" ? .01 : 1;
9699
+ motionTranslation = startingTranslation;
9700
+ motionScaleMultiplier = startingScale;
9701
+ motionOpacity = motion.name === "fadeIn" ? 0 : 1;
9702
+ setFrame();
9703
+ await runMotionTimeline(scheduler, durationSeconds, (progress) => {
9704
+ const easedProgress = eased(progress);
9705
+ motionTranslation = [startingTranslation[0] * (1 - easedProgress), startingTranslation[1] * (1 - easedProgress)];
9706
+ motionScaleMultiplier = startingScale + (1 - startingScale) * easedProgress;
9707
+ motionOpacity = motion.name === "fadeIn" ? easedProgress : 1;
9708
+ setFrame();
9709
+ });
9710
+ motionTranslation = [0, 0];
9711
+ motionScaleMultiplier = 1;
9712
+ motionOpacity = 1;
9713
+ position();
9714
+ return;
9715
+ }
9716
+ if (motion.name === "fadeOut" || motion.name === "floatOut" || motion.name === "zoomOut" || motion.name === "sink") {
9717
+ const endingTranslation = motion.name === "floatOut" || motion.name === "sink" ? [0, -16] : [0, 0];
9718
+ const endingScale = motion.name === "zoomOut" ? .01 : 1;
9719
+ motionTranslation = [0, 0];
9720
+ motionScaleMultiplier = 1;
9721
+ motionOpacity = 1;
9722
+ setFrame();
9723
+ await runMotionTimeline(scheduler, durationSeconds, (progress) => {
9724
+ const easedProgress = eased(progress);
9725
+ motionTranslation = [endingTranslation[0] * easedProgress, endingTranslation[1] * easedProgress];
9726
+ motionScaleMultiplier = 1 + (endingScale - 1) * easedProgress;
9727
+ motionOpacity = motion.name === "fadeOut" ? 1 - easedProgress : 1;
9728
+ setFrame();
9729
+ });
9730
+ motionTranslation = endingTranslation;
9731
+ motionScaleMultiplier = endingScale;
9732
+ motionOpacity = motion.name === "fadeOut" ? 0 : 1;
9733
+ setFrame();
9734
+ surfaceVisible = false;
9735
+ updateVisibility();
9736
+ motionTranslation = [0, 0];
9737
+ motionScaleMultiplier = 1;
9738
+ motionOpacity = 1;
9739
+ return;
9740
+ }
9741
+ if (motion.name === "shake") {
9742
+ const count = Math.max(1, Math.floor(motion.count ?? 1));
9743
+ const animationDuration = durationSeconds > 0 ? durationSeconds : count * .08;
9744
+ const vector = bubbleDirectionVector(typeof motion.direction === "number" ? motion.direction : motion.direction ?? "right") ?? bubbleDirectionVector("right");
9745
+ const amplitude = 5;
9746
+ motionTranslation = [0, 0];
9747
+ await runMotionTimeline(scheduler, animationDuration, (progress) => {
9748
+ const phase = eased(progress) * count * Math.PI * 2;
9749
+ const displacement = Math.sin(phase) * amplitude;
9750
+ motionTranslation = [vector.x * displacement, vector.y * displacement];
9751
+ setFrame();
9752
+ });
9753
+ motionTranslation = [0, 0];
9754
+ position();
9755
+ return;
9756
+ }
9757
+ if (motion.name === "explode") {
9758
+ const count = Math.max(1, Math.floor(motion.count ?? 1));
9759
+ const animationDuration = durationSeconds > 0 ? durationSeconds : count * .12;
9760
+ const factor = motion.relativeScale ?? 1.15;
9761
+ await runMotionTimeline(scheduler, animationDuration, (progress) => {
9762
+ const easedProgress = eased(progress);
9763
+ const wave = Math.abs(Math.sin(easedProgress * count * Math.PI));
9764
+ motionScaleMultiplier = 1 + (factor - 1) * wave;
9765
+ setFrame();
9766
+ });
9767
+ motionScaleMultiplier = 1;
9768
+ position();
9769
+ return;
9770
+ }
9771
+ if (motion.name === "animateBubbleShape") {
9772
+ const targetStyle = motion.visualStyle ?? currentStyle.visualStyle;
9773
+ const fromStyle = currentStyle.visualStyle;
9774
+ const speed = motion.speed === void 0 ? 1 : Math.max(0, motion.speed);
9775
+ shapeTransition = {
9776
+ from: fromStyle,
9777
+ to: targetStyle,
9778
+ progress: 0
9779
+ };
9780
+ position();
9781
+ await runMotionTimeline(scheduler, durationSeconds, (progress) => {
9782
+ const speedProgress = durationSeconds === 0 ? 1 : clamp01(progress * Math.max(speed, 1) / 1);
9783
+ shapeTransition = {
9784
+ from: fromStyle,
9785
+ to: targetStyle,
9786
+ progress: easeProgress(speedProgress, motion.ease ?? "easeInOut")
9787
+ };
9788
+ position();
9789
+ });
9790
+ shapeTransition = void 0;
9791
+ position();
9792
+ return;
9793
+ }
9794
+ },
8885
9795
  show() {
8886
9796
  if (disposed) return;
8887
9797
  surfaceVisible = true;
@@ -8933,12 +9843,20 @@
8933
9843
  runtime.requestRedraw?.();
8934
9844
  }
8935
9845
  },
8936
- audio: options.audio ?? { async playSound(name, playOptions = {}) {
8937
- const extension = getAssetExtension();
8938
- const method = playOptions.untilDone ? extension?.playSoundUntilDone : extension?.playSound;
8939
- if (typeof method !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "TurboWarp Asset Manager does not provide audio playback.");
8940
- await method.call(extension, { NAME: name });
8941
- } },
9846
+ audio: options.audio ?? {
9847
+ isRegistered(name) {
9848
+ return getAssetExtension().isLoaded({ NAME: name });
9849
+ },
9850
+ getMimeType(name) {
9851
+ return getAssetExtension().getAssetMimeType({ NAME: name });
9852
+ },
9853
+ async playSound(name, playOptions = {}) {
9854
+ const extension = getAssetExtension();
9855
+ const method = playOptions.untilDone ? extension?.playSoundUntilDone : extension?.playSound;
9856
+ if (typeof method !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "TurboWarp Asset Manager does not provide audio playback.");
9857
+ await method.call(extension, { NAME: name });
9858
+ }
9859
+ },
8942
9860
  svgText: options.svgText ?? {
8943
9861
  setText({ styleName, target, text }) {
8944
9862
  svgTextExtension?.setText({
@@ -8957,7 +9875,10 @@
8957
9875
  },
8958
9876
  createSurface({ actor, actorKey, style }) {
8959
9877
  if (!isRecord(actor) || typeof actor.id !== "string") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "Bubble actor target is invalid.");
8960
- return createSurface(runtime, actor, actorKey, style);
9878
+ return createSurface(runtime, actor, actorKey, style, options.scheduler ?? {
9879
+ setTimeout: (callback, milliseconds) => globalThis.setTimeout(callback, milliseconds),
9880
+ clearTimeout: (handle) => globalThis.clearTimeout(handle)
9881
+ });
8961
9882
  },
8962
9883
  ...options.scheduler === void 0 ? {} : { scheduler: options.scheduler },
8963
9884
  ...options.onAnimationError === void 0 ? {} : { onAnimationError: options.onAnimationError }
@@ -8972,8 +9893,39 @@
8972
9893
  "talking",
8973
9894
  "awaiting-continue"
8974
9895
  ]);
9896
+ var validRevealUnits = /* @__PURE__ */ new Set([
9897
+ "CHARACTER",
9898
+ "WORD",
9899
+ "LINE",
9900
+ "BLOCK"
9901
+ ]);
9902
+ var showMotionNames = /* @__PURE__ */ new Set([
9903
+ "fadeIn",
9904
+ "floatIn",
9905
+ "zoomIn",
9906
+ "riseUp"
9907
+ ]);
9908
+ var hideMotionNames = /* @__PURE__ */ new Set([
9909
+ "fadeOut",
9910
+ "floatOut",
9911
+ "zoomOut",
9912
+ "sink"
9913
+ ]);
9914
+ var motionNames = /* @__PURE__ */ new Set([
9915
+ ...showMotionNames,
9916
+ ...hideMotionNames,
9917
+ "shake",
9918
+ "explode",
9919
+ "animateBubbleShape"
9920
+ ]);
9921
+ var easeNames = /* @__PURE__ */ new Set([
9922
+ "linear",
9923
+ "easeIn",
9924
+ "easeOut",
9925
+ "easeInOut"
9926
+ ]);
8975
9927
  var EXTENSION_DOCS_URI = "https://kubohiroya.github.io/turbowarp-bubble/";
8976
- var EXTENSION_VERSION = "0.2.0";
9928
+ var EXTENSION_VERSION = "0.3.0";
8977
9929
  function extensionError(message) {
8978
9930
  const error = /* @__PURE__ */ new Error(`[Bubble] ${message}`);
8979
9931
  Object.defineProperty(error, "code", { value: "BUBBLE-EXTENSION-001" });
@@ -9117,6 +10069,146 @@
9117
10069
  });
9118
10070
  this.installStyle(nextStyle);
9119
10071
  }
10072
+ setBubbleReveal(args) {
10073
+ const style = this.requireStyle(args.STYLE);
10074
+ const unit = this.toString(args.UNIT).trim().toUpperCase();
10075
+ if (!validRevealUnits.has(unit)) throw extensionError("reveal unit must be CHARACTER, WORD, LINE, or BLOCK.");
10076
+ const seconds = Scratch.Cast.toNumber(args.SECONDS);
10077
+ if (!Number.isFinite(seconds) || seconds < 0) throw extensionError("reveal interval must be zero or greater.");
10078
+ const layout = this.toString(args.LAYOUT).trim().toUpperCase();
10079
+ if (layout !== "DYNAMIC" && layout !== "RESERVED") throw extensionError("reveal layout must be DYNAMIC or RESERVED.");
10080
+ const previous = style.reveal;
10081
+ const reveal = Object.freeze({
10082
+ unit,
10083
+ ...previous?.delimiters === void 0 ? {} : { delimiters: previous.delimiters },
10084
+ ...previous?.showDelimiters === void 0 ? {} : { showDelimiters: previous.showDelimiters },
10085
+ layout,
10086
+ intervalSeconds: seconds,
10087
+ ...previous?.sound === void 0 ? {} : { sound: previous.sound }
10088
+ });
10089
+ this.installStyle(Object.freeze({
10090
+ ...style,
10091
+ reveal
10092
+ }));
10093
+ }
10094
+ setBubbleWordDelimiters(args) {
10095
+ const style = this.requireStyle(args.STYLE);
10096
+ const delimiters = this.toString(args.DELIMITERS);
10097
+ if (!delimiters) throw extensionError("word delimiters are empty.");
10098
+ const show = this.toString(args.SHOW).trim().toLowerCase();
10099
+ if (show !== "true" && show !== "false") throw extensionError("show delimiters must be true or false.");
10100
+ const previous = style.reveal;
10101
+ const reveal = Object.freeze({
10102
+ unit: previous?.unit ?? "WORD",
10103
+ delimiters,
10104
+ showDelimiters: show === "true",
10105
+ ...previous?.layout === void 0 ? {} : { layout: previous.layout },
10106
+ ...previous?.intervalSeconds === void 0 ? {} : { intervalSeconds: previous.intervalSeconds },
10107
+ ...previous?.sound === void 0 ? {} : { sound: previous.sound }
10108
+ });
10109
+ this.installStyle(Object.freeze({
10110
+ ...style,
10111
+ reveal
10112
+ }));
10113
+ }
10114
+ setBubbleRevealSound(args) {
10115
+ const style = this.requireStyle(args.STYLE);
10116
+ const asset = this.toString(args.ASSET).trim();
10117
+ const audio = style.audio;
10118
+ const nextAudio = asset ? Object.freeze({
10119
+ ...audio ?? {},
10120
+ reveal: asset
10121
+ }) : (() => {
10122
+ if (!audio) return void 0;
10123
+ const { reveal, ...withoutReveal } = audio;
10124
+ return Object.freeze(withoutReveal);
10125
+ })();
10126
+ this.installStyle(Object.freeze({
10127
+ ...style,
10128
+ ...nextAudio === void 0 ? {} : { audio: nextAudio }
10129
+ }));
10130
+ }
10131
+ setBubbleVoice(args) {
10132
+ const style = this.requireStyle(args.STYLE);
10133
+ const asset = this.toString(args.ASSET).trim();
10134
+ const audio = style.audio;
10135
+ const nextAudio = asset ? Object.freeze({
10136
+ ...audio ?? {},
10137
+ voice: asset
10138
+ }) : (() => {
10139
+ if (!audio) return void 0;
10140
+ const { voice, ...withoutVoice } = audio;
10141
+ return Object.freeze(withoutVoice);
10142
+ })();
10143
+ this.installStyle(Object.freeze({
10144
+ ...style,
10145
+ ...nextAudio === void 0 ? {} : { audio: nextAudio }
10146
+ }));
10147
+ }
10148
+ setBubbleShowAnimation(args) {
10149
+ const style = this.requireStyle(args.STYLE);
10150
+ const motion = this.motionInput(args.MOTION, args.SECONDS, "show", showMotionNames);
10151
+ this.installStyle(Object.freeze({
10152
+ ...style,
10153
+ showAnimation: motion
10154
+ }));
10155
+ }
10156
+ setBubbleHideAnimation(args) {
10157
+ const style = this.requireStyle(args.STYLE);
10158
+ const motion = this.motionInput(args.MOTION, args.SECONDS, "hide", hideMotionNames);
10159
+ this.installStyle(Object.freeze({
10160
+ ...style,
10161
+ hideAnimation: motion
10162
+ }));
10163
+ }
10164
+ async animateBubble(args, util) {
10165
+ const handle = this.requireHandle(util);
10166
+ const name = this.toString(args.MOTION).trim();
10167
+ if (!motionNames.has(name)) throw extensionError("unsupported Bubble motion.");
10168
+ await handle.animate({ name });
10169
+ }
10170
+ async shakeBubble(args, util) {
10171
+ const handle = this.requireHandle(util);
10172
+ const count = Scratch.Cast.toNumber(args.COUNT);
10173
+ if (!Number.isInteger(count) || count < 1) throw extensionError("shake count must be a positive integer.");
10174
+ const ease = this.toString(args.EASE).trim();
10175
+ if (!easeNames.has(ease)) throw extensionError("unsupported easing.");
10176
+ await handle.animate({
10177
+ name: "shake",
10178
+ direction: Scratch.Cast.toNumber(args.DIRECTION),
10179
+ count,
10180
+ ease
10181
+ });
10182
+ }
10183
+ async explodeBubble(args, util) {
10184
+ const handle = this.requireHandle(util);
10185
+ const scale = Scratch.Cast.toNumber(args.SCALE);
10186
+ const count = Scratch.Cast.toNumber(args.COUNT);
10187
+ if (!Number.isFinite(scale) || scale <= 0) throw extensionError("explode scale must be positive.");
10188
+ if (!Number.isInteger(count) || count < 1) throw extensionError("explode count must be a positive integer.");
10189
+ const ease = this.toString(args.EASE).trim();
10190
+ if (!easeNames.has(ease)) throw extensionError("unsupported easing.");
10191
+ await handle.animate({
10192
+ name: "explode",
10193
+ relativeScale: scale,
10194
+ count,
10195
+ ease
10196
+ });
10197
+ }
10198
+ async animateBubbleShape(args, util) {
10199
+ const handle = this.requireHandle(util);
10200
+ const visualStyle = this.toString(args.VISUAL_STYLE).trim().toUpperCase();
10201
+ if (!bubbleVisualStyles.includes(visualStyle)) throw extensionError("unsupported Bubble visual style.");
10202
+ const speed = Scratch.Cast.toNumber(args.SPEED);
10203
+ const seconds = Scratch.Cast.toNumber(args.SECONDS);
10204
+ if (!Number.isFinite(speed) || speed < 0 || !Number.isFinite(seconds) || seconds < 0) throw extensionError("shape animation speed and duration must be zero or greater.");
10205
+ await handle.animate({
10206
+ name: "animateBubbleShape",
10207
+ visualStyle,
10208
+ speed,
10209
+ durationSeconds: seconds
10210
+ });
10211
+ }
9120
10212
  sayWithBubbleStyle(args, util) {
9121
10213
  return this.show("say", args, util);
9122
10214
  }
@@ -9177,6 +10269,22 @@
9177
10269
  checkCondition();
9178
10270
  });
9179
10271
  }
10272
+ async finishBubbleReveal(args, util) {
10273
+ const handle = this.requireHandle(util);
10274
+ const unit = this.toString(args.UNIT).trim().toUpperCase();
10275
+ if (!validRevealUnits.has(unit)) throw extensionError("reveal unit is invalid.");
10276
+ const conditionText = this.toString(args.CONDITION).trim();
10277
+ const timeoutSeconds = Scratch.Cast.toNumber(args.TIMEOUT);
10278
+ if (!conditionText) throw extensionError("finish condition is empty.");
10279
+ if (!Number.isFinite(timeoutSeconds) || timeoutSeconds < 0) throw extensionError("finish timeout must be zero or greater.");
10280
+ const expression = this.runtime.ext_kubohiroyaruntimeexpression;
10281
+ if (!this.isRecord(expression) || typeof expression.runtimeCondition !== "function") throw extensionError("Bubble finish requires Runtime Expression. Load @kubohiroya/turbowarp-runtime-expression before using this block.");
10282
+ await handle.finish({
10283
+ unit,
10284
+ timeoutSeconds,
10285
+ condition: () => expression.runtimeCondition({ EXPRESSION: conditionText })
10286
+ });
10287
+ }
9180
10288
  async closeBubble(_args, util) {
9181
10289
  const target = this.requireTarget(util);
9182
10290
  await this.releaseOwnedTarget(target.id);
@@ -9264,6 +10372,16 @@
9264
10372
  frameIntervalSeconds: seconds
9265
10373
  });
9266
10374
  }
10375
+ motionInput(value, secondsValue, label, valid) {
10376
+ const name = this.toString(value).trim();
10377
+ if (!valid.has(name)) throw extensionError(`${label} animation is invalid.`);
10378
+ const seconds = Scratch.Cast.toNumber(secondsValue);
10379
+ if (!Number.isFinite(seconds) || seconds < 0) throw extensionError(`${label} animation duration must be zero or greater.`);
10380
+ return Object.freeze({
10381
+ name,
10382
+ durationSeconds: seconds
10383
+ });
10384
+ }
9267
10385
  setPortraitAnimation(field, args) {
9268
10386
  const style = this.requireStyle(args.STYLE);
9269
10387
  const portrait = style.portrait;
@@ -9293,6 +10411,12 @@
9293
10411
  if (!this.isTarget(target)) throw extensionError("target is unavailable.");
9294
10412
  return target;
9295
10413
  }
10414
+ requireHandle(util) {
10415
+ const target = this.requireTarget(util);
10416
+ const handle = this.handles.get(target.id);
10417
+ if (!handle) throw extensionError("this target does not have an active bubble.");
10418
+ return handle;
10419
+ }
9296
10420
  placementInput(placement) {
9297
10421
  return placement.basis === "actor" ? placement.direction : placement.region;
9298
10422
  }