import { defineComponent , InjectionKey , provide , inject , readonly , SetupContext , VNode , PropType , DefineComponent , } from 'vue' ; export type ContextType < T > = any ; export type CreateContext < T > = DefineComponent < { } , ( ) => VNode | VNode [ ] | undefined , any > ; export const createContext = < T > ( contextInjectKey = Symbol ( ) , injectCompName = 'Context.Provider' ) : CreateContext < T > => { const ContextProvider = defineComponent ( { name : injectCompName , props : { value : { type : Object as PropType < ContextType < T > > , required : true , } , } , setup ( props , { slots } ) { provide ( contextInjectKey , readonly ( props . value ) ) ; return ( ) => slots . default ?. ( ) ; } , } ) ; return ContextProvider as any ; } ; export const useContext = < T > ( contextInjectKey = Symbol ( ) , defaultValue ? ) : T => { return inject ( contextInjectKey , defaultValue || ( { } as T ) ) ; } ;