@@ -38,7 +38,7 @@ let app = {
38
38
href : 'https://michaelsboost.com/' ,
39
39
src : 'imgs/author.jpg'
40
40
} ,
41
- version : '1.2.2 ' ,
41
+ version : '1.2.3 ' ,
42
42
url : 'https://github.com/michaelsboost/kodeWeave/' ,
43
43
license : 'https://github.com/michaelsboost/kodeWeave/blob/main/LICENSE'
44
44
}
@@ -295,22 +295,24 @@ const icons = (function() {
295
295
} ) ( ) ;
296
296
297
297
// Reactive objects
298
- window . project = onChange ( p , ( property , oldValue , newValue ) => {
298
+ window . project = onChange ( p , async ( property , oldValue , newValue ) => {
299
299
const iframe = document . getElementById ( 'iframe' ) ;
300
- const doc = iframe . contentWindow . document ;
300
+ const doc = iframe ? iframe . contentWindow . document : null ;
301
301
if ( oldValue !== newValue ) {
302
302
localStorage . setItem ( 'kodeWeave' , JSON . stringify ( project ) ) ;
303
303
App . render ( '#app' ) ;
304
+
304
305
if ( property . toString ( ) === 'activePanel' ) {
305
306
getIFrameClientSize ( ) ;
306
307
if ( ! window . editorManager ) return ;
307
308
if ( project . activePanel === 'html' ) setActiveEditor ( editorManager . htmlEditor )
308
309
if ( project . activePanel === 'css' ) setActiveEditor ( editorManager . cssEditor )
309
310
if ( project . activePanel === 'javascript' ) setActiveEditor ( editorManager . javascriptEditor )
310
311
}
312
+
311
313
if ( ! App . initialRender ) {
312
314
let string = property . toString ( ) ;
313
- // diff nodes
315
+
314
316
if ( string === 'css' || string === 'console' ) {
315
317
let consoleCSS = `
316
318
[data-zwj=zwjkonsole] {
@@ -327,7 +329,7 @@ window.project = onChange(p, (property, oldValue, newValue) => {
327
329
doc . getElementById ( 'cuxjju3ew' ) . textContent = consoleCSS ;
328
330
}
329
331
}
330
- // render right away
332
+
331
333
if ( string === 'html' ) {
332
334
renderPreview ( project . autorun ) ;
333
335
if ( ! window . editorManager ) return ;
@@ -347,9 +349,13 @@ window.project = onChange(p, (property, oldValue, newValue) => {
347
349
if ( string === 'module' || string === 'meta' || string === 'libraries' || string === 'html_pre_processor' || string === 'css_pre_processor' || string === 'javascript_pre_processor' ) {
348
350
renderPreview ( project . autorun ) ;
349
351
}
352
+
350
353
if ( string === "previewDark" ) {
351
- doc . documentElement . setAttribute ( 'data-theme' , project . previewDark ? 'dark' : 'light' ) ;
354
+ if ( doc ) {
355
+ doc . documentElement . setAttribute ( 'data-theme' , project . previewDark ? 'dark' : 'light' ) ;
356
+ }
352
357
}
358
+
353
359
if ( string === "dark" ) {
354
360
App . render ( '#app' ) ;
355
361
document . documentElement . setAttribute ( 'data-theme' , project . dark ? 'dark' : 'light' ) ;
@@ -2893,9 +2899,7 @@ window.importProject = () => {
2893
2899
reader . onload = event => {
2894
2900
try {
2895
2901
importJSON ( JSON . parse ( event . target . result ) ) ;
2896
- setTimeout ( function ( ) {
2897
- renderPreview ( true ) ;
2898
- } , 100 ) ;
2902
+ renderPreview ( true ) ;
2899
2903
} catch ( error ) {
2900
2904
console . error ( 'Error parsing JSON file:' , error ) ;
2901
2905
}
@@ -3939,6 +3943,10 @@ window.screenshot = async () => {
3939
3943
removeScript ( "../libraries/jszip/FileSaver.min.js" ) ;
3940
3944
}
3941
3945
}
3946
+ window . createBlobURL = ( content , type ) => {
3947
+ const blob = new Blob ( [ content ] , { type } ) ;
3948
+ return URL . createObjectURL ( blob ) ;
3949
+ }
3942
3950
window . renderPreview = async ( forceRun = false ) => {
3943
3951
const iframe = document . getElementById ( 'iframe' ) ;
3944
3952
if ( ! iframe ) return ;
@@ -3957,10 +3965,14 @@ window.renderPreview = async (forceRun = false) => {
3957
3965
3958
3966
const javascriptCode = await compileCode ( 'javascript' ) ;
3959
3967
const cssCode = await compileCode ( 'css' ) ;
3960
- const consoleCSS = `
3961
- [data-zwj=zwjkonsole] {
3962
- display: ${ project . console ? 'flex' : 'none' } ;
3963
- }`
3968
+ const consoleCSS = `[data-zwj=zwjkonsole] {
3969
+ display: ${ project . console ? 'flex' : 'none' } ;
3970
+ }
3971
+
3972
+ `
3973
+
3974
+ const domconsoleContent = await fetch ( 'libraries/domconsole/dom-console-mod.min.js' ) . then ( response => response . text ( ) ) ;
3975
+ let jsLink = createBlobURL ( javascriptCode , 'application/javascript' ) ;
3964
3976
const iframeSrc = `<html data-theme="${ project . previewDark ? 'dark' : 'light' } ">
3965
3977
<head>
3966
3978
<title>${ project . title } </title>
@@ -3973,24 +3985,21 @@ window.renderPreview = async (forceRun = false) => {
3973
3985
<style id="cuxjju3ew" type="text/${ project . css_pre_processor === 'css' || project . css_pre_processor === 'stylus' || project . css_pre_processor === 'sass' ? 'css' : project . css_pre_processor } ">
3974
3986
${ consoleCSS + cssCode }
3975
3987
</style>
3976
- <script type="module" src="libraries/domconsole/dom-console-mod.min.js" defer></script>
3988
+ <script type="module">
3989
+ ${ domconsoleContent }
3990
+ </script>
3977
3991
</head>
3978
3992
<body>
3979
3993
${ await compileCode ( 'html' ) }
3980
3994
${ scriptTags ? scriptTags : '' }
3981
3995
${ project . css_pre_processor === 'less' ? '<script src="libraries/preprocessors/less.js"></script>' : '' }
3996
+ <script type="${ project . module ? 'module' : 'text/javascript' } " src="${ jsLink } "></script>
3982
3997
</body>
3983
3998
</html>` ;
3999
+ const newHtmlBlobURL = createBlobURL ( iframeSrc , 'text/html' ) ;
3984
4000
3985
4001
if ( forceRun ) {
3986
- iframe . setAttribute ( 'srcdoc' , iframeSrc ) ;
3987
- iframe . onload = ( ) => {
3988
- const doc = iframe . contentWindow . document ;
3989
- const script = doc . createElement ( 'script' ) ;
3990
- script . type = project . module ? 'module' : 'text/javascript' ;
3991
- script . textContent = javascriptCode ;
3992
- doc . body . appendChild ( script ) ;
3993
- }
4002
+ iframe . setAttribute ( 'src' , newHtmlBlobURL ) ;
3994
4003
}
3995
4004
}
3996
4005
@@ -4084,9 +4093,7 @@ document.addEventListener('DOMContentLoaded', function() {
4084
4093
4085
4094
if ( localStorage . getItem ( 'kodeWeave' ) ) {
4086
4095
importJSON ( JSON . parse ( localStorage . getItem ( 'kodeWeave' ) ) ) ;
4087
- setTimeout ( function ( ) {
4088
- renderPreview ( true ) ;
4089
- } , 100 ) ;
4096
+ renderPreview ( true ) ;
4090
4097
}
4091
4098
}
4092
4099
window . onresize = ( ) => getIFrameClientSize ( ) ;
0 commit comments