netscape-bookmark-parser 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/LICENSE +2 -2
  2. package/README-ja.md +233 -386
  3. package/README.md +152 -302
  4. package/dist/index.d.ts +240 -0
  5. package/dist/index.js +333 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/web.d.ts +241 -0
  8. package/dist/web.js +330 -0
  9. package/dist/web.js.map +1 -0
  10. package/package.json +58 -15
  11. package/esm/_dnt.polyfills.d.ts +0 -101
  12. package/esm/_dnt.polyfills.d.ts.map +0 -1
  13. package/esm/_dnt.polyfills.js +0 -127
  14. package/esm/_dnt.shims.d.ts +0 -6
  15. package/esm/_dnt.shims.d.ts.map +0 -1
  16. package/esm/_dnt.shims.js +0 -61
  17. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts +0 -14
  18. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts.map +0 -1
  19. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.js +0 -151
  20. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts +0 -23
  21. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts.map +0 -1
  22. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js +0 -26
  23. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts +0 -24
  24. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts.map +0 -1
  25. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.js +0 -48
  26. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts +0 -5
  27. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts.map +0 -1
  28. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.js +0 -4
  29. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts +0 -4
  30. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts.map +0 -1
  31. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.js +0 -61
  32. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts +0 -19
  33. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts.map +0 -1
  34. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.js +0 -110
  35. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts +0 -68
  36. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts.map +0 -1
  37. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.js +0 -322
  38. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts +0 -6
  39. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts.map +0 -1
  40. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.js +0 -46
  41. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts +0 -127
  42. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts.map +0 -1
  43. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.js +0 -1068
  44. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts +0 -29
  45. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts.map +0 -1
  46. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.js +0 -94
  47. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts +0 -21
  48. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts.map +0 -1
  49. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.js +0 -80
  50. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts +0 -23
  51. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts.map +0 -1
  52. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.js +0 -159
  53. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts +0 -127
  54. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts.map +0 -1
  55. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.js +0 -629
  56. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts +0 -6
  57. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts.map +0 -1
  58. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.js +0 -5
  59. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts +0 -12
  60. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts.map +0 -1
  61. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.js +0 -2
  62. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts +0 -90
  63. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts.map +0 -1
  64. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.js +0 -1611
  65. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts +0 -16
  66. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts.map +0 -1
  67. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.js +0 -28
  68. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts +0 -8
  69. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts.map +0 -1
  70. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.js +0 -2
  71. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts +0 -7
  72. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts.map +0 -1
  73. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.js +0 -2061
  74. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts +0 -3
  75. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts.map +0 -1
  76. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.js +0 -10
  77. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts +0 -13
  78. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts.map +0 -1
  79. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.js +0 -8
  80. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts +0 -31
  81. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts.map +0 -1
  82. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.js +0 -239
  83. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts +0 -5
  84. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts.map +0 -1
  85. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.js +0 -20
  86. package/esm/mod.d.ts +0 -10
  87. package/esm/mod.d.ts.map +0 -1
  88. package/esm/mod.js +0 -9
  89. package/esm/mod_web.d.ts +0 -9
  90. package/esm/mod_web.d.ts.map +0 -1
  91. package/esm/mod_web.js +0 -8
  92. package/esm/package.json +0 -3
  93. package/esm/src/BookmarksParser/BookmarksParser.d.ts +0 -66
  94. package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +0 -1
  95. package/esm/src/BookmarksParser/BookmarksParser.js +0 -70
  96. package/esm/src/BookmarksParser/index.d.ts +0 -8
  97. package/esm/src/BookmarksParser/index.d.ts.map +0 -1
  98. package/esm/src/BookmarksParser/index.js +0 -7
  99. package/esm/src/BookmarksTree/BookmarksTree.d.ts +0 -112
  100. package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +0 -1
  101. package/esm/src/BookmarksTree/BookmarksTree.js +0 -217
  102. package/esm/src/BookmarksTree/index.d.ts +0 -8
  103. package/esm/src/BookmarksTree/index.d.ts.map +0 -1
  104. package/esm/src/BookmarksTree/index.js +0 -7
  105. package/esm/src/deps.d.ts +0 -9
  106. package/esm/src/deps.d.ts.map +0 -1
  107. package/esm/src/deps.js +0 -7
  108. package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +0 -66
  109. package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +0 -1
  110. package/esm/src/web/BookmarksParser/BookmarksParser.js +0 -70
  111. package/esm/src/web/BookmarksParser/index.d.ts +0 -8
  112. package/esm/src/web/BookmarksParser/index.d.ts.map +0 -1
  113. package/esm/src/web/BookmarksParser/index.js +0 -7
  114. package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +0 -112
  115. package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +0 -1
  116. package/esm/src/web/BookmarksTree/BookmarksTree.js +0 -217
  117. package/esm/src/web/BookmarksTree/index.d.ts +0 -8
  118. package/esm/src/web/BookmarksTree/index.d.ts.map +0 -1
  119. package/esm/src/web/BookmarksTree/index.js +0 -7
  120. package/esm/src/web/deps.d.ts +0 -10
  121. package/esm/src/web/deps.d.ts.map +0 -1
  122. package/esm/src/web/deps.js +0 -9
@@ -1,1068 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _DOMTokenList_instances, _a, _DOMTokenList_DOM_TOKEN_LIST_MIN_SET_SIZE, _DOMTokenList__value, _DOMTokenList_value_get, _DOMTokenList_value_set, _DOMTokenList_set, _DOMTokenList_onChange, _DOMTokenList_invalidToken, _DOMTokenList_setIndices, _DOMTokenList_arrayAdd, _DOMTokenList_setAdd, _DOMTokenList_arrayRemove, _DOMTokenList_setRemove, _DOMTokenList_updateClassString, _UninitializedDOMTokenList_instances, _UninitializedDOMTokenList_getInitialized, _b, _Attr_namedNodeMap, _Attr_name, _Attr_value, _Attr_ownerElement, _c, _NamedNodeMap_indexedAttrAccess, _NamedNodeMap_onAttrNodeChange, _NamedNodeMap_attrNodeCache, _NamedNodeMap_map, _NamedNodeMap_length, _NamedNodeMap_capacity, _NamedNodeMap_ownerElement, _Element_instances, _Element_namedNodeMap, _Element_datasetProxy, _Element_currentId, _Element_currentClassName, _Element_hasIdAttribute, _Element_hasClassNameAttribute, _Element_classListInstance, _Element_classList_get;
13
- import { CTOR_KEY } from "../constructor-lock.js";
14
- import { fragmentNodesFromString } from "../deserialize.js";
15
- import { Node, nodesAndTextNodes, NodeType } from "./node.js";
16
- import { NodeList, nodeListMutatorSym } from "./node-list.js";
17
- import { getDatasetHtmlAttrName, getDatasetJavascriptName, getElementsByClassName, getOuterOrInnerHtml, insertBeforeAfter, lowerCaseCharRe, upperCaseCharRe, } from "./utils.js";
18
- import UtilTypes from "./utils-types.js";
19
- import { getLowerCase, getUpperCase } from "./string-cache.js";
20
- export class DOMTokenList {
21
- constructor(onChange, key) {
22
- _DOMTokenList_instances.add(this);
23
- _DOMTokenList__value.set(this, "");
24
- _DOMTokenList_set.set(this, []);
25
- _DOMTokenList_onChange.set(this, void 0);
26
- if (key !== CTOR_KEY) {
27
- throw new TypeError("Illegal constructor");
28
- }
29
- __classPrivateFieldSet(this, _DOMTokenList_onChange, onChange, "f");
30
- }
31
- set value(input) {
32
- __classPrivateFieldSet(this, _DOMTokenList_instances, input, "a", _DOMTokenList_value_set);
33
- __classPrivateFieldSet(this, _DOMTokenList_set, input
34
- .trim()
35
- .split(/[\t\n\f\r\s]+/g)
36
- .filter(Boolean), "f");
37
- if (__classPrivateFieldGet(this, _DOMTokenList_set, "f").length > __classPrivateFieldGet(_a, _a, "f", _DOMTokenList_DOM_TOKEN_LIST_MIN_SET_SIZE)) {
38
- __classPrivateFieldSet(this, _DOMTokenList_set, new Set(__classPrivateFieldGet(this, _DOMTokenList_set, "f")), "f");
39
- }
40
- else {
41
- const deduplicatedSet = [];
42
- for (const element of __classPrivateFieldGet(this, _DOMTokenList_set, "f")) {
43
- if (!deduplicatedSet.includes(element)) {
44
- deduplicatedSet.push(element);
45
- }
46
- }
47
- __classPrivateFieldSet(this, _DOMTokenList_set, deduplicatedSet, "f");
48
- }
49
- __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setIndices).call(this);
50
- }
51
- get value() {
52
- return __classPrivateFieldGet(this, _DOMTokenList__value, "f");
53
- }
54
- get length() {
55
- if (__classPrivateFieldGet(this, _DOMTokenList_set, "f").constructor === Array) {
56
- return __classPrivateFieldGet(this, _DOMTokenList_set, "f").length;
57
- }
58
- else {
59
- return __classPrivateFieldGet(this, _DOMTokenList_set, "f").size;
60
- }
61
- }
62
- *entries() {
63
- const array = Array.from(__classPrivateFieldGet(this, _DOMTokenList_set, "f"));
64
- for (let i = 0; i < array.length; i++) {
65
- yield [i, array[i]];
66
- }
67
- }
68
- *values() {
69
- yield* __classPrivateFieldGet(this, _DOMTokenList_set, "f").values();
70
- }
71
- *keys() {
72
- const length = this.length;
73
- for (let i = 0; i < length; i++) {
74
- yield i;
75
- }
76
- }
77
- *[(_DOMTokenList__value = new WeakMap(), _DOMTokenList_set = new WeakMap(), _DOMTokenList_onChange = new WeakMap(), _DOMTokenList_instances = new WeakSet(), _DOMTokenList_value_get = function _DOMTokenList_value_get() {
78
- return __classPrivateFieldGet(this, _DOMTokenList__value, "f");
79
- }, _DOMTokenList_value_set = function _DOMTokenList_value_set(value) {
80
- __classPrivateFieldSet(this, _DOMTokenList__value, value, "f");
81
- __classPrivateFieldGet(this, _DOMTokenList_onChange, "f").call(this, value);
82
- }, _DOMTokenList_invalidToken = function _DOMTokenList_invalidToken(token) {
83
- return token === "" || /[\t\n\f\r ]/.test(token);
84
- }, _DOMTokenList_setIndices = function _DOMTokenList_setIndices() {
85
- const classes = Array.from(__classPrivateFieldGet(this, _DOMTokenList_set, "f"));
86
- for (let i = 0; i < classes.length; i++) {
87
- this[i] = classes[i];
88
- }
89
- }, Symbol.iterator)]() {
90
- yield* __classPrivateFieldGet(this, _DOMTokenList_set, "f").values();
91
- }
92
- item(index) {
93
- index = Number(index);
94
- if (Number.isNaN(index) || index === Infinity)
95
- index = 0;
96
- return this[Math.trunc(index) % 2 ** 32] ?? null;
97
- }
98
- contains(element) {
99
- if (__classPrivateFieldGet(this, _DOMTokenList_set, "f").constructor === Array) {
100
- return __classPrivateFieldGet(this, _DOMTokenList_set, "f").includes(element);
101
- }
102
- else {
103
- return __classPrivateFieldGet(this, _DOMTokenList_set, "f").has(element);
104
- }
105
- }
106
- add(...elements) {
107
- const method = (__classPrivateFieldGet(this, _DOMTokenList_set, "f").constructor === Array ? __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_arrayAdd) : __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setAdd)).bind(this);
108
- for (const element of elements) {
109
- if (__classPrivateFieldGet(_a, _a, "m", _DOMTokenList_invalidToken).call(_a, element)) {
110
- throw new DOMException("Failed to execute 'add' on 'DOMTokenList': The token provided must not be empty.");
111
- }
112
- method(element);
113
- }
114
- __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_updateClassString).call(this);
115
- }
116
- remove(...elements) {
117
- const method = (__classPrivateFieldGet(this, _DOMTokenList_set, "f").constructor === Array ? __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_arrayRemove) : __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setRemove))
118
- .bind(this);
119
- const size = this.length;
120
- for (const element of elements) {
121
- if (__classPrivateFieldGet(_a, _a, "m", _DOMTokenList_invalidToken).call(_a, element)) {
122
- throw new DOMException("Failed to execute 'remove' on 'DOMTokenList': The token provided must not be empty.");
123
- }
124
- method(element);
125
- }
126
- const newSize = this.length;
127
- if (size !== newSize) {
128
- for (let i = newSize; i < size; i++) {
129
- delete this[i];
130
- }
131
- __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setIndices).call(this);
132
- }
133
- __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_updateClassString).call(this);
134
- }
135
- replace(oldToken, newToken) {
136
- const isArrayBacked = __classPrivateFieldGet(this, _DOMTokenList_set, "f").constructor === Array;
137
- const removeMethod = (isArrayBacked ? __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_arrayRemove) : __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setRemove))
138
- .bind(this);
139
- const addMethod = (isArrayBacked ? __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_arrayAdd) : __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setAdd)).bind(this);
140
- if ([oldToken, newToken].some((v) => __classPrivateFieldGet(_a, _a, "m", _DOMTokenList_invalidToken).call(_a, v))) {
141
- throw new DOMException("Failed to execute 'replace' on 'DOMTokenList': The token provided must not be empty.");
142
- }
143
- if (!this.contains(oldToken)) {
144
- return false;
145
- }
146
- if (this.contains(newToken)) {
147
- this.remove(oldToken);
148
- }
149
- else {
150
- removeMethod(oldToken);
151
- addMethod(newToken);
152
- __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_setIndices).call(this);
153
- __classPrivateFieldGet(this, _DOMTokenList_instances, "m", _DOMTokenList_updateClassString).call(this);
154
- }
155
- return true;
156
- }
157
- supports() {
158
- throw new Error("Not implemented");
159
- }
160
- toggle(element, force) {
161
- if (force !== undefined) {
162
- const operation = force ? "add" : "remove";
163
- this[operation](element);
164
- return false;
165
- }
166
- else {
167
- const contains = this.contains(element);
168
- const operation = contains ? "remove" : "add";
169
- this[operation](element);
170
- return !contains;
171
- }
172
- }
173
- forEach(callback) {
174
- for (const [i, value] of this.entries()) {
175
- callback(value, i, this);
176
- }
177
- }
178
- }
179
- _a = DOMTokenList, _DOMTokenList_arrayAdd = function _DOMTokenList_arrayAdd(element) {
180
- const array = __classPrivateFieldGet(this, _DOMTokenList_set, "f");
181
- if (!array.includes(element)) {
182
- this[array.length] = element;
183
- array.push(element);
184
- }
185
- }, _DOMTokenList_setAdd = function _DOMTokenList_setAdd(element) {
186
- const set = __classPrivateFieldGet(this, _DOMTokenList_set, "f");
187
- const { size } = set;
188
- set.add(element);
189
- if (size < set.size) {
190
- this[size] = element;
191
- }
192
- }, _DOMTokenList_arrayRemove = function _DOMTokenList_arrayRemove(element) {
193
- const array = __classPrivateFieldGet(this, _DOMTokenList_set, "f");
194
- const index = array.indexOf(element);
195
- if (index >= 0) {
196
- array.splice(index, 1);
197
- }
198
- }, _DOMTokenList_setRemove = function _DOMTokenList_setRemove(element) {
199
- __classPrivateFieldGet(this, _DOMTokenList_set, "f").delete(element);
200
- }, _DOMTokenList_updateClassString = function _DOMTokenList_updateClassString() {
201
- __classPrivateFieldSet(this, _DOMTokenList_instances, Array.from(__classPrivateFieldGet(this, _DOMTokenList_set, "f")).join(" "), "a", _DOMTokenList_value_set);
202
- if (__classPrivateFieldGet(this, _DOMTokenList_set, "f").constructor === Array &&
203
- __classPrivateFieldGet(this, _DOMTokenList_set, "f").length > __classPrivateFieldGet(_a, _a, "f", _DOMTokenList_DOM_TOKEN_LIST_MIN_SET_SIZE)) {
204
- __classPrivateFieldSet(this, _DOMTokenList_set, new Set(__classPrivateFieldGet(this, _DOMTokenList_set, "f")), "f");
205
- }
206
- };
207
- // Minimum number of classnames/tokens in order to switch from
208
- // an array-backed to a set-backed list
209
- _DOMTokenList_DOM_TOKEN_LIST_MIN_SET_SIZE = { value: 32 };
210
- const initializeClassListSym = Symbol("initializeClassListSym");
211
- const domTokenListCurrentElementSym = Symbol("domTokenListCurrentElementSym");
212
- /**
213
- * The purpose of this uninitialized DOMTokenList is to consume less memory
214
- * than the actual DOMTokenList class. By measurements of Deno v2.1.0 (V8 13.0.245.12-rusty)
215
- * this class consumes 48 bytes while the smallest DOMTokenList consumes 488
216
- * bytes
217
- */
218
- class UninitializedDOMTokenList {
219
- constructor(currentElement) {
220
- _UninitializedDOMTokenList_instances.add(this);
221
- // This will always be populated with the current element
222
- // being queried
223
- Object.defineProperty(this, _b, {
224
- enumerable: true,
225
- configurable: true,
226
- writable: true,
227
- value: void 0
228
- });
229
- this[domTokenListCurrentElementSym] = currentElement;
230
- }
231
- set value(input) {
232
- this[domTokenListCurrentElementSym][initializeClassListSym]();
233
- this[domTokenListCurrentElementSym].classList.value = String(input);
234
- }
235
- get value() {
236
- return __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.value ?? "";
237
- }
238
- get length() {
239
- return __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.length ?? 0;
240
- }
241
- *entries() {
242
- const initialized = __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this);
243
- if (initialized) {
244
- yield* initialized.entries();
245
- }
246
- }
247
- *values() {
248
- const initialized = __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this);
249
- if (initialized) {
250
- yield* initialized.values();
251
- }
252
- }
253
- *keys() {
254
- const initialized = __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this);
255
- if (initialized) {
256
- yield* initialized.keys();
257
- }
258
- }
259
- *[(_UninitializedDOMTokenList_instances = new WeakSet(), _b = domTokenListCurrentElementSym, _UninitializedDOMTokenList_getInitialized = function _UninitializedDOMTokenList_getInitialized() {
260
- const currentClassList = this[domTokenListCurrentElementSym].classList;
261
- if (currentClassList === this) {
262
- return null;
263
- }
264
- return currentClassList;
265
- }, Symbol.iterator)]() {
266
- yield* this.values();
267
- }
268
- item(index) {
269
- return __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.item(index) ?? null;
270
- }
271
- contains(element) {
272
- return __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.contains(element) ?? false;
273
- }
274
- add(...elements) {
275
- this[domTokenListCurrentElementSym][initializeClassListSym]();
276
- this[domTokenListCurrentElementSym].classList.add(...elements);
277
- }
278
- remove(...elements) {
279
- __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.remove(...elements);
280
- }
281
- replace(oldToken, newToken) {
282
- return __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.replace(oldToken, newToken) ?? false;
283
- }
284
- supports() {
285
- throw new Error("Not implemented");
286
- }
287
- toggle(element, force) {
288
- if (force === false) {
289
- return __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.toggle(element, force) ?? false;
290
- }
291
- this[domTokenListCurrentElementSym][initializeClassListSym]();
292
- this[domTokenListCurrentElementSym].classList.add(element);
293
- return true;
294
- }
295
- forEach(callback) {
296
- __classPrivateFieldGet(this, _UninitializedDOMTokenList_instances, "m", _UninitializedDOMTokenList_getInitialized).call(this)?.forEach(callback);
297
- }
298
- }
299
- const setNamedNodeMapOwnerElementSym = Symbol("setNamedNodeMapOwnerElementSym");
300
- const setAttrValueSym = Symbol("setAttrValueSym");
301
- export class Attr extends Node {
302
- constructor(map, name, value, key) {
303
- if (key !== CTOR_KEY) {
304
- throw new TypeError("Illegal constructor");
305
- }
306
- super(name, NodeType.ATTRIBUTE_NODE, null, CTOR_KEY);
307
- _Attr_namedNodeMap.set(this, null);
308
- _Attr_name.set(this, "");
309
- _Attr_value.set(this, "");
310
- _Attr_ownerElement.set(this, null);
311
- __classPrivateFieldSet(this, _Attr_name, name, "f");
312
- __classPrivateFieldSet(this, _Attr_value, value, "f");
313
- __classPrivateFieldSet(this, _Attr_namedNodeMap, map, "f");
314
- }
315
- [(_Attr_namedNodeMap = new WeakMap(), _Attr_name = new WeakMap(), _Attr_value = new WeakMap(), _Attr_ownerElement = new WeakMap(), setNamedNodeMapOwnerElementSym)](ownerElement) {
316
- __classPrivateFieldSet(this, _Attr_ownerElement, ownerElement, "f");
317
- __classPrivateFieldSet(this, _Attr_namedNodeMap, ownerElement?.attributes ?? null, "f");
318
- if (ownerElement) {
319
- this._setOwnerDocument(ownerElement.ownerDocument);
320
- }
321
- }
322
- [setAttrValueSym](value) {
323
- __classPrivateFieldSet(this, _Attr_value, value, "f");
324
- }
325
- _shallowClone() {
326
- const newAttr = new Attr(null, __classPrivateFieldGet(this, _Attr_name, "f"), __classPrivateFieldGet(this, _Attr_value, "f"), CTOR_KEY);
327
- newAttr._setOwnerDocument(this.ownerDocument);
328
- return newAttr;
329
- }
330
- cloneNode() {
331
- return super.cloneNode();
332
- }
333
- appendChild() {
334
- throw new DOMException("Cannot add children to an Attribute");
335
- }
336
- replaceChild() {
337
- throw new DOMException("Cannot add children to an Attribute");
338
- }
339
- insertBefore() {
340
- throw new DOMException("Cannot add children to an Attribute");
341
- }
342
- removeChild() {
343
- throw new DOMException("The node to be removed is not a child of this node");
344
- }
345
- get name() {
346
- return __classPrivateFieldGet(this, _Attr_name, "f");
347
- }
348
- get localName() {
349
- // TODO: When we make namespaces a thing this needs
350
- // to be updated
351
- return __classPrivateFieldGet(this, _Attr_name, "f");
352
- }
353
- get value() {
354
- return __classPrivateFieldGet(this, _Attr_value, "f");
355
- }
356
- set value(value) {
357
- __classPrivateFieldSet(this, _Attr_value, String(value), "f");
358
- if (__classPrivateFieldGet(this, _Attr_namedNodeMap, "f")) {
359
- __classPrivateFieldGet(this, _Attr_namedNodeMap, "f")[setNamedNodeMapValueSym](__classPrivateFieldGet(this, _Attr_name, "f"), __classPrivateFieldGet(this, _Attr_value, "f"), true);
360
- }
361
- }
362
- get ownerElement() {
363
- return __classPrivateFieldGet(this, _Attr_ownerElement, "f") ?? null;
364
- }
365
- get specified() {
366
- return true;
367
- }
368
- // TODO
369
- get prefix() {
370
- return null;
371
- }
372
- }
373
- const setNamedNodeMapValueSym = Symbol("setNamedNodeMapValueSym");
374
- const getNamedNodeMapValueSym = Symbol("getNamedNodeMapValueSym");
375
- const getNamedNodeMapAttrNamesSym = Symbol("getNamedNodeMapAttrNamesSym");
376
- const getNamedNodeMapAttrNodeSym = Symbol("getNamedNodeMapAttrNodeSym");
377
- const removeNamedNodeMapAttrSym = Symbol("removeNamedNodeMapAttrSym");
378
- export class NamedNodeMap {
379
- constructor(ownerElement, onAttrNodeChange, key) {
380
- _NamedNodeMap_onAttrNodeChange.set(this, void 0);
381
- _NamedNodeMap_attrNodeCache.set(this, {});
382
- _NamedNodeMap_map.set(this, {});
383
- _NamedNodeMap_length.set(this, 0);
384
- _NamedNodeMap_capacity.set(this, 0);
385
- _NamedNodeMap_ownerElement.set(this, null);
386
- if (key !== CTOR_KEY) {
387
- throw new TypeError("Illegal constructor.");
388
- }
389
- __classPrivateFieldSet(this, _NamedNodeMap_ownerElement, ownerElement, "f");
390
- __classPrivateFieldSet(this, _NamedNodeMap_onAttrNodeChange, onAttrNodeChange, "f");
391
- // Retain ordering of any preceding id or class attributes
392
- for (const attr of ownerElement.getAttributeNames()) {
393
- this[setNamedNodeMapValueSym](attr, ownerElement.getAttribute(attr));
394
- }
395
- }
396
- [(_NamedNodeMap_onAttrNodeChange = new WeakMap(), _NamedNodeMap_attrNodeCache = new WeakMap(), _NamedNodeMap_map = new WeakMap(), _NamedNodeMap_length = new WeakMap(), _NamedNodeMap_capacity = new WeakMap(), _NamedNodeMap_ownerElement = new WeakMap(), getNamedNodeMapAttrNodeSym)](attribute) {
397
- const safeAttrName = "a" + attribute;
398
- let attrNode = __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName];
399
- if (!attrNode) {
400
- attrNode = __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName] = new Attr(this, attribute, __classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName], CTOR_KEY);
401
- attrNode[setNamedNodeMapOwnerElementSym](__classPrivateFieldGet(this, _NamedNodeMap_ownerElement, "f"));
402
- }
403
- return attrNode;
404
- }
405
- [getNamedNodeMapAttrNamesSym]() {
406
- const names = [];
407
- for (const [name, value] of Object.entries(__classPrivateFieldGet(this, _NamedNodeMap_map, "f"))) {
408
- if (value !== undefined) {
409
- names.push(name.slice(1)); // Remove "a" for safeAttrName
410
- }
411
- }
412
- return names;
413
- }
414
- [getNamedNodeMapValueSym](attribute) {
415
- const safeAttrName = "a" + attribute;
416
- return __classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName];
417
- }
418
- [setNamedNodeMapValueSym](attribute, value, bubble = false) {
419
- var _d;
420
- const safeAttrName = "a" + attribute;
421
- if (__classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] === undefined) {
422
- __classPrivateFieldSet(this, _NamedNodeMap_length, (_d = __classPrivateFieldGet(this, _NamedNodeMap_length, "f"), _d++, _d), "f");
423
- if (__classPrivateFieldGet(this, _NamedNodeMap_length, "f") > __classPrivateFieldGet(this, _NamedNodeMap_capacity, "f")) {
424
- __classPrivateFieldSet(this, _NamedNodeMap_capacity, __classPrivateFieldGet(this, _NamedNodeMap_length, "f"), "f");
425
- const index = __classPrivateFieldGet(this, _NamedNodeMap_capacity, "f") - 1;
426
- Object.defineProperty(this, String(__classPrivateFieldGet(this, _NamedNodeMap_capacity, "f") - 1), {
427
- get: __classPrivateFieldGet(_c, _c, "f", _NamedNodeMap_indexedAttrAccess).bind(this, __classPrivateFieldGet(this, _NamedNodeMap_map, "f"), index),
428
- });
429
- }
430
- }
431
- else if (__classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName]) {
432
- __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName][setAttrValueSym](value);
433
- }
434
- __classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] = value;
435
- if (bubble) {
436
- __classPrivateFieldGet(this, _NamedNodeMap_onAttrNodeChange, "f").call(this, attribute, value);
437
- }
438
- }
439
- /**
440
- * Called when an attribute is removed from
441
- * an element
442
- */
443
- [removeNamedNodeMapAttrSym](attribute) {
444
- var _d;
445
- const safeAttrName = "a" + attribute;
446
- if (__classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] !== undefined) {
447
- __classPrivateFieldSet(this, _NamedNodeMap_length, (_d = __classPrivateFieldGet(this, _NamedNodeMap_length, "f"), _d--, _d), "f");
448
- __classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] = undefined;
449
- __classPrivateFieldGet(this, _NamedNodeMap_onAttrNodeChange, "f").call(this, attribute, null);
450
- const attrNode = __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName];
451
- if (attrNode) {
452
- attrNode[setNamedNodeMapOwnerElementSym](null);
453
- __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName] = undefined;
454
- }
455
- }
456
- }
457
- *[Symbol.iterator]() {
458
- for (let i = 0; i < this.length; i++) {
459
- yield this[i];
460
- }
461
- }
462
- get length() {
463
- return __classPrivateFieldGet(this, _NamedNodeMap_length, "f");
464
- }
465
- // FIXME: This method should accept anything and basically
466
- // coerce any non numbers (and Infinity/-Infinity) into 0
467
- item(index) {
468
- if (index >= __classPrivateFieldGet(this, _NamedNodeMap_length, "f")) {
469
- return null;
470
- }
471
- return this[index];
472
- }
473
- getNamedItem(attribute) {
474
- const safeAttrName = "a" + attribute;
475
- if (__classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] !== undefined) {
476
- return this[getNamedNodeMapAttrNodeSym](attribute);
477
- }
478
- return null;
479
- }
480
- setNamedItem(attrNode) {
481
- if (attrNode.ownerElement) {
482
- throw new DOMException("Attribute already in use");
483
- }
484
- const safeAttrName = "a" + attrNode.name;
485
- const previousAttr = __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName];
486
- if (previousAttr) {
487
- previousAttr[setNamedNodeMapOwnerElementSym](null);
488
- __classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] = undefined;
489
- }
490
- attrNode[setNamedNodeMapOwnerElementSym](__classPrivateFieldGet(this, _NamedNodeMap_ownerElement, "f"));
491
- __classPrivateFieldGet(this, _NamedNodeMap_attrNodeCache, "f")[safeAttrName] = attrNode;
492
- this[setNamedNodeMapValueSym](attrNode.name, attrNode.value, true);
493
- }
494
- removeNamedItem(attribute) {
495
- const safeAttrName = "a" + attribute;
496
- if (__classPrivateFieldGet(this, _NamedNodeMap_map, "f")[safeAttrName] !== undefined) {
497
- const attrNode = this[getNamedNodeMapAttrNodeSym](attribute);
498
- this[removeNamedNodeMapAttrSym](attribute);
499
- return attrNode;
500
- }
501
- throw new DOMException("Node was not found");
502
- }
503
- }
504
- _c = NamedNodeMap;
505
- _NamedNodeMap_indexedAttrAccess = { value: function (map, index) {
506
- if (index + 1 > this.length) {
507
- return undefined;
508
- }
509
- const attribute = Object
510
- .keys(map)
511
- .filter((attribute) => map[attribute] !== undefined)[index]
512
- ?.slice(1); // Remove "a" for safeAttrName
513
- return this[getNamedNodeMapAttrNodeSym](attribute);
514
- } };
515
- const XML_NAMESTART_CHAR_RE_SRC = ":A-Za-z_" +
516
- String.raw `\u{C0}-\u{D6}\u{D8}-\u{F6}\u{F8}-\u{2FF}\u{370}-\u{37D}` +
517
- String
518
- .raw `\u{37F}-\u{1FFF}\u{200C}-\u{200D}\u{2070}-\u{218F}\u{2C00}-\u{2FEF}` +
519
- String
520
- .raw `\u{3001}-\u{D7FF}\u{F900}-\u{FDCF}\u{FDF0}-\u{FFFD}\u{10000}-\u{EFFFF}`;
521
- const XML_NAME_CHAR_RE_SRC = XML_NAMESTART_CHAR_RE_SRC +
522
- String.raw `\u{B7}\u{0300}-\u{036F}\u{203F}-\u{2040}0-9.-`;
523
- const xmlNamestartCharRe = new RegExp(`[${XML_NAMESTART_CHAR_RE_SRC}]`, "u");
524
- const xmlNameCharRe = new RegExp(`[${XML_NAME_CHAR_RE_SRC}]`, "u");
525
- export class Element extends Node {
526
- get attributes() {
527
- if (!__classPrivateFieldGet(this, _Element_namedNodeMap, "f")) {
528
- __classPrivateFieldSet(this, _Element_namedNodeMap, new NamedNodeMap(this, (attribute, value) => {
529
- const isRemoved = value === null;
530
- if (value === null) {
531
- value = "";
532
- }
533
- switch (attribute) {
534
- case "class": {
535
- if (isRemoved) {
536
- __classPrivateFieldSet(this, _Element_hasClassNameAttribute, -1, "f");
537
- }
538
- else if (__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f") === -1) {
539
- __classPrivateFieldSet(this, _Element_hasClassNameAttribute, __classPrivateFieldGet(this, _Element_hasIdAttribute, "f") + 1, "f");
540
- }
541
- // This must happen after the attribute is marked removed
542
- __classPrivateFieldSet(this, _Element_currentClassName, value, "f");
543
- __classPrivateFieldGet(this, _Element_instances, "a", _Element_classList_get).value = value;
544
- break;
545
- }
546
- case "id": {
547
- if (isRemoved) {
548
- __classPrivateFieldSet(this, _Element_hasIdAttribute, -1, "f");
549
- }
550
- else if (__classPrivateFieldGet(this, _Element_hasIdAttribute, "f") === -1) {
551
- __classPrivateFieldSet(this, _Element_hasIdAttribute, __classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f") + 1, "f");
552
- }
553
- __classPrivateFieldSet(this, _Element_currentId, value, "f");
554
- break;
555
- }
556
- }
557
- }, CTOR_KEY), "f");
558
- }
559
- return __classPrivateFieldGet(this, _Element_namedNodeMap, "f");
560
- }
561
- [(_Element_namedNodeMap = new WeakMap(), _Element_datasetProxy = new WeakMap(), _Element_currentId = new WeakMap(), _Element_currentClassName = new WeakMap(), _Element_hasIdAttribute = new WeakMap(), _Element_hasClassNameAttribute = new WeakMap(), _Element_classListInstance = new WeakMap(), _Element_instances = new WeakSet(), _Element_classList_get = function _Element_classList_get() {
562
- return __classPrivateFieldGet(this, _Element_classListInstance, "f");
563
- }, initializeClassListSym)]() {
564
- if (__classPrivateFieldGet(this, _Element_classListInstance, "f").constructor === DOMTokenList) {
565
- return;
566
- }
567
- __classPrivateFieldSet(this, _Element_classListInstance, new DOMTokenList((className) => {
568
- if (__classPrivateFieldGet(this, _Element_currentClassName, "f") !== className) {
569
- __classPrivateFieldSet(this, _Element_currentClassName, className, "f");
570
- if (__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f") === -1) {
571
- __classPrivateFieldSet(this, _Element_hasClassNameAttribute, __classPrivateFieldGet(this, _Element_hasIdAttribute, "f") + 1, "f");
572
- }
573
- if (__classPrivateFieldGet(this, _Element_namedNodeMap, "f") &&
574
- (this.hasAttribute("class") || className !== "")) {
575
- this.attributes[setNamedNodeMapValueSym]("class", className);
576
- }
577
- }
578
- }, CTOR_KEY), "f");
579
- }
580
- constructor(tagName, parentNode, attributes, key) {
581
- super(tagName, NodeType.ELEMENT_NODE, parentNode, key);
582
- _Element_instances.add(this);
583
- _Element_namedNodeMap.set(this, null);
584
- _Element_datasetProxy.set(this, null);
585
- _Element_currentId.set(this, "");
586
- _Element_currentClassName.set(this, "");
587
- _Element_hasIdAttribute.set(this, -1);
588
- _Element_hasClassNameAttribute.set(this, -1);
589
- // Only initialize a classList when we need one
590
- _Element_classListInstance.set(this, new UninitializedDOMTokenList(this));
591
- for (const attr of attributes) {
592
- this.setAttribute(attr[0], attr[1]);
593
- }
594
- this.nodeName = getUpperCase(tagName);
595
- }
596
- get tagName() {
597
- return this.nodeName;
598
- }
599
- get localName() {
600
- return getLowerCase(this.tagName);
601
- }
602
- _shallowClone() {
603
- // FIXME: This attribute copying needs to also be fixed in other
604
- // elements that override _shallowClone like <template>
605
- const attributes = [];
606
- for (const attribute of this.getAttributeNames()) {
607
- attributes.push([attribute, this.getAttribute(attribute)]);
608
- }
609
- return new Element(this.nodeName, null, attributes, CTOR_KEY);
610
- }
611
- get childElementCount() {
612
- return this._getChildNodesMutator().elementsView().length;
613
- }
614
- get className() {
615
- return __classPrivateFieldGet(this, _Element_currentClassName, "f");
616
- }
617
- set className(className) {
618
- __classPrivateFieldGet(this, _Element_instances, "a", _Element_classList_get).value = className;
619
- }
620
- get classList() {
621
- return __classPrivateFieldGet(this, _Element_instances, "a", _Element_classList_get);
622
- }
623
- get outerHTML() {
624
- return getOuterOrInnerHtml(this, true);
625
- }
626
- set outerHTML(html) {
627
- if (this.parentNode) {
628
- const { parentElement, parentNode } = this;
629
- let contextLocalName = parentElement?.localName;
630
- switch (parentNode.nodeType) {
631
- case NodeType.DOCUMENT_NODE: {
632
- throw new DOMException("Modifications are not allowed for this document");
633
- }
634
- // setting outerHTML, step 4. Document Fragment
635
- // ref: https://w3c.github.io/DOM-Parsing/#dom-element-outerhtml
636
- case NodeType.DOCUMENT_FRAGMENT_NODE: {
637
- contextLocalName = "body";
638
- // fall-through
639
- }
640
- default: {
641
- const { childNodes: newChildNodes } = fragmentNodesFromString(html, contextLocalName).childNodes[0];
642
- const mutator = parentNode._getChildNodesMutator();
643
- const insertionIndex = mutator.indexOf(this);
644
- for (let i = newChildNodes.length - 1; i >= 0; i--) {
645
- const child = newChildNodes[i];
646
- mutator.splice(insertionIndex, 0, child);
647
- child._setParent(parentNode);
648
- child._setOwnerDocument(parentNode.ownerDocument);
649
- }
650
- this.remove();
651
- }
652
- }
653
- }
654
- }
655
- get innerHTML() {
656
- return getOuterOrInnerHtml(this, false);
657
- }
658
- set innerHTML(html) {
659
- // Remove all children
660
- for (const child of this.childNodes) {
661
- child._setParent(null);
662
- }
663
- const mutator = this._getChildNodesMutator();
664
- mutator.splice(0, this.childNodes.length);
665
- // Parse HTML into new children
666
- if (html.length) {
667
- const parsed = fragmentNodesFromString(html, this.localName);
668
- for (const child of parsed.childNodes[0].childNodes) {
669
- mutator.push(child);
670
- }
671
- for (const child of this.childNodes) {
672
- child._setParent(this);
673
- child._setOwnerDocument(this.ownerDocument);
674
- }
675
- }
676
- }
677
- get innerText() {
678
- return this.textContent;
679
- }
680
- set innerText(text) {
681
- this.textContent = text;
682
- }
683
- get children() {
684
- return this._getChildNodesMutator().elementsView();
685
- }
686
- get id() {
687
- return __classPrivateFieldGet(this, _Element_currentId, "f") || "";
688
- }
689
- set id(id) {
690
- this.setAttribute("id", id);
691
- }
692
- get dataset() {
693
- if (__classPrivateFieldGet(this, _Element_datasetProxy, "f")) {
694
- return __classPrivateFieldGet(this, _Element_datasetProxy, "f");
695
- }
696
- __classPrivateFieldSet(this, _Element_datasetProxy, new Proxy({}, {
697
- get: (_target, property, _receiver) => {
698
- if (typeof property === "string") {
699
- const attributeName = getDatasetHtmlAttrName(property);
700
- return this.getAttribute(attributeName) ?? undefined;
701
- }
702
- return undefined;
703
- },
704
- set: (_target, property, value, _receiver) => {
705
- if (typeof property === "string") {
706
- let attributeName = "data-";
707
- let prevChar = "";
708
- for (const char of property) {
709
- // Step 1. https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem
710
- if (prevChar === "-" && lowerCaseCharRe.test(char)) {
711
- throw new DOMException("An invalid or illegal string was specified");
712
- }
713
- // Step 4. https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem
714
- if (!xmlNameCharRe.test(char)) {
715
- throw new DOMException("String contains an invalid character");
716
- }
717
- // Step 2. https://html.spec.whatwg.org/multipage/dom.html#dom-domstringmap-setitem
718
- if (upperCaseCharRe.test(char)) {
719
- attributeName += "-";
720
- }
721
- attributeName += char.toLowerCase();
722
- prevChar = char;
723
- }
724
- this.setAttribute(attributeName, String(value));
725
- }
726
- return true;
727
- },
728
- deleteProperty: (_target, property) => {
729
- if (typeof property === "string") {
730
- const attributeName = getDatasetHtmlAttrName(property);
731
- this.removeAttribute(attributeName);
732
- }
733
- return true;
734
- },
735
- ownKeys: (_target) => {
736
- return this
737
- .getAttributeNames()
738
- .flatMap((attributeName) => {
739
- if (attributeName.startsWith?.("data-")) {
740
- return [getDatasetJavascriptName(attributeName)];
741
- }
742
- else {
743
- return [];
744
- }
745
- });
746
- },
747
- getOwnPropertyDescriptor: (_target, property) => {
748
- if (typeof property === "string") {
749
- const attributeName = getDatasetHtmlAttrName(property);
750
- if (this.hasAttribute(attributeName)) {
751
- return {
752
- writable: true,
753
- enumerable: true,
754
- configurable: true,
755
- };
756
- }
757
- }
758
- return undefined;
759
- },
760
- has: (_target, property) => {
761
- if (typeof property === "string") {
762
- const attributeName = getDatasetHtmlAttrName(property);
763
- return this.hasAttribute(attributeName);
764
- }
765
- return false;
766
- },
767
- }), "f");
768
- return __classPrivateFieldGet(this, _Element_datasetProxy, "f");
769
- }
770
- getAttributeNames() {
771
- if (!__classPrivateFieldGet(this, _Element_namedNodeMap, "f")) {
772
- const attributes = [];
773
- // We preserve the order of the "id" and "class" attributes when
774
- // returning the list of names with an uninitialized NamedNodeMap
775
- const startWithClassAttr = Number(__classPrivateFieldGet(this, _Element_hasIdAttribute, "f") > __classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f"));
776
- for (let i = 0; i < 2; i++) {
777
- const attributeIdx = (i + startWithClassAttr) % 2;
778
- switch (attributeIdx) {
779
- // "id" attribute
780
- case 0: {
781
- ~__classPrivateFieldGet(this, _Element_hasIdAttribute, "f") && attributes.push("id");
782
- break;
783
- }
784
- // "class" attribute
785
- case 1: {
786
- ~__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f") && attributes.push("class");
787
- break;
788
- }
789
- }
790
- }
791
- return attributes;
792
- }
793
- return this.attributes[getNamedNodeMapAttrNamesSym]();
794
- }
795
- getAttribute(rawName) {
796
- const name = getLowerCase(String(rawName));
797
- switch (name) {
798
- case "id": {
799
- if (~__classPrivateFieldGet(this, _Element_hasIdAttribute, "f")) {
800
- return __classPrivateFieldGet(this, _Element_currentId, "f");
801
- }
802
- else {
803
- return null;
804
- }
805
- }
806
- case "class": {
807
- if (~__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f")) {
808
- return __classPrivateFieldGet(this, _Element_currentClassName, "f");
809
- }
810
- else {
811
- return null;
812
- }
813
- }
814
- }
815
- if (!__classPrivateFieldGet(this, _Element_namedNodeMap, "f")) {
816
- return null;
817
- }
818
- return this.attributes[getNamedNodeMapValueSym](name) ?? null;
819
- }
820
- setAttribute(rawName, value) {
821
- const name = getLowerCase(String(rawName));
822
- const strValue = String(value);
823
- let isNormalAttribute = false;
824
- switch (name) {
825
- case "id": {
826
- __classPrivateFieldSet(this, _Element_currentId, strValue, "f");
827
- if (__classPrivateFieldGet(this, _Element_hasIdAttribute, "f") === -1) {
828
- __classPrivateFieldSet(this, _Element_hasIdAttribute, __classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f") + 1, "f");
829
- }
830
- break;
831
- }
832
- case "class": {
833
- __classPrivateFieldGet(this, _Element_instances, "a", _Element_classList_get).value = strValue;
834
- if (__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f") === -1) {
835
- __classPrivateFieldSet(this, _Element_hasClassNameAttribute, __classPrivateFieldGet(this, _Element_hasIdAttribute, "f") + 1, "f");
836
- }
837
- break;
838
- }
839
- default: {
840
- isNormalAttribute = true;
841
- }
842
- }
843
- if (__classPrivateFieldGet(this, _Element_namedNodeMap, "f") || isNormalAttribute) {
844
- this.attributes[setNamedNodeMapValueSym](name, strValue);
845
- }
846
- }
847
- removeAttribute(rawName) {
848
- const name = getLowerCase(String(rawName));
849
- switch (name) {
850
- case "id": {
851
- __classPrivateFieldSet(this, _Element_currentId, "", "f");
852
- __classPrivateFieldSet(this, _Element_hasIdAttribute, -1, "f");
853
- break;
854
- }
855
- case "class": {
856
- __classPrivateFieldGet(this, _Element_instances, "a", _Element_classList_get).value = "";
857
- __classPrivateFieldSet(this, _Element_hasClassNameAttribute, -1, "f");
858
- break;
859
- }
860
- }
861
- if (!__classPrivateFieldGet(this, _Element_namedNodeMap, "f")) {
862
- return;
863
- }
864
- this.attributes[removeNamedNodeMapAttrSym](name);
865
- }
866
- toggleAttribute(rawName, force) {
867
- const name = getLowerCase(String(rawName));
868
- if (this.hasAttribute(name)) {
869
- if ((force === undefined) || (force === false)) {
870
- this.removeAttribute(name);
871
- return false;
872
- }
873
- return true;
874
- }
875
- if ((force === undefined) || (force === true)) {
876
- this.setAttribute(name, "");
877
- return true;
878
- }
879
- return false;
880
- }
881
- hasAttribute(rawName) {
882
- const name = getLowerCase(String(rawName));
883
- switch (name) {
884
- case "id": {
885
- return Boolean(~__classPrivateFieldGet(this, _Element_hasIdAttribute, "f"));
886
- }
887
- case "class": {
888
- return Boolean(~__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f"));
889
- }
890
- }
891
- if (!__classPrivateFieldGet(this, _Element_namedNodeMap, "f")) {
892
- return false;
893
- }
894
- return this.attributes[getNamedNodeMapValueSym](name) !== undefined;
895
- }
896
- hasAttributeNS(_namespace, rawName) {
897
- const name = getLowerCase(String(rawName));
898
- switch (name) {
899
- case "id": {
900
- return Boolean(~__classPrivateFieldGet(this, _Element_hasIdAttribute, "f"));
901
- }
902
- case "class": {
903
- return Boolean(~__classPrivateFieldGet(this, _Element_hasClassNameAttribute, "f"));
904
- }
905
- }
906
- if (!__classPrivateFieldGet(this, _Element_namedNodeMap, "f")) {
907
- return false;
908
- }
909
- // TODO: Use namespace
910
- return this.attributes[getNamedNodeMapValueSym](name) !== undefined;
911
- }
912
- replaceWith(...nodes) {
913
- this._replaceWith(...nodes);
914
- }
915
- remove() {
916
- this._remove();
917
- }
918
- append(...nodes) {
919
- const mutator = this._getChildNodesMutator();
920
- mutator.push(...nodesAndTextNodes(nodes, this));
921
- }
922
- prepend(...nodes) {
923
- const mutator = this._getChildNodesMutator();
924
- mutator.splice(0, 0, ...nodesAndTextNodes(nodes, this));
925
- }
926
- before(...nodes) {
927
- if (this.parentNode) {
928
- insertBeforeAfter(this, nodes, true);
929
- }
930
- }
931
- after(...nodes) {
932
- if (this.parentNode) {
933
- insertBeforeAfter(this, nodes, false);
934
- }
935
- }
936
- get firstElementChild() {
937
- const elements = this._getChildNodesMutator().elementsView();
938
- return elements[0] ?? null;
939
- }
940
- get lastElementChild() {
941
- const elements = this._getChildNodesMutator().elementsView();
942
- return elements[elements.length - 1] ?? null;
943
- }
944
- get nextElementSibling() {
945
- const parent = this.parentNode;
946
- if (!parent) {
947
- return null;
948
- }
949
- const mutator = parent._getChildNodesMutator();
950
- const index = mutator.indexOfElementsView(this);
951
- const elements = mutator.elementsView();
952
- return elements[index + 1] ?? null;
953
- }
954
- get previousElementSibling() {
955
- const parent = this.parentNode;
956
- if (!parent) {
957
- return null;
958
- }
959
- const mutator = parent._getChildNodesMutator();
960
- const index = mutator.indexOfElementsView(this);
961
- const elements = mutator.elementsView();
962
- return elements[index - 1] ?? null;
963
- }
964
- querySelector(selectors) {
965
- if (!this.ownerDocument) {
966
- throw new Error("Element must have an owner document");
967
- }
968
- return this.ownerDocument._nwapi.first(selectors, this);
969
- }
970
- querySelectorAll(selectors) {
971
- if (!this.ownerDocument) {
972
- throw new Error("Element must have an owner document");
973
- }
974
- const nodeList = new NodeList();
975
- const mutator = nodeList[nodeListMutatorSym]();
976
- for (const match of this.ownerDocument._nwapi.select(selectors, this)) {
977
- mutator.push(match);
978
- }
979
- return nodeList;
980
- }
981
- matches(selectorString) {
982
- return this.ownerDocument._nwapi.match(selectorString, this);
983
- }
984
- closest(selectorString) {
985
- const { match } = this.ownerDocument._nwapi; // See note below
986
- // deno-lint-ignore no-this-alias
987
- let el = this;
988
- do {
989
- // Note: Not using `el.matches(selectorString)` because on a browser if you override
990
- // `matches`, you *don't* see it being used by `closest`.
991
- if (match(selectorString, el)) {
992
- return el;
993
- }
994
- el = el.parentElement;
995
- } while (el !== null);
996
- return null;
997
- }
998
- // TODO: DRY!!!
999
- getElementById(id) {
1000
- if (!this._hasInitializedChildNodes()) {
1001
- return null;
1002
- }
1003
- for (const child of this.childNodes) {
1004
- if (child.nodeType === NodeType.ELEMENT_NODE) {
1005
- if (child.id === id) {
1006
- return child;
1007
- }
1008
- const search = child.getElementById(id);
1009
- if (search) {
1010
- return search;
1011
- }
1012
- }
1013
- }
1014
- return null;
1015
- }
1016
- getElementsByTagName(tagName) {
1017
- if (!this._hasInitializedChildNodes()) {
1018
- return [];
1019
- }
1020
- const fixCaseTagName = getUpperCase(tagName);
1021
- if (fixCaseTagName === "*") {
1022
- return this._getElementsByTagNameWildcard([]);
1023
- }
1024
- else {
1025
- return this._getElementsByTagName(fixCaseTagName, []);
1026
- }
1027
- }
1028
- _getElementsByTagNameWildcard(search) {
1029
- if (!this._hasInitializedChildNodes()) {
1030
- return search;
1031
- }
1032
- for (const child of this.childNodes) {
1033
- if (child.nodeType === NodeType.ELEMENT_NODE) {
1034
- search.push(child);
1035
- child._getElementsByTagNameWildcard(search);
1036
- }
1037
- }
1038
- return search;
1039
- }
1040
- _getElementsByTagName(tagName, search) {
1041
- if (!this._hasInitializedChildNodes()) {
1042
- return search;
1043
- }
1044
- for (const child of this.childNodes) {
1045
- if (child.nodeType === NodeType.ELEMENT_NODE) {
1046
- if (child.tagName === tagName) {
1047
- search.push(child);
1048
- }
1049
- child._getElementsByTagName(tagName, search);
1050
- }
1051
- }
1052
- return search;
1053
- }
1054
- getElementsByClassName(className) {
1055
- if (!this._hasInitializedChildNodes()) {
1056
- return [];
1057
- }
1058
- return getElementsByClassName(this, className.trim().split(/\s+/), []);
1059
- }
1060
- getElementsByTagNameNS(_namespace, localName) {
1061
- if (!this._hasInitializedChildNodes()) {
1062
- return [];
1063
- }
1064
- // TODO: Use namespace
1065
- return this.getElementsByTagName(localName);
1066
- }
1067
- }
1068
- UtilTypes.Element = Element;