packages/lit-dev-content/site/_includes/api.html
--- layout: docs --- {% macro importStatement(symbol) -%} import { {{symbol.name}} } from '{{ symbol.entrypointSources[0].moduleSpecifier }}'; {%- endmacro %} {% macro locationLink(location, label) -%} {{label}} {%- endmacro %} {%- macro externalLink(url, label) -%} {%- if url.startsWith("https://developer.mozilla.org") -%} MDN {%- endif %} {{ label -}} {%- endmacro -%} {% macro heritageList(node) -%} {%- set arrow = joiner(' → ') %} {%- for super in node.heritage -%} {{- arrow() }} {{- type(super) -}} {%- endfor -%} {% endmacro %} {% macro kind(obj) %} {% if obj.kindString == "Function" and obj.sources[0].fileName.includes('/decorators/') %} decorator {% elif obj.kindString == "Function" and obj.sources[0].fileName.includes('/directives/') %} directive {% elif obj.kindString == "Interface" %} type {% elif obj.kindString == "Type alias" %} type {% elif obj.kindString == "Variable" %} value {% elif obj.kindString == "Accessor" %} property {% else %} {{ obj.kindString | lower }} {% endif %} {% endmacro %} {%- macro type(t) -%} {%- if t.type == 'array' -%} Array<{{- type(t.elementType) -}}> {%- elif t.operator == 'readonly' and t.target.type == 'array' -%} ReadonlyArray<{{- type(t.target.elementType) -}}> {%- elif t.operator == 'keyof' -%} keyof {{ type(t.target) }} {%- elif t.operator == 'unique' and t.target.name == 'symbol' -%} symbol {%- elif t.type == 'conditional' -%} {{ type(t.checkType) }} ? {{ type(t.trueType) }} : {{ type(t.falseType) }} {%- elif t.type == 'union' -%} {%- set pipe = joiner(' | ') -%} {%- for item in t.types -%} {{- pipe() -}} {{- type(item) -}} {%- endfor -%} {%- elif t.type === 'indexedAccess' -%} {{- type(t.objectType) }}[{{ type(t.indexType) }}] {%- elif t.type == 'query' -%} {{- type(t.queryType) -}} {%- elif t.type == 'tuple' -%} [{%- set comma = joiner(', ') -%} {%- for el in t.elements -%} {{- comma() -}} {{- type(el) -}} {%- endfor -%}] {%- elif t.type == 'reflection' -%} {{- type(t.declaration) -}} {%- elif (t.kindString == 'Interface' or t.kindString == 'Type literal') and t.children -%} { {%- set comma = joiner(', ') -%} {%- for prop in t.children -%} {{- comma() -}} {{- prop.name -}}: {{ type(prop) -}} {%- endfor -%} } {%- elif t.signatures[0] -%} {{- type(t.signatures[0]) -}} {%- elif t.kindString === 'Call signature' -%} ( {%- set comma = joiner(', ') -%} {%- for param in t.parameters -%} {{- comma() -}} {%- if param.type.type == 'tuple' -%} {{- type(param.type) -}} {%- else -%} {{- param.name -}} {%- if param.flags.isOptional -%} ? {%- endif -%} : {{ type(param.type) -}} {%- endif -%} {%- endfor -%} ) => {{ type(t.type) }} {%- elif t.location -%} {{- locationLink(t.location, t.name) -}} {%- elif t.externalUrl -%} {{- externalLink(t.externalUrl, t.name) -}} {%- elif t.type == "literal" -%} {%- if t.value == null -%} null {%- elif (t.value | typeof) == "string" -%} "{{- t.value -}}" {%- else -%} {{- t.value -}} {%- endif -%} {%- elif (t.type | typeof) == "object" -%} {{- type(t.type) -}} {%- elif t.name and t.name !== '__type' -%} {{- t.name -}} {%- else -%} TODO {# {{ t | dump }} #} {%- endif -%} {%- if t.typeArguments -%} < {%- set comma = joiner(', ') -%} {%- for arg in t.typeArguments -%} {{- comma() -}} {{- type(arg) -}} {%- endfor -%} > {%- endif -%} {%- endmacro -%} {% macro signature(sig) -%} {%- if sig.kindString === "Constructor signature" -%} new{{ sig.type.name -}} {%- else -%} {{- sig.name -}} {%- endif -%} ( {%- set comma = joiner(', ') -%} {%- for param in sig.parameters -%} {{- comma() -}} {{- param.name -}} {%- if param.flags.isOptional -%} ? {%- endif -%} {%- endfor -%} ): {{ type(sig.type) -}} {%- endmacro %} {% macro params(t) %}
{% for param in t.signatures[0].parameters %} {{ param.name -}} {%- if param.flags.isOptional -%} ? {%- endif -%} {{ type(param.type) }} {{ param.comment.shortText | markdownWithoutHtml | safe }} {% endfor %} {% endmacro %} {% macro viewSourceLink(symbol) %} {% if symbol.sources[0].fileName and not symbol.sources[0].fileName.endsWith('.d.ts') %} View source {% endif %} {% endmacro %} {% macro anchor(id, name) %} # Permalink to {{ name }} {% endmacro %} {% macro properties(arr) %} {% for prop in arr %}
{{ anchor(prop.location.anchor, prop.name) }} {{ viewSourceLink(prop) }}
{{ prop.comment.shortText | markdownWithoutHtml | safe }} {% if prop.signatures[0].parameters.length > 0 %}
{{ params(prop) }} {% endif %} {% if prop.comment.text %}
{{ prop.comment.text | markdownWithoutHtml | safe }} {% endif %} {% endfor %} {% endmacro %} {% for item in data.items %}
{{ kind(item) }} {% if item.location.anchor %} {{ anchor(item.location.anchor, item.name) }} {% endif %} {{ viewSourceLink(item) }} {{ item.comment.shortText | markdownWithoutHtml | safe }}
{% highlight "ts" -%}{{ importStatement(item) }}{%- endhighlight -%} {% if item.signatures[0] %}
{{ signature(item.signatures[0]) }}
{% if item.signatures[0].parameters.length > 0 %}
{{ params(item) }} {% endif %} {% elif item.type %}
{{ type(item.type) }} {% endif %} {% if item.comment.text %}
{{ item.comment.text | markdownWithoutHtml | safe }} {% endif %} {% if item.expandedCategories.length > 0 %} {% for category in item.expandedCategories %}
{{ properties(category.children) }} {% endfor %} {% elif item.children.length > 0 %}
{{ properties(item.children) }} {% endif %} {% endfor %}