import type { ComponentPublicInstance , App } from 'vue' ; import type { SetupOptions } from '@vuedx/preview-provider' ; import * as Path from 'path' ; import { getStackTraceLine } from './stacktrace' ; import { execute , executeAsApp } from './vm' ; param previewName export function usePreview ( previewName ) ; param previewName param overrides export function usePreview ( previewName , overrides ) ; param fileName param previewName export function usePreview ( fileName , previewName ) ; param fileName param previewName param overrides export function usePreview ( fileName , previewName , overrides ) ; export function usePreview ( ... args ) { const { fileName , previewName , overrides } = prepareArgs ( args ) ; return execute ( fileName , previewName ) ( overrides ) ; } param previewName export function usePreviewApp ( previewName ) ; param previewName param overrides export function usePreviewApp ( previewName , overrides ) ; param fileName param previewName export function usePreviewApp ( fileName , previewName ) ; param fileName param previewName param overrides export function usePreviewApp ( fileName , previewName , overrides ) ; export function usePreviewApp ( ... args ) { const { fileName , previewName , overrides } = prepareArgs ( args ) ; return executeAsApp ( fileName , previewName ) ( overrides ) ; } function prepareArgs ( args ) { const fileName = getFileName ( args . length === 3 || ( args . length === 2 && typeof args [ 1 ] === 'string' ) ? args [ 0 ] : undefined , 3 ) ; const previewName = args . length === 3 ? args [ 1 ] : args . length === 2 && typeof args [ 1 ] === 'string' ? args [ 1 ] : args [ 0 ] ; const overrides = args . length === 3 ? args [ 2 ] : args . length === 2 && typeof args [ 1 ] !== 'string' ? args [ 1 ] : { } ; return { fileName , previewName , overrides } ; } function getFileName ( fileName ? , depth = 2 ) { if ( fileName != null && Path . isAbsolute ( fileName ) ) return fileName ; const trace = getStackTraceLine ( depth ) ; if ( trace == null ) throw new Error ( 'CannotDetectFileName' ) ; if ( fileName != null ) return Path . resolve ( Path . dirname ( trace . fileName ) , fileName ) ; const dirName = Path . dirname ( trace . fileName ) ; const baseName = Path . basename ( trace . fileName ) . replace ( /(?:\.(?:spec|test))?\.(?:js|ts)x?$/ , '' ) + '.vue' ; const testDir = Path . sep + '__tests__' + Path . sep ; if ( dirName . includes ( testDir ) ) { return Path . resolve ( dirName . replace ( testDir , Path . sep ) , baseName ) ; } return Path . resolve ( dirName , baseName ) ; }