@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/{chunk-JP44RJUI.js → chunk-ZV3RQAUJ.js} +631 -1
- package/dist/chunk-ZV3RQAUJ.js.map +1 -0
- package/dist/{index-FDQDo2pR.d.cts → index-9XU-qEO-.d.cts} +247 -1
- package/dist/{index-XWLBYyFQ.d.ts → index-Qc3rcMrW.d.ts} +247 -1
- package/dist/index.cjs +646 -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 +49 -17
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +648 -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 +35 -3
- package/package.json +12 -12
- package/dist/chunk-JP44RJUI.js.map +0 -1
package/dist/rendering/index.cjs
CHANGED
|
@@ -21,12 +21,28 @@ var rendering_exports = {};
|
|
|
21
21
|
__export(rendering_exports, {
|
|
22
22
|
CANONICAL_RENDERER_VERSION: () => CANONICAL_RENDERER_VERSION,
|
|
23
23
|
TEXT_TEMPLATE_RENDERER_VERSION: () => TEXT_TEMPLATE_RENDERER_VERSION,
|
|
24
|
+
compileBubblePath: () => compileBubblePath,
|
|
25
|
+
compileBubbleSvg: () => compileBubbleSvg,
|
|
26
|
+
createBubbleAssetDefinition: () => createBubbleAssetDefinition,
|
|
27
|
+
createFreeformBubbleAssetDefinition: () => createFreeformBubbleAssetDefinition,
|
|
28
|
+
drawChalkSpeechBubble: () => drawChalkSpeechBubble,
|
|
29
|
+
drawComicBurst: () => drawComicBurst,
|
|
30
|
+
drawRibbonBanner: () => drawRibbonBanner,
|
|
31
|
+
drawSpeechBubble: () => drawSpeechBubble,
|
|
32
|
+
drawThoughtCloud: () => drawThoughtCloud,
|
|
33
|
+
drawTornPaper: () => drawTornPaper,
|
|
24
34
|
getTextTemplateControls: () => getTextTemplateControls,
|
|
35
|
+
pseudoNoise: () => pseudoNoise,
|
|
36
|
+
renderBubbleAssetDefinition: () => renderBubbleAssetDefinition,
|
|
37
|
+
renderBubbleBackground: () => renderBubbleBackground,
|
|
38
|
+
renderBubblePresetBackground: () => renderBubblePresetBackground,
|
|
25
39
|
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
26
40
|
renderTextEffectToCanvas: () => renderTextEffectToCanvas,
|
|
27
41
|
renderTextTemplateToCanvas: () => renderTextTemplateToCanvas,
|
|
42
|
+
resolveBubbleLayout: () => resolveBubbleLayout,
|
|
28
43
|
resolveTemplateFontFamily: () => resolveTemplateFontFamily,
|
|
29
|
-
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact
|
|
44
|
+
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact,
|
|
45
|
+
validateBubbleAssetDefinition: () => validateBubbleAssetDefinition
|
|
30
46
|
});
|
|
31
47
|
module.exports = __toCommonJS(rendering_exports);
|
|
32
48
|
|
|
@@ -3995,6 +4011,620 @@ function renderTextTemplateToCanvas(ctx, input) {
|
|
|
3995
4011
|
};
|
|
3996
4012
|
}
|
|
3997
4013
|
|
|
4014
|
+
// src/rendering/textBubbles.ts
|
|
4015
|
+
function resolveBubbleLayout(textWidth, textHeight, layout) {
|
|
4016
|
+
const p = layout.padding ?? {
|
|
4017
|
+
top: 14,
|
|
4018
|
+
right: 18,
|
|
4019
|
+
bottom: 14,
|
|
4020
|
+
left: 18
|
|
4021
|
+
};
|
|
4022
|
+
const rawOuterW = textWidth + p.left + p.right;
|
|
4023
|
+
const rawOuterH = textHeight + p.top + p.bottom;
|
|
4024
|
+
let outerWidth = Math.max(rawOuterW, layout.minWidth);
|
|
4025
|
+
let outerHeight = Math.max(rawOuterH, layout.minHeight);
|
|
4026
|
+
if (layout.preserveAspectRatio && layout.minWidth > 0 && layout.minHeight > 0) {
|
|
4027
|
+
const aspect = layout.minWidth / layout.minHeight;
|
|
4028
|
+
const currentAspect = outerWidth / outerHeight;
|
|
4029
|
+
if (currentAspect > aspect) {
|
|
4030
|
+
outerHeight = outerWidth / aspect;
|
|
4031
|
+
} else {
|
|
4032
|
+
outerWidth = outerHeight * aspect;
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
const textOffsetX = (p.left - p.right) / 2;
|
|
4036
|
+
const textOffsetY = (p.top - p.bottom) / 2;
|
|
4037
|
+
return {
|
|
4038
|
+
outerWidth,
|
|
4039
|
+
outerHeight,
|
|
4040
|
+
textOffsetX,
|
|
4041
|
+
textOffsetY,
|
|
4042
|
+
contentWidth: outerWidth - p.left - p.right,
|
|
4043
|
+
contentHeight: outerHeight - p.top - p.bottom
|
|
4044
|
+
};
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
// src/rendering/bubbleRenderer.ts
|
|
4048
|
+
function pseudoNoise(seed) {
|
|
4049
|
+
const x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
|
|
4050
|
+
return x - Math.floor(x);
|
|
4051
|
+
}
|
|
4052
|
+
function drawTornPaper(ctx, x, y, width, height, fillColor = "#faf9f6", shadow = true) {
|
|
4053
|
+
ctx.save();
|
|
4054
|
+
if (shadow) {
|
|
4055
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0.35)";
|
|
4056
|
+
ctx.shadowBlur = 12;
|
|
4057
|
+
ctx.shadowOffsetX = 0;
|
|
4058
|
+
ctx.shadowOffsetY = 4;
|
|
4059
|
+
}
|
|
4060
|
+
ctx.fillStyle = fillColor;
|
|
4061
|
+
ctx.beginPath();
|
|
4062
|
+
const steps = Math.max(16, Math.floor(width / 14));
|
|
4063
|
+
const stepW = width / steps;
|
|
4064
|
+
ctx.moveTo(x, y + 6);
|
|
4065
|
+
for (let i = 0; i <= steps; i++) {
|
|
4066
|
+
const curX = x + i * stepW;
|
|
4067
|
+
const n = pseudoNoise(i * 1.37 + 10);
|
|
4068
|
+
const wave = Math.sin(i / steps * Math.PI * 3) * 3;
|
|
4069
|
+
const curY = y + (n * 5 - 2.5) + wave;
|
|
4070
|
+
if (i === 0) ctx.lineTo(curX, curY);
|
|
4071
|
+
else ctx.lineTo(curX, curY);
|
|
4072
|
+
}
|
|
4073
|
+
ctx.lineTo(x + width, y + height - 6);
|
|
4074
|
+
for (let i = steps; i >= 0; i--) {
|
|
4075
|
+
const curX = x + i * stepW;
|
|
4076
|
+
const n = pseudoNoise(i * 2.19 + 50);
|
|
4077
|
+
const wave = Math.sin(i / steps * Math.PI * 2) * 4;
|
|
4078
|
+
const curY = y + height + (n * 6 - 3) + wave;
|
|
4079
|
+
ctx.lineTo(curX, curY);
|
|
4080
|
+
}
|
|
4081
|
+
ctx.lineTo(x, y + 6);
|
|
4082
|
+
ctx.closePath();
|
|
4083
|
+
ctx.fill();
|
|
4084
|
+
if (shadow) {
|
|
4085
|
+
ctx.shadowColor = "transparent";
|
|
4086
|
+
ctx.shadowBlur = 0;
|
|
4087
|
+
}
|
|
4088
|
+
const paperGrad = ctx.createLinearGradient(x, y, x, y + height);
|
|
4089
|
+
paperGrad.addColorStop(0, "rgba(255, 255, 255, 0.4)");
|
|
4090
|
+
paperGrad.addColorStop(0.5, "rgba(0, 0, 0, 0.02)");
|
|
4091
|
+
paperGrad.addColorStop(1, "rgba(0, 0, 0, 0.06)");
|
|
4092
|
+
ctx.fillStyle = paperGrad;
|
|
4093
|
+
ctx.fill();
|
|
4094
|
+
ctx.restore();
|
|
4095
|
+
}
|
|
4096
|
+
function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2, radius = 16) {
|
|
4097
|
+
ctx.save();
|
|
4098
|
+
const tailH = Math.min(16, height * 0.25);
|
|
4099
|
+
const bodyH = height - tailH;
|
|
4100
|
+
ctx.fillStyle = fillColor;
|
|
4101
|
+
ctx.strokeStyle = strokeColor;
|
|
4102
|
+
ctx.lineWidth = strokeWidth;
|
|
4103
|
+
ctx.beginPath();
|
|
4104
|
+
if (typeof ctx.roundRect === "function") {
|
|
4105
|
+
ctx.roundRect(x, y, width, bodyH, radius);
|
|
4106
|
+
} else {
|
|
4107
|
+
ctx.rect(x, y, width, bodyH);
|
|
4108
|
+
}
|
|
4109
|
+
ctx.fill();
|
|
4110
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4111
|
+
const tailBaseX = x + width * 0.25;
|
|
4112
|
+
const tailBaseW = Math.min(24, width * 0.2);
|
|
4113
|
+
const tailTipX = x + width * 0.15;
|
|
4114
|
+
const tailTipY = y + height;
|
|
4115
|
+
ctx.beginPath();
|
|
4116
|
+
ctx.moveTo(tailBaseX, y + bodyH - 2);
|
|
4117
|
+
ctx.quadraticCurveTo(tailBaseX + 2, y + bodyH + tailH * 0.6, tailTipX, tailTipY);
|
|
4118
|
+
ctx.quadraticCurveTo(tailBaseX + tailBaseW * 0.7, y + bodyH + tailH * 0.4, tailBaseX + tailBaseW, y + bodyH - 2);
|
|
4119
|
+
ctx.closePath();
|
|
4120
|
+
ctx.fill();
|
|
4121
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4122
|
+
ctx.beginPath();
|
|
4123
|
+
if (typeof ctx.roundRect === "function") {
|
|
4124
|
+
ctx.roundRect(x + 1, y + 1, width - 2, bodyH - 2, radius);
|
|
4125
|
+
} else {
|
|
4126
|
+
ctx.rect(x + 1, y + 1, width - 2, bodyH - 2);
|
|
4127
|
+
}
|
|
4128
|
+
ctx.fill();
|
|
4129
|
+
ctx.restore();
|
|
4130
|
+
}
|
|
4131
|
+
function drawConfigurableSpeechBubble(ctx, x, y, width, height, appearance) {
|
|
4132
|
+
const tailHeight = Math.min(appearance.tailSize, height * 0.38);
|
|
4133
|
+
const bodyHeight = height - tailHeight;
|
|
4134
|
+
const radius = Math.min(appearance.cornerRadius, bodyHeight / 2);
|
|
4135
|
+
const tailCenter = appearance.tailPosition === "bottom-left" ? x + width * 0.2 : appearance.tailPosition === "bottom-right" ? x + width * 0.8 : x + width * 0.5;
|
|
4136
|
+
const tailWidth = Math.min(Math.max(18, appearance.tailSize * 1.5), width * 0.28);
|
|
4137
|
+
ctx.save();
|
|
4138
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, appearance.fillOpacity));
|
|
4139
|
+
ctx.fillStyle = appearance.fillColor;
|
|
4140
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
4141
|
+
ctx.lineWidth = Math.max(0, appearance.strokeWidth);
|
|
4142
|
+
ctx.beginPath();
|
|
4143
|
+
if (typeof ctx.roundRect === "function") {
|
|
4144
|
+
ctx.roundRect(x, y, width, bodyHeight, radius);
|
|
4145
|
+
} else {
|
|
4146
|
+
ctx.rect(x, y, width, bodyHeight);
|
|
4147
|
+
}
|
|
4148
|
+
ctx.fill();
|
|
4149
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
4150
|
+
ctx.beginPath();
|
|
4151
|
+
ctx.moveTo(tailCenter - tailWidth / 2, y + bodyHeight - 1);
|
|
4152
|
+
ctx.quadraticCurveTo(tailCenter - tailWidth * 0.15, y + bodyHeight + tailHeight * 0.7, tailCenter, y + height);
|
|
4153
|
+
ctx.quadraticCurveTo(tailCenter + tailWidth * 0.18, y + bodyHeight + tailHeight * 0.55, tailCenter + tailWidth / 2, y + bodyHeight - 1);
|
|
4154
|
+
ctx.closePath();
|
|
4155
|
+
ctx.fill();
|
|
4156
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
4157
|
+
ctx.restore();
|
|
4158
|
+
}
|
|
4159
|
+
function renderBubblePresetBackground(ctx, preset, x, y, width, height) {
|
|
4160
|
+
const appearance = preset.appearance;
|
|
4161
|
+
if (!appearance) return renderBubbleBackground(ctx, preset.id, x, y, width, height);
|
|
4162
|
+
ctx.save();
|
|
4163
|
+
switch (appearance.shape) {
|
|
4164
|
+
case "chalk":
|
|
4165
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
4166
|
+
break;
|
|
4167
|
+
case "cloud":
|
|
4168
|
+
drawThoughtCloud(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
4169
|
+
break;
|
|
4170
|
+
case "comic":
|
|
4171
|
+
drawComicBurst(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
4172
|
+
break;
|
|
4173
|
+
case "paper":
|
|
4174
|
+
drawTornPaper(ctx, x, y, width, height, appearance.fillColor, true);
|
|
4175
|
+
break;
|
|
4176
|
+
case "ribbon":
|
|
4177
|
+
drawRibbonBanner(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
4178
|
+
break;
|
|
4179
|
+
case "speech":
|
|
4180
|
+
drawConfigurableSpeechBubble(ctx, x, y, width, height, appearance);
|
|
4181
|
+
break;
|
|
4182
|
+
case "rounded": {
|
|
4183
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, appearance.fillOpacity));
|
|
4184
|
+
ctx.fillStyle = appearance.fillColor;
|
|
4185
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
4186
|
+
ctx.lineWidth = Math.max(0, appearance.strokeWidth);
|
|
4187
|
+
ctx.beginPath();
|
|
4188
|
+
if (typeof ctx.roundRect === "function") {
|
|
4189
|
+
ctx.roundRect(x, y, width, height, Math.min(appearance.cornerRadius, height / 2));
|
|
4190
|
+
} else {
|
|
4191
|
+
ctx.rect(x, y, width, height);
|
|
4192
|
+
}
|
|
4193
|
+
ctx.fill();
|
|
4194
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
4195
|
+
break;
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
if (appearance.texture === "chalk") {
|
|
4199
|
+
ctx.globalAlpha = 0.55;
|
|
4200
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
4201
|
+
ctx.setLineDash([1, 3]);
|
|
4202
|
+
ctx.lineWidth = Math.max(1, appearance.strokeWidth * 0.7);
|
|
4203
|
+
ctx.strokeRect(x + 1, y + 1, width - 2, height - 2);
|
|
4204
|
+
} else if (appearance.texture === "hatch") {
|
|
4205
|
+
ctx.globalAlpha = 0.22;
|
|
4206
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
4207
|
+
ctx.lineWidth = 1;
|
|
4208
|
+
for (let offset = -height; offset < width; offset += 9) {
|
|
4209
|
+
ctx.beginPath();
|
|
4210
|
+
ctx.moveTo(x + offset, y + height);
|
|
4211
|
+
ctx.lineTo(x + offset + height, y);
|
|
4212
|
+
ctx.stroke();
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
ctx.restore();
|
|
4216
|
+
return true;
|
|
4217
|
+
}
|
|
4218
|
+
function drawChalkSpeechBubble(ctx, x, y, width, height) {
|
|
4219
|
+
ctx.save();
|
|
4220
|
+
const tailHeight = Math.min(46, height * 0.3);
|
|
4221
|
+
const bodyHeight = height - tailHeight;
|
|
4222
|
+
const radius = Math.min(36, bodyHeight * 0.25);
|
|
4223
|
+
const tailLeft = x + width * 0.1;
|
|
4224
|
+
const tailRight = x + width * 0.19;
|
|
4225
|
+
const tailTipX = x + width * 0.14;
|
|
4226
|
+
const tailTipY = y + height;
|
|
4227
|
+
const balloonPath = () => {
|
|
4228
|
+
ctx.beginPath();
|
|
4229
|
+
ctx.moveTo(x + radius, y);
|
|
4230
|
+
ctx.lineTo(x + width - radius, y);
|
|
4231
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
4232
|
+
ctx.lineTo(x + width, y + bodyHeight - radius);
|
|
4233
|
+
ctx.quadraticCurveTo(x + width, y + bodyHeight, x + width - radius, y + bodyHeight);
|
|
4234
|
+
ctx.lineTo(tailRight, y + bodyHeight);
|
|
4235
|
+
ctx.quadraticCurveTo(tailRight - width * 0.02, y + bodyHeight + tailHeight * 0.35, tailTipX, tailTipY);
|
|
4236
|
+
ctx.quadraticCurveTo(tailLeft + width * 5e-3, y + bodyHeight + tailHeight * 0.32, tailLeft, y + bodyHeight);
|
|
4237
|
+
ctx.lineTo(x + radius, y + bodyHeight);
|
|
4238
|
+
ctx.quadraticCurveTo(x, y + bodyHeight, x, y + bodyHeight - radius);
|
|
4239
|
+
ctx.lineTo(x, y + radius);
|
|
4240
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
4241
|
+
ctx.closePath();
|
|
4242
|
+
};
|
|
4243
|
+
ctx.fillStyle = "rgba(184, 122, 132, 0.58)";
|
|
4244
|
+
balloonPath();
|
|
4245
|
+
ctx.fill();
|
|
4246
|
+
ctx.save();
|
|
4247
|
+
ctx.beginPath();
|
|
4248
|
+
ctx.moveTo(x + width * 0.2, y + bodyHeight - tailHeight * 0.13);
|
|
4249
|
+
ctx.quadraticCurveTo(x + width * 0.48, y + bodyHeight + tailHeight * 0.37, x + width * 0.91, y + bodyHeight - tailHeight * 0.02);
|
|
4250
|
+
ctx.quadraticCurveTo(x + width * 0.66, y + bodyHeight + tailHeight * 0.72, x + width * 0.24, y + bodyHeight + tailHeight * 0.44);
|
|
4251
|
+
ctx.closePath();
|
|
4252
|
+
ctx.clip();
|
|
4253
|
+
ctx.shadowColor = "rgba(222, 228, 105, 0.32)";
|
|
4254
|
+
ctx.shadowBlur = 3;
|
|
4255
|
+
ctx.strokeStyle = "rgba(203, 211, 76, 0.52)";
|
|
4256
|
+
ctx.lineWidth = 1.25;
|
|
4257
|
+
for (let offset = -height; offset < width; offset += 9) {
|
|
4258
|
+
ctx.beginPath();
|
|
4259
|
+
ctx.moveTo(x + offset, y + height);
|
|
4260
|
+
ctx.lineTo(x + offset + height, y);
|
|
4261
|
+
ctx.stroke();
|
|
4262
|
+
}
|
|
4263
|
+
ctx.shadowBlur = 0;
|
|
4264
|
+
ctx.strokeStyle = "rgba(255, 250, 196, 0.48)";
|
|
4265
|
+
ctx.lineWidth = 0.8;
|
|
4266
|
+
for (let offset = 0; offset < width + height; offset += 12) {
|
|
4267
|
+
ctx.beginPath();
|
|
4268
|
+
ctx.moveTo(x + offset, y);
|
|
4269
|
+
ctx.lineTo(x + offset - height, y + height);
|
|
4270
|
+
ctx.stroke();
|
|
4271
|
+
}
|
|
4272
|
+
ctx.restore();
|
|
4273
|
+
ctx.strokeStyle = "rgba(255, 253, 246, 0.82)";
|
|
4274
|
+
ctx.lineCap = "round";
|
|
4275
|
+
ctx.lineWidth = 1.35;
|
|
4276
|
+
balloonPath();
|
|
4277
|
+
ctx.stroke();
|
|
4278
|
+
const edgeSegments = 66;
|
|
4279
|
+
for (let index = 0; index < edgeSegments; index++) {
|
|
4280
|
+
const pointX = x + width * (index / edgeSegments);
|
|
4281
|
+
const topNoise = (pseudoNoise(index + 91) - 0.5) * 4;
|
|
4282
|
+
const strokeLength = 0.8 + pseudoNoise(index + 143) * 2.1;
|
|
4283
|
+
ctx.lineWidth = 0.6 + pseudoNoise(index + 211) * 1.1;
|
|
4284
|
+
ctx.beginPath();
|
|
4285
|
+
ctx.moveTo(pointX, y + topNoise);
|
|
4286
|
+
ctx.lineTo(pointX + strokeLength, y + topNoise + (pseudoNoise(index + 19) - 0.5) * 2);
|
|
4287
|
+
ctx.stroke();
|
|
4288
|
+
ctx.beginPath();
|
|
4289
|
+
ctx.moveTo(pointX, y + bodyHeight + topNoise);
|
|
4290
|
+
ctx.lineTo(pointX + strokeLength, y + bodyHeight + topNoise + (pseudoNoise(index + 37) - 0.5) * 2);
|
|
4291
|
+
ctx.stroke();
|
|
4292
|
+
}
|
|
4293
|
+
ctx.restore();
|
|
4294
|
+
}
|
|
4295
|
+
function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
|
|
4296
|
+
ctx.save();
|
|
4297
|
+
ctx.fillStyle = fillColor;
|
|
4298
|
+
ctx.strokeStyle = strokeColor;
|
|
4299
|
+
ctx.lineWidth = strokeWidth;
|
|
4300
|
+
const cx = x + width / 2;
|
|
4301
|
+
const cy = y + height / 2;
|
|
4302
|
+
const rx = width * 0.44;
|
|
4303
|
+
const ry = height * 0.38;
|
|
4304
|
+
ctx.beginPath();
|
|
4305
|
+
const lobes = 8;
|
|
4306
|
+
for (let i = 0; i < lobes; i++) {
|
|
4307
|
+
const angle = i / lobes * Math.PI * 2;
|
|
4308
|
+
const lx = cx + Math.cos(angle) * rx;
|
|
4309
|
+
const ly = cy + Math.sin(angle) * ry;
|
|
4310
|
+
const lobeR = Math.min(width, height) * 0.28;
|
|
4311
|
+
ctx.moveTo(lx + lobeR, ly);
|
|
4312
|
+
ctx.arc(lx, ly, lobeR, 0, Math.PI * 2);
|
|
4313
|
+
}
|
|
4314
|
+
ctx.fill();
|
|
4315
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4316
|
+
ctx.restore();
|
|
4317
|
+
}
|
|
4318
|
+
function drawComicBurst(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 3) {
|
|
4319
|
+
ctx.save();
|
|
4320
|
+
ctx.fillStyle = fillColor;
|
|
4321
|
+
ctx.strokeStyle = strokeColor;
|
|
4322
|
+
ctx.lineWidth = strokeWidth;
|
|
4323
|
+
const cx = x + width / 2;
|
|
4324
|
+
const cy = y + height / 2;
|
|
4325
|
+
const points = 16;
|
|
4326
|
+
const outerRx = width / 2;
|
|
4327
|
+
const outerRy = height / 2;
|
|
4328
|
+
const innerRx = width * 0.32;
|
|
4329
|
+
const innerRy = height * 0.32;
|
|
4330
|
+
ctx.beginPath();
|
|
4331
|
+
for (let i = 0; i < points * 2; i++) {
|
|
4332
|
+
const angle = i / (points * 2) * Math.PI * 2 - Math.PI / 2;
|
|
4333
|
+
const isOuter = i % 2 === 0;
|
|
4334
|
+
const rx = isOuter ? outerRx : innerRx;
|
|
4335
|
+
const ry = isOuter ? outerRy : innerRy;
|
|
4336
|
+
const px = cx + Math.cos(angle) * rx;
|
|
4337
|
+
const py = cy + Math.sin(angle) * ry;
|
|
4338
|
+
if (i === 0) ctx.moveTo(px, py);
|
|
4339
|
+
else ctx.lineTo(px, py);
|
|
4340
|
+
}
|
|
4341
|
+
ctx.closePath();
|
|
4342
|
+
ctx.fill();
|
|
4343
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4344
|
+
ctx.restore();
|
|
4345
|
+
}
|
|
4346
|
+
function drawRibbonBanner(ctx, x, y, width, height, fillColor = "#facc15", strokeColor = "#000000", strokeWidth = 2) {
|
|
4347
|
+
ctx.save();
|
|
4348
|
+
ctx.fillStyle = fillColor;
|
|
4349
|
+
ctx.strokeStyle = strokeColor;
|
|
4350
|
+
ctx.lineWidth = strokeWidth;
|
|
4351
|
+
const notch = Math.min(18, width * 0.08);
|
|
4352
|
+
ctx.beginPath();
|
|
4353
|
+
ctx.moveTo(x, y);
|
|
4354
|
+
ctx.lineTo(x + width - notch, y);
|
|
4355
|
+
ctx.lineTo(x + width, y + height / 2);
|
|
4356
|
+
ctx.lineTo(x + width - notch, y + height);
|
|
4357
|
+
ctx.lineTo(x, y + height);
|
|
4358
|
+
ctx.lineTo(x + notch, y + height / 2);
|
|
4359
|
+
ctx.closePath();
|
|
4360
|
+
ctx.fill();
|
|
4361
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4362
|
+
ctx.restore();
|
|
4363
|
+
}
|
|
4364
|
+
function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
4365
|
+
if (!presetId || presetId === "none") return false;
|
|
4366
|
+
const color = options?.color || "#ffffff";
|
|
4367
|
+
const opacity = options?.opacity ?? 1;
|
|
4368
|
+
ctx.save();
|
|
4369
|
+
if (opacity < 1) {
|
|
4370
|
+
ctx.globalAlpha *= opacity;
|
|
4371
|
+
}
|
|
4372
|
+
if (presetId === "bubble-paper-torn" || presetId === "bubble-paper-torn-beige" || presetId === "bubble-paper-kraft" || presetId === "bubble-paper-notebook") {
|
|
4373
|
+
const paperColor = presetId === "bubble-paper-kraft" ? "#d4a373" : presetId === "bubble-paper-torn-beige" ? "#f3eed9" : "#faf9f6";
|
|
4374
|
+
drawTornPaper(ctx, x, y, width, height, color || paperColor, true);
|
|
4375
|
+
ctx.restore();
|
|
4376
|
+
return true;
|
|
4377
|
+
}
|
|
4378
|
+
if (presetId === "bubble-speech-round" || presetId === "bubble-speech-oval" || presetId === "bubble-speech-tall") {
|
|
4379
|
+
drawSpeechBubble(ctx, x, y, width, height, color, "#000000", 2, 16);
|
|
4380
|
+
ctx.restore();
|
|
4381
|
+
return true;
|
|
4382
|
+
}
|
|
4383
|
+
if (presetId === "bubble-speech-chalk-rose") {
|
|
4384
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
4385
|
+
ctx.restore();
|
|
4386
|
+
return true;
|
|
4387
|
+
}
|
|
4388
|
+
if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
|
|
4389
|
+
drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
|
|
4390
|
+
ctx.restore();
|
|
4391
|
+
return true;
|
|
4392
|
+
}
|
|
4393
|
+
if (presetId === "bubble-comic-bam" || presetId === "bubble-comic-dark-hero") {
|
|
4394
|
+
const burstColor = presetId === "bubble-comic-dark-hero" ? "#18181b" : color;
|
|
4395
|
+
const strokeColor = presetId === "bubble-comic-dark-hero" ? "#ef4444" : "#000000";
|
|
4396
|
+
drawComicBurst(ctx, x, y, width, height, burstColor, strokeColor, 3);
|
|
4397
|
+
ctx.restore();
|
|
4398
|
+
return true;
|
|
4399
|
+
}
|
|
4400
|
+
if (presetId === "bubble-ribbon-sunny" || presetId === "bubble-ribbon-yellow") {
|
|
4401
|
+
drawRibbonBanner(ctx, x, y, width, height, color || "#facc15", "#000000", 2);
|
|
4402
|
+
ctx.restore();
|
|
4403
|
+
return true;
|
|
4404
|
+
}
|
|
4405
|
+
const radius = options?.borderRadius ?? 8;
|
|
4406
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
|
|
4407
|
+
ctx.shadowBlur = 8;
|
|
4408
|
+
ctx.shadowOffsetY = 2;
|
|
4409
|
+
ctx.fillStyle = color;
|
|
4410
|
+
ctx.beginPath();
|
|
4411
|
+
if (typeof ctx.roundRect === "function") {
|
|
4412
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
4413
|
+
} else {
|
|
4414
|
+
ctx.rect(x, y, width, height);
|
|
4415
|
+
}
|
|
4416
|
+
ctx.fill();
|
|
4417
|
+
ctx.restore();
|
|
4418
|
+
return true;
|
|
4419
|
+
}
|
|
4420
|
+
|
|
4421
|
+
// src/rendering/bubbleAssets.ts
|
|
4422
|
+
var createBubbleAssetDefinition = () => ({
|
|
4423
|
+
schemaVersion: 1,
|
|
4424
|
+
type: "clypra.textBubble",
|
|
4425
|
+
coordinateSpace: "normalized",
|
|
4426
|
+
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 } },
|
|
4427
|
+
layers: { fill: { color: "#7c3aed", opacity: 0.9 }, outline: { color: "#ffffff", width: 0.018, roughness: 0, seed: 1 } },
|
|
4428
|
+
textLayout: { padding: [0.1, 0.1, 0.18, 0.1], alignment: "center", overflow: "grow" }
|
|
4429
|
+
});
|
|
4430
|
+
var createFreeformBubbleAssetDefinition = () => ({
|
|
4431
|
+
...createBubbleAssetDefinition(),
|
|
4432
|
+
geometry: {
|
|
4433
|
+
kind: "freeform-path",
|
|
4434
|
+
closed: true,
|
|
4435
|
+
commands: [
|
|
4436
|
+
{ kind: "move", to: [0.12, 0.04] },
|
|
4437
|
+
{ kind: "line", to: [0.88, 0.04] },
|
|
4438
|
+
{ kind: "quadratic", control: [0.98, 0.04], to: [0.98, 0.16] },
|
|
4439
|
+
{ kind: "line", to: [0.98, 0.7] },
|
|
4440
|
+
{ kind: "quadratic", control: [0.98, 0.82], to: [0.86, 0.82] },
|
|
4441
|
+
{ kind: "line", to: [0.38, 0.82] },
|
|
4442
|
+
{ kind: "line", to: [0.22, 1] },
|
|
4443
|
+
{ kind: "line", to: [0.27, 0.82] },
|
|
4444
|
+
{ kind: "line", to: [0.12, 0.82] },
|
|
4445
|
+
{ kind: "quadratic", control: [0.02, 0.82], to: [0.02, 0.7] },
|
|
4446
|
+
{ kind: "line", to: [0.02, 0.16] },
|
|
4447
|
+
{ kind: "quadratic", control: [0.02, 0.04], to: [0.12, 0.04] },
|
|
4448
|
+
{ kind: "close" }
|
|
4449
|
+
]
|
|
4450
|
+
}
|
|
4451
|
+
});
|
|
4452
|
+
var clamp = (value) => Math.max(0, Math.min(1, value));
|
|
4453
|
+
function compileBubblePath(definition) {
|
|
4454
|
+
if (definition.geometry.kind === "freeform-path") {
|
|
4455
|
+
return definition.geometry.commands.map((command) => {
|
|
4456
|
+
if (command.kind === "close") return "Z";
|
|
4457
|
+
if (command.kind === "move") return `M ${command.to[0]} ${command.to[1]}`;
|
|
4458
|
+
if (command.kind === "line") return `L ${command.to[0]} ${command.to[1]}`;
|
|
4459
|
+
if (command.kind === "quadratic") return `Q ${command.control[0]} ${command.control[1]} ${command.to[0]} ${command.to[1]}`;
|
|
4460
|
+
if (command.kind === "cubic") return `C ${command.control1[0]} ${command.control1[1]} ${command.control2[0]} ${command.control2[1]} ${command.to[0]} ${command.to[1]}`;
|
|
4461
|
+
return "";
|
|
4462
|
+
}).join(" ");
|
|
4463
|
+
}
|
|
4464
|
+
const { body, tail } = definition.geometry;
|
|
4465
|
+
const r = clamp(body.cornerRadius) * 0.5;
|
|
4466
|
+
const anchor = clamp(tail.anchor);
|
|
4467
|
+
const tailWidth = clamp(tail.width) * 0.5;
|
|
4468
|
+
const depth = clamp(tail.depth);
|
|
4469
|
+
const left = clamp(anchor - tailWidth);
|
|
4470
|
+
const right = clamp(anchor + tailWidth);
|
|
4471
|
+
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`;
|
|
4472
|
+
if (!tail.enabled) return bodyPath;
|
|
4473
|
+
if (tail.side === "bottom") {
|
|
4474
|
+
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`;
|
|
4475
|
+
}
|
|
4476
|
+
if (tail.side === "top") {
|
|
4477
|
+
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`;
|
|
4478
|
+
}
|
|
4479
|
+
if (tail.side === "left") {
|
|
4480
|
+
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`;
|
|
4481
|
+
}
|
|
4482
|
+
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`;
|
|
4483
|
+
}
|
|
4484
|
+
function compileBubbleSvg(definition, width = 1e3, height = 700) {
|
|
4485
|
+
const { fill, outline, accent } = definition.layers;
|
|
4486
|
+
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>` : "";
|
|
4487
|
+
const textureOverlay = accent?.texture === "hatch" ? `<path d="${compileBubblePath(definition)}" fill="url(#hatch)" />` : "";
|
|
4488
|
+
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>`;
|
|
4489
|
+
}
|
|
4490
|
+
function traceBubbleSilhouette(ctx, x, y, width, height, radius, tail, tailDepth) {
|
|
4491
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
4492
|
+
const anchor = clamp(tail.anchor);
|
|
4493
|
+
const halfTail = clamp(tail.width) * (tail.side === "left" || tail.side === "right" ? height : width) / 2;
|
|
4494
|
+
const along = tail.side === "left" || tail.side === "right" ? y + height * anchor : x + width * anchor;
|
|
4495
|
+
ctx.beginPath();
|
|
4496
|
+
ctx.moveTo(x + r, y);
|
|
4497
|
+
if (tail.enabled && tail.side === "top") {
|
|
4498
|
+
ctx.lineTo(along - halfTail, y);
|
|
4499
|
+
ctx.quadraticCurveTo(along - halfTail * 0.35, y - tailDepth * tail.curvature, along, y - tailDepth);
|
|
4500
|
+
ctx.quadraticCurveTo(along + halfTail * 0.35, y - tailDepth * tail.curvature, along + halfTail, y);
|
|
4501
|
+
}
|
|
4502
|
+
ctx.lineTo(x + width - r, y);
|
|
4503
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
|
|
4504
|
+
if (tail.enabled && tail.side === "right") {
|
|
4505
|
+
ctx.lineTo(x + width, along - halfTail);
|
|
4506
|
+
ctx.quadraticCurveTo(x + width + tailDepth * tail.curvature, along - halfTail * 0.35, x + width + tailDepth, along);
|
|
4507
|
+
ctx.quadraticCurveTo(x + width + tailDepth * tail.curvature, along + halfTail * 0.35, x + width, along + halfTail);
|
|
4508
|
+
}
|
|
4509
|
+
ctx.lineTo(x + width, y + height - r);
|
|
4510
|
+
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
|
|
4511
|
+
if (tail.enabled && tail.side === "bottom") {
|
|
4512
|
+
ctx.lineTo(along + halfTail, y + height);
|
|
4513
|
+
ctx.quadraticCurveTo(along + halfTail * 0.35, y + height + tailDepth * tail.curvature, along, y + height + tailDepth);
|
|
4514
|
+
ctx.quadraticCurveTo(along - halfTail * 0.35, y + height + tailDepth * tail.curvature, along - halfTail, y + height);
|
|
4515
|
+
}
|
|
4516
|
+
ctx.lineTo(x + r, y + height);
|
|
4517
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
|
|
4518
|
+
if (tail.enabled && tail.side === "left") {
|
|
4519
|
+
ctx.lineTo(x, along + halfTail);
|
|
4520
|
+
ctx.quadraticCurveTo(x - tailDepth * tail.curvature, along + halfTail * 0.35, x - tailDepth, along);
|
|
4521
|
+
ctx.quadraticCurveTo(x - tailDepth * tail.curvature, along - halfTail * 0.35, x, along - halfTail);
|
|
4522
|
+
}
|
|
4523
|
+
ctx.lineTo(x, y + r);
|
|
4524
|
+
ctx.quadraticCurveTo(x, y, x + r, y);
|
|
4525
|
+
ctx.closePath();
|
|
4526
|
+
}
|
|
4527
|
+
function renderBubbleAssetDefinition(ctx, definition, x, y, width, height) {
|
|
4528
|
+
if (definition.geometry.kind === "freeform-path") {
|
|
4529
|
+
renderFreeformBubbleAssetDefinition(ctx, definition, x, y, width, height);
|
|
4530
|
+
return;
|
|
4531
|
+
}
|
|
4532
|
+
const { tail, body } = definition.geometry;
|
|
4533
|
+
const tailDepth = tail.enabled ? clamp(tail.depth) * (tail.side === "left" || tail.side === "right" ? width : height) : 0;
|
|
4534
|
+
const bodyX = x + (tail.side === "left" ? tailDepth : 0);
|
|
4535
|
+
const bodyY = y + (tail.side === "top" ? tailDepth : 0);
|
|
4536
|
+
const bodyWidth = width - (tail.side === "left" || tail.side === "right" ? tailDepth : 0);
|
|
4537
|
+
const bodyHeight = height - (tail.side === "top" || tail.side === "bottom" ? tailDepth : 0);
|
|
4538
|
+
const radius = clamp(body.cornerRadius) * Math.min(bodyWidth, bodyHeight) / 2;
|
|
4539
|
+
ctx.save();
|
|
4540
|
+
traceBubbleSilhouette(ctx, bodyX, bodyY, bodyWidth, bodyHeight, radius, tail, tailDepth);
|
|
4541
|
+
ctx.globalAlpha = definition.layers.fill.opacity;
|
|
4542
|
+
ctx.fillStyle = definition.layers.fill.color;
|
|
4543
|
+
ctx.fill();
|
|
4544
|
+
const accent = definition.layers.accent;
|
|
4545
|
+
if (accent && accent.texture !== "none") {
|
|
4546
|
+
ctx.save();
|
|
4547
|
+
ctx.clip();
|
|
4548
|
+
ctx.globalAlpha = accent.opacity;
|
|
4549
|
+
ctx.strokeStyle = accent.color;
|
|
4550
|
+
ctx.lineWidth = Math.max(1, Math.min(width, height) * 6e-3);
|
|
4551
|
+
if (accent.texture === "hatch") {
|
|
4552
|
+
const spacing = Math.max(5, Math.min(width, height) * 0.09);
|
|
4553
|
+
for (let offset = -height; offset < width + height; offset += spacing) {
|
|
4554
|
+
ctx.beginPath();
|
|
4555
|
+
ctx.moveTo(x + offset, y + height);
|
|
4556
|
+
ctx.lineTo(x + offset + height, y);
|
|
4557
|
+
ctx.stroke();
|
|
4558
|
+
}
|
|
4559
|
+
} else {
|
|
4560
|
+
let state = definition.layers.outline.seed >>> 0;
|
|
4561
|
+
const nextRandom = () => {
|
|
4562
|
+
state = state * 1664525 + 1013904223 >>> 0;
|
|
4563
|
+
return state / 4294967296;
|
|
4564
|
+
};
|
|
4565
|
+
const count = Math.max(18, Math.round(width * height / 700));
|
|
4566
|
+
for (let index = 0; index < count; index += 1) {
|
|
4567
|
+
const px = x + nextRandom() * width;
|
|
4568
|
+
const py = y + nextRandom() * height;
|
|
4569
|
+
const length = 1 + nextRandom() * Math.min(width, height) * 0.025;
|
|
4570
|
+
ctx.beginPath();
|
|
4571
|
+
ctx.moveTo(px, py);
|
|
4572
|
+
ctx.lineTo(px + length, py);
|
|
4573
|
+
ctx.stroke();
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
ctx.restore();
|
|
4577
|
+
}
|
|
4578
|
+
if (definition.layers.outline.width > 0) {
|
|
4579
|
+
ctx.globalAlpha = 1;
|
|
4580
|
+
ctx.strokeStyle = definition.layers.outline.color;
|
|
4581
|
+
ctx.lineWidth = definition.layers.outline.width * Math.min(width, height);
|
|
4582
|
+
ctx.stroke();
|
|
4583
|
+
}
|
|
4584
|
+
ctx.restore();
|
|
4585
|
+
}
|
|
4586
|
+
function traceFreeformPath(ctx, definition, x, y, width, height) {
|
|
4587
|
+
ctx.beginPath();
|
|
4588
|
+
for (const command of definition.geometry.commands) {
|
|
4589
|
+
if (command.kind === "close") ctx.closePath();
|
|
4590
|
+
else if (command.kind === "move") ctx.moveTo(x + command.to[0] * width, y + command.to[1] * height);
|
|
4591
|
+
else if (command.kind === "line") ctx.lineTo(x + command.to[0] * width, y + command.to[1] * height);
|
|
4592
|
+
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);
|
|
4593
|
+
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);
|
|
4594
|
+
}
|
|
4595
|
+
}
|
|
4596
|
+
function renderFreeformBubbleAssetDefinition(ctx, definition, x, y, width, height) {
|
|
4597
|
+
ctx.save();
|
|
4598
|
+
traceFreeformPath(ctx, definition, x, y, width, height);
|
|
4599
|
+
ctx.globalAlpha = definition.layers.fill.opacity;
|
|
4600
|
+
ctx.fillStyle = definition.layers.fill.color;
|
|
4601
|
+
ctx.fill();
|
|
4602
|
+
if (definition.layers.outline.width > 0) {
|
|
4603
|
+
ctx.globalAlpha = 1;
|
|
4604
|
+
ctx.strokeStyle = definition.layers.outline.color;
|
|
4605
|
+
ctx.lineWidth = definition.layers.outline.width * Math.min(width, height);
|
|
4606
|
+
ctx.stroke();
|
|
4607
|
+
}
|
|
4608
|
+
ctx.restore();
|
|
4609
|
+
}
|
|
4610
|
+
function validateBubbleAssetDefinition(definition) {
|
|
4611
|
+
const errors = [];
|
|
4612
|
+
if (definition.schemaVersion !== 1 || definition.type !== "clypra.textBubble") errors.push("Unsupported bubble asset schema.");
|
|
4613
|
+
if (!/^#[0-9a-f]{6}$/i.test(definition.layers.fill.color)) errors.push("Fill color must be a six-digit hex value.");
|
|
4614
|
+
if (definition.layers.fill.opacity < 0 || definition.layers.fill.opacity > 1) errors.push("Fill opacity must be between 0 and 1.");
|
|
4615
|
+
if (!/^#[0-9a-f]{6}$/i.test(definition.layers.outline.color)) errors.push("Outline color must be a six-digit hex value.");
|
|
4616
|
+
if (definition.layers.outline.width < 0 || definition.layers.outline.width > 0.1) errors.push("Outline width must be normalized between 0 and 0.1.");
|
|
4617
|
+
if (definition.geometry.kind === "parametric-path") {
|
|
4618
|
+
if (definition.geometry.body.cornerRadius < 0 || definition.geometry.body.cornerRadius > 1) errors.push("Corner radius must be normalized.");
|
|
4619
|
+
if (definition.geometry.tail.anchor < 0 || definition.geometry.tail.anchor > 1) errors.push("Tail anchor must be normalized.");
|
|
4620
|
+
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.");
|
|
4621
|
+
} else if (definition.geometry.commands.length < 4 || !definition.geometry.commands.some((command) => command.kind === "close")) {
|
|
4622
|
+
errors.push("Freeform bubble paths must contain a closed silhouette.");
|
|
4623
|
+
}
|
|
4624
|
+
if (definition.textLayout.padding.some((value) => value < 0 || value > 0.5)) errors.push("Text padding must be normalized between 0 and 0.5.");
|
|
4625
|
+
return errors;
|
|
4626
|
+
}
|
|
4627
|
+
|
|
3998
4628
|
// src/rendering/index.ts
|
|
3999
4629
|
function renderCanonicalToCanvas(ctx, input) {
|
|
4000
4630
|
if (input.capability === "text-template") {
|
|
@@ -4015,11 +4645,27 @@ function renderCanonicalToCanvas(ctx, input) {
|
|
|
4015
4645
|
0 && (module.exports = {
|
|
4016
4646
|
CANONICAL_RENDERER_VERSION,
|
|
4017
4647
|
TEXT_TEMPLATE_RENDERER_VERSION,
|
|
4648
|
+
compileBubblePath,
|
|
4649
|
+
compileBubbleSvg,
|
|
4650
|
+
createBubbleAssetDefinition,
|
|
4651
|
+
createFreeformBubbleAssetDefinition,
|
|
4652
|
+
drawChalkSpeechBubble,
|
|
4653
|
+
drawComicBurst,
|
|
4654
|
+
drawRibbonBanner,
|
|
4655
|
+
drawSpeechBubble,
|
|
4656
|
+
drawThoughtCloud,
|
|
4657
|
+
drawTornPaper,
|
|
4018
4658
|
getTextTemplateControls,
|
|
4659
|
+
pseudoNoise,
|
|
4660
|
+
renderBubbleAssetDefinition,
|
|
4661
|
+
renderBubbleBackground,
|
|
4662
|
+
renderBubblePresetBackground,
|
|
4019
4663
|
renderCanonicalToCanvas,
|
|
4020
4664
|
renderTextEffectToCanvas,
|
|
4021
4665
|
renderTextTemplateToCanvas,
|
|
4666
|
+
resolveBubbleLayout,
|
|
4022
4667
|
resolveTemplateFontFamily,
|
|
4023
|
-
resolveTextTemplateArtifact
|
|
4668
|
+
resolveTextTemplateArtifact,
|
|
4669
|
+
validateBubbleAssetDefinition
|
|
4024
4670
|
});
|
|
4025
4671
|
//# sourceMappingURL=index.cjs.map
|