<commit_before>import Ember from "ember";
export default Ember.Mixin.create({
  exportToPng: function(){
    var img = this.get("image"),
        canvas = this.$("canvas")[0],
        context = canvas.getContext("2d"),
        svg = this.$("svg").clone(),
        svgImg = new Image(),
        url, promise,
        that = this;

    promise = new Ember.RSVP.Promise(function(resolve, reject){
      try {
        if(img){
          img = that.$("img")[0];
          canvas.width = img.naturalWidth;
          canvas.height = img.naturalHeight;

          svg.attr("width", canvas.width);
          svg.attr("height", canvas.height);

          context.drawImage(img, 0, 0);

        }else{
          canvas.width = that.$().width();
          canvas.height = that.$().height();
        }
        url = "data:image/svg+xml," + svg[0].outerHTML;

        svgImg.onload = function () {
          context.drawImage(svgImg, 0, 0);
          resolve(canvas.toDataURL());
        }
        svgImg.onError = reject;
        svgImg.src = url;
      } catch(e){
        reject(e);
      }
    });

    return promise;
  }
});<commit_msg>Export to png: svg image does not work in safari and fails silently (l) safari<commit_after>import Ember from "ember";
export default Ember.Mixin.create({
  exportToPng: function(){
    var img = this.get("image"),
        canvas = this.$("canvas")[0],
        context = canvas.getContext("2d"),
        outerSvg = this.$(".squiggle-paper").clone(),
        svg,
        svgImg = new Image(),
        url, promise,
        that = this;

    outerSvg.find("textarea").remove();
    outerSvg.find("image").remove();
    svg = outerSvg.find("svg");

    promise = new Ember.RSVP.Promise(function(resolve, reject){
      try {
        if(img){
          img = that.$("img")[0];
          canvas.width = img.naturalWidth;
          canvas.height = img.naturalHeight;

          svg.attr("width", canvas.width);
          svg.attr("height", canvas.height);

          context.drawImage(img, 0, 0);

        }else{
          canvas.width = that.$().width();
          canvas.height = that.$().height();
        }

        url = "data:image/svg+xml," + outerSvg.html();

        svgImg.onload = function(){
          context.drawImage(svgImg, 0, 0);
          resolve(canvas.toDataURL());
        };
        svgImg.onError = reject;
        svgImg.src = url;

      } catch(e){
        reject(e);
      }
    });

    return promise;
  }
});
{'fraction_non_alphanumeric': 0.16253555465258024, 'fraction_numerical': 0.006095083299471759, 'mean_word_length': 1.9842424242424241, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5298006', 'n_tokens_mistral': 781, 'n_tokens_neox': 743, 'n_words': 151}