visualfries 0.1.10 → 0.1.102
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/components/hooks/HtmlToCanvasHook.js +24 -2
- package/dist/components/hooks/PixiSplitScreenDisplayObjectHook.js +9 -3
- package/dist/components/hooks/PixiVideoTextureHook.js +25 -3
- package/dist/managers/SubtitlesManager.svelte.js +3 -1
- package/dist/utils/utils.js +3 -1
- package/package.json +1 -1
|
@@ -67,8 +67,30 @@ export class HtmlToCanvasHook {
|
|
|
67
67
|
}
|
|
68
68
|
const { width, height } = this.state;
|
|
69
69
|
if (!this.svgBase) {
|
|
70
|
-
|
|
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;
|
|
@@ -78,7 +78,8 @@ export class PixiSplitScreenDisplayObjectHook {
|
|
|
78
78
|
// Get the source element (video/image)
|
|
79
79
|
const sourceElement = this.#context.getResource('videoElement');
|
|
80
80
|
if (!sourceElement) {
|
|
81
|
-
|
|
81
|
+
// Video element not ready yet - will be called again on next update
|
|
82
|
+
return;
|
|
82
83
|
}
|
|
83
84
|
// const sourceElement = this.#pixiTexture.baseTexture.resource.source as
|
|
84
85
|
// | HTMLVideoElement
|
|
@@ -187,8 +188,13 @@ export class PixiSplitScreenDisplayObjectHook {
|
|
|
187
188
|
}
|
|
188
189
|
async #handleRefresh() {
|
|
189
190
|
await this.#handleDestroy();
|
|
190
|
-
|
|
191
|
-
this.#
|
|
191
|
+
// Reset texture reference so it gets refreshed from context
|
|
192
|
+
this.#pixiTexture = undefined;
|
|
193
|
+
if (this.#displayObject) {
|
|
194
|
+
this.#displayObject.removeChildren();
|
|
195
|
+
}
|
|
196
|
+
// Don't call #initDisplayObject here - let #handleUpdate do it
|
|
197
|
+
// after resources are ready
|
|
192
198
|
await this.#handleUpdate();
|
|
193
199
|
}
|
|
194
200
|
async #handleDestroy() {
|
|
@@ -2,18 +2,25 @@ import * as PIXI from 'pixi.js-legacy';
|
|
|
2
2
|
import { VideoComponentShape } from '../..';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export class PixiVideoTextureHook {
|
|
5
|
-
types = ['update'];
|
|
5
|
+
types = ['update', 'destroy', 'refresh'];
|
|
6
6
|
priority = 1;
|
|
7
7
|
#context;
|
|
8
8
|
#videoTexture;
|
|
9
9
|
componentElement;
|
|
10
|
+
#handlers = {
|
|
11
|
+
update: this.#handleUpdate.bind(this),
|
|
12
|
+
destroy: this.#handleDestroy.bind(this),
|
|
13
|
+
refresh: this.#handleRefresh.bind(this),
|
|
14
|
+
'refresh:config': this.#handleRefresh.bind(this)
|
|
15
|
+
};
|
|
10
16
|
async #handleUpdate() {
|
|
11
17
|
if (this.#videoTexture) {
|
|
12
18
|
return;
|
|
13
19
|
}
|
|
14
20
|
const media = this.#context.getResource('videoElement');
|
|
15
21
|
if (!media) {
|
|
16
|
-
|
|
22
|
+
// Video element not ready yet - will be called again on next update
|
|
23
|
+
return;
|
|
17
24
|
}
|
|
18
25
|
const res = new PIXI.VideoResource(media, {
|
|
19
26
|
autoPlay: false,
|
|
@@ -23,6 +30,18 @@ export class PixiVideoTextureHook {
|
|
|
23
30
|
this.#videoTexture = new PIXI.Texture(baseTexture);
|
|
24
31
|
this.#context.setResource('pixiTexture', this.#videoTexture);
|
|
25
32
|
}
|
|
33
|
+
async #handleDestroy() {
|
|
34
|
+
if (this.#videoTexture) {
|
|
35
|
+
// Destroy the texture and its base texture to free GPU memory
|
|
36
|
+
this.#videoTexture.destroy(true);
|
|
37
|
+
this.#videoTexture = undefined;
|
|
38
|
+
this.#context.removeResource('pixiTexture');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async #handleRefresh() {
|
|
42
|
+
await this.#handleDestroy();
|
|
43
|
+
// #handleUpdate will recreate texture on next update call
|
|
44
|
+
}
|
|
26
45
|
async handle(type, context) {
|
|
27
46
|
this.#context = context;
|
|
28
47
|
const data = this.#context.contextData;
|
|
@@ -30,6 +49,9 @@ export class PixiVideoTextureHook {
|
|
|
30
49
|
return;
|
|
31
50
|
}
|
|
32
51
|
this.componentElement = data;
|
|
33
|
-
|
|
52
|
+
const handler = this.#handlers[type];
|
|
53
|
+
if (handler) {
|
|
54
|
+
await handler();
|
|
55
|
+
}
|
|
34
56
|
}
|
|
35
57
|
}
|
|
@@ -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
|
-
|
|
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)) {
|
package/dist/utils/utils.js
CHANGED
|
@@ -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
|
-
|
|
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
|