-
-
Save beckyconning/a71bf600d94526a6180b8e40b9b0be9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var domtoimage = window.domtoimage; | |
exports.toSvgImpl = function (element) { | |
return function () { | |
console.log("toSvgImpl"); | |
return domtoimage.toSvg(element); | |
}; | |
}; | |
exports.toBlobImpl = function (element) { | |
return function () { | |
return domtoimage.toBlob(element); | |
}; | |
}; | |
exports.toJpegImpl = function (element) { | |
return function () { | |
return domtoimage.toJpeg(element); | |
}; | |
}; | |
exports.toPngImpl = function (element) { | |
return function () { | |
return domtoimage.toPng(element); | |
}; | |
}; | |
exports.toPixelDataImpl = function (element) { | |
return function () { | |
return domtoimage.toPixelData(element); | |
}; | |
}; | |
exports.promiseCallbacks = function (promiseEff) { | |
return function (error) { | |
return function (success) { | |
return function () { | |
promiseEff() | |
.then(function (x) { success(x)(); }, function (x) { error(x)(); }); | |
}; | |
}; | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DomToImage where | |
import Prelude | |
import Control.Monad.Aff (Aff) | |
import Control.Monad.Aff as Aff | |
import Control.Monad.Eff (Eff, kind Effect) | |
import Control.Monad.Eff.Exception (Error) | |
import Data.ArrayBuffer.Types (Uint8Array) | |
import DOM.File.Types (Blob) | |
import DOM.Node.Types (Element) | |
newtype DataUri = DataUri String | |
unDataUri :: DataUri -> String | |
unDataUri (DataUri s) = s | |
foreign import data DOMTOIMAGE :: Effect | |
foreign import data Promise :: Type -> Type | |
foreign import promiseCallbacks | |
:: forall a b | |
. Eff a (Promise b) | |
-> (Error -> Eff a Unit) | |
-> (b -> Eff a Unit) | |
-> Eff a Unit | |
foreign import toBlobImpl | |
:: forall a | |
. Element | |
-> Eff (domToImage :: DOMTOIMAGE | a) (Promise Blob) | |
foreign import toSvgImpl | |
:: forall a | |
. Element | |
-> Eff (domToImage :: DOMTOIMAGE | a) (Promise DataUri) | |
foreign import toJpegImpl | |
:: forall a | |
. Element | |
-> Eff (domToImage :: DOMTOIMAGE | a) (Promise DataUri) | |
foreign import toPngImpl | |
:: forall a | |
. Element | |
-> Eff (domToImage :: DOMTOIMAGE | a) (Promise DataUri) | |
foreign import toPixelDataImpl | |
:: forall a | |
. Element | |
-> Eff (domToImage :: DOMTOIMAGE | a) (Promise Uint8Array) | |
toBlob :: forall a. Element -> Aff (domToImage :: DOMTOIMAGE | a) Blob | |
toBlob = Aff.makeAff <<< promiseCallbacks <<< toBlobImpl | |
toSvg :: forall a. Element -> Aff (domToImage :: DOMTOIMAGE | a) DataUri | |
toSvg = Aff.makeAff <<< promiseCallbacks <<< toSvgImpl | |
toPng :: forall a. Element -> Aff (domToImage :: DOMTOIMAGE | a) DataUri | |
toPng = Aff.makeAff <<< promiseCallbacks <<< toPngImpl | |
toPixelData :: forall a. Element -> Aff (domToImage :: DOMTOIMAGE | a) Uint8Array | |
toPixelData = Aff.makeAff <<< promiseCallbacks <<< toPixelDataImpl | |
toJpeg :: forall a. Element -> Aff (domToImage :: DOMTOIMAGE | a) DataUri | |
toJpeg = Aff.makeAff <<< promiseCallbacks <<< toJpegImpl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment