import { g as e, c as t } from "./alasql-f60045ee.js";
import r from "react";
function i(e2, t2) {
  for (var r2 = 0; r2 < t2.length; r2++) {
    const i2 = t2[r2];
    if ("string" != typeof i2 && !Array.isArray(i2)) {
      for (const t3 in i2)
        if ("default" !== t3 && !(t3 in e2)) {
          const r3 = Object.getOwnPropertyDescriptor(i2, t3);
          r3 && Object.defineProperty(e2, t3, r3.get ? r3 : { enumerable: true, get: () => i2[t3] });
        }
    }
  }
  return Object.freeze(Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }));
}
var n = { exports: {} }, o = n.exports = function(e2) {
  return function(e3) {
    var t2 = {};
    function r2(i2) {
      if (t2[i2])
        return t2[i2].exports;
      var n2 = t2[i2] = { i: i2, l: false, exports: {} };
      return e3[i2].call(n2.exports, n2, n2.exports, r2), n2.l = true, n2.exports;
    }
    return r2.m = e3, r2.c = t2, r2.d = function(e4, t3, i2) {
      r2.o(e4, t3) || Object.defineProperty(e4, t3, { enumerable: true, get: i2 });
    }, r2.r = function(e4) {
      "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e4, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e4, "__esModule", { value: true });
    }, r2.t = function(e4, t3) {
      if (1 & t3 && (e4 = r2(e4)), 8 & t3)
        return e4;
      if (4 & t3 && "object" == typeof e4 && e4 && e4.__esModule)
        return e4;
      var i2 = /* @__PURE__ */ Object.create(null);
      if (r2.r(i2), Object.defineProperty(i2, "default", { enumerable: true, value: e4 }), 2 & t3 && "string" != typeof e4)
        for (var n2 in e4)
          r2.d(i2, n2, (function(t4) {
            return e4[t4];
          }).bind(null, n2));
      return i2;
    }, r2.n = function(e4) {
      var t3 = e4 && e4.__esModule ? function() {
        return e4.default;
      } : function() {
        return e4;
      };
      return r2.d(t3, "a", t3), t3;
    }, r2.o = function(e4, t3) {
      return Object.prototype.hasOwnProperty.call(e4, t3);
    }, r2.p = "", r2(r2.s = "./src/react-webcam.tsx");
  }({ "./src/react-webcam.tsx": function(e3, t2, r2) {
    r2.r(t2);
    var i2, n2 = r2("react"), o2 = (i2 = function(e4, t3) {
      return i2 = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e5, t4) {
        e5.__proto__ = t4;
      } || function(e5, t4) {
        for (var r3 in t4)
          t4.hasOwnProperty(r3) && (e5[r3] = t4[r3]);
      }, i2(e4, t3);
    }, function(e4, t3) {
      function r3() {
        this.constructor = e4;
      }
      i2(e4, t3), e4.prototype = null === t3 ? Object.create(t3) : (r3.prototype = t3.prototype, new r3());
    }), a2 = function() {
      return a2 = Object.assign || function(e4) {
        for (var t3, r3 = 1, i3 = arguments.length; r3 < i3; r3++)
          for (var n3 in t3 = arguments[r3])
            Object.prototype.hasOwnProperty.call(t3, n3) && (e4[n3] = t3[n3]);
        return e4;
      }, a2.apply(this, arguments);
    };
    function s() {
      return !(!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia);
    }
    "undefined" != typeof window && (void 0 === navigator.mediaDevices && (navigator.mediaDevices = {}), void 0 === navigator.mediaDevices.getUserMedia && (navigator.mediaDevices.getUserMedia = function(e4) {
      var t3 = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
      return t3 ? new Promise(function(r3, i3) {
        t3.call(navigator, e4, r3, i3);
      }) : Promise.reject(new Error("getUserMedia is not implemented in this browser"));
    }));
    var c = function(e4) {
      function t3(t4) {
        var r3 = e4.call(this, t4) || this;
        return r3.canvas = null, r3.ctx = null, r3.requestUserMediaId = 0, r3.unmounted = false, r3.state = { hasUserMedia: false }, r3;
      }
      return o2(t3, e4), t3.prototype.componentDidMount = function() {
        var e5 = this.state, t4 = this.props;
        this.unmounted = false, s() ? (e5.hasUserMedia || this.requestUserMedia(), t4.children && t4.children) : t4.onUserMediaError("getUserMedia not supported");
      }, t3.prototype.componentDidUpdate = function(e5) {
        var t4 = this.props;
        if (s()) {
          var r3 = JSON.stringify(e5.audioConstraints) !== JSON.stringify(t4.audioConstraints), i3 = JSON.stringify(e5.videoConstraints) !== JSON.stringify(t4.videoConstraints), n3 = e5.minScreenshotWidth !== t4.minScreenshotWidth, o3 = e5.minScreenshotHeight !== t4.minScreenshotHeight;
          (i3 || n3 || o3) && (this.canvas = null, this.ctx = null), (r3 || i3) && (this.stopAndCleanup(), this.requestUserMedia());
        } else
          t4.onUserMediaError("getUserMedia not supported");
      }, t3.prototype.componentWillUnmount = function() {
        this.unmounted = true, this.stopAndCleanup();
      }, t3.stopMediaStream = function(e5) {
        e5 && (e5.getVideoTracks && e5.getAudioTracks ? (e5.getVideoTracks().map(function(t4) {
          e5.removeTrack(t4), t4.stop();
        }), e5.getAudioTracks().map(function(t4) {
          e5.removeTrack(t4), t4.stop();
        })) : e5.stop());
      }, t3.prototype.stopAndCleanup = function() {
        var e5 = this.state;
        e5.hasUserMedia && (t3.stopMediaStream(this.stream), e5.src && window.URL.revokeObjectURL(e5.src));
      }, t3.prototype.getScreenshot = function(e5) {
        var t4 = this.state, r3 = this.props;
        if (!t4.hasUserMedia)
          return null;
        var i3 = this.getCanvas(e5);
        return i3 && i3.toDataURL(r3.screenshotFormat, r3.screenshotQuality);
      }, t3.prototype.getCanvas = function(e5) {
        var t4 = this.state, r3 = this.props;
        if (!this.video)
          return null;
        if (!t4.hasUserMedia || !this.video.videoHeight)
          return null;
        if (!this.ctx) {
          var i3 = this.video.videoWidth, n3 = this.video.videoHeight;
          if (!this.props.forceScreenshotSourceSize) {
            var o3 = i3 / n3;
            n3 = (i3 = r3.minScreenshotWidth || this.video.clientWidth) / o3, r3.minScreenshotHeight && n3 < r3.minScreenshotHeight && (i3 = (n3 = r3.minScreenshotHeight) * o3);
          }
          this.canvas = document.createElement("canvas"), this.canvas.width = (null == e5 ? void 0 : e5.width) || i3, this.canvas.height = (null == e5 ? void 0 : e5.height) || n3, this.ctx = this.canvas.getContext("2d");
        }
        var a3 = this.ctx, s2 = this.canvas;
        return a3 && s2 && (s2.width = (null == e5 ? void 0 : e5.width) || s2.width, s2.height = (null == e5 ? void 0 : e5.height) || s2.height, r3.mirrored && (a3.translate(s2.width, 0), a3.scale(-1, 1)), a3.imageSmoothingEnabled = r3.imageSmoothing, a3.drawImage(this.video, 0, 0, (null == e5 ? void 0 : e5.width) || s2.width, (null == e5 ? void 0 : e5.height) || s2.height), r3.mirrored && (a3.scale(-1, 1), a3.translate(-s2.width, 0))), s2;
      }, t3.prototype.requestUserMedia = function() {
        var e5 = this, r3 = this.props, i3 = function(i4, n4) {
          var o4 = { video: void 0 === n4 || n4 };
          r3.audio && (o4.audio = void 0 === i4 || i4), e5.requestUserMediaId++;
          var a3 = e5.requestUserMediaId;
          navigator.mediaDevices.getUserMedia(o4).then(function(r4) {
            e5.unmounted || a3 !== e5.requestUserMediaId ? t3.stopMediaStream(r4) : e5.handleUserMedia(null, r4);
          }).catch(function(t4) {
            e5.handleUserMedia(t4);
          });
        };
        if ("mediaDevices" in navigator)
          i3(r3.audioConstraints, r3.videoConstraints);
        else {
          var n3 = function(e6) {
            return { optional: [{ sourceId: e6 }] };
          }, o3 = function(e6) {
            var t4 = e6.deviceId;
            return "string" == typeof t4 ? t4 : Array.isArray(t4) && t4.length > 0 ? t4[0] : "object" == typeof t4 && t4.ideal ? t4.ideal : null;
          };
          MediaStreamTrack.getSources(function(e6) {
            var t4 = null, a3 = null;
            e6.forEach(function(e7) {
              "audio" === e7.kind ? t4 = e7.id : "video" === e7.kind && (a3 = e7.id);
            });
            var s2 = o3(r3.audioConstraints);
            s2 && (t4 = s2);
            var c2 = o3(r3.videoConstraints);
            c2 && (a3 = c2), i3(n3(t4), n3(a3));
          });
        }
      }, t3.prototype.handleUserMedia = function(e5, t4) {
        var r3 = this.props;
        if (e5 || !t4)
          return this.setState({ hasUserMedia: false }), void r3.onUserMediaError(e5);
        this.stream = t4;
        try {
          this.video && (this.video.srcObject = t4), this.setState({ hasUserMedia: true });
        } catch (e6) {
          this.setState({ hasUserMedia: true, src: window.URL.createObjectURL(t4) });
        }
        r3.onUserMedia(t4);
      }, t3.prototype.render = function() {
        var e5 = this, t4 = this.state, r3 = this.props, i3 = r3.audio, o3 = r3.disablePictureInPicture, s2 = r3.mirrored, c2 = r3.style, d = void 0 === c2 ? {} : c2, u = r3.children, h = function(e6, t5) {
          var r4 = {};
          for (var i4 in e6)
            Object.prototype.hasOwnProperty.call(e6, i4) && t5.indexOf(i4) < 0 && (r4[i4] = e6[i4]);
          if (null != e6 && "function" == typeof Object.getOwnPropertySymbols) {
            var n3 = 0;
            for (i4 = Object.getOwnPropertySymbols(e6); n3 < i4.length; n3++)
              t5.indexOf(i4[n3]) < 0 && Object.prototype.propertyIsEnumerable.call(e6, i4[n3]) && (r4[i4[n3]] = e6[i4[n3]]);
          }
          return r4;
        }(r3, ["audio", "forceScreenshotSourceSize", "disablePictureInPicture", "onUserMedia", "onUserMediaError", "screenshotFormat", "screenshotQuality", "minScreenshotWidth", "minScreenshotHeight", "audioConstraints", "videoConstraints", "imageSmoothing", "mirrored", "style", "children"]), l = s2 ? a2(a2({}, d), { transform: (d.transform || "") + " scaleX(-1)" }) : d, p = { getScreenshot: this.getScreenshot.bind(this) };
        return n2.createElement(n2.Fragment, null, n2.createElement("video", a2({ autoPlay: true, disablePictureInPicture: o3, src: t4.src, muted: !i3, playsInline: true, ref: function(t5) {
          e5.video = t5;
        }, style: l }, h)), u && u(p));
      }, t3.defaultProps = { audio: false, disablePictureInPicture: false, forceScreenshotSourceSize: false, imageSmoothing: true, mirrored: false, onUserMedia: function() {
      }, onUserMediaError: function() {
      }, screenshotFormat: "image/webp", screenshotQuality: 0.92 }, t3;
    }(n2.Component);
    t2.default = c;
  }, react: function(t2, r2) {
    t2.exports = e2;
  } }).default;
}(r);
const a = i({ __proto__: null, default: e(o) }, [o]);
export {
  a as r
};
