ugcinc 4.5.71 → 4.5.73

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.
@@ -162,18 +162,61 @@ function calculateAutoWidthAndLines({ text, maxWidth, paddingLeft, paddingRight,
162
162
  const calculatedWidth = Math.min(widestLineWidth + paddingLeft + paddingRight, maxWidth);
163
163
  return { width: calculatedWidth, lines };
164
164
  }
165
+ /** Word Joiner (U+2060) — zero-width character that prevents line breaks */
166
+ const WJ = '\u2060';
167
+ /** Style for emoji spans in the fill layer — no visual change */
168
+ const emojiSpanStyle = { display: 'inline' };
169
+ /** Style for emoji spans in the stroke layer — hidden from SVG filter */
170
+ const emojiSpanStrokeStyle = { display: 'inline', opacity: 0 };
165
171
  /**
166
- * Replace emoji characters with em-spaces for the stroke layer.
167
- * Em-space (U+2003) is 1em wide, close to emoji width (~1-1.2em),
168
- * preserving line width for correct text-align centering.
169
- * The em-space renders as whitespace (no alpha for feMorphology to dilate).
172
+ * Group consecutive parts from splitTextAndEmojis into merged groups.
173
+ * Consecutive emoji parts are joined into a single group so they share one span,
174
+ * reducing break opportunities.
170
175
  */
171
- function getStrokeText(text) {
176
+ function groupEmojiParts(parts) {
177
+ const groups = [];
178
+ for (const part of parts) {
179
+ const last = groups[groups.length - 1];
180
+ if (last && last.type === part.type) {
181
+ last.content += part.content;
182
+ }
183
+ else {
184
+ groups.push({ type: part.type, content: part.content });
185
+ }
186
+ }
187
+ return groups;
188
+ }
189
+ /**
190
+ * Render text with emojis wrapped in spans + Word Joiners at span boundaries.
191
+ *
192
+ * Both fill and stroke divs use this so they have identical DOM structure
193
+ * (matching vertical metrics and line breaks). The only difference is the
194
+ * emoji span style: fill spans are visible, stroke spans have opacity: 0.
195
+ *
196
+ * Word Joiners (U+2060) are inserted at boundaries between text nodes and
197
+ * emoji spans to prevent the browser from introducing break opportunities
198
+ * that don't exist in the original plain text.
199
+ */
200
+ function renderTextWithEmojiSpans(text, forStroke) {
172
201
  if (!(0, emoji_1.hasEmoji)(text))
173
202
  return text;
174
- return (0, emoji_1.splitTextAndEmojis)(text)
175
- .map(part => part.type === 'emoji' ? '\u2003' : part.content)
176
- .join('');
203
+ const parts = (0, emoji_1.splitTextAndEmojis)(text);
204
+ const groups = groupEmojiParts(parts);
205
+ const style = forStroke ? emojiSpanStrokeStyle : emojiSpanStyle;
206
+ const result = [];
207
+ for (let i = 0; i < groups.length; i++) {
208
+ const group = groups[i];
209
+ // Insert Word Joiner between adjacent groups to prevent unwanted line breaks
210
+ if (i > 0)
211
+ result.push(WJ);
212
+ if (group.type === 'emoji') {
213
+ result.push((0, jsx_runtime_1.jsx)("span", { style: style, children: group.content }, i));
214
+ }
215
+ else {
216
+ result.push(group.content);
217
+ }
218
+ }
219
+ return result;
177
220
  }
178
221
  /**
179
222
  * TextElement renders text with full styling support including:
@@ -379,8 +422,8 @@ function TextElement({ segment, scale = 1 }) {
379
422
  const strokePadPct = Math.max(50, Math.ceil((strokeWidth / fontSize) * 200));
380
423
  const strokeFilterSvg = hasStroke ? ((0, jsx_runtime_1.jsx)("svg", { style: { position: 'absolute', width: 0, height: 0, overflow: 'hidden' }, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsxs)("filter", { id: filterId, x: `-${strokePadPct}%`, y: `-${strokePadPct}%`, width: `${100 + 2 * strokePadPct}%`, height: `${100 + 2 * strokePadPct}%`, children: [(0, jsx_runtime_1.jsx)("feMorphology", { in: "SourceAlpha", operator: "dilate", radius: strokeWidth, result: "dilated" }), (0, jsx_runtime_1.jsx)("feFlood", { floodColor: strokeColor, result: "color" }), (0, jsx_runtime_1.jsx)("feComposite", { in: "color", in2: "dilated", operator: "in" })] }) }) })) : null;
381
424
  if (autoWidth) {
382
- const textContent = calculatedLines.map((line, index) => ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [line, index < calculatedLines.length - 1 && (0, jsx_runtime_1.jsx)("br", {})] }, index)));
383
- const strokeContent = calculatedLines.map((line, index) => ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [getStrokeText(line), index < calculatedLines.length - 1 && (0, jsx_runtime_1.jsx)("br", {})] }, index)));
425
+ const textContent = calculatedLines.map((line, index) => ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [renderTextWithEmojiSpans(line, false), index < calculatedLines.length - 1 && (0, jsx_runtime_1.jsx)("br", {})] }, index)));
426
+ const strokeContent = calculatedLines.map((line, index) => ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [renderTextWithEmojiSpans(line, true), index < calculatedLines.length - 1 && (0, jsx_runtime_1.jsx)("br", {})] }, index)));
384
427
  if (backgroundColor) {
385
428
  return ((0, jsx_runtime_1.jsx)("div", { style: positioningContainerStyle, children: (0, jsx_runtime_1.jsxs)("div", { style: {
386
429
  width: calculatedWidth,
@@ -392,6 +435,6 @@ function TextElement({ segment, scale = 1 }) {
392
435
  }
393
436
  return ((0, jsx_runtime_1.jsx)("div", { style: positioningContainerStyle, children: (0, jsx_runtime_1.jsxs)("div", { style: { width: calculatedWidth, maxWidth: width, ...(hasStroke && { position: 'relative' }) }, children: [strokeFilterSvg, strokeTextStyle && (0, jsx_runtime_1.jsx)("div", { style: strokeTextStyle, "aria-hidden": "true", children: strokeContent }), (0, jsx_runtime_1.jsx)("div", { style: textStyle, children: textContent })] }) }));
394
437
  }
395
- return ((0, jsx_runtime_1.jsx)("div", { style: positioningContainerStyle, children: (0, jsx_runtime_1.jsxs)("div", { style: { ...backgroundBoxStyle, ...(hasStroke && { position: 'relative' }) }, children: [strokeFilterSvg, strokeTextStyle && (0, jsx_runtime_1.jsx)("div", { style: strokeTextStyle, "aria-hidden": "true", children: getStrokeText(segment.text) }), (0, jsx_runtime_1.jsx)("div", { style: textStyle, children: segment.text })] }) }));
438
+ return ((0, jsx_runtime_1.jsx)("div", { style: positioningContainerStyle, children: (0, jsx_runtime_1.jsxs)("div", { style: { ...backgroundBoxStyle, ...(hasStroke && { position: 'relative' }) }, children: [strokeFilterSvg, strokeTextStyle && (0, jsx_runtime_1.jsx)("div", { style: strokeTextStyle, "aria-hidden": "true", children: renderTextWithEmojiSpans(segment.text, true) }), (0, jsx_runtime_1.jsx)("div", { style: textStyle, children: renderTextWithEmojiSpans(segment.text, false) })] }) }));
396
439
  }
397
440
  exports.default = TextElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc",
3
- "version": "4.5.71",
3
+ "version": "4.5.73",
4
4
  "description": "TypeScript/JavaScript client for the UGC Inc API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",