@clypra/engine 1.2.0 → 1.2.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/index.cjs +22 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -263,35 +263,26 @@ function wrapTextToWidth(ctx, text, maxWidth, letterSpacing) {
|
|
|
263
263
|
const paragraphs = text.split("\n");
|
|
264
264
|
const lines = [];
|
|
265
265
|
for (const para of paragraphs) {
|
|
266
|
-
if (
|
|
266
|
+
if (para === "") {
|
|
267
267
|
lines.push("");
|
|
268
268
|
continue;
|
|
269
269
|
}
|
|
270
|
-
const words = para.split(/\s+/).filter(Boolean);
|
|
271
270
|
let current = "";
|
|
272
|
-
for (
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
for (let i = 0; i < para.length; i++) {
|
|
272
|
+
const char = para[i];
|
|
273
|
+
const tryLine = current + char;
|
|
274
|
+
if (measureLine(ctx, tryLine, letterSpacing) <= maxWidth) {
|
|
275
|
+
current = tryLine;
|
|
276
276
|
} else {
|
|
277
|
-
if (current)
|
|
278
|
-
|
|
279
|
-
let chunk = "";
|
|
280
|
-
for (const ch of word) {
|
|
281
|
-
const tryChunk = chunk + ch;
|
|
282
|
-
if (measureLine(ctx, tryChunk, letterSpacing) <= maxWidth) chunk = tryChunk;
|
|
283
|
-
else {
|
|
284
|
-
if (chunk) lines.push(chunk);
|
|
285
|
-
chunk = ch;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
current = chunk;
|
|
289
|
-
} else {
|
|
290
|
-
current = word;
|
|
277
|
+
if (current) {
|
|
278
|
+
lines.push(current);
|
|
291
279
|
}
|
|
280
|
+
current = char;
|
|
292
281
|
}
|
|
293
282
|
}
|
|
294
|
-
if (current)
|
|
283
|
+
if (current) {
|
|
284
|
+
lines.push(current);
|
|
285
|
+
}
|
|
295
286
|
}
|
|
296
287
|
return lines.length > 0 ? lines : [""];
|
|
297
288
|
}
|
|
@@ -317,17 +308,17 @@ function layoutWithFontSize(ctx, cfg, fontSize, lines) {
|
|
|
317
308
|
} else {
|
|
318
309
|
startX = safe.x + safe.width / 2;
|
|
319
310
|
}
|
|
320
|
-
let startY = safe.y + (safe.height - textBlockHeight) / 2 + fontSize * 0.
|
|
311
|
+
let startY = safe.y + (safe.height - textBlockHeight) / 2 + fontSize * 0.85;
|
|
321
312
|
if (cfg.textPosY === "top") {
|
|
322
|
-
startY = safe.y + fontSize * 0.
|
|
313
|
+
startY = safe.y + fontSize * 0.85;
|
|
323
314
|
} else if (cfg.textPosY === "bottom") {
|
|
324
|
-
startY = safe.y + safe.height - textBlockHeight + fontSize * 0.
|
|
315
|
+
startY = safe.y + safe.height - textBlockHeight + fontSize * 0.85;
|
|
325
316
|
}
|
|
326
317
|
let xMin = startX;
|
|
327
318
|
if (align === "center") xMin = startX - maxLineWidth / 2;
|
|
328
319
|
else if (align === "right") xMin = startX - maxLineWidth;
|
|
329
320
|
const yMin = startY - fontSize * 0.85;
|
|
330
|
-
const yMax = startY + (lines.length - 1) * fontSize * lineHeight + fontSize * 0.
|
|
321
|
+
const yMax = startY + (lines.length - 1) * fontSize * lineHeight + fontSize * 0.15;
|
|
331
322
|
return {
|
|
332
323
|
lines,
|
|
333
324
|
fontSize,
|
|
@@ -766,11 +757,11 @@ var InkBrushEngine = class {
|
|
|
766
757
|
if (letterSpacing !== 0) {
|
|
767
758
|
ctx.letterSpacing = `${letterSpacing}px`;
|
|
768
759
|
}
|
|
769
|
-
let startY = (height - textBlockHeight) / 2 + fontSize * 0.
|
|
760
|
+
let startY = (height - textBlockHeight) / 2 + fontSize * 0.85;
|
|
770
761
|
if (textPosY === "top") {
|
|
771
|
-
startY = 40 + fontSize * 0.
|
|
762
|
+
startY = 40 + fontSize * 0.85;
|
|
772
763
|
} else if (textPosY === "bottom") {
|
|
773
|
-
startY = height - 40 - textBlockHeight + fontSize * 0.
|
|
764
|
+
startY = height - 40 - textBlockHeight + fontSize * 0.85;
|
|
774
765
|
}
|
|
775
766
|
ctx.save();
|
|
776
767
|
if (skewX !== 0) {
|
|
@@ -918,11 +909,11 @@ var InkBrushEngine = class {
|
|
|
918
909
|
if (letterSpacing !== 0) {
|
|
919
910
|
ctx.letterSpacing = `${letterSpacing}px`;
|
|
920
911
|
}
|
|
921
|
-
let startY = (height - textBlockHeight) / 2 + fontSize * 0.
|
|
912
|
+
let startY = (height - textBlockHeight) / 2 + fontSize * 0.85;
|
|
922
913
|
if (textPosY === "top") {
|
|
923
|
-
startY = 40 + fontSize * 0.
|
|
914
|
+
startY = 40 + fontSize * 0.85;
|
|
924
915
|
} else if (textPosY === "bottom") {
|
|
925
|
-
startY = height - 40 - textBlockHeight + fontSize * 0.
|
|
916
|
+
startY = height - 40 - textBlockHeight + fontSize * 0.85;
|
|
926
917
|
}
|
|
927
918
|
ctx.save();
|
|
928
919
|
if (skewX !== 0) {
|