modern-canvas 0.0.2 → 0.0.3
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/README.md +39 -9
- package/dist/index.cjs +8 -39
- package/dist/index.js +8 -39
- package/dist/index.mjs +477 -502
- package/package.json +1 -1
- package/types/app.d.ts +63 -0
- package/types/container.d.ts +0 -1
- package/types/create-app.d.ts +3 -0
- package/types/index.d.ts +3 -1
- package/types/material.d.ts +8 -10
- package/types/node.d.ts +0 -6
- package/types/options.d.ts +7 -0
- package/types/plugin.d.ts +2 -4
- package/types/plugins/index.d.ts +1 -7
- package/types/plugins/renderer2d.d.ts +1 -0
- package/types/query.d.ts +4 -0
- package/types/render.d.ts +13 -2
- package/types/setup.d.ts +2 -0
- package/types/shape.d.ts +6 -8
- package/types/system.d.ts +5 -0
- package/types/texture.d.ts +7 -0
- package/types/utils.d.ts +11 -0
- package/types/canvas.d.ts +0 -42
- package/types/gl.d.ts +0 -20
- package/types/node-renderer.d.ts +0 -18
- package/types/plugins/base.d.ts +0 -1
- package/types/plugins/fade.d.ts +0 -1
- package/types/plugins/node-image.d.ts +0 -1
- package/types/plugins/node-text.d.ts +0 -1
- package/types/plugins/selector2d.d.ts +0 -1
- package/types/plugins/transform2d.d.ts +0 -1
- package/types/resource.d.ts +0 -10
- package/types/utils/index.d.ts +0 -1
- package/types/utils/matrix3.d.ts +0 -7
package/dist/index.mjs
CHANGED
|
@@ -1,120 +1,9 @@
|
|
|
1
|
-
function
|
|
1
|
+
function w(o) {
|
|
2
2
|
return typeof o == "function" ? o() : o;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
name: "canvas:base",
|
|
6
|
-
register(o) {
|
|
7
|
-
o.registerShape({
|
|
8
|
-
name: "rectangle",
|
|
9
|
-
type: "2d",
|
|
10
|
-
mode: "triangles",
|
|
11
|
-
data: new Float32Array([
|
|
12
|
-
-1,
|
|
13
|
-
1,
|
|
14
|
-
-1,
|
|
15
|
-
-1,
|
|
16
|
-
1,
|
|
17
|
-
-1,
|
|
18
|
-
1,
|
|
19
|
-
-1,
|
|
20
|
-
1,
|
|
21
|
-
1,
|
|
22
|
-
-1,
|
|
23
|
-
1
|
|
24
|
-
])
|
|
25
|
-
}), o.registerMaterial({
|
|
26
|
-
name: "baseMaterial",
|
|
27
|
-
vertexShader: `attribute vec2 aPosition;
|
|
28
|
-
varying vec2 vTextureCoord;
|
|
29
|
-
void main() {
|
|
30
|
-
vTextureCoord = step(0.0, aPosition);
|
|
31
|
-
gl_Position = vec4(aPosition, 0, 1);
|
|
32
|
-
}`,
|
|
33
|
-
fragmentShader: `uniform sampler2D uSampler;
|
|
34
|
-
varying vec2 vTextureCoord;
|
|
35
|
-
void main() {
|
|
36
|
-
gl_FragColor = texture2D(uSampler, vTextureCoord);
|
|
37
|
-
}`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
})), D = v(() => ({
|
|
41
|
-
name: "canvas:node-image",
|
|
42
|
-
register(o) {
|
|
43
|
-
o.registerNodeRenderer({
|
|
44
|
-
name: "image",
|
|
45
|
-
include: (r) => Boolean(r.image),
|
|
46
|
-
shape: "rectangle",
|
|
47
|
-
material: "baseMaterial",
|
|
48
|
-
update(r) {
|
|
49
|
-
if (!o.resources.has(r.image)) {
|
|
50
|
-
const e = new Image();
|
|
51
|
-
e.src = r.image, o.registerResource({
|
|
52
|
-
name: r.image,
|
|
53
|
-
data: e
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
uSampler: r.image
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
})), N = v(() => {
|
|
63
|
-
const o = document.createElement("canvas").getContext("2d");
|
|
64
|
-
return {
|
|
65
|
-
name: "canvas:node-text",
|
|
66
|
-
register(r) {
|
|
67
|
-
r.registerNodeRenderer({
|
|
68
|
-
name: "text",
|
|
69
|
-
include: (e) => Boolean(e.text),
|
|
70
|
-
shape: "rectangle",
|
|
71
|
-
material: "baseMaterial",
|
|
72
|
-
update(e) {
|
|
73
|
-
const { width: a = 100, height: t = 100, text: c } = e;
|
|
74
|
-
return r.resources.has(c) || (o.canvas.width = a, o.canvas.height = t, o.font = "20px monospace", o.textAlign = "center", o.textBaseline = "middle", o.fillStyle = "black", o.clearRect(0, 0, o.canvas.width, o.canvas.height), o.fillText(c, a / 2, t / 2), r.registerResource({
|
|
75
|
-
name: c,
|
|
76
|
-
data: o.canvas
|
|
77
|
-
})), {
|
|
78
|
-
uSampler: e.text
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}), F = v(() => ({
|
|
85
|
-
name: "canvas:fade",
|
|
86
|
-
register(o) {
|
|
87
|
-
o.registerNodeRenderer({
|
|
88
|
-
name: "fade",
|
|
89
|
-
include: (r) => Boolean(r.fade),
|
|
90
|
-
shape: "rectangle",
|
|
91
|
-
material: {
|
|
92
|
-
vertexShader: `attribute vec2 aPosition;
|
|
93
|
-
varying vec2 vTextureCoord;
|
|
94
|
-
void main() {
|
|
95
|
-
vTextureCoord = step(0.0, aPosition);
|
|
96
|
-
gl_Position = vec4(aPosition, 0, 1);
|
|
97
|
-
}`,
|
|
98
|
-
fragmentShader: `uniform sampler2D uSampler;
|
|
99
|
-
varying vec2 vTextureCoord;
|
|
100
|
-
uniform float uTime;
|
|
101
|
-
float linear(float time, float offset, float change, float duration) {
|
|
102
|
-
return change * (time / duration) + offset;
|
|
103
|
-
}
|
|
104
|
-
void main(void) {
|
|
105
|
-
vec4 color = texture2D(uSampler, vTextureCoord);
|
|
106
|
-
gl_FragColor = vec4(color.rgb, linear(uTime, 0.0, 1.0, 3.0));
|
|
107
|
-
}`
|
|
108
|
-
},
|
|
109
|
-
update: (r, e) => ({
|
|
110
|
-
uTime: e
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}));
|
|
115
|
-
class _ extends Float32Array {
|
|
4
|
+
class x extends Float32Array {
|
|
116
5
|
static identity() {
|
|
117
|
-
return new
|
|
6
|
+
return new x([
|
|
118
7
|
1,
|
|
119
8
|
0,
|
|
120
9
|
0,
|
|
@@ -126,8 +15,8 @@ class _ extends Float32Array {
|
|
|
126
15
|
1
|
|
127
16
|
]);
|
|
128
17
|
}
|
|
129
|
-
static translation(r,
|
|
130
|
-
return new
|
|
18
|
+
static translation(r, c) {
|
|
19
|
+
return new x([
|
|
131
20
|
1,
|
|
132
21
|
0,
|
|
133
22
|
0,
|
|
@@ -135,31 +24,31 @@ class _ extends Float32Array {
|
|
|
135
24
|
1,
|
|
136
25
|
0,
|
|
137
26
|
r,
|
|
138
|
-
|
|
27
|
+
c,
|
|
139
28
|
1
|
|
140
29
|
]);
|
|
141
30
|
}
|
|
142
31
|
static rotation(r) {
|
|
143
|
-
const
|
|
144
|
-
return new
|
|
145
|
-
|
|
146
|
-
-
|
|
32
|
+
const c = Math.cos(r), t = Math.sin(r);
|
|
33
|
+
return new x([
|
|
34
|
+
c,
|
|
35
|
+
-t,
|
|
147
36
|
0,
|
|
148
|
-
|
|
149
|
-
|
|
37
|
+
t,
|
|
38
|
+
c,
|
|
150
39
|
0,
|
|
151
40
|
0,
|
|
152
41
|
0,
|
|
153
42
|
1
|
|
154
43
|
]);
|
|
155
44
|
}
|
|
156
|
-
static scaling(r,
|
|
157
|
-
return new
|
|
45
|
+
static scaling(r, c) {
|
|
46
|
+
return new x([
|
|
158
47
|
r,
|
|
159
48
|
0,
|
|
160
49
|
0,
|
|
161
50
|
0,
|
|
162
|
-
|
|
51
|
+
c,
|
|
163
52
|
0,
|
|
164
53
|
0,
|
|
165
54
|
0,
|
|
@@ -167,91 +56,97 @@ class _ extends Float32Array {
|
|
|
167
56
|
]);
|
|
168
57
|
}
|
|
169
58
|
multiply(r) {
|
|
170
|
-
const
|
|
171
|
-
return this[0] =
|
|
59
|
+
const c = this[0], t = this[1], n = this[2], d = this[3], m = this[4], a = this[5], s = this[6], e = this[7], i = this[8], u = r[0], f = r[1], h = r[2], E = r[3], T = r[4], l = r[5], g = r[6], R = r[7], A = r[8];
|
|
60
|
+
return this[0] = u * c + f * d + h * s, this[1] = u * t + f * m + h * e, this[2] = u * n + f * a + h * i, this[3] = E * c + T * d + l * s, this[4] = E * t + T * m + l * e, this[5] = E * n + T * a + l * i, this[6] = g * c + R * d + A * s, this[7] = g * t + R * m + A * e, this[8] = g * n + R * a + A * i, this;
|
|
172
61
|
}
|
|
173
62
|
}
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
const s = new Uint8Array(4);
|
|
236
|
-
t.readPixels(o.x, a - o.y, 1, 1, t.RGBA, t.UNSIGNED_BYTE, s);
|
|
237
|
-
const n = l[(s[0] << 16) + (s[1] << 8) + s[2]];
|
|
238
|
-
if (((R = r.get("hoveredPath")) == null ? void 0 : R.join("")) === (n == null ? void 0 : n.join("")))
|
|
239
|
-
return;
|
|
240
|
-
let f;
|
|
241
|
-
n && (f = { children: c }, n.forEach((T) => {
|
|
242
|
-
var d;
|
|
243
|
-
return f = (d = f.children) == null ? void 0 : d[T];
|
|
244
|
-
})), r.set("hovered", f), r.set("hoveredPath", n), f && ((g = r.get("onHover")) == null || g(f, n));
|
|
63
|
+
function P(o) {
|
|
64
|
+
const r = [];
|
|
65
|
+
for (let c = o.length, t = 0; t < c; t++) {
|
|
66
|
+
const n = o[t], d = ~~(n / 16);
|
|
67
|
+
for (let m = 0; m <= d; m++)
|
|
68
|
+
m in r || (r[m] = 0);
|
|
69
|
+
r[d] |= 1 << n % 16;
|
|
70
|
+
}
|
|
71
|
+
return r;
|
|
72
|
+
}
|
|
73
|
+
function B(o) {
|
|
74
|
+
const r = document.createElement("video");
|
|
75
|
+
return r.playsInline = !0, r.muted = !0, r.loop = !0, r.src = o, r;
|
|
76
|
+
}
|
|
77
|
+
function O(o) {
|
|
78
|
+
const r = new Image();
|
|
79
|
+
return r.decoding = "sync", r.loading = "eager", r.crossOrigin = "anonymous", r.src = o, r;
|
|
80
|
+
}
|
|
81
|
+
let b;
|
|
82
|
+
const y = /* @__PURE__ */ new Map();
|
|
83
|
+
function X() {
|
|
84
|
+
var o;
|
|
85
|
+
return b || (b = document.createElement("iframe"), b.id = `__SANDBOX__${Math.random()}`, b.width = "0", b.height = "0", b.style.visibility = "hidden", b.style.position = "fixed", document.body.appendChild(b), (o = b.contentWindow) == null || o.document.write('<!DOCTYPE html><meta charset="UTF-8"><title></title><body>')), b;
|
|
86
|
+
}
|
|
87
|
+
function U(o) {
|
|
88
|
+
switch (!0) {
|
|
89
|
+
case (o.startsWith("#") && o.length === 7):
|
|
90
|
+
return o = o.substring(1), [
|
|
91
|
+
parseInt(`${o[0]}${o[1]}`, 16) / 255,
|
|
92
|
+
parseInt(`${o[2]}${o[3]}`, 16) / 255,
|
|
93
|
+
parseInt(`${o[4]}${o[5]}`, 16) / 255,
|
|
94
|
+
1
|
|
95
|
+
];
|
|
96
|
+
case (o.startsWith("#") && o.length === 9):
|
|
97
|
+
return o = o.substring(1), [
|
|
98
|
+
parseInt(`${o[0]}${o[1]}`, 16) / 255,
|
|
99
|
+
parseInt(`${o[2]}${o[3]}`, 16) / 255,
|
|
100
|
+
parseInt(`${o[4]}${o[5]}`, 16) / 255,
|
|
101
|
+
parseInt(`${o[6]}${o[7]}`, 16) / 255
|
|
102
|
+
];
|
|
103
|
+
case o.startsWith("rgb("):
|
|
104
|
+
return [
|
|
105
|
+
...o.replace(/rgb\((.+?)\)/, "$1").split(",").slice(0, 3).map((r) => Number(r.trim()) / 255),
|
|
106
|
+
1
|
|
107
|
+
];
|
|
108
|
+
case o.startsWith("rgba("):
|
|
109
|
+
return o.replace(/rgba\((.+?)\)/, "$1").split(",").slice(0, 4).map((r) => Number(r.trim()) / 255);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function G(o, r = [0, 0, 0, 0]) {
|
|
113
|
+
if (y.has(o))
|
|
114
|
+
return y.get(o);
|
|
115
|
+
let c = U(o);
|
|
116
|
+
if (!c) {
|
|
117
|
+
const t = X();
|
|
118
|
+
if (t) {
|
|
119
|
+
const n = t.contentWindow;
|
|
120
|
+
if (n) {
|
|
121
|
+
const d = n.document, m = d.createElement("div");
|
|
122
|
+
d.body.appendChild(m), m.textContent = " ", m.style.color = o, c = U(n.getComputedStyle(m).color), d.body.removeChild(m);
|
|
123
|
+
}
|
|
245
124
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
125
|
+
}
|
|
126
|
+
return c && y.set(o, c), c ?? r;
|
|
127
|
+
}
|
|
128
|
+
const j = w({
|
|
129
|
+
name: "renderer2d",
|
|
249
130
|
register(o) {
|
|
250
|
-
o.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
131
|
+
o.registerShape("rectangle", {
|
|
132
|
+
type: "2d",
|
|
133
|
+
mode: "triangles",
|
|
134
|
+
buffer: new Float32Array([
|
|
135
|
+
-1,
|
|
136
|
+
1,
|
|
137
|
+
-1,
|
|
138
|
+
-1,
|
|
139
|
+
1,
|
|
140
|
+
-1,
|
|
141
|
+
1,
|
|
142
|
+
-1,
|
|
143
|
+
1,
|
|
144
|
+
1,
|
|
145
|
+
-1,
|
|
146
|
+
1
|
|
147
|
+
])
|
|
148
|
+
}), o.registerMaterial("material2d", {
|
|
149
|
+
vertexShader: `attribute vec2 aPosition;
|
|
255
150
|
varying vec2 vTextureCoord;
|
|
256
151
|
uniform mat3 uModelMatrix;
|
|
257
152
|
void main() {
|
|
@@ -259,262 +154,422 @@ void main() {
|
|
|
259
154
|
vec2 position = aPosition;
|
|
260
155
|
gl_Position = vec4((uModelMatrix * vec3(position, 1)).xy, 0, 1);
|
|
261
156
|
}`,
|
|
262
|
-
|
|
157
|
+
fragmentShader: `uniform sampler2D uSampler;
|
|
263
158
|
varying vec2 vTextureCoord;
|
|
159
|
+
uniform vec4 uBackgroundColor;
|
|
264
160
|
void main() {
|
|
265
|
-
|
|
161
|
+
vec4 color = texture2D(uSampler, vTextureCoord);
|
|
162
|
+
gl_FragColor = mix(uBackgroundColor, color, color.a);
|
|
266
163
|
}`
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
164
|
+
});
|
|
165
|
+
const r = document.createElement("canvas").getContext("2d");
|
|
166
|
+
o.registerSystem({
|
|
167
|
+
update(c = 0) {
|
|
168
|
+
var d;
|
|
169
|
+
const { textures: t } = o, n = o.query("type");
|
|
170
|
+
for (let m = n.length, a = 0; a < m; a++) {
|
|
171
|
+
const s = n[a], { type: e } = s;
|
|
172
|
+
if (e === "image" && s.src)
|
|
173
|
+
t.has(s.id) || o.registerTexture(s.id, O(s.src));
|
|
174
|
+
else if (e === "video")
|
|
175
|
+
if (!t.has(s.id))
|
|
176
|
+
o.registerTexture(s.id, B(s.src));
|
|
177
|
+
else {
|
|
178
|
+
const i = (d = t.get(s.id)) == null ? void 0 : d.source;
|
|
179
|
+
i.duration && (i.currentTime = c % i.duration);
|
|
180
|
+
}
|
|
181
|
+
else if (e === "text") {
|
|
182
|
+
const {
|
|
183
|
+
width: i,
|
|
184
|
+
height: u,
|
|
185
|
+
color: f = "black",
|
|
186
|
+
fontSize: h = 14,
|
|
187
|
+
fontWeight: E = 400,
|
|
188
|
+
direction: T = "inherit",
|
|
189
|
+
fontFamily: l = "monospace",
|
|
190
|
+
fontKerning: g = "normal",
|
|
191
|
+
textAlign: R = "center",
|
|
192
|
+
textBaseline: A = "middle"
|
|
193
|
+
} = s.style ?? {};
|
|
194
|
+
if (!t.has(s.id)) {
|
|
195
|
+
const _ = `${E} ${h}px ${l}`;
|
|
196
|
+
r.font = _;
|
|
197
|
+
const p = r.measureText(s.content), I = u ?? p.actualBoundingBoxAscent + p.actualBoundingBoxDescent, v = i ?? p.width;
|
|
198
|
+
s.style.width = v, s.style.height = I, r.canvas.width = v, r.canvas.height = I, r.fillStyle = f, r.direction = T, r.font = _, r.fontKerning = g, r.textAlign = R, r.textBaseline = A, r.clearRect(0, 0, v, I), r.fillText(s.content, v / 2, I / 2), o.registerTexture(s.id, r.canvas);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}), o.registerSystem({
|
|
204
|
+
update() {
|
|
205
|
+
var m;
|
|
276
206
|
const {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
207
|
+
width: c,
|
|
208
|
+
height: t,
|
|
209
|
+
textures: n
|
|
210
|
+
} = o, d = o.query();
|
|
211
|
+
for (let a = d.length, s = 0; s < a; s++) {
|
|
212
|
+
const e = d[s], {
|
|
213
|
+
shape: i = "rectangle",
|
|
214
|
+
material: u = "material2d",
|
|
215
|
+
filters: f = []
|
|
216
|
+
} = e, {
|
|
217
|
+
left: h = 0,
|
|
218
|
+
top: E = 0,
|
|
219
|
+
width: T = 0,
|
|
220
|
+
height: l = 0,
|
|
221
|
+
rotation: g = 0,
|
|
222
|
+
background: R
|
|
223
|
+
} = e.style ?? {}, A = h / c, _ = E / t, p = T / c, I = l / t, v = g / 180 * Math.PI, D = R != null && R.color ? G(R.color) : [0, 0, 0, 0];
|
|
224
|
+
o.renderNode({
|
|
225
|
+
shape: i,
|
|
226
|
+
material: u,
|
|
227
|
+
uniforms: {
|
|
228
|
+
uSampler: (m = n.get(e.id)) == null ? void 0 : m.value,
|
|
229
|
+
uBackgroundColor: D,
|
|
230
|
+
uModelMatrix: x.identity().multiply(x.translation(2 * A - (1 - p), 1 - I - 2 * _)).multiply(x.scaling(p, I)).multiply(x.rotation(v))
|
|
231
|
+
},
|
|
232
|
+
extraRenderers: f == null ? void 0 : f.map((N) => {
|
|
233
|
+
const {
|
|
234
|
+
shape: C,
|
|
235
|
+
material: M,
|
|
236
|
+
type: S,
|
|
237
|
+
...F
|
|
238
|
+
} = N;
|
|
239
|
+
return {
|
|
240
|
+
shape: C ?? i,
|
|
241
|
+
material: M ?? S ?? u,
|
|
242
|
+
uniforms: F
|
|
243
|
+
};
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
}
|
|
284
247
|
}
|
|
285
248
|
});
|
|
286
249
|
}
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
]
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
}), u.forEach((n) => {
|
|
316
|
-
var f;
|
|
317
|
-
return (f = n.afterRender) == null ? void 0 : f.call(n, o);
|
|
318
|
-
}), e.flush();
|
|
250
|
+
});
|
|
251
|
+
function $(o, r) {
|
|
252
|
+
const { width: c, height: t, context: n, shapes: d, materials: m, framebuffers: a, lastState: s } = o, { extraRenderers: e = [] } = r, i = [
|
|
253
|
+
r,
|
|
254
|
+
...e
|
|
255
|
+
].filter((u) => d.has(u.shape) && m.has(u.material));
|
|
256
|
+
for (let u = i.length, f = 0; f < u; f++) {
|
|
257
|
+
const h = i[f], {
|
|
258
|
+
shape: E,
|
|
259
|
+
material: T,
|
|
260
|
+
uniforms: l
|
|
261
|
+
} = h, g = d.get(E), R = m.get(T);
|
|
262
|
+
(s == null ? void 0 : s.material) !== T && (s == null ? void 0 : s.shape) !== E && R.setupAttributes({ aPosition: g.buffer });
|
|
263
|
+
const A = f < u - 1 ? a[f % 2] : null;
|
|
264
|
+
n.bindFramebuffer(n.FRAMEBUFFER, (A == null ? void 0 : A.buffer) ?? null), n.viewport(0, 0, c, t), A && n.clear(n.COLOR_BUFFER_BIT | n.DEPTH_BUFFER_BIT), (s == null ? void 0 : s.material) !== T && n.useProgram(R.program), l && R.setupUniforms(l), n.drawArrays(g.mode, 0, g.count), A && n.bindTexture(n.TEXTURE_2D, A.texture), o.lastState = {
|
|
265
|
+
material: T,
|
|
266
|
+
shape: E
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function L(o, r = 0) {
|
|
271
|
+
var d, m;
|
|
272
|
+
const { context: c, systems: t, framebuffers: n } = o;
|
|
273
|
+
n.forEach((a) => a.resize()), c.clear(c.COLOR_BUFFER_BIT | c.DEPTH_BUFFER_BIT);
|
|
274
|
+
for (let a = t.length, s = 0; s < a; s++)
|
|
275
|
+
(m = (d = t[s]).update) == null || m.call(d, r);
|
|
276
|
+
c.flush();
|
|
319
277
|
}
|
|
320
|
-
function
|
|
278
|
+
function W() {
|
|
321
279
|
const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
|
|
322
|
-
function
|
|
323
|
-
if (o.has(
|
|
324
|
-
return o.get(
|
|
325
|
-
if (r.has(
|
|
326
|
-
const { value:
|
|
327
|
-
return
|
|
280
|
+
function c(a) {
|
|
281
|
+
if (o.has(a))
|
|
282
|
+
return o.get(a);
|
|
283
|
+
if (r.has(a)) {
|
|
284
|
+
const { value: s, shared: e } = r.get(a), i = s();
|
|
285
|
+
return e && n(a, i), i;
|
|
328
286
|
}
|
|
329
287
|
}
|
|
330
|
-
function a
|
|
331
|
-
return o.has(
|
|
288
|
+
function t(a) {
|
|
289
|
+
return o.has(a) || r.has(a);
|
|
332
290
|
}
|
|
333
|
-
function
|
|
334
|
-
o.set(
|
|
291
|
+
function n(a, s) {
|
|
292
|
+
o.set(a, s);
|
|
335
293
|
}
|
|
336
|
-
function
|
|
337
|
-
|
|
294
|
+
function d(a, s) {
|
|
295
|
+
m(a, s, !0);
|
|
338
296
|
}
|
|
339
|
-
function
|
|
340
|
-
r.set(
|
|
297
|
+
function m(a, s, e = !1) {
|
|
298
|
+
r.set(a, { value: s, shared: e });
|
|
341
299
|
}
|
|
342
300
|
return new Proxy(
|
|
343
|
-
{ instances: o, bindings: r, get:
|
|
301
|
+
{ instances: o, bindings: r, get: c, has: t, set: n, bind: m, singleton: d },
|
|
344
302
|
{
|
|
345
|
-
get(
|
|
346
|
-
return typeof
|
|
303
|
+
get(a, s, e) {
|
|
304
|
+
return typeof s == "symbol" || s in a ? Reflect.get(a, s, e) : a.get(s);
|
|
347
305
|
},
|
|
348
|
-
has(
|
|
349
|
-
return typeof
|
|
306
|
+
has(a, s) {
|
|
307
|
+
return typeof s == "symbol" || s in a ? Reflect.has(a, s) : a.has(s);
|
|
350
308
|
},
|
|
351
|
-
set(
|
|
352
|
-
return typeof
|
|
309
|
+
set(a, s, e, i) {
|
|
310
|
+
return typeof s == "symbol" || s in a ? Reflect.set(a, s, e, i) : (a.set(s, e), !0);
|
|
353
311
|
}
|
|
354
312
|
}
|
|
355
313
|
);
|
|
356
314
|
}
|
|
357
|
-
function
|
|
358
|
-
const {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (a.has(c))
|
|
315
|
+
function V(o, r, c) {
|
|
316
|
+
const { context: t, materials: n, slTypes: d } = o, {
|
|
317
|
+
vertexShader: m,
|
|
318
|
+
fragmentShader: a,
|
|
319
|
+
uniforms: s
|
|
320
|
+
} = c;
|
|
321
|
+
if (n.has(r))
|
|
365
322
|
return;
|
|
366
|
-
const
|
|
367
|
-
{ type:
|
|
368
|
-
{ type:
|
|
369
|
-
${
|
|
370
|
-
].map(({ type:
|
|
371
|
-
const
|
|
372
|
-
if (!
|
|
323
|
+
const e = [
|
|
324
|
+
{ type: t.VERTEX_SHADER, source: m },
|
|
325
|
+
{ type: t.FRAGMENT_SHADER, source: a.includes("precision") ? a : `precision mediump float;
|
|
326
|
+
${a}` }
|
|
327
|
+
].map(({ type: E, source: T }) => {
|
|
328
|
+
const l = t.createShader(E);
|
|
329
|
+
if (!l)
|
|
373
330
|
throw new Error("failed to create shader");
|
|
374
|
-
if (
|
|
331
|
+
if (t.shaderSource(l, T), t.compileShader(l), !t.getShaderParameter(l, t.COMPILE_STATUS))
|
|
375
332
|
throw new Error(`failed to compiling shader:
|
|
376
|
-
${
|
|
377
|
-
${
|
|
378
|
-
return
|
|
379
|
-
}),
|
|
380
|
-
if (!
|
|
333
|
+
${T}
|
|
334
|
+
${t.getShaderInfoLog(l)}`);
|
|
335
|
+
return l;
|
|
336
|
+
}), i = t.createProgram();
|
|
337
|
+
if (!i)
|
|
381
338
|
throw new Error("failed to create program");
|
|
382
|
-
if (
|
|
383
|
-
throw new Error(`failed to initing program: ${
|
|
384
|
-
const
|
|
385
|
-
for (let
|
|
386
|
-
const
|
|
387
|
-
if (!
|
|
339
|
+
if (e.forEach((E) => t.attachShader(i, E)), t.linkProgram(i), e.forEach((E) => t.deleteShader(E)), !t.getProgramParameter(i, t.LINK_STATUS))
|
|
340
|
+
throw new Error(`failed to initing program: ${t.getProgramInfoLog(i)}`);
|
|
341
|
+
const u = {};
|
|
342
|
+
for (let E = t.getProgramParameter(i, t.ACTIVE_ATTRIBUTES), T = 0; T < E; T++) {
|
|
343
|
+
const l = t.getActiveAttrib(i, T);
|
|
344
|
+
if (!l)
|
|
388
345
|
continue;
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
type:
|
|
392
|
-
isArray:
|
|
393
|
-
location:
|
|
346
|
+
const g = l.name.replace(/\[.*?]$/, "");
|
|
347
|
+
u[g] = {
|
|
348
|
+
type: d[l.type],
|
|
349
|
+
isArray: g !== l.name,
|
|
350
|
+
location: t.getAttribLocation(i, g)
|
|
394
351
|
};
|
|
395
352
|
}
|
|
396
|
-
const
|
|
397
|
-
for (let
|
|
398
|
-
const
|
|
399
|
-
if (!
|
|
353
|
+
const f = {};
|
|
354
|
+
for (let E = t.getProgramParameter(i, t.ACTIVE_UNIFORMS), T = 0; T < E; T++) {
|
|
355
|
+
const l = t.getActiveUniform(i, T);
|
|
356
|
+
if (!l)
|
|
400
357
|
continue;
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
type:
|
|
404
|
-
isArray:
|
|
405
|
-
location:
|
|
358
|
+
const g = l.name.replace(/\[.*?]$/, "");
|
|
359
|
+
f[g] = {
|
|
360
|
+
type: d[l.type],
|
|
361
|
+
isArray: g !== l.name,
|
|
362
|
+
location: t.getUniformLocation(i, g)
|
|
406
363
|
};
|
|
407
364
|
}
|
|
408
|
-
const
|
|
409
|
-
...
|
|
410
|
-
program:
|
|
411
|
-
attributes:
|
|
412
|
-
uniforms:
|
|
413
|
-
|
|
414
|
-
for (const [
|
|
415
|
-
const
|
|
416
|
-
if (!
|
|
365
|
+
const h = {
|
|
366
|
+
...c,
|
|
367
|
+
program: i,
|
|
368
|
+
attributes: u,
|
|
369
|
+
uniforms: f,
|
|
370
|
+
setupAttributes(E) {
|
|
371
|
+
for (const [T, l] of Object.entries(E)) {
|
|
372
|
+
const g = u[T];
|
|
373
|
+
if (!g)
|
|
417
374
|
continue;
|
|
418
|
-
const { type:
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
switch (
|
|
375
|
+
const { type: R, isArray: A, location: _ } = g;
|
|
376
|
+
if (l instanceof WebGLBuffer) {
|
|
377
|
+
t.bindBuffer(t.ARRAY_BUFFER, l);
|
|
378
|
+
const p = t.getAttribLocation(i, T);
|
|
379
|
+
switch (R) {
|
|
423
380
|
case "vec2":
|
|
424
|
-
|
|
381
|
+
t.vertexAttribPointer(p, 2, t.FLOAT, !1, 0, 0), t.enableVertexAttribArray(p);
|
|
425
382
|
break;
|
|
426
383
|
case "vec3":
|
|
427
|
-
|
|
384
|
+
t.vertexAttribPointer(p, 3, t.FLOAT, !1, 0, 0), t.enableVertexAttribArray(p);
|
|
428
385
|
break;
|
|
429
386
|
}
|
|
430
387
|
} else
|
|
431
|
-
switch (
|
|
388
|
+
switch (R) {
|
|
432
389
|
case "float":
|
|
433
|
-
|
|
390
|
+
A ? t.vertexAttrib1fv(_, l) : t.vertexAttrib1f(_, l);
|
|
434
391
|
break;
|
|
435
392
|
case "vec2":
|
|
436
|
-
|
|
393
|
+
t.vertexAttrib2fv(_, l);
|
|
437
394
|
break;
|
|
438
395
|
case "vec3":
|
|
439
|
-
|
|
396
|
+
t.vertexAttrib3fv(_, l);
|
|
440
397
|
break;
|
|
441
398
|
case "vec4":
|
|
442
|
-
|
|
399
|
+
t.vertexAttrib4fv(_, l);
|
|
443
400
|
break;
|
|
444
401
|
}
|
|
445
402
|
}
|
|
446
403
|
},
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (!A)
|
|
404
|
+
setupUniforms(E) {
|
|
405
|
+
for (const [T, l] of Object.entries(E)) {
|
|
406
|
+
const g = f[T];
|
|
407
|
+
if (!g)
|
|
452
408
|
continue;
|
|
453
|
-
const { type:
|
|
454
|
-
switch (
|
|
409
|
+
const { type: R, isArray: A, location: _ } = g;
|
|
410
|
+
switch (R) {
|
|
455
411
|
case "float":
|
|
456
|
-
|
|
412
|
+
A ? t.uniform1fv(_, l) : t.uniform1f(_, l);
|
|
457
413
|
break;
|
|
458
414
|
case "bool":
|
|
459
415
|
case "int":
|
|
460
|
-
|
|
416
|
+
A ? t.uniform1iv(_, l) : t.uniform1i(_, l);
|
|
461
417
|
break;
|
|
462
418
|
case "vec2":
|
|
463
|
-
|
|
419
|
+
t.uniform2fv(_, l);
|
|
464
420
|
break;
|
|
465
421
|
case "vec3":
|
|
466
|
-
|
|
422
|
+
t.uniform3fv(_, l);
|
|
467
423
|
break;
|
|
468
424
|
case "vec4":
|
|
469
|
-
|
|
425
|
+
t.uniform4fv(_, l);
|
|
470
426
|
break;
|
|
471
427
|
case "mat2":
|
|
472
|
-
|
|
428
|
+
t.uniformMatrix2fv(_, !1, l);
|
|
473
429
|
break;
|
|
474
430
|
case "mat3":
|
|
475
|
-
|
|
431
|
+
t.uniformMatrix3fv(_, !1, l);
|
|
476
432
|
break;
|
|
477
433
|
case "mat4":
|
|
478
|
-
|
|
434
|
+
t.uniformMatrix4fv(_, !1, l);
|
|
479
435
|
break;
|
|
480
436
|
case "sampler2D":
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
),
|
|
437
|
+
t.bindTexture(
|
|
438
|
+
t.TEXTURE_2D,
|
|
439
|
+
l ?? o.defaultTexture
|
|
440
|
+
), t.uniform1i(_, 0);
|
|
485
441
|
break;
|
|
486
442
|
}
|
|
487
443
|
}
|
|
488
444
|
}
|
|
489
445
|
};
|
|
490
|
-
|
|
446
|
+
s && h.setupUniforms(s), n.set(r, h);
|
|
447
|
+
}
|
|
448
|
+
function H(o, r, c) {
|
|
449
|
+
const { context: t, shapes: n, drawModes: d } = o, {
|
|
450
|
+
type: m = "2d",
|
|
451
|
+
mode: a = "triangles",
|
|
452
|
+
buffer: s = new Float32Array([])
|
|
453
|
+
} = c, e = t.createBuffer();
|
|
454
|
+
t.bindBuffer(t.ARRAY_BUFFER, e), t.bufferData(t.ARRAY_BUFFER, s, t.STATIC_DRAW), n.set(r, {
|
|
455
|
+
mode: d[a],
|
|
456
|
+
count: s.byteLength / s.BYTES_PER_ELEMENT / (m === "2d" ? 2 : 3),
|
|
457
|
+
buffer: e
|
|
458
|
+
});
|
|
491
459
|
}
|
|
492
|
-
function
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
460
|
+
function Y(o) {
|
|
461
|
+
const { entities: r, children: c, components: t, archetypes: n } = o;
|
|
462
|
+
r.clear(), t.clear(), n.clear();
|
|
463
|
+
const d = function() {
|
|
464
|
+
let e = 0;
|
|
465
|
+
return () => ++e;
|
|
466
|
+
}(), m = function() {
|
|
467
|
+
let e = 0;
|
|
468
|
+
return () => ++e;
|
|
469
|
+
}();
|
|
470
|
+
function a(e, i) {
|
|
471
|
+
var R, A;
|
|
472
|
+
e.id || (e.id = d());
|
|
473
|
+
const u = e.id, f = [];
|
|
474
|
+
for (const _ in e) {
|
|
475
|
+
let p = t.get(_);
|
|
476
|
+
p || (p = m(), t.set(_, p)), f.push(p);
|
|
477
|
+
}
|
|
478
|
+
const h = P(f), E = h.map((_) => String.fromCharCode(_)).join(""), T = r.get(u);
|
|
479
|
+
T && ((A = (R = n.get(T.archetypeId)) == null ? void 0 : R.entityIds) == null || A.delete(u));
|
|
480
|
+
const l = n.get(E);
|
|
481
|
+
let g = l == null ? void 0 : l.entityIds;
|
|
482
|
+
l || (g = /* @__PURE__ */ new Set(), n.set(E, {
|
|
483
|
+
entityIds: g,
|
|
484
|
+
codePoints: h
|
|
485
|
+
})), g.add(u), r.set(u, { path: i, archetypeId: E });
|
|
486
|
+
}
|
|
487
|
+
function s(e, i) {
|
|
488
|
+
for (let u = e.length, f = 0; f < u; f++) {
|
|
489
|
+
const h = e[f], E = [...i, f];
|
|
490
|
+
a(h, E), h.children && s(h.children, E);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
s(c, []);
|
|
494
|
+
}
|
|
495
|
+
function k(o, r) {
|
|
496
|
+
const { entities: c, components: t, children: n, archetypes: d } = o;
|
|
497
|
+
if (!r)
|
|
498
|
+
return n.flatMap(function i(u) {
|
|
499
|
+
var f;
|
|
500
|
+
return [u, (f = u.children) == null ? void 0 : f.flatMap(i)].filter(Boolean);
|
|
501
|
+
});
|
|
502
|
+
const m = typeof r == "string" ? [r] : r, a = [];
|
|
503
|
+
for (let i = m.length, u = 0; u < i; u++) {
|
|
504
|
+
const f = t.get(m[u]);
|
|
505
|
+
f && a.push(f);
|
|
506
|
+
}
|
|
507
|
+
const s = P(a), e = [];
|
|
508
|
+
for (const [, { entityIds: i, codePoints: u }] of d.entries())
|
|
509
|
+
if (u.some((f) => s.some((h) => h & f)))
|
|
510
|
+
for (const [f] of i.entries()) {
|
|
511
|
+
const { path: h } = c.get(f);
|
|
512
|
+
if (!h || !h.length)
|
|
513
|
+
continue;
|
|
514
|
+
let E = n[h[0]];
|
|
515
|
+
for (let T = h.length, l = 1; l < T; l++)
|
|
516
|
+
E = E[l];
|
|
517
|
+
e.push(E);
|
|
518
|
+
}
|
|
519
|
+
return e;
|
|
520
|
+
}
|
|
521
|
+
function q(o, r, c) {
|
|
522
|
+
const { context: t, textures: n } = o, d = {
|
|
523
|
+
loading: !0,
|
|
524
|
+
value: null,
|
|
525
|
+
source: c
|
|
526
|
+
};
|
|
527
|
+
return n.set(r, d), new Promise((m) => {
|
|
528
|
+
c instanceof HTMLImageElement ? c.addEventListener("load", a, { once: !0 }) : c instanceof HTMLVideoElement ? (c.addEventListener("canplay", a, { once: !0 }), c.addEventListener("timeupdate", () => {
|
|
529
|
+
t.bindTexture(t.TEXTURE_2D, d.value), t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, c);
|
|
530
|
+
})) : a();
|
|
531
|
+
function a() {
|
|
532
|
+
d.value = t.createTexture(), d.value && (t.bindTexture(t.TEXTURE_2D, d.value), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.LINEAR), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.LINEAR), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE), t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, c)), d.loading = !1, c instanceof HTMLVideoElement && (c.currentTime = 0.01), m();
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
function K(o, r) {
|
|
537
|
+
const { systems: c } = o;
|
|
538
|
+
c.push(r);
|
|
539
|
+
}
|
|
540
|
+
function z(o = {}) {
|
|
541
|
+
var a, s;
|
|
542
|
+
const {
|
|
543
|
+
view: r = document.createElement("canvas"),
|
|
544
|
+
children: c = [],
|
|
545
|
+
plugins: t = []
|
|
546
|
+
} = o, n = W();
|
|
547
|
+
n.view = r, n.singleton("context", () => {
|
|
548
|
+
const { view: e } = n, i = e.getContext("webgl", o) || e.getContext("experimental-webgl", o);
|
|
549
|
+
if (!i)
|
|
496
550
|
throw new Error("failed to getContext for webgl");
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
551
|
+
const u = i.drawingBufferWidth, f = i.drawingBufferHeight;
|
|
552
|
+
return i.viewport(0, 0, u, f), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, !0), i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), i.clearColor(0, 0, 0, 0), i.enable(i.DEPTH_TEST), i.enable(i.CULL_FACE), i.enable(i.BLEND), i.blendFunc(i.ONE, i.ONE_MINUS_SRC_ALPHA), i.depthMask(!1), i;
|
|
553
|
+
}), n.singleton("defaultTexture", () => {
|
|
554
|
+
const { context: e, width: i, height: u } = n, f = e.createTexture();
|
|
555
|
+
return e.bindTexture(e.TEXTURE_2D, f), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, i, u, 0, e.RGBA, e.UNSIGNED_BYTE, null), f;
|
|
556
|
+
}), n.singleton("framebuffers", () => {
|
|
557
|
+
const { context: e } = n;
|
|
503
558
|
return Array.from({ length: 2 }, () => {
|
|
504
|
-
const
|
|
505
|
-
function
|
|
506
|
-
const { width:
|
|
507
|
-
e.bindTexture(e.TEXTURE_2D,
|
|
559
|
+
const i = e.createTexture(), u = e.createFramebuffer(), f = e.createRenderbuffer();
|
|
560
|
+
function h() {
|
|
561
|
+
const { width: E, height: T } = n;
|
|
562
|
+
e.bindTexture(e.TEXTURE_2D, i), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, E, T, 0, e.RGBA, e.UNSIGNED_BYTE, null), e.bindRenderbuffer(e.RENDERBUFFER, f), e.renderbufferStorage(e.RENDERBUFFER, e.DEPTH_COMPONENT16, E, T);
|
|
508
563
|
}
|
|
509
|
-
return
|
|
510
|
-
buffer:
|
|
511
|
-
depthBuffer:
|
|
512
|
-
texture:
|
|
513
|
-
resize:
|
|
564
|
+
return h(), e.bindTexture(e.TEXTURE_2D, i), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), e.bindFramebuffer(e.FRAMEBUFFER, u), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, i, 0), e.bindRenderbuffer(e.RENDERBUFFER, f), e.framebufferRenderbuffer(e.FRAMEBUFFER, e.DEPTH_ATTACHMENT, e.RENDERBUFFER, f), {
|
|
565
|
+
buffer: u,
|
|
566
|
+
depthBuffer: f,
|
|
567
|
+
texture: i,
|
|
568
|
+
resize: h
|
|
514
569
|
};
|
|
515
570
|
});
|
|
516
|
-
}),
|
|
517
|
-
const {
|
|
571
|
+
}), n.singleton("drawModes", () => {
|
|
572
|
+
const { context: e } = n;
|
|
518
573
|
return {
|
|
519
574
|
points: e.POINTS,
|
|
520
575
|
linear: e.LINEAR,
|
|
@@ -522,8 +577,8 @@ function I(o, r) {
|
|
|
522
577
|
triangleStrip: e.TRIANGLE_STRIP,
|
|
523
578
|
triangleFan: e.TRIANGLE_FAN
|
|
524
579
|
};
|
|
525
|
-
}),
|
|
526
|
-
const e =
|
|
580
|
+
}), n.singleton("slTypes", () => {
|
|
581
|
+
const { context: e } = n;
|
|
527
582
|
return {
|
|
528
583
|
[e.FLOAT]: "float",
|
|
529
584
|
[e.FLOAT_VEC2]: "vec2",
|
|
@@ -534,9 +589,9 @@ function I(o, r) {
|
|
|
534
589
|
[e.INT_VEC3]: "ivec3",
|
|
535
590
|
[e.INT_VEC4]: "ivec4",
|
|
536
591
|
[e.UNSIGNED_INT]: "uint",
|
|
537
|
-
[e.UNSIGNED_INT_VEC2]: "uvec2",
|
|
538
|
-
[e.UNSIGNED_INT_VEC3]: "uvec3",
|
|
539
|
-
[e.UNSIGNED_INT_VEC4]: "uvec4",
|
|
592
|
+
[e.UNSIGNED_INT_VEC2 ?? -1]: "uvec2",
|
|
593
|
+
[e.UNSIGNED_INT_VEC3 ?? -1]: "uvec3",
|
|
594
|
+
[e.UNSIGNED_INT_VEC4 ?? -1]: "uvec4",
|
|
540
595
|
[e.BOOL]: "bool",
|
|
541
596
|
[e.BOOL_VEC2]: "bvec2",
|
|
542
597
|
[e.BOOL_VEC3]: "bvec3",
|
|
@@ -545,128 +600,48 @@ function I(o, r) {
|
|
|
545
600
|
[e.FLOAT_MAT3]: "mat3",
|
|
546
601
|
[e.FLOAT_MAT4]: "mat4",
|
|
547
602
|
[e.SAMPLER_2D]: "sampler2D",
|
|
548
|
-
[e.INT_SAMPLER_2D]: "sampler2D",
|
|
549
|
-
[e.UNSIGNED_INT_SAMPLER_2D]: "sampler2D",
|
|
603
|
+
[e.INT_SAMPLER_2D ?? -1]: "sampler2D",
|
|
604
|
+
[e.UNSIGNED_INT_SAMPLER_2D ?? -1]: "sampler2D",
|
|
550
605
|
[e.SAMPLER_CUBE]: "samplerCube",
|
|
551
|
-
[e.INT_SAMPLER_CUBE]: "samplerCube",
|
|
552
|
-
[e.UNSIGNED_INT_SAMPLER_CUBE]: "samplerCube",
|
|
553
|
-
[e.SAMPLER_2D_ARRAY]: "sampler2DArray",
|
|
554
|
-
[e.INT_SAMPLER_2D_ARRAY]: "sampler2DArray",
|
|
555
|
-
[e.UNSIGNED_INT_SAMPLER_2D_ARRAY]: "sampler2DArray"
|
|
606
|
+
[e.INT_SAMPLER_CUBE ?? -1]: "samplerCube",
|
|
607
|
+
[e.UNSIGNED_INT_SAMPLER_CUBE ?? -1]: "samplerCube",
|
|
608
|
+
[e.SAMPLER_2D_ARRAY ?? -1]: "sampler2DArray",
|
|
609
|
+
[e.INT_SAMPLER_2D_ARRAY ?? -1]: "sampler2DArray",
|
|
610
|
+
[e.UNSIGNED_INT_SAMPLER_2D_ARRAY ?? -1]: "sampler2DArray"
|
|
556
611
|
};
|
|
557
|
-
}),
|
|
558
|
-
loseContext:
|
|
559
|
-
}))
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
buffer: s
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
function y(o, r) {
|
|
575
|
-
const { gl: e, shapes: a, materials: t, nodeRenderers: c } = o, { name: u, shape: i, material: l } = r, s = typeof i == "string" ? i : `${u}-shape`;
|
|
576
|
-
typeof i != "string" && o.registerShape({ ...i, name: s });
|
|
577
|
-
const n = typeof l == "string" ? l : `${u}-material`;
|
|
578
|
-
typeof l != "string" && o.registerMaterial({ ...l, name: n });
|
|
579
|
-
const f = a.get(s), R = t.get(n);
|
|
580
|
-
if (!f || !R)
|
|
581
|
-
return;
|
|
582
|
-
const { buffer: g } = f;
|
|
583
|
-
R.setAttributes({ aPosition: g }), c.set(u, {
|
|
584
|
-
...r,
|
|
585
|
-
shape: s,
|
|
586
|
-
material: n,
|
|
587
|
-
render: (T, d) => {
|
|
588
|
-
var p;
|
|
589
|
-
const E = a.get(s), m = t.get(n);
|
|
590
|
-
if (!E || !m)
|
|
591
|
-
return;
|
|
592
|
-
const { program: A } = m, { mode: x, count: b } = E;
|
|
593
|
-
e.useProgram(A);
|
|
594
|
-
const h = (p = r.update) == null ? void 0 : p.call(r, T, d);
|
|
595
|
-
h && m.setUniforms(h), e.drawArrays(x, 0, b);
|
|
612
|
+
}), n.singleton("extensions", () => ({
|
|
613
|
+
loseContext: n.context.getExtension("WEBGL_lose_context")
|
|
614
|
+
})), n.bind("width", () => n.context.drawingBufferWidth), n.bind("height", () => n.context.drawingBufferHeight), n.plugins = /* @__PURE__ */ new Map(), n.children = c, n.shapes = /* @__PURE__ */ new Map(), n.registerShape = (e, i) => H(n, e, i), n.materials = /* @__PURE__ */ new Map(), n.registerMaterial = (e, i) => V(n, e, i), n.textures = /* @__PURE__ */ new Map(), n.registerTexture = (e, i) => q(n, e, i), n.entities = /* @__PURE__ */ new Map(), n.components = /* @__PURE__ */ new Map(), n.archetypes = /* @__PURE__ */ new Map(), n.systems = [], n.registerSystem = (e) => K(n, e), n.query = (e) => k(n, e), n.setup = () => Y(n), n.load = async () => {
|
|
615
|
+
var u, f;
|
|
616
|
+
const { systems: e, textures: i } = n;
|
|
617
|
+
for (let h = e.length, E = 0; E < h; E++)
|
|
618
|
+
(f = (u = e[E]).update) == null || f.call(u, 0);
|
|
619
|
+
for (; Array.from(i.values()).some((h) => h.loading); )
|
|
620
|
+
await new Promise((h) => setTimeout(h, 100));
|
|
621
|
+
}, n.renderNode = (e) => $(n, e), n.render = (e) => L(n, e), n.start = () => {
|
|
622
|
+
let e = 0, i = 0;
|
|
623
|
+
u(0);
|
|
624
|
+
function u(f) {
|
|
625
|
+
requestAnimationFrame(u), L(n, i), f *= 1e-3, i += f - e, e = f;
|
|
596
626
|
}
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
function w(o, r) {
|
|
600
|
-
const { children: e } = o;
|
|
601
|
-
function a(t, c = []) {
|
|
602
|
-
for (let u = t.length - 1; u >= 0; u--) {
|
|
603
|
-
const i = [...c, u], l = t[u];
|
|
604
|
-
a(l.children ?? [], i), r(l, i);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
a(e);
|
|
608
|
-
}
|
|
609
|
-
function O(o, r) {
|
|
610
|
-
const { gl: e, resources: a } = o, { name: t, data: c } = r, u = {
|
|
611
|
-
loading: !0,
|
|
612
|
-
texture: null
|
|
613
627
|
};
|
|
614
|
-
function
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
function G(o = {}) {
|
|
620
|
-
var i, l;
|
|
621
|
-
const {
|
|
622
|
-
view: r = document.createElement("canvas"),
|
|
623
|
-
children: e = [],
|
|
624
|
-
plugins: a = []
|
|
625
|
-
} = o, t = C();
|
|
626
|
-
t.set("view", r), I(t, o), t.bind("width", () => t.gl.drawingBufferWidth), t.bind("height", () => t.gl.drawingBufferHeight), t.singleton("plugins", () => {
|
|
627
|
-
const s = /* @__PURE__ */ new Map();
|
|
628
|
-
return a.forEach((n) => {
|
|
629
|
-
var f;
|
|
630
|
-
(f = n.register) == null || f.call(n, t), s.set(n.name, n);
|
|
631
|
-
}), s;
|
|
632
|
-
}), t.singleton("beforeRenderPlugins", () => Array.from(t.plugins.values()).filter((s) => "beforeRender" in s)), t.singleton("afterRenderPlugins", () => Array.from(t.plugins.values()).filter((s) => "afterRender" in s)), t.set("children", e), t.set("shapes", /* @__PURE__ */ new Map()), t.set("registerShape", (s) => B(t, s)), t.set("materials", /* @__PURE__ */ new Map()), t.set("registerMaterial", (s) => M(t, s)), t.set("resources", /* @__PURE__ */ new Map()), t.set("registerResource", (s) => O(t, s)), t.set("nodeRenderers", /* @__PURE__ */ new Map()), t.set("registerNodeRenderer", (s) => y(t, s)), t.set("forEachNode", (s) => w(t, s)), t.set("load", async () => {
|
|
633
|
-
t.get("plugins");
|
|
634
|
-
const s = Array.from(t.nodeRenderers.values());
|
|
635
|
-
for (t.forEachNode((n, f) => {
|
|
636
|
-
s.filter((g) => !g.include && !g.exclude || g.include && g.include(n, f) || g.exclude && !g.exclude(n, f)).forEach((g) => {
|
|
637
|
-
var T;
|
|
638
|
-
return (T = g.update) == null ? void 0 : T.call(g, n, 0);
|
|
639
|
-
});
|
|
640
|
-
}); Array.from(t.resources.values()).some((n) => n.loading); )
|
|
641
|
-
await new Promise((n) => setTimeout(n, 100));
|
|
642
|
-
return !0;
|
|
643
|
-
}), t.set("render", (s) => P(t, s)), t.set("startRenderLoop", () => {
|
|
644
|
-
let s = 0, n = 0;
|
|
645
|
-
f(0);
|
|
646
|
-
function f(R) {
|
|
647
|
-
requestAnimationFrame(f), P(t, n), R *= 1e-3, n += R - s, s = R;
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
function c(s) {
|
|
651
|
-
s.preventDefault(), setTimeout(() => {
|
|
652
|
-
var n;
|
|
653
|
-
t.gl.isContextLost() && ((n = t.glExtensions.loseContext) == null || n.restoreContext());
|
|
628
|
+
function d(e) {
|
|
629
|
+
e.preventDefault(), setTimeout(() => {
|
|
630
|
+
var i;
|
|
631
|
+
n.context.isContextLost() && ((i = n.extensions.loseContext) == null || i.restoreContext());
|
|
654
632
|
}, 0);
|
|
655
633
|
}
|
|
656
|
-
function
|
|
634
|
+
function m() {
|
|
657
635
|
}
|
|
658
|
-
return (
|
|
659
|
-
var
|
|
660
|
-
(
|
|
661
|
-
}
|
|
636
|
+
return (a = r.addEventListener) == null || a.call(r, "webglcontextlost", d, !1), (s = r.addEventListener) == null || s.call(r, "webglcontextrestored", m, !1), n.destroy = () => {
|
|
637
|
+
var e, i, u;
|
|
638
|
+
(e = r.removeEventListener) == null || e.call(r, "webglcontextlost", d), (i = r.removeEventListener) == null || i.call(r, "webglcontextrestored", m), n.context.useProgram(null), (u = n.extensions.loseContext) == null || u.loseContext();
|
|
639
|
+
}, t.forEach((e) => {
|
|
640
|
+
var i;
|
|
641
|
+
(i = e.register) == null || i.call(e, n), n.plugins.set(e.name, e);
|
|
642
|
+
}), n.setup(), n;
|
|
662
643
|
}
|
|
663
644
|
export {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
F as fadePlugin,
|
|
667
|
-
D as nodeImagePlugin,
|
|
668
|
-
N as nodeTextPlugin,
|
|
669
|
-
X as plugins,
|
|
670
|
-
L as selector2dPlugin,
|
|
671
|
-
S as transform2dPlugin
|
|
645
|
+
j as Renderer2d,
|
|
646
|
+
z as createApp
|
|
672
647
|
};
|