import { DeepTypeRef , Description , InputValue , TypeRef } from "../interface" ; import { LIST , NON_NULL } from "./introspection" ; export class HTML { index = 1 ; code ( code ) { return `<code class="highlight"><table class="code"><tbody>${ code }</tbody></table></code>` ; } highlight ( text ) { return `<strong>${ text }</strong>` ; } sup ( text ) { return ` <sup>${ text }</sup>` ; } line ( code ? ) { const row = this . index ++ ; return `<tr class="row"><td id="L${ row }" class="td-index">${ row }</td><td id="LC${ row }" class="td-code">${ code || "" }</td></tr>` ; } tab ( code ) { return `<span class="tab">${ code }</span>` ; } keyword ( keyword ) { return `<span class="keyword operator ts">${ keyword }</span>` ; } comment ( comment ) { return `<span class="comment line"># ${ comment }</span>` ; } identifier ( type ) { return `<span class="identifier">${ type . name }</span>` ; } parameter ( arg ) { return `<span class="variable parameter">${ arg . name }</span>` ; } property ( name ) { return `<span class="meta">${ name }</span>` ; } useIdentifier ( type , toUrl ) { switch ( type . kind ) { case LIST : return ( "[" + this . useIdentifier ( ( type as DeepTypeRef ) . ofType , toUrl ) + "]" ) ; case NON_NULL : return this . useIdentifier ( ( type as DeepTypeRef ) . ofType , toUrl ) + "!" ; default : return `<a class="support type" href="${ toUrl }">${ type . name }</a>` ; } } useIdentifierLength ( type , base = 0 ) { switch ( type . kind ) { case LIST : return this . useIdentifierLength ( ( type as DeepTypeRef ) . ofType , base + 2 ) ; case NON_NULL : return this . useIdentifierLength ( ( type as DeepTypeRef ) . ofType , base + 1 ) ; default : return base + ( type . name || "" ) . length ; } } value ( val ) { return val [ 0 ] === '"' ? `<span class="string">${ val }</span>` : `<span class="constant numeric">${ val }</span>` ; } } export function split ( text , len ) { return text . split ( /\s+/ ) . reduce ( ( result , word ) => { const last = result . length - 1 ; const lineLen = result [ last ] . length ; if ( lineLen === 0 ) { result [ last ] = word ; } else if ( lineLen < len ) { result [ last ] = result [ last ] + " " + word ; } else { result . push ( word ) ; } return result ; } , [ "" ] ) ; }