All files / attr.ts

100.00% Branches 4/4
100.00% Lines 80/80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
x1
 
 
x3
 
 
 
x3
x3
x3
x3
 
 
 
 
 
 
 
x3
x3
x28
x28
x28
x28
x28
x28
x28
 
x3
x3
x9
x9
 
x3
x5
x5
 
x3
x3
x9
x9
 
x3
x5
x5
 
x3
 
x27
x27
x31
x31
 
x27
x29
x29
 
x27
x27
x27
x30
x30
 
x27
x29
x29
 
x27
 
x27
x27
x27
x38
x38
 
x27
x29
x29
 
x27
 
x27
x27
x37
x37
 
x27
x29
x29
 
x27
 
x27
x27
x33
x33
 
x27
x29
x29
 
x3
 
x3
x3
x3
x6
x6
 
x3
x5
x5
x3














































































































// Imports
import type { Nullable } from "@libs/typing"
import type { _Attr, internal } from "./_.ts"
import { Node } from "./node.ts"
import type { Document } from "./document.ts"
import type { Element } from "./element.ts"

/** https://developer.mozilla.org/en-US/docs/Web/API/Attr */
export class Attr extends Node implements _Attr {
  constructor(
    { ownerElement = null, namespaceURI = null, prefix = null, localName = "", value = "" } = {} as {
      [internal]?: boolean
      ownerDocument?: Nullable<Document>
      ownerElement?: Nullable<Element>
      namespaceURI?: Nullable<string>
      prefix?: Nullable<string>
      localName?: string
      value?: string
    },
  ) {
    super(...arguments)
    this.#ownerElement = ownerElement
    this.#namespaceURI = namespaceURI
    this.#prefix = prefix?.toLocaleLowerCase() ?? null
    this.#localName = localName!.toLocaleLowerCase()
    this.#value = value
  }

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/ownerElement
  override get ownerDocument(): Document {
    return super.ownerDocument!
  }

  override set ownerDocument(_: Document) {
    return
  }

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/ownerElement
  get ownerElement(): Nullable<Element> {
    return this.#ownerElement
  }

  set ownerElement(_: Nullable<Element>) {
    return
  }

  #ownerElement

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/name
  get name(): string {
    return `${this.prefix ? `${this.prefix}:` : ""}${this.localName}`
  }

  set name(_: string) {
    return
  }

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/value
  // Note: string-only
  get value(): string {
    return this.#value
  }

  set value(value: string) {
    this.#value = `${value}`
  }

  #value

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/prefix
  //Note: hardcoded to null in HTML namespace
  get prefix(): Nullable<string> {
    return this.#prefix
  }

  set prefix(_: Nullable<string>) {
    return
  }

  #prefix

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/localName
  get localName(): string {
    return this.#localName
  }

  set localName(_: string) {
    return
  }

  #localName

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/namespaceURI
  get namespaceURI(): Nullable<string> {
    return this.#namespaceURI
  }

  set namespaceURI(_: Nullable<string>) {
    return
  }

  #namespaceURI

  // https://developer.mozilla.org/en-US/docs/Web/API/Attr/specified
  // Note: hardcoded
  get specified(): boolean {
    return true
  }

  set specified(_: boolean) {
    return
  }
}