nv-basic-bw 1.0.12 → 1.0.15
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/DIST/nv-basci-bw.js +23 -23
- package/attr.js +1 -1
- package/calc.js +144 -0
- package/cls-accessor.js +1 -1
- package/code.js +191 -0
- package/com.sh +1 -0
- package/const.js +48 -0
- package/dnld.js +171 -0
- package/ele.js +365 -0
- package/index.js +21 -595
- package/limit.js +11 -1
- package/nd.js +390 -0
- package/package.json +2 -2
- package/ui.js +219 -1
- package/util.js +75 -0
package/ele.js
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
const {TAGS,NEED_TO_SP_ATTR_NMS} = require("./const");
|
|
2
|
+
const {is_url,fullfill_url} = require("./util");
|
|
3
|
+
const {editonly_sdfs_for_each,is_topo_leaf} = require("./nd");
|
|
4
|
+
|
|
5
|
+
const plget = (root, tags) => {
|
|
6
|
+
let curr = [root];
|
|
7
|
+
|
|
8
|
+
for (const tag of tags) {
|
|
9
|
+
const next = [];
|
|
10
|
+
|
|
11
|
+
for (const el of curr) {
|
|
12
|
+
// 使用 children 是正确的
|
|
13
|
+
const children = el.children;
|
|
14
|
+
for (let i = 0; i < children.length; i++) {
|
|
15
|
+
const c = children[i];
|
|
16
|
+
if (c.tagName.toLowerCase() === tag) {
|
|
17
|
+
next.push(c);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (next.length === 0) return [];
|
|
23
|
+
curr = next;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return curr;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const plinget = (root, tags) => {
|
|
30
|
+
const res = [];
|
|
31
|
+
const L = tags.length;
|
|
32
|
+
|
|
33
|
+
function dfs(node, idx) {
|
|
34
|
+
let nextIdx = idx;
|
|
35
|
+
|
|
36
|
+
if (node.nodeType === 1) {
|
|
37
|
+
const tag = node.tagName.toLowerCase();
|
|
38
|
+
if (tag === tags[idx]) {
|
|
39
|
+
nextIdx = idx + 1;
|
|
40
|
+
if (nextIdx === L) {
|
|
41
|
+
res.push(node);
|
|
42
|
+
// 注意:不 return,允许继续找更深的匹配
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const children = node.children;
|
|
48
|
+
if (!children) return;
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < children.length; i++) {
|
|
51
|
+
dfs(children[i], nextIdx);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
dfs(root, 0);
|
|
56
|
+
return res;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const filter_on_tag_or_attr_key_with_rgx = async(rt,o,is_leaf=is_topo_leaf)=>{
|
|
61
|
+
let arr =[];
|
|
62
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
63
|
+
if(el.tagName) {
|
|
64
|
+
if(o.test(el.tagName)) {
|
|
65
|
+
arr.push(el);
|
|
66
|
+
} else {
|
|
67
|
+
if(el.attributes) {
|
|
68
|
+
for(let a of el.attributes) {
|
|
69
|
+
if(o.test(a.name)) {
|
|
70
|
+
arr.push(el);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
//忽略非element 节点
|
|
79
|
+
}
|
|
80
|
+
},is_leaf);
|
|
81
|
+
return arr;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const summary = async(rt,is_leaf=is_topo_leaf)=>{
|
|
86
|
+
let tags = new Set();
|
|
87
|
+
let keys = new Set();
|
|
88
|
+
let vals = new Set();
|
|
89
|
+
let txts = new Set();
|
|
90
|
+
let cmts = new Set();
|
|
91
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
92
|
+
if(el.nodeType === Node.ELEMENT_NODE) {
|
|
93
|
+
tags.add(el.tagName.toLowerCase());
|
|
94
|
+
if(el.attributes) {
|
|
95
|
+
for(let a of el.attributes) {
|
|
96
|
+
keys.add(a.name.toLowerCase());
|
|
97
|
+
if(NEED_TO_SP_ATTR_NMS.has(a.name.toLowerCase())) {
|
|
98
|
+
let vs = a.value.split(/[ ]+/g);
|
|
99
|
+
for(let v of vs) { vals.add(v);}
|
|
100
|
+
} else {
|
|
101
|
+
vals.add(a.value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} else if(el.nodeType === Node.TEXT_NODE) {
|
|
106
|
+
txts.add(el.nodeValue);
|
|
107
|
+
} else if(el.nodeType === Node.COMMENT_NODE) {
|
|
108
|
+
cmts.add(el.nodeValue);
|
|
109
|
+
} else {
|
|
110
|
+
}
|
|
111
|
+
},is_leaf);
|
|
112
|
+
return {tags:Array.from(tags),keys:Array.from(keys),vals:Array.from(vals),txts:Array.from(txts),cmts:Array.from(cmts)};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const filter = async(rt,o,is_leaf=is_topo_leaf)=>{
|
|
117
|
+
if(typeof(o)==="string") {
|
|
118
|
+
if(o[0]==="#") {
|
|
119
|
+
let arr =[];
|
|
120
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
121
|
+
if(el.tagName) {
|
|
122
|
+
let expected = o.slice(1);
|
|
123
|
+
let id = el.getAttribute("id");
|
|
124
|
+
if(expected === id) {
|
|
125
|
+
arr.push(el);
|
|
126
|
+
} else {}
|
|
127
|
+
} else {
|
|
128
|
+
//忽略非element 节点
|
|
129
|
+
}
|
|
130
|
+
},is_leaf);
|
|
131
|
+
return arr;
|
|
132
|
+
} else if(o[0] === ".") {
|
|
133
|
+
let arr =[];
|
|
134
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
135
|
+
if(el.tagName) {
|
|
136
|
+
let expected = o.slice(1);
|
|
137
|
+
let clses = el.getAttribute("class").split(/[ ]+/g).map(r=>r.toLowerCase());
|
|
138
|
+
if(clses.includes(expected)) {
|
|
139
|
+
arr.push(el);
|
|
140
|
+
} else {}
|
|
141
|
+
} else {
|
|
142
|
+
//忽略非element 节点
|
|
143
|
+
}
|
|
144
|
+
},is_leaf);
|
|
145
|
+
return arr;
|
|
146
|
+
} else if(o[0] === "`") {
|
|
147
|
+
let arr =[];
|
|
148
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
149
|
+
if(el.nodeType === Node.TEXT_NODE ) {
|
|
150
|
+
let expected = o.slice(1);
|
|
151
|
+
if(node.nodeValue.includes(expected)) {
|
|
152
|
+
arr.push(el)
|
|
153
|
+
} else {}
|
|
154
|
+
} else {
|
|
155
|
+
//忽略非text 节点
|
|
156
|
+
}
|
|
157
|
+
},is_leaf);
|
|
158
|
+
return arr;
|
|
159
|
+
} else if(o[0] === "!") {
|
|
160
|
+
let arr =[];
|
|
161
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
162
|
+
if(
|
|
163
|
+
el.nodeType === Node.ELEMENT_NODE
|
|
164
|
+
) {
|
|
165
|
+
if(typeof(el.click) === "function") {
|
|
166
|
+
let tagnm = el.tagName.toLowerCase();
|
|
167
|
+
if(!(["html","head","meta","link","style","script"].includes(tagnm))) {
|
|
168
|
+
if(tagnm.includes(o.slice(1).toLowerCase())) {
|
|
169
|
+
arr.push(el)
|
|
170
|
+
} else {}
|
|
171
|
+
}
|
|
172
|
+
} else {}
|
|
173
|
+
} else {
|
|
174
|
+
//忽略非text 节点
|
|
175
|
+
}
|
|
176
|
+
},is_leaf);
|
|
177
|
+
return arr;
|
|
178
|
+
} else if(o[0] === "@") {
|
|
179
|
+
let arr =[];
|
|
180
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
181
|
+
if(el.tagName) {
|
|
182
|
+
if(el.attributes) {
|
|
183
|
+
for(let a of el.attributes) {
|
|
184
|
+
let v = a.value;
|
|
185
|
+
let vs = v.split(/[ ]+/g);
|
|
186
|
+
let match = o.slice(1);
|
|
187
|
+
for(let each of vs) {
|
|
188
|
+
if(is_url(each)) {
|
|
189
|
+
if(each.includes(match)) {
|
|
190
|
+
arr.push(el);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
//忽略非element 节点
|
|
200
|
+
}
|
|
201
|
+
},is_leaf);
|
|
202
|
+
return arr;
|
|
203
|
+
} else if(o[0] === "-") {
|
|
204
|
+
let rslt = {};
|
|
205
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
206
|
+
if(el.tagName) {
|
|
207
|
+
if(el.attributes) {
|
|
208
|
+
for(let a of el.attributes) {
|
|
209
|
+
if(a.name.startsWith("data-")) {
|
|
210
|
+
let name = a.name.slice(5);
|
|
211
|
+
if(name.includes(o.slice(1))) {
|
|
212
|
+
let v = a.value;
|
|
213
|
+
try{v= JSON.parse(v);} catch(e) {}
|
|
214
|
+
if(rslt[name]) {
|
|
215
|
+
rslt[name].push(v);
|
|
216
|
+
} else {
|
|
217
|
+
rslt[name] = [v];
|
|
218
|
+
}
|
|
219
|
+
} else {}
|
|
220
|
+
} else {
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
//忽略非element 节点
|
|
227
|
+
}
|
|
228
|
+
},is_leaf);
|
|
229
|
+
return rslt;
|
|
230
|
+
} else if(o[0] === "*") {
|
|
231
|
+
return summary(rt,is_leaf);
|
|
232
|
+
} else if(o[0] === "&") {
|
|
233
|
+
let arr =[];
|
|
234
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
235
|
+
if(el.tagName) {
|
|
236
|
+
if(el.attributes) {
|
|
237
|
+
for(let a of el.attributes) {
|
|
238
|
+
let v = a.value;
|
|
239
|
+
let vs = v.split(/[ ]+/g);
|
|
240
|
+
let match = o.slice(1);
|
|
241
|
+
for(let each of vs) {
|
|
242
|
+
if(is_url(each)) {
|
|
243
|
+
if(each.includes(match)) {
|
|
244
|
+
arr.push(fullfill_url(each));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
//忽略非element 节点
|
|
253
|
+
}
|
|
254
|
+
},is_leaf);
|
|
255
|
+
return arr;
|
|
256
|
+
} else if(o.slice(0,2) === "//") {
|
|
257
|
+
let arr =[];
|
|
258
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
259
|
+
if(el.nodeType === Node.COMMENT_NODE ) {
|
|
260
|
+
let expected = o.slice(2);
|
|
261
|
+
if(node.nodeValue.toLowerCase().includes(expected.toLowerCase())) {
|
|
262
|
+
arr.push(el)
|
|
263
|
+
} else {}
|
|
264
|
+
} else {
|
|
265
|
+
//忽略非注释 节点
|
|
266
|
+
}
|
|
267
|
+
},is_leaf);
|
|
268
|
+
return arr;
|
|
269
|
+
} else if(o.slice(0,2) === "?:") {
|
|
270
|
+
let arr =[];
|
|
271
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
272
|
+
if(el.tagName) {
|
|
273
|
+
if(el.attributes) {
|
|
274
|
+
for(let a of el.attributes) {
|
|
275
|
+
if( o.slice(2).toLowerCase() === a.name.toLowerCase()) {
|
|
276
|
+
arr.push(el);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
//忽略非element 节点
|
|
284
|
+
}
|
|
285
|
+
},is_leaf);
|
|
286
|
+
return arr;
|
|
287
|
+
} else if(o.slice(0,2) === ":?") {
|
|
288
|
+
let arr =[];
|
|
289
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
290
|
+
if(el.tagName) {
|
|
291
|
+
if(el.attributes) {
|
|
292
|
+
for(let a of el.attributes) {
|
|
293
|
+
if( a.value.includes(o.slice(2))) {
|
|
294
|
+
arr.push(el);
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
//忽略非element 节点
|
|
302
|
+
}
|
|
303
|
+
},is_leaf);
|
|
304
|
+
return arr;
|
|
305
|
+
} else if(o[0] === "/") {
|
|
306
|
+
let pl = o.split("/").filter(r=>r!=="");
|
|
307
|
+
let arr = plget(document,pl);
|
|
308
|
+
if(arr.length === 0) {
|
|
309
|
+
return await filter_on_tag_or_attr_key_with_rgx(rt,new RegExp(o),is_leaf);
|
|
310
|
+
} else {
|
|
311
|
+
return arr;
|
|
312
|
+
}
|
|
313
|
+
} else if(o.includes("/")) {
|
|
314
|
+
let subpl = o.split("/").filter(r=>r!=="");
|
|
315
|
+
return plinget(document,subpl);
|
|
316
|
+
} else {
|
|
317
|
+
let arr =[];
|
|
318
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
319
|
+
let cond = el.tagName? (el.tagName.toLowerCase()===o.toLowerCase()):false;
|
|
320
|
+
if(cond){arr.push(el)}
|
|
321
|
+
},is_leaf);
|
|
322
|
+
return arr;
|
|
323
|
+
}
|
|
324
|
+
} else if(o instanceof RegExp) {
|
|
325
|
+
return await filter_on_tag_or_attr_key_with_rgx(rt,o,is_leaf);
|
|
326
|
+
} else {
|
|
327
|
+
let arr = [];
|
|
328
|
+
if(is_async(o)) {
|
|
329
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{let cond = await o(el,rel_depth);if(cond){arr.push(el)}},is_leaf);
|
|
330
|
+
} else {
|
|
331
|
+
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{let cond = o(el,rel_depth);if(cond){arr.push(el)}},is_leaf);
|
|
332
|
+
}
|
|
333
|
+
return arr;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const $ = new Proxy(document,{
|
|
338
|
+
get(target, property, receiver) {
|
|
339
|
+
if(
|
|
340
|
+
TAGS.has(property.toLowerCase())
|
|
341
|
+
|| property[0] === "*"
|
|
342
|
+
|| property[0] === "&"
|
|
343
|
+
|| property[0] === "-"
|
|
344
|
+
////------------------------------------------
|
|
345
|
+
|| property[0] === "#"
|
|
346
|
+
|| property[0] === "."
|
|
347
|
+
|| property[0] === "?"
|
|
348
|
+
|| property[0] === ":"
|
|
349
|
+
|| property[0] === "@"
|
|
350
|
+
|| property[0] === "!"
|
|
351
|
+
|| property.includes("/")
|
|
352
|
+
) {
|
|
353
|
+
return filter(document,property)
|
|
354
|
+
} else {
|
|
355
|
+
return Reflect.get(target, property, receiver);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
module.exports = {
|
|
361
|
+
plget,plinget,
|
|
362
|
+
filter_on_tag_or_attr_key_with_rgx,
|
|
363
|
+
filter,
|
|
364
|
+
$,
|
|
365
|
+
}
|