ugcinc-render 1.3.6 → 1.3.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 +33 -14
- package/dist/index.mjs +33 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -314,31 +314,39 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
314
314
|
if (!radii) return void 0;
|
|
315
315
|
return `${radii[0] * scale}px ${radii[1] * scale}px ${radii[2] * scale}px ${radii[3] * scale}px`;
|
|
316
316
|
}, [backgroundBorderRadius, scale]);
|
|
317
|
-
const
|
|
317
|
+
const positioningContainerStyle = (0, import_react.useMemo)(() => ({
|
|
318
318
|
position: "absolute",
|
|
319
319
|
left: x,
|
|
320
320
|
top: y,
|
|
321
|
-
width
|
|
322
|
-
|
|
323
|
-
height: autoWidth ? "auto" : height,
|
|
321
|
+
width,
|
|
322
|
+
height,
|
|
324
323
|
transform: rotation !== 0 ? `rotate(${rotation}deg)` : void 0,
|
|
325
324
|
transformOrigin: "center center",
|
|
326
325
|
display: "flex",
|
|
327
326
|
flexDirection: "column",
|
|
327
|
+
// Vertical alignment within the container
|
|
328
328
|
justifyContent: verticalAlign === "top" ? "flex-start" : verticalAlign === "bottom" ? "flex-end" : "center",
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
left: boxAlign === "center" ? x + width / 2 : boxAlign === "right" ? x + width : x,
|
|
332
|
-
transform: rotation !== 0 ? `translateX(${boxAlign === "center" ? "-50%" : boxAlign === "right" ? "-100%" : "0"}) rotate(${rotation}deg)` : boxAlign === "center" ? "translateX(-50%)" : boxAlign === "right" ? "translateX(-100%)" : void 0
|
|
333
|
-
}
|
|
329
|
+
// Horizontal alignment (boxAlign) - only applies when autoWidth is enabled
|
|
330
|
+
alignItems: autoWidth ? boxAlign === "center" ? "center" : boxAlign === "right" ? "flex-end" : "flex-start" : "stretch"
|
|
334
331
|
}), [x, y, width, height, rotation, verticalAlign, autoWidth, boxAlign]);
|
|
335
|
-
const
|
|
336
|
-
|
|
332
|
+
const backgroundBoxStyle = (0, import_react.useMemo)(() => {
|
|
333
|
+
const baseStyle = autoWidth ? {
|
|
334
|
+
width: "fit-content",
|
|
335
|
+
maxWidth: "100%"
|
|
336
|
+
} : {
|
|
337
|
+
// When not autoWidth, let the text div handle everything
|
|
338
|
+
display: "flex",
|
|
339
|
+
flexDirection: "column",
|
|
340
|
+
flex: 1,
|
|
341
|
+
minHeight: 0
|
|
342
|
+
};
|
|
343
|
+
if (!backgroundColor) return baseStyle;
|
|
337
344
|
return {
|
|
345
|
+
...baseStyle,
|
|
338
346
|
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
339
347
|
borderRadius: borderRadiusStyle
|
|
340
348
|
};
|
|
341
|
-
}, [backgroundColor, backgroundOpacity, borderRadiusStyle]);
|
|
349
|
+
}, [autoWidth, backgroundColor, backgroundOpacity, borderRadiusStyle]);
|
|
342
350
|
const textStyle = (0, import_react.useMemo)(() => ({
|
|
343
351
|
fontFamily,
|
|
344
352
|
fontSize,
|
|
@@ -346,10 +354,19 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
346
354
|
color,
|
|
347
355
|
lineHeight,
|
|
348
356
|
letterSpacing,
|
|
357
|
+
// textAlign works for multi-line text within the (possibly auto-width) box
|
|
349
358
|
textAlign: alignment === "justify" ? "justify" : alignment,
|
|
350
359
|
padding: `${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`,
|
|
351
360
|
whiteSpace: "pre-wrap",
|
|
352
361
|
wordBreak: "break-word",
|
|
362
|
+
// When not autoWidth, handle vertical alignment via flex
|
|
363
|
+
...!autoWidth && {
|
|
364
|
+
display: "flex",
|
|
365
|
+
flexDirection: "column",
|
|
366
|
+
justifyContent: verticalAlign === "top" ? "flex-start" : verticalAlign === "bottom" ? "flex-end" : "center",
|
|
367
|
+
flex: 1,
|
|
368
|
+
minHeight: 0
|
|
369
|
+
},
|
|
353
370
|
// Text stroke using text-shadow for cross-browser support
|
|
354
371
|
...strokeWidth > 0 && strokeColor && {
|
|
355
372
|
textShadow: `
|
|
@@ -379,9 +396,11 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
379
396
|
paddingBottom,
|
|
380
397
|
paddingLeft,
|
|
381
398
|
strokeWidth,
|
|
382
|
-
strokeColor
|
|
399
|
+
strokeColor,
|
|
400
|
+
autoWidth,
|
|
401
|
+
verticalAlign
|
|
383
402
|
]);
|
|
384
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style:
|
|
403
|
+
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 }) }) });
|
|
385
404
|
}
|
|
386
405
|
|
|
387
406
|
// src/components/ImageElement.tsx
|
package/dist/index.mjs
CHANGED
|
@@ -253,31 +253,39 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
253
253
|
if (!radii) return void 0;
|
|
254
254
|
return `${radii[0] * scale}px ${radii[1] * scale}px ${radii[2] * scale}px ${radii[3] * scale}px`;
|
|
255
255
|
}, [backgroundBorderRadius, scale]);
|
|
256
|
-
const
|
|
256
|
+
const positioningContainerStyle = useMemo(() => ({
|
|
257
257
|
position: "absolute",
|
|
258
258
|
left: x,
|
|
259
259
|
top: y,
|
|
260
|
-
width
|
|
261
|
-
|
|
262
|
-
height: autoWidth ? "auto" : height,
|
|
260
|
+
width,
|
|
261
|
+
height,
|
|
263
262
|
transform: rotation !== 0 ? `rotate(${rotation}deg)` : void 0,
|
|
264
263
|
transformOrigin: "center center",
|
|
265
264
|
display: "flex",
|
|
266
265
|
flexDirection: "column",
|
|
266
|
+
// Vertical alignment within the container
|
|
267
267
|
justifyContent: verticalAlign === "top" ? "flex-start" : verticalAlign === "bottom" ? "flex-end" : "center",
|
|
268
|
-
//
|
|
269
|
-
|
|
270
|
-
left: boxAlign === "center" ? x + width / 2 : boxAlign === "right" ? x + width : x,
|
|
271
|
-
transform: rotation !== 0 ? `translateX(${boxAlign === "center" ? "-50%" : boxAlign === "right" ? "-100%" : "0"}) rotate(${rotation}deg)` : boxAlign === "center" ? "translateX(-50%)" : boxAlign === "right" ? "translateX(-100%)" : void 0
|
|
272
|
-
}
|
|
268
|
+
// Horizontal alignment (boxAlign) - only applies when autoWidth is enabled
|
|
269
|
+
alignItems: autoWidth ? boxAlign === "center" ? "center" : boxAlign === "right" ? "flex-end" : "flex-start" : "stretch"
|
|
273
270
|
}), [x, y, width, height, rotation, verticalAlign, autoWidth, boxAlign]);
|
|
274
|
-
const
|
|
275
|
-
|
|
271
|
+
const backgroundBoxStyle = useMemo(() => {
|
|
272
|
+
const baseStyle = autoWidth ? {
|
|
273
|
+
width: "fit-content",
|
|
274
|
+
maxWidth: "100%"
|
|
275
|
+
} : {
|
|
276
|
+
// When not autoWidth, let the text div handle everything
|
|
277
|
+
display: "flex",
|
|
278
|
+
flexDirection: "column",
|
|
279
|
+
flex: 1,
|
|
280
|
+
minHeight: 0
|
|
281
|
+
};
|
|
282
|
+
if (!backgroundColor) return baseStyle;
|
|
276
283
|
return {
|
|
284
|
+
...baseStyle,
|
|
277
285
|
backgroundColor: hexToRgba(backgroundColor, backgroundOpacity),
|
|
278
286
|
borderRadius: borderRadiusStyle
|
|
279
287
|
};
|
|
280
|
-
}, [backgroundColor, backgroundOpacity, borderRadiusStyle]);
|
|
288
|
+
}, [autoWidth, backgroundColor, backgroundOpacity, borderRadiusStyle]);
|
|
281
289
|
const textStyle = useMemo(() => ({
|
|
282
290
|
fontFamily,
|
|
283
291
|
fontSize,
|
|
@@ -285,10 +293,19 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
285
293
|
color,
|
|
286
294
|
lineHeight,
|
|
287
295
|
letterSpacing,
|
|
296
|
+
// textAlign works for multi-line text within the (possibly auto-width) box
|
|
288
297
|
textAlign: alignment === "justify" ? "justify" : alignment,
|
|
289
298
|
padding: `${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`,
|
|
290
299
|
whiteSpace: "pre-wrap",
|
|
291
300
|
wordBreak: "break-word",
|
|
301
|
+
// When not autoWidth, handle vertical alignment via flex
|
|
302
|
+
...!autoWidth && {
|
|
303
|
+
display: "flex",
|
|
304
|
+
flexDirection: "column",
|
|
305
|
+
justifyContent: verticalAlign === "top" ? "flex-start" : verticalAlign === "bottom" ? "flex-end" : "center",
|
|
306
|
+
flex: 1,
|
|
307
|
+
minHeight: 0
|
|
308
|
+
},
|
|
292
309
|
// Text stroke using text-shadow for cross-browser support
|
|
293
310
|
...strokeWidth > 0 && strokeColor && {
|
|
294
311
|
textShadow: `
|
|
@@ -318,9 +335,11 @@ function TextElement({ segment, scale = 1 }) {
|
|
|
318
335
|
paddingBottom,
|
|
319
336
|
paddingLeft,
|
|
320
337
|
strokeWidth,
|
|
321
|
-
strokeColor
|
|
338
|
+
strokeColor,
|
|
339
|
+
autoWidth,
|
|
340
|
+
verticalAlign
|
|
322
341
|
]);
|
|
323
|
-
return /* @__PURE__ */ jsx("div", { style:
|
|
342
|
+
return /* @__PURE__ */ jsx("div", { style: positioningContainerStyle, children: /* @__PURE__ */ jsx("div", { style: backgroundBoxStyle, children: /* @__PURE__ */ jsx("div", { style: textStyle, children: segment.text }) }) });
|
|
324
343
|
}
|
|
325
344
|
|
|
326
345
|
// src/components/ImageElement.tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugcinc-render",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.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",
|