visualfries 0.1.101 → 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.
@@ -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
- throw new Error('videoElement not found in resources.');
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
- this.#displayObject.removeChildren();
191
- this.#initDisplayObject();
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
- throw new Error('videoElement not found in resources.');
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
- return await this.#handleUpdate();
52
+ const handler = this.#handlers[type];
53
+ if (handler) {
54
+ await handler();
55
+ }
34
56
  }
35
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "visualfries",
3
- "version": "0.1.101",
3
+ "version": "0.1.102",
4
4
  "license": "MIT",
5
5
  "author": "ContentFries",
6
6
  "repository": {