/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import type { Config , Printer , Refs } from '../../types' ; import escapeHTML from './escapeHTML' ; export const printProps = ( keys , props , config , indentation , depth , refs , printer ) : string => { const indentationNext = indentation + config . indent ; const colors = config . colors ; return keys . map ( ( key ) => { const value = props [ key ] ; let printed = printer ( value , config , indentationNext , depth , refs ) ; if ( typeof value !== 'string' ) { if ( printed . indexOf ( '\n' ) !== - 1 ) { printed = config . spacingOuter + indentationNext + printed + config . spacingOuter + indentation ; } printed = '{' + printed + '}' ; } return ( config . spacingInner + indentation + colors . prop . open + key + colors . prop . close + '=' + colors . value . open + printed + colors . value . close ) ; } ) . join ( '' ) ; } ; export const printChildren = ( children , config , indentation , depth , refs , printer ) : string => children . map ( ( child ) => config . spacingOuter + indentation + ( typeof child === 'string' ? printText ( child , config ) : printer ( child , config , indentation , depth , refs ) ) ) . join ( '' ) ; export const printText = ( text , config ) : string => { const contentColor = config . colors . content ; return contentColor . open + escapeHTML ( text ) + contentColor . close ; } ; export const printComment = ( comment , config ) : string => { const commentColor = config . colors . comment ; return ( commentColor . open + '<!--' + escapeHTML ( comment ) + '-->' + commentColor . close ) ; } ; export const printElement = ( type , printedProps , printedChildren , config , indentation ) : string => { const tagColor = config . colors . tag ; return ( tagColor . open + '<' + type + ( printedProps && tagColor . close + printedProps + config . spacingOuter + indentation + tagColor . open ) + ( printedChildren ? '>' + tagColor . close + printedChildren + config . spacingOuter + indentation + tagColor . open + '</' + type : ( printedProps && ! config . min ? '' : ' ' ) + '/' ) + '>' + tagColor . close ) ; } ; export const printElementAsLeaf = ( type , config ) : string => { const tagColor = config . colors . tag ; return ( tagColor . open + '<' + type + tagColor . close + ' …' + tagColor . open + ' />' + tagColor . close ) ; } ;