default.d.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { DOCUMENT_MODE, type NS } from '../common/html.js';
  2. import type { Attribute, Location, ElementLocation } from '../common/token.js';
  3. import type { TreeAdapter, TreeAdapterTypeMap } from './interface.js';
  4. export interface Document {
  5. /** The name of the node. */
  6. nodeName: '#document';
  7. /**
  8. * Document mode.
  9. *
  10. * @see {@link DOCUMENT_MODE} */
  11. mode: DOCUMENT_MODE;
  12. /** The node's children. */
  13. childNodes: ChildNode[];
  14. /** Comment source code location info. Available if location info is enabled. */
  15. sourceCodeLocation?: Location | null;
  16. }
  17. export interface DocumentFragment {
  18. /** The name of the node. */
  19. nodeName: '#document-fragment';
  20. /** The node's children. */
  21. childNodes: ChildNode[];
  22. /** Comment source code location info. Available if location info is enabled. */
  23. sourceCodeLocation?: Location | null;
  24. }
  25. export interface Element {
  26. /** Element tag name. Same as {@link tagName}. */
  27. nodeName: string;
  28. /** Element tag name. Same as {@link nodeName}. */
  29. tagName: string;
  30. /** List of element attributes. */
  31. attrs: Attribute[];
  32. /** Element namespace. */
  33. namespaceURI: NS;
  34. /** Element source code location info, with attributes. Available if location info is enabled. */
  35. sourceCodeLocation?: ElementLocation | null;
  36. /** Parent node. */
  37. parentNode: ParentNode | null;
  38. /** The node's children. */
  39. childNodes: ChildNode[];
  40. }
  41. export interface CommentNode {
  42. /** The name of the node. */
  43. nodeName: '#comment';
  44. /** Parent node. */
  45. parentNode: ParentNode | null;
  46. /** Comment text. */
  47. data: string;
  48. /** Comment source code location info. Available if location info is enabled. */
  49. sourceCodeLocation?: Location | null;
  50. }
  51. export interface TextNode {
  52. nodeName: '#text';
  53. /** Parent node. */
  54. parentNode: ParentNode | null;
  55. /** Text content. */
  56. value: string;
  57. /** Comment source code location info. Available if location info is enabled. */
  58. sourceCodeLocation?: Location | null;
  59. }
  60. export interface Template extends Element {
  61. nodeName: 'template';
  62. tagName: 'template';
  63. /** The content of a `template` tag. */
  64. content: DocumentFragment;
  65. }
  66. export interface DocumentType {
  67. /** The name of the node. */
  68. nodeName: '#documentType';
  69. /** Parent node. */
  70. parentNode: ParentNode | null;
  71. /** Document type name. */
  72. name: string;
  73. /** Document type public identifier. */
  74. publicId: string;
  75. /** Document type system identifier. */
  76. systemId: string;
  77. /** Comment source code location info. Available if location info is enabled. */
  78. sourceCodeLocation?: Location | null;
  79. }
  80. export type ParentNode = Document | DocumentFragment | Element | Template;
  81. export type ChildNode = Element | Template | CommentNode | TextNode | DocumentType;
  82. export type Node = ParentNode | ChildNode;
  83. export type DefaultTreeAdapterMap = TreeAdapterTypeMap<Node, ParentNode, ChildNode, Document, DocumentFragment, Element, CommentNode, TextNode, Template, DocumentType>;
  84. export declare const defaultTreeAdapter: TreeAdapter<DefaultTreeAdapterMap>;