@clypra-studio/engine 1.9.0 → 1.10.1
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-KUJR5V3B.js} +247 -1
- package/dist/chunk-KUJR5V3B.js.map +1 -0
- package/dist/{index-XWLBYyFQ.d.ts → index--k_VrUnv.d.ts} +132 -1
- package/dist/{index-FDQDo2pR.d.cts → index-n6E8NGM_.d.cts} +132 -1
- package/dist/index.cjs +440 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -3
- package/dist/index.d.ts +65 -3
- package/dist/index.js +196 -10
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +254 -0
- 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 +17 -1
- package/package.json +3 -3
- package/dist/chunk-JP44RJUI.js.map +0 -1
package/dist/rendering/index.cjs
CHANGED
|
@@ -21,10 +21,18 @@ 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
|
+
drawComicBurst: () => drawComicBurst,
|
|
25
|
+
drawRibbonBanner: () => drawRibbonBanner,
|
|
26
|
+
drawSpeechBubble: () => drawSpeechBubble,
|
|
27
|
+
drawThoughtCloud: () => drawThoughtCloud,
|
|
28
|
+
drawTornPaper: () => drawTornPaper,
|
|
24
29
|
getTextTemplateControls: () => getTextTemplateControls,
|
|
30
|
+
pseudoNoise: () => pseudoNoise,
|
|
31
|
+
renderBubbleBackground: () => renderBubbleBackground,
|
|
25
32
|
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
26
33
|
renderTextEffectToCanvas: () => renderTextEffectToCanvas,
|
|
27
34
|
renderTextTemplateToCanvas: () => renderTextTemplateToCanvas,
|
|
35
|
+
resolveBubbleLayout: () => resolveBubbleLayout,
|
|
28
36
|
resolveTemplateFontFamily: () => resolveTemplateFontFamily,
|
|
29
37
|
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact
|
|
30
38
|
});
|
|
@@ -3995,6 +4003,244 @@ function renderTextTemplateToCanvas(ctx, input) {
|
|
|
3995
4003
|
};
|
|
3996
4004
|
}
|
|
3997
4005
|
|
|
4006
|
+
// src/rendering/textBubbles.ts
|
|
4007
|
+
function resolveBubbleLayout(textWidth, textHeight, layout) {
|
|
4008
|
+
const p = layout.padding ?? {
|
|
4009
|
+
top: 14,
|
|
4010
|
+
right: 18,
|
|
4011
|
+
bottom: 14,
|
|
4012
|
+
left: 18
|
|
4013
|
+
};
|
|
4014
|
+
const rawOuterW = textWidth + p.left + p.right;
|
|
4015
|
+
const rawOuterH = textHeight + p.top + p.bottom;
|
|
4016
|
+
let outerWidth = Math.max(rawOuterW, layout.minWidth);
|
|
4017
|
+
let outerHeight = Math.max(rawOuterH, layout.minHeight);
|
|
4018
|
+
if (layout.preserveAspectRatio && layout.minWidth > 0 && layout.minHeight > 0) {
|
|
4019
|
+
const aspect = layout.minWidth / layout.minHeight;
|
|
4020
|
+
const currentAspect = outerWidth / outerHeight;
|
|
4021
|
+
if (currentAspect > aspect) {
|
|
4022
|
+
outerHeight = outerWidth / aspect;
|
|
4023
|
+
} else {
|
|
4024
|
+
outerWidth = outerHeight * aspect;
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
const textOffsetX = (p.left - p.right) / 2;
|
|
4028
|
+
const textOffsetY = (p.top - p.bottom) / 2;
|
|
4029
|
+
return {
|
|
4030
|
+
outerWidth,
|
|
4031
|
+
outerHeight,
|
|
4032
|
+
textOffsetX,
|
|
4033
|
+
textOffsetY,
|
|
4034
|
+
contentWidth: outerWidth - p.left - p.right,
|
|
4035
|
+
contentHeight: outerHeight - p.top - p.bottom
|
|
4036
|
+
};
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
// src/rendering/bubbleRenderer.ts
|
|
4040
|
+
function pseudoNoise(seed) {
|
|
4041
|
+
const x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
|
|
4042
|
+
return x - Math.floor(x);
|
|
4043
|
+
}
|
|
4044
|
+
function drawTornPaper(ctx, x, y, width, height, fillColor = "#faf9f6", shadow = true) {
|
|
4045
|
+
ctx.save();
|
|
4046
|
+
if (shadow) {
|
|
4047
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0.35)";
|
|
4048
|
+
ctx.shadowBlur = 12;
|
|
4049
|
+
ctx.shadowOffsetX = 0;
|
|
4050
|
+
ctx.shadowOffsetY = 4;
|
|
4051
|
+
}
|
|
4052
|
+
ctx.fillStyle = fillColor;
|
|
4053
|
+
ctx.beginPath();
|
|
4054
|
+
const steps = Math.max(16, Math.floor(width / 14));
|
|
4055
|
+
const stepW = width / steps;
|
|
4056
|
+
ctx.moveTo(x, y + 6);
|
|
4057
|
+
for (let i = 0; i <= steps; i++) {
|
|
4058
|
+
const curX = x + i * stepW;
|
|
4059
|
+
const n = pseudoNoise(i * 1.37 + 10);
|
|
4060
|
+
const wave = Math.sin(i / steps * Math.PI * 3) * 3;
|
|
4061
|
+
const curY = y + (n * 5 - 2.5) + wave;
|
|
4062
|
+
if (i === 0) ctx.lineTo(curX, curY);
|
|
4063
|
+
else ctx.lineTo(curX, curY);
|
|
4064
|
+
}
|
|
4065
|
+
ctx.lineTo(x + width, y + height - 6);
|
|
4066
|
+
for (let i = steps; i >= 0; i--) {
|
|
4067
|
+
const curX = x + i * stepW;
|
|
4068
|
+
const n = pseudoNoise(i * 2.19 + 50);
|
|
4069
|
+
const wave = Math.sin(i / steps * Math.PI * 2) * 4;
|
|
4070
|
+
const curY = y + height + (n * 6 - 3) + wave;
|
|
4071
|
+
ctx.lineTo(curX, curY);
|
|
4072
|
+
}
|
|
4073
|
+
ctx.lineTo(x, y + 6);
|
|
4074
|
+
ctx.closePath();
|
|
4075
|
+
ctx.fill();
|
|
4076
|
+
if (shadow) {
|
|
4077
|
+
ctx.shadowColor = "transparent";
|
|
4078
|
+
ctx.shadowBlur = 0;
|
|
4079
|
+
}
|
|
4080
|
+
const paperGrad = ctx.createLinearGradient(x, y, x, y + height);
|
|
4081
|
+
paperGrad.addColorStop(0, "rgba(255, 255, 255, 0.4)");
|
|
4082
|
+
paperGrad.addColorStop(0.5, "rgba(0, 0, 0, 0.02)");
|
|
4083
|
+
paperGrad.addColorStop(1, "rgba(0, 0, 0, 0.06)");
|
|
4084
|
+
ctx.fillStyle = paperGrad;
|
|
4085
|
+
ctx.fill();
|
|
4086
|
+
ctx.restore();
|
|
4087
|
+
}
|
|
4088
|
+
function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2, radius = 16) {
|
|
4089
|
+
ctx.save();
|
|
4090
|
+
const tailH = Math.min(16, height * 0.25);
|
|
4091
|
+
const bodyH = height - tailH;
|
|
4092
|
+
ctx.fillStyle = fillColor;
|
|
4093
|
+
ctx.strokeStyle = strokeColor;
|
|
4094
|
+
ctx.lineWidth = strokeWidth;
|
|
4095
|
+
ctx.beginPath();
|
|
4096
|
+
if (typeof ctx.roundRect === "function") {
|
|
4097
|
+
ctx.roundRect(x, y, width, bodyH, radius);
|
|
4098
|
+
} else {
|
|
4099
|
+
ctx.rect(x, y, width, bodyH);
|
|
4100
|
+
}
|
|
4101
|
+
ctx.fill();
|
|
4102
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4103
|
+
const tailBaseX = x + width * 0.25;
|
|
4104
|
+
const tailBaseW = Math.min(24, width * 0.2);
|
|
4105
|
+
const tailTipX = x + width * 0.15;
|
|
4106
|
+
const tailTipY = y + height;
|
|
4107
|
+
ctx.beginPath();
|
|
4108
|
+
ctx.moveTo(tailBaseX, y + bodyH - 2);
|
|
4109
|
+
ctx.quadraticCurveTo(tailBaseX + 2, y + bodyH + tailH * 0.6, tailTipX, tailTipY);
|
|
4110
|
+
ctx.quadraticCurveTo(tailBaseX + tailBaseW * 0.7, y + bodyH + tailH * 0.4, tailBaseX + tailBaseW, y + bodyH - 2);
|
|
4111
|
+
ctx.closePath();
|
|
4112
|
+
ctx.fill();
|
|
4113
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4114
|
+
ctx.beginPath();
|
|
4115
|
+
if (typeof ctx.roundRect === "function") {
|
|
4116
|
+
ctx.roundRect(x + 1, y + 1, width - 2, bodyH - 2, radius);
|
|
4117
|
+
} else {
|
|
4118
|
+
ctx.rect(x + 1, y + 1, width - 2, bodyH - 2);
|
|
4119
|
+
}
|
|
4120
|
+
ctx.fill();
|
|
4121
|
+
ctx.restore();
|
|
4122
|
+
}
|
|
4123
|
+
function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
|
|
4124
|
+
ctx.save();
|
|
4125
|
+
ctx.fillStyle = fillColor;
|
|
4126
|
+
ctx.strokeStyle = strokeColor;
|
|
4127
|
+
ctx.lineWidth = strokeWidth;
|
|
4128
|
+
const cx = x + width / 2;
|
|
4129
|
+
const cy = y + height / 2;
|
|
4130
|
+
const rx = width * 0.44;
|
|
4131
|
+
const ry = height * 0.38;
|
|
4132
|
+
ctx.beginPath();
|
|
4133
|
+
const lobes = 8;
|
|
4134
|
+
for (let i = 0; i < lobes; i++) {
|
|
4135
|
+
const angle = i / lobes * Math.PI * 2;
|
|
4136
|
+
const lx = cx + Math.cos(angle) * rx;
|
|
4137
|
+
const ly = cy + Math.sin(angle) * ry;
|
|
4138
|
+
const lobeR = Math.min(width, height) * 0.28;
|
|
4139
|
+
ctx.moveTo(lx + lobeR, ly);
|
|
4140
|
+
ctx.arc(lx, ly, lobeR, 0, Math.PI * 2);
|
|
4141
|
+
}
|
|
4142
|
+
ctx.fill();
|
|
4143
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4144
|
+
ctx.restore();
|
|
4145
|
+
}
|
|
4146
|
+
function drawComicBurst(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 3) {
|
|
4147
|
+
ctx.save();
|
|
4148
|
+
ctx.fillStyle = fillColor;
|
|
4149
|
+
ctx.strokeStyle = strokeColor;
|
|
4150
|
+
ctx.lineWidth = strokeWidth;
|
|
4151
|
+
const cx = x + width / 2;
|
|
4152
|
+
const cy = y + height / 2;
|
|
4153
|
+
const points = 16;
|
|
4154
|
+
const outerRx = width / 2;
|
|
4155
|
+
const outerRy = height / 2;
|
|
4156
|
+
const innerRx = width * 0.32;
|
|
4157
|
+
const innerRy = height * 0.32;
|
|
4158
|
+
ctx.beginPath();
|
|
4159
|
+
for (let i = 0; i < points * 2; i++) {
|
|
4160
|
+
const angle = i / (points * 2) * Math.PI * 2 - Math.PI / 2;
|
|
4161
|
+
const isOuter = i % 2 === 0;
|
|
4162
|
+
const rx = isOuter ? outerRx : innerRx;
|
|
4163
|
+
const ry = isOuter ? outerRy : innerRy;
|
|
4164
|
+
const px = cx + Math.cos(angle) * rx;
|
|
4165
|
+
const py = cy + Math.sin(angle) * ry;
|
|
4166
|
+
if (i === 0) ctx.moveTo(px, py);
|
|
4167
|
+
else ctx.lineTo(px, py);
|
|
4168
|
+
}
|
|
4169
|
+
ctx.closePath();
|
|
4170
|
+
ctx.fill();
|
|
4171
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4172
|
+
ctx.restore();
|
|
4173
|
+
}
|
|
4174
|
+
function drawRibbonBanner(ctx, x, y, width, height, fillColor = "#facc15", strokeColor = "#000000", strokeWidth = 2) {
|
|
4175
|
+
ctx.save();
|
|
4176
|
+
ctx.fillStyle = fillColor;
|
|
4177
|
+
ctx.strokeStyle = strokeColor;
|
|
4178
|
+
ctx.lineWidth = strokeWidth;
|
|
4179
|
+
const notch = Math.min(18, width * 0.08);
|
|
4180
|
+
ctx.beginPath();
|
|
4181
|
+
ctx.moveTo(x, y);
|
|
4182
|
+
ctx.lineTo(x + width - notch, y);
|
|
4183
|
+
ctx.lineTo(x + width, y + height / 2);
|
|
4184
|
+
ctx.lineTo(x + width - notch, y + height);
|
|
4185
|
+
ctx.lineTo(x, y + height);
|
|
4186
|
+
ctx.lineTo(x + notch, y + height / 2);
|
|
4187
|
+
ctx.closePath();
|
|
4188
|
+
ctx.fill();
|
|
4189
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
4190
|
+
ctx.restore();
|
|
4191
|
+
}
|
|
4192
|
+
function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
4193
|
+
if (!presetId || presetId === "none") return false;
|
|
4194
|
+
const color = options?.color || "#ffffff";
|
|
4195
|
+
const opacity = options?.opacity ?? 1;
|
|
4196
|
+
ctx.save();
|
|
4197
|
+
if (opacity < 1) {
|
|
4198
|
+
ctx.globalAlpha *= opacity;
|
|
4199
|
+
}
|
|
4200
|
+
if (presetId === "bubble-paper-torn" || presetId === "bubble-paper-torn-beige" || presetId === "bubble-paper-kraft" || presetId === "bubble-paper-notebook") {
|
|
4201
|
+
const paperColor = presetId === "bubble-paper-kraft" ? "#d4a373" : presetId === "bubble-paper-torn-beige" ? "#f3eed9" : "#faf9f6";
|
|
4202
|
+
drawTornPaper(ctx, x, y, width, height, color || paperColor, true);
|
|
4203
|
+
ctx.restore();
|
|
4204
|
+
return true;
|
|
4205
|
+
}
|
|
4206
|
+
if (presetId === "bubble-speech-round" || presetId === "bubble-speech-oval" || presetId === "bubble-speech-tall") {
|
|
4207
|
+
drawSpeechBubble(ctx, x, y, width, height, color, "#000000", 2, 16);
|
|
4208
|
+
ctx.restore();
|
|
4209
|
+
return true;
|
|
4210
|
+
}
|
|
4211
|
+
if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
|
|
4212
|
+
drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
|
|
4213
|
+
ctx.restore();
|
|
4214
|
+
return true;
|
|
4215
|
+
}
|
|
4216
|
+
if (presetId === "bubble-comic-bam" || presetId === "bubble-comic-dark-hero") {
|
|
4217
|
+
const burstColor = presetId === "bubble-comic-dark-hero" ? "#18181b" : color;
|
|
4218
|
+
const strokeColor = presetId === "bubble-comic-dark-hero" ? "#ef4444" : "#000000";
|
|
4219
|
+
drawComicBurst(ctx, x, y, width, height, burstColor, strokeColor, 3);
|
|
4220
|
+
ctx.restore();
|
|
4221
|
+
return true;
|
|
4222
|
+
}
|
|
4223
|
+
if (presetId === "bubble-ribbon-sunny" || presetId === "bubble-ribbon-yellow") {
|
|
4224
|
+
drawRibbonBanner(ctx, x, y, width, height, color || "#facc15", "#000000", 2);
|
|
4225
|
+
ctx.restore();
|
|
4226
|
+
return true;
|
|
4227
|
+
}
|
|
4228
|
+
const radius = options?.borderRadius ?? 8;
|
|
4229
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
|
|
4230
|
+
ctx.shadowBlur = 8;
|
|
4231
|
+
ctx.shadowOffsetY = 2;
|
|
4232
|
+
ctx.fillStyle = color;
|
|
4233
|
+
ctx.beginPath();
|
|
4234
|
+
if (typeof ctx.roundRect === "function") {
|
|
4235
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
4236
|
+
} else {
|
|
4237
|
+
ctx.rect(x, y, width, height);
|
|
4238
|
+
}
|
|
4239
|
+
ctx.fill();
|
|
4240
|
+
ctx.restore();
|
|
4241
|
+
return true;
|
|
4242
|
+
}
|
|
4243
|
+
|
|
3998
4244
|
// src/rendering/index.ts
|
|
3999
4245
|
function renderCanonicalToCanvas(ctx, input) {
|
|
4000
4246
|
if (input.capability === "text-template") {
|
|
@@ -4015,10 +4261,18 @@ function renderCanonicalToCanvas(ctx, input) {
|
|
|
4015
4261
|
0 && (module.exports = {
|
|
4016
4262
|
CANONICAL_RENDERER_VERSION,
|
|
4017
4263
|
TEXT_TEMPLATE_RENDERER_VERSION,
|
|
4264
|
+
drawComicBurst,
|
|
4265
|
+
drawRibbonBanner,
|
|
4266
|
+
drawSpeechBubble,
|
|
4267
|
+
drawThoughtCloud,
|
|
4268
|
+
drawTornPaper,
|
|
4018
4269
|
getTextTemplateControls,
|
|
4270
|
+
pseudoNoise,
|
|
4271
|
+
renderBubbleBackground,
|
|
4019
4272
|
renderCanonicalToCanvas,
|
|
4020
4273
|
renderTextEffectToCanvas,
|
|
4021
4274
|
renderTextTemplateToCanvas,
|
|
4275
|
+
resolveBubbleLayout,
|
|
4022
4276
|
resolveTemplateFontFamily,
|
|
4023
4277
|
resolveTextTemplateArtifact
|
|
4024
4278
|
});
|