|
1 | 1 |
|
2 | 2 |
|
3 | | -<output-console> |
| 3 | +<output-console v2.0> |
4 | 4 |
|
5 | 5 | <template shadowrootmode=open> |
6 | 6 |
|
|
53 | 53 |
|
54 | 54 | <script> |
55 | 55 |
|
56 | | -(function output_console({mod,dom,node}){ |
| 56 | +(function output_console({mod,dom,host}){ |
57 | 57 | //console.log('output'); |
58 | 58 | var obj = { |
59 | 59 | version : 'v2.0', |
|
85 | 85 | var shadow; |
86 | 86 |
|
87 | 87 | var output; |
| 88 | + var cur = {}; |
| 89 | + |
88 | 90 | var iframe; |
| 91 | + obj.iframe; |
89 | 92 |
|
90 | 93 |
|
91 | 94 |
|
|
98 | 101 |
|
99 | 102 | obj.init = async function(){ |
100 | 103 |
|
101 | | - libs(); |
| 104 | + await libs(); |
102 | 105 |
|
103 | 106 | }//init |
104 | 107 |
|
105 | 108 |
|
106 | 109 | async function libs(){ |
107 | 110 |
|
108 | 111 | [inspect] = await ext.load.libs('js/string/inspect.js'); |
| 112 | + console.log(inspect); |
109 | 113 |
|
110 | 114 | }//libs |
111 | 115 |
|
|
115 | 119 |
|
116 | 120 | obj.initdom = function(rootnode){ |
117 | 121 |
|
118 | | - shadow = node.shadowRoot; |
| 122 | + shadow = host.shadowRoot; |
119 | 123 |
|
120 | 124 | chk.persist = $.chkbox(shadow,'#console-persist',false); |
121 | 125 | chk.log = $.chkbox(shadow,'#console-log',false); |
|
126 | 130 |
|
127 | 131 |
|
128 | 132 | output = $(shadow,'#output'); |
| 133 | + cur.root = output; |
129 | 134 |
|
130 | 135 |
|
131 | 136 | wrap(chk.wrap.checked); |
|
159 | 164 | }//wrap |
160 | 165 |
|
161 | 166 |
|
162 | | - obj.run = async function(js,params){ |
| 167 | + obj.run = async function(js,params={}){ |
163 | 168 | console.log('run'); |
164 | 169 | var sandbox = (()=>{ |
165 | 170 |
|
| 171 | + var console = {}; |
166 | 172 | console.log = log; |
167 | 173 | console.clear = clear; |
168 | 174 | console.error = error; |
| 175 | + console.write = write; |
169 | 176 |
|
170 | 177 |
|
171 | 178 | async function run(js){ |
|
198 | 205 | console.log(result); |
199 | 206 | } |
200 | 207 |
|
201 | | - console.log = con.log; |
202 | | - console.clear = con.clear; |
203 | | - console.error = con.error; |
| 208 | + //console.log = con.log; |
| 209 | + //console.clear = con.clear; |
| 210 | + //console.error = con.error; |
| 211 | + |
204 | 212 |
|
205 | 213 |
|
206 | 214 | }//run |
207 | 215 |
|
208 | 216 |
|
209 | | - obj.run.iframe = async function(js,params){ |
| 217 | + obj.run.iframe = async function(js,params={}){ |
210 | 218 | console.log('run.iframe'); |
211 | 219 | var resolve,promise=new Promise(res=>resolve=res); |
212 | 220 |
|
|
215 | 223 | } |
216 | 224 |
|
217 | 225 | iframe = document.createElement('iframe'); |
| 226 | + obj.iframe = iframe; |
218 | 227 | iframe.srcdoc = ''; |
219 | 228 | iframe.onload = onload; |
220 | 229 | root.append(iframe); |
|
229 | 238 | win.console.log = log; |
230 | 239 | win.console.clear = clear; |
231 | 240 | win.console.error = error; |
| 241 | + win.console.write = write; |
232 | 242 |
|
233 | 243 | if(!chk.persist){ |
234 | 244 | clear(); |
|
258 | 268 |
|
259 | 269 |
|
260 | 270 |
|
| 271 | + obj.set = function(root){ |
| 272 | + |
| 273 | + if(root){ |
| 274 | + cur.root = root; |
| 275 | + }else{ |
| 276 | + cur.root = output; |
| 277 | + } |
| 278 | + |
| 279 | + }//set |
| 280 | + |
| 281 | + |
261 | 282 | //: |
262 | 283 |
|
263 | 284 |
|
|
270 | 291 | con.clear.call(window.console); |
271 | 292 | } |
272 | 293 |
|
273 | | - output.replaceChildren(); |
| 294 | + cur.root.replaceChildren(); |
274 | 295 |
|
275 | 296 | }//clear |
276 | 297 |
|
|
283 | 304 | con.log.apply(window.console,arguments); |
284 | 305 | } |
285 | 306 |
|
286 | | - var str = ''; |
287 | | - var args = [...arguments]; |
288 | | - args = args.map(v=>{ |
289 | | - |
290 | | - var type = datatype(v); |
291 | | - switch(type){ |
292 | | - |
293 | | - case 'function' : |
294 | | - case 'asyncfunction' : str = v.toString(); break; |
295 | | - case 'string' : str = v; break; |
296 | | - default : str = inspect(v); break; |
297 | | - |
298 | | - }//switch |
299 | | - return str; |
300 | | - |
301 | | - }); |
302 | | - |
303 | | - var txt = args.join(' '); |
| 307 | + var txt = build(arguments); |
304 | 308 | var div = document.createElement('div'); |
305 | 309 | div.textContent = txt; |
306 | | - output.append(div); |
| 310 | + cur.root.append(div); |
| 311 | + |
| 312 | + cur.node = div; |
| 313 | + |
| 314 | + if(txt==''){ |
| 315 | + div.style.height = '16px'; |
| 316 | + } |
307 | 317 |
|
308 | | - output.scrollTop = 999999999; |
| 318 | + cur.root.scrollTop = 999999999; |
309 | 319 |
|
310 | 320 | return div; |
311 | 321 |
|
|
328 | 338 |
|
329 | 339 |
|
330 | 340 |
|
| 341 | + obj.node = function(){return node.apply(null,arguments)} |
| 342 | + |
| 343 | + function node(node){ |
| 344 | + |
| 345 | + node = create(node); |
| 346 | + |
| 347 | + cur.root.append(node); |
| 348 | + |
| 349 | + return node; |
| 350 | + |
| 351 | + }//node |
| 352 | + |
| 353 | + |
| 354 | + |
| 355 | + obj.write = function(){return write.apply(null,arguments)} |
| 356 | + |
| 357 | + function write(){ |
| 358 | + |
| 359 | + var txt = build(arguments); |
| 360 | + |
| 361 | + var span = document.createElement('span'); |
| 362 | + span.textContent = txt; |
| 363 | + |
| 364 | + if(cur.node){ |
| 365 | + cur.node.append(span); |
| 366 | + }else{ |
| 367 | + cur.root.append(span); |
| 368 | + } |
| 369 | + return span; |
| 370 | + |
| 371 | + }//write |
| 372 | + |
| 373 | + |
| 374 | + //: |
| 375 | + |
| 376 | + |
| 377 | + function build(args){ |
| 378 | + |
| 379 | + var str = ''; |
| 380 | + var args = [...args]; |
| 381 | + args = args.map(v=>{ |
| 382 | + |
| 383 | + var type = datatype(v); |
| 384 | + switch(type){ |
| 385 | + |
| 386 | + case 'function' : |
| 387 | + case 'asyncfunction' : str = v.toString(); break; |
| 388 | + case 'string' : str = v; break; |
| 389 | + default : str = inspect(v); break; |
| 390 | + |
| 391 | + }//switch |
| 392 | + return str; |
| 393 | + |
| 394 | + }); |
| 395 | + |
| 396 | + var txt = args.join(' '); |
| 397 | + return txt; |
| 398 | + |
| 399 | + }//build |
| 400 | + |
| 401 | + |
| 402 | + function create(node){ |
| 403 | + |
| 404 | + var type = datatype(node); |
| 405 | + switch(type){ |
| 406 | + |
| 407 | + case 'string' : node = create.string(node); break; |
| 408 | + |
| 409 | + }//switch |
| 410 | + return node; |
| 411 | + |
| 412 | + }//create |
| 413 | + |
| 414 | + |
| 415 | + create.string = function(str){ |
| 416 | + |
| 417 | + var node = document.createElement(str); |
| 418 | + return node; |
| 419 | + |
| 420 | + }//string |
| 421 | + |
| 422 | + |
| 423 | + |
331 | 424 |
|
332 | 425 |
|
333 | 426 | return obj; |
|
0 commit comments