|
| 1 | + |
| 2 | +{% if package %} |
| 3 | + {% set types = api.packages[package] %} |
| 4 | +{% endif %} |
| 5 | + |
| 6 | +{%- macro anchor(text, level=3, prefix='', class='', slot='') -%} |
| 7 | + {%- set id = (prefix + '-' + text) if prefix else text -%} |
| 8 | + <h{{ level }} |
| 9 | + id="{{- id | lower | trim -}}" |
| 10 | + class="{{- class -}}" |
| 11 | + slot="{{- slot -}}"> |
| 12 | + <a class="anchor" href="#{{- id | lower | trim -}}"> |
| 13 | + <svg class="octicon octicon-link" viewBox="0 0 16 16" aria-hidden="true" width="16" height="16"> |
| 14 | + <path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path> |
| 15 | + </svg> |
| 16 | + </a> |
| 17 | + {{- text -}} |
| 18 | + </h{{ level }}> |
| 19 | +{%- endmacro -%} |
| 20 | + |
| 21 | +{% macro getTSDocMarkdown(type) %} |
| 22 | +{% markdown %}{{ type | getSummary }}{% endmarkdown %} |
| 23 | +{% markdown %}{{ type.comment.shortText }}{% endmarkdown %} |
| 24 | +{% markdown %}{{ type.comment.text }}{% endmarkdown %} |
| 25 | +{% endmacro %} |
| 26 | + |
| 27 | +{%- macro codeBlock(type, lang='ts') -%} |
| 28 | +{% markdown %}```{{ lang }} |
| 29 | +{{ type | safe }} |
| 30 | +```{% endmarkdown %} |
| 31 | +{%- endmacro -%} |
| 32 | + |
| 33 | +{%- macro literal(type) -%} |
| 34 | + {{ ('null' if type.value == null else ('"' + type.value + '"')) | safe }} |
| 35 | +{%- endmacro -%} |
| 36 | + |
| 37 | +{%- macro union(type, flags) -%} |
| 38 | + {%- for item in type.types -%} |
| 39 | + {%- if flags.isOptional and item.type == 'intrinsic' and item.name == 'undefined' -%} |
| 40 | + {%- else -%} |
| 41 | + {{ typeString(item) }}{{ '|' if not loop.last }} |
| 42 | + {%- endif -%} |
| 43 | + {%- endfor -%} |
| 44 | +{%- endmacro -%} |
| 45 | + |
| 46 | +{%- macro array(type) -%} |
| 47 | + {{ type.elementType.name }}[] |
| 48 | +{%- endmacro -%} |
| 49 | + |
| 50 | +{%- macro reflection(type) -%} |
| 51 | + {%- if type.declaration.kindString == 'Type literal' -%} |
| 52 | + {{ '' }} |
| 53 | + {% elif type.declaration.kindString == 'Call signature' %} |
| 54 | + {{ callSignature(type.declaration.signatures[0]) }} |
| 55 | + {%- endif -%} |
| 56 | +{%- endmacro -%} |
| 57 | + |
| 58 | +{%- macro typeString(type, flags) -%} |
| 59 | + {%- if type.type == 'reflection' -%} {{ reflection(type) }} |
| 60 | + {%- elif type.type == 'literal' -%} {{ literal(type) }} |
| 61 | + {%- elif type.type == 'typeOperator' -%} {{ type.operator }} {{ typeString(type.target) }} |
| 62 | + {%- elif type.type == 'array' -%} {{ array(type, flags) }} |
| 63 | + {%- elif type.type == 'union' -%} {{ union(type, flags) }} |
| 64 | + {%- else -%} |
| 65 | + {{ type.name }} |
| 66 | + {%- if type.typeArguments -%} |
| 67 | + < |
| 68 | + {%- for arg in type.typeArguments -%} |
| 69 | + {%- if arg.type == 'array' -%} |
| 70 | + {{ array(arg) }} |
| 71 | + {%- elif arg.type == 'union' -%} |
| 72 | + {{ union(arg) }} |
| 73 | + {%- else -%} |
| 74 | + {{ arg.name }} |
| 75 | + {%- endif -%} |
| 76 | + {{- ', ' if not loop.last -}} |
| 77 | + {%- endfor -%} |
| 78 | + > |
| 79 | + {%- endif -%} |
| 80 | + {%- endif -%} |
| 81 | +{%- endmacro -%} |
| 82 | + |
| 83 | +{%- macro callSignature(sig) -%} |
| 84 | + {{ sig.name if sig.name != '__type' }} |
| 85 | + {%- if sig.typeParameter -%}< |
| 86 | + {%- for param in sig.typeParameter -%} |
| 87 | + {{ param.name }}{{- ', ' if not loop.last -}} |
| 88 | + {%- endfor -%} |
| 89 | + >{%- endif -%}( |
| 90 | + {%- for param in sig.parameters -%} |
| 91 | + {{ param.name }}: {{ typeString(param.type, param.flags) }}{{- ', ' if not loop.last -}} |
| 92 | + {%- endfor -%} |
| 93 | + ){{ (' =>' if sig.name == '__type' else ':') | safe }} {{ typeString(sig.type, sig.flags) }} |
| 94 | +{%- endmacro -%} |
| 95 | + |
| 96 | + |
| 97 | +{%- for type in types -%} |
| 98 | + <article class="type" data-name="{{ type.name }}"> |
| 99 | + {{ anchor(type.name, level=3) }} |
| 100 | + {{ getTSDocMarkdown(type) }} |
| 101 | + |
| 102 | + {# Properties #} |
| 103 | + {% if type | getProperties | length %} |
| 104 | + {{ anchor('Properties', level=3, prefix=type.name) }} |
| 105 | + {%- for property in type | getProperties -%} |
| 106 | + <type-doc kind="property" data-name="{{ property.name }}"> |
| 107 | + <span slot="name"> |
| 108 | + {{ anchor(property.name, level=4, prefix=type.name) }} |
| 109 | + {% if property.flags.isOptional %}<span>(optional)</span>{% endif %} |
| 110 | + </span> |
| 111 | + {% if property.type %} |
| 112 | + <span slot="type">{{ codeBlock(typeString(property.type, property.flags)) }}</span> |
| 113 | + {% endif %} |
| 114 | + |
| 115 | + {{ getTSDocMarkdown(property) }} |
| 116 | + </type-doc> |
| 117 | + {%- endfor -%} |
| 118 | + {% endif %} |
| 119 | + {# End Properties #} |
| 120 | + |
| 121 | + {# Methods #} |
| 122 | + {% if type | getMethods | length %} |
| 123 | + {{ anchor('Methods', level=3, prefix=type.name) }} |
| 124 | + {%- for method in type | getMethods -%} |
| 125 | + <type-doc kind="method" |
| 126 | + data-method="{{ method.name }}" |
| 127 | + data-name="{{ method.name }}"> |
| 128 | + {{ anchor(method.name, level=4, slot='name', prefix=type.name) }} |
| 129 | + |
| 130 | + {% for sig in method.signatures %} |
| 131 | + |
| 132 | + {{ getTSDocMarkdown(sig) }} |
| 133 | + |
| 134 | + {# Type Parameters #} |
| 135 | + {%- if sig.typeParameter -%} |
| 136 | + {{ anchor('Type Parameters', level=4, prefix=(type.name + '-' + method.name)) }} |
| 137 | + {%- for param in sig.typeParameter -%} |
| 138 | + <type-doc kind="type-parameter" data-parameter="{{ param.name }}"> |
| 139 | + {{ anchor(param.name, level=5, slot='name', prefix=(type.name + '-' + method.name + '-type-parameter')) }} |
| 140 | + {% if param.type %} |
| 141 | + <span slot="type"> |
| 142 | + {%- markdown -%}{{ codeBlock(typeString(param.type, param.flags)) }}{%- endmarkdown -%} |
| 143 | + </span> |
| 144 | + {% endif %} |
| 145 | + {{ getTSDocMarkdown(param) }} |
| 146 | + </type-doc> |
| 147 | + {%- endfor -%} |
| 148 | + {%- endif -%} |
| 149 | + {# End Type Parameters #} |
| 150 | + |
| 151 | + {# Parameters #} |
| 152 | + {% if sig.parameters %} |
| 153 | + {{ anchor('Parameters', level=4, prefix=method.name) }} |
| 154 | + {%- for param in sig.parameters -%} |
| 155 | + <type-doc kind="parameter" data-parameter="{{ param.name }}"> |
| 156 | + {{ anchor(param.name, level=5, slot='name', prefix=('parameter-'+method.name)) }} |
| 157 | + <span slot="type"> |
| 158 | + {%- markdown -%}{{ codeBlock(typeString(param.type, param.flags)) }}{%- endmarkdown -%} |
| 159 | + </span> |
| 160 | + {{ getTSDocMarkdown(param) }} |
| 161 | + </type-doc> |
| 162 | + {%- endfor -%} |
| 163 | + {% endif %} |
| 164 | + {# End Parameters #} |
| 165 | + |
| 166 | + {# Return #} |
| 167 | + <type-doc kind="return"> |
| 168 | + {{ anchor('Returns', level=4, slot='name', prefix=(type.name + '-' + method.name)) }} |
| 169 | + <span slot="type"> |
| 170 | + {% markdown %}{{ codeBlock(typeString(sig.type)) }}{% endmarkdown %} |
| 171 | + </span> |
| 172 | + {{ getTSDocMarkdown(param) }} |
| 173 | + </type-doc> |
| 174 | + {# End Return #} |
| 175 | + {% endfor %} |
| 176 | + |
| 177 | + </type-doc> |
| 178 | + {%- endfor -%} |
| 179 | + {% endif %} |
| 180 | + {# End Methods #} |
| 181 | + |
| 182 | + </article> |
| 183 | +{%- endfor -%} |
0 commit comments