@react-three/test-renderer 7.0.7

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.
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./react-three-test-renderer.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./react-three-test-renderer.cjs.dev.js");
7
+ }
@@ -0,0 +1,728 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fiber = require('@react-three/fiber');
6
+
7
+ const lowerCaseFirstLetter = str => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
8
+ const toEventHandlerName = eventName => `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
9
+
10
+ const treeObjectFactory = (type, props, children) => ({
11
+ type,
12
+ props,
13
+ children
14
+ });
15
+
16
+ const toTreeBranch = obj => obj.map(child => {
17
+ return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), { ...child.__r3f.memoizedProps
18
+ }, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
19
+ });
20
+
21
+ const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), { ...obj.__r3f.memoizedProps
22
+ }, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
23
+
24
+ const graphObjectFactory = (type, name, children) => ({
25
+ type,
26
+ name,
27
+ children
28
+ });
29
+
30
+ const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
31
+
32
+ const is = {
33
+ obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
34
+ fun: a => typeof a === 'function',
35
+ str: a => typeof a === 'string',
36
+ num: a => typeof a === 'number',
37
+ und: a => a === void 0,
38
+ arr: a => Array.isArray(a),
39
+
40
+ equ(a, b) {
41
+ // Wrong type or one of the two undefined, doesn't match
42
+ if (typeof a !== typeof b || !!a !== !!b) return false; // Atomic, just compare a against b
43
+
44
+ if (is.str(a) || is.num(a) || is.obj(a)) return a === b; // Array, shallow compare first to see if it's a match
45
+
46
+ if (is.arr(a) && a == b) return true; // Last resort, go through keys
47
+
48
+ let i;
49
+
50
+ for (i in a) if (!(i in b)) return false;
51
+
52
+ for (i in b) if (a[i] !== b[i]) return false;
53
+
54
+ return is.und(i) ? a === b : true;
55
+ }
56
+
57
+ };
58
+
59
+ const createCanvas = ({
60
+ beforeReturn,
61
+ width = 1280,
62
+ height = 800
63
+ } = {}) => {
64
+ const canvas = document.createElement('canvas');
65
+ canvas.height = height;
66
+ canvas.width = width;
67
+
68
+ canvas.addEventListener = () => {};
69
+
70
+ canvas.removeEventListener = () => {};
71
+
72
+ if (beforeReturn) {
73
+ beforeReturn(canvas);
74
+ }
75
+
76
+ return canvas;
77
+ };
78
+
79
+ const functions = ['attachShader', 'bindAttribLocation', 'bindBuffer', 'bindFramebuffer', 'bindRenderbuffer', 'bindTexture', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clear', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'compileShader', 'compressedTexImage2D', 'compressedTexSubImage2D', 'copyTexImage2D', 'copyTexSubImage2D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createRenderbuffer', 'createShader', 'createTexture', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteRenderbuffer', 'deleteShader', 'deleteTexture', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'disableVertexAttribArray', 'drawArrays', 'drawElements', 'enable', 'enableVertexAttribArray', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getContextAttributes', 'getError', 'getFramebufferAttachmentParameter', 'getProgramParameter', 'getRenderbufferParameter', 'getShaderParameter', 'getShaderSource', 'getSupportedExtensions', 'getTexParameter', 'getUniform', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isRenderbuffer', 'isShader', 'isTexture', 'lineWidth', 'linkProgram', 'pixelStorei', 'polygonOffset', 'readPixels', 'renderbufferStorage', 'sampleCoverage', 'scissor', 'setPixelRatio', 'setSize', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texParameterf', 'texParameteri', 'texImage2D', 'texSubImage2D', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniformMatrix2fv', 'uniformMatrix3fv', 'uniformMatrix4fv', 'useProgram', 'validateProgram', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribPointer', 'viewport'];
80
+ const enums = {
81
+ DEPTH_BUFFER_BIT: 256,
82
+ STENCIL_BUFFER_BIT: 1024,
83
+ COLOR_BUFFER_BIT: 16384,
84
+ POINTS: 0,
85
+ LINES: 1,
86
+ LINE_LOOP: 2,
87
+ LINE_STRIP: 3,
88
+ TRIANGLES: 4,
89
+ TRIANGLE_STRIP: 5,
90
+ TRIANGLE_FAN: 6,
91
+ ZERO: 0,
92
+ ONE: 1,
93
+ SRC_COLOR: 768,
94
+ ONE_MINUS_SRC_COLOR: 769,
95
+ SRC_ALPHA: 770,
96
+ ONE_MINUS_SRC_ALPHA: 771,
97
+ DST_ALPHA: 772,
98
+ ONE_MINUS_DST_ALPHA: 773,
99
+ DST_COLOR: 774,
100
+ ONE_MINUS_DST_COLOR: 775,
101
+ SRC_ALPHA_SATURATE: 776,
102
+ FUNC_ADD: 32774,
103
+ BLEND_EQUATION: 32777,
104
+ BLEND_EQUATION_RGB: 32777,
105
+ BLEND_EQUATION_ALPHA: 34877,
106
+ FUNC_SUBTRACT: 32778,
107
+ FUNC_REVERSE_SUBTRACT: 32779,
108
+ BLEND_DST_RGB: 32968,
109
+ BLEND_SRC_RGB: 32969,
110
+ BLEND_DST_ALPHA: 32970,
111
+ BLEND_SRC_ALPHA: 32971,
112
+ CONSTANT_COLOR: 32769,
113
+ ONE_MINUS_CONSTANT_COLOR: 32770,
114
+ CONSTANT_ALPHA: 32771,
115
+ ONE_MINUS_CONSTANT_ALPHA: 32772,
116
+ BLEND_COLOR: 32773,
117
+ ARRAY_BUFFER: 34962,
118
+ ELEMENT_ARRAY_BUFFER: 34963,
119
+ ARRAY_BUFFER_BINDING: 34964,
120
+ ELEMENT_ARRAY_BUFFER_BINDING: 34965,
121
+ STREAM_DRAW: 35040,
122
+ STATIC_DRAW: 35044,
123
+ DYNAMIC_DRAW: 35048,
124
+ BUFFER_SIZE: 34660,
125
+ BUFFER_USAGE: 34661,
126
+ CURRENT_VERTEX_ATTRIB: 34342,
127
+ FRONT: 1028,
128
+ BACK: 1029,
129
+ FRONT_AND_BACK: 1032,
130
+ TEXTURE_2D: 3553,
131
+ CULL_FACE: 2884,
132
+ BLEND: 3042,
133
+ DITHER: 3024,
134
+ STENCIL_TEST: 2960,
135
+ DEPTH_TEST: 2929,
136
+ SCISSOR_TEST: 3089,
137
+ POLYGON_OFFSET_FILL: 32823,
138
+ SAMPLE_ALPHA_TO_COVERAGE: 32926,
139
+ SAMPLE_COVERAGE: 32928,
140
+ NO_ERROR: 0,
141
+ INVALID_ENUM: 1280,
142
+ INVALID_VALUE: 1281,
143
+ INVALID_OPERATION: 1282,
144
+ OUT_OF_MEMORY: 1285,
145
+ CW: 2304,
146
+ CCW: 2305,
147
+ LINE_WIDTH: 2849,
148
+ ALIASED_POINT_SIZE_RANGE: 33901,
149
+ ALIASED_LINE_WIDTH_RANGE: 33902,
150
+ CULL_FACE_MODE: 2885,
151
+ FRONT_FACE: 2886,
152
+ DEPTH_RANGE: 2928,
153
+ DEPTH_WRITEMASK: 2930,
154
+ DEPTH_CLEAR_VALUE: 2931,
155
+ DEPTH_FUNC: 2932,
156
+ STENCIL_CLEAR_VALUE: 2961,
157
+ STENCIL_FUNC: 2962,
158
+ STENCIL_FAIL: 2964,
159
+ STENCIL_PASS_DEPTH_FAIL: 2965,
160
+ STENCIL_PASS_DEPTH_PASS: 2966,
161
+ STENCIL_REF: 2967,
162
+ STENCIL_VALUE_MASK: 2963,
163
+ STENCIL_WRITEMASK: 2968,
164
+ STENCIL_BACK_FUNC: 34816,
165
+ STENCIL_BACK_FAIL: 34817,
166
+ STENCIL_BACK_PASS_DEPTH_FAIL: 34818,
167
+ STENCIL_BACK_PASS_DEPTH_PASS: 34819,
168
+ STENCIL_BACK_REF: 36003,
169
+ STENCIL_BACK_VALUE_MASK: 36004,
170
+ STENCIL_BACK_WRITEMASK: 36005,
171
+ VIEWPORT: 2978,
172
+ SCISSOR_BOX: 3088,
173
+ COLOR_CLEAR_VALUE: 3106,
174
+ COLOR_WRITEMASK: 3107,
175
+ UNPACK_ALIGNMENT: 3317,
176
+ PACK_ALIGNMENT: 3333,
177
+ MAX_TEXTURE_SIZE: 3379,
178
+ MAX_VIEWPORT_DIMS: 3386,
179
+ SUBPIXEL_BITS: 3408,
180
+ RED_BITS: 3410,
181
+ GREEN_BITS: 3411,
182
+ BLUE_BITS: 3412,
183
+ ALPHA_BITS: 3413,
184
+ DEPTH_BITS: 3414,
185
+ STENCIL_BITS: 3415,
186
+ POLYGON_OFFSET_UNITS: 10752,
187
+ POLYGON_OFFSET_FACTOR: 32824,
188
+ TEXTURE_BINDING_2D: 32873,
189
+ SAMPLE_BUFFERS: 32936,
190
+ SAMPLES: 32937,
191
+ SAMPLE_COVERAGE_VALUE: 32938,
192
+ SAMPLE_COVERAGE_INVERT: 32939,
193
+ COMPRESSED_TEXTURE_FORMATS: 34467,
194
+ DONT_CARE: 4352,
195
+ FASTEST: 4353,
196
+ NICEST: 4354,
197
+ GENERATE_MIPMAP_HINT: 33170,
198
+ BYTE: 5120,
199
+ UNSIGNED_BYTE: 5121,
200
+ SHORT: 5122,
201
+ UNSIGNED_SHORT: 5123,
202
+ INT: 5124,
203
+ UNSIGNED_INT: 5125,
204
+ FLOAT: 5126,
205
+ DEPTH_COMPONENT: 6402,
206
+ ALPHA: 6406,
207
+ RGB: 6407,
208
+ RGBA: 6408,
209
+ LUMINANCE: 6409,
210
+ LUMINANCE_ALPHA: 6410,
211
+ UNSIGNED_SHORT_4_4_4_4: 32819,
212
+ UNSIGNED_SHORT_5_5_5_1: 32820,
213
+ UNSIGNED_SHORT_5_6_5: 33635,
214
+ FRAGMENT_SHADER: 35632,
215
+ VERTEX_SHADER: 35633,
216
+ MAX_VERTEX_ATTRIBS: 34921,
217
+ MAX_VERTEX_UNIFORM_VECTORS: 36347,
218
+ MAX_VARYING_VECTORS: 36348,
219
+ MAX_COMBINED_TEXTURE_IMAGE_UNITS: 35661,
220
+ MAX_VERTEX_TEXTURE_IMAGE_UNITS: 35660,
221
+ MAX_TEXTURE_IMAGE_UNITS: 34930,
222
+ MAX_FRAGMENT_UNIFORM_VECTORS: 36349,
223
+ SHADER_TYPE: 35663,
224
+ DELETE_STATUS: 35712,
225
+ LINK_STATUS: 35714,
226
+ VALIDATE_STATUS: 35715,
227
+ ATTACHED_SHADERS: 35717,
228
+ ACTIVE_UNIFORMS: 35718,
229
+ ACTIVE_ATTRIBUTES: 35721,
230
+ SHADING_LANGUAGE_VERSION: 35724,
231
+ CURRENT_PROGRAM: 35725,
232
+ NEVER: 512,
233
+ LESS: 513,
234
+ EQUAL: 514,
235
+ LEQUAL: 515,
236
+ GREATER: 516,
237
+ NOTEQUAL: 517,
238
+ GEQUAL: 518,
239
+ ALWAYS: 519,
240
+ KEEP: 7680,
241
+ REPLACE: 7681,
242
+ INCR: 7682,
243
+ DECR: 7683,
244
+ INVERT: 5386,
245
+ INCR_WRAP: 34055,
246
+ DECR_WRAP: 34056,
247
+ VENDOR: 7936,
248
+ RENDERER: 7937,
249
+ VERSION: 7938,
250
+ NEAREST: 9728,
251
+ LINEAR: 9729,
252
+ NEAREST_MIPMAP_NEAREST: 9984,
253
+ LINEAR_MIPMAP_NEAREST: 9985,
254
+ NEAREST_MIPMAP_LINEAR: 9986,
255
+ LINEAR_MIPMAP_LINEAR: 9987,
256
+ TEXTURE_MAG_FILTER: 10240,
257
+ TEXTURE_MIN_FILTER: 10241,
258
+ TEXTURE_WRAP_S: 10242,
259
+ TEXTURE_WRAP_T: 10243,
260
+ TEXTURE: 5890,
261
+ TEXTURE_CUBE_MAP: 34067,
262
+ TEXTURE_BINDING_CUBE_MAP: 34068,
263
+ TEXTURE_CUBE_MAP_POSITIVE_X: 34069,
264
+ TEXTURE_CUBE_MAP_NEGATIVE_X: 34070,
265
+ TEXTURE_CUBE_MAP_POSITIVE_Y: 34071,
266
+ TEXTURE_CUBE_MAP_NEGATIVE_Y: 34072,
267
+ TEXTURE_CUBE_MAP_POSITIVE_Z: 34073,
268
+ TEXTURE_CUBE_MAP_NEGATIVE_Z: 34074,
269
+ MAX_CUBE_MAP_TEXTURE_SIZE: 34076,
270
+ TEXTURE0: 33984,
271
+ TEXTURE1: 33985,
272
+ TEXTURE2: 33986,
273
+ TEXTURE3: 33987,
274
+ TEXTURE4: 33988,
275
+ TEXTURE5: 33989,
276
+ TEXTURE6: 33990,
277
+ TEXTURE7: 33991,
278
+ TEXTURE8: 33992,
279
+ TEXTURE9: 33993,
280
+ TEXTURE10: 33994,
281
+ TEXTURE11: 33995,
282
+ TEXTURE12: 33996,
283
+ TEXTURE13: 33997,
284
+ TEXTURE14: 33998,
285
+ TEXTURE15: 33999,
286
+ TEXTURE16: 34000,
287
+ TEXTURE17: 34001,
288
+ TEXTURE18: 34002,
289
+ TEXTURE19: 34003,
290
+ TEXTURE20: 34004,
291
+ TEXTURE21: 34005,
292
+ TEXTURE22: 34006,
293
+ TEXTURE23: 34007,
294
+ TEXTURE24: 34008,
295
+ TEXTURE25: 34009,
296
+ TEXTURE26: 34010,
297
+ TEXTURE27: 34011,
298
+ TEXTURE28: 34012,
299
+ TEXTURE29: 34013,
300
+ TEXTURE30: 34014,
301
+ TEXTURE31: 34015,
302
+ ACTIVE_TEXTURE: 34016,
303
+ REPEAT: 10497,
304
+ CLAMP_TO_EDGE: 33071,
305
+ MIRRORED_REPEAT: 33648,
306
+ FLOAT_VEC2: 35664,
307
+ FLOAT_VEC3: 35665,
308
+ FLOAT_VEC4: 35666,
309
+ INT_VEC2: 35667,
310
+ INT_VEC3: 35668,
311
+ INT_VEC4: 35669,
312
+ BOOL: 35670,
313
+ BOOL_VEC2: 35671,
314
+ BOOL_VEC3: 35672,
315
+ BOOL_VEC4: 35673,
316
+ FLOAT_MAT2: 35674,
317
+ FLOAT_MAT3: 35675,
318
+ FLOAT_MAT4: 35676,
319
+ SAMPLER_2D: 35678,
320
+ SAMPLER_CUBE: 35680,
321
+ VERTEX_ATTRIB_ARRAY_ENABLED: 34338,
322
+ VERTEX_ATTRIB_ARRAY_SIZE: 34339,
323
+ VERTEX_ATTRIB_ARRAY_STRIDE: 34340,
324
+ VERTEX_ATTRIB_ARRAY_TYPE: 34341,
325
+ VERTEX_ATTRIB_ARRAY_NORMALIZED: 34922,
326
+ VERTEX_ATTRIB_ARRAY_POINTER: 34373,
327
+ VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 34975,
328
+ IMPLEMENTATION_COLOR_READ_TYPE: 35738,
329
+ IMPLEMENTATION_COLOR_READ_FORMAT: 35739,
330
+ COMPILE_STATUS: 35713,
331
+ LOW_FLOAT: 36336,
332
+ MEDIUM_FLOAT: 36337,
333
+ HIGH_FLOAT: 36338,
334
+ LOW_INT: 36339,
335
+ MEDIUM_INT: 36340,
336
+ HIGH_INT: 36341,
337
+ FRAMEBUFFER: 36160,
338
+ RENDERBUFFER: 36161,
339
+ RGBA4: 32854,
340
+ RGB5_A1: 32855,
341
+ RGB565: 36194,
342
+ DEPTH_COMPONENT16: 33189,
343
+ STENCIL_INDEX: 6401,
344
+ STENCIL_INDEX8: 36168,
345
+ DEPTH_STENCIL: 34041,
346
+ RENDERBUFFER_WIDTH: 36162,
347
+ RENDERBUFFER_HEIGHT: 36163,
348
+ RENDERBUFFER_INTERNAL_FORMAT: 36164,
349
+ RENDERBUFFER_RED_SIZE: 36176,
350
+ RENDERBUFFER_GREEN_SIZE: 36177,
351
+ RENDERBUFFER_BLUE_SIZE: 36178,
352
+ RENDERBUFFER_ALPHA_SIZE: 36179,
353
+ RENDERBUFFER_DEPTH_SIZE: 36180,
354
+ RENDERBUFFER_STENCIL_SIZE: 36181,
355
+ FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 36048,
356
+ FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 36049,
357
+ FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: 36050,
358
+ FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: 36051,
359
+ COLOR_ATTACHMENT0: 36064,
360
+ DEPTH_ATTACHMENT: 36096,
361
+ STENCIL_ATTACHMENT: 36128,
362
+ DEPTH_STENCIL_ATTACHMENT: 33306,
363
+ NONE: 0,
364
+ FRAMEBUFFER_COMPLETE: 36053,
365
+ FRAMEBUFFER_INCOMPLETE_ATTACHMENT: 36054,
366
+ FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: 36055,
367
+ FRAMEBUFFER_INCOMPLETE_DIMENSIONS: 36057,
368
+ FRAMEBUFFER_UNSUPPORTED: 36061,
369
+ FRAMEBUFFER_BINDING: 36006,
370
+ RENDERBUFFER_BINDING: 36007,
371
+ MAX_RENDERBUFFER_SIZE: 34024,
372
+ INVALID_FRAMEBUFFER_OPERATION: 1286,
373
+ UNPACK_FLIP_Y_WEBGL: 37440,
374
+ UNPACK_PREMULTIPLY_ALPHA_WEBGL: 37441,
375
+ CONTEXT_LOST_WEBGL: 37442,
376
+ UNPACK_COLORSPACE_CONVERSION_WEBGL: 37443,
377
+ BROWSER_DEFAULT_WEBGL: 37444
378
+ };
379
+ const extensions = {
380
+ // ratified
381
+ OES_texture_float: {},
382
+ OES_texture_half_float: {},
383
+ WEBGL_lose_context: {
384
+ loseContext: () => {}
385
+ },
386
+ OES_standard_derivatives: {},
387
+ OES_vertex_array_object: {
388
+ createVertexArrayOES: () => {},
389
+ bindVertexArrayOES: () => {},
390
+ deleteVertexArrayOES: () => {}
391
+ },
392
+ WEBGL_debug_renderer_info: null,
393
+ WEBGL_debug_shaders: null,
394
+ WEBGL_compressed_texture_s3tc: null,
395
+ WEBGL_depth_texture: {},
396
+ OES_element_index_uint: {},
397
+ EXT_texture_filter_anisotropic: null,
398
+ EXT_frag_depth: {},
399
+ WEBGL_draw_buffers: {},
400
+ ANGLE_instanced_arrays: null,
401
+ OES_texture_float_linear: null,
402
+ OES_texture_half_float_linear: null,
403
+ EXT_blend_minmax: {
404
+ MIN_EXT: 0,
405
+ MAX_EXT: 0
406
+ },
407
+ EXT_shader_texture_lod: null,
408
+ // community
409
+ WEBGL_compressed_texture_atc: null,
410
+ WEBGL_compressed_texture_pvrtc: null,
411
+ EXT_color_buffer_half_float: null,
412
+ WEBGL_color_buffer_float: null,
413
+ EXT_sRGB: null,
414
+ WEBGL_compressed_texture_etc1: null
415
+ };
416
+
417
+ class WebGLRenderingContext {
418
+ constructor(canvas) {
419
+ this.getShaderPrecisionFormat = () => {
420
+ return {
421
+ rangeMin: 127,
422
+ rangeMax: 127,
423
+ precision: 23
424
+ };
425
+ };
426
+
427
+ this.GL_VERSION = 7938;
428
+ this.SCISSOR_BOX = 3088;
429
+ this.VIEWPORT = 2978;
430
+
431
+ this.getParameter = paramId => {
432
+ switch (paramId) {
433
+ case this.GL_VERSION:
434
+ return ['WebGL1'];
435
+
436
+ case this.SCISSOR_BOX:
437
+ case this.VIEWPORT:
438
+ return [0, 0, 1, 1];
439
+ }
440
+ };
441
+
442
+ this.getExtension = ext => {
443
+ return extensions[ext];
444
+ };
445
+
446
+ this.getProgramInfoLog = () => '';
447
+
448
+ this.getShaderInfoLog = () => '';
449
+
450
+ this.canvas = canvas;
451
+ this.drawingBufferWidth = canvas.width;
452
+ this.drawingBufferHeight = canvas.height;
453
+ functions.forEach(func => {
454
+ this[func] = () => {
455
+ return {};
456
+ };
457
+ });
458
+ Object.keys(enums).forEach(key => {
459
+ this[key] = enums[key];
460
+ });
461
+ }
462
+
463
+ }
464
+
465
+ const createWebGLContext = canvas => new WebGLRenderingContext(canvas);
466
+
467
+ const createEventFirer = (act, store) => {
468
+ const findEventHandler = (element, eventName) => {
469
+ const eventHandlerName = toEventHandlerName(eventName);
470
+ const props = element.props;
471
+
472
+ if (typeof props[eventHandlerName] === 'function') {
473
+ return props[eventHandlerName];
474
+ }
475
+
476
+ if (typeof props[eventName] === 'function') {
477
+ return props[eventName];
478
+ }
479
+
480
+ console.warn(`Handler for ${eventName} was not found. You must pass event names in camelCase or name of the handler https://github.com/pmndrs/react-three-fiber/blob/master/packages/test-renderer/markdown/rttr.md#create-fireevent`);
481
+ return null;
482
+ };
483
+
484
+ const createSyntheticEvent = (element, data) => {
485
+ const raycastEvent = {
486
+ camera: store.getState().camera,
487
+ stopPropagation: () => {},
488
+ target: element,
489
+ currentTarget: element,
490
+ sourceEvent: data,
491
+ ...data
492
+ };
493
+ return raycastEvent;
494
+ };
495
+
496
+ const invokeEvent = async (element, eventName, data) => {
497
+ const handler = findEventHandler(element, eventName);
498
+
499
+ if (!handler) {
500
+ return;
501
+ }
502
+
503
+ let returnValue;
504
+ await act(async () => {
505
+ returnValue = handler(createSyntheticEvent(element, data));
506
+ });
507
+ return returnValue;
508
+ };
509
+
510
+ const fireEvent = async (element, eventName, data = {}) => await invokeEvent(element, eventName, data);
511
+
512
+ return fireEvent;
513
+ };
514
+
515
+ const expectOne = (items, msg) => {
516
+ if (items.length === 1) {
517
+ return items[0];
518
+ }
519
+
520
+ const prefix = items.length === 0 ? 'RTTR: No instances found' : `RTTR: Expected 1 but found ${items.length} instances`;
521
+ throw new Error(`${prefix} ${msg}`);
522
+ };
523
+ const matchProps = (props, filter) => {
524
+ for (const key in filter) {
525
+ if (props[key] !== filter[key]) {
526
+ return false;
527
+ }
528
+ }
529
+
530
+ return true;
531
+ };
532
+ const findAll = (root, decider) => {
533
+ const results = [];
534
+
535
+ if (decider(root)) {
536
+ results.push(root);
537
+ }
538
+
539
+ root.allChildren.forEach(child => {
540
+ results.push(...findAll(child, decider));
541
+ });
542
+ return results;
543
+ };
544
+
545
+ class ReactThreeTestInstance {
546
+ constructor(_fiber) {
547
+ this.getChildren = (fiber, opts = {
548
+ exhaustive: false
549
+ }) => {
550
+ if (opts.exhaustive) {
551
+ /**
552
+ * this will return objects like
553
+ * color or effects etc.
554
+ */
555
+ return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
556
+ } else {
557
+ return (fiber.children || []).map(fib => wrapFiber(fib));
558
+ }
559
+ };
560
+
561
+ this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
562
+
563
+ this.findAll = decider => findAll(this, decider);
564
+
565
+ this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
566
+
567
+ this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
568
+
569
+ this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
570
+
571
+ this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
572
+
573
+ this._fiber = _fiber;
574
+ }
575
+
576
+ get instance() {
577
+ return this._fiber;
578
+ }
579
+
580
+ get type() {
581
+ return this._fiber.type;
582
+ }
583
+
584
+ get props() {
585
+ return this._fiber.__r3f.memoizedProps;
586
+ }
587
+
588
+ get parent() {
589
+ const parent = this._fiber.parent;
590
+
591
+ if (parent !== null) {
592
+ return wrapFiber(parent);
593
+ }
594
+
595
+ return parent;
596
+ }
597
+
598
+ get children() {
599
+ return this.getChildren(this._fiber);
600
+ }
601
+
602
+ get allChildren() {
603
+ return this.getChildren(this._fiber, {
604
+ exhaustive: true
605
+ });
606
+ }
607
+
608
+ }
609
+ const fiberToWrapper = new WeakMap();
610
+ const wrapFiber = fiber => {
611
+ let wrapper = fiberToWrapper.get(fiber);
612
+
613
+ if (wrapper === undefined) {
614
+ wrapper = new ReactThreeTestInstance(fiber);
615
+ fiberToWrapper.set(fiber, wrapper);
616
+ }
617
+
618
+ return wrapper;
619
+ };
620
+
621
+ var index$1 = /*#__PURE__*/Object.freeze({
622
+ __proto__: null,
623
+ ReactThreeTestInstance: ReactThreeTestInstance
624
+ });
625
+
626
+ const create = async (element, options) => {
627
+ const canvas = createCanvas({
628
+ width: options == null ? void 0 : options.width,
629
+ height: options == null ? void 0 : options.height,
630
+ beforeReturn: canvas => {
631
+ //@ts-ignore
632
+ canvas.getContext = type => {
633
+ if (type === 'webgl' || type === 'webgl2') {
634
+ return createWebGLContext(canvas);
635
+ }
636
+ };
637
+ }
638
+ });
639
+ const _fiber = canvas;
640
+ let scene = null;
641
+ await fiber.reconciler.act(async () => {
642
+ scene = fiber.render(element, _fiber, {
643
+ frameloop: 'never',
644
+ ...options,
645
+ events: undefined
646
+ }).getState().scene;
647
+ });
648
+ const _store = fiber._roots.get(_fiber).store;
649
+ return {
650
+ scene: wrapFiber(scene),
651
+ unmount: async () => {
652
+ await fiber.reconciler.act(async () => {
653
+ fiber.unmountComponentAtNode(_fiber);
654
+ });
655
+ },
656
+ getInstance: () => {
657
+ var _mockRoots$get;
658
+
659
+ // this is our root
660
+ const fiber$1 = (_mockRoots$get = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get.fiber;
661
+ const root = {
662
+ /**
663
+ * we wrap our child in a Provider component
664
+ * and context.Provider, so do a little
665
+ * artificial dive to get round this and
666
+ * pass context.Provider as if it was the
667
+ * actual react root
668
+ */
669
+ current: fiber$1.current.child.child
670
+ };
671
+
672
+ if (fiber$1.current.child.child) {
673
+ /**
674
+ * so this actually returns the instance
675
+ * the user has passed through as a Fiber
676
+ */
677
+ return fiber.reconciler.getPublicRootInstance(root);
678
+ } else {
679
+ return null;
680
+ }
681
+ },
682
+ update: async newElement => {
683
+ var _mockRoots$get2;
684
+
685
+ const fiber$1 = (_mockRoots$get2 = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get2.fiber;
686
+
687
+ if (fiber$1) {
688
+ await fiber.reconciler.act(async () => {
689
+ fiber.reconciler.updateContainer(newElement, fiber$1, null, () => null);
690
+ });
691
+ }
692
+
693
+ return;
694
+ },
695
+ toTree: () => {
696
+ return toTree(scene);
697
+ },
698
+ toGraph: () => {
699
+ return toGraph(scene);
700
+ },
701
+ fireEvent: createEventFirer(fiber.reconciler.act, _store),
702
+ advanceFrames: async (frames, delta = 1) => {
703
+ const state = _store.getState();
704
+
705
+ const storeSubscribers = state.internal.subscribers;
706
+ const promises = [];
707
+ storeSubscribers.forEach(subscriber => {
708
+ for (let i = 0; i < frames; i++) {
709
+ if (is.arr(delta)) {
710
+ promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
711
+ } else {
712
+ promises.push(new Promise(() => subscriber.ref.current(state, delta)));
713
+ }
714
+ }
715
+ });
716
+ Promise.all(promises);
717
+ }
718
+ };
719
+ };
720
+
721
+ const act = fiber.act;
722
+ var index = {
723
+ create,
724
+ act
725
+ };
726
+
727
+ exports.ReactThreeTest = index$1;
728
+ exports.default = index;