@actioneer/ads 0.3.1 → 0.5.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.
@@ -1,531 +0,0 @@
1
- "use client";
2
- var Be = Object.defineProperty;
3
- var $e = (c, i, n) => i in c ? Be(c, i, { enumerable: !0, configurable: !0, writable: !0, value: n }) : c[i] = n;
4
- var v = (c, i, n) => $e(c, typeof i != "symbol" ? i + "" : i, n);
5
- import { jsx as Ve } from "react/jsx-runtime";
6
- import { useRef as p, useEffect as q } from "react";
7
- const de = ["lowp", "mediump", "highp"], Ye = `
8
- void main(void){
9
- vec4 color = vec4(0.0,0.0,0.0,1.0);
10
- mainImage( color, gl_FragCoord.xy );
11
- gl_FragColor = color;
12
- }`, Ge = `void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
13
- vec2 uv = fragCoord/iResolution.xy;
14
- vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
15
- fragColor = vec4(col,1.0);
16
- }`, me = `attribute vec3 aVertexPosition;
17
- void main(void) {
18
- gl_Position = vec4(aVertexPosition, 1.0);
19
- }`, le = "iTime", he = "iTimeDelta", ve = "iDate", pe = "iFrame", ge = "iMouse", Te = "iResolution", He = "iChannel", Ee = "iChannelResolution", Re = "iDeviceOrientation";
20
- function je(c, i) {
21
- return c.includes("Matrix") && Array.isArray(i);
22
- }
23
- function ze(c, i) {
24
- return c.includes("v") && Array.isArray(i) && i.length > Number.parseInt(c.charAt(0));
25
- }
26
- function ke(c, i) {
27
- return !c.includes("v") && Array.isArray(i) && i.length > Number.parseInt(c.charAt(0));
28
- }
29
- const qe = (c, i, n, s) => {
30
- if (ke(n, s))
31
- switch (n) {
32
- case "2f":
33
- return c.uniform2f(i, s[0], s[1]);
34
- case "3f":
35
- return c.uniform3f(i, s[0], s[1], s[2]);
36
- case "4f":
37
- return c.uniform4f(i, s[0], s[1], s[2], s[3]);
38
- case "2i":
39
- return c.uniform2i(i, s[0], s[1]);
40
- case "3i":
41
- return c.uniform3i(i, s[0], s[1], s[2]);
42
- case "4i":
43
- return c.uniform4i(i, s[0], s[1], s[2], s[3]);
44
- }
45
- if (typeof s == "number")
46
- switch (n) {
47
- case "1i":
48
- return c.uniform1i(i, s);
49
- default:
50
- return c.uniform1f(i, s);
51
- }
52
- switch (n) {
53
- case "1iv":
54
- return c.uniform1iv(i, s);
55
- case "2iv":
56
- return c.uniform2iv(i, s);
57
- case "3iv":
58
- return c.uniform3iv(i, s);
59
- case "4iv":
60
- return c.uniform4iv(i, s);
61
- case "1fv":
62
- return c.uniform1fv(i, s);
63
- case "2fv":
64
- return c.uniform2fv(i, s);
65
- case "3fv":
66
- return c.uniform3fv(i, s);
67
- case "4fv":
68
- return c.uniform4fv(i, s);
69
- case "Matrix2fv":
70
- return c.uniformMatrix2fv(i, !1, s);
71
- case "Matrix3fv":
72
- return c.uniformMatrix3fv(i, !1, s);
73
- case "Matrix4fv":
74
- return c.uniformMatrix4fv(i, !1, s);
75
- }
76
- }, Ke = (c) => {
77
- switch (c) {
78
- case "1f":
79
- return "float";
80
- case "2f":
81
- return "vec2";
82
- case "3f":
83
- return "vec3";
84
- case "4f":
85
- return "vec4";
86
- case "1i":
87
- return "int";
88
- case "2i":
89
- return "ivec2";
90
- case "3i":
91
- return "ivec3";
92
- case "4i":
93
- return "ivec4";
94
- case "1iv":
95
- return "int";
96
- case "2iv":
97
- return "ivec2";
98
- case "3iv":
99
- return "ivec3";
100
- case "4iv":
101
- return "ivec4";
102
- case "1fv":
103
- return "float";
104
- case "2fv":
105
- return "vec2";
106
- case "3fv":
107
- return "vec3";
108
- case "4fv":
109
- return "vec4";
110
- case "Matrix2fv":
111
- return "mat2";
112
- case "Matrix3fv":
113
- return "mat3";
114
- case "Matrix4fv":
115
- return "mat4";
116
- default:
117
- console.error(
118
- N(`The uniform type "${c}" is not valid, please make sure your uniform type is valid`)
119
- );
120
- }
121
- }, ie = 9729, we = 9728, We = 9987, _e = 33071, ye = 10497;
122
- class Qe {
123
- constructor(i) {
124
- v(this, "gl");
125
- v(this, "url");
126
- v(this, "wrapS");
127
- v(this, "wrapT");
128
- v(this, "minFilter");
129
- v(this, "magFilter");
130
- v(this, "source");
131
- v(this, "pow2canvas");
132
- v(this, "isLoaded", !1);
133
- v(this, "isVideo", !1);
134
- v(this, "flipY", -1);
135
- v(this, "width", 0);
136
- v(this, "height", 0);
137
- v(this, "_webglTexture", null);
138
- v(this, "updateTexture", (i, n, s) => {
139
- const { gl: T } = this, L = 0, H = T.RGBA, D = T.RGBA, F = T.UNSIGNED_BYTE;
140
- T.bindTexture(T.TEXTURE_2D, i), T.pixelStorei(T.UNPACK_FLIP_Y_WEBGL, s), T.texImage2D(T.TEXTURE_2D, L, H, D, F, n);
141
- });
142
- v(this, "setupVideo", (i) => {
143
- const n = document.createElement("video");
144
- let s = !1, T = !1;
145
- n.autoplay = !0, n.muted = !0, n.loop = !0, n.crossOrigin = "anonymous";
146
- const L = () => {
147
- s && T && (this.isLoaded = !0);
148
- };
149
- return n.addEventListener(
150
- "playing",
151
- () => {
152
- s = !0, this.width = n.videoWidth || 0, this.height = n.videoHeight || 0, L();
153
- },
154
- !0
155
- ), n.addEventListener(
156
- "timeupdate",
157
- () => {
158
- T = !0, L();
159
- },
160
- !0
161
- ), n.src = i, n;
162
- });
163
- v(this, "makePowerOf2", (i) => {
164
- if (i instanceof HTMLImageElement || i instanceof HTMLCanvasElement || i instanceof ImageBitmap) {
165
- this.pow2canvas === void 0 && (this.pow2canvas = document.createElement("canvas")), this.pow2canvas.width = 2 ** Math.floor(Math.log(i.width) / Math.LN2), this.pow2canvas.height = 2 ** Math.floor(Math.log(i.height) / Math.LN2);
166
- const n = this.pow2canvas.getContext("2d");
167
- return n == null || n.drawImage(i, 0, 0, this.pow2canvas.width, this.pow2canvas.height), console.warn(
168
- N(
169
- `Image is not power of two ${i.width} x ${i.height}. Resized to ${this.pow2canvas.width} x ${this.pow2canvas.height};`
170
- )
171
- ), this.pow2canvas;
172
- }
173
- return i;
174
- });
175
- v(this, "load", async (i) => {
176
- const { gl: n } = this, { url: s, wrapS: T, wrapT: L, minFilter: H, magFilter: D, flipY: F = -1 } = i;
177
- if (!s)
178
- return Promise.reject(
179
- new Error(
180
- N("Missing url, please make sure to pass the url of your texture { url: ... }")
181
- )
182
- );
183
- const b = /(\.jpg|\.jpeg|\.png|\.gif|\.bmp)$/i.exec(s), M = /(\.mp4|\.3gp|\.webm|\.ogv)$/i.exec(s);
184
- if (b === null && M === null)
185
- return Promise.reject(
186
- new Error(N(`Please upload a video or an image with a valid format (url: ${s})`))
187
- );
188
- Object.assign(this, { url: s, wrapS: T, wrapT: L, minFilter: H, magFilter: D, flipY: F });
189
- const w = 0, I = n.RGBA, S = 1, P = 1, re = 0, u = n.RGBA, g = n.UNSIGNED_BYTE, j = new Uint8Array([255, 255, 255, 0]), m = n.createTexture();
190
- if (n.bindTexture(n.TEXTURE_2D, m), n.texImage2D(
191
- n.TEXTURE_2D,
192
- w,
193
- I,
194
- S,
195
- P,
196
- re,
197
- u,
198
- g,
199
- j
200
- ), M) {
201
- const x = this.setupVideo(s);
202
- return n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, n.CLAMP_TO_EDGE), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, n.LINEAR), this._webglTexture = m, this.source = x, this.isVideo = !0, x.play().then(() => this);
203
- }
204
- async function z() {
205
- return new Promise((x, K) => {
206
- const _ = new Image();
207
- _.crossOrigin = "anonymous", _.onload = () => {
208
- x(_);
209
- }, _.onerror = () => {
210
- K(new Error(N(`failed loading url: ${s}`)));
211
- }, _.src = s ?? "";
212
- });
213
- }
214
- let E = await z(), C = (E.width & E.width - 1) === 0 && (E.height & E.height - 1) === 0;
215
- return (i.wrapS !== _e || i.wrapT !== _e || i.minFilter !== we && i.minFilter !== ie) && !C && (E = this.makePowerOf2(E), C = !0), n.bindTexture(n.TEXTURE_2D, m), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, F), n.texImage2D(n.TEXTURE_2D, w, I, u, g, E), C && i.minFilter !== we && i.minFilter !== ie && n.generateMipmap(n.TEXTURE_2D), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, this.wrapS || ye), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, this.wrapT || ye), n.texParameteri(
216
- n.TEXTURE_2D,
217
- n.TEXTURE_MIN_FILTER,
218
- this.minFilter || We
219
- ), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, this.magFilter || ie), this._webglTexture = m, this.source = E, this.isVideo = !1, this.isLoaded = !0, this.width = E.width || 0, this.height = E.height || 0, this;
220
- });
221
- this.gl = i;
222
- }
223
- }
224
- const N = (c) => `react-shaders: ${c}`, Ae = (c) => {
225
- if ("changedTouches" in c) {
226
- const i = c.changedTouches[0];
227
- return [(i == null ? void 0 : i.clientX) ?? 0, (i == null ? void 0 : i.clientY) ?? 0];
228
- }
229
- return [c.clientX, c.clientY];
230
- }, Le = (c, i, n) => c * (1 - n) + i * n, Je = (c, i, n) => n > 0 ? c.substring(0, n) + i + c.substring(n, c.length) : i + c;
231
- function rt({
232
- fs: c,
233
- vs: i = me,
234
- textures: n = [],
235
- uniforms: s,
236
- clearColor: T = [0, 0, 0, 1],
237
- precision: L = "highp",
238
- style: H,
239
- contextAttributes: D = {},
240
- lerp: F = 1,
241
- devicePixelRatio: b = 1,
242
- onDoneLoadingTextures: M,
243
- onError: w = console.error,
244
- onWarning: I = console.warn,
245
- animateWhenNotVisible: S = !1,
246
- paused: P = !1,
247
- ...re
248
- }) {
249
- const u = p(null), g = p(null), j = p(null), m = p(null), z = p(void 0), E = p(void 0), C = p(void 0), x = p(!0), K = p(S), _ = p(P), Ue = p(!1), U = p(void 0), Fe = p(0), X = p([0, 0]), B = p([]), W = p(0), Q = p(void 0), a = p({
250
- [le]: { type: "float", isNeeded: !1, value: 0 },
251
- [he]: { type: "float", isNeeded: !1, value: 0 },
252
- [ve]: { type: "vec4", isNeeded: !1, value: [0, 0, 0, 0] },
253
- [ge]: { type: "vec4", isNeeded: !1, value: [0, 0, 0, 0] },
254
- [Te]: { type: "vec2", isNeeded: !1, value: [0, 0] },
255
- [pe]: { type: "int", isNeeded: !1, value: 0 },
256
- [Re]: { type: "vec4", isNeeded: !1, value: [0, 0, 0, 0] }
257
- }), se = p(s), ce = (e, t) => {
258
- const r = "width" in e ? e.width ?? 0 : 0, o = "height" in e ? e.height ?? 0 : 0, f = a.current.iChannelResolution;
259
- if (!f) return;
260
- const l = Array.isArray(f.value) ? f.value : f.value = [];
261
- l[t * 3] = r * b, l[t * 3 + 1] = o * b, l[t * 3 + 2] = 0;
262
- }, Me = () => {
263
- var e, t;
264
- u.current && (g.current = u.current.getContext("webgl", D) || u.current.getContext(
265
- "experimental-webgl",
266
- D
267
- ), (e = g.current) == null || e.getExtension("OES_standard_derivatives"), (t = g.current) == null || t.getExtension("EXT_shader_texture_lod"));
268
- }, Ie = () => {
269
- const e = g.current;
270
- j.current = (e == null ? void 0 : e.createBuffer()) ?? null, e == null || e.bindBuffer(e.ARRAY_BUFFER, j.current);
271
- const t = [1, 1, 0, -1, 1, 0, 1, -1, 0, -1, -1, 0];
272
- e == null || e.bufferData(e.ARRAY_BUFFER, new Float32Array(t), e.STATIC_DRAW);
273
- }, oe = ({ alpha: e, beta: t, gamma: r }) => {
274
- a.current.iDeviceOrientation.value = [
275
- e ?? 0,
276
- t ?? 0,
277
- r ?? 0,
278
- window.orientation ?? 0
279
- ];
280
- }, J = (e) => {
281
- var h, R, y, O;
282
- const [t = 0, r = 0] = Ae(e), o = t - (((h = U.current) == null ? void 0 : h.left) ?? 0) - window.pageXOffset, f = (((R = U.current) == null ? void 0 : R.height) ?? 0) - r - (((y = U.current) == null ? void 0 : y.top) ?? 0) - window.pageYOffset;
283
- Ue.current = !0;
284
- const l = Array.isArray((O = a.current.iMouse) == null ? void 0 : O.value) ? a.current.iMouse.value : void 0;
285
- l && (l[2] = o, l[3] = f), X.current[0] = o, X.current[1] = f;
286
- }, Z = (e) => {
287
- var l, h, R, y, O;
288
- U.current = (l = u.current) == null ? void 0 : l.getBoundingClientRect();
289
- const [t = 0, r = 0] = Ae(e), o = t - (((h = U.current) == null ? void 0 : h.left) ?? 0), f = (((R = U.current) == null ? void 0 : R.height) ?? 0) - r - (((y = U.current) == null ? void 0 : y.top) ?? 0);
290
- if (F !== 1)
291
- X.current[0] = o, X.current[1] = f;
292
- else {
293
- const Y = Array.isArray((O = a.current.iMouse) == null ? void 0 : O.value) ? a.current.iMouse.value : void 0;
294
- Y && (Y[0] = o, Y[1] = f);
295
- }
296
- }, $ = () => {
297
- var t;
298
- const e = Array.isArray((t = a.current.iMouse) == null ? void 0 : t.value) ? a.current.iMouse.value : void 0;
299
- e && (e[2] = 0, e[3] = 0);
300
- }, ee = () => {
301
- var f, l, h, R;
302
- const e = g.current;
303
- if (!e) return;
304
- U.current = (f = u.current) == null ? void 0 : f.getBoundingClientRect();
305
- const t = b, r = Math.floor((((l = U.current) == null ? void 0 : l.width) ?? 1) * t), o = Math.floor((((h = U.current) == null ? void 0 : h.height) ?? 1) * t);
306
- if (e.canvas.width = r, e.canvas.height = o, (R = a.current.iResolution) != null && R.isNeeded && m.current) {
307
- const y = e.getUniformLocation(m.current, Te);
308
- e.uniform2fv(y, [e.canvas.width, e.canvas.height]);
309
- }
310
- }, ue = (e, t) => {
311
- const r = g.current;
312
- if (!r) return null;
313
- const o = r.createShader(e);
314
- if (!o) return null;
315
- if (r.shaderSource(o, t), r.compileShader(o), !r.getShaderParameter(o, r.COMPILE_STATUS)) {
316
- I == null || I(N(`Error compiling the shader:
317
- ${t}`));
318
- const f = r.getShaderInfoLog(o);
319
- r.deleteShader(o), w == null || w(N(`Shader compiler log: ${f}`));
320
- }
321
- return o;
322
- }, Ne = (e, t) => {
323
- const r = g.current;
324
- if (!r) return;
325
- const o = ue(r.FRAGMENT_SHADER, e), f = ue(r.VERTEX_SHADER, t);
326
- if (m.current = r.createProgram(), !(!m.current || !f || !o)) {
327
- if (r.attachShader(m.current, f), r.attachShader(m.current, o), r.linkProgram(m.current), !r.getProgramParameter(m.current, r.LINK_STATUS)) {
328
- w == null || w(
329
- N(
330
- `Unable to initialize the shader program: ${r.getProgramInfoLog(m.current)}`
331
- )
332
- );
333
- return;
334
- }
335
- r.useProgram(m.current), z.current = r.getAttribLocation(
336
- m.current,
337
- "aVertexPosition"
338
- ), r.enableVertexAttribArray(z.current);
339
- }
340
- }, Se = () => {
341
- if (s)
342
- for (const e of Object.keys(s)) {
343
- const t = s[e];
344
- if (!t) continue;
345
- const { value: r, type: o } = t, f = Ke(o);
346
- if (!f) continue;
347
- const l = {};
348
- if (je(o, r)) {
349
- const h = o.length, R = Number.parseInt(o.charAt(h - 3)), y = Math.floor(r.length / (R * R));
350
- r.length > R * R && (l.arraySize = `[${y}]`);
351
- } else ze(o, r) && (l.arraySize = `[${Math.floor(r.length / Number.parseInt(o.charAt(0)))}]`);
352
- a.current[e] = { type: f, isNeeded: !1, value: r, ...l };
353
- }
354
- }, xe = () => {
355
- const e = g.current;
356
- if (e)
357
- if (n && n.length > 0) {
358
- a.current[`${Ee}`] = {
359
- type: "vec3",
360
- isNeeded: !1,
361
- arraySize: `[${n.length}]`,
362
- value: []
363
- };
364
- const t = n.map((r, o) => {
365
- var f;
366
- return a.current[`${He}${o}`] = {
367
- type: "sampler2D",
368
- isNeeded: !1
369
- }, ce(r, o), B.current[o] = new Qe(e), (f = B.current[o]) == null ? void 0 : f.load(r).then((l) => {
370
- ce(l, o);
371
- });
372
- });
373
- Promise.all(t).then(() => {
374
- M && M();
375
- }).catch((r) => {
376
- w == null || w(r), M && M();
377
- });
378
- } else M && M();
379
- }, Oe = (e) => {
380
- const t = de.includes(L ?? "highp"), r = `precision ${t ? L : de[1]} float;
381
- `;
382
- t || I == null || I(
383
- N(
384
- `wrong precision type ${L}, please make sure to pass one of a valid precision lowp, mediump, highp, by default you shader precision will be set to highp.`
385
- )
386
- );
387
- let o = r.concat(`#define DPR ${b.toFixed(1)}
388
- `).concat(e.replace(/texture\(/g, "texture2D("));
389
- for (const l of Object.keys(a.current))
390
- if (e.includes(l)) {
391
- const h = a.current[l];
392
- if (!h) continue;
393
- o = Je(
394
- o,
395
- `uniform ${h.type} ${l}${h.arraySize || ""};
396
- `,
397
- o.lastIndexOf(r) + r.length
398
- ), h.isNeeded = !0;
399
- }
400
- return e.includes("mainImage") && (o = o.concat(Ye)), o;
401
- }, Pe = (e) => {
402
- var f, l, h, R, y, O, Y, ae, fe;
403
- const t = g.current;
404
- if (!t || !m.current) return;
405
- const r = !_.current && W.current ? (e - W.current) / 1e3 : 0;
406
- W.current = e;
407
- const o = se.current;
408
- if (o)
409
- for (const d of Object.keys(o)) {
410
- const A = o[d];
411
- if (A && (f = a.current[d]) != null && f.isNeeded) {
412
- if (!m.current) return;
413
- const G = t.getUniformLocation(m.current, d);
414
- if (!G) return;
415
- qe(
416
- t,
417
- G,
418
- A.type,
419
- A.value
420
- );
421
- }
422
- }
423
- if ((l = a.current.iMouse) != null && l.isNeeded) {
424
- const d = t.getUniformLocation(m.current, ge);
425
- t.uniform4fv(d, a.current.iMouse.value);
426
- }
427
- if ((h = a.current.iChannelResolution) != null && h.isNeeded) {
428
- const d = t.getUniformLocation(
429
- m.current,
430
- Ee
431
- );
432
- t.uniform3fv(d, a.current.iChannelResolution.value);
433
- }
434
- if ((R = a.current.iDeviceOrientation) != null && R.isNeeded) {
435
- const d = t.getUniformLocation(
436
- m.current,
437
- Re
438
- );
439
- t.uniform4fv(
440
- d,
441
- a.current.iDeviceOrientation.value
442
- );
443
- }
444
- if ((y = a.current.iTime) != null && y.isNeeded) {
445
- const d = t.getUniformLocation(m.current, le);
446
- t.uniform1f(d, Fe.current += r);
447
- }
448
- if ((O = a.current.iTimeDelta) != null && O.isNeeded) {
449
- const d = t.getUniformLocation(m.current, he);
450
- t.uniform1f(d, r);
451
- }
452
- if ((Y = a.current.iDate) != null && Y.isNeeded) {
453
- const d = /* @__PURE__ */ new Date(), A = d.getMonth() + 1, G = d.getDate(), k = d.getFullYear(), te = d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds() + d.getMilliseconds() * 1e-3, ne = t.getUniformLocation(m.current, ve);
454
- t.uniform4fv(ne, [k, A, G, te]);
455
- }
456
- if ((ae = a.current.iFrame) != null && ae.isNeeded) {
457
- const d = t.getUniformLocation(m.current, pe), A = a.current.iFrame.value;
458
- t.uniform1i(d, A), a.current.iFrame.value = A + 1;
459
- }
460
- if (B.current.length > 0)
461
- for (let d = 0; d < B.current.length; d++) {
462
- const A = B.current[d];
463
- if (!A) return;
464
- const { isVideo: G, _webglTexture: k, source: te, flipY: ne, isLoaded: Ce } = A;
465
- if (!Ce || !k || !te) return;
466
- if ((fe = a.current[`iChannel${d}`]) != null && fe.isNeeded) {
467
- if (!m.current) return;
468
- const Xe = t.getUniformLocation(m.current, `iChannel${d}`);
469
- t.activeTexture(t.TEXTURE0 + d), t.bindTexture(t.TEXTURE_2D, k), t.uniform1i(Xe, d), G && A.updateTexture(k, te, ne);
470
- }
471
- }
472
- }, V = (e) => {
473
- var o, f;
474
- const t = g.current;
475
- if (!t) return;
476
- t.viewport(0, 0, t.drawingBufferWidth, t.drawingBufferHeight), t.clear(t.COLOR_BUFFER_BIT | t.DEPTH_BUFFER_BIT), t.bindBuffer(t.ARRAY_BUFFER, j.current), t.vertexAttribPointer(z.current ?? 0, 3, t.FLOAT, !1, 0, 0), Pe(e), t.drawArrays(t.TRIANGLE_STRIP, 0, 4);
477
- const r = (o = a.current.iMouse) == null ? void 0 : o.value;
478
- if ((f = a.current.iMouse) != null && f.isNeeded && F !== 1 && Array.isArray(r)) {
479
- const l = r[0] ?? 0, h = r[1] ?? 0;
480
- r[0] = Le(l, X.current[0] ?? 0, F), r[1] = Le(h, X.current[1] ?? 0, F);
481
- }
482
- !_.current && (K.current || x.current) && (E.current = requestAnimationFrame(V));
483
- }, De = () => {
484
- var t, r;
485
- const e = { passive: !0 };
486
- (t = a.current.iMouse) != null && t.isNeeded && u.current && (u.current.addEventListener("mousemove", Z, e), u.current.addEventListener("mouseout", $, e), u.current.addEventListener("mouseup", $, e), u.current.addEventListener("mousedown", J, e), u.current.addEventListener("touchmove", Z, e), u.current.addEventListener("touchend", $, e), u.current.addEventListener("touchstart", J, e)), (r = a.current.iDeviceOrientation) != null && r.isNeeded && window.addEventListener("deviceorientation", oe, e), u.current && (Q.current = new ResizeObserver(ee), Q.current.observe(u.current), window.addEventListener("resize", ee, e));
487
- }, be = () => {
488
- var t, r;
489
- const e = { passive: !0 };
490
- (t = a.current.iMouse) != null && t.isNeeded && u.current && (u.current.removeEventListener("mousemove", Z, e), u.current.removeEventListener("mouseout", $, e), u.current.removeEventListener("mouseup", $, e), u.current.removeEventListener("mousedown", J, e), u.current.removeEventListener("touchmove", Z, e), u.current.removeEventListener("touchend", $, e), u.current.removeEventListener("touchstart", J, e)), (r = a.current.iDeviceOrientation) != null && r.isNeeded && window.removeEventListener("deviceorientation", oe, e), Q.current && (Q.current.disconnect(), window.removeEventListener("resize", ee, e));
491
- };
492
- return q(() => {
493
- se.current = s, _.current && g.current && (E.current = requestAnimationFrame(V));
494
- }, [s]), q(() => {
495
- const e = _.current;
496
- _.current = P, !P && e && g.current ? (W.current = performance.now(), E.current = requestAnimationFrame(V)) : P && g.current && (E.current = requestAnimationFrame(V));
497
- }, [P]), q(() => {
498
- K.current = S, S && (x.current = !0);
499
- }, [S]), q(() => {
500
- if (S || !u.current) return;
501
- const e = u.current, t = new IntersectionObserver(
502
- (r) => {
503
- for (const o of r)
504
- x.current = o.isIntersecting, o.isIntersecting && !_.current && requestAnimationFrame(V);
505
- },
506
- { threshold: 0 }
507
- );
508
- return t.observe(e), () => t.disconnect();
509
- }, [S]), q(() => {
510
- const e = B.current;
511
- function t() {
512
- Me();
513
- const r = g.current;
514
- r && u.current && (r.clearColor(...T), r.clearDepth(1), r.enable(r.DEPTH_TEST), r.depthFunc(r.LEQUAL), r.viewport(0, 0, u.current.width, u.current.height), u.current.height = u.current.clientHeight, u.current.width = u.current.clientWidth, Se(), xe(), Ne(Oe(c || Ge), i || me), Ie(), requestAnimationFrame(V), De(), ee());
515
- }
516
- return C.current = requestAnimationFrame(t), () => {
517
- var o;
518
- const r = g.current;
519
- if (r) {
520
- if ((o = r.getExtension("WEBGL_lose_context")) == null || o.loseContext(), r.useProgram(null), r.deleteProgram(m.current ?? null), e.length > 0)
521
- for (const f of e)
522
- r.deleteTexture(f._webglTexture);
523
- m.current = null;
524
- }
525
- be(), cancelAnimationFrame(C.current ?? 0), cancelAnimationFrame(E.current ?? 0);
526
- };
527
- }, []), /* @__PURE__ */ Ve("canvas", { ref: u, style: H, ...re });
528
- }
529
- export {
530
- rt as ReactShaderToy
531
- };