als-document 1.0.6-alpha → 1.0.7-alpha

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.
package/document.js CHANGED
@@ -22,7 +22,7 @@ function buildStyle(attributes){
22
22
  const styles=attributes.style || "";
23
23
  con
24
24
  class NodeClassList{
25
25
  constructor(node){ this.node=node }
26
26
  get classes(){ return (this.node.attributes.class || "").split(" ").filter(Boolean) }
27
27
  set classes(val){ this.node.attributes.class=val.join(" ") }
28
28
  contains(className){ return this.classes.includes(className) }
29
29
  add(className){
30
30
  const currentClasses=this.classes;
31
31
  if (!currentClasses.includes(className)) this.classes=[...currentClasses,className];
32
32
  }
33
33
  remove(className){ this.classes=this.classes.filter(cls=>cls!==className); }
34
34
  toggle(className){
35
35
  if (this.classes.includes(className)) this.remove(className);
36
36
  else this.add(className);
37
37
  }
38
38
  replace(oldClass,newClass){
39
39
  if (this.classes.includes(oldClass)){
40
40
  this.remove(oldClass);
41
41
  this.add(newClass);
42
42
  }
43
43
  }
44
44
  }
45
45
  function insertBefore(arr,index,newItem){
46
46
  const existingIndex=arr.indexOf(newItem);
47
47
  if (existingIndex!==-1) arr.splice(existingIndex,1);
48
48
  arr.splice(index,0,newItem);
49
- }
50
49
  class Node{
51
50
  constructor(tagName,attributes={},parent=null){
52
51
  this.isSingle=false;
53
52
  this.tagName=tagName;
54
53
  this.attributes=attributes;
55
54
  this.childNodes=[];
56
55
  if (parent!==null) parent.childNodes.push(this)
57
56
  this.parent=parent;
58
57
  this._classList=null;
59
58
  this.__style=null;
60
59
  this._dataset=null
61
60
  }
62
61
  get id(){ return this.attributes.id ? this.attributes.id : null; }
63
62
  set id(newValue){ this.attributes.id=newValue; }
64
63
  get className(){return this.attributes.class || null}
65
64
  get parentNode(){ return this.parent }
66
65
  get ancestors(){
67
66
  if(!this.parent) return []
68
67
  const ancestors=[]
69
68
  let element=this.parent
70
69
  while (element.tagName!=='ROOT'){
71
70
  ancestors.push(element)
72
71
  element=element.parent
73
72
  }
74
73
  return ancestors.reverse()
75
74
  }
76
75
  get childNodeIndex(){
77
76
  if(!this.parent) return null
78
77
  return this.parent.childNodes ? this.parent.childNodes.indexOf(this) : null
79
78
  }
80
79
  get childIndex(){
81
80
  if(!this.parent) return null
82
81
  return this.parent.children ? this.parent.children.indexOf(this) : null
83
82
  }
84
83
  get previousElementSibling(){ return this.prev }
85
84
  get prev(){
86
85
  if (!this.childIndex) return null
87
86
  return this.parent.children[this.childIndex-1]
88
87
  }
89
88
  get nextElementSibling(){ return this.next }
90
89
  get next(){
91
90
  if (!this.childIndex) return null
92
91
  return this.parent.children[this.childIndex+1] || null
93
92
  }
94
93
  get dataset(){
95
94
  if (!this._dataset) this._dataset=getDataset(this);
96
95
  return this._dataset;
97
96
  }
98
97
  get classList(){
99
98
  if (!this._classList) this._classList=new NodeClassList(this);
100
99
  return this._classList;
101
100
  }
102
101
  get style(){
103
102
  if (!this.__style) this.__style=buildStyle(this.attributes)
104
103
  return this.__style
105
104
  }
106
105
  get outerHTML(){
107
106
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
108
107
  return `<${this.tagName}${attrs ? ' '+attrs : ''}>${this.innerHTML}</${this.tagName}>`;
109
108
  }
110
109
  getAttribute(attrName){ return this.attributes[attrName] || null }
111
110
  setAttribute(attrName,value){ this.attributes[attrName]=value }
112
111
  removeAttribute(attrName){ delete this.attributes[attrName] }
113
112
  remove(){
114
113
  if (!this.parent) return
115
114
  const index=this.childIndex;
116
115
  if (index!==null) this.parent.childNodes.splice(index,1);
117
116
  }
118
117
  get innerHTML(){
119
118
  return this.childNodes.map(child=>{
120
119
  if (child instanceof Node || child instanceof SingleNode) return child.outerHTML;
121
120
  else if (child instanceof TextNode) return child.textContent;
122
121
  else return child
123
122
  }).join("");
124
123
  }
125
124
  $$(query){return this.querySelectorAll(query)}
126
125
  querySelectorAll(query){
127
126
  const selectors=Query.get(query)
128
127
  return find(selectors,this,new Set())
129
128
  }
130
129
  $(query){return this.querySelector(query)}
131
130
  querySelector(query){
132
131
  const selectors=Query.get(query)
133
132
  return find(selectors,this,new Set(),true)[0] || null
134
133
  }
135
134
  getElementsByClassName(query){ return this.querySelectorAll('.'+query) }
136
135
  getElementsByTagName(query){ return this.querySelectorAll(query) }
137
136
  getElementById(query){ return this.querySelector('#'+query) }
138
137
  get children(){
139
138
  return this.childNodes.filter(child=>{
140
139
  if (!(child instanceof Node)) return false
141
140
  if (child.tagName==='#comment') return false
142
141
  return true
143
142
  });
144
143
  }
145
144
  insertAdjacentElement(position,newElement){
146
145
  if(newElement.tagName==='ROOT' && newElement.childNodes.length>0) newElement=newElement.childNodes[0]
147
146
  const pos=position.toLowerCase();
148
147
  if (pos==="afterbegin") this.childNodes.unshift(newElement);
149
148
  else if (pos==="beforeend") this.childNodes.push(newElement);
150
149
  newElement.parent=this
151
150
  if (!this.parent) return newElement
152
151
  if (pos==="beforebegin") insertBefore(this.parent.childNodes,this.childNodeIndex,newElement)
153
152
  else if (pos==="afterend") this.parent.childNodes.splice(this.childNodeIndex+1,0,newElement);
154
153
  newElement.parent=this.parent
155
154
  return newElement
156
155
  }
157
156
  insertAdjacentHTML(position,html){
158
157
  const newNode=parseHTML(html);
159
158
  newNode.childNodes.reverse().forEach(node=>{
160
159
  this.insertAdjacentElement(position,node);
161
160
  });
162
161
  return newNode
163
162
  }
164
163
  insertAdjacentText(position,text){
165
164
  return this.insertAdjacentElement(position,new TextNode(text));
166
165
  }
167
166
  set innerHTML(html){
168
167
  const parsed=parseHTML(html);
169
168
  this.childNodes=parsed.childNodes;
170
169
  }
171
170
  set outerHTML(html){
172
171
  const parsed=parseHTML(html);
173
172
  if (!this.parent) return console.log('element has no parent node')
174
173
  const index=this.childIndex
175
174
  if (index!==null) this.parent.childNodes.splice(index,1,...parsed.childNodes);
176
175
  }
177
176
  appendChild(newChild){
178
177
  if (newChild instanceof Node || newChild instanceof TextNode || newChild instanceof SingleNode){
179
178
  if (newChild.parent) newChild.parent.childNodes=newChild.parent.childNodes.filter(child=>child!==newChild);
180
179
  } else if(typeof newChild==='string') newChild=new TextNode(newChild)
181
180
  else return newChild
182
181
  this.childNodes.push(newChild);
183
182
  newChild.parent=this;
184
183
  return newChild;
185
184
  }
186
185
  get textContent(){
187
186
  if (this.childNodes.length===0) return this.nodeName==='#text' ? this.nodeValue : '';
188
187
  return this.childNodes.map(child=>{
189
188
  if(child instanceof SingleNode) return ''
190
189
  if(child instanceof TextNode) return child.nodeValue
191
190
  if(child instanceof Node) return child.textContent;
192
191
  else return child;
193
192
  }).join(" ");
194
193
  }
195
194
  set textContent(value){
196
195
  this.childNodes=[];
197
196
  if (value!==null && value!==undefined){
198
197
  this.childNodes.push(value.toString());
199
198
  }
200
199
  }
200
+ }
201
201
  class Node{
202
202
  constructor(tagName,attributes={},parent=null){
203
203
  this.isSingle=false;
204
204
  this.tagName=tagName;
205
205
  this.attributes=attributes;
206
206
  this.childNodes=[];
207
207
  if (parent!==null) parent.childNodes.push(this)
208
208
  this.parent=parent;
209
209
  this._classList=null;
210
210
  this.__style=null;
211
211
  this._dataset=null
212
212
  }
213
213
  get id(){ return this.attributes.id ? this.attributes.id : null; }
214
214
  set id(newValue){ this.attributes.id=newValue; }
215
215
  get className(){return this.attributes.class || null}
216
216
  get parentNode(){ return this.parent }
217
217
  get ancestors(){
218
218
  if(!this.parent) return []
219
219
  const ancestors=[]
220
220
  let element=this.parent
221
221
  while (element.tagName!=='ROOT'){
222
222
  ancestors.push(element)
223
223
  element=element.parent
224
224
  }
225
225
  return ancestors.reverse()
226
226
  }
227
227
  get childNodeIndex(){
228
228
  if(!this.parent) return null
229
229
  return this.parent.childNodes ? this.parent.childNodes.indexOf(this) : null
230
230
  }
231
231
  get childIndex(){
232
232
  if(!this.parent) return null
233
233
  return this.parent.children ? this.parent.children.indexOf(this) : null
234
234
  }
235
235
  get previousElementSibling(){ return this.prev }
236
236
  get prev(){
237
237
  if (!this.childIndex) return null
238
238
  return this.parent.children[this.childIndex-1]
239
239
  }
240
240
  get nextElementSibling(){ return this.next }
241
241
  get next(){
242
242
  if (!this.childIndex) return null
243
243
  return this.parent.children[this.childIndex+1] || null
244
244
  }
245
245
  get dataset(){
246
246
  if (!this._dataset) this._dataset=getDataset(this);
247
247
  return this._dataset;
248
248
  }
249
249
  get classList(){
250
250
  if (!this._classList) this._classList=new NodeClassList(this);
251
251
  return this._classList;
252
252
  }
253
253
  get style(){
254
254
  if (!this.__style) this.__style=buildStyle(this.attributes)
255
255
  return this.__style
256
256
  }
257
257
  get outerHTML(){
258
258
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
259
259
  return `<${this.tagName}${attrs ? ' '+attrs : ''}>${this.innerHTML}</${this.tagName}>`;
260
260
  }
261
261
  getAttribute(attrName){ return this.attributes[attrName] || null }
262
262
  setAttribute(attrName,value){ this.attributes[attrName]=value }
263
263
  removeAttribute(attrName){ delete this.attributes[attrName] }
264
264
  remove(){
265
265
  if (!this.parent) return
266
266
  const index=this.childNodeIndex;
267
267
  if (index!==null) this.parent.childNodes.splice(index,1);
268
268
  }
269
269
  get innerHTML(){
270
270
  return this.childNodes.map(child=>{
271
271
  if (child instanceof Node || child instanceof SingleNode) return child.outerHTML;
272
272
  else if (child instanceof TextNode) return child.textContent;
273
273
  else return child
274
274
  }).join("");
275
275
  }
276
276
  $$(query){return this.querySelectorAll(query)}
277
277
  querySelectorAll(query){
278
278
  const selectors=Query.get(query)
279
279
  return find(selectors,this,new Set())
280
280
  }
281
281
  $(query){return this.querySelector(query)}
282
282
  querySelector(query){
283
283
  const selectors=Query.get(query)
284
284
  return find(selectors,this,new Set(),true)[0] || null
285
285
  }
286
286
  getElementsByClassName(query){ return this.querySelectorAll('.'+query) }
287
287
  getElementsByTagName(query){ return this.querySelectorAll(query) }
288
288
  getElementById(query){ return this.querySelector('#'+query) }
289
289
  get children(){
290
290
  return this.childNodes.filter(child=>{
291
291
  if (!(child instanceof Node)) return false
292
292
  if (child.tagName==='#comment') return false
293
293
  return true
294
294
  });
295
295
  }
296
296
  insertAdjacentElement(position,newElement){
297
297
  if(newElement.tagName==='ROOT' && newElement.childNodes.length>0) newElement=newElement.childNodes[0]
298
298
  const pos=position.toLowerCase();
299
299
  if (pos==="afterbegin") this.childNodes.unshift(newElement);
300
300
  else if (pos==="beforeend") this.childNodes.push(newElement);
301
301
  newElement.parent=this
302
302
  if (!this.parent) return newElement
303
303
  if (pos==="beforebegin") insertBefore(this.parent.childNodes,this.childNodeIndex,newElement)
304
304
  else if (pos==="afterend") this.parent.childNodes.splice(this.childNodeIndex+1,0,newElement);
305
305
  newElement.parent=this.parent
306
306
  return newElement
307
307
  }
308
308
  insertAdjacentHTML(position,html){
309
309
  const newNode=parseHTML(html);
310
310
  newNode.childNodes.reverse().forEach(node=>{
311
311
  this.insertAdjacentElement(position,node);
312
312
  });
313
313
  return newNode
314
314
  }
315
315
  insertAdjacentText(position,text){
316
316
  return this.insertAdjacentElement(position,new TextNode(text));
317
317
  }
318
318
  set innerHTML(html){
319
319
  const parsed=parseHTML(html);
320
320
  this.childNodes=parsed.childNodes;
321
321
  }
322
322
  set outerHTML(html){
323
323
  const parsed=parseHTML(html);
324
324
  if (!this.parent) return console.log('element has no parent node')
325
325
  const index=this.childIndex
326
326
  if (index!==null) this.parent.childNodes.splice(index,1,...parsed.childNodes);
327
327
  }
328
328
  appendChild(newChild){
329
329
  if (newChild instanceof Node || newChild instanceof TextNode || newChild instanceof SingleNode){
330
330
  if (newChild.parent) newChild.parent.childNodes=newChild.parent.childNodes.filter(child=>child!==newChild);
331
331
  } else if(typeof newChild==='string') newChild=new TextNode(newChild)
332
332
  else return newChild
333
333
  this.childNodes.push(newChild);
334
334
  newChild.parent=this;
335
335
  return newChild;
336
336
  }
337
337
  get textContent(){
338
338
  if (this.childNodes.length===0) return this.nodeName==='#text' ? this.nodeValue : '';
339
339
  return this.childNodes.map(child=>{
340
340
  if(child instanceof SingleNode) return ''
341
341
  if(child instanceof TextNode) return child.nodeValue
342
342
  if(child instanceof Node) return child.textContent;
343
343
  else return child;
344
344
  }).join(" ");
345
345
  }
346
346
  set textContent(value){
347
347
  this.childNodes=[];
348
348
  if (value!==null && value!==undefined){
349
349
  this.childNodes.push(value.toString());
350
350
  }
351
351
  }
352
352
  }
353
353
  class SingleNode extends Node{
354
354
  constructor(tagName,attributes={},parent=null){
355
355
  if(attributes['?'] && tagName==='?xml') delete attributes['?']
356
356
  super(tagName,attributes,parent);
357
357
  this.isSingle=true
358
358
  }
359
359
  get outerHTML(){
360
360
  if (this.tagName==="#cdata-section") return `<![CDATA[${this.nodeValue}]]>`;
361
361
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
362
362
  return `<${this.tagName} ${attrs}${this.tagName==='?xml' ? '?' : ''}>`;
363
363
  }
364
364
  get innerHTML(){ return ""; }
365
365
  set innerHTML(_){ }
366
366
  $(_){return null}
367
367
  $$(_){return []}
368
368
  querySelectorAll(_){ return []; }
369
369
  querySelector(_){ return null; }
370
370
  getElementsByClassName(_){ return []; }
371
371
  getElementsByTagName(_){ return []; }
372
372
  getElementById(_){ return null; }
373
373
  get children(){ return []; }
374
374
  insertAdjacentElement(_,__){ }
375
375
  insertAdjacentHTML(_,__){ }
376
376
  insertAdjacentText(_,__){ }
377
377
  appendChild(_){ }
378
378
  get textContent(){ return ""; }
379
379
  set textContent(_){ }
380
380
  }
package/index.js CHANGED
@@ -21,7 +21,7 @@ function buildStyle(attributes){
21
21
  const styles=attributes.style || "";
22
22
  con
23
23
  class NodeClassList{
24
24
  constructor(node){ this.node=node }
25
25
  get classes(){ return (this.node.attributes.class || "").split(" ").filter(Boolean) }
26
26
  set classes(val){ this.node.attributes.class=val.join(" ") }
27
27
  contains(className){ return this.classes.includes(className) }
28
28
  add(className){
29
29
  const currentClasses=this.classes;
30
30
  if (!currentClasses.includes(className)) this.classes=[...currentClasses,className];
31
31
  }
32
32
  remove(className){ this.classes=this.classes.filter(cls=>cls!==className); }
33
33
  toggle(className){
34
34
  if (this.classes.includes(className)) this.remove(className);
35
35
  else this.add(className);
36
36
  }
37
37
  replace(oldClass,newClass){
38
38
  if (this.classes.includes(oldClass)){
39
39
  this.remove(oldClass);
40
40
  this.add(newClass);
41
41
  }
42
42
  }
43
43
  }
44
44
  function insertBefore(arr,index,newItem){
45
45
  const existingIndex=arr.indexOf(newItem);
46
46
  if (existingIndex!==-1) arr.splice(existingIndex,1);
47
47
  arr.splice(index,0,newItem);
48
- }
49
48
  class Node{
50
49
  constructor(tagName,attributes={},parent=null){
51
50
  this.isSingle=false;
52
51
  this.tagName=tagName;
53
52
  this.attributes=attributes;
54
53
  this.childNodes=[];
55
54
  if (parent!==null) parent.childNodes.push(this)
56
55
  this.parent=parent;
57
56
  this._classList=null;
58
57
  this.__style=null;
59
58
  this._dataset=null
60
59
  }
61
60
  get id(){ return this.attributes.id ? this.attributes.id : null; }
62
61
  set id(newValue){ this.attributes.id=newValue; }
63
62
  get className(){return this.attributes.class || null}
64
63
  get parentNode(){ return this.parent }
65
64
  get ancestors(){
66
65
  if(!this.parent) return []
67
66
  const ancestors=[]
68
67
  let element=this.parent
69
68
  while (element.tagName!=='ROOT'){
70
69
  ancestors.push(element)
71
70
  element=element.parent
72
71
  }
73
72
  return ancestors.reverse()
74
73
  }
75
74
  get childNodeIndex(){
76
75
  if(!this.parent) return null
77
76
  return this.parent.childNodes ? this.parent.childNodes.indexOf(this) : null
78
77
  }
79
78
  get childIndex(){
80
79
  if(!this.parent) return null
81
80
  return this.parent.children ? this.parent.children.indexOf(this) : null
82
81
  }
83
82
  get previousElementSibling(){ return this.prev }
84
83
  get prev(){
85
84
  if (!this.childIndex) return null
86
85
  return this.parent.children[this.childIndex-1]
87
86
  }
88
87
  get nextElementSibling(){ return this.next }
89
88
  get next(){
90
89
  if (!this.childIndex) return null
91
90
  return this.parent.children[this.childIndex+1] || null
92
91
  }
93
92
  get dataset(){
94
93
  if (!this._dataset) this._dataset=getDataset(this);
95
94
  return this._dataset;
96
95
  }
97
96
  get classList(){
98
97
  if (!this._classList) this._classList=new NodeClassList(this);
99
98
  return this._classList;
100
99
  }
101
100
  get style(){
102
101
  if (!this.__style) this.__style=buildStyle(this.attributes)
103
102
  return this.__style
104
103
  }
105
104
  get outerHTML(){
106
105
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
107
106
  return `<${this.tagName}${attrs ? ' '+attrs : ''}>${this.innerHTML}</${this.tagName}>`;
108
107
  }
109
108
  getAttribute(attrName){ return this.attributes[attrName] || null }
110
109
  setAttribute(attrName,value){ this.attributes[attrName]=value }
111
110
  removeAttribute(attrName){ delete this.attributes[attrName] }
112
111
  remove(){
113
112
  if (!this.parent) return
114
113
  const index=this.childIndex;
115
114
  if (index!==null) this.parent.childNodes.splice(index,1);
116
115
  }
117
116
  get innerHTML(){
118
117
  return this.childNodes.map(child=>{
119
118
  if (child instanceof Node || child instanceof SingleNode) return child.outerHTML;
120
119
  else if (child instanceof TextNode) return child.textContent;
121
120
  else return child
122
121
  }).join("");
123
122
  }
124
123
  $$(query){return this.querySelectorAll(query)}
125
124
  querySelectorAll(query){
126
125
  const selectors=Query.get(query)
127
126
  return find(selectors,this,new Set())
128
127
  }
129
128
  $(query){return this.querySelector(query)}
130
129
  querySelector(query){
131
130
  const selectors=Query.get(query)
132
131
  return find(selectors,this,new Set(),true)[0] || null
133
132
  }
134
133
  getElementsByClassName(query){ return this.querySelectorAll('.'+query) }
135
134
  getElementsByTagName(query){ return this.querySelectorAll(query) }
136
135
  getElementById(query){ return this.querySelector('#'+query) }
137
136
  get children(){
138
137
  return this.childNodes.filter(child=>{
139
138
  if (!(child instanceof Node)) return false
140
139
  if (child.tagName==='#comment') return false
141
140
  return true
142
141
  });
143
142
  }
144
143
  insertAdjacentElement(position,newElement){
145
144
  if(newElement.tagName==='ROOT' && newElement.childNodes.length>0) newElement=newElement.childNodes[0]
146
145
  const pos=position.toLowerCase();
147
146
  if (pos==="afterbegin") this.childNodes.unshift(newElement);
148
147
  else if (pos==="beforeend") this.childNodes.push(newElement);
149
148
  newElement.parent=this
150
149
  if (!this.parent) return newElement
151
150
  if (pos==="beforebegin") insertBefore(this.parent.childNodes,this.childNodeIndex,newElement)
152
151
  else if (pos==="afterend") this.parent.childNodes.splice(this.childNodeIndex+1,0,newElement);
153
152
  newElement.parent=this.parent
154
153
  return newElement
155
154
  }
156
155
  insertAdjacentHTML(position,html){
157
156
  const newNode=parseHTML(html);
158
157
  newNode.childNodes.reverse().forEach(node=>{
159
158
  this.insertAdjacentElement(position,node);
160
159
  });
161
160
  return newNode
162
161
  }
163
162
  insertAdjacentText(position,text){
164
163
  return this.insertAdjacentElement(position,new TextNode(text));
165
164
  }
166
165
  set innerHTML(html){
167
166
  const parsed=parseHTML(html);
168
167
  this.childNodes=parsed.childNodes;
169
168
  }
170
169
  set outerHTML(html){
171
170
  const parsed=parseHTML(html);
172
171
  if (!this.parent) return console.log('element has no parent node')
173
172
  const index=this.childIndex
174
173
  if (index!==null) this.parent.childNodes.splice(index,1,...parsed.childNodes);
175
174
  }
176
175
  appendChild(newChild){
177
176
  if (newChild instanceof Node || newChild instanceof TextNode || newChild instanceof SingleNode){
178
177
  if (newChild.parent) newChild.parent.childNodes=newChild.parent.childNodes.filter(child=>child!==newChild);
179
178
  } else if(typeof newChild==='string') newChild=new TextNode(newChild)
180
179
  else return newChild
181
180
  this.childNodes.push(newChild);
182
181
  newChild.parent=this;
183
182
  return newChild;
184
183
  }
185
184
  get textContent(){
186
185
  if (this.childNodes.length===0) return this.nodeName==='#text' ? this.nodeValue : '';
187
186
  return this.childNodes.map(child=>{
188
187
  if(child instanceof SingleNode) return ''
189
188
  if(child instanceof TextNode) return child.nodeValue
190
189
  if(child instanceof Node) return child.textContent;
191
190
  else return child;
192
191
  }).join(" ");
193
192
  }
194
193
  set textContent(value){
195
194
  this.childNodes=[];
196
195
  if (value!==null && value!==undefined){
197
196
  this.childNodes.push(value.toString());
198
197
  }
199
198
  }
199
+ }
200
200
  class Node{
201
201
  constructor(tagName,attributes={},parent=null){
202
202
  this.isSingle=false;
203
203
  this.tagName=tagName;
204
204
  this.attributes=attributes;
205
205
  this.childNodes=[];
206
206
  if (parent!==null) parent.childNodes.push(this)
207
207
  this.parent=parent;
208
208
  this._classList=null;
209
209
  this.__style=null;
210
210
  this._dataset=null
211
211
  }
212
212
  get id(){ return this.attributes.id ? this.attributes.id : null; }
213
213
  set id(newValue){ this.attributes.id=newValue; }
214
214
  get className(){return this.attributes.class || null}
215
215
  get parentNode(){ return this.parent }
216
216
  get ancestors(){
217
217
  if(!this.parent) return []
218
218
  const ancestors=[]
219
219
  let element=this.parent
220
220
  while (element.tagName!=='ROOT'){
221
221
  ancestors.push(element)
222
222
  element=element.parent
223
223
  }
224
224
  return ancestors.reverse()
225
225
  }
226
226
  get childNodeIndex(){
227
227
  if(!this.parent) return null
228
228
  return this.parent.childNodes ? this.parent.childNodes.indexOf(this) : null
229
229
  }
230
230
  get childIndex(){
231
231
  if(!this.parent) return null
232
232
  return this.parent.children ? this.parent.children.indexOf(this) : null
233
233
  }
234
234
  get previousElementSibling(){ return this.prev }
235
235
  get prev(){
236
236
  if (!this.childIndex) return null
237
237
  return this.parent.children[this.childIndex-1]
238
238
  }
239
239
  get nextElementSibling(){ return this.next }
240
240
  get next(){
241
241
  if (!this.childIndex) return null
242
242
  return this.parent.children[this.childIndex+1] || null
243
243
  }
244
244
  get dataset(){
245
245
  if (!this._dataset) this._dataset=getDataset(this);
246
246
  return this._dataset;
247
247
  }
248
248
  get classList(){
249
249
  if (!this._classList) this._classList=new NodeClassList(this);
250
250
  return this._classList;
251
251
  }
252
252
  get style(){
253
253
  if (!this.__style) this.__style=buildStyle(this.attributes)
254
254
  return this.__style
255
255
  }
256
256
  get outerHTML(){
257
257
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
258
258
  return `<${this.tagName}${attrs ? ' '+attrs : ''}>${this.innerHTML}</${this.tagName}>`;
259
259
  }
260
260
  getAttribute(attrName){ return this.attributes[attrName] || null }
261
261
  setAttribute(attrName,value){ this.attributes[attrName]=value }
262
262
  removeAttribute(attrName){ delete this.attributes[attrName] }
263
263
  remove(){
264
264
  if (!this.parent) return
265
265
  const index=this.childNodeIndex;
266
266
  if (index!==null) this.parent.childNodes.splice(index,1);
267
267
  }
268
268
  get innerHTML(){
269
269
  return this.childNodes.map(child=>{
270
270
  if (child instanceof Node || child instanceof SingleNode) return child.outerHTML;
271
271
  else if (child instanceof TextNode) return child.textContent;
272
272
  else return child
273
273
  }).join("");
274
274
  }
275
275
  $$(query){return this.querySelectorAll(query)}
276
276
  querySelectorAll(query){
277
277
  const selectors=Query.get(query)
278
278
  return find(selectors,this,new Set())
279
279
  }
280
280
  $(query){return this.querySelector(query)}
281
281
  querySelector(query){
282
282
  const selectors=Query.get(query)
283
283
  return find(selectors,this,new Set(),true)[0] || null
284
284
  }
285
285
  getElementsByClassName(query){ return this.querySelectorAll('.'+query) }
286
286
  getElementsByTagName(query){ return this.querySelectorAll(query) }
287
287
  getElementById(query){ return this.querySelector('#'+query) }
288
288
  get children(){
289
289
  return this.childNodes.filter(child=>{
290
290
  if (!(child instanceof Node)) return false
291
291
  if (child.tagName==='#comment') return false
292
292
  return true
293
293
  });
294
294
  }
295
295
  insertAdjacentElement(position,newElement){
296
296
  if(newElement.tagName==='ROOT' && newElement.childNodes.length>0) newElement=newElement.childNodes[0]
297
297
  const pos=position.toLowerCase();
298
298
  if (pos==="afterbegin") this.childNodes.unshift(newElement);
299
299
  else if (pos==="beforeend") this.childNodes.push(newElement);
300
300
  newElement.parent=this
301
301
  if (!this.parent) return newElement
302
302
  if (pos==="beforebegin") insertBefore(this.parent.childNodes,this.childNodeIndex,newElement)
303
303
  else if (pos==="afterend") this.parent.childNodes.splice(this.childNodeIndex+1,0,newElement);
304
304
  newElement.parent=this.parent
305
305
  return newElement
306
306
  }
307
307
  insertAdjacentHTML(position,html){
308
308
  const newNode=parseHTML(html);
309
309
  newNode.childNodes.reverse().forEach(node=>{
310
310
  this.insertAdjacentElement(position,node);
311
311
  });
312
312
  return newNode
313
313
  }
314
314
  insertAdjacentText(position,text){
315
315
  return this.insertAdjacentElement(position,new TextNode(text));
316
316
  }
317
317
  set innerHTML(html){
318
318
  const parsed=parseHTML(html);
319
319
  this.childNodes=parsed.childNodes;
320
320
  }
321
321
  set outerHTML(html){
322
322
  const parsed=parseHTML(html);
323
323
  if (!this.parent) return console.log('element has no parent node')
324
324
  const index=this.childIndex
325
325
  if (index!==null) this.parent.childNodes.splice(index,1,...parsed.childNodes);
326
326
  }
327
327
  appendChild(newChild){
328
328
  if (newChild instanceof Node || newChild instanceof TextNode || newChild instanceof SingleNode){
329
329
  if (newChild.parent) newChild.parent.childNodes=newChild.parent.childNodes.filter(child=>child!==newChild);
330
330
  } else if(typeof newChild==='string') newChild=new TextNode(newChild)
331
331
  else return newChild
332
332
  this.childNodes.push(newChild);
333
333
  newChild.parent=this;
334
334
  return newChild;
335
335
  }
336
336
  get textContent(){
337
337
  if (this.childNodes.length===0) return this.nodeName==='#text' ? this.nodeValue : '';
338
338
  return this.childNodes.map(child=>{
339
339
  if(child instanceof SingleNode) return ''
340
340
  if(child instanceof TextNode) return child.nodeValue
341
341
  if(child instanceof Node) return child.textContent;
342
342
  else return child;
343
343
  }).join(" ");
344
344
  }
345
345
  set textContent(value){
346
346
  this.childNodes=[];
347
347
  if (value!==null && value!==undefined){
348
348
  this.childNodes.push(value.toString());
349
349
  }
350
350
  }
351
351
  }
352
352
  class SingleNode extends Node{
353
353
  constructor(tagName,attributes={},parent=null){
354
354
  if(attributes['?'] && tagName==='?xml') delete attributes['?']
355
355
  super(tagName,attributes,parent);
356
356
  this.isSingle=true
357
357
  }
358
358
  get outerHTML(){
359
359
  if (this.tagName==="#cdata-section") return `<![CDATA[${this.nodeValue}]]>`;
360
360
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
361
361
  return `<${this.tagName} ${attrs}${this.tagName==='?xml' ? '?' : ''}>`;
362
362
  }
363
363
  get innerHTML(){ return ""; }
364
364
  set innerHTML(_){ }
365
365
  $(_){return null}
366
366
  $$(_){return []}
367
367
  querySelectorAll(_){ return []; }
368
368
  querySelector(_){ return null; }
369
369
  getElementsByClassName(_){ return []; }
370
370
  getElementsByTagName(_){ return []; }
371
371
  getElementById(_){ return null; }
372
372
  get children(){ return []; }
373
373
  insertAdjacentElement(_,__){ }
374
374
  insertAdjacentHTML(_,__){ }
375
375
  insertAdjacentText(_,__){ }
376
376
  appendChild(_){ }
377
377
  get textContent(){ return ""; }
378
378
  set textContent(_){ }
379
379
  }
package/index.mjs CHANGED
@@ -21,7 +21,7 @@ function buildStyle(attributes){
21
21
  const styles=attributes.style || "";
22
22
  con
23
23
  class NodeClassList{
24
24
  constructor(node){ this.node=node }
25
25
  get classes(){ return (this.node.attributes.class || "").split(" ").filter(Boolean) }
26
26
  set classes(val){ this.node.attributes.class=val.join(" ") }
27
27
  contains(className){ return this.classes.includes(className) }
28
28
  add(className){
29
29
  const currentClasses=this.classes;
30
30
  if (!currentClasses.includes(className)) this.classes=[...currentClasses,className];
31
31
  }
32
32
  remove(className){ this.classes=this.classes.filter(cls=>cls!==className); }
33
33
  toggle(className){
34
34
  if (this.classes.includes(className)) this.remove(className);
35
35
  else this.add(className);
36
36
  }
37
37
  replace(oldClass,newClass){
38
38
  if (this.classes.includes(oldClass)){
39
39
  this.remove(oldClass);
40
40
  this.add(newClass);
41
41
  }
42
42
  }
43
43
  }
44
44
  function insertBefore(arr,index,newItem){
45
45
  const existingIndex=arr.indexOf(newItem);
46
46
  if (existingIndex!==-1) arr.splice(existingIndex,1);
47
47
  arr.splice(index,0,newItem);
48
- }
49
48
  class Node{
50
49
  constructor(tagName,attributes={},parent=null){
51
50
  this.isSingle=false;
52
51
  this.tagName=tagName;
53
52
  this.attributes=attributes;
54
53
  this.childNodes=[];
55
54
  if (parent!==null) parent.childNodes.push(this)
56
55
  this.parent=parent;
57
56
  this._classList=null;
58
57
  this.__style=null;
59
58
  this._dataset=null
60
59
  }
61
60
  get id(){ return this.attributes.id ? this.attributes.id : null; }
62
61
  set id(newValue){ this.attributes.id=newValue; }
63
62
  get className(){return this.attributes.class || null}
64
63
  get parentNode(){ return this.parent }
65
64
  get ancestors(){
66
65
  if(!this.parent) return []
67
66
  const ancestors=[]
68
67
  let element=this.parent
69
68
  while (element.tagName!=='ROOT'){
70
69
  ancestors.push(element)
71
70
  element=element.parent
72
71
  }
73
72
  return ancestors.reverse()
74
73
  }
75
74
  get childNodeIndex(){
76
75
  if(!this.parent) return null
77
76
  return this.parent.childNodes ? this.parent.childNodes.indexOf(this) : null
78
77
  }
79
78
  get childIndex(){
80
79
  if(!this.parent) return null
81
80
  return this.parent.children ? this.parent.children.indexOf(this) : null
82
81
  }
83
82
  get previousElementSibling(){ return this.prev }
84
83
  get prev(){
85
84
  if (!this.childIndex) return null
86
85
  return this.parent.children[this.childIndex-1]
87
86
  }
88
87
  get nextElementSibling(){ return this.next }
89
88
  get next(){
90
89
  if (!this.childIndex) return null
91
90
  return this.parent.children[this.childIndex+1] || null
92
91
  }
93
92
  get dataset(){
94
93
  if (!this._dataset) this._dataset=getDataset(this);
95
94
  return this._dataset;
96
95
  }
97
96
  get classList(){
98
97
  if (!this._classList) this._classList=new NodeClassList(this);
99
98
  return this._classList;
100
99
  }
101
100
  get style(){
102
101
  if (!this.__style) this.__style=buildStyle(this.attributes)
103
102
  return this.__style
104
103
  }
105
104
  get outerHTML(){
106
105
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
107
106
  return `<${this.tagName}${attrs ? ' '+attrs : ''}>${this.innerHTML}</${this.tagName}>`;
108
107
  }
109
108
  getAttribute(attrName){ return this.attributes[attrName] || null }
110
109
  setAttribute(attrName,value){ this.attributes[attrName]=value }
111
110
  removeAttribute(attrName){ delete this.attributes[attrName] }
112
111
  remove(){
113
112
  if (!this.parent) return
114
113
  const index=this.childIndex;
115
114
  if (index!==null) this.parent.childNodes.splice(index,1);
116
115
  }
117
116
  get innerHTML(){
118
117
  return this.childNodes.map(child=>{
119
118
  if (child instanceof Node || child instanceof SingleNode) return child.outerHTML;
120
119
  else if (child instanceof TextNode) return child.textContent;
121
120
  else return child
122
121
  }).join("");
123
122
  }
124
123
  $$(query){return this.querySelectorAll(query)}
125
124
  querySelectorAll(query){
126
125
  const selectors=Query.get(query)
127
126
  return find(selectors,this,new Set())
128
127
  }
129
128
  $(query){return this.querySelector(query)}
130
129
  querySelector(query){
131
130
  const selectors=Query.get(query)
132
131
  return find(selectors,this,new Set(),true)[0] || null
133
132
  }
134
133
  getElementsByClassName(query){ return this.querySelectorAll('.'+query) }
135
134
  getElementsByTagName(query){ return this.querySelectorAll(query) }
136
135
  getElementById(query){ return this.querySelector('#'+query) }
137
136
  get children(){
138
137
  return this.childNodes.filter(child=>{
139
138
  if (!(child instanceof Node)) return false
140
139
  if (child.tagName==='#comment') return false
141
140
  return true
142
141
  });
143
142
  }
144
143
  insertAdjacentElement(position,newElement){
145
144
  if(newElement.tagName==='ROOT' && newElement.childNodes.length>0) newElement=newElement.childNodes[0]
146
145
  const pos=position.toLowerCase();
147
146
  if (pos==="afterbegin") this.childNodes.unshift(newElement);
148
147
  else if (pos==="beforeend") this.childNodes.push(newElement);
149
148
  newElement.parent=this
150
149
  if (!this.parent) return newElement
151
150
  if (pos==="beforebegin") insertBefore(this.parent.childNodes,this.childNodeIndex,newElement)
152
151
  else if (pos==="afterend") this.parent.childNodes.splice(this.childNodeIndex+1,0,newElement);
153
152
  newElement.parent=this.parent
154
153
  return newElement
155
154
  }
156
155
  insertAdjacentHTML(position,html){
157
156
  const newNode=parseHTML(html);
158
157
  newNode.childNodes.reverse().forEach(node=>{
159
158
  this.insertAdjacentElement(position,node);
160
159
  });
161
160
  return newNode
162
161
  }
163
162
  insertAdjacentText(position,text){
164
163
  return this.insertAdjacentElement(position,new TextNode(text));
165
164
  }
166
165
  set innerHTML(html){
167
166
  const parsed=parseHTML(html);
168
167
  this.childNodes=parsed.childNodes;
169
168
  }
170
169
  set outerHTML(html){
171
170
  const parsed=parseHTML(html);
172
171
  if (!this.parent) return console.log('element has no parent node')
173
172
  const index=this.childIndex
174
173
  if (index!==null) this.parent.childNodes.splice(index,1,...parsed.childNodes);
175
174
  }
176
175
  appendChild(newChild){
177
176
  if (newChild instanceof Node || newChild instanceof TextNode || newChild instanceof SingleNode){
178
177
  if (newChild.parent) newChild.parent.childNodes=newChild.parent.childNodes.filter(child=>child!==newChild);
179
178
  } else if(typeof newChild==='string') newChild=new TextNode(newChild)
180
179
  else return newChild
181
180
  this.childNodes.push(newChild);
182
181
  newChild.parent=this;
183
182
  return newChild;
184
183
  }
185
184
  get textContent(){
186
185
  if (this.childNodes.length===0) return this.nodeName==='#text' ? this.nodeValue : '';
187
186
  return this.childNodes.map(child=>{
188
187
  if(child instanceof SingleNode) return ''
189
188
  if(child instanceof TextNode) return child.nodeValue
190
189
  if(child instanceof Node) return child.textContent;
191
190
  else return child;
192
191
  }).join(" ");
193
192
  }
194
193
  set textContent(value){
195
194
  this.childNodes=[];
196
195
  if (value!==null && value!==undefined){
197
196
  this.childNodes.push(value.toString());
198
197
  }
199
198
  }
199
+ }
200
200
  class Node{
201
201
  constructor(tagName,attributes={},parent=null){
202
202
  this.isSingle=false;
203
203
  this.tagName=tagName;
204
204
  this.attributes=attributes;
205
205
  this.childNodes=[];
206
206
  if (parent!==null) parent.childNodes.push(this)
207
207
  this.parent=parent;
208
208
  this._classList=null;
209
209
  this.__style=null;
210
210
  this._dataset=null
211
211
  }
212
212
  get id(){ return this.attributes.id ? this.attributes.id : null; }
213
213
  set id(newValue){ this.attributes.id=newValue; }
214
214
  get className(){return this.attributes.class || null}
215
215
  get parentNode(){ return this.parent }
216
216
  get ancestors(){
217
217
  if(!this.parent) return []
218
218
  const ancestors=[]
219
219
  let element=this.parent
220
220
  while (element.tagName!=='ROOT'){
221
221
  ancestors.push(element)
222
222
  element=element.parent
223
223
  }
224
224
  return ancestors.reverse()
225
225
  }
226
226
  get childNodeIndex(){
227
227
  if(!this.parent) return null
228
228
  return this.parent.childNodes ? this.parent.childNodes.indexOf(this) : null
229
229
  }
230
230
  get childIndex(){
231
231
  if(!this.parent) return null
232
232
  return this.parent.children ? this.parent.children.indexOf(this) : null
233
233
  }
234
234
  get previousElementSibling(){ return this.prev }
235
235
  get prev(){
236
236
  if (!this.childIndex) return null
237
237
  return this.parent.children[this.childIndex-1]
238
238
  }
239
239
  get nextElementSibling(){ return this.next }
240
240
  get next(){
241
241
  if (!this.childIndex) return null
242
242
  return this.parent.children[this.childIndex+1] || null
243
243
  }
244
244
  get dataset(){
245
245
  if (!this._dataset) this._dataset=getDataset(this);
246
246
  return this._dataset;
247
247
  }
248
248
  get classList(){
249
249
  if (!this._classList) this._classList=new NodeClassList(this);
250
250
  return this._classList;
251
251
  }
252
252
  get style(){
253
253
  if (!this.__style) this.__style=buildStyle(this.attributes)
254
254
  return this.__style
255
255
  }
256
256
  get outerHTML(){
257
257
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
258
258
  return `<${this.tagName}${attrs ? ' '+attrs : ''}>${this.innerHTML}</${this.tagName}>`;
259
259
  }
260
260
  getAttribute(attrName){ return this.attributes[attrName] || null }
261
261
  setAttribute(attrName,value){ this.attributes[attrName]=value }
262
262
  removeAttribute(attrName){ delete this.attributes[attrName] }
263
263
  remove(){
264
264
  if (!this.parent) return
265
265
  const index=this.childNodeIndex;
266
266
  if (index!==null) this.parent.childNodes.splice(index,1);
267
267
  }
268
268
  get innerHTML(){
269
269
  return this.childNodes.map(child=>{
270
270
  if (child instanceof Node || child instanceof SingleNode) return child.outerHTML;
271
271
  else if (child instanceof TextNode) return child.textContent;
272
272
  else return child
273
273
  }).join("");
274
274
  }
275
275
  $$(query){return this.querySelectorAll(query)}
276
276
  querySelectorAll(query){
277
277
  const selectors=Query.get(query)
278
278
  return find(selectors,this,new Set())
279
279
  }
280
280
  $(query){return this.querySelector(query)}
281
281
  querySelector(query){
282
282
  const selectors=Query.get(query)
283
283
  return find(selectors,this,new Set(),true)[0] || null
284
284
  }
285
285
  getElementsByClassName(query){ return this.querySelectorAll('.'+query) }
286
286
  getElementsByTagName(query){ return this.querySelectorAll(query) }
287
287
  getElementById(query){ return this.querySelector('#'+query) }
288
288
  get children(){
289
289
  return this.childNodes.filter(child=>{
290
290
  if (!(child instanceof Node)) return false
291
291
  if (child.tagName==='#comment') return false
292
292
  return true
293
293
  });
294
294
  }
295
295
  insertAdjacentElement(position,newElement){
296
296
  if(newElement.tagName==='ROOT' && newElement.childNodes.length>0) newElement=newElement.childNodes[0]
297
297
  const pos=position.toLowerCase();
298
298
  if (pos==="afterbegin") this.childNodes.unshift(newElement);
299
299
  else if (pos==="beforeend") this.childNodes.push(newElement);
300
300
  newElement.parent=this
301
301
  if (!this.parent) return newElement
302
302
  if (pos==="beforebegin") insertBefore(this.parent.childNodes,this.childNodeIndex,newElement)
303
303
  else if (pos==="afterend") this.parent.childNodes.splice(this.childNodeIndex+1,0,newElement);
304
304
  newElement.parent=this.parent
305
305
  return newElement
306
306
  }
307
307
  insertAdjacentHTML(position,html){
308
308
  const newNode=parseHTML(html);
309
309
  newNode.childNodes.reverse().forEach(node=>{
310
310
  this.insertAdjacentElement(position,node);
311
311
  });
312
312
  return newNode
313
313
  }
314
314
  insertAdjacentText(position,text){
315
315
  return this.insertAdjacentElement(position,new TextNode(text));
316
316
  }
317
317
  set innerHTML(html){
318
318
  const parsed=parseHTML(html);
319
319
  this.childNodes=parsed.childNodes;
320
320
  }
321
321
  set outerHTML(html){
322
322
  const parsed=parseHTML(html);
323
323
  if (!this.parent) return console.log('element has no parent node')
324
324
  const index=this.childIndex
325
325
  if (index!==null) this.parent.childNodes.splice(index,1,...parsed.childNodes);
326
326
  }
327
327
  appendChild(newChild){
328
328
  if (newChild instanceof Node || newChild instanceof TextNode || newChild instanceof SingleNode){
329
329
  if (newChild.parent) newChild.parent.childNodes=newChild.parent.childNodes.filter(child=>child!==newChild);
330
330
  } else if(typeof newChild==='string') newChild=new TextNode(newChild)
331
331
  else return newChild
332
332
  this.childNodes.push(newChild);
333
333
  newChild.parent=this;
334
334
  return newChild;
335
335
  }
336
336
  get textContent(){
337
337
  if (this.childNodes.length===0) return this.nodeName==='#text' ? this.nodeValue : '';
338
338
  return this.childNodes.map(child=>{
339
339
  if(child instanceof SingleNode) return ''
340
340
  if(child instanceof TextNode) return child.nodeValue
341
341
  if(child instanceof Node) return child.textContent;
342
342
  else return child;
343
343
  }).join(" ");
344
344
  }
345
345
  set textContent(value){
346
346
  this.childNodes=[];
347
347
  if (value!==null && value!==undefined){
348
348
  this.childNodes.push(value.toString());
349
349
  }
350
350
  }
351
351
  }
352
352
  class SingleNode extends Node{
353
353
  constructor(tagName,attributes={},parent=null){
354
354
  if(attributes['?'] && tagName==='?xml') delete attributes['?']
355
355
  super(tagName,attributes,parent);
356
356
  this.isSingle=true
357
357
  }
358
358
  get outerHTML(){
359
359
  if (this.tagName==="#cdata-section") return `<![CDATA[${this.nodeValue}]]>`;
360
360
  const attrs=Object.entries(this.attributes).map(([key,val])=>`${key}="${val}"`).join(" ");
361
361
  return `<${this.tagName} ${attrs}${this.tagName==='?xml' ? '?' : ''}>`;
362
362
  }
363
363
  get innerHTML(){ return ""; }
364
364
  set innerHTML(_){ }
365
365
  $(_){return null}
366
366
  $$(_){return []}
367
367
  querySelectorAll(_){ return []; }
368
368
  querySelector(_){ return null; }
369
369
  getElementsByClassName(_){ return []; }
370
370
  getElementsByTagName(_){ return []; }
371
371
  getElementById(_){ return null; }
372
372
  get children(){ return []; }
373
373
  insertAdjacentElement(_,__){ }
374
374
  insertAdjacentHTML(_,__){ }
375
375
  insertAdjacentText(_,__){ }
376
376
  appendChild(_){ }
377
377
  get textContent(){ return ""; }
378
378
  set textContent(_){ }
379
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-document",
3
- "version": "1.0.6-alpha",
3
+ "version": "1.0.7-alpha",
4
4
  "description": "A powerful HTML parser & DOM manipulation library for both backend and frontend.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
package/src/node/node.js CHANGED
@@ -79,7 +79,7 @@ class Node {
79
79
 
80
80
  remove() {
81
81
  if (!this.parent) return
82
- const index = this.childIndex;
82
+ const index = this.childNodeIndex;
83
83
  if (index !== null) this.parent.childNodes.splice(index, 1);
84
84
  }
85
85