@kubohiroya/turbowarp-bubble 0.2.0 → 0.3.1

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 ?? " \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.length === 0)) 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 }
8350
+ });
8351
+ }
8352
+ function splitWords(text, delimiters, showDelimiters) {
8353
+ const delimiterSet = new Set(Array.from(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
  }
@@ -8047,11 +8444,15 @@
8047
8444
  if (typeof value !== "string" || value.trim().length === 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be a non-empty string.`);
8048
8445
  return value.trim();
8049
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
+ }
8050
8451
  function normalizeAnimation(value, label, minimumFrames) {
8051
8452
  if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8052
8453
  requireExactKeys(value, ["frames", "frameIntervalSeconds"], [], label);
8053
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"}.`);
8054
- 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}]`)));
8055
8456
  const interval = value.frameIntervalSeconds;
8056
8457
  if (typeof interval !== "number" || !Number.isFinite(interval) || interval <= 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.frameIntervalSeconds must be a positive finite number.`);
8057
8458
  return Object.freeze({
@@ -8065,11 +8466,69 @@
8065
8466
  const blink = value.blink === void 0 ? void 0 : normalizeAnimation(value.blink, "Bubble portrait blink", 1);
8066
8467
  const lipSync = value.lipSync === void 0 ? void 0 : normalizeAnimation(value.lipSync, "Bubble portrait lip-sync", 1);
8067
8468
  return Object.freeze({
8068
- base: requireName(value.base, "Bubble portrait base"),
8469
+ base: requireAssetName(value.base, "Bubble portrait base"),
8069
8470
  ...blink === void 0 ? {} : { blink },
8070
8471
  ...lipSync === void 0 ? {} : { lipSync }
8071
8472
  });
8072
8473
  }
8474
+ function normalizeMotion(value, label) {
8475
+ if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
8476
+ requireExactKeys(value, ["name"], [
8477
+ "durationSeconds",
8478
+ "ease",
8479
+ "direction",
8480
+ "count",
8481
+ "relativeScale",
8482
+ "speed",
8483
+ "visualStyle"
8484
+ ], label);
8485
+ if (!validMotionNames.has(value.name)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.name is not a supported Bubble motion.`);
8486
+ const numberField = (key, minimum, integer = false) => {
8487
+ const candidate = value[key];
8488
+ if (candidate === void 0) return void 0;
8489
+ if (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < minimum || integer && !Number.isInteger(candidate)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.${key} is invalid.`);
8490
+ return candidate;
8491
+ };
8492
+ const durationSeconds = numberField("durationSeconds", 0);
8493
+ const count = numberField("count", 1, true);
8494
+ const relativeScale = numberField("relativeScale", 0);
8495
+ const speed = numberField("speed", 0);
8496
+ const direction = value.direction;
8497
+ if (direction !== void 0 && typeof direction !== "number" && typeof direction !== "string") throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.direction is invalid.`);
8498
+ const ease = value.ease ?? "easeInOut";
8499
+ if (typeof ease !== "string" || !validEases.has(ease)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.ease is invalid.`);
8500
+ const visualStyle = value.visualStyle;
8501
+ if (visualStyle !== void 0 && (typeof visualStyle !== "string" || !bubbleVisualStyles.includes(visualStyle))) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.visualStyle is invalid.`);
8502
+ return Object.freeze({
8503
+ name: value.name,
8504
+ ...durationSeconds === void 0 ? {} : { durationSeconds },
8505
+ ease,
8506
+ ...direction === void 0 ? {} : { direction },
8507
+ ...count === void 0 ? {} : { count },
8508
+ ...relativeScale === void 0 ? {} : { relativeScale },
8509
+ ...speed === void 0 ? {} : { speed },
8510
+ ...visualStyle === void 0 ? {} : { visualStyle }
8511
+ });
8512
+ }
8513
+ function normalizeAudio(value) {
8514
+ if (value === void 0) return void 0;
8515
+ if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble audio must be an object.");
8516
+ requireExactKeys(value, [], [
8517
+ "voice",
8518
+ "reveal",
8519
+ "finish"
8520
+ ], "Bubble audio");
8521
+ const result = {};
8522
+ for (const key of [
8523
+ "voice",
8524
+ "reveal",
8525
+ "finish"
8526
+ ]) {
8527
+ const asset = value[key];
8528
+ if (asset !== void 0) result[key] = requireAssetName(asset, `Bubble audio ${key}`);
8529
+ }
8530
+ return Object.freeze(result);
8531
+ }
8073
8532
  function normalizeStyle(value) {
8074
8533
  if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
8075
8534
  requireExactKeys(value, ["name", "textStyle"], [
@@ -8081,10 +8540,23 @@
8081
8540
  "offset",
8082
8541
  "visualStyle",
8083
8542
  "portrait",
8084
- "continueIndicator"
8543
+ "continueIndicator",
8544
+ "reveal",
8545
+ "audio",
8546
+ "showAnimation",
8547
+ "hideAnimation"
8085
8548
  ], "Bubble style");
8086
8549
  const portrait = value.portrait === void 0 ? void 0 : normalizePortrait(value.portrait);
8087
8550
  const continueIndicator = value.continueIndicator === void 0 ? void 0 : normalizeAnimation(value.continueIndicator, "Bubble continue indicator", 2);
8551
+ let reveal;
8552
+ if (value.reveal !== void 0) try {
8553
+ reveal = normalizeBubbleReveal(value.reveal);
8554
+ } catch (error) {
8555
+ throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", error instanceof Error ? error.message : "Bubble reveal is invalid.");
8556
+ }
8557
+ const audio = normalizeAudio(value.audio);
8558
+ const showAnimation = value.showAnimation === void 0 ? void 0 : normalizeMotion(value.showAnimation, "Bubble showAnimation");
8559
+ const hideAnimation = value.hideAnimation === void 0 ? void 0 : normalizeMotion(value.hideAnimation, "Bubble hideAnimation");
8088
8560
  let placement;
8089
8561
  try {
8090
8562
  placement = normalizeBubblePlacement(value.placement ?? "up-right");
@@ -8120,7 +8592,11 @@
8120
8592
  offset,
8121
8593
  visualStyle,
8122
8594
  ...portrait === void 0 ? {} : { portrait },
8123
- ...continueIndicator === void 0 ? {} : { continueIndicator }
8595
+ ...continueIndicator === void 0 ? {} : { continueIndicator },
8596
+ ...reveal === void 0 ? {} : { reveal },
8597
+ ...audio === void 0 ? {} : { audio },
8598
+ ...showAnimation === void 0 ? {} : { showAnimation },
8599
+ ...hideAnimation === void 0 ? {} : { hideAnimation }
8124
8600
  });
8125
8601
  }
8126
8602
  function validateImageResolver(value) {
@@ -8128,6 +8604,13 @@
8128
8604
  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
8605
  return value;
8130
8606
  }
8607
+ function validateAudioCapability(value) {
8608
+ if (value === void 0) return void 0;
8609
+ if (!isRecord$1(value) || typeof value.playSound !== "function") throw new TypeError("Bubble audio capability must provide playSound.");
8610
+ if (value.isRegistered !== void 0 && typeof value.isRegistered !== "function") throw new TypeError("Bubble audio capability isRegistered must be a function.");
8611
+ if (value.getMimeType !== void 0 && typeof value.getMimeType !== "function") throw new TypeError("Bubble audio capability getMimeType must be a function.");
8612
+ return value;
8613
+ }
8131
8614
  function requireImageResolver(value) {
8132
8615
  if (value === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", "Bubble image assets require an image capability. Provide options.imageResolver.");
8133
8616
  return value;
@@ -8177,6 +8660,12 @@
8177
8660
  if (!imageResolver.isRegistered(name)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble image asset is not registered: ${name}`);
8178
8661
  if (!imageResolver.getMimeType(name).startsWith("image/")) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble asset is not an image: ${name}`);
8179
8662
  }
8663
+ function requireAudioAsset(audio, name) {
8664
+ if (audio === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", `Bubble audio assets require an audio capability: ${name}. Provide options.audio.`);
8665
+ if (audio.isRegistered?.(name) === false) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble audio asset is not registered: ${name}`);
8666
+ const mimeType = audio.getMimeType?.(name);
8667
+ if (mimeType !== void 0 && !mimeType.startsWith("audio/")) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble asset is not audio: ${name}`);
8668
+ }
8180
8669
  function styleAssetNames(style) {
8181
8670
  return [...style.portrait === void 0 ? [] : [
8182
8671
  style.portrait.base,
@@ -8267,23 +8756,31 @@
8267
8756
  "kind",
8268
8757
  "text",
8269
8758
  "styleName"
8270
- ], ["animationMode"], "Show bubble input");
8759
+ ], ["animationMode", "reveal"], "Show bubble input");
8271
8760
  if (!validKinds.has(value.kind)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble kind must be say or think.");
8272
8761
  if (typeof value.text !== "string") throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble text must be a string.");
8273
8762
  const animationMode = value.animationMode ?? "talking";
8274
8763
  if (!validAnimationModes$1.has(animationMode)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble animation mode is invalid.");
8764
+ let reveal;
8765
+ if (value.reveal !== void 0) try {
8766
+ reveal = normalizeBubbleReveal(value.reveal);
8767
+ } catch (error) {
8768
+ throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", error instanceof Error ? error.message : "Bubble reveal is invalid.");
8769
+ }
8275
8770
  return {
8276
8771
  actor: value.actor,
8277
8772
  actorKey: requireName(value.actorKey, "Bubble actor key"),
8278
8773
  kind: value.kind,
8279
8774
  text: value.text,
8280
8775
  styleName: requireName(value.styleName, "Bubble style name"),
8281
- animationMode
8776
+ animationMode,
8777
+ ...reveal === void 0 ? {} : { reveal }
8282
8778
  };
8283
8779
  }
8284
8780
  function createBubbleComposition(options) {
8285
8781
  if (!isRecord$1(options)) throw new TypeError("Bubble composition options must be an object.");
8286
8782
  const imageResolver = validateImageResolver(options.imageResolver);
8783
+ const audio = validateAudioCapability(options.audio);
8287
8784
  const svgText = validateSvgText(options.svgText);
8288
8785
  if (typeof options.createSurface !== "function") throw new TypeError("Bubble composition createSurface must be a function.");
8289
8786
  if (options.onAnimationError !== void 0 && typeof options.onAnimationError !== "function") throw new TypeError("Bubble composition onAnimationError must be a function.");
@@ -8309,6 +8806,10 @@
8309
8806
  const style = styles.get(input.styleName);
8310
8807
  if (!style) throw new BubbleCompositionError("BUBBLE-COMPOSITION-002", `Bubble style is not defined: ${input.styleName}`);
8311
8808
  let activeStyle = style;
8809
+ if (input.reveal !== void 0) activeStyle = Object.freeze({
8810
+ ...style,
8811
+ reveal: input.reveal
8812
+ });
8312
8813
  let currentText = input.text;
8313
8814
  const resolveStyleImageCapability = (nextStyle) => {
8314
8815
  const assetNames = new Set(styleAssetNames(nextStyle));
@@ -8317,6 +8818,16 @@
8317
8818
  return nextImageResolver;
8318
8819
  };
8319
8820
  const styleImageResolver = resolveStyleImageCapability(activeStyle);
8821
+ for (const audioAsset of [
8822
+ activeStyle.audio?.voice,
8823
+ activeStyle.audio?.reveal,
8824
+ activeStyle.audio?.finish,
8825
+ activeStyle.reveal?.sound
8826
+ ]) if (audioAsset !== void 0) requireAudioAsset(audio, audioAsset);
8827
+ const playAudio = async (assetName, untilDone = false) => {
8828
+ if (assetName === void 0 || audio === void 0) return;
8829
+ await audio.playSound(assetName, { untilDone });
8830
+ };
8320
8831
  const primeStyleImages = async (nextStyle, nextImageResolver, nextSurface) => {
8321
8832
  const imageCapability = styleAssetNames(nextStyle).length === 0 ? void 0 : requireImageResolver(nextImageResolver);
8322
8833
  const operations = [];
@@ -8372,6 +8883,11 @@
8372
8883
  let blinkLoop;
8373
8884
  let lipSyncLoop;
8374
8885
  let indicatorLoop;
8886
+ let reveal = activeStyle.reveal;
8887
+ let revealChunks = reveal ? splitBubbleText(input.text, reveal) : Object.freeze([input.text]);
8888
+ let revealedCount = reveal ? Math.min(1, revealChunks.length) : 1;
8889
+ let revealTimer;
8890
+ let revealGeneration = 0;
8375
8891
  try {
8376
8892
  surface = validateSurface(await options.createSurface(Object.freeze({
8377
8893
  actor: input.actor,
@@ -8379,10 +8895,19 @@
8379
8895
  kind: input.kind,
8380
8896
  style: activeStyle
8381
8897
  })), activeStyle);
8898
+ const fullText = formatBubbleText(input.text, activeStyle, svgText);
8899
+ if (reveal?.layout === "RESERVED") {
8900
+ svgText.setText({
8901
+ styleName: activeStyle.textStyle,
8902
+ target: surface.targets.text,
8903
+ text: fullText
8904
+ });
8905
+ surface.captureTextLayout?.();
8906
+ }
8382
8907
  svgText.setText({
8383
8908
  styleName: activeStyle.textStyle,
8384
8909
  target: surface.targets.text,
8385
- text: formatBubbleText(input.text, activeStyle, svgText)
8910
+ text: formatBubbleText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text, activeStyle, svgText)
8386
8911
  });
8387
8912
  textOwned = true;
8388
8913
  await primeStyleImages(activeStyle, styleImageResolver, surface);
@@ -8390,6 +8915,38 @@
8390
8915
  let currentAnimationMode = "idle";
8391
8916
  let closed = false;
8392
8917
  let transitionTail = Promise.resolve();
8918
+ const renderVisibleText = async () => {
8919
+ if (!surface) return;
8920
+ const visible = reveal ? revealedBubbleText(revealChunks, revealedCount) : currentText;
8921
+ svgText.setText({
8922
+ styleName: activeStyle.textStyle,
8923
+ target: surface.targets.text,
8924
+ text: formatBubbleText(visible, activeStyle, svgText)
8925
+ });
8926
+ await surface.show();
8927
+ };
8928
+ const stopRevealTimer = () => {
8929
+ revealGeneration += 1;
8930
+ if (revealTimer !== void 0) scheduler.clearTimeout(revealTimer);
8931
+ revealTimer = void 0;
8932
+ };
8933
+ const advanceReveal = async () => {
8934
+ if (!reveal || revealedCount >= revealChunks.length) return false;
8935
+ revealedCount += 1;
8936
+ await renderVisibleText();
8937
+ await playAudio(reveal.sound ?? activeStyle.audio?.reveal);
8938
+ if (revealedCount >= revealChunks.length) stopRevealTimer();
8939
+ return true;
8940
+ };
8941
+ const scheduleReveal = () => {
8942
+ if (!reveal || reveal.intervalSeconds <= 0 || revealedCount >= revealChunks.length) return;
8943
+ const expectedGeneration = revealGeneration;
8944
+ revealTimer = scheduler.setTimeout(() => {
8945
+ revealTimer = void 0;
8946
+ if (closed || expectedGeneration !== revealGeneration) return;
8947
+ transitionTail = transitionTail.then(() => advanceReveal()).then(() => scheduleReveal());
8948
+ }, reveal.intervalSeconds * 1e3);
8949
+ };
8393
8950
  const applyAnimationMode = async (mode) => {
8394
8951
  if (mode === currentAnimationMode) return;
8395
8952
  if (mode === "talking") {
@@ -8416,6 +8973,8 @@
8416
8973
  ]);
8417
8974
  await surface.show();
8418
8975
  surfaceVisible = true;
8976
+ await playAudio(activeStyle.audio?.voice);
8977
+ if (reveal !== void 0) await playAudio(reveal.sound ?? activeStyle.audio?.reveal);
8419
8978
  await blinkLoop?.start({ primed: true });
8420
8979
  await applyAnimationMode(input.animationMode);
8421
8980
  const handle = Object.freeze({
@@ -8429,13 +8988,22 @@
8429
8988
  if (typeof text !== "string") return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble text must be a string."));
8430
8989
  transitionTail = transitionTail.then(async () => {
8431
8990
  if (!surface) return;
8432
- svgText.setText({
8433
- styleName: activeStyle.textStyle,
8434
- target: surface.targets.text,
8435
- text: formatBubbleText(text, activeStyle, svgText)
8436
- });
8991
+ stopRevealTimer();
8437
8992
  currentText = text;
8438
- await surface.show();
8993
+ if (reveal) {
8994
+ revealChunks = splitBubbleText(text, reveal);
8995
+ revealedCount = Math.min(1, revealChunks.length);
8996
+ if (reveal.layout === "RESERVED") {
8997
+ svgText.setText({
8998
+ styleName: activeStyle.textStyle,
8999
+ target: surface.targets.text,
9000
+ text: formatBubbleText(text, activeStyle, svgText)
9001
+ });
9002
+ surface.captureTextLayout?.();
9003
+ }
9004
+ await renderVisibleText();
9005
+ scheduleReveal();
9006
+ } else await renderVisibleText();
8439
9007
  });
8440
9008
  return transitionTail;
8441
9009
  },
@@ -8451,6 +9019,12 @@
8451
9019
  if (!surface) return;
8452
9020
  validateSurface(surface, nextStyle);
8453
9021
  const nextImageResolver = resolveStyleImageCapability(nextStyle);
9022
+ for (const audioAsset of [
9023
+ nextStyle.audio?.voice,
9024
+ nextStyle.audio?.reveal,
9025
+ nextStyle.audio?.finish,
9026
+ nextStyle.reveal?.sound
9027
+ ]) if (audioAsset !== void 0) requireAudioAsset(audio, audioAsset);
8454
9028
  await Promise.all([
8455
9029
  blinkLoop?.stop(),
8456
9030
  lipSyncLoop?.stop(),
@@ -8459,6 +9033,18 @@
8459
9033
  await primeStyleImages(nextStyle, nextImageResolver, surface);
8460
9034
  await surface.updateStyle(nextStyle);
8461
9035
  activeStyle = nextStyle;
9036
+ reveal = nextStyle.reveal;
9037
+ revealChunks = reveal ? splitBubbleText(currentText, reveal) : Object.freeze([currentText]);
9038
+ revealedCount = reveal ? Math.min(1, revealChunks.length) : 1;
9039
+ stopRevealTimer();
9040
+ if (reveal?.layout === "RESERVED") {
9041
+ svgText.setText({
9042
+ styleName: nextStyle.textStyle,
9043
+ target: surface.targets.text,
9044
+ text: formatBubbleText(currentText, nextStyle, svgText)
9045
+ });
9046
+ surface.captureTextLayout?.();
9047
+ }
8462
9048
  svgText.setText({
8463
9049
  styleName: nextStyle.textStyle,
8464
9050
  target: surface.targets.text,
@@ -8475,7 +9061,9 @@
8475
9061
  currentAnimationMode = "idle";
8476
9062
  await blinkLoop?.start({ primed: true });
8477
9063
  await applyAnimationMode(previousMode);
8478
- await surface.show();
9064
+ await renderVisibleText();
9065
+ scheduleReveal();
9066
+ await playAudio(activeStyle.audio?.voice);
8479
9067
  });
8480
9068
  return transitionTail;
8481
9069
  },
@@ -8485,16 +9073,131 @@
8485
9073
  transitionTail = transitionTail.then(() => applyAnimationMode(mode));
8486
9074
  return transitionTail;
8487
9075
  },
9076
+ revealNext() {
9077
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9078
+ let advanced = false;
9079
+ transitionTail = transitionTail.then(async () => {
9080
+ advanced = await advanceReveal();
9081
+ if (advanced) scheduleReveal();
9082
+ });
9083
+ return transitionTail.then(() => advanced);
9084
+ },
9085
+ revealAll() {
9086
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9087
+ transitionTail = transitionTail.then(async () => {
9088
+ stopRevealTimer();
9089
+ if (!reveal) return;
9090
+ while (await advanceReveal());
9091
+ });
9092
+ return transitionTail;
9093
+ },
9094
+ finish(finishInput = {}) {
9095
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9096
+ const timeoutSeconds = finishInput.timeoutSeconds ?? 0;
9097
+ if (!Number.isFinite(timeoutSeconds) || timeoutSeconds < 0) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble finish timeoutSeconds must be zero or greater."));
9098
+ if (finishInput.condition !== void 0 && typeof finishInput.condition !== "function") return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble finish condition must be a function."));
9099
+ transitionTail = transitionTail.then(async () => {
9100
+ stopRevealTimer();
9101
+ if (finishInput.unit !== void 0) {
9102
+ reveal = normalizeBubbleReveal({
9103
+ ...reveal ?? {},
9104
+ unit: finishInput.unit
9105
+ });
9106
+ revealChunks = splitBubbleText(currentText, reveal);
9107
+ revealedCount = Math.min(1, revealChunks.length);
9108
+ if (reveal.layout === "RESERVED" && surface) {
9109
+ svgText.setText({
9110
+ styleName: activeStyle.textStyle,
9111
+ target: surface.targets.text,
9112
+ text: formatBubbleText(currentText, activeStyle, svgText)
9113
+ });
9114
+ surface.captureTextLayout?.();
9115
+ }
9116
+ }
9117
+ if (reveal) while (await advanceReveal());
9118
+ const condition = finishInput.condition;
9119
+ if (condition === void 0 && timeoutSeconds === 0) {
9120
+ await playAudio(activeStyle.audio?.finish);
9121
+ return;
9122
+ }
9123
+ await new Promise((resolve, reject) => {
9124
+ let settled = false;
9125
+ let timeoutHandle;
9126
+ let pollHandle;
9127
+ const settle = () => {
9128
+ if (settled) return;
9129
+ settled = true;
9130
+ if (timeoutHandle !== void 0) scheduler.clearTimeout(timeoutHandle);
9131
+ if (pollHandle !== void 0) scheduler.clearTimeout(pollHandle);
9132
+ playAudio(activeStyle.audio?.finish).then(resolve, reject);
9133
+ };
9134
+ if (timeoutSeconds > 0) timeoutHandle = scheduler.setTimeout(settle, timeoutSeconds * 1e3);
9135
+ if (!condition) return;
9136
+ const poll = () => {
9137
+ let result;
9138
+ try {
9139
+ result = condition();
9140
+ } catch (error) {
9141
+ if (!settled) {
9142
+ settled = true;
9143
+ if (timeoutHandle !== void 0) scheduler.clearTimeout(timeoutHandle);
9144
+ if (pollHandle !== void 0) scheduler.clearTimeout(pollHandle);
9145
+ reject(error);
9146
+ }
9147
+ return;
9148
+ }
9149
+ Promise.resolve(result).then((done) => {
9150
+ if (done) settle();
9151
+ else if (!settled) pollHandle = scheduler.setTimeout(poll, 16);
9152
+ }, (error) => {
9153
+ if (!settled) {
9154
+ settled = true;
9155
+ if (timeoutHandle !== void 0) scheduler.clearTimeout(timeoutHandle);
9156
+ if (pollHandle !== void 0) scheduler.clearTimeout(pollHandle);
9157
+ reject(error);
9158
+ }
9159
+ });
9160
+ };
9161
+ poll();
9162
+ });
9163
+ });
9164
+ return transitionTail;
9165
+ },
9166
+ animate(motion) {
9167
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9168
+ let normalized;
9169
+ try {
9170
+ normalized = normalizeMotion(motion, "Bubble motion");
9171
+ } catch (error) {
9172
+ return Promise.reject(error);
9173
+ }
9174
+ transitionTail = transitionTail.then(async () => {
9175
+ if (normalized.name === "animateBubbleShape" && normalized.visualStyle) {
9176
+ const nextStyle = Object.freeze({
9177
+ ...activeStyle,
9178
+ visualStyle: normalized.visualStyle
9179
+ });
9180
+ await surface?.animate?.(normalized);
9181
+ activeStyle = nextStyle;
9182
+ await surface?.updateStyle(activeStyle);
9183
+ return;
9184
+ }
9185
+ await surface?.animate?.(normalized);
9186
+ });
9187
+ return transitionTail;
9188
+ },
8488
9189
  async close() {
8489
9190
  if (closed) return;
8490
9191
  closed = true;
8491
9192
  const errors = [];
9193
+ stopRevealTimer();
8492
9194
  try {
8493
9195
  await transitionTail;
8494
9196
  } catch (error) {
8495
9197
  errors.push(error);
8496
9198
  }
8497
9199
  for (const operation of [
9200
+ () => activeStyle.hideAnimation === void 0 ? void 0 : surface?.animate?.(activeStyle.hideAnimation),
8498
9201
  () => blinkLoop?.stop(),
8499
9202
  () => lipSyncLoop?.stop(),
8500
9203
  () => indicatorLoop?.stop(),
@@ -8515,8 +9218,11 @@
8515
9218
  }
8516
9219
  });
8517
9220
  active.set(input.actorKey, handle);
9221
+ scheduleReveal();
9222
+ if (activeStyle.showAnimation !== void 0) await handle.animate(activeStyle.showAnimation);
8518
9223
  return handle;
8519
9224
  } catch (error) {
9225
+ active.delete(input.actorKey);
8520
9226
  const cleanupErrors = [];
8521
9227
  const loopResults = await Promise.allSettled([
8522
9228
  blinkLoop?.stop(),
@@ -8653,6 +9359,52 @@
8653
9359
  height
8654
9360
  };
8655
9361
  }
9362
+ function clamp01(value) {
9363
+ return Math.max(0, Math.min(1, value));
9364
+ }
9365
+ function easeProgress(value, ease) {
9366
+ const progress = clamp01(value);
9367
+ switch (ease) {
9368
+ case "linear": return progress;
9369
+ case "easeIn": return progress * progress;
9370
+ case "easeOut": return 1 - (1 - progress) * (1 - progress);
9371
+ case "easeInOut": return progress < .5 ? 2 * progress * progress : 1 - Math.pow(-2 * progress + 2, 2) / 2;
9372
+ default: return progress;
9373
+ }
9374
+ }
9375
+ /**
9376
+ * Drives a motion with the same scheduler used by frame loops and reveal.
9377
+ * The adapter intentionally does not depend on requestAnimationFrame so a
9378
+ * host can provide deterministic time in tests and non-browser runtimes.
9379
+ */
9380
+ function runMotionTimeline(scheduler, durationSeconds, onFrame) {
9381
+ const durationMilliseconds = Math.max(0, durationSeconds * 1e3);
9382
+ if (durationMilliseconds === 0) {
9383
+ onFrame(1);
9384
+ return Promise.resolve();
9385
+ }
9386
+ return new Promise((resolve, reject) => {
9387
+ let elapsed = 0;
9388
+ let timer;
9389
+ const tick = () => {
9390
+ const step = Math.min(16, durationMilliseconds - elapsed);
9391
+ elapsed += step;
9392
+ try {
9393
+ onFrame(clamp01(elapsed / durationMilliseconds));
9394
+ } catch (error) {
9395
+ if (timer !== void 0) scheduler.clearTimeout(timer);
9396
+ reject(error);
9397
+ return;
9398
+ }
9399
+ if (elapsed >= durationMilliseconds) {
9400
+ resolve();
9401
+ return;
9402
+ }
9403
+ timer = scheduler.setTimeout(tick, Math.min(16, durationMilliseconds - elapsed));
9404
+ };
9405
+ timer = scheduler.setTimeout(tick, Math.min(16, durationMilliseconds));
9406
+ });
9407
+ }
8656
9408
  function fitDrawable(renderer, target, boxSize, scaleMultiplier = 1) {
8657
9409
  const native = readSize(renderer, target, {
8658
9410
  width: boxSize,
@@ -8678,7 +9430,7 @@
8678
9430
  const vector = bubbleDirectionVector(direction);
8679
9431
  return (Math.atan2(-vector.x, -vector.y) * 180 / Math.PI % 360 + 360) % 360;
8680
9432
  }
8681
- function createSurface(runtime, actor, actorKey, style) {
9433
+ function createSurface(runtime, actor, actorKey, style, scheduler) {
8682
9434
  const renderer = runtime.renderer;
8683
9435
  const sequence = surfaceSequence;
8684
9436
  surfaceSequence += 1;
@@ -8721,17 +9473,34 @@
8721
9473
  let disposed = false;
8722
9474
  let cachedBodySkinSignature = "";
8723
9475
  let currentStyle = style;
9476
+ let reservedTextSize;
9477
+ const layoutPositions = /* @__PURE__ */ new Map();
9478
+ const layoutScales = /* @__PURE__ */ new Map();
9479
+ let motionTranslation = [0, 0];
9480
+ let motionScaleMultiplier = 1;
9481
+ let motionOpacity = 1;
9482
+ let shapeTransition;
9483
+ const applyMotionTransforms = () => {
9484
+ for (const target of drawables) {
9485
+ const basePosition = layoutPositions.get(target.drawableID);
9486
+ if (basePosition) renderer.updateDrawablePosition(target.drawableID, [basePosition[0] + motionTranslation[0], basePosition[1] + motionTranslation[1]]);
9487
+ const baseScale = layoutScales.get(target.drawableID);
9488
+ if (baseScale) renderer.updateDrawableScale(target.drawableID, [baseScale[0] * motionScaleMultiplier, baseScale[1] * motionScaleMultiplier]);
9489
+ renderer.updateDrawableEffect?.(target.drawableID, "ghost", (1 - motionOpacity) * 100);
9490
+ }
9491
+ };
8724
9492
  const updateVisibility = () => {
8725
9493
  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));
9494
+ renderer.updateDrawableVisible(body.drawableID, surfaceVisible && actorVisible && currentStyle.visualStyle !== "NO_BUBBLE" && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9495
+ renderer.updateDrawableVisible(text.drawableID, surfaceVisible && actorVisible && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9496
+ for (const [layer, target] of layerTargets) renderer.updateDrawableVisible(target.drawableID, surfaceVisible && actorVisible && (layerVisibility.get(layer) ?? false) && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9497
+ applyMotionTransforms();
8729
9498
  runtime.requestRedraw?.();
8730
9499
  };
8731
9500
  const position = () => {
8732
9501
  if (disposed) return;
8733
9502
  const scaleMultiplier = currentStyle.placement.basis === "actor" ? currentStyle.offset.scalePercent / 100 : 1;
8734
- const nativeTextSize = readSize(renderer, text, {
9503
+ const nativeTextSize = reservedTextSize ?? readSize(renderer, text, {
8735
9504
  width: 180,
8736
9505
  height: 48
8737
9506
  });
@@ -8819,7 +9588,8 @@
8819
9588
  tailLength: currentStyle.tailLength,
8820
9589
  viewportExtraX,
8821
9590
  viewportExtraY,
8822
- visualStyle: currentStyle.visualStyle
9591
+ visualStyle: currentStyle.visualStyle,
9592
+ shapeTransition
8823
9593
  });
8824
9594
  if (nextBodySkinSignature !== cachedBodySkinSignature) {
8825
9595
  const expanded = expandSvgViewport(renderBubbleSvg({
@@ -8830,7 +9600,8 @@
8830
9600
  tailDirection,
8831
9601
  tailLength: currentStyle.tailLength,
8832
9602
  offset: bodyOffset,
8833
- title: `${currentStyle.name} Bubble body`
9603
+ title: `${currentStyle.name} Bubble body`,
9604
+ ...shapeTransition === void 0 ? {} : { shapeTransition }
8834
9605
  }), baseBubbleWidth, baseBubbleHeight, viewportExtraX, viewportExtraY);
8835
9606
  const nextSkinId = renderer.createSVGSkin(expanded);
8836
9607
  if (!Number.isInteger(nextSkinId) || nextSkinId < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "TurboWarp did not create the Bubble body SVG skin.");
@@ -8857,6 +9628,23 @@
8857
9628
  ]) if (target) renderer.updateDrawablePosition(target.drawableID, [portraitX, centerY]);
8858
9629
  renderer.updateDrawablePosition(text.drawableID, [textX, centerY]);
8859
9630
  if (continueIndicator) renderer.updateDrawablePosition(continueIndicator.drawableID, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
9631
+ const remember = (target, positionValue) => {
9632
+ if (!target) return;
9633
+ layoutPositions.set(target.drawableID, positionValue);
9634
+ };
9635
+ remember(body, [centerX - bodyCenterOffset.x, centerY + bodyCenterOffset.y]);
9636
+ remember(text, [textX, centerY]);
9637
+ remember(portraitBase, [portraitX, centerY]);
9638
+ remember(portraitBlink, [portraitX, centerY]);
9639
+ remember(portraitLipSync, [portraitX, centerY]);
9640
+ layoutScales.set(body.drawableID, [100, 100]);
9641
+ layoutScales.set(text.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9642
+ if (portraitBase) layoutScales.set(portraitBase.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9643
+ if (portraitBlink) layoutScales.set(portraitBlink.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9644
+ if (portraitLipSync) layoutScales.set(portraitLipSync.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9645
+ if (continueIndicator) layoutScales.set(continueIndicator.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9646
+ if (continueIndicator) remember(continueIndicator, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
9647
+ applyMotionTransforms();
8860
9648
  updateVisibility();
8861
9649
  };
8862
9650
  const originalVisualChange = actor.onTargetVisualChange;
@@ -8876,12 +9664,138 @@
8876
9664
  if (disposed) return;
8877
9665
  const wasActorRelative = currentStyle.placement.basis === "actor";
8878
9666
  currentStyle = nextStyle;
9667
+ motionTranslation = [0, 0];
9668
+ motionScaleMultiplier = 1;
9669
+ motionOpacity = 1;
9670
+ shapeTransition = void 0;
9671
+ if (nextStyle.reveal?.layout !== "RESERVED") reservedTextSize = void 0;
8879
9672
  const isActorRelative = currentStyle.placement.basis === "actor";
8880
9673
  if (wasActorRelative && !isActorRelative) {
8881
9674
  if (actor.onTargetVisualChange === visualChangeHook) actor.onTargetVisualChange = originalVisualChange ?? null;
8882
9675
  } else if (!wasActorRelative && isActorRelative) actor.onTargetVisualChange = visualChangeHook;
8883
9676
  position();
8884
9677
  },
9678
+ captureTextLayout() {
9679
+ if (disposed) return;
9680
+ reservedTextSize = readSize(renderer, text, {
9681
+ width: 180,
9682
+ height: 48
9683
+ });
9684
+ position();
9685
+ },
9686
+ clearTextLayout() {
9687
+ reservedTextSize = void 0;
9688
+ position();
9689
+ },
9690
+ async animate(motion) {
9691
+ if (disposed) return;
9692
+ const durationSeconds = Math.max(0, motion.durationSeconds ?? 0);
9693
+ const setFrame = () => {
9694
+ if (disposed) return;
9695
+ applyMotionTransforms();
9696
+ updateVisibility();
9697
+ };
9698
+ const eased = (progress) => easeProgress(progress, motion.ease ?? "easeInOut");
9699
+ if (motion.name === "fadeIn" || motion.name === "floatIn" || motion.name === "zoomIn" || motion.name === "riseUp") {
9700
+ surfaceVisible = true;
9701
+ const startingTranslation = motion.name === "floatIn" || motion.name === "riseUp" ? [0, 16] : [0, 0];
9702
+ const startingScale = motion.name === "zoomIn" ? .01 : 1;
9703
+ motionTranslation = startingTranslation;
9704
+ motionScaleMultiplier = startingScale;
9705
+ motionOpacity = motion.name === "fadeIn" ? 0 : 1;
9706
+ setFrame();
9707
+ await runMotionTimeline(scheduler, durationSeconds, (progress) => {
9708
+ const easedProgress = eased(progress);
9709
+ motionTranslation = [startingTranslation[0] * (1 - easedProgress), startingTranslation[1] * (1 - easedProgress)];
9710
+ motionScaleMultiplier = startingScale + (1 - startingScale) * easedProgress;
9711
+ motionOpacity = motion.name === "fadeIn" ? easedProgress : 1;
9712
+ setFrame();
9713
+ });
9714
+ motionTranslation = [0, 0];
9715
+ motionScaleMultiplier = 1;
9716
+ motionOpacity = 1;
9717
+ position();
9718
+ return;
9719
+ }
9720
+ if (motion.name === "fadeOut" || motion.name === "floatOut" || motion.name === "zoomOut" || motion.name === "sink") {
9721
+ const endingTranslation = motion.name === "floatOut" || motion.name === "sink" ? [0, -16] : [0, 0];
9722
+ const endingScale = motion.name === "zoomOut" ? .01 : 1;
9723
+ motionTranslation = [0, 0];
9724
+ motionScaleMultiplier = 1;
9725
+ motionOpacity = 1;
9726
+ setFrame();
9727
+ await runMotionTimeline(scheduler, durationSeconds, (progress) => {
9728
+ const easedProgress = eased(progress);
9729
+ motionTranslation = [endingTranslation[0] * easedProgress, endingTranslation[1] * easedProgress];
9730
+ motionScaleMultiplier = 1 + (endingScale - 1) * easedProgress;
9731
+ motionOpacity = motion.name === "fadeOut" ? 1 - easedProgress : 1;
9732
+ setFrame();
9733
+ });
9734
+ motionTranslation = endingTranslation;
9735
+ motionScaleMultiplier = endingScale;
9736
+ motionOpacity = motion.name === "fadeOut" ? 0 : 1;
9737
+ setFrame();
9738
+ surfaceVisible = false;
9739
+ updateVisibility();
9740
+ motionTranslation = [0, 0];
9741
+ motionScaleMultiplier = 1;
9742
+ motionOpacity = 1;
9743
+ return;
9744
+ }
9745
+ if (motion.name === "shake") {
9746
+ const count = Math.max(1, Math.floor(motion.count ?? 1));
9747
+ const animationDuration = durationSeconds > 0 ? durationSeconds : count * .08;
9748
+ const vector = bubbleDirectionVector(typeof motion.direction === "number" ? motion.direction : motion.direction ?? "right") ?? bubbleDirectionVector("right");
9749
+ const amplitude = 5;
9750
+ motionTranslation = [0, 0];
9751
+ await runMotionTimeline(scheduler, animationDuration, (progress) => {
9752
+ const phase = eased(progress) * count * Math.PI * 2;
9753
+ const displacement = Math.sin(phase) * amplitude;
9754
+ motionTranslation = [vector.x * displacement, vector.y * displacement];
9755
+ setFrame();
9756
+ });
9757
+ motionTranslation = [0, 0];
9758
+ position();
9759
+ return;
9760
+ }
9761
+ if (motion.name === "explode") {
9762
+ const count = Math.max(1, Math.floor(motion.count ?? 1));
9763
+ const animationDuration = durationSeconds > 0 ? durationSeconds : count * .12;
9764
+ const factor = motion.relativeScale ?? 1.15;
9765
+ await runMotionTimeline(scheduler, animationDuration, (progress) => {
9766
+ const easedProgress = eased(progress);
9767
+ const wave = Math.abs(Math.sin(easedProgress * count * Math.PI));
9768
+ motionScaleMultiplier = 1 + (factor - 1) * wave;
9769
+ setFrame();
9770
+ });
9771
+ motionScaleMultiplier = 1;
9772
+ position();
9773
+ return;
9774
+ }
9775
+ if (motion.name === "animateBubbleShape") {
9776
+ const targetStyle = motion.visualStyle ?? currentStyle.visualStyle;
9777
+ const fromStyle = currentStyle.visualStyle;
9778
+ const speed = motion.speed === void 0 ? 1 : Math.max(0, motion.speed);
9779
+ shapeTransition = {
9780
+ from: fromStyle,
9781
+ to: targetStyle,
9782
+ progress: 0
9783
+ };
9784
+ position();
9785
+ await runMotionTimeline(scheduler, durationSeconds, (progress) => {
9786
+ const speedProgress = durationSeconds === 0 ? 1 : clamp01(progress * Math.max(speed, 1) / 1);
9787
+ shapeTransition = {
9788
+ from: fromStyle,
9789
+ to: targetStyle,
9790
+ progress: easeProgress(speedProgress, motion.ease ?? "easeInOut")
9791
+ };
9792
+ position();
9793
+ });
9794
+ shapeTransition = void 0;
9795
+ position();
9796
+ return;
9797
+ }
9798
+ },
8885
9799
  show() {
8886
9800
  if (disposed) return;
8887
9801
  surfaceVisible = true;
@@ -8933,12 +9847,20 @@
8933
9847
  runtime.requestRedraw?.();
8934
9848
  }
8935
9849
  },
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
- } },
9850
+ audio: options.audio ?? {
9851
+ isRegistered(name) {
9852
+ return getAssetExtension().isLoaded({ NAME: name });
9853
+ },
9854
+ getMimeType(name) {
9855
+ return getAssetExtension().getAssetMimeType({ NAME: name });
9856
+ },
9857
+ async playSound(name, playOptions = {}) {
9858
+ const extension = getAssetExtension();
9859
+ const method = playOptions.untilDone ? extension?.playSoundUntilDone : extension?.playSound;
9860
+ if (typeof method !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "TurboWarp Asset Manager does not provide audio playback.");
9861
+ await method.call(extension, { NAME: name });
9862
+ }
9863
+ },
8942
9864
  svgText: options.svgText ?? {
8943
9865
  setText({ styleName, target, text }) {
8944
9866
  svgTextExtension?.setText({
@@ -8957,7 +9879,10 @@
8957
9879
  },
8958
9880
  createSurface({ actor, actorKey, style }) {
8959
9881
  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);
9882
+ return createSurface(runtime, actor, actorKey, style, options.scheduler ?? {
9883
+ setTimeout: (callback, milliseconds) => globalThis.setTimeout(callback, milliseconds),
9884
+ clearTimeout: (handle) => globalThis.clearTimeout(handle)
9885
+ });
8961
9886
  },
8962
9887
  ...options.scheduler === void 0 ? {} : { scheduler: options.scheduler },
8963
9888
  ...options.onAnimationError === void 0 ? {} : { onAnimationError: options.onAnimationError }
@@ -8972,8 +9897,39 @@
8972
9897
  "talking",
8973
9898
  "awaiting-continue"
8974
9899
  ]);
9900
+ var validRevealUnits = /* @__PURE__ */ new Set([
9901
+ "CHARACTER",
9902
+ "WORD",
9903
+ "LINE",
9904
+ "BLOCK"
9905
+ ]);
9906
+ var showMotionNames = /* @__PURE__ */ new Set([
9907
+ "fadeIn",
9908
+ "floatIn",
9909
+ "zoomIn",
9910
+ "riseUp"
9911
+ ]);
9912
+ var hideMotionNames = /* @__PURE__ */ new Set([
9913
+ "fadeOut",
9914
+ "floatOut",
9915
+ "zoomOut",
9916
+ "sink"
9917
+ ]);
9918
+ var motionNames = /* @__PURE__ */ new Set([
9919
+ ...showMotionNames,
9920
+ ...hideMotionNames,
9921
+ "shake",
9922
+ "explode",
9923
+ "animateBubbleShape"
9924
+ ]);
9925
+ var easeNames = /* @__PURE__ */ new Set([
9926
+ "linear",
9927
+ "easeIn",
9928
+ "easeOut",
9929
+ "easeInOut"
9930
+ ]);
8975
9931
  var EXTENSION_DOCS_URI = "https://kubohiroya.github.io/turbowarp-bubble/";
8976
- var EXTENSION_VERSION = "0.2.0";
9932
+ var EXTENSION_VERSION = "0.3.1";
8977
9933
  function extensionError(message) {
8978
9934
  const error = /* @__PURE__ */ new Error(`[Bubble] ${message}`);
8979
9935
  Object.defineProperty(error, "code", { value: "BUBBLE-EXTENSION-001" });
@@ -9117,6 +10073,146 @@
9117
10073
  });
9118
10074
  this.installStyle(nextStyle);
9119
10075
  }
10076
+ setBubbleReveal(args) {
10077
+ const style = this.requireStyle(args.STYLE);
10078
+ const unit = this.toString(args.UNIT).trim().toUpperCase();
10079
+ if (!validRevealUnits.has(unit)) throw extensionError("reveal unit must be CHARACTER, WORD, LINE, or BLOCK.");
10080
+ const seconds = Scratch.Cast.toNumber(args.SECONDS);
10081
+ if (!Number.isFinite(seconds) || seconds < 0) throw extensionError("reveal interval must be zero or greater.");
10082
+ const layout = this.toString(args.LAYOUT).trim().toUpperCase();
10083
+ if (layout !== "DYNAMIC" && layout !== "RESERVED") throw extensionError("reveal layout must be DYNAMIC or RESERVED.");
10084
+ const previous = style.reveal;
10085
+ const reveal = Object.freeze({
10086
+ unit,
10087
+ ...previous?.delimiters === void 0 ? {} : { delimiters: previous.delimiters },
10088
+ ...previous?.showDelimiters === void 0 ? {} : { showDelimiters: previous.showDelimiters },
10089
+ layout,
10090
+ intervalSeconds: seconds,
10091
+ ...previous?.sound === void 0 ? {} : { sound: previous.sound }
10092
+ });
10093
+ this.installStyle(Object.freeze({
10094
+ ...style,
10095
+ reveal
10096
+ }));
10097
+ }
10098
+ setBubbleWordDelimiters(args) {
10099
+ const style = this.requireStyle(args.STYLE);
10100
+ const delimiters = this.toString(args.DELIMITERS);
10101
+ if (!delimiters) throw extensionError("word delimiters are empty.");
10102
+ const show = this.toString(args.SHOW).trim().toLowerCase();
10103
+ if (show !== "true" && show !== "false") throw extensionError("show delimiters must be true or false.");
10104
+ const previous = style.reveal;
10105
+ const reveal = Object.freeze({
10106
+ unit: previous?.unit ?? "WORD",
10107
+ delimiters,
10108
+ showDelimiters: show === "true",
10109
+ ...previous?.layout === void 0 ? {} : { layout: previous.layout },
10110
+ ...previous?.intervalSeconds === void 0 ? {} : { intervalSeconds: previous.intervalSeconds },
10111
+ ...previous?.sound === void 0 ? {} : { sound: previous.sound }
10112
+ });
10113
+ this.installStyle(Object.freeze({
10114
+ ...style,
10115
+ reveal
10116
+ }));
10117
+ }
10118
+ setBubbleRevealSound(args) {
10119
+ const style = this.requireStyle(args.STYLE);
10120
+ const asset = this.toString(args.ASSET).trim();
10121
+ const audio = style.audio;
10122
+ const nextAudio = asset ? Object.freeze({
10123
+ ...audio ?? {},
10124
+ reveal: asset
10125
+ }) : (() => {
10126
+ if (!audio) return void 0;
10127
+ const { reveal, ...withoutReveal } = audio;
10128
+ return Object.freeze(withoutReveal);
10129
+ })();
10130
+ this.installStyle(Object.freeze({
10131
+ ...style,
10132
+ ...nextAudio === void 0 ? {} : { audio: nextAudio }
10133
+ }));
10134
+ }
10135
+ setBubbleVoice(args) {
10136
+ const style = this.requireStyle(args.STYLE);
10137
+ const asset = this.toString(args.ASSET).trim();
10138
+ const audio = style.audio;
10139
+ const nextAudio = asset ? Object.freeze({
10140
+ ...audio ?? {},
10141
+ voice: asset
10142
+ }) : (() => {
10143
+ if (!audio) return void 0;
10144
+ const { voice, ...withoutVoice } = audio;
10145
+ return Object.freeze(withoutVoice);
10146
+ })();
10147
+ this.installStyle(Object.freeze({
10148
+ ...style,
10149
+ ...nextAudio === void 0 ? {} : { audio: nextAudio }
10150
+ }));
10151
+ }
10152
+ setBubbleShowAnimation(args) {
10153
+ const style = this.requireStyle(args.STYLE);
10154
+ const motion = this.motionInput(args.MOTION, args.SECONDS, "show", showMotionNames);
10155
+ this.installStyle(Object.freeze({
10156
+ ...style,
10157
+ showAnimation: motion
10158
+ }));
10159
+ }
10160
+ setBubbleHideAnimation(args) {
10161
+ const style = this.requireStyle(args.STYLE);
10162
+ const motion = this.motionInput(args.MOTION, args.SECONDS, "hide", hideMotionNames);
10163
+ this.installStyle(Object.freeze({
10164
+ ...style,
10165
+ hideAnimation: motion
10166
+ }));
10167
+ }
10168
+ async animateBubble(args, util) {
10169
+ const handle = this.requireHandle(util);
10170
+ const name = this.toString(args.MOTION).trim();
10171
+ if (!motionNames.has(name)) throw extensionError("unsupported Bubble motion.");
10172
+ await handle.animate({ name });
10173
+ }
10174
+ async shakeBubble(args, util) {
10175
+ const handle = this.requireHandle(util);
10176
+ const count = Scratch.Cast.toNumber(args.COUNT);
10177
+ if (!Number.isInteger(count) || count < 1) throw extensionError("shake count must be a positive integer.");
10178
+ const ease = this.toString(args.EASE).trim();
10179
+ if (!easeNames.has(ease)) throw extensionError("unsupported easing.");
10180
+ await handle.animate({
10181
+ name: "shake",
10182
+ direction: Scratch.Cast.toNumber(args.DIRECTION),
10183
+ count,
10184
+ ease
10185
+ });
10186
+ }
10187
+ async explodeBubble(args, util) {
10188
+ const handle = this.requireHandle(util);
10189
+ const scale = Scratch.Cast.toNumber(args.SCALE);
10190
+ const count = Scratch.Cast.toNumber(args.COUNT);
10191
+ if (!Number.isFinite(scale) || scale <= 0) throw extensionError("explode scale must be positive.");
10192
+ if (!Number.isInteger(count) || count < 1) throw extensionError("explode count must be a positive integer.");
10193
+ const ease = this.toString(args.EASE).trim();
10194
+ if (!easeNames.has(ease)) throw extensionError("unsupported easing.");
10195
+ await handle.animate({
10196
+ name: "explode",
10197
+ relativeScale: scale,
10198
+ count,
10199
+ ease
10200
+ });
10201
+ }
10202
+ async animateBubbleShape(args, util) {
10203
+ const handle = this.requireHandle(util);
10204
+ const visualStyle = this.toString(args.VISUAL_STYLE).trim().toUpperCase();
10205
+ if (!bubbleVisualStyles.includes(visualStyle)) throw extensionError("unsupported Bubble visual style.");
10206
+ const speed = Scratch.Cast.toNumber(args.SPEED);
10207
+ const seconds = Scratch.Cast.toNumber(args.SECONDS);
10208
+ if (!Number.isFinite(speed) || speed < 0 || !Number.isFinite(seconds) || seconds < 0) throw extensionError("shape animation speed and duration must be zero or greater.");
10209
+ await handle.animate({
10210
+ name: "animateBubbleShape",
10211
+ visualStyle,
10212
+ speed,
10213
+ durationSeconds: seconds
10214
+ });
10215
+ }
9120
10216
  sayWithBubbleStyle(args, util) {
9121
10217
  return this.show("say", args, util);
9122
10218
  }
@@ -9177,6 +10273,22 @@
9177
10273
  checkCondition();
9178
10274
  });
9179
10275
  }
10276
+ async finishBubbleReveal(args, util) {
10277
+ const handle = this.requireHandle(util);
10278
+ const unit = this.toString(args.UNIT).trim().toUpperCase();
10279
+ if (!validRevealUnits.has(unit)) throw extensionError("reveal unit is invalid.");
10280
+ const conditionText = this.toString(args.CONDITION).trim();
10281
+ const timeoutSeconds = Scratch.Cast.toNumber(args.TIMEOUT);
10282
+ if (!conditionText) throw extensionError("finish condition is empty.");
10283
+ if (!Number.isFinite(timeoutSeconds) || timeoutSeconds < 0) throw extensionError("finish timeout must be zero or greater.");
10284
+ const expression = this.runtime.ext_kubohiroyaruntimeexpression;
10285
+ if (!this.isRecord(expression) || typeof expression.runtimeCondition !== "function") throw extensionError("Bubble finish requires Runtime Expression. Load @kubohiroya/turbowarp-runtime-expression before using this block.");
10286
+ await handle.finish({
10287
+ unit,
10288
+ timeoutSeconds,
10289
+ condition: () => expression.runtimeCondition({ EXPRESSION: conditionText })
10290
+ });
10291
+ }
9180
10292
  async closeBubble(_args, util) {
9181
10293
  const target = this.requireTarget(util);
9182
10294
  await this.releaseOwnedTarget(target.id);
@@ -9264,6 +10376,16 @@
9264
10376
  frameIntervalSeconds: seconds
9265
10377
  });
9266
10378
  }
10379
+ motionInput(value, secondsValue, label, valid) {
10380
+ const name = this.toString(value).trim();
10381
+ if (!valid.has(name)) throw extensionError(`${label} animation is invalid.`);
10382
+ const seconds = Scratch.Cast.toNumber(secondsValue);
10383
+ if (!Number.isFinite(seconds) || seconds < 0) throw extensionError(`${label} animation duration must be zero or greater.`);
10384
+ return Object.freeze({
10385
+ name,
10386
+ durationSeconds: seconds
10387
+ });
10388
+ }
9267
10389
  setPortraitAnimation(field, args) {
9268
10390
  const style = this.requireStyle(args.STYLE);
9269
10391
  const portrait = style.portrait;
@@ -9293,6 +10415,12 @@
9293
10415
  if (!this.isTarget(target)) throw extensionError("target is unavailable.");
9294
10416
  return target;
9295
10417
  }
10418
+ requireHandle(util) {
10419
+ const target = this.requireTarget(util);
10420
+ const handle = this.handles.get(target.id);
10421
+ if (!handle) throw extensionError("this target does not have an active bubble.");
10422
+ return handle;
10423
+ }
9296
10424
  placementInput(placement) {
9297
10425
  return placement.basis === "actor" ? placement.direction : placement.region;
9298
10426
  }