"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.invokeRef=void 0;exports.invokeRefsForVTree=invokeRefsForVTree;var _types=require("../util/types");var _binding=_interopRequireDefault(require("../util/binding"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})),keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach(function(key){_defineProperty(target,key,source[key])}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}const{Internals}=_binding.default;/**
 * @param {any} target
 * @param {VTree} vTree
 * @param {HTMLElement | VTree | null=} value
 */const invokeRef=(target=_types.EMPTY.OBJ,vTree,value)=>{let{ref}=target.props||target;// Allow refs to be passed to HTML elements. When in a DOM environment
// a Node will be passed to the ref function and assigned.
if(!ref){target=Internals.NodeCache.get(vTree);ref=vTree.attributes.ref}// Only backfill the value with target if no value was provided (either null
// or a truthy value).
if(value===undefined){value=target}if(typeof ref==="function"){ref(value)}else if(typeof ref==="object"&&ref){ref.current=value}else if(typeof ref==="string"){target.refs=_objectSpread(_objectSpread({},target.refs),{},{[ref]:value})}};/**
 * @param {VTree} vTree - Element to start search, crawl for refs to invoke
 * @param {HTMLElement | VTree | null} value - Value to populate ref with
 */exports.invokeRef=invokeRef;function invokeRefsForVTree(vTree,value){const componentTree=_types.ComponentTreeCache.get(vTree);if(vTree.childNodes.length){vTree.childNodes.filter(Boolean).forEach(childNode=>{invokeRefsForVTree(childNode,value)})}const instance=_types.InstanceCache.get(componentTree||vTree);if(!instance){invokeRef(Internals.NodeCache.get(vTree),vTree,value);return}// If any instances exist, loop through them and invoke the respective `ref`
// logic.
invokeRef(instance,vTree,value)}