als-document 0.6.1 → 0.7.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.
- package/document.js +25 -11
- package/document.mjs +804 -0
- package/package.json +3 -6
- package/readme.md +12 -4
- package/test/{html1.js → data/html1.js} +1 -2
- package/test/{html2.js → data/html2.js} +1 -1
- package/test/front-test/html.html +5650 -0
- package/test/front-test/html.js +3218 -0
- package/test/front-test/test.html +18 -0
- package/test/front-test/test.js +129 -0
- package/test/test.html +17 -0
- package/test/test.js +15 -19
- package/test/tests/document-test.js +402 -0
- package/test/tests/parser-test.js +99 -0
- package/test/tests/query-test.js +71 -0
- package/test/tests/selector-test.js +169 -0
- package/test/utils/__dirname.js +6 -0
- package/test/utils/als-simple-test/test.mjs +153 -0
- package/test/utils/iframe.js +4 -0
- package/document/document.js +0 -192
- package/document/test.js +0 -678
- package/document.min.js +0 -1
- package/index.js +0 -6
- package/parser/parser.js +0 -336
- package/parser/test.js +0 -233
- package/query/query.js +0 -147
- package/query/readme.md +0 -134
- package/query/test.js +0 -143
- package/selector/selector.js +0 -126
- package/selector/test.js +0 -410
package/document.js
CHANGED
|
@@ -103,8 +103,8 @@ class HtmlSelector {
|
|
|
103
103
|
let passedTests = 0
|
|
104
104
|
if(attribs) for(let i=0; i<attribs.length; i++) {
|
|
105
105
|
let {name,value,check} = attribs[i]
|
|
106
|
-
if(name == 'inner' && value !== undefined && check && el.
|
|
107
|
-
if(check(el.
|
|
106
|
+
if(name == 'inner' && value !== undefined && check && el.inner) {
|
|
107
|
+
if(check(el.inner)) passedTests++
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
if(!names.includes(name)) continue
|
|
@@ -118,7 +118,6 @@ class HtmlSelector {
|
|
|
118
118
|
else return false
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
|
|
122
121
|
class Query {
|
|
123
122
|
static get(query) {
|
|
124
123
|
let q = new Query(query)
|
|
@@ -265,7 +264,6 @@ class Query {
|
|
|
265
264
|
return selector
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
|
-
|
|
269
267
|
class HtmlParser {
|
|
270
268
|
static parse(html) {
|
|
271
269
|
let result = new HtmlParser(html)
|
|
@@ -513,6 +511,16 @@ class HtmlParser {
|
|
|
513
511
|
|
|
514
512
|
innerText(element) {
|
|
515
513
|
Object.defineProperty(element, 'innerText', { get() {
|
|
514
|
+
if(element.children)
|
|
515
|
+
return element.children.map(child =>
|
|
516
|
+
child.type == 'text' ? child.text.trim()
|
|
517
|
+
: child.type == 'tag'
|
|
518
|
+
? child.innerText
|
|
519
|
+
: ''
|
|
520
|
+
).join(' ')
|
|
521
|
+
else return ''
|
|
522
|
+
}})
|
|
523
|
+
Object.defineProperty(element, 'inner', { get() {
|
|
516
524
|
if(element.children)
|
|
517
525
|
return element.children.map(child => child.type == 'text' ? child.text : '').join('')
|
|
518
526
|
else return ''
|
|
@@ -566,11 +574,14 @@ class HtmlParser {
|
|
|
566
574
|
|
|
567
575
|
parseAttributes(tagString,classList=[],attribs={},style={},id=null) {
|
|
568
576
|
let text = tagString
|
|
569
|
-
let attributes = tagString.match(/(
|
|
570
|
-
if(attributes) attributes.forEach(attribString => {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
577
|
+
let attributes = tagString.match(/(\w+)(?:\s*=\s*(['"]?)(.*?)\2)?/g)
|
|
578
|
+
if(attributes) attributes.forEach((attribString,i) => {
|
|
579
|
+
if(i == 0) return
|
|
580
|
+
let array = attribString.split('=')
|
|
581
|
+
let name = array[0]
|
|
582
|
+
if(array.length>1 && name !== '') {
|
|
583
|
+
let value = array.filter((v,i) => i>0).join('=')
|
|
584
|
+
value = value.trim().replace(/^\"|\'/,'').replace(/\"|\'$/m,'')
|
|
574
585
|
let eventIndex = value.match(/(?<=\{\{\{\{event\s)(\d*)?/)
|
|
575
586
|
if(eventIndex !== null) {
|
|
576
587
|
value = this.events[eventIndex[0]]
|
|
@@ -601,7 +612,6 @@ class HtmlParser {
|
|
|
601
612
|
return styles
|
|
602
613
|
}
|
|
603
614
|
}
|
|
604
|
-
|
|
605
615
|
class Document extends HtmlSelector {
|
|
606
616
|
constructor(html) {
|
|
607
617
|
super(html)
|
|
@@ -645,6 +655,7 @@ class Document extends HtmlSelector {
|
|
|
645
655
|
obj[prop] = value
|
|
646
656
|
element.attribs.style = Object.keys(obj).map(key => `${convertProp(key)}:${obj[key]};`).join('')
|
|
647
657
|
self.changeElementText(this)
|
|
658
|
+
return true
|
|
648
659
|
},
|
|
649
660
|
deleteProperty(obj, prop) {
|
|
650
661
|
if (prop in obj) {
|
|
@@ -652,6 +663,7 @@ class Document extends HtmlSelector {
|
|
|
652
663
|
element.attribs.style = Object.keys(obj).map(key => `${convertProp(key)}:${obj[key]};`).join('')
|
|
653
664
|
}
|
|
654
665
|
self.changeElementText(this)
|
|
666
|
+
return true
|
|
655
667
|
}
|
|
656
668
|
};
|
|
657
669
|
element.style = new Proxy(obj, handler);
|
|
@@ -789,4 +801,6 @@ class Document extends HtmlSelector {
|
|
|
789
801
|
element.text = `<${tag}${atts}>`
|
|
790
802
|
}
|
|
791
803
|
}
|
|
792
|
-
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
try {module.exports = {HtmlSelector,Query,HtmlParser,Document}} catch (error) {}
|