@kubohiroya/turbowarp-bubble 0.8.0 → 0.9.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.
- package/README.md +292 -242
- package/README_ja.md +693 -0
- package/dist/composition.js +835 -668
- package/dist/extension-manifest.json +34 -0
- package/dist/turbowarp-adapter.js +1911 -1337
- package/dist/turbowarp-bubble.js +1037 -110
- package/dist/types/bubble-svg.d.ts +4 -0
- package/dist/types/composition.d.ts +5 -0
- package/dist/types/scratch-default.d.ts +67 -0
- package/dist/types/svg-overlay-surface.d.ts +2 -2
- package/dist/types/turbowarp-adapter.d.ts +4 -1
- package/dist/types/turbowarp-svg-text-adapter.d.ts +5 -0
- package/docs/assets/block-quick-start.svg +8 -8
- package/docs/assets/bubble-lifecycle.gif +0 -0
- package/docs/assets/bubble-style-gallery.svg +2 -20
- package/docs/assets/turbowarp-say-think-block-comparison.png +0 -0
- package/docs/assets/turbowarp-say-think-stage-comparison.png +0 -0
- package/docs/block-manual.ja.md +70 -45
- package/docs/block-manual.md +55 -30
- package/docs/index.html +38 -22
- package/docs/ja/index.html +38 -22
- package/docs/release-notes-0.8.0.md +63 -12
- package/docs/release-notes-0.9.0.md +47 -0
- package/package.json +5 -3
package/dist/turbowarp-bubble.js
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}) : target, mod));
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/config.ts
|
|
34
|
-
var extensionConfig = {
|
|
34
|
+
var extensionConfig$1 = {
|
|
35
35
|
id: "kubohiroyabubble",
|
|
36
36
|
slug: "turbowarp-bubble",
|
|
37
37
|
name: "Bubble",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"opcode": "defineBubbleStyle",
|
|
48
48
|
"blockType": "COMMAND",
|
|
49
49
|
"text": "define bubble style [STYLE] using text style [TEXT_STYLE]",
|
|
50
|
-
"description": "Defines or replaces a bubble style
|
|
50
|
+
"description": "Defines or replaces a bubble style. The default text style without further settings uses the Scratch-compatible basic profile.",
|
|
51
51
|
"arguments": {
|
|
52
52
|
"STYLE": {
|
|
53
53
|
"type": "STRING",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"opcode": "setBubbleVisualStyle",
|
|
146
146
|
"blockType": "COMMAND",
|
|
147
147
|
"text": "set bubble visual style [VISUAL_STYLE] for bubble style [STYLE]",
|
|
148
|
-
"description": "Sets the SVG body shape used by this bubble style.",
|
|
148
|
+
"description": "Sets the inseparable SVG body and tail or trail shape pair used by this bubble style.",
|
|
149
149
|
"arguments": {
|
|
150
150
|
"VISUAL_STYLE": {
|
|
151
151
|
"type": "STRING",
|
|
@@ -474,11 +474,48 @@
|
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
476
|
},
|
|
477
|
+
{
|
|
478
|
+
"opcode": "say",
|
|
479
|
+
"blockType": "COMMAND",
|
|
480
|
+
"text": "say [MESSAGE]",
|
|
481
|
+
"description": "Shows or replaces this sprite's Scratch-compatible default say bubble. An empty message closes it.",
|
|
482
|
+
"arguments": { "MESSAGE": {
|
|
483
|
+
"type": "STRING",
|
|
484
|
+
"defaultValue": "Hello!"
|
|
485
|
+
} }
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
"opcode": "think",
|
|
489
|
+
"blockType": "COMMAND",
|
|
490
|
+
"text": "think [MESSAGE]",
|
|
491
|
+
"description": "Shows or replaces this sprite's Scratch-compatible default think bubble. An empty message closes it.",
|
|
492
|
+
"arguments": { "MESSAGE": {
|
|
493
|
+
"type": "STRING",
|
|
494
|
+
"defaultValue": "Hmm..."
|
|
495
|
+
} }
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
"opcode": "showWithBubbleStyle",
|
|
499
|
+
"blockType": "COMMAND",
|
|
500
|
+
"text": "show [MESSAGE] with bubble style [STYLE]",
|
|
501
|
+
"description": "Shows or replaces this sprite's Bubble. The selected style determines the complete body and tail or trail shape.",
|
|
502
|
+
"arguments": {
|
|
503
|
+
"MESSAGE": {
|
|
504
|
+
"type": "STRING",
|
|
505
|
+
"defaultValue": "Hello!"
|
|
506
|
+
},
|
|
507
|
+
"STYLE": {
|
|
508
|
+
"type": "STRING",
|
|
509
|
+
"defaultValue": "say"
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
},
|
|
477
513
|
{
|
|
478
514
|
"opcode": "sayWithBubbleStyle",
|
|
479
515
|
"blockType": "COMMAND",
|
|
480
516
|
"text": "say [MESSAGE] with bubble style [STYLE]",
|
|
481
|
-
"description": "Shows or replaces this sprite's
|
|
517
|
+
"description": "Shows or replaces this sprite's say bubble in talking animation mode. An empty message closes the basic profile.",
|
|
518
|
+
"hideFromPalette": true,
|
|
482
519
|
"arguments": {
|
|
483
520
|
"MESSAGE": {
|
|
484
521
|
"type": "STRING",
|
|
@@ -494,7 +531,8 @@
|
|
|
494
531
|
"opcode": "thinkWithBubbleStyle",
|
|
495
532
|
"blockType": "COMMAND",
|
|
496
533
|
"text": "think [MESSAGE] with bubble style [STYLE]",
|
|
497
|
-
"description": "Shows or replaces this sprite's
|
|
534
|
+
"description": "Shows or replaces this sprite's think bubble in talking animation mode. An empty message closes the basic profile.",
|
|
535
|
+
"hideFromPalette": true,
|
|
498
536
|
"arguments": {
|
|
499
537
|
"MESSAGE": {
|
|
500
538
|
"type": "STRING",
|
|
@@ -6005,7 +6043,18 @@
|
|
|
6005
6043
|
"NARRATION",
|
|
6006
6044
|
"NO_BUBBLE"
|
|
6007
6045
|
]);
|
|
6008
|
-
|
|
6046
|
+
var cloudBodyMinimumSize = Object.freeze({
|
|
6047
|
+
height: 96,
|
|
6048
|
+
width: 176
|
|
6049
|
+
});
|
|
6050
|
+
var emptyBodyMinimumSize = Object.freeze({
|
|
6051
|
+
height: 0,
|
|
6052
|
+
width: 0
|
|
6053
|
+
});
|
|
6054
|
+
function bubbleBodyMinimumSize(...styles) {
|
|
6055
|
+
return styles.some((style) => style === "THINKING" || style === "DREAMING") ? cloudBodyMinimumSize : emptyBodyMinimumSize;
|
|
6056
|
+
}
|
|
6057
|
+
function escapeXml$2(value) {
|
|
6009
6058
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
6010
6059
|
}
|
|
6011
6060
|
function requireDimension(value, fallback) {
|
|
@@ -6196,22 +6245,56 @@
|
|
|
6196
6245
|
if (!outer) throw new Error("JSClipper returned an empty Bubble outline.");
|
|
6197
6246
|
return `<path d="${polygonPath(outer)}" fill="${fill}" stroke="${border}" stroke-width="3" stroke-linejoin="round" data-boolean-operation="union" data-tail-base-on-border="true" ${extra}/>`;
|
|
6198
6247
|
}
|
|
6248
|
+
function smoothClosedPath(points) {
|
|
6249
|
+
const first = points[0];
|
|
6250
|
+
if (!first || points.length < 3) throw new TypeError("Smooth Bubble path requires at least three points.");
|
|
6251
|
+
const format = (value) => value.toFixed(4);
|
|
6252
|
+
const segments = points.map((current, index) => {
|
|
6253
|
+
const previous = points[(index - 1 + points.length) % points.length];
|
|
6254
|
+
const next = points[(index + 1) % points.length];
|
|
6255
|
+
const afterNext = points[(index + 2) % points.length];
|
|
6256
|
+
if (!previous || !next || !afterNext) throw new Error("Smooth Bubble path is invalid.");
|
|
6257
|
+
const firstControl = {
|
|
6258
|
+
x: current.x + (next.x - previous.x) / 6,
|
|
6259
|
+
y: current.y + (next.y - previous.y) / 6
|
|
6260
|
+
};
|
|
6261
|
+
const secondControl = {
|
|
6262
|
+
x: next.x - (afterNext.x - current.x) / 6,
|
|
6263
|
+
y: next.y - (afterNext.y - current.y) / 6
|
|
6264
|
+
};
|
|
6265
|
+
return `C ${format(firstControl.x)} ${format(firstControl.y)} ${format(secondControl.x)} ${format(secondControl.y)} ${format(next.x)} ${format(next.y)}`;
|
|
6266
|
+
});
|
|
6267
|
+
return `M ${format(first.x)} ${format(first.y)} ${segments.join(" ")} Z`;
|
|
6268
|
+
}
|
|
6199
6269
|
function cloudBody(width, height, fill, border) {
|
|
6270
|
+
const x = 24;
|
|
6200
6271
|
const y = 24;
|
|
6201
6272
|
const right = width - 24;
|
|
6202
6273
|
const bottom = height - 24;
|
|
6203
|
-
const
|
|
6204
|
-
const
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6274
|
+
const bodyWidth = right - x;
|
|
6275
|
+
const bodyHeight = bottom - y;
|
|
6276
|
+
const point = (xRatio, yRatio) => ({
|
|
6277
|
+
x: x + bodyWidth * xRatio,
|
|
6278
|
+
y: y + bodyHeight * yRatio
|
|
6279
|
+
});
|
|
6280
|
+
return `<path d="${smoothClosedPath([
|
|
6281
|
+
point(0, .5),
|
|
6282
|
+
point(.03, .3),
|
|
6283
|
+
point(.18, .2),
|
|
6284
|
+
point(.28, .04),
|
|
6285
|
+
point(.5, .16),
|
|
6286
|
+
point(.68, .03),
|
|
6287
|
+
point(.84, .18),
|
|
6288
|
+
point(.98, .3),
|
|
6289
|
+
point(1, .52),
|
|
6290
|
+
point(.95, .7),
|
|
6291
|
+
point(.82, .82),
|
|
6292
|
+
point(.68, .97),
|
|
6293
|
+
point(.5, .84),
|
|
6294
|
+
point(.32, .97),
|
|
6295
|
+
point(.18, .82),
|
|
6296
|
+
point(.03, .7)
|
|
6297
|
+
])}" fill="${fill}" stroke="${border}" stroke-width="3" stroke-linejoin="round"/>`;
|
|
6215
6298
|
}
|
|
6216
6299
|
function thoughtTrail(body, bodyCenter, tip, fill, border, dreaming) {
|
|
6217
6300
|
const tipVector = subtract(tip, bodyCenter);
|
|
@@ -6306,8 +6389,9 @@
|
|
|
6306
6389
|
return roundedRectanglePoints(width, height);
|
|
6307
6390
|
}
|
|
6308
6391
|
function bubbleBodyCenterOffset(input) {
|
|
6309
|
-
const
|
|
6310
|
-
const
|
|
6392
|
+
const minimumSize = bubbleBodyMinimumSize(input.style);
|
|
6393
|
+
const width = Math.max(requireDimension(input.width, 220), minimumSize.width);
|
|
6394
|
+
const height = Math.max(requireDimension(input.height, 112), minimumSize.height);
|
|
6311
6395
|
const direction = normalizeDirection(input.tailDirection);
|
|
6312
6396
|
if (direction === null) throw new TypeError("Bubble body center offset requires a tail direction.");
|
|
6313
6397
|
const tailLength = normalizeSvgTailLength(input.tailLength ?? svgDefaultTailLength);
|
|
@@ -6364,8 +6448,8 @@
|
|
|
6364
6448
|
function renderBubbleSvg(input) {
|
|
6365
6449
|
if (!bubbleVisualStyles.includes(input.style)) throw new TypeError(`Unsupported Bubble visual style: ${String(input.style)}`);
|
|
6366
6450
|
if (!Array.isArray(input.lines) || input.lines.some((line) => typeof line !== "string")) throw new TypeError("lines must be an array of strings.");
|
|
6367
|
-
const
|
|
6368
|
-
const
|
|
6451
|
+
const requestedWidth = requireDimension(input.width, 220);
|
|
6452
|
+
const requestedHeight = requireDimension(input.height, 112);
|
|
6369
6453
|
const fontSize = requireDimension(input.fontSize, 15);
|
|
6370
6454
|
const direction = normalizeDirection(input.tailDirection);
|
|
6371
6455
|
const tailLength = normalizeSvgTailLength(input.tailLength ?? svgDefaultTailLength);
|
|
@@ -6374,6 +6458,9 @@
|
|
|
6374
6458
|
if (shapeTransition !== void 0) {
|
|
6375
6459
|
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.");
|
|
6376
6460
|
}
|
|
6461
|
+
const minimumSize = bubbleBodyMinimumSize(input.style, ...shapeTransition === void 0 ? [] : [shapeTransition.from, shapeTransition.to]);
|
|
6462
|
+
const width = Math.max(requestedWidth, minimumSize.width);
|
|
6463
|
+
const height = Math.max(requestedHeight, minimumSize.height);
|
|
6377
6464
|
const fill = input.fillColor ?? "#fff4cc";
|
|
6378
6465
|
const border = input.borderColor ?? "#6f5b45";
|
|
6379
6466
|
const textColor = input.textColor ?? "#25283a";
|
|
@@ -6385,11 +6472,11 @@
|
|
|
6385
6472
|
x: width / 2,
|
|
6386
6473
|
y: height / 2
|
|
6387
6474
|
} : transformedBodyGeometry(roundedRectanglePoints(width, height), width, height, direction, tailLength, offset).bodyCenter;
|
|
6388
|
-
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("");
|
|
6475
|
+
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$2(textColor)}" font-family="${escapeXml$2(fontFamily)}" font-size="${fontSize * textScale}">${escapeXml$2(line)}</text>`).join("");
|
|
6389
6476
|
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>`;
|
|
6390
|
-
const title = escapeXml(input.title ?? `${input.style} bubble`);
|
|
6477
|
+
const title = escapeXml$2(input.title ?? `${input.style} bubble`);
|
|
6391
6478
|
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)}"`;
|
|
6392
|
-
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>`;
|
|
6479
|
+
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}" data-bubble-body-width="${width}" data-bubble-body-height="${height}"${transitionAttributes}><title>${title}</title>${body}${text}</svg>`;
|
|
6393
6480
|
}
|
|
6394
6481
|
//#endregion
|
|
6395
6482
|
//#region node_modules/.pnpm/@cto.af+unicode-trie-runtime@3.2.9/node_modules/@cto.af/unicode-trie-runtime/constants.js
|
|
@@ -8480,6 +8567,144 @@
|
|
|
8480
8567
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new TypeError("Bubble portrait corner radius must be zero or greater.");
|
|
8481
8568
|
return value;
|
|
8482
8569
|
}
|
|
8570
|
+
var scratchDefaultOptionalStyleKeys = Object.freeze([
|
|
8571
|
+
"placement",
|
|
8572
|
+
"maxWidth",
|
|
8573
|
+
"textLocale",
|
|
8574
|
+
"distance",
|
|
8575
|
+
"tailLength",
|
|
8576
|
+
"offset",
|
|
8577
|
+
"visualStyle",
|
|
8578
|
+
"portrait",
|
|
8579
|
+
"continueIndicator",
|
|
8580
|
+
"reveal",
|
|
8581
|
+
"audio",
|
|
8582
|
+
"showAnimation",
|
|
8583
|
+
"hideAnimation"
|
|
8584
|
+
]);
|
|
8585
|
+
function isRecord$6(value) {
|
|
8586
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8587
|
+
}
|
|
8588
|
+
/**
|
|
8589
|
+
* The block-level basic style is intentionally narrow. Any explicit layout,
|
|
8590
|
+
* body, media, reveal, or motion option selects the existing custom renderer.
|
|
8591
|
+
*/
|
|
8592
|
+
function bubbleLayoutProfileForStyleInput(value) {
|
|
8593
|
+
if (!isRecord$6(value)) return "custom";
|
|
8594
|
+
if (typeof value.textStyle !== "string" || value.textStyle.trim() !== "default") return "custom";
|
|
8595
|
+
return scratchDefaultOptionalStyleKeys.every((key) => value[key] === void 0) ? "scratch-default" : "custom";
|
|
8596
|
+
}
|
|
8597
|
+
function isScratchDefaultBubbleStyleInput(value) {
|
|
8598
|
+
return bubbleLayoutProfileForStyleInput(value) === "scratch-default";
|
|
8599
|
+
}
|
|
8600
|
+
/** Matches the numeric presentation and length limit used by say/think. */
|
|
8601
|
+
function formatScratchBubbleArgument(value) {
|
|
8602
|
+
let formatted = value;
|
|
8603
|
+
if (typeof value === "number" && Math.abs(value) >= .01 && value % 1 !== 0) formatted = value.toFixed(2);
|
|
8604
|
+
return String(formatted).slice(0, 330);
|
|
8605
|
+
}
|
|
8606
|
+
function estimatedHelveticaWidth(text) {
|
|
8607
|
+
let units = 0;
|
|
8608
|
+
for (const character of text) {
|
|
8609
|
+
if (/\p{Mark}/u.test(character)) continue;
|
|
8610
|
+
if (/\s/u.test(character)) {
|
|
8611
|
+
units += .35;
|
|
8612
|
+
continue;
|
|
8613
|
+
}
|
|
8614
|
+
units += (character.codePointAt(0) ?? 0) <= 127 ? .62 : 1;
|
|
8615
|
+
}
|
|
8616
|
+
return units * 14;
|
|
8617
|
+
}
|
|
8618
|
+
function layoutScratchBubbleText(value, measureText = estimatedHelveticaWidth) {
|
|
8619
|
+
const text = value.slice(0, 330);
|
|
8620
|
+
const measured = (candidate) => {
|
|
8621
|
+
let width;
|
|
8622
|
+
try {
|
|
8623
|
+
width = measureText(candidate);
|
|
8624
|
+
} catch {
|
|
8625
|
+
return estimatedHelveticaWidth(candidate);
|
|
8626
|
+
}
|
|
8627
|
+
return Number.isFinite(width) && width >= 0 ? width : estimatedHelveticaWidth(candidate);
|
|
8628
|
+
};
|
|
8629
|
+
const wrapped = wrapText({
|
|
8630
|
+
text,
|
|
8631
|
+
maxWidth: 170,
|
|
8632
|
+
measureText: measured
|
|
8633
|
+
});
|
|
8634
|
+
const lines = Object.freeze(wrapped.lines.map((line) => Object.freeze({
|
|
8635
|
+
text: line.text,
|
|
8636
|
+
width: line.width
|
|
8637
|
+
})));
|
|
8638
|
+
return Object.freeze({
|
|
8639
|
+
lines,
|
|
8640
|
+
maxLineWidth: Math.max(0, ...lines.map((line) => line.width)),
|
|
8641
|
+
text: lines.map((line) => line.text).join("\n")
|
|
8642
|
+
});
|
|
8643
|
+
}
|
|
8644
|
+
function scratchBubbleMetrics(layout) {
|
|
8645
|
+
const lineCount = Math.max(1, layout.lines.length);
|
|
8646
|
+
const paddedWidth = Math.max(layout.maxLineWidth, 50) + 20;
|
|
8647
|
+
const paddedHeight = 16 * lineCount + 20;
|
|
8648
|
+
return Object.freeze({
|
|
8649
|
+
bodyHeight: paddedHeight + 4,
|
|
8650
|
+
bodyWidth: paddedWidth + 4,
|
|
8651
|
+
height: paddedHeight + 4 + 12,
|
|
8652
|
+
paddedHeight,
|
|
8653
|
+
paddedWidth,
|
|
8654
|
+
width: paddedWidth + 4
|
|
8655
|
+
});
|
|
8656
|
+
}
|
|
8657
|
+
function positionScratchBubble(input) {
|
|
8658
|
+
const stageLeft = -input.stageWidth / 2;
|
|
8659
|
+
const stageRight = input.stageWidth / 2;
|
|
8660
|
+
const stageTop = input.stageHeight / 2;
|
|
8661
|
+
let pointsLeft = input.pointsLeft;
|
|
8662
|
+
if (!pointsLeft && input.width + input.bounds.right > stageRight && input.bounds.left - input.width > stageLeft) pointsLeft = true;
|
|
8663
|
+
else if (pointsLeft && input.bounds.left - input.width < stageLeft && input.width + input.bounds.right < stageRight) pointsLeft = false;
|
|
8664
|
+
const left = pointsLeft ? Math.min(stageRight - input.width, Math.max(stageLeft, input.bounds.left - input.width)) : Math.max(stageLeft, Math.min(stageRight - input.width, input.bounds.right));
|
|
8665
|
+
const top = Math.min(stageTop, input.bounds.bottom + input.height);
|
|
8666
|
+
return Object.freeze({
|
|
8667
|
+
centerX: left + input.width / 2,
|
|
8668
|
+
centerY: top - input.height / 2,
|
|
8669
|
+
left,
|
|
8670
|
+
pointsLeft,
|
|
8671
|
+
top
|
|
8672
|
+
});
|
|
8673
|
+
}
|
|
8674
|
+
function escapeXml$1(value) {
|
|
8675
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
8676
|
+
}
|
|
8677
|
+
function scratchBodyPath(metrics) {
|
|
8678
|
+
const { paddedHeight: height, paddedWidth: width } = metrics;
|
|
8679
|
+
const radius = Math.min(16, width / 2, height / 2);
|
|
8680
|
+
return [
|
|
8681
|
+
`M ${radius} ${height}`,
|
|
8682
|
+
`Q 0 ${height} 0 ${height - radius}`,
|
|
8683
|
+
`L 0 ${radius}`,
|
|
8684
|
+
`Q 0 0 ${radius} 0`,
|
|
8685
|
+
`L ${width - radius} 0`,
|
|
8686
|
+
`Q ${width} 0 ${width} ${radius}`,
|
|
8687
|
+
`L ${width} ${height - radius}`,
|
|
8688
|
+
`Q ${width} ${height} ${width - radius} ${height}`
|
|
8689
|
+
].join(" ");
|
|
8690
|
+
}
|
|
8691
|
+
function scratchSayBody(metrics) {
|
|
8692
|
+
const { paddedHeight: height, paddedWidth: width } = metrics;
|
|
8693
|
+
return `<path d="${`${scratchBodyPath(metrics)} C ${width - 16} ${height + 4} ${width - 12} ${height + 8} ${width - 12} ${height + 10} Q ${width - 12} ${height + 12} ${width - 14} ${height + 12} C ${width - 17} ${height + 12} ${width - 27} ${height + 8} ${width - 32} ${height} Z`}" fill="white" stroke="rgba(0, 0, 0, 0.15)" stroke-width="4" stroke-linejoin="round" paint-order="stroke fill"/>`;
|
|
8694
|
+
}
|
|
8695
|
+
function scratchThinkBody(metrics) {
|
|
8696
|
+
const { paddedHeight: height, paddedWidth: width } = metrics;
|
|
8697
|
+
return `<path d="${`${scratchBodyPath(metrics)} L ${width - 28} ${height} A 4 4 0 0 1 ${width - 36} ${height} Z`}" fill="white" stroke="rgba(0, 0, 0, 0.15)" stroke-width="4" stroke-linejoin="round" paint-order="stroke fill"/><circle cx="${width - 25.25}" cy="${height + 7.25}" r="2.25" fill="white" stroke="rgba(0, 0, 0, 0.15)" stroke-width="4" paint-order="stroke fill"/><circle cx="${width - 17.5}" cy="${height + 9.5}" r="1.5" fill="white" stroke="rgba(0, 0, 0, 0.15)" stroke-width="4" paint-order="stroke fill"/>`;
|
|
8698
|
+
}
|
|
8699
|
+
function renderScratchBubbleSvg(input) {
|
|
8700
|
+
const metrics = scratchBubbleMetrics(input.layout);
|
|
8701
|
+
const body = input.kind === "say" ? scratchSayBody(metrics) : scratchThinkBody(metrics);
|
|
8702
|
+
const bodyTransform = input.pointsLeft ? `translate(2 2)` : `translate(${metrics.width} 0) scale(-1 1) translate(2 2)`;
|
|
8703
|
+
const firstBaseline = 24.6;
|
|
8704
|
+
const text = input.layout.lines.map((line, index) => `<text x="12" y="${firstBaseline + 16 * index}" fill="#575E75" font-family="Helvetica, sans-serif" font-size="14" xml:space="preserve">${escapeXml$1(line.text)}</text>`).join("");
|
|
8705
|
+
const title = escapeXml$1(input.title ?? `${input.kind} bubble`);
|
|
8706
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${metrics.width}" height="${metrics.height}" viewBox="0 0 ${metrics.width} ${metrics.height}" role="img" data-bubble-profile="scratch-default" data-bubble-kind="${input.kind}"><title>${title}</title><g transform="${bodyTransform}">${body}</g>${text}</svg>`;
|
|
8707
|
+
}
|
|
8483
8708
|
//#endregion
|
|
8484
8709
|
//#region src/composition.ts
|
|
8485
8710
|
var BubbleCompositionError = class extends Error {
|
|
@@ -8515,7 +8740,7 @@
|
|
|
8515
8740
|
"easeOut",
|
|
8516
8741
|
"easeInOut"
|
|
8517
8742
|
]);
|
|
8518
|
-
function isRecord$
|
|
8743
|
+
function isRecord$5(value) {
|
|
8519
8744
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8520
8745
|
}
|
|
8521
8746
|
function requireExactKeys$1(value, required, optional, label) {
|
|
@@ -8533,7 +8758,7 @@
|
|
|
8533
8758
|
return value;
|
|
8534
8759
|
}
|
|
8535
8760
|
function normalizeAnimation(value, label, minimumFrames) {
|
|
8536
|
-
if (!isRecord$
|
|
8761
|
+
if (!isRecord$5(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
|
|
8537
8762
|
requireExactKeys$1(value, ["frames", "frameIntervalSeconds"], [], label);
|
|
8538
8763
|
if (!Array.isArray(value.frames) || value.frames.length < minimumFrames) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label}.frames must contain at least ${minimumFrames} image asset name${minimumFrames === 1 ? "" : "s"}.`);
|
|
8539
8764
|
const frames = Object.freeze(value.frames.map((frame, index) => requireAssetName(frame, `${label}.frames[${index}]`)));
|
|
@@ -8545,7 +8770,7 @@
|
|
|
8545
8770
|
});
|
|
8546
8771
|
}
|
|
8547
8772
|
function normalizePortrait(value) {
|
|
8548
|
-
if (!isRecord$
|
|
8773
|
+
if (!isRecord$5(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble portrait must be an object.");
|
|
8549
8774
|
requireExactKeys$1(value, ["base"], [
|
|
8550
8775
|
"blink",
|
|
8551
8776
|
"lipSync",
|
|
@@ -8575,7 +8800,7 @@
|
|
|
8575
8800
|
});
|
|
8576
8801
|
}
|
|
8577
8802
|
function normalizeMotion(value, label) {
|
|
8578
|
-
if (!isRecord$
|
|
8803
|
+
if (!isRecord$5(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", `${label} must be an object.`);
|
|
8579
8804
|
requireExactKeys$1(value, ["name"], [
|
|
8580
8805
|
"durationSeconds",
|
|
8581
8806
|
"ease",
|
|
@@ -8615,7 +8840,7 @@
|
|
|
8615
8840
|
}
|
|
8616
8841
|
function normalizeAudio(value) {
|
|
8617
8842
|
if (value === void 0) return void 0;
|
|
8618
|
-
if (!isRecord$
|
|
8843
|
+
if (!isRecord$5(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble audio must be an object.");
|
|
8619
8844
|
requireExactKeys$1(value, [], [
|
|
8620
8845
|
"voice",
|
|
8621
8846
|
"reveal",
|
|
@@ -8633,7 +8858,7 @@
|
|
|
8633
8858
|
return Object.freeze(result);
|
|
8634
8859
|
}
|
|
8635
8860
|
function normalizeStyle(value) {
|
|
8636
|
-
if (!isRecord$
|
|
8861
|
+
if (!isRecord$5(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Bubble style must be an object.");
|
|
8637
8862
|
requireExactKeys$1(value, ["name", "textStyle"], [
|
|
8638
8863
|
"placement",
|
|
8639
8864
|
"maxWidth",
|
|
@@ -8684,9 +8909,11 @@
|
|
|
8684
8909
|
maxWidth = value.maxWidth;
|
|
8685
8910
|
}
|
|
8686
8911
|
const textLocale = value.textLocale === void 0 ? void 0 : requireName$1(value.textLocale, "Bubble style text locale");
|
|
8912
|
+
const layoutProfile = bubbleLayoutProfileForStyleInput(value);
|
|
8687
8913
|
return Object.freeze({
|
|
8688
8914
|
name: requireName$1(value.name, "Bubble style name"),
|
|
8689
8915
|
textStyle: requireName$1(value.textStyle, "Bubble text style name"),
|
|
8916
|
+
layoutProfile,
|
|
8690
8917
|
...maxWidth === void 0 ? {} : { maxWidth },
|
|
8691
8918
|
...textLocale === void 0 ? {} : { textLocale },
|
|
8692
8919
|
placement,
|
|
@@ -8704,12 +8931,12 @@
|
|
|
8704
8931
|
}
|
|
8705
8932
|
function validateImageResolver(value) {
|
|
8706
8933
|
if (value === void 0) return void 0;
|
|
8707
|
-
if (!isRecord$
|
|
8934
|
+
if (!isRecord$5(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.");
|
|
8708
8935
|
return value;
|
|
8709
8936
|
}
|
|
8710
8937
|
function validateAudioCapability(value) {
|
|
8711
8938
|
if (value === void 0) return void 0;
|
|
8712
|
-
if (!isRecord$
|
|
8939
|
+
if (!isRecord$5(value) || typeof value.playSound !== "function") throw new TypeError("Bubble audio capability must provide playSound.");
|
|
8713
8940
|
if (value.isRegistered !== void 0 && typeof value.isRegistered !== "function") throw new TypeError("Bubble audio capability isRegistered must be a function.");
|
|
8714
8941
|
if (value.getMimeType !== void 0 && typeof value.getMimeType !== "function") throw new TypeError("Bubble audio capability getMimeType must be a function.");
|
|
8715
8942
|
return value;
|
|
@@ -8719,7 +8946,7 @@
|
|
|
8719
8946
|
return value;
|
|
8720
8947
|
}
|
|
8721
8948
|
function validateTextCapability(value) {
|
|
8722
|
-
if (!isRecord$
|
|
8949
|
+
if (!isRecord$5(value) || typeof value.setText !== "function" || typeof value.releaseTarget !== "function") throw new TypeError("Bubble text capability must provide setText and releaseTarget.");
|
|
8723
8950
|
return value;
|
|
8724
8951
|
}
|
|
8725
8952
|
function defaultScheduler() {
|
|
@@ -8729,11 +8956,11 @@
|
|
|
8729
8956
|
});
|
|
8730
8957
|
}
|
|
8731
8958
|
function validateScheduler(value) {
|
|
8732
|
-
if (!isRecord$
|
|
8959
|
+
if (!isRecord$5(value) || typeof value.setTimeout !== "function" || typeof value.clearTimeout !== "function") throw new TypeError("Bubble scheduler must provide setTimeout and clearTimeout.");
|
|
8733
8960
|
return value;
|
|
8734
8961
|
}
|
|
8735
8962
|
function validateAssetTarget(value, label) {
|
|
8736
|
-
if (!isRecord$
|
|
8963
|
+
if (!isRecord$5(value) || typeof value.id !== "string" || value.id.length === 0 || typeof value.isStage !== "boolean") throw new BubbleCompositionError("BUBBLE-COMPOSITION-004", `${label} must provide id and isStage.`);
|
|
8737
8964
|
return value;
|
|
8738
8965
|
}
|
|
8739
8966
|
function validateTextTarget(value) {
|
|
@@ -8741,7 +8968,7 @@
|
|
|
8741
8968
|
return value;
|
|
8742
8969
|
}
|
|
8743
8970
|
function validateSurface(value, style) {
|
|
8744
|
-
if (!isRecord$
|
|
8971
|
+
if (!isRecord$5(value) || !isRecord$5(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.");
|
|
8745
8972
|
const targets = value.targets;
|
|
8746
8973
|
validateTextTarget(targets.text);
|
|
8747
8974
|
const assetTargetIds = /* @__PURE__ */ new Set();
|
|
@@ -8777,6 +9004,10 @@
|
|
|
8777
9004
|
], ...style.continueIndicator?.frames ?? []];
|
|
8778
9005
|
}
|
|
8779
9006
|
function formatBubbleText(text, style, textCapability) {
|
|
9007
|
+
if (style.layoutProfile === "scratch-default") return layoutScratchBubbleText(text, (candidate) => typeof textCapability.measureText === "function" ? textCapability.measureText({
|
|
9008
|
+
styleName: style.textStyle,
|
|
9009
|
+
text: candidate
|
|
9010
|
+
}) : NaN).text;
|
|
8780
9011
|
if (style.maxWidth === void 0) return text;
|
|
8781
9012
|
if (typeof textCapability.measureText !== "function") throw new BubbleCompositionError("BUBBLE-COMPOSITION-007", "Bubble style maxWidth requires the text capability measureText method.");
|
|
8782
9013
|
return wrapText({
|
|
@@ -8852,7 +9083,7 @@
|
|
|
8852
9083
|
});
|
|
8853
9084
|
}
|
|
8854
9085
|
function normalizeShowInput(value) {
|
|
8855
|
-
if (!isRecord$
|
|
9086
|
+
if (!isRecord$5(value)) throw new BubbleCompositionError("BUBBLE-COMPOSITION-001", "Show bubble input must be an object.");
|
|
8856
9087
|
requireExactKeys$1(value, [
|
|
8857
9088
|
"actor",
|
|
8858
9089
|
"actorKey",
|
|
@@ -8881,7 +9112,7 @@
|
|
|
8881
9112
|
};
|
|
8882
9113
|
}
|
|
8883
9114
|
function createBubbleComposition(options) {
|
|
8884
|
-
if (!isRecord$
|
|
9115
|
+
if (!isRecord$5(options)) throw new TypeError("Bubble composition options must be an object.");
|
|
8885
9116
|
const imageResolver = validateImageResolver(options.imageResolver);
|
|
8886
9117
|
const audio = validateAudioCapability(options.audio);
|
|
8887
9118
|
const textCapability = validateTextCapability(options.textCapability);
|
|
@@ -8911,6 +9142,7 @@
|
|
|
8911
9142
|
let activeStyle = style;
|
|
8912
9143
|
if (input.reveal !== void 0) activeStyle = Object.freeze({
|
|
8913
9144
|
...style,
|
|
9145
|
+
layoutProfile: "custom",
|
|
8914
9146
|
reveal: input.reveal
|
|
8915
9147
|
});
|
|
8916
9148
|
let currentText = input.text;
|
|
@@ -8998,21 +9230,34 @@
|
|
|
8998
9230
|
kind: input.kind,
|
|
8999
9231
|
style: activeStyle
|
|
9000
9232
|
})), activeStyle);
|
|
9001
|
-
const
|
|
9233
|
+
const applySurfaceText = async (rawText, nextStyle = activeStyle) => {
|
|
9234
|
+
if (nextStyle.layoutProfile === "scratch-default" && surface?.renderScratchText) {
|
|
9235
|
+
const layout = layoutScratchBubbleText(rawText, (candidate) => typeof textCapability.measureText === "function" ? textCapability.measureText({
|
|
9236
|
+
styleName: nextStyle.textStyle,
|
|
9237
|
+
text: candidate
|
|
9238
|
+
}) : NaN);
|
|
9239
|
+
await surface.renderScratchText(layout);
|
|
9240
|
+
return;
|
|
9241
|
+
}
|
|
9242
|
+
if (!surface) return;
|
|
9243
|
+
textCapability.setText({
|
|
9244
|
+
styleName: nextStyle.textStyle,
|
|
9245
|
+
target: surface.targets.text,
|
|
9246
|
+
text: formatBubbleText(rawText, nextStyle, textCapability)
|
|
9247
|
+
});
|
|
9248
|
+
textOwned = true;
|
|
9249
|
+
};
|
|
9002
9250
|
if (reveal?.layout === "RESERVED") {
|
|
9251
|
+
const fullText = formatBubbleText(input.text, activeStyle, textCapability);
|
|
9003
9252
|
textCapability.setText({
|
|
9004
9253
|
styleName: activeStyle.textStyle,
|
|
9005
9254
|
target: surface.targets.text,
|
|
9006
9255
|
text: fullText
|
|
9007
9256
|
});
|
|
9257
|
+
textOwned = true;
|
|
9008
9258
|
surface.captureTextLayout?.();
|
|
9009
9259
|
}
|
|
9010
|
-
|
|
9011
|
-
styleName: activeStyle.textStyle,
|
|
9012
|
-
target: surface.targets.text,
|
|
9013
|
-
text: formatBubbleText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text, activeStyle, textCapability)
|
|
9014
|
-
});
|
|
9015
|
-
textOwned = true;
|
|
9260
|
+
await applySurfaceText(reveal ? revealedBubbleText(revealChunks, revealedCount) : input.text);
|
|
9016
9261
|
await primeStyleImages(activeStyle, styleImageResolver, surface);
|
|
9017
9262
|
createStyleLoops(activeStyle, styleImageResolver, surface);
|
|
9018
9263
|
let currentAnimationMode = "idle";
|
|
@@ -9021,11 +9266,7 @@
|
|
|
9021
9266
|
const renderVisibleText = async () => {
|
|
9022
9267
|
if (!surface) return;
|
|
9023
9268
|
const visible = reveal ? revealedBubbleText(revealChunks, revealedCount) : currentText;
|
|
9024
|
-
|
|
9025
|
-
styleName: activeStyle.textStyle,
|
|
9026
|
-
target: surface.targets.text,
|
|
9027
|
-
text: formatBubbleText(visible, activeStyle, textCapability)
|
|
9028
|
-
});
|
|
9269
|
+
await applySurfaceText(visible);
|
|
9029
9270
|
await surface.show();
|
|
9030
9271
|
};
|
|
9031
9272
|
const stopRevealTimer = () => {
|
|
@@ -9102,6 +9343,7 @@
|
|
|
9102
9343
|
target: surface.targets.text,
|
|
9103
9344
|
text: formatBubbleText(text, activeStyle, textCapability)
|
|
9104
9345
|
});
|
|
9346
|
+
textOwned = true;
|
|
9105
9347
|
surface.captureTextLayout?.();
|
|
9106
9348
|
}
|
|
9107
9349
|
await renderVisibleText();
|
|
@@ -9146,13 +9388,10 @@
|
|
|
9146
9388
|
target: surface.targets.text,
|
|
9147
9389
|
text: formatBubbleText(currentText, nextStyle, textCapability)
|
|
9148
9390
|
});
|
|
9391
|
+
textOwned = true;
|
|
9149
9392
|
surface.captureTextLayout?.();
|
|
9150
9393
|
}
|
|
9151
|
-
|
|
9152
|
-
styleName: nextStyle.textStyle,
|
|
9153
|
-
target: surface.targets.text,
|
|
9154
|
-
text: formatBubbleText(currentText, nextStyle, textCapability)
|
|
9155
|
-
});
|
|
9394
|
+
await applySurfaceText(currentText, nextStyle);
|
|
9156
9395
|
createStyleLoops(nextStyle, nextImageResolver, surface);
|
|
9157
9396
|
await Promise.all([
|
|
9158
9397
|
surface.setLayerVisible("portraitBase", nextStyle.portrait !== void 0),
|
|
@@ -9214,6 +9453,7 @@
|
|
|
9214
9453
|
target: surface.targets.text,
|
|
9215
9454
|
text: formatBubbleText(currentText, activeStyle, textCapability)
|
|
9216
9455
|
});
|
|
9456
|
+
textOwned = true;
|
|
9217
9457
|
surface.captureTextLayout?.();
|
|
9218
9458
|
}
|
|
9219
9459
|
}
|
|
@@ -9276,10 +9516,19 @@
|
|
|
9276
9516
|
}
|
|
9277
9517
|
transitionTail = transitionTail.then(async () => {
|
|
9278
9518
|
if (normalized.name === "animateBubbleShape" && normalized.visualStyle) {
|
|
9279
|
-
const
|
|
9519
|
+
const transitionStyle = Object.freeze({
|
|
9280
9520
|
...activeStyle,
|
|
9521
|
+
layoutProfile: "custom"
|
|
9522
|
+
});
|
|
9523
|
+
const nextStyle = Object.freeze({
|
|
9524
|
+
...transitionStyle,
|
|
9281
9525
|
visualStyle: normalized.visualStyle
|
|
9282
9526
|
});
|
|
9527
|
+
if (activeStyle.layoutProfile === "scratch-default") {
|
|
9528
|
+
await surface?.updateStyle(transitionStyle);
|
|
9529
|
+
await applySurfaceText(currentText, transitionStyle);
|
|
9530
|
+
await surface?.show();
|
|
9531
|
+
}
|
|
9283
9532
|
await surface?.animate?.(normalized);
|
|
9284
9533
|
activeStyle = nextStyle;
|
|
9285
9534
|
await surface?.updateStyle(activeStyle);
|
|
@@ -9389,7 +9638,7 @@
|
|
|
9389
9638
|
});
|
|
9390
9639
|
}
|
|
9391
9640
|
//#endregion
|
|
9392
|
-
//#region node_modules/.pnpm/@kubohiroya+turbowarp-svg-text@0.8.
|
|
9641
|
+
//#region node_modules/.pnpm/@kubohiroya+turbowarp-svg-text@0.8.1/node_modules/@kubohiroya/turbowarp-svg-text/dist/composition.js
|
|
9393
9642
|
var block_definitions_default = {
|
|
9394
9643
|
extensionName: "SVG Text",
|
|
9395
9644
|
blocks: [{
|
|
@@ -9449,6 +9698,15 @@
|
|
|
9449
9698
|
]
|
|
9450
9699
|
} }
|
|
9451
9700
|
};
|
|
9701
|
+
var extensionConfig = {
|
|
9702
|
+
id: "kubohiroyasvgtext",
|
|
9703
|
+
slug: "svg-text",
|
|
9704
|
+
name: "SVG Text",
|
|
9705
|
+
description: "Responsive named-style SVG text actors for TurboWarp.",
|
|
9706
|
+
author: "Hiroya Kubo",
|
|
9707
|
+
license: "MPL-2.0",
|
|
9708
|
+
unsandboxed: true
|
|
9709
|
+
};
|
|
9452
9710
|
var baseStageWidth = 480;
|
|
9453
9711
|
var baseStageHeight = 360;
|
|
9454
9712
|
var defaultFontPercent$1 = 100;
|
|
@@ -9657,6 +9915,21 @@
|
|
|
9657
9915
|
width
|
|
9658
9916
|
});
|
|
9659
9917
|
}
|
|
9918
|
+
function renderSvgTextLayout(layout) {
|
|
9919
|
+
const textAnchor = layout.style.alignment === "center" ? "middle" : layout.style.alignment === "right" ? "end" : "start";
|
|
9920
|
+
const text = layout.lines.map((line) => line.text).join("\n");
|
|
9921
|
+
const tspans = layout.lines.map((line) => `<tspan x="${formatSvgNumber(line.x)}" y="${formatSvgNumber(line.baseline)}">${escapeXml(line.text)}</tspan>`).join("");
|
|
9922
|
+
const whitespaceAttribute = layout.preserveWhitespace ? " xml:space=\"preserve\"" : "";
|
|
9923
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}" viewBox="0 0 ${layout.width} ${layout.height}" role="img"><title>${escapeXml(text)}</title><rect width="${layout.width}" height="${layout.height}" rx="${formatSvgNumber(layout.style.cornerRadius)}" fill="${escapeXml(layout.style.backgroundColor)}"/><text${whitespaceAttribute} fill="${escapeXml(layout.style.textColor)}" font-family="${escapeXml(layout.style.font)}" font-size="${formatSvgNumber(layout.style.fontSize)}" text-anchor="${textAnchor}">${tspans}</text></svg>`;
|
|
9924
|
+
}
|
|
9925
|
+
function renderSvgTextRichLayout(layout) {
|
|
9926
|
+
const tspans = layout.lines.flatMap((line) => line.fragments.flatMap((fragment) => {
|
|
9927
|
+
if (fragment.type === "text") return [`<tspan x="${formatSvgNumber(fragment.x)}" y="${formatSvgNumber(fragment.baseline)}" font-size="${formatSvgNumber(layout.style.fontSize)}">${escapeXml(fragment.text)}</tspan>`];
|
|
9928
|
+
return [`<tspan x="${formatSvgNumber(fragment.reading.x)}" y="${formatSvgNumber(fragment.reading.baseline)}" font-size="${formatSvgNumber(fragment.reading.fontSize)}">${escapeXml(fragment.reading.text)}</tspan>`, `<tspan x="${formatSvgNumber(fragment.base.x)}" y="${formatSvgNumber(fragment.base.baseline)}" font-size="${formatSvgNumber(fragment.base.fontSize)}">${escapeXml(fragment.base.text)}</tspan>`];
|
|
9929
|
+
})).join("");
|
|
9930
|
+
const whitespaceAttribute = layout.preserveWhitespace ? " xml:space=\"preserve\"" : "";
|
|
9931
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}" viewBox="0 0 ${layout.width} ${layout.height}" role="img"><title>${escapeXml(layout.plainText)}</title><rect width="${layout.width}" height="${layout.height}" rx="${formatSvgNumber(layout.style.cornerRadius)}" fill="${escapeXml(layout.style.backgroundColor)}"/><text${whitespaceAttribute} fill="${escapeXml(layout.style.textColor)}" font-family="${escapeXml(layout.style.font)}" text-anchor="start">${tspans}</text></svg>`;
|
|
9932
|
+
}
|
|
9660
9933
|
function normalizeSvgTextColor(value, fallback) {
|
|
9661
9934
|
const color = value.trim();
|
|
9662
9935
|
if (color === "") return fallback;
|
|
@@ -9743,9 +10016,211 @@
|
|
|
9743
10016
|
}
|
|
9744
10017
|
return units * fontSize;
|
|
9745
10018
|
}
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
10019
|
+
function escapeXml(value) {
|
|
10020
|
+
return value.replace(/[&<>"']/gu, (character) => {
|
|
10021
|
+
switch (character) {
|
|
10022
|
+
case "&": return "&";
|
|
10023
|
+
case "<": return "<";
|
|
10024
|
+
case ">": return ">";
|
|
10025
|
+
case "\"": return """;
|
|
10026
|
+
default: return "'";
|
|
10027
|
+
}
|
|
10028
|
+
});
|
|
10029
|
+
}
|
|
10030
|
+
function formatSvgNumber(value) {
|
|
10031
|
+
return String(Math.round(value * 1e3) / 1e3);
|
|
10032
|
+
}
|
|
10033
|
+
var blockDefinitions$1 = block_definitions_default.blocks;
|
|
10034
|
+
var definitionMenus$1 = block_definitions_default.menus;
|
|
10035
|
+
var EXTENSION_DOCS_URI$1 = "https://kubohiroya.github.io/turbowarp-svg-text/";
|
|
10036
|
+
var defaultStyleName$1 = "default";
|
|
10037
|
+
var defaultFontPercent = 100;
|
|
10038
|
+
var defaultRubyFontPercent = 50;
|
|
10039
|
+
var defaultRubyGap = 1;
|
|
10040
|
+
var minimumFontPercent = 1;
|
|
10041
|
+
var maximumFontPercent = 1e3;
|
|
10042
|
+
var minimumRubyFontPercent = 10;
|
|
10043
|
+
var maximumRubyFontPercent = 100;
|
|
10044
|
+
var minimumRubyGap = 0;
|
|
10045
|
+
var maximumRubyGap = 100;
|
|
10046
|
+
var BLOCK_ICON_URI$1 = `data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\"><g fill=\"none\" stroke=\"#fff\" stroke-width=\"5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M13 23V12h11M40 12h11v11M13 41v11h11M40 52h11V41M22 23h20M32 23v23\"/></g></svg>")}`;
|
|
10047
|
+
var SvgTextExtension = class {
|
|
10048
|
+
constructor(runtime = Scratch.vm?.runtime, options = {}) {
|
|
10049
|
+
this.styles = /* @__PURE__ */ new Map([[defaultStyleName$1, DEFAULT_SVG_TEXT_RICH_STYLE]]);
|
|
10050
|
+
this.textActors = /* @__PURE__ */ new Map();
|
|
10051
|
+
if (!runtime) throw new Error("SVG Text requires the TurboWarp VM.");
|
|
10052
|
+
this.runtime = runtime;
|
|
10053
|
+
this.castToString = options.castToString ?? Scratch.Cast.toString;
|
|
10054
|
+
if (options.listenForRuntimeEvents ?? true) this.runtime.on("STAGE_SIZE_CHANGED", () => {
|
|
10055
|
+
this.restyleTextActors();
|
|
10056
|
+
});
|
|
10057
|
+
}
|
|
10058
|
+
getInfo() {
|
|
10059
|
+
return {
|
|
10060
|
+
id: extensionConfig.id,
|
|
10061
|
+
name: Scratch.translate(block_definitions_default.extensionName),
|
|
10062
|
+
docsURI: EXTENSION_DOCS_URI$1,
|
|
10063
|
+
blockIconURI: BLOCK_ICON_URI$1,
|
|
10064
|
+
color1: "#9966ff",
|
|
10065
|
+
blocks: blockDefinitions$1.map((block) => this.toScratchBlock(block)),
|
|
10066
|
+
menus: definitionMenus$1
|
|
10067
|
+
};
|
|
10068
|
+
}
|
|
10069
|
+
defineStyle(args) {
|
|
10070
|
+
const styleName = this.normalizeStyleName(args.STYLE);
|
|
10071
|
+
this.styles.set(styleName, {
|
|
10072
|
+
alignment: this.normalizeAlignment(args.ALIGN),
|
|
10073
|
+
backgroundColor: this.normalizeColor(args.BACKGROUND, DEFAULT_SVG_TEXT_STYLE.backgroundColor),
|
|
10074
|
+
font: this.normalizeFont(args.FONT),
|
|
10075
|
+
fontPercent: this.normalizeFontPercent(args.SIZE),
|
|
10076
|
+
rubyFontPercent: this.normalizeRubyFontPercent(args.RUBY_SIZE),
|
|
10077
|
+
rubyGap: this.normalizeRubyGap(args.RUBY_GAP),
|
|
10078
|
+
textColor: this.normalizeColor(args.TEXT_COLOR, DEFAULT_SVG_TEXT_STYLE.textColor)
|
|
10079
|
+
});
|
|
10080
|
+
this.restyleTextActors(styleName);
|
|
10081
|
+
}
|
|
10082
|
+
setText(args, util) {
|
|
10083
|
+
this.applyTextActor(util.target, {
|
|
10084
|
+
kind: "plain",
|
|
10085
|
+
text: this.normalizeMessage(args.TEXT)
|
|
10086
|
+
}, this.resolveStyle(args.STYLE));
|
|
10087
|
+
}
|
|
10088
|
+
measureText(styleName, text) {
|
|
10089
|
+
const selection = this.resolveStyle(styleName);
|
|
10090
|
+
const layout = createSvgTextLayout(this.normalizeMessage(text), selection.definition, this.getNativeSize());
|
|
10091
|
+
return Math.max(0, ...layout.lines.map((line) => line.width));
|
|
10092
|
+
}
|
|
10093
|
+
/**
|
|
10094
|
+
* Exposes the stock named-style registry through a skin-free layout contract.
|
|
10095
|
+
* Consumers receive current layout data without access to the mutable registry.
|
|
10096
|
+
*/
|
|
10097
|
+
getLayoutCapability() {
|
|
10098
|
+
this.layoutCapabilityValue ?? (this.layoutCapabilityValue = Object.freeze({ layoutText: (input) => {
|
|
10099
|
+
if (typeof input !== "object" || input === null || typeof input.styleName !== "string" || typeof input.text !== "string") throw new TypeError("SVG Text layout capability input is invalid.");
|
|
10100
|
+
const nativeSize = this.requireLayoutNativeSize(input.nativeSize);
|
|
10101
|
+
const selection = this.resolveStyle(input.styleName);
|
|
10102
|
+
return createSvgTextLayout(this.normalizeMessage(input.text), selection.definition, nativeSize);
|
|
10103
|
+
} }));
|
|
10104
|
+
return this.layoutCapabilityValue;
|
|
10105
|
+
}
|
|
10106
|
+
setCompositionText(styleName, render, target) {
|
|
10107
|
+
const content = Object.freeze({
|
|
10108
|
+
kind: "composition",
|
|
10109
|
+
render
|
|
10110
|
+
});
|
|
10111
|
+
this.applyTextActor(target, content, this.resolveStyle(styleName));
|
|
10112
|
+
}
|
|
10113
|
+
releaseTextActor(target) {
|
|
10114
|
+
const state = this.textActors.get(target);
|
|
10115
|
+
if (!state) return false;
|
|
10116
|
+
this.textActors.delete(target);
|
|
10117
|
+
this.runtime.renderer?.destroySkin?.(state.skinId);
|
|
10118
|
+
this.runtime.requestRedraw?.();
|
|
10119
|
+
return true;
|
|
10120
|
+
}
|
|
10121
|
+
toScratchBlock(block) {
|
|
10122
|
+
return {
|
|
10123
|
+
opcode: block.opcode,
|
|
10124
|
+
blockType: Scratch.BlockType[block.blockType],
|
|
10125
|
+
text: Scratch.translate(block.text),
|
|
10126
|
+
hideFromPalette: block.hideFromPalette ?? false,
|
|
10127
|
+
arguments: Object.fromEntries(Object.entries(block.arguments).map(([name, argument]) => [name, {
|
|
10128
|
+
type: Scratch.ArgumentType[argument.type],
|
|
10129
|
+
defaultValue: argument.defaultValue,
|
|
10130
|
+
...argument.menu === void 0 ? {} : { menu: argument.menu }
|
|
10131
|
+
}]))
|
|
10132
|
+
};
|
|
10133
|
+
}
|
|
10134
|
+
normalizeStyleName(value) {
|
|
10135
|
+
return this.castToString(value).trim() || defaultStyleName$1;
|
|
10136
|
+
}
|
|
10137
|
+
normalizeFontPercent(value) {
|
|
10138
|
+
if (typeof value === "string" && value.trim() === "") return defaultFontPercent;
|
|
10139
|
+
const numericValue = Number(value);
|
|
10140
|
+
if (!Number.isFinite(numericValue)) return defaultFontPercent;
|
|
10141
|
+
return Math.min(maximumFontPercent, Math.max(minimumFontPercent, numericValue));
|
|
10142
|
+
}
|
|
10143
|
+
normalizeRubyFontPercent(value) {
|
|
10144
|
+
if (typeof value === "string" && value.trim() === "") return defaultRubyFontPercent;
|
|
10145
|
+
const numericValue = Number(value);
|
|
10146
|
+
if (!Number.isFinite(numericValue)) return defaultRubyFontPercent;
|
|
10147
|
+
return Math.min(maximumRubyFontPercent, Math.max(minimumRubyFontPercent, numericValue));
|
|
10148
|
+
}
|
|
10149
|
+
normalizeRubyGap(value) {
|
|
10150
|
+
if (typeof value === "string" && value.trim() === "") return defaultRubyGap;
|
|
10151
|
+
const numericValue = Number(value);
|
|
10152
|
+
if (!Number.isFinite(numericValue)) return defaultRubyGap;
|
|
10153
|
+
return Math.min(maximumRubyGap, Math.max(minimumRubyGap, numericValue));
|
|
10154
|
+
}
|
|
10155
|
+
normalizeMessage(value) {
|
|
10156
|
+
return this.castToString(value).replace(/\\r\\n|\\n|\\r/gu, "\n");
|
|
10157
|
+
}
|
|
10158
|
+
normalizeAlignment(value) {
|
|
10159
|
+
const alignment = this.castToString(value).trim().toLowerCase();
|
|
10160
|
+
if (alignment === "center" || alignment === "right") return alignment;
|
|
10161
|
+
return "left";
|
|
10162
|
+
}
|
|
10163
|
+
normalizeColor(value, fallback) {
|
|
10164
|
+
return normalizeSvgTextColor(this.castToString(value), fallback);
|
|
10165
|
+
}
|
|
10166
|
+
normalizeFont(value) {
|
|
10167
|
+
return normalizeSvgTextFont(this.castToString(value));
|
|
10168
|
+
}
|
|
10169
|
+
getNativeSize() {
|
|
10170
|
+
const nativeSize = this.runtime.renderer?.getNativeSize?.();
|
|
10171
|
+
if (!Array.isArray(nativeSize) || nativeSize.length < 2) return [480, 360];
|
|
10172
|
+
const width = Number(nativeSize[0]);
|
|
10173
|
+
const height = Number(nativeSize[1]);
|
|
10174
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return [480, 360];
|
|
10175
|
+
return [width, height];
|
|
10176
|
+
}
|
|
10177
|
+
requireLayoutNativeSize(value) {
|
|
10178
|
+
if (!Array.isArray(value) || value.length !== 2 || value.some((dimension) => typeof dimension !== "number" || !Number.isFinite(dimension) || dimension <= 0)) throw new TypeError("SVG Text layout capability nativeSize must contain two positive finite numbers.");
|
|
10179
|
+
return value;
|
|
10180
|
+
}
|
|
10181
|
+
createTextActorSvg(content, definition) {
|
|
10182
|
+
if (content.kind === "composition") return content.render(definition, this.getNativeSize());
|
|
10183
|
+
return renderSvgTextLayout(createSvgTextLayout(content.text, definition, this.getNativeSize()));
|
|
10184
|
+
}
|
|
10185
|
+
applyTextActor(target, content, selection) {
|
|
10186
|
+
const renderer = this.runtime.renderer;
|
|
10187
|
+
if (typeof target.drawableID !== "number" || typeof renderer?.createSVGSkin !== "function" || typeof renderer.updateDrawableSkinId !== "function") throw new Error("SVG Text requires SVG skin APIs from TurboWarp.");
|
|
10188
|
+
const skinId = renderer.createSVGSkin(this.createTextActorSvg(content, selection.definition));
|
|
10189
|
+
if (!Number.isInteger(skinId) || skinId < 0) throw new Error("TurboWarp did not create an SVG text skin.");
|
|
10190
|
+
try {
|
|
10191
|
+
renderer.updateDrawableSkinId(target.drawableID, skinId);
|
|
10192
|
+
} catch (error) {
|
|
10193
|
+
renderer.destroySkin?.(skinId);
|
|
10194
|
+
throw error;
|
|
10195
|
+
}
|
|
10196
|
+
const previous = this.textActors.get(target);
|
|
10197
|
+
this.textActors.set(target, {
|
|
10198
|
+
content,
|
|
10199
|
+
skinId,
|
|
10200
|
+
styleName: selection.styleName
|
|
10201
|
+
});
|
|
10202
|
+
if (previous && previous.skinId !== skinId) renderer.destroySkin?.(previous.skinId);
|
|
10203
|
+
this.runtime.requestRedraw?.();
|
|
10204
|
+
}
|
|
10205
|
+
resolveStyle(value) {
|
|
10206
|
+
const requestedName = this.normalizeStyleName(value);
|
|
10207
|
+
const definition = this.styles.get(requestedName);
|
|
10208
|
+
if (definition) return {
|
|
10209
|
+
definition,
|
|
10210
|
+
styleName: requestedName
|
|
10211
|
+
};
|
|
10212
|
+
return {
|
|
10213
|
+
definition: this.styles.get(defaultStyleName$1) ?? DEFAULT_SVG_TEXT_RICH_STYLE,
|
|
10214
|
+
styleName: defaultStyleName$1
|
|
10215
|
+
};
|
|
10216
|
+
}
|
|
10217
|
+
restyleTextActors(styleName) {
|
|
10218
|
+
for (const [target, state] of [...this.textActors]) {
|
|
10219
|
+
if (styleName !== void 0 && state.styleName !== styleName) continue;
|
|
10220
|
+
this.applyTextActor(target, state.content, this.resolveStyle(state.styleName));
|
|
10221
|
+
}
|
|
10222
|
+
}
|
|
10223
|
+
};
|
|
9749
10224
|
var defaultStyleName = "default";
|
|
9750
10225
|
var maximumContentCharacters = 1e5;
|
|
9751
10226
|
var maximumContentLines = 1e3;
|
|
@@ -9754,7 +10229,7 @@
|
|
|
9754
10229
|
var maximumLayoutWidth = 1e5;
|
|
9755
10230
|
var maximumRubyBaseCharacters = 256;
|
|
9756
10231
|
var maximumRubyReadingCharacters = 512;
|
|
9757
|
-
function isRecord$
|
|
10232
|
+
function isRecord$4(value) {
|
|
9758
10233
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9759
10234
|
}
|
|
9760
10235
|
function compositionError(code, message) {
|
|
@@ -9770,11 +10245,27 @@
|
|
|
9770
10245
|
if (typeof value !== "string" || value.trim().length === 0) throw compositionError("SVG-TEXT-COMPOSITION-001", `${label} must be a non-empty string.`);
|
|
9771
10246
|
return value.trim();
|
|
9772
10247
|
}
|
|
10248
|
+
function validateRuntime(value) {
|
|
10249
|
+
if (!isRecord$4(value) || !isRecord$4(value.renderer)) throw new TypeError("SVG Text composition runtime must provide a renderer.");
|
|
10250
|
+
const renderer = value.renderer;
|
|
10251
|
+
const methods = [
|
|
10252
|
+
"createSVGSkin",
|
|
10253
|
+
"destroySkin",
|
|
10254
|
+
"updateDrawableSkinId"
|
|
10255
|
+
];
|
|
10256
|
+
if (methods.some((method) => typeof renderer[method] !== "function")) throw new TypeError(`SVG Text composition renderer must provide ${methods.join(", ")}.`);
|
|
10257
|
+
if (value.requestRedraw !== void 0 && typeof value.requestRedraw !== "function") throw new TypeError("SVG Text composition requestRedraw must be a function.");
|
|
10258
|
+
return value;
|
|
10259
|
+
}
|
|
10260
|
+
function validateTarget(value) {
|
|
10261
|
+
if (!isRecord$4(value) || typeof value.drawableID !== "number" || !Number.isInteger(value.drawableID) || value.drawableID < 0) throw compositionError("SVG-TEXT-COMPOSITION-002", "SVG Text target must provide a non-negative integer drawableID.");
|
|
10262
|
+
return value;
|
|
10263
|
+
}
|
|
9773
10264
|
function validateOptionalString(value, label) {
|
|
9774
10265
|
if (value !== void 0 && (typeof value !== "string" || value.length === 0)) throw compositionError("SVG-TEXT-COMPOSITION-001", `${label} must be a non-empty string when provided.`);
|
|
9775
10266
|
}
|
|
9776
10267
|
function validateStyle(value) {
|
|
9777
|
-
if (!isRecord$
|
|
10268
|
+
if (!isRecord$4(value)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text style must be an object.");
|
|
9778
10269
|
requireExactKeys(value, ["name"], [
|
|
9779
10270
|
"alignment",
|
|
9780
10271
|
"backgroundColor",
|
|
@@ -9812,6 +10303,14 @@
|
|
|
9812
10303
|
if (!Array.isArray(value) || value.length !== 2 || value.some((dimension) => typeof dimension !== "number" || !Number.isFinite(dimension) || dimension <= 0)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text nativeSize must be [width, height] with two positive finite numbers.");
|
|
9813
10304
|
return value;
|
|
9814
10305
|
}
|
|
10306
|
+
function getRuntimeNativeSize(renderer) {
|
|
10307
|
+
const value = renderer.getNativeSize?.();
|
|
10308
|
+
if (!Array.isArray(value) || value.length < 2) return [480, 360];
|
|
10309
|
+
const width = Number(value[0]);
|
|
10310
|
+
const height = Number(value[1]);
|
|
10311
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return [480, 360];
|
|
10312
|
+
return [width, height];
|
|
10313
|
+
}
|
|
9815
10314
|
function normalizeText(value) {
|
|
9816
10315
|
return value.replace(/\\r\\n|\\n|\\r/gu, "\n");
|
|
9817
10316
|
}
|
|
@@ -9828,7 +10327,7 @@
|
|
|
9828
10327
|
let fragmentCount = 0;
|
|
9829
10328
|
let lineCount = 1;
|
|
9830
10329
|
const runs = value.map((candidate, runIndex) => {
|
|
9831
|
-
if (!isRecord$
|
|
10330
|
+
if (!isRecord$4(candidate)) throw compositionError("SVG-TEXT-COMPOSITION-001", `SVG Text rich content run ${runIndex} must be an object.`);
|
|
9832
10331
|
if (candidate.type === "text") {
|
|
9833
10332
|
requireExactKeys(candidate, ["type", "text"], [], `SVG Text rich content run ${runIndex}`);
|
|
9834
10333
|
if (typeof candidate.text !== "string") throw compositionError("SVG-TEXT-COMPOSITION-001", `SVG Text rich content run ${runIndex} text must be a string.`);
|
|
@@ -9874,7 +10373,7 @@
|
|
|
9874
10373
|
return value;
|
|
9875
10374
|
}
|
|
9876
10375
|
function layoutTextFromStyles(styles, input) {
|
|
9877
|
-
if (!isRecord$
|
|
10376
|
+
if (!isRecord$4(input)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text layout input is invalid.");
|
|
9878
10377
|
requireExactKeys(input, [
|
|
9879
10378
|
"styleName",
|
|
9880
10379
|
"text",
|
|
@@ -9887,7 +10386,7 @@
|
|
|
9887
10386
|
return createSvgTextLayout(normalizeText(input.text), definition, validateNativeSize(input.nativeSize));
|
|
9888
10387
|
}
|
|
9889
10388
|
function layoutRichTextFromStyles(styles, input) {
|
|
9890
|
-
if (!isRecord$
|
|
10389
|
+
if (!isRecord$4(input)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text rich layout input is invalid.");
|
|
9891
10390
|
requireExactKeys(input, [
|
|
9892
10391
|
"styleName",
|
|
9893
10392
|
"runs",
|
|
@@ -9916,17 +10415,141 @@
|
|
|
9916
10415
|
}
|
|
9917
10416
|
});
|
|
9918
10417
|
}
|
|
10418
|
+
function createSvgTextComposition(options) {
|
|
10419
|
+
if (!isRecord$4(options)) throw new TypeError("SVG Text composition options must be an object.");
|
|
10420
|
+
const runtime = validateRuntime(options.runtime);
|
|
10421
|
+
const extension = new SvgTextExtension(runtime, {
|
|
10422
|
+
castToString: (value) => String(value),
|
|
10423
|
+
listenForRuntimeEvents: false
|
|
10424
|
+
});
|
|
10425
|
+
const styles = /* @__PURE__ */ new Map([[defaultStyleName, DEFAULT_SVG_TEXT_RICH_STYLE]]);
|
|
10426
|
+
const targets = /* @__PURE__ */ new Set();
|
|
10427
|
+
let disposed = false;
|
|
10428
|
+
function ensureActive() {
|
|
10429
|
+
if (disposed) throw compositionError("SVG-TEXT-COMPOSITION-004", "SVG Text composition has been released.");
|
|
10430
|
+
}
|
|
10431
|
+
return Object.freeze({
|
|
10432
|
+
defineStyle(input) {
|
|
10433
|
+
ensureActive();
|
|
10434
|
+
const style = validateStyle(input);
|
|
10435
|
+
extension.defineStyle({
|
|
10436
|
+
ALIGN: style.alignment ?? "",
|
|
10437
|
+
BACKGROUND: style.backgroundColor ?? "",
|
|
10438
|
+
FONT: style.font ?? "",
|
|
10439
|
+
RUBY_GAP: style.rubyGap ?? "",
|
|
10440
|
+
RUBY_SIZE: style.rubyFontPercent ?? "",
|
|
10441
|
+
SIZE: style.fontPercent ?? "",
|
|
10442
|
+
STYLE: style.name,
|
|
10443
|
+
TEXT_COLOR: style.textColor ?? ""
|
|
10444
|
+
});
|
|
10445
|
+
styles.set(style.name, createStyleDefinition(style));
|
|
10446
|
+
},
|
|
10447
|
+
layoutRichText(input) {
|
|
10448
|
+
ensureActive();
|
|
10449
|
+
return layoutRichTextFromStyles(styles, input);
|
|
10450
|
+
},
|
|
10451
|
+
layoutText(input) {
|
|
10452
|
+
ensureActive();
|
|
10453
|
+
return layoutTextFromStyles(styles, input);
|
|
10454
|
+
},
|
|
10455
|
+
measureText(input) {
|
|
10456
|
+
ensureActive();
|
|
10457
|
+
if (!isRecord$4(input)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text measure input is invalid.");
|
|
10458
|
+
requireExactKeys(input, ["styleName", "text"], [], "SVG Text measure input");
|
|
10459
|
+
const styleName = requireName(input.styleName, "SVG Text styleName");
|
|
10460
|
+
if (!styles.has(styleName)) throw compositionError("SVG-TEXT-COMPOSITION-003", `SVG Text style is not defined: ${styleName}`);
|
|
10461
|
+
if (typeof input.text !== "string") throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text text must be a string.");
|
|
10462
|
+
return extension.measureText(styleName, input.text);
|
|
10463
|
+
},
|
|
10464
|
+
measureRichText(input) {
|
|
10465
|
+
ensureActive();
|
|
10466
|
+
if (!isRecord$4(input)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text rich measure input is invalid.");
|
|
10467
|
+
requireExactKeys(input, ["styleName", "runs"], ["maxWidth"], "SVG Text rich measure input");
|
|
10468
|
+
const styleName = requireName(input.styleName, "SVG Text styleName");
|
|
10469
|
+
const definition = styles.get(styleName);
|
|
10470
|
+
if (!definition) throw compositionError("SVG-TEXT-COMPOSITION-003", `SVG Text style is not defined: ${styleName}`);
|
|
10471
|
+
const runs = validateContentRuns(input.runs);
|
|
10472
|
+
const maxWidth = validateMaxWidth(input.maxWidth);
|
|
10473
|
+
const nativeSize = getRuntimeNativeSize(runtime.renderer);
|
|
10474
|
+
const layout = maxWidth === void 0 ? createSvgTextRichLayout(runs, definition, nativeSize) : createSvgTextRichLayout(runs, definition, nativeSize, maxWidth);
|
|
10475
|
+
return Math.max(0, ...layout.lines.map((line) => line.width));
|
|
10476
|
+
},
|
|
10477
|
+
setRichText(input) {
|
|
10478
|
+
ensureActive();
|
|
10479
|
+
if (!isRecord$4(input)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text rich actor input is invalid.");
|
|
10480
|
+
requireExactKeys(input, [
|
|
10481
|
+
"styleName",
|
|
10482
|
+
"target",
|
|
10483
|
+
"runs"
|
|
10484
|
+
], ["maxWidth"], "SVG Text rich actor input");
|
|
10485
|
+
const target = validateTarget(input.target);
|
|
10486
|
+
const styleName = requireName(input.styleName, "SVG Text styleName");
|
|
10487
|
+
if (!styles.has(styleName)) throw compositionError("SVG-TEXT-COMPOSITION-003", `SVG Text style is not defined: ${styleName}`);
|
|
10488
|
+
const runs = validateContentRuns(input.runs);
|
|
10489
|
+
const maxWidth = validateMaxWidth(input.maxWidth);
|
|
10490
|
+
extension.setCompositionText(styleName, (definition, nativeSize) => {
|
|
10491
|
+
return renderSvgTextRichLayout(maxWidth === void 0 ? createSvgTextRichLayout(runs, definition, nativeSize) : createSvgTextRichLayout(runs, definition, nativeSize, maxWidth));
|
|
10492
|
+
}, target);
|
|
10493
|
+
targets.add(target);
|
|
10494
|
+
},
|
|
10495
|
+
setText(input) {
|
|
10496
|
+
ensureActive();
|
|
10497
|
+
if (!isRecord$4(input)) throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text actor input is invalid.");
|
|
10498
|
+
requireExactKeys(input, [
|
|
10499
|
+
"styleName",
|
|
10500
|
+
"target",
|
|
10501
|
+
"text"
|
|
10502
|
+
], [], "SVG Text actor input");
|
|
10503
|
+
const target = validateTarget(input.target);
|
|
10504
|
+
const styleName = requireName(input.styleName, "SVG Text styleName");
|
|
10505
|
+
if (!styles.has(styleName)) throw compositionError("SVG-TEXT-COMPOSITION-003", `SVG Text style is not defined: ${styleName}`);
|
|
10506
|
+
if (typeof input.text !== "string") throw compositionError("SVG-TEXT-COMPOSITION-001", "SVG Text text must be a string.");
|
|
10507
|
+
extension.setText({
|
|
10508
|
+
STYLE: styleName,
|
|
10509
|
+
TEXT: input.text
|
|
10510
|
+
}, { target });
|
|
10511
|
+
targets.add(target);
|
|
10512
|
+
},
|
|
10513
|
+
releaseTarget(value) {
|
|
10514
|
+
ensureActive();
|
|
10515
|
+
const target = validateTarget(value);
|
|
10516
|
+
if (!targets.delete(target)) throw compositionError("SVG-TEXT-COMPOSITION-005", "SVG Text target is not owned by this composition.");
|
|
10517
|
+
if (!extension.releaseTextActor(target)) throw compositionError("SVG-TEXT-COMPOSITION-005", "SVG Text target ownership is inconsistent.");
|
|
10518
|
+
},
|
|
10519
|
+
releaseAll() {
|
|
10520
|
+
if (disposed) return;
|
|
10521
|
+
disposed = true;
|
|
10522
|
+
const errors = [];
|
|
10523
|
+
for (const target of targets) try {
|
|
10524
|
+
extension.releaseTextActor(target);
|
|
10525
|
+
} catch (error) {
|
|
10526
|
+
errors.push(error);
|
|
10527
|
+
}
|
|
10528
|
+
targets.clear();
|
|
10529
|
+
styles.clear();
|
|
10530
|
+
if (errors.length > 0) {
|
|
10531
|
+
const error = compositionError("SVG-TEXT-COMPOSITION-006", "SVG Text composition failed to release one or more skins.");
|
|
10532
|
+
Object.defineProperty(error, "errors", { value: Object.freeze([...errors]) });
|
|
10533
|
+
throw error;
|
|
10534
|
+
}
|
|
10535
|
+
}
|
|
10536
|
+
});
|
|
10537
|
+
}
|
|
9919
10538
|
//#endregion
|
|
9920
10539
|
//#region src/turbowarp-svg-text-adapter.ts
|
|
9921
|
-
function isRecord$
|
|
10540
|
+
function isRecord$3(value) {
|
|
9922
10541
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9923
10542
|
}
|
|
9924
10543
|
function validateExtension(value) {
|
|
9925
|
-
if (!isRecord$
|
|
10544
|
+
if (!isRecord$3(value) || typeof value.setText !== "function" || typeof value.releaseTextActor !== "function") throw new TypeError("TurboWarp SVG Text adapter requires setText and releaseTextActor.");
|
|
10545
|
+
return value;
|
|
10546
|
+
}
|
|
10547
|
+
function validateComposition(value) {
|
|
10548
|
+
if (!isRecord$3(value) || typeof value.setText !== "function" || typeof value.releaseTarget !== "function") throw new TypeError("SVG Text composition adapter requires setText and releaseTarget.");
|
|
9926
10549
|
return value;
|
|
9927
10550
|
}
|
|
9928
10551
|
function validateLayoutComposition(value) {
|
|
9929
|
-
if (!isRecord$
|
|
10552
|
+
if (!isRecord$3(value) || typeof value.layoutText !== "function") throw new TypeError("SVG Text overlay adapter requires the layoutText composition API.");
|
|
9930
10553
|
return value;
|
|
9931
10554
|
}
|
|
9932
10555
|
function requireFiniteNumber(value, label) {
|
|
@@ -9935,14 +10558,14 @@
|
|
|
9935
10558
|
return result;
|
|
9936
10559
|
}
|
|
9937
10560
|
function adaptSvgTextLayout(value) {
|
|
9938
|
-
if (!isRecord$
|
|
10561
|
+
if (!isRecord$3(value) || !isRecord$3(value.style) || !Array.isArray(value.lines)) throw new TypeError("SVG Text layout result is invalid.");
|
|
9939
10562
|
const style = value.style;
|
|
9940
10563
|
const alignment = style.alignment;
|
|
9941
10564
|
if (alignment !== "left" && alignment !== "center" && alignment !== "right") throw new TypeError("SVG Text layout alignment is invalid.");
|
|
9942
10565
|
const width = requireFiniteNumber(value.width, "SVG Text layout width");
|
|
9943
10566
|
const height = requireFiniteNumber(value.height, "SVG Text layout height");
|
|
9944
10567
|
const lines = Object.freeze(value.lines.map((line) => {
|
|
9945
|
-
if (!isRecord$
|
|
10568
|
+
if (!isRecord$3(line) || typeof line.text !== "string") throw new TypeError("SVG Text layout line is invalid.");
|
|
9946
10569
|
return Object.freeze({
|
|
9947
10570
|
baseline: requireFiniteNumber(line.baseline, "SVG Text line baseline") - height / 2,
|
|
9948
10571
|
text: line.text,
|
|
@@ -9986,6 +10609,30 @@
|
|
|
9986
10609
|
});
|
|
9987
10610
|
}
|
|
9988
10611
|
/**
|
|
10612
|
+
* Adapt the SVG Text package's composition API to Bubble's text capability.
|
|
10613
|
+
* This helper keeps the core package independent from SVG Text's target type.
|
|
10614
|
+
*/
|
|
10615
|
+
function createSvgTextCompositionCapability(compositionInput) {
|
|
10616
|
+
const composition = validateComposition(compositionInput);
|
|
10617
|
+
const capability = {
|
|
10618
|
+
setText({ styleName, target, text }) {
|
|
10619
|
+
composition.setText({
|
|
10620
|
+
styleName,
|
|
10621
|
+
target,
|
|
10622
|
+
text
|
|
10623
|
+
});
|
|
10624
|
+
},
|
|
10625
|
+
releaseTarget(target) {
|
|
10626
|
+
composition.releaseTarget(target);
|
|
10627
|
+
}
|
|
10628
|
+
};
|
|
10629
|
+
if (typeof composition.measureText === "function") capability.measureText = ({ styleName, text }) => composition.measureText?.({
|
|
10630
|
+
styleName,
|
|
10631
|
+
text
|
|
10632
|
+
}) ?? 0;
|
|
10633
|
+
return Object.freeze(capability);
|
|
10634
|
+
}
|
|
10635
|
+
/**
|
|
9989
10636
|
* Adapt SVG Text's host-neutral layout composition to Bubble's SVG overlay.
|
|
9990
10637
|
* The adapter preserves SVG Text's line coordinates without creating skins.
|
|
9991
10638
|
*/
|
|
@@ -10009,6 +10656,76 @@
|
|
|
10009
10656
|
}
|
|
10010
10657
|
});
|
|
10011
10658
|
}
|
|
10659
|
+
/**
|
|
10660
|
+
* Adapts the stock SVG Text extension's shared named-style layout registry.
|
|
10661
|
+
*/
|
|
10662
|
+
function createTurboWarpSvgTextOverlayTextCapability(extensionInput) {
|
|
10663
|
+
if (!isRecord$3(extensionInput) || typeof extensionInput.getLayoutCapability !== "function") throw new TypeError("TurboWarp SVG Text overlay adapter requires SVG Text 0.8.1 getLayoutCapability().");
|
|
10664
|
+
return createSvgTextOverlayTextCapability(extensionInput.getLayoutCapability());
|
|
10665
|
+
}
|
|
10666
|
+
//#endregion
|
|
10667
|
+
//#region src/asset-manager-image-adapter.ts
|
|
10668
|
+
var supportedMimeTypes = /* @__PURE__ */ new Set([
|
|
10669
|
+
"image/avif",
|
|
10670
|
+
"image/gif",
|
|
10671
|
+
"image/jpeg",
|
|
10672
|
+
"image/png",
|
|
10673
|
+
"image/svg+xml",
|
|
10674
|
+
"image/webp"
|
|
10675
|
+
]);
|
|
10676
|
+
function isRecord$2(value) {
|
|
10677
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10678
|
+
}
|
|
10679
|
+
function normalizeMimeType(value) {
|
|
10680
|
+
const mimeType = value.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
10681
|
+
if (mimeType === "image/jpg" || mimeType === "image/pjpeg") return "image/jpeg";
|
|
10682
|
+
if (mimeType === "image/x-png") return "image/png";
|
|
10683
|
+
return mimeType;
|
|
10684
|
+
}
|
|
10685
|
+
function isSupportedMimeType(value) {
|
|
10686
|
+
return supportedMimeTypes.has(normalizeMimeType(value));
|
|
10687
|
+
}
|
|
10688
|
+
function requireAssetManagerResource(value) {
|
|
10689
|
+
if (!isRecord$2(value) || typeof value.url !== "string" || !value.url.startsWith("blob:") || typeof value.mimeType !== "string" || !isSupportedMimeType(value.mimeType) || typeof value.width !== "number" || !Number.isFinite(value.width) || value.width <= 0 || typeof value.height !== "number" || !Number.isFinite(value.height) || value.height <= 0 || typeof value.release !== "function") throw new TypeError("Asset Manager DOM image resources must provide a supported MIME type, positive intrinsic dimensions, a blob URL, and release().");
|
|
10690
|
+
return value;
|
|
10691
|
+
}
|
|
10692
|
+
/**
|
|
10693
|
+
* Adapts Asset Manager's host-neutral DOM resource API to Bubble's SVG overlay contract.
|
|
10694
|
+
* Asset Manager owns byte validation and SVG sanitization; Bubble owns its capability shape.
|
|
10695
|
+
*/
|
|
10696
|
+
function createAssetManagerSvgOverlayImageCapability(capabilityInput) {
|
|
10697
|
+
if (!isRecord$2(capabilityInput) || typeof capabilityInput.isRegistered !== "function" || typeof capabilityInput.getMimeType !== "function" || typeof capabilityInput.resolveDOMImageResource !== "function") throw new TypeError("Asset Manager DOM image capability is invalid.");
|
|
10698
|
+
const capability = capabilityInput;
|
|
10699
|
+
return Object.freeze({
|
|
10700
|
+
isRegistered(name) {
|
|
10701
|
+
return capability.isRegistered(name) && isSupportedMimeType(capability.getMimeType(name));
|
|
10702
|
+
},
|
|
10703
|
+
getMimeType(name) {
|
|
10704
|
+
return normalizeMimeType(capability.getMimeType(name));
|
|
10705
|
+
},
|
|
10706
|
+
async resolveImage(name) {
|
|
10707
|
+
const declaredMimeType = normalizeMimeType(capability.getMimeType(name));
|
|
10708
|
+
if (!capability.isRegistered(name) || !isSupportedMimeType(declaredMimeType)) throw new TypeError("Asset Manager image is not registered with a Bubble-compatible MIME type.");
|
|
10709
|
+
const resource = await capability.resolveDOMImageResource(name);
|
|
10710
|
+
try {
|
|
10711
|
+
requireAssetManagerResource(resource);
|
|
10712
|
+
const mimeType = normalizeMimeType(resource.mimeType);
|
|
10713
|
+
if (mimeType !== declaredMimeType) throw new TypeError("Asset Manager DOM image resource MIME type changed during resolution.");
|
|
10714
|
+
return Object.freeze({
|
|
10715
|
+
height: resource.height,
|
|
10716
|
+
mimeType,
|
|
10717
|
+
src: resource.url,
|
|
10718
|
+
width: resource.width,
|
|
10719
|
+
release: () => resource.release(),
|
|
10720
|
+
...mimeType === "image/svg+xml" ? { svgSecurity: "sanitized" } : {}
|
|
10721
|
+
});
|
|
10722
|
+
} catch (error) {
|
|
10723
|
+
resource?.release?.();
|
|
10724
|
+
throw error;
|
|
10725
|
+
}
|
|
10726
|
+
}
|
|
10727
|
+
});
|
|
10728
|
+
}
|
|
10012
10729
|
//#endregion
|
|
10013
10730
|
//#region src/surface-motion.ts
|
|
10014
10731
|
function clampMotionProgress(value) {
|
|
@@ -10442,6 +11159,7 @@
|
|
|
10442
11159
|
"g",
|
|
10443
11160
|
"path",
|
|
10444
11161
|
"rect",
|
|
11162
|
+
"text",
|
|
10445
11163
|
"title"
|
|
10446
11164
|
]);
|
|
10447
11165
|
var allowedBodyAttributes = /* @__PURE__ */ new Set([
|
|
@@ -10452,8 +11170,11 @@
|
|
|
10452
11170
|
"data-tail-base-on-border",
|
|
10453
11171
|
"fill",
|
|
10454
11172
|
"fill-rule",
|
|
11173
|
+
"font-family",
|
|
11174
|
+
"font-size",
|
|
10455
11175
|
"height",
|
|
10456
11176
|
"opacity",
|
|
11177
|
+
"paint-order",
|
|
10457
11178
|
"r",
|
|
10458
11179
|
"rx",
|
|
10459
11180
|
"stroke",
|
|
@@ -10462,6 +11183,7 @@
|
|
|
10462
11183
|
"stroke-width",
|
|
10463
11184
|
"transform",
|
|
10464
11185
|
"width",
|
|
11186
|
+
"xml:space",
|
|
10465
11187
|
"x",
|
|
10466
11188
|
"y"
|
|
10467
11189
|
]);
|
|
@@ -10475,7 +11197,7 @@
|
|
|
10475
11197
|
if (/javascript:|url\s*\(/iu.test(value)) throw new TypeError("Bubble body SVG contains an unsafe attribute value.");
|
|
10476
11198
|
result.setAttribute(attribute, value);
|
|
10477
11199
|
}
|
|
10478
|
-
if (name === "title") result.textContent = source.textContent ?? "";
|
|
11200
|
+
if (name === "title" || name === "text") result.textContent = source.textContent ?? "";
|
|
10479
11201
|
for (const child of Array.from(source.children)) result.appendChild(copyAllowedBodyNode(child, document));
|
|
10480
11202
|
return result;
|
|
10481
11203
|
}
|
|
@@ -10497,7 +11219,7 @@
|
|
|
10497
11219
|
target.setDisplaySize(size);
|
|
10498
11220
|
return size;
|
|
10499
11221
|
}
|
|
10500
|
-
function createSvgOverlaySurface(manager, actor, actorKey, style, scheduler) {
|
|
11222
|
+
function createSvgOverlaySurface(manager, actor, actorKey, kind, style, scheduler) {
|
|
10501
11223
|
const { document, renderer } = manager;
|
|
10502
11224
|
const sequence = overlaySurfaceSequence;
|
|
10503
11225
|
overlaySurfaceSequence += 1;
|
|
@@ -10550,6 +11272,8 @@
|
|
|
10550
11272
|
let motionOpacity = 1;
|
|
10551
11273
|
let center = [0, 0];
|
|
10552
11274
|
let shapeTransition;
|
|
11275
|
+
let scratchTextLayout;
|
|
11276
|
+
let scratchPointsLeft = false;
|
|
10553
11277
|
const applyMotionTransform = (native = manager.updateNativeSize()) => {
|
|
10554
11278
|
const centerX = native.width / 2 + center[0];
|
|
10555
11279
|
const centerY = native.height / 2 - center[1];
|
|
@@ -10567,15 +11291,53 @@
|
|
|
10567
11291
|
const updateVisibility = (nativeSize) => {
|
|
10568
11292
|
const actorVisible = currentStyle.placement.basis === "background" || actor.visible !== false;
|
|
10569
11293
|
const visible = surfaceVisible && actorVisible && motionOpacity > 0;
|
|
11294
|
+
const scratchDefaultRendered = currentStyle.layoutProfile === "scratch-default" && scratchTextLayout !== void 0;
|
|
10570
11295
|
surfaceGroup.setAttribute("visibility", visible ? "visible" : "hidden");
|
|
10571
|
-
bodyGroup.setAttribute("visibility", visible && currentStyle.visualStyle !== "NO_BUBBLE" ? "visible" : "hidden");
|
|
10572
|
-
textGroup.setAttribute("visibility", visible ? "visible" : "hidden");
|
|
11296
|
+
bodyGroup.setAttribute("visibility", visible && (scratchDefaultRendered || currentStyle.visualStyle !== "NO_BUBBLE") ? "visible" : "hidden");
|
|
11297
|
+
textGroup.setAttribute("visibility", visible && !scratchDefaultRendered ? "visible" : "hidden");
|
|
10573
11298
|
for (const [layer, target] of layerTargets) target.setVisible(visible && layerAllowedByStyle(layer) && (layerVisibility.get(layer) ?? false));
|
|
10574
11299
|
applyMotionTransform(nativeSize);
|
|
10575
11300
|
};
|
|
10576
11301
|
const position = () => {
|
|
10577
11302
|
if (disposed) return;
|
|
10578
11303
|
const native = manager.updateNativeSize();
|
|
11304
|
+
if (currentStyle.layoutProfile === "scratch-default" && scratchTextLayout !== void 0) {
|
|
11305
|
+
const metrics = scratchBubbleMetrics(scratchTextLayout);
|
|
11306
|
+
const nextPosition = positionScratchBubble({
|
|
11307
|
+
bounds: targetBounds$1(actor),
|
|
11308
|
+
height: metrics.height,
|
|
11309
|
+
pointsLeft: scratchPointsLeft,
|
|
11310
|
+
stageHeight: native.height,
|
|
11311
|
+
stageWidth: native.width,
|
|
11312
|
+
width: metrics.width
|
|
11313
|
+
});
|
|
11314
|
+
scratchPointsLeft = nextPosition.pointsLeft;
|
|
11315
|
+
center = [nextPosition.centerX, nextPosition.centerY];
|
|
11316
|
+
const nextBodySignature = JSON.stringify({
|
|
11317
|
+
kind,
|
|
11318
|
+
layout: scratchTextLayout,
|
|
11319
|
+
pointsLeft: scratchPointsLeft
|
|
11320
|
+
});
|
|
11321
|
+
if (nextBodySignature !== bodySignature) {
|
|
11322
|
+
replaceBodyFromCanonicalSvg(bodyGroup, renderScratchBubbleSvg({
|
|
11323
|
+
kind,
|
|
11324
|
+
layout: scratchTextLayout,
|
|
11325
|
+
pointsLeft: scratchPointsLeft,
|
|
11326
|
+
title: `${currentStyle.name} ${kind} Bubble`
|
|
11327
|
+
}), document);
|
|
11328
|
+
bodySignature = nextBodySignature;
|
|
11329
|
+
}
|
|
11330
|
+
bodyGroup.setAttribute("data-bubble-style", "SCRATCH_DEFAULT");
|
|
11331
|
+
bodyGroup.setAttribute("data-bubble-profile", "scratch-default");
|
|
11332
|
+
bodyGroup.setAttribute("data-bubble-kind", kind);
|
|
11333
|
+
bodyGroup.setAttribute("data-bubble-body-width", String(metrics.width));
|
|
11334
|
+
bodyGroup.setAttribute("data-bubble-body-height", String(metrics.height));
|
|
11335
|
+
bodyGroup.setAttribute("transform", `translate(${native.width / 2 + nextPosition.left} ${native.height / 2 - nextPosition.top})`);
|
|
11336
|
+
updateVisibility(native);
|
|
11337
|
+
return;
|
|
11338
|
+
}
|
|
11339
|
+
bodyGroup.removeAttribute("data-bubble-profile");
|
|
11340
|
+
bodyGroup.removeAttribute("data-bubble-kind");
|
|
10579
11341
|
const scaleMultiplier = currentStyle.placement.basis === "actor" ? currentStyle.offset.scalePercent / 100 : 1;
|
|
10580
11342
|
const nativeTextSize = text.getCapturedSize() ?? text.getSize();
|
|
10581
11343
|
const textSize = {
|
|
@@ -10592,8 +11354,11 @@
|
|
|
10592
11354
|
const indicatorSize = fitImage(continueIndicator, indicatorBoxSize$1, scaleMultiplier);
|
|
10593
11355
|
const totalWidth = portraitSize.width + (hasPortrait ? contentGap$1 * scaleMultiplier : 0) + textSize.width;
|
|
10594
11356
|
const contentHeight = Math.max(portraitSize.height, textSize.height);
|
|
10595
|
-
const
|
|
10596
|
-
const
|
|
11357
|
+
const minimumBodySize = bubbleBodyMinimumSize(currentStyle.visualStyle, ...shapeTransition === void 0 ? [] : [shapeTransition.from, shapeTransition.to]);
|
|
11358
|
+
const baseBubbleWidth = Math.max(totalWidth / scaleMultiplier + 48, minimumBodySize.width);
|
|
11359
|
+
const baseBubbleHeight = Math.max(contentHeight / scaleMultiplier + 48, minimumBodySize.height);
|
|
11360
|
+
const bubbleWidth = Math.max(totalWidth, (baseBubbleWidth - 48) * scaleMultiplier);
|
|
11361
|
+
const bubbleHeight = Math.max(contentHeight, (baseBubbleHeight - 48) * scaleMultiplier);
|
|
10597
11362
|
const stageLeft = -native.width / 2;
|
|
10598
11363
|
const stageRight = native.width / 2;
|
|
10599
11364
|
const stageTop = native.height / 2;
|
|
@@ -10602,14 +11367,14 @@
|
|
|
10602
11367
|
let centerY;
|
|
10603
11368
|
if (currentStyle.placement.basis === "background") {
|
|
10604
11369
|
centerX = 0;
|
|
10605
|
-
if (currentStyle.placement.region === "HEADER_LIKE") centerY = stageTop - stageSafeMargin$1 -
|
|
10606
|
-
else if (currentStyle.placement.region === "FOOTER_LIKE") centerY = stageBottom + stageSafeMargin$1 +
|
|
11370
|
+
if (currentStyle.placement.region === "HEADER_LIKE") centerY = stageTop - stageSafeMargin$1 - bubbleHeight / 2;
|
|
11371
|
+
else if (currentStyle.placement.region === "FOOTER_LIKE") centerY = stageBottom + stageSafeMargin$1 + bubbleHeight / 2;
|
|
10607
11372
|
else centerY = 0;
|
|
10608
11373
|
} else {
|
|
10609
11374
|
const nextCenter = actorRelativeBubbleCenter({
|
|
10610
11375
|
bounds: targetBounds$1(actor),
|
|
10611
|
-
bubbleWidth
|
|
10612
|
-
bubbleHeight
|
|
11376
|
+
bubbleWidth,
|
|
11377
|
+
bubbleHeight,
|
|
10613
11378
|
direction: currentStyle.placement.direction,
|
|
10614
11379
|
distance: currentStyle.distance,
|
|
10615
11380
|
tailLength: currentStyle.tailLength,
|
|
@@ -10618,8 +11383,8 @@
|
|
|
10618
11383
|
centerX = nextCenter.x;
|
|
10619
11384
|
centerY = nextCenter.y;
|
|
10620
11385
|
}
|
|
10621
|
-
centerX = clamp$1(centerX, stageLeft +
|
|
10622
|
-
centerY = clamp$1(centerY, stageBottom +
|
|
11386
|
+
centerX = clamp$1(centerX, stageLeft + bubbleWidth / 2, stageRight - bubbleWidth / 2);
|
|
11387
|
+
centerY = clamp$1(centerY, stageBottom + bubbleHeight / 2, stageTop - bubbleHeight / 2);
|
|
10623
11388
|
center = [centerX, centerY];
|
|
10624
11389
|
const tailDirection = currentStyle.placement.basis === "actor" ? tailDirectionForPlacement$1(currentStyle.placement.direction) : null;
|
|
10625
11390
|
const bodyOffset = currentStyle.placement.basis === "actor" ? [
|
|
@@ -10666,6 +11431,8 @@
|
|
|
10666
11431
|
bodySignature = nextBodySignature;
|
|
10667
11432
|
}
|
|
10668
11433
|
bodyGroup.setAttribute("data-bubble-style", currentStyle.visualStyle);
|
|
11434
|
+
bodyGroup.setAttribute("data-bubble-body-width", String(baseBubbleWidth));
|
|
11435
|
+
bodyGroup.setAttribute("data-bubble-body-height", String(baseBubbleHeight));
|
|
10669
11436
|
if (shapeTransition === void 0) {
|
|
10670
11437
|
bodyGroup.removeAttribute("data-bubble-shape-transition-from");
|
|
10671
11438
|
bodyGroup.removeAttribute("data-bubble-shape-transition-to");
|
|
@@ -10732,8 +11499,14 @@
|
|
|
10732
11499
|
layerVisibility.set(layer, visible);
|
|
10733
11500
|
updateVisibility();
|
|
10734
11501
|
},
|
|
10735
|
-
updateStyle(nextStyle) {
|
|
11502
|
+
async updateStyle(nextStyle) {
|
|
10736
11503
|
if (disposed) return;
|
|
11504
|
+
const removedTargets = [...nextStyle.portrait === void 0 ? [
|
|
11505
|
+
portraitBase,
|
|
11506
|
+
portraitBlink,
|
|
11507
|
+
portraitLipSync
|
|
11508
|
+
] : [...nextStyle.portrait.blink === void 0 ? [portraitBlink] : [], ...nextStyle.portrait.lipSync === void 0 ? [portraitLipSync] : []], ...nextStyle.continueIndicator === void 0 ? [continueIndicator] : []];
|
|
11509
|
+
await Promise.all(removedTargets.map((target) => target.release()));
|
|
10737
11510
|
const wasActorRelative = currentStyle.placement.basis === "actor";
|
|
10738
11511
|
currentStyle = nextStyle;
|
|
10739
11512
|
motionTranslation = [0, 0];
|
|
@@ -10757,6 +11530,12 @@
|
|
|
10757
11530
|
text.clearCapturedLayout();
|
|
10758
11531
|
position();
|
|
10759
11532
|
},
|
|
11533
|
+
renderScratchText(layout) {
|
|
11534
|
+
if (disposed) return;
|
|
11535
|
+
scratchTextLayout = layout;
|
|
11536
|
+
bodySignature = "";
|
|
11537
|
+
position();
|
|
11538
|
+
},
|
|
10760
11539
|
async animate(motion) {
|
|
10761
11540
|
if (disposed) return;
|
|
10762
11541
|
const durationSeconds = Math.max(0, motion.durationSeconds ?? 0);
|
|
@@ -10962,10 +11741,44 @@
|
|
|
10962
11741
|
return composition.layoutText(input);
|
|
10963
11742
|
} }));
|
|
10964
11743
|
}
|
|
11744
|
+
function createDefaultScratchRenderTextCapability(runtime) {
|
|
11745
|
+
const composition = createSvgTextComposition({ runtime });
|
|
11746
|
+
const definedStyles = /* @__PURE__ */ new Set();
|
|
11747
|
+
const defineStyle = (name) => {
|
|
11748
|
+
composition.defineStyle({
|
|
11749
|
+
name,
|
|
11750
|
+
backgroundColor: "transparent"
|
|
11751
|
+
});
|
|
11752
|
+
definedStyles.add(name);
|
|
11753
|
+
};
|
|
11754
|
+
const ensureStyle = (name) => {
|
|
11755
|
+
if (!definedStyles.has(name)) defineStyle(name);
|
|
11756
|
+
};
|
|
11757
|
+
defineStyle("default");
|
|
11758
|
+
return createSvgTextCompositionCapability(Object.freeze({
|
|
11759
|
+
setText(input) {
|
|
11760
|
+
ensureStyle(input.styleName);
|
|
11761
|
+
composition.setText(input);
|
|
11762
|
+
},
|
|
11763
|
+
releaseTarget(target) {
|
|
11764
|
+
composition.releaseTarget(target);
|
|
11765
|
+
},
|
|
11766
|
+
measureText(input) {
|
|
11767
|
+
ensureStyle(input.styleName);
|
|
11768
|
+
return composition.measureText(input);
|
|
11769
|
+
}
|
|
11770
|
+
}));
|
|
11771
|
+
}
|
|
10965
11772
|
function requireAssetManager(value) {
|
|
10966
11773
|
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.");
|
|
10967
11774
|
return value;
|
|
10968
11775
|
}
|
|
11776
|
+
function requireAssetManagerDOMImageCapability(value) {
|
|
11777
|
+
if (!isRecord(value) || typeof value.getDOMImageCapability !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "Bubble SVG overlay image assets require @kubohiroya/turbowarp-asset-manager 0.12.1 or a host-provided options.svgOverlayImageCapability.");
|
|
11778
|
+
const capability = value.getDOMImageCapability();
|
|
11779
|
+
if (!isRecord(capability) || typeof capability.isRegistered !== "function" || typeof capability.getMimeType !== "function" || typeof capability.resolveDOMImageResource !== "function") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-002", "Asset Manager did not provide a valid DOM image capability.");
|
|
11780
|
+
return capability;
|
|
11781
|
+
}
|
|
10969
11782
|
function targetBounds(target) {
|
|
10970
11783
|
try {
|
|
10971
11784
|
const bounds = target.getBoundsForBubble?.();
|
|
@@ -11030,7 +11843,7 @@
|
|
|
11030
11843
|
const vector = bubbleDirectionVector(direction);
|
|
11031
11844
|
return (Math.atan2(-vector.x, -vector.y) * 180 / Math.PI % 360 + 360) % 360;
|
|
11032
11845
|
}
|
|
11033
|
-
function createSurface(runtime, actor, actorKey, style, scheduler) {
|
|
11846
|
+
function createSurface(runtime, actor, actorKey, kind, style, scheduler) {
|
|
11034
11847
|
const renderer = runtime.renderer;
|
|
11035
11848
|
const sequence = surfaceSequence;
|
|
11036
11849
|
surfaceSequence += 1;
|
|
@@ -11083,6 +11896,8 @@
|
|
|
11083
11896
|
let motionScaleMultiplier = 1;
|
|
11084
11897
|
let motionOpacity = 1;
|
|
11085
11898
|
let shapeTransition;
|
|
11899
|
+
let scratchTextLayout;
|
|
11900
|
+
let scratchPointsLeft = false;
|
|
11086
11901
|
const applyMotionTransforms = () => {
|
|
11087
11902
|
for (const target of drawables) {
|
|
11088
11903
|
const basePosition = layoutPositions.get(target.drawableID);
|
|
@@ -11094,8 +11909,9 @@
|
|
|
11094
11909
|
};
|
|
11095
11910
|
const updateVisibility = () => {
|
|
11096
11911
|
const actorVisible = currentStyle.placement.basis === "background" || actor.visible !== false;
|
|
11097
|
-
|
|
11098
|
-
renderer.updateDrawableVisible(
|
|
11912
|
+
const scratchDefaultRendered = currentStyle.layoutProfile === "scratch-default" && scratchTextLayout !== void 0;
|
|
11913
|
+
renderer.updateDrawableVisible(body.drawableID, surfaceVisible && actorVisible && (scratchDefaultRendered || currentStyle.visualStyle !== "NO_BUBBLE") && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
|
|
11914
|
+
renderer.updateDrawableVisible(text.drawableID, surfaceVisible && actorVisible && !scratchDefaultRendered && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
|
|
11099
11915
|
for (const [layer, target] of layerTargets) renderer.updateDrawableVisible(target.drawableID, surfaceVisible && actorVisible && (layerVisibility.get(layer) ?? false) && (renderer.updateDrawableEffect !== void 0 || motionOpacity > 0));
|
|
11100
11916
|
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));
|
|
11101
11917
|
applyMotionTransforms();
|
|
@@ -11103,6 +11919,51 @@
|
|
|
11103
11919
|
};
|
|
11104
11920
|
const position = () => {
|
|
11105
11921
|
if (disposed) return;
|
|
11922
|
+
if (currentStyle.layoutProfile === "scratch-default" && scratchTextLayout !== void 0) {
|
|
11923
|
+
const nativeSize = renderer.getNativeSize();
|
|
11924
|
+
const stageWidth = Array.isArray(nativeSize) && Number(nativeSize[0]) > 0 ? Number(nativeSize[0]) : 480;
|
|
11925
|
+
const stageHeight = Array.isArray(nativeSize) && Number(nativeSize[1]) > 0 ? Number(nativeSize[1]) : 360;
|
|
11926
|
+
const metrics = scratchBubbleMetrics(scratchTextLayout);
|
|
11927
|
+
const nextPosition = positionScratchBubble({
|
|
11928
|
+
bounds: targetBounds(actor),
|
|
11929
|
+
height: metrics.height,
|
|
11930
|
+
pointsLeft: scratchPointsLeft,
|
|
11931
|
+
stageHeight,
|
|
11932
|
+
stageWidth,
|
|
11933
|
+
width: metrics.width
|
|
11934
|
+
});
|
|
11935
|
+
scratchPointsLeft = nextPosition.pointsLeft;
|
|
11936
|
+
const nextBodySkinSignature = JSON.stringify({
|
|
11937
|
+
kind,
|
|
11938
|
+
layout: scratchTextLayout,
|
|
11939
|
+
pointsLeft: scratchPointsLeft
|
|
11940
|
+
});
|
|
11941
|
+
if (nextBodySkinSignature !== cachedBodySkinSignature) {
|
|
11942
|
+
const nextSkinId = renderer.createSVGSkin(renderScratchBubbleSvg({
|
|
11943
|
+
kind,
|
|
11944
|
+
layout: scratchTextLayout,
|
|
11945
|
+
pointsLeft: scratchPointsLeft,
|
|
11946
|
+
title: `${currentStyle.name} ${kind} Bubble`
|
|
11947
|
+
}));
|
|
11948
|
+
if (!Number.isInteger(nextSkinId) || nextSkinId < 0) throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "TurboWarp did not create the Scratch-compatible Bubble SVG skin.");
|
|
11949
|
+
try {
|
|
11950
|
+
renderer.updateDrawableSkinId(body.drawableID, nextSkinId);
|
|
11951
|
+
} catch (error) {
|
|
11952
|
+
renderer.destroySkin(nextSkinId);
|
|
11953
|
+
throw error;
|
|
11954
|
+
}
|
|
11955
|
+
const previousBodySkinId = bodySkinId;
|
|
11956
|
+
bodySkinId = nextSkinId;
|
|
11957
|
+
cachedBodySkinSignature = nextBodySkinSignature;
|
|
11958
|
+
if (previousBodySkinId !== void 0) renderer.destroySkin(previousBodySkinId);
|
|
11959
|
+
}
|
|
11960
|
+
renderer.updateDrawableScale(body.drawableID, [100, 100]);
|
|
11961
|
+
renderer.updateDrawablePosition(body.drawableID, [nextPosition.centerX, nextPosition.centerY]);
|
|
11962
|
+
layoutPositions.set(body.drawableID, [nextPosition.centerX, nextPosition.centerY]);
|
|
11963
|
+
layoutScales.set(body.drawableID, [100, 100]);
|
|
11964
|
+
updateVisibility();
|
|
11965
|
+
return;
|
|
11966
|
+
}
|
|
11106
11967
|
const scaleMultiplier = currentStyle.placement.basis === "actor" ? currentStyle.offset.scalePercent / 100 : 1;
|
|
11107
11968
|
const nativeTextSize = reservedTextSize ?? readSize(renderer, text, {
|
|
11108
11969
|
width: 180,
|
|
@@ -11133,10 +11994,11 @@
|
|
|
11133
11994
|
};
|
|
11134
11995
|
const totalWidth = portraitSize.width + (hasPortrait ? contentGap * scaleMultiplier : 0) + textSize.width;
|
|
11135
11996
|
const contentHeight = Math.max(portraitSize.height, textSize.height);
|
|
11136
|
-
const
|
|
11137
|
-
const
|
|
11138
|
-
const
|
|
11139
|
-
const
|
|
11997
|
+
const minimumBodySize = bubbleBodyMinimumSize(currentStyle.visualStyle, ...shapeTransition === void 0 ? [] : [shapeTransition.from, shapeTransition.to]);
|
|
11998
|
+
const baseBubbleWidth = Math.max(totalWidth / scaleMultiplier + 48, minimumBodySize.width);
|
|
11999
|
+
const baseBubbleHeight = Math.max(contentHeight / scaleMultiplier + 48, minimumBodySize.height);
|
|
12000
|
+
const bubbleWidth = Math.max(totalWidth, (baseBubbleWidth - 48) * scaleMultiplier);
|
|
12001
|
+
const bubbleHeight = Math.max(contentHeight, (baseBubbleHeight - 48) * scaleMultiplier);
|
|
11140
12002
|
const nativeSize = renderer.getNativeSize();
|
|
11141
12003
|
const stageWidth = Array.isArray(nativeSize) && Number(nativeSize[0]) > 0 ? Number(nativeSize[0]) : 480;
|
|
11142
12004
|
const stageHeight = Array.isArray(nativeSize) && Number(nativeSize[1]) > 0 ? Number(nativeSize[1]) : 360;
|
|
@@ -11309,7 +12171,9 @@
|
|
|
11309
12171
|
originalVisualChange?.(changedTarget);
|
|
11310
12172
|
position();
|
|
11311
12173
|
};
|
|
12174
|
+
const nativeSizeHook = () => position();
|
|
11312
12175
|
if (currentStyle.placement.basis === "actor") actor.onTargetVisualChange = visualChangeHook;
|
|
12176
|
+
renderer.on?.("NativeSizeChanged", nativeSizeHook);
|
|
11313
12177
|
return Object.freeze({
|
|
11314
12178
|
targets,
|
|
11315
12179
|
setLayerVisible(layer, visible) {
|
|
@@ -11344,6 +12208,12 @@
|
|
|
11344
12208
|
reservedTextSize = void 0;
|
|
11345
12209
|
position();
|
|
11346
12210
|
},
|
|
12211
|
+
renderScratchText(layout) {
|
|
12212
|
+
if (disposed) return;
|
|
12213
|
+
scratchTextLayout = layout;
|
|
12214
|
+
cachedBodySkinSignature = "";
|
|
12215
|
+
position();
|
|
12216
|
+
},
|
|
11347
12217
|
async animate(motion) {
|
|
11348
12218
|
if (disposed) return;
|
|
11349
12219
|
const durationSeconds = Math.max(0, motion.durationSeconds ?? 0);
|
|
@@ -11466,6 +12336,7 @@
|
|
|
11466
12336
|
dispose() {
|
|
11467
12337
|
if (disposed) return;
|
|
11468
12338
|
disposed = true;
|
|
12339
|
+
renderer.off?.("NativeSizeChanged", nativeSizeHook);
|
|
11469
12340
|
if (currentStyle.placement.basis === "actor" && actor.onTargetVisualChange === visualChangeHook) actor.onTargetVisualChange = originalVisualChange ?? null;
|
|
11470
12341
|
for (const target of [...drawables].reverse()) renderer.destroyDrawable(target.drawableID, spriteLayer);
|
|
11471
12342
|
if (bodySkinId !== void 0) {
|
|
@@ -11491,10 +12362,20 @@
|
|
|
11491
12362
|
const runtime = runtimeInput;
|
|
11492
12363
|
const renderer = requireRenderer(runtime.renderer);
|
|
11493
12364
|
const requestedBackend = normalizeRenderBackend(options.bubbleRenderBackend);
|
|
11494
|
-
|
|
12365
|
+
let overlayTextCapability;
|
|
12366
|
+
let overlayTextCapabilityError;
|
|
12367
|
+
if (requestedBackend === "svg-overlay") {
|
|
12368
|
+
if (options.svgOverlayTextCapability !== void 0) overlayTextCapability = options.svgOverlayTextCapability;
|
|
12369
|
+
else if (runtime.ext_kubohiroyasvgtext === void 0) overlayTextCapability = createDefaultSvgOverlayTextCapability();
|
|
12370
|
+
else try {
|
|
12371
|
+
overlayTextCapability = createTurboWarpSvgTextOverlayTextCapability(runtime.ext_kubohiroyasvgtext);
|
|
12372
|
+
} catch (error) {
|
|
12373
|
+
overlayTextCapabilityError = error instanceof Error ? error.message : String(error);
|
|
12374
|
+
}
|
|
12375
|
+
}
|
|
11495
12376
|
const unsupportedBehavior = normalizeOverlayUnsupportedBehavior(options.svgOverlayUnsupportedBehavior);
|
|
11496
12377
|
const overlayDocument = requestedBackend === "svg-overlay" ? resolveOverlayDocument(options.document) : void 0;
|
|
11497
|
-
const unavailableReason = requestedBackend === "svg-overlay" ? overlayUnavailableReason(renderer, overlayDocument, overlayTextCapability) : void 0;
|
|
12378
|
+
const unavailableReason = requestedBackend === "svg-overlay" ? overlayTextCapabilityError ?? overlayUnavailableReason(renderer, overlayDocument, overlayTextCapability) : void 0;
|
|
11498
12379
|
if (requestedBackend === "svg-overlay" && unavailableReason !== void 0 && unsupportedBehavior === "error") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-004", `Bubble SVG overlay backend is unavailable because ${unavailableReason}. Use scratch-render or install the required public upstream capability.`);
|
|
11499
12380
|
const renderBackend = requestedBackend === "svg-overlay" && unavailableReason === void 0 ? "svg-overlay" : "scratch-render";
|
|
11500
12381
|
const scheduler = options.scheduler ?? {
|
|
@@ -11502,6 +12383,11 @@
|
|
|
11502
12383
|
clearTimeout: (handle) => globalThis.clearTimeout(handle)
|
|
11503
12384
|
};
|
|
11504
12385
|
const getAssetExtension = () => requireAssetManager(runtime.ext_kubohiroyaassetmanager);
|
|
12386
|
+
let assetManagerDOMImages;
|
|
12387
|
+
const getAssetManagerDOMImages = () => {
|
|
12388
|
+
assetManagerDOMImages ?? (assetManagerDOMImages = requireAssetManagerDOMImageCapability(runtime.ext_kubohiroyaassetmanager));
|
|
12389
|
+
return assetManagerDOMImages;
|
|
12390
|
+
};
|
|
11505
12391
|
let textCapability;
|
|
11506
12392
|
if (renderBackend === "svg-overlay") try {
|
|
11507
12393
|
textCapability = createSvgOverlayTextAdapter(overlayTextCapability, renderer);
|
|
@@ -11510,18 +12396,27 @@
|
|
|
11510
12396
|
}
|
|
11511
12397
|
else if (options.textCapability !== void 0) textCapability = options.textCapability;
|
|
11512
12398
|
else try {
|
|
11513
|
-
textCapability = createTurboWarpSvgTextCapability(runtime.ext_kubohiroyasvgtext);
|
|
11514
|
-
} catch {
|
|
11515
|
-
throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-003",
|
|
12399
|
+
textCapability = runtime.ext_kubohiroyasvgtext === void 0 ? createDefaultScratchRenderTextCapability(runtime) : createTurboWarpSvgTextCapability(runtime.ext_kubohiroyasvgtext);
|
|
12400
|
+
} catch (error) {
|
|
12401
|
+
throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-003", `Bubble could not initialize the scratch-render text provider: ${error instanceof Error ? error.message : String(error)}`);
|
|
11516
12402
|
}
|
|
11517
12403
|
let imageResolver;
|
|
11518
|
-
if (renderBackend === "svg-overlay") {
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
12404
|
+
if (renderBackend === "svg-overlay") try {
|
|
12405
|
+
imageResolver = createSvgOverlayImageAdapter(options.svgOverlayImageCapability ?? createAssetManagerSvgOverlayImageCapability(Object.freeze({
|
|
12406
|
+
isRegistered(name) {
|
|
12407
|
+
return getAssetManagerDOMImages().isRegistered(name);
|
|
12408
|
+
},
|
|
12409
|
+
getMimeType(name) {
|
|
12410
|
+
return getAssetManagerDOMImages().getMimeType(name);
|
|
12411
|
+
},
|
|
12412
|
+
resolveDOMImageResource(name) {
|
|
12413
|
+
return getAssetManagerDOMImages().resolveDOMImageResource(name);
|
|
12414
|
+
}
|
|
12415
|
+
})));
|
|
12416
|
+
} catch (error) {
|
|
12417
|
+
throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-004", `Bubble SVG overlay image capability is invalid: ${error instanceof Error ? error.message : String(error)}`);
|
|
12418
|
+
}
|
|
12419
|
+
else imageResolver = options.imageResolver ?? {
|
|
11525
12420
|
isRegistered(name) {
|
|
11526
12421
|
return getAssetExtension().isLoaded({ NAME: name });
|
|
11527
12422
|
},
|
|
@@ -11556,9 +12451,9 @@
|
|
|
11556
12451
|
...imageResolver === void 0 ? {} : { imageResolver },
|
|
11557
12452
|
audio,
|
|
11558
12453
|
textCapability,
|
|
11559
|
-
createSurface({ actor, actorKey, style }) {
|
|
12454
|
+
createSurface({ actor, actorKey, kind, style }) {
|
|
11560
12455
|
if (!isRecord(actor) || typeof actor.id !== "string") throw new BubbleRuntimeAdapterError("BUBBLE-RUNTIME-001", "Bubble actor target is invalid.");
|
|
11561
|
-
return renderBackend === "svg-overlay" ? createSvgOverlaySurface(overlayManager, actor, actorKey, style, scheduler) : createSurface(runtime, actor, actorKey, style, scheduler);
|
|
12456
|
+
return renderBackend === "svg-overlay" ? createSvgOverlaySurface(overlayManager, actor, actorKey, kind, style, scheduler) : createSurface(runtime, actor, actorKey, kind, style, scheduler);
|
|
11562
12457
|
},
|
|
11563
12458
|
...options.scheduler === void 0 ? {} : { scheduler: options.scheduler },
|
|
11564
12459
|
...options.onAnimationError === void 0 ? {} : { onAnimationError: options.onAnimationError }
|
|
@@ -11604,8 +12499,15 @@
|
|
|
11604
12499
|
"easeOut",
|
|
11605
12500
|
"easeInOut"
|
|
11606
12501
|
]);
|
|
12502
|
+
var builtInBubbleStyles = Object.freeze([Object.freeze({
|
|
12503
|
+
name: "say",
|
|
12504
|
+
textStyle: "default"
|
|
12505
|
+
}), Object.freeze({
|
|
12506
|
+
name: "think",
|
|
12507
|
+
textStyle: "default"
|
|
12508
|
+
})]);
|
|
11607
12509
|
var EXTENSION_DOCS_URI = "https://kubohiroya.github.io/turbowarp-bubble/";
|
|
11608
|
-
var EXTENSION_VERSION = "0.
|
|
12510
|
+
var EXTENSION_VERSION = "0.9.0";
|
|
11609
12511
|
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>")}`;
|
|
11610
12512
|
function extensionError(message) {
|
|
11611
12513
|
const error = /* @__PURE__ */ new Error(`[Bubble] ${message}`);
|
|
@@ -11616,7 +12518,7 @@
|
|
|
11616
12518
|
constructor(runtime = Scratch.vm?.runtime, options = {}) {
|
|
11617
12519
|
_defineProperty(this, "runtime", void 0);
|
|
11618
12520
|
_defineProperty(this, "options", void 0);
|
|
11619
|
-
_defineProperty(this, "styles",
|
|
12521
|
+
_defineProperty(this, "styles", new Map(builtInBubbleStyles.map((style) => [style.name, style])));
|
|
11620
12522
|
_defineProperty(this, "handles", /* @__PURE__ */ new Map());
|
|
11621
12523
|
_defineProperty(this, "waits", /* @__PURE__ */ new Map());
|
|
11622
12524
|
_defineProperty(this, "waitScheduler", void 0);
|
|
@@ -11644,11 +12546,13 @@
|
|
|
11644
12546
|
}
|
|
11645
12547
|
getInfo() {
|
|
11646
12548
|
return {
|
|
11647
|
-
id: extensionConfig.id,
|
|
12549
|
+
id: extensionConfig$1.id,
|
|
11648
12550
|
name: Scratch.translate(block_definitions_default$1.extensionName),
|
|
11649
12551
|
docsURI: EXTENSION_DOCS_URI,
|
|
11650
12552
|
blockIconURI: BLOCK_ICON_URI,
|
|
11651
12553
|
color1: "#ff6680",
|
|
12554
|
+
color2: "#e64d6a",
|
|
12555
|
+
color3: "#b83255",
|
|
11652
12556
|
blocks: blockDefinitions.map((block) => this.toScratchBlock(block)),
|
|
11653
12557
|
menus: definitionMenus
|
|
11654
12558
|
};
|
|
@@ -11927,6 +12831,22 @@
|
|
|
11927
12831
|
durationSeconds: seconds
|
|
11928
12832
|
});
|
|
11929
12833
|
}
|
|
12834
|
+
say(args, util) {
|
|
12835
|
+
return this.show("say", Object.freeze({
|
|
12836
|
+
MESSAGE: args.MESSAGE,
|
|
12837
|
+
STYLE: "say"
|
|
12838
|
+
}), util);
|
|
12839
|
+
}
|
|
12840
|
+
think(args, util) {
|
|
12841
|
+
return this.show("think", Object.freeze({
|
|
12842
|
+
MESSAGE: args.MESSAGE,
|
|
12843
|
+
STYLE: "think"
|
|
12844
|
+
}), util);
|
|
12845
|
+
}
|
|
12846
|
+
showWithBubbleStyle(args, util) {
|
|
12847
|
+
const style = this.requireStyle(args.STYLE);
|
|
12848
|
+
return this.show(style.name === "think" ? "think" : "say", args, util);
|
|
12849
|
+
}
|
|
11930
12850
|
sayWithBubbleStyle(args, util) {
|
|
11931
12851
|
return this.show("say", args, util);
|
|
11932
12852
|
}
|
|
@@ -12029,6 +12949,7 @@
|
|
|
12029
12949
|
opcode: block.opcode,
|
|
12030
12950
|
blockType: Scratch.BlockType[block.blockType],
|
|
12031
12951
|
text: Scratch.translate(block.text),
|
|
12952
|
+
...block.hideFromPalette === true ? { hideFromPalette: true } : {},
|
|
12032
12953
|
arguments: Object.fromEntries(Object.entries(block.arguments).map(([name, argument]) => [name, {
|
|
12033
12954
|
type: Scratch.ArgumentType[argument.type],
|
|
12034
12955
|
defaultValue: argument.defaultValue,
|
|
@@ -12153,6 +13074,12 @@
|
|
|
12153
13074
|
const placement = normalizeBubblePlacement(style.placement ?? "up-right");
|
|
12154
13075
|
if (target.isStage && placement.basis === "actor") throw extensionError("actor-relative bubble placement requires a sprite or clone.");
|
|
12155
13076
|
this.cancelWait(target.id, "Bubble wait was replaced.");
|
|
13077
|
+
const scratchDefault = isScratchDefaultBubbleStyleInput(style);
|
|
13078
|
+
const message = scratchDefault ? formatScratchBubbleArgument(args.MESSAGE) : this.toString(args.MESSAGE);
|
|
13079
|
+
if (scratchDefault && message === "") {
|
|
13080
|
+
await this.releaseOwnedTarget(target.id);
|
|
13081
|
+
return;
|
|
13082
|
+
}
|
|
12156
13083
|
const composition = this.getComposition();
|
|
12157
13084
|
let handle;
|
|
12158
13085
|
try {
|
|
@@ -12160,7 +13087,7 @@
|
|
|
12160
13087
|
actor: target,
|
|
12161
13088
|
actorKey: target.id,
|
|
12162
13089
|
kind,
|
|
12163
|
-
text:
|
|
13090
|
+
text: message,
|
|
12164
13091
|
styleName: style.name
|
|
12165
13092
|
});
|
|
12166
13093
|
} catch (error) {
|
|
@@ -12177,7 +13104,7 @@
|
|
|
12177
13104
|
};
|
|
12178
13105
|
//#endregion
|
|
12179
13106
|
//#region src/index.ts
|
|
12180
|
-
if (extensionConfig.unsandboxed && !Scratch.extensions.unsandboxed) throw new Error(`${extensionConfig.name} must run unsandboxed.`);
|
|
13107
|
+
if (extensionConfig$1.unsandboxed && !Scratch.extensions.unsandboxed) throw new Error(`${extensionConfig$1.name} must run unsandboxed.`);
|
|
12181
13108
|
Scratch.extensions.register(new BubbleExtension());
|
|
12182
13109
|
//#endregion
|
|
12183
13110
|
|