nv-basic-bw 1.0.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.
@@ -0,0 +1,7 @@
1
+ var nvbasicbw=(()=>{var N=(e,l)=>()=>(l||e((l={exports:{}}).exports,l),l.exports);var F=N(($,k)=>{var d=e=>e.constructor.name==="AsyncFunction",S=e=>{let l=0;for(;e&&e.parentNode;)e=e.parentNode,l++;return l},x=(e,l)=>{if(l>0){let r=1;for(;;){let t=e.parentNode;if(r===l)return t;e=t,++r}}else return e},C=e=>{for(;e.parentNode;)e=e.parentNode;return e},g=e=>{let l=0;for(;e.lastChild;)e=e.lastChild,++l;return[e,l]},y=e=>{let l=0;for(;;){let r=e.firstChild;if(r)++l,e=r;else return[e,l]}},b=(e,l)=>{if(e.nextSibling)return[e.nextSibling,l];let r=e.parentNode,t=l;for(;r;){if(t-=1,r.nextSibling)return[r.nextSibling,t];r=r.parentNode}return[null,-1]},w=async(e,l=(r,t)=>{})=>{let[r,t]=g(e),s=e,a=d(l),i=0;for(;;){let n=!1;if(a?n=await l(s,i):n=l(s,i),n||s===r)return;{let f=s.firstChild;if(f)++i,s=f;else{let _=b(s,i);if(s=_[0],s)i=_[1];else break}}}},m=(e,l)=>{if(e.prevSibling)return[e.prevSibling,l];let r=e.parentNode,t=l;for(;r;){if(t-=1,r.prevSibling)return[r.prevSibling,t];r=r.parentNode}return[null,-1]},v=async(e,l=(r,t)=>{})=>{let[r,t]=y(e),s=e,a=d(l),i=0;for(;;){let n=!1;if(a?n=await l(s,i):n=l(s,i),n||s===r)return;{let f=s.firstChild;if(f)++i,s=f;else{let _=m(s,i);if(s=_[0],s)i=_[1];else break}}}},A=async(e,l=(r,t)=>{})=>{let[r,t]=y(e),s=d(l);for(;;){let a=!1;if(s?a=await l(r,t):a=l(r,t),a||r===e)return;{let i=r.nextSibling;if(i){let n=y(i);t+=n[1],r=n[0]}else{let n=r.parentNode;if(n)--t,r=n;else break}}}},q=async(e,l=(r,t)=>{})=>{let[r,t]=g(e),s=d(l);for(;;){let a=!1;if(s?a=await l(r,t):a=l(r,t),a||r===e)return;{let i=r.prevSibling;if(i){let n=g(i);t+=n[1],r=n[0]}else{let n=r.parentNode;if(n)--t,r=n;else break}}}},o=async(e,l=(t,s)=>{},r=(t,s)=>{})=>{let t=e,s="open",a={open:[r,d(r)],clos:[l,d(l)]},i=0;for(;;){let n=!1,[f,_]=a[s];if(s==="open"){if(_?n=await f(t,i):n=f(t,i),n)return;{let c=t.firstChild;c?(t=c,++i):s="clos"}}else{let c,h,p,u=t.nextSibling;if(u?(p="open",c=u,h=i):(p="clos",c=t.parentNode,h=i-1),_?n=await f(t,i):n=f(t,i),n)return;if(t!==e)s=p,t=c,i=h;else break}}},P=async(e,l=(t,s)=>{},r=(t,s)=>{})=>{let t=e,s="open",a={open:[r,d(r)],clos:[l,d(l)]},i=0;for(;;){let n=!1,[f,_]=a[s];if(s==="open"){if(_?n=await f(t,i):n=f(t,i),n)return;{let c=t.lastChild;c?(t=c,++i):s="clos"}}else{let c,h,p,u=t.prevSibling;if(u?(p="open",c=u,h=i):(p="clos",c=t.parentNode,h=i-1),_?n=await f(t,i):n=f(t,i),n)return;if(t!==e)s=p,t=c,i=h;else break}}},J=async(e,l)=>{if(typeof l=="string"){let r=[];return await w(e,async(t,s)=>{(t.tagName?t.tagName.toLowerCase()===l.toLowerCase():!1)&&r.push(t)}),r}else{let r=[];return d(l)?await w(e,async(t,s)=>{await l(t,s)&&r.push(t)}):await w(e,async(t,s)=>{l(t,s)&&r.push(t)}),r}},L=async()=>{let e=document.querySelectorAll("script"),l=[];for(let s of e)if(s.src)l.push(fetch(s.src).then(a=>a.ok?a.text():"").catch(()=>""));else{let a=s.textContent;a.trim()&&l.push(Promise.resolve(a))}return`<script>
2
+ ${(await Promise.all(l)).filter(s=>s).join(`
3
+
4
+ `)}
5
+ <\/script>`},j=async()=>{let e="";for(let l of document.querySelectorAll('link[rel="stylesheet"]'))if(l.href)try{e+=await(await fetch(l.href)).text()+`
6
+ `}catch{}for(let l of document.querySelectorAll("style"))e+=l.outerHtml+`
7
+ `;return e};o.rvisit=P;o.get_depth=S;o.get_ance=x;o.get_rt=C;o.get_dlmost=y;o.get_drmost=g;o.find_rb_of_fst_ance_has_rb=b;o.find_lb_of_fst_ance_has_lb=m;o.editonly_sdfs_for_each=w;o.editonly_rsdfs_for_each=v;o.editonly_edfs_for_each=A;o.editonly_redfs_for_each=q;o.filter=J;o.get_all_csses=j;o.get_all_scripts=L;k.exports=o});return F();})();
package/com.sh ADDED
@@ -0,0 +1 @@
1
+ nv_cli_build -m -g nvbasicbw -i index.js -o ./DIST/nv-basci-bw.js
package/index.js ADDED
@@ -0,0 +1,444 @@
1
+ const is_async = (f)=>f.constructor.name === "AsyncFunction";
2
+
3
+ const get_depth = (node) => {
4
+ let depth = 0;
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
+ const get_drmost = (node) => {
38
+ let rel_depth = 0;
39
+ while (node.lastChild) {
40
+ node = node.lastChild;
41
+ ++rel_depth;
42
+ }
43
+ return [node,rel_depth];
44
+ };
45
+
46
+ const get_dlmost = (node)=>{
47
+ let rel_depth = 0;
48
+ while(true) {
49
+ let fc = node.firstChild;
50
+ if(fc) {
51
+ ++rel_depth;
52
+ node = fc;
53
+ } else {
54
+ return [node,rel_depth];
55
+ }
56
+ }
57
+ }
58
+
59
+ const find_rb_of_fst_ance_has_rb = (node, rel_depth) => {
60
+ // 1️⃣ 当前节点有 nextSibling
61
+ if (node.nextSibling) {
62
+ return [node.nextSibling, rel_depth];
63
+ }
64
+
65
+ // 2️⃣ 沿父节点向上查找
66
+ let current = node.parentNode;
67
+ let depth = rel_depth;
68
+
69
+ while (current) {
70
+ depth -= 1; // 向上走一层
71
+
72
+ if (current.nextSibling) {
73
+ return [current.nextSibling, depth];
74
+ }
75
+
76
+ current = current.parentNode;
77
+ }
78
+
79
+ // 3️⃣ 已到根节点,仍然没有
80
+ return [null,-1];
81
+ };
82
+
83
+ const editonly_sdfs_for_each = async(rt,cb=(el,rel_depth)=>{})=> {
84
+ let [drmost,ignore] = get_drmost(rt)
85
+ let curr = rt;
86
+ let should_await = is_async(cb);
87
+ let rel_depth =0;
88
+ while(true) {
89
+ let should_break = false;
90
+ if(should_await) {
91
+ should_break = await cb(curr,rel_depth);
92
+ } else {
93
+ should_break = cb(curr,rel_depth);
94
+ }
95
+ if(should_break||curr=== drmost) {return;} else {
96
+ let fc = curr.firstChild;
97
+ if(fc) {
98
+ ++rel_depth;
99
+ curr = fc
100
+ } else {
101
+ let pair = find_rb_of_fst_ance_has_rb(curr,rel_depth);
102
+ curr = pair[0];
103
+ if(curr) {
104
+ rel_depth = pair[1];
105
+ } else {
106
+ break;
107
+ }
108
+ }
109
+
110
+ }
111
+ }
112
+ }
113
+
114
+ const find_lb_of_fst_ance_has_lb = (node, rel_depth) => {
115
+ // 1️⃣ 当前节点有 nextSibling
116
+ if (node.prevSibling) {
117
+ return [node.prevSibling, rel_depth];
118
+ }
119
+
120
+ // 2️⃣ 沿父节点向上查找
121
+ let current = node.parentNode;
122
+ let depth = rel_depth;
123
+
124
+ while (current) {
125
+ depth -= 1; // 向上走一层
126
+
127
+ if (current.prevSibling) {
128
+ return [current.prevSibling, depth];
129
+ }
130
+
131
+ current = current.parentNode;
132
+ }
133
+
134
+ // 3️⃣ 已到根节点,仍然没有
135
+ return [null,-1];
136
+ };
137
+
138
+ const editonly_rsdfs_for_each = async(rt,cb=(el,rel_depth)=>{})=> {
139
+ let [dlmost,ignore] = get_dlmost(rt)
140
+ let curr = rt;
141
+ let should_await = is_async(cb);
142
+ let rel_depth =0;
143
+ while(true) {
144
+ let should_break = false;
145
+ if(should_await) {
146
+ should_break = await cb(curr,rel_depth);
147
+ } else {
148
+ should_break = cb(curr,rel_depth);
149
+ }
150
+ if(should_break||curr=== dlmost) {return;} else {
151
+ let lc = curr.firstChild;
152
+ if(lc) {
153
+ ++rel_depth;
154
+ curr = lc
155
+ } else {
156
+ let pair = find_lb_of_fst_ance_has_lb(curr,rel_depth);
157
+ curr = pair[0];
158
+ if(curr) {
159
+ rel_depth = pair[1];
160
+ } else {
161
+ break;
162
+ }
163
+ }
164
+
165
+ }
166
+ }
167
+ }
168
+
169
+ const editonly_edfs_for_each = async(rt,cb=(el,rel_depth)=>{})=> {
170
+ let [curr,rel_depth] = get_dlmost(rt)
171
+ let should_await = is_async(cb);
172
+ while(true) {
173
+ let should_break = false;
174
+ if(should_await) {
175
+ should_break = await cb(curr,rel_depth);
176
+ } else {
177
+ should_break = cb(curr,rel_depth);
178
+ }
179
+ if(should_break|| curr === rt) {return;} else {
180
+ let rb = curr.nextSibling;
181
+ if(rb) {
182
+ let pair = get_dlmost(rb);
183
+ rel_depth+= pair[1];
184
+ curr = pair[0];
185
+ } else {
186
+ let pr = curr.parentNode;
187
+ if(pr) {
188
+ --rel_depth;
189
+ curr = pr;
190
+ } else {
191
+ break;
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ const editonly_redfs_for_each = async(rt,cb=(el,rel_depth)=>{})=> {
199
+ let [curr,rel_depth] = get_drmost(rt)
200
+ let should_await = is_async(cb);
201
+ while(true) {
202
+ let should_break = false;
203
+ if(should_await) {
204
+ should_break = await cb(curr,rel_depth);
205
+ } else {
206
+ should_break = cb(curr,rel_depth);
207
+ }
208
+ if(should_break || curr === rt) {return;} else {
209
+ let lb = curr.prevSibling;
210
+ if(lb) {
211
+ let pair = get_drmost(lb);
212
+ rel_depth+= pair[1];
213
+ curr = pair[0];
214
+ } else {
215
+ let pr = curr.parentNode;
216
+ if(pr) {
217
+ --rel_depth;
218
+ curr = pr;
219
+ } else {
220
+ break;
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ const visit = async(
228
+ rt,
229
+ exit_cb = (el,rel_depth)=>{},
230
+ enter_cb = (el,rel_depth)=>{},
231
+ ) => {
232
+ let curr = rt;
233
+ let state = "open";
234
+ let cbs = {
235
+ "open": [enter_cb, is_async(enter_cb)],
236
+ "clos": [exit_cb, is_async(exit_cb) ]
237
+ };
238
+ let rel_depth = 0;
239
+ while(true) {
240
+ let should_break = false;
241
+ let [cb,should_await] = cbs[state];
242
+ if(state === "open") {
243
+ // open 状态 先执行用户回调
244
+ if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
245
+ // 然后再取下一个节点: 用户回调如果修改了树结构,拿到的是修改后的
246
+ if(should_break) {return;} else {
247
+ let fc = curr.firstChild;
248
+ if(fc) {
249
+ curr=fc; ++rel_depth;
250
+ } else {
251
+ state = "clos";
252
+ }
253
+ }
254
+ } else {
255
+ //事先拿出nxt,因为用户可能改变树结构
256
+ let nxt;
257
+ let nxt_rel_depth;
258
+ let nxt_state;
259
+ let rb = curr.nextSibling;
260
+ if(rb) {
261
+ nxt_state = "open";
262
+ nxt = rb;
263
+ nxt_rel_depth = rel_depth;
264
+ } else {
265
+ nxt_state = "clos";
266
+ nxt = curr.parentNode;
267
+ nxt_rel_depth = rel_depth -1;
268
+ }
269
+ if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
270
+ if(should_break) {return;} else {
271
+ if(curr !== rt) {
272
+ state = nxt_state;curr = nxt;rel_depth = nxt_rel_depth;
273
+ } else {
274
+ break;
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+
281
+
282
+ const rvisit = async(
283
+ rt,
284
+ exit_cb = (el,rel_depth)=>{},
285
+ enter_cb = (el,rel_depth)=>{},
286
+ ) => {
287
+ let curr = rt;
288
+ let state = "open";
289
+ let cbs = {
290
+ "open": [enter_cb, is_async(enter_cb)],
291
+ "clos": [exit_cb, is_async(exit_cb) ]
292
+ };
293
+ let rel_depth = 0;
294
+ while(true) {
295
+ let should_break = false;
296
+ let [cb,should_await] = cbs[state];
297
+ if(state === "open") {
298
+ // open 状态 先执行用户回调
299
+ if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
300
+ // 然后再取下一个节点: 用户回调如果修改了树结构,拿到的是修改后的
301
+ if(should_break) {return;} else {
302
+ let lc = curr.lastChild;
303
+ if(lc) {
304
+ curr=lc; ++rel_depth;
305
+ } else {
306
+ state = "clos";
307
+ }
308
+ }
309
+ } else {
310
+ //事先拿出nxt,因为用户可能改变树结构
311
+ let nxt;
312
+ let nxt_rel_depth;
313
+ let nxt_state;
314
+ let lb = curr.prevSibling;
315
+ if(lb) {
316
+ nxt_state = "open";
317
+ nxt = lb;
318
+ nxt_rel_depth = rel_depth;
319
+ } else {
320
+ nxt_state = "clos";
321
+ nxt = curr.parentNode;
322
+ nxt_rel_depth = rel_depth -1;
323
+ }
324
+ if(should_await) {should_break = await cb(curr,rel_depth);} else{should_break = cb(curr,rel_depth);}
325
+ if(should_break) {return;} else {
326
+ if(curr !== rt) {
327
+ state = nxt_state;curr = nxt;rel_depth = nxt_rel_depth;
328
+ } else {
329
+ break;
330
+ }
331
+ }
332
+ }
333
+ }
334
+ }
335
+
336
+ const filter = async(rt,o)=>{
337
+ if(typeof(o)==="string") {
338
+ let arr =[];
339
+ await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{
340
+ let cond = el.tagName? (el.tagName.toLowerCase()===o.toLowerCase()):false;
341
+ if(cond){arr.push(el)}
342
+ });
343
+ return arr;
344
+ } else {
345
+ let arr = [];
346
+ if(is_async(o)) {
347
+ await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{let cond = await o(el,rel_depth);if(cond){arr.push(el)}});
348
+ } else {
349
+ await editonly_sdfs_for_each(rt,async (el,rel_depth)=>{let cond = o(el,rel_depth);if(cond){arr.push(el)}});
350
+ }
351
+ return arr;
352
+ }
353
+ }
354
+
355
+ const get_all_scripts = async()=>{
356
+ const scripts = document.querySelectorAll('script');
357
+ const codePromises = [];
358
+
359
+ for (const script of scripts) {
360
+ if (script.src) {
361
+ codePromises.push(
362
+ fetch(script.src)
363
+ .then(r => r.ok ? r.text() : '')
364
+ .catch(() => '')
365
+ );
366
+ } else {
367
+ const inlineCode = script.textContent;
368
+ if (inlineCode.trim()) {
369
+ codePromises.push(Promise.resolve(inlineCode));
370
+ }
371
+ }
372
+ }
373
+
374
+ const codes = await Promise.all(codePromises);
375
+ const allJsCode = codes.filter(code => code).join('\n\n');
376
+
377
+ return `<script>\n${allJsCode}\n</script>`;
378
+ }
379
+
380
+ const get_all_csses = async()=>{
381
+ let css = '';
382
+ for (const link of document.querySelectorAll('link[rel="stylesheet"]')) {
383
+ if (link.href) {
384
+ try {
385
+ css += await (await fetch(link.href)).text() + '\n';
386
+ } catch {}
387
+ }
388
+ }
389
+ for (const style of document.querySelectorAll('style')) {
390
+ css += style.outerHtml + '\n';
391
+ }
392
+ return css;
393
+ }
394
+
395
+ visit.rvisit = rvisit;
396
+ visit.get_depth = get_depth;
397
+ visit.get_ance = get_ance;
398
+ visit.get_rt = get_rt;
399
+ visit.get_dlmost = get_dlmost;
400
+ visit.get_drmost = get_drmost;
401
+ visit.find_rb_of_fst_ance_has_rb = find_rb_of_fst_ance_has_rb;
402
+ visit.find_lb_of_fst_ance_has_lb = find_lb_of_fst_ance_has_lb;
403
+ visit.editonly_sdfs_for_each = editonly_sdfs_for_each;
404
+ visit.editonly_rsdfs_for_each = editonly_rsdfs_for_each;
405
+ visit.editonly_edfs_for_each = editonly_edfs_for_each;
406
+ visit.editonly_redfs_for_each = editonly_redfs_for_each;
407
+ visit.filter = filter;
408
+ visit.get_all_csses = get_all_csses;
409
+ visit.get_all_scripts = get_all_scripts;
410
+
411
+
412
+
413
+ module.exports = visit;
414
+
415
+ /*
416
+ visit(
417
+ document,
418
+ (el,rel_depth)=>{
419
+ let t = el.nodeType;
420
+ switch(t) {
421
+ case document.ELEMENT_NODE :{console.log(" ".repeat(rel_depth)+"</"+el.tagName.toLowerCase()+">");break;}
422
+ case document.TEXT_NODE :{console.log(" ".repeat(rel_depth)+el.textContent);break;}
423
+ case document.COMMENT_NODE :{console.log(" ".repeat(rel_depth)+"<!--" +el.data + "-->");break;}
424
+ case document.ATTRIBUTE_NODE: {break;}
425
+ case document.CDATA_SECTION_NODE : {break;}
426
+ case document.ENTITY_REFERENCE_NODE: {break;}
427
+ case document.ENTITY_NODE : {break;}
428
+ case document.PROCESSING_INSTRUCTION_NODE: {break;}
429
+ case document.DOCUMENT_NODE: {break;}
430
+ case document.DOCUMENT_TYPE_NODE: {break;}
431
+ case document.DOCUMENT_FRAGMENT_NODE: {break;}
432
+ case document.NOTATION_NODE : {break;}
433
+ }
434
+ },
435
+ (el,rel_depth)=>{
436
+ let t = el.nodeType;
437
+ switch(t) {
438
+ case document.ELEMENT_NODE :{
439
+ console.log(" ".repeat(rel_depth)+"<"+el.tagName.toLowerCase()+">");break;
440
+ }
441
+ }
442
+ },
443
+ )
444
+ */
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "nv-basic-bw",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "author": "",
9
+ "license": "ISC",
10
+ "description": ""
11
+ }