@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
|
@@ -2052,6 +2052,244 @@ function renderTextTemplateToCanvas(ctx, input) {
|
|
|
2052
2052
|
};
|
|
2053
2053
|
}
|
|
2054
2054
|
|
|
2055
|
+
// src/rendering/textBubbles.ts
|
|
2056
|
+
function resolveBubbleLayout(textWidth, textHeight, layout) {
|
|
2057
|
+
const p = layout.padding ?? {
|
|
2058
|
+
top: 14,
|
|
2059
|
+
right: 18,
|
|
2060
|
+
bottom: 14,
|
|
2061
|
+
left: 18
|
|
2062
|
+
};
|
|
2063
|
+
const rawOuterW = textWidth + p.left + p.right;
|
|
2064
|
+
const rawOuterH = textHeight + p.top + p.bottom;
|
|
2065
|
+
let outerWidth = Math.max(rawOuterW, layout.minWidth);
|
|
2066
|
+
let outerHeight = Math.max(rawOuterH, layout.minHeight);
|
|
2067
|
+
if (layout.preserveAspectRatio && layout.minWidth > 0 && layout.minHeight > 0) {
|
|
2068
|
+
const aspect = layout.minWidth / layout.minHeight;
|
|
2069
|
+
const currentAspect = outerWidth / outerHeight;
|
|
2070
|
+
if (currentAspect > aspect) {
|
|
2071
|
+
outerHeight = outerWidth / aspect;
|
|
2072
|
+
} else {
|
|
2073
|
+
outerWidth = outerHeight * aspect;
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
const textOffsetX = (p.left - p.right) / 2;
|
|
2077
|
+
const textOffsetY = (p.top - p.bottom) / 2;
|
|
2078
|
+
return {
|
|
2079
|
+
outerWidth,
|
|
2080
|
+
outerHeight,
|
|
2081
|
+
textOffsetX,
|
|
2082
|
+
textOffsetY,
|
|
2083
|
+
contentWidth: outerWidth - p.left - p.right,
|
|
2084
|
+
contentHeight: outerHeight - p.top - p.bottom
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
// src/rendering/bubbleRenderer.ts
|
|
2089
|
+
function pseudoNoise(seed) {
|
|
2090
|
+
const x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
|
|
2091
|
+
return x - Math.floor(x);
|
|
2092
|
+
}
|
|
2093
|
+
function drawTornPaper(ctx, x, y, width, height, fillColor = "#faf9f6", shadow = true) {
|
|
2094
|
+
ctx.save();
|
|
2095
|
+
if (shadow) {
|
|
2096
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0.35)";
|
|
2097
|
+
ctx.shadowBlur = 12;
|
|
2098
|
+
ctx.shadowOffsetX = 0;
|
|
2099
|
+
ctx.shadowOffsetY = 4;
|
|
2100
|
+
}
|
|
2101
|
+
ctx.fillStyle = fillColor;
|
|
2102
|
+
ctx.beginPath();
|
|
2103
|
+
const steps = Math.max(16, Math.floor(width / 14));
|
|
2104
|
+
const stepW = width / steps;
|
|
2105
|
+
ctx.moveTo(x, y + 6);
|
|
2106
|
+
for (let i = 0; i <= steps; i++) {
|
|
2107
|
+
const curX = x + i * stepW;
|
|
2108
|
+
const n = pseudoNoise(i * 1.37 + 10);
|
|
2109
|
+
const wave = Math.sin(i / steps * Math.PI * 3) * 3;
|
|
2110
|
+
const curY = y + (n * 5 - 2.5) + wave;
|
|
2111
|
+
if (i === 0) ctx.lineTo(curX, curY);
|
|
2112
|
+
else ctx.lineTo(curX, curY);
|
|
2113
|
+
}
|
|
2114
|
+
ctx.lineTo(x + width, y + height - 6);
|
|
2115
|
+
for (let i = steps; i >= 0; i--) {
|
|
2116
|
+
const curX = x + i * stepW;
|
|
2117
|
+
const n = pseudoNoise(i * 2.19 + 50);
|
|
2118
|
+
const wave = Math.sin(i / steps * Math.PI * 2) * 4;
|
|
2119
|
+
const curY = y + height + (n * 6 - 3) + wave;
|
|
2120
|
+
ctx.lineTo(curX, curY);
|
|
2121
|
+
}
|
|
2122
|
+
ctx.lineTo(x, y + 6);
|
|
2123
|
+
ctx.closePath();
|
|
2124
|
+
ctx.fill();
|
|
2125
|
+
if (shadow) {
|
|
2126
|
+
ctx.shadowColor = "transparent";
|
|
2127
|
+
ctx.shadowBlur = 0;
|
|
2128
|
+
}
|
|
2129
|
+
const paperGrad = ctx.createLinearGradient(x, y, x, y + height);
|
|
2130
|
+
paperGrad.addColorStop(0, "rgba(255, 255, 255, 0.4)");
|
|
2131
|
+
paperGrad.addColorStop(0.5, "rgba(0, 0, 0, 0.02)");
|
|
2132
|
+
paperGrad.addColorStop(1, "rgba(0, 0, 0, 0.06)");
|
|
2133
|
+
ctx.fillStyle = paperGrad;
|
|
2134
|
+
ctx.fill();
|
|
2135
|
+
ctx.restore();
|
|
2136
|
+
}
|
|
2137
|
+
function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2, radius = 16) {
|
|
2138
|
+
ctx.save();
|
|
2139
|
+
const tailH = Math.min(16, height * 0.25);
|
|
2140
|
+
const bodyH = height - tailH;
|
|
2141
|
+
ctx.fillStyle = fillColor;
|
|
2142
|
+
ctx.strokeStyle = strokeColor;
|
|
2143
|
+
ctx.lineWidth = strokeWidth;
|
|
2144
|
+
ctx.beginPath();
|
|
2145
|
+
if (typeof ctx.roundRect === "function") {
|
|
2146
|
+
ctx.roundRect(x, y, width, bodyH, radius);
|
|
2147
|
+
} else {
|
|
2148
|
+
ctx.rect(x, y, width, bodyH);
|
|
2149
|
+
}
|
|
2150
|
+
ctx.fill();
|
|
2151
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
2152
|
+
const tailBaseX = x + width * 0.25;
|
|
2153
|
+
const tailBaseW = Math.min(24, width * 0.2);
|
|
2154
|
+
const tailTipX = x + width * 0.15;
|
|
2155
|
+
const tailTipY = y + height;
|
|
2156
|
+
ctx.beginPath();
|
|
2157
|
+
ctx.moveTo(tailBaseX, y + bodyH - 2);
|
|
2158
|
+
ctx.quadraticCurveTo(tailBaseX + 2, y + bodyH + tailH * 0.6, tailTipX, tailTipY);
|
|
2159
|
+
ctx.quadraticCurveTo(tailBaseX + tailBaseW * 0.7, y + bodyH + tailH * 0.4, tailBaseX + tailBaseW, y + bodyH - 2);
|
|
2160
|
+
ctx.closePath();
|
|
2161
|
+
ctx.fill();
|
|
2162
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
2163
|
+
ctx.beginPath();
|
|
2164
|
+
if (typeof ctx.roundRect === "function") {
|
|
2165
|
+
ctx.roundRect(x + 1, y + 1, width - 2, bodyH - 2, radius);
|
|
2166
|
+
} else {
|
|
2167
|
+
ctx.rect(x + 1, y + 1, width - 2, bodyH - 2);
|
|
2168
|
+
}
|
|
2169
|
+
ctx.fill();
|
|
2170
|
+
ctx.restore();
|
|
2171
|
+
}
|
|
2172
|
+
function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
|
|
2173
|
+
ctx.save();
|
|
2174
|
+
ctx.fillStyle = fillColor;
|
|
2175
|
+
ctx.strokeStyle = strokeColor;
|
|
2176
|
+
ctx.lineWidth = strokeWidth;
|
|
2177
|
+
const cx = x + width / 2;
|
|
2178
|
+
const cy = y + height / 2;
|
|
2179
|
+
const rx = width * 0.44;
|
|
2180
|
+
const ry = height * 0.38;
|
|
2181
|
+
ctx.beginPath();
|
|
2182
|
+
const lobes = 8;
|
|
2183
|
+
for (let i = 0; i < lobes; i++) {
|
|
2184
|
+
const angle = i / lobes * Math.PI * 2;
|
|
2185
|
+
const lx = cx + Math.cos(angle) * rx;
|
|
2186
|
+
const ly = cy + Math.sin(angle) * ry;
|
|
2187
|
+
const lobeR = Math.min(width, height) * 0.28;
|
|
2188
|
+
ctx.moveTo(lx + lobeR, ly);
|
|
2189
|
+
ctx.arc(lx, ly, lobeR, 0, Math.PI * 2);
|
|
2190
|
+
}
|
|
2191
|
+
ctx.fill();
|
|
2192
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
2193
|
+
ctx.restore();
|
|
2194
|
+
}
|
|
2195
|
+
function drawComicBurst(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 3) {
|
|
2196
|
+
ctx.save();
|
|
2197
|
+
ctx.fillStyle = fillColor;
|
|
2198
|
+
ctx.strokeStyle = strokeColor;
|
|
2199
|
+
ctx.lineWidth = strokeWidth;
|
|
2200
|
+
const cx = x + width / 2;
|
|
2201
|
+
const cy = y + height / 2;
|
|
2202
|
+
const points = 16;
|
|
2203
|
+
const outerRx = width / 2;
|
|
2204
|
+
const outerRy = height / 2;
|
|
2205
|
+
const innerRx = width * 0.32;
|
|
2206
|
+
const innerRy = height * 0.32;
|
|
2207
|
+
ctx.beginPath();
|
|
2208
|
+
for (let i = 0; i < points * 2; i++) {
|
|
2209
|
+
const angle = i / (points * 2) * Math.PI * 2 - Math.PI / 2;
|
|
2210
|
+
const isOuter = i % 2 === 0;
|
|
2211
|
+
const rx = isOuter ? outerRx : innerRx;
|
|
2212
|
+
const ry = isOuter ? outerRy : innerRy;
|
|
2213
|
+
const px = cx + Math.cos(angle) * rx;
|
|
2214
|
+
const py = cy + Math.sin(angle) * ry;
|
|
2215
|
+
if (i === 0) ctx.moveTo(px, py);
|
|
2216
|
+
else ctx.lineTo(px, py);
|
|
2217
|
+
}
|
|
2218
|
+
ctx.closePath();
|
|
2219
|
+
ctx.fill();
|
|
2220
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
2221
|
+
ctx.restore();
|
|
2222
|
+
}
|
|
2223
|
+
function drawRibbonBanner(ctx, x, y, width, height, fillColor = "#facc15", strokeColor = "#000000", strokeWidth = 2) {
|
|
2224
|
+
ctx.save();
|
|
2225
|
+
ctx.fillStyle = fillColor;
|
|
2226
|
+
ctx.strokeStyle = strokeColor;
|
|
2227
|
+
ctx.lineWidth = strokeWidth;
|
|
2228
|
+
const notch = Math.min(18, width * 0.08);
|
|
2229
|
+
ctx.beginPath();
|
|
2230
|
+
ctx.moveTo(x, y);
|
|
2231
|
+
ctx.lineTo(x + width - notch, y);
|
|
2232
|
+
ctx.lineTo(x + width, y + height / 2);
|
|
2233
|
+
ctx.lineTo(x + width - notch, y + height);
|
|
2234
|
+
ctx.lineTo(x, y + height);
|
|
2235
|
+
ctx.lineTo(x + notch, y + height / 2);
|
|
2236
|
+
ctx.closePath();
|
|
2237
|
+
ctx.fill();
|
|
2238
|
+
if (strokeWidth > 0) ctx.stroke();
|
|
2239
|
+
ctx.restore();
|
|
2240
|
+
}
|
|
2241
|
+
function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
2242
|
+
if (!presetId || presetId === "none") return false;
|
|
2243
|
+
const color = options?.color || "#ffffff";
|
|
2244
|
+
const opacity = options?.opacity ?? 1;
|
|
2245
|
+
ctx.save();
|
|
2246
|
+
if (opacity < 1) {
|
|
2247
|
+
ctx.globalAlpha *= opacity;
|
|
2248
|
+
}
|
|
2249
|
+
if (presetId === "bubble-paper-torn" || presetId === "bubble-paper-torn-beige" || presetId === "bubble-paper-kraft" || presetId === "bubble-paper-notebook") {
|
|
2250
|
+
const paperColor = presetId === "bubble-paper-kraft" ? "#d4a373" : presetId === "bubble-paper-torn-beige" ? "#f3eed9" : "#faf9f6";
|
|
2251
|
+
drawTornPaper(ctx, x, y, width, height, color || paperColor, true);
|
|
2252
|
+
ctx.restore();
|
|
2253
|
+
return true;
|
|
2254
|
+
}
|
|
2255
|
+
if (presetId === "bubble-speech-round" || presetId === "bubble-speech-oval" || presetId === "bubble-speech-tall") {
|
|
2256
|
+
drawSpeechBubble(ctx, x, y, width, height, color, "#000000", 2, 16);
|
|
2257
|
+
ctx.restore();
|
|
2258
|
+
return true;
|
|
2259
|
+
}
|
|
2260
|
+
if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
|
|
2261
|
+
drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
|
|
2262
|
+
ctx.restore();
|
|
2263
|
+
return true;
|
|
2264
|
+
}
|
|
2265
|
+
if (presetId === "bubble-comic-bam" || presetId === "bubble-comic-dark-hero") {
|
|
2266
|
+
const burstColor = presetId === "bubble-comic-dark-hero" ? "#18181b" : color;
|
|
2267
|
+
const strokeColor = presetId === "bubble-comic-dark-hero" ? "#ef4444" : "#000000";
|
|
2268
|
+
drawComicBurst(ctx, x, y, width, height, burstColor, strokeColor, 3);
|
|
2269
|
+
ctx.restore();
|
|
2270
|
+
return true;
|
|
2271
|
+
}
|
|
2272
|
+
if (presetId === "bubble-ribbon-sunny" || presetId === "bubble-ribbon-yellow") {
|
|
2273
|
+
drawRibbonBanner(ctx, x, y, width, height, color || "#facc15", "#000000", 2);
|
|
2274
|
+
ctx.restore();
|
|
2275
|
+
return true;
|
|
2276
|
+
}
|
|
2277
|
+
const radius = options?.borderRadius ?? 8;
|
|
2278
|
+
ctx.shadowColor = "rgba(0, 0, 0, 0.2)";
|
|
2279
|
+
ctx.shadowBlur = 8;
|
|
2280
|
+
ctx.shadowOffsetY = 2;
|
|
2281
|
+
ctx.fillStyle = color;
|
|
2282
|
+
ctx.beginPath();
|
|
2283
|
+
if (typeof ctx.roundRect === "function") {
|
|
2284
|
+
ctx.roundRect(x, y, width, height, radius);
|
|
2285
|
+
} else {
|
|
2286
|
+
ctx.rect(x, y, width, height);
|
|
2287
|
+
}
|
|
2288
|
+
ctx.fill();
|
|
2289
|
+
ctx.restore();
|
|
2290
|
+
return true;
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2055
2293
|
// src/rendering/index.ts
|
|
2056
2294
|
function renderCanonicalToCanvas(ctx, input) {
|
|
2057
2295
|
if (input.capability === "text-template") {
|
|
@@ -2106,6 +2344,14 @@ export {
|
|
|
2106
2344
|
getTextTemplateControls,
|
|
2107
2345
|
resolveTemplateFontFamily,
|
|
2108
2346
|
renderTextTemplateToCanvas,
|
|
2347
|
+
resolveBubbleLayout,
|
|
2348
|
+
pseudoNoise,
|
|
2349
|
+
drawTornPaper,
|
|
2350
|
+
drawSpeechBubble,
|
|
2351
|
+
drawThoughtCloud,
|
|
2352
|
+
drawComicBurst,
|
|
2353
|
+
drawRibbonBanner,
|
|
2354
|
+
renderBubbleBackground,
|
|
2109
2355
|
renderCanonicalToCanvas
|
|
2110
2356
|
};
|
|
2111
|
-
//# sourceMappingURL=chunk-
|
|
2357
|
+
//# sourceMappingURL=chunk-KUJR5V3B.js.map
|