@clypra-studio/engine 1.10.1 → 1.10.2
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/dist/{chunk-KUJR5V3B.js → chunk-ZV3RQAUJ.js} +385 -1
- package/dist/chunk-ZV3RQAUJ.js.map +1 -0
- package/dist/{index-n6E8NGM_.d.cts → index-9XU-qEO-.d.cts} +116 -1
- package/dist/{index--k_VrUnv.d.ts → index-Qc3rcMrW.d.ts} +116 -1
- package/dist/index.cjs +392 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -45
- package/dist/index.d.ts +45 -45
- package/dist/index.js +42 -26
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +394 -2
- package/dist/rendering/index.cjs.map +1 -1
- package/dist/rendering/index.d.cts +1 -1
- package/dist/rendering/index.d.ts +1 -1
- package/dist/rendering/index.js +19 -3
- package/package.json +1 -1
- package/dist/chunk-KUJR5V3B.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -198,6 +198,8 @@ __export(index_exports, {
|
|
|
198
198
|
clearRecipeCache: () => clearRecipeCache,
|
|
199
199
|
cloneSceneWithNewIds: () => cloneSceneWithNewIds,
|
|
200
200
|
commandExecutor: () => commandExecutor,
|
|
201
|
+
compileBubblePath: () => compileBubblePath,
|
|
202
|
+
compileBubbleSvg: () => compileBubbleSvg,
|
|
201
203
|
compileSemanticOverlay: () => compileSemanticOverlay,
|
|
202
204
|
compileTextTemplate: () => compileTextTemplate,
|
|
203
205
|
componentRegistry: () => componentRegistry,
|
|
@@ -209,10 +211,12 @@ __export(index_exports, {
|
|
|
209
211
|
createBlankLottie: () => createBlankLottie,
|
|
210
212
|
createBlankScratchTemplate: () => createBlankScratchTemplate,
|
|
211
213
|
createBlankTextEffectConfig: () => createBlankTextEffectConfig,
|
|
214
|
+
createBubbleAssetDefinition: () => createBubbleAssetDefinition,
|
|
212
215
|
createCanvas: () => createCanvas,
|
|
213
216
|
createDefaultRevealTrack: () => createDefaultRevealTrack,
|
|
214
217
|
createDefaultScratchBlock: () => createDefaultScratchBlock,
|
|
215
218
|
createEmptyScene: () => createEmptyScene,
|
|
219
|
+
createFreeformBubbleAssetDefinition: () => createFreeformBubbleAssetDefinition,
|
|
216
220
|
createKeyframed: () => createKeyframed,
|
|
217
221
|
createPulseOpacityTrack: () => createPulseOpacityTrack,
|
|
218
222
|
cubicBezier: () => cubicBezier,
|
|
@@ -228,6 +232,7 @@ __export(index_exports, {
|
|
|
228
232
|
downloadLottieMp4: () => downloadLottieMp4,
|
|
229
233
|
downloadPngSequenceZip: () => downloadPngSequenceZip,
|
|
230
234
|
downloadSceneWebM: () => downloadSceneWebM,
|
|
235
|
+
drawChalkSpeechBubble: () => drawChalkSpeechBubble,
|
|
231
236
|
drawComicBurst: () => drawComicBurst,
|
|
232
237
|
drawPerCharText: () => drawPerCharText,
|
|
233
238
|
drawRibbonBanner: () => drawRibbonBanner,
|
|
@@ -347,7 +352,9 @@ __export(index_exports, {
|
|
|
347
352
|
removeKeyframe: () => removeKeyframe,
|
|
348
353
|
removeTemplateKeyframe: () => removeTemplateKeyframe,
|
|
349
354
|
removeTrack: () => removeTrack,
|
|
355
|
+
renderBubbleAssetDefinition: () => renderBubbleAssetDefinition,
|
|
350
356
|
renderBubbleBackground: () => renderBubbleBackground,
|
|
357
|
+
renderBubblePresetBackground: () => renderBubblePresetBackground,
|
|
351
358
|
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
352
359
|
renderEvaluatedSceneToCanvas: () => renderEvaluatedSceneToCanvas,
|
|
353
360
|
renderPngSequence: () => renderPngSequence,
|
|
@@ -419,6 +426,7 @@ __export(index_exports, {
|
|
|
419
426
|
updateTrack: () => updateTrack,
|
|
420
427
|
updateTrackMatte: () => updateTrackMatte,
|
|
421
428
|
upsertKeyframe: () => upsertKeyframe,
|
|
429
|
+
validateBubbleAssetDefinition: () => validateBubbleAssetDefinition,
|
|
422
430
|
validateEffectDefinition: () => validateEffectDefinition,
|
|
423
431
|
validateEffectDefinitionStrict: () => validateEffectDefinitionStrict,
|
|
424
432
|
validateTextEffectDefinition: () => validateTextEffectDefinition,
|
|
@@ -13929,6 +13937,170 @@ function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strok
|
|
|
13929
13937
|
ctx.fill();
|
|
13930
13938
|
ctx.restore();
|
|
13931
13939
|
}
|
|
13940
|
+
function drawConfigurableSpeechBubble(ctx, x, y, width, height, appearance) {
|
|
13941
|
+
const tailHeight = Math.min(appearance.tailSize, height * 0.38);
|
|
13942
|
+
const bodyHeight = height - tailHeight;
|
|
13943
|
+
const radius = Math.min(appearance.cornerRadius, bodyHeight / 2);
|
|
13944
|
+
const tailCenter = appearance.tailPosition === "bottom-left" ? x + width * 0.2 : appearance.tailPosition === "bottom-right" ? x + width * 0.8 : x + width * 0.5;
|
|
13945
|
+
const tailWidth = Math.min(Math.max(18, appearance.tailSize * 1.5), width * 0.28);
|
|
13946
|
+
ctx.save();
|
|
13947
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, appearance.fillOpacity));
|
|
13948
|
+
ctx.fillStyle = appearance.fillColor;
|
|
13949
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
13950
|
+
ctx.lineWidth = Math.max(0, appearance.strokeWidth);
|
|
13951
|
+
ctx.beginPath();
|
|
13952
|
+
if (typeof ctx.roundRect === "function") {
|
|
13953
|
+
ctx.roundRect(x, y, width, bodyHeight, radius);
|
|
13954
|
+
} else {
|
|
13955
|
+
ctx.rect(x, y, width, bodyHeight);
|
|
13956
|
+
}
|
|
13957
|
+
ctx.fill();
|
|
13958
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
13959
|
+
ctx.beginPath();
|
|
13960
|
+
ctx.moveTo(tailCenter - tailWidth / 2, y + bodyHeight - 1);
|
|
13961
|
+
ctx.quadraticCurveTo(tailCenter - tailWidth * 0.15, y + bodyHeight + tailHeight * 0.7, tailCenter, y + height);
|
|
13962
|
+
ctx.quadraticCurveTo(tailCenter + tailWidth * 0.18, y + bodyHeight + tailHeight * 0.55, tailCenter + tailWidth / 2, y + bodyHeight - 1);
|
|
13963
|
+
ctx.closePath();
|
|
13964
|
+
ctx.fill();
|
|
13965
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
13966
|
+
ctx.restore();
|
|
13967
|
+
}
|
|
13968
|
+
function renderBubblePresetBackground(ctx, preset, x, y, width, height) {
|
|
13969
|
+
const appearance = preset.appearance;
|
|
13970
|
+
if (!appearance) return renderBubbleBackground(ctx, preset.id, x, y, width, height);
|
|
13971
|
+
ctx.save();
|
|
13972
|
+
switch (appearance.shape) {
|
|
13973
|
+
case "chalk":
|
|
13974
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
13975
|
+
break;
|
|
13976
|
+
case "cloud":
|
|
13977
|
+
drawThoughtCloud(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
13978
|
+
break;
|
|
13979
|
+
case "comic":
|
|
13980
|
+
drawComicBurst(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
13981
|
+
break;
|
|
13982
|
+
case "paper":
|
|
13983
|
+
drawTornPaper(ctx, x, y, width, height, appearance.fillColor, true);
|
|
13984
|
+
break;
|
|
13985
|
+
case "ribbon":
|
|
13986
|
+
drawRibbonBanner(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
13987
|
+
break;
|
|
13988
|
+
case "speech":
|
|
13989
|
+
drawConfigurableSpeechBubble(ctx, x, y, width, height, appearance);
|
|
13990
|
+
break;
|
|
13991
|
+
case "rounded": {
|
|
13992
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, appearance.fillOpacity));
|
|
13993
|
+
ctx.fillStyle = appearance.fillColor;
|
|
13994
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
13995
|
+
ctx.lineWidth = Math.max(0, appearance.strokeWidth);
|
|
13996
|
+
ctx.beginPath();
|
|
13997
|
+
if (typeof ctx.roundRect === "function") {
|
|
13998
|
+
ctx.roundRect(x, y, width, height, Math.min(appearance.cornerRadius, height / 2));
|
|
13999
|
+
} else {
|
|
14000
|
+
ctx.rect(x, y, width, height);
|
|
14001
|
+
}
|
|
14002
|
+
ctx.fill();
|
|
14003
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
14004
|
+
break;
|
|
14005
|
+
}
|
|
14006
|
+
}
|
|
14007
|
+
if (appearance.texture === "chalk") {
|
|
14008
|
+
ctx.globalAlpha = 0.55;
|
|
14009
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
14010
|
+
ctx.setLineDash([1, 3]);
|
|
14011
|
+
ctx.lineWidth = Math.max(1, appearance.strokeWidth * 0.7);
|
|
14012
|
+
ctx.strokeRect(x + 1, y + 1, width - 2, height - 2);
|
|
14013
|
+
} else if (appearance.texture === "hatch") {
|
|
14014
|
+
ctx.globalAlpha = 0.22;
|
|
14015
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
14016
|
+
ctx.lineWidth = 1;
|
|
14017
|
+
for (let offset = -height; offset < width; offset += 9) {
|
|
14018
|
+
ctx.beginPath();
|
|
14019
|
+
ctx.moveTo(x + offset, y + height);
|
|
14020
|
+
ctx.lineTo(x + offset + height, y);
|
|
14021
|
+
ctx.stroke();
|
|
14022
|
+
}
|
|
14023
|
+
}
|
|
14024
|
+
ctx.restore();
|
|
14025
|
+
return true;
|
|
14026
|
+
}
|
|
14027
|
+
function drawChalkSpeechBubble(ctx, x, y, width, height) {
|
|
14028
|
+
ctx.save();
|
|
14029
|
+
const tailHeight = Math.min(46, height * 0.3);
|
|
14030
|
+
const bodyHeight = height - tailHeight;
|
|
14031
|
+
const radius = Math.min(36, bodyHeight * 0.25);
|
|
14032
|
+
const tailLeft = x + width * 0.1;
|
|
14033
|
+
const tailRight = x + width * 0.19;
|
|
14034
|
+
const tailTipX = x + width * 0.14;
|
|
14035
|
+
const tailTipY = y + height;
|
|
14036
|
+
const balloonPath = () => {
|
|
14037
|
+
ctx.beginPath();
|
|
14038
|
+
ctx.moveTo(x + radius, y);
|
|
14039
|
+
ctx.lineTo(x + width - radius, y);
|
|
14040
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
14041
|
+
ctx.lineTo(x + width, y + bodyHeight - radius);
|
|
14042
|
+
ctx.quadraticCurveTo(x + width, y + bodyHeight, x + width - radius, y + bodyHeight);
|
|
14043
|
+
ctx.lineTo(tailRight, y + bodyHeight);
|
|
14044
|
+
ctx.quadraticCurveTo(tailRight - width * 0.02, y + bodyHeight + tailHeight * 0.35, tailTipX, tailTipY);
|
|
14045
|
+
ctx.quadraticCurveTo(tailLeft + width * 5e-3, y + bodyHeight + tailHeight * 0.32, tailLeft, y + bodyHeight);
|
|
14046
|
+
ctx.lineTo(x + radius, y + bodyHeight);
|
|
14047
|
+
ctx.quadraticCurveTo(x, y + bodyHeight, x, y + bodyHeight - radius);
|
|
14048
|
+
ctx.lineTo(x, y + radius);
|
|
14049
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
14050
|
+
ctx.closePath();
|
|
14051
|
+
};
|
|
14052
|
+
ctx.fillStyle = "rgba(184, 122, 132, 0.58)";
|
|
14053
|
+
balloonPath();
|
|
14054
|
+
ctx.fill();
|
|
14055
|
+
ctx.save();
|
|
14056
|
+
ctx.beginPath();
|
|
14057
|
+
ctx.moveTo(x + width * 0.2, y + bodyHeight - tailHeight * 0.13);
|
|
14058
|
+
ctx.quadraticCurveTo(x + width * 0.48, y + bodyHeight + tailHeight * 0.37, x + width * 0.91, y + bodyHeight - tailHeight * 0.02);
|
|
14059
|
+
ctx.quadraticCurveTo(x + width * 0.66, y + bodyHeight + tailHeight * 0.72, x + width * 0.24, y + bodyHeight + tailHeight * 0.44);
|
|
14060
|
+
ctx.closePath();
|
|
14061
|
+
ctx.clip();
|
|
14062
|
+
ctx.shadowColor = "rgba(222, 228, 105, 0.32)";
|
|
14063
|
+
ctx.shadowBlur = 3;
|
|
14064
|
+
ctx.strokeStyle = "rgba(203, 211, 76, 0.52)";
|
|
14065
|
+
ctx.lineWidth = 1.25;
|
|
14066
|
+
for (let offset = -height; offset < width; offset += 9) {
|
|
14067
|
+
ctx.beginPath();
|
|
14068
|
+
ctx.moveTo(x + offset, y + height);
|
|
14069
|
+
ctx.lineTo(x + offset + height, y);
|
|
14070
|
+
ctx.stroke();
|
|
14071
|
+
}
|
|
14072
|
+
ctx.shadowBlur = 0;
|
|
14073
|
+
ctx.strokeStyle = "rgba(255, 250, 196, 0.48)";
|
|
14074
|
+
ctx.lineWidth = 0.8;
|
|
14075
|
+
for (let offset = 0; offset < width + height; offset += 12) {
|
|
14076
|
+
ctx.beginPath();
|
|
14077
|
+
ctx.moveTo(x + offset, y);
|
|
14078
|
+
ctx.lineTo(x + offset - height, y + height);
|
|
14079
|
+
ctx.stroke();
|
|
14080
|
+
}
|
|
14081
|
+
ctx.restore();
|
|
14082
|
+
ctx.strokeStyle = "rgba(255, 253, 246, 0.82)";
|
|
14083
|
+
ctx.lineCap = "round";
|
|
14084
|
+
ctx.lineWidth = 1.35;
|
|
14085
|
+
balloonPath();
|
|
14086
|
+
ctx.stroke();
|
|
14087
|
+
const edgeSegments = 66;
|
|
14088
|
+
for (let index = 0; index < edgeSegments; index++) {
|
|
14089
|
+
const pointX = x + width * (index / edgeSegments);
|
|
14090
|
+
const topNoise = (pseudoNoise(index + 91) - 0.5) * 4;
|
|
14091
|
+
const strokeLength = 0.8 + pseudoNoise(index + 143) * 2.1;
|
|
14092
|
+
ctx.lineWidth = 0.6 + pseudoNoise(index + 211) * 1.1;
|
|
14093
|
+
ctx.beginPath();
|
|
14094
|
+
ctx.moveTo(pointX, y + topNoise);
|
|
14095
|
+
ctx.lineTo(pointX + strokeLength, y + topNoise + (pseudoNoise(index + 19) - 0.5) * 2);
|
|
14096
|
+
ctx.stroke();
|
|
14097
|
+
ctx.beginPath();
|
|
14098
|
+
ctx.moveTo(pointX, y + bodyHeight + topNoise);
|
|
14099
|
+
ctx.lineTo(pointX + strokeLength, y + bodyHeight + topNoise + (pseudoNoise(index + 37) - 0.5) * 2);
|
|
14100
|
+
ctx.stroke();
|
|
14101
|
+
}
|
|
14102
|
+
ctx.restore();
|
|
14103
|
+
}
|
|
13932
14104
|
function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
|
|
13933
14105
|
ctx.save();
|
|
13934
14106
|
ctx.fillStyle = fillColor;
|
|
@@ -14017,6 +14189,11 @@ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
|
14017
14189
|
ctx.restore();
|
|
14018
14190
|
return true;
|
|
14019
14191
|
}
|
|
14192
|
+
if (presetId === "bubble-speech-chalk-rose") {
|
|
14193
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
14194
|
+
ctx.restore();
|
|
14195
|
+
return true;
|
|
14196
|
+
}
|
|
14020
14197
|
if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
|
|
14021
14198
|
drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
|
|
14022
14199
|
ctx.restore();
|
|
@@ -14050,6 +14227,213 @@ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
|
14050
14227
|
return true;
|
|
14051
14228
|
}
|
|
14052
14229
|
|
|
14230
|
+
// src/rendering/bubbleAssets.ts
|
|
14231
|
+
var createBubbleAssetDefinition = () => ({
|
|
14232
|
+
schemaVersion: 1,
|
|
14233
|
+
type: "clypra.textBubble",
|
|
14234
|
+
coordinateSpace: "normalized",
|
|
14235
|
+
geometry: { kind: "parametric-path", body: { cornerRadius: 0.12 }, tail: { enabled: true, side: "bottom", anchor: 0.22, width: 0.18, depth: 0.2, curvature: 0.55 } },
|
|
14236
|
+
layers: { fill: { color: "#7c3aed", opacity: 0.9 }, outline: { color: "#ffffff", width: 0.018, roughness: 0, seed: 1 } },
|
|
14237
|
+
textLayout: { padding: [0.1, 0.1, 0.18, 0.1], alignment: "center", overflow: "grow" }
|
|
14238
|
+
});
|
|
14239
|
+
var createFreeformBubbleAssetDefinition = () => ({
|
|
14240
|
+
...createBubbleAssetDefinition(),
|
|
14241
|
+
geometry: {
|
|
14242
|
+
kind: "freeform-path",
|
|
14243
|
+
closed: true,
|
|
14244
|
+
commands: [
|
|
14245
|
+
{ kind: "move", to: [0.12, 0.04] },
|
|
14246
|
+
{ kind: "line", to: [0.88, 0.04] },
|
|
14247
|
+
{ kind: "quadratic", control: [0.98, 0.04], to: [0.98, 0.16] },
|
|
14248
|
+
{ kind: "line", to: [0.98, 0.7] },
|
|
14249
|
+
{ kind: "quadratic", control: [0.98, 0.82], to: [0.86, 0.82] },
|
|
14250
|
+
{ kind: "line", to: [0.38, 0.82] },
|
|
14251
|
+
{ kind: "line", to: [0.22, 1] },
|
|
14252
|
+
{ kind: "line", to: [0.27, 0.82] },
|
|
14253
|
+
{ kind: "line", to: [0.12, 0.82] },
|
|
14254
|
+
{ kind: "quadratic", control: [0.02, 0.82], to: [0.02, 0.7] },
|
|
14255
|
+
{ kind: "line", to: [0.02, 0.16] },
|
|
14256
|
+
{ kind: "quadratic", control: [0.02, 0.04], to: [0.12, 0.04] },
|
|
14257
|
+
{ kind: "close" }
|
|
14258
|
+
]
|
|
14259
|
+
}
|
|
14260
|
+
});
|
|
14261
|
+
var clamp = (value) => Math.max(0, Math.min(1, value));
|
|
14262
|
+
function compileBubblePath(definition) {
|
|
14263
|
+
if (definition.geometry.kind === "freeform-path") {
|
|
14264
|
+
return definition.geometry.commands.map((command) => {
|
|
14265
|
+
if (command.kind === "close") return "Z";
|
|
14266
|
+
if (command.kind === "move") return `M ${command.to[0]} ${command.to[1]}`;
|
|
14267
|
+
if (command.kind === "line") return `L ${command.to[0]} ${command.to[1]}`;
|
|
14268
|
+
if (command.kind === "quadratic") return `Q ${command.control[0]} ${command.control[1]} ${command.to[0]} ${command.to[1]}`;
|
|
14269
|
+
if (command.kind === "cubic") return `C ${command.control1[0]} ${command.control1[1]} ${command.control2[0]} ${command.control2[1]} ${command.to[0]} ${command.to[1]}`;
|
|
14270
|
+
return "";
|
|
14271
|
+
}).join(" ");
|
|
14272
|
+
}
|
|
14273
|
+
const { body, tail } = definition.geometry;
|
|
14274
|
+
const r = clamp(body.cornerRadius) * 0.5;
|
|
14275
|
+
const anchor = clamp(tail.anchor);
|
|
14276
|
+
const tailWidth = clamp(tail.width) * 0.5;
|
|
14277
|
+
const depth = clamp(tail.depth);
|
|
14278
|
+
const left = clamp(anchor - tailWidth);
|
|
14279
|
+
const right = clamp(anchor + tailWidth);
|
|
14280
|
+
const bodyPath = `M ${r} 0 H ${1 - r} Q 1 0 1 ${r} V ${1 - r} Q 1 1 ${1 - r} 1 H ${r} Q 0 1 0 ${1 - r} V ${r} Q 0 0 ${r} 0 Z`;
|
|
14281
|
+
if (!tail.enabled) return bodyPath;
|
|
14282
|
+
if (tail.side === "bottom") {
|
|
14283
|
+
return `M ${r} 0 H ${1 - r} Q 1 0 1 ${r} V ${1 - r} Q 1 1 ${1 - r} 1 H ${right} Q ${anchor + tailWidth * 0.35} ${1 + depth * tail.curvature} ${anchor} ${1 + depth} Q ${anchor - tailWidth * 0.35} ${1 + depth * tail.curvature} ${left} 1 H ${r} Q 0 1 0 ${1 - r} V ${r} Q 0 0 ${r} 0 Z`;
|
|
14284
|
+
}
|
|
14285
|
+
if (tail.side === "top") {
|
|
14286
|
+
return `M ${r} 0 H ${left} Q ${anchor - tailWidth * 0.35} ${-depth * tail.curvature} ${anchor} ${-depth} Q ${anchor + tailWidth * 0.35} ${-depth * tail.curvature} ${right} 0 H ${1 - r} Q 1 0 1 ${r} V ${1 - r} Q 1 1 ${1 - r} 1 H ${r} Q 0 1 0 ${1 - r} V ${r} Q 0 0 ${r} 0 Z`;
|
|
14287
|
+
}
|
|
14288
|
+
if (tail.side === "left") {
|
|
14289
|
+
return `M ${r} 0 H ${1 - r} Q 1 0 1 ${r} V ${1 - r} Q 1 1 ${1 - r} 1 H ${r} Q 0 1 0 ${1 - r} V ${right} Q ${-depth * tail.curvature} ${anchor + tailWidth * 0.35} ${-depth} ${anchor} Q ${-depth * tail.curvature} ${anchor - tailWidth * 0.35} 0 ${left} V ${r} Q 0 0 ${r} 0 Z`;
|
|
14290
|
+
}
|
|
14291
|
+
return `M ${r} 0 H ${1 - r} Q 1 0 1 ${r} V ${left} Q ${1 + depth * tail.curvature} ${anchor - tailWidth * 0.35} ${1 + depth} ${anchor} Q ${1 + depth * tail.curvature} ${anchor + tailWidth * 0.35} 1 ${right} V ${1 - r} Q 1 1 ${1 - r} 1 H ${r} Q 0 1 0 ${1 - r} V ${r} Q 0 0 ${r} 0 Z`;
|
|
14292
|
+
}
|
|
14293
|
+
function compileBubbleSvg(definition, width = 1e3, height = 700) {
|
|
14294
|
+
const { fill, outline, accent } = definition.layers;
|
|
14295
|
+
const texture = accent?.texture === "hatch" ? `<pattern id="hatch" width="24" height="24" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><line x1="0" y1="0" x2="0" y2="24" stroke="${accent.color}" stroke-opacity="${accent.opacity}" stroke-width="3" /></pattern>` : "";
|
|
14296
|
+
const textureOverlay = accent?.texture === "hatch" ? `<path d="${compileBubblePath(definition)}" fill="url(#hatch)" />` : "";
|
|
14297
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="-0.25 -0.25 1.5 1.5"><defs>${texture}</defs><path d="${compileBubblePath(definition)}" fill="${fill.color}" fill-opacity="${fill.opacity}" stroke="${outline.color}" stroke-width="${outline.width}" vector-effect="non-scaling-stroke" />${textureOverlay}</svg>`;
|
|
14298
|
+
}
|
|
14299
|
+
function traceBubbleSilhouette(ctx, x, y, width, height, radius, tail, tailDepth) {
|
|
14300
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
14301
|
+
const anchor = clamp(tail.anchor);
|
|
14302
|
+
const halfTail = clamp(tail.width) * (tail.side === "left" || tail.side === "right" ? height : width) / 2;
|
|
14303
|
+
const along = tail.side === "left" || tail.side === "right" ? y + height * anchor : x + width * anchor;
|
|
14304
|
+
ctx.beginPath();
|
|
14305
|
+
ctx.moveTo(x + r, y);
|
|
14306
|
+
if (tail.enabled && tail.side === "top") {
|
|
14307
|
+
ctx.lineTo(along - halfTail, y);
|
|
14308
|
+
ctx.quadraticCurveTo(along - halfTail * 0.35, y - tailDepth * tail.curvature, along, y - tailDepth);
|
|
14309
|
+
ctx.quadraticCurveTo(along + halfTail * 0.35, y - tailDepth * tail.curvature, along + halfTail, y);
|
|
14310
|
+
}
|
|
14311
|
+
ctx.lineTo(x + width - r, y);
|
|
14312
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
|
|
14313
|
+
if (tail.enabled && tail.side === "right") {
|
|
14314
|
+
ctx.lineTo(x + width, along - halfTail);
|
|
14315
|
+
ctx.quadraticCurveTo(x + width + tailDepth * tail.curvature, along - halfTail * 0.35, x + width + tailDepth, along);
|
|
14316
|
+
ctx.quadraticCurveTo(x + width + tailDepth * tail.curvature, along + halfTail * 0.35, x + width, along + halfTail);
|
|
14317
|
+
}
|
|
14318
|
+
ctx.lineTo(x + width, y + height - r);
|
|
14319
|
+
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
|
|
14320
|
+
if (tail.enabled && tail.side === "bottom") {
|
|
14321
|
+
ctx.lineTo(along + halfTail, y + height);
|
|
14322
|
+
ctx.quadraticCurveTo(along + halfTail * 0.35, y + height + tailDepth * tail.curvature, along, y + height + tailDepth);
|
|
14323
|
+
ctx.quadraticCurveTo(along - halfTail * 0.35, y + height + tailDepth * tail.curvature, along - halfTail, y + height);
|
|
14324
|
+
}
|
|
14325
|
+
ctx.lineTo(x + r, y + height);
|
|
14326
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
|
|
14327
|
+
if (tail.enabled && tail.side === "left") {
|
|
14328
|
+
ctx.lineTo(x, along + halfTail);
|
|
14329
|
+
ctx.quadraticCurveTo(x - tailDepth * tail.curvature, along + halfTail * 0.35, x - tailDepth, along);
|
|
14330
|
+
ctx.quadraticCurveTo(x - tailDepth * tail.curvature, along - halfTail * 0.35, x, along - halfTail);
|
|
14331
|
+
}
|
|
14332
|
+
ctx.lineTo(x, y + r);
|
|
14333
|
+
ctx.quadraticCurveTo(x, y, x + r, y);
|
|
14334
|
+
ctx.closePath();
|
|
14335
|
+
}
|
|
14336
|
+
function renderBubbleAssetDefinition(ctx, definition, x, y, width, height) {
|
|
14337
|
+
if (definition.geometry.kind === "freeform-path") {
|
|
14338
|
+
renderFreeformBubbleAssetDefinition(ctx, definition, x, y, width, height);
|
|
14339
|
+
return;
|
|
14340
|
+
}
|
|
14341
|
+
const { tail, body } = definition.geometry;
|
|
14342
|
+
const tailDepth = tail.enabled ? clamp(tail.depth) * (tail.side === "left" || tail.side === "right" ? width : height) : 0;
|
|
14343
|
+
const bodyX = x + (tail.side === "left" ? tailDepth : 0);
|
|
14344
|
+
const bodyY = y + (tail.side === "top" ? tailDepth : 0);
|
|
14345
|
+
const bodyWidth = width - (tail.side === "left" || tail.side === "right" ? tailDepth : 0);
|
|
14346
|
+
const bodyHeight = height - (tail.side === "top" || tail.side === "bottom" ? tailDepth : 0);
|
|
14347
|
+
const radius = clamp(body.cornerRadius) * Math.min(bodyWidth, bodyHeight) / 2;
|
|
14348
|
+
ctx.save();
|
|
14349
|
+
traceBubbleSilhouette(ctx, bodyX, bodyY, bodyWidth, bodyHeight, radius, tail, tailDepth);
|
|
14350
|
+
ctx.globalAlpha = definition.layers.fill.opacity;
|
|
14351
|
+
ctx.fillStyle = definition.layers.fill.color;
|
|
14352
|
+
ctx.fill();
|
|
14353
|
+
const accent = definition.layers.accent;
|
|
14354
|
+
if (accent && accent.texture !== "none") {
|
|
14355
|
+
ctx.save();
|
|
14356
|
+
ctx.clip();
|
|
14357
|
+
ctx.globalAlpha = accent.opacity;
|
|
14358
|
+
ctx.strokeStyle = accent.color;
|
|
14359
|
+
ctx.lineWidth = Math.max(1, Math.min(width, height) * 6e-3);
|
|
14360
|
+
if (accent.texture === "hatch") {
|
|
14361
|
+
const spacing = Math.max(5, Math.min(width, height) * 0.09);
|
|
14362
|
+
for (let offset = -height; offset < width + height; offset += spacing) {
|
|
14363
|
+
ctx.beginPath();
|
|
14364
|
+
ctx.moveTo(x + offset, y + height);
|
|
14365
|
+
ctx.lineTo(x + offset + height, y);
|
|
14366
|
+
ctx.stroke();
|
|
14367
|
+
}
|
|
14368
|
+
} else {
|
|
14369
|
+
let state = definition.layers.outline.seed >>> 0;
|
|
14370
|
+
const nextRandom = () => {
|
|
14371
|
+
state = state * 1664525 + 1013904223 >>> 0;
|
|
14372
|
+
return state / 4294967296;
|
|
14373
|
+
};
|
|
14374
|
+
const count = Math.max(18, Math.round(width * height / 700));
|
|
14375
|
+
for (let index = 0; index < count; index += 1) {
|
|
14376
|
+
const px = x + nextRandom() * width;
|
|
14377
|
+
const py = y + nextRandom() * height;
|
|
14378
|
+
const length = 1 + nextRandom() * Math.min(width, height) * 0.025;
|
|
14379
|
+
ctx.beginPath();
|
|
14380
|
+
ctx.moveTo(px, py);
|
|
14381
|
+
ctx.lineTo(px + length, py);
|
|
14382
|
+
ctx.stroke();
|
|
14383
|
+
}
|
|
14384
|
+
}
|
|
14385
|
+
ctx.restore();
|
|
14386
|
+
}
|
|
14387
|
+
if (definition.layers.outline.width > 0) {
|
|
14388
|
+
ctx.globalAlpha = 1;
|
|
14389
|
+
ctx.strokeStyle = definition.layers.outline.color;
|
|
14390
|
+
ctx.lineWidth = definition.layers.outline.width * Math.min(width, height);
|
|
14391
|
+
ctx.stroke();
|
|
14392
|
+
}
|
|
14393
|
+
ctx.restore();
|
|
14394
|
+
}
|
|
14395
|
+
function traceFreeformPath(ctx, definition, x, y, width, height) {
|
|
14396
|
+
ctx.beginPath();
|
|
14397
|
+
for (const command of definition.geometry.commands) {
|
|
14398
|
+
if (command.kind === "close") ctx.closePath();
|
|
14399
|
+
else if (command.kind === "move") ctx.moveTo(x + command.to[0] * width, y + command.to[1] * height);
|
|
14400
|
+
else if (command.kind === "line") ctx.lineTo(x + command.to[0] * width, y + command.to[1] * height);
|
|
14401
|
+
else if (command.kind === "quadratic") ctx.quadraticCurveTo(x + command.control[0] * width, y + command.control[1] * height, x + command.to[0] * width, y + command.to[1] * height);
|
|
14402
|
+
else if (command.kind === "cubic") ctx.bezierCurveTo(x + command.control1[0] * width, y + command.control1[1] * height, x + command.control2[0] * width, y + command.control2[1] * height, x + command.to[0] * width, y + command.to[1] * height);
|
|
14403
|
+
}
|
|
14404
|
+
}
|
|
14405
|
+
function renderFreeformBubbleAssetDefinition(ctx, definition, x, y, width, height) {
|
|
14406
|
+
ctx.save();
|
|
14407
|
+
traceFreeformPath(ctx, definition, x, y, width, height);
|
|
14408
|
+
ctx.globalAlpha = definition.layers.fill.opacity;
|
|
14409
|
+
ctx.fillStyle = definition.layers.fill.color;
|
|
14410
|
+
ctx.fill();
|
|
14411
|
+
if (definition.layers.outline.width > 0) {
|
|
14412
|
+
ctx.globalAlpha = 1;
|
|
14413
|
+
ctx.strokeStyle = definition.layers.outline.color;
|
|
14414
|
+
ctx.lineWidth = definition.layers.outline.width * Math.min(width, height);
|
|
14415
|
+
ctx.stroke();
|
|
14416
|
+
}
|
|
14417
|
+
ctx.restore();
|
|
14418
|
+
}
|
|
14419
|
+
function validateBubbleAssetDefinition(definition) {
|
|
14420
|
+
const errors = [];
|
|
14421
|
+
if (definition.schemaVersion !== 1 || definition.type !== "clypra.textBubble") errors.push("Unsupported bubble asset schema.");
|
|
14422
|
+
if (!/^#[0-9a-f]{6}$/i.test(definition.layers.fill.color)) errors.push("Fill color must be a six-digit hex value.");
|
|
14423
|
+
if (definition.layers.fill.opacity < 0 || definition.layers.fill.opacity > 1) errors.push("Fill opacity must be between 0 and 1.");
|
|
14424
|
+
if (!/^#[0-9a-f]{6}$/i.test(definition.layers.outline.color)) errors.push("Outline color must be a six-digit hex value.");
|
|
14425
|
+
if (definition.layers.outline.width < 0 || definition.layers.outline.width > 0.1) errors.push("Outline width must be normalized between 0 and 0.1.");
|
|
14426
|
+
if (definition.geometry.kind === "parametric-path") {
|
|
14427
|
+
if (definition.geometry.body.cornerRadius < 0 || definition.geometry.body.cornerRadius > 1) errors.push("Corner radius must be normalized.");
|
|
14428
|
+
if (definition.geometry.tail.anchor < 0 || definition.geometry.tail.anchor > 1) errors.push("Tail anchor must be normalized.");
|
|
14429
|
+
if (definition.geometry.tail.width < 0 || definition.geometry.tail.width > 1 || definition.geometry.tail.depth < 0 || definition.geometry.tail.depth > 1) errors.push("Tail width and depth must be normalized.");
|
|
14430
|
+
} else if (definition.geometry.commands.length < 4 || !definition.geometry.commands.some((command) => command.kind === "close")) {
|
|
14431
|
+
errors.push("Freeform bubble paths must contain a closed silhouette.");
|
|
14432
|
+
}
|
|
14433
|
+
if (definition.textLayout.padding.some((value) => value < 0 || value > 0.5)) errors.push("Text padding must be normalized between 0 and 0.5.");
|
|
14434
|
+
return errors;
|
|
14435
|
+
}
|
|
14436
|
+
|
|
14053
14437
|
// src/rendering/index.ts
|
|
14054
14438
|
function renderCanonicalToCanvas(ctx, input) {
|
|
14055
14439
|
if (input.capability === "text-template") {
|
|
@@ -25072,6 +25456,8 @@ var VERSION = "1.4.0";
|
|
|
25072
25456
|
clearRecipeCache,
|
|
25073
25457
|
cloneSceneWithNewIds,
|
|
25074
25458
|
commandExecutor,
|
|
25459
|
+
compileBubblePath,
|
|
25460
|
+
compileBubbleSvg,
|
|
25075
25461
|
compileSemanticOverlay,
|
|
25076
25462
|
compileTextTemplate,
|
|
25077
25463
|
componentRegistry,
|
|
@@ -25083,10 +25469,12 @@ var VERSION = "1.4.0";
|
|
|
25083
25469
|
createBlankLottie,
|
|
25084
25470
|
createBlankScratchTemplate,
|
|
25085
25471
|
createBlankTextEffectConfig,
|
|
25472
|
+
createBubbleAssetDefinition,
|
|
25086
25473
|
createCanvas,
|
|
25087
25474
|
createDefaultRevealTrack,
|
|
25088
25475
|
createDefaultScratchBlock,
|
|
25089
25476
|
createEmptyScene,
|
|
25477
|
+
createFreeformBubbleAssetDefinition,
|
|
25090
25478
|
createKeyframed,
|
|
25091
25479
|
createPulseOpacityTrack,
|
|
25092
25480
|
cubicBezier,
|
|
@@ -25102,6 +25490,7 @@ var VERSION = "1.4.0";
|
|
|
25102
25490
|
downloadLottieMp4,
|
|
25103
25491
|
downloadPngSequenceZip,
|
|
25104
25492
|
downloadSceneWebM,
|
|
25493
|
+
drawChalkSpeechBubble,
|
|
25105
25494
|
drawComicBurst,
|
|
25106
25495
|
drawPerCharText,
|
|
25107
25496
|
drawRibbonBanner,
|
|
@@ -25221,7 +25610,9 @@ var VERSION = "1.4.0";
|
|
|
25221
25610
|
removeKeyframe,
|
|
25222
25611
|
removeTemplateKeyframe,
|
|
25223
25612
|
removeTrack,
|
|
25613
|
+
renderBubbleAssetDefinition,
|
|
25224
25614
|
renderBubbleBackground,
|
|
25615
|
+
renderBubblePresetBackground,
|
|
25225
25616
|
renderCanonicalToCanvas,
|
|
25226
25617
|
renderEvaluatedSceneToCanvas,
|
|
25227
25618
|
renderPngSequence,
|
|
@@ -25293,6 +25684,7 @@ var VERSION = "1.4.0";
|
|
|
25293
25684
|
updateTrack,
|
|
25294
25685
|
updateTrackMatte,
|
|
25295
25686
|
upsertKeyframe,
|
|
25687
|
+
validateBubbleAssetDefinition,
|
|
25296
25688
|
validateEffectDefinition,
|
|
25297
25689
|
validateEffectDefinitionStrict,
|
|
25298
25690
|
validateTextEffectDefinition,
|