Revert "Replace viz.js v1.8.2 with @hpcc-js/wasm 0.3.14"

Revert “Replace viz.js v1.8.2 with @hpcc-js/wasm 0.3.14”

This reverts commit 38aef85c6550f957daeb764fbe8f9b2dd190de6d.

Unfortunately this broke server side rendering and does not work when CSP has been enabled.

diff --git a/assets/javascripts/initializers/discourse-graphviz.js.es6 b/assets/javascripts/initializers/discourse-graphviz.js.es6
index 8457782..770c87d 100644
--- a/assets/javascripts/initializers/discourse-graphviz.js.es6
+++ b/assets/javascripts/initializers/discourse-graphviz.js.es6
@@ -26,32 +26,26 @@ export default {
     const $spinner = $("<div class='spinner tiny'></div>");
     $container.html($spinner);
 
-    if (worker === undefined) {
-      worker = new Worker("/plugins/discourse-graphviz/javascripts/worker.js");
+    loadScript("/plugins/discourse-graphviz/javascripts/viz-1.8.2.js").then(
+      () => {
+        $container.removeClass("is-loading");
 
-      worker.postMessage({
-        scriptURL: getURLWithCDN(
-          "/plugins/discourse-graphviz/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js"
-        )
-      });
-    }
-
-    worker.addEventListener("message", event => {
-      const data = event.data;
-      $container.removeClass("is-loading");
-
-      if (data.svgChart) {
-        $container.html(data.svgChart);
-      } else {
-        // graphviz errors are very helpful so we just show them as is
-        const $error = $(
-          "<div class='graph-error'>" + escape(data.errorMessage) + "</div>"
-        );
-        $container.html($error);
+        try {
+          /* global Viz */
+          const svgChart = Viz(graphDefinition, {
+            format: "svg",
+            engine
+          });
+          $container.html(svgChart);
+        } catch (e) {
+          // graphviz error are unhelpful so we just show a default error
+          const $error = $(
+            "<div class='graph-error'>Error while rendering graph.</div>"
+          );
+          $container.html($error);
+        }
       }
-    });
-
-    worker.postMessage({ graphDefinition, engine });
+    );
   },
 
   initialize(container) {
diff --git a/plugin.rb b/plugin.rb
index 611d90c..ba57967 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -14,7 +14,7 @@ after_initialize do
 
   def context
     context = MiniRacer::Context.new
-    context.load("#{Rails.root}/plugins/discourse-graphviz/public/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js")
+    context.load("#{Rails.root}/plugins/discourse-graphviz/public/javascripts/viz-1.8.2.js")
     context
   end
 
diff --git a/public/javascripts/@hpcc-js/wasm@0.3.14/dist/graphvizlib.wasm b/public/javascripts/@hpcc-js/wasm@0.3.14/dist/graphvizlib.wasm
deleted file mode 100644
index 8499c32..0000000
Binary files a/public/javascripts/@hpcc-js/wasm@0.3.14/dist/graphvizlib.wasm and /dev/null differ
diff --git a/public/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js b/public/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js
deleted file mode 100644
index 99ccf8a..0000000
--- a/public/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js
+++ /dev/null
@@ -1 +0,0 @@

[... diff too long, it was truncated ...]

GitHub sha: c6ad4fa3