function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function")}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass)}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o};return _setPrototypeOf(o,p)}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget)}else{result=Super.apply(this,arguments)}return _possibleConstructorReturn(this,result)}}function _possibleConstructorReturn(self,call){if(call&&(typeof call==="object"||typeof call==="function")){return call}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined")}return _assertThisInitialized(self)}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return self}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true}catch(e){return false}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o)};return _getPrototypeOf(o)}import{MountCache,ComponentTreeCache,ActiveRenderState,InstanceCache,VTree,Transaction}from"./util/types.js";import{$$hooks,$$vTree}from"./util/symbols.js";import diff from"./util/binding.js";import Component from"./component.js";const{createTree}=diff;/**
 * Used during a synchronization flow. Takes in a vTree and a context object
 * and renders the component as a class or a function. Calls standard lifecycle
 * methods.
 *
 * @param {VTree} vTree - tree to render
 * @param {Transaction} transaction - used to key mounts to a transaction
 *
 * @returns {VTree | null}
 */export default function renderComponent(vTree,transaction){const props=vTree.attributes;const RawComponent=vTree.rawNodeName;const isNewable=RawComponent.prototype&&RawComponent.prototype.render;const isInstance=InstanceCache.has(vTree);/** @type {VTree|null} */let renderedTree=null;// Existing class component rerender.
if(isInstance){const instance=InstanceCache.get(vTree);if(instance.componentWillReceiveProps){instance.componentWillReceiveProps(props)}if(instance.shouldComponentUpdate&&instance.shouldComponentUpdate(props,instance.state)){ActiveRenderState.push(instance);// Reset the hooks iterator.
instance[$$hooks].i=0;renderedTree=createTree(instance.render(props,instance.state));ActiveRenderState.length=0;if(instance.componentDidUpdate&&instance.componentDidUpdate){instance.componentDidUpdate(instance.props,instance.state)}}else{return null}}// New class instance.
else if(isNewable){const instance=new RawComponent(props);// Associate the instance to the vTree.
InstanceCache.set(vTree,instance);ActiveRenderState.push(instance);// Initial render of the class component, this should not be called again
// for the same component in the same position. It will be picked up
// automatically as a class component and rendered via its own Transaction.
const renderRetVal=instance.render(props,instance.state);ActiveRenderState.length=0;MountCache.get(transaction)?.add(instance);renderedTree=createTree(renderRetVal||"#text");if(typeof renderedTree.rawNodeName!=="function"&&renderedTree.nodeType===11&&!renderedTree.childNodes.length){renderedTree=createTree("#text")}// Set up the HoC parent/child relationship.
if(typeof renderedTree.rawNodeName==="function"){ComponentTreeCache.set(renderedTree,vTree)}// Associate the instance with the vTree.
instance[$$vTree]=vTree}// Function component, upgrade to a class to make it reactive.
else{let FunctionComponent=/*#__PURE__*/function(_Component){_inherits(FunctionComponent,_Component);var _super=_createSuper(FunctionComponent);/**
       * @param {any} props
       */function FunctionComponent(props){var _this;_classCallCheck(this,FunctionComponent);_this=_super.call(this,props);_this[$$vTree]=null;return _this}/**
       * @param {any} props
       * @param {any} state
       */_createClass(FunctionComponent,[{key:"render",value:function render(props,state){// Always render the latest `rawNodeName` of a VTree in case of
// hot-reloading the cached value above wouldn't be correct.
return createTree(RawComponent(props,state))}/** @type {VTree | null} */}]);return FunctionComponent}(Component);const instance=new FunctionComponent(props);// Associate the instance to the vTree.
InstanceCache.set(vTree,instance);// Allow hooks to "hook" into the active rendering component.
ActiveRenderState.push(instance);let renderRetVal=null;try{renderRetVal=instance.render(props,instance.state)}catch(e){// Clean up after a potential failure.
ActiveRenderState.length=0;MountCache.delete(transaction);throw e}ActiveRenderState.length=0;MountCache.get(transaction)?.add(instance);renderedTree=createTree(renderRetVal||"#text");// If the rendered return value is an empty fragment, default to an empty
// text value.
if(typeof renderedTree.rawNodeName!=="function"&&renderedTree.nodeType===11&&!renderedTree.childNodes.length){renderedTree=createTree("#text")}// Set up the HoC parent/child relationship.
if(typeof renderedTree.rawNodeName==="function"){ComponentTreeCache.set(renderedTree,vTree)}// Associate the instance with the vTree.
instance[$$vTree]=vTree}if(renderedTree!==vTree){// Map all top-level fragment elements to this parent node.
if(renderedTree.nodeType===11){renderedTree.childNodes.forEach(childNode=>{ComponentTreeCache.set(childNode,vTree)})}// Otherwise directly map the rendered VTree to the component tree.
else{ComponentTreeCache.set(renderedTree,vTree)}}return renderedTree};