{"size": 2307, "ext": "js", "max_stars_repo_path": "platforms/windows/platform_www/plugins/cordova-plugin-qrscanner/src/windows/lib/preview.js", "max_stars_repo_name": "GrantLei/Ulord", "max_stars_repo_stars_event_min_datetime": "2018-03-16T06:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-16T06:11:20.000Z", "max_issues_repo_path": "platforms/windows/platform_www/plugins/cordova-plugin-qrscanner/src/windows/lib/preview.js", "max_issues_repo_name": "GrantLei/Ulord", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "platforms/windows/platform_www/plugins/cordova-plugin-qrscanner/src/windows/lib/preview.js", "max_forks_repo_name": "GrantLei/Ulord", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.3516483516, "max_line_length": 98, "alphanum_fraction": 0.6445600347}
cordova.define("cordova-plugin-qrscanner.preview", function(require, exports, module) {
  const urlutil = require('cordova/urlutil');

  let preview;

  function create() {

    if (preview) {
      throw 'preview already exists';
    }

    let capturePreviewFrameStyle = document.createElement('link');
    capturePreviewFrameStyle.rel = "stylesheet";
    capturePreviewFrameStyle.type = "text/css";
    capturePreviewFrameStyle.href = urlutil.makeAbsolute("/www/css/plugin-qrscanner-preview.css");
    document.head.appendChild(capturePreviewFrameStyle);

    let capturePreviewFrame = document.createElement('div');
    capturePreviewFrame.className = "barcode-scanner-wrap";
    capturePreviewFrame.style.zIndex = -100;
    capturePreviewFrame.style.visibility = 'hidden';

    let capturePreview = document.createElement("video");
    capturePreview.className = "barcode-scanner-preview";
    capturePreview.msZoom = true;
    capturePreview.style.height = 'calc(100%)';
    capturePreview.style.top = 'calc(50%)';

    capturePreviewFrame.appendChild(capturePreview);
    document.body.appendChild(capturePreviewFrame);

    preview = {};

    preview.setVideoUrl = function (videoUrl) {
      capturePreview.src = videoUrl;
    }

    preview.setMirroring = function (isMirrored) {
      if (isMirrored) {
        capturePreviewFrame.style.transform = 'scaleY(-1)';
      } else {
        capturePreviewFrame.style.transform = '';
      }
    }

    preview.show = function () {
        if (!capturePreviewFrame) {
          return;
        }

        capturePreview.play();
        capturePreviewFrame.style.visibility = 'visible';
      }

    preview.hide = function () {
        if (!capturePreviewFrame) {
          return;
        }

        capturePreviewFrame.style.visibility = 'hidden';
        capturePreview.pause();
      }

    preview.pause = function() {
        capturePreview.pause();
      }

    preview.resume = function() {
        capturePreview.play();
    }

    preview.destroy = function () {
        if (!preview) {
          return;
        }

        preview = null;
        document.head.removeChild(capturePreviewFrameStyle);
        document.body.removeChild(capturePreviewFrame);
    }

    return preview;

    }

  module.exports = {
    create: create
  };

});
