Back to Lit

MDN

packages/lit-dev-content/site/_includes/api-v1.html

latest6.0 KB
Original Source

--- 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.externalLocation -%} {{- externalLink(t.externalLocation.url, 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.text | 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 %}

{% if prop.flags.isStatic %} static {% endif %} {% if prop.flags.isReadonly %} readonly {% endif %} {% if prop.signatures[0] %} {{ signature(prop.signatures[0]) }} {% elif prop.type %} {{ prop.name }} {%- if prop.flags.isOptional -%} ? {%- endif -%} : {{ type(prop.type) }} {% else %} {{ prop.name }} {% endif %}

{{ anchor(prop.location.anchor, prop.name) }} {{ viewSourceLink(prop) }}

{{ prop.comment.shortText | markdownWithoutHtml | safe }} {% if prop.signatures[0].parameters.length > 0 %}

Parameters

{{ params(prop) }} {% endif %} {% if prop.comment.text %}

Details

{{ prop.comment.text | markdownWithoutHtml | safe }} {% endif %} {% endfor %} {% endmacro %} {% for item in data.items %}

{{ item.name }}

{{ kind(item) }} {% if item.location.anchor %} {{ anchor(item.location.anchor, item.name) }} {% endif %} {{ viewSourceLink(item) }} {{ item.comment.shortText | markdownWithoutHtml | safe }}

Import

{% highlight "ts" -%}{{ importStatement(item) }}{%- endhighlight -%} {% if item.signatures[0] %}

Signature

{{ signature(item.signatures[0]) }}

{% if item.signatures[0].parameters.length > 0 %}

Parameters

{{ params(item) }} {% endif %} {% elif item.type %}

Type

{{ type(item.type) }} {% endif %} {% if item.comment.text %}

Details

{{ item.comment.text | markdownWithoutHtml | safe }} {% endif %} {% if item.expandedCategories.length > 0 %} {% for category in item.expandedCategories %}

{{ category.title }} {{ anchor(category.anchor, category.title) }}

{{ properties(category.children) }} {% endfor %} {% elif item.children.length > 0 %}

Methods and properties

{{ properties(item.children) }} {% endif %} {% endfor %}