@react-three/test-renderer 9.0.0 → 9.1.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.
@@ -33,14 +33,10 @@ const treeObjectFactory = (type, props, children) => ({
33
33
  props,
34
34
  children
35
35
  });
36
-
37
- const toTreeBranch = obj => obj.map(child => {
38
- return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), { ...child.__r3f.memoizedProps
39
- }, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
36
+ const toTreeBranch = children => children.map(child => {
37
+ return treeObjectFactory(lowerCaseFirstLetter(child.object.type || child.object.constructor.name), child.props, toTreeBranch(child.children));
40
38
  });
41
-
42
- const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), { ...obj.__r3f.memoizedProps
43
- }, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
39
+ const toTree = root => toTreeBranch(root.children);
44
40
 
45
41
  const graphObjectFactory = (type, name, children) => ({
46
42
  type,
@@ -48,56 +44,26 @@ const graphObjectFactory = (type, name, children) => ({
48
44
  children
49
45
  });
50
46
 
51
- const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
52
-
53
- const is = {
54
- obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
55
- fun: a => typeof a === 'function',
56
- str: a => typeof a === 'string',
57
- num: a => typeof a === 'number',
58
- und: a => a === void 0,
59
- arr: a => Array.isArray(a),
60
-
61
- equ(a, b) {
62
- // Wrong type or one of the two undefined, doesn't match
63
- if (typeof a !== typeof b || !!a !== !!b) return false; // Atomic, just compare a against b
64
-
65
- if (is.str(a) || is.num(a) || is.obj(a)) return a === b; // Array, shallow compare first to see if it's a match
66
-
67
- if (is.arr(a) && a == b) return true; // Last resort, go through keys
68
-
69
- let i;
70
-
71
- for (i in a) if (!(i in b)) return false;
72
-
73
- for (i in b) if (a[i] !== b[i]) return false;
74
-
75
- return is.und(i) ? a === b : true;
76
- }
77
-
78
- };
79
-
80
- const createCanvas = ({
81
- beforeReturn,
82
- width = 1280,
83
- height = 800
84
- } = {}) => {
85
- const canvas = document.createElement('canvas');
86
- canvas.height = height;
87
- canvas.width = width;
88
-
89
- canvas.addEventListener = () => {};
90
-
91
- canvas.removeEventListener = () => {};
92
-
93
- if (beforeReturn) {
94
- beforeReturn(canvas);
95
- }
96
-
97
- return canvas;
47
+ // Helper function to process raw THREE.js children objects
48
+ function processThreeChildren(children) {
49
+ return children.map(object => graphObjectFactory(object.type, object.name || '', object.children && object.children.length > 0 ? processThreeChildren(object.children) : []));
50
+ }
51
+ const toGraph = object => {
52
+ return object.children.map(child => {
53
+ var _child$object$childre, _child$object$name;
54
+ // Process standard R3F children
55
+ const children = toGraph(child);
56
+
57
+ // For primitives, also include THREE.js object children
58
+ if (child.type === 'primitive' && (_child$object$childre = child.object.children) != null && _child$object$childre.length) {
59
+ const threeChildren = processThreeChildren(child.object.children);
60
+ children.push(...threeChildren);
61
+ }
62
+ return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', children);
63
+ });
98
64
  };
99
65
 
100
- 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'];
66
+ const functions = ['activeTexture', 'attachShader', 'beginQuery', 'beginTransformFeedback', 'bindAttribLocation', 'bindBufferBase', 'bindBufferRange', 'bindRenderbuffer', 'bindSampler', 'bindTransformFeedback', 'bindVertexArray', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'blitFramebuffer', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clientWaitSync', 'compileShader', 'compressedTexImage2D', 'compressedTexImage3D', 'compressedTexSubImage2D', 'compressedTexSubImage3D', 'copyBufferSubData', 'copyTexImage2D', 'copyTexSubImage2D', 'copyTexSubImage3D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createQuery', 'createRenderbuffer', 'createSampler', 'createShader', 'createTexture', 'createTransformFeedback', 'createVertexArray', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteQuery', 'deleteRenderbuffer', 'deleteSampler', 'deleteShader', 'deleteSync', 'deleteTexture', 'deleteTransformFeedback', 'deleteVertexArray', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'drawArraysInstanced', 'drawElementsInstanced', 'drawRangeElements', 'enable', 'endQuery', 'endTransformFeedback', 'fenceSync', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'framebufferTextureLayer', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getActiveUniformBlockName', 'getActiveUniformBlockParameter', 'getActiveUniforms', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getBufferSubData', 'getContextAttributes', 'getError', 'getExtension', 'getFragDataLocation', 'getFramebufferAttachmentParameter', 'getIndexedParameter', 'getInternalformatParameter', 'getParameter', 'getProgramInfoLog', 'getProgramParameter', 'getQuery', 'getQueryParameter', 'getRenderbufferParameter', 'getSamplerParameter', 'getShaderInfoLog', 'getShaderParameter', 'getShaderPrecisionFormat', 'getShaderSource', 'getSupportedExtensions', 'getSyncParameter', 'getTexParameter', 'getTransformFeedbackVarying', 'getUniform', 'getUniformBlockIndex', 'getUniformIndices', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'invalidateFramebuffer', 'invalidateSubFramebuffer', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isQuery', 'isRenderbuffer', 'isSampler', 'isShader', 'isSync', 'isTexture', 'isTransformFeedback', 'isVertexArray', 'lineWidth', 'linkProgram', 'pauseTransformFeedback', 'pixelStorei', 'polygonOffset', 'readBuffer', 'readPixels', 'renderbufferStorage', 'renderbufferStorageMultisample', 'resumeTransformFeedback', 'sampleCoverage', 'samplerParameterf', 'samplerParameteri', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texImage2D', 'texImage3D', 'texParameterf', 'texParameteri', 'texStorage2D', 'texStorage3D', 'texSubImage2D', 'texSubImage3D', 'transformFeedbackVaryings', 'uniform1ui', 'uniform2ui', 'uniform3ui', 'uniform4ui', 'uniformBlockBinding', 'useProgram', 'validateProgram', 'vertexAttribDivisor', 'vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribIPointer', 'waitSync', 'bindBuffer', 'bindFramebuffer', 'bindTexture', 'clear', 'clearBufferfi', 'clearBufferfv', 'clearBufferiv', 'clearBufferuiv', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'disableVertexAttribArray', 'drawArrays', 'drawBuffers', 'drawElements', 'enableVertexAttribArray', 'scissor', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform1uiv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform2uiv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform3uiv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniform4uiv', 'uniformMatrix2fv', 'uniformMatrix2x3fv', 'uniformMatrix2x4fv', 'uniformMatrix3fv', 'uniformMatrix3x2fv', 'uniformMatrix3x4fv', 'uniformMatrix4fv', 'uniformMatrix4x2fv', 'uniformMatrix4x3fv', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribI4iv', 'vertexAttribI4uiv', 'vertexAttribPointer', 'viewport', 'makeXRCompatible'];
101
67
  const enums = {
102
68
  DEPTH_BUFFER_BIT: 256,
103
69
  STENCIL_BUFFER_BIT: 1024,
@@ -395,7 +361,159 @@ const enums = {
395
361
  UNPACK_PREMULTIPLY_ALPHA_WEBGL: 37441,
396
362
  CONTEXT_LOST_WEBGL: 37442,
397
363
  UNPACK_COLORSPACE_CONVERSION_WEBGL: 37443,
398
- BROWSER_DEFAULT_WEBGL: 37444
364
+ BROWSER_DEFAULT_WEBGL: 37444,
365
+ READ_BUFFER: 3074,
366
+ UNPACK_ROW_LENGTH: 3314,
367
+ UNPACK_SKIP_ROWS: 3315,
368
+ UNPACK_SKIP_PIXELS: 3316,
369
+ PACK_ROW_LENGTH: 3330,
370
+ PACK_SKIP_ROWS: 3331,
371
+ PACK_SKIP_PIXELS: 3332,
372
+ COLOR: 6144,
373
+ DEPTH: 6145,
374
+ STENCIL: 6146,
375
+ RED: 6403,
376
+ UNPACK_SKIP_IMAGES: 32877,
377
+ UNPACK_IMAGE_HEIGHT: 32878,
378
+ TEXTURE_WRAP_R: 32882,
379
+ MAX_ELEMENTS_VERTICES: 33000,
380
+ MAX_ELEMENTS_INDICES: 33001,
381
+ TEXTURE_MIN_LOD: 33082,
382
+ TEXTURE_MAX_LOD: 33083,
383
+ TEXTURE_BASE_LEVEL: 33084,
384
+ TEXTURE_MAX_LEVEL: 33085,
385
+ MIN: 32775,
386
+ MAX: 32776,
387
+ MAX_TEXTURE_LOD_BIAS: 34045,
388
+ TEXTURE_COMPARE_MODE: 34892,
389
+ TEXTURE_COMPARE_FUNC: 34893,
390
+ CURRENT_QUERY: 34917,
391
+ QUERY_RESULT: 34918,
392
+ QUERY_RESULT_AVAILABLE: 34919,
393
+ STREAM_READ: 35041,
394
+ STREAM_COPY: 35042,
395
+ STATIC_READ: 35045,
396
+ STATIC_COPY: 35046,
397
+ DYNAMIC_READ: 35049,
398
+ DYNAMIC_COPY: 35050,
399
+ MAX_DRAW_BUFFERS: 34852,
400
+ MAX_FRAGMENT_UNIFORM_COMPONENTS: 35657,
401
+ MAX_VERTEX_UNIFORM_COMPONENTS: 35658,
402
+ FRAGMENT_SHADER_DERIVATIVE_HINT: 35723,
403
+ PIXEL_PACK_BUFFER: 35051,
404
+ PIXEL_UNPACK_BUFFER: 35052,
405
+ PIXEL_PACK_BUFFER_BINDING: 35053,
406
+ PIXEL_UNPACK_BUFFER_BINDING: 35055,
407
+ SRGB: 35904,
408
+ COMPARE_REF_TO_TEXTURE: 34894,
409
+ VERTEX_ATTRIB_ARRAY_INTEGER: 35069,
410
+ MAX_ARRAY_TEXTURE_LAYERS: 35071,
411
+ MIN_PROGRAM_TEXEL_OFFSET: 35076,
412
+ MAX_PROGRAM_TEXEL_OFFSET: 35077,
413
+ MAX_VARYING_COMPONENTS: 35659,
414
+ TRANSFORM_FEEDBACK_BUFFER_MODE: 35967,
415
+ MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: 35968,
416
+ TRANSFORM_FEEDBACK_VARYINGS: 35971,
417
+ TRANSFORM_FEEDBACK_BUFFER_START: 35972,
418
+ TRANSFORM_FEEDBACK_BUFFER_SIZE: 35973,
419
+ TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: 35976,
420
+ RASTERIZER_DISCARD: 35977,
421
+ MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: 35978,
422
+ MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: 35979,
423
+ INTERLEAVED_ATTRIBS: 35980,
424
+ SEPARATE_ATTRIBS: 35981,
425
+ TRANSFORM_FEEDBACK_BUFFER: 35982,
426
+ TRANSFORM_FEEDBACK_BUFFER_BINDING: 35983,
427
+ RED_INTEGER: 36244,
428
+ RGB_INTEGER: 36248,
429
+ RGBA_INTEGER: 36249,
430
+ SAMPLER_CUBE_SHADOW: 36293,
431
+ INT_SAMPLER_CUBE: 36300,
432
+ UNSIGNED_INT_SAMPLER_CUBE: 36308,
433
+ FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: 33296,
434
+ FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: 33297,
435
+ FRAMEBUFFER_ATTACHMENT_RED_SIZE: 33298,
436
+ FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: 33299,
437
+ FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: 33300,
438
+ FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: 33301,
439
+ FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: 33302,
440
+ FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: 33303,
441
+ FRAMEBUFFER_DEFAULT: 33304,
442
+ UNSIGNED_NORMALIZED: 35863,
443
+ DRAW_FRAMEBUFFER_BINDING: 36006,
444
+ READ_FRAMEBUFFER: 36008,
445
+ DRAW_FRAMEBUFFER: 36009,
446
+ READ_FRAMEBUFFER_BINDING: 36010,
447
+ RENDERBUFFER_SAMPLES: 36011,
448
+ FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: 36052,
449
+ MAX_COLOR_ATTACHMENTS: 36063,
450
+ FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: 36182,
451
+ MAX_SAMPLES: 36183,
452
+ HALF_FLOAT: 5131,
453
+ RG: 33319,
454
+ RG_INTEGER: 33320,
455
+ VERTEX_ARRAY_BINDING: 34229,
456
+ SIGNED_NORMALIZED: 36764,
457
+ COPY_READ_BUFFER: 36662,
458
+ COPY_WRITE_BUFFER: 36663,
459
+ COPY_READ_BUFFER_BINDING: 36662,
460
+ COPY_WRITE_BUFFER_BINDING: 36663,
461
+ UNIFORM_BUFFER: 35345,
462
+ UNIFORM_BUFFER_BINDING: 35368,
463
+ UNIFORM_BUFFER_START: 35369,
464
+ UNIFORM_BUFFER_SIZE: 35370,
465
+ MAX_VERTEX_UNIFORM_BLOCKS: 35371,
466
+ MAX_FRAGMENT_UNIFORM_BLOCKS: 35373,
467
+ MAX_COMBINED_UNIFORM_BLOCKS: 35374,
468
+ MAX_UNIFORM_BUFFER_BINDINGS: 35375,
469
+ MAX_UNIFORM_BLOCK_SIZE: 35376,
470
+ MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: 35377,
471
+ MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: 35379,
472
+ UNIFORM_BUFFER_OFFSET_ALIGNMENT: 35380,
473
+ ACTIVE_UNIFORM_BLOCKS: 35382,
474
+ UNIFORM_TYPE: 35383,
475
+ UNIFORM_SIZE: 35384,
476
+ UNIFORM_BLOCK_INDEX: 35386,
477
+ UNIFORM_OFFSET: 35387,
478
+ UNIFORM_ARRAY_STRIDE: 35388,
479
+ UNIFORM_MATRIX_STRIDE: 35389,
480
+ UNIFORM_IS_ROW_MAJOR: 35390,
481
+ UNIFORM_BLOCK_BINDING: 35391,
482
+ UNIFORM_BLOCK_DATA_SIZE: 35392,
483
+ UNIFORM_BLOCK_ACTIVE_UNIFORMS: 35394,
484
+ UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: 35395,
485
+ UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: 35396,
486
+ UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: 35398,
487
+ INVALID_INDEX: 4294967295,
488
+ MAX_VERTEX_OUTPUT_COMPONENTS: 37154,
489
+ MAX_FRAGMENT_INPUT_COMPONENTS: 37157,
490
+ MAX_SERVER_WAIT_TIMEOUT: 37137,
491
+ OBJECT_TYPE: 37138,
492
+ SYNC_CONDITION: 37139,
493
+ SYNC_STATUS: 37140,
494
+ SYNC_FLAGS: 37141,
495
+ SYNC_FENCE: 37142,
496
+ SYNC_GPU_COMMANDS_COMPLETE: 37143,
497
+ UNSIGNALED: 37144,
498
+ SIGNALED: 37145,
499
+ ALREADY_SIGNALED: 37146,
500
+ TIMEOUT_EXPIRED: 37147,
501
+ CONDITION_SATISFIED: 37148,
502
+ WAIT_FAILED: 37149,
503
+ SYNC_FLUSH_COMMANDS_BIT: 1,
504
+ VERTEX_ATTRIB_ARRAY_DIVISOR: 35070,
505
+ ANY_SAMPLES_PASSED: 35887,
506
+ ANY_SAMPLES_PASSED_CONSERVATIVE: 36202,
507
+ SAMPLER_BINDING: 35097,
508
+ TRANSFORM_FEEDBACK: 36386,
509
+ TRANSFORM_FEEDBACK_PAUSED: 36387,
510
+ TRANSFORM_FEEDBACK_ACTIVE: 36388,
511
+ TRANSFORM_FEEDBACK_BINDING: 36389,
512
+ TEXTURE_IMMUTABLE_FORMAT: 37167,
513
+ MAX_ELEMENT_INDEX: 36203,
514
+ TEXTURE_IMMUTABLE_LEVELS: 33503,
515
+ TIMEOUT_IGNORED: -1,
516
+ MAX_CLIENT_WAIT_TIMEOUT_WEBGL: 37447
399
517
  };
400
518
  const extensions = {
401
519
  // ratified
@@ -434,8 +552,7 @@ const extensions = {
434
552
  EXT_sRGB: null,
435
553
  WEBGL_compressed_texture_etc1: null
436
554
  };
437
-
438
- class WebGLRenderingContext {
555
+ class WebGL2RenderingContext {
439
556
  constructor(canvas) {
440
557
  this.getShaderPrecisionFormat = () => {
441
558
  return {
@@ -444,62 +561,84 @@ class WebGLRenderingContext {
444
561
  precision: 23
445
562
  };
446
563
  };
447
-
448
564
  this.GL_VERSION = 7938;
449
565
  this.SCISSOR_BOX = 3088;
450
566
  this.VIEWPORT = 2978;
451
-
452
- this.getParameter = paramId => {
453
- switch (paramId) {
454
- case this.GL_VERSION:
455
- return ['WebGL1'];
456
-
457
- case this.SCISSOR_BOX:
458
- case this.VIEWPORT:
459
- return [0, 0, 1, 1];
460
- }
461
- };
462
-
463
- this.getExtension = ext => {
464
- return extensions[ext];
465
- };
466
-
467
567
  this.getProgramInfoLog = () => '';
468
-
469
568
  this.getShaderInfoLog = () => '';
470
-
471
569
  this.canvas = canvas;
472
570
  this.drawingBufferWidth = canvas.width;
473
571
  this.drawingBufferHeight = canvas.height;
474
- functions.forEach(func => {
475
- this[func] = () => {
476
- return {};
477
- };
478
- });
572
+ for (const method of functions) {
573
+ var _this$method;
574
+ (_this$method = this[method]) != null ? _this$method : this[method] = () => {};
575
+ }
479
576
  Object.assign(this, enums);
480
577
  }
481
-
578
+ getParameter(paramId) {
579
+ switch (paramId) {
580
+ case this.GL_VERSION:
581
+ return ['WebGL2'];
582
+ case this.SCISSOR_BOX:
583
+ case this.VIEWPORT:
584
+ return [0, 0, 1, 1];
585
+ }
586
+ }
587
+ getExtension(ext) {
588
+ return extensions[ext];
589
+ }
482
590
  }
483
591
 
484
- const createWebGLContext = canvas => new WebGLRenderingContext(canvas);
592
+ const createCanvas = ({
593
+ beforeReturn,
594
+ width = 1280,
595
+ height = 800
596
+ } = {}) => {
597
+ var _globalThis$WebGLRend, _globalThis$WebGL2Ren;
598
+ let canvas;
599
+ if (typeof document !== 'undefined' && typeof document.createElement === 'function') {
600
+ canvas = document.createElement('canvas');
601
+ } else {
602
+ canvas = {
603
+ style: {},
604
+ addEventListener: () => {},
605
+ removeEventListener: () => {},
606
+ clientWidth: width,
607
+ clientHeight: height,
608
+ getContext: () => new WebGL2RenderingContext(canvas)
609
+ };
610
+ }
611
+ canvas.width = width;
612
+ canvas.height = height;
613
+ if (globalThis.HTMLCanvasElement) {
614
+ const getContext = HTMLCanvasElement.prototype.getContext;
615
+ HTMLCanvasElement.prototype.getContext = function (id) {
616
+ if (id.startsWith('webgl')) return new WebGL2RenderingContext(this);
617
+ return getContext.apply(this, arguments);
618
+ };
619
+ }
620
+ beforeReturn == null ? void 0 : beforeReturn(canvas);
621
+ class WebGLRenderingContext extends WebGL2RenderingContext {}
622
+ // @ts-expect-error
623
+ (_globalThis$WebGLRend = globalThis.WebGLRenderingContext) != null ? _globalThis$WebGLRend : globalThis.WebGLRenderingContext = WebGLRenderingContext;
624
+ // @ts-expect-error
625
+ (_globalThis$WebGL2Ren = globalThis.WebGL2RenderingContext) != null ? _globalThis$WebGL2Ren : globalThis.WebGL2RenderingContext = WebGL2RenderingContext;
626
+ return canvas;
627
+ };
485
628
 
486
629
  const createEventFirer = (act, store) => {
487
630
  const findEventHandler = (element, eventName) => {
488
631
  const eventHandlerName = toEventHandlerName(eventName);
489
632
  const props = element.props;
490
-
491
633
  if (typeof props[eventHandlerName] === 'function') {
492
634
  return props[eventHandlerName];
493
635
  }
494
-
495
636
  if (typeof props[eventName] === 'function') {
496
637
  return props[eventName];
497
638
  }
498
-
499
639
  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`);
500
640
  return null;
501
641
  };
502
-
503
642
  const createSyntheticEvent = (element, data) => {
504
643
  const raycastEvent = {
505
644
  camera: store.getState().camera,
@@ -511,23 +650,18 @@ const createEventFirer = (act, store) => {
511
650
  };
512
651
  return raycastEvent;
513
652
  };
514
-
515
653
  const invokeEvent = async (element, eventName, data) => {
516
654
  const handler = findEventHandler(element, eventName);
517
-
518
655
  if (!handler) {
519
656
  return;
520
657
  }
521
-
522
658
  let returnValue;
523
659
  await act(async () => {
524
660
  returnValue = handler(createSyntheticEvent(element, data));
525
661
  });
526
662
  return returnValue;
527
663
  };
528
-
529
664
  const fireEvent = async (element, eventName, data = {}) => await invokeEvent(element, eventName, data);
530
-
531
665
  return fireEvent;
532
666
  };
533
667
 
@@ -535,7 +669,6 @@ const expectOne = (items, msg) => {
535
669
  if (items.length === 1) {
536
670
  return items[0];
537
671
  }
538
-
539
672
  const prefix = items.length === 0 ? 'RTTR: No instances found' : `RTTR: Expected 1 but found ${items.length} instances`;
540
673
  throw new Error(`${prefix} ${msg}`);
541
674
  };
@@ -544,201 +677,214 @@ const matchProps = (props, filter) => {
544
677
  // Check for matches if filter contains regex matchers
545
678
  const isRegex = filter[key] instanceof RegExp;
546
679
  const shouldMatch = isRegex && typeof props[key] === 'string';
547
- const match = shouldMatch && filter[key].test(props[key]); // Bail if props aren't identical and filters found no match
680
+ const match = shouldMatch && filter[key].test(props[key]);
548
681
 
682
+ // Bail if props aren't identical and filters found no match
549
683
  if (props[key] !== filter[key] && !match) {
550
684
  return false;
551
685
  }
552
686
  }
553
-
554
687
  return true;
555
688
  };
556
- const findAll = (root, decider) => {
689
+ const findAll = (root, decider, options = {
690
+ includeRoot: true
691
+ }) => {
557
692
  const results = [];
558
693
 
559
- if (decider(root)) {
694
+ // Only include the root node if the option is enabled
695
+ if (options.includeRoot !== false && decider(root)) {
560
696
  results.push(root);
561
697
  }
562
698
 
699
+ // Always search through children
563
700
  root.allChildren.forEach(child => {
564
- results.push(...findAll(child, decider));
701
+ // When recursively searching children, we always want to include their roots
702
+ results.push(...findAll(child, decider, {
703
+ includeRoot: true
704
+ }));
565
705
  });
566
706
  return results;
567
707
  };
568
708
 
709
+ // Helper to create a minimal wrapper for THREE.Object3D children of primitives
710
+ const createVirtualInstance = (object, parent) => {
711
+ // Create the virtual instance for this object
712
+ // we can't import the prepare method from packages/fiber/src/core/utils.tsx so we do what we can
713
+ const instance = {
714
+ root: parent.root,
715
+ type: object.type.toLowerCase(),
716
+ // Convert to lowercase to match R3F convention
717
+ parent,
718
+ children: [],
719
+ props: {
720
+ object
721
+ },
722
+ object,
723
+ eventCount: 0,
724
+ handlers: {},
725
+ isHidden: false
726
+ };
727
+
728
+ // Recursively process children if they exist
729
+ if (object.children && object.children.length > 0) {
730
+ const objectChildren = object.children;
731
+ instance.children = Array.from(objectChildren).map(child => createVirtualInstance(child, instance));
732
+ }
733
+ return instance;
734
+ };
569
735
  class ReactThreeTestInstance {
570
736
  constructor(_fiber) {
571
737
  this.getChildren = (fiber, opts = {
572
738
  exhaustive: false
573
739
  }) => {
574
- if (opts.exhaustive) {
575
- /**
576
- * this will return objects like
577
- * color or effects etc.
578
- */
579
- return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
580
- } else {
581
- return (fiber.children || []).map(fib => wrapFiber(fib));
740
+ var _fiber$object$childre;
741
+ // Get standard R3F children
742
+ const r3fChildren = fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
743
+
744
+ // For primitives, also add THREE.js object children
745
+ if (fiber.type === 'primitive' && (_fiber$object$childre = fiber.object.children) != null && _fiber$object$childre.length) {
746
+ const threeChildren = fiber.object.children.map(child => {
747
+ // Create a virtual instance that wraps the THREE.js child
748
+ const virtualInstance = createVirtualInstance(child, fiber);
749
+ return wrapFiber(virtualInstance);
750
+ });
751
+ r3fChildren.push(...threeChildren);
752
+ return r3fChildren;
582
753
  }
754
+ return r3fChildren;
583
755
  };
584
-
585
- this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
586
-
587
- this.findAll = decider => findAll(this, decider);
588
-
589
- this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
590
-
591
- this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
592
-
756
+ this.findAll = decider => findAll(this, decider, {
757
+ includeRoot: false
758
+ });
759
+ this.find = decider => expectOne(this.findAll(decider), `matching custom checker: ${decider.toString()}`);
760
+ this.findByType = type => expectOne(this.findAll(node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
761
+ this.findAllByType = type => this.findAll(node => Boolean(node.type && node.type === type));
593
762
  this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
594
-
595
- this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
596
-
763
+ this.findAllByProps = props => this.findAll(node => Boolean(node.props && matchProps(node.props, props)));
597
764
  this._fiber = _fiber;
598
765
  }
599
-
600
- get instance() {
766
+ get fiber() {
601
767
  return this._fiber;
602
768
  }
603
-
769
+ get instance() {
770
+ return this._fiber.object;
771
+ }
604
772
  get type() {
605
- return this._fiber.type;
773
+ return this._fiber.object.type;
606
774
  }
607
-
608
775
  get props() {
609
- return this._fiber.__r3f.memoizedProps;
776
+ return this._fiber.props;
610
777
  }
611
-
612
778
  get parent() {
613
- const parent = this._fiber.__r3f.parent;
614
-
779
+ const parent = this._fiber.parent;
615
780
  if (parent !== null) {
616
781
  return wrapFiber(parent);
617
782
  }
618
-
619
783
  return parent;
620
784
  }
621
-
622
785
  get children() {
623
786
  return this.getChildren(this._fiber);
624
787
  }
625
-
626
788
  get allChildren() {
627
789
  return this.getChildren(this._fiber, {
628
790
  exhaustive: true
629
791
  });
630
792
  }
631
-
632
793
  }
633
794
  const fiberToWrapper = new WeakMap();
634
795
  const wrapFiber = fiber => {
635
796
  let wrapper = fiberToWrapper.get(fiber);
636
-
637
797
  if (wrapper === undefined) {
638
798
  wrapper = new ReactThreeTestInstance(fiber);
639
799
  fiberToWrapper.set(fiber, wrapper);
640
800
  }
641
-
642
801
  return wrapper;
643
802
  };
644
803
 
804
+ async function waitFor(callback, {
805
+ interval = 50,
806
+ timeout = 5000
807
+ } = {}) {
808
+ await fiber.act(async () => {
809
+ const start = performance.now();
810
+ while (true) {
811
+ const result = callback();
812
+ if (result || result == null) break;
813
+ if (interval) await new Promise(resolve => setTimeout(resolve, interval));
814
+ if (timeout && performance.now() - start >= timeout) throw new Error(`Timed out after ${timeout}ms.`);
815
+ }
816
+ });
817
+ }
818
+
645
819
  var index$1 = /*#__PURE__*/Object.freeze({
646
820
  __proto__: null,
647
821
  ReactThreeTestInstance: ReactThreeTestInstance
648
822
  });
649
823
 
824
+ // Extend catalogue for render API in tests.
650
825
  fiber.extend(THREE__namespace);
651
- const act = fiber.act;
652
-
653
826
  const create = async (element, options) => {
654
- const canvas = createCanvas({
655
- width: options == null ? void 0 : options.width,
656
- height: options == null ? void 0 : options.height,
657
- beforeReturn: canvas => {
658
- //@ts-ignore
659
- canvas.getContext = type => {
660
- if (type === 'webgl' || type === 'webgl2') {
661
- return createWebGLContext(canvas);
662
- }
663
- };
664
- }
665
- });
666
- const _fiber = canvas;
667
-
668
- const _root = fiber.createRoot(_fiber).configure({
827
+ var _options$width, _options$height;
828
+ const canvas = createCanvas(options);
829
+ const _root = fiber.createRoot(canvas);
830
+ await _root.configure({
669
831
  frameloop: 'never',
832
+ // TODO: remove and use default behavior
833
+ size: {
834
+ width: (_options$width = options == null ? void 0 : options.width) != null ? _options$width : 1280,
835
+ height: (_options$height = options == null ? void 0 : options.height) != null ? _options$height : 800,
836
+ top: 0,
837
+ left: 0
838
+ },
670
839
  ...options,
671
840
  events: undefined
672
841
  });
673
-
674
- let scene = null;
675
- await act(async () => {
676
- scene = _root.render(element).getState().scene;
677
- });
678
- const _store = fiber._roots.get(_fiber).store;
842
+ const _store = fiber._roots.get(canvas).store;
843
+ await fiber.act(async () => _root.render(element));
844
+ const _scene = _store.getState().scene.__r3f;
679
845
  return {
680
- scene: wrapFiber(scene),
681
- unmount: async () => {
682
- await act(async () => {
846
+ scene: wrapFiber(_scene),
847
+ async unmount() {
848
+ await fiber.act(async () => {
683
849
  _root.unmount();
684
850
  });
685
851
  },
686
- getInstance: () => {
687
- var _mockRoots$get;
688
-
689
- // this is our root
690
- const fiber$1 = (_mockRoots$get = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get.fiber;
691
- const current = fiber$1 == null ? void 0 : fiber$1.current.child.child;
692
-
693
- if (current) {
694
- const root = {
695
- /**
696
- * we wrap our child in a Provider component
697
- * and context.Provider, so do a little
698
- * artificial dive to get round this and
699
- * pass context.Provider as if it was the
700
- * actual react root
701
- */
702
- current
703
- };
704
- /**
705
- * so this actually returns the instance
706
- * the user has passed through as a Fiber
707
- */
708
-
709
- return fiber.reconciler.getPublicRootInstance(root);
710
- } else {
711
- return null;
712
- }
713
- },
714
- update: async newElement => {
715
- var _mockRoots$get2;
716
-
717
- const fiber$1 = (_mockRoots$get2 = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get2.fiber;
852
+ getInstance() {
853
+ // Bail if canvas is unmounted
854
+ if (!fiber._roots.has(canvas)) return null;
718
855
 
719
- if (fiber$1) {
720
- await act(async () => {
721
- fiber.reconciler.updateContainer(newElement, fiber$1, null, () => null);
722
- });
856
+ // Traverse fiber nodes for R3F root
857
+ const root = {
858
+ current: fiber._roots.get(canvas).fiber.current
859
+ };
860
+ while (!((_root$current$child = root.current.child) != null && _root$current$child.stateNode)) {
861
+ var _root$current$child;
862
+ root.current = root.current.child;
723
863
  }
724
864
 
725
- return;
865
+ // Return R3F instance from root
866
+ return fiber.reconciler.getPublicRootInstance(root);
726
867
  },
727
- toTree: () => {
728
- return toTree(scene);
868
+ async update(newElement) {
869
+ if (!fiber._roots.has(canvas)) return console.warn('RTTR: attempted to update an unmounted root!');
870
+ await fiber.act(async () => {
871
+ _root.render(newElement);
872
+ });
729
873
  },
730
- toGraph: () => {
731
- return toGraph(scene);
874
+ toTree() {
875
+ return toTree(_scene);
732
876
  },
733
- fireEvent: createEventFirer(act, _store),
734
- advanceFrames: async (frames, delta = 1) => {
877
+ toGraph() {
878
+ return toGraph(_scene);
879
+ },
880
+ fireEvent: createEventFirer(fiber.act, _store),
881
+ async advanceFrames(frames, delta = 1) {
735
882
  const state = _store.getState();
736
-
737
883
  const storeSubscribers = state.internal.subscribers;
738
884
  const promises = [];
739
885
  storeSubscribers.forEach(subscriber => {
740
886
  for (let i = 0; i < frames; i++) {
741
- if (is.arr(delta)) {
887
+ if (Array.isArray(delta)) {
742
888
  promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
743
889
  } else {
744
890
  promises.push(new Promise(() => subscriber.ref.current(state, delta)));
@@ -751,8 +897,15 @@ const create = async (element, options) => {
751
897
  };
752
898
  var index = {
753
899
  create,
754
- act
900
+ act: fiber.act,
901
+ waitFor
755
902
  };
756
903
 
904
+ Object.defineProperty(exports, 'act', {
905
+ enumerable: true,
906
+ get: function () { return fiber.act; }
907
+ });
757
908
  exports.ReactThreeTest = index$1;
909
+ exports.create = create;
758
910
  exports["default"] = index;
911
+ exports.waitFor = waitFor;