ugcinc-render 1.5.6 → 1.5.7
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.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +82 -61
- package/dist/index.mjs +79 -68
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -892,6 +892,11 @@ interface TextElementProps {
|
|
|
892
892
|
* - Padding (uniform and individual)
|
|
893
893
|
* - Auto-width with box alignment
|
|
894
894
|
* - Rotation
|
|
895
|
+
*
|
|
896
|
+
* When autoWidth is enabled:
|
|
897
|
+
* - Text wraps at maxWidth (the element's width)
|
|
898
|
+
* - Background shrinks to the widest line
|
|
899
|
+
* - boxAlign positions the box within the maxWidth container
|
|
895
900
|
*/
|
|
896
901
|
declare function TextElement({ segment, scale }: TextElementProps): react_jsx_runtime.JSX.Element;
|
|
897
902
|
|
package/dist/index.d.ts
CHANGED
|
@@ -892,6 +892,11 @@ interface TextElementProps {
|
|
|
892
892
|
* - Padding (uniform and individual)
|
|
893
893
|
* - Auto-width with box alignment
|
|
894
894
|
* - Rotation
|
|
895
|
+
*
|
|
896
|
+
* When autoWidth is enabled:
|
|
897
|
+
* - Text wraps at maxWidth (the element's width)
|
|
898
|
+
* - Background shrinks to the widest line
|
|
899
|
+
* - boxAlign positions the box within the maxWidth container
|
|
895
900
|
*/
|
|
896
901
|
declare function TextElement({ segment, scale }: TextElementProps): react_jsx_runtime.JSX.Element;
|
|
897
902
|
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -86,7 +96,7 @@ var import_react3 = require("react");
|
|
|
86
96
|
var import_remotion2 = require("remotion");
|
|
87
97
|
|
|
88
98
|
// src/components/TextElement.tsx
|
|
89
|
-
var import_react = require("react");
|
|
99
|
+
var import_react = __toESM(require("react"));
|
|
90
100
|
|
|
91
101
|
// src/utils/defaults.ts
|
|
92
102
|
var TEXT_DEFAULTS = {
|
|
@@ -294,7 +304,7 @@ function hexToRgba(hex, opacity = 100) {
|
|
|
294
304
|
|
|
295
305
|
// src/components/TextElement.tsx
|
|
296
306
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
297
|
-
function
|
|
307
|
+
function calculateAutoWidthAndLines({
|
|
298
308
|
text,
|
|
299
309
|
maxWidth,
|
|
300
310
|
paddingLeft,
|
|
@@ -306,52 +316,17 @@ function calculateAutoWidth({
|
|
|
306
316
|
lineHeight
|
|
307
317
|
}) {
|
|
308
318
|
if (typeof document === "undefined") {
|
|
309
|
-
|
|
319
|
+
return { width: maxWidth, lines: [text] };
|
|
310
320
|
}
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
visibility: hidden;
|
|
315
|
-
pointer-events: none;
|
|
316
|
-
width: ${maxWidth}px;
|
|
317
|
-
padding: 0 ${paddingRight}px 0 ${paddingLeft}px;
|
|
318
|
-
box-sizing: border-box;
|
|
319
|
-
font-family: ${fontFamily};
|
|
320
|
-
font-size: ${fontSize}px;
|
|
321
|
-
font-weight: ${fontWeight};
|
|
322
|
-
letter-spacing: ${letterSpacing}px;
|
|
323
|
-
line-height: ${lineHeight};
|
|
324
|
-
white-space: pre-wrap;
|
|
325
|
-
word-break: break-word;
|
|
326
|
-
`;
|
|
327
|
-
container.textContent = text;
|
|
328
|
-
document.body.appendChild(container);
|
|
329
|
-
const totalHeight = container.offsetHeight;
|
|
330
|
-
const lineHeightPx = fontSize * lineHeight;
|
|
331
|
-
const numLines = Math.max(1, Math.round(totalHeight / lineHeightPx));
|
|
332
|
-
if (numLines === 1) {
|
|
333
|
-
const span = document.createElement("span");
|
|
334
|
-
span.style.cssText = `
|
|
335
|
-
font-family: ${fontFamily};
|
|
336
|
-
font-size: ${fontSize}px;
|
|
337
|
-
font-weight: ${fontWeight};
|
|
338
|
-
letter-spacing: ${letterSpacing}px;
|
|
339
|
-
white-space: nowrap;
|
|
340
|
-
`;
|
|
341
|
-
span.textContent = text;
|
|
342
|
-
document.body.appendChild(span);
|
|
343
|
-
const textWidth = span.offsetWidth;
|
|
344
|
-
document.body.removeChild(span);
|
|
345
|
-
document.body.removeChild(container);
|
|
346
|
-
return Math.min(textWidth + paddingLeft + paddingRight, maxWidth);
|
|
321
|
+
const availableWidth = maxWidth - paddingLeft - paddingRight;
|
|
322
|
+
if (availableWidth <= 0) {
|
|
323
|
+
return { width: maxWidth, lines: [text] };
|
|
347
324
|
}
|
|
348
|
-
const words = text.split(" ");
|
|
349
|
-
const lines = [];
|
|
350
|
-
let currentLine = "";
|
|
351
325
|
const measureSpan = document.createElement("span");
|
|
352
326
|
measureSpan.style.cssText = `
|
|
353
327
|
position: absolute;
|
|
354
328
|
visibility: hidden;
|
|
329
|
+
pointer-events: none;
|
|
355
330
|
font-family: ${fontFamily};
|
|
356
331
|
font-size: ${fontSize}px;
|
|
357
332
|
font-weight: ${fontWeight};
|
|
@@ -359,28 +334,74 @@ function calculateAutoWidth({
|
|
|
359
334
|
white-space: nowrap;
|
|
360
335
|
`;
|
|
361
336
|
document.body.appendChild(measureSpan);
|
|
362
|
-
|
|
363
|
-
|
|
337
|
+
measureSpan.textContent = "M";
|
|
338
|
+
const charWidth = measureSpan.offsetWidth;
|
|
339
|
+
const words = text.split(/(\s+)/);
|
|
340
|
+
const lines = [];
|
|
341
|
+
let currentLine = "";
|
|
342
|
+
for (let i = 0; i < words.length; i++) {
|
|
343
|
+
const word = words[i];
|
|
344
|
+
if (word === "\n" || word === "\r\n") {
|
|
345
|
+
if (currentLine) {
|
|
346
|
+
lines.push(currentLine);
|
|
347
|
+
}
|
|
348
|
+
currentLine = "";
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
364
351
|
if (!word) continue;
|
|
365
|
-
|
|
352
|
+
if (/^\s+$/.test(word)) {
|
|
353
|
+
if (currentLine) {
|
|
354
|
+
currentLine += word;
|
|
355
|
+
}
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const testLine = currentLine + word;
|
|
366
359
|
measureSpan.textContent = testLine;
|
|
367
360
|
const testWidth = measureSpan.offsetWidth;
|
|
368
|
-
if (testWidth > availableWidth && currentLine) {
|
|
369
|
-
lines.push(currentLine);
|
|
361
|
+
if (testWidth > availableWidth && currentLine.trim()) {
|
|
362
|
+
lines.push(currentLine.trimEnd());
|
|
370
363
|
currentLine = word;
|
|
364
|
+
measureSpan.textContent = word;
|
|
365
|
+
const wordWidth = measureSpan.offsetWidth;
|
|
366
|
+
if (wordWidth > availableWidth) {
|
|
367
|
+
let remainingWord = word;
|
|
368
|
+
while (remainingWord) {
|
|
369
|
+
let breakPoint = 1;
|
|
370
|
+
for (let j = 1; j <= remainingWord.length; j++) {
|
|
371
|
+
measureSpan.textContent = remainingWord.substring(0, j);
|
|
372
|
+
if (measureSpan.offsetWidth > availableWidth) {
|
|
373
|
+
breakPoint = Math.max(1, j - 1);
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
breakPoint = j;
|
|
377
|
+
}
|
|
378
|
+
if (breakPoint >= remainingWord.length) {
|
|
379
|
+
currentLine = remainingWord;
|
|
380
|
+
break;
|
|
381
|
+
} else {
|
|
382
|
+
lines.push(remainingWord.substring(0, breakPoint));
|
|
383
|
+
remainingWord = remainingWord.substring(breakPoint);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
371
387
|
} else {
|
|
372
388
|
currentLine = testLine;
|
|
373
389
|
}
|
|
374
390
|
}
|
|
375
|
-
if (currentLine
|
|
391
|
+
if (currentLine.trim()) {
|
|
392
|
+
lines.push(currentLine.trimEnd());
|
|
393
|
+
}
|
|
394
|
+
if (lines.length === 0) {
|
|
395
|
+
lines.push("");
|
|
396
|
+
}
|
|
376
397
|
let widestLineWidth = 0;
|
|
377
398
|
for (const line of lines) {
|
|
378
399
|
measureSpan.textContent = line;
|
|
379
400
|
widestLineWidth = Math.max(widestLineWidth, measureSpan.offsetWidth);
|
|
380
401
|
}
|
|
381
402
|
document.body.removeChild(measureSpan);
|
|
382
|
-
|
|
383
|
-
return
|
|
403
|
+
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
404
|
+
return { width: calculatedWidth, lines };
|
|
384
405
|
}
|
|
385
406
|
function TextElement({ segment, scale = 1 }) {
|
|
386
407
|
const fontType = segment.fontType ?? TEXT_DEFAULTS.fontType;
|
|
@@ -409,9 +430,9 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
409
430
|
const backgroundOpacity = segment.backgroundOpacity ?? TEXT_DEFAULTS.backgroundOpacity;
|
|
410
431
|
const backgroundBorderRadius = segment.backgroundBorderRadius;
|
|
411
432
|
const fontFamily = getFontFamily(fontType);
|
|
412
|
-
const
|
|
413
|
-
if (!autoWidth) return
|
|
414
|
-
return
|
|
433
|
+
const autoWidthResult = (0, import_react.useMemo)(() => {
|
|
434
|
+
if (!autoWidth) return null;
|
|
435
|
+
return calculateAutoWidthAndLines({
|
|
415
436
|
text: segment.text,
|
|
416
437
|
maxWidth: width,
|
|
417
438
|
paddingLeft,
|
|
@@ -423,6 +444,8 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
423
444
|
lineHeight
|
|
424
445
|
});
|
|
425
446
|
}, [autoWidth, segment.text, width, paddingLeft, paddingRight, fontSize, fontWeight, fontFamily, letterSpacing, lineHeight]);
|
|
447
|
+
const calculatedWidth = autoWidthResult?.width ?? width;
|
|
448
|
+
const calculatedLines = autoWidthResult?.lines ?? [segment.text];
|
|
426
449
|
const borderRadiusStyle = (0, import_react.useMemo)(() => {
|
|
427
450
|
if (!backgroundBorderRadius) return void 0;
|
|
428
451
|
const radii = getBorderRadii(backgroundBorderRadius);
|
|
@@ -518,12 +541,10 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
518
541
|
verticalAlign
|
|
519
542
|
]);
|
|
520
543
|
if (autoWidth) {
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
textAlign: autoWidthTextAlign
|
|
526
|
-
};
|
|
544
|
+
const textContent = calculatedLines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.default.Fragment, { children: [
|
|
545
|
+
line,
|
|
546
|
+
index < calculatedLines.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})
|
|
547
|
+
] }, index));
|
|
527
548
|
if (backgroundColor) {
|
|
528
549
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: positioningContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
529
550
|
"div",
|
|
@@ -534,11 +555,11 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
534
555
|
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
535
556
|
borderRadius: borderRadiusStyle
|
|
536
557
|
},
|
|
537
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style:
|
|
558
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: textStyle, children: textContent })
|
|
538
559
|
}
|
|
539
560
|
) });
|
|
540
561
|
}
|
|
541
|
-
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:
|
|
562
|
+
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 }) }) });
|
|
542
563
|
}
|
|
543
564
|
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 }) }) });
|
|
544
565
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { useMemo as useMemo3 } from "react";
|
|
|
12
12
|
import { AbsoluteFill, Img as Img2 } from "remotion";
|
|
13
13
|
|
|
14
14
|
// src/components/TextElement.tsx
|
|
15
|
-
import { useMemo } from "react";
|
|
15
|
+
import React, { useMemo } from "react";
|
|
16
16
|
|
|
17
17
|
// src/utils/defaults.ts
|
|
18
18
|
var TEXT_DEFAULTS = {
|
|
@@ -219,8 +219,8 @@ function hexToRgba(hex, opacity = 100) {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
// src/components/TextElement.tsx
|
|
222
|
-
import { jsx } from "react/jsx-runtime";
|
|
223
|
-
function
|
|
222
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
223
|
+
function calculateAutoWidthAndLines({
|
|
224
224
|
text,
|
|
225
225
|
maxWidth,
|
|
226
226
|
paddingLeft,
|
|
@@ -232,52 +232,17 @@ function calculateAutoWidth({
|
|
|
232
232
|
lineHeight
|
|
233
233
|
}) {
|
|
234
234
|
if (typeof document === "undefined") {
|
|
235
|
-
|
|
235
|
+
return { width: maxWidth, lines: [text] };
|
|
236
236
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
visibility: hidden;
|
|
241
|
-
pointer-events: none;
|
|
242
|
-
width: ${maxWidth}px;
|
|
243
|
-
padding: 0 ${paddingRight}px 0 ${paddingLeft}px;
|
|
244
|
-
box-sizing: border-box;
|
|
245
|
-
font-family: ${fontFamily};
|
|
246
|
-
font-size: ${fontSize}px;
|
|
247
|
-
font-weight: ${fontWeight};
|
|
248
|
-
letter-spacing: ${letterSpacing}px;
|
|
249
|
-
line-height: ${lineHeight};
|
|
250
|
-
white-space: pre-wrap;
|
|
251
|
-
word-break: break-word;
|
|
252
|
-
`;
|
|
253
|
-
container.textContent = text;
|
|
254
|
-
document.body.appendChild(container);
|
|
255
|
-
const totalHeight = container.offsetHeight;
|
|
256
|
-
const lineHeightPx = fontSize * lineHeight;
|
|
257
|
-
const numLines = Math.max(1, Math.round(totalHeight / lineHeightPx));
|
|
258
|
-
if (numLines === 1) {
|
|
259
|
-
const span = document.createElement("span");
|
|
260
|
-
span.style.cssText = `
|
|
261
|
-
font-family: ${fontFamily};
|
|
262
|
-
font-size: ${fontSize}px;
|
|
263
|
-
font-weight: ${fontWeight};
|
|
264
|
-
letter-spacing: ${letterSpacing}px;
|
|
265
|
-
white-space: nowrap;
|
|
266
|
-
`;
|
|
267
|
-
span.textContent = text;
|
|
268
|
-
document.body.appendChild(span);
|
|
269
|
-
const textWidth = span.offsetWidth;
|
|
270
|
-
document.body.removeChild(span);
|
|
271
|
-
document.body.removeChild(container);
|
|
272
|
-
return Math.min(textWidth + paddingLeft + paddingRight, maxWidth);
|
|
237
|
+
const availableWidth = maxWidth - paddingLeft - paddingRight;
|
|
238
|
+
if (availableWidth <= 0) {
|
|
239
|
+
return { width: maxWidth, lines: [text] };
|
|
273
240
|
}
|
|
274
|
-
const words = text.split(" ");
|
|
275
|
-
const lines = [];
|
|
276
|
-
let currentLine = "";
|
|
277
241
|
const measureSpan = document.createElement("span");
|
|
278
242
|
measureSpan.style.cssText = `
|
|
279
243
|
position: absolute;
|
|
280
244
|
visibility: hidden;
|
|
245
|
+
pointer-events: none;
|
|
281
246
|
font-family: ${fontFamily};
|
|
282
247
|
font-size: ${fontSize}px;
|
|
283
248
|
font-weight: ${fontWeight};
|
|
@@ -285,28 +250,74 @@ function calculateAutoWidth({
|
|
|
285
250
|
white-space: nowrap;
|
|
286
251
|
`;
|
|
287
252
|
document.body.appendChild(measureSpan);
|
|
288
|
-
|
|
289
|
-
|
|
253
|
+
measureSpan.textContent = "M";
|
|
254
|
+
const charWidth = measureSpan.offsetWidth;
|
|
255
|
+
const words = text.split(/(\s+)/);
|
|
256
|
+
const lines = [];
|
|
257
|
+
let currentLine = "";
|
|
258
|
+
for (let i = 0; i < words.length; i++) {
|
|
259
|
+
const word = words[i];
|
|
260
|
+
if (word === "\n" || word === "\r\n") {
|
|
261
|
+
if (currentLine) {
|
|
262
|
+
lines.push(currentLine);
|
|
263
|
+
}
|
|
264
|
+
currentLine = "";
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
290
267
|
if (!word) continue;
|
|
291
|
-
|
|
268
|
+
if (/^\s+$/.test(word)) {
|
|
269
|
+
if (currentLine) {
|
|
270
|
+
currentLine += word;
|
|
271
|
+
}
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const testLine = currentLine + word;
|
|
292
275
|
measureSpan.textContent = testLine;
|
|
293
276
|
const testWidth = measureSpan.offsetWidth;
|
|
294
|
-
if (testWidth > availableWidth && currentLine) {
|
|
295
|
-
lines.push(currentLine);
|
|
277
|
+
if (testWidth > availableWidth && currentLine.trim()) {
|
|
278
|
+
lines.push(currentLine.trimEnd());
|
|
296
279
|
currentLine = word;
|
|
280
|
+
measureSpan.textContent = word;
|
|
281
|
+
const wordWidth = measureSpan.offsetWidth;
|
|
282
|
+
if (wordWidth > availableWidth) {
|
|
283
|
+
let remainingWord = word;
|
|
284
|
+
while (remainingWord) {
|
|
285
|
+
let breakPoint = 1;
|
|
286
|
+
for (let j = 1; j <= remainingWord.length; j++) {
|
|
287
|
+
measureSpan.textContent = remainingWord.substring(0, j);
|
|
288
|
+
if (measureSpan.offsetWidth > availableWidth) {
|
|
289
|
+
breakPoint = Math.max(1, j - 1);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
breakPoint = j;
|
|
293
|
+
}
|
|
294
|
+
if (breakPoint >= remainingWord.length) {
|
|
295
|
+
currentLine = remainingWord;
|
|
296
|
+
break;
|
|
297
|
+
} else {
|
|
298
|
+
lines.push(remainingWord.substring(0, breakPoint));
|
|
299
|
+
remainingWord = remainingWord.substring(breakPoint);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
297
303
|
} else {
|
|
298
304
|
currentLine = testLine;
|
|
299
305
|
}
|
|
300
306
|
}
|
|
301
|
-
if (currentLine
|
|
307
|
+
if (currentLine.trim()) {
|
|
308
|
+
lines.push(currentLine.trimEnd());
|
|
309
|
+
}
|
|
310
|
+
if (lines.length === 0) {
|
|
311
|
+
lines.push("");
|
|
312
|
+
}
|
|
302
313
|
let widestLineWidth = 0;
|
|
303
314
|
for (const line of lines) {
|
|
304
315
|
measureSpan.textContent = line;
|
|
305
316
|
widestLineWidth = Math.max(widestLineWidth, measureSpan.offsetWidth);
|
|
306
317
|
}
|
|
307
318
|
document.body.removeChild(measureSpan);
|
|
308
|
-
|
|
309
|
-
return
|
|
319
|
+
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
320
|
+
return { width: calculatedWidth, lines };
|
|
310
321
|
}
|
|
311
322
|
function TextElement({ segment, scale = 1 }) {
|
|
312
323
|
const fontType = segment.fontType ?? TEXT_DEFAULTS.fontType;
|
|
@@ -335,9 +346,9 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
335
346
|
const backgroundOpacity = segment.backgroundOpacity ?? TEXT_DEFAULTS.backgroundOpacity;
|
|
336
347
|
const backgroundBorderRadius = segment.backgroundBorderRadius;
|
|
337
348
|
const fontFamily = getFontFamily(fontType);
|
|
338
|
-
const
|
|
339
|
-
if (!autoWidth) return
|
|
340
|
-
return
|
|
349
|
+
const autoWidthResult = useMemo(() => {
|
|
350
|
+
if (!autoWidth) return null;
|
|
351
|
+
return calculateAutoWidthAndLines({
|
|
341
352
|
text: segment.text,
|
|
342
353
|
maxWidth: width,
|
|
343
354
|
paddingLeft,
|
|
@@ -349,6 +360,8 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
349
360
|
lineHeight
|
|
350
361
|
});
|
|
351
362
|
}, [autoWidth, segment.text, width, paddingLeft, paddingRight, fontSize, fontWeight, fontFamily, letterSpacing, lineHeight]);
|
|
363
|
+
const calculatedWidth = autoWidthResult?.width ?? width;
|
|
364
|
+
const calculatedLines = autoWidthResult?.lines ?? [segment.text];
|
|
352
365
|
const borderRadiusStyle = useMemo(() => {
|
|
353
366
|
if (!backgroundBorderRadius) return void 0;
|
|
354
367
|
const radii = getBorderRadii(backgroundBorderRadius);
|
|
@@ -444,12 +457,10 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
444
457
|
verticalAlign
|
|
445
458
|
]);
|
|
446
459
|
if (autoWidth) {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
textAlign: autoWidthTextAlign
|
|
452
|
-
};
|
|
460
|
+
const textContent = calculatedLines.map((line, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
461
|
+
line,
|
|
462
|
+
index < calculatedLines.length - 1 && /* @__PURE__ */ jsx("br", {})
|
|
463
|
+
] }, index));
|
|
453
464
|
if (backgroundColor) {
|
|
454
465
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx(
|
|
455
466
|
"div",
|
|
@@ -460,11 +471,11 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
460
471
|
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
461
472
|
borderRadius: borderRadiusStyle
|
|
462
473
|
},
|
|
463
|
-
children: /* @__PURE__ */ jsx("div", { style:
|
|
474
|
+
children: /* @__PURE__ */ jsx("div", { style: textStyle, children: textContent })
|
|
464
475
|
}
|
|
465
476
|
) });
|
|
466
477
|
}
|
|
467
|
-
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: { width: calculatedWidth, maxWidth: width }, children: /* @__PURE__ */ jsx("div", { style:
|
|
478
|
+
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: { width: calculatedWidth, maxWidth: width }, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: textContent }) }) });
|
|
468
479
|
}
|
|
469
480
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: backgroundBoxStyle, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: segment.text }) }) });
|
|
470
481
|
}
|
|
@@ -973,7 +984,7 @@ function isDynamicCropEnabled(dynamicCrop) {
|
|
|
973
984
|
}
|
|
974
985
|
|
|
975
986
|
// src/compositions/ImageEditorComposition.tsx
|
|
976
|
-
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
987
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
977
988
|
function getSortedSegments(config) {
|
|
978
989
|
const allSegments = [];
|
|
979
990
|
for (const channel of config.channels) {
|
|
@@ -1109,7 +1120,7 @@ function ImageEditorComposition({
|
|
|
1109
1120
|
return void 0;
|
|
1110
1121
|
};
|
|
1111
1122
|
const containerBgColor = backgroundType === "color" && backgroundColor ? backgroundColor : "#000000";
|
|
1112
|
-
return /* @__PURE__ */ jsx3(AbsoluteFill, { style: { backgroundColor: containerBgColor }, children: /* @__PURE__ */
|
|
1123
|
+
return /* @__PURE__ */ jsx3(AbsoluteFill, { style: { backgroundColor: containerBgColor }, children: /* @__PURE__ */ jsxs2(
|
|
1113
1124
|
"div",
|
|
1114
1125
|
{
|
|
1115
1126
|
style: {
|
|
@@ -1283,7 +1294,7 @@ function VideoElement({
|
|
|
1283
1294
|
}
|
|
1284
1295
|
|
|
1285
1296
|
// src/compositions/VideoEditorComposition.tsx
|
|
1286
|
-
import { jsx as jsx5, jsxs as
|
|
1297
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1287
1298
|
function calculateSegmentTimings(config, fps) {
|
|
1288
1299
|
const timings = [];
|
|
1289
1300
|
const timingsMap = /* @__PURE__ */ new Map();
|
|
@@ -1387,7 +1398,7 @@ function VideoEditorComposition({
|
|
|
1387
1398
|
const audioTimings = useMemo5(() => {
|
|
1388
1399
|
return segmentTimings.filter(({ segment }) => segment.type === "audio");
|
|
1389
1400
|
}, [segmentTimings]);
|
|
1390
|
-
return /* @__PURE__ */
|
|
1401
|
+
return /* @__PURE__ */ jsxs3(AbsoluteFill2, { style: { backgroundColor: "#000000" }, children: [
|
|
1391
1402
|
activeVisualSegments.map(({ segment, startFrame, durationInFrames: durationInFrames2 }) => {
|
|
1392
1403
|
if (segment.type === "text") {
|
|
1393
1404
|
const textSegment = segment;
|
|
@@ -1703,7 +1714,7 @@ function useResolvedPositions(elements, textValues) {
|
|
|
1703
1714
|
|
|
1704
1715
|
// src/Root.tsx
|
|
1705
1716
|
import { Composition } from "remotion";
|
|
1706
|
-
import { Fragment, jsx as jsx6, jsxs as
|
|
1717
|
+
import { Fragment, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1707
1718
|
var defaultImageProps = {
|
|
1708
1719
|
config: {
|
|
1709
1720
|
width: 1080,
|
|
@@ -1727,7 +1738,7 @@ var defaultVideoProps = {
|
|
|
1727
1738
|
var ImageComp = ImageEditorComposition;
|
|
1728
1739
|
var VideoComp = VideoEditorComposition;
|
|
1729
1740
|
var RenderRoot = () => {
|
|
1730
|
-
return /* @__PURE__ */
|
|
1741
|
+
return /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
1731
1742
|
/* @__PURE__ */ jsx6(
|
|
1732
1743
|
Composition,
|
|
1733
1744
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugcinc-render",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
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",
|