ugcinc-render 1.5.17 → 1.5.18
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 +154 -7
- package/dist/index.mjs +154 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -401,15 +401,48 @@ function calculateAutoWidthAndLines({
|
|
|
401
401
|
letterSpacing,
|
|
402
402
|
lineHeight
|
|
403
403
|
}) {
|
|
404
|
+
console.log("[TextElement/calculateAutoWidthAndLines] ===== START CALCULATION =====");
|
|
405
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Input params:", {
|
|
406
|
+
text: text.substring(0, 100) + (text.length > 100 ? "..." : ""),
|
|
407
|
+
textLength: text.length,
|
|
408
|
+
maxWidth,
|
|
409
|
+
paddingLeft,
|
|
410
|
+
paddingRight,
|
|
411
|
+
fontSize,
|
|
412
|
+
fontWeight,
|
|
413
|
+
fontFamily,
|
|
414
|
+
letterSpacing,
|
|
415
|
+
lineHeight
|
|
416
|
+
});
|
|
404
417
|
if (typeof document === "undefined") {
|
|
418
|
+
console.log("[TextElement/calculateAutoWidthAndLines] SSR mode - returning maxWidth");
|
|
405
419
|
return { width: maxWidth, lines: [text] };
|
|
406
420
|
}
|
|
421
|
+
if (typeof document.fonts !== "undefined") {
|
|
422
|
+
const fontChecks = {
|
|
423
|
+
"SF Pro normal": document.fonts.check(`normal ${fontSize}px "SF Pro"`),
|
|
424
|
+
"SF Pro bold": document.fonts.check(`bold ${fontSize}px "SF Pro"`),
|
|
425
|
+
"TikTok Sans normal": document.fonts.check(`normal ${fontSize}px "TikTok Sans"`),
|
|
426
|
+
"TikTok Sans bold": document.fonts.check(`bold ${fontSize}px "TikTok Sans"`),
|
|
427
|
+
"requestedFont": document.fonts.check(`${fontWeight} ${fontSize}px ${fontFamily.split(",")[0]}`)
|
|
428
|
+
};
|
|
429
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Font loading status:", fontChecks);
|
|
430
|
+
const loadedFonts = [];
|
|
431
|
+
document.fonts.forEach((font) => {
|
|
432
|
+
loadedFonts.push(`${font.family} (weight: ${font.weight}, status: ${font.status})`);
|
|
433
|
+
});
|
|
434
|
+
console.log("[TextElement/calculateAutoWidthAndLines] All document.fonts:", loadedFonts);
|
|
435
|
+
} else {
|
|
436
|
+
console.log("[TextElement/calculateAutoWidthAndLines] document.fonts API not available");
|
|
437
|
+
}
|
|
407
438
|
const availableWidth = maxWidth - paddingLeft - paddingRight;
|
|
439
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Available width for text:", availableWidth);
|
|
408
440
|
if (availableWidth <= 0) {
|
|
441
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Available width <= 0, returning maxWidth");
|
|
409
442
|
return { width: maxWidth, lines: [text] };
|
|
410
443
|
}
|
|
411
444
|
const measureSpan = document.createElement("span");
|
|
412
|
-
|
|
445
|
+
const cssText = `
|
|
413
446
|
position: absolute;
|
|
414
447
|
visibility: hidden;
|
|
415
448
|
pointer-events: none;
|
|
@@ -419,16 +452,29 @@ function calculateAutoWidthAndLines({
|
|
|
419
452
|
letter-spacing: ${letterSpacing}px;
|
|
420
453
|
white-space: nowrap;
|
|
421
454
|
`;
|
|
455
|
+
measureSpan.style.cssText = cssText;
|
|
456
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Measurement span CSS:", cssText.replace(/\s+/g, " ").trim());
|
|
422
457
|
document.body.appendChild(measureSpan);
|
|
423
458
|
const measureText = (textToMeasure) => {
|
|
424
459
|
measureSpan.textContent = textToMeasure;
|
|
425
|
-
|
|
460
|
+
const width = measureSpan.getBoundingClientRect().width;
|
|
461
|
+
return width;
|
|
426
462
|
};
|
|
427
463
|
measureSpan.textContent = "M";
|
|
428
464
|
const charWidth = measureSpan.getBoundingClientRect().width;
|
|
465
|
+
console.log('[TextElement/calculateAutoWidthAndLines] Single "M" character width:', charWidth);
|
|
466
|
+
measureSpan.textContent = "Test String";
|
|
467
|
+
const testStringWidth = measureSpan.getBoundingClientRect().width;
|
|
468
|
+
console.log('[TextElement/calculateAutoWidthAndLines] "Test String" width:', testStringWidth);
|
|
469
|
+
const computedStyle = window.getComputedStyle(measureSpan);
|
|
470
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed font-family:", computedStyle.fontFamily);
|
|
471
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed font-size:", computedStyle.fontSize);
|
|
472
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed font-weight:", computedStyle.fontWeight);
|
|
473
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed letter-spacing:", computedStyle.letterSpacing);
|
|
429
474
|
const words = text.split(/(\s+)/);
|
|
430
475
|
const lines = [];
|
|
431
476
|
let currentLine = "";
|
|
477
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Word count:", words.filter((w) => w.trim()).length);
|
|
432
478
|
for (let i = 0; i < words.length; i++) {
|
|
433
479
|
const word = words[i];
|
|
434
480
|
if (word === "\n" || word === "\r\n") {
|
|
@@ -484,24 +530,60 @@ function calculateAutoWidthAndLines({
|
|
|
484
530
|
lines.push("");
|
|
485
531
|
}
|
|
486
532
|
let widestLineWidth = 0;
|
|
533
|
+
const lineWidths = [];
|
|
487
534
|
for (const line of lines) {
|
|
488
535
|
const lineWidth = measureText(line);
|
|
536
|
+
lineWidths.push({ line: line.substring(0, 50) + (line.length > 50 ? "..." : ""), width: lineWidth });
|
|
489
537
|
widestLineWidth = Math.max(widestLineWidth, lineWidth);
|
|
490
538
|
}
|
|
539
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Line measurements:", lineWidths);
|
|
540
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Widest line width:", widestLineWidth);
|
|
491
541
|
document.body.removeChild(measureSpan);
|
|
492
542
|
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
543
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Final calculation:", {
|
|
544
|
+
widestLineWidth,
|
|
545
|
+
paddingLeft,
|
|
546
|
+
paddingRight,
|
|
547
|
+
rawCalculatedWidth: widestLineWidth + paddingLeft + paddingRight,
|
|
548
|
+
cappedToMaxWidth: calculatedWidth,
|
|
549
|
+
maxWidth
|
|
550
|
+
});
|
|
551
|
+
console.log("[TextElement/calculateAutoWidthAndLines] ===== END CALCULATION =====");
|
|
493
552
|
return { width: calculatedWidth, lines };
|
|
494
553
|
}
|
|
495
554
|
function TextElement({ segment, scale = 1 }) {
|
|
496
555
|
import_react.default.useEffect(() => {
|
|
497
556
|
const fontFamily2 = getFontFamily(segment.fontType ?? TEXT_DEFAULTS.fontType);
|
|
498
|
-
console.log("[
|
|
557
|
+
console.log("[TextElement] ===== RENDER EFFECT =====");
|
|
558
|
+
console.log("[TextElement] Segment ID:", segment.id);
|
|
559
|
+
console.log("[TextElement] Rendering with:", {
|
|
499
560
|
text: segment.text?.substring(0, 50) + (segment.text?.length > 50 ? "..." : ""),
|
|
500
561
|
fontType: segment.fontType ?? TEXT_DEFAULTS.fontType,
|
|
501
562
|
fontFamily: fontFamily2,
|
|
502
|
-
hasEmojis: /[\u{1F300}-\u{1F9FF}]/u.test(segment.text || "")
|
|
563
|
+
hasEmojis: /[\u{1F300}-\u{1F9FF}]/u.test(segment.text || ""),
|
|
564
|
+
autoWidth: segment.autoWidth,
|
|
565
|
+
boxAlign: segment.boxAlign
|
|
503
566
|
});
|
|
504
|
-
|
|
567
|
+
console.log("[TextElement] Segment dimensions:", {
|
|
568
|
+
xOffset: segment.xOffset,
|
|
569
|
+
yOffset: segment.yOffset,
|
|
570
|
+
width: segment.width,
|
|
571
|
+
height: segment.height
|
|
572
|
+
});
|
|
573
|
+
console.log("[TextElement] Segment padding:", {
|
|
574
|
+
paddingTop: segment.paddingTop,
|
|
575
|
+
paddingRight: segment.paddingRight,
|
|
576
|
+
paddingBottom: segment.paddingBottom,
|
|
577
|
+
paddingLeft: segment.paddingLeft
|
|
578
|
+
});
|
|
579
|
+
console.log("[TextElement] Segment font styling:", {
|
|
580
|
+
fontSize: segment.fontSize,
|
|
581
|
+
fontWeight: segment.fontWeight,
|
|
582
|
+
letterSpacing: segment.letterSpacing,
|
|
583
|
+
lineHeight: segment.lineHeight
|
|
584
|
+
});
|
|
585
|
+
console.log("[TextElement] Scale:", scale);
|
|
586
|
+
}, [segment, scale]);
|
|
505
587
|
const fontType = segment.fontType ?? TEXT_DEFAULTS.fontType;
|
|
506
588
|
const fontSize = (segment.fontSize ?? TEXT_DEFAULTS.fontSize) * scale;
|
|
507
589
|
const fontWeight = segment.fontWeight ?? TEXT_DEFAULTS.fontWeight;
|
|
@@ -580,7 +662,7 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
580
662
|
lineHeight
|
|
581
663
|
});
|
|
582
664
|
}
|
|
583
|
-
|
|
665
|
+
const result = {
|
|
584
666
|
calculatedWidth: autoWidth ? finalResult.width : width,
|
|
585
667
|
calculatedLines: autoWidth ? finalResult.lines : [segment.text],
|
|
586
668
|
paddingTop: finalPaddingTop,
|
|
@@ -588,6 +670,19 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
588
670
|
paddingBottom: finalPaddingBottom,
|
|
589
671
|
paddingLeft: finalPaddingLeft
|
|
590
672
|
};
|
|
673
|
+
console.log("[TextElement/useMemo] ===== FINAL VALUES =====");
|
|
674
|
+
console.log("[TextElement/useMemo] autoWidth:", autoWidth);
|
|
675
|
+
console.log("[TextElement/useMemo] calculatedWidth:", result.calculatedWidth);
|
|
676
|
+
console.log("[TextElement/useMemo] calculatedLines:", result.calculatedLines);
|
|
677
|
+
console.log("[TextElement/useMemo] Final padding:", {
|
|
678
|
+
top: result.paddingTop,
|
|
679
|
+
right: result.paddingRight,
|
|
680
|
+
bottom: result.paddingBottom,
|
|
681
|
+
left: result.paddingLeft
|
|
682
|
+
});
|
|
683
|
+
console.log("[TextElement/useMemo] Element width (maxWidth):", width);
|
|
684
|
+
console.log("[TextElement/useMemo] Difference (maxWidth - calculatedWidth):", width - result.calculatedWidth);
|
|
685
|
+
return result;
|
|
591
686
|
}, [
|
|
592
687
|
autoWidth,
|
|
593
688
|
segment.text,
|
|
@@ -702,11 +797,29 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
702
797
|
verticalAlign
|
|
703
798
|
]);
|
|
704
799
|
if (autoWidth) {
|
|
800
|
+
console.log("[TextElement/render] ===== RENDERING WITH AUTO-WIDTH =====");
|
|
801
|
+
console.log("[TextElement/render] Segment ID:", segment.id);
|
|
802
|
+
console.log("[TextElement/render] calculatedWidth being applied:", calculatedWidth);
|
|
803
|
+
console.log("[TextElement/render] maxWidth (element width):", width);
|
|
804
|
+
console.log("[TextElement/render] boxAlign:", boxAlign);
|
|
805
|
+
console.log("[TextElement/render] textAlign:", alignment);
|
|
806
|
+
console.log("[TextElement/render] Number of lines:", calculatedLines.length);
|
|
807
|
+
console.log("[TextElement/render] textStyle padding:", textStyle.padding);
|
|
808
|
+
console.log("[TextElement/render] textStyle fontFamily:", textStyle.fontFamily);
|
|
809
|
+
console.log("[TextElement/render] textStyle fontSize:", textStyle.fontSize);
|
|
810
|
+
console.log("[TextElement/render] textStyle letterSpacing:", textStyle.letterSpacing);
|
|
705
811
|
const textContent = calculatedLines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.default.Fragment, { children: [
|
|
706
812
|
line,
|
|
707
813
|
index < calculatedLines.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})
|
|
708
814
|
] }, index));
|
|
709
815
|
if (backgroundColor) {
|
|
816
|
+
console.log("[TextElement/render] Rendering WITH background");
|
|
817
|
+
console.log("[TextElement/render] Background wrapper style:", {
|
|
818
|
+
width: calculatedWidth,
|
|
819
|
+
maxWidth: width,
|
|
820
|
+
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
821
|
+
borderRadius: borderRadiusStyle
|
|
822
|
+
});
|
|
710
823
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: positioningContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
711
824
|
"div",
|
|
712
825
|
{
|
|
@@ -720,6 +833,7 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
720
833
|
}
|
|
721
834
|
) });
|
|
722
835
|
}
|
|
836
|
+
console.log("[TextElement/render] Rendering WITHOUT background");
|
|
723
837
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: positioningContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: calculatedWidth, maxWidth: width }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: textStyle, children: textContent }) }) });
|
|
724
838
|
}
|
|
725
839
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: positioningContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: backgroundBoxStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: textStyle, children: segment.text }) }) });
|
|
@@ -1242,7 +1356,7 @@ function getSortedSegments(config) {
|
|
|
1242
1356
|
});
|
|
1243
1357
|
}
|
|
1244
1358
|
function elementToTextSegment(elem) {
|
|
1245
|
-
|
|
1359
|
+
const segment = {
|
|
1246
1360
|
id: elem.id,
|
|
1247
1361
|
type: "text",
|
|
1248
1362
|
source: "",
|
|
@@ -1280,6 +1394,27 @@ function elementToTextSegment(elem) {
|
|
|
1280
1394
|
autoWidth: elem.autoWidth,
|
|
1281
1395
|
boxAlign: elem.boxAlign
|
|
1282
1396
|
};
|
|
1397
|
+
console.log("[ImageEditorComposition/elementToTextSegment] ===== CONVERTING ELEMENT TO SEGMENT =====");
|
|
1398
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element ID:", elem.id);
|
|
1399
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element text:", (elem.text ?? "").substring(0, 50));
|
|
1400
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element dimensions:", { x: elem.x, y: elem.y, width: elem.width, height: elem.height });
|
|
1401
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element padding:", {
|
|
1402
|
+
paddingTop: elem.paddingTop,
|
|
1403
|
+
paddingRight: elem.paddingRight,
|
|
1404
|
+
paddingBottom: elem.paddingBottom,
|
|
1405
|
+
paddingLeft: elem.paddingLeft
|
|
1406
|
+
});
|
|
1407
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element autoWidth:", elem.autoWidth, "boxAlign:", elem.boxAlign);
|
|
1408
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element font:", elem.font, "fontSize:", elem.fontSize, "fontWeight:", elem.fontWeight);
|
|
1409
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element letterSpacing:", elem.letterSpacing, "lineHeight:", elem.lineHeight);
|
|
1410
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Segment created:", {
|
|
1411
|
+
fontType: segment.fontType,
|
|
1412
|
+
fontSize: segment.fontSize,
|
|
1413
|
+
fontWeight: segment.fontWeight,
|
|
1414
|
+
letterSpacing: segment.letterSpacing,
|
|
1415
|
+
lineHeight: segment.lineHeight
|
|
1416
|
+
});
|
|
1417
|
+
return segment;
|
|
1283
1418
|
}
|
|
1284
1419
|
function elementToImageSegment(elem, source) {
|
|
1285
1420
|
return {
|
|
@@ -1315,8 +1450,20 @@ function ImageEditorComposition({
|
|
|
1315
1450
|
textValues = {},
|
|
1316
1451
|
dynamicCrop
|
|
1317
1452
|
}) {
|
|
1453
|
+
console.log("[ImageEditorComposition] ===== COMPOSITION RENDER =====");
|
|
1454
|
+
console.log("[ImageEditorComposition] Props received:", {
|
|
1455
|
+
hasConfig: !!config,
|
|
1456
|
+
hasElements: !!elements,
|
|
1457
|
+
elementCount: elements?.length ?? 0,
|
|
1458
|
+
width,
|
|
1459
|
+
height,
|
|
1460
|
+
scale,
|
|
1461
|
+
backgroundType,
|
|
1462
|
+
textValuesKeys: Object.keys(textValues)
|
|
1463
|
+
});
|
|
1318
1464
|
const canvasWidth = width ?? config?.width ?? 1080;
|
|
1319
1465
|
const canvasHeight = height ?? config?.height ?? 1920;
|
|
1466
|
+
console.log("[ImageEditorComposition] Canvas dimensions:", { canvasWidth, canvasHeight });
|
|
1320
1467
|
const resolvedElements = (0, import_react3.useMemo)(() => {
|
|
1321
1468
|
if (!elements) return null;
|
|
1322
1469
|
const result = resolveElementPositions(elements, textValues);
|
package/dist/index.mjs
CHANGED
|
@@ -315,15 +315,48 @@ function calculateAutoWidthAndLines({
|
|
|
315
315
|
letterSpacing,
|
|
316
316
|
lineHeight
|
|
317
317
|
}) {
|
|
318
|
+
console.log("[TextElement/calculateAutoWidthAndLines] ===== START CALCULATION =====");
|
|
319
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Input params:", {
|
|
320
|
+
text: text.substring(0, 100) + (text.length > 100 ? "..." : ""),
|
|
321
|
+
textLength: text.length,
|
|
322
|
+
maxWidth,
|
|
323
|
+
paddingLeft,
|
|
324
|
+
paddingRight,
|
|
325
|
+
fontSize,
|
|
326
|
+
fontWeight,
|
|
327
|
+
fontFamily,
|
|
328
|
+
letterSpacing,
|
|
329
|
+
lineHeight
|
|
330
|
+
});
|
|
318
331
|
if (typeof document === "undefined") {
|
|
332
|
+
console.log("[TextElement/calculateAutoWidthAndLines] SSR mode - returning maxWidth");
|
|
319
333
|
return { width: maxWidth, lines: [text] };
|
|
320
334
|
}
|
|
335
|
+
if (typeof document.fonts !== "undefined") {
|
|
336
|
+
const fontChecks = {
|
|
337
|
+
"SF Pro normal": document.fonts.check(`normal ${fontSize}px "SF Pro"`),
|
|
338
|
+
"SF Pro bold": document.fonts.check(`bold ${fontSize}px "SF Pro"`),
|
|
339
|
+
"TikTok Sans normal": document.fonts.check(`normal ${fontSize}px "TikTok Sans"`),
|
|
340
|
+
"TikTok Sans bold": document.fonts.check(`bold ${fontSize}px "TikTok Sans"`),
|
|
341
|
+
"requestedFont": document.fonts.check(`${fontWeight} ${fontSize}px ${fontFamily.split(",")[0]}`)
|
|
342
|
+
};
|
|
343
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Font loading status:", fontChecks);
|
|
344
|
+
const loadedFonts = [];
|
|
345
|
+
document.fonts.forEach((font) => {
|
|
346
|
+
loadedFonts.push(`${font.family} (weight: ${font.weight}, status: ${font.status})`);
|
|
347
|
+
});
|
|
348
|
+
console.log("[TextElement/calculateAutoWidthAndLines] All document.fonts:", loadedFonts);
|
|
349
|
+
} else {
|
|
350
|
+
console.log("[TextElement/calculateAutoWidthAndLines] document.fonts API not available");
|
|
351
|
+
}
|
|
321
352
|
const availableWidth = maxWidth - paddingLeft - paddingRight;
|
|
353
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Available width for text:", availableWidth);
|
|
322
354
|
if (availableWidth <= 0) {
|
|
355
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Available width <= 0, returning maxWidth");
|
|
323
356
|
return { width: maxWidth, lines: [text] };
|
|
324
357
|
}
|
|
325
358
|
const measureSpan = document.createElement("span");
|
|
326
|
-
|
|
359
|
+
const cssText = `
|
|
327
360
|
position: absolute;
|
|
328
361
|
visibility: hidden;
|
|
329
362
|
pointer-events: none;
|
|
@@ -333,16 +366,29 @@ function calculateAutoWidthAndLines({
|
|
|
333
366
|
letter-spacing: ${letterSpacing}px;
|
|
334
367
|
white-space: nowrap;
|
|
335
368
|
`;
|
|
369
|
+
measureSpan.style.cssText = cssText;
|
|
370
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Measurement span CSS:", cssText.replace(/\s+/g, " ").trim());
|
|
336
371
|
document.body.appendChild(measureSpan);
|
|
337
372
|
const measureText = (textToMeasure) => {
|
|
338
373
|
measureSpan.textContent = textToMeasure;
|
|
339
|
-
|
|
374
|
+
const width = measureSpan.getBoundingClientRect().width;
|
|
375
|
+
return width;
|
|
340
376
|
};
|
|
341
377
|
measureSpan.textContent = "M";
|
|
342
378
|
const charWidth = measureSpan.getBoundingClientRect().width;
|
|
379
|
+
console.log('[TextElement/calculateAutoWidthAndLines] Single "M" character width:', charWidth);
|
|
380
|
+
measureSpan.textContent = "Test String";
|
|
381
|
+
const testStringWidth = measureSpan.getBoundingClientRect().width;
|
|
382
|
+
console.log('[TextElement/calculateAutoWidthAndLines] "Test String" width:', testStringWidth);
|
|
383
|
+
const computedStyle = window.getComputedStyle(measureSpan);
|
|
384
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed font-family:", computedStyle.fontFamily);
|
|
385
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed font-size:", computedStyle.fontSize);
|
|
386
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed font-weight:", computedStyle.fontWeight);
|
|
387
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Computed letter-spacing:", computedStyle.letterSpacing);
|
|
343
388
|
const words = text.split(/(\s+)/);
|
|
344
389
|
const lines = [];
|
|
345
390
|
let currentLine = "";
|
|
391
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Word count:", words.filter((w) => w.trim()).length);
|
|
346
392
|
for (let i = 0; i < words.length; i++) {
|
|
347
393
|
const word = words[i];
|
|
348
394
|
if (word === "\n" || word === "\r\n") {
|
|
@@ -398,24 +444,60 @@ function calculateAutoWidthAndLines({
|
|
|
398
444
|
lines.push("");
|
|
399
445
|
}
|
|
400
446
|
let widestLineWidth = 0;
|
|
447
|
+
const lineWidths = [];
|
|
401
448
|
for (const line of lines) {
|
|
402
449
|
const lineWidth = measureText(line);
|
|
450
|
+
lineWidths.push({ line: line.substring(0, 50) + (line.length > 50 ? "..." : ""), width: lineWidth });
|
|
403
451
|
widestLineWidth = Math.max(widestLineWidth, lineWidth);
|
|
404
452
|
}
|
|
453
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Line measurements:", lineWidths);
|
|
454
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Widest line width:", widestLineWidth);
|
|
405
455
|
document.body.removeChild(measureSpan);
|
|
406
456
|
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
457
|
+
console.log("[TextElement/calculateAutoWidthAndLines] Final calculation:", {
|
|
458
|
+
widestLineWidth,
|
|
459
|
+
paddingLeft,
|
|
460
|
+
paddingRight,
|
|
461
|
+
rawCalculatedWidth: widestLineWidth + paddingLeft + paddingRight,
|
|
462
|
+
cappedToMaxWidth: calculatedWidth,
|
|
463
|
+
maxWidth
|
|
464
|
+
});
|
|
465
|
+
console.log("[TextElement/calculateAutoWidthAndLines] ===== END CALCULATION =====");
|
|
407
466
|
return { width: calculatedWidth, lines };
|
|
408
467
|
}
|
|
409
468
|
function TextElement({ segment, scale = 1 }) {
|
|
410
469
|
React.useEffect(() => {
|
|
411
470
|
const fontFamily2 = getFontFamily(segment.fontType ?? TEXT_DEFAULTS.fontType);
|
|
412
|
-
console.log("[
|
|
471
|
+
console.log("[TextElement] ===== RENDER EFFECT =====");
|
|
472
|
+
console.log("[TextElement] Segment ID:", segment.id);
|
|
473
|
+
console.log("[TextElement] Rendering with:", {
|
|
413
474
|
text: segment.text?.substring(0, 50) + (segment.text?.length > 50 ? "..." : ""),
|
|
414
475
|
fontType: segment.fontType ?? TEXT_DEFAULTS.fontType,
|
|
415
476
|
fontFamily: fontFamily2,
|
|
416
|
-
hasEmojis: /[\u{1F300}-\u{1F9FF}]/u.test(segment.text || "")
|
|
477
|
+
hasEmojis: /[\u{1F300}-\u{1F9FF}]/u.test(segment.text || ""),
|
|
478
|
+
autoWidth: segment.autoWidth,
|
|
479
|
+
boxAlign: segment.boxAlign
|
|
417
480
|
});
|
|
418
|
-
|
|
481
|
+
console.log("[TextElement] Segment dimensions:", {
|
|
482
|
+
xOffset: segment.xOffset,
|
|
483
|
+
yOffset: segment.yOffset,
|
|
484
|
+
width: segment.width,
|
|
485
|
+
height: segment.height
|
|
486
|
+
});
|
|
487
|
+
console.log("[TextElement] Segment padding:", {
|
|
488
|
+
paddingTop: segment.paddingTop,
|
|
489
|
+
paddingRight: segment.paddingRight,
|
|
490
|
+
paddingBottom: segment.paddingBottom,
|
|
491
|
+
paddingLeft: segment.paddingLeft
|
|
492
|
+
});
|
|
493
|
+
console.log("[TextElement] Segment font styling:", {
|
|
494
|
+
fontSize: segment.fontSize,
|
|
495
|
+
fontWeight: segment.fontWeight,
|
|
496
|
+
letterSpacing: segment.letterSpacing,
|
|
497
|
+
lineHeight: segment.lineHeight
|
|
498
|
+
});
|
|
499
|
+
console.log("[TextElement] Scale:", scale);
|
|
500
|
+
}, [segment, scale]);
|
|
419
501
|
const fontType = segment.fontType ?? TEXT_DEFAULTS.fontType;
|
|
420
502
|
const fontSize = (segment.fontSize ?? TEXT_DEFAULTS.fontSize) * scale;
|
|
421
503
|
const fontWeight = segment.fontWeight ?? TEXT_DEFAULTS.fontWeight;
|
|
@@ -494,7 +576,7 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
494
576
|
lineHeight
|
|
495
577
|
});
|
|
496
578
|
}
|
|
497
|
-
|
|
579
|
+
const result = {
|
|
498
580
|
calculatedWidth: autoWidth ? finalResult.width : width,
|
|
499
581
|
calculatedLines: autoWidth ? finalResult.lines : [segment.text],
|
|
500
582
|
paddingTop: finalPaddingTop,
|
|
@@ -502,6 +584,19 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
502
584
|
paddingBottom: finalPaddingBottom,
|
|
503
585
|
paddingLeft: finalPaddingLeft
|
|
504
586
|
};
|
|
587
|
+
console.log("[TextElement/useMemo] ===== FINAL VALUES =====");
|
|
588
|
+
console.log("[TextElement/useMemo] autoWidth:", autoWidth);
|
|
589
|
+
console.log("[TextElement/useMemo] calculatedWidth:", result.calculatedWidth);
|
|
590
|
+
console.log("[TextElement/useMemo] calculatedLines:", result.calculatedLines);
|
|
591
|
+
console.log("[TextElement/useMemo] Final padding:", {
|
|
592
|
+
top: result.paddingTop,
|
|
593
|
+
right: result.paddingRight,
|
|
594
|
+
bottom: result.paddingBottom,
|
|
595
|
+
left: result.paddingLeft
|
|
596
|
+
});
|
|
597
|
+
console.log("[TextElement/useMemo] Element width (maxWidth):", width);
|
|
598
|
+
console.log("[TextElement/useMemo] Difference (maxWidth - calculatedWidth):", width - result.calculatedWidth);
|
|
599
|
+
return result;
|
|
505
600
|
}, [
|
|
506
601
|
autoWidth,
|
|
507
602
|
segment.text,
|
|
@@ -616,11 +711,29 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
616
711
|
verticalAlign
|
|
617
712
|
]);
|
|
618
713
|
if (autoWidth) {
|
|
714
|
+
console.log("[TextElement/render] ===== RENDERING WITH AUTO-WIDTH =====");
|
|
715
|
+
console.log("[TextElement/render] Segment ID:", segment.id);
|
|
716
|
+
console.log("[TextElement/render] calculatedWidth being applied:", calculatedWidth);
|
|
717
|
+
console.log("[TextElement/render] maxWidth (element width):", width);
|
|
718
|
+
console.log("[TextElement/render] boxAlign:", boxAlign);
|
|
719
|
+
console.log("[TextElement/render] textAlign:", alignment);
|
|
720
|
+
console.log("[TextElement/render] Number of lines:", calculatedLines.length);
|
|
721
|
+
console.log("[TextElement/render] textStyle padding:", textStyle.padding);
|
|
722
|
+
console.log("[TextElement/render] textStyle fontFamily:", textStyle.fontFamily);
|
|
723
|
+
console.log("[TextElement/render] textStyle fontSize:", textStyle.fontSize);
|
|
724
|
+
console.log("[TextElement/render] textStyle letterSpacing:", textStyle.letterSpacing);
|
|
619
725
|
const textContent = calculatedLines.map((line, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
620
726
|
line,
|
|
621
727
|
index < calculatedLines.length - 1 && /* @__PURE__ */ jsx("br", {})
|
|
622
728
|
] }, index));
|
|
623
729
|
if (backgroundColor) {
|
|
730
|
+
console.log("[TextElement/render] Rendering WITH background");
|
|
731
|
+
console.log("[TextElement/render] Background wrapper style:", {
|
|
732
|
+
width: calculatedWidth,
|
|
733
|
+
maxWidth: width,
|
|
734
|
+
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
735
|
+
borderRadius: borderRadiusStyle
|
|
736
|
+
});
|
|
624
737
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx(
|
|
625
738
|
"div",
|
|
626
739
|
{
|
|
@@ -634,6 +747,7 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
634
747
|
}
|
|
635
748
|
) });
|
|
636
749
|
}
|
|
750
|
+
console.log("[TextElement/render] Rendering WITHOUT background");
|
|
637
751
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: { width: calculatedWidth, maxWidth: width }, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: textContent }) }) });
|
|
638
752
|
}
|
|
639
753
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: backgroundBoxStyle, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: segment.text }) }) });
|
|
@@ -1156,7 +1270,7 @@ function getSortedSegments(config) {
|
|
|
1156
1270
|
});
|
|
1157
1271
|
}
|
|
1158
1272
|
function elementToTextSegment(elem) {
|
|
1159
|
-
|
|
1273
|
+
const segment = {
|
|
1160
1274
|
id: elem.id,
|
|
1161
1275
|
type: "text",
|
|
1162
1276
|
source: "",
|
|
@@ -1194,6 +1308,27 @@ function elementToTextSegment(elem) {
|
|
|
1194
1308
|
autoWidth: elem.autoWidth,
|
|
1195
1309
|
boxAlign: elem.boxAlign
|
|
1196
1310
|
};
|
|
1311
|
+
console.log("[ImageEditorComposition/elementToTextSegment] ===== CONVERTING ELEMENT TO SEGMENT =====");
|
|
1312
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element ID:", elem.id);
|
|
1313
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element text:", (elem.text ?? "").substring(0, 50));
|
|
1314
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element dimensions:", { x: elem.x, y: elem.y, width: elem.width, height: elem.height });
|
|
1315
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element padding:", {
|
|
1316
|
+
paddingTop: elem.paddingTop,
|
|
1317
|
+
paddingRight: elem.paddingRight,
|
|
1318
|
+
paddingBottom: elem.paddingBottom,
|
|
1319
|
+
paddingLeft: elem.paddingLeft
|
|
1320
|
+
});
|
|
1321
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element autoWidth:", elem.autoWidth, "boxAlign:", elem.boxAlign);
|
|
1322
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element font:", elem.font, "fontSize:", elem.fontSize, "fontWeight:", elem.fontWeight);
|
|
1323
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Element letterSpacing:", elem.letterSpacing, "lineHeight:", elem.lineHeight);
|
|
1324
|
+
console.log("[ImageEditorComposition/elementToTextSegment] Segment created:", {
|
|
1325
|
+
fontType: segment.fontType,
|
|
1326
|
+
fontSize: segment.fontSize,
|
|
1327
|
+
fontWeight: segment.fontWeight,
|
|
1328
|
+
letterSpacing: segment.letterSpacing,
|
|
1329
|
+
lineHeight: segment.lineHeight
|
|
1330
|
+
});
|
|
1331
|
+
return segment;
|
|
1197
1332
|
}
|
|
1198
1333
|
function elementToImageSegment(elem, source) {
|
|
1199
1334
|
return {
|
|
@@ -1229,8 +1364,20 @@ function ImageEditorComposition({
|
|
|
1229
1364
|
textValues = {},
|
|
1230
1365
|
dynamicCrop
|
|
1231
1366
|
}) {
|
|
1367
|
+
console.log("[ImageEditorComposition] ===== COMPOSITION RENDER =====");
|
|
1368
|
+
console.log("[ImageEditorComposition] Props received:", {
|
|
1369
|
+
hasConfig: !!config,
|
|
1370
|
+
hasElements: !!elements,
|
|
1371
|
+
elementCount: elements?.length ?? 0,
|
|
1372
|
+
width,
|
|
1373
|
+
height,
|
|
1374
|
+
scale,
|
|
1375
|
+
backgroundType,
|
|
1376
|
+
textValuesKeys: Object.keys(textValues)
|
|
1377
|
+
});
|
|
1232
1378
|
const canvasWidth = width ?? config?.width ?? 1080;
|
|
1233
1379
|
const canvasHeight = height ?? config?.height ?? 1920;
|
|
1380
|
+
console.log("[ImageEditorComposition] Canvas dimensions:", { canvasWidth, canvasHeight });
|
|
1234
1381
|
const resolvedElements = useMemo3(() => {
|
|
1235
1382
|
if (!elements) return null;
|
|
1236
1383
|
const result = resolveElementPositions(elements, textValues);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugcinc-render",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.18",
|
|
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",
|