import { hL as E, jl as I } from "./56c67d3b.js";
import W from "react";
function A(M, O) {
  for (var m = 0; m < O.length; m++) {
    const g = O[m];
    if (typeof g != "string" && !Array.isArray(g)) {
      for (const l in g)
        if (l !== "default" && !(l in M)) {
          const a = Object.getOwnPropertyDescriptor(g, l);
          a && Object.defineProperty(M, l, a.get ? a : {
            enumerable: !0,
            get: () => g[l]
          });
        }
    }
  }
  return Object.freeze(Object.defineProperty(M, Symbol.toStringTag, { value: "Module" }));
}
var _ = { exports: {} };
(function(M, O) {
  (function(g, l) {
    M.exports = l(W);
  })(I, function(m) {
    return (
      /******/
      function(g) {
        var l = {};
        function a(n) {
          if (l[n])
            return l[n].exports;
          var s = l[n] = {
            /******/
            i: n,
            /******/
            l: !1,
            /******/
            exports: {}
            /******/
          };
          return g[n].call(s.exports, s, s.exports, a), s.l = !0, s.exports;
        }
        return a.m = g, a.c = l, a.d = function(n, s, v) {
          a.o(n, s) || Object.defineProperty(n, s, { enumerable: !0, get: v });
        }, a.r = function(n) {
          typeof Symbol < "u" && Symbol.toStringTag && Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(n, "__esModule", { value: !0 });
        }, a.t = function(n, s) {
          if (s & 1 && (n = a(n)), s & 8 || s & 4 && typeof n == "object" && n && n.__esModule)
            return n;
          var v = /* @__PURE__ */ Object.create(null);
          if (a.r(v), Object.defineProperty(v, "default", { enumerable: !0, value: n }), s & 2 && typeof n != "string")
            for (var U in n)
              a.d(v, U, (function(b) {
                return n[b];
              }).bind(null, U));
          return v;
        }, a.n = function(n) {
          var s = n && n.__esModule ? (
            /******/
            function() {
              return n.default;
            }
          ) : (
            /******/
            function() {
              return n;
            }
          );
          return a.d(s, "a", s), s;
        }, a.o = function(n, s) {
          return Object.prototype.hasOwnProperty.call(n, s);
        }, a.p = "", a(a.s = "./src/react-webcam.tsx");
      }({
        /***/
        "./src/react-webcam.tsx": (
          /*!******************************!*\
            !*** ./src/react-webcam.tsx ***!
            \******************************/
          /*! exports provided: default */
          /***/
          function(g, l, a) {
            a.r(l);
            var n = a(
              /*! react */
              "react"
            ), s = function() {
              var f = function(o, e) {
                return f = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, i) {
                  t.__proto__ = i;
                } || function(t, i) {
                  for (var r in i)
                    i.hasOwnProperty(r) && (t[r] = i[r]);
                }, f(o, e);
              };
              return function(o, e) {
                f(o, e);
                function t() {
                  this.constructor = o;
                }
                o.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
              };
            }(), v = function() {
              return v = Object.assign || function(f) {
                for (var o, e = 1, t = arguments.length; e < t; e++) {
                  o = arguments[e];
                  for (var i in o)
                    Object.prototype.hasOwnProperty.call(o, i) && (f[i] = o[i]);
                }
                return f;
              }, v.apply(this, arguments);
            }, U = function(f, o) {
              var e = {};
              for (var t in f)
                Object.prototype.hasOwnProperty.call(f, t) && o.indexOf(t) < 0 && (e[t] = f[t]);
              if (f != null && typeof Object.getOwnPropertySymbols == "function")
                for (var i = 0, t = Object.getOwnPropertySymbols(f); i < t.length; i++)
                  o.indexOf(t[i]) < 0 && Object.prototype.propertyIsEnumerable.call(f, t[i]) && (e[t[i]] = f[t[i]]);
              return e;
            };
            (function() {
              typeof window > "u" || (navigator.mediaDevices === void 0 && (navigator.mediaDevices = {}), navigator.mediaDevices.getUserMedia === void 0 && (navigator.mediaDevices.getUserMedia = function(o) {
                var e = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
                return e ? new Promise(function(t, i) {
                  e.call(navigator, o, t, i);
                }) : Promise.reject(new Error("getUserMedia is not implemented in this browser"));
              }));
            })();
            function b() {
              return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
            }
            var P = (
              /** @class */
              function(f) {
                s(o, f);
                function o(e) {
                  var t = f.call(this, e) || this;
                  return t.canvas = null, t.ctx = null, t.requestUserMediaId = 0, t.unmounted = !1, t.state = {
                    hasUserMedia: !1
                  }, t;
                }
                return o.prototype.componentDidMount = function() {
                  var e = this, t = e.state, i = e.props;
                  if (this.unmounted = !1, !b()) {
                    i.onUserMediaError("getUserMedia not supported");
                    return;
                  }
                  t.hasUserMedia || this.requestUserMedia(), i.children && typeof i.children != "function" && console.warn("children must be a function");
                }, o.prototype.componentDidUpdate = function(e) {
                  var t = this.props;
                  if (!b()) {
                    t.onUserMediaError("getUserMedia not supported");
                    return;
                  }
                  var i = JSON.stringify(e.audioConstraints) !== JSON.stringify(t.audioConstraints), r = JSON.stringify(e.videoConstraints) !== JSON.stringify(t.videoConstraints), p = e.minScreenshotWidth !== t.minScreenshotWidth, c = e.minScreenshotHeight !== t.minScreenshotHeight;
                  (r || p || c) && (this.canvas = null, this.ctx = null), (i || r) && (this.stopAndCleanup(), this.requestUserMedia());
                }, o.prototype.componentWillUnmount = function() {
                  this.unmounted = !0, this.stopAndCleanup();
                }, o.stopMediaStream = function(e) {
                  e && (e.getVideoTracks && e.getAudioTracks ? (e.getVideoTracks().map(function(t) {
                    e.removeTrack(t), t.stop();
                  }), e.getAudioTracks().map(function(t) {
                    e.removeTrack(t), t.stop();
                  })) : e.stop());
                }, o.prototype.stopAndCleanup = function() {
                  var e = this.state;
                  e.hasUserMedia && (o.stopMediaStream(this.stream), e.src && window.URL.revokeObjectURL(e.src));
                }, o.prototype.getScreenshot = function(e) {
                  var t = this, i = t.state, r = t.props;
                  if (!i.hasUserMedia)
                    return null;
                  var p = this.getCanvas(e);
                  return p && p.toDataURL(r.screenshotFormat, r.screenshotQuality);
                }, o.prototype.getCanvas = function(e) {
                  var t = this, i = t.state, r = t.props;
                  if (!this.video || !i.hasUserMedia || !this.video.videoHeight)
                    return null;
                  if (!this.ctx) {
                    var p = this.video.videoWidth, c = this.video.videoHeight;
                    if (!this.props.forceScreenshotSourceSize) {
                      var u = p / c;
                      p = r.minScreenshotWidth || this.video.clientWidth, c = p / u, r.minScreenshotHeight && c < r.minScreenshotHeight && (c = r.minScreenshotHeight, p = c * u);
                    }
                    this.canvas = document.createElement("canvas"), this.canvas.width = (e == null ? void 0 : e.width) || p, this.canvas.height = (e == null ? void 0 : e.height) || c, this.ctx = this.canvas.getContext("2d");
                  }
                  var y = this, h = y.ctx, d = y.canvas;
                  return h && d && (d.width = (e == null ? void 0 : e.width) || d.width, d.height = (e == null ? void 0 : e.height) || d.height, r.mirrored && (h.translate(d.width, 0), h.scale(-1, 1)), h.imageSmoothingEnabled = r.imageSmoothing, h.drawImage(this.video, 0, 0, (e == null ? void 0 : e.width) || d.width, (e == null ? void 0 : e.height) || d.height), r.mirrored && (h.scale(-1, 1), h.translate(-d.width, 0))), d;
                }, o.prototype.requestUserMedia = function() {
                  var e = this, t = this.props, i = function(c, u) {
                    var y = {
                      video: typeof u < "u" ? u : !0
                    };
                    t.audio && (y.audio = typeof c < "u" ? c : !0), e.requestUserMediaId++;
                    var h = e.requestUserMediaId;
                    navigator.mediaDevices.getUserMedia(y).then(function(d) {
                      e.unmounted || h !== e.requestUserMediaId ? o.stopMediaStream(d) : e.handleUserMedia(null, d);
                    }).catch(function(d) {
                      e.handleUserMedia(d);
                    });
                  };
                  if ("mediaDevices" in navigator)
                    i(t.audioConstraints, t.videoConstraints);
                  else {
                    var r = function(c) {
                      return { optional: [{ sourceId: c }] };
                    }, p = function(c) {
                      var u = c.deviceId;
                      return typeof u == "string" ? u : Array.isArray(u) && u.length > 0 ? u[0] : typeof u == "object" && u.ideal ? u.ideal : null;
                    };
                    MediaStreamTrack.getSources(function(c) {
                      var u = null, y = null;
                      c.forEach(function(S) {
                        S.kind === "audio" ? u = S.id : S.kind === "video" && (y = S.id);
                      });
                      var h = p(t.audioConstraints);
                      h && (u = h);
                      var d = p(t.videoConstraints);
                      d && (y = d), i(r(u), r(y));
                    });
                  }
                }, o.prototype.handleUserMedia = function(e, t) {
                  var i = this.props;
                  if (e || !t) {
                    this.setState({ hasUserMedia: !1 }), i.onUserMediaError(e);
                    return;
                  }
                  this.stream = t;
                  try {
                    this.video && (this.video.srcObject = t), this.setState({ hasUserMedia: !0 });
                  } catch {
                    this.setState({
                      hasUserMedia: !0,
                      src: window.URL.createObjectURL(t)
                    });
                  }
                  i.onUserMedia(t);
                }, o.prototype.render = function() {
                  var e = this, t = this, i = t.state, r = t.props, p = r.audio;
                  r.forceScreenshotSourceSize;
                  var c = r.disablePictureInPicture;
                  r.onUserMedia, r.onUserMediaError, r.screenshotFormat, r.screenshotQuality, r.minScreenshotWidth, r.minScreenshotHeight, r.audioConstraints, r.videoConstraints, r.imageSmoothing;
                  var u = r.mirrored, y = r.style, h = y === void 0 ? {} : y, d = r.children, S = U(r, ["audio", "forceScreenshotSourceSize", "disablePictureInPicture", "onUserMedia", "onUserMediaError", "screenshotFormat", "screenshotQuality", "minScreenshotWidth", "minScreenshotHeight", "audioConstraints", "videoConstraints", "imageSmoothing", "mirrored", "style", "children"]), j = u ? v(v({}, h), { transform: (h.transform || "") + " scaleX(-1)" }) : h, C = {
                    getScreenshot: this.getScreenshot.bind(this)
                  };
                  return n.createElement(
                    n.Fragment,
                    null,
                    n.createElement("video", v({ autoPlay: !0, disablePictureInPicture: c, src: i.src, muted: !p, playsInline: !0, ref: function(x) {
                      e.video = x;
                    }, style: j }, S)),
                    d && d(C)
                  );
                }, o.defaultProps = {
                  audio: !1,
                  disablePictureInPicture: !1,
                  forceScreenshotSourceSize: !1,
                  imageSmoothing: !0,
                  mirrored: !1,
                  onUserMedia: function() {
                  },
                  onUserMediaError: function() {
                  },
                  screenshotFormat: "image/webp",
                  screenshotQuality: 0.92
                }, o;
              }(n.Component)
            );
            l.default = P;
          }
        ),
        /***/
        react: (
          /*!**************************************************************************************!*\
            !*** external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"} ***!
            \**************************************************************************************/
          /*! no static exports found */
          /***/
          function(g, l) {
            g.exports = m;
          }
        )
        /******/
      }).default
    );
  });
})(_);
var w = _.exports;
const T = /* @__PURE__ */ E(w), L = /* @__PURE__ */ A({
  __proto__: null,
  default: T
}, [w]);
export {
  L as r
};
