streamlit-nightly 1.42.1.dev20250211__py2.py3-none-any.whl → 1.42.1.dev20250212__py2.py3-none-any.whl
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.
- streamlit/commands/page_config.py +1 -1
- streamlit/elements/arrow.py +11 -0
- streamlit/elements/widgets/data_editor.py +22 -6
- streamlit/proto/Arrow_pb2.py +8 -8
- streamlit/proto/Arrow_pb2.pyi +7 -2
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{FileDownload.esm.Cynb6pHv.js → FileDownload.esm.gmDYBMnS.js} +1 -1
- streamlit/static/static/js/{FileDropzone.CVp7XX9M.js → FileDropzone.BhS2dkwO.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.0-LU4kzK.js → FormClearHelper.BjdyfMQx.js} +1 -1
- streamlit/static/static/js/{Hooks.CO99RwN4.js → Hooks.BKB06vs4.js} +1 -1
- streamlit/static/static/js/{InputInstructions.BM7jV9sg.js → InputInstructions.BEaJdOY6.js} +1 -1
- streamlit/static/static/js/{ProgressBar.B-igBN-q.js → ProgressBar.DycN90bZ.js} +1 -1
- streamlit/static/static/js/{RenderInPortalIfExists.BbrAiS4q.js → RenderInPortalIfExists.BhsYk57k.js} +1 -1
- streamlit/static/static/js/{Toolbar.B4UnlLJR.js → Toolbar.M28tVbcl.js} +1 -1
- streamlit/static/static/js/{base-input.BdySl3Wo.js → base-input.BJFXZaN6.js} +1 -1
- streamlit/static/static/js/{createSuper.CT9j4pwt.js → createSuper.CR2BB5ll.js} +1 -1
- streamlit/static/static/js/{data-grid-overlay-editor.CTNOILgF.js → data-grid-overlay-editor.DThw5LO3.js} +1 -1
- streamlit/static/static/js/{downloader.BI10Ut1s.js → downloader.oXcdDod3.js} +1 -1
- streamlit/static/static/js/{es6.D57lNoID.js → es6.Dm6Lr5sS.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.Dp7tzCKc.js → iframeResizer.contentWindow.EQIQrAd4.js} +1 -1
- streamlit/static/static/js/{index.B_RT9XEh.js → index.0Eb9CO_K.js} +1 -1
- streamlit/static/static/js/{index.BsGCnWXN.js → index.B1X_ANFX.js} +1 -1
- streamlit/static/static/js/{index.2ZU4u6uf.js → index.B2zhJEHf.js} +1 -1
- streamlit/static/static/js/{index.Ce593GKt.js → index.B49jyHZy.js} +1 -1
- streamlit/static/static/js/{index.DVZLDFTf.js → index.BELZ0Ua3.js} +1 -1
- streamlit/static/static/js/{index.D-W0WnPg.js → index.BZUNGvtg.js} +1 -1
- streamlit/static/static/js/{index.6gMd28--.js → index.BjOrvaSf.js} +1 -1
- streamlit/static/static/js/{index.CQe0cVuu.js → index.BkwFDrjh.js} +1 -1
- streamlit/static/static/js/{index.E-uCquNT.js → index.BmunCvlQ.js} +1 -1
- streamlit/static/static/js/{index.DIuYZOo1.js → index.BrTAJ7cx.js} +5 -5
- streamlit/static/static/js/{index.CxuOpTfE.js → index.BzhkD1G1.js} +1 -1
- streamlit/static/static/js/{index.MyWIyUAB.js → index.C-qfcK5k.js} +22 -22
- streamlit/static/static/js/{index.CNzGrsa-.js → index.C02XURgk.js} +1 -1
- streamlit/static/static/js/{index.Bv9SpIsp.js → index.C8ahq2Yl.js} +1 -1
- streamlit/static/static/js/{index.i3_Oogic.js → index.CAvxO15c.js} +1 -1
- streamlit/static/static/js/{index.BJr-0rbs.js → index.CIgcpP2h.js} +1 -1
- streamlit/static/static/js/{index.DHeMuZWt.js → index.CPA4hfh-.js} +1 -1
- streamlit/static/static/js/{index.fiZSFOKl.js → index.CYO_k8m0.js} +1 -1
- streamlit/static/static/js/{index.Do-aY-b0.js → index.CYR86Hh7.js} +1 -1
- streamlit/static/static/js/{index.DHlZQRJ2.js → index.Cb9G_5ys.js} +1 -1
- streamlit/static/static/js/{index.D7RSv6ey.js → index.Cm_RlOaX.js} +1 -1
- streamlit/static/static/js/{index.NyidZo79.js → index.CqE8cJhC.js} +1 -1
- streamlit/static/static/js/{index.CQdVmKGZ.js → index.D-x9B5Oa.js} +1 -1
- streamlit/static/static/js/{index.DG8N1agE.js → index.D2G_9kKo.js} +1 -1
- streamlit/static/static/js/{index.DKChIiWS.js → index.DHr41xKA.js} +1 -1
- streamlit/static/static/js/{index.SZrBXA0x.js → index.DXjCUYHV.js} +1 -1
- streamlit/static/static/js/{index.CMeUNbsd.js → index.DhzvJb2S.js} +1 -1
- streamlit/static/static/js/{index.CQy70Tuh.js → index.DvCjEp1s.js} +1 -1
- streamlit/static/static/js/{index.BIbTzsBv.js → index.DwnmFzkn.js} +1 -1
- streamlit/static/static/js/{index.BvzG4uRR.js → index.DxFBqI9I.js} +1 -1
- streamlit/static/static/js/{index.D6cby_GK.js → index.L2uUYiab.js} +1 -1
- streamlit/static/static/js/{index.Cv4f0quN.js → index.V7XbIe_g.js} +1 -1
- streamlit/static/static/js/{index.DVQA7678.js → index.Vm77sF3W.js} +1 -1
- streamlit/static/static/js/{index.EY84KFkO.js → index.X-CeecsU.js} +1 -1
- streamlit/static/static/js/{index.Bd1tyA5C.js → index.YLipy1A9.js} +1 -1
- streamlit/static/static/js/{index.CuMSXAh1.js → index.tuHBuV8y.js} +1 -1
- streamlit/static/static/js/{index.DWawEgfs.js → index.xghdNmh6.js} +1 -1
- streamlit/static/static/js/{input.BLlUQSRv.js → input.Ch5EKcBw.js} +1 -1
- streamlit/static/static/js/{memory.D5yzKxGm.js → memory.cKfo0PEw.js} +1 -1
- streamlit/static/static/js/{mergeWith.BSbf2-C9.js → mergeWith.CrVvaazT.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.DSD8puEB.js → number-overlay-editor.C5_oSHKj.js} +1 -1
- streamlit/static/static/js/{possibleConstructorReturn.BazPwu8U.js → possibleConstructorReturn.B1H1HPCb.js} +1 -1
- streamlit/static/static/js/{sandbox.EiD3ZISo.js → sandbox.ZiYcTL56.js} +1 -1
- streamlit/static/static/js/{textarea.Dpen_LA2.js → textarea.GanBEqei.js} +1 -1
- streamlit/static/static/js/{timepicker.Bcj6rh3c.js → timepicker.D-6GNeM1.js} +1 -1
- streamlit/static/static/js/{toConsumableArray.l-Pgl8gO.js → toConsumableArray.DP3pcQU2.js} +1 -1
- streamlit/static/static/js/{uniqueId.D9pvJLzq.js → uniqueId.Br0SB0lz.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.BWe8Pksb.js → useBasicWidgetState.DDri_chl.js} +1 -1
- streamlit/static/static/js/{useOnInputChange.CcKPFKqO.js → useOnInputChange.DwB-vggD.js} +1 -1
- streamlit/static/static/js/{withFullScreenWrapper.DG7rb1Mv.js → withFullScreenWrapper.sAYwL3bu.js} +1 -1
- {streamlit_nightly-1.42.1.dev20250211.dist-info → streamlit_nightly-1.42.1.dev20250212.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.42.1.dev20250211.dist-info → streamlit_nightly-1.42.1.dev20250212.dist-info}/RECORD +76 -76
- {streamlit_nightly-1.42.1.dev20250211.data → streamlit_nightly-1.42.1.dev20250212.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.42.1.dev20250211.dist-info → streamlit_nightly-1.42.1.dev20250212.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.42.1.dev20250211.dist-info → streamlit_nightly-1.42.1.dev20250212.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.42.1.dev20250211.dist-info → streamlit_nightly-1.42.1.dev20250212.dist-info}/top_level.txt +0 -0
@@ -1 +1 @@
|
|
1
|
-
import{r as p,E as V,_ as z,n as w,z as u,j as r,b7 as U,bo as g,cn as E,bp as y,co as L,aZ as B,F as k,R as N,aC as W,bj as T,K as h,bl as D,bk as H,br as A,bE as R,bs as $,bb as O,bt as X}from"./index.
|
1
|
+
import{r as p,E as V,_ as z,n as w,z as u,j as r,b7 as U,bo as g,cn as E,bp as y,co as L,aZ as B,F as k,R as N,aC as W,bj as T,K as h,bl as D,bk as H,br as A,bE as R,bs as $,bb as O,bt as X}from"./index.BrTAJ7cx.js";import{a as S}from"./axios.upsvKRUO.js";import{F as _}from"./FormClearHelper.BjdyfMQx.js";import{S as x,I as K,b as j,c as q,d as G,C as Z,e as J,f as Q,h as Y,i as ee,g as b,F as f,j as te,k as se,l as ie,s as le,m as ae,n as re}from"./FileDropzone.BhS2dkwO.js";import{S as ne,P as oe}from"./ProgressBar.DycN90bZ.js";import{u as de}from"./Hooks.BKB06vs4.js";import{U as m}from"./UploadFileInfo.C-jY39rj.js";var C=p.forwardRef(function(l,o){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return p.createElement(V,z({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},l,{ref:o}),p.createElement("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}))});C.displayName="Error";const ce=w("div",{target:"egc9vxm0"})(({theme:l})=>({display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:l.spacing.twoXS,marginBottom:l.spacing.twoXS})),pe=w("div",{target:"egc9vxm1"})(({theme:l})=>({display:"flex",alignItems:"center",justifyContent:"center",color:l.colors.fadedText40})),ue=({currentPage:l,totalPages:o,onNext:e,onPrevious:t})=>u(ce,{"data-testid":"stFileUploaderPagination",children:[r(x,{children:`Showing page ${l} of ${o}`}),u(pe,{children:[r(y,{onClick:t,kind:U.MINIMAL,children:r(g,{content:E,size:"xl"})}),r(y,{onClick:e,kind:U.MINIMAL,children:r(g,{content:L,size:"xl"})})]})]}),I=(l,o)=>Math.ceil(l.length/o),he=l=>B(({pageSize:e,items:t,resetOnAdd:s,...a})=>{const[i,n]=p.useState(0),[d,F]=p.useState(I(t,e)),c=de(t);p.useEffect(()=>{c&&c.length!==t.length&&F(I(t,e)),c&&c.length<t.length?s&&n(0):i+1>=d&&n(d-1)},[t,i,e,c,s,d]);const v=()=>{n(Math.min(i+1,d-1))},M=()=>{n(Math.max(0,i-1))},P=t.slice(i*e,i*e+e);return u(k,{children:[r(l,{items:P,...a}),t.length>e?r(ue,{pageSize:e,totalPages:d,currentPage:i+1,onNext:v,onPrevious:M}):null]})},l),ge=({fileInfo:l})=>l.status.type==="uploading"?r(oe,{value:l.status.progress,size:ne.SMALL}):l.status.type==="error"?u(ee,{children:[r(Q,{"data-testid":"stFileUploaderFileErrorMessage",children:l.status.errorMessage}),r(Y,{children:r(g,{content:C,size:"lg"})})]}):l.status.type==="uploaded"?r(x,{children:b(l.size,f.Byte)}):null,me=({fileInfo:l,onDelete:o})=>u(J,{className:"stFileUploaderFile","data-testid":"stFileUploaderFile",children:[r(j,{children:r(g,{content:K,size:"twoXL"})}),u(q,{className:"stFileUploaderFileData",children:[r(G,{className:"stFileUploaderFileName","data-testid":"stFileUploaderFileName",title:l.name,children:l.name}),r(ge,{fileInfo:l})]}),r("div",{"data-testid":"stFileUploaderDeleteBtn",children:r(y,{onClick:()=>o(l.id),kind:U.MINIMAL,children:r(g,{content:Z,size:"lg"})})})]}),fe=({items:l,onDelete:o})=>r(ie,{children:l.map(e=>r(se,{children:r(me,{fileInfo:e,onDelete:o})},e.id))}),Fe=he(fe),Ue=l=>r(te,{children:r(Fe,{...l})});class ye extends N.PureComponent{constructor(o){super(o),this.formClearHelper=new _,this.localFileIdCounter=1,this.forceUpdatingStatus=!1,this.componentDidUpdate=()=>{if(this.status!=="ready")return;const e=this.createWidgetValue(),{element:t,widgetMgr:s,fragmentId:a}=this.props,i=s.getFileUploaderStateValue(t);W(e,i)||s.setFileUploaderStateValue(t,e,{fromUi:!0},a)},this.reset=()=>{this.setState({files:[]})},this.dropHandler=(e,t)=>{const{element:s}=this.props,{multipleFiles:a}=s;if(!a&&e.length===0&&t.length>1){const i=t.findIndex(n=>n.errors.length===1&&n.errors[0].code==="too-many-files");i>=0&&(e.push(t[i].file),t.splice(i,1))}if(this.props.uploadClient.fetchFileURLs(e).then(i=>{if(!a&&e.length>0){const n=this.state.files.find(d=>d.status.type!=="error");n&&(this.forceUpdatingStatus=!0,this.deleteFile(n.id),this.forceUpdatingStatus=!1)}T(i,e).forEach(([n,d])=>{this.uploadFile(n,d)})}).catch(i=>{this.addFiles(e.map(n=>new m(n.name,n.size,this.nextLocalFileId(),{type:"error",errorMessage:i})))}),t.length>0){const i=t.map(n=>{const{file:d}=n;return new m(d.name,d.size,this.nextLocalFileId(),{type:"error",errorMessage:this.getErrorMessage(n.errors[0].code,n.file)})});this.addFiles(i)}},this.uploadFile=(e,t)=>{const s=S.CancelToken.source(),a=new m(t.name,t.size,this.nextLocalFileId(),{type:"uploading",cancelToken:s,progress:1});this.addFile(a),this.props.uploadClient.uploadFile(this.props.element,e.uploadUrl,t,i=>this.onUploadProgress(i,a.id),s.token).then(()=>this.onUploadComplete(a.id,e)).catch(i=>{S.isCancel(i)||this.updateFile(a.id,a.setStatus({type:"error",errorMessage:i?i.toString():"Unknown error"}))})},this.onUploadComplete=(e,t)=>{const s=this.getFile(e);h(s)||s.status.type!=="uploading"||this.updateFile(s.id,s.setStatus({type:"uploaded",fileId:t.fileId,fileUrls:t}))},this.getErrorMessage=(e,t)=>{switch(e){case"file-too-large":return`File must be ${b(this.maxUploadSizeInBytes,f.Byte)} or smaller.`;case"file-invalid-type":return`${t.type} files are not allowed.`;case"file-too-small":return"File size is too small.";case"too-many-files":return"Only one file is allowed.";default:return"Unexpected error. Please try again."}},this.deleteFile=e=>{const t=this.getFile(e);h(t)||(t.status.type==="uploading"&&t.status.cancelToken.cancel(),t.status.type==="uploaded"&&t.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(t.status.fileUrls.deleteUrl),this.removeFile(e))},this.addFile=e=>{this.setState(t=>({files:[...t.files,e]}))},this.addFiles=e=>{this.setState(t=>({files:[...t.files,...e]}))},this.removeFile=e=>{this.setState(t=>({files:t.files.filter(s=>s.id!==e)}))},this.getFile=e=>this.state.files.find(t=>t.id===e),this.updateFile=(e,t)=>{this.setState(s=>({files:s.files.map(a=>a.id===e?t:a)}))},this.onUploadProgress=(e,t)=>{const s=this.getFile(t);if(h(s)||s.status.type!=="uploading")return;const a=Math.round(e.loaded*100/e.total);s.status.progress!==a&&this.updateFile(t,s.setStatus({type:"uploading",cancelToken:s.status.cancelToken,progress:a}))},this.onFormCleared=()=>{this.setState({files:[]},()=>{const e=this.createWidgetValue();if(h(e))return;const{widgetMgr:t,element:s,fragmentId:a}=this.props;t.setFileUploaderStateValue(s,e,{fromUi:!0},a)})},this.state=this.initialValue}get initialValue(){const o={files:[],newestServerFileId:0},{widgetMgr:e,element:t}=this.props,s=e.getFileUploaderStateValue(t);if(h(s))return o;const{uploadedFileInfo:a}=s;return h(a)||a.length===0?o:{files:a.map(i=>{const n=i.name,d=i.size,F=i.fileId,c=i.fileUrls;return new m(n,d,this.nextLocalFileId(),{type:"uploaded",fileId:F,fileUrls:c})})}}componentWillUnmount(){this.formClearHelper.disconnect()}get maxUploadSizeInBytes(){const o=this.props.element.maxUploadSizeMb;return le(o,f.Megabyte,f.Byte)}get status(){const o=e=>e.status.type==="uploading";return this.state.files.some(o)||this.forceUpdatingStatus?"updating":"ready"}componentDidMount(){const o=this.createWidgetValue(),{element:e,widgetMgr:t,fragmentId:s}=this.props;t.getFileUploaderStateValue(e)===void 0&&t.setFileUploaderStateValue(e,o,{fromUi:!1},s)}createWidgetValue(){const o=this.state.files.filter(e=>e.status.type==="uploaded").map(e=>{const{name:t,size:s,status:a}=e,{fileId:i,fileUrls:n}=a;return new D({fileId:i,fileUrls:n,name:t,size:s})});return new H({uploadedFileInfo:o})}render(){var d;const{files:o}=this.state,{element:e,disabled:t,widgetMgr:s,width:a}=this.props,i=e.type;this.formClearHelper.manageFormClearListener(s,e.formId,this.onFormCleared);const n=o.slice().reverse();return u(re,{className:"stFileUploader","data-testid":"stFileUploader",width:a,children:[r(X,{label:e.label,disabled:t,labelVisibility:A((d=e.labelVisibility)==null?void 0:d.value),children:e.help&&r(R,{children:r($,{content:e.help,placement:O.TOP_RIGHT})})}),r(ae,{onDrop:this.dropHandler,multiple:e.multipleFiles,acceptedExtensions:i,maxSizeBytes:this.maxUploadSizeInBytes,label:e.label,disabled:t}),n.length>0&&r(Ue,{items:n,pageSize:3,onDelete:this.deleteFile,resetOnAdd:!0})]})}nextLocalFileId(){return this.localFileIdCounter++}}const Me=p.memo(ye);export{Me as default};
|
@@ -1 +1 @@
|
|
1
|
-
import{n as o,r as S,z as m,j as i,aE as y}from"./index.
|
1
|
+
import{n as o,r as S,z as m,j as i,aE as y}from"./index.BrTAJ7cx.js";import{S as g,T as W}from"./Toolbar.M28tVbcl.js";import{w as b,u as E,E as M}from"./withFullScreenWrapper.sAYwL3bu.js";const L=o("div",{target:"evl31sl0"})(({theme:t})=>({display:"flex",flexDirection:"row",flexWrap:"wrap",rowGap:t.spacing.lg,maxWidth:"100%",width:"fit-content"})),O=o("div",{target:"evl31sl1"})(({theme:t})=>({display:"flex",flexDirection:"column",alignItems:"stretch",width:"auto",flexGrow:0,">img":{borderRadius:t.radii.default}})),T=o("div",{target:"evl31sl2"})(({theme:t})=>({textAlign:"center",marginTop:t.spacing.xs,wordWrap:"break-word",padding:t.spacing.threeXS}));var p;(function(t){t[t.OriginalWidth=-1]="OriginalWidth",t[t.ColumnWidth=-2]="ColumnWidth",t[t.AutoWidth=-3]="AutoWidth",t[t.MinImageOrContainer=-4]="MinImageOrContainer",t[t.MaxImageOrContainer=-5]="MaxImageOrContainer"})(p||(p={}));function j({element:t,width:u,endpoints:x,disableFullscreenMode:f}){const{expanded:n,width:w,height:l,expand:C,collapse:h}=E(M),d=n?w:u;let r;const a=t.width;if([-1,-3,-4].includes(a))r=void 0;else if([-2,-5].includes(a))r=d;else if(a>0)r=a;else throw Error(`Invalid image width: ${a}`);const e={};return l&&n?(e.maxHeight=l,e.objectFit="contain"):(e.width=r,e.maxWidth="100%"),m(g,{width:d,height:l,useContainerWidth:n,topCentered:!0,children:[i(W,{target:g,isFullScreen:n,onExpand:C,onCollapse:h,disableFullscreenMode:f}),i(L,{className:"stImage","data-testid":"stImage",children:t.imgs.map((I,c)=>{const s=I;return m(O,{"data-testid":"stImageContainer",children:[i("img",{style:e,src:x.buildMediaURL(s.url),alt:c.toString()}),s.caption&&i(T,{"data-testid":"stImageCaption",style:e,children:i(y,{source:s.caption,allowHTML:!1,isCaption:!0,isLabel:!0})})]},c)})})]})}const k=S.memo(b(j));export{k as default};
|
@@ -1 +1 @@
|
|
1
|
-
import{r as y,E as _,_ as T,n as E,az as Q,z as R,j as p,bu as J,bb as B,bp as K,b7 as Y,bo as j,bB as z,d as Z,g as ee,aN as te,y as re,bC as ie,bD as ae,am as oe,R as ne,aC as se,K as P,bl as le,bk as de,br as ce,bE as ue,bs as fe,bt as he,F as pe}from"./index.DIuYZOo1.js";import{a as V}from"./axios.upsvKRUO.js";import{F as ge}from"./FormClearHelper.0-LU4kzK.js";import{U as W}from"./UploadFileInfo.C-jY39rj.js";import{P as me,S as ve}from"./ProgressBar.B-igBN-q.js";var A=y.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return y.createElement(_,T({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:l}),y.createElement("path",{d:"M.5 1c-.28 0-.5.23-.5.5v4c0 .28.23.5.5.5h5c.28 0 .5-.22.5-.5V4l1 1h1V2H7L6 3V1.5c0-.28-.22-.5-.5-.5h-5z"}))});A.displayName="Video";var N=y.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return y.createElement(_,T({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:l}),y.createElement("path",{d:"M1.41 0L0 1.41l.72.72L2.5 3.94.72 5.72 0 6.41l1.41 1.44.72-.72 1.81-1.81 1.78 1.81.69.72 1.44-1.44-.72-.69-1.81-1.78 1.81-1.81.72-.72L6.41 0l-.69.72L3.94 2.5 2.13.72 1.41 0z"}))});N.displayName="X";var $=y.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return y.createElement(_,T({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:l}),y.createElement("rect",{width:24,height:24,fill:"none"}),y.createElement("path",{d:"M20 5h-3.17l-1.24-1.35A1.99 1.99 0 0014.12 3H9.88c-.56 0-1.1.24-1.48.65L7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-1.35 8.35l-2.79 2.79c-.32.32-.86.1-.86-.35v-1.75H9v1.75c0 .45-.54.67-.85.35l-2.79-2.79c-.2-.2-.2-.51 0-.71l2.79-2.79a.5.5 0 01.85.36v1.83h6v-1.83c0-.45.54-.67.85-.35l2.79 2.79c.2.19.2.51.01.7z"}))});$.displayName="SwitchCamera";var L;(function(t){t.XSMALL="xsmall",t.SMALL="small",t.MEDIUM="medium",t.LARGE="large"})(L||(L={}));function Se(t,l){switch(t){case"xsmall":return{padding:`${l.spacing.twoXS} ${l.spacing.sm}`,fontSize:l.fontSizes.sm};case"small":return{padding:`${l.spacing.twoXS} ${l.spacing.md}`};case"large":return{padding:`${l.spacing.md} ${l.spacing.md}`};default:return{padding:`${l.spacing.xs} ${l.spacing.md}`}}}const D=E("div",{target:"e47j7ja0"})({position:"relative",overflow:"hidden",width:"100%",objectFit:"contain"}),O=E("div",{target:"e47j7ja1"})(({theme:t,width:l})=>({backgroundColor:t.colors.secondaryBg,borderRadius:`${t.radii.default} ${t.radii.default} 0 0`,width:"100%",height:l*9/16,display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"})),ye=E("p",{target:"e47j7ja2"})(({theme:t})=>({marginTop:t.spacing.sm,textAlign:"center"})),be=E("img",{target:"e47j7ja3"})(({theme:t,opacity:l})=>({borderRadius:`${t.radii.default} ${t.radii.default} 0 0`,objectFit:"contain",opacity:l})),Me=E("a",{target:"e47j7ja4"})(({theme:t})=>({color:t.colors.primary,display:"block",textDecoration:"none"})),we=E("span",{target:"e47j7ja5"})({display:"flex",alignItems:"center"}),Ce=E("div",{target:"e47j7ja6"})(({theme:t})=>({position:"absolute",top:t.spacing.lg,right:t.spacing.lg,zIndex:t.zIndices.priority,color:t.colors.fadedText40,mixBlendMode:"difference",opacity:.6})),Ue=E("div",{target:"e47j7ja8"})({height:"fit-content",width:"100%",position:"absolute",bottom:0}),Ee=E("button",{target:"e47j7ja9"})(({theme:t})=>({position:"relative",display:"inline-flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:t.colors.lightenedBg05,border:`${t.sizes.borderWidth} solid ${t.colors.borderColor}`,borderRadius:`0 0 ${t.radii.default} ${t.radii.default}`,"&:hover":{borderColor:t.colors.primary,color:t.colors.primary},"&:active":{color:t.colors.white,borderColor:t.colors.primary,backgroundColor:t.colors.primary},"&:focus:not(:active)":{borderColor:t.colors.primary,color:t.colors.primary},"&:disabled, &:disabled:hover, &:disabled:active":{color:t.colors.fadedText40},fontWeight:t.fontWeights.normal,padding:`${t.spacing.xs} ${t.spacing.md}`,margin:t.spacing.none,lineHeight:t.lineHeights.base,color:"inherit",width:"100%",userSelect:"none","&:focus":{outline:"none"},"&:focus-visible":{boxShadow:`0 0 0 0.2rem ${Q(t.colors.primary,.5)}`},...Se("medium",t)}));function H({disabled:t,onClick:l,children:r,progress:o}){return R(Ee,{disabled:t||!1,onClick:l||(()=>{}),progress:o||null,"data-testid":"stCameraInputButton",children:[r,o&&p(Ue,{children:p(me,{value:o,size:ve.EXTRASMALL,overrides:{Bar:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}},BarProgress:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}},BarContainer:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}}}})})]})}var F;(function(t){t.USER="user",t.ENVIRONMENT="environment"})(F||(F={}));const Ie=({switchFacingMode:t})=>p(Ce,{"data-testid":"stCameraInputSwitchButton",children:p(J,{content:"Switch camera",placement:B.TOP_RIGHT,children:p(K,{kind:Y.MINIMAL,onClick:t,children:p(j,{content:$,size:"twoXL",color:z.white})})})});var G={exports:{}};(function(t,l){(function(o,a){t.exports=a(y)})(Z,function(r){return function(o){var a={};function n(s){if(a[s])return a[s].exports;var f=a[s]={i:s,l:!1,exports:{}};return o[s].call(f.exports,f,f.exports,n),f.l=!0,f.exports}return n.m=o,n.c=a,n.d=function(s,f,g){n.o(s,f)||Object.defineProperty(s,f,{enumerable:!0,get:g})},n.r=function(s){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(s,"__esModule",{value:!0})},n.t=function(s,f){if(f&1&&(s=n(s)),f&8||f&4&&typeof s=="object"&&s&&s.__esModule)return s;var g=Object.create(null);if(n.r(g),Object.defineProperty(g,"default",{enumerable:!0,value:s}),f&2&&typeof s!="string")for(var U in s)n.d(g,U,(function(C){return s[C]}).bind(null,U));return g},n.n=function(s){var f=s&&s.__esModule?function(){return s.default}:function(){return s};return n.d(f,"a",f),f},n.o=function(s,f){return Object.prototype.hasOwnProperty.call(s,f)},n.p="",n(n.s="./src/react-webcam.tsx")}({"./src/react-webcam.tsx":function(o,a,n){n.r(a);var s=n("react"),f=function(){var m=function(u,e){return m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,d){i.__proto__=d}||function(i,d){for(var c in d)d.hasOwnProperty(c)&&(i[c]=d[c])},m(u,e)};return function(u,e){m(u,e);function i(){this.constructor=u}u.prototype=e===null?Object.create(e):(i.prototype=e.prototype,new i)}}(),g=function(){return g=Object.assign||function(m){for(var u,e=1,i=arguments.length;e<i;e++){u=arguments[e];for(var d in u)Object.prototype.hasOwnProperty.call(u,d)&&(m[d]=u[d])}return m},g.apply(this,arguments)},U=function(m,u){var e={};for(var i in m)Object.prototype.hasOwnProperty.call(m,i)&&u.indexOf(i)<0&&(e[i]=m[i]);if(m!=null&&typeof Object.getOwnPropertySymbols=="function")for(var d=0,i=Object.getOwnPropertySymbols(m);d<i.length;d++)u.indexOf(i[d])<0&&Object.prototype.propertyIsEnumerable.call(m,i[d])&&(e[i[d]]=m[i[d]]);return e};(function(){typeof window>"u"||(navigator.mediaDevices===void 0&&(navigator.mediaDevices={}),navigator.mediaDevices.getUserMedia===void 0&&(navigator.mediaDevices.getUserMedia=function(u){var e=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;return e?new Promise(function(i,d){e.call(navigator,u,i,d)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}))})();function C(){return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}var I=function(m){f(u,m);function u(e){var i=m.call(this,e)||this;return i.canvas=null,i.ctx=null,i.requestUserMediaId=0,i.unmounted=!1,i.state={hasUserMedia:!1},i}return u.prototype.componentDidMount=function(){var e=this,i=e.state,d=e.props;if(this.unmounted=!1,!C()){d.onUserMediaError("getUserMedia not supported");return}i.hasUserMedia||this.requestUserMedia(),d.children&&typeof d.children!="function"&&console.warn("children must be a function")},u.prototype.componentDidUpdate=function(e){var i=this.props;if(!C()){i.onUserMediaError("getUserMedia not supported");return}var d=JSON.stringify(e.audioConstraints)!==JSON.stringify(i.audioConstraints),c=JSON.stringify(e.videoConstraints)!==JSON.stringify(i.videoConstraints),b=e.minScreenshotWidth!==i.minScreenshotWidth,S=e.minScreenshotHeight!==i.minScreenshotHeight;(c||b||S)&&(this.canvas=null,this.ctx=null),(d||c)&&(this.stopAndCleanup(),this.requestUserMedia())},u.prototype.componentWillUnmount=function(){this.unmounted=!0,this.stopAndCleanup()},u.stopMediaStream=function(e){e&&(e.getVideoTracks&&e.getAudioTracks?(e.getVideoTracks().map(function(i){e.removeTrack(i),i.stop()}),e.getAudioTracks().map(function(i){e.removeTrack(i),i.stop()})):e.stop())},u.prototype.stopAndCleanup=function(){var e=this.state;e.hasUserMedia&&(u.stopMediaStream(this.stream),e.src&&window.URL.revokeObjectURL(e.src))},u.prototype.getScreenshot=function(e){var i=this,d=i.state,c=i.props;if(!d.hasUserMedia)return null;var b=this.getCanvas(e);return b&&b.toDataURL(c.screenshotFormat,c.screenshotQuality)},u.prototype.getCanvas=function(e){var i=this,d=i.state,c=i.props;if(!this.video||!d.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var b=this.video.videoWidth,S=this.video.videoHeight;if(!this.props.forceScreenshotSourceSize){var h=b/S;b=c.minScreenshotWidth||this.video.clientWidth,S=b/h,c.minScreenshotHeight&&S<c.minScreenshotHeight&&(S=c.minScreenshotHeight,b=S*h)}this.canvas=document.createElement("canvas"),this.canvas.width=(e==null?void 0:e.width)||b,this.canvas.height=(e==null?void 0:e.height)||S,this.ctx=this.canvas.getContext("2d")}var w=this,M=w.ctx,v=w.canvas;return M&&v&&(v.width=(e==null?void 0:e.width)||v.width,v.height=(e==null?void 0:e.height)||v.height,c.mirrored&&(M.translate(v.width,0),M.scale(-1,1)),M.imageSmoothingEnabled=c.imageSmoothing,M.drawImage(this.video,0,0,(e==null?void 0:e.width)||v.width,(e==null?void 0:e.height)||v.height),c.mirrored&&(M.scale(-1,1),M.translate(-v.width,0))),v},u.prototype.requestUserMedia=function(){var e=this,i=this.props,d=function(S,h){var w={video:typeof h<"u"?h:!0};i.audio&&(w.audio=typeof S<"u"?S:!0),e.requestUserMediaId++;var M=e.requestUserMediaId;navigator.mediaDevices.getUserMedia(w).then(function(v){e.unmounted||M!==e.requestUserMediaId?u.stopMediaStream(v):e.handleUserMedia(null,v)}).catch(function(v){e.handleUserMedia(v)})};if("mediaDevices"in navigator)d(i.audioConstraints,i.videoConstraints);else{var c=function(S){return{optional:[{sourceId:S}]}},b=function(S){var h=S.deviceId;return typeof h=="string"?h:Array.isArray(h)&&h.length>0?h[0]:typeof h=="object"&&h.ideal?h.ideal:null};MediaStreamTrack.getSources(function(S){var h=null,w=null;S.forEach(function(x){x.kind==="audio"?h=x.id:x.kind==="video"&&(w=x.id)});var M=b(i.audioConstraints);M&&(h=M);var v=b(i.videoConstraints);v&&(w=v),d(c(h),c(w))})}},u.prototype.handleUserMedia=function(e,i){var d=this.props;if(e||!i){this.setState({hasUserMedia:!1}),d.onUserMediaError(e);return}this.stream=i;try{this.video&&(this.video.srcObject=i),this.setState({hasUserMedia:!0})}catch{this.setState({hasUserMedia:!0,src:window.URL.createObjectURL(i)})}d.onUserMedia(i)},u.prototype.render=function(){var e=this,i=this,d=i.state,c=i.props,b=c.audio;c.forceScreenshotSourceSize,c.onUserMedia,c.onUserMediaError,c.screenshotFormat,c.screenshotQuality,c.minScreenshotWidth,c.minScreenshotHeight,c.audioConstraints,c.videoConstraints,c.imageSmoothing;var S=c.mirrored,h=c.style,w=h===void 0?{}:h,M=c.children,v=U(c,["audio","forceScreenshotSourceSize","onUserMedia","onUserMediaError","screenshotFormat","screenshotQuality","minScreenshotWidth","minScreenshotHeight","audioConstraints","videoConstraints","imageSmoothing","mirrored","style","children"]),x=S?g(g({},w),{transform:(w.transform||"")+" scaleX(-1)"}):w,q={getScreenshot:this.getScreenshot.bind(this)};return s.createElement(s.Fragment,null,s.createElement("video",g({autoPlay:!0,src:d.src,muted:!b,playsInline:!0,ref:function(X){e.video=X},style:x},v)),M&&M(q))},u.defaultProps={audio:!1,forceScreenshotSourceSize:!1,imageSmoothing:!0,mirrored:!1,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",screenshotQuality:.92},u}(s.Component);a.default=I},react:function(o,a){o.exports=r}}).default})})(G);var Fe=G.exports;const Re=ee(Fe);var k;(function(t){t.PENDING="pending",t.SUCCESS="success",t.ERROR="error"})(k||(k={}));const xe=({width:t})=>R(O,{width:t,children:[p(j,{size:"threeXL",color:z.gray60,content:A}),R(ye,{children:["This app would like to use your camera.",p(Me,{href:ae,rel:"noopener noreferrer",target:"_blank",children:"Learn how to allow access."})]})]}),Pe=({handleCapture:t,width:l,disabled:r,clearPhotoInProgress:o,setClearPhotoInProgress:a,facingMode:n,setFacingMode:s,testOverride:f})=>{const[g,U]=y.useState(f||"pending"),C=y.useRef(null),[I,m]=y.useState(l),u=y.useCallback(te(1e3,m),[]);y.useEffect(()=>{u(l)},[l,u]);function e(){if(C.current!==null){const d=C.current.getScreenshot();t(d)}}const i=re();return R(D,{"data-testid":"stCameraInputWebcamComponent",children:[g!=="success"&&!r&&!o?p(xe,{width:I}):ie&&p(Ie,{switchFacingMode:s}),p(O,{"data-testid":"stCameraInputWebcamStyledBox",hidden:g!=="success"&&!r&&!o,width:I,children:!r&&p(Re,{audio:!1,ref:C,screenshotFormat:"image/jpeg",screenshotQuality:1,width:I,height:I*9/16,style:{borderRadius:`${i.radii.default} ${i.radii.default} 0 0`},onUserMediaError:()=>{U("error")},onUserMedia:()=>{U("success"),a(!1)},videoConstraints:{width:{ideal:I},facingMode:n}})}),p(H,{onClick:e,disabled:g!=="success"||r||o,children:"Take Photo"})]})},_e=150,Te=oe.getLogger("CameraInput");class Be extends ne.PureComponent{constructor(l){super(l),this.localFileIdCounter=1,this.RESTORED_FROM_WIDGET_STRING="RESTORED_FROM_WIDGET",this.formClearHelper=new ge,this.getProgress=()=>{if(this.state.files.length>0&&this.state.files[this.state.files.length-1].status.type==="uploading")return this.state.files[this.state.files.length-1].status.progress},this.setClearPhotoInProgress=r=>{this.setState({clearPhotoInProgress:r})},this.setFacingMode=()=>{this.setState(r=>({facingMode:r.facingMode===F.USER?F.ENVIRONMENT:F.USER}))},this.handleCapture=r=>{if(r===null)return Promise.resolve();this.setState({imgSrc:r,shutter:!0,minShutterEffectPassed:!1});const o=a=>new Promise(n=>setTimeout(n,a));return je(r,`camera-input-${new Date().toISOString().replace(/:/g,"_")}.jpg`).then(a=>this.props.uploadClient.fetchFileURLs([a]).then(n=>({file:a,fileUrls:n[0]}))).then(({file:a,fileUrls:n})=>this.uploadFile(n,a)).then(()=>o(_e)).then(()=>{this.setState((a,n)=>({imgSrc:r,shutter:a.shutter,minShutterEffectPassed:!0}))}).catch(a=>{Te.error(a)})},this.removeCapture=()=>{this.state.files.length!==0&&(this.state.files.forEach(r=>this.deleteFile(r.id)),this.setState({imgSrc:null,clearPhotoInProgress:!0}))},this.componentDidUpdate=()=>{if(this.status!=="ready")return;const r=this.createWidgetValue(),{element:o,widgetMgr:a,fragmentId:n}=this.props,s=a.getFileUploaderStateValue(o);se(r,s)||a.setFileUploaderStateValue(o,r,{fromUi:!0},n)},this.onFormCleared=()=>{this.setState({files:[]},()=>{const r=this.createWidgetValue();if(P(r))return;this.setState({imgSrc:null});const{widgetMgr:o,element:a,fragmentId:n}=this.props;o.setFileUploaderStateValue(a,r,{fromUi:!0},n)})},this.deleteFile=r=>{const o=this.getFile(r);P(o)||(o.status.type==="uploading"&&o.status.cancelToken.cancel(),o.status.type==="uploaded"&&o.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(o.status.fileUrls.deleteUrl),this.removeFile(r))},this.addFile=r=>{this.setState(o=>({files:[...o.files,r]}))},this.removeFile=r=>{this.setState(o=>({files:o.files.filter(a=>a.id!==r)}))},this.getFile=r=>this.state.files.find(o=>o.id===r),this.updateFile=(r,o)=>{this.setState(a=>({files:a.files.map(n=>n.id===r?o:n)}))},this.onUploadComplete=(r,o)=>{this.setState(()=>({shutter:!1}));const a=this.getFile(r);P(a)||a.status.type!=="uploading"||this.updateFile(a.id,a.setStatus({type:"uploaded",fileId:o.fileId,fileUrls:o}))},this.onUploadProgress=(r,o)=>{const a=this.getFile(o);if(P(a)||a.status.type!=="uploading")return;const n=Math.round(r.loaded*100/r.total);a.status.progress!==n&&this.updateFile(o,a.setStatus({type:"uploading",cancelToken:a.status.cancelToken,progress:n}))},this.reset=()=>{this.setState({files:[],imgSrc:null})},this.uploadFile=(r,o)=>{const a=V.CancelToken.source(),n=new W(o.name,o.size,this.nextLocalFileId(),{type:"uploading",cancelToken:a,progress:1});this.addFile(n),this.props.uploadClient.uploadFile(this.props.element,r.uploadUrl,o,s=>this.onUploadProgress(s,n.id),a.token).then(()=>this.onUploadComplete(n.id,r)).catch(s=>{V.isCancel(s)||this.updateFile(n.id,n.setStatus({type:"error",errorMessage:s?s.toString():"Unknown error"}))})},this.state=this.initialValue}get initialValue(){const l={files:[],imgSrc:null,shutter:!1,minShutterEffectPassed:!0,clearPhotoInProgress:!1,facingMode:F.USER},{widgetMgr:r,element:o}=this.props,a=r.getFileUploaderStateValue(o);if(P(a))return l;const{uploadedFileInfo:n}=a;return P(n)||n.length===0?l:{files:n.map(s=>{const f=s.name,g=s.size,U=s.fileId,C=s.fileUrls;return new W(f,g,this.nextLocalFileId(),{type:"uploaded",fileId:U,fileUrls:C})}),imgSrc:n.length===0?"":this.RESTORED_FROM_WIDGET_STRING,shutter:!1,minShutterEffectPassed:!1,clearPhotoInProgress:!1,facingMode:F.USER}}componentWillUnmount(){this.formClearHelper.disconnect()}get status(){const l=r=>r.status.type==="uploading";return this.state.files.some(l)?"updating":"ready"}componentDidMount(){const l=this.createWidgetValue(),{element:r,widgetMgr:o,fragmentId:a}=this.props;o.getFileUploaderStateValue(r)===void 0&&o.setFileUploaderStateValue(r,l,{fromUi:!1},a)}createWidgetValue(){const l=this.state.files.filter(r=>r.status.type==="uploaded").map(r=>{const{name:o,size:a,status:n}=r;return new le({fileId:n.fileId,fileUrls:n.fileUrls,name:o,size:a})});return new de({uploadedFileInfo:l})}render(){var n;const{element:l,widgetMgr:r,disabled:o,width:a}=this.props;return this.formClearHelper.manageFormClearListener(r,l.formId,this.onFormCleared),R(D,{className:"stCameraInput","data-testid":"stCameraInput",children:[p(he,{label:l.label,disabled:o,labelVisibility:ce((n=l.labelVisibility)==null?void 0:n.value),children:l.help&&p(ue,{children:p(fe,{content:l.help,placement:B.TOP_RIGHT})})}),this.state.imgSrc?R(pe,{children:[p(O,{width:a,children:this.state.imgSrc!==this.RESTORED_FROM_WIDGET_STRING&&p(be,{src:this.state.imgSrc,alt:"Snapshot",opacity:this.state.shutter||!this.state.minShutterEffectPassed?"50%":"100%",width:a,height:a*9/16})}),p(H,{onClick:this.removeCapture,progress:this.getProgress(),disabled:!!this.getProgress()||o,children:this.getProgress()?"Uploading...":R(we,{children:[p(j,{content:N,margin:"0 xs 0 0",size:"sm"})," Clear photo"]})})]}):p(Pe,{handleCapture:this.handleCapture,width:a,disabled:o,clearPhotoInProgress:this.state.clearPhotoInProgress,setClearPhotoInProgress:this.setClearPhotoInProgress,facingMode:this.state.facingMode,setFacingMode:this.setFacingMode,testOverride:this.props.testOverride})]})}nextLocalFileId(){return this.localFileIdCounter++}}function je(t,l){return fetch(t).then(r=>r.arrayBuffer()).then(r=>new File([r],l,{type:"image/jpeg"}))}export{Be as default};
|
1
|
+
import{r as y,E as _,_ as T,n as E,az as Q,z as R,j as p,bu as J,bb as B,bp as K,b7 as Y,bo as j,bB as z,d as Z,g as ee,aN as te,y as re,bC as ie,bD as ae,am as oe,R as ne,aC as se,K as P,bl as le,bk as de,br as ce,bE as ue,bs as fe,bt as he,F as pe}from"./index.BrTAJ7cx.js";import{a as V}from"./axios.upsvKRUO.js";import{F as ge}from"./FormClearHelper.BjdyfMQx.js";import{U as W}from"./UploadFileInfo.C-jY39rj.js";import{P as me,S as ve}from"./ProgressBar.DycN90bZ.js";var A=y.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return y.createElement(_,T({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:l}),y.createElement("path",{d:"M.5 1c-.28 0-.5.23-.5.5v4c0 .28.23.5.5.5h5c.28 0 .5-.22.5-.5V4l1 1h1V2H7L6 3V1.5c0-.28-.22-.5-.5-.5h-5z"}))});A.displayName="Video";var N=y.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return y.createElement(_,T({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:l}),y.createElement("path",{d:"M1.41 0L0 1.41l.72.72L2.5 3.94.72 5.72 0 6.41l1.41 1.44.72-.72 1.81-1.81 1.78 1.81.69.72 1.44-1.44-.72-.69-1.81-1.78 1.81-1.81.72-.72L6.41 0l-.69.72L3.94 2.5 2.13.72 1.41 0z"}))});N.displayName="X";var $=y.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return y.createElement(_,T({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:l}),y.createElement("rect",{width:24,height:24,fill:"none"}),y.createElement("path",{d:"M20 5h-3.17l-1.24-1.35A1.99 1.99 0 0014.12 3H9.88c-.56 0-1.1.24-1.48.65L7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-1.35 8.35l-2.79 2.79c-.32.32-.86.1-.86-.35v-1.75H9v1.75c0 .45-.54.67-.85.35l-2.79-2.79c-.2-.2-.2-.51 0-.71l2.79-2.79a.5.5 0 01.85.36v1.83h6v-1.83c0-.45.54-.67.85-.35l2.79 2.79c.2.19.2.51.01.7z"}))});$.displayName="SwitchCamera";var L;(function(t){t.XSMALL="xsmall",t.SMALL="small",t.MEDIUM="medium",t.LARGE="large"})(L||(L={}));function Se(t,l){switch(t){case"xsmall":return{padding:`${l.spacing.twoXS} ${l.spacing.sm}`,fontSize:l.fontSizes.sm};case"small":return{padding:`${l.spacing.twoXS} ${l.spacing.md}`};case"large":return{padding:`${l.spacing.md} ${l.spacing.md}`};default:return{padding:`${l.spacing.xs} ${l.spacing.md}`}}}const D=E("div",{target:"e47j7ja0"})({position:"relative",overflow:"hidden",width:"100%",objectFit:"contain"}),O=E("div",{target:"e47j7ja1"})(({theme:t,width:l})=>({backgroundColor:t.colors.secondaryBg,borderRadius:`${t.radii.default} ${t.radii.default} 0 0`,width:"100%",height:l*9/16,display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"})),ye=E("p",{target:"e47j7ja2"})(({theme:t})=>({marginTop:t.spacing.sm,textAlign:"center"})),be=E("img",{target:"e47j7ja3"})(({theme:t,opacity:l})=>({borderRadius:`${t.radii.default} ${t.radii.default} 0 0`,objectFit:"contain",opacity:l})),Me=E("a",{target:"e47j7ja4"})(({theme:t})=>({color:t.colors.primary,display:"block",textDecoration:"none"})),we=E("span",{target:"e47j7ja5"})({display:"flex",alignItems:"center"}),Ce=E("div",{target:"e47j7ja6"})(({theme:t})=>({position:"absolute",top:t.spacing.lg,right:t.spacing.lg,zIndex:t.zIndices.priority,color:t.colors.fadedText40,mixBlendMode:"difference",opacity:.6})),Ue=E("div",{target:"e47j7ja8"})({height:"fit-content",width:"100%",position:"absolute",bottom:0}),Ee=E("button",{target:"e47j7ja9"})(({theme:t})=>({position:"relative",display:"inline-flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:t.colors.lightenedBg05,border:`${t.sizes.borderWidth} solid ${t.colors.borderColor}`,borderRadius:`0 0 ${t.radii.default} ${t.radii.default}`,"&:hover":{borderColor:t.colors.primary,color:t.colors.primary},"&:active":{color:t.colors.white,borderColor:t.colors.primary,backgroundColor:t.colors.primary},"&:focus:not(:active)":{borderColor:t.colors.primary,color:t.colors.primary},"&:disabled, &:disabled:hover, &:disabled:active":{color:t.colors.fadedText40},fontWeight:t.fontWeights.normal,padding:`${t.spacing.xs} ${t.spacing.md}`,margin:t.spacing.none,lineHeight:t.lineHeights.base,color:"inherit",width:"100%",userSelect:"none","&:focus":{outline:"none"},"&:focus-visible":{boxShadow:`0 0 0 0.2rem ${Q(t.colors.primary,.5)}`},...Se("medium",t)}));function H({disabled:t,onClick:l,children:r,progress:o}){return R(Ee,{disabled:t||!1,onClick:l||(()=>{}),progress:o||null,"data-testid":"stCameraInputButton",children:[r,o&&p(Ue,{children:p(me,{value:o,size:ve.EXTRASMALL,overrides:{Bar:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}},BarProgress:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}},BarContainer:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}}}})})]})}var F;(function(t){t.USER="user",t.ENVIRONMENT="environment"})(F||(F={}));const Ie=({switchFacingMode:t})=>p(Ce,{"data-testid":"stCameraInputSwitchButton",children:p(J,{content:"Switch camera",placement:B.TOP_RIGHT,children:p(K,{kind:Y.MINIMAL,onClick:t,children:p(j,{content:$,size:"twoXL",color:z.white})})})});var G={exports:{}};(function(t,l){(function(o,a){t.exports=a(y)})(Z,function(r){return function(o){var a={};function n(s){if(a[s])return a[s].exports;var f=a[s]={i:s,l:!1,exports:{}};return o[s].call(f.exports,f,f.exports,n),f.l=!0,f.exports}return n.m=o,n.c=a,n.d=function(s,f,g){n.o(s,f)||Object.defineProperty(s,f,{enumerable:!0,get:g})},n.r=function(s){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(s,"__esModule",{value:!0})},n.t=function(s,f){if(f&1&&(s=n(s)),f&8||f&4&&typeof s=="object"&&s&&s.__esModule)return s;var g=Object.create(null);if(n.r(g),Object.defineProperty(g,"default",{enumerable:!0,value:s}),f&2&&typeof s!="string")for(var U in s)n.d(g,U,(function(C){return s[C]}).bind(null,U));return g},n.n=function(s){var f=s&&s.__esModule?function(){return s.default}:function(){return s};return n.d(f,"a",f),f},n.o=function(s,f){return Object.prototype.hasOwnProperty.call(s,f)},n.p="",n(n.s="./src/react-webcam.tsx")}({"./src/react-webcam.tsx":function(o,a,n){n.r(a);var s=n("react"),f=function(){var m=function(u,e){return m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,d){i.__proto__=d}||function(i,d){for(var c in d)d.hasOwnProperty(c)&&(i[c]=d[c])},m(u,e)};return function(u,e){m(u,e);function i(){this.constructor=u}u.prototype=e===null?Object.create(e):(i.prototype=e.prototype,new i)}}(),g=function(){return g=Object.assign||function(m){for(var u,e=1,i=arguments.length;e<i;e++){u=arguments[e];for(var d in u)Object.prototype.hasOwnProperty.call(u,d)&&(m[d]=u[d])}return m},g.apply(this,arguments)},U=function(m,u){var e={};for(var i in m)Object.prototype.hasOwnProperty.call(m,i)&&u.indexOf(i)<0&&(e[i]=m[i]);if(m!=null&&typeof Object.getOwnPropertySymbols=="function")for(var d=0,i=Object.getOwnPropertySymbols(m);d<i.length;d++)u.indexOf(i[d])<0&&Object.prototype.propertyIsEnumerable.call(m,i[d])&&(e[i[d]]=m[i[d]]);return e};(function(){typeof window>"u"||(navigator.mediaDevices===void 0&&(navigator.mediaDevices={}),navigator.mediaDevices.getUserMedia===void 0&&(navigator.mediaDevices.getUserMedia=function(u){var e=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;return e?new Promise(function(i,d){e.call(navigator,u,i,d)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}))})();function C(){return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}var I=function(m){f(u,m);function u(e){var i=m.call(this,e)||this;return i.canvas=null,i.ctx=null,i.requestUserMediaId=0,i.unmounted=!1,i.state={hasUserMedia:!1},i}return u.prototype.componentDidMount=function(){var e=this,i=e.state,d=e.props;if(this.unmounted=!1,!C()){d.onUserMediaError("getUserMedia not supported");return}i.hasUserMedia||this.requestUserMedia(),d.children&&typeof d.children!="function"&&console.warn("children must be a function")},u.prototype.componentDidUpdate=function(e){var i=this.props;if(!C()){i.onUserMediaError("getUserMedia not supported");return}var d=JSON.stringify(e.audioConstraints)!==JSON.stringify(i.audioConstraints),c=JSON.stringify(e.videoConstraints)!==JSON.stringify(i.videoConstraints),b=e.minScreenshotWidth!==i.minScreenshotWidth,S=e.minScreenshotHeight!==i.minScreenshotHeight;(c||b||S)&&(this.canvas=null,this.ctx=null),(d||c)&&(this.stopAndCleanup(),this.requestUserMedia())},u.prototype.componentWillUnmount=function(){this.unmounted=!0,this.stopAndCleanup()},u.stopMediaStream=function(e){e&&(e.getVideoTracks&&e.getAudioTracks?(e.getVideoTracks().map(function(i){e.removeTrack(i),i.stop()}),e.getAudioTracks().map(function(i){e.removeTrack(i),i.stop()})):e.stop())},u.prototype.stopAndCleanup=function(){var e=this.state;e.hasUserMedia&&(u.stopMediaStream(this.stream),e.src&&window.URL.revokeObjectURL(e.src))},u.prototype.getScreenshot=function(e){var i=this,d=i.state,c=i.props;if(!d.hasUserMedia)return null;var b=this.getCanvas(e);return b&&b.toDataURL(c.screenshotFormat,c.screenshotQuality)},u.prototype.getCanvas=function(e){var i=this,d=i.state,c=i.props;if(!this.video||!d.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var b=this.video.videoWidth,S=this.video.videoHeight;if(!this.props.forceScreenshotSourceSize){var h=b/S;b=c.minScreenshotWidth||this.video.clientWidth,S=b/h,c.minScreenshotHeight&&S<c.minScreenshotHeight&&(S=c.minScreenshotHeight,b=S*h)}this.canvas=document.createElement("canvas"),this.canvas.width=(e==null?void 0:e.width)||b,this.canvas.height=(e==null?void 0:e.height)||S,this.ctx=this.canvas.getContext("2d")}var w=this,M=w.ctx,v=w.canvas;return M&&v&&(v.width=(e==null?void 0:e.width)||v.width,v.height=(e==null?void 0:e.height)||v.height,c.mirrored&&(M.translate(v.width,0),M.scale(-1,1)),M.imageSmoothingEnabled=c.imageSmoothing,M.drawImage(this.video,0,0,(e==null?void 0:e.width)||v.width,(e==null?void 0:e.height)||v.height),c.mirrored&&(M.scale(-1,1),M.translate(-v.width,0))),v},u.prototype.requestUserMedia=function(){var e=this,i=this.props,d=function(S,h){var w={video:typeof h<"u"?h:!0};i.audio&&(w.audio=typeof S<"u"?S:!0),e.requestUserMediaId++;var M=e.requestUserMediaId;navigator.mediaDevices.getUserMedia(w).then(function(v){e.unmounted||M!==e.requestUserMediaId?u.stopMediaStream(v):e.handleUserMedia(null,v)}).catch(function(v){e.handleUserMedia(v)})};if("mediaDevices"in navigator)d(i.audioConstraints,i.videoConstraints);else{var c=function(S){return{optional:[{sourceId:S}]}},b=function(S){var h=S.deviceId;return typeof h=="string"?h:Array.isArray(h)&&h.length>0?h[0]:typeof h=="object"&&h.ideal?h.ideal:null};MediaStreamTrack.getSources(function(S){var h=null,w=null;S.forEach(function(x){x.kind==="audio"?h=x.id:x.kind==="video"&&(w=x.id)});var M=b(i.audioConstraints);M&&(h=M);var v=b(i.videoConstraints);v&&(w=v),d(c(h),c(w))})}},u.prototype.handleUserMedia=function(e,i){var d=this.props;if(e||!i){this.setState({hasUserMedia:!1}),d.onUserMediaError(e);return}this.stream=i;try{this.video&&(this.video.srcObject=i),this.setState({hasUserMedia:!0})}catch{this.setState({hasUserMedia:!0,src:window.URL.createObjectURL(i)})}d.onUserMedia(i)},u.prototype.render=function(){var e=this,i=this,d=i.state,c=i.props,b=c.audio;c.forceScreenshotSourceSize,c.onUserMedia,c.onUserMediaError,c.screenshotFormat,c.screenshotQuality,c.minScreenshotWidth,c.minScreenshotHeight,c.audioConstraints,c.videoConstraints,c.imageSmoothing;var S=c.mirrored,h=c.style,w=h===void 0?{}:h,M=c.children,v=U(c,["audio","forceScreenshotSourceSize","onUserMedia","onUserMediaError","screenshotFormat","screenshotQuality","minScreenshotWidth","minScreenshotHeight","audioConstraints","videoConstraints","imageSmoothing","mirrored","style","children"]),x=S?g(g({},w),{transform:(w.transform||"")+" scaleX(-1)"}):w,q={getScreenshot:this.getScreenshot.bind(this)};return s.createElement(s.Fragment,null,s.createElement("video",g({autoPlay:!0,src:d.src,muted:!b,playsInline:!0,ref:function(X){e.video=X},style:x},v)),M&&M(q))},u.defaultProps={audio:!1,forceScreenshotSourceSize:!1,imageSmoothing:!0,mirrored:!1,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",screenshotQuality:.92},u}(s.Component);a.default=I},react:function(o,a){o.exports=r}}).default})})(G);var Fe=G.exports;const Re=ee(Fe);var k;(function(t){t.PENDING="pending",t.SUCCESS="success",t.ERROR="error"})(k||(k={}));const xe=({width:t})=>R(O,{width:t,children:[p(j,{size:"threeXL",color:z.gray60,content:A}),R(ye,{children:["This app would like to use your camera.",p(Me,{href:ae,rel:"noopener noreferrer",target:"_blank",children:"Learn how to allow access."})]})]}),Pe=({handleCapture:t,width:l,disabled:r,clearPhotoInProgress:o,setClearPhotoInProgress:a,facingMode:n,setFacingMode:s,testOverride:f})=>{const[g,U]=y.useState(f||"pending"),C=y.useRef(null),[I,m]=y.useState(l),u=y.useCallback(te(1e3,m),[]);y.useEffect(()=>{u(l)},[l,u]);function e(){if(C.current!==null){const d=C.current.getScreenshot();t(d)}}const i=re();return R(D,{"data-testid":"stCameraInputWebcamComponent",children:[g!=="success"&&!r&&!o?p(xe,{width:I}):ie&&p(Ie,{switchFacingMode:s}),p(O,{"data-testid":"stCameraInputWebcamStyledBox",hidden:g!=="success"&&!r&&!o,width:I,children:!r&&p(Re,{audio:!1,ref:C,screenshotFormat:"image/jpeg",screenshotQuality:1,width:I,height:I*9/16,style:{borderRadius:`${i.radii.default} ${i.radii.default} 0 0`},onUserMediaError:()=>{U("error")},onUserMedia:()=>{U("success"),a(!1)},videoConstraints:{width:{ideal:I},facingMode:n}})}),p(H,{onClick:e,disabled:g!=="success"||r||o,children:"Take Photo"})]})},_e=150,Te=oe.getLogger("CameraInput");class Be extends ne.PureComponent{constructor(l){super(l),this.localFileIdCounter=1,this.RESTORED_FROM_WIDGET_STRING="RESTORED_FROM_WIDGET",this.formClearHelper=new ge,this.getProgress=()=>{if(this.state.files.length>0&&this.state.files[this.state.files.length-1].status.type==="uploading")return this.state.files[this.state.files.length-1].status.progress},this.setClearPhotoInProgress=r=>{this.setState({clearPhotoInProgress:r})},this.setFacingMode=()=>{this.setState(r=>({facingMode:r.facingMode===F.USER?F.ENVIRONMENT:F.USER}))},this.handleCapture=r=>{if(r===null)return Promise.resolve();this.setState({imgSrc:r,shutter:!0,minShutterEffectPassed:!1});const o=a=>new Promise(n=>setTimeout(n,a));return je(r,`camera-input-${new Date().toISOString().replace(/:/g,"_")}.jpg`).then(a=>this.props.uploadClient.fetchFileURLs([a]).then(n=>({file:a,fileUrls:n[0]}))).then(({file:a,fileUrls:n})=>this.uploadFile(n,a)).then(()=>o(_e)).then(()=>{this.setState((a,n)=>({imgSrc:r,shutter:a.shutter,minShutterEffectPassed:!0}))}).catch(a=>{Te.error(a)})},this.removeCapture=()=>{this.state.files.length!==0&&(this.state.files.forEach(r=>this.deleteFile(r.id)),this.setState({imgSrc:null,clearPhotoInProgress:!0}))},this.componentDidUpdate=()=>{if(this.status!=="ready")return;const r=this.createWidgetValue(),{element:o,widgetMgr:a,fragmentId:n}=this.props,s=a.getFileUploaderStateValue(o);se(r,s)||a.setFileUploaderStateValue(o,r,{fromUi:!0},n)},this.onFormCleared=()=>{this.setState({files:[]},()=>{const r=this.createWidgetValue();if(P(r))return;this.setState({imgSrc:null});const{widgetMgr:o,element:a,fragmentId:n}=this.props;o.setFileUploaderStateValue(a,r,{fromUi:!0},n)})},this.deleteFile=r=>{const o=this.getFile(r);P(o)||(o.status.type==="uploading"&&o.status.cancelToken.cancel(),o.status.type==="uploaded"&&o.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(o.status.fileUrls.deleteUrl),this.removeFile(r))},this.addFile=r=>{this.setState(o=>({files:[...o.files,r]}))},this.removeFile=r=>{this.setState(o=>({files:o.files.filter(a=>a.id!==r)}))},this.getFile=r=>this.state.files.find(o=>o.id===r),this.updateFile=(r,o)=>{this.setState(a=>({files:a.files.map(n=>n.id===r?o:n)}))},this.onUploadComplete=(r,o)=>{this.setState(()=>({shutter:!1}));const a=this.getFile(r);P(a)||a.status.type!=="uploading"||this.updateFile(a.id,a.setStatus({type:"uploaded",fileId:o.fileId,fileUrls:o}))},this.onUploadProgress=(r,o)=>{const a=this.getFile(o);if(P(a)||a.status.type!=="uploading")return;const n=Math.round(r.loaded*100/r.total);a.status.progress!==n&&this.updateFile(o,a.setStatus({type:"uploading",cancelToken:a.status.cancelToken,progress:n}))},this.reset=()=>{this.setState({files:[],imgSrc:null})},this.uploadFile=(r,o)=>{const a=V.CancelToken.source(),n=new W(o.name,o.size,this.nextLocalFileId(),{type:"uploading",cancelToken:a,progress:1});this.addFile(n),this.props.uploadClient.uploadFile(this.props.element,r.uploadUrl,o,s=>this.onUploadProgress(s,n.id),a.token).then(()=>this.onUploadComplete(n.id,r)).catch(s=>{V.isCancel(s)||this.updateFile(n.id,n.setStatus({type:"error",errorMessage:s?s.toString():"Unknown error"}))})},this.state=this.initialValue}get initialValue(){const l={files:[],imgSrc:null,shutter:!1,minShutterEffectPassed:!0,clearPhotoInProgress:!1,facingMode:F.USER},{widgetMgr:r,element:o}=this.props,a=r.getFileUploaderStateValue(o);if(P(a))return l;const{uploadedFileInfo:n}=a;return P(n)||n.length===0?l:{files:n.map(s=>{const f=s.name,g=s.size,U=s.fileId,C=s.fileUrls;return new W(f,g,this.nextLocalFileId(),{type:"uploaded",fileId:U,fileUrls:C})}),imgSrc:n.length===0?"":this.RESTORED_FROM_WIDGET_STRING,shutter:!1,minShutterEffectPassed:!1,clearPhotoInProgress:!1,facingMode:F.USER}}componentWillUnmount(){this.formClearHelper.disconnect()}get status(){const l=r=>r.status.type==="uploading";return this.state.files.some(l)?"updating":"ready"}componentDidMount(){const l=this.createWidgetValue(),{element:r,widgetMgr:o,fragmentId:a}=this.props;o.getFileUploaderStateValue(r)===void 0&&o.setFileUploaderStateValue(r,l,{fromUi:!1},a)}createWidgetValue(){const l=this.state.files.filter(r=>r.status.type==="uploaded").map(r=>{const{name:o,size:a,status:n}=r;return new le({fileId:n.fileId,fileUrls:n.fileUrls,name:o,size:a})});return new de({uploadedFileInfo:l})}render(){var n;const{element:l,widgetMgr:r,disabled:o,width:a}=this.props;return this.formClearHelper.manageFormClearListener(r,l.formId,this.onFormCleared),R(D,{className:"stCameraInput","data-testid":"stCameraInput",children:[p(he,{label:l.label,disabled:o,labelVisibility:ce((n=l.labelVisibility)==null?void 0:n.value),children:l.help&&p(ue,{children:p(fe,{content:l.help,placement:B.TOP_RIGHT})})}),this.state.imgSrc?R(pe,{children:[p(O,{width:a,children:this.state.imgSrc!==this.RESTORED_FROM_WIDGET_STRING&&p(be,{src:this.state.imgSrc,alt:"Snapshot",opacity:this.state.shutter||!this.state.minShutterEffectPassed?"50%":"100%",width:a,height:a*9/16})}),p(H,{onClick:this.removeCapture,progress:this.getProgress(),disabled:!!this.getProgress()||o,children:this.getProgress()?"Uploading...":R(we,{children:[p(j,{content:N,margin:"0 xs 0 0",size:"sm"})," Clear photo"]})})]}):p(Pe,{handleCapture:this.handleCapture,width:a,disabled:o,clearPhotoInProgress:this.state.clearPhotoInProgress,setClearPhotoInProgress:this.setClearPhotoInProgress,facingMode:this.state.facingMode,setFacingMode:this.setFacingMode,testOverride:this.props.testOverride})]})}nextLocalFileId(){return this.localFileIdCounter++}}function je(t,l){return fetch(t).then(r=>r.arrayBuffer()).then(r=>new File([r],l,{type:"image/jpeg"}))}export{Be as default};
|