import { Text , Fragment , Comment , cloneIfMounted , normalizeVNode , VNode , VNodeArrayChildren , createVNode , isSameVNodeType , Static , VNodeNormalizedRef , VNodeHook , VNodeNormalizedRefAtom , VNodeProps } from './vnode' ; import { ComponentInternalInstance , ComponentOptions , createComponentInstance , Data , getExposeProxy , setupComponent } from './component' ; import { filterSingleRoot , renderComponentRoot , shouldUpdateComponent , updateHOCHostEl } from './componentRenderUtils' ; import { isString , EMPTY_OBJ , EMPTY_ARR , isReservedProp , isFunction , PatchFlags , ShapeFlags , NOOP , hasOwn , invokeArrayFns , isArray , getGlobalThis } from '@vue/shared' ; import { queueJob , queuePostFlushCb , flushPostFlushCbs , invalidateJob , flushPreFlushCbs , SchedulerJob } from './scheduler' ; import { isRef , pauseTracking , resetTracking , ReactiveEffect } from '@vue/reactivity' ; import { updateProps } from './componentProps' ; import { updateSlots } from './componentSlots' ; import { pushWarningContext , popWarningContext , warn } from './warning' ; import { createAppAPI , CreateAppFunction } from './apiCreateApp' ; import { SuspenseBoundary , queueEffectWithSuspense , SuspenseImpl } from './components/Suspense' ; import { TeleportImpl , TeleportVNode } from './components/Teleport' ; import { isKeepAlive , KeepAliveContext } from './components/KeepAlive' ; import { registerHMR , unregisterHMR , isHmrUpdating } from './hmr' ; import { ErrorCodes , callWithErrorHandling , callWithAsyncErrorHandling } from './errorHandling' ; import { createHydrationFunctions , RootHydrateFunction } from './hydration' ; import { invokeDirectiveHook } from './directives' ; import { startMeasure , endMeasure } from './profiling' ; import { devtoolsComponentAdded , devtoolsComponentRemoved , devtoolsComponentUpdated , setDevtoolsHook } from './devtools' ; import { initFeatureFlags } from './featureFlags' ; import { isAsyncWrapper } from './apiAsyncComponent' ; import { isCompatEnabled } from './compat/compatConfig' ; import { DeprecationTypes } from './compat/compatConfig' ; import { registerLegacyRef } from './compat/ref' ; export interface Renderer < HostElement = RendererElement > { render : RootRenderFunction < HostElement > ; createApp : CreateAppFunction < HostElement > ; } export interface HydrationRenderer extends Renderer < Element | ShadowRoot > { hydrate : RootHydrateFunction ; } export type RootRenderFunction < HostElement = RendererElement > = ( vnode : VNode | null , container : HostElement , isSVG ? : boolean ) => void ; export interface RendererOptions < HostNode = RendererNode , HostElement = RendererElement > { patchProp ( el , key , prevValue , nextValue , isSVG ? , prevChildren ? , parentComponent ? , parentSuspense ? , unmountChildren ? ) : void ; insert ( el , parent , anchor ? ) : void ; remove ( el ) : void ; createElement ( type , isSVG ? , isCustomizedBuiltIn ? , vnodeProps ? ) : HostElement ; createText ( text ) : HostNode ; createComment ( text ) : HostNode ; setText ( node , text ) : void ; setElementText ( node , text ) : void ; parentNode ( node ) : HostElement | null ; nextSibling ( node ) : HostNode | null ; querySelector ? ( selector ) : HostElement | null ; setScopeId ? ( el , id ) : void ; cloneNode ? ( node ) : HostNode ; insertStaticContent ? ( content , parent , anchor , isSVG ) : [ HostNode , HostNode ] ; } export interface RendererNode { [ key ] : any ; } export interface RendererElement extends RendererNode { } export interface RendererInternals < HostNode = RendererNode , HostElement = RendererElement > { p : PatchFn ; um : UnmountFn ; r : RemoveFn ; m : MoveFn ; mt : MountComponentFn ; mc : MountChildrenFn ; pc : PatchChildrenFn ; pbc : PatchBlockChildrenFn ; n : NextFn ; o : RendererOptions < HostNode , HostElement > ; } type PatchFn = ( n1 : VNode | null , n2 : VNode , container : RendererElement , anchor ? : RendererNode | null , parentComponent ? : ComponentInternalInstance | null , parentSuspense ? : SuspenseBoundary | null , isSVG ? : boolean , slotScopeIds ? : string [ ] | null , optimized ? : boolean ) => void ; type MountChildrenFn = ( children : VNodeArrayChildren , container : RendererElement , anchor : RendererNode | null , parentComponent : ComponentInternalInstance | null , parentSuspense : SuspenseBoundary | null , isSVG : boolean , slotScopeIds : string [ ] | null , optimized : boolean , start ? : number ) => void ; type PatchChildrenFn = ( n1 : VNode | null , n2 : VNode , container : RendererElement , anchor : RendererNode | null , parentComponent : ComponentInternalInstance | null , parentSuspense : SuspenseBoundary | null , isSVG : boolean , slotScopeIds : string [ ] | null , optimized : boolean ) => void ; type PatchBlockChildrenFn = ( oldChildren : VNode [ ] , newChildren : VNode [ ] , fallbackContainer : RendererElement , parentComponent : ComponentInternalInstance | null , parentSuspense : SuspenseBoundary | null , isSVG : boolean , slotScopeIds : string [ ] | null ) => void ; type MoveFn = ( vnode : VNode , container : RendererElement , anchor : RendererNode | null , type : MoveType , parentSuspense ? : SuspenseBoundary | null ) => void ; type NextFn = ( vnode : VNode ) => RendererNode | null ; type UnmountFn = ( vnode : VNode , parentComponent : ComponentInternalInstance | null , parentSuspense : SuspenseBoundary | null , doRemove ? : boolean , optimized ? : boolean ) => void ; type RemoveFn = ( vnode : VNode ) => void ; type UnmountChildrenFn = ( children : VNode [ ] , parentComponent : ComponentInternalInstance | null , parentSuspense : SuspenseBoundary | null , doRemove ? : boolean , optimized ? : boolean , start ? : number ) => void ; export type MountComponentFn = ( initialVNode : VNode , container : RendererElement , anchor : RendererNode | null , parentComponent : ComponentInternalInstance | null , parentSuspense : SuspenseBoundary | null , isSVG : boolean , optimized : boolean ) => void ; type ProcessTextOrCommentFn = ( n1 : VNode | null , n2 : VNode , container : RendererElement , anchor : RendererNode | null ) => void ; export type SetupRenderEffectFn = ( instance : ComponentInternalInstance , initialVNode : VNode , container : RendererElement , anchor : RendererNode | null , parentSuspense : SuspenseBoundary | null , isSVG : boolean , optimized : boolean ) => void ; export const enum MoveType { ENTER , LEAVE , REORDER } export const queuePostRenderEffect = __FEATURE_SUSPENSE__ ? queueEffectWithSuspense : queuePostFlushCb ; /**
 * The createRenderer function accepts two generic arguments:
 * HostNode and HostElement, corresponding to Node and Element types in the
 * host environment. For example, for runtime-dom, HostNode would be the DOM
 * `Node` interface and HostElement would be the DOM `Element` interface.
 *
 * Custom renderers can pass in the platform specific types like this:
 *
 * ``` js
 * const { render, createApp } = createRenderer<Node, Element>({
 *   patchProp,
 *   ...nodeOps
 * })
 * ```
 */ export function createRenderer < HostNode = RendererNode , HostElement = RendererElement > ( options ) { return baseCreateRenderer < HostNode , HostElement > ( options ) ; } export function createHydrationRenderer ( options ) { return baseCreateRenderer ( options , createHydrationFunctions ) ; } function baseCreateRenderer < HostNode = RendererNode , HostElement = RendererElement > ( options ) ; function baseCreateRenderer ( options , createHydrationFns ) ; function baseCreateRenderer ( options , createHydrationFns ? ) { if ( __ESM_BUNDLER__ && ! __TEST__ ) { initFeatureFlags ( ) ; } if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) { const target = getGlobalThis ( ) ; target . __VUE__ = true ; setDevtoolsHook ( target . __VUE_DEVTOOLS_GLOBAL_HOOK__ ) ; } const { insert : hostInsert , remove : hostRemove , patchProp : hostPatchProp , createElement : hostCreateElement , createText : hostCreateText , createComment : hostCreateComment , setText : hostSetText , setElementText : hostSetElementText , parentNode : hostParentNode , nextSibling : hostNextSibling , setScopeId : hostSetScopeId = NOOP , cloneNode : hostCloneNode , insertStaticContent : hostInsertStaticContent } = options ; const patch = ( n1 , n2 , container , anchor = null , parentComponent = null , parentSuspense = null , isSVG = false , slotScopeIds = null , optimized = __DEV__ && isHmrUpdating ? false : ! ! n2 . dynamicChildren ) => { if ( n1 === n2 ) { return ; } if ( n1 && ! isSameVNodeType ( n1 , n2 ) ) { anchor = getNextHostNode ( n1 ) ; unmount ( n1 , parentComponent , parentSuspense , true ) ; n1 = null ; } if ( n2 . patchFlag === PatchFlags . BAIL ) { optimized = false ; n2 . dynamicChildren = null ; } const { type , ref , shapeFlag } = n2 ; switch ( type ) { case Text : processText ( n1 , n2 , container , anchor ) ; break ; case Comment : processCommentNode ( n1 , n2 , container , anchor ) ; break ; case Static : if ( n1 == null ) { mountStaticNode ( n2 , container , anchor , isSVG ) ; } else if ( __DEV__ ) { patchStaticNode ( n1 , n2 , container , isSVG ) ; } break ; case Fragment : processFragment ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; break ; default : if ( shapeFlag & ShapeFlags . ELEMENT ) { processElement ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else if ( shapeFlag & ShapeFlags . COMPONENT ) { processComponent ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else if ( shapeFlag & ShapeFlags . TELEPORT ) { ; ( type as typeof TeleportImpl ) . process ( n1 as TeleportVNode , n2 as TeleportVNode , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized , internals ) ; } else if ( __FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags . SUSPENSE ) { ; ( type as typeof SuspenseImpl ) . process ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized , internals ) ; } else if ( __DEV__ ) { warn ( 'Invalid VNode type:' , type , `(${ typeof type })` ) ; } } if ( ref != null && parentComponent ) { setRef ( ref , n1 && n1 . ref , parentSuspense , n2 || n1 , ! n2 ) ; } } ; const processText = ( n1 , n2 , container , anchor ) => { if ( n1 == null ) { hostInsert ( ( n2 . el = hostCreateText ( n2 . children as string ) ) , container , anchor ) ; } else { const el = ( n2 . el = n1 . el ! ) ; if ( n2 . children !== n1 . children ) { hostSetText ( el , n2 . children as string ) ; } } } ; const processCommentNode = ( n1 , n2 , container , anchor ) => { if ( n1 == null ) { hostInsert ( ( n2 . el = hostCreateComment ( ( n2 . children as string ) || '' ) ) , container , anchor ) ; } else { n2 . el = n1 . el ; } } ; const mountStaticNode = ( n2 , container , anchor , isSVG ) => { ; [ n2 . el , n2 . anchor ] = hostInsertStaticContent ! ( n2 . children as string , container , anchor , isSVG ) ; } ; /**
     * Dev / HMR only
     */ const patchStaticNode = ( n1 , n2 , container , isSVG ) => { if ( n2 . children !== n1 . children ) { const anchor = hostNextSibling ( n1 . anchor ! ) ; removeStaticNode ( n1 ) ; [ n2 . el , n2 . anchor ] = hostInsertStaticContent ! ( n2 . children as string , container , anchor , isSVG ) ; } else { n2 . el = n1 . el ; n2 . anchor = n1 . anchor ; } } ; const moveStaticNode = ( { el , anchor } , container , nextSibling ) => { let next ; while ( el && el !== anchor ) { next = hostNextSibling ( el ) ; hostInsert ( el , container , nextSibling ) ; el = next ; } hostInsert ( anchor ! , container , nextSibling ) ; } ; const removeStaticNode = ( { el , anchor } ) => { let next ; while ( el && el !== anchor ) { next = hostNextSibling ( el ) ; hostRemove ( el ) ; el = next ; } hostRemove ( anchor ! ) ; } ; const processElement = ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { isSVG = isSVG || ( n2 . type as string ) === 'svg' ; if ( n1 == null ) { mountElement ( n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else { patchElement ( n1 , n2 , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } } ; const mountElement = ( vnode , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { let el ; let vnodeHook ; const { type , props , shapeFlag , transition , patchFlag , dirs } = vnode ; if ( ! __DEV__ && vnode . el && hostCloneNode !== undefined && patchFlag === PatchFlags . HOISTED ) { el = vnode . el = hostCloneNode ( vnode . el ) ; } else { el = vnode . el = hostCreateElement ( vnode . type as string , isSVG , props && props . is , props ) ; if ( shapeFlag & ShapeFlags . TEXT_CHILDREN ) { hostSetElementText ( el , vnode . children as string ) ; } else if ( shapeFlag & ShapeFlags . ARRAY_CHILDREN ) { mountChildren ( vnode . children as VNodeArrayChildren , el , null , parentComponent , parentSuspense , isSVG && type !== 'foreignObject' , slotScopeIds , optimized ) ; } if ( dirs ) { invokeDirectiveHook ( vnode , null , parentComponent , 'created' ) ; } if ( props ) { for ( const key in props ) { if ( key !== 'value' && ! isReservedProp ( key ) ) { hostPatchProp ( el , key , null , props [ key ] , isSVG , vnode . children as VNode [ ] , parentComponent , parentSuspense , unmountChildren ) ; } } /**
                 * Special case for setting value on DOM elements:
                 * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
                 * - it needs to be forced (#1471)
                 * #2353 proposes adding another renderer option to configure this, but
                 * the properties affects are so finite it is worth special casing it
                 * here to reduce the complexity. (Special casing it also should not
                 * affect non-DOM renderers)
                 */ if ( 'value' in props ) { hostPatchProp ( el , 'value' , null , props . value ) ; } if ( ( vnodeHook = props . onVnodeBeforeMount ) ) { invokeVNodeHook ( vnodeHook , parentComponent , vnode ) ; } } setScopeId ( el , vnode , vnode . scopeId , slotScopeIds , parentComponent ) ; } if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) { Object . defineProperty ( el , '__vnode' , { value : vnode , enumerable : false } ) ; Object . defineProperty ( el , '__vueParentComponent' , { value : parentComponent , enumerable : false } ) ; } if ( dirs ) { invokeDirectiveHook ( vnode , null , parentComponent , 'beforeMount' ) ; } const needCallTransitionHooks = ( ! parentSuspense || ( parentSuspense && ! parentSuspense . pendingBranch ) ) && transition && ! transition . persisted ; if ( needCallTransitionHooks ) { transition ! . beforeEnter ( el ) ; } hostInsert ( el , container , anchor ) ; if ( ( vnodeHook = props && props . onVnodeMounted ) || needCallTransitionHooks || dirs ) { queuePostRenderEffect ( ( ) => { vnodeHook && invokeVNodeHook ( vnodeHook , parentComponent , vnode ) ; needCallTransitionHooks && transition ! . enter ( el ) ; dirs && invokeDirectiveHook ( vnode , null , parentComponent , 'mounted' ) ; } , parentSuspense ) ; } } ; const setScopeId = ( el , vnode , scopeId , slotScopeIds , parentComponent ) => { if ( scopeId ) { hostSetScopeId ( el , scopeId ) ; } if ( slotScopeIds ) { for ( let i = 0 ; i < slotScopeIds . length ; i ++ ) { hostSetScopeId ( el , slotScopeIds [ i ] ) ; } } if ( parentComponent ) { let subTree = parentComponent . subTree ; if ( __DEV__ && subTree . patchFlag > 0 && subTree . patchFlag & PatchFlags . DEV_ROOT_FRAGMENT ) { subTree = filterSingleRoot ( subTree . children as VNodeArrayChildren ) || subTree ; } if ( vnode === subTree ) { const parentVNode = parentComponent . vnode ; setScopeId ( el , parentVNode , parentVNode . scopeId , parentVNode . slotScopeIds , parentComponent . parent ) ; } } } ; const mountChildren = ( children , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized , start = 0 ) => { for ( let i = start ; i < children . length ; i ++ ) { const child = ( children [ i ] = optimized ? cloneIfMounted ( children [ i ] as VNode ) : normalizeVNode ( children [ i ] ) ) ; patch ( null , child , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } } ; const patchElement = ( n1 , n2 , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { const el = ( n2 . el = n1 . el ! ) ; let { patchFlag , dynamicChildren , dirs } = n2 ; patchFlag |= n1 . patchFlag & PatchFlags . FULL_PROPS ; const oldProps = n1 . props || EMPTY_OBJ ; const newProps = n2 . props || EMPTY_OBJ ; let vnodeHook ; if ( ( vnodeHook = newProps . onVnodeBeforeUpdate ) ) { invokeVNodeHook ( vnodeHook , parentComponent , n2 , n1 ) ; } if ( dirs ) { invokeDirectiveHook ( n2 , n1 , parentComponent , 'beforeUpdate' ) ; } if ( __DEV__ && isHmrUpdating ) { patchFlag = 0 ; optimized = false ; dynamicChildren = null ; } const areChildrenSVG = isSVG && n2 . type !== 'foreignObject' ; if ( dynamicChildren ) { patchBlockChildren ( n1 . dynamicChildren ! , dynamicChildren , el , parentComponent , parentSuspense , areChildrenSVG , slotScopeIds ) ; if ( __DEV__ && parentComponent && parentComponent . type . __hmrId ) { traverseStaticChildren ( n1 , n2 ) ; } } else if ( ! optimized ) { patchChildren ( n1 , n2 , el , null , parentComponent , parentSuspense , areChildrenSVG , slotScopeIds , false ) ; } if ( patchFlag > 0 ) { if ( patchFlag & PatchFlags . FULL_PROPS ) { patchProps ( el , n2 , oldProps , newProps , parentComponent , parentSuspense , isSVG ) ; } else { if ( patchFlag & PatchFlags . CLASS ) { if ( oldProps . class !== newProps . class ) { hostPatchProp ( el , 'class' , null , newProps . class , isSVG ) ; } } if ( patchFlag & PatchFlags . STYLE ) { hostPatchProp ( el , 'style' , oldProps . style , newProps . style , isSVG ) ; } if ( patchFlag & PatchFlags . PROPS ) { const propsToUpdate = n2 . dynamicProps ! ; for ( let i = 0 ; i < propsToUpdate . length ; i ++ ) { const key = propsToUpdate [ i ] ; const prev = oldProps [ key ] ; const next = newProps [ key ] ; if ( next !== prev || key === 'value' ) { hostPatchProp ( el , key , prev , next , isSVG , n1 . children as VNode [ ] , parentComponent , parentSuspense , unmountChildren ) ; } } } } if ( patchFlag & PatchFlags . TEXT ) { if ( n1 . children !== n2 . children ) { hostSetElementText ( el , n2 . children as string ) ; } } } else if ( ! optimized && dynamicChildren == null ) { patchProps ( el , n2 , oldProps , newProps , parentComponent , parentSuspense , isSVG ) ; } if ( ( vnodeHook = newProps . onVnodeUpdated ) || dirs ) { queuePostRenderEffect ( ( ) => { vnodeHook && invokeVNodeHook ( vnodeHook , parentComponent , n2 , n1 ) ; dirs && invokeDirectiveHook ( n2 , n1 , parentComponent , 'updated' ) ; } , parentSuspense ) ; } } ; const patchBlockChildren = ( oldChildren , newChildren , fallbackContainer , parentComponent , parentSuspense , isSVG , slotScopeIds ) => { for ( let i = 0 ; i < newChildren . length ; i ++ ) { const oldVNode = oldChildren [ i ] ; const newVNode = newChildren [ i ] ; const container = oldVNode . el && ( oldVNode . type === Fragment || ! isSameVNodeType ( oldVNode , newVNode ) || oldVNode . shapeFlag & ( ShapeFlags . COMPONENT | ShapeFlags . TELEPORT ) ) ? hostParentNode ( oldVNode . el ) ! : fallbackContainer ; patch ( oldVNode , newVNode , container , null , parentComponent , parentSuspense , isSVG , slotScopeIds , true ) ; } } ; const patchProps = ( el , vnode , oldProps , newProps , parentComponent , parentSuspense , isSVG ) => { if ( oldProps !== newProps ) { for ( const key in newProps ) { if ( isReservedProp ( key ) ) continue ; const next = newProps [ key ] ; const prev = oldProps [ key ] ; if ( next !== prev && key !== 'value' ) { hostPatchProp ( el , key , prev , next , isSVG , vnode . children as VNode [ ] , parentComponent , parentSuspense , unmountChildren ) ; } } if ( oldProps !== EMPTY_OBJ ) { for ( const key in oldProps ) { if ( ! isReservedProp ( key ) && ! ( key in newProps ) ) { hostPatchProp ( el , key , oldProps [ key ] , null , isSVG , vnode . children as VNode [ ] , parentComponent , parentSuspense , unmountChildren ) ; } } } if ( 'value' in newProps ) { hostPatchProp ( el , 'value' , oldProps . value , newProps . value ) ; } } } ; const processFragment = ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { const fragmentStartAnchor = ( n2 . el = n1 ? n1 . el : hostCreateText ( '' ) ) ! ; const fragmentEndAnchor = ( n2 . anchor = n1 ? n1 . anchor : hostCreateText ( '' ) ) ! ; let { patchFlag , dynamicChildren , slotScopeIds : fragmentSlotScopeIds } = n2 ; if ( __DEV__ && isHmrUpdating ) { patchFlag = 0 ; optimized = false ; dynamicChildren = null ; } if ( fragmentSlotScopeIds ) { slotScopeIds = slotScopeIds ? slotScopeIds . concat ( fragmentSlotScopeIds ) : fragmentSlotScopeIds ; } if ( n1 == null ) { hostInsert ( fragmentStartAnchor , container , anchor ) ; hostInsert ( fragmentEndAnchor , container , anchor ) ; mountChildren ( n2 . children as VNodeArrayChildren , container , fragmentEndAnchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else { if ( patchFlag > 0 && patchFlag & PatchFlags . STABLE_FRAGMENT && dynamicChildren && n1 . dynamicChildren ) { patchBlockChildren ( n1 . dynamicChildren , dynamicChildren , container , parentComponent , parentSuspense , isSVG , slotScopeIds ) ; if ( __DEV__ && parentComponent && parentComponent . type . __hmrId ) { traverseStaticChildren ( n1 , n2 ) ; } else if ( n2 . key != null || ( parentComponent && n2 === parentComponent . subTree ) ) { traverseStaticChildren ( n1 , n2 , true ) ; } } else { patchChildren ( n1 , n2 , container , fragmentEndAnchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } } } ; const processComponent = ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { n2 . slotScopeIds = slotScopeIds ; if ( n1 == null ) { if ( n2 . shapeFlag & ShapeFlags . COMPONENT_KEPT_ALIVE ) { ; ( parentComponent ! . ctx as KeepAliveContext ) . activate ( n2 , container , anchor , isSVG , optimized ) ; } else { mountComponent ( n2 , container , anchor , parentComponent , parentSuspense , isSVG , optimized ) ; } } else { updateComponent ( n1 , n2 , optimized ) ; } } ; const mountComponent = ( initialVNode , container , anchor , parentComponent , parentSuspense , isSVG , optimized ) => { const compatMountInstance = __COMPAT__ && initialVNode . isCompatRoot && initialVNode . component ; const instance = compatMountInstance || ( initialVNode . component = createComponentInstance ( initialVNode , parentComponent , parentSuspense ) ) ; if ( __DEV__ && instance . type . __hmrId ) { registerHMR ( instance ) ; } if ( __DEV__ ) { pushWarningContext ( initialVNode ) ; startMeasure ( instance , `mount` ) ; } if ( isKeepAlive ( initialVNode ) ) { ; ( instance . ctx as KeepAliveContext ) . renderer = internals ; } if ( ! ( __COMPAT__ && compatMountInstance ) ) { if ( __DEV__ ) { startMeasure ( instance , `init` ) ; } setupComponent ( instance ) ; if ( __DEV__ ) { endMeasure ( instance , `init` ) ; } } if ( __FEATURE_SUSPENSE__ && instance . asyncDep ) { parentSuspense && parentSuspense . registerDep ( instance , setupRenderEffect ) ; if ( ! initialVNode . el ) { const placeholder = ( instance . subTree = createVNode ( Comment ) ) ; processCommentNode ( null , placeholder , container ! , anchor ) ; } return ; } setupRenderEffect ( instance , initialVNode , container , anchor , parentSuspense , isSVG , optimized ) ; if ( __DEV__ ) { popWarningContext ( ) ; endMeasure ( instance , `mount` ) ; } } ; const updateComponent = ( n1 , n2 , optimized ) => { const instance = ( n2 . component = n1 . component ) ! ; if ( shouldUpdateComponent ( n1 , n2 , optimized ) ) { if ( __FEATURE_SUSPENSE__ && instance . asyncDep && ! instance . asyncResolved ) { if ( __DEV__ ) { pushWarningContext ( n2 ) ; } updateComponentPreRender ( instance , n2 , optimized ) ; if ( __DEV__ ) { popWarningContext ( ) ; } return ; } else { instance . next = n2 ; invalidateJob ( instance . update ) ; instance . update ( ) ; } } else { n2 . component = n1 . component ; n2 . el = n1 . el ; instance . vnode = n2 ; } } ; const setupRenderEffect = ( instance , initialVNode , container , anchor , parentSuspense , isSVG , optimized ) => { const componentUpdateFn = ( ) => { if ( ! instance . isMounted ) { let vnodeHook ; const { el , props } = initialVNode ; const { bm , m , parent } = instance ; const isAsyncWrapperVNode = isAsyncWrapper ( initialVNode ) ; effect . allowRecurse = false ; if ( bm ) { invokeArrayFns ( bm ) ; } if ( ! isAsyncWrapperVNode && ( vnodeHook = props && props . onVnodeBeforeMount ) ) { invokeVNodeHook ( vnodeHook , parent , initialVNode ) ; } if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { instance . emit ( 'hook:beforeMount' ) ; } effect . allowRecurse = true ; if ( el && hydrateNode ) { const hydrateSubTree = ( ) => { if ( __DEV__ ) { startMeasure ( instance , `render` ) ; } instance . subTree = renderComponentRoot ( instance ) ; if ( __DEV__ ) { endMeasure ( instance , `render` ) ; } if ( __DEV__ ) { startMeasure ( instance , `hydrate` ) ; } hydrateNode ! ( el as Node , instance . subTree , instance , parentSuspense , null ) ; if ( __DEV__ ) { endMeasure ( instance , `hydrate` ) ; } } ; if ( isAsyncWrapperVNode ) { ; ( initialVNode . type as ComponentOptions ) . __asyncLoader ! ( ) . then ( ( ) => ! instance . isUnmounted && hydrateSubTree ( ) ) ; } else { hydrateSubTree ( ) ; } } else { if ( __DEV__ ) { startMeasure ( instance , `render` ) ; } const subTree = ( instance . subTree = renderComponentRoot ( instance ) ) ; if ( __DEV__ ) { endMeasure ( instance , `render` ) ; } if ( __DEV__ ) { startMeasure ( instance , `patch` ) ; } patch ( null , subTree , container , anchor , instance , parentSuspense , isSVG ) ; if ( __DEV__ ) { endMeasure ( instance , `patch` ) ; } initialVNode . el = subTree . el ; } if ( m ) { queuePostRenderEffect ( m , parentSuspense ) ; } if ( ! isAsyncWrapperVNode && ( vnodeHook = props && props . onVnodeMounted ) ) { const scopedInitialVNode = initialVNode ; queuePostRenderEffect ( ( ) => invokeVNodeHook ( vnodeHook ! , parent , scopedInitialVNode ) , parentSuspense ) ; } if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { queuePostRenderEffect ( ( ) => instance . emit ( 'hook:mounted' ) , parentSuspense ) ; } if ( initialVNode . shapeFlag & ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE ) { instance . a && queuePostRenderEffect ( instance . a , parentSuspense ) ; if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { queuePostRenderEffect ( ( ) => instance . emit ( 'hook:activated' ) , parentSuspense ) ; } } instance . isMounted = true ; if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) { devtoolsComponentAdded ( instance ) ; } initialVNode = container = anchor = null as any ; } else { let { next , bu , u , parent , vnode } = instance ; let originNext = next ; let vnodeHook ; if ( __DEV__ ) { pushWarningContext ( next || instance . vnode ) ; } effect . allowRecurse = false ; if ( next ) { next . el = vnode . el ; updateComponentPreRender ( instance , next , optimized ) ; } else { next = vnode ; } if ( bu ) { invokeArrayFns ( bu ) ; } if ( ( vnodeHook = next . props && next . props . onVnodeBeforeUpdate ) ) { invokeVNodeHook ( vnodeHook , parent , next , vnode ) ; } if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { instance . emit ( 'hook:beforeUpdate' ) ; } effect . allowRecurse = true ; if ( __DEV__ ) { startMeasure ( instance , `render` ) ; } const nextTree = renderComponentRoot ( instance ) ; if ( __DEV__ ) { endMeasure ( instance , `render` ) ; } const prevTree = instance . subTree ; instance . subTree = nextTree ; if ( __DEV__ ) { startMeasure ( instance , `patch` ) ; } patch ( prevTree , nextTree , hostParentNode ( prevTree . el ! ) ! , getNextHostNode ( prevTree ) , instance , parentSuspense , isSVG ) ; if ( __DEV__ ) { endMeasure ( instance , `patch` ) ; } next . el = nextTree . el ; if ( originNext === null ) { updateHOCHostEl ( instance , nextTree . el ) ; } if ( u ) { queuePostRenderEffect ( u , parentSuspense ) ; } if ( ( vnodeHook = next . props && next . props . onVnodeUpdated ) ) { queuePostRenderEffect ( ( ) => invokeVNodeHook ( vnodeHook ! , parent , next ! , vnode ) , parentSuspense ) ; } if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { queuePostRenderEffect ( ( ) => instance . emit ( 'hook:updated' ) , parentSuspense ) ; } if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) { devtoolsComponentUpdated ( instance ) ; } if ( __DEV__ ) { popWarningContext ( ) ; } } } ; const effect = new ReactiveEffect ( componentUpdateFn , ( ) => queueJob ( instance . update ) , instance . scope ) ; const update = ( instance . update = effect . run . bind ( effect ) as SchedulerJob ) ; update . id = instance . uid ; effect . allowRecurse = update . allowRecurse = true ; if ( __DEV__ ) { effect . onTrack = instance . rtc ? e => invokeArrayFns ( instance . rtc ! , e ) : void 0 ; effect . onTrigger = instance . rtg ? e => invokeArrayFns ( instance . rtg ! , e ) : void 0 ; update . ownerInstance = instance ; } update ( ) ; } ; const updateComponentPreRender = ( instance , nextVNode , optimized ) => { nextVNode . component = instance ; const prevProps = instance . vnode . props ; instance . vnode = nextVNode ; instance . next = null ; updateProps ( instance , nextVNode . props , prevProps , optimized ) ; updateSlots ( instance , nextVNode . children , optimized ) ; pauseTracking ( ) ; flushPreFlushCbs ( undefined , instance . update ) ; resetTracking ( ) ; } ; const patchChildren = ( n1 , n2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized = false ) => { const c1 = n1 && n1 . children ; const prevShapeFlag = n1 ? n1 . shapeFlag : 0 ; const c2 = n2 . children ; const { patchFlag , shapeFlag } = n2 ; if ( patchFlag > 0 ) { if ( patchFlag & PatchFlags . KEYED_FRAGMENT ) { patchKeyedChildren ( c1 as VNode [ ] , c2 as VNodeArrayChildren , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; return ; } else if ( patchFlag & PatchFlags . UNKEYED_FRAGMENT ) { patchUnkeyedChildren ( c1 as VNode [ ] , c2 as VNodeArrayChildren , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; return ; } } if ( shapeFlag & ShapeFlags . TEXT_CHILDREN ) { if ( prevShapeFlag & ShapeFlags . ARRAY_CHILDREN ) { unmountChildren ( c1 as VNode [ ] , parentComponent , parentSuspense ) ; } if ( c2 !== c1 ) { hostSetElementText ( container , c2 as string ) ; } } else { if ( prevShapeFlag & ShapeFlags . ARRAY_CHILDREN ) { if ( shapeFlag & ShapeFlags . ARRAY_CHILDREN ) { patchKeyedChildren ( c1 as VNode [ ] , c2 as VNodeArrayChildren , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else { unmountChildren ( c1 as VNode [ ] , parentComponent , parentSuspense , true ) ; } } else { if ( prevShapeFlag & ShapeFlags . TEXT_CHILDREN ) { hostSetElementText ( container , '' ) ; } if ( shapeFlag & ShapeFlags . ARRAY_CHILDREN ) { mountChildren ( c2 as VNodeArrayChildren , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } } } } ; const patchUnkeyedChildren = ( c1 , c2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { c1 = c1 || EMPTY_ARR ; c2 = c2 || EMPTY_ARR ; const oldLength = c1 . length ; const newLength = c2 . length ; const commonLength = Math . min ( oldLength , newLength ) ; let i ; for ( i = 0 ; i < commonLength ; i ++ ) { const nextChild = ( c2 [ i ] = optimized ? cloneIfMounted ( c2 [ i ] as VNode ) : normalizeVNode ( c2 [ i ] ) ) ; patch ( c1 [ i ] , nextChild , container , null , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } if ( oldLength > newLength ) { unmountChildren ( c1 , parentComponent , parentSuspense , true , false , commonLength ) ; } else { mountChildren ( c2 , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized , commonLength ) ; } } ; const patchKeyedChildren = ( c1 , c2 , container , parentAnchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) => { let i = 0 ; const l2 = c2 . length ; let e1 = c1 . length - 1 ; let e2 = l2 - 1 ; while ( i <= e1 && i <= e2 ) { const n1 = c1 [ i ] ; const n2 = ( c2 [ i ] = optimized ? cloneIfMounted ( c2 [ i ] as VNode ) : normalizeVNode ( c2 [ i ] ) ) ; if ( isSameVNodeType ( n1 , n2 ) ) { patch ( n1 , n2 , container , null , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else { break ; } i ++ ; } while ( i <= e1 && i <= e2 ) { const n1 = c1 [ e1 ] ; const n2 = ( c2 [ e2 ] = optimized ? cloneIfMounted ( c2 [ e2 ] as VNode ) : normalizeVNode ( c2 [ e2 ] ) ) ; if ( isSameVNodeType ( n1 , n2 ) ) { patch ( n1 , n2 , container , null , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else { break ; } e1 -- ; e2 -- ; } if ( i > e1 ) { if ( i <= e2 ) { const nextPos = e2 + 1 ; const anchor = nextPos < l2 ? ( c2 [ nextPos ] as VNode ) . el : parentAnchor ; while ( i <= e2 ) { patch ( null , ( c2 [ i ] = optimized ? cloneIfMounted ( c2 [ i ] as VNode ) : normalizeVNode ( c2 [ i ] ) ) , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; i ++ ; } } } else if ( i > e2 ) { while ( i <= e1 ) { unmount ( c1 [ i ] , parentComponent , parentSuspense , true ) ; i ++ ; } } else { const s1 = i ; const s2 = i ; const keyToNewIndexMap = new Map ( ) ; for ( i = s2 ; i <= e2 ; i ++ ) { const nextChild = ( c2 [ i ] = optimized ? cloneIfMounted ( c2 [ i ] as VNode ) : normalizeVNode ( c2 [ i ] ) ) ; if ( nextChild . key != null ) { if ( __DEV__ && keyToNewIndexMap . has ( nextChild . key ) ) { warn ( `Duplicate keys found during update:` , JSON . stringify ( nextChild . key ) , `Make sure keys are unique.` ) ; } keyToNewIndexMap . set ( nextChild . key , i ) ; } } let j ; let patched = 0 ; const toBePatched = e2 - s2 + 1 ; let moved = false ; let maxNewIndexSoFar = 0 ; const newIndexToOldIndexMap = new Array ( toBePatched ) ; for ( i = 0 ; i < toBePatched ; i ++ ) newIndexToOldIndexMap [ i ] = 0 ; for ( i = s1 ; i <= e1 ; i ++ ) { const prevChild = c1 [ i ] ; if ( patched >= toBePatched ) { unmount ( prevChild , parentComponent , parentSuspense , true ) ; continue ; } let newIndex ; if ( prevChild . key != null ) { newIndex = keyToNewIndexMap . get ( prevChild . key ) ; } else { for ( j = s2 ; j <= e2 ; j ++ ) { if ( newIndexToOldIndexMap [ j - s2 ] === 0 && isSameVNodeType ( prevChild , c2 [ j ] as VNode ) ) { newIndex = j ; break ; } } } if ( newIndex === undefined ) { unmount ( prevChild , parentComponent , parentSuspense , true ) ; } else { newIndexToOldIndexMap [ newIndex - s2 ] = i + 1 ; if ( newIndex >= maxNewIndexSoFar ) { maxNewIndexSoFar = newIndex ; } else { moved = true ; } patch ( prevChild , c2 [ newIndex ] as VNode , container , null , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; patched ++ ; } } const increasingNewIndexSequence = moved ? getSequence ( newIndexToOldIndexMap ) : EMPTY_ARR ; j = increasingNewIndexSequence . length - 1 ; for ( i = toBePatched - 1 ; i >= 0 ; i -- ) { const nextIndex = s2 + i ; const nextChild = c2 [ nextIndex ] as VNode ; const anchor = nextIndex + 1 < l2 ? ( c2 [ nextIndex + 1 ] as VNode ) . el : parentAnchor ; if ( newIndexToOldIndexMap [ i ] === 0 ) { patch ( null , nextChild , container , anchor , parentComponent , parentSuspense , isSVG , slotScopeIds , optimized ) ; } else if ( moved ) { if ( j < 0 || i !== increasingNewIndexSequence [ j ] ) { move ( nextChild , container , anchor , MoveType . REORDER ) ; } else { j -- ; } } } } } ; const move = ( vnode , container , anchor , moveType , parentSuspense = null ) => { const { el , type , transition , children , shapeFlag } = vnode ; if ( shapeFlag & ShapeFlags . COMPONENT ) { move ( vnode . component ! . subTree , container , anchor , moveType ) ; return ; } if ( __FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags . SUSPENSE ) { vnode . suspense ! . move ( container , anchor , moveType ) ; return ; } if ( shapeFlag & ShapeFlags . TELEPORT ) { ; ( type as typeof TeleportImpl ) . move ( vnode , container , anchor , internals ) ; return ; } if ( type === Fragment ) { hostInsert ( el ! , container , anchor ) ; for ( let i = 0 ; i < ( children as VNode [ ] ) . length ; i ++ ) { move ( ( children as VNode [ ] ) [ i ] , container , anchor , moveType ) ; } hostInsert ( vnode . anchor ! , container , anchor ) ; return ; } if ( type === Static ) { moveStaticNode ( vnode , container , anchor ) ; return ; } const needTransition = moveType !== MoveType . REORDER && shapeFlag & ShapeFlags . ELEMENT && transition ; if ( needTransition ) { if ( moveType === MoveType . ENTER ) { transition ! . beforeEnter ( el ! ) ; hostInsert ( el ! , container , anchor ) ; queuePostRenderEffect ( ( ) => transition ! . enter ( el ! ) , parentSuspense ) ; } else { const { leave , delayLeave , afterLeave } = transition ! ; const remove = ( ) => hostInsert ( el ! , container , anchor ) ; const performLeave = ( ) => { leave ( el ! , ( ) => { remove ( ) ; afterLeave && afterLeave ( ) ; } ) ; } ; if ( delayLeave ) { delayLeave ( el ! , remove , performLeave ) ; } else { performLeave ( ) ; } } } else { hostInsert ( el ! , container , anchor ) ; } } ; const unmount = ( vnode , parentComponent , parentSuspense , doRemove = false , optimized = false ) => { const { type , props , ref , children , dynamicChildren , shapeFlag , patchFlag , dirs } = vnode ; if ( ref != null ) { setRef ( ref , null , parentSuspense , vnode , true ) ; } if ( shapeFlag & ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE ) { ; ( parentComponent ! . ctx as KeepAliveContext ) . deactivate ( vnode ) ; return ; } const shouldInvokeDirs = shapeFlag & ShapeFlags . ELEMENT && dirs ; const shouldInvokeVnodeHook = ! isAsyncWrapper ( vnode ) ; let vnodeHook ; if ( shouldInvokeVnodeHook && ( vnodeHook = props && props . onVnodeBeforeUnmount ) ) { invokeVNodeHook ( vnodeHook , parentComponent , vnode ) ; } if ( shapeFlag & ShapeFlags . COMPONENT ) { unmountComponent ( vnode . component ! , parentSuspense , doRemove ) ; } else { if ( __FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags . SUSPENSE ) { vnode . suspense ! . unmount ( parentSuspense , doRemove ) ; return ; } if ( shouldInvokeDirs ) { invokeDirectiveHook ( vnode , null , parentComponent , 'beforeUnmount' ) ; } if ( shapeFlag & ShapeFlags . TELEPORT ) { ; ( vnode . type as typeof TeleportImpl ) . remove ( vnode , parentComponent , parentSuspense , optimized , internals , doRemove ) ; } else if ( dynamicChildren && ( type !== Fragment || ( patchFlag > 0 && patchFlag & PatchFlags . STABLE_FRAGMENT ) ) ) { unmountChildren ( dynamicChildren , parentComponent , parentSuspense , false , true ) ; } else if ( ( type === Fragment && patchFlag & ( PatchFlags . KEYED_FRAGMENT | PatchFlags . UNKEYED_FRAGMENT ) ) || ( ! optimized && shapeFlag & ShapeFlags . ARRAY_CHILDREN ) ) { unmountChildren ( children as VNode [ ] , parentComponent , parentSuspense ) ; } if ( doRemove ) { remove ( vnode ) ; } } if ( ( shouldInvokeVnodeHook && ( vnodeHook = props && props . onVnodeUnmounted ) ) || shouldInvokeDirs ) { queuePostRenderEffect ( ( ) => { vnodeHook && invokeVNodeHook ( vnodeHook , parentComponent , vnode ) ; shouldInvokeDirs && invokeDirectiveHook ( vnode , null , parentComponent , 'unmounted' ) ; } , parentSuspense ) ; } } ; const remove = vnode => { const { type , el , anchor , transition } = vnode ; if ( type === Fragment ) { removeFragment ( el ! , anchor ! ) ; return ; } if ( type === Static ) { removeStaticNode ( vnode ) ; return ; } const performRemove = ( ) => { hostRemove ( el ! ) ; if ( transition && ! transition . persisted && transition . afterLeave ) { transition . afterLeave ( ) ; } } ; if ( vnode . shapeFlag & ShapeFlags . ELEMENT && transition && ! transition . persisted ) { const { leave , delayLeave } = transition ; const performLeave = ( ) => leave ( el ! , performRemove ) ; if ( delayLeave ) { delayLeave ( vnode . el ! , performRemove , performLeave ) ; } else { performLeave ( ) ; } } else { performRemove ( ) ; } } ; const removeFragment = ( cur , end ) => { let next ; while ( cur !== end ) { next = hostNextSibling ( cur ) ! ; hostRemove ( cur ) ; cur = next ; } hostRemove ( end ) ; } ; const unmountComponent = ( instance , parentSuspense , doRemove ? ) => { if ( __DEV__ && instance . type . __hmrId ) { unregisterHMR ( instance ) ; } const { bum , scope , update , subTree , um } = instance ; if ( bum ) { invokeArrayFns ( bum ) ; } if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { instance . emit ( 'hook:beforeDestroy' ) ; } scope . stop ( ) ; if ( update ) { update . active = false ; unmount ( subTree , instance , parentSuspense , doRemove ) ; } if ( um ) { queuePostRenderEffect ( um , parentSuspense ) ; } if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance ) ) { queuePostRenderEffect ( ( ) => instance . emit ( 'hook:destroyed' ) , parentSuspense ) ; } queuePostRenderEffect ( ( ) => { instance . isUnmounted = true ; } , parentSuspense ) ; if ( __FEATURE_SUSPENSE__ && parentSuspense && parentSuspense . pendingBranch && ! parentSuspense . isUnmounted && instance . asyncDep && ! instance . asyncResolved && instance . suspenseId === parentSuspense . pendingId ) { parentSuspense . deps -- ; if ( parentSuspense . deps === 0 ) { parentSuspense . resolve ( ) ; } } if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) { devtoolsComponentRemoved ( instance ) ; } } ; const unmountChildren = ( children , parentComponent , parentSuspense , doRemove = false , optimized = false , start = 0 ) => { for ( let i = start ; i < children . length ; i ++ ) { unmount ( children [ i ] , parentComponent , parentSuspense , doRemove , optimized ) ; } } ; const getNextHostNode = vnode => { if ( vnode . shapeFlag & ShapeFlags . COMPONENT ) { return getNextHostNode ( vnode . component ! . subTree ) ; } if ( __FEATURE_SUSPENSE__ && vnode . shapeFlag & ShapeFlags . SUSPENSE ) { return vnode . suspense ! . next ( ) ; } return hostNextSibling ( ( vnode . anchor || vnode . el ) ! ) ; } ; const render = ( vnode , container , isSVG ) => { if ( vnode == null ) { if ( container . _vnode ) { unmount ( container . _vnode , null , null , true ) ; } } else { patch ( container . _vnode || null , vnode , container , null , null , null , isSVG ) ; } flushPostFlushCbs ( ) ; container . _vnode = vnode ; } ; const internals = { p : patch , um : unmount , m : move , r : remove , mt : mountComponent , mc : mountChildren , pc : patchChildren , pbc : patchBlockChildren , n : getNextHostNode , o : options } ; let hydrate ; let hydrateNode ; if ( createHydrationFns ) { ; [ hydrate , hydrateNode ] = createHydrationFns ( internals as RendererInternals < Node , Element > ) ; } return { render , hydrate , createApp : createAppAPI ( render , hydrate ) } ; } export function setRef ( rawRef , oldRawRef , parentSuspense , vnode , isUnmount = false ) { if ( isArray ( rawRef ) ) { rawRef . forEach ( ( r , i ) => setRef ( r , oldRawRef && ( isArray ( oldRawRef ) ? oldRawRef [ i ] : oldRawRef ) , parentSuspense , vnode , isUnmount ) ) ; return ; } if ( isAsyncWrapper ( vnode ) && ! isUnmount ) { return ; } const refValue = vnode . shapeFlag & ShapeFlags . STATEFUL_COMPONENT ? getExposeProxy ( vnode . component ! ) || vnode . component ! . proxy : vnode . el ; const value = isUnmount ? null : refValue ; const { i : owner , r : ref } = rawRef ; if ( __DEV__ && ! owner ) { warn ( `Missing ref owner context. ref cannot be used on hoisted vnodes. ` + `A vnode with ref must be created inside the render function.` ) ; return ; } const oldRef = oldRawRef && ( oldRawRef as VNodeNormalizedRefAtom ) . r ; const refs = owner . refs === EMPTY_OBJ ? ( owner . refs = { } ) : owner . refs ; const setupState = owner . setupState ; if ( oldRef != null && oldRef !== ref ) { if ( isString ( oldRef ) ) { refs [ oldRef ] = null ; if ( hasOwn ( setupState , oldRef ) ) { setupState [ oldRef ] = null ; } } else if ( isRef ( oldRef ) ) { oldRef . value = null ; } } if ( isString ( ref ) ) { const doSet = ( ) => { if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . V_FOR_REF , owner ) ) { registerLegacyRef ( refs , ref , refValue , owner , rawRef . f , isUnmount ) ; } else { refs [ ref ] = value ; } if ( hasOwn ( setupState , ref ) ) { setupState [ ref ] = value ; } } ; if ( value ) { ; ( doSet as SchedulerJob ) . id = - 1 ; queuePostRenderEffect ( doSet , parentSuspense ) ; } else { doSet ( ) ; } } else if ( isRef ( ref ) ) { const doSet = ( ) => { ref . value = value ; } ; if ( value ) { ; ( doSet as SchedulerJob ) . id = - 1 ; queuePostRenderEffect ( doSet , parentSuspense ) ; } else { doSet ( ) ; } } else if ( isFunction ( ref ) ) { callWithErrorHandling ( ref , owner , ErrorCodes . FUNCTION_REF , [ value , refs ] ) ; } else if ( __DEV__ ) { warn ( 'Invalid template ref type:' , value , `(${ typeof value })` ) ; } } export function invokeVNodeHook ( hook , instance , vnode , prevVNode = null ) { callWithAsyncErrorHandling ( hook , instance , ErrorCodes . VNODE_HOOK , [ vnode , prevVNode ] ) ; } /**
 * #1156
 * When a component is HMR-enabled, we need to make sure that all static nodes
 * inside a block also inherit the DOM element from the previous tree so that
 * HMR updates (which are full updates) can retrieve the element for patching.
 *
 * #2080
 * Inside keyed `template` fragment static children, if a fragment is moved,
 * the children will always moved so that need inherit el form previous nodes
 * to ensure correct moved position.
 */ export function traverseStaticChildren ( n1 , n2 , shallow = false ) { const ch1 = n1 . children ; const ch2 = n2 . children ; if ( isArray ( ch1 ) && isArray ( ch2 ) ) { for ( let i = 0 ; i < ch1 . length ; i ++ ) { const c1 = ch1 [ i ] as VNode ; let c2 = ch2 [ i ] as VNode ; if ( c2 . shapeFlag & ShapeFlags . ELEMENT && ! c2 . dynamicChildren ) { if ( c2 . patchFlag <= 0 || c2 . patchFlag === PatchFlags . HYDRATE_EVENTS ) { c2 = ch2 [ i ] = cloneIfMounted ( ch2 [ i ] as VNode ) ; c2 . el = c1 . el ; } if ( ! shallow ) traverseStaticChildren ( c1 , c2 ) ; } if ( __DEV__ && c2 . type === Comment && ! c2 . el ) { c2 . el = c1 . el ; } } } } function getSequence ( arr ) { const p = arr . slice ( ) ; const result = [ 0 ] ; let i , j , u , v , c ; const len = arr . length ; for ( i = 0 ; i < len ; i ++ ) { const arrI = arr [ i ] ; if ( arrI !== 0 ) { j = result [ result . length - 1 ] ; if ( arr [ j ] < arrI ) { p [ i ] = j ; result . push ( i ) ; continue ; } u = 0 ; v = result . length - 1 ; while ( u < v ) { c = ( u + v ) >> 1 ; if ( arr [ result [ c ] ] < arrI ) { u = c + 1 ; } else { v = c ; } } if ( arrI < arr [ result [ u ] ] ) { if ( u > 0 ) { p [ i ] = result [ u - 1 ] ; } result [ u ] = i ; } } } u = result . length ; v = result [ u - 1 ] ; while ( u -- > 0 ) { result [ u ] = v ; v = p [ v ] ; } return result ; }