nv-basic-bw 1.0.11 → 1.0.14
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 -13
- package/attr.js +1 -1
- package/calc.js +144 -0
- package/cls-accessor.js +1 -1
- package/code.js +181 -0
- package/com.sh +1 -0
- package/const.js +48 -0
- package/dnld.js +90 -0
- package/ele.js +365 -0
- package/index.js +21 -593
- package/limit.js +103 -0
- package/nd.js +390 -0
- package/package.json +2 -2
- package/util.js +75 -0
package/index.js
CHANGED
|
@@ -1,599 +1,27 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
while (node && node.parentNode) {
|
|
6
|
-
node = node.parentNode;
|
|
7
|
-
depth++;
|
|
8
|
-
}
|
|
9
|
-
return depth;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const get_ance = (node,which)=>{
|
|
13
|
-
if(which >0) {
|
|
14
|
-
let c = 1;
|
|
15
|
-
while(true) {
|
|
16
|
-
let pr = node.parentNode;
|
|
17
|
-
if(c===which) {
|
|
18
|
-
return pr;
|
|
19
|
-
} else {
|
|
20
|
-
node = pr;
|
|
21
|
-
++c;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
return node;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const get_rt = (node) => {
|
|
30
|
-
while (node.parentNode) {
|
|
31
|
-
node = node.parentNode;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return node;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const is_topo_leaf = (nd)=> nd.firstChild!==null && nd.firstChild!==undefined;
|
|
39
|
-
|
|
40
|
-
const get_drmost = (node,is_leaf=is_topo_leaf) => {
|
|
41
|
-
let rel_depth = 0;
|
|
42
|
-
while (!(is_leaf(node))) {
|
|
43
|
-
node = node.lastChild;
|
|
44
|
-
++rel_depth;
|
|
45
|
-
}
|
|
46
|
-
return [node,rel_depth];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const get_dlmost = (node,is_leaf=is_topo_leaf)=>{
|
|
50
|
-
let rel_depth = 0;
|
|
51
|
-
while(!is_leaf(node)) {
|
|
52
|
-
node = node.firstChild;
|
|
53
|
-
++rel_depth;
|
|
54
|
-
}
|
|
55
|
-
return [node,rel_depth];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const find_rb_of_fst_ance_has_rb = (node, rel_depth) => {
|
|
59
|
-
// 1️⃣ 当前节点有 nextSibling
|
|
60
|
-
if (node.nextSibling) {
|
|
61
|
-
return [node.nextSibling, rel_depth];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 2️⃣ 沿父节点向上查找
|
|
65
|
-
let current = node.parentNode;
|
|
66
|
-
let depth = rel_depth;
|
|
67
|
-
|
|
68
|
-
while (current) {
|
|
69
|
-
depth -= 1; // 向上走一层
|
|
70
|
-
|
|
71
|
-
if (current.nextSibling) {
|
|
72
|
-
return [current.nextSibling, depth];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
current = current.parentNode;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 3️⃣ 已到根节点,仍然没有
|
|
79
|
-
return [null,-1];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const editonly_sdfs_for_each = async(rt,cb=(el,rel_depth)=>{},is_leaf=is_topo_leaf)=> {
|
|
83
|
-
let [drmost,ignore] = get_drmost(rt,is_leaf)
|
|
84
|
-
let curr = rt;
|
|
85
|
-
let should_await = is_async(cb);
|
|
86
|
-
let rel_depth =0;
|
|
87
|
-
while(true) {
|
|
88
|
-
let should_break = false;
|
|
89
|
-
if(should_await) {
|
|
90
|
-
should_break = await cb(curr,rel_depth);
|
|
91
|
-
} else {
|
|
92
|
-
should_break = cb(curr,rel_depth);
|
|
93
|
-
}
|
|
94
|
-
if(should_break||curr=== drmost) {return;} else {
|
|
95
|
-
if(!is_leaf(curr)) {
|
|
96
|
-
++rel_depth;
|
|
97
|
-
curr = curr.firstChild;
|
|
98
|
-
} else {
|
|
99
|
-
let pair = find_rb_of_fst_ance_has_rb(curr,rel_depth);
|
|
100
|
-
curr = pair[0];
|
|
101
|
-
if(curr) {
|
|
102
|
-
rel_depth = pair[1];
|
|
103
|
-
} else {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const find_lb_of_fst_ance_has_lb = (node, rel_depth) => {
|
|
113
|
-
// 1️⃣ 当前节点有 nextSibling
|
|
114
|
-
if (node.prevSibling) {
|
|
115
|
-
return [node.prevSibling, rel_depth];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 2️⃣ 沿父节点向上查找
|
|
119
|
-
let current = node.parentNode;
|
|
120
|
-
let depth = rel_depth;
|
|
121
|
-
|
|
122
|
-
while (current) {
|
|
123
|
-
depth -= 1; // 向上走一层
|
|
124
|
-
|
|
125
|
-
if (current.prevSibling) {
|
|
126
|
-
return [current.prevSibling, depth];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
current = current.parentNode;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 3️⃣ 已到根节点,仍然没有
|
|
133
|
-
return [null,-1];
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const editonly_rsdfs_for_each = async(rt,cb=(el,rel_depth)=>{},is_leaf=is_topo_leaf)=> {
|
|
137
|
-
let [dlmost,ignore] = get_dlmost(rt,is_leaf)
|
|
138
|
-
let curr = rt;
|
|
139
|
-
let should_await = is_async(cb);
|
|
140
|
-
let rel_depth =0;
|
|
141
|
-
while(true) {
|
|
142
|
-
let should_break = false;
|
|
143
|
-
if(should_await) {
|
|
144
|
-
should_break = await cb(curr,rel_depth);
|
|
145
|
-
} else {
|
|
146
|
-
should_break = cb(curr,rel_depth);
|
|
147
|
-
}
|
|
148
|
-
if(should_break||curr=== dlmost) {return;} else {
|
|
149
|
-
if(!is_leaf(curr)) {
|
|
150
|
-
++rel_depth;
|
|
151
|
-
curr = curr.lastChild;
|
|
152
|
-
} else {
|
|
153
|
-
let pair = find_lb_of_fst_ance_has_lb(curr,rel_depth);
|
|
154
|
-
curr = pair[0];
|
|
155
|
-
if(curr) {
|
|
156
|
-
rel_depth = pair[1];
|
|
157
|
-
} else {
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const editonly_edfs_for_each = async(rt,cb=(el,rel_depth)=>{},is_leaf=is_topo_leaf)=> {
|
|
167
|
-
let [curr,rel_depth] = get_dlmost(rt,is_leaf)
|
|
168
|
-
let should_await = is_async(cb);
|
|
169
|
-
while(true) {
|
|
170
|
-
let should_break = false;
|
|
171
|
-
if(should_await) {
|
|
172
|
-
should_break = await cb(curr,rel_depth);
|
|
173
|
-
} else {
|
|
174
|
-
should_break = cb(curr,rel_depth);
|
|
175
|
-
}
|
|
176
|
-
if(should_break|| curr === rt) {return;} else {
|
|
177
|
-
let rb = curr.nextSibling;
|
|
178
|
-
if(rb) {
|
|
179
|
-
let pair = get_dlmost(rb,is_leaf);
|
|
180
|
-
rel_depth+= pair[1];
|
|
181
|
-
curr = pair[0];
|
|
182
|
-
} else {
|
|
183
|
-
let pr = curr.parentNode;
|
|
184
|
-
if(pr) {
|
|
185
|
-
--rel_depth;
|
|
186
|
-
curr = pr;
|
|
187
|
-
} else {
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const editonly_redfs_for_each = async(rt,cb=(el,rel_depth)=>{},is_leaf=is_topo_leaf)=> {
|
|
196
|
-
let [curr,rel_depth] = get_drmost(rt,is_leaf)
|
|
197
|
-
let should_await = is_async(cb);
|
|
198
|
-
while(true) {
|
|
199
|
-
let should_break = false;
|
|
200
|
-
if(should_await) {
|
|
201
|
-
should_break = await cb(curr,rel_depth);
|
|
202
|
-
} else {
|
|
203
|
-
should_break = cb(curr,rel_depth);
|
|
204
|
-
}
|
|
205
|
-
if(should_break || curr === rt) {return;} else {
|
|
206
|
-
let lb = curr.prevSibling;
|
|
207
|
-
if(lb) {
|
|
208
|
-
let pair = get_drmost(lb,is_leaf);
|
|
209
|
-
rel_depth+= pair[1];
|
|
210
|
-
curr = pair[0];
|
|
211
|
-
} else {
|
|
212
|
-
let pr = curr.parentNode;
|
|
213
|
-
if(pr) {
|
|
214
|
-
--rel_depth;
|
|
215
|
-
curr = pr;
|
|
216
|
-
} else {
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const visit = async(
|
|
225
|
-
rt,
|
|
226
|
-
exit_cb = (el,rel_depth)=>{},
|
|
227
|
-
enter_cb = (el,rel_depth)=>{},
|
|
228
|
-
is_leaf=is_topo_leaf,
|
|
229
|
-
) => {
|
|
230
|
-
let curr = rt;
|
|
231
|
-
let state = "open";
|
|
232
|
-
let cbs = {
|
|
233
|
-
"open": [enter_cb, is_async(enter_cb)],
|
|
234
|
-
"clos": [exit_cb, is_async(exit_cb) ]
|
|
235
|
-
};
|
|
236
|
-
let rel_depth = 0;
|
|
237
|
-
while(true) {
|
|
238
|
-
let should_break = false;
|
|
239
|
-
let [cb,should_await] = cbs[state];
|
|
240
|
-
if(state === "open") {
|
|
241
|
-
// open 状态 先执行用户回调
|
|
242
|
-
if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
|
|
243
|
-
// 然后再取下一个节点: 用户回调如果修改了树结构,拿到的是修改后的
|
|
244
|
-
if(should_break) {return;} else {
|
|
245
|
-
if(!is_leaf(curr)) {
|
|
246
|
-
curr=curr.firstChild; ++rel_depth;
|
|
247
|
-
} else {
|
|
248
|
-
state = "clos";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
//事先拿出nxt,因为用户可能改变树结构
|
|
253
|
-
let nxt;
|
|
254
|
-
let nxt_rel_depth;
|
|
255
|
-
let nxt_state;
|
|
256
|
-
let rb = curr.nextSibling;
|
|
257
|
-
if(rb) {
|
|
258
|
-
nxt_state = "open";
|
|
259
|
-
nxt = rb;
|
|
260
|
-
nxt_rel_depth = rel_depth;
|
|
261
|
-
} else {
|
|
262
|
-
nxt_state = "clos";
|
|
263
|
-
nxt = curr.parentNode;
|
|
264
|
-
nxt_rel_depth = rel_depth -1;
|
|
265
|
-
}
|
|
266
|
-
if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
|
|
267
|
-
if(should_break) {return;} else {
|
|
268
|
-
if(curr !== rt) {
|
|
269
|
-
state = nxt_state;curr = nxt;rel_depth = nxt_rel_depth;
|
|
270
|
-
} else {
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const rvisit = async(
|
|
280
|
-
rt,
|
|
281
|
-
exit_cb = (el,rel_depth)=>{},
|
|
282
|
-
enter_cb = (el,rel_depth)=>{},
|
|
283
|
-
is_leaf=is_topo_leaf,
|
|
284
|
-
) => {
|
|
285
|
-
let curr = rt;
|
|
286
|
-
let state = "open";
|
|
287
|
-
let cbs = {
|
|
288
|
-
"open": [enter_cb, is_async(enter_cb)],
|
|
289
|
-
"clos": [exit_cb, is_async(exit_cb) ]
|
|
290
|
-
};
|
|
291
|
-
let rel_depth = 0;
|
|
292
|
-
while(true) {
|
|
293
|
-
let should_break = false;
|
|
294
|
-
let [cb,should_await] = cbs[state];
|
|
295
|
-
if(state === "open") {
|
|
296
|
-
// open 状态 先执行用户回调
|
|
297
|
-
if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
|
|
298
|
-
// 然后再取下一个节点: 用户回调如果修改了树结构,拿到的是修改后的
|
|
299
|
-
if(should_break) {return;} else {
|
|
300
|
-
if(!is_leaf(curr)) {
|
|
301
|
-
curr=curr.lastChild;; ++rel_depth;
|
|
302
|
-
} else {
|
|
303
|
-
state = "clos";
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
} else {
|
|
307
|
-
//事先拿出nxt,因为用户可能改变树结构
|
|
308
|
-
let nxt;
|
|
309
|
-
let nxt_rel_depth;
|
|
310
|
-
let nxt_state;
|
|
311
|
-
let lb = curr.prevSibling;
|
|
312
|
-
if(lb) {
|
|
313
|
-
nxt_state = "open";
|
|
314
|
-
nxt = lb;
|
|
315
|
-
nxt_rel_depth = rel_depth;
|
|
316
|
-
} else {
|
|
317
|
-
nxt_state = "clos";
|
|
318
|
-
nxt = curr.parentNode;
|
|
319
|
-
nxt_rel_depth = rel_depth -1;
|
|
320
|
-
}
|
|
321
|
-
if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
|
|
322
|
-
if(should_break) {return;} else {
|
|
323
|
-
if(curr !== rt) {
|
|
324
|
-
state = nxt_state;curr = nxt;rel_depth = nxt_rel_depth;
|
|
325
|
-
} else {
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const filter = async(rt,o,is_leaf=is_topo_leaf)=>{
|
|
334
|
-
if(typeof(o)==="string") {
|
|
335
|
-
let arr =[];
|
|
336
|
-
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
|
|
337
|
-
let cond = el.tagName? (el.tagName.toLowerCase()===o.toLowerCase()):false;
|
|
338
|
-
if(cond){arr.push(el)}
|
|
339
|
-
},is_leaf);
|
|
340
|
-
return arr;
|
|
341
|
-
} else {
|
|
342
|
-
let arr = [];
|
|
343
|
-
if(is_async(o)) {
|
|
344
|
-
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{let cond = await o(el,rel_depth);if(cond){arr.push(el)}},is_leaf);
|
|
345
|
-
} else {
|
|
346
|
-
await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{let cond = o(el,rel_depth);if(cond){arr.push(el)}},is_leaf);
|
|
347
|
-
}
|
|
348
|
-
return arr;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const get_all_scripts = async()=>{
|
|
353
|
-
const scripts = document.querySelectorAll('script');
|
|
354
|
-
const codePromises = [];
|
|
355
|
-
|
|
356
|
-
for (const script of scripts) {
|
|
357
|
-
if (script.src) {
|
|
358
|
-
codePromises.push(
|
|
359
|
-
fetch(script.src)
|
|
360
|
-
.then(r => r.ok ? r.text() : '')
|
|
361
|
-
.catch(() => '')
|
|
362
|
-
);
|
|
363
|
-
} else {
|
|
364
|
-
const inlineCode = script.textContent;
|
|
365
|
-
if (inlineCode.trim()) {
|
|
366
|
-
codePromises.push(Promise.resolve(inlineCode));
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const codes = await Promise.all(codePromises);
|
|
372
|
-
const allJsCode = codes.filter(code => code).join('\n\n');
|
|
373
|
-
|
|
374
|
-
return `<script>\n${allJsCode}\n</script>`;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const get_all_csses = async()=>{
|
|
378
|
-
let css = '';
|
|
379
|
-
for (const link of document.querySelectorAll('link[rel="stylesheet"]')) {
|
|
380
|
-
if (link.href) {
|
|
381
|
-
try {
|
|
382
|
-
css += await (await fetch(link.href)).text() + '\n';
|
|
383
|
-
} catch {}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
for (const style of document.querySelectorAll('style')) {
|
|
387
|
-
css += style.outerHtml + '\n';
|
|
388
|
-
}
|
|
389
|
-
return css;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
visit.rvisit = rvisit;
|
|
393
|
-
visit.get_depth = get_depth;
|
|
394
|
-
visit.get_ance = get_ance;
|
|
395
|
-
visit.get_rt = get_rt;
|
|
396
|
-
visit.is_topo_leaf = is_topo_leaf;
|
|
397
|
-
visit.get_dlmost = get_dlmost;
|
|
398
|
-
visit.get_drmost = get_drmost;
|
|
399
|
-
visit.find_rb_of_fst_ance_has_rb = find_rb_of_fst_ance_has_rb;
|
|
400
|
-
visit.find_lb_of_fst_ance_has_lb = find_lb_of_fst_ance_has_lb;
|
|
401
|
-
visit.editonly_sdfs_for_each = editonly_sdfs_for_each;
|
|
402
|
-
visit.editonly_rsdfs_for_each = editonly_rsdfs_for_each;
|
|
403
|
-
visit.editonly_edfs_for_each = editonly_edfs_for_each;
|
|
404
|
-
visit.editonly_redfs_for_each = editonly_redfs_for_each;
|
|
405
|
-
visit.filter = filter;
|
|
406
|
-
visit.get_all_csses = get_all_csses;
|
|
407
|
-
visit.get_all_scripts = get_all_scripts;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const {wait_for_layout_ready} = require("./wait");
|
|
411
|
-
|
|
412
|
-
const creat_rect_desc = () => ({
|
|
413
|
-
"x": 0,
|
|
414
|
-
"y": 0,
|
|
415
|
-
"width": 0,
|
|
416
|
-
"height": 0,
|
|
417
|
-
"top": 0,
|
|
418
|
-
"right": 0,
|
|
419
|
-
"bottom": 0,
|
|
420
|
-
"left": 0
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
const get_rect_desc_bfr_transfrom = async(el) => {
|
|
424
|
-
let rect_bfr_transfrom = creat_rect_desc();
|
|
425
|
-
// 方法:临时移除 transform 获取真实位置
|
|
426
|
-
// 保存原始 transform
|
|
427
|
-
const originalTransform = el.style.transform;
|
|
428
|
-
// 临时移除 transform(会触发一次 reflow)
|
|
429
|
-
el.style.transform = 'none';
|
|
430
|
-
await wait_for_layout_ready();
|
|
431
|
-
// 获取无 transform 的位置
|
|
432
|
-
const rect = el.getBoundingClientRect();
|
|
433
|
-
// 立即恢复 transform
|
|
434
|
-
el.style.transform = originalTransform;
|
|
435
|
-
// 复制所有值
|
|
436
|
-
rect_bfr_transfrom.x = rect.x;
|
|
437
|
-
rect_bfr_transfrom.y = rect.y;
|
|
438
|
-
rect_bfr_transfrom.width = rect.width;
|
|
439
|
-
rect_bfr_transfrom.height = rect.height;
|
|
440
|
-
rect_bfr_transfrom.top = rect.top;
|
|
441
|
-
rect_bfr_transfrom.left = rect.left;
|
|
442
|
-
rect_bfr_transfrom.right = rect.right;
|
|
443
|
-
rect_bfr_transfrom.bottom = rect.bottom;
|
|
444
|
-
return rect_bfr_transfrom;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
const get_all_positions_bfr_transform = async (
|
|
448
|
-
el,
|
|
449
|
-
filter = (el) => true
|
|
450
|
-
) => {
|
|
451
|
-
//使用editonly_sdfs_for_each 获取
|
|
452
|
-
//类似 .getBoundingClientRect()
|
|
453
|
-
let results = [];
|
|
454
|
-
await editonly_sdfs_for_each(el, async (curr_el) => {
|
|
455
|
-
if (filter(curr_el)) {
|
|
456
|
-
let rect_bfr_transfrom = await get_rect_desc_bfr_transfrom(curr_el);
|
|
457
|
-
results.push({
|
|
458
|
-
el: curr_el,
|
|
459
|
-
rect: rect_bfr_transfrom
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
return results;
|
|
465
|
-
}
|
|
466
|
-
const get_all_positions_aft_transform = async (
|
|
467
|
-
el,
|
|
468
|
-
filter = (el) => true
|
|
469
|
-
) => {
|
|
470
|
-
// 获取 transform 之后的最终位置
|
|
471
|
-
let results = [];
|
|
472
|
-
await editonly_sdfs_for_each(el, async (curr_el) => {
|
|
473
|
-
if (filter(curr_el)) {
|
|
474
|
-
await wait_for_layout_ready();
|
|
475
|
-
let rect_aft_transfrom = curr_el.getBoundingClientRect();
|
|
476
|
-
results.push({
|
|
477
|
-
el: curr_el,
|
|
478
|
-
rect: rect_aft_transfrom
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
return results;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
const get_all_positions_transform_diff = async(
|
|
487
|
-
el,
|
|
488
|
-
filter = (el) => true
|
|
489
|
-
) => {
|
|
490
|
-
// 计算 transform 前后的差异
|
|
491
|
-
let results = [];
|
|
492
|
-
await editonly_sdfs_for_each(el, async (curr_el) => {
|
|
493
|
-
if (filter(curr_el)) {
|
|
494
|
-
let rect_bfr_transfrom = await get_rect_desc_bfr_transfrom(curr_el);
|
|
495
|
-
await wait_for_layout_ready();//因为 get_rect_desc_bfr_transfrom 会改回去 transform,需要等待布局稳定
|
|
496
|
-
let rect_aft_transfrom = curr_el.getBoundingClientRect();
|
|
497
|
-
let rect_diff = {
|
|
498
|
-
x: rect_aft_transfrom.x - rect_bfr_transfrom.x,
|
|
499
|
-
y: rect_aft_transfrom.y - rect_bfr_transfrom.y,
|
|
500
|
-
width: rect_aft_transfrom.width - rect_bfr_transfrom.width,
|
|
501
|
-
height: rect_aft_transfrom.height - rect_bfr_transfrom.height,
|
|
502
|
-
top: rect_aft_transfrom.top - rect_bfr_transfrom.top,
|
|
503
|
-
right: rect_aft_transfrom.right - rect_bfr_transfrom.right,
|
|
504
|
-
bottom: rect_aft_transfrom.bottom - rect_bfr_transfrom.bottom,
|
|
505
|
-
left: rect_aft_transfrom.left - rect_bfr_transfrom.left
|
|
506
|
-
};
|
|
507
|
-
if (rect_diff.x === 0 && rect_diff.y === 0 &&
|
|
508
|
-
rect_diff.width === 0 && rect_diff.height === 0 &&
|
|
509
|
-
rect_diff.top === 0 && rect_diff.right === 0 &&
|
|
510
|
-
rect_diff.bottom === 0 && rect_diff.left === 0) {
|
|
511
|
-
} else {
|
|
512
|
-
results.push({
|
|
513
|
-
el: curr_el,
|
|
514
|
-
rect: rect_diff
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
return results;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
visit.creat_rect_desc = creat_rect_desc;
|
|
525
|
-
visit.get_rect_desc_bfr_transfrom = get_rect_desc_bfr_transfrom;
|
|
526
|
-
visit.get_all_positions_bfr_transform = get_all_positions_bfr_transform;
|
|
527
|
-
visit.get_all_positions_aft_transform = get_all_positions_aft_transform;
|
|
528
|
-
visit.get_all_positions_transform_diff = get_all_positions_transform_diff;
|
|
529
|
-
|
|
530
|
-
const is_rect_overlapping = (rect1, rect2) => {
|
|
531
|
-
return !(rect1.right < rect2.left ||
|
|
532
|
-
rect1.left > rect2.right ||
|
|
533
|
-
rect1.bottom < rect2.top ||
|
|
534
|
-
rect1.top > rect2.bottom);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const is_ele_overlapping_with_eles = (checkEle, eleList) => {
|
|
538
|
-
let isOverlapping = false;
|
|
539
|
-
for (const element of eleList) {
|
|
540
|
-
const elementRect = element.getBoundingClientRect();
|
|
541
|
-
// 检查元素是否与标题重叠
|
|
542
|
-
if (is_rect_overlapping(elementRect, checkEle.getBoundingClientRect())) {
|
|
543
|
-
isOverlapping = true;
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return isOverlapping;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
visit.is_rect_overlapping = is_rect_overlapping;
|
|
551
|
-
visit.is_ele_overlapping_with_eles = is_ele_overlapping_with_eles;
|
|
552
|
-
|
|
553
|
-
|
|
1
|
+
const _ison = require("nvison-bw");
|
|
2
|
+
const _util = require("./util");
|
|
3
|
+
const _nd = require("./nd");
|
|
4
|
+
const _ele = require("./ele");
|
|
554
5
|
const _attr = require("./attr");
|
|
555
6
|
const _wait = require("./wait");
|
|
556
7
|
const _ele_getter = require("./ele-getter");
|
|
557
8
|
const _cls_accessor = require("./cls-accessor");
|
|
9
|
+
const _limit = require("./limit");
|
|
10
|
+
const _code = require("./code");
|
|
558
11
|
const _ui = require("./ui");
|
|
12
|
+
const _dnld = require("./dnld");
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
_ison,
|
|
16
|
+
_util,
|
|
17
|
+
_nd,
|
|
18
|
+
_ele,
|
|
19
|
+
_attr,
|
|
20
|
+
_wait,
|
|
21
|
+
_ele_getter,_cls_accessor,
|
|
22
|
+
_limit,
|
|
23
|
+
_code,
|
|
24
|
+
_ui,
|
|
25
|
+
_dnld
|
|
26
|
+
}
|
|
559
27
|
|
|
560
|
-
visit._attr = _attr;
|
|
561
|
-
visit._wait = _wait;
|
|
562
|
-
visit._ele_getter = _ele_getter;
|
|
563
|
-
visit._cls_accessor = _cls_accessor;
|
|
564
|
-
visit._ui = _ui;
|
|
565
|
-
|
|
566
|
-
const _nvison = require("nvison");
|
|
567
|
-
|
|
568
|
-
module.exports = visit;
|
|
569
|
-
|
|
570
|
-
/*
|
|
571
|
-
visit(
|
|
572
|
-
document,
|
|
573
|
-
(el,rel_depth)=>{
|
|
574
|
-
let t = el.nodeType;
|
|
575
|
-
switch(t) {
|
|
576
|
-
case document.ELEMENT_NODE :{console.log(" ".repeat(rel_depth)+"</"+el.tagName.toLowerCase()+">");break;}
|
|
577
|
-
case document.TEXT_NODE :{console.log(" ".repeat(rel_depth)+el.textContent);break;}
|
|
578
|
-
case document.COMMENT_NODE :{console.log(" ".repeat(rel_depth)+"<!--" +el.data + "-->");break;}
|
|
579
|
-
case document.ATTRIBUTE_NODE: {break;}
|
|
580
|
-
case document.CDATA_SECTION_NODE : {break;}
|
|
581
|
-
case document.ENTITY_REFERENCE_NODE: {break;}
|
|
582
|
-
case document.ENTITY_NODE : {break;}
|
|
583
|
-
case document.PROCESSING_INSTRUCTION_NODE: {break;}
|
|
584
|
-
case document.DOCUMENT_NODE: {break;}
|
|
585
|
-
case document.DOCUMENT_TYPE_NODE: {break;}
|
|
586
|
-
case document.DOCUMENT_FRAGMENT_NODE: {break;}
|
|
587
|
-
case document.NOTATION_NODE : {break;}
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
(el,rel_depth)=>{
|
|
591
|
-
let t = el.nodeType;
|
|
592
|
-
switch(t) {
|
|
593
|
-
case document.ELEMENT_NODE :{
|
|
594
|
-
console.log(" ".repeat(rel_depth)+"<"+el.tagName.toLowerCase()+">");break;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
},
|
|
598
|
-
)
|
|
599
|
-
*/
|
package/limit.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
class MxWhCtx {
|
|
2
|
+
css = `
|
|
3
|
+
position: fixed;
|
|
4
|
+
top: 0;
|
|
5
|
+
left: 0;
|
|
6
|
+
visibility: hidden;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
border: none;
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
is_ok(ele, dimension, val) {
|
|
15
|
+
ele.style[dimension] = `${val}px`;
|
|
16
|
+
const rect = ele.getBoundingClientRect();
|
|
17
|
+
return rect[dimension] === val;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
find_upbound(ele, dimension) {
|
|
21
|
+
let upper = 1;
|
|
22
|
+
while(true) {
|
|
23
|
+
if(this.is_ok(ele, dimension, upper)) {
|
|
24
|
+
upper *= 2;
|
|
25
|
+
} else {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return upper;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
mx(ele, dimension) {
|
|
33
|
+
ele.style.cssText = this.css;
|
|
34
|
+
document.body.appendChild(ele);
|
|
35
|
+
|
|
36
|
+
// 找到上界
|
|
37
|
+
let upper = this.find_upbound(ele, dimension);
|
|
38
|
+
let lower = Math.floor(upper / 2);
|
|
39
|
+
|
|
40
|
+
// 二分法查找精确的最大值
|
|
41
|
+
while (lower + 1 < upper) {
|
|
42
|
+
const mid = Math.floor((lower + upper) / 2);
|
|
43
|
+
if (this.is_ok(ele, dimension, mid)) {
|
|
44
|
+
lower = mid; // 成功,向右搜索
|
|
45
|
+
} else {
|
|
46
|
+
upper = mid; // 失败,向左搜索
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
document.body.removeChild(ele);
|
|
51
|
+
return lower;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 主函数
|
|
56
|
+
const find_mx_wh = () => {
|
|
57
|
+
let ele = document.createElement('div');
|
|
58
|
+
let ctx = new MxWhCtx();
|
|
59
|
+
let w = ctx.mx(ele, "width");
|
|
60
|
+
let h = ctx.mx(ele, "height");
|
|
61
|
+
return [w, h];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const creat_mxw_ele = (tag,height)=>{
|
|
66
|
+
let [w,h] = find_mx_wh();
|
|
67
|
+
let ele = document.createElement(tag);
|
|
68
|
+
ele.style.width = `${w}px`;
|
|
69
|
+
ele.style.height = `${height}px`;
|
|
70
|
+
return ele;
|
|
71
|
+
}
|
|
72
|
+
const creat_mxh_ele = (tag,width)=>{
|
|
73
|
+
let [w,h] = find_mx_wh();
|
|
74
|
+
let ele = document.createElement(tag);
|
|
75
|
+
ele.style.width = `${width}px`;
|
|
76
|
+
ele.style.height = `${h}px`;
|
|
77
|
+
return ele;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const creat_mxwh_ele = (tag)=>{
|
|
81
|
+
let [w,h] = find_mx_wh();
|
|
82
|
+
let ele = document.createElement(tag);
|
|
83
|
+
ele.style.width = `${w}px`;
|
|
84
|
+
ele.style.height = `${h}px`;
|
|
85
|
+
return ele;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const calc_mx_cnt = (item_sz,dimension="height")=>{
|
|
89
|
+
let [w,h] = find_mx_wh();
|
|
90
|
+
if(dimension === "height") {
|
|
91
|
+
return Math.floor(w/item_sz);
|
|
92
|
+
} else {
|
|
93
|
+
return Math.floor(w/item_sz);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = {
|
|
98
|
+
find_mx_wh,
|
|
99
|
+
creat_mxw_ele,
|
|
100
|
+
creat_mxh_ele,
|
|
101
|
+
creat_mxwh_ele,
|
|
102
|
+
calc_mx_cnt
|
|
103
|
+
}
|