@shivantra/react-web-camera 1.0.0 β†’ 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # WebCamera React Component πŸ“Έ
1
+ # React Web Camera
2
2
 
3
3
  A lightweight and flexible React component for capturing images from the user’s camera (front or back) with support for `jpeg`, `png`, and `webp` formats. Built with modern React (`hooks` + `forwardRef`) and works on both desktop and mobile browsers.
4
4
 
5
- ## πŸ“‘ Table of Contents
5
+ ## Table of Contents
6
6
 
7
7
  - [Why?](#why-)
8
8
  - [Our Solution](#our-solution-)
@@ -21,7 +21,7 @@ A lightweight and flexible React component for capturing images from the user’
21
21
 
22
22
  ---
23
23
 
24
- ## Why? ❓
24
+ ## Why?
25
25
 
26
26
  Capturing multiple images from a webcam is a common need in modern web apps, especially Progressive Web Apps (PWAs).
27
27
  Existing solutions are often:
@@ -43,7 +43,7 @@ This creates a poor user experience for apps needing **multi-photo sessions** (f
43
43
 
44
44
  ---
45
45
 
46
- ## Our Solution πŸ’‘
46
+ ## Our Solution
47
47
 
48
48
  `react-web-camera` provides a headless, platform-independent React component that gives you full control over your UI. It handles the complex logic of accessing the webcam, capturing multiple images, and managing state, while you focus on styling and user experience.
49
49
 
@@ -55,7 +55,7 @@ This makes it:
55
55
 
56
56
  ---
57
57
 
58
- ## Features ✨
58
+ ## Features
59
59
 
60
60
  - **πŸ“· Front & Back Camera Support** – Easily capture images from both cameras.
61
61
  - **πŸ–Ό Multiple Image Formats** – Export images as jpeg, png, or webp.
@@ -68,22 +68,26 @@ This makes it:
68
68
 
69
69
  ---
70
70
 
71
- ## Installation πŸ“¦
71
+ ## Installation
72
72
 
73
73
  ```bash
74
74
  # If using npm
75
75
  npm install @shivantra/react-web-camera
76
+ ```
76
77
 
78
+ ```bash
77
79
  # Or with yarn
78
80
  yarn add @shivantra/react-web-camera
81
+ ```
79
82
 
83
+ ```bash
80
84
  # Or with pnpm
81
85
  pnpm add @shivantra/react-web-camera
82
86
  ```
83
87
 
84
88
  ---
85
89
 
86
- ## Usage πŸ› 
90
+ ## Usage
87
91
 
88
92
  - **Basic Example**
89
93
 
@@ -228,7 +232,7 @@ export default function PWAApp() {
228
232
 
229
233
  ---
230
234
 
231
- ## Ref Methods πŸ–
235
+ ## Ref Methods
232
236
 
233
237
  Access these methods via `ref`:
234
238
 
@@ -240,7 +244,7 @@ Access these methods via `ref`:
240
244
 
241
245
  ---
242
246
 
243
- ## Notes ⚠️
247
+ ## Notes
244
248
 
245
249
  - On mobile devices, some browsers may require HTTPS to access the camera.
246
250
  - Ensure the user grants camera permissions; otherwise, the component will throw an error.
@@ -248,13 +252,13 @@ Access these methods via `ref`:
248
252
 
249
253
  ---
250
254
 
251
- ## License πŸ“„
255
+ ## License
252
256
 
253
257
  MIT License Β© 2025 Shivantra Solutions Private Limited
254
258
 
255
259
  ---
256
260
 
257
- ## Contact πŸ“§
261
+ ## Contact
258
262
 
259
263
  For more details about our projects, services, or any general information regarding **react-web-camera**, feel free to reach out to us. We are here to provide support and answer any questions you may have. Below are the best ways to contact our team:
260
264
 
@@ -17,5 +17,6 @@ export type WebCameraHandler = {
17
17
  capture: () => Promise<File | null>;
18
18
  switch: (facingMode?: FacingMode) => Promise<void>;
19
19
  getMode: () => CaptureMode;
20
+ stop: () => void;
20
21
  };
21
22
  export declare const WebCamera: import('react').ForwardRefExoticComponent<WebCameraProps & import('react').RefAttributes<WebCameraHandler>>;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react");var z={exports:{}},x={};/**
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("react");var G={exports:{}},N={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Z;function te(){if(Z)return x;Z=1;var b=Symbol.for("react.transitional.element"),h=Symbol.for("react.fragment");function k(g,o,i){var _=null;if(i!==void 0&&(_=""+i),o.key!==void 0&&(_=""+o.key),"key"in o){i={};for(var R in o)R!=="key"&&(i[R]=o[R])}else i=o;return o=i.ref,{$$typeof:b,type:g,key:_,ref:o!==void 0?o:null,props:i}}return x.Fragment=h,x.jsx=k,x.jsxs=k,x}var C={};/**
9
+ */var Q;function te(){if(Q)return N;Q=1;var v=Symbol.for("react.transitional.element"),h=Symbol.for("react.fragment");function k(g,o,l){var b=null;if(l!==void 0&&(b=""+l),o.key!==void 0&&(b=""+o.key),"key"in o){l={};for(var R in o)R!=="key"&&(l[R]=o[R])}else l=o;return o=l.ref,{$$typeof:v,type:g,key:b,ref:o!==void 0?o:null,props:l}}return N.Fragment=h,N.jsx=k,N.jsxs=k,N}var M={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,9 +14,9 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Q;function ne(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&function(){function b(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===I?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case P:return"Fragment";case W:return"Profiler";case A:return"StrictMode";case t:return"Suspense";case w:return"SuspenseList";case D:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case T:return"Portal";case M:return(e.displayName||"Context")+".Provider";case N:return(e._context.displayName||"Context")+".Consumer";case a:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case u:return r=e.displayName||null,r!==null?r:b(e.type)||"Memo";case m:r=e._payload,e=e._init;try{return b(e(r))}catch{}}return null}function h(e){return""+e}function k(e){try{h(e);var r=!1}catch{r=!0}if(r){r=console;var n=r.error,s=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",s),h(e)}}function g(e){if(e===P)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===m)return"<...>";try{var r=b(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function o(){var e=O.A;return e===null?null:e.getOwner()}function i(){return Error("react-stack-top-frame")}function _(e){if(Y.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function R(e,r){function n(){G||(G=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function f(){var e=b(this.type);return J[e]||(J[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function $(e,r,n,s,p,v,L,U){return n=v.ref,e={$$typeof:y,type:e,key:r,props:v,_owner:p},(n!==void 0?n:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:f}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:L}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,r,n,s,p,v,L,U){var c=r.children;if(c!==void 0)if(s)if(ee(c)){for(s=0;s<c.length;s++)j(c[s]);Object.freeze&&Object.freeze(c)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else j(c);if(Y.call(r,"key")){c=b(e);var S=Object.keys(r).filter(function(re){return re!=="key"});s=0<S.length?"{key: someKey, "+S.join(": ..., ")+": ...}":"{key: someKey}",B[c+s]||(S=0<S.length?"{"+S.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var K;function ne(){return K||(K=1,process.env.NODE_ENV!=="production"&&function(){function v(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Y?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case A:return"Fragment";case W:return"Profiler";case x:return"StrictMode";case a:return"Suspense";case n:return"SuspenseList";case _:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case p:return"Portal";case O:return(e.displayName||"Context")+".Provider";case D:return(e._context.displayName||"Context")+".Consumer";case I:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case w:return r=e.displayName||null,r!==null?r:v(e.type)||"Memo";case i:r=e._payload,e=e._init;try{return v(e(r))}catch{}}return null}function h(e){return""+e}function k(e){try{h(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,s=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",s),h(e)}}function g(e){if(e===A)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===i)return"<...>";try{var r=v(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function o(){var e=S.A;return e===null?null:e.getOwner()}function l(){return Error("react-stack-top-frame")}function b(e){if(C.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function R(e,r){function t(){J||(J=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function f(){var e=v(this.type);return X[e]||(X[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function $(e,r,t,s,T,m,U,V){return t=m.ref,e={$$typeof:P,type:e,key:r,props:m,_owner:T},(t!==void 0?t:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:f}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,r,t,s,T,m,U,V){var c=r.children;if(c!==void 0)if(s)if(F(c)){for(s=0;s<c.length;s++)y(c[s]);Object.freeze&&Object.freeze(c)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else y(c);if(C.call(r,"key")){c=v(e);var j=Object.keys(r).filter(function(re){return re!=="key"});s=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",Z[c+s]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,s,c,S,c),B[c+s]=!0)}if(c=null,n!==void 0&&(k(n),c=""+n),_(r)&&(k(r.key),c=""+r.key),"key"in r){n={};for(var V in r)V!=="key"&&(n[V]=r[V])}else n=r;return c&&R(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),$(e,c,v,p,o(),n,L,U)}function j(e){typeof e=="object"&&e!==null&&e.$$typeof===y&&e._store&&(e._store.validated=1)}var E=l,y=Symbol.for("react.transitional.element"),T=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),M=Symbol.for("react.context"),a=Symbol.for("react.forward_ref"),t=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),u=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),D=Symbol.for("react.activity"),I=Symbol.for("react.client.reference"),O=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=Object.prototype.hasOwnProperty,ee=Array.isArray,F=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var G,J={},X=E.react_stack_bottom_frame.bind(E,i)(),H=F(g(i)),B={};C.Fragment=P,C.jsx=function(e,r,n,s,p){var v=1e4>O.recentlyCreatedOwnerStacks++;return d(e,r,n,!1,s,p,v?Error("react-stack-top-frame"):X,v?F(g(e)):H)},C.jsxs=function(e,r,n,s,p){var v=1e4>O.recentlyCreatedOwnerStacks++;return d(e,r,n,!0,s,p,v?Error("react-stack-top-frame"):X,v?F(g(e)):H)}}()),C}process.env.NODE_ENV==="production"?z.exports=te():z.exports=ne();var q=z.exports;const ae={back:"environment",front:"user"},K=l.forwardRef(({className:b,style:h,videoClassName:k,videoStyle:g,getFileName:o,captureMode:i="back",captureType:_="jpeg",captureQuality:R=.8,onError:f},$)=>{const d=l.useRef(null),j=l.useRef(null),[E,y]=l.useState(null),[T,P]=l.useState(ae[i]),[A,W]=l.useState([]),N=l.useCallback(async()=>{const a=d.current,t=j.current;return!a||!t||a.readyState<2?null:new Promise(w=>{const u=t.getContext("2d"),m=a.videoWidth||640,D=a.videoHeight||480;t.width=m,t.height=D,u.drawImage(a,0,0,m,D);const I=`image/${_}`;t.toBlob(async O=>{if(!O)return;const Y=new File([O],(o==null?void 0:o())??`capture-${Date.now()}.${_}`,{type:I,lastModified:Date.now()});w(Y)},I,R)})},[_,R,o]),M=l.useCallback(async()=>{E&&(E.getTracks().forEach(t=>t.stop()),d.current&&(d.current.srcObject=null));const a=T==="user"?"environment":"user";P(a);try{let t;if(A.length>=2){const u=A.find(m=>a==="user"?m.label.toLowerCase().includes("front"):m.label.toLowerCase().includes("back"));t=u?{video:{deviceId:{exact:u.deviceId}}}:{video:{facingMode:{ideal:a}}}}else t={video:{facingMode:{ideal:a}}};const w=await navigator.mediaDevices.getUserMedia(t);d.current&&(d.current.srcObject=w),y(w)}catch(t){f==null||f(t)}},[E,T,A,f]);return l.useImperativeHandle($,()=>({capture:N,switch:M,getMode:()=>T==="environment"?"back":"front"}),[T,N,M]),l.useEffect(()=>{let a;const t=d.current;return(async()=>{try{const u=await navigator.mediaDevices.enumerateDevices();W(u.filter(m=>m.kind==="videoinput")),a=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:T}}}),t&&(t.srcObject=a,t.onloadedmetadata=()=>t==null?void 0:t.play()),y(a)}catch(u){f==null||f(u)}})(),()=>{a==null||a.getTracks().forEach(u=>u.stop()),t&&(t.srcObject=null)}},[T,f]),q.jsxs("div",{className:b,style:h,children:[q.jsx("video",{ref:d,className:k,autoPlay:!0,playsInline:!0,muted:!0,style:{...g,display:"block",objectFit:"cover",height:"100%",width:"100%"},children:"Video stream not available."}),q.jsx("canvas",{ref:j,style:{display:"none"}})]})});exports.WebCamera=K;exports.default=K;
22
+ <%s key={someKey} {...props} />`,s,c,j,c),Z[c+s]=!0)}if(c=null,t!==void 0&&(k(t),c=""+t),b(r)&&(k(r.key),c=""+r.key),"key"in r){t={};for(var q in r)q!=="key"&&(t[q]=r[q])}else t=r;return c&&R(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),$(e,c,m,T,o(),t,U,V)}function y(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var E=u,P=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),W=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),O=Symbol.for("react.context"),I=Symbol.for("react.forward_ref"),a=Symbol.for("react.suspense"),n=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),i=Symbol.for("react.lazy"),_=Symbol.for("react.activity"),Y=Symbol.for("react.client.reference"),S=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,C=Object.prototype.hasOwnProperty,F=Array.isArray,L=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var J,X={},H=E.react_stack_bottom_frame.bind(E,l)(),B=L(g(l)),Z={};M.Fragment=A,M.jsx=function(e,r,t,s,T){var m=1e4>S.recentlyCreatedOwnerStacks++;return d(e,r,t,!1,s,T,m?Error("react-stack-top-frame"):H,m?L(g(e)):B)},M.jsxs=function(e,r,t,s,T){var m=1e4>S.recentlyCreatedOwnerStacks++;return d(e,r,t,!0,s,T,m?Error("react-stack-top-frame"):H,m?L(g(e)):B)}}()),M}process.env.NODE_ENV==="production"?G.exports=te():G.exports=ne();var z=G.exports;const ae={back:"environment",front:"user"},ee=u.forwardRef(({className:v,style:h,videoClassName:k,videoStyle:g,getFileName:o,captureMode:l="back",captureType:b="jpeg",captureQuality:R=.8,onError:f},$)=>{const d=u.useRef(null),y=u.useRef(null),[E,P]=u.useState(null),[p,A]=u.useState(ae[l]),[x,W]=u.useState([]),D=u.useCallback(async()=>{const a=d.current,n=y.current;return!a||!n||a.readyState<2?null:new Promise(w=>{const i=n.getContext("2d"),_=a.videoWidth||640,Y=a.videoHeight||480;n.width=_,n.height=Y,i.drawImage(a,0,0,_,Y);const S=`image/${b}`;n.toBlob(async C=>{if(!C)return;const F=new File([C],(o==null?void 0:o())??`capture-${Date.now()}.${b}`,{type:S,lastModified:Date.now()});w(F)},S,R)})},[b,R,o]),O=u.useCallback(()=>{E&&(E.getTracks().forEach(a=>a.stop()),d.current&&(d.current.srcObject=null))},[E]),I=u.useCallback(async()=>{O();const a=p==="user"?"environment":"user";A(a);try{let n;if(x.length>=2){const i=x.find(_=>a==="user"?_.label.toLowerCase().includes("front"):_.label.toLowerCase().includes("back"));n=i?{video:{deviceId:{exact:i.deviceId}}}:{video:{facingMode:{ideal:a}}}}else n={video:{facingMode:{ideal:a}}};const w=await navigator.mediaDevices.getUserMedia(n);d.current&&(d.current.srcObject=w),P(w)}catch(n){f==null||f(n)}},[O,p,x,f]);return u.useImperativeHandle($,()=>({capture:D,stop:O,switch:I,getMode:()=>p==="environment"?"back":"front"}),[p,D,O,I]),u.useEffect(()=>{let a;const n=d.current;return(async()=>{try{const i=await navigator.mediaDevices.enumerateDevices();W(i.filter(_=>_.kind==="videoinput")),a=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:p}}}),n&&(n.srcObject=a,n.onloadedmetadata=()=>n==null?void 0:n.play()),P(a)}catch(i){f==null||f(i)}})(),()=>{a==null||a.getTracks().forEach(i=>i.stop()),n&&(n.srcObject=null)}},[p,f]),z.jsxs("div",{className:v,style:h,children:[z.jsx("video",{ref:d,className:k,autoPlay:!0,playsInline:!0,muted:!0,style:{...g,display:"block",objectFit:"cover",height:"100%",width:"100%"},children:"Video stream not available."}),z.jsx("canvas",{ref:y,style:{display:"none"}})]})});exports.WebCamera=ee;exports.default=ee;
@@ -1,5 +1,5 @@
1
- import ne, { forwardRef as ae, useRef as Z, useState as V, useCallback as Q, useImperativeHandle as oe, useEffect as se } from "react";
2
- var q = { exports: {} }, P = {};
1
+ import ne, { forwardRef as ae, useRef as K, useState as z, useCallback as q, useImperativeHandle as oe, useEffect as se } from "react";
2
+ var J = { exports: {} }, C = {};
3
3
  /**
4
4
  * @license React
5
5
  * react-jsx-runtime.production.js
@@ -9,29 +9,29 @@ var q = { exports: {} }, P = {};
9
9
  * This source code is licensed under the MIT license found in the
10
10
  * LICENSE file in the root directory of this source tree.
11
11
  */
12
- var K;
12
+ var ee;
13
13
  function ce() {
14
- if (K) return P;
15
- K = 1;
16
- var v = Symbol.for("react.transitional.element"), g = Symbol.for("react.fragment");
17
- function T(k, o, i) {
18
- var b = null;
19
- if (i !== void 0 && (b = "" + i), o.key !== void 0 && (b = "" + o.key), "key" in o) {
20
- i = {};
14
+ if (ee) return C;
15
+ ee = 1;
16
+ var m = Symbol.for("react.transitional.element"), g = Symbol.for("react.fragment");
17
+ function T(k, o, l) {
18
+ var v = null;
19
+ if (l !== void 0 && (v = "" + l), o.key !== void 0 && (v = "" + o.key), "key" in o) {
20
+ l = {};
21
21
  for (var R in o)
22
- R !== "key" && (i[R] = o[R]);
23
- } else i = o;
24
- return o = i.ref, {
25
- $$typeof: v,
22
+ R !== "key" && (l[R] = o[R]);
23
+ } else l = o;
24
+ return o = l.ref, {
25
+ $$typeof: m,
26
26
  type: k,
27
- key: b,
27
+ key: v,
28
28
  ref: o !== void 0 ? o : null,
29
- props: i
29
+ props: l
30
30
  };
31
31
  }
32
- return P.Fragment = g, P.jsx = T, P.jsxs = T, P;
32
+ return C.Fragment = g, C.jsx = T, C.jsxs = T, C;
33
33
  }
34
- var x = {};
34
+ var N = {};
35
35
  /**
36
36
  * @license React
37
37
  * react-jsx-runtime.development.js
@@ -41,26 +41,26 @@ var x = {};
41
41
  * This source code is licensed under the MIT license found in the
42
42
  * LICENSE file in the root directory of this source tree.
43
43
  */
44
- var ee;
44
+ var re;
45
45
  function ie() {
46
- return ee || (ee = 1, process.env.NODE_ENV !== "production" && function() {
47
- function v(e) {
46
+ return re || (re = 1, process.env.NODE_ENV !== "production" && function() {
47
+ function m(e) {
48
48
  if (e == null) return null;
49
49
  if (typeof e == "function")
50
- return e.$$typeof === M ? null : e.displayName || e.name || null;
50
+ return e.$$typeof === I ? null : e.displayName || e.name || null;
51
51
  if (typeof e == "string") return e;
52
52
  switch (e) {
53
- case S:
53
+ case A:
54
54
  return "Fragment";
55
55
  case $:
56
56
  return "Profiler";
57
- case A:
57
+ case P:
58
58
  return "StrictMode";
59
- case t:
59
+ case a:
60
60
  return "Suspense";
61
- case w:
61
+ case n:
62
62
  return "SuspenseList";
63
- case D:
63
+ case b:
64
64
  return "Activity";
65
65
  }
66
66
  if (typeof e == "object")
@@ -69,19 +69,19 @@ function ie() {
69
69
  ), e.$$typeof) {
70
70
  case E:
71
71
  return "Portal";
72
- case N:
72
+ case h:
73
73
  return (e.displayName || "Context") + ".Provider";
74
- case C:
74
+ case D:
75
75
  return (e._context.displayName || "Context") + ".Consumer";
76
- case a:
76
+ case M:
77
77
  var r = e.render;
78
78
  return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case l:
80
- return r = e.displayName || null, r !== null ? r : v(e.type) || "Memo";
81
- case d:
79
+ case w:
80
+ return r = e.displayName || null, r !== null ? r : m(e.type) || "Memo";
81
+ case i:
82
82
  r = e._payload, e = e._init;
83
83
  try {
84
- return v(e(r));
84
+ return m(e(r));
85
85
  } catch {
86
86
  }
87
87
  }
@@ -99,8 +99,8 @@ function ie() {
99
99
  }
100
100
  if (r) {
101
101
  r = console;
102
- var n = r.error, s = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
- return n.call(
102
+ var t = r.error, s = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
+ return t.call(
104
104
  r,
105
105
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
106
  s
@@ -108,56 +108,56 @@ function ie() {
108
108
  }
109
109
  }
110
110
  function k(e) {
111
- if (e === S) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === d)
111
+ if (e === A) return "<>";
112
+ if (typeof e == "object" && e !== null && e.$$typeof === i)
113
113
  return "<...>";
114
114
  try {
115
- var r = v(e);
115
+ var r = m(e);
116
116
  return r ? "<" + r + ">" : "<...>";
117
117
  } catch {
118
118
  return "<...>";
119
119
  }
120
120
  }
121
121
  function o() {
122
- var e = h.A;
122
+ var e = O.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
- function i() {
125
+ function l() {
126
126
  return Error("react-stack-top-frame");
127
127
  }
128
- function b(e) {
129
- if (I.call(e, "key")) {
128
+ function v(e) {
129
+ if (x.call(e, "key")) {
130
130
  var r = Object.getOwnPropertyDescriptor(e, "key").get;
131
131
  if (r && r.isReactWarning) return !1;
132
132
  }
133
133
  return e.key !== void 0;
134
134
  }
135
135
  function R(e, r) {
136
- function n() {
137
- G || (G = !0, console.error(
136
+ function t() {
137
+ X || (X = !0, console.error(
138
138
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
139
139
  r
140
140
  ));
141
141
  }
142
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
143
- get: n,
142
+ t.isReactWarning = !0, Object.defineProperty(e, "key", {
143
+ get: t,
144
144
  configurable: !0
145
145
  });
146
146
  }
147
147
  function u() {
148
- var e = v(this.type);
149
- return J[e] || (J[e] = !0, console.error(
148
+ var e = m(this.type);
149
+ return H[e] || (H[e] = !0, console.error(
150
150
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
151
151
  )), e = this.props.ref, e !== void 0 ? e : null;
152
152
  }
153
- function Y(e, r, n, s, p, m, L, U) {
154
- return n = m.ref, e = {
155
- $$typeof: y,
153
+ function Y(e, r, t, s, p, d, U, W) {
154
+ return t = d.ref, e = {
155
+ $$typeof: S,
156
156
  type: e,
157
157
  key: r,
158
- props: m,
158
+ props: d,
159
159
  _owner: p
160
- }, (n !== void 0 ? n : null) !== null ? Object.defineProperty(e, "ref", {
160
+ }, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
161
161
  enumerable: !1,
162
162
  get: u
163
163
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
@@ -174,33 +174,33 @@ function ie() {
174
174
  configurable: !1,
175
175
  enumerable: !1,
176
176
  writable: !0,
177
- value: L
177
+ value: U
178
178
  }), Object.defineProperty(e, "_debugTask", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: U
182
+ value: W
183
183
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
184
  }
185
- function f(e, r, n, s, p, m, L, U) {
185
+ function f(e, r, t, s, p, d, U, W) {
186
186
  var c = r.children;
187
187
  if (c !== void 0)
188
188
  if (s)
189
- if (re(c)) {
189
+ if (F(c)) {
190
190
  for (s = 0; s < c.length; s++)
191
- j(c[s]);
191
+ y(c[s]);
192
192
  Object.freeze && Object.freeze(c);
193
193
  } else
194
194
  console.error(
195
195
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
196
196
  );
197
- else j(c);
198
- if (I.call(r, "key")) {
199
- c = v(e);
200
- var O = Object.keys(r).filter(function(te) {
197
+ else y(c);
198
+ if (x.call(r, "key")) {
199
+ c = m(e);
200
+ var j = Object.keys(r).filter(function(te) {
201
201
  return te !== "key";
202
202
  });
203
- s = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", B[c + s] || (O = 0 < O.length ? "{" + O.join(": ..., ") + ": ...}" : "{}", console.error(
203
+ s = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", Q[c + s] || (j = 0 < j.length ? "{" + j.join(": ..., ") + ": ...}" : "{}", console.error(
204
204
  `A props object containing a "key" prop is being spread into JSX:
205
205
  let props = %s;
206
206
  <%s {...props} />
@@ -209,33 +209,33 @@ React keys must be passed directly to JSX without using spread:
209
209
  <%s key={someKey} {...props} />`,
210
210
  s,
211
211
  c,
212
- O,
212
+ j,
213
213
  c
214
- ), B[c + s] = !0);
214
+ ), Q[c + s] = !0);
215
215
  }
216
- if (c = null, n !== void 0 && (T(n), c = "" + n), b(r) && (T(r.key), c = "" + r.key), "key" in r) {
217
- n = {};
218
- for (var W in r)
219
- W !== "key" && (n[W] = r[W]);
220
- } else n = r;
216
+ if (c = null, t !== void 0 && (T(t), c = "" + t), v(r) && (T(r.key), c = "" + r.key), "key" in r) {
217
+ t = {};
218
+ for (var V in r)
219
+ V !== "key" && (t[V] = r[V]);
220
+ } else t = r;
221
221
  return c && R(
222
- n,
222
+ t,
223
223
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
224
224
  ), Y(
225
225
  e,
226
226
  c,
227
- m,
227
+ d,
228
228
  p,
229
229
  o(),
230
- n,
231
- L,
232
- U
230
+ t,
231
+ U,
232
+ W
233
233
  );
234
234
  }
235
- function j(e) {
236
- typeof e == "object" && e !== null && e.$$typeof === y && e._store && (e._store.validated = 1);
235
+ function y(e) {
236
+ typeof e == "object" && e !== null && e.$$typeof === S && e._store && (e._store.validated = 1);
237
237
  }
238
- var _ = ne, y = Symbol.for("react.transitional.element"), E = Symbol.for("react.portal"), S = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), $ = Symbol.for("react.profiler"), C = Symbol.for("react.consumer"), N = Symbol.for("react.context"), a = Symbol.for("react.forward_ref"), t = Symbol.for("react.suspense"), w = Symbol.for("react.suspense_list"), l = Symbol.for("react.memo"), d = Symbol.for("react.lazy"), D = Symbol.for("react.activity"), M = Symbol.for("react.client.reference"), h = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, I = Object.prototype.hasOwnProperty, re = Array.isArray, F = console.createTask ? console.createTask : function() {
238
+ var _ = ne, S = Symbol.for("react.transitional.element"), E = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), P = Symbol.for("react.strict_mode"), $ = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), h = Symbol.for("react.context"), M = Symbol.for("react.forward_ref"), a = Symbol.for("react.suspense"), n = Symbol.for("react.suspense_list"), w = Symbol.for("react.memo"), i = Symbol.for("react.lazy"), b = Symbol.for("react.activity"), I = Symbol.for("react.client.reference"), O = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, F = Array.isArray, L = console.createTask ? console.createTask : function() {
239
239
  return null;
240
240
  };
241
241
  _ = {
@@ -243,123 +243,126 @@ React keys must be passed directly to JSX without using spread:
243
243
  return e();
244
244
  }
245
245
  };
246
- var G, J = {}, X = _.react_stack_bottom_frame.bind(
246
+ var X, H = {}, B = _.react_stack_bottom_frame.bind(
247
247
  _,
248
- i
249
- )(), H = F(k(i)), B = {};
250
- x.Fragment = S, x.jsx = function(e, r, n, s, p) {
251
- var m = 1e4 > h.recentlyCreatedOwnerStacks++;
248
+ l
249
+ )(), Z = L(k(l)), Q = {};
250
+ N.Fragment = A, N.jsx = function(e, r, t, s, p) {
251
+ var d = 1e4 > O.recentlyCreatedOwnerStacks++;
252
252
  return f(
253
253
  e,
254
254
  r,
255
- n,
255
+ t,
256
256
  !1,
257
257
  s,
258
258
  p,
259
- m ? Error("react-stack-top-frame") : X,
260
- m ? F(k(e)) : H
259
+ d ? Error("react-stack-top-frame") : B,
260
+ d ? L(k(e)) : Z
261
261
  );
262
- }, x.jsxs = function(e, r, n, s, p) {
263
- var m = 1e4 > h.recentlyCreatedOwnerStacks++;
262
+ }, N.jsxs = function(e, r, t, s, p) {
263
+ var d = 1e4 > O.recentlyCreatedOwnerStacks++;
264
264
  return f(
265
265
  e,
266
266
  r,
267
- n,
267
+ t,
268
268
  !0,
269
269
  s,
270
270
  p,
271
- m ? Error("react-stack-top-frame") : X,
272
- m ? F(k(e)) : H
271
+ d ? Error("react-stack-top-frame") : B,
272
+ d ? L(k(e)) : Z
273
273
  );
274
274
  };
275
- }()), x;
275
+ }()), N;
276
276
  }
277
- process.env.NODE_ENV === "production" ? q.exports = ce() : q.exports = ie();
278
- var z = q.exports;
277
+ process.env.NODE_ENV === "production" ? J.exports = ce() : J.exports = ie();
278
+ var G = J.exports;
279
279
  const le = {
280
280
  back: "environment",
281
281
  front: "user"
282
282
  }, fe = ae(
283
283
  ({
284
- className: v,
284
+ className: m,
285
285
  style: g,
286
286
  videoClassName: T,
287
287
  videoStyle: k,
288
288
  getFileName: o,
289
- captureMode: i = "back",
290
- captureType: b = "jpeg",
289
+ captureMode: l = "back",
290
+ captureType: v = "jpeg",
291
291
  captureQuality: R = 0.8,
292
292
  onError: u
293
293
  }, Y) => {
294
- const f = Z(null), j = Z(null), [_, y] = V(null), [E, S] = V(
295
- le[i]
296
- ), [A, $] = V([]), C = Q(async () => {
297
- const a = f.current, t = j.current;
298
- return !a || !t || a.readyState < 2 ? null : new Promise((w) => {
299
- const l = t.getContext("2d"), d = a.videoWidth || 640, D = a.videoHeight || 480;
300
- t.width = d, t.height = D, l.drawImage(a, 0, 0, d, D);
301
- const M = `image/${b}`;
302
- t.toBlob(
303
- async (h) => {
304
- if (!h) return;
305
- const I = new File(
306
- [h],
307
- (o == null ? void 0 : o()) ?? `capture-${Date.now()}.${b}`,
294
+ const f = K(null), y = K(null), [_, S] = z(null), [E, A] = z(
295
+ le[l]
296
+ ), [P, $] = z([]), D = q(async () => {
297
+ const a = f.current, n = y.current;
298
+ return !a || !n || a.readyState < 2 ? null : new Promise((w) => {
299
+ const i = n.getContext("2d"), b = a.videoWidth || 640, I = a.videoHeight || 480;
300
+ n.width = b, n.height = I, i.drawImage(a, 0, 0, b, I);
301
+ const O = `image/${v}`;
302
+ n.toBlob(
303
+ async (x) => {
304
+ if (!x) return;
305
+ const F = new File(
306
+ [x],
307
+ (o == null ? void 0 : o()) ?? `capture-${Date.now()}.${v}`,
308
308
  {
309
- type: M,
309
+ type: O,
310
310
  lastModified: Date.now()
311
311
  }
312
312
  );
313
- w(I);
313
+ w(F);
314
314
  },
315
- M,
315
+ O,
316
316
  R
317
317
  );
318
318
  });
319
- }, [b, R, o]), N = Q(async () => {
320
- _ && (_.getTracks().forEach((t) => t.stop()), f.current && (f.current.srcObject = null));
319
+ }, [v, R, o]), h = q(() => {
320
+ _ && (_.getTracks().forEach((a) => a.stop()), f.current && (f.current.srcObject = null));
321
+ }, [_]), M = q(async () => {
322
+ h();
321
323
  const a = E === "user" ? "environment" : "user";
322
- S(a);
324
+ A(a);
323
325
  try {
324
- let t;
325
- if (A.length >= 2) {
326
- const l = A.find(
327
- (d) => a === "user" ? d.label.toLowerCase().includes("front") : d.label.toLowerCase().includes("back")
326
+ let n;
327
+ if (P.length >= 2) {
328
+ const i = P.find(
329
+ (b) => a === "user" ? b.label.toLowerCase().includes("front") : b.label.toLowerCase().includes("back")
328
330
  );
329
- t = l ? { video: { deviceId: { exact: l.deviceId } } } : { video: { facingMode: { ideal: a } } };
331
+ n = i ? { video: { deviceId: { exact: i.deviceId } } } : { video: { facingMode: { ideal: a } } };
330
332
  } else
331
- t = { video: { facingMode: { ideal: a } } };
332
- const w = await navigator.mediaDevices.getUserMedia(t);
333
- f.current && (f.current.srcObject = w), y(w);
334
- } catch (t) {
335
- u == null || u(t);
333
+ n = { video: { facingMode: { ideal: a } } };
334
+ const w = await navigator.mediaDevices.getUserMedia(n);
335
+ f.current && (f.current.srcObject = w), S(w);
336
+ } catch (n) {
337
+ u == null || u(n);
336
338
  }
337
- }, [_, E, A, u]);
339
+ }, [h, E, P, u]);
338
340
  return oe(
339
341
  Y,
340
342
  () => ({
341
- capture: C,
342
- switch: N,
343
+ capture: D,
344
+ stop: h,
345
+ switch: M,
343
346
  getMode: () => E === "environment" ? "back" : "front"
344
347
  }),
345
- [E, C, N]
348
+ [E, D, h, M]
346
349
  ), se(() => {
347
350
  let a;
348
- const t = f.current;
351
+ const n = f.current;
349
352
  return (async () => {
350
353
  try {
351
- const l = await navigator.mediaDevices.enumerateDevices();
352
- $(l.filter((d) => d.kind === "videoinput")), a = await navigator.mediaDevices.getUserMedia({
354
+ const i = await navigator.mediaDevices.enumerateDevices();
355
+ $(i.filter((b) => b.kind === "videoinput")), a = await navigator.mediaDevices.getUserMedia({
353
356
  video: { facingMode: { ideal: E } }
354
- }), t && (t.srcObject = a, t.onloadedmetadata = () => t == null ? void 0 : t.play()), y(a);
355
- } catch (l) {
356
- u == null || u(l);
357
+ }), n && (n.srcObject = a, n.onloadedmetadata = () => n == null ? void 0 : n.play()), S(a);
358
+ } catch (i) {
359
+ u == null || u(i);
357
360
  }
358
361
  })(), () => {
359
- a == null || a.getTracks().forEach((l) => l.stop()), t && (t.srcObject = null);
362
+ a == null || a.getTracks().forEach((i) => i.stop()), n && (n.srcObject = null);
360
363
  };
361
- }, [E, u]), /* @__PURE__ */ z.jsxs("div", { className: v, style: g, children: [
362
- /* @__PURE__ */ z.jsx(
364
+ }, [E, u]), /* @__PURE__ */ G.jsxs("div", { className: m, style: g, children: [
365
+ /* @__PURE__ */ G.jsx(
363
366
  "video",
364
367
  {
365
368
  ref: f,
@@ -377,7 +380,7 @@ const le = {
377
380
  children: "Video stream not available."
378
381
  }
379
382
  ),
380
- /* @__PURE__ */ z.jsx("canvas", { ref: j, style: { display: "none" } })
383
+ /* @__PURE__ */ G.jsx("canvas", { ref: y, style: { display: "none" } })
381
384
  ] });
382
385
  }
383
386
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivantra/react-web-camera",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Web camera component for React (by Shivantra)",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,