@kubohiroya/turbowarp-bubble 0.1.1 → 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.
@@ -1,6 +1,6 @@
1
1
  // Name: Bubble
2
2
  // ID: kubohiroyabubble
3
- // Description: Layered say and think bubbles with portrait animation and advance indicators.
3
+ // Description: Layered say and think bubbles with portrait animation and continue indicators.
4
4
  // By: Hiroya Kubo
5
5
  // License: MPL-2.0
6
6
 
@@ -35,7 +35,7 @@
35
35
  id: "kubohiroyabubble",
36
36
  slug: "turbowarp-bubble",
37
37
  name: "Bubble",
38
- description: "Layered say and think bubbles with portrait animation and advance indicators.",
38
+ description: "Layered say and think bubbles with portrait animation and continue indicators.",
39
39
  author: "Hiroya Kubo",
40
40
  license: "MPL-2.0",
41
41
  unsandboxed: true
@@ -186,10 +186,10 @@
186
186
  }
187
187
  },
188
188
  {
189
- "opcode": "setTalkFrames",
189
+ "opcode": "setLipSyncFrames",
190
190
  "blockType": "COMMAND",
191
- "text": "set talk frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]",
192
- "description": "Sets comma-separated registered image assets for the portrait talk layer. An empty list removes talk animation.",
191
+ "text": "set lip-sync frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]",
192
+ "description": "Sets comma-separated registered image assets for the portrait lip-sync layer. An empty list removes lip-sync animation.",
193
193
  "arguments": {
194
194
  "ASSETS": {
195
195
  "type": "STRING",
@@ -206,10 +206,10 @@
206
206
  }
207
207
  },
208
208
  {
209
- "opcode": "setAdvanceFrames",
209
+ "opcode": "setContinueFrames",
210
210
  "blockType": "COMMAND",
211
- "text": "set advance frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]",
212
- "description": "Sets at least two comma-separated registered image assets for the awaiting-advance indicator. An empty list removes the indicator.",
211
+ "text": "set continue frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]",
212
+ "description": "Sets at least two comma-separated registered image assets for the awaiting-continue indicator. An empty list removes the indicator.",
213
213
  "arguments": {
214
214
  "ASSETS": {
215
215
  "type": "STRING",
@@ -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",
@@ -261,18 +477,18 @@
261
477
  "opcode": "setBubbleAnimationMode",
262
478
  "blockType": "COMMAND",
263
479
  "text": "set this bubble animation mode [MODE]",
264
- "description": "Changes this sprite's bubble animation mode. Awaiting advance stops talk animation and starts the configured advance frames.",
480
+ "description": "Changes this sprite's bubble animation mode. Awaiting continue stops lip-sync animation and starts the configured continue frames.",
265
481
  "arguments": { "MODE": {
266
482
  "type": "STRING",
267
- "defaultValue": "awaiting-advance",
483
+ "defaultValue": "awaiting-continue",
268
484
  "menu": "animationMode"
269
485
  } }
270
486
  },
271
487
  {
272
- "opcode": "waitForBubbleAdvance",
488
+ "opcode": "waitForBubbleContinue",
273
489
  "blockType": "COMMAND",
274
490
  "text": "wait with this bubble until condition [CONDITION] or timeout after [TIMEOUT] seconds",
275
- "description": "Switches to awaiting-advance mode, evaluates a Runtime Expression condition using variables updated by Async Input, and waits until the condition is true or the timeout expires. Zero disables the timeout.",
491
+ "description": "Switches to awaiting-continue mode, evaluates a Runtime Expression condition using variables updated by Async Input, and waits until the condition is true or the timeout expires. Zero disables the timeout.",
276
492
  "arguments": {
277
493
  "CONDITION": {
278
494
  "type": "STRING",
@@ -343,9 +559,69 @@
343
559
  "acceptReporters": true,
344
560
  "items": [
345
561
  "talking",
346
- "awaiting-advance",
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,46 +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>`;
6066
- }
6067
- //#endregion
6068
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/typeof.js
6069
- function _typeof(o) {
6070
- "@babel/helpers - typeof";
6071
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6072
- return typeof o;
6073
- } : function(o) {
6074
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
6075
- }, _typeof(o);
6076
- }
6077
- //#endregion
6078
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPrimitive.js
6079
- function toPrimitive(t, r) {
6080
- if ("object" != _typeof(t) || !t) return t;
6081
- var e = t[Symbol.toPrimitive];
6082
- if (void 0 !== e) {
6083
- var i = e.call(t, r || "default");
6084
- if ("object" != _typeof(i)) return i;
6085
- throw new TypeError("@@toPrimitive must return a primitive value.");
6086
- }
6087
- return ("string" === r ? String : Number)(t);
6088
- }
6089
- //#endregion
6090
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPropertyKey.js
6091
- function toPropertyKey(t) {
6092
- var i = toPrimitive(t, "string");
6093
- return "symbol" == _typeof(i) ? i : i + "";
6094
- }
6095
- //#endregion
6096
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/defineProperty.js
6097
- function _defineProperty(e, r, t) {
6098
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
6099
- value: t,
6100
- enumerable: !0,
6101
- configurable: !0,
6102
- writable: !0
6103
- }) : e[r] = t, e;
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>`;
6104
6348
  }
6105
6349
  //#endregion
6106
6350
  //#region node_modules/.pnpm/@cto.af+unicode-trie-runtime@3.2.9/node_modules/@cto.af/unicode-trie-runtime/constants.js
@@ -6653,46 +6897,1542 @@
6653
6897
  */
6654
6898
  var names$1 = Object.fromEntries(LineBreak.values.map((v, i) => [v, i]));
6655
6899
  var { values: values$1 } = LineBreak;
6656
- var { AI, AL: AL$1, CJ, CM: CM$1, NS: NS$1, SA, SG, SP: SP$1, XX } = names$1;
6657
- //#endregion
6658
- //#region node_modules/.pnpm/@cto.af+linebreak@4.0.3/node_modules/@cto.af/linebreak/lib/EastAsianWidth.js
6659
- var EastAsianWidth = UnicodeTrie.fromBase64(`AAAEAAAAAAD/////wQIAAB+LCAC1xcFoAgPtmj1IHUEQxzd5FiaEkMLSKqQIViEQCEmTjyqk
6660
- SUgR7OySTrHxdVoIYqUg2AgqFhYWFhYidpYqKDaClVZaqJWF2qj/xT1cjjtv772Z3T1uHvzY
6661
- 753d2b252ds3+1SpRbAMVkGSrlMo5LNjIfqoB/uEfR2Ao5yy4zb7PgUX4Brcgo6GUi9AF+gG
6662
- r0EPeAc+AN3mM8KvJu6DH0bWb08yeyEneV77rHia/yjbMvEBxJum7mCqzQjSo1beuBWfRFy3
6663
- 1fHpR2QJgiAIgiAIgiAIQpoZc45c8HhGd2WJYUyy5oIgCP5oRPhuEQQh7vvPVuAe34q5x1lH
6664
- uJFh15J7HRt9Z7MJ9iKwg1fP72kG4osqz3ynUlNPHjhC2i5/9UypX8DOa6bSa0hfAbsf33zE
6665
- /EPLr7NtOYj4zlTfD+v7dG0r8uzhXM39qEPH9TtBvTNwUXK9dyv0frzE3DSxje8mZ0yNjuz8
6666
- zlT+S6T1OnQh7M5oo+f+Bvk67EGY/OfiPeKfTL5+hr6ZuM13k/cT4R/QC86tMfdZbf4a2Un6
6667
- H9L9OXNIGCoo12yDYdR7mzG+tP8yhjoTpt607tuh/6r7b1VG7yv5ya/OP7iZQXEdYyi9UNel
6668
- WKM83YTQE/f8qftudz9y7G/OdWlXLxTPYRm9cu+ZMutMaYuK2tnjyqpb5jnPa8+xH7n3eJFO
6669
- ivRGbTNC6su3PeHYM0V7OxZ/hUtWLP5ZFfzDmMYQSieU8qj78rF3fMsI+axX5fwWYvw+5t9u
6670
- f0VnNR964yh31bdLOce8qfYb11ndVWeUvibHfCj8tZD2LNZvTRyyW/GfQr1/OM8gob/LcPn8
6671
- If3iVmVT23Iu/69KaxHzOYn6XenTNw1551DW/3V5X7v6c9Tfh7jPX9TrFtqOhjgPttqeW28u
6672
- 33192kvqs2vW7w7BeyuJcEoAAB+LCAC1xcFoAgOLVvJT0lGKVIoFANHfAiwJAAAA`);
6673
- Object.fromEntries(EastAsianWidth.values.map((v, i) => [v, i]));
6674
- var { values } = EastAsianWidth;
6675
6900
  //#endregion
6676
- //#region node_modules/.pnpm/@cto.af+linebreak@4.0.3/node_modules/@cto.af/linebreak/lib/index.js
6677
- var { AK, AL, AP, AS, B2, BA, BB, BK, CB, CL, CM, CP, CR, EB, EM, EX, GL, H2, H3, HH, HL, HY, ID, IN, IS, JL, JT, JV, LF, NU, OP, NL, NS, PO, PR, RI, SP, SY, QU, VF, VI, WJ, ZW, ZWJ } = names$1;
6901
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/typeof.js
6902
+ function _typeof(o) {
6903
+ "@babel/helpers - typeof";
6904
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6905
+ return typeof o;
6906
+ } : function(o) {
6907
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
6908
+ }, _typeof(o);
6909
+ }
6678
6910
  //#endregion
6679
- //#region src/composition.ts
6680
- var BubbleCompositionError = class extends Error {
6681
- constructor(code, message) {
6682
- super(message);
6683
- _defineProperty(this, "code", void 0);
6684
- this.name = "BubbleCompositionError";
6685
- this.code = code;
6911
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPrimitive.js
6912
+ function toPrimitive(t, r) {
6913
+ if ("object" != _typeof(t) || !t) return t;
6914
+ var e = t[Symbol.toPrimitive];
6915
+ if (void 0 !== e) {
6916
+ var i = e.call(t, r || "default");
6917
+ if ("object" != _typeof(i)) return i;
6918
+ throw new TypeError("@@toPrimitive must return a primitive value.");
6686
6919
  }
6687
- };
6688
- var validKinds = /* @__PURE__ */ new Set(["say", "think"]);
6689
- var validAnimationModes$1 = /* @__PURE__ */ new Set([
6690
- "idle",
6691
- "talking",
6692
- "awaiting-advance"
6693
- ]);
6694
- function isRecord$1(value) {
6695
- return typeof value === "object" && value !== null && !Array.isArray(value);
6920
+ return ("string" === r ? String : Number)(t);
6921
+ }
6922
+ //#endregion
6923
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPropertyKey.js
6924
+ function toPropertyKey(t) {
6925
+ var i = toPrimitive(t, "string");
6926
+ return "symbol" == _typeof(i) ? i : i + "";
6927
+ }
6928
+ //#endregion
6929
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/defineProperty.js
6930
+ function _defineProperty(e, r, t) {
6931
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
6932
+ value: t,
6933
+ enumerable: !0,
6934
+ configurable: !0,
6935
+ writable: !0
6936
+ }) : e[r] = t, e;
6937
+ }
6938
+ //#endregion
6939
+ //#region node_modules/.pnpm/@cto.af+linebreak@4.0.3/node_modules/@cto.af/linebreak/lib/state.js
6940
+ var _Symbol$for;
6941
+ var _Symbol$for2;
6942
+ var { AI, AL: AL$1, CJ, CM: CM$1, NS: NS$1, SA, SG, SP: SP$1, XX } = names$1;
6943
+ /**
6944
+ * Convert a class number to a string, if possible.
6945
+ *
6946
+ * @param {number?} cls
6947
+ */
6948
+ function classText(cls) {
6949
+ switch (cls) {
6950
+ case null: return null;
6951
+ case -1: return "sot";
6952
+ case -2: return "eot";
6953
+ default: return values$1[cls];
6954
+ }
6955
+ }
6956
+ /**
6957
+ * LB1: Assign a line breaking class to each code point of the input. Resolve
6958
+ * AI, CB, CJ, SA, SG, and XX into other line breaking classes depending on
6959
+ * criteria outside the scope of this algorithm.
6960
+ *
6961
+ * @param {number} cls
6962
+ * @param {string} char
6963
+ * @returns {number}
6964
+ */
6965
+ function resolve(cls, char) {
6966
+ switch (cls) {
6967
+ case AI:
6968
+ case SG:
6969
+ case XX: return AL$1;
6970
+ case SA: return /^[\p{gc=Mn}\p{gc=Mc}]$/u.test(char) ? CM$1 : AL$1;
6971
+ case CJ: return NS$1;
6972
+ }
6973
+ return cls;
6974
+ }
6975
+ _Symbol$for = Symbol.for("nodejs.util.inspect.custom");
6976
+ /**
6977
+ * Information about a particular input character.
6978
+ */
6979
+ var BreakerChar = class {
6980
+ /**
6981
+ * @param {number} cls
6982
+ * @param {number} cp
6983
+ * @param {string} char
6984
+ * @param {number} len
6985
+ */
6986
+ constructor(cls, cp, char, len) {
6987
+ _defineProperty(
6988
+ this,
6989
+ /**
6990
+ * Code point
6991
+ */
6992
+ "cp",
6993
+ -Infinity
6994
+ );
6995
+ _defineProperty(
6996
+ this,
6997
+ /**
6998
+ * Line breaking class, or `sot` or `eot`.
6999
+ */
7000
+ "cls",
7001
+ -1
7002
+ );
7003
+ _defineProperty(
7004
+ this,
7005
+ /**
7006
+ * The character. Might be one or two UTF-16 JS characters.
7007
+ */
7008
+ "char",
7009
+ ""
7010
+ );
7011
+ _defineProperty(
7012
+ this,
7013
+ /**
7014
+ * The length of the whole string up to and including char, in JS chars.
7015
+ */
7016
+ "len",
7017
+ 0
7018
+ );
7019
+ _defineProperty(
7020
+ this,
7021
+ /**
7022
+ * If true, this is an LB9 CM or ZWJ that is treated as coalesced into
7023
+ * the previous code point.
7024
+ */
7025
+ "ignored",
7026
+ false
7027
+ );
7028
+ this.cls = cls;
7029
+ this.cp = cp;
7030
+ this.char = char;
7031
+ this.len = len;
7032
+ }
7033
+ /**
7034
+ * Debug helper.
7035
+ *
7036
+ * @param {number} _depth
7037
+ * @param {import('util').InspectOptionsStylized} _inspectOptions
7038
+ * @param {(x: any) => string} _inspect
7039
+ * @returns
7040
+ */
7041
+ [_Symbol$for](_depth, _inspectOptions, _inspect) {
7042
+ return `${classText(this.cls)}(${this.cp.toString(16).padStart(4, "0")}:${JSON.stringify(this.char)})${this.ignored ? "Ig" : ""}`;
7043
+ }
7044
+ };
7045
+ _Symbol$for2 = Symbol.for("nodejs.util.inspect.custom");
7046
+ /**
7047
+ * @private
7048
+ */
7049
+ var BreakerState = class {
7050
+ /**
7051
+ * @param {string} str
7052
+ */
7053
+ constructor(str) {
7054
+ _defineProperty(this, "str", "");
7055
+ _defineProperty(this, "len", 0);
7056
+ _defineProperty(this, "prevChunk", 0);
7057
+ _defineProperty(this, "prev", new BreakerChar(-1, -Infinity, "", 0));
7058
+ _defineProperty(this, "cur", new BreakerChar(-1, -Infinity, "", 0));
7059
+ _defineProperty(this, "next", new BreakerChar(-1, -Infinity, "", 0));
7060
+ _defineProperty(this, "LB8", false);
7061
+ _defineProperty(this, "spaces", false);
7062
+ _defineProperty(this, "RI", 0);
7063
+ _defineProperty(
7064
+ this,
7065
+ /**
7066
+ * Extra properties, to be copied to Break when created.
7067
+ *
7068
+ * @type {Record<string,any>=}
7069
+ */
7070
+ "props",
7071
+ void 0
7072
+ );
7073
+ _defineProperty(
7074
+ this,
7075
+ /**
7076
+ * Extra state information, for use by tailoring subclasses.
7077
+ *
7078
+ * @type {Record<string,any>}
7079
+ */
7080
+ "extra",
7081
+ {}
7082
+ );
7083
+ this.str = str;
7084
+ this.len = str.length;
7085
+ }
7086
+ /**
7087
+ * Move to the next state.
7088
+ *
7089
+ * @param {BreakerChar} step
7090
+ */
7091
+ push(step) {
7092
+ if (this.next.ignored) this.cur.len = this.next.len;
7093
+ else {
7094
+ this.prev = this.cur;
7095
+ this.cur = this.next;
7096
+ }
7097
+ this.next = step;
7098
+ }
7099
+ pushEnd() {
7100
+ this.push(new BreakerChar(-2, Infinity, "", this.next.len));
7101
+ }
7102
+ /**
7103
+ * Iterate over the codepoints in the string, starting at pos.
7104
+ *
7105
+ * @param {number} pos;
7106
+ * @param {boolean} [fwd=true] If true, go forward. Otherwise reverse.
7107
+ */
7108
+ *codePoints(pos, fwd = true) {
7109
+ if (fwd) while (pos < this.len) if (pos === this.cur.len && this.next.cls >= 0) {
7110
+ yield this.next;
7111
+ pos += this.next.char.length;
7112
+ } else {
7113
+ const cp = this.str.codePointAt(pos);
7114
+ const char = String.fromCodePoint(cp);
7115
+ const cls = LineBreak.get(cp);
7116
+ pos += char.length;
7117
+ yield new BreakerChar(resolve(cls, char), cp, char, pos);
7118
+ }
7119
+ else while (pos > 0) if (pos === this.cur.len) {
7120
+ yield this.cur;
7121
+ pos -= this.cur.char.length;
7122
+ } else if (pos === this.prev.len) {
7123
+ yield this.prev;
7124
+ pos -= this.prev.char.length;
7125
+ } else {
7126
+ let prev = pos - 1;
7127
+ const prevUSV = this.str.charCodeAt(prev);
7128
+ if (prevUSV >= 56320 && prevUSV <= 57343) prev--;
7129
+ const cp = this.str.codePointAt(prev);
7130
+ const char = String.fromCodePoint(cp);
7131
+ yield new BreakerChar(resolve(LineBreak.get(cp), char), cp, char, pos);
7132
+ pos = prev;
7133
+ }
7134
+ }
7135
+ /**
7136
+ * Look ahead in the string to see what the next linebreak class is after zero
7137
+ * or more spaces, starting at JS char offset pos.
7138
+ *
7139
+ * @param {number} pos
7140
+ * @returns {number}
7141
+ */
7142
+ classAfterSpaces(pos) {
7143
+ for (const { cls } of this.codePoints(pos)) if (cls !== SP$1) return cls;
7144
+ return -2;
7145
+ }
7146
+ /**
7147
+ * Get the character after next.
7148
+ *
7149
+ * @returns {BreakerChar?}
7150
+ */
7151
+ afterNext(offset = 1) {
7152
+ for (const chr of this.codePoints(this.next.len)) if (--offset <= 0) return chr;
7153
+ return null;
7154
+ }
7155
+ /**
7156
+ * Set some extra information in the state that will be passed to
7157
+ * the next created Break.
7158
+ *
7159
+ * @param {string} key
7160
+ * @param {any} value
7161
+ */
7162
+ setProp(key, value) {
7163
+ if (!this.props) this.props = {};
7164
+ this.props[key] = value;
7165
+ }
7166
+ /**
7167
+ * Debug helper.
7168
+ *
7169
+ * @param {number} _depth
7170
+ * @param {import('util').InspectOptionsStylized} _inspectOptions
7171
+ * @param {(x: any) => string} inspect
7172
+ * @returns
7173
+ */
7174
+ [_Symbol$for2](_depth, _inspectOptions, inspect) {
7175
+ let pn = `${inspect(this.prev)} => ${inspect(this.cur)} => ${inspect(this.next)}`;
7176
+ if (this.LB8) pn += " LB8";
7177
+ if (this.spaces) pn += " spaces";
7178
+ if (this.RI > 0) pn += ` RI: ${this.RI}`;
7179
+ if (this.props) pn += ` ${JSON.stringify(this.props)}`;
7180
+ return pn;
7181
+ }
7182
+ };
7183
+ //#endregion
7184
+ //#region node_modules/.pnpm/@cto.af+linebreak@4.0.3/node_modules/@cto.af/linebreak/lib/break.js
7185
+ var Break = class {
7186
+ /**
7187
+ * @param {number} position
7188
+ * @param {boolean} [required=false]
7189
+ */
7190
+ constructor(position, required = false) {
7191
+ _defineProperty(
7192
+ this,
7193
+ /**
7194
+ * If the `string` option is enabled, a slice of the original input.
7195
+ *
7196
+ * @type {string=}
7197
+ */
7198
+ "string",
7199
+ void 0
7200
+ );
7201
+ _defineProperty(
7202
+ this,
7203
+ /**
7204
+ * Extra info from plugin rules.
7205
+ *
7206
+ * @type {Record<string,any>=}
7207
+ */
7208
+ "props",
7209
+ void 0
7210
+ );
7211
+ /**
7212
+ * Offset into input string in JS characters (16bit code units).
7213
+ *
7214
+ * @type {number}
7215
+ */
7216
+ this.position = position;
7217
+ /**
7218
+ * Is this a required break?
7219
+ *
7220
+ * @type {boolean}
7221
+ */
7222
+ this.required = required;
7223
+ }
7224
+ };
7225
+ //#endregion
7226
+ //#region node_modules/.pnpm/@cto.af+linebreak@4.0.3/node_modules/@cto.af/linebreak/lib/EastAsianWidth.js
7227
+ var EastAsianWidth = UnicodeTrie.fromBase64(`AAAEAAAAAAD/////wQIAAB+LCAC1xcFoAgPtmj1IHUEQxzd5FiaEkMLSKqQIViEQCEmTjyqk
7228
+ SUgR7OySTrHxdVoIYqUg2AgqFhYWFhYidpYqKDaClVZaqJWF2qj/xT1cjjtv772Z3T1uHvzY
7229
+ 753d2b252ds3+1SpRbAMVkGSrlMo5LNjIfqoB/uEfR2Ao5yy4zb7PgUX4Brcgo6GUi9AF+gG
7230
+ r0EPeAc+AN3mM8KvJu6DH0bWb08yeyEneV77rHia/yjbMvEBxJum7mCqzQjSo1beuBWfRFy3
7231
+ 1fHpR2QJgiAIgiAIgiAIQpoZc45c8HhGd2WJYUyy5oIgCP5oRPhuEQQh7vvPVuAe34q5x1lH
7232
+ uJFh15J7HRt9Z7MJ9iKwg1fP72kG4osqz3ynUlNPHjhC2i5/9UypX8DOa6bSa0hfAbsf33zE
7233
+ /EPLr7NtOYj4zlTfD+v7dG0r8uzhXM39qEPH9TtBvTNwUXK9dyv0frzE3DSxje8mZ0yNjuz8
7234
+ zlT+S6T1OnQh7M5oo+f+Bvk67EGY/OfiPeKfTL5+hr6ZuM13k/cT4R/QC86tMfdZbf4a2Un6
7235
+ H9L9OXNIGCoo12yDYdR7mzG+tP8yhjoTpt607tuh/6r7b1VG7yv5ya/OP7iZQXEdYyi9UNel
7236
+ WKM83YTQE/f8qftudz9y7G/OdWlXLxTPYRm9cu+ZMutMaYuK2tnjyqpb5jnPa8+xH7n3eJFO
7237
+ ivRGbTNC6su3PeHYM0V7OxZ/hUtWLP5ZFfzDmMYQSieU8qj78rF3fMsI+axX5fwWYvw+5t9u
7238
+ f0VnNR964yh31bdLOce8qfYb11ndVWeUvibHfCj8tZD2LNZvTRyyW/GfQr1/OM8gob/LcPn8
7239
+ If3iVmVT23Iu/69KaxHzOYn6XenTNw1551DW/3V5X7v6c9Tfh7jPX9TrFtqOhjgPttqeW28u
7240
+ 33192kvqs2vW7w7BeyuJcEoAAB+LCAC1xcFoAgOLVvJT0lGKVIoFANHfAiwJAAAA`);
7241
+ Object.fromEntries(EastAsianWidth.values.map((v, i) => [v, i]));
7242
+ var { values } = EastAsianWidth;
7243
+ //#endregion
7244
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/checkPrivateRedeclaration.js
7245
+ function _checkPrivateRedeclaration(e, t) {
7246
+ if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
7247
+ }
7248
+ //#endregion
7249
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateMethodInitSpec.js
7250
+ function _classPrivateMethodInitSpec(e, a) {
7251
+ _checkPrivateRedeclaration(e, a), a.add(e);
7252
+ }
7253
+ //#endregion
7254
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateFieldInitSpec.js
7255
+ function _classPrivateFieldInitSpec(e, t, a) {
7256
+ _checkPrivateRedeclaration(e, t), t.set(e, a);
7257
+ }
7258
+ //#endregion
7259
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/assertClassBrand.js
7260
+ function _assertClassBrand(e, t, n) {
7261
+ if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
7262
+ throw new TypeError("Private element is not present on this object");
7263
+ }
7264
+ //#endregion
7265
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateFieldSet2.js
7266
+ function _classPrivateFieldSet2(s, a, r) {
7267
+ return s.set(_assertClassBrand(s, a), r), r;
7268
+ }
7269
+ //#endregion
7270
+ //#region \0@oxc-project+runtime@0.143.0/helpers/esm/classPrivateFieldGet2.js
7271
+ function _classPrivateFieldGet2(s, a) {
7272
+ return s.get(_assertClassBrand(s, a));
7273
+ }
7274
+ //#endregion
7275
+ //#region node_modules/.pnpm/@cto.af+linebreak@4.0.3/node_modules/@cto.af/linebreak/lib/index.js
7276
+ var { AK, AL, AP, AS, B2, BA, BB, BK, CB, CL, CM, CP, CR, EB, EM, EX, GL, H2, H3, HH, HL, HY, ID, IN, IS, JL, JT, JV, LF, NU, OP, NL, NS, PO, PR, RI, SP, SY, QU, VF, VI, WJ, ZW, ZWJ } = names$1;
7277
+ var ALHLNU = /* @__PURE__ */ new Set([
7278
+ AL,
7279
+ HL,
7280
+ NU
7281
+ ]);
7282
+ var BKCRLFNLSPZW = /* @__PURE__ */ new Set([
7283
+ BK,
7284
+ CR,
7285
+ LF,
7286
+ NL,
7287
+ SP,
7288
+ ZW
7289
+ ]);
7290
+ var IDEBEM = /* @__PURE__ */ new Set([
7291
+ ID,
7292
+ EB,
7293
+ EM
7294
+ ]);
7295
+ var JLJVH2H3 = /* @__PURE__ */ new Set([
7296
+ JL,
7297
+ JV,
7298
+ H2,
7299
+ H3
7300
+ ]);
7301
+ var JLJVJTH2H3 = /* @__PURE__ */ new Set([
7302
+ JL,
7303
+ JV,
7304
+ JT,
7305
+ H2,
7306
+ H3
7307
+ ]);
7308
+ var JVJT = /* @__PURE__ */ new Set([JV, JT]);
7309
+ var SPGLWJCLQUCPEXISSYBKCRLFNLZW = /* @__PURE__ */ new Set([
7310
+ SP,
7311
+ GL,
7312
+ WJ,
7313
+ CL,
7314
+ QU,
7315
+ CP,
7316
+ EX,
7317
+ IS,
7318
+ SY,
7319
+ BK,
7320
+ CR,
7321
+ LF,
7322
+ NL,
7323
+ ZW
7324
+ ]);
7325
+ var sotBKCRLFNLOPQUGLSPZW = /* @__PURE__ */ new Set([
7326
+ -1,
7327
+ BK,
7328
+ CR,
7329
+ LF,
7330
+ NL,
7331
+ OP,
7332
+ QU,
7333
+ GL,
7334
+ SP,
7335
+ ZW
7336
+ ]);
7337
+ /**
7338
+ * @template T
7339
+ * @typedef {ValuesWithKeys<T, keyof T>} EnumValues
7340
+ */
7341
+ /**
7342
+ * @template T
7343
+ * @template {keyof T} K
7344
+ * @typedef {T[K]} ValuesWithKeys
7345
+ */
7346
+ /**
7347
+ * This rule has no opinion.
7348
+ */
7349
+ var PASS = Symbol("PASS");
7350
+ /**
7351
+ * This rule asserts that there must not be a break after the current
7352
+ * code point.
7353
+ */
7354
+ var NO_BREAK = Symbol("NO_BREAK");
7355
+ /**
7356
+ * This rule asserts that there may be a break after the current code point.
7357
+ */
7358
+ var MAY_BREAK = Symbol("MAY_BREAK");
7359
+ /**
7360
+ * This rule asserts that there must be a line break after the current code point.
7361
+ */
7362
+ var MUST_BREAK = Symbol("MUST_BREAK");
7363
+ /**
7364
+ * @typedef {EnumValues<typeof RuleResults>} RuleResultsEnum
7365
+ */
7366
+ /**
7367
+ * A rule that impacts linebreaking. Looking ahead and behind one code point
7368
+ * is fast, using `state.prev` and `state.next` respectively. Looking ahead
7369
+ * more code points is possible with `*BreakerState.codePoints()`, but be
7370
+ * careful of causing ReDos vulnerabilities.
7371
+ *
7372
+ * @callback BreakRule
7373
+ * @param {BreakerState} state
7374
+ * @returns {RuleResultsEnum}
7375
+ */
7376
+ /**
7377
+ * LB2: Never break at the start of text.
7378
+ *
7379
+ * @type {BreakRule}
7380
+ */
7381
+ function LB02(state) {
7382
+ if (state.cur.cls === -1 && state.next.cls !== -2) return NO_BREAK;
7383
+ return PASS;
7384
+ }
7385
+ /**
7386
+ * LB3 Always break at the end of text.
7387
+ *
7388
+ * @type {BreakRule}
7389
+ */
7390
+ function LB03(state) {
7391
+ if (state.next.cls === -2 && (state.cur.len === 0 || state.cur.len !== state.prevChunk)) return MUST_BREAK;
7392
+ return PASS;
7393
+ }
7394
+ /**
7395
+ * LB4: Always break after hard line breaks.
7396
+ *
7397
+ * @type {BreakRule}
7398
+ */
7399
+ function LB04(state) {
7400
+ if (state.cur.cls === BK) return MUST_BREAK;
7401
+ return PASS;
7402
+ }
7403
+ /**
7404
+ * LB5: Treat CR followed by LF, as well as CR, LF, and NL as hard line
7405
+ * breaks.
7406
+ *
7407
+ * @type {BreakRule}
7408
+ */
7409
+ function LB05(state) {
7410
+ switch (state.cur.cls) {
7411
+ case CR:
7412
+ if (state.next.cls === LF) return NO_BREAK;
7413
+ return MUST_BREAK;
7414
+ case LF:
7415
+ case NL: return MUST_BREAK;
7416
+ }
7417
+ return PASS;
7418
+ }
7419
+ /**
7420
+ * LB6: Do not break before hard line breaks.
7421
+ *
7422
+ * @type {BreakRule}
7423
+ */
7424
+ function LB06(state) {
7425
+ switch (state.next.cls) {
7426
+ case BK:
7427
+ case CR:
7428
+ case LF:
7429
+ case NL: return NO_BREAK;
7430
+ }
7431
+ return PASS;
7432
+ }
7433
+ /**
7434
+ * The end of a run of spaces, for rules that have "Do not break within
7435
+ * ...even with intervening spaces", such as LB15.
7436
+ *
7437
+ * @type {BreakRule}
7438
+ */
7439
+ function LBspacesStop(state) {
7440
+ if (state.cur.cls !== RI) state.RI = 0;
7441
+ if (state.spaces) {
7442
+ if (state.next.cls !== SP) state.spaces = false;
7443
+ return NO_BREAK;
7444
+ }
7445
+ return PASS;
7446
+ }
7447
+ /**
7448
+ * LB7: Do not break before spaces or zero width space.
7449
+ *
7450
+ * @type {BreakRule}
7451
+ */
7452
+ function LB07(state) {
7453
+ if (state.next.cls === ZW) return NO_BREAK;
7454
+ if (state.next.cls === SP) switch (state.cur.cls) {
7455
+ case ZW:
7456
+ case OP:
7457
+ case QU:
7458
+ case CL:
7459
+ case CP:
7460
+ case B2: break;
7461
+ default: return NO_BREAK;
7462
+ }
7463
+ return PASS;
7464
+ }
7465
+ /**
7466
+ * LB8: Break before any character following a zero-width space, even if one or
7467
+ * more spaces intervene.
7468
+ *
7469
+ * @type {BreakRule}
7470
+ */
7471
+ function LB08(state) {
7472
+ if (state.LB8) {
7473
+ state.LB8 = false;
7474
+ return MAY_BREAK;
7475
+ } else if (state.cur.cls === ZW) {
7476
+ if (state.next.cls === SP) {
7477
+ state.LB8 = true;
7478
+ return NO_BREAK;
7479
+ }
7480
+ return MAY_BREAK;
7481
+ }
7482
+ return PASS;
7483
+ }
7484
+ /**
7485
+ * LB8a: Do not break after a zero width joiner.
7486
+ *
7487
+ * @type {BreakRule}
7488
+ */
7489
+ function LB08a(state) {
7490
+ if (state.cur.cls === ZWJ) return NO_BREAK;
7491
+ return PASS;
7492
+ }
7493
+ /**
7494
+ * LB9: Do not break a combining character sequence; treat it as if it has the
7495
+ * line breaking class of the base character in all of the following rules.
7496
+ * Treat ZWJ as if it were CM.
7497
+ *
7498
+ * @type {BreakRule}
7499
+ */
7500
+ function LB09(state) {
7501
+ if (!BKCRLFNLSPZW.has(state.cur.cls) && (state.next.cls === CM || state.next.cls === ZWJ)) {
7502
+ state.next.ignored = true;
7503
+ return NO_BREAK;
7504
+ }
7505
+ return PASS;
7506
+ }
7507
+ /**
7508
+ * LB10: Treat any remaining combining mark or ZWJ as AL.
7509
+ *
7510
+ * @type {BreakRule}
7511
+ */
7512
+ function LB10(state) {
7513
+ if (state.cur.cls === CM) state.cur.cls = AL;
7514
+ if (state.next.cls === CM) state.next.cls = AL;
7515
+ return PASS;
7516
+ }
7517
+ /**
7518
+ * LB11: Do not break before or after Word joiner and related characters.
7519
+ *
7520
+ * @type {BreakRule}
7521
+ */
7522
+ function LB11(state) {
7523
+ if (state.next.cls === WJ || state.cur.cls === WJ) return NO_BREAK;
7524
+ return PASS;
7525
+ }
7526
+ /**
7527
+ * LB12: Do not break after NBSP and related characters.
7528
+ *
7529
+ * @type {BreakRule}
7530
+ */
7531
+ function LB12(state) {
7532
+ if (state.cur.cls === GL) return NO_BREAK;
7533
+ return PASS;
7534
+ }
7535
+ /**
7536
+ * LB12a: Do not break before NBSP and related characters, except after spaces
7537
+ * and hyphens.
7538
+ *
7539
+ * @type {BreakRule}
7540
+ */
7541
+ function LB12a(state) {
7542
+ if (state.next.cls === GL) switch (state.cur.cls) {
7543
+ case SP:
7544
+ case BA:
7545
+ case HY:
7546
+ case HH: return PASS;
7547
+ default: return NO_BREAK;
7548
+ }
7549
+ return PASS;
7550
+ }
7551
+ /**
7552
+ * LB13: Do not break before ‘]’ or ‘!’ or ‘;’ or ‘/’, even after spaces.
7553
+ *
7554
+ * @type {BreakRule}
7555
+ */
7556
+ function LB13(state) {
7557
+ switch (state.next.cls) {
7558
+ case CL:
7559
+ case CP:
7560
+ case EX:
7561
+ case SY: return NO_BREAK;
7562
+ }
7563
+ return PASS;
7564
+ }
7565
+ /**
7566
+ * LB14: Do not break after ‘[’, even after spaces.
7567
+ *
7568
+ * @type {BreakRule}
7569
+ */
7570
+ function LB14(state) {
7571
+ if (state.cur.cls === OP) {
7572
+ if (state.next.cls === SP) state.spaces = true;
7573
+ return NO_BREAK;
7574
+ }
7575
+ return PASS;
7576
+ }
7577
+ /**
7578
+ * LB15a: Do not break after an unresolved initial punctuation that lies at
7579
+ * the start of the line, after a space, after opening punctuation, or after
7580
+ * an unresolved quotation mark, even after spaces.
7581
+ *
7582
+ * @type {BreakRule}
7583
+ */
7584
+ function LB15a(state) {
7585
+ if (sotBKCRLFNLOPQUGLSPZW.has(state.prev.cls) && /^\p{Pi}$/u.test(state.cur.char) && state.cur.cls === QU) {
7586
+ state.spaces = true;
7587
+ return NO_BREAK;
7588
+ }
7589
+ return PASS;
7590
+ }
7591
+ /**
7592
+ * LB15b: Do not break before an unresolved final punctuation that lies at the
7593
+ * end of the line, before a space, before a prohibited break, or before an
7594
+ * unresolved quotation mark, even after spaces.
7595
+ *
7596
+ * @type {BreakRule}
7597
+ */
7598
+ function LB15b(state) {
7599
+ if (/^\p{gc=Pf}$/u.test(state.next.char) && state.next.cls === QU) {
7600
+ const after = state.afterNext();
7601
+ if (!after) return NO_BREAK;
7602
+ if (SPGLWJCLQUCPEXISSYBKCRLFNLZW.has(after.cls)) return NO_BREAK;
7603
+ }
7604
+ return PASS;
7605
+ }
7606
+ /**
7607
+ * LB15c: Break before a decimal mark that follows a space, for instance, in
7608
+ * ‘subtract .5’.
7609
+ *
7610
+ * @type {BreakRule}
7611
+ */
7612
+ function LB15c(state) {
7613
+ if (state.cur.cls === SP && state.next.cls === IS) {
7614
+ if (state.afterNext()?.cls === NU) return MAY_BREAK;
7615
+ }
7616
+ return PASS;
7617
+ }
7618
+ /**
7619
+ * LB15d: Otherwise, do not break before ‘;’, ‘,’, or ‘.’, even after spaces
7620
+ *
7621
+ * @type {BreakRule}
7622
+ */
7623
+ function LB15d(state) {
7624
+ if (state.next.cls === IS) return NO_BREAK;
7625
+ return PASS;
7626
+ }
7627
+ /**
7628
+ * LB16: Do not break between closing punctuation and a nonstarter (lb=NS),
7629
+ * even with intervening spaces.
7630
+ *
7631
+ * @type {BreakRule}
7632
+ */
7633
+ function LB16(state) {
7634
+ if (state.cur.cls === CL || state.cur.cls === CP) {
7635
+ if (state.classAfterSpaces(state.cur.len) === NS) {
7636
+ if (state.next.cls === SP) state.spaces = true;
7637
+ return NO_BREAK;
7638
+ }
7639
+ if (state.next.cls === SP) return NO_BREAK;
7640
+ }
7641
+ return PASS;
7642
+ }
7643
+ /**
7644
+ * LB17: Do not break within ‘——’, even with intervening spaces.
7645
+ *
7646
+ * @type {BreakRule}
7647
+ */
7648
+ function LB17(state) {
7649
+ if (state.cur.cls === B2) {
7650
+ if (state.classAfterSpaces(state.cur.len) === B2) {
7651
+ if (state.next.cls !== SP) return NO_BREAK;
7652
+ state.spaces = true;
7653
+ return NO_BREAK;
7654
+ } else if (state.next.cls === SP) return NO_BREAK;
7655
+ }
7656
+ return PASS;
7657
+ }
7658
+ /**
7659
+ * LB18: Break after spaces.
7660
+ *
7661
+ * @type {BreakRule}
7662
+ */
7663
+ function LB18(state) {
7664
+ if (state.cur.cls === SP) return MAY_BREAK;
7665
+ return PASS;
7666
+ }
7667
+ /**
7668
+ * LB19: Do not break before non-initial unresolved quotation marks, such as ‘
7669
+ * ” ’ or ‘ " ’, nor after non-final unresolved quotation marks, such as ‘ “ ’
7670
+ * or ‘ " ’.
7671
+ *
7672
+ * @type {BreakRule}
7673
+ */
7674
+ function LB19(state) {
7675
+ if (state.next.cls === QU && !/^\p{Pi}$/u.test(state.next.char)) return NO_BREAK;
7676
+ if (state.cur.cls === QU && !/^\p{Pf}$/u.test(state.cur.char)) return NO_BREAK;
7677
+ return PASS;
7678
+ }
7679
+ /**
7680
+ * LB19a: Unless surrounded by East Asian characters, do not break either side
7681
+ * of any unresolved quotation marks.
7682
+ *
7683
+ * @type {BreakRule}
7684
+ */
7685
+ function LB19a(state) {
7686
+ if (!EastAsianWidth.get(state.cur.cp) && state.next.cls === QU) return NO_BREAK;
7687
+ if (state.next.cls === QU) {
7688
+ const after = state.afterNext();
7689
+ if (!after || !EastAsianWidth.get(after.cp)) return NO_BREAK;
7690
+ }
7691
+ if (state.cur.cls === QU && !EastAsianWidth.get(state.next.cp)) return NO_BREAK;
7692
+ if ((state.prev.cls === -1 || !EastAsianWidth.get(state.prev.cp)) && state.cur.cls === QU) return NO_BREAK;
7693
+ return PASS;
7694
+ }
7695
+ /**
7696
+ * LB20: Break before and after unresolved CB.
7697
+ *
7698
+ * @type {BreakRule}
7699
+ */
7700
+ function LB20(state) {
7701
+ if (state.cur.cls === CB || state.next.cls === CB) return MAY_BREAK;
7702
+ return PASS;
7703
+ }
7704
+ var sotBKCRLFNLSPZWCBGL = /* @__PURE__ */ new Set([
7705
+ -1,
7706
+ BK,
7707
+ CR,
7708
+ LF,
7709
+ NL,
7710
+ SP,
7711
+ ZW,
7712
+ CB,
7713
+ GL
7714
+ ]);
7715
+ /**
7716
+ * LB20a: Do not break after a word-initial hyphen.
7717
+ *
7718
+ * @type {BreakRule}
7719
+ */
7720
+ function LB20a(state) {
7721
+ if (sotBKCRLFNLSPZWCBGL.has(state.prev.cls) && (state.cur.cls === HY || state.cur.cls === HH) && (state.next.cls === AL || state.next.cls === HL)) return NO_BREAK;
7722
+ return PASS;
7723
+ }
7724
+ /**
7725
+ * LB21: Do not break before hyphen-minus, other hyphens, fixed-width spaces,
7726
+ * small kana, and other non-starters, or after acute accents.
7727
+ *
7728
+ * @type {BreakRule}
7729
+ */
7730
+ function LB21(state) {
7731
+ if (state.cur.cls === BB) return NO_BREAK;
7732
+ switch (state.next.cls) {
7733
+ case BA:
7734
+ case HH:
7735
+ case HY:
7736
+ case NS: return NO_BREAK;
7737
+ }
7738
+ return PASS;
7739
+ }
7740
+ /**
7741
+ * LB21a: Do not break after the hyphen in Hebrew + Hyphen + non-Hebrew.
7742
+ *
7743
+ * @type {BreakRule}
7744
+ */
7745
+ function LB21a(state) {
7746
+ if (state.prev.cls === HL && (state.cur.cls === HY || state.cur.cls === HH) && state.next.cls !== HL) return NO_BREAK;
7747
+ return PASS;
7748
+ }
7749
+ /**
7750
+ * LB21b: Don’t break between Solidus and Hebrew letters.
7751
+ *
7752
+ * @type {BreakRule}
7753
+ */
7754
+ function LB21b(state) {
7755
+ if (state.cur.cls === SY && state.next.cls === HL) return NO_BREAK;
7756
+ return PASS;
7757
+ }
7758
+ /**
7759
+ * LB22: Do not break before ellipses.
7760
+ *
7761
+ * @type {BreakRule}
7762
+ */
7763
+ function LB22(state) {
7764
+ if (state.next.cls === IN) return NO_BREAK;
7765
+ return PASS;
7766
+ }
7767
+ /**
7768
+ * LB23: Do not break between digits and letters.
7769
+ *
7770
+ * @type {BreakRule}
7771
+ */
7772
+ function LB23(state) {
7773
+ switch (state.cur.cls) {
7774
+ case AL:
7775
+ case HL:
7776
+ if (state.next.cls === NU) return NO_BREAK;
7777
+ break;
7778
+ case NU: if (state.next.cls === AL || state.next.cls === HL) return NO_BREAK;
7779
+ }
7780
+ return PASS;
7781
+ }
7782
+ /**
7783
+ * LB23a: Do not break between numeric prefixes and ideographs, or between
7784
+ * ideographs and numeric postfixes.
7785
+ *
7786
+ * @type {BreakRule}
7787
+ */
7788
+ function LB23a(state) {
7789
+ if (state.cur.cls === PR && IDEBEM.has(state.next.cls)) return NO_BREAK;
7790
+ if (state.next.cls === PO && IDEBEM.has(state.cur.cls)) return NO_BREAK;
7791
+ return PASS;
7792
+ }
7793
+ /**
7794
+ * LB24: Do not break between numeric prefix/postfix and letters, or between
7795
+ * letters and prefix/postfix.
7796
+ *
7797
+ * @type {BreakRule}
7798
+ */
7799
+ function LB24(state) {
7800
+ if ((state.cur.cls === PR || state.cur.cls === PO) && (state.next.cls === AL || state.next.cls === HL)) return NO_BREAK;
7801
+ if ((state.cur.cls === AL || state.cur.cls === HL) && (state.next.cls === PR || state.next.cls === PO)) return NO_BREAK;
7802
+ return PASS;
7803
+ }
7804
+ var POPR = /* @__PURE__ */ new Set([PO, PR]);
7805
+ var CLCP = /* @__PURE__ */ new Set([CL, CP]);
7806
+ /**
7807
+ * LB25: Do not break numbers.
7808
+ * Approach: Find the end of a matching run, then no-break everything as we go
7809
+ * past it.
7810
+ *
7811
+ * @type {BreakRule}
7812
+ */
7813
+ function LB25(state) {
7814
+ let syIs = null;
7815
+ if (POPR.has(state.next.cls)) {
7816
+ if (CLCP.has(state.cur.cls)) syIs = state.prev.len;
7817
+ else syIs = state.cur.len;
7818
+ } else if (state.next.cls === NU) syIs = state.cur.len;
7819
+ if (syIs !== null) SyIsLoop: for (const { cls } of state.codePoints(syIs, false)) switch (cls) {
7820
+ case SY:
7821
+ case IS: continue;
7822
+ case NU: return NO_BREAK;
7823
+ default: break SyIsLoop;
7824
+ }
7825
+ if (state.cur.cls === PO || state.cur.cls === PR) {
7826
+ if (state.next.cls === OP) {
7827
+ const after = state.afterNext();
7828
+ if (after) {
7829
+ if (after.cls === NU) return NO_BREAK;
7830
+ else if (after.cls === IS) {
7831
+ if (state.afterNext(2)?.cls === NU) return NO_BREAK;
7832
+ }
7833
+ }
7834
+ } else if (state.next.cls === NU) return NO_BREAK;
7835
+ }
7836
+ if (state.cur.cls === HY && state.next.cls === NU) return NO_BREAK;
7837
+ if (state.cur.cls === IS && state.next.cls === NU) return NO_BREAK;
7838
+ return PASS;
7839
+ }
7840
+ /**
7841
+ * LB26: Do not break a Korean syllable.
7842
+ *
7843
+ * @type {BreakRule}
7844
+ */
7845
+ function LB26(state) {
7846
+ switch (state.cur.cls) {
7847
+ case JL:
7848
+ if (JLJVH2H3.has(state.next.cls)) return NO_BREAK;
7849
+ break;
7850
+ case JV:
7851
+ case H2:
7852
+ if (JVJT.has(state.next.cls)) return NO_BREAK;
7853
+ break;
7854
+ case JT:
7855
+ case H3: if (state.next.cls === JT) return NO_BREAK;
7856
+ }
7857
+ return PASS;
7858
+ }
7859
+ /**
7860
+ * LB27: Treat a Korean Syllable Block the same as ID.
7861
+ *
7862
+ * @type {BreakRule}
7863
+ */
7864
+ function LB27(state) {
7865
+ switch (state.cur.cls) {
7866
+ case JL:
7867
+ case JV:
7868
+ case JT:
7869
+ case H2:
7870
+ case H3:
7871
+ if (state.next.cls === PO) return NO_BREAK;
7872
+ break;
7873
+ case PR: if (JLJVJTH2H3.has(state.next.cls)) return NO_BREAK;
7874
+ }
7875
+ return PASS;
7876
+ }
7877
+ /**
7878
+ * LB28 Do not break between alphabetics (“at”).
7879
+ *
7880
+ * @type {BreakRule}
7881
+ */
7882
+ function LB28(state) {
7883
+ if ((state.cur.cls === AL || state.cur.cls === HL) && (state.next.cls === AL || state.next.cls === HL)) return NO_BREAK;
7884
+ return PASS;
7885
+ }
7886
+ /**
7887
+ * LB28a: Do not break inside the orthographic syllables of Brahmic scripts.
7888
+ *
7889
+ * @type {BreakRule}
7890
+ */
7891
+ function LB28a(state) {
7892
+ const { prev, cur, next } = state;
7893
+ const dotCircle = "◌";
7894
+ /**
7895
+ * AK | ◌ | AS
7896
+ *
7897
+ * @param {import('./state.js').BreakerChar} chr Check one char
7898
+ * @returns true if char matches
7899
+ */
7900
+ function akCas(chr) {
7901
+ return chr.cls === AK || chr.char === dotCircle || chr.cls === AS;
7902
+ }
7903
+ if (cur.cls === AP && akCas(next)) return NO_BREAK;
7904
+ if (akCas(cur) && (next.cls === VF || next.cls === VI)) return NO_BREAK;
7905
+ if (akCas(prev) && cur.cls === VI && (next.cls === AK || next.char === dotCircle)) return NO_BREAK;
7906
+ if (akCas(cur) && akCas(next) && state.afterNext()?.cls === VF) return NO_BREAK;
7907
+ return PASS;
7908
+ }
7909
+ /**
7910
+ * LB29: Do not break between numeric punctuation and alphabetics (“e.g.”).
7911
+ *
7912
+ * @type {BreakRule}
7913
+ */
7914
+ function LB29(state) {
7915
+ if (state.cur.cls === IS && (state.next.cls === AL || state.next.cls === HL)) return NO_BREAK;
7916
+ return PASS;
7917
+ }
7918
+ /**
7919
+ * LB30: Do not break between letters, numbers, or ordinary symbols and
7920
+ * opening or closing parentheses.
7921
+ *
7922
+ * @type {BreakRule}
7923
+ */
7924
+ function LB30(state) {
7925
+ switch (state.cur.cls) {
7926
+ case AL:
7927
+ case HL:
7928
+ case NU:
7929
+ if (state.next.cls === OP && !EastAsianWidth.get(state.next.cp)) return NO_BREAK;
7930
+ break;
7931
+ case CP: if (!EastAsianWidth.get(state.cur.cp) && ALHLNU.has(state.next.cls)) return NO_BREAK;
7932
+ }
7933
+ return PASS;
7934
+ }
7935
+ /**
7936
+ * LB30a: Break between two regional indicator symbols if and only if there
7937
+ * are an even number of regional indicators preceding the position of the
7938
+ * break.
7939
+ *
7940
+ * @type {BreakRule}
7941
+ */
7942
+ function LB30a(state) {
7943
+ if (state.cur.cls === RI) {
7944
+ if (state.next.cls === RI) {
7945
+ if (++state.RI % 2 !== 0) return NO_BREAK;
7946
+ }
7947
+ } else state.RI = 0;
7948
+ return PASS;
7949
+ }
7950
+ /**
7951
+ * LB30b: Do not break between an emoji base (or potential emoji) and an emoji
7952
+ * modifier.
7953
+ *
7954
+ * @type {BreakRule}
7955
+ */
7956
+ function LB30b(state) {
7957
+ if (state.cur.cls === EB && state.next.cls === EM) return NO_BREAK;
7958
+ if (state.next.cls === EM && /^\p{ExtPict}$/u.test(state.cur.char) && /^\p{gc=Cn}$/u.test(state.cur.char)) return NO_BREAK;
7959
+ return PASS;
7960
+ }
7961
+ /**
7962
+ * LB31: Break everywhere else.
7963
+ *
7964
+ * @type {BreakRule}
7965
+ */
7966
+ function LB31() {
7967
+ return MAY_BREAK;
7968
+ }
7969
+ /**
7970
+ * @type {BreakRule[]}
7971
+ * @private
7972
+ */
7973
+ var rules = [
7974
+ LB02,
7975
+ LB03,
7976
+ LB04,
7977
+ LB05,
7978
+ LB06,
7979
+ LBspacesStop,
7980
+ LB07,
7981
+ LB08,
7982
+ LB08a,
7983
+ LB09,
7984
+ LB10,
7985
+ LB11,
7986
+ LB12,
7987
+ LB12a,
7988
+ LB13,
7989
+ LB14,
7990
+ LB15a,
7991
+ LB15b,
7992
+ LB15c,
7993
+ LB15d,
7994
+ LB16,
7995
+ LB17,
7996
+ LB18,
7997
+ LB19,
7998
+ LB19a,
7999
+ LB20,
8000
+ LB20a,
8001
+ LB21a,
8002
+ LB21,
8003
+ LB21b,
8004
+ LB22,
8005
+ LB23,
8006
+ LB23a,
8007
+ LB24,
8008
+ LB25,
8009
+ LB26,
8010
+ LB27,
8011
+ LB28,
8012
+ LB28a,
8013
+ LB29,
8014
+ LB30,
8015
+ LB30a,
8016
+ LB30b,
8017
+ LB31
8018
+ ];
8019
+ var _opts = /* @__PURE__ */ new WeakMap();
8020
+ var _Rules_brand = /* @__PURE__ */ new WeakSet();
8021
+ /**
8022
+ * Options for how rules are applied.
8023
+ *
8024
+ * @typedef {object} RulesOptions
8025
+ * @prop {boolean} [string=false] Extract strings from input, rather than just
8026
+ * returning char offsets.
8027
+ * @prop {boolean} [verbose=false] Turn on some verbose logging that is
8028
+ * useful for debug.
8029
+ */
8030
+ var Rules = class {
8031
+ /**
8032
+ *
8033
+ * @param {RulesOptions} opts
8034
+ */
8035
+ constructor(opts = {}) {
8036
+ _classPrivateMethodInitSpec(this, _Rules_brand);
8037
+ _classPrivateFieldInitSpec(this, _opts, void 0);
8038
+ /**
8039
+ * @type {Required<RulesOptions>}
8040
+ */
8041
+ _classPrivateFieldSet2(_opts, this, {
8042
+ string: false,
8043
+ example7: false,
8044
+ verbose: false,
8045
+ ...opts
8046
+ });
8047
+ /**
8048
+ * Copy of rules, safe to tweak.
8049
+ *
8050
+ * @type {BreakRule[]}
8051
+ */
8052
+ this.rules = [...rules];
8053
+ if (_classPrivateFieldGet2(_opts, this).example7) throw new Error("'example7' flag deprecated");
8054
+ if (_classPrivateFieldGet2(_opts, this).verbose) this.rules.unshift((state) => {
8055
+ console.log(state.cur.len, state);
8056
+ return PASS;
8057
+ });
8058
+ }
8059
+ /**
8060
+ * Remove the rules with names as indicated.
8061
+ *
8062
+ * @param {...string} names
8063
+ * @returns {BreakRule[]} The deleted rules
8064
+ */
8065
+ removeRule(...names) {
8066
+ /**
8067
+ * @type {BreakRule[]}
8068
+ */
8069
+ const ret = [];
8070
+ this.rules = this.rules.filter((r) => {
8071
+ if (names.includes(r.name)) {
8072
+ ret.push(r);
8073
+ return false;
8074
+ }
8075
+ return true;
8076
+ });
8077
+ return ret;
8078
+ }
8079
+ /**
8080
+ * Add rules after the one named `name`.
8081
+ *
8082
+ * @param {string} name The name of the rule before.
8083
+ * @param {...BreakRule} newRules
8084
+ * @returns {number} Index of start of the new rules
8085
+ */
8086
+ addRuleAfter(name, ...newRules) {
8087
+ const i = this.rules.findIndex((r) => r.name === name);
8088
+ if (i === -1) throw new Error(`Rule not found: "${name}"`);
8089
+ this.rules.splice(i + 1, 0, ...newRules);
8090
+ return i + 1;
8091
+ }
8092
+ /**
8093
+ * Add rules before the one named `name`.
8094
+ *
8095
+ * @param {string} name The name of the rule before.
8096
+ * @param {...BreakRule} newRules
8097
+ * @returns {number} Index of start of the new rules
8098
+ */
8099
+ addRuleBefore(name, ...newRules) {
8100
+ const i = this.rules.findIndex((r) => r.name === name);
8101
+ if (i === -1) throw new Error(`Rule not found: "${name}"`);
8102
+ this.rules.splice(i, 0, ...newRules);
8103
+ return i;
8104
+ }
8105
+ /**
8106
+ * Replace the rule named `name` with the given rules.
8107
+ *
8108
+ * @param {string} name The name of the rule before.
8109
+ * @param {...BreakRule} newRules
8110
+ * @returns {BreakRule[]} The replaced rules.
8111
+ */
8112
+ replaceRule(name, ...newRules) {
8113
+ const i = this.rules.findIndex((r) => r.name === name);
8114
+ if (i === -1) throw new Error(`Rule not found: "${name}"`);
8115
+ return this.rules.splice(i, 1, ...newRules);
8116
+ }
8117
+ /**
8118
+ * Enumerate all of the potential line breaks.
8119
+ *
8120
+ * @param {string} str
8121
+ */
8122
+ *breaks(str) {
8123
+ const state = new BreakerState(str);
8124
+ for (const step of state.codePoints(0)) {
8125
+ state.push(step);
8126
+ yield* _assertClassBrand(_Rules_brand, this, _exec).call(this, state);
8127
+ }
8128
+ state.pushEnd();
8129
+ yield* _assertClassBrand(_Rules_brand, this, _exec).call(this, state);
8130
+ }
8131
+ };
8132
+ /**
8133
+ *
8134
+ * @param {BreakerState} state
8135
+ * @returns {Break?}
8136
+ */
8137
+ function _execRules(state) {
8138
+ for (const rule of this.rules) {
8139
+ const res = rule.call(this, state);
8140
+ switch (res) {
8141
+ case PASS: break;
8142
+ case NO_BREAK:
8143
+ if (_classPrivateFieldGet2(_opts, this).verbose) console.log(` ${rule.name}: NO_BREAK`);
8144
+ return null;
8145
+ case MAY_BREAK:
8146
+ if (_classPrivateFieldGet2(_opts, this).verbose) console.log(` ${rule.name}: MAY_BREAK`);
8147
+ return new Break(state.cur.len);
8148
+ case MUST_BREAK:
8149
+ if (_classPrivateFieldGet2(_opts, this).verbose) console.log(` ${rule.name}: MUST_BREAK`);
8150
+ return new Break(state.cur.len, true);
8151
+ default: throw new Error(`Invalid state: "${res}"`);
8152
+ }
8153
+ }
8154
+ return null;
8155
+ }
8156
+ /**
8157
+ * @param {BreakerState} state
8158
+ */
8159
+ function* _exec(state) {
8160
+ const res = _assertClassBrand(_Rules_brand, this, _execRules).call(this, state);
8161
+ if (res) {
8162
+ if (_classPrivateFieldGet2(_opts, this).string) res.string = state.str.slice(state.prevChunk, state.cur.len);
8163
+ if (state.props) {
8164
+ res.props = state.props;
8165
+ state.props = void 0;
8166
+ }
8167
+ yield res;
8168
+ state.prevChunk = state.cur.len;
8169
+ }
8170
+ }
8171
+ //#endregion
8172
+ //#region src/text-layout.ts
8173
+ function graphemeBoundaries(text, locale) {
8174
+ const segmenter = new Intl.Segmenter(locale, { granularity: "grapheme" });
8175
+ const boundaries = /* @__PURE__ */ new Set([0]);
8176
+ for (const item of segmenter.segment(text)) boundaries.add(item.index + item.segment.length);
8177
+ return boundaries;
8178
+ }
8179
+ var _rules = /* @__PURE__ */ new WeakMap();
8180
+ var _locale = /* @__PURE__ */ new WeakMap();
8181
+ /**
8182
+ * Adapts UAX #14 opportunities and removes positions inside grapheme clusters.
8183
+ */
8184
+ var UnicodeLineBreakProvider = class {
8185
+ constructor(locale = "ja") {
8186
+ _classPrivateFieldInitSpec(this, _rules, new Rules());
8187
+ _classPrivateFieldInitSpec(this, _locale, void 0);
8188
+ _classPrivateFieldSet2(_locale, this, locale);
8189
+ }
8190
+ getBreakOpportunities(text) {
8191
+ const boundaries = graphemeBoundaries(text, _classPrivateFieldGet2(_locale, this));
8192
+ const opportunities = /* @__PURE__ */ new Map();
8193
+ for (const candidate of _classPrivateFieldGet2(_rules, this).breaks(text)) {
8194
+ if (!boundaries.has(candidate.position)) continue;
8195
+ opportunities.set(candidate.position, (opportunities.get(candidate.position) ?? false) || candidate.required);
8196
+ }
8197
+ return Object.freeze([...opportunities].sort(([left], [right]) => left - right).map(([position, required]) => Object.freeze({
8198
+ position,
8199
+ required
8200
+ })));
8201
+ }
8202
+ };
8203
+ var defaultLineBreakProviders = /* @__PURE__ */ new Map();
8204
+ var newlinePattern = /\r\n|[\n\r\v\f\u0085\u2028\u2029]/gu;
8205
+ function defaultLineBreakProvider(locale) {
8206
+ const existing = defaultLineBreakProviders.get(locale);
8207
+ if (existing) return existing;
8208
+ const provider = new UnicodeLineBreakProvider(locale);
8209
+ defaultLineBreakProviders.set(locale, provider);
8210
+ return provider;
8211
+ }
8212
+ function requireWidth(width, label) {
8213
+ if (!Number.isFinite(width) || width < 0) throw new TypeError(`${label} must return a non-negative finite number.`);
8214
+ return width;
8215
+ }
8216
+ function normalizeOpportunities(text, provider, boundaries) {
8217
+ const normalized = /* @__PURE__ */ new Map();
8218
+ for (const opportunity of provider.getBreakOpportunities(text)) {
8219
+ const { position, required } = opportunity;
8220
+ if (!Number.isInteger(position) || position <= 0 || position > text.length || !boundaries.has(position)) continue;
8221
+ normalized.set(position, (normalized.get(position) ?? false) || required);
8222
+ }
8223
+ normalized.set(text.length, true);
8224
+ return [...normalized].sort(([left], [right]) => left - right).map(([position, required]) => ({
8225
+ position,
8226
+ required
8227
+ }));
8228
+ }
8229
+ function wrapParagraph(text, originalStart, input, provider, locale) {
8230
+ if (text.length === 0) return [{
8231
+ text: "",
8232
+ start: originalStart,
8233
+ end: originalStart,
8234
+ width: 0
8235
+ }];
8236
+ const boundarySet = graphemeBoundaries(text, locale);
8237
+ const boundaries = [...boundarySet].sort((left, right) => left - right);
8238
+ const opportunities = normalizeOpportunities(text, provider, boundarySet);
8239
+ const lines = [];
8240
+ let start = 0;
8241
+ while (start < text.length) {
8242
+ const requiredEnd = opportunities.find((opportunity) => opportunity.position > start && opportunity.required)?.position ?? text.length;
8243
+ let selected;
8244
+ let selectedWidth = 0;
8245
+ for (const opportunity of opportunities) {
8246
+ if (opportunity.position <= start || opportunity.position > requiredEnd) continue;
8247
+ const candidate = text.slice(start, opportunity.position);
8248
+ const width = requireWidth(input.measureText(candidate), "measureText");
8249
+ if (width <= input.maxWidth) {
8250
+ selected = opportunity.position;
8251
+ selectedWidth = width;
8252
+ }
8253
+ }
8254
+ if (selected === void 0) {
8255
+ const fallbackBoundaries = boundaries.filter((position) => position > start && position <= requiredEnd);
8256
+ for (const position of fallbackBoundaries) {
8257
+ const candidate = text.slice(start, position);
8258
+ const width = requireWidth(input.measureText(candidate), "measureText");
8259
+ if (width <= input.maxWidth) {
8260
+ selected = position;
8261
+ selectedWidth = width;
8262
+ }
8263
+ }
8264
+ if (selected === void 0) {
8265
+ selected = fallbackBoundaries[0] ?? requiredEnd;
8266
+ selectedWidth = requireWidth(input.measureText(text.slice(start, selected)), "measureText");
8267
+ }
8268
+ }
8269
+ lines.push({
8270
+ text: text.slice(start, selected),
8271
+ start: originalStart + start,
8272
+ end: originalStart + selected,
8273
+ width: selectedWidth
8274
+ });
8275
+ start = selected;
8276
+ }
8277
+ return lines;
8278
+ }
8279
+ /**
8280
+ * Greedily chooses the last legal break that fits the measured pixel width.
8281
+ * Explicit newlines are preserved. Unbreakable overflow falls back to a
8282
+ * grapheme boundary, even when a single grapheme is wider than maxWidth.
8283
+ */
8284
+ function wrapText(input) {
8285
+ if (typeof input.text !== "string") throw new TypeError("text must be a string.");
8286
+ if (!Number.isFinite(input.maxWidth) || input.maxWidth <= 0) throw new TypeError("maxWidth must be a positive finite number.");
8287
+ if (typeof input.measureText !== "function") throw new TypeError("measureText must be a function.");
8288
+ const locale = input.locale ?? "ja";
8289
+ const provider = input.lineBreakProvider ?? defaultLineBreakProvider(locale);
8290
+ const lines = [];
8291
+ let paragraphStart = 0;
8292
+ for (const newline of input.text.matchAll(newlinePattern)) {
8293
+ const newlineStart = newline.index;
8294
+ lines.push(...wrapParagraph(input.text.slice(paragraphStart, newlineStart), paragraphStart, input, provider, locale));
8295
+ paragraphStart = newlineStart + newline[0].length;
8296
+ }
8297
+ lines.push(...wrapParagraph(input.text.slice(paragraphStart), paragraphStart, input, provider, locale));
8298
+ return Object.freeze({
8299
+ lines: Object.freeze(lines.map((line) => Object.freeze(line))),
8300
+ maxLineWidth: Math.max(0, ...lines.map((line) => line.width))
8301
+ });
8302
+ }
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
8400
+ //#region src/composition.ts
8401
+ var BubbleCompositionError = class extends Error {
8402
+ constructor(code, message) {
8403
+ super(message);
8404
+ _defineProperty(this, "code", void 0);
8405
+ this.name = "BubbleCompositionError";
8406
+ this.code = code;
8407
+ }
8408
+ };
8409
+ var validKinds = /* @__PURE__ */ new Set(["say", "think"]);
8410
+ var validAnimationModes$1 = /* @__PURE__ */ new Set([
8411
+ "idle",
8412
+ "talking",
8413
+ "awaiting-continue"
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
+ ]);
8434
+ function isRecord$1(value) {
8435
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6696
8436
  }
6697
8437
  function requireExactKeys(value, required, optional, label) {
6698
8438
  const allowed = /* @__PURE__ */ new Set([...required, ...optional]);
@@ -6718,28 +8458,101 @@
6718
8458
  }
6719
8459
  function normalizePortrait(value) {
6720
8460
  if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble portrait must be an object.");
6721
- requireExactKeys(value, ["base"], ["blink", "talk"], "Bubble portrait");
8461
+ requireExactKeys(value, ["base"], ["blink", "lipSync"], "Bubble portrait");
6722
8462
  const blink = value.blink === void 0 ? void 0 : normalizeAnimation(value.blink, "Bubble portrait blink", 1);
6723
- const talk = value.talk === void 0 ? void 0 : normalizeAnimation(value.talk, "Bubble portrait talk", 1);
8463
+ const lipSync = value.lipSync === void 0 ? void 0 : normalizeAnimation(value.lipSync, "Bubble portrait lip-sync", 1);
6724
8464
  return Object.freeze({
6725
8465
  base: requireName(value.base, "Bubble portrait base"),
6726
8466
  ...blink === void 0 ? {} : { blink },
6727
- ...talk === void 0 ? {} : { talk }
8467
+ ...lipSync === void 0 ? {} : { lipSync }
8468
+ });
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 }
6728
8507
  });
6729
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
+ }
6730
8528
  function normalizeStyle(value) {
6731
8529
  if (!isRecord$1(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
6732
8530
  requireExactKeys(value, ["name", "textStyle"], [
6733
8531
  "placement",
8532
+ "maxWidth",
8533
+ "textLocale",
6734
8534
  "distance",
6735
8535
  "tailLength",
6736
8536
  "offset",
6737
8537
  "visualStyle",
6738
8538
  "portrait",
6739
- "advanceIndicator"
8539
+ "continueIndicator",
8540
+ "reveal",
8541
+ "audio",
8542
+ "showAnimation",
8543
+ "hideAnimation"
6740
8544
  ], "Bubble style");
6741
8545
  const portrait = value.portrait === void 0 ? void 0 : normalizePortrait(value.portrait);
6742
- const advanceIndicator = value.advanceIndicator === void 0 ? void 0 : normalizeAnimation(value.advanceIndicator, "Bubble advance indicator", 2);
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");
6743
8556
  let placement;
6744
8557
  try {
6745
8558
  placement = normalizeBubblePlacement(value.placement ?? "up-right");
@@ -6758,20 +8571,44 @@
6758
8571
  }
6759
8572
  const visualStyle = value.visualStyle ?? "NORMAL";
6760
8573
  if (typeof visualStyle !== "string" || !bubbleVisualStyles.includes(visualStyle)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `Unsupported Bubble visual style: ${String(visualStyle)}`);
8574
+ let maxWidth;
8575
+ if (value.maxWidth !== void 0) {
8576
+ if (typeof value.maxWidth !== "number" || !Number.isFinite(value.maxWidth) || value.maxWidth <= 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style maxWidth must be a positive finite number.");
8577
+ maxWidth = value.maxWidth;
8578
+ }
8579
+ const textLocale = value.textLocale === void 0 ? void 0 : requireName(value.textLocale, "Bubble style text locale");
6761
8580
  return Object.freeze({
6762
8581
  name: requireName(value.name, "Bubble style name"),
6763
8582
  textStyle: requireName(value.textStyle, "Bubble text style name"),
8583
+ ...maxWidth === void 0 ? {} : { maxWidth },
8584
+ ...textLocale === void 0 ? {} : { textLocale },
6764
8585
  placement,
6765
8586
  distance,
6766
8587
  tailLength,
6767
8588
  offset,
6768
8589
  visualStyle,
6769
8590
  ...portrait === void 0 ? {} : { portrait },
6770
- ...advanceIndicator === void 0 ? {} : { advanceIndicator }
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 }
6771
8596
  });
6772
8597
  }
6773
- function validateAssetManager(value) {
6774
- if (!isRecord$1(value) || typeof value.applyToTarget !== "function" || typeof value.getMimeType !== "function" || typeof value.isRegistered !== "function") throw new TypeError("Bubble asset manager must provide applyToTarget, getMimeType, and isRegistered.");
8598
+ function validateImageResolver(value) {
8599
+ if (value === void 0) return void 0;
8600
+ if (!isRecord$1(value) || typeof value.applyToTarget !== "function" || typeof value.getMimeType !== "function" || typeof value.isRegistered !== "function") throw new TypeError("Bubble image capability must provide applyToTarget, getMimeType, and isRegistered.");
8601
+ return value;
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
+ }
8610
+ function requireImageResolver(value) {
8611
+ if (value === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", "Bubble image assets require an image capability. Provide options.imageResolver.");
6775
8612
  return value;
6776
8613
  }
6777
8614
  function validateSvgText(value) {
@@ -6797,7 +8634,7 @@
6797
8634
  return value;
6798
8635
  }
6799
8636
  function validateSurface(value, style) {
6800
- if (!isRecord$1(value) || !isRecord$1(value.targets) || typeof value.setLayerVisible !== "function" || typeof value.show !== "function" || typeof value.hide !== "function" || typeof value.dispose !== "function") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", "Bubble surface is invalid.");
8637
+ if (!isRecord$1(value) || !isRecord$1(value.targets) || typeof value.setLayerVisible !== "function" || typeof value.updateStyle !== "function" || typeof value.show !== "function" || typeof value.hide !== "function" || typeof value.dispose !== "function") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", "Bubble surface is invalid.");
6801
8638
  const targets = value.targets;
6802
8639
  validateTextTarget(targets.text);
6803
8640
  const assetTargetIds = /* @__PURE__ */ new Set();
@@ -6810,20 +8647,40 @@
6810
8647
  };
6811
8648
  requireLayerTarget("portraitBase", style.portrait !== void 0);
6812
8649
  requireLayerTarget("portraitBlink", style.portrait?.blink !== void 0);
6813
- requireLayerTarget("portraitTalk", style.portrait?.talk !== void 0);
6814
- requireLayerTarget("advanceIndicator", style.advanceIndicator !== void 0);
8650
+ requireLayerTarget("portraitLipSync", style.portrait?.lipSync !== void 0);
8651
+ requireLayerTarget("continueIndicator", style.continueIndicator !== void 0);
6815
8652
  return value;
6816
8653
  }
6817
- function requireImageAsset(assetManager, name) {
6818
- if (!assetManager.isRegistered(name)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble image asset is not registered: ${name}`);
6819
- if (!assetManager.getMimeType(name).startsWith("image/")) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble asset is not an image: ${name}`);
8654
+ function requireImageAsset(imageResolver, name) {
8655
+ if (imageResolver === void 0) throw new BubbleCompositionError("BUBBLE-COMPOSITION-006", `Bubble image capability is required for: ${name}. Provide options.imageResolver.`);
8656
+ if (!imageResolver.isRegistered(name)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble image asset is not registered: ${name}`);
8657
+ if (!imageResolver.getMimeType(name).startsWith("image/")) throw new BubbleCompositionError("BUBBLE-COMPOSITION-003", `Bubble asset is not an image: ${name}`);
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}`);
6820
8664
  }
6821
8665
  function styleAssetNames(style) {
6822
8666
  return [...style.portrait === void 0 ? [] : [
6823
8667
  style.portrait.base,
6824
8668
  ...style.portrait.blink?.frames ?? [],
6825
- ...style.portrait.talk?.frames ?? []
6826
- ], ...style.advanceIndicator?.frames ?? []];
8669
+ ...style.portrait.lipSync?.frames ?? []
8670
+ ], ...style.continueIndicator?.frames ?? []];
8671
+ }
8672
+ function formatBubbleText(text, style, textCapability) {
8673
+ if (style.maxWidth === void 0) return text;
8674
+ if (typeof textCapability.measureText !== "function") throw new BubbleCompositionError("BUBBLE-COMPOSITION-007", "Bubble style maxWidth requires the text capability measureText method.");
8675
+ return wrapText({
8676
+ text,
8677
+ maxWidth: style.maxWidth,
8678
+ ...style.textLocale === void 0 ? {} : { locale: style.textLocale },
8679
+ measureText: (candidate) => textCapability.measureText?.({
8680
+ styleName: style.textStyle,
8681
+ text: candidate
8682
+ }) ?? 0
8683
+ }).lines.map(({ text: line }) => line).join("\n");
6827
8684
  }
6828
8685
  function aggregateErrors(errors, message) {
6829
8686
  if (errors.length === 1) throw errors[0];
@@ -6838,7 +8695,7 @@
6838
8695
  const applyFrame = async (index) => {
6839
8696
  const assetName = options.animation.frames[index];
6840
8697
  if (assetName === void 0) return;
6841
- await options.assetManager.applyToTarget(assetName, options.target);
8698
+ await options.imageResolver.applyToTarget(assetName, options.target);
6842
8699
  };
6843
8700
  const reportError = (error, assetName) => {
6844
8701
  options.onError?.(error, Object.freeze({
@@ -6895,23 +8752,31 @@
6895
8752
  "kind",
6896
8753
  "text",
6897
8754
  "styleName"
6898
- ], ["animationMode"], "Show bubble input");
8755
+ ], ["animationMode", "reveal"], "Show bubble input");
6899
8756
  if (!validKinds.has(value.kind)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble kind must be say or think.");
6900
8757
  if (typeof value.text !== "string") throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble text must be a string.");
6901
8758
  const animationMode = value.animationMode ?? "talking";
6902
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
+ }
6903
8766
  return {
6904
8767
  actor: value.actor,
6905
8768
  actorKey: requireName(value.actorKey, "Bubble actor key"),
6906
8769
  kind: value.kind,
6907
8770
  text: value.text,
6908
8771
  styleName: requireName(value.styleName, "Bubble style name"),
6909
- animationMode
8772
+ animationMode,
8773
+ ...reveal === void 0 ? {} : { reveal }
6910
8774
  };
6911
8775
  }
6912
8776
  function createBubbleComposition(options) {
6913
8777
  if (!isRecord$1(options)) throw new TypeError("Bubble composition options must be an object.");
6914
- const assetManager = validateAssetManager(options.assetManager);
8778
+ const imageResolver = validateImageResolver(options.imageResolver);
8779
+ const audio = validateAudioCapability(options.audio);
6915
8780
  const svgText = validateSvgText(options.svgText);
6916
8781
  if (typeof options.createSurface !== "function") throw new TypeError("Bubble composition createSurface must be a function.");
6917
8782
  if (options.onAnimationError !== void 0 && typeof options.onAnimationError !== "function") throw new TypeError("Bubble composition onAnimationError must be a function.");
@@ -6936,95 +8801,176 @@
6936
8801
  ensureActive();
6937
8802
  const style = styles.get(input.styleName);
6938
8803
  if (!style) throw new BubbleCompositionError("BUBBLE-COMPOSITION-002", `Bubble style is not defined: ${input.styleName}`);
6939
- for (const assetName of new Set(styleAssetNames(style))) requireImageAsset(assetManager, assetName);
8804
+ let activeStyle = style;
8805
+ if (input.reveal !== void 0) activeStyle = Object.freeze({
8806
+ ...style,
8807
+ reveal: input.reveal
8808
+ });
8809
+ let currentText = input.text;
8810
+ const resolveStyleImageCapability = (nextStyle) => {
8811
+ const assetNames = new Set(styleAssetNames(nextStyle));
8812
+ const nextImageResolver = assetNames.size === 0 ? void 0 : requireImageResolver(imageResolver);
8813
+ for (const assetName of assetNames) requireImageAsset(nextImageResolver, assetName);
8814
+ return nextImageResolver;
8815
+ };
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
+ };
8827
+ const primeStyleImages = async (nextStyle, nextImageResolver, nextSurface) => {
8828
+ const imageCapability = styleAssetNames(nextStyle).length === 0 ? void 0 : requireImageResolver(nextImageResolver);
8829
+ const operations = [];
8830
+ if (nextStyle.portrait) {
8831
+ const capability = requireImageResolver(imageCapability);
8832
+ operations.push(Promise.resolve(capability.applyToTarget(nextStyle.portrait.base, nextSurface.targets.portraitBase)));
8833
+ const blinkFirst = nextStyle.portrait.blink?.frames[0];
8834
+ if (blinkFirst !== void 0) operations.push(Promise.resolve(capability.applyToTarget(blinkFirst, nextSurface.targets.portraitBlink)));
8835
+ const lipSyncFirst = nextStyle.portrait.lipSync?.frames[0];
8836
+ if (lipSyncFirst !== void 0) operations.push(Promise.resolve(capability.applyToTarget(lipSyncFirst, nextSurface.targets.portraitLipSync)));
8837
+ }
8838
+ const continueFirst = nextStyle.continueIndicator?.frames[0];
8839
+ if (continueFirst !== void 0) {
8840
+ const capability = requireImageResolver(imageCapability);
8841
+ operations.push(Promise.resolve(capability.applyToTarget(continueFirst, nextSurface.targets.continueIndicator)));
8842
+ }
8843
+ await Promise.all(operations);
8844
+ };
8845
+ const createStyleLoops = (nextStyle, nextImageResolver, nextSurface) => {
8846
+ blinkLoop = nextStyle.portrait?.blink === void 0 ? void 0 : createFrameLoop({
8847
+ actorKey: input.actorKey,
8848
+ layer: "portraitBlink",
8849
+ animation: nextStyle.portrait.blink,
8850
+ target: nextSurface.targets.portraitBlink,
8851
+ imageResolver: requireImageResolver(nextImageResolver),
8852
+ scheduler,
8853
+ ...options.onAnimationError === void 0 ? {} : { onError: options.onAnimationError }
8854
+ });
8855
+ lipSyncLoop = nextStyle.portrait?.lipSync === void 0 ? void 0 : createFrameLoop({
8856
+ actorKey: input.actorKey,
8857
+ layer: "portraitLipSync",
8858
+ animation: nextStyle.portrait.lipSync,
8859
+ target: nextSurface.targets.portraitLipSync,
8860
+ imageResolver: requireImageResolver(nextImageResolver),
8861
+ scheduler,
8862
+ ...options.onAnimationError === void 0 ? {} : { onError: options.onAnimationError }
8863
+ });
8864
+ indicatorLoop = nextStyle.continueIndicator === void 0 ? void 0 : createFrameLoop({
8865
+ actorKey: input.actorKey,
8866
+ layer: "continueIndicator",
8867
+ animation: nextStyle.continueIndicator,
8868
+ target: nextSurface.targets.continueIndicator,
8869
+ imageResolver: requireImageResolver(nextImageResolver),
8870
+ scheduler,
8871
+ ...options.onAnimationError === void 0 ? {} : { onError: options.onAnimationError }
8872
+ });
8873
+ };
6940
8874
  const previous = active.get(input.actorKey);
6941
8875
  if (previous) await previous.close();
6942
8876
  let surface;
6943
8877
  let textOwned = false;
6944
8878
  let surfaceVisible = false;
6945
8879
  let blinkLoop;
6946
- let talkLoop;
8880
+ let lipSyncLoop;
6947
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;
6948
8887
  try {
6949
8888
  surface = validateSurface(await options.createSurface(Object.freeze({
6950
8889
  actor: input.actor,
6951
8890
  actorKey: input.actorKey,
6952
8891
  kind: input.kind,
6953
- style
6954
- })), style);
8892
+ style: activeStyle
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
+ }
6955
8903
  svgText.setText({
6956
- styleName: style.textStyle,
8904
+ styleName: activeStyle.textStyle,
6957
8905
  target: surface.targets.text,
6958
- text: input.text
8906
+ text: formatBubbleText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text, activeStyle, svgText)
6959
8907
  });
6960
8908
  textOwned = true;
6961
- const primeOperations = [];
6962
- if (style.portrait) {
6963
- primeOperations.push(assetManager.applyToTarget(style.portrait.base, surface.targets.portraitBase));
6964
- const blinkFirst = style.portrait.blink?.frames[0];
6965
- if (blinkFirst !== void 0) primeOperations.push(assetManager.applyToTarget(blinkFirst, surface.targets.portraitBlink));
6966
- const talkFirst = style.portrait.talk?.frames[0];
6967
- if (talkFirst !== void 0) primeOperations.push(assetManager.applyToTarget(talkFirst, surface.targets.portraitTalk));
6968
- }
6969
- const indicatorFirst = style.advanceIndicator?.frames[0];
6970
- if (indicatorFirst !== void 0) primeOperations.push(assetManager.applyToTarget(indicatorFirst, surface.targets.advanceIndicator));
6971
- await Promise.all(primeOperations);
6972
- blinkLoop = style.portrait?.blink === void 0 ? void 0 : createFrameLoop({
6973
- actorKey: input.actorKey,
6974
- layer: "portraitBlink",
6975
- animation: style.portrait.blink,
6976
- target: surface.targets.portraitBlink,
6977
- assetManager,
6978
- scheduler,
6979
- ...options.onAnimationError === void 0 ? {} : { onError: options.onAnimationError }
6980
- });
6981
- talkLoop = style.portrait?.talk === void 0 ? void 0 : createFrameLoop({
6982
- actorKey: input.actorKey,
6983
- layer: "portraitTalk",
6984
- animation: style.portrait.talk,
6985
- target: surface.targets.portraitTalk,
6986
- assetManager,
6987
- scheduler,
6988
- ...options.onAnimationError === void 0 ? {} : { onError: options.onAnimationError }
6989
- });
6990
- indicatorLoop = style.advanceIndicator === void 0 ? void 0 : createFrameLoop({
6991
- actorKey: input.actorKey,
6992
- layer: "advanceIndicator",
6993
- animation: style.advanceIndicator,
6994
- target: surface.targets.advanceIndicator,
6995
- assetManager,
6996
- scheduler,
6997
- ...options.onAnimationError === void 0 ? {} : { onError: options.onAnimationError }
6998
- });
8909
+ await primeStyleImages(activeStyle, styleImageResolver, surface);
8910
+ createStyleLoops(activeStyle, styleImageResolver, surface);
6999
8911
  let currentAnimationMode = "idle";
7000
8912
  let closed = false;
7001
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
+ };
7002
8946
  const applyAnimationMode = async (mode) => {
7003
8947
  if (mode === currentAnimationMode) return;
7004
8948
  if (mode === "talking") {
7005
8949
  await indicatorLoop?.stop();
7006
- await surface?.setLayerVisible("advanceIndicator", false);
7007
- await surface?.setLayerVisible("portraitTalk", talkLoop !== void 0);
7008
- await talkLoop?.start({ primed: true });
7009
- } else if (mode === "awaiting-advance") {
7010
- await talkLoop?.stop({ reset: true });
7011
- await surface?.setLayerVisible("portraitTalk", false);
7012
- await surface?.setLayerVisible("advanceIndicator", indicatorLoop !== void 0);
8950
+ await surface?.setLayerVisible("continueIndicator", false);
8951
+ await surface?.setLayerVisible("portraitLipSync", lipSyncLoop !== void 0);
8952
+ await lipSyncLoop?.start({ primed: true });
8953
+ } else if (mode === "awaiting-continue") {
8954
+ await lipSyncLoop?.stop({ reset: true });
8955
+ await surface?.setLayerVisible("portraitLipSync", false);
8956
+ await surface?.setLayerVisible("continueIndicator", indicatorLoop !== void 0);
7013
8957
  await indicatorLoop?.start({ primed: true });
7014
8958
  } else {
7015
- await Promise.all([talkLoop?.stop({ reset: true }), indicatorLoop?.stop()]);
7016
- await Promise.all([surface?.setLayerVisible("portraitTalk", false), surface?.setLayerVisible("advanceIndicator", false)]);
8959
+ await Promise.all([lipSyncLoop?.stop({ reset: true }), indicatorLoop?.stop()]);
8960
+ await Promise.all([surface?.setLayerVisible("portraitLipSync", false), surface?.setLayerVisible("continueIndicator", false)]);
7017
8961
  }
7018
8962
  currentAnimationMode = mode;
7019
8963
  };
7020
8964
  await Promise.all([
7021
- surface.setLayerVisible("portraitBase", style.portrait !== void 0),
7022
- surface.setLayerVisible("portraitBlink", style.portrait?.blink !== void 0),
7023
- surface.setLayerVisible("portraitTalk", false),
7024
- surface.setLayerVisible("advanceIndicator", false)
8965
+ surface.setLayerVisible("portraitBase", activeStyle.portrait !== void 0),
8966
+ surface.setLayerVisible("portraitBlink", activeStyle.portrait?.blink !== void 0),
8967
+ surface.setLayerVisible("portraitLipSync", false),
8968
+ surface.setLayerVisible("continueIndicator", false)
7025
8969
  ]);
7026
8970
  await surface.show();
7027
8971
  surfaceVisible = true;
8972
+ await playAudio(activeStyle.audio?.voice);
8973
+ if (reveal !== void 0) await playAudio(reveal.sound ?? activeStyle.audio?.reveal);
7028
8974
  await blinkLoop?.start({ primed: true });
7029
8975
  await applyAnimationMode(input.animationMode);
7030
8976
  const handle = Object.freeze({
@@ -7038,12 +8984,82 @@
7038
8984
  if (typeof text !== "string") return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble text must be a string."));
7039
8985
  transitionTail = transitionTail.then(async () => {
7040
8986
  if (!surface) return;
8987
+ stopRevealTimer();
8988
+ currentText = text;
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();
9003
+ });
9004
+ return transitionTail;
9005
+ },
9006
+ updateStyle(styleInput) {
9007
+ if (closed) return Promise.reject(new BubbleCompositionError("BUBBLE-COMPOSITION-005", `Bubble is already closed: ${input.actorKey}`));
9008
+ let nextStyle;
9009
+ try {
9010
+ nextStyle = normalizeStyle(styleInput);
9011
+ } catch (error) {
9012
+ return Promise.reject(error);
9013
+ }
9014
+ transitionTail = transitionTail.then(async () => {
9015
+ if (!surface) return;
9016
+ validateSurface(surface, nextStyle);
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);
9024
+ await Promise.all([
9025
+ blinkLoop?.stop(),
9026
+ lipSyncLoop?.stop(),
9027
+ indicatorLoop?.stop()
9028
+ ]);
9029
+ await primeStyleImages(nextStyle, nextImageResolver, surface);
9030
+ await surface.updateStyle(nextStyle);
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
+ }
7041
9044
  svgText.setText({
7042
- styleName: style.textStyle,
9045
+ styleName: nextStyle.textStyle,
7043
9046
  target: surface.targets.text,
7044
- text
9047
+ text: formatBubbleText(currentText, nextStyle, svgText)
7045
9048
  });
7046
- await surface.show();
9049
+ createStyleLoops(nextStyle, nextImageResolver, surface);
9050
+ await Promise.all([
9051
+ surface.setLayerVisible("portraitBase", nextStyle.portrait !== void 0),
9052
+ surface.setLayerVisible("portraitBlink", nextStyle.portrait?.blink !== void 0),
9053
+ surface.setLayerVisible("portraitLipSync", false),
9054
+ surface.setLayerVisible("continueIndicator", false)
9055
+ ]);
9056
+ const previousMode = currentAnimationMode;
9057
+ currentAnimationMode = "idle";
9058
+ await blinkLoop?.start({ primed: true });
9059
+ await applyAnimationMode(previousMode);
9060
+ await renderVisibleText();
9061
+ scheduleReveal();
9062
+ await playAudio(activeStyle.audio?.voice);
7047
9063
  });
7048
9064
  return transitionTail;
7049
9065
  },
@@ -7053,18 +9069,133 @@
7053
9069
  transitionTail = transitionTail.then(() => applyAnimationMode(mode));
7054
9070
  return transitionTail;
7055
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
+ },
7056
9185
  async close() {
7057
9186
  if (closed) return;
7058
9187
  closed = true;
7059
9188
  const errors = [];
9189
+ stopRevealTimer();
7060
9190
  try {
7061
9191
  await transitionTail;
7062
9192
  } catch (error) {
7063
9193
  errors.push(error);
7064
9194
  }
7065
9195
  for (const operation of [
9196
+ () => activeStyle.hideAnimation === void 0 ? void 0 : surface?.animate?.(activeStyle.hideAnimation),
7066
9197
  () => blinkLoop?.stop(),
7067
- () => talkLoop?.stop(),
9198
+ () => lipSyncLoop?.stop(),
7068
9199
  () => indicatorLoop?.stop(),
7069
9200
  async () => {
7070
9201
  if (surfaceVisible) await surface?.hide();
@@ -7083,12 +9214,15 @@
7083
9214
  }
7084
9215
  });
7085
9216
  active.set(input.actorKey, handle);
9217
+ scheduleReveal();
9218
+ if (activeStyle.showAnimation !== void 0) await handle.animate(activeStyle.showAnimation);
7086
9219
  return handle;
7087
9220
  } catch (error) {
9221
+ active.delete(input.actorKey);
7088
9222
  const cleanupErrors = [];
7089
9223
  const loopResults = await Promise.allSettled([
7090
9224
  blinkLoop?.stop(),
7091
- talkLoop?.stop(),
9225
+ lipSyncLoop?.stop(),
7092
9226
  indicatorLoop?.stop()
7093
9227
  ]);
7094
9228
  cleanupErrors.push(...loopResults.flatMap((result) => result.status === "rejected" ? [result.reason] : []));
@@ -7184,7 +9318,7 @@
7184
9318
  return value;
7185
9319
  }
7186
9320
  function requireAssetManager(value) {
7187
- if (!isRecord(value) || typeof value.isLoaded !== "function" || typeof value.getAssetMimeType !== "function" || typeof value.resolveSkin !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "Bubble requires Asset Manager. Load @kubohiroya/turbowarp-asset-manager before using Bubble blocks.");
9321
+ if (!isRecord(value) || typeof value.isLoaded !== "function" || typeof value.getAssetMimeType !== "function" || typeof value.resolveSkin !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "Bubble image assets require an imageResolver capability. Load @kubohiroya/turbowarp-asset-manager or provide options.imageResolver before using image features.");
7188
9322
  return value;
7189
9323
  }
7190
9324
  function requireSvgText(value) {
@@ -7221,6 +9355,52 @@
7221
9355
  height
7222
9356
  };
7223
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
+ }
7224
9404
  function fitDrawable(renderer, target, boxSize, scaleMultiplier = 1) {
7225
9405
  const native = readSize(renderer, target, {
7226
9406
  width: boxSize,
@@ -7246,7 +9426,7 @@
7246
9426
  const vector = bubbleDirectionVector(direction);
7247
9427
  return (Math.atan2(-vector.x, -vector.y) * 180 / Math.PI % 360 + 360) % 360;
7248
9428
  }
7249
- function createSurface(runtime, actor, actorKey, style) {
9429
+ function createSurface(runtime, actor, actorKey, style, scheduler) {
7250
9430
  const renderer = runtime.renderer;
7251
9431
  const sequence = surfaceSequence;
7252
9432
  surfaceSequence += 1;
@@ -7269,36 +9449,54 @@
7269
9449
  const body = createTarget("body");
7270
9450
  const portraitBase = style.portrait ? createTarget("portrait-base") : void 0;
7271
9451
  const portraitBlink = style.portrait?.blink ? createTarget("portrait-blink") : void 0;
7272
- const portraitTalk = style.portrait?.talk ? createTarget("portrait-talk") : void 0;
9452
+ const portraitLipSync = style.portrait?.lipSync ? createTarget("portrait-lip-sync") : void 0;
7273
9453
  const text = createTarget("text");
7274
- const advanceIndicator = style.advanceIndicator ? createTarget("advance-indicator") : void 0;
9454
+ const continueIndicator = style.continueIndicator ? createTarget("continue-indicator") : void 0;
7275
9455
  const targets = Object.freeze({
7276
9456
  text,
7277
9457
  ...portraitBase ? { portraitBase } : {},
7278
9458
  ...portraitBlink ? { portraitBlink } : {},
7279
- ...portraitTalk ? { portraitTalk } : {},
7280
- ...advanceIndicator ? { advanceIndicator } : {}
9459
+ ...portraitLipSync ? { portraitLipSync } : {},
9460
+ ...continueIndicator ? { continueIndicator } : {}
7281
9461
  });
7282
9462
  const layerTargets = /* @__PURE__ */ new Map();
7283
9463
  if (portraitBase) layerTargets.set("portraitBase", portraitBase);
7284
9464
  if (portraitBlink) layerTargets.set("portraitBlink", portraitBlink);
7285
- if (portraitTalk) layerTargets.set("portraitTalk", portraitTalk);
7286
- if (advanceIndicator) layerTargets.set("advanceIndicator", advanceIndicator);
9465
+ if (portraitLipSync) layerTargets.set("portraitLipSync", portraitLipSync);
9466
+ if (continueIndicator) layerTargets.set("continueIndicator", continueIndicator);
7287
9467
  const layerVisibility = /* @__PURE__ */ new Map();
7288
9468
  let surfaceVisible = false;
7289
9469
  let disposed = false;
7290
9470
  let cachedBodySkinSignature = "";
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
+ };
7291
9488
  const updateVisibility = () => {
7292
- const actorVisible = style.placement.basis === "background" || actor.visible !== false;
7293
- renderer.updateDrawableVisible(body.drawableID, surfaceVisible && actorVisible && style.visualStyle !== "NO_BUBBLE");
7294
- renderer.updateDrawableVisible(text.drawableID, surfaceVisible && actorVisible);
7295
- for (const [layer, target] of layerTargets) renderer.updateDrawableVisible(target.drawableID, surfaceVisible && actorVisible && (layerVisibility.get(layer) ?? false));
9489
+ const actorVisible = currentStyle.placement.basis === "background" || actor.visible !== 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();
7296
9494
  runtime.requestRedraw?.();
7297
9495
  };
7298
9496
  const position = () => {
7299
9497
  if (disposed) return;
7300
- const scaleMultiplier = style.placement.basis === "actor" ? style.offset.scalePercent / 100 : 1;
7301
- const nativeTextSize = readSize(renderer, text, {
9498
+ const scaleMultiplier = currentStyle.placement.basis === "actor" ? currentStyle.offset.scalePercent / 100 : 1;
9499
+ const nativeTextSize = reservedTextSize ?? readSize(renderer, text, {
7302
9500
  width: 180,
7303
9501
  height: 48
7304
9502
  });
@@ -7311,8 +9509,8 @@
7311
9509
  width: 0,
7312
9510
  height: 0
7313
9511
  };
7314
- for (const target of [portraitBlink, portraitTalk]) if (target) fitDrawable(renderer, target, portraitBoxSize, scaleMultiplier);
7315
- const indicatorSize = advanceIndicator ? fitDrawable(renderer, advanceIndicator, indicatorBoxSize, scaleMultiplier) : {
9512
+ for (const target of [portraitBlink, portraitLipSync]) if (target) fitDrawable(renderer, target, portraitBoxSize, scaleMultiplier);
9513
+ const indicatorSize = continueIndicator ? fitDrawable(renderer, continueIndicator, indicatorBoxSize, scaleMultiplier) : {
7316
9514
  width: 0,
7317
9515
  height: 0
7318
9516
  };
@@ -7335,31 +9533,31 @@
7335
9533
  const maximumCenterY = stageTop - bubbleHeight / 2;
7336
9534
  let centerX;
7337
9535
  let centerY;
7338
- if (style.placement.basis === "background") {
9536
+ if (currentStyle.placement.basis === "background") {
7339
9537
  centerX = 0;
7340
- if (style.placement.region === "HEADER_LIKE") centerY = stageTop - stageSafeMargin - bubbleHeight / 2;
7341
- else if (style.placement.region === "FOOTER_LIKE") centerY = stageBottom + stageSafeMargin + bubbleHeight / 2;
9538
+ if (currentStyle.placement.region === "HEADER_LIKE") centerY = stageTop - stageSafeMargin - bubbleHeight / 2;
9539
+ else if (currentStyle.placement.region === "FOOTER_LIKE") centerY = stageBottom + stageSafeMargin + bubbleHeight / 2;
7342
9540
  else centerY = 0;
7343
9541
  } else {
7344
9542
  const center = actorRelativeBubbleCenter({
7345
9543
  bounds: targetBounds(actor),
7346
9544
  bubbleWidth,
7347
9545
  bubbleHeight,
7348
- direction: style.placement.direction,
7349
- distance: style.distance,
7350
- tailLength: style.tailLength,
7351
- offset: style.offset
9546
+ direction: currentStyle.placement.direction,
9547
+ distance: currentStyle.distance,
9548
+ tailLength: currentStyle.tailLength,
9549
+ offset: currentStyle.offset
7352
9550
  });
7353
9551
  centerX = center.x;
7354
9552
  centerY = center.y;
7355
9553
  }
7356
9554
  centerX = clamp(centerX, minimumCenterX, maximumCenterX);
7357
9555
  centerY = clamp(centerY, minimumCenterY, maximumCenterY);
7358
- const tailDirection = style.placement.basis === "actor" ? tailDirectionForPlacement(style.placement.direction) : null;
7359
- const bodyOffset = style.placement.basis === "actor" ? [
7360
- style.offset.x,
7361
- style.offset.y,
7362
- style.offset.scalePercent
9556
+ const tailDirection = currentStyle.placement.basis === "actor" ? tailDirectionForPlacement(currentStyle.placement.direction) : null;
9557
+ const bodyOffset = currentStyle.placement.basis === "actor" ? [
9558
+ currentStyle.offset.x,
9559
+ currentStyle.offset.y,
9560
+ currentStyle.offset.scalePercent
7363
9561
  ] : [
7364
9562
  0,
7365
9563
  0,
@@ -7369,35 +9567,37 @@
7369
9567
  x: 0,
7370
9568
  y: 0
7371
9569
  } : bubbleBodyCenterOffset({
7372
- style: style.visualStyle,
9570
+ style: currentStyle.visualStyle,
7373
9571
  width: baseBubbleWidth,
7374
9572
  height: baseBubbleHeight,
7375
9573
  tailDirection,
7376
- tailLength: style.tailLength,
9574
+ tailLength: currentStyle.tailLength,
7377
9575
  offset: bodyOffset
7378
9576
  });
7379
- const viewportExtraX = Math.abs(bodyOffset[0]) + baseBubbleWidth * Math.abs(scaleMultiplier - 1) + Math.max(0, style.tailLength - 18) + 8;
7380
- const viewportExtraY = Math.abs(bodyOffset[1]) + baseBubbleHeight * Math.abs(scaleMultiplier - 1) + Math.max(0, style.tailLength - 18) + 8;
9577
+ const viewportExtraX = Math.abs(bodyOffset[0]) + baseBubbleWidth * Math.abs(scaleMultiplier - 1) + Math.max(0, currentStyle.tailLength - 18) + 8;
9578
+ const viewportExtraY = Math.abs(bodyOffset[1]) + baseBubbleHeight * Math.abs(scaleMultiplier - 1) + Math.max(0, currentStyle.tailLength - 18) + 8;
7381
9579
  const nextBodySkinSignature = JSON.stringify({
7382
9580
  baseBubbleHeight,
7383
9581
  baseBubbleWidth,
7384
9582
  bodyOffset,
7385
9583
  tailDirection,
7386
- tailLength: style.tailLength,
9584
+ tailLength: currentStyle.tailLength,
7387
9585
  viewportExtraX,
7388
9586
  viewportExtraY,
7389
- visualStyle: style.visualStyle
9587
+ visualStyle: currentStyle.visualStyle,
9588
+ shapeTransition
7390
9589
  });
7391
9590
  if (nextBodySkinSignature !== cachedBodySkinSignature) {
7392
9591
  const expanded = expandSvgViewport(renderBubbleSvg({
7393
- style: style.visualStyle,
9592
+ style: currentStyle.visualStyle,
7394
9593
  lines: [],
7395
9594
  width: baseBubbleWidth,
7396
9595
  height: baseBubbleHeight,
7397
9596
  tailDirection,
7398
- tailLength: style.tailLength,
9597
+ tailLength: currentStyle.tailLength,
7399
9598
  offset: bodyOffset,
7400
- title: `${style.name} Bubble body`
9599
+ title: `${currentStyle.name} Bubble body`,
9600
+ ...shapeTransition === void 0 ? {} : { shapeTransition }
7401
9601
  }), baseBubbleWidth, baseBubbleHeight, viewportExtraX, viewportExtraY);
7402
9602
  const nextSkinId = renderer.createSVGSkin(expanded);
7403
9603
  if (!Number.isInteger(nextSkinId) || nextSkinId < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "TurboWarp did not create the Bubble body SVG skin.");
@@ -7420,10 +9620,27 @@
7420
9620
  for (const target of [
7421
9621
  portraitBase,
7422
9622
  portraitBlink,
7423
- portraitTalk
9623
+ portraitLipSync
7424
9624
  ]) if (target) renderer.updateDrawablePosition(target.drawableID, [portraitX, centerY]);
7425
9625
  renderer.updateDrawablePosition(text.drawableID, [textX, centerY]);
7426
- if (advanceIndicator) renderer.updateDrawablePosition(advanceIndicator.drawableID, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
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();
7427
9644
  updateVisibility();
7428
9645
  };
7429
9646
  const originalVisualChange = actor.onTargetVisualChange;
@@ -7431,7 +9648,7 @@
7431
9648
  originalVisualChange?.(changedTarget);
7432
9649
  position();
7433
9650
  };
7434
- if (style.placement.basis === "actor") actor.onTargetVisualChange = visualChangeHook;
9651
+ if (currentStyle.placement.basis === "actor") actor.onTargetVisualChange = visualChangeHook;
7435
9652
  return Object.freeze({
7436
9653
  targets,
7437
9654
  setLayerVisible(layer, visible) {
@@ -7439,6 +9656,142 @@
7439
9656
  layerVisibility.set(layer, visible);
7440
9657
  updateVisibility();
7441
9658
  },
9659
+ updateStyle(nextStyle) {
9660
+ if (disposed) return;
9661
+ const wasActorRelative = currentStyle.placement.basis === "actor";
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;
9668
+ const isActorRelative = currentStyle.placement.basis === "actor";
9669
+ if (wasActorRelative && !isActorRelative) {
9670
+ if (actor.onTargetVisualChange === visualChangeHook) actor.onTargetVisualChange = originalVisualChange ?? null;
9671
+ } else if (!wasActorRelative && isActorRelative) actor.onTargetVisualChange = visualChangeHook;
9672
+ position();
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
+ },
7442
9795
  show() {
7443
9796
  if (disposed) return;
7444
9797
  surfaceVisible = true;
@@ -7452,7 +9805,7 @@
7452
9805
  dispose() {
7453
9806
  if (disposed) return;
7454
9807
  disposed = true;
7455
- if (style.placement.basis === "actor" && actor.onTargetVisualChange === visualChangeHook) actor.onTargetVisualChange = originalVisualChange ?? null;
9808
+ if (currentStyle.placement.basis === "actor" && actor.onTargetVisualChange === visualChangeHook) actor.onTargetVisualChange = originalVisualChange ?? null;
7456
9809
  for (const target of [...drawables].reverse()) renderer.destroyDrawable(target.drawableID, spriteLayer);
7457
9810
  if (bodySkinId !== void 0) {
7458
9811
  renderer.destroySkin(bodySkinId);
@@ -7471,25 +9824,39 @@
7471
9824
  if (!isRecord(runtimeInput)) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "Bubble requires the TurboWarp runtime.");
7472
9825
  const runtime = runtimeInput;
7473
9826
  const renderer = requireRenderer(runtime.renderer);
7474
- const assetExtension = options.assetManager ? null : requireAssetManager(runtime.ext_kubohiroyaassetmanager);
9827
+ const getAssetExtension = () => requireAssetManager(runtime.ext_kubohiroyaassetmanager);
7475
9828
  const svgTextExtension = options.svgText ? null : requireSvgText(runtime.ext_kubohiroyasvgtext);
7476
9829
  return createBubbleComposition({
7477
- assetManager: options.assetManager ?? {
9830
+ imageResolver: options.imageResolver ?? {
7478
9831
  isRegistered(name) {
7479
- return assetExtension?.isLoaded({ NAME: name }) ?? false;
9832
+ return getAssetExtension().isLoaded({ NAME: name });
7480
9833
  },
7481
9834
  getMimeType(name) {
7482
- return assetExtension?.getAssetMimeType({ NAME: name }) ?? "";
9835
+ return getAssetExtension().getAssetMimeType({ NAME: name });
7483
9836
  },
7484
9837
  async applyToTarget(name, target) {
7485
9838
  const drawableID = target.drawableID;
7486
9839
  if (!Number.isInteger(drawableID) || drawableID < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "Bubble image target drawable is invalid.");
7487
- const skin = await assetExtension?.resolveSkin(name);
9840
+ const skin = await getAssetExtension().resolveSkin(name);
7488
9841
  if (!isRecord(skin) || !Number.isInteger(skin.skinId) || skin.skinId < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", `Asset Manager did not resolve an image skin: ${String(name)}`);
7489
9842
  renderer.updateDrawableSkinId(drawableID, skin.skinId);
7490
9843
  runtime.requestRedraw?.();
7491
9844
  }
7492
9845
  },
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
+ },
7493
9860
  svgText: options.svgText ?? {
7494
9861
  setText({ styleName, target, text }) {
7495
9862
  svgTextExtension?.setText({
@@ -7499,11 +9866,19 @@
7499
9866
  },
7500
9867
  releaseTarget(target) {
7501
9868
  svgTextExtension?.releaseTextActor(target);
9869
+ },
9870
+ measureText({ styleName, text }) {
9871
+ const measureText = svgTextExtension?.measureText;
9872
+ if (typeof measureText !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-003", "SVG Text does not provide text measurement.");
9873
+ return measureText.call(svgTextExtension, styleName, text);
7502
9874
  }
7503
9875
  },
7504
9876
  createSurface({ actor, actorKey, style }) {
7505
9877
  if (!isRecord(actor) || typeof actor.id !== "string") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "Bubble actor target is invalid.");
7506
- 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
+ });
7507
9882
  },
7508
9883
  ...options.scheduler === void 0 ? {} : { scheduler: options.scheduler },
7509
9884
  ...options.onAnimationError === void 0 ? {} : { onAnimationError: options.onAnimationError }
@@ -7516,10 +9891,41 @@
7516
9891
  var validAnimationModes = /* @__PURE__ */ new Set([
7517
9892
  "idle",
7518
9893
  "talking",
7519
- "awaiting-advance"
9894
+ "awaiting-continue"
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"
7520
9926
  ]);
7521
9927
  var EXTENSION_DOCS_URI = "https://kubohiroya.github.io/turbowarp-bubble/";
7522
- var EXTENSION_VERSION = "0.1.0";
9928
+ var EXTENSION_VERSION = "0.3.0";
7523
9929
  function extensionError(message) {
7524
9930
  const error = /* @__PURE__ */ new Error(`[Bubble] ${message}`);
7525
9931
  Object.defineProperty(error, "code", { value: "BUBBLE-EXTENSION-001" });
@@ -7648,21 +10054,161 @@
7648
10054
  setBlinkFrames(args) {
7649
10055
  this.setPortraitAnimation("blink", args);
7650
10056
  }
7651
- setTalkFrames(args) {
7652
- this.setPortraitAnimation("talk", args);
10057
+ setLipSyncFrames(args) {
10058
+ this.setPortraitAnimation("lipSync", args);
7653
10059
  }
7654
- setAdvanceFrames(args) {
10060
+ setContinueFrames(args) {
7655
10061
  const style = this.requireStyle(args.STYLE);
7656
10062
  const frames = this.parseFrames(args.ASSETS);
7657
- if (frames.length === 1) throw extensionError("advance frames must contain at least two assets.");
7658
- const advanceIndicator = frames.length === 0 ? void 0 : this.animationInput(frames, args.SECONDS, "advance");
7659
- const { advanceIndicator: previousAdvance, ...withoutAdvance } = style;
10063
+ if (frames.length === 1) throw extensionError("continue frames must contain at least two assets.");
10064
+ const continueIndicator = frames.length === 0 ? void 0 : this.animationInput(frames, args.SECONDS, "continue");
10065
+ const { continueIndicator: previousContinue, ...withoutContinue } = style;
7660
10066
  const nextStyle = Object.freeze({
7661
- ...withoutAdvance,
7662
- ...advanceIndicator ? { advanceIndicator } : {}
10067
+ ...withoutContinue,
10068
+ ...continueIndicator ? { continueIndicator } : {}
7663
10069
  });
7664
10070
  this.installStyle(nextStyle);
7665
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
+ }
7666
10212
  sayWithBubbleStyle(args, util) {
7667
10213
  return this.show("say", args, util);
7668
10214
  }
@@ -7672,12 +10218,12 @@
7672
10218
  async setBubbleAnimationMode(args, util) {
7673
10219
  const target = this.requireTarget(util);
7674
10220
  const mode = this.toString(args.MODE).trim().toLowerCase();
7675
- if (!validAnimationModes.has(mode)) throw extensionError("animation mode must be talking, awaiting-advance, or idle.");
10221
+ if (!validAnimationModes.has(mode)) throw extensionError("animation mode must be talking, awaiting-continue, or idle.");
7676
10222
  const handle = this.handles.get(target.id);
7677
10223
  if (!handle) throw extensionError("this target does not have an active bubble.");
7678
10224
  await handle.setAnimationMode(mode);
7679
10225
  }
7680
- async waitForBubbleAdvance(args, util) {
10226
+ async waitForBubbleContinue(args, util) {
7681
10227
  const target = this.requireTarget(util);
7682
10228
  const handle = this.handles.get(target.id);
7683
10229
  if (!handle) throw extensionError("this target does not have an active bubble.");
@@ -7690,7 +10236,7 @@
7690
10236
  if (!this.isRecord(runtimeExpression) || typeof runtimeExpression.runtimeCondition !== "function") throw extensionError("Bubble wait requires Runtime Expression. Load @kubohiroya/turbowarp-runtime-expression before using this block.");
7691
10237
  if (typeof this.runtime.on !== "function" || typeof this.runtime.off !== "function") throw extensionError("TurboWarp runtime events are unavailable.");
7692
10238
  this.cancelWait(target.id, "Bubble wait was replaced.");
7693
- await handle.setAnimationMode("awaiting-advance");
10239
+ await handle.setAnimationMode("awaiting-continue");
7694
10240
  await new Promise((resolve, reject) => {
7695
10241
  let settled = false;
7696
10242
  let timeoutHandle;
@@ -7723,6 +10269,22 @@
7723
10269
  checkCondition();
7724
10270
  });
7725
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
+ }
7726
10288
  async closeBubble(_args, util) {
7727
10289
  const target = this.requireTarget(util);
7728
10290
  await this.releaseOwnedTarget(target.id);
@@ -7810,6 +10372,16 @@
7810
10372
  frameIntervalSeconds: seconds
7811
10373
  });
7812
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
+ }
7813
10385
  setPortraitAnimation(field, args) {
7814
10386
  const style = this.requireStyle(args.STYLE);
7815
10387
  const portrait = style.portrait;
@@ -7820,10 +10392,10 @@
7820
10392
  base: portrait.base,
7821
10393
  ...field === "blink" ? {
7822
10394
  ...animation ? { blink: animation } : {},
7823
- ...portrait.talk ? { talk: portrait.talk } : {}
10395
+ ...portrait.lipSync ? { lipSync: portrait.lipSync } : {}
7824
10396
  } : {
7825
10397
  ...portrait.blink ? { blink: portrait.blink } : {},
7826
- ...animation ? { talk: animation } : {}
10398
+ ...animation ? { lipSync: animation } : {}
7827
10399
  }
7828
10400
  });
7829
10401
  this.installStyle(Object.freeze({
@@ -7839,6 +10411,12 @@
7839
10411
  if (!this.isTarget(target)) throw extensionError("target is unavailable.");
7840
10412
  return target;
7841
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
+ }
7842
10420
  placementInput(placement) {
7843
10421
  return placement.basis === "actor" ? placement.direction : placement.region;
7844
10422
  }