ugcinc-render 1.5.7 → 1.5.8
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 +7 -6
- package/dist/index.mjs +7 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -335,7 +335,7 @@ function calculateAutoWidthAndLines({
|
|
|
335
335
|
`;
|
|
336
336
|
document.body.appendChild(measureSpan);
|
|
337
337
|
measureSpan.textContent = "M";
|
|
338
|
-
const charWidth = measureSpan.
|
|
338
|
+
const charWidth = measureSpan.getBoundingClientRect().width;
|
|
339
339
|
const words = text.split(/(\s+)/);
|
|
340
340
|
const lines = [];
|
|
341
341
|
let currentLine = "";
|
|
@@ -357,19 +357,20 @@ function calculateAutoWidthAndLines({
|
|
|
357
357
|
}
|
|
358
358
|
const testLine = currentLine + word;
|
|
359
359
|
measureSpan.textContent = testLine;
|
|
360
|
-
const testWidth = measureSpan.
|
|
361
|
-
|
|
360
|
+
const testWidth = measureSpan.getBoundingClientRect().width;
|
|
361
|
+
const WRAP_TOLERANCE = 0.5;
|
|
362
|
+
if (testWidth > availableWidth + WRAP_TOLERANCE && currentLine.trim()) {
|
|
362
363
|
lines.push(currentLine.trimEnd());
|
|
363
364
|
currentLine = word;
|
|
364
365
|
measureSpan.textContent = word;
|
|
365
|
-
const wordWidth = measureSpan.
|
|
366
|
+
const wordWidth = measureSpan.getBoundingClientRect().width;
|
|
366
367
|
if (wordWidth > availableWidth) {
|
|
367
368
|
let remainingWord = word;
|
|
368
369
|
while (remainingWord) {
|
|
369
370
|
let breakPoint = 1;
|
|
370
371
|
for (let j = 1; j <= remainingWord.length; j++) {
|
|
371
372
|
measureSpan.textContent = remainingWord.substring(0, j);
|
|
372
|
-
if (measureSpan.
|
|
373
|
+
if (measureSpan.getBoundingClientRect().width > availableWidth) {
|
|
373
374
|
breakPoint = Math.max(1, j - 1);
|
|
374
375
|
break;
|
|
375
376
|
}
|
|
@@ -397,7 +398,7 @@ function calculateAutoWidthAndLines({
|
|
|
397
398
|
let widestLineWidth = 0;
|
|
398
399
|
for (const line of lines) {
|
|
399
400
|
measureSpan.textContent = line;
|
|
400
|
-
widestLineWidth = Math.max(widestLineWidth, measureSpan.
|
|
401
|
+
widestLineWidth = Math.max(widestLineWidth, measureSpan.getBoundingClientRect().width);
|
|
401
402
|
}
|
|
402
403
|
document.body.removeChild(measureSpan);
|
|
403
404
|
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
package/dist/index.mjs
CHANGED
|
@@ -251,7 +251,7 @@ function calculateAutoWidthAndLines({
|
|
|
251
251
|
`;
|
|
252
252
|
document.body.appendChild(measureSpan);
|
|
253
253
|
measureSpan.textContent = "M";
|
|
254
|
-
const charWidth = measureSpan.
|
|
254
|
+
const charWidth = measureSpan.getBoundingClientRect().width;
|
|
255
255
|
const words = text.split(/(\s+)/);
|
|
256
256
|
const lines = [];
|
|
257
257
|
let currentLine = "";
|
|
@@ -273,19 +273,20 @@ function calculateAutoWidthAndLines({
|
|
|
273
273
|
}
|
|
274
274
|
const testLine = currentLine + word;
|
|
275
275
|
measureSpan.textContent = testLine;
|
|
276
|
-
const testWidth = measureSpan.
|
|
277
|
-
|
|
276
|
+
const testWidth = measureSpan.getBoundingClientRect().width;
|
|
277
|
+
const WRAP_TOLERANCE = 0.5;
|
|
278
|
+
if (testWidth > availableWidth + WRAP_TOLERANCE && currentLine.trim()) {
|
|
278
279
|
lines.push(currentLine.trimEnd());
|
|
279
280
|
currentLine = word;
|
|
280
281
|
measureSpan.textContent = word;
|
|
281
|
-
const wordWidth = measureSpan.
|
|
282
|
+
const wordWidth = measureSpan.getBoundingClientRect().width;
|
|
282
283
|
if (wordWidth > availableWidth) {
|
|
283
284
|
let remainingWord = word;
|
|
284
285
|
while (remainingWord) {
|
|
285
286
|
let breakPoint = 1;
|
|
286
287
|
for (let j = 1; j <= remainingWord.length; j++) {
|
|
287
288
|
measureSpan.textContent = remainingWord.substring(0, j);
|
|
288
|
-
if (measureSpan.
|
|
289
|
+
if (measureSpan.getBoundingClientRect().width > availableWidth) {
|
|
289
290
|
breakPoint = Math.max(1, j - 1);
|
|
290
291
|
break;
|
|
291
292
|
}
|
|
@@ -313,7 +314,7 @@ function calculateAutoWidthAndLines({
|
|
|
313
314
|
let widestLineWidth = 0;
|
|
314
315
|
for (const line of lines) {
|
|
315
316
|
measureSpan.textContent = line;
|
|
316
|
-
widestLineWidth = Math.max(widestLineWidth, measureSpan.
|
|
317
|
+
widestLineWidth = Math.max(widestLineWidth, measureSpan.getBoundingClientRect().width);
|
|
317
318
|
}
|
|
318
319
|
document.body.removeChild(measureSpan);
|
|
319
320
|
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.
|
|
3
|
+
"version": "1.5.8",
|
|
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",
|