From 4c2cb5ff18369fbea7b330fa66219569f5445f1f Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Mon, 25 Nov 2019 15:22:51 +0100
Subject: [PATCH] Add Edge polyfill for toBlob method

---
 src/polyfills.ts | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/polyfills.ts b/src/polyfills.ts
index a5d20e271..7992435c1 100644
--- a/src/polyfills.ts
+++ b/src/polyfills.ts
@@ -78,3 +78,21 @@ import "zone.js/dist/zone";  // Included with Angular CLI.
 // Requis pour Buffer dans jalhyd (!?)
 (window as any).global = window;
 global.Buffer = global.Buffer || require("buffer").Buffer;
+
+// Edge polyfill for canvas.toBlob method
+if (!HTMLCanvasElement.prototype.toBlob) {
+    Object.defineProperty(HTMLCanvasElement.prototype, "toBlob", {
+      value: function (callback, type, quality) {
+        const dataURL = this.toDataURL(type, quality).split(",")[1];
+        setTimeout(function() {
+          const binStr = atob( dataURL ),
+              len = binStr.length,
+              arr = new Uint8Array(len);
+          for (let i = 0; i < len; i++ ) {
+            arr[i] = binStr.charCodeAt(i);
+          }
+          callback( new Blob( [arr], {type: type || "image/png"} ) );
+        });
+      }
+    });
+  }
-- 
GitLab