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