ugcinc-render 1.5.13 → 1.5.15
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.js +29 -8
- package/dist/index.mjs +29 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -353,6 +353,18 @@ function splitTextAndEmojis(text) {
|
|
|
353
353
|
}
|
|
354
354
|
return segments;
|
|
355
355
|
}
|
|
356
|
+
function countEmojis(text) {
|
|
357
|
+
EMOJI_REGEX.lastIndex = 0;
|
|
358
|
+
const matches = text.match(EMOJI_REGEX);
|
|
359
|
+
return matches ? matches.length : 0;
|
|
360
|
+
}
|
|
361
|
+
function getEmojiWidth(fontSize) {
|
|
362
|
+
return fontSize * 1.2;
|
|
363
|
+
}
|
|
364
|
+
function stripEmojis(text) {
|
|
365
|
+
EMOJI_REGEX.lastIndex = 0;
|
|
366
|
+
return text.replace(EMOJI_REGEX, "");
|
|
367
|
+
}
|
|
356
368
|
|
|
357
369
|
// src/components/TextElement.tsx
|
|
358
370
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -386,6 +398,18 @@ function calculateAutoWidthAndLines({
|
|
|
386
398
|
white-space: nowrap;
|
|
387
399
|
`;
|
|
388
400
|
document.body.appendChild(measureSpan);
|
|
401
|
+
const emojiWidth = getEmojiWidth(fontSize);
|
|
402
|
+
const measureTextWithEmojis = (textToMeasure) => {
|
|
403
|
+
const emojiCount = countEmojis(textToMeasure);
|
|
404
|
+
if (emojiCount === 0) {
|
|
405
|
+
measureSpan.textContent = textToMeasure;
|
|
406
|
+
return measureSpan.getBoundingClientRect().width;
|
|
407
|
+
}
|
|
408
|
+
const textWithoutEmojis = stripEmojis(textToMeasure);
|
|
409
|
+
measureSpan.textContent = textWithoutEmojis;
|
|
410
|
+
const textWidth = measureSpan.getBoundingClientRect().width;
|
|
411
|
+
return textWidth + emojiCount * emojiWidth;
|
|
412
|
+
};
|
|
389
413
|
measureSpan.textContent = "M";
|
|
390
414
|
const charWidth = measureSpan.getBoundingClientRect().width;
|
|
391
415
|
const words = text.split(/(\s+)/);
|
|
@@ -408,14 +432,12 @@ function calculateAutoWidthAndLines({
|
|
|
408
432
|
continue;
|
|
409
433
|
}
|
|
410
434
|
const testLine = currentLine + word;
|
|
411
|
-
|
|
412
|
-
const testWidth = measureSpan.getBoundingClientRect().width;
|
|
435
|
+
const testWidth = measureTextWithEmojis(testLine);
|
|
413
436
|
const WRAP_TOLERANCE = 0.5;
|
|
414
437
|
if (testWidth > availableWidth + WRAP_TOLERANCE && currentLine.trim()) {
|
|
415
438
|
lines.push(currentLine.trimEnd());
|
|
416
439
|
currentLine = word;
|
|
417
|
-
|
|
418
|
-
const wordWidth = measureSpan.getBoundingClientRect().width;
|
|
440
|
+
const wordWidth = measureTextWithEmojis(word);
|
|
419
441
|
if (wordWidth > availableWidth) {
|
|
420
442
|
let remainingWord = word;
|
|
421
443
|
while (remainingWord) {
|
|
@@ -449,8 +471,8 @@ function calculateAutoWidthAndLines({
|
|
|
449
471
|
}
|
|
450
472
|
let widestLineWidth = 0;
|
|
451
473
|
for (const line of lines) {
|
|
452
|
-
|
|
453
|
-
widestLineWidth = Math.max(widestLineWidth,
|
|
474
|
+
const lineWidth = measureTextWithEmojis(line);
|
|
475
|
+
widestLineWidth = Math.max(widestLineWidth, lineWidth);
|
|
454
476
|
}
|
|
455
477
|
document.body.removeChild(measureSpan);
|
|
456
478
|
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
@@ -672,8 +694,7 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
672
694
|
height: "1.2em",
|
|
673
695
|
width: "1.2em",
|
|
674
696
|
verticalAlign: "-0.25em",
|
|
675
|
-
display: "inline
|
|
676
|
-
margin: "0 0.05em"
|
|
697
|
+
display: "inline"
|
|
677
698
|
},
|
|
678
699
|
draggable: false
|
|
679
700
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -265,6 +265,18 @@ function splitTextAndEmojis(text) {
|
|
|
265
265
|
}
|
|
266
266
|
return segments;
|
|
267
267
|
}
|
|
268
|
+
function countEmojis(text) {
|
|
269
|
+
EMOJI_REGEX.lastIndex = 0;
|
|
270
|
+
const matches = text.match(EMOJI_REGEX);
|
|
271
|
+
return matches ? matches.length : 0;
|
|
272
|
+
}
|
|
273
|
+
function getEmojiWidth(fontSize) {
|
|
274
|
+
return fontSize * 1.2;
|
|
275
|
+
}
|
|
276
|
+
function stripEmojis(text) {
|
|
277
|
+
EMOJI_REGEX.lastIndex = 0;
|
|
278
|
+
return text.replace(EMOJI_REGEX, "");
|
|
279
|
+
}
|
|
268
280
|
|
|
269
281
|
// src/components/TextElement.tsx
|
|
270
282
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -298,6 +310,18 @@ function calculateAutoWidthAndLines({
|
|
|
298
310
|
white-space: nowrap;
|
|
299
311
|
`;
|
|
300
312
|
document.body.appendChild(measureSpan);
|
|
313
|
+
const emojiWidth = getEmojiWidth(fontSize);
|
|
314
|
+
const measureTextWithEmojis = (textToMeasure) => {
|
|
315
|
+
const emojiCount = countEmojis(textToMeasure);
|
|
316
|
+
if (emojiCount === 0) {
|
|
317
|
+
measureSpan.textContent = textToMeasure;
|
|
318
|
+
return measureSpan.getBoundingClientRect().width;
|
|
319
|
+
}
|
|
320
|
+
const textWithoutEmojis = stripEmojis(textToMeasure);
|
|
321
|
+
measureSpan.textContent = textWithoutEmojis;
|
|
322
|
+
const textWidth = measureSpan.getBoundingClientRect().width;
|
|
323
|
+
return textWidth + emojiCount * emojiWidth;
|
|
324
|
+
};
|
|
301
325
|
measureSpan.textContent = "M";
|
|
302
326
|
const charWidth = measureSpan.getBoundingClientRect().width;
|
|
303
327
|
const words = text.split(/(\s+)/);
|
|
@@ -320,14 +344,12 @@ function calculateAutoWidthAndLines({
|
|
|
320
344
|
continue;
|
|
321
345
|
}
|
|
322
346
|
const testLine = currentLine + word;
|
|
323
|
-
|
|
324
|
-
const testWidth = measureSpan.getBoundingClientRect().width;
|
|
347
|
+
const testWidth = measureTextWithEmojis(testLine);
|
|
325
348
|
const WRAP_TOLERANCE = 0.5;
|
|
326
349
|
if (testWidth > availableWidth + WRAP_TOLERANCE && currentLine.trim()) {
|
|
327
350
|
lines.push(currentLine.trimEnd());
|
|
328
351
|
currentLine = word;
|
|
329
|
-
|
|
330
|
-
const wordWidth = measureSpan.getBoundingClientRect().width;
|
|
352
|
+
const wordWidth = measureTextWithEmojis(word);
|
|
331
353
|
if (wordWidth > availableWidth) {
|
|
332
354
|
let remainingWord = word;
|
|
333
355
|
while (remainingWord) {
|
|
@@ -361,8 +383,8 @@ function calculateAutoWidthAndLines({
|
|
|
361
383
|
}
|
|
362
384
|
let widestLineWidth = 0;
|
|
363
385
|
for (const line of lines) {
|
|
364
|
-
|
|
365
|
-
widestLineWidth = Math.max(widestLineWidth,
|
|
386
|
+
const lineWidth = measureTextWithEmojis(line);
|
|
387
|
+
widestLineWidth = Math.max(widestLineWidth, lineWidth);
|
|
366
388
|
}
|
|
367
389
|
document.body.removeChild(measureSpan);
|
|
368
390
|
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
@@ -584,8 +606,7 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
584
606
|
height: "1.2em",
|
|
585
607
|
width: "1.2em",
|
|
586
608
|
verticalAlign: "-0.25em",
|
|
587
|
-
display: "inline
|
|
588
|
-
margin: "0 0.05em"
|
|
609
|
+
display: "inline"
|
|
589
610
|
},
|
|
590
611
|
draggable: false
|
|
591
612
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugcinc-render",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.15",
|
|
4
4
|
"description": "Unified rendering package for UGC Inc - shared types, components, and compositions for pixel-perfect client/server rendering",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|