visualfries 0.1.10 → 0.1.101

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.
@@ -67,8 +67,30 @@ export class HtmlToCanvasHook {
67
67
  }
68
68
  const { width, height } = this.state;
69
69
  if (!this.svgBase) {
70
- const { base, content, end } = await svgGenerator.generateSVG(this.#htmlEl, this.#context.data.appearance.text, width, height, 'svg-' + this.#context.contextData.id, encodeURIComponent(this.state.getCharactersList().join('')) // current component text encoded
71
- );
70
+ // Safely encode characters list, filtering out any problematic characters
71
+ let encodedChars = '';
72
+ try {
73
+ const charsList = this.state.getCharactersList().join('');
74
+ encodedChars = encodeURIComponent(charsList);
75
+ }
76
+ catch (error) {
77
+ // If encoding fails (e.g., unpaired surrogates), filter to only safe characters
78
+ console.warn('Failed to encode characters list, filtering to safe characters:', error);
79
+ const safeChars = this.state
80
+ .getCharactersList()
81
+ .filter((char) => {
82
+ try {
83
+ encodeURIComponent(char);
84
+ return true;
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ })
90
+ .join('');
91
+ encodedChars = encodeURIComponent(safeChars);
92
+ }
93
+ const { base, content, end } = await svgGenerator.generateSVG(this.#htmlEl, this.#context.data.appearance.text, width, height, 'svg-' + this.#context.contextData.id, encodedChars);
72
94
  this.svgBase = base;
73
95
  this.svgEnd = end;
74
96
  this.svg = base + content + end;
@@ -208,7 +208,9 @@ function buildSubtitlesManager(timeManager, eventManager, sceneData, subtitles)
208
208
  for (const [lang, langIndex] of Object.entries(assetIndex)) {
209
209
  for (const [subtitleId, subtitle] of Object.entries(langIndex)) {
210
210
  const text = subtitle.text;
211
- const characters = text.split('');
211
+ // Use Array.from to properly handle multi-codepoint characters (emojis, etc.)
212
+ // This prevents splitting emojis into unpaired surrogates that cause encodeURIComponent to fail
213
+ const characters = Array.from(text);
212
214
  if (characters && characters.length > 0) {
213
215
  for (const char of characters) {
214
216
  if (!charactersList.includes(char)) {
@@ -41,7 +41,9 @@ export const buildCharactersListFromComponentsAndSubtitles = function (layers, s
41
41
  const c = component;
42
42
  const text = c.text;
43
43
  if (text) {
44
- const textList = text.split('');
44
+ // Use Array.from to properly handle multi-codepoint characters (emojis, etc.)
45
+ // This prevents splitting emojis into unpaired surrogates
46
+ const textList = Array.from(text);
45
47
  const missingChars = textList.filter((char) => {
46
48
  // Check if the character is not whitespace, not in the characters list,
47
49
  // is a Unicode letter or number, and is NOT an emoji
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visualfries",
3
- "version": "0.1.10",
3
+ "version": "0.1.101",
4
4
  "license": "MIT",
5
5
  "author": "ContentFries",
6
6
  "repository": {