@kubohiroya/turbowarp-bubble 0.5.0 → 0.7.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.
@@ -92,6 +92,39 @@
92
92
  }
93
93
  }
94
94
  },
95
+ {
96
+ "opcode": "setPortraitLayout",
97
+ "blockType": "COMMAND",
98
+ "text": "set portrait [PLACEMENT] offset x [X] y [Y] zoom [ZOOM] % corner radius [RADIUS] px for bubble style [STYLE]",
99
+ "description": "Places the portrait at a bubble edge or corner with a local offset, zoom, and rounded corners. NONE removes the portrait.",
100
+ "arguments": {
101
+ "PLACEMENT": {
102
+ "type": "STRING",
103
+ "defaultValue": "left",
104
+ "menu": "portraitPlacement"
105
+ },
106
+ "X": {
107
+ "type": "NUMBER",
108
+ "defaultValue": 0
109
+ },
110
+ "Y": {
111
+ "type": "NUMBER",
112
+ "defaultValue": 0
113
+ },
114
+ "ZOOM": {
115
+ "type": "NUMBER",
116
+ "defaultValue": 100
117
+ },
118
+ "RADIUS": {
119
+ "type": "NUMBER",
120
+ "defaultValue": 0
121
+ },
122
+ "STYLE": {
123
+ "type": "STRING",
124
+ "defaultValue": "dialogue"
125
+ }
126
+ }
127
+ },
95
128
  {
96
129
  "opcode": "setBubbleDistance",
97
130
  "blockType": "COMMAND",
@@ -516,6 +549,18 @@
516
549
  }
517
550
  ],
518
551
  menus: {
552
+ "portraitPlacement": {
553
+ "acceptReporters": true,
554
+ "items": [
555
+ "none",
556
+ "left",
557
+ "right",
558
+ "top-left",
559
+ "top-right",
560
+ "bottom-left",
561
+ "bottom-right"
562
+ ]
563
+ },
519
564
  "visualStyle": {
520
565
  "acceptReporters": true,
521
566
  "items": [
@@ -8397,6 +8442,45 @@
8397
8442
  return chunks.slice(0, Math.max(0, Math.min(count, chunks.length))).join("");
8398
8443
  }
8399
8444
  //#endregion
8445
+ //#region src/portrait-layout.ts
8446
+ var bubblePortraitPlacements = Object.freeze([
8447
+ "left",
8448
+ "right",
8449
+ "top-left",
8450
+ "top-right",
8451
+ "bottom-left",
8452
+ "bottom-right"
8453
+ ]);
8454
+ var defaultBubblePortraitOffset = Object.freeze({
8455
+ x: 0,
8456
+ y: 0,
8457
+ zoomPercent: 100
8458
+ });
8459
+ function normalizeBubblePortraitPlacement(value) {
8460
+ if (typeof value !== "string") throw new TypeError("Bubble portrait placement must be a string.");
8461
+ const normalized = value.trim().toLowerCase().replaceAll("_", "-");
8462
+ if (!bubblePortraitPlacements.includes(normalized)) throw new TypeError(`Unsupported Bubble portrait placement: ${value}`);
8463
+ return normalized;
8464
+ }
8465
+ function normalizeBubblePortraitOffset(value) {
8466
+ if (!Array.isArray(value) || value.length !== 2 && value.length !== 3) throw new TypeError("Bubble portrait offset must be [x, y] or [x, y, zoom].");
8467
+ const [x, y, zoomPercent = 100] = value;
8468
+ if (![
8469
+ x,
8470
+ y,
8471
+ zoomPercent
8472
+ ].every(Number.isFinite) || zoomPercent <= 0) throw new TypeError("Bubble portrait offset values must be finite and zoom positive.");
8473
+ return Object.freeze({
8474
+ x,
8475
+ y,
8476
+ zoomPercent
8477
+ });
8478
+ }
8479
+ function normalizeBubblePortraitCornerRadius(value) {
8480
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new TypeError("Bubble portrait corner radius must be zero or greater.");
8481
+ return value;
8482
+ }
8483
+ //#endregion
8400
8484
  //#region src/composition.ts
8401
8485
  var BubbleCompositionError = class extends Error {
8402
8486
  constructor(code, message) {
@@ -8462,13 +8546,32 @@
8462
8546
  }
8463
8547
  function normalizePortrait(value) {
8464
8548
  if (!isRecord$2(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble portrait must be an object.");
8465
- requireExactKeys(value, ["base"], ["blink", "lipSync"], "Bubble portrait");
8549
+ requireExactKeys(value, ["base"], [
8550
+ "blink",
8551
+ "lipSync",
8552
+ "placement",
8553
+ "offset",
8554
+ "cornerRadius"
8555
+ ], "Bubble portrait");
8466
8556
  const blink = value.blink === void 0 ? void 0 : normalizeAnimation(value.blink, "Bubble portrait blink", 1);
8467
8557
  const lipSync = value.lipSync === void 0 ? void 0 : normalizeAnimation(value.lipSync, "Bubble portrait lip-sync", 1);
8558
+ let placement;
8559
+ let offset;
8560
+ let cornerRadius;
8561
+ try {
8562
+ placement = normalizeBubblePortraitPlacement(value.placement ?? "left");
8563
+ offset = value.offset === void 0 ? defaultBubblePortraitOffset : normalizeBubblePortraitOffset(value.offset);
8564
+ cornerRadius = normalizeBubblePortraitCornerRadius(value.cornerRadius ?? 0);
8565
+ } catch (error) {
8566
+ throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", error instanceof Error ? error.message : "Bubble portrait layout is invalid.");
8567
+ }
8468
8568
  return Object.freeze({
8469
8569
  base: requireAssetName(value.base, "Bubble portrait base"),
8470
8570
  ...blink === void 0 ? {} : { blink },
8471
- ...lipSync === void 0 ? {} : { lipSync }
8571
+ ...lipSync === void 0 ? {} : { lipSync },
8572
+ placement,
8573
+ offset,
8574
+ cornerRadius
8472
8575
  });
8473
8576
  }
8474
8577
  function normalizeMotion(value, label) {
@@ -9441,9 +9544,18 @@
9441
9544
  renderer.updateDrawableScale(target.drawableID, [effectiveScale * 100, effectiveScale * 100]);
9442
9545
  return {
9443
9546
  width: native.width * effectiveScale,
9444
- height: native.height * effectiveScale
9547
+ height: native.height * effectiveScale,
9548
+ scalePercent: effectiveScale * 100
9445
9549
  };
9446
9550
  }
9551
+ function renderPortraitCornerMaskSvg(width, height, radius) {
9552
+ const roundedRadius = Math.min(radius, width / 2, height / 2);
9553
+ const right = width - roundedRadius;
9554
+ const bottom = height - roundedRadius;
9555
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
9556
+ <path d="M0 0H${width}V${height}H0Z M${roundedRadius} 0H${right}A${roundedRadius} ${roundedRadius} 0 0 1 ${width} ${roundedRadius}V${bottom}A${roundedRadius} ${roundedRadius} 0 0 1 ${right} ${height}H${roundedRadius}A${roundedRadius} ${roundedRadius} 0 0 1 0 ${bottom}V${roundedRadius}A${roundedRadius} ${roundedRadius} 0 0 1 ${roundedRadius} 0Z" fill="#fff4cc" fill-rule="evenodd" data-bubble-portrait-corner-radius="${roundedRadius}"/>
9557
+ </svg>`;
9558
+ }
9447
9559
  function clamp(value, minimum, maximum) {
9448
9560
  if (maximum < minimum) return (minimum + maximum) / 2;
9449
9561
  return Math.min(maximum, Math.max(minimum, value));
@@ -9463,6 +9575,7 @@
9463
9575
  surfaceSequence += 1;
9464
9576
  const drawables = [];
9465
9577
  let bodySkinId;
9578
+ let portraitMaskSkinId;
9466
9579
  const createTarget = (layer) => {
9467
9580
  const drawableID = renderer.createDrawable(spriteLayer);
9468
9581
  if (!Number.isInteger(drawableID) || drawableID < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", `TurboWarp did not create the Bubble ${layer} drawable.`);
@@ -9481,6 +9594,7 @@
9481
9594
  const portraitBase = style.portrait ? createTarget("portrait-base") : void 0;
9482
9595
  const portraitBlink = style.portrait?.blink ? createTarget("portrait-blink") : void 0;
9483
9596
  const portraitLipSync = style.portrait?.lipSync ? createTarget("portrait-lip-sync") : void 0;
9597
+ const portraitMask = style.portrait ? createTarget("portrait-corner-mask") : void 0;
9484
9598
  const text = createTarget("text");
9485
9599
  const continueIndicator = style.continueIndicator ? createTarget("continue-indicator") : void 0;
9486
9600
  const targets = Object.freeze({
@@ -9499,6 +9613,7 @@
9499
9613
  let surfaceVisible = false;
9500
9614
  let disposed = false;
9501
9615
  let cachedBodySkinSignature = "";
9616
+ let cachedPortraitMaskSignature = "";
9502
9617
  let currentStyle = style;
9503
9618
  let reservedTextSize;
9504
9619
  const layoutPositions = /* @__PURE__ */ new Map();
@@ -9521,6 +9636,7 @@
9521
9636
  renderer.updateDrawableVisible(body.drawableID, surfaceVisible && actorVisible && currentStyle.visualStyle !== "NO_BUBBLE" && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9522
9637
  renderer.updateDrawableVisible(text.drawableID, surfaceVisible && actorVisible && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9523
9638
  for (const [layer, target] of layerTargets) renderer.updateDrawableVisible(target.drawableID, surfaceVisible && actorVisible && (layerVisibility.get(layer) ?? false) && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9639
+ if (portraitMask) renderer.updateDrawableVisible(portraitMask.drawableID, surfaceVisible && actorVisible && currentStyle.portrait !== void 0 && currentStyle.portrait.cornerRadius > 0 && currentStyle.visualStyle !== "NO_BUBBLE" && (layerVisibility.get("portraitBase") ?? false) && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
9524
9640
  applyMotionTransforms();
9525
9641
  runtime.requestRedraw?.();
9526
9642
  };
@@ -9536,16 +9652,25 @@
9536
9652
  width: nativeTextSize.width * scaleMultiplier,
9537
9653
  height: nativeTextSize.height * scaleMultiplier
9538
9654
  };
9539
- const portraitSize = portraitBase ? fitDrawable(renderer, portraitBase, portraitBoxSize, scaleMultiplier) : {
9655
+ const portraitFitBoxSize = portraitBoxSize * ((currentStyle.portrait?.offset.zoomPercent ?? 100) / 100);
9656
+ const hasPortrait = portraitBase !== void 0 && currentStyle.portrait !== void 0;
9657
+ const portraitSize = hasPortrait ? fitDrawable(renderer, portraitBase, portraitFitBoxSize, scaleMultiplier) : {
9540
9658
  width: 0,
9541
- height: 0
9659
+ height: 0,
9660
+ scalePercent: 0
9542
9661
  };
9543
- for (const target of [portraitBlink, portraitLipSync]) if (target) fitDrawable(renderer, target, portraitBoxSize, scaleMultiplier);
9662
+ const portraitLayerScales = /* @__PURE__ */ new Map();
9663
+ if (hasPortrait) portraitLayerScales.set(portraitBase.drawableID, portraitSize.scalePercent);
9664
+ for (const target of [portraitBlink, portraitLipSync]) if (target && hasPortrait) {
9665
+ const fitted = fitDrawable(renderer, target, portraitFitBoxSize, scaleMultiplier);
9666
+ portraitLayerScales.set(target.drawableID, fitted.scalePercent);
9667
+ }
9544
9668
  const indicatorSize = continueIndicator ? fitDrawable(renderer, continueIndicator, indicatorBoxSize, scaleMultiplier) : {
9545
9669
  width: 0,
9546
- height: 0
9670
+ height: 0,
9671
+ scalePercent: 0
9547
9672
  };
9548
- const totalWidth = portraitSize.width + (portraitBase ? contentGap * scaleMultiplier : 0) + textSize.width;
9673
+ const totalWidth = portraitSize.width + (hasPortrait ? contentGap * scaleMultiplier : 0) + textSize.width;
9549
9674
  const contentHeight = Math.max(portraitSize.height, textSize.height);
9550
9675
  const baseBubbleWidth = totalWidth / scaleMultiplier + 48;
9551
9676
  const baseBubbleHeight = contentHeight / scaleMultiplier + 48;
@@ -9646,13 +9771,49 @@
9646
9771
  renderer.updateDrawableScale(body.drawableID, [100, 100]);
9647
9772
  renderer.updateDrawablePosition(body.drawableID, [centerX - bodyCenterOffset.x, centerY + bodyCenterOffset.y]);
9648
9773
  const left = centerX - totalWidth / 2;
9649
- const portraitX = left + portraitSize.width / 2;
9650
- const textX = left + portraitSize.width + (portraitBase ? contentGap * scaleMultiplier : 0) + textSize.width / 2;
9774
+ const portraitPlacement = currentStyle.portrait?.placement ?? "left";
9775
+ const portraitOnRight = portraitPlacement.endsWith("right");
9776
+ const portraitOffsetX = (currentStyle.portrait?.offset.x ?? 0) * scaleMultiplier;
9777
+ const portraitOffsetY = (currentStyle.portrait?.offset.y ?? 0) * scaleMultiplier;
9778
+ const portraitX = (portraitOnRight ? left + textSize.width + contentGap * scaleMultiplier : left) + portraitSize.width / 2 + portraitOffsetX;
9779
+ let portraitY = centerY;
9780
+ if (portraitPlacement.startsWith("top-")) portraitY = centerY + contentHeight / 2 - portraitSize.height / 2;
9781
+ else if (portraitPlacement.startsWith("bottom-")) portraitY = centerY - contentHeight / 2 + portraitSize.height / 2;
9782
+ portraitY += portraitOffsetY;
9783
+ const textX = (portraitOnRight || !hasPortrait ? left : left + portraitSize.width + contentGap * scaleMultiplier) + textSize.width / 2;
9651
9784
  for (const target of [
9652
9785
  portraitBase,
9653
9786
  portraitBlink,
9654
9787
  portraitLipSync
9655
- ]) if (target) renderer.updateDrawablePosition(target.drawableID, [portraitX, centerY]);
9788
+ ]) if (target) renderer.updateDrawablePosition(target.drawableID, [portraitX, portraitY]);
9789
+ if (portraitMask) {
9790
+ const maskWidth = portraitSize.width / scaleMultiplier;
9791
+ const maskHeight = portraitSize.height / scaleMultiplier;
9792
+ const radius = Math.min(currentStyle.portrait?.cornerRadius ?? 0, maskWidth / 2, maskHeight / 2);
9793
+ const nextPortraitMaskSignature = radius > 0 ? JSON.stringify({
9794
+ maskHeight,
9795
+ maskWidth,
9796
+ radius
9797
+ }) : "";
9798
+ if (nextPortraitMaskSignature !== cachedPortraitMaskSignature) {
9799
+ const previousPortraitMaskSkinId = portraitMaskSkinId;
9800
+ portraitMaskSkinId = void 0;
9801
+ cachedPortraitMaskSignature = nextPortraitMaskSignature;
9802
+ if (radius > 0) {
9803
+ const nextSkinId = renderer.createSVGSkin(renderPortraitCornerMaskSvg(maskWidth, maskHeight, radius));
9804
+ if (!Number.isInteger(nextSkinId) || nextSkinId < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "TurboWarp did not create the Bubble portrait corner mask SVG skin.");
9805
+ try {
9806
+ renderer.updateDrawableSkinId(portraitMask.drawableID, nextSkinId);
9807
+ portraitMaskSkinId = nextSkinId;
9808
+ } catch (error) {
9809
+ renderer.destroySkin(nextSkinId);
9810
+ throw error;
9811
+ }
9812
+ }
9813
+ if (previousPortraitMaskSkinId !== void 0) renderer.destroySkin(previousPortraitMaskSkinId);
9814
+ }
9815
+ renderer.updateDrawablePosition(portraitMask.drawableID, [portraitX, portraitY]);
9816
+ }
9656
9817
  renderer.updateDrawablePosition(text.drawableID, [textX, centerY]);
9657
9818
  if (continueIndicator) renderer.updateDrawablePosition(continueIndicator.drawableID, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
9658
9819
  const remember = (target, positionValue) => {
@@ -9661,15 +9822,23 @@
9661
9822
  };
9662
9823
  remember(body, [centerX - bodyCenterOffset.x, centerY + bodyCenterOffset.y]);
9663
9824
  remember(text, [textX, centerY]);
9664
- remember(portraitBase, [portraitX, centerY]);
9665
- remember(portraitBlink, [portraitX, centerY]);
9666
- remember(portraitLipSync, [portraitX, centerY]);
9825
+ remember(portraitBase, [portraitX, portraitY]);
9826
+ remember(portraitBlink, [portraitX, portraitY]);
9827
+ remember(portraitLipSync, [portraitX, portraitY]);
9828
+ remember(portraitMask, [portraitX, portraitY]);
9667
9829
  layoutScales.set(body.drawableID, [100, 100]);
9668
9830
  layoutScales.set(text.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9669
- if (portraitBase) layoutScales.set(portraitBase.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9670
- if (portraitBlink) layoutScales.set(portraitBlink.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9671
- if (portraitLipSync) layoutScales.set(portraitLipSync.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9672
- if (continueIndicator) layoutScales.set(continueIndicator.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9831
+ for (const target of [
9832
+ portraitBase,
9833
+ portraitBlink,
9834
+ portraitLipSync
9835
+ ]) {
9836
+ if (!target) continue;
9837
+ const portraitScale = portraitLayerScales.get(target.drawableID) ?? 0;
9838
+ layoutScales.set(target.drawableID, [portraitScale, portraitScale]);
9839
+ }
9840
+ if (portraitMask) layoutScales.set(portraitMask.drawableID, [scaleMultiplier * 100, scaleMultiplier * 100]);
9841
+ if (continueIndicator) layoutScales.set(continueIndicator.drawableID, [indicatorSize.scalePercent, indicatorSize.scalePercent]);
9673
9842
  if (continueIndicator) remember(continueIndicator, [textX + textSize.width / 2 - indicatorSize.width / 2 - contentGap * scaleMultiplier, centerY - textSize.height / 2 + indicatorSize.height / 2 + contentGap * scaleMultiplier]);
9674
9843
  applyMotionTransforms();
9675
9844
  updateVisibility();
@@ -9842,12 +10011,17 @@
9842
10011
  renderer.destroySkin(bodySkinId);
9843
10012
  bodySkinId = void 0;
9844
10013
  }
10014
+ if (portraitMaskSkinId !== void 0) {
10015
+ renderer.destroySkin(portraitMaskSkinId);
10016
+ portraitMaskSkinId = void 0;
10017
+ }
9845
10018
  runtime.requestRedraw?.();
9846
10019
  }
9847
10020
  });
9848
10021
  } catch (error) {
9849
10022
  for (const target of [...drawables].reverse()) renderer.destroyDrawable(target.drawableID, spriteLayer);
9850
10023
  if (bodySkinId !== void 0) renderer.destroySkin(bodySkinId);
10024
+ if (portraitMaskSkinId !== void 0) renderer.destroySkin(portraitMaskSkinId);
9851
10025
  throw error;
9852
10026
  }
9853
10027
  }
@@ -9947,7 +10121,7 @@
9947
10121
  "easeInOut"
9948
10122
  ]);
9949
10123
  var EXTENSION_DOCS_URI = "https://kubohiroya.github.io/turbowarp-bubble/";
9950
- var EXTENSION_VERSION = "0.5.0";
10124
+ var EXTENSION_VERSION = "0.7.0";
9951
10125
  var BLOCK_ICON_URI = `data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\"><path fill=\"none\" stroke=\"#fff\" stroke-width=\"5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M12 13h40a5 5 0 0 1 5 5v23a5 5 0 0 1-5 5H30L17 55v-9h-5a5 5 0 0 1-5-5V18a5 5 0 0 1 5-5Z\"/><g fill=\"#fff\"><circle cx=\"23\" cy=\"30\" r=\"3\"/><circle cx=\"32\" cy=\"30\" r=\"3\"/><circle cx=\"41\" cy=\"30\" r=\"3\"/></g></svg>")}`;
9952
10126
  function extensionError(message) {
9953
10127
  const error = /* @__PURE__ */ new Error(`[Bubble] ${message}`);
@@ -10018,6 +10192,42 @@
10018
10192
  })();
10019
10193
  this.installStyle(nextStyle);
10020
10194
  }
10195
+ setPortraitLayout(args) {
10196
+ const style = this.requireStyle(args.STYLE);
10197
+ if (this.toString(args.PLACEMENT).trim().toLowerCase() === "none") {
10198
+ const { portrait, ...withoutPortrait } = style;
10199
+ this.installStyle(Object.freeze(withoutPortrait));
10200
+ return;
10201
+ }
10202
+ if (!style.portrait?.base) throw extensionError("set the portrait base before portrait layout.");
10203
+ let placement;
10204
+ let offset;
10205
+ let cornerRadius;
10206
+ try {
10207
+ placement = normalizeBubblePortraitPlacement(args.PLACEMENT);
10208
+ offset = normalizeBubblePortraitOffset([
10209
+ Scratch.Cast.toNumber(args.X),
10210
+ Scratch.Cast.toNumber(args.Y),
10211
+ Scratch.Cast.toNumber(args.ZOOM)
10212
+ ]);
10213
+ cornerRadius = normalizeBubblePortraitCornerRadius(Scratch.Cast.toNumber(args.RADIUS));
10214
+ } catch (error) {
10215
+ throw extensionError(error instanceof Error ? error.message : "Bubble portrait layout is invalid.");
10216
+ }
10217
+ this.installStyle(Object.freeze({
10218
+ ...style,
10219
+ portrait: Object.freeze({
10220
+ ...style.portrait,
10221
+ placement,
10222
+ offset: Object.freeze([
10223
+ offset.x,
10224
+ offset.y,
10225
+ offset.zoomPercent
10226
+ ]),
10227
+ cornerRadius
10228
+ })
10229
+ }));
10230
+ }
10021
10231
  setBubblePlacement(args) {
10022
10232
  const style = this.requireStyle(args.STYLE);
10023
10233
  let placement;
@@ -10412,13 +10622,14 @@
10412
10622
  if (!portrait?.base) throw extensionError("set the portrait base before portrait animation frames.");
10413
10623
  const frames = this.parseFrames(args.ASSETS);
10414
10624
  const animation = frames.length === 0 ? void 0 : this.animationInput(frames, args.SECONDS, field);
10625
+ const { blink, lipSync, ...portraitLayout } = portrait;
10415
10626
  const nextPortrait = Object.freeze({
10416
- base: portrait.base,
10627
+ ...portraitLayout,
10417
10628
  ...field === "blink" ? {
10418
10629
  ...animation ? { blink: animation } : {},
10419
- ...portrait.lipSync ? { lipSync: portrait.lipSync } : {}
10630
+ ...lipSync ? { lipSync } : {}
10420
10631
  } : {
10421
- ...portrait.blink ? { blink: portrait.blink } : {},
10632
+ ...blink ? { blink } : {},
10422
10633
  ...animation ? { lipSync: animation } : {}
10423
10634
  }
10424
10635
  });
@@ -3,12 +3,14 @@ import { type BubbleOffset, type BubbleOffsetInput } from "./actor-transform.js"
3
3
  import { type BubbleVisualStyle } from "./bubble-svg.js";
4
4
  import { type BubbleRevealInput, type BubbleRevealUnit, type NormalizedBubbleReveal } from "./reveal.js";
5
5
  import type { BubbleTextCapability, BubbleTextTarget } from "./text-capability.js";
6
+ import { type BubblePortraitOffset, type BubblePortraitOffsetInput, type BubblePortraitPlacement } from "./portrait-layout.js";
6
7
  export type { BubbleTextCapability, BubbleTextTarget, } from "./text-capability.js";
7
8
  export { UnicodeLineBreakProvider, wrapText, type LineBreakOpportunity, type LineBreakProvider, type TextWidthMeasurer, type WrappedTextLayout, type WrappedTextLine, type WrapTextInput, } from "./text-layout.js";
8
9
  export { bubbleBackgroundRegions, bubbleDirectionAliases, bubbleDirectionNames, defaultBubblePlacementInput, normalizeBubblePlacement, type BubbleActorPlacement, type BubbleBackgroundPlacement, type BubbleBackgroundRegion, type BubbleDirectionAlias, type BubbleDirectionName, type BubblePlacement, type BubblePlacementInput, } from "./placement.js";
9
10
  export { actorRelativeBubbleCenter, defaultBubbleDistance, defaultBubbleOffset, defaultBubbleTailLength, normalizeBubbleDistance, normalizeBubbleOffset, normalizeBubbleTailLength, type ActorBounds, type ActorRelativeCenterInput, type BubbleOffset, type BubbleOffsetInput, } from "./actor-transform.js";
10
11
  export { bubbleBodyCenterOffset, bubbleVisualStyles, renderBubbleSvg, type BubbleBodyCenterOffsetInput, type BubbleShapeTransition, type BubbleVisualStyle, type RenderBubbleSvgInput, } from "./bubble-svg.js";
11
12
  export { bubbleRevealUnits, normalizeBubbleReveal, revealedBubbleText, splitBubbleText, type BubbleRevealInput, type BubbleRevealLayout, type BubbleRevealUnit, type NormalizedBubbleReveal, } from "./reveal.js";
13
+ export { bubblePortraitPlacements, defaultBubblePortraitCornerRadius, defaultBubblePortraitOffset, defaultBubblePortraitPlacement, normalizeBubblePortraitCornerRadius, normalizeBubblePortraitOffset, normalizeBubblePortraitPlacement, type BubblePortraitOffset, type BubblePortraitOffsetInput, type BubblePortraitPlacement, } from "./portrait-layout.js";
12
14
  export type BubbleKind = "say" | "think";
13
15
  export type BubbleAnimationMode = "idle" | "talking" | "awaiting-continue";
14
16
  export type BubbleEase = "linear" | "easeIn" | "easeOut" | "easeInOut";
@@ -42,6 +44,11 @@ export interface BubblePortraitInput {
42
44
  readonly base: string;
43
45
  readonly blink?: BubbleFrameAnimationInput;
44
46
  readonly lipSync?: BubbleFrameAnimationInput;
47
+ readonly placement?: BubblePortraitPlacement;
48
+ /** Portrait-local [x, y, zoom percent]. */
49
+ readonly offset?: BubblePortraitOffsetInput;
50
+ /** Radius in pixels. */
51
+ readonly cornerRadius?: number;
45
52
  }
46
53
  export interface BubbleStyleInput {
47
54
  readonly name: string;
@@ -70,6 +77,9 @@ export interface BubblePortrait {
70
77
  readonly base: string;
71
78
  readonly blink?: BubbleFrameAnimation;
72
79
  readonly lipSync?: BubbleFrameAnimation;
80
+ readonly placement: BubblePortraitPlacement;
81
+ readonly offset: BubblePortraitOffset;
82
+ readonly cornerRadius: number;
73
83
  }
74
84
  export interface BubbleStyle {
75
85
  readonly name: string;
@@ -0,0 +1,14 @@
1
+ export declare const bubblePortraitPlacements: readonly ["left", "right", "top-left", "top-right", "bottom-left", "bottom-right"];
2
+ export type BubblePortraitPlacement = (typeof bubblePortraitPlacements)[number];
3
+ export type BubblePortraitOffsetInput = readonly [x: number, y: number] | readonly [x: number, y: number, zoomPercent: number];
4
+ export interface BubblePortraitOffset {
5
+ readonly x: number;
6
+ readonly y: number;
7
+ readonly zoomPercent: number;
8
+ }
9
+ export declare const defaultBubblePortraitPlacement: BubblePortraitPlacement;
10
+ export declare const defaultBubblePortraitOffset: BubblePortraitOffset;
11
+ export declare const defaultBubblePortraitCornerRadius = 0;
12
+ export declare function normalizeBubblePortraitPlacement(value: unknown): BubblePortraitPlacement;
13
+ export declare function normalizeBubblePortraitOffset(value: BubblePortraitOffsetInput): BubblePortraitOffset;
14
+ export declare function normalizeBubblePortraitCornerRadius(value: unknown): number;
@@ -15,7 +15,7 @@
15
15
  | 3 | Runtime Expression 0.3.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-runtime-expression@0.3.0/dist/runtime-expression.js` |
16
16
  | 4 | Asset Manager 0.7.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-asset-manager@0.7.0/dist/asset-manager.js` |
17
17
  | 5 | SVG Text 0.4.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-svg-text@0.4.0/dist/svg-text.js` |
18
- | 6 | Bubble 0.5.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.5.0/dist/turbowarp-bubble.js` |
18
+ | 6 | Bubble 0.7.0 | `https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-bubble@0.7.0/dist/turbowarp-bubble.js` |
19
19
 
20
20
  開発中のBubbleを試す場合は、このリポジトリの`dist/turbowarp-bubble.js`をローカルカスタム拡張機能として読み込みます。表示時に既定のSVG Text adapterが、画像・メディア機能の使用時にAsset Managerが、待機開始時にAsync InputかRuntime Expressionが見つからなければ、Bubbleは明示的なエラーを返します。低レベルComposition APIでは別のtext capabilityを注入でき、その場合SVG Textは不要です。
21
21
 
@@ -154,6 +154,7 @@ visual styleを省略した場合は`NORMAL`です。本体drawableは文字・p
154
154
 
155
155
  ```text
156
156
  set portrait base [HeroFace] for bubble style [hero-dialogue]
157
+ set portrait [top-left] offset x [-4] y [6] zoom [120] % corner radius [12] px for bubble style [hero-dialogue]
157
158
 
158
159
  set blink frames [HeroEyesOpen,HeroEyesClosed]
159
160
  every [0.4] seconds for bubble style [hero-dialogue]
@@ -171,7 +172,10 @@ set continue frames [Next1,Next2]
171
172
  - 「次へ」はループが分かるよう2枚以上必要です。
172
173
  - `SECONDS`は0より大きい秒数です。
173
174
  - `ASSETS`を空にすると、そのアニメーション設定を解除します。
174
- - 表情ベースを空にするとportrait全体を解除します。
175
+ - portrait配置の既定値は`left`です。`left`/`right`は対応する端の上下中央、`top-left`/`top-right`/`bottom-left`/`bottom-right`は対応する隅へ揃えます。portrait用の列は維持されるため、大きなoffsetで移動しない限り文字と重なりません。
176
+ - portraitのxは右正、yは上正です。zoomは96pxのportrait枠に対する0より大きい百分率で、Bubble全体のscaleより先に適用します。角丸半径は0以上のpixel値で、表示幅または表示高の半分を上限にします。
177
+ - `none`を選ぶか表情ベースを空にすると、目パチ・口パク設定を含むportrait全体を解除します。別の配置へ戻すときは、先に表情ベースを再設定します。
178
+ - 角丸はBubbleのfill色でベース・目パチ・口パクの各レイヤーをmaskします。`NO_BUBBLE`にはmaskに使うfillがないため、portraitは矩形表示のままです。
175
179
 
176
180
  ## 5. 逐次表示、音声、表示サイズ
177
181
 
@@ -261,35 +265,36 @@ cloneが停止・削除された場合は、そのtargetに属するtimer、SVG
261
265
 
262
266
  ## 11. ブロック一覧
263
267
 
264
- | ブロック | 説明 |
265
- | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------- |
266
- | `define bubble style [STYLE] using text style [TEXT_STYLE]` | Bubble styleを定義または再定義する |
267
- | `set bubble placement [PLACEMENT] for bubble style [STYLE]` | Actor相対方向・角度、または背景相対領域を設定する |
268
- | `set bubble distance [DISTANCE] for bubble style [STYLE]` | Actor boundsからtail先端までの距離を設定する |
269
- | `set bubble visual style [VISUAL_STYLE] for bubble style [STYLE]` | Bubble本体のSVG形状を10種類から設定する |
270
- | `set bubble tail length [LENGTH] for bubble style [STYLE]` | Bubble borderからtail先端までの基準長を設定する |
271
- | `set bubble offset x [X] y [Y] scale [SCALE] % for bubble style [STYLE]` | 本体位置と、文字を含む全体のscaleを設定する |
272
- | `set portrait base [ASSET] for bubble style [STYLE]` | portraitのベース画像を設定する |
273
- | `set blink frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]` | 目パチ差分と間隔を設定する |
274
- | `set lip-sync frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]` | 口パク差分と間隔を設定する |
275
- | `set continue frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]` | `awaiting-continue`中の「次へ」アニメーションを設定する |
276
- | `set bubble reveal unit [UNIT] every [SECONDS] seconds layout [LAYOUT] for bubble style [STYLE]` | CHARACTER/WORD/LINE/BLOCKの逐次表示を設定する |
277
- | `set bubble word delimiters [DELIMITERS] show [SHOW] for bubble style [STYLE]` | WORDの区切り文字集合と表示可否を設定する |
278
- | `set bubble reveal sound [ASSET] for bubble style [STYLE]` | 表示単位ごとの効果音を設定する |
279
- | `set bubble voice [ASSET] for bubble style [STYLE]` | 表示開始時のフルボイスを設定する |
280
- | `finish [UNIT] with condition [CONDITION] or timeout after [TIMEOUT] seconds` | 未表示単位を最後まで進め、条件またはtimeoutを待つ |
281
- | `set bubble show animation [MOTION] for [SECONDS] seconds for bubble style [STYLE]` | 表示開始animationを設定する |
282
- | `set bubble hide animation [MOTION] for [SECONDS] seconds for bubble style [STYLE]` | 表示終了animationを設定する |
283
- | `animate this bubble [MOTION]` | Bubble全体のanimationを再生する |
284
- | `shake this bubble direction [DIRECTION] count [COUNT] ease [EASE]` | 吹き出し全体を指定方向へ揺らす |
285
- | `explode this bubble relative scale [SCALE] count [COUNT] ease [EASE]` | 吹き出し全体を相対倍率で変化させる |
286
- | `animate bubble shape to [VISUAL_STYLE] speed [SPEED] for [SECONDS] seconds` | Bubble外形を時間経過で切り替える |
287
- | `say [MESSAGE] with bubble style [STYLE]` | `talking` modeでsay表示を開始・置換する |
288
- | `think [MESSAGE] with bubble style [STYLE]` | `talking` modeでthink表示を開始・置換する |
289
- | `set this bubble animation mode [MODE]` | `talking`、`awaiting-continue`、`idle`からmodeを選ぶ |
290
- | `wait with this bubble until condition [CONDITION] or timeout after [TIMEOUT] seconds` | Runtime Expressionの条件成立またはtimeoutまで待つ |
291
- | `close this bubble` | 自分のBubbleと所有resourceを解放する |
292
- | `Bubble version` | Bubble実装versionを返す |
268
+ | ブロック | 説明 |
269
+ | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
270
+ | `define bubble style [STYLE] using text style [TEXT_STYLE]` | Bubble styleを定義または再定義する |
271
+ | `set bubble placement [PLACEMENT] for bubble style [STYLE]` | Actor相対方向・角度、または背景相対領域を設定する |
272
+ | `set bubble distance [DISTANCE] for bubble style [STYLE]` | Actor boundsからtail先端までの距離を設定する |
273
+ | `set bubble visual style [VISUAL_STYLE] for bubble style [STYLE]` | Bubble本体のSVG形状を10種類から設定する |
274
+ | `set bubble tail length [LENGTH] for bubble style [STYLE]` | Bubble borderからtail先端までの基準長を設定する |
275
+ | `set bubble offset x [X] y [Y] scale [SCALE] % for bubble style [STYLE]` | 本体位置と、文字を含む全体のscaleを設定する |
276
+ | `set portrait base [ASSET] for bubble style [STYLE]` | portraitのベース画像を設定する |
277
+ | `set portrait [PLACEMENT] offset x [X] y [Y] zoom [ZOOM] % corner radius [RADIUS] px for bubble style [STYLE]` | portraitの有無、端/隅の配置、変形、角丸を設定する |
278
+ | `set blink frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]` | 目パチ差分と間隔を設定する |
279
+ | `set lip-sync frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]` | 口パク差分と間隔を設定する |
280
+ | `set continue frames [ASSETS] every [SECONDS] seconds for bubble style [STYLE]` | `awaiting-continue`中の「次へ」アニメーションを設定する |
281
+ | `set bubble reveal unit [UNIT] every [SECONDS] seconds layout [LAYOUT] for bubble style [STYLE]` | CHARACTER/WORD/LINE/BLOCKの逐次表示を設定する |
282
+ | `set bubble word delimiters [DELIMITERS] show [SHOW] for bubble style [STYLE]` | WORDの区切り文字集合と表示可否を設定する |
283
+ | `set bubble reveal sound [ASSET] for bubble style [STYLE]` | 表示単位ごとの効果音を設定する |
284
+ | `set bubble voice [ASSET] for bubble style [STYLE]` | 表示開始時のフルボイスを設定する |
285
+ | `finish [UNIT] with condition [CONDITION] or timeout after [TIMEOUT] seconds` | 未表示単位を最後まで進め、条件またはtimeoutを待つ |
286
+ | `set bubble show animation [MOTION] for [SECONDS] seconds for bubble style [STYLE]` | 表示開始animationを設定する |
287
+ | `set bubble hide animation [MOTION] for [SECONDS] seconds for bubble style [STYLE]` | 表示終了animationを設定する |
288
+ | `animate this bubble [MOTION]` | Bubble全体のanimationを再生する |
289
+ | `shake this bubble direction [DIRECTION] count [COUNT] ease [EASE]` | 吹き出し全体を指定方向へ揺らす |
290
+ | `explode this bubble relative scale [SCALE] count [COUNT] ease [EASE]` | 吹き出し全体を相対倍率で変化させる |
291
+ | `animate bubble shape to [VISUAL_STYLE] speed [SPEED] for [SECONDS] seconds` | Bubble外形を時間経過で切り替える |
292
+ | `say [MESSAGE] with bubble style [STYLE]` | `talking` modeでsay表示を開始・置換する |
293
+ | `think [MESSAGE] with bubble style [STYLE]` | `talking` modeでthink表示を開始・置換する |
294
+ | `set this bubble animation mode [MODE]` | `talking`、`awaiting-continue`、`idle`からmodeを選ぶ |
295
+ | `wait with this bubble until condition [CONDITION] or timeout after [TIMEOUT] seconds` | Runtime Expressionの条件成立またはtimeoutまで待つ |
296
+ | `close this bubble` | 自分のBubbleと所有resourceを解放する |
297
+ | `Bubble version` | Bubble実装versionを返す |
293
298
 
294
299
  ## 12. よくあるエラー
295
300