@vmz/plugin-live2d 0.0.17 → 0.0.19

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.
@@ -1,96 +1,96 @@
1
- <template>
2
- <div class="live2d-stage" id={hostId}></div>
3
- </template>
4
-
5
- <style>
6
- .live2d-stage {
7
- position: relative;
8
- width: 100%;
9
- min-height: 320px;
10
- height: 100%;
11
- background: color-mix(in srgb, var(--vmz-surface-page, #f5f9fc) 88%, #fff);
12
- border: 1px solid var(--vmz-line-default, rgba(0, 0, 0, 0.08));
13
- border-radius: 0.5rem;
14
- overflow: hidden;
15
- }
16
-
17
- .live2d-stage canvas {
18
- display: block;
19
- width: 100%;
20
- height: 100%;
21
- }
22
- </style>
23
-
24
- <script client>
25
- import { createLive2dStage } from '@doki-land/live2d';
26
-
27
- let stageSeq = 0;
28
-
29
- export default class Live2dStage {
30
- /** Append-only model sources; new entries spawn actors on the stage. */
31
- public sources = [];
32
- public updateMode = 'auto';
33
- public prefer = ['canvas2d', 'webgl2', 'webgpu'];
34
-
35
- hostId = `live2d-stage-${++stageSeq}`;
36
- stage = null;
37
- _canvas = null;
38
- _applied = 0;
39
- _syncTimer = 0;
40
-
41
- onMount() {
42
- void this.boot();
43
- this._syncTimer = window.setInterval(() => this.syncSources(), 150);
44
- }
45
-
46
- onDestroy() {
47
- if (this._syncTimer) clearInterval(this._syncTimer);
48
- this._syncTimer = 0;
49
- void this.stage?.destroy?.();
50
- this.stage = null;
51
- this._canvas = null;
52
- }
53
-
54
- ensureCanvas(host) {
55
- host.replaceChildren();
56
- const canvas = document.createElement('canvas');
57
- const rect = host.getBoundingClientRect();
58
- const w = Math.max(320, Math.round(rect.width || 640));
59
- const h = Math.max(320, Math.round(rect.height || 480));
60
- const dpr = Math.min(window.devicePixelRatio || 1, 2);
61
- canvas.width = Math.max(1, Math.round(w * dpr));
62
- canvas.height = Math.max(1, Math.round(h * dpr));
63
- canvas.style.width = '100%';
64
- canvas.style.height = '100%';
65
- host.appendChild(canvas);
66
- this._canvas = canvas;
67
- return canvas;
68
- }
69
-
70
- async boot() {
71
- const host = document.getElementById(this.hostId);
72
- if (!host) return;
73
- const canvas = this.ensureCanvas(host);
74
- const stage = createLive2dStage({ updateMode: this.updateMode, prefer: this.prefer });
75
- await stage.mount(canvas);
76
- this.stage = stage;
77
- await this.syncSources();
78
- }
79
-
80
- async syncSources() {
81
- if (!this.stage) return;
82
- const list = Array.isArray(this.sources) ? this.sources : [];
83
- while (this._applied < list.length) {
84
- const src = list[this._applied];
85
- this._applied += 1;
86
- if (!src) continue;
87
- try {
88
- const actor = this.stage.createActor();
89
- await actor.load(src);
90
- } catch {
91
- /* skip failed actor; keep stage usable */
92
- }
93
- }
94
- }
95
- }
96
- </script>
1
+ <template>
2
+ <div class="live2d-stage" id={hostId}></div>
3
+ </template>
4
+
5
+ <style>
6
+ .live2d-stage {
7
+ position: relative;
8
+ width: 100%;
9
+ min-height: 320px;
10
+ height: 100%;
11
+ background: color-mix(in srgb, var(--vmz-surface-page, #f5f9fc) 88%, #fff);
12
+ border: 1px solid var(--vmz-line-default, rgba(0, 0, 0, 0.08));
13
+ border-radius: 0.5rem;
14
+ overflow: hidden;
15
+ }
16
+
17
+ .live2d-stage canvas {
18
+ display: block;
19
+ width: 100%;
20
+ height: 100%;
21
+ }
22
+ </style>
23
+
24
+ <script client>
25
+ import { createLive2dStage } from '@doki-land/live2d';
26
+
27
+ let stageSeq = 0;
28
+
29
+ export default class Live2dStage {
30
+ /** Append-only model sources; new entries spawn actors on the stage. */
31
+ public sources = [];
32
+ public updateMode = 'auto';
33
+ public prefer = ['canvas2d', 'webgl2', 'webgpu'];
34
+
35
+ hostId = `live2d-stage-${++stageSeq}`;
36
+ stage = null;
37
+ _canvas = null;
38
+ _applied = 0;
39
+ _syncTimer = 0;
40
+
41
+ onMount() {
42
+ void this.boot();
43
+ this._syncTimer = window.setInterval(() => this.syncSources(), 150);
44
+ }
45
+
46
+ onDestroy() {
47
+ if (this._syncTimer) clearInterval(this._syncTimer);
48
+ this._syncTimer = 0;
49
+ void this.stage?.destroy?.();
50
+ this.stage = null;
51
+ this._canvas = null;
52
+ }
53
+
54
+ ensureCanvas(host) {
55
+ host.replaceChildren();
56
+ const canvas = document.createElement('canvas');
57
+ const rect = host.getBoundingClientRect();
58
+ const w = Math.max(320, Math.round(rect.width || 640));
59
+ const h = Math.max(320, Math.round(rect.height || 480));
60
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
61
+ canvas.width = Math.max(1, Math.round(w * dpr));
62
+ canvas.height = Math.max(1, Math.round(h * dpr));
63
+ canvas.style.width = '100%';
64
+ canvas.style.height = '100%';
65
+ host.appendChild(canvas);
66
+ this._canvas = canvas;
67
+ return canvas;
68
+ }
69
+
70
+ async boot() {
71
+ const host = document.getElementById(this.hostId);
72
+ if (!host) return;
73
+ const canvas = this.ensureCanvas(host);
74
+ const stage = createLive2dStage({ updateMode: this.updateMode, prefer: this.prefer });
75
+ await stage.mount(canvas);
76
+ this.stage = stage;
77
+ await this.syncSources();
78
+ }
79
+
80
+ async syncSources() {
81
+ if (!this.stage) return;
82
+ const list = Array.isArray(this.sources) ? this.sources : [];
83
+ while (this._applied < list.length) {
84
+ const src = list[this._applied];
85
+ this._applied += 1;
86
+ if (!src) continue;
87
+ try {
88
+ const actor = this.stage.createActor();
89
+ await actor.load(src);
90
+ } catch {
91
+ /* skip failed actor; keep stage usable */
92
+ }
93
+ }
94
+ }
95
+ }
96
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vmz/plugin-live2d",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "VMZ Live2D adapter — <Live2dHost> for @doki-land/live2d in VMZ applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "test": "vitest run --passWithNoTests"
37
37
  },
38
38
  "dependencies": {
39
- "@doki-land/live2d": "0.0.17",
39
+ "@doki-land/live2d": "0.0.19",
40
40
  "@vmz/plugin": "^0.1.8"
41
41
  }
42
42
  }