@clypra-studio/engine 1.10.0 → 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/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,8 +232,14 @@ __export(index_exports, {
228
232
  downloadLottieMp4: () => downloadLottieMp4,
229
233
  downloadPngSequenceZip: () => downloadPngSequenceZip,
230
234
  downloadSceneWebM: () => downloadSceneWebM,
235
+ drawChalkSpeechBubble: () => drawChalkSpeechBubble,
236
+ drawComicBurst: () => drawComicBurst,
231
237
  drawPerCharText: () => drawPerCharText,
238
+ drawRibbonBanner: () => drawRibbonBanner,
232
239
  drawRoundedRect: () => drawRoundedRect,
240
+ drawSpeechBubble: () => drawSpeechBubble,
241
+ drawThoughtCloud: () => drawThoughtCloud,
242
+ drawTornPaper: () => drawTornPaper,
233
243
  duplicateTrackAtPlayhead: () => duplicateTrackAtPlayhead,
234
244
  ease: () => ease,
235
245
  editorCommandSystem: () => editorCommandSystem,
@@ -333,6 +343,7 @@ __export(index_exports, {
333
343
  propertyInspectorEngine: () => propertyInspectorEngine,
334
344
  propertyInterpolator: () => propertyInterpolator,
335
345
  pruneTracksForLayer: () => pruneTracksForLayer,
346
+ pseudoNoise: () => pseudoNoise,
336
347
  rainbowCharFillColors: () => rainbowCharFillColors,
337
348
  readLayerScalar: () => readLayerScalar,
338
349
  readStyleFromLottieLayer: () => readStyleFromLottieLayer,
@@ -341,6 +352,9 @@ __export(index_exports, {
341
352
  removeKeyframe: () => removeKeyframe,
342
353
  removeTemplateKeyframe: () => removeTemplateKeyframe,
343
354
  removeTrack: () => removeTrack,
355
+ renderBubbleAssetDefinition: () => renderBubbleAssetDefinition,
356
+ renderBubbleBackground: () => renderBubbleBackground,
357
+ renderBubblePresetBackground: () => renderBubblePresetBackground,
344
358
  renderCanonicalToCanvas: () => renderCanonicalToCanvas,
345
359
  renderEvaluatedSceneToCanvas: () => renderEvaluatedSceneToCanvas,
346
360
  renderPngSequence: () => renderPngSequence,
@@ -354,6 +368,7 @@ __export(index_exports, {
354
368
  resolveAnchorPosition: () => resolveAnchorPosition,
355
369
  resolveAnimatedScalar: () => resolveAnimatedScalar,
356
370
  resolveBehaviorToAnimationSpec: () => resolveBehaviorToAnimationSpec,
371
+ resolveBubbleLayout: () => resolveBubbleLayout,
357
372
  resolveConform: () => resolveConform,
358
373
  resolveDocumentForBreakpoint: () => resolveDocumentForBreakpoint,
359
374
  resolveExportCanvasDimensions: () => resolveExportCanvasDimensions,
@@ -411,6 +426,7 @@ __export(index_exports, {
411
426
  updateTrack: () => updateTrack,
412
427
  updateTrackMatte: () => updateTrackMatte,
413
428
  upsertKeyframe: () => upsertKeyframe,
429
+ validateBubbleAssetDefinition: () => validateBubbleAssetDefinition,
414
430
  validateEffectDefinition: () => validateEffectDefinition,
415
431
  validateEffectDefinitionStrict: () => validateEffectDefinitionStrict,
416
432
  validateTextEffectDefinition: () => validateTextEffectDefinition,
@@ -13804,6 +13820,620 @@ function renderTextTemplateToCanvas(ctx, input) {
13804
13820
  };
13805
13821
  }
13806
13822
 
13823
+ // src/rendering/textBubbles.ts
13824
+ function resolveBubbleLayout(textWidth, textHeight, layout) {
13825
+ const p = layout.padding ?? {
13826
+ top: 14,
13827
+ right: 18,
13828
+ bottom: 14,
13829
+ left: 18
13830
+ };
13831
+ const rawOuterW = textWidth + p.left + p.right;
13832
+ const rawOuterH = textHeight + p.top + p.bottom;
13833
+ let outerWidth = Math.max(rawOuterW, layout.minWidth);
13834
+ let outerHeight = Math.max(rawOuterH, layout.minHeight);
13835
+ if (layout.preserveAspectRatio && layout.minWidth > 0 && layout.minHeight > 0) {
13836
+ const aspect = layout.minWidth / layout.minHeight;
13837
+ const currentAspect = outerWidth / outerHeight;
13838
+ if (currentAspect > aspect) {
13839
+ outerHeight = outerWidth / aspect;
13840
+ } else {
13841
+ outerWidth = outerHeight * aspect;
13842
+ }
13843
+ }
13844
+ const textOffsetX = (p.left - p.right) / 2;
13845
+ const textOffsetY = (p.top - p.bottom) / 2;
13846
+ return {
13847
+ outerWidth,
13848
+ outerHeight,
13849
+ textOffsetX,
13850
+ textOffsetY,
13851
+ contentWidth: outerWidth - p.left - p.right,
13852
+ contentHeight: outerHeight - p.top - p.bottom
13853
+ };
13854
+ }
13855
+
13856
+ // src/rendering/bubbleRenderer.ts
13857
+ function pseudoNoise(seed) {
13858
+ const x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
13859
+ return x - Math.floor(x);
13860
+ }
13861
+ function drawTornPaper(ctx, x, y, width, height, fillColor = "#faf9f6", shadow = true) {
13862
+ ctx.save();
13863
+ if (shadow) {
13864
+ ctx.shadowColor = "rgba(0, 0, 0, 0.35)";
13865
+ ctx.shadowBlur = 12;
13866
+ ctx.shadowOffsetX = 0;
13867
+ ctx.shadowOffsetY = 4;
13868
+ }
13869
+ ctx.fillStyle = fillColor;
13870
+ ctx.beginPath();
13871
+ const steps = Math.max(16, Math.floor(width / 14));
13872
+ const stepW = width / steps;
13873
+ ctx.moveTo(x, y + 6);
13874
+ for (let i = 0; i <= steps; i++) {
13875
+ const curX = x + i * stepW;
13876
+ const n = pseudoNoise(i * 1.37 + 10);
13877
+ const wave2 = Math.sin(i / steps * Math.PI * 3) * 3;
13878
+ const curY = y + (n * 5 - 2.5) + wave2;
13879
+ if (i === 0) ctx.lineTo(curX, curY);
13880
+ else ctx.lineTo(curX, curY);
13881
+ }
13882
+ ctx.lineTo(x + width, y + height - 6);
13883
+ for (let i = steps; i >= 0; i--) {
13884
+ const curX = x + i * stepW;
13885
+ const n = pseudoNoise(i * 2.19 + 50);
13886
+ const wave2 = Math.sin(i / steps * Math.PI * 2) * 4;
13887
+ const curY = y + height + (n * 6 - 3) + wave2;
13888
+ ctx.lineTo(curX, curY);
13889
+ }
13890
+ ctx.lineTo(x, y + 6);
13891
+ ctx.closePath();
13892
+ ctx.fill();
13893
+ if (shadow) {
13894
+ ctx.shadowColor = "transparent";
13895
+ ctx.shadowBlur = 0;
13896
+ }
13897
+ const paperGrad = ctx.createLinearGradient(x, y, x, y + height);
13898
+ paperGrad.addColorStop(0, "rgba(255, 255, 255, 0.4)");
13899
+ paperGrad.addColorStop(0.5, "rgba(0, 0, 0, 0.02)");
13900
+ paperGrad.addColorStop(1, "rgba(0, 0, 0, 0.06)");
13901
+ ctx.fillStyle = paperGrad;
13902
+ ctx.fill();
13903
+ ctx.restore();
13904
+ }
13905
+ function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2, radius = 16) {
13906
+ ctx.save();
13907
+ const tailH = Math.min(16, height * 0.25);
13908
+ const bodyH = height - tailH;
13909
+ ctx.fillStyle = fillColor;
13910
+ ctx.strokeStyle = strokeColor;
13911
+ ctx.lineWidth = strokeWidth;
13912
+ ctx.beginPath();
13913
+ if (typeof ctx.roundRect === "function") {
13914
+ ctx.roundRect(x, y, width, bodyH, radius);
13915
+ } else {
13916
+ ctx.rect(x, y, width, bodyH);
13917
+ }
13918
+ ctx.fill();
13919
+ if (strokeWidth > 0) ctx.stroke();
13920
+ const tailBaseX = x + width * 0.25;
13921
+ const tailBaseW = Math.min(24, width * 0.2);
13922
+ const tailTipX = x + width * 0.15;
13923
+ const tailTipY = y + height;
13924
+ ctx.beginPath();
13925
+ ctx.moveTo(tailBaseX, y + bodyH - 2);
13926
+ ctx.quadraticCurveTo(tailBaseX + 2, y + bodyH + tailH * 0.6, tailTipX, tailTipY);
13927
+ ctx.quadraticCurveTo(tailBaseX + tailBaseW * 0.7, y + bodyH + tailH * 0.4, tailBaseX + tailBaseW, y + bodyH - 2);
13928
+ ctx.closePath();
13929
+ ctx.fill();
13930
+ if (strokeWidth > 0) ctx.stroke();
13931
+ ctx.beginPath();
13932
+ if (typeof ctx.roundRect === "function") {
13933
+ ctx.roundRect(x + 1, y + 1, width - 2, bodyH - 2, radius);
13934
+ } else {
13935
+ ctx.rect(x + 1, y + 1, width - 2, bodyH - 2);
13936
+ }
13937
+ ctx.fill();
13938
+ ctx.restore();
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
+ }
14104
+ function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
14105
+ ctx.save();
14106
+ ctx.fillStyle = fillColor;
14107
+ ctx.strokeStyle = strokeColor;
14108
+ ctx.lineWidth = strokeWidth;
14109
+ const cx = x + width / 2;
14110
+ const cy = y + height / 2;
14111
+ const rx = width * 0.44;
14112
+ const ry = height * 0.38;
14113
+ ctx.beginPath();
14114
+ const lobes = 8;
14115
+ for (let i = 0; i < lobes; i++) {
14116
+ const angle = i / lobes * Math.PI * 2;
14117
+ const lx = cx + Math.cos(angle) * rx;
14118
+ const ly = cy + Math.sin(angle) * ry;
14119
+ const lobeR = Math.min(width, height) * 0.28;
14120
+ ctx.moveTo(lx + lobeR, ly);
14121
+ ctx.arc(lx, ly, lobeR, 0, Math.PI * 2);
14122
+ }
14123
+ ctx.fill();
14124
+ if (strokeWidth > 0) ctx.stroke();
14125
+ ctx.restore();
14126
+ }
14127
+ function drawComicBurst(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 3) {
14128
+ ctx.save();
14129
+ ctx.fillStyle = fillColor;
14130
+ ctx.strokeStyle = strokeColor;
14131
+ ctx.lineWidth = strokeWidth;
14132
+ const cx = x + width / 2;
14133
+ const cy = y + height / 2;
14134
+ const points = 16;
14135
+ const outerRx = width / 2;
14136
+ const outerRy = height / 2;
14137
+ const innerRx = width * 0.32;
14138
+ const innerRy = height * 0.32;
14139
+ ctx.beginPath();
14140
+ for (let i = 0; i < points * 2; i++) {
14141
+ const angle = i / (points * 2) * Math.PI * 2 - Math.PI / 2;
14142
+ const isOuter = i % 2 === 0;
14143
+ const rx = isOuter ? outerRx : innerRx;
14144
+ const ry = isOuter ? outerRy : innerRy;
14145
+ const px = cx + Math.cos(angle) * rx;
14146
+ const py = cy + Math.sin(angle) * ry;
14147
+ if (i === 0) ctx.moveTo(px, py);
14148
+ else ctx.lineTo(px, py);
14149
+ }
14150
+ ctx.closePath();
14151
+ ctx.fill();
14152
+ if (strokeWidth > 0) ctx.stroke();
14153
+ ctx.restore();
14154
+ }
14155
+ function drawRibbonBanner(ctx, x, y, width, height, fillColor = "#facc15", strokeColor = "#000000", strokeWidth = 2) {
14156
+ ctx.save();
14157
+ ctx.fillStyle = fillColor;
14158
+ ctx.strokeStyle = strokeColor;
14159
+ ctx.lineWidth = strokeWidth;
14160
+ const notch = Math.min(18, width * 0.08);
14161
+ ctx.beginPath();
14162
+ ctx.moveTo(x, y);
14163
+ ctx.lineTo(x + width - notch, y);
14164
+ ctx.lineTo(x + width, y + height / 2);
14165
+ ctx.lineTo(x + width - notch, y + height);
14166
+ ctx.lineTo(x, y + height);
14167
+ ctx.lineTo(x + notch, y + height / 2);
14168
+ ctx.closePath();
14169
+ ctx.fill();
14170
+ if (strokeWidth > 0) ctx.stroke();
14171
+ ctx.restore();
14172
+ }
14173
+ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
14174
+ if (!presetId || presetId === "none") return false;
14175
+ const color = options?.color || "#ffffff";
14176
+ const opacity = options?.opacity ?? 1;
14177
+ ctx.save();
14178
+ if (opacity < 1) {
14179
+ ctx.globalAlpha *= opacity;
14180
+ }
14181
+ if (presetId === "bubble-paper-torn" || presetId === "bubble-paper-torn-beige" || presetId === "bubble-paper-kraft" || presetId === "bubble-paper-notebook") {
14182
+ const paperColor = presetId === "bubble-paper-kraft" ? "#d4a373" : presetId === "bubble-paper-torn-beige" ? "#f3eed9" : "#faf9f6";
14183
+ drawTornPaper(ctx, x, y, width, height, color || paperColor, true);
14184
+ ctx.restore();
14185
+ return true;
14186
+ }
14187
+ if (presetId === "bubble-speech-round" || presetId === "bubble-speech-oval" || presetId === "bubble-speech-tall") {
14188
+ drawSpeechBubble(ctx, x, y, width, height, color, "#000000", 2, 16);
14189
+ ctx.restore();
14190
+ return true;
14191
+ }
14192
+ if (presetId === "bubble-speech-chalk-rose") {
14193
+ drawChalkSpeechBubble(ctx, x, y, width, height);
14194
+ ctx.restore();
14195
+ return true;
14196
+ }
14197
+ if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
14198
+ drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
14199
+ ctx.restore();
14200
+ return true;
14201
+ }
14202
+ if (presetId === "bubble-comic-bam" || presetId === "bubble-comic-dark-hero") {
14203
+ const burstColor = presetId === "bubble-comic-dark-hero" ? "#18181b" : color;
14204
+ const strokeColor = presetId === "bubble-comic-dark-hero" ? "#ef4444" : "#000000";
14205
+ drawComicBurst(ctx, x, y, width, height, burstColor, strokeColor, 3);
14206
+ ctx.restore();
14207
+ return true;
14208
+ }
14209
+ if (presetId === "bubble-ribbon-sunny" || presetId === "bubble-ribbon-yellow") {
14210
+ drawRibbonBanner(ctx, x, y, width, height, color || "#facc15", "#000000", 2);
14211
+ ctx.restore();
14212
+ return true;
14213
+ }
14214
+ const radius = options?.borderRadius ?? 8;
14215
+ ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
14216
+ ctx.shadowBlur = 8;
14217
+ ctx.shadowOffsetY = 2;
14218
+ ctx.fillStyle = color;
14219
+ ctx.beginPath();
14220
+ if (typeof ctx.roundRect === "function") {
14221
+ ctx.roundRect(x, y, width, height, radius);
14222
+ } else {
14223
+ ctx.rect(x, y, width, height);
14224
+ }
14225
+ ctx.fill();
14226
+ ctx.restore();
14227
+ return true;
14228
+ }
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
+
13807
14437
  // src/rendering/index.ts
13808
14438
  function renderCanonicalToCanvas(ctx, input) {
13809
14439
  if (input.capability === "text-template") {
@@ -24826,6 +25456,8 @@ var VERSION = "1.4.0";
24826
25456
  clearRecipeCache,
24827
25457
  cloneSceneWithNewIds,
24828
25458
  commandExecutor,
25459
+ compileBubblePath,
25460
+ compileBubbleSvg,
24829
25461
  compileSemanticOverlay,
24830
25462
  compileTextTemplate,
24831
25463
  componentRegistry,
@@ -24837,10 +25469,12 @@ var VERSION = "1.4.0";
24837
25469
  createBlankLottie,
24838
25470
  createBlankScratchTemplate,
24839
25471
  createBlankTextEffectConfig,
25472
+ createBubbleAssetDefinition,
24840
25473
  createCanvas,
24841
25474
  createDefaultRevealTrack,
24842
25475
  createDefaultScratchBlock,
24843
25476
  createEmptyScene,
25477
+ createFreeformBubbleAssetDefinition,
24844
25478
  createKeyframed,
24845
25479
  createPulseOpacityTrack,
24846
25480
  cubicBezier,
@@ -24856,8 +25490,14 @@ var VERSION = "1.4.0";
24856
25490
  downloadLottieMp4,
24857
25491
  downloadPngSequenceZip,
24858
25492
  downloadSceneWebM,
25493
+ drawChalkSpeechBubble,
25494
+ drawComicBurst,
24859
25495
  drawPerCharText,
25496
+ drawRibbonBanner,
24860
25497
  drawRoundedRect,
25498
+ drawSpeechBubble,
25499
+ drawThoughtCloud,
25500
+ drawTornPaper,
24861
25501
  duplicateTrackAtPlayhead,
24862
25502
  ease,
24863
25503
  editorCommandSystem,
@@ -24961,6 +25601,7 @@ var VERSION = "1.4.0";
24961
25601
  propertyInspectorEngine,
24962
25602
  propertyInterpolator,
24963
25603
  pruneTracksForLayer,
25604
+ pseudoNoise,
24964
25605
  rainbowCharFillColors,
24965
25606
  readLayerScalar,
24966
25607
  readStyleFromLottieLayer,
@@ -24969,6 +25610,9 @@ var VERSION = "1.4.0";
24969
25610
  removeKeyframe,
24970
25611
  removeTemplateKeyframe,
24971
25612
  removeTrack,
25613
+ renderBubbleAssetDefinition,
25614
+ renderBubbleBackground,
25615
+ renderBubblePresetBackground,
24972
25616
  renderCanonicalToCanvas,
24973
25617
  renderEvaluatedSceneToCanvas,
24974
25618
  renderPngSequence,
@@ -24982,6 +25626,7 @@ var VERSION = "1.4.0";
24982
25626
  resolveAnchorPosition,
24983
25627
  resolveAnimatedScalar,
24984
25628
  resolveBehaviorToAnimationSpec,
25629
+ resolveBubbleLayout,
24985
25630
  resolveConform,
24986
25631
  resolveDocumentForBreakpoint,
24987
25632
  resolveExportCanvasDimensions,
@@ -25039,6 +25684,7 @@ var VERSION = "1.4.0";
25039
25684
  updateTrack,
25040
25685
  updateTrackMatte,
25041
25686
  upsertKeyframe,
25687
+ validateBubbleAssetDefinition,
25042
25688
  validateEffectDefinition,
25043
25689
  validateEffectDefinitionStrict,
25044
25690
  validateTextEffectDefinition,