|
5 | 5 | <template shadowrootmode=open> |
6 | 6 |
|
7 | 7 | <style> |
8 | | - |
| 8 | + |
9 | 9 | :host |
10 | 10 | {font-family:arial} |
11 | | - |
| 11 | + |
12 | 12 | #root |
13 | 13 | {height:100%;display:flex;flex-direction:column} |
14 | 14 | #hdr |
15 | 15 | {display:flex;align-items:center;margin:0;margin-bottom:5px} |
16 | | - |
| 16 | + |
17 | 17 | #spc |
18 | 18 | {flex:1} |
19 | | - |
| 19 | + |
20 | 20 | .ext-button |
21 | 21 | {border:1px solid lightgray;padding:2px 5px;cursor:pointer;display:flex;align-items:center;margin-right:10px} |
22 | 22 | .ext-button [type=checkbox] |
23 | 23 | {margin:0;margin-left:5px;cursor:pointer} |
24 | | - |
| 24 | + |
25 | 25 | button |
26 | 26 | {font-size:16px;margin-right:10px} |
27 | | - |
| 27 | + |
28 | 28 | #output |
29 | 29 | {flex:1; |
30 | 30 | overflow:auto;border:2px solid lightgray;box-sizing:border-box; |
31 | 31 | padding:10px;margin:0; |
32 | 32 | word-break:break-all; |
33 | 33 | font-size:16px;line-height:1.5; |
34 | 34 | } |
35 | | - |
| 35 | + |
36 | 36 | </style> |
37 | 37 |
|
38 | 38 | <div id=root> |
|
58 | 58 | var obj = { |
59 | 59 | version : 'v2.0', |
60 | 60 | }; |
61 | | - |
62 | | - |
| 61 | + |
| 62 | + |
63 | 63 | var ext,$ |
64 | 64 | ; |
65 | 65 |
|
66 | 66 | obj.initmod = function(params){ |
67 | | - |
| 67 | + |
68 | 68 | ext = params.ext; |
69 | 69 | $ = params.$; |
70 | 70 |
|
71 | 71 | }//initmod |
72 | 72 |
|
73 | 73 |
|
74 | 74 | //vars:- |
75 | | - |
76 | | - var inspect; |
77 | 75 |
|
| 76 | + var inspect; |
| 77 | + |
78 | 78 | var con = {}; |
79 | 79 | con.log = console.log; |
80 | 80 | con.clear = console.clear; |
|
89 | 89 |
|
90 | 90 | var iframe; |
91 | 91 | obj.iframe; |
92 | | - |
93 | | - |
| 92 | + |
| 93 | + |
94 | 94 |
|
95 | 95 | var chk = {}; |
96 | 96 | var btn = {}; |
97 | | - |
| 97 | + |
98 | 98 |
|
99 | 99 | //: |
100 | | - |
| 100 | + |
101 | 101 |
|
102 | 102 | obj.init = async function(){ |
103 | 103 |
|
104 | 104 | await libs(); |
105 | 105 |
|
106 | 106 | }//init |
107 | | - |
108 | | - |
| 107 | + |
| 108 | + |
109 | 109 | async function libs(){ |
110 | | - |
| 110 | + |
111 | 111 | [inspect] = await ext.load.libs('js/string/inspect.js'); |
112 | 112 | console.log(inspect); |
113 | 113 |
|
114 | 114 | }//libs |
115 | | - |
| 115 | + |
116 | 116 |
|
117 | 117 | //: |
118 | | - |
| 118 | + |
119 | 119 |
|
120 | 120 | obj.initdom = function(rootnode){ |
121 | 121 |
|
|
131 | 131 |
|
132 | 132 | output = $(shadow,'#output'); |
133 | 133 | cur.root = output; |
134 | | - |
135 | | - |
| 134 | + |
| 135 | + |
136 | 136 | wrap(chk.wrap.checked); |
137 | | - |
| 137 | + |
138 | 138 |
|
139 | 139 | }//initdom |
140 | 140 |
|
141 | 141 |
|
142 | 142 | btn.kill = function(){ |
143 | | - |
| 143 | + |
144 | 144 | kill(); |
145 | 145 |
|
146 | 146 | }//kill |
147 | 147 |
|
148 | 148 |
|
149 | 149 | btn.clear = function(){ |
150 | | - |
| 150 | + |
151 | 151 | clear(); |
152 | 152 |
|
153 | 153 | }//clear |
|
162 | 162 | } |
163 | 163 |
|
164 | 164 | }//wrap |
165 | | - |
| 165 | + |
166 | 166 |
|
167 | 167 | obj.run = async function(js,params={}){ |
168 | 168 | console.log('run'); |
|
179 | 179 | console.groupEnd = window.console.groupEnd.bind(window.console); |
180 | 180 | console.trace = window.console.trace.bind(window.console); |
181 | 181 | console.info = window.console.info.bind(window.console); |
182 | | - |
| 182 | + |
183 | 183 |
|
184 | 184 | async function run(js){ |
185 | 185 |
|
|
202 | 202 |
|
203 | 203 |
|
204 | 204 | return run; |
205 | | - |
| 205 | + |
206 | 206 | })(); |
207 | 207 |
|
208 | 208 | var result = await sandbox(js); |
|
216 | 216 | //console.error = con.error; |
217 | 217 |
|
218 | 218 |
|
219 | | - |
| 219 | + |
220 | 220 | }//run |
221 | 221 |
|
222 | 222 |
|
|
238 | 238 |
|
239 | 239 |
|
240 | 240 | async function onload(){ |
241 | | - |
| 241 | + |
242 | 242 | setTimeout(complete,100); |
243 | 243 |
|
244 | 244 | }//onload |
245 | 245 |
|
246 | 246 | async function complete(){ |
247 | | - |
| 247 | + |
248 | 248 | var win = iframe.contentWindow; |
249 | 249 | win.focus(); |
250 | 250 | win.console.log = log; |
|
272 | 272 | obj.kill = function(){return kill()} |
273 | 273 |
|
274 | 274 | function kill(){ |
275 | | - |
| 275 | + |
276 | 276 | if(!iframe)return; |
277 | 277 | iframe.remove(); |
278 | 278 |
|
279 | 279 | }//kill |
280 | | - |
281 | | - |
282 | | - |
| 280 | + |
| 281 | + |
| 282 | + |
283 | 283 | obj.set = function(root){ |
284 | | - |
| 284 | + |
285 | 285 | if(root){ |
286 | 286 | cur.root = root; |
287 | 287 | }else{ |
|
290 | 290 |
|
291 | 291 | }//set |
292 | 292 |
|
293 | | - |
| 293 | + |
294 | 294 | //: |
295 | 295 |
|
296 | 296 |
|
297 | | - |
| 297 | + |
298 | 298 | obj.clear = function(){return clear()} |
299 | 299 |
|
300 | 300 | function clear(){ |
301 | | - |
| 301 | + |
302 | 302 | if(chk.log.checked){ |
303 | 303 | con.clear.call(window.console); |
304 | 304 | } |
|
311 | 311 | obj.log = function(){return log.apply(log,arguments)}; |
312 | 312 |
|
313 | 313 | function log(){ |
314 | | - |
| 314 | + |
315 | 315 | if(chk.log.checked){ |
316 | | - con.log.apply(window.console,arguments); |
| 316 | + //con.log.apply(window.console,arguments); |
| 317 | + window.console.groupCollapsed.apply(window.console,arguments); |
| 318 | + window.console.trace(); |
| 319 | + window.console.groupEnd(); |
317 | 320 | } |
318 | | - |
| 321 | + |
319 | 322 | var txt = build(arguments); |
320 | 323 | var div = document.createElement('div'); |
321 | 324 | div.textContent = txt; |
322 | 325 | cur.root.append(div); |
323 | 326 |
|
324 | 327 | cur.node = div; |
325 | | - |
| 328 | + |
326 | 329 | if(txt==''){ |
327 | 330 | div.style.height = '16px'; |
328 | 331 | } |
329 | 332 |
|
330 | 333 | cur.root.scrollTop = 999999999; |
331 | 334 |
|
332 | 335 | return div; |
333 | | - |
| 336 | + |
334 | 337 | }//log |
335 | | - |
336 | | - |
| 338 | + |
| 339 | + |
337 | 340 | obj.error = function(){return error.apply(null,arguments)} |
338 | 341 |
|
339 | 342 | function error(){ |
340 | | - |
| 343 | + |
341 | 344 | if(chk.log.checked){ |
342 | 345 | con.error.apply(window.console,arguments); |
343 | 346 | } |
|
353 | 356 | obj.node = function(){return node.apply(null,arguments)} |
354 | 357 |
|
355 | 358 | function node(node){ |
356 | | - |
| 359 | + |
357 | 360 | node = create(node); |
358 | 361 |
|
359 | 362 | cur.root.append(node); |
|
367 | 370 | obj.write = function(){return write.apply(null,arguments)} |
368 | 371 |
|
369 | 372 | function write(){ |
370 | | - |
| 373 | + |
371 | 374 | var txt = build(arguments); |
372 | 375 |
|
373 | 376 | var span = document.createElement('span'); |
|
382 | 385 |
|
383 | 386 | }//write |
384 | 387 |
|
385 | | - |
| 388 | + |
386 | 389 | //: |
387 | 390 |
|
388 | 391 |
|
389 | 392 | function build(args){ |
390 | | - |
| 393 | + |
391 | 394 | var str = ''; |
392 | 395 | var args = [...args]; |
393 | 396 | args = args.map(v=>{ |
|
407 | 410 |
|
408 | 411 | var txt = args.join(' '); |
409 | 412 | return txt; |
410 | | - |
| 413 | + |
411 | 414 | }//build |
412 | | - |
413 | | - |
| 415 | + |
| 416 | + |
414 | 417 | function create(node){ |
415 | | - |
| 418 | + |
416 | 419 | var type = datatype(node); |
417 | 420 | switch(type){ |
418 | | - |
| 421 | + |
419 | 422 | case 'string' : node = create.string(node); break; |
420 | 423 |
|
421 | 424 | }//switch |
422 | | - return node; |
| 425 | + return node; |
423 | 426 |
|
424 | 427 | }//create |
425 | 428 |
|
426 | 429 |
|
427 | 430 | create.string = function(str){ |
428 | | - |
| 431 | + |
429 | 432 | var node = document.createElement(str); |
430 | 433 | return node; |
431 | 434 |
|
|
436 | 439 |
|
437 | 440 |
|
438 | 441 | obj.horiz = function(){ |
439 | | - |
| 442 | + |
440 | 443 | host.style.width = '100%'; |
441 | 444 | host.style.height = '50%'; |
442 | 445 |
|
443 | 446 | }//horiz |
444 | 447 |
|
445 | 448 |
|
446 | 449 | obj.vert = function(){ |
447 | | - |
| 450 | + |
448 | 451 | host.style.width = '50%'; |
449 | 452 | host.style.height = '100%'; |
450 | 453 |
|
451 | 454 | }//vert |
452 | | - |
| 455 | + |
453 | 456 |
|
454 | 457 | //: |
455 | 458 |
|
|
458 | 461 | return obj; |
459 | 462 |
|
460 | 463 | })//output_console |
461 | | - |
| 464 | + |
462 | 465 | </script> |
463 | 466 |
|
464 | 467 | </output-console> |
|
0 commit comments