@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/rendering/index.cjs
CHANGED
|
@@ -21,6 +21,11 @@ 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,
|
|
24
29
|
drawComicBurst: () => drawComicBurst,
|
|
25
30
|
drawRibbonBanner: () => drawRibbonBanner,
|
|
26
31
|
drawSpeechBubble: () => drawSpeechBubble,
|
|
@@ -28,13 +33,16 @@ __export(rendering_exports, {
|
|
|
28
33
|
drawTornPaper: () => drawTornPaper,
|
|
29
34
|
getTextTemplateControls: () => getTextTemplateControls,
|
|
30
35
|
pseudoNoise: () => pseudoNoise,
|
|
36
|
+
renderBubbleAssetDefinition: () => renderBubbleAssetDefinition,
|
|
31
37
|
renderBubbleBackground: () => renderBubbleBackground,
|
|
38
|
+
renderBubblePresetBackground: () => renderBubblePresetBackground,
|
|
32
39
|
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
33
40
|
renderTextEffectToCanvas: () => renderTextEffectToCanvas,
|
|
34
41
|
renderTextTemplateToCanvas: () => renderTextTemplateToCanvas,
|
|
35
42
|
resolveBubbleLayout: () => resolveBubbleLayout,
|
|
36
43
|
resolveTemplateFontFamily: () => resolveTemplateFontFamily,
|
|
37
|
-
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact
|
|
44
|
+
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact,
|
|
45
|
+
validateBubbleAssetDefinition: () => validateBubbleAssetDefinition
|
|
38
46
|
});
|
|
39
47
|
module.exports = __toCommonJS(rendering_exports);
|
|
40
48
|
|
|
@@ -4120,6 +4128,170 @@ function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strok
|
|
|
4120
4128
|
ctx.fill();
|
|
4121
4129
|
ctx.restore();
|
|
4122
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
|
+
}
|
|
4123
4295
|
function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
|
|
4124
4296
|
ctx.save();
|
|
4125
4297
|
ctx.fillStyle = fillColor;
|
|
@@ -4208,6 +4380,11 @@ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
|
4208
4380
|
ctx.restore();
|
|
4209
4381
|
return true;
|
|
4210
4382
|
}
|
|
4383
|
+
if (presetId === "bubble-speech-chalk-rose") {
|
|
4384
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
4385
|
+
ctx.restore();
|
|
4386
|
+
return true;
|
|
4387
|
+
}
|
|
4211
4388
|
if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
|
|
4212
4389
|
drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
|
|
4213
4390
|
ctx.restore();
|
|
@@ -4241,6 +4418,213 @@ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
|
4241
4418
|
return true;
|
|
4242
4419
|
}
|
|
4243
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
|
+
|
|
4244
4628
|
// src/rendering/index.ts
|
|
4245
4629
|
function renderCanonicalToCanvas(ctx, input) {
|
|
4246
4630
|
if (input.capability === "text-template") {
|
|
@@ -4261,6 +4645,11 @@ function renderCanonicalToCanvas(ctx, input) {
|
|
|
4261
4645
|
0 && (module.exports = {
|
|
4262
4646
|
CANONICAL_RENDERER_VERSION,
|
|
4263
4647
|
TEXT_TEMPLATE_RENDERER_VERSION,
|
|
4648
|
+
compileBubblePath,
|
|
4649
|
+
compileBubbleSvg,
|
|
4650
|
+
createBubbleAssetDefinition,
|
|
4651
|
+
createFreeformBubbleAssetDefinition,
|
|
4652
|
+
drawChalkSpeechBubble,
|
|
4264
4653
|
drawComicBurst,
|
|
4265
4654
|
drawRibbonBanner,
|
|
4266
4655
|
drawSpeechBubble,
|
|
@@ -4268,12 +4657,15 @@ function renderCanonicalToCanvas(ctx, input) {
|
|
|
4268
4657
|
drawTornPaper,
|
|
4269
4658
|
getTextTemplateControls,
|
|
4270
4659
|
pseudoNoise,
|
|
4660
|
+
renderBubbleAssetDefinition,
|
|
4271
4661
|
renderBubbleBackground,
|
|
4662
|
+
renderBubblePresetBackground,
|
|
4272
4663
|
renderCanonicalToCanvas,
|
|
4273
4664
|
renderTextEffectToCanvas,
|
|
4274
4665
|
renderTextTemplateToCanvas,
|
|
4275
4666
|
resolveBubbleLayout,
|
|
4276
4667
|
resolveTemplateFontFamily,
|
|
4277
|
-
resolveTextTemplateArtifact
|
|
4668
|
+
resolveTextTemplateArtifact,
|
|
4669
|
+
validateBubbleAssetDefinition
|
|
4278
4670
|
});
|
|
4279
4671
|
//# sourceMappingURL=index.cjs.map
|