import { tc , SVEMIX_DIR } from '../utils.js' ; import type { InternalConfig } from '../../load_config' ; import type { Transformer } from './types' ; const SvemixMeta = ( defaults ) : string => `
  <Meta _defaults={${ stringify ( defaults ) }} {_metadata} />
` ; function stringify ( obj_from_json ) { if ( typeof obj_from_json !== 'object' || Array . isArray ( obj_from_json ) ) { return JSON . stringify ( obj_from_json ) ; } let props = Object . keys ( obj_from_json ) . map ( ( key ) => `${ key }:${ stringify ( obj_from_json [ key ] ) }` ) . join ( ',' ) ; return `{${ props }}` ; } const InstanceTransformer = function ( args ) { let { doc , config } = args ; const instanceContent = `
    <script ${ tc ( doc . scripts . instance ?. attrs ?. lang === 'ts' , 'lang="ts"' ) }>
        import { Meta } from "${ SVEMIX_DIR ( ) }"; 
        ${ doc . scripts . instance ?. content || '' }
        export let _metadata = {};
    </script>
    ${ SvemixMeta ( config . seo ) }
  ` ; return instanceContent ; } ; export default InstanceTransformer ;