99        var  wasmBinaryFile ; 
1010        switch  ( window . location . hostname )  { 
1111            case  "localhost" :
12-                 document . write ( '<script type="text/javascript" src="./dist/index.js"><'  +  '/script>' ) ; 
13-                 wasmBinaryFile  =  "./dist/graphvizlib.wasm" ; 
12+                 document . write ( '<script type="text/javascript" src="./dist/sfx-graphviz.js"><'  +  '/script>' ) ; 
1413                break ; 
1514            default :
1615                document . write ( '<script src="https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.min.js"><'  +  '/script>' ) ; 
2120
2221    < script > 
2322        var  hpccWasm  =  window [ "@hpcc-js/wasm" ] ; 
24-         // hpccWasm.wasmFolder("build/cpp/graphviz/graphvizlib"); 
2523    </ script > 
2624</ head > 
2725
@@ -36,11 +34,10 @@ <h3>Two</h3>
3634    < h3 > Sync DOT</ h3 > 
3735    < div  id ="placeholder3 "> </ div > 
3836    < hr > 
39-     < h3 > Cached  wasmBinary</ h3 > 
37+     < h3 > ESM  wasmBinary</ h3 > 
4038    < div  id ="placeholder4 "> </ div > 
4139    < hr > 
4240    < script > 
43-         hpccWasm . expatVersion ( ) . then ( v  =>  alert ( v ) ) ; 
4441        const  dot  =  ` 
4542            digraph G { 
4643                node [shape=rect]; 
@@ -112,19 +109,27 @@ <h3>Cached wasmBinary</h3>
112109            } 
113110        } ) ; 
114111
115-         fetch ( wasmBinaryFile ,  {  credentials : 'same-origin'  } ) . then ( response  =>  { 
116-             if  ( ! response . ok )  { 
117-                 throw  "failed to load wasm binary file at '"  +  wasmBinaryFile  +  "'" ; 
118-             } 
119-             return  response . arrayBuffer ( ) ; 
120-         } ) . then ( wasmBinary  =>  { 
121-             hpccWasm . graphviz . layout ( dot ,  "svg" ,  "dot" ,  {  wasmBinary : wasmBinary  } ) . then ( svg  =>  { 
122-                 const  div  =  document . getElementById ( "placeholder4" ) ; 
123-                 div . innerHTML  =  svg ; 
124-             } ) . catch ( err  =>  console . error ( err . message ) ) ; 
125-         } ) ; 
126112    </ script > 
127113
114+     < script  type ="module "> 
115+         import  {  Graphviz  }  from  "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/sfx-graphviz.esm.js" ; 
116+         if  ( Graphviz )  { 
117+             const  graphviz  =  await  Graphviz . load ( ) ; 
118+             const  svg  =  graphviz . layout ( dot ,  "svg" ,  "dot" ) ; 
119+             const  div  =  document . getElementById ( "placeholder4" ) ; 
120+             div . innerHTML  =  svg ; 
121+         }  
122+     </ script > 
123+ 
124+     < script  type ="module "> 
125+         import  {  Graphviz  }  from  "./dist/sfx-graphviz.esm.js" ; 
126+         if  ( Graphviz )  { 
127+             const  graphviz  =  await  Graphviz . load ( ) ; 
128+             const  svg  =  graphviz . layout ( dot ,  "svg" ,  "dot" ) ; 
129+             const  div  =  document . getElementById ( "placeholder4" ) ; 
130+             div . innerHTML  =  svg ; 
131+         } 
132+     </ script > 
128133</ body > 
129134
130135</ html > 
0 commit comments