ugcinc-render 1.5.6 → 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.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +85 -63
- package/dist/index.mjs +82 -70
- 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,75 @@ 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.getBoundingClientRect().width;
|
|
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
|
-
const testWidth = measureSpan.
|
|
368
|
-
|
|
369
|
-
|
|
360
|
+
const testWidth = measureSpan.getBoundingClientRect().width;
|
|
361
|
+
const WRAP_TOLERANCE = 0.5;
|
|
362
|
+
if (testWidth > availableWidth + WRAP_TOLERANCE && currentLine.trim()) {
|
|
363
|
+
lines.push(currentLine.trimEnd());
|
|
370
364
|
currentLine = word;
|
|
365
|
+
measureSpan.textContent = word;
|
|
366
|
+
const wordWidth = measureSpan.getBoundingClientRect().width;
|
|
367
|
+
if (wordWidth > availableWidth) {
|
|
368
|
+
let remainingWord = word;
|
|
369
|
+
while (remainingWord) {
|
|
370
|
+
let breakPoint = 1;
|
|
371
|
+
for (let j = 1; j <= remainingWord.length; j++) {
|
|
372
|
+
measureSpan.textContent = remainingWord.substring(0, j);
|
|
373
|
+
if (measureSpan.getBoundingClientRect().width > availableWidth) {
|
|
374
|
+
breakPoint = Math.max(1, j - 1);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
breakPoint = j;
|
|
378
|
+
}
|
|
379
|
+
if (breakPoint >= remainingWord.length) {
|
|
380
|
+
currentLine = remainingWord;
|
|
381
|
+
break;
|
|
382
|
+
} else {
|
|
383
|
+
lines.push(remainingWord.substring(0, breakPoint));
|
|
384
|
+
remainingWord = remainingWord.substring(breakPoint);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
371
388
|
} else {
|
|
372
389
|
currentLine = testLine;
|
|
373
390
|
}
|
|
374
391
|
}
|
|
375
|
-
if (currentLine
|
|
392
|
+
if (currentLine.trim()) {
|
|
393
|
+
lines.push(currentLine.trimEnd());
|
|
394
|
+
}
|
|
395
|
+
if (lines.length === 0) {
|
|
396
|
+
lines.push("");
|
|
397
|
+
}
|
|
376
398
|
let widestLineWidth = 0;
|
|
377
399
|
for (const line of lines) {
|
|
378
400
|
measureSpan.textContent = line;
|
|
379
|
-
widestLineWidth = Math.max(widestLineWidth, measureSpan.
|
|
401
|
+
widestLineWidth = Math.max(widestLineWidth, measureSpan.getBoundingClientRect().width);
|
|
380
402
|
}
|
|
381
403
|
document.body.removeChild(measureSpan);
|
|
382
|
-
|
|
383
|
-
return
|
|
404
|
+
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
405
|
+
return { width: calculatedWidth, lines };
|
|
384
406
|
}
|
|
385
407
|
function TextElement({ segment, scale = 1 }) {
|
|
386
408
|
const fontType = segment.fontType ?? TEXT_DEFAULTS.fontType;
|
|
@@ -409,9 +431,9 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
409
431
|
const backgroundOpacity = segment.backgroundOpacity ?? TEXT_DEFAULTS.backgroundOpacity;
|
|
410
432
|
const backgroundBorderRadius = segment.backgroundBorderRadius;
|
|
411
433
|
const fontFamily = getFontFamily(fontType);
|
|
412
|
-
const
|
|
413
|
-
if (!autoWidth) return
|
|
414
|
-
return
|
|
434
|
+
const autoWidthResult = (0, import_react.useMemo)(() => {
|
|
435
|
+
if (!autoWidth) return null;
|
|
436
|
+
return calculateAutoWidthAndLines({
|
|
415
437
|
text: segment.text,
|
|
416
438
|
maxWidth: width,
|
|
417
439
|
paddingLeft,
|
|
@@ -423,6 +445,8 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
423
445
|
lineHeight
|
|
424
446
|
});
|
|
425
447
|
}, [autoWidth, segment.text, width, paddingLeft, paddingRight, fontSize, fontWeight, fontFamily, letterSpacing, lineHeight]);
|
|
448
|
+
const calculatedWidth = autoWidthResult?.width ?? width;
|
|
449
|
+
const calculatedLines = autoWidthResult?.lines ?? [segment.text];
|
|
426
450
|
const borderRadiusStyle = (0, import_react.useMemo)(() => {
|
|
427
451
|
if (!backgroundBorderRadius) return void 0;
|
|
428
452
|
const radii = getBorderRadii(backgroundBorderRadius);
|
|
@@ -518,12 +542,10 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
518
542
|
verticalAlign
|
|
519
543
|
]);
|
|
520
544
|
if (autoWidth) {
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
textAlign: autoWidthTextAlign
|
|
526
|
-
};
|
|
545
|
+
const textContent = calculatedLines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.default.Fragment, { children: [
|
|
546
|
+
line,
|
|
547
|
+
index < calculatedLines.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})
|
|
548
|
+
] }, index));
|
|
527
549
|
if (backgroundColor) {
|
|
528
550
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: positioningContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
529
551
|
"div",
|
|
@@ -534,11 +556,11 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
534
556
|
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
535
557
|
borderRadius: borderRadiusStyle
|
|
536
558
|
},
|
|
537
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style:
|
|
559
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: textStyle, children: textContent })
|
|
538
560
|
}
|
|
539
561
|
) });
|
|
540
562
|
}
|
|
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:
|
|
563
|
+
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
564
|
}
|
|
543
565
|
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
566
|
}
|
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,75 @@ 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.getBoundingClientRect().width;
|
|
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
|
-
const testWidth = measureSpan.
|
|
294
|
-
|
|
295
|
-
|
|
276
|
+
const testWidth = measureSpan.getBoundingClientRect().width;
|
|
277
|
+
const WRAP_TOLERANCE = 0.5;
|
|
278
|
+
if (testWidth > availableWidth + WRAP_TOLERANCE && currentLine.trim()) {
|
|
279
|
+
lines.push(currentLine.trimEnd());
|
|
296
280
|
currentLine = word;
|
|
281
|
+
measureSpan.textContent = word;
|
|
282
|
+
const wordWidth = measureSpan.getBoundingClientRect().width;
|
|
283
|
+
if (wordWidth > availableWidth) {
|
|
284
|
+
let remainingWord = word;
|
|
285
|
+
while (remainingWord) {
|
|
286
|
+
let breakPoint = 1;
|
|
287
|
+
for (let j = 1; j <= remainingWord.length; j++) {
|
|
288
|
+
measureSpan.textContent = remainingWord.substring(0, j);
|
|
289
|
+
if (measureSpan.getBoundingClientRect().width > availableWidth) {
|
|
290
|
+
breakPoint = Math.max(1, j - 1);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
breakPoint = j;
|
|
294
|
+
}
|
|
295
|
+
if (breakPoint >= remainingWord.length) {
|
|
296
|
+
currentLine = remainingWord;
|
|
297
|
+
break;
|
|
298
|
+
} else {
|
|
299
|
+
lines.push(remainingWord.substring(0, breakPoint));
|
|
300
|
+
remainingWord = remainingWord.substring(breakPoint);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
297
304
|
} else {
|
|
298
305
|
currentLine = testLine;
|
|
299
306
|
}
|
|
300
307
|
}
|
|
301
|
-
if (currentLine
|
|
308
|
+
if (currentLine.trim()) {
|
|
309
|
+
lines.push(currentLine.trimEnd());
|
|
310
|
+
}
|
|
311
|
+
if (lines.length === 0) {
|
|
312
|
+
lines.push("");
|
|
313
|
+
}
|
|
302
314
|
let widestLineWidth = 0;
|
|
303
315
|
for (const line of lines) {
|
|
304
316
|
measureSpan.textContent = line;
|
|
305
|
-
widestLineWidth = Math.max(widestLineWidth, measureSpan.
|
|
317
|
+
widestLineWidth = Math.max(widestLineWidth, measureSpan.getBoundingClientRect().width);
|
|
306
318
|
}
|
|
307
319
|
document.body.removeChild(measureSpan);
|
|
308
|
-
|
|
309
|
-
return
|
|
320
|
+
const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
|
|
321
|
+
return { width: calculatedWidth, lines };
|
|
310
322
|
}
|
|
311
323
|
function TextElement({ segment, scale = 1 }) {
|
|
312
324
|
const fontType = segment.fontType ?? TEXT_DEFAULTS.fontType;
|
|
@@ -335,9 +347,9 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
335
347
|
const backgroundOpacity = segment.backgroundOpacity ?? TEXT_DEFAULTS.backgroundOpacity;
|
|
336
348
|
const backgroundBorderRadius = segment.backgroundBorderRadius;
|
|
337
349
|
const fontFamily = getFontFamily(fontType);
|
|
338
|
-
const
|
|
339
|
-
if (!autoWidth) return
|
|
340
|
-
return
|
|
350
|
+
const autoWidthResult = useMemo(() => {
|
|
351
|
+
if (!autoWidth) return null;
|
|
352
|
+
return calculateAutoWidthAndLines({
|
|
341
353
|
text: segment.text,
|
|
342
354
|
maxWidth: width,
|
|
343
355
|
paddingLeft,
|
|
@@ -349,6 +361,8 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
349
361
|
lineHeight
|
|
350
362
|
});
|
|
351
363
|
}, [autoWidth, segment.text, width, paddingLeft, paddingRight, fontSize, fontWeight, fontFamily, letterSpacing, lineHeight]);
|
|
364
|
+
const calculatedWidth = autoWidthResult?.width ?? width;
|
|
365
|
+
const calculatedLines = autoWidthResult?.lines ?? [segment.text];
|
|
352
366
|
const borderRadiusStyle = useMemo(() => {
|
|
353
367
|
if (!backgroundBorderRadius) return void 0;
|
|
354
368
|
const radii = getBorderRadii(backgroundBorderRadius);
|
|
@@ -444,12 +458,10 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
444
458
|
verticalAlign
|
|
445
459
|
]);
|
|
446
460
|
if (autoWidth) {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
textAlign: autoWidthTextAlign
|
|
452
|
-
};
|
|
461
|
+
const textContent = calculatedLines.map((line, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
462
|
+
line,
|
|
463
|
+
index < calculatedLines.length - 1 && /* @__PURE__ */ jsx("br", {})
|
|
464
|
+
] }, index));
|
|
453
465
|
if (backgroundColor) {
|
|
454
466
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx(
|
|
455
467
|
"div",
|
|
@@ -460,11 +472,11 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
460
472
|
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
461
473
|
borderRadius: borderRadiusStyle
|
|
462
474
|
},
|
|
463
|
-
children: /* @__PURE__ */ jsx("div", { style:
|
|
475
|
+
children: /* @__PURE__ */ jsx("div", { style: textStyle, children: textContent })
|
|
464
476
|
}
|
|
465
477
|
) });
|
|
466
478
|
}
|
|
467
|
-
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: { width: calculatedWidth, maxWidth: width }, children: /* @__PURE__ */ jsx("div", { style:
|
|
479
|
+
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: { width: calculatedWidth, maxWidth: width }, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: textContent }) }) });
|
|
468
480
|
}
|
|
469
481
|
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: backgroundBoxStyle, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: segment.text }) }) });
|
|
470
482
|
}
|
|
@@ -973,7 +985,7 @@ function isDynamicCropEnabled(dynamicCrop) {
|
|
|
973
985
|
}
|
|
974
986
|
|
|
975
987
|
// src/compositions/ImageEditorComposition.tsx
|
|
976
|
-
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
988
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
977
989
|
function getSortedSegments(config) {
|
|
978
990
|
const allSegments = [];
|
|
979
991
|
for (const channel of config.channels) {
|
|
@@ -1109,7 +1121,7 @@ function ImageEditorComposition({
|
|
|
1109
1121
|
return void 0;
|
|
1110
1122
|
};
|
|
1111
1123
|
const containerBgColor = backgroundType === "color" && backgroundColor ? backgroundColor : "#000000";
|
|
1112
|
-
return /* @__PURE__ */ jsx3(AbsoluteFill, { style: { backgroundColor: containerBgColor }, children: /* @__PURE__ */
|
|
1124
|
+
return /* @__PURE__ */ jsx3(AbsoluteFill, { style: { backgroundColor: containerBgColor }, children: /* @__PURE__ */ jsxs2(
|
|
1113
1125
|
"div",
|
|
1114
1126
|
{
|
|
1115
1127
|
style: {
|
|
@@ -1283,7 +1295,7 @@ function VideoElement({
|
|
|
1283
1295
|
}
|
|
1284
1296
|
|
|
1285
1297
|
// src/compositions/VideoEditorComposition.tsx
|
|
1286
|
-
import { jsx as jsx5, jsxs as
|
|
1298
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1287
1299
|
function calculateSegmentTimings(config, fps) {
|
|
1288
1300
|
const timings = [];
|
|
1289
1301
|
const timingsMap = /* @__PURE__ */ new Map();
|
|
@@ -1387,7 +1399,7 @@ function VideoEditorComposition({
|
|
|
1387
1399
|
const audioTimings = useMemo5(() => {
|
|
1388
1400
|
return segmentTimings.filter(({ segment }) => segment.type === "audio");
|
|
1389
1401
|
}, [segmentTimings]);
|
|
1390
|
-
return /* @__PURE__ */
|
|
1402
|
+
return /* @__PURE__ */ jsxs3(AbsoluteFill2, { style: { backgroundColor: "#000000" }, children: [
|
|
1391
1403
|
activeVisualSegments.map(({ segment, startFrame, durationInFrames: durationInFrames2 }) => {
|
|
1392
1404
|
if (segment.type === "text") {
|
|
1393
1405
|
const textSegment = segment;
|
|
@@ -1703,7 +1715,7 @@ function useResolvedPositions(elements, textValues) {
|
|
|
1703
1715
|
|
|
1704
1716
|
// src/Root.tsx
|
|
1705
1717
|
import { Composition } from "remotion";
|
|
1706
|
-
import { Fragment, jsx as jsx6, jsxs as
|
|
1718
|
+
import { Fragment, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1707
1719
|
var defaultImageProps = {
|
|
1708
1720
|
config: {
|
|
1709
1721
|
width: 1080,
|
|
@@ -1727,7 +1739,7 @@ var defaultVideoProps = {
|
|
|
1727
1739
|
var ImageComp = ImageEditorComposition;
|
|
1728
1740
|
var VideoComp = VideoEditorComposition;
|
|
1729
1741
|
var RenderRoot = () => {
|
|
1730
|
-
return /* @__PURE__ */
|
|
1742
|
+
return /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
1731
1743
|
/* @__PURE__ */ jsx6(
|
|
1732
1744
|
Composition,
|
|
1733
1745
|
{
|
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",
|