ugcinc-render 1.5.13 → 1.5.14

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 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.3;
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
- measureSpan.textContent = testLine;
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
- measureSpan.textContent = word;
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
- measureSpan.textContent = line;
453
- widestLineWidth = Math.max(widestLineWidth, measureSpan.getBoundingClientRect().width);
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);
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.3;
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
- measureSpan.textContent = testLine;
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
- measureSpan.textContent = word;
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
- measureSpan.textContent = line;
365
- widestLineWidth = Math.max(widestLineWidth, measureSpan.getBoundingClientRect().width);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc-render",
3
- "version": "1.5.13",
3
+ "version": "1.5.14",
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",