@vivi2d/web 0.1.0-alpha.0
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/LICENSE +160 -0
- package/README.md +201 -0
- package/dist/CanvasPool-CASccukD.js +48 -0
- package/dist/CanvasPool-CASccukD.js.map +1 -0
- package/dist/CanvasRenderer-BWDoXN0L.js +5750 -0
- package/dist/CanvasRenderer-BWDoXN0L.js.map +1 -0
- package/dist/GpuStencilModesToPixi-c2lsBIrd.js +221 -0
- package/dist/GpuStencilModesToPixi-c2lsBIrd.js.map +1 -0
- package/dist/RenderTargetSystem-BCowAg_f.js +3493 -0
- package/dist/RenderTargetSystem-BCowAg_f.js.map +1 -0
- package/dist/WebGLRenderer-KKZauisz.js +2236 -0
- package/dist/WebGLRenderer-KKZauisz.js.map +1 -0
- package/dist/WebGPURenderer-xmqgPtcF.js +1632 -0
- package/dist/WebGPURenderer-xmqgPtcF.js.map +1 -0
- package/dist/auto-register.d.ts +1 -0
- package/dist/auto-register.js +3 -0
- package/dist/auto-register.js.map +1 -0
- package/dist/browserAll-DQ0eWekj.js +1872 -0
- package/dist/browserAll-DQ0eWekj.js.map +1 -0
- package/dist/canvasUtils-BSaR9Fot.js +210 -0
- package/dist/canvasUtils-BSaR9Fot.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/getTextureBatchBindGroup-BYhXfZM4.js +22 -0
- package/dist/getTextureBatchBindGroup-BYhXfZM4.js.map +1 -0
- package/dist/index-CW8mx7yF.js +18805 -0
- package/dist/index-CW8mx7yF.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/model-loader.d.ts +42 -0
- package/dist/player.d.ts +85 -0
- package/dist/vivi-model-element.d.ts +65 -0
- package/dist/vivi2d.es.js +11 -0
- package/dist/vivi2d.es.js.map +1 -0
- package/dist/vivi2d.umd.js +1020 -0
- package/dist/vivi2d.umd.js.map +1 -0
- package/dist/webworkerAll-oTmmI2Qm.js +694 -0
- package/dist/webworkerAll-oTmmI2Qm.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and
|
|
27
|
+
configuration files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object
|
|
31
|
+
code, generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
36
|
+
below).
|
|
37
|
+
|
|
38
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
39
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
40
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
41
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
42
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
43
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
44
|
+
|
|
45
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
46
|
+
version of the Work and any modifications or additions to that Work or
|
|
47
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
48
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
49
|
+
Entity authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal, or
|
|
51
|
+
written communication sent to the Licensor or its representatives, including
|
|
52
|
+
but not limited to communication on electronic mailing lists, source code
|
|
53
|
+
control systems, and issue tracking systems that are managed by, or on behalf
|
|
54
|
+
of, the Licensor for the purpose of discussing and improving the Work, but
|
|
55
|
+
excluding communication that is conspicuously marked or otherwise designated in
|
|
56
|
+
writing by the copyright owner as "Not a Contribution."
|
|
57
|
+
|
|
58
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
59
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
60
|
+
incorporated within the Work.
|
|
61
|
+
|
|
62
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
63
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
64
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
65
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
66
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
67
|
+
Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
70
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
71
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
72
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
73
|
+
and otherwise transfer the Work, where such license applies only to those
|
|
74
|
+
patent claims licensable by such Contributor that are necessarily infringed by
|
|
75
|
+
their Contribution(s) alone or by combination of their Contribution(s) with the
|
|
76
|
+
Work to which such Contribution(s) was submitted. If You institute patent
|
|
77
|
+
litigation against any entity (including a cross-claim or counterclaim in a
|
|
78
|
+
lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
|
79
|
+
constitutes direct or contributory patent infringement, then any patent
|
|
80
|
+
licenses granted to You under this License for that Work shall terminate as of
|
|
81
|
+
the date such litigation is filed.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
84
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
85
|
+
Source or Object form, provided that You meet the following conditions:
|
|
86
|
+
|
|
87
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
88
|
+
of this License; and
|
|
89
|
+
|
|
90
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
91
|
+
You changed the files; and
|
|
92
|
+
|
|
93
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
94
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
95
|
+
Source form of the Work, excluding those notices that do not pertain to any
|
|
96
|
+
part of the Derivative Works; and
|
|
97
|
+
|
|
98
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
99
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents
|
|
106
|
+
of the NOTICE file are for informational purposes only and do not modify the
|
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
|
110
|
+
modifying the License.
|
|
111
|
+
|
|
112
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
113
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
114
|
+
distribution of Your modifications, or for any such Derivative Works as a
|
|
115
|
+
whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
116
|
+
complies with the conditions stated in this License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
119
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
120
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
121
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
122
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
123
|
+
executed with Licensor regarding such Contributions.
|
|
124
|
+
|
|
125
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
126
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
127
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
128
|
+
reproducing the content of the NOTICE file.
|
|
129
|
+
|
|
130
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
131
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
132
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
133
|
+
KIND, either express or implied, including, without limitation, any warranties
|
|
134
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
135
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
136
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
137
|
+
associated with Your exercise of permissions under this License.
|
|
138
|
+
|
|
139
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
140
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
141
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
142
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
143
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
144
|
+
character arising as a result of this License or out of the use or inability to
|
|
145
|
+
use the Work (including but not limited to damages for loss of goodwill, work
|
|
146
|
+
stoppage, computer failure or malfunction, or any and all other commercial
|
|
147
|
+
damages or losses), even if such Contributor has been advised of the
|
|
148
|
+
possibility of such damages.
|
|
149
|
+
|
|
150
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
151
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
152
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
153
|
+
and/or rights consistent with this License. However, in accepting such
|
|
154
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
155
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
156
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
157
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
158
|
+
accepting any such warranty or additional liability.
|
|
159
|
+
|
|
160
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# @vivi2d/web
|
|
2
|
+
|
|
3
|
+
Experimental browser SDK for embedding Vivi2D public-profile `.vivi` models.
|
|
4
|
+
|
|
5
|
+
## Install / Import
|
|
6
|
+
|
|
7
|
+
Before npm publication, use this package from the Vivi2D repository or from an
|
|
8
|
+
explicit release tarball. After npm publication:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @vivi2d/web@alpha
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Alpha releases are intentionally published under the `alpha` dist-tag, not
|
|
15
|
+
`latest`. Pin an exact version in production experiments if reproducibility
|
|
16
|
+
matters.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { createViviWebPlayer, loadViviWebModel } from "@vivi2d/web";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Minimal Display
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { createViviWebPlayer, loadViviWebModel } from "@vivi2d/web";
|
|
26
|
+
import { formatViviWebError } from "./error-copy";
|
|
27
|
+
|
|
28
|
+
const canvas = document.querySelector<HTMLCanvasElement>("#vivi-canvas");
|
|
29
|
+
const statusElement = document.querySelector<HTMLElement>("#status");
|
|
30
|
+
if (!canvas || !statusElement) throw new Error("Missing sample elements");
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const model = await loadViviWebModel("/generated-avatar.vivi");
|
|
34
|
+
const player = await createViviWebPlayer({
|
|
35
|
+
autoStart: true,
|
|
36
|
+
canvas,
|
|
37
|
+
model,
|
|
38
|
+
});
|
|
39
|
+
void player;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
statusElement.textContent = formatViviWebError(error).message;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The full monorepo example lives at
|
|
46
|
+
`examples/web-sdk-basic/README.md`. It includes ownership, HMR cleanup,
|
|
47
|
+
`AbortController`, stale-load protection, input controls, and error-copy
|
|
48
|
+
helpers. That example is repository content only; it is not packed into the npm
|
|
49
|
+
tarball.
|
|
50
|
+
|
|
51
|
+
## Load From A File Picker
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const input = document.querySelector<HTMLInputElement>('input[type="file"]');
|
|
55
|
+
input?.addEventListener("change", async () => {
|
|
56
|
+
const file = input.files?.[0];
|
|
57
|
+
if (!file) return;
|
|
58
|
+
const model = await loadViviWebModel(file);
|
|
59
|
+
await createViviWebPlayer({ canvas, model });
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Static servers should serve `.vivi` files as normal static assets. A generic
|
|
64
|
+
binary MIME type is acceptable. Cross-origin model loading is the host
|
|
65
|
+
application's responsibility and requires normal CORS headers.
|
|
66
|
+
|
|
67
|
+
## Lifecycle Controls
|
|
68
|
+
|
|
69
|
+
The basic SDK shape is:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
load model -> create player -> start/update/render -> set inputs -> dispose
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`createViviWebPlayer` returns a `Promise<ViviWebPlayer>`. Apps should own one
|
|
76
|
+
current player, abort in-flight loads before replacement, dispose old players,
|
|
77
|
+
and ignore stale async completions after reload or dispose. The sample shows a
|
|
78
|
+
single ownership helper for this pattern.
|
|
79
|
+
|
|
80
|
+
Useful player methods:
|
|
81
|
+
|
|
82
|
+
- `start()` and `stop()` control the automatic frame loop.
|
|
83
|
+
- `update(deltaSeconds)` advances model state with a finite non-negative delta.
|
|
84
|
+
- `render()` draws the current frame.
|
|
85
|
+
- `resize(width, height)` changes the canvas size with positive integer bounds.
|
|
86
|
+
- `dispose()` is idempotent and releases renderer resources.
|
|
87
|
+
|
|
88
|
+
## Drive Inputs
|
|
89
|
+
|
|
90
|
+
Use the public parameter list from the loaded model instead of hard-coding
|
|
91
|
+
semantic parameter names:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
for (const parameter of player.getParameters()) {
|
|
95
|
+
player.setInput(parameter.id, parameter.default);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
player.setInputs({
|
|
99
|
+
[player.getParameters()[0]?.id ?? ""]: 0,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
player.resetInputs();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Unknown input IDs are ignored by default. Pass `strictInputs: true` to
|
|
106
|
+
`createViviWebPlayer` if the host app wants unknown input IDs to throw
|
|
107
|
+
`VIVI_WEB_UNKNOWN_INPUT`.
|
|
108
|
+
|
|
109
|
+
## Handle Errors
|
|
110
|
+
|
|
111
|
+
SDK failures are normalized to `ViviWebError` with stable public codes. Host
|
|
112
|
+
apps should display fixed copy derived from `error.code`; do not render raw
|
|
113
|
+
messages, stack traces, causes, local paths, credentials, URLs, or model
|
|
114
|
+
payload snippets.
|
|
115
|
+
|
|
116
|
+
Common public codes include:
|
|
117
|
+
|
|
118
|
+
- `VIVI_WEB_FETCH_FAILED`
|
|
119
|
+
- `VIVI_WEB_PARSE_FAILED`
|
|
120
|
+
- `VIVI_WEB_VALIDATION_FAILED`
|
|
121
|
+
- `VIVI_WEB_INVALID_INPUT`
|
|
122
|
+
- `VIVI_WEB_UNKNOWN_INPUT`
|
|
123
|
+
- `VIVI_WEB_DISPOSED`
|
|
124
|
+
- `VIVI_WEB_ABORTED`
|
|
125
|
+
|
|
126
|
+
## Custom Element Alternative
|
|
127
|
+
|
|
128
|
+
The root package import is side-effect free. Register the element explicitly:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { defineViviModelElement } from "@vivi2d/web";
|
|
132
|
+
|
|
133
|
+
defineViviModelElement();
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```html
|
|
137
|
+
<vivi-model src="./character.vivi" width="320" height="480" autoplay></vivi-model>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
If you want import-time registration for a browser page, use the explicit
|
|
141
|
+
side-effect entry point:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import "@vivi2d/web/auto-register";
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The repository-local `packages/web/demo.html` remains the custom-element demo.
|
|
148
|
+
Open it through the repository dev server, not as a standalone `file://` page.
|
|
149
|
+
|
|
150
|
+
## Experimental Status And Compatibility
|
|
151
|
+
|
|
152
|
+
This package is pre-1.0 and marked as experimental. The custom element name,
|
|
153
|
+
methods, events, and file-format behavior may change before the first stable
|
|
154
|
+
release.
|
|
155
|
+
|
|
156
|
+
The guidance above is stable for the current Web SDK shape only. It does not
|
|
157
|
+
promise native runtime ABI stability, official WASM binary stability, Unity SDK
|
|
158
|
+
stability, or long-term low-level renderer internals.
|
|
159
|
+
|
|
160
|
+
Browser assumptions:
|
|
161
|
+
|
|
162
|
+
- Modern evergreen browser.
|
|
163
|
+
- ES2020-compatible runtime.
|
|
164
|
+
- WebGL-capable `HTMLCanvasElement`.
|
|
165
|
+
- Keyboard and pointer interaction for sliders and controls.
|
|
166
|
+
|
|
167
|
+
## API Reference
|
|
168
|
+
|
|
169
|
+
Primary root exports:
|
|
170
|
+
|
|
171
|
+
- `loadViviWebModel(source, options?)`
|
|
172
|
+
- `createViviWebPlayer(options)`
|
|
173
|
+
- `isViviWebError(error)`
|
|
174
|
+
- `ViviWebError`
|
|
175
|
+
- `ViviWebErrorCode`
|
|
176
|
+
- `ViviWebModel`
|
|
177
|
+
- `ViviWebPlayer`
|
|
178
|
+
- `defineViviModelElement(tagName?)`
|
|
179
|
+
- `ViviModelElement`
|
|
180
|
+
|
|
181
|
+
`loadViviWebModel` accepts public `.vivi` sources, deep-clones object input,
|
|
182
|
+
rejects private/authoring-only profiles, and returns an opaque `ViviWebModel`
|
|
183
|
+
that external code cannot construct.
|
|
184
|
+
|
|
185
|
+
Phase 1 targets `HTMLCanvasElement`. Worker-side `OffscreenCanvas` rendering is
|
|
186
|
+
reserved for a later SDK phase.
|
|
187
|
+
|
|
188
|
+
Thumbnails are bounded to 1,048,576 pixels and 2 MiB of data URL output. Apps
|
|
189
|
+
with custom frame loops can pass a `scheduler` to `createViviWebPlayer` for
|
|
190
|
+
deterministic tests or non-standard browser environments.
|
|
191
|
+
|
|
192
|
+
## Security And Privacy
|
|
193
|
+
|
|
194
|
+
- No telemetry or remote upload is enabled by default.
|
|
195
|
+
- `.vivi` files are fetched only from sources provided by the host app.
|
|
196
|
+
- The package is built as a browser-facing bundle and does not expose internal
|
|
197
|
+
workspace packages as public npm dependencies.
|
|
198
|
+
- Runtime browser dependencies such as Pixi are bundled into the release files.
|
|
199
|
+
If this changes, the package must move the dependency into `dependencies` or
|
|
200
|
+
`peerDependencies`, update the tarball review, and refresh notices/SBOM
|
|
201
|
+
records before publication.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { D as n, aj as c, o as r } from "./index-CW8mx7yF.js";
|
|
2
|
+
class l {
|
|
3
|
+
constructor(a) {
|
|
4
|
+
this._canvasPool = /* @__PURE__ */ Object.create(null), this.canvasOptions = a || {}, this.enableFullScreen = !1;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates texture with params that were specified in pool constructor.
|
|
8
|
+
* @param pixelWidth - Width of texture in pixels.
|
|
9
|
+
* @param pixelHeight - Height of texture in pixels.
|
|
10
|
+
*/
|
|
11
|
+
_createCanvasAndContext(a, s) {
|
|
12
|
+
const t = n.get().createCanvas();
|
|
13
|
+
t.width = a, t.height = s;
|
|
14
|
+
const e = t.getContext("2d");
|
|
15
|
+
return { canvas: t, context: e };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets a Power-of-Two render texture or fullScreen texture
|
|
19
|
+
* @param minWidth - The minimum width of the render texture.
|
|
20
|
+
* @param minHeight - The minimum height of the render texture.
|
|
21
|
+
* @param resolution - The resolution of the render texture.
|
|
22
|
+
* @returns The new render texture.
|
|
23
|
+
*/
|
|
24
|
+
getOptimalCanvasAndContext(a, s, t = 1) {
|
|
25
|
+
a = Math.ceil(a * t - 1e-6), s = Math.ceil(s * t - 1e-6), a = c(a), s = c(s);
|
|
26
|
+
const e = (a << 17) + (s << 1);
|
|
27
|
+
this._canvasPool[e] || (this._canvasPool[e] = []);
|
|
28
|
+
let o = this._canvasPool[e].pop();
|
|
29
|
+
return o || (o = this._createCanvasAndContext(a, s)), o;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Place a render texture back into the pool.
|
|
33
|
+
* @param canvasAndContext
|
|
34
|
+
*/
|
|
35
|
+
returnCanvasAndContext(a) {
|
|
36
|
+
const s = a.canvas, { width: t, height: e } = s, o = (t << 17) + (e << 1);
|
|
37
|
+
a.context.resetTransform(), a.context.clearRect(0, 0, t, e), this._canvasPool[o].push(a);
|
|
38
|
+
}
|
|
39
|
+
clear() {
|
|
40
|
+
this._canvasPool = {};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const v = new l();
|
|
44
|
+
r.register(v);
|
|
45
|
+
export {
|
|
46
|
+
v as C
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=CanvasPool-CASccukD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasPool-CASccukD.js","sources":["../../../node_modules/pixi.js/lib/rendering/renderers/shared/texture/CanvasPool.mjs"],"sourcesContent":["import { DOMAdapter } from '../../../../environment/adapter.mjs';\nimport { nextPow2 } from '../../../../maths/misc/pow2.mjs';\nimport { GlobalResourceRegistry } from '../../../../utils/pool/GlobalResourceRegistry.mjs';\n\n\"use strict\";\nclass CanvasPoolClass {\n constructor(canvasOptions) {\n this._canvasPool = /* @__PURE__ */ Object.create(null);\n this.canvasOptions = canvasOptions || {};\n this.enableFullScreen = false;\n }\n /**\n * Creates texture with params that were specified in pool constructor.\n * @param pixelWidth - Width of texture in pixels.\n * @param pixelHeight - Height of texture in pixels.\n */\n _createCanvasAndContext(pixelWidth, pixelHeight) {\n const canvas = DOMAdapter.get().createCanvas();\n canvas.width = pixelWidth;\n canvas.height = pixelHeight;\n const context = canvas.getContext(\"2d\");\n return { canvas, context };\n }\n /**\n * Gets a Power-of-Two render texture or fullScreen texture\n * @param minWidth - The minimum width of the render texture.\n * @param minHeight - The minimum height of the render texture.\n * @param resolution - The resolution of the render texture.\n * @returns The new render texture.\n */\n getOptimalCanvasAndContext(minWidth, minHeight, resolution = 1) {\n minWidth = Math.ceil(minWidth * resolution - 1e-6);\n minHeight = Math.ceil(minHeight * resolution - 1e-6);\n minWidth = nextPow2(minWidth);\n minHeight = nextPow2(minHeight);\n const key = (minWidth << 17) + (minHeight << 1);\n if (!this._canvasPool[key]) {\n this._canvasPool[key] = [];\n }\n let canvasAndContext = this._canvasPool[key].pop();\n if (!canvasAndContext) {\n canvasAndContext = this._createCanvasAndContext(minWidth, minHeight);\n }\n return canvasAndContext;\n }\n /**\n * Place a render texture back into the pool.\n * @param canvasAndContext\n */\n returnCanvasAndContext(canvasAndContext) {\n const canvas = canvasAndContext.canvas;\n const { width, height } = canvas;\n const key = (width << 17) + (height << 1);\n canvasAndContext.context.resetTransform();\n canvasAndContext.context.clearRect(0, 0, width, height);\n this._canvasPool[key].push(canvasAndContext);\n }\n clear() {\n this._canvasPool = {};\n }\n}\nconst CanvasPool = new CanvasPoolClass();\nGlobalResourceRegistry.register(CanvasPool);\n\nexport { CanvasPool, CanvasPoolClass };\n//# sourceMappingURL=CanvasPool.mjs.map\n"],"names":["CanvasPoolClass","canvasOptions","pixelWidth","pixelHeight","canvas","DOMAdapter","context","minWidth","minHeight","resolution","nextPow2","key","canvasAndContext","width","height","CanvasPool","GlobalResourceRegistry"],"mappings":";AAKA,MAAMA,EAAgB;AAAA,EACpB,YAAYC,GAAe;AACzB,SAAK,cAA8B,uBAAO,OAAO,IAAI,GACrD,KAAK,gBAAgBA,KAAiB,CAAA,GACtC,KAAK,mBAAmB;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,wBAAwBC,GAAYC,GAAa;AAC/C,UAAMC,IAASC,EAAW,IAAG,EAAG,aAAY;AAC5C,IAAAD,EAAO,QAAQF,GACfE,EAAO,SAASD;AAChB,UAAMG,IAAUF,EAAO,WAAW,IAAI;AACtC,WAAO,EAAE,QAAAA,GAAQ,SAAAE,EAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,2BAA2BC,GAAUC,GAAWC,IAAa,GAAG;AAC9D,IAAAF,IAAW,KAAK,KAAKA,IAAWE,IAAa,IAAI,GACjDD,IAAY,KAAK,KAAKA,IAAYC,IAAa,IAAI,GACnDF,IAAWG,EAASH,CAAQ,GAC5BC,IAAYE,EAASF,CAAS;AAC9B,UAAMG,KAAOJ,KAAY,OAAOC,KAAa;AAC7C,IAAK,KAAK,YAAYG,CAAG,MACvB,KAAK,YAAYA,CAAG,IAAI,CAAA;AAE1B,QAAIC,IAAmB,KAAK,YAAYD,CAAG,EAAE,IAAG;AAChD,WAAKC,MACHA,IAAmB,KAAK,wBAAwBL,GAAUC,CAAS,IAE9DI;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,uBAAuBA,GAAkB;AACvC,UAAMR,IAASQ,EAAiB,QAC1B,EAAE,OAAAC,GAAO,QAAAC,EAAM,IAAKV,GACpBO,KAAOE,KAAS,OAAOC,KAAU;AACvC,IAAAF,EAAiB,QAAQ,eAAc,GACvCA,EAAiB,QAAQ,UAAU,GAAG,GAAGC,GAAOC,CAAM,GACtD,KAAK,YAAYH,CAAG,EAAE,KAAKC,CAAgB;AAAA,EAC7C;AAAA,EACA,QAAQ;AACN,SAAK,cAAc,CAAA;AAAA,EACrB;AACF;AACK,MAACG,IAAa,IAAIf,EAAe;AACtCgB,EAAuB,SAASD,CAAU;","x_google_ignoreList":[0]}
|