@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
|
@@ -2169,6 +2169,170 @@ function drawSpeechBubble(ctx, x, y, width, height, fillColor = "#ffffff", strok
|
|
|
2169
2169
|
ctx.fill();
|
|
2170
2170
|
ctx.restore();
|
|
2171
2171
|
}
|
|
2172
|
+
function drawConfigurableSpeechBubble(ctx, x, y, width, height, appearance) {
|
|
2173
|
+
const tailHeight = Math.min(appearance.tailSize, height * 0.38);
|
|
2174
|
+
const bodyHeight = height - tailHeight;
|
|
2175
|
+
const radius = Math.min(appearance.cornerRadius, bodyHeight / 2);
|
|
2176
|
+
const tailCenter = appearance.tailPosition === "bottom-left" ? x + width * 0.2 : appearance.tailPosition === "bottom-right" ? x + width * 0.8 : x + width * 0.5;
|
|
2177
|
+
const tailWidth = Math.min(Math.max(18, appearance.tailSize * 1.5), width * 0.28);
|
|
2178
|
+
ctx.save();
|
|
2179
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, appearance.fillOpacity));
|
|
2180
|
+
ctx.fillStyle = appearance.fillColor;
|
|
2181
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
2182
|
+
ctx.lineWidth = Math.max(0, appearance.strokeWidth);
|
|
2183
|
+
ctx.beginPath();
|
|
2184
|
+
if (typeof ctx.roundRect === "function") {
|
|
2185
|
+
ctx.roundRect(x, y, width, bodyHeight, radius);
|
|
2186
|
+
} else {
|
|
2187
|
+
ctx.rect(x, y, width, bodyHeight);
|
|
2188
|
+
}
|
|
2189
|
+
ctx.fill();
|
|
2190
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
2191
|
+
ctx.beginPath();
|
|
2192
|
+
ctx.moveTo(tailCenter - tailWidth / 2, y + bodyHeight - 1);
|
|
2193
|
+
ctx.quadraticCurveTo(tailCenter - tailWidth * 0.15, y + bodyHeight + tailHeight * 0.7, tailCenter, y + height);
|
|
2194
|
+
ctx.quadraticCurveTo(tailCenter + tailWidth * 0.18, y + bodyHeight + tailHeight * 0.55, tailCenter + tailWidth / 2, y + bodyHeight - 1);
|
|
2195
|
+
ctx.closePath();
|
|
2196
|
+
ctx.fill();
|
|
2197
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
2198
|
+
ctx.restore();
|
|
2199
|
+
}
|
|
2200
|
+
function renderBubblePresetBackground(ctx, preset, x, y, width, height) {
|
|
2201
|
+
const appearance = preset.appearance;
|
|
2202
|
+
if (!appearance) return renderBubbleBackground(ctx, preset.id, x, y, width, height);
|
|
2203
|
+
ctx.save();
|
|
2204
|
+
switch (appearance.shape) {
|
|
2205
|
+
case "chalk":
|
|
2206
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
2207
|
+
break;
|
|
2208
|
+
case "cloud":
|
|
2209
|
+
drawThoughtCloud(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
2210
|
+
break;
|
|
2211
|
+
case "comic":
|
|
2212
|
+
drawComicBurst(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
2213
|
+
break;
|
|
2214
|
+
case "paper":
|
|
2215
|
+
drawTornPaper(ctx, x, y, width, height, appearance.fillColor, true);
|
|
2216
|
+
break;
|
|
2217
|
+
case "ribbon":
|
|
2218
|
+
drawRibbonBanner(ctx, x, y, width, height, appearance.fillColor, appearance.strokeColor, appearance.strokeWidth);
|
|
2219
|
+
break;
|
|
2220
|
+
case "speech":
|
|
2221
|
+
drawConfigurableSpeechBubble(ctx, x, y, width, height, appearance);
|
|
2222
|
+
break;
|
|
2223
|
+
case "rounded": {
|
|
2224
|
+
ctx.globalAlpha = Math.max(0, Math.min(1, appearance.fillOpacity));
|
|
2225
|
+
ctx.fillStyle = appearance.fillColor;
|
|
2226
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
2227
|
+
ctx.lineWidth = Math.max(0, appearance.strokeWidth);
|
|
2228
|
+
ctx.beginPath();
|
|
2229
|
+
if (typeof ctx.roundRect === "function") {
|
|
2230
|
+
ctx.roundRect(x, y, width, height, Math.min(appearance.cornerRadius, height / 2));
|
|
2231
|
+
} else {
|
|
2232
|
+
ctx.rect(x, y, width, height);
|
|
2233
|
+
}
|
|
2234
|
+
ctx.fill();
|
|
2235
|
+
if (appearance.strokeWidth > 0) ctx.stroke();
|
|
2236
|
+
break;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
if (appearance.texture === "chalk") {
|
|
2240
|
+
ctx.globalAlpha = 0.55;
|
|
2241
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
2242
|
+
ctx.setLineDash([1, 3]);
|
|
2243
|
+
ctx.lineWidth = Math.max(1, appearance.strokeWidth * 0.7);
|
|
2244
|
+
ctx.strokeRect(x + 1, y + 1, width - 2, height - 2);
|
|
2245
|
+
} else if (appearance.texture === "hatch") {
|
|
2246
|
+
ctx.globalAlpha = 0.22;
|
|
2247
|
+
ctx.strokeStyle = appearance.strokeColor;
|
|
2248
|
+
ctx.lineWidth = 1;
|
|
2249
|
+
for (let offset = -height; offset < width; offset += 9) {
|
|
2250
|
+
ctx.beginPath();
|
|
2251
|
+
ctx.moveTo(x + offset, y + height);
|
|
2252
|
+
ctx.lineTo(x + offset + height, y);
|
|
2253
|
+
ctx.stroke();
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
ctx.restore();
|
|
2257
|
+
return true;
|
|
2258
|
+
}
|
|
2259
|
+
function drawChalkSpeechBubble(ctx, x, y, width, height) {
|
|
2260
|
+
ctx.save();
|
|
2261
|
+
const tailHeight = Math.min(46, height * 0.3);
|
|
2262
|
+
const bodyHeight = height - tailHeight;
|
|
2263
|
+
const radius = Math.min(36, bodyHeight * 0.25);
|
|
2264
|
+
const tailLeft = x + width * 0.1;
|
|
2265
|
+
const tailRight = x + width * 0.19;
|
|
2266
|
+
const tailTipX = x + width * 0.14;
|
|
2267
|
+
const tailTipY = y + height;
|
|
2268
|
+
const balloonPath = () => {
|
|
2269
|
+
ctx.beginPath();
|
|
2270
|
+
ctx.moveTo(x + radius, y);
|
|
2271
|
+
ctx.lineTo(x + width - radius, y);
|
|
2272
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
2273
|
+
ctx.lineTo(x + width, y + bodyHeight - radius);
|
|
2274
|
+
ctx.quadraticCurveTo(x + width, y + bodyHeight, x + width - radius, y + bodyHeight);
|
|
2275
|
+
ctx.lineTo(tailRight, y + bodyHeight);
|
|
2276
|
+
ctx.quadraticCurveTo(tailRight - width * 0.02, y + bodyHeight + tailHeight * 0.35, tailTipX, tailTipY);
|
|
2277
|
+
ctx.quadraticCurveTo(tailLeft + width * 5e-3, y + bodyHeight + tailHeight * 0.32, tailLeft, y + bodyHeight);
|
|
2278
|
+
ctx.lineTo(x + radius, y + bodyHeight);
|
|
2279
|
+
ctx.quadraticCurveTo(x, y + bodyHeight, x, y + bodyHeight - radius);
|
|
2280
|
+
ctx.lineTo(x, y + radius);
|
|
2281
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
2282
|
+
ctx.closePath();
|
|
2283
|
+
};
|
|
2284
|
+
ctx.fillStyle = "rgba(184, 122, 132, 0.58)";
|
|
2285
|
+
balloonPath();
|
|
2286
|
+
ctx.fill();
|
|
2287
|
+
ctx.save();
|
|
2288
|
+
ctx.beginPath();
|
|
2289
|
+
ctx.moveTo(x + width * 0.2, y + bodyHeight - tailHeight * 0.13);
|
|
2290
|
+
ctx.quadraticCurveTo(x + width * 0.48, y + bodyHeight + tailHeight * 0.37, x + width * 0.91, y + bodyHeight - tailHeight * 0.02);
|
|
2291
|
+
ctx.quadraticCurveTo(x + width * 0.66, y + bodyHeight + tailHeight * 0.72, x + width * 0.24, y + bodyHeight + tailHeight * 0.44);
|
|
2292
|
+
ctx.closePath();
|
|
2293
|
+
ctx.clip();
|
|
2294
|
+
ctx.shadowColor = "rgba(222, 228, 105, 0.32)";
|
|
2295
|
+
ctx.shadowBlur = 3;
|
|
2296
|
+
ctx.strokeStyle = "rgba(203, 211, 76, 0.52)";
|
|
2297
|
+
ctx.lineWidth = 1.25;
|
|
2298
|
+
for (let offset = -height; offset < width; offset += 9) {
|
|
2299
|
+
ctx.beginPath();
|
|
2300
|
+
ctx.moveTo(x + offset, y + height);
|
|
2301
|
+
ctx.lineTo(x + offset + height, y);
|
|
2302
|
+
ctx.stroke();
|
|
2303
|
+
}
|
|
2304
|
+
ctx.shadowBlur = 0;
|
|
2305
|
+
ctx.strokeStyle = "rgba(255, 250, 196, 0.48)";
|
|
2306
|
+
ctx.lineWidth = 0.8;
|
|
2307
|
+
for (let offset = 0; offset < width + height; offset += 12) {
|
|
2308
|
+
ctx.beginPath();
|
|
2309
|
+
ctx.moveTo(x + offset, y);
|
|
2310
|
+
ctx.lineTo(x + offset - height, y + height);
|
|
2311
|
+
ctx.stroke();
|
|
2312
|
+
}
|
|
2313
|
+
ctx.restore();
|
|
2314
|
+
ctx.strokeStyle = "rgba(255, 253, 246, 0.82)";
|
|
2315
|
+
ctx.lineCap = "round";
|
|
2316
|
+
ctx.lineWidth = 1.35;
|
|
2317
|
+
balloonPath();
|
|
2318
|
+
ctx.stroke();
|
|
2319
|
+
const edgeSegments = 66;
|
|
2320
|
+
for (let index = 0; index < edgeSegments; index++) {
|
|
2321
|
+
const pointX = x + width * (index / edgeSegments);
|
|
2322
|
+
const topNoise = (pseudoNoise(index + 91) - 0.5) * 4;
|
|
2323
|
+
const strokeLength = 0.8 + pseudoNoise(index + 143) * 2.1;
|
|
2324
|
+
ctx.lineWidth = 0.6 + pseudoNoise(index + 211) * 1.1;
|
|
2325
|
+
ctx.beginPath();
|
|
2326
|
+
ctx.moveTo(pointX, y + topNoise);
|
|
2327
|
+
ctx.lineTo(pointX + strokeLength, y + topNoise + (pseudoNoise(index + 19) - 0.5) * 2);
|
|
2328
|
+
ctx.stroke();
|
|
2329
|
+
ctx.beginPath();
|
|
2330
|
+
ctx.moveTo(pointX, y + bodyHeight + topNoise);
|
|
2331
|
+
ctx.lineTo(pointX + strokeLength, y + bodyHeight + topNoise + (pseudoNoise(index + 37) - 0.5) * 2);
|
|
2332
|
+
ctx.stroke();
|
|
2333
|
+
}
|
|
2334
|
+
ctx.restore();
|
|
2335
|
+
}
|
|
2172
2336
|
function drawThoughtCloud(ctx, x, y, width, height, fillColor = "#ffffff", strokeColor = "#000000", strokeWidth = 2) {
|
|
2173
2337
|
ctx.save();
|
|
2174
2338
|
ctx.fillStyle = fillColor;
|
|
@@ -2257,6 +2421,11 @@ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
|
2257
2421
|
ctx.restore();
|
|
2258
2422
|
return true;
|
|
2259
2423
|
}
|
|
2424
|
+
if (presetId === "bubble-speech-chalk-rose") {
|
|
2425
|
+
drawChalkSpeechBubble(ctx, x, y, width, height);
|
|
2426
|
+
ctx.restore();
|
|
2427
|
+
return true;
|
|
2428
|
+
}
|
|
2260
2429
|
if (presetId === "bubble-cloud-dotted" || presetId === "bubble-cloud-morning" || presetId === "bubble-cloud-yellow") {
|
|
2261
2430
|
drawThoughtCloud(ctx, x, y, width, height, color, "#000000", 2);
|
|
2262
2431
|
ctx.restore();
|
|
@@ -2290,6 +2459,213 @@ function renderBubbleBackground(ctx, presetId, x, y, width, height, options) {
|
|
|
2290
2459
|
return true;
|
|
2291
2460
|
}
|
|
2292
2461
|
|
|
2462
|
+
// src/rendering/bubbleAssets.ts
|
|
2463
|
+
var createBubbleAssetDefinition = () => ({
|
|
2464
|
+
schemaVersion: 1,
|
|
2465
|
+
type: "clypra.textBubble",
|
|
2466
|
+
coordinateSpace: "normalized",
|
|
2467
|
+
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 } },
|
|
2468
|
+
layers: { fill: { color: "#7c3aed", opacity: 0.9 }, outline: { color: "#ffffff", width: 0.018, roughness: 0, seed: 1 } },
|
|
2469
|
+
textLayout: { padding: [0.1, 0.1, 0.18, 0.1], alignment: "center", overflow: "grow" }
|
|
2470
|
+
});
|
|
2471
|
+
var createFreeformBubbleAssetDefinition = () => ({
|
|
2472
|
+
...createBubbleAssetDefinition(),
|
|
2473
|
+
geometry: {
|
|
2474
|
+
kind: "freeform-path",
|
|
2475
|
+
closed: true,
|
|
2476
|
+
commands: [
|
|
2477
|
+
{ kind: "move", to: [0.12, 0.04] },
|
|
2478
|
+
{ kind: "line", to: [0.88, 0.04] },
|
|
2479
|
+
{ kind: "quadratic", control: [0.98, 0.04], to: [0.98, 0.16] },
|
|
2480
|
+
{ kind: "line", to: [0.98, 0.7] },
|
|
2481
|
+
{ kind: "quadratic", control: [0.98, 0.82], to: [0.86, 0.82] },
|
|
2482
|
+
{ kind: "line", to: [0.38, 0.82] },
|
|
2483
|
+
{ kind: "line", to: [0.22, 1] },
|
|
2484
|
+
{ kind: "line", to: [0.27, 0.82] },
|
|
2485
|
+
{ kind: "line", to: [0.12, 0.82] },
|
|
2486
|
+
{ kind: "quadratic", control: [0.02, 0.82], to: [0.02, 0.7] },
|
|
2487
|
+
{ kind: "line", to: [0.02, 0.16] },
|
|
2488
|
+
{ kind: "quadratic", control: [0.02, 0.04], to: [0.12, 0.04] },
|
|
2489
|
+
{ kind: "close" }
|
|
2490
|
+
]
|
|
2491
|
+
}
|
|
2492
|
+
});
|
|
2493
|
+
var clamp = (value) => Math.max(0, Math.min(1, value));
|
|
2494
|
+
function compileBubblePath(definition) {
|
|
2495
|
+
if (definition.geometry.kind === "freeform-path") {
|
|
2496
|
+
return definition.geometry.commands.map((command) => {
|
|
2497
|
+
if (command.kind === "close") return "Z";
|
|
2498
|
+
if (command.kind === "move") return `M ${command.to[0]} ${command.to[1]}`;
|
|
2499
|
+
if (command.kind === "line") return `L ${command.to[0]} ${command.to[1]}`;
|
|
2500
|
+
if (command.kind === "quadratic") return `Q ${command.control[0]} ${command.control[1]} ${command.to[0]} ${command.to[1]}`;
|
|
2501
|
+
if (command.kind === "cubic") return `C ${command.control1[0]} ${command.control1[1]} ${command.control2[0]} ${command.control2[1]} ${command.to[0]} ${command.to[1]}`;
|
|
2502
|
+
return "";
|
|
2503
|
+
}).join(" ");
|
|
2504
|
+
}
|
|
2505
|
+
const { body, tail } = definition.geometry;
|
|
2506
|
+
const r = clamp(body.cornerRadius) * 0.5;
|
|
2507
|
+
const anchor = clamp(tail.anchor);
|
|
2508
|
+
const tailWidth = clamp(tail.width) * 0.5;
|
|
2509
|
+
const depth = clamp(tail.depth);
|
|
2510
|
+
const left = clamp(anchor - tailWidth);
|
|
2511
|
+
const right = clamp(anchor + tailWidth);
|
|
2512
|
+
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`;
|
|
2513
|
+
if (!tail.enabled) return bodyPath;
|
|
2514
|
+
if (tail.side === "bottom") {
|
|
2515
|
+
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`;
|
|
2516
|
+
}
|
|
2517
|
+
if (tail.side === "top") {
|
|
2518
|
+
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`;
|
|
2519
|
+
}
|
|
2520
|
+
if (tail.side === "left") {
|
|
2521
|
+
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`;
|
|
2522
|
+
}
|
|
2523
|
+
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`;
|
|
2524
|
+
}
|
|
2525
|
+
function compileBubbleSvg(definition, width = 1e3, height = 700) {
|
|
2526
|
+
const { fill, outline, accent } = definition.layers;
|
|
2527
|
+
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>` : "";
|
|
2528
|
+
const textureOverlay = accent?.texture === "hatch" ? `<path d="${compileBubblePath(definition)}" fill="url(#hatch)" />` : "";
|
|
2529
|
+
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>`;
|
|
2530
|
+
}
|
|
2531
|
+
function traceBubbleSilhouette(ctx, x, y, width, height, radius, tail, tailDepth) {
|
|
2532
|
+
const r = Math.min(radius, width / 2, height / 2);
|
|
2533
|
+
const anchor = clamp(tail.anchor);
|
|
2534
|
+
const halfTail = clamp(tail.width) * (tail.side === "left" || tail.side === "right" ? height : width) / 2;
|
|
2535
|
+
const along = tail.side === "left" || tail.side === "right" ? y + height * anchor : x + width * anchor;
|
|
2536
|
+
ctx.beginPath();
|
|
2537
|
+
ctx.moveTo(x + r, y);
|
|
2538
|
+
if (tail.enabled && tail.side === "top") {
|
|
2539
|
+
ctx.lineTo(along - halfTail, y);
|
|
2540
|
+
ctx.quadraticCurveTo(along - halfTail * 0.35, y - tailDepth * tail.curvature, along, y - tailDepth);
|
|
2541
|
+
ctx.quadraticCurveTo(along + halfTail * 0.35, y - tailDepth * tail.curvature, along + halfTail, y);
|
|
2542
|
+
}
|
|
2543
|
+
ctx.lineTo(x + width - r, y);
|
|
2544
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
|
|
2545
|
+
if (tail.enabled && tail.side === "right") {
|
|
2546
|
+
ctx.lineTo(x + width, along - halfTail);
|
|
2547
|
+
ctx.quadraticCurveTo(x + width + tailDepth * tail.curvature, along - halfTail * 0.35, x + width + tailDepth, along);
|
|
2548
|
+
ctx.quadraticCurveTo(x + width + tailDepth * tail.curvature, along + halfTail * 0.35, x + width, along + halfTail);
|
|
2549
|
+
}
|
|
2550
|
+
ctx.lineTo(x + width, y + height - r);
|
|
2551
|
+
ctx.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
|
|
2552
|
+
if (tail.enabled && tail.side === "bottom") {
|
|
2553
|
+
ctx.lineTo(along + halfTail, y + height);
|
|
2554
|
+
ctx.quadraticCurveTo(along + halfTail * 0.35, y + height + tailDepth * tail.curvature, along, y + height + tailDepth);
|
|
2555
|
+
ctx.quadraticCurveTo(along - halfTail * 0.35, y + height + tailDepth * tail.curvature, along - halfTail, y + height);
|
|
2556
|
+
}
|
|
2557
|
+
ctx.lineTo(x + r, y + height);
|
|
2558
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
|
|
2559
|
+
if (tail.enabled && tail.side === "left") {
|
|
2560
|
+
ctx.lineTo(x, along + halfTail);
|
|
2561
|
+
ctx.quadraticCurveTo(x - tailDepth * tail.curvature, along + halfTail * 0.35, x - tailDepth, along);
|
|
2562
|
+
ctx.quadraticCurveTo(x - tailDepth * tail.curvature, along - halfTail * 0.35, x, along - halfTail);
|
|
2563
|
+
}
|
|
2564
|
+
ctx.lineTo(x, y + r);
|
|
2565
|
+
ctx.quadraticCurveTo(x, y, x + r, y);
|
|
2566
|
+
ctx.closePath();
|
|
2567
|
+
}
|
|
2568
|
+
function renderBubbleAssetDefinition(ctx, definition, x, y, width, height) {
|
|
2569
|
+
if (definition.geometry.kind === "freeform-path") {
|
|
2570
|
+
renderFreeformBubbleAssetDefinition(ctx, definition, x, y, width, height);
|
|
2571
|
+
return;
|
|
2572
|
+
}
|
|
2573
|
+
const { tail, body } = definition.geometry;
|
|
2574
|
+
const tailDepth = tail.enabled ? clamp(tail.depth) * (tail.side === "left" || tail.side === "right" ? width : height) : 0;
|
|
2575
|
+
const bodyX = x + (tail.side === "left" ? tailDepth : 0);
|
|
2576
|
+
const bodyY = y + (tail.side === "top" ? tailDepth : 0);
|
|
2577
|
+
const bodyWidth = width - (tail.side === "left" || tail.side === "right" ? tailDepth : 0);
|
|
2578
|
+
const bodyHeight = height - (tail.side === "top" || tail.side === "bottom" ? tailDepth : 0);
|
|
2579
|
+
const radius = clamp(body.cornerRadius) * Math.min(bodyWidth, bodyHeight) / 2;
|
|
2580
|
+
ctx.save();
|
|
2581
|
+
traceBubbleSilhouette(ctx, bodyX, bodyY, bodyWidth, bodyHeight, radius, tail, tailDepth);
|
|
2582
|
+
ctx.globalAlpha = definition.layers.fill.opacity;
|
|
2583
|
+
ctx.fillStyle = definition.layers.fill.color;
|
|
2584
|
+
ctx.fill();
|
|
2585
|
+
const accent = definition.layers.accent;
|
|
2586
|
+
if (accent && accent.texture !== "none") {
|
|
2587
|
+
ctx.save();
|
|
2588
|
+
ctx.clip();
|
|
2589
|
+
ctx.globalAlpha = accent.opacity;
|
|
2590
|
+
ctx.strokeStyle = accent.color;
|
|
2591
|
+
ctx.lineWidth = Math.max(1, Math.min(width, height) * 6e-3);
|
|
2592
|
+
if (accent.texture === "hatch") {
|
|
2593
|
+
const spacing = Math.max(5, Math.min(width, height) * 0.09);
|
|
2594
|
+
for (let offset = -height; offset < width + height; offset += spacing) {
|
|
2595
|
+
ctx.beginPath();
|
|
2596
|
+
ctx.moveTo(x + offset, y + height);
|
|
2597
|
+
ctx.lineTo(x + offset + height, y);
|
|
2598
|
+
ctx.stroke();
|
|
2599
|
+
}
|
|
2600
|
+
} else {
|
|
2601
|
+
let state = definition.layers.outline.seed >>> 0;
|
|
2602
|
+
const nextRandom = () => {
|
|
2603
|
+
state = state * 1664525 + 1013904223 >>> 0;
|
|
2604
|
+
return state / 4294967296;
|
|
2605
|
+
};
|
|
2606
|
+
const count = Math.max(18, Math.round(width * height / 700));
|
|
2607
|
+
for (let index = 0; index < count; index += 1) {
|
|
2608
|
+
const px = x + nextRandom() * width;
|
|
2609
|
+
const py = y + nextRandom() * height;
|
|
2610
|
+
const length = 1 + nextRandom() * Math.min(width, height) * 0.025;
|
|
2611
|
+
ctx.beginPath();
|
|
2612
|
+
ctx.moveTo(px, py);
|
|
2613
|
+
ctx.lineTo(px + length, py);
|
|
2614
|
+
ctx.stroke();
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
ctx.restore();
|
|
2618
|
+
}
|
|
2619
|
+
if (definition.layers.outline.width > 0) {
|
|
2620
|
+
ctx.globalAlpha = 1;
|
|
2621
|
+
ctx.strokeStyle = definition.layers.outline.color;
|
|
2622
|
+
ctx.lineWidth = definition.layers.outline.width * Math.min(width, height);
|
|
2623
|
+
ctx.stroke();
|
|
2624
|
+
}
|
|
2625
|
+
ctx.restore();
|
|
2626
|
+
}
|
|
2627
|
+
function traceFreeformPath(ctx, definition, x, y, width, height) {
|
|
2628
|
+
ctx.beginPath();
|
|
2629
|
+
for (const command of definition.geometry.commands) {
|
|
2630
|
+
if (command.kind === "close") ctx.closePath();
|
|
2631
|
+
else if (command.kind === "move") ctx.moveTo(x + command.to[0] * width, y + command.to[1] * height);
|
|
2632
|
+
else if (command.kind === "line") ctx.lineTo(x + command.to[0] * width, y + command.to[1] * height);
|
|
2633
|
+
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);
|
|
2634
|
+
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);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function renderFreeformBubbleAssetDefinition(ctx, definition, x, y, width, height) {
|
|
2638
|
+
ctx.save();
|
|
2639
|
+
traceFreeformPath(ctx, definition, x, y, width, height);
|
|
2640
|
+
ctx.globalAlpha = definition.layers.fill.opacity;
|
|
2641
|
+
ctx.fillStyle = definition.layers.fill.color;
|
|
2642
|
+
ctx.fill();
|
|
2643
|
+
if (definition.layers.outline.width > 0) {
|
|
2644
|
+
ctx.globalAlpha = 1;
|
|
2645
|
+
ctx.strokeStyle = definition.layers.outline.color;
|
|
2646
|
+
ctx.lineWidth = definition.layers.outline.width * Math.min(width, height);
|
|
2647
|
+
ctx.stroke();
|
|
2648
|
+
}
|
|
2649
|
+
ctx.restore();
|
|
2650
|
+
}
|
|
2651
|
+
function validateBubbleAssetDefinition(definition) {
|
|
2652
|
+
const errors = [];
|
|
2653
|
+
if (definition.schemaVersion !== 1 || definition.type !== "clypra.textBubble") errors.push("Unsupported bubble asset schema.");
|
|
2654
|
+
if (!/^#[0-9a-f]{6}$/i.test(definition.layers.fill.color)) errors.push("Fill color must be a six-digit hex value.");
|
|
2655
|
+
if (definition.layers.fill.opacity < 0 || definition.layers.fill.opacity > 1) errors.push("Fill opacity must be between 0 and 1.");
|
|
2656
|
+
if (!/^#[0-9a-f]{6}$/i.test(definition.layers.outline.color)) errors.push("Outline color must be a six-digit hex value.");
|
|
2657
|
+
if (definition.layers.outline.width < 0 || definition.layers.outline.width > 0.1) errors.push("Outline width must be normalized between 0 and 0.1.");
|
|
2658
|
+
if (definition.geometry.kind === "parametric-path") {
|
|
2659
|
+
if (definition.geometry.body.cornerRadius < 0 || definition.geometry.body.cornerRadius > 1) errors.push("Corner radius must be normalized.");
|
|
2660
|
+
if (definition.geometry.tail.anchor < 0 || definition.geometry.tail.anchor > 1) errors.push("Tail anchor must be normalized.");
|
|
2661
|
+
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.");
|
|
2662
|
+
} else if (definition.geometry.commands.length < 4 || !definition.geometry.commands.some((command) => command.kind === "close")) {
|
|
2663
|
+
errors.push("Freeform bubble paths must contain a closed silhouette.");
|
|
2664
|
+
}
|
|
2665
|
+
if (definition.textLayout.padding.some((value) => value < 0 || value > 0.5)) errors.push("Text padding must be normalized between 0 and 0.5.");
|
|
2666
|
+
return errors;
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2293
2669
|
// src/rendering/index.ts
|
|
2294
2670
|
function renderCanonicalToCanvas(ctx, input) {
|
|
2295
2671
|
if (input.capability === "text-template") {
|
|
@@ -2348,10 +2724,18 @@ export {
|
|
|
2348
2724
|
pseudoNoise,
|
|
2349
2725
|
drawTornPaper,
|
|
2350
2726
|
drawSpeechBubble,
|
|
2727
|
+
renderBubblePresetBackground,
|
|
2728
|
+
drawChalkSpeechBubble,
|
|
2351
2729
|
drawThoughtCloud,
|
|
2352
2730
|
drawComicBurst,
|
|
2353
2731
|
drawRibbonBanner,
|
|
2354
2732
|
renderBubbleBackground,
|
|
2733
|
+
createBubbleAssetDefinition,
|
|
2734
|
+
createFreeformBubbleAssetDefinition,
|
|
2735
|
+
compileBubblePath,
|
|
2736
|
+
compileBubbleSvg,
|
|
2737
|
+
renderBubbleAssetDefinition,
|
|
2738
|
+
validateBubbleAssetDefinition,
|
|
2355
2739
|
renderCanonicalToCanvas
|
|
2356
2740
|
};
|
|
2357
|
-
//# sourceMappingURL=chunk-
|
|
2741
|
+
//# sourceMappingURL=chunk-ZV3RQAUJ.js.map
|