From 6a20c03a2d08bddfaeee23f4237d29f9bb67c7a2 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 4 Jun 2021 09:16:54 +0200 Subject: Introduced common librairy into viz.js --- resources/download.js | 162 -------------------------------------------------- viz.js/convert.ml | 17 +++--- viz.js/dune | 2 + viz.js/index.html | 2 - 4 files changed, 10 insertions(+), 173 deletions(-) delete mode 100755 resources/download.js diff --git a/resources/download.js b/resources/download.js deleted file mode 100755 index 934edcc..0000000 --- a/resources/download.js +++ /dev/null @@ -1,162 +0,0 @@ -//download.js v4.2, by dandavis; 2008-2016. [CCBY2] see http://danml.com/download.html for tests/usage -// v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime -// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs -// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling. -// v4 adds AMD/UMD, commonJS, and plain browser support -// v4.1 adds url download capability via solo URL argument (same domain/CORS only) -// v4.2 adds semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors -// https://github.com/rndme/download - -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define([], factory); - } else if (typeof exports === 'object') { - // Node. Does not work with strict CommonJS, but - // only CommonJS-like environments that support module.exports, - // like Node. - module.exports = factory(); - } else { - // Browser globals (root is window) - root.download = factory(); - } -}(this, function () { - - return function download(data, strFileName, strMimeType) { - - var self = window, // this script is only for browsers anyway... - defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads - mimeType = strMimeType || defaultMime, - payload = data, - url = !strFileName && !strMimeType && payload, - anchor = document.createElement("a"), - toString = function(a){return String(a);}, - myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString), - fileName = strFileName || "download", - blob, - reader; - myBlob= myBlob.call ? myBlob.bind(self) : Blob ; - - if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback - payload=[payload, mimeType]; - mimeType=payload[0]; - payload=payload[1]; - } - - - if(url && url.length< 2048){ // if no filename and no mime, assume a url was passed as the only argument - fileName = url.split("/").pop().split("?")[0]; - anchor.href = url; // assign href prop to temp anchor - if(anchor.href.indexOf(url) !== -1){ // if the browser determines that it's a potentially valid url path: - var ajax=new XMLHttpRequest(); - ajax.open( "GET", url, true); - ajax.responseType = 'blob'; - ajax.onload= function(e){ - download(e.target.response, fileName, defaultMime); - }; - setTimeout(function(){ ajax.send();}, 0); // allows setting custom ajax headers using the return: - return ajax; - } // end if valid url? - } // end if url? - - - //go ahead and download dataURLs right away - if(/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(payload)){ - - if(payload.length > (1024*1024*1.999) && myBlob !== toString ){ - payload=dataUrlToBlob(payload); - mimeType=payload.type || defaultMime; - }else{ - return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs: - navigator.msSaveBlob(dataUrlToBlob(payload), fileName) : - saver(payload) ; // everyone else can save dataURLs un-processed - } - - }//end if dataURL passed? - - blob = payload instanceof myBlob ? - payload : - new myBlob([payload], {type: mimeType}) ; - - - function dataUrlToBlob(strUrl) { - var parts= strUrl.split(/[:;,]/), - type= parts[1], - decoder= parts[2] == "base64" ? atob : decodeURIComponent, - binData= decoder( parts.pop() ), - mx= binData.length, - i= 0, - uiArr= new Uint8Array(mx); - - for(i;i - let _ = download input (Js.string "output.dot") (Js.string "text/plain") in + let _ = Elements.Transfert.send + ~mime_type:(Jstr.v "text/plain") + ~filename:(Jstr.v "output.dot") + (Obj.magic input) in Js._false ); @@ -86,7 +82,10 @@ let load () = output_button##.onclick := Dom_html.handler (fun _-> (*download image*) CanvasTool.generate_png image (fun image -> - let _ = download image (Js.string "output.png") (Js.string "text/plain") in + let _ = + Elements.Transfert.send_raw + ~filename:(Jstr.v "output.png") + (Obj.magic image) in () ); Js._false diff --git a/viz.js/dune b/viz.js/dune index d6eba67..18ba438 100755 --- a/viz.js/dune +++ b/viz.js/dune @@ -5,6 +5,8 @@ js_of_ocaml-lwt promise process + elements + brr ) (modes js) (preprocess (pps js_of_ocaml-ppx)) diff --git a/viz.js/index.html b/viz.js/index.html index abb158c..2c4952e 100755 --- a/viz.js/index.html +++ b/viz.js/index.html @@ -102,8 +102,6 @@ - - -- cgit v1.2.3