2 lines
8.9 KiB
JavaScript
2 lines
8.9 KiB
JavaScript
import{c as s,t as O,G as T,H as x,aJ as I,l as C,d4 as L,z as R,D as p,Q as S,T as b,U as $,a2 as M,a4 as E,d5 as k}from"./index-CEmnTf-r.js";var j={},m={},P=s&&s.__awaiter||function(o,l,n,a){function r(e){return e instanceof n?e:new n(function(i){i(e)})}return new(n||(n=Promise))(function(e,i){function c(u){try{t(a.next(u))}catch(d){i(d)}}function f(u){try{t(a.throw(u))}catch(d){i(d)}}function t(u){u.done?e(u.value):r(u.value).then(c,f)}t((a=a.apply(o,l||[])).next())})},A=s&&s.__generator||function(o,l){var n={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},a,r,e,i;return i={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(t){return function(u){return f([t,u])}}function f(t){if(a)throw new TypeError("Generator is already executing.");for(;i&&(i=0,t[0]&&(n=0)),n;)try{if(a=1,r&&(e=t[0]&2?r.return:t[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,t[1])).done)return e;switch(r=0,e&&(t=[t[0]&2,e.value]),t[0]){case 0:case 1:e=t;break;case 4:return n.label++,{value:t[1],done:!1};case 5:n.label++,r=t[1],t=[0];continue;case 7:t=n.ops.pop(),n.trys.pop();continue;default:if(e=n.trys,!(e=e.length>0&&e[e.length-1])&&(t[0]===6||t[0]===2)){n=0;continue}if(t[0]===3&&(!e||t[1]>e[0]&&t[1]<e[3])){n.label=t[1];break}if(t[0]===6&&n.label<e[1]){n.label=e[1],e=t;break}if(e&&n.label<e[2]){n.label=e[2],n.ops.push(t);break}e[2]&&n.ops.pop(),n.trys.pop();continue}t=l.call(o,n)}catch(u){t=[6,u],r=0}finally{a=e=0}if(t[0]&5)throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}};Object.defineProperty(m,"__esModule",{value:!0});m.base64ToBlob=G;function G(o){return P(this,void 0,void 0,function(){var l,n,a;return A(this,function(r){switch(r.label){case 0:return[4,fetch(o)];case 1:return l=r.sent(),[4,l.blob()];case 2:return n=r.sent(),a=z(o),a&&(n=n.slice(0,n.size,a)),[2,n]}})})}var U=/^data:(.+);base64,/;function z(o){var l;return(l=o.match(U))===null||l===void 0?void 0:l.slice(1,2).pop()}var w={},D=s&&s.__awaiter||function(o,l,n,a){function r(e){return e instanceof n?e:new n(function(i){i(e)})}return new(n||(n=Promise))(function(e,i){function c(u){try{t(a.next(u))}catch(d){i(d)}}function f(u){try{t(a.throw(u))}catch(d){i(d)}}function t(u){u.done?e(u.value):r(u.value).then(c,f)}t((a=a.apply(o,l||[])).next())})},N=s&&s.__generator||function(o,l){var n={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},a,r,e,i;return i={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(t){return function(u){return f([t,u])}}function f(t){if(a)throw new TypeError("Generator is already executing.");for(;i&&(i=0,t[0]&&(n=0)),n;)try{if(a=1,r&&(e=t[0]&2?r.return:t[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,t[1])).done)return e;switch(r=0,e&&(t=[t[0]&2,e.value]),t[0]){case 0:case 1:e=t;break;case 4:return n.label++,{value:t[1],done:!1};case 5:n.label++,r=t[1],t=[0];continue;case 7:t=n.ops.pop(),n.trys.pop();continue;default:if(e=n.trys,!(e=e.length>0&&e[e.length-1])&&(t[0]===6||t[0]===2)){n=0;continue}if(t[0]===3&&(!e||t[1]>e[0]&&t[1]<e[3])){n.label=t[1];break}if(t[0]===6&&n.label<e[1]){n.label=e[1],e=t;break}if(e&&n.label<e[2]){n.label=e[2],n.ops.push(t);break}e[2]&&n.ops.pop(),n.trys.pop();continue}t=l.call(o,n)}catch(u){t=[6,u],r=0}finally{a=e=0}if(t[0]&5)throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}};Object.defineProperty(w,"__esModule",{value:!0});w.base64ToFile=W;function W(o,l,n){return D(this,void 0,void 0,function(){var a,r;return N(this,function(e){switch(e.label){case 0:return[4,fetch(o)];case 1:return a=e.sent(),[4,a.blob()];case 2:return r=e.sent(),[2,new File([r],l,n)]}})})}var y={},_=s&&s.__awaiter||function(o,l,n,a){function r(e){return e instanceof n?e:new n(function(i){i(e)})}return new(n||(n=Promise))(function(e,i){function c(u){try{t(a.next(u))}catch(d){i(d)}}function f(u){try{t(a.throw(u))}catch(d){i(d)}}function t(u){u.done?e(u.value):r(u.value).then(c,f)}t((a=a.apply(o,l||[])).next())})},g=s&&s.__generator||function(o,l){var n={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},a,r,e,i;return i={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(t){return function(u){return f([t,u])}}function f(t){if(a)throw new TypeError("Generator is already executing.");for(;i&&(i=0,t[0]&&(n=0)),n;)try{if(a=1,r&&(e=t[0]&2?r.return:t[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,t[1])).done)return e;switch(r=0,e&&(t=[t[0]&2,e.value]),t[0]){case 0:case 1:e=t;break;case 4:return n.label++,{value:t[1],done:!1};case 5:n.label++,r=t[1],t=[0];continue;case 7:t=n.ops.pop(),n.trys.pop();continue;default:if(e=n.trys,!(e=e.length>0&&e[e.length-1])&&(t[0]===6||t[0]===2)){n=0;continue}if(t[0]===3&&(!e||t[1]>e[0]&&t[1]<e[3])){n.label=t[1];break}if(t[0]===6&&n.label<e[1]){n.label=e[1],e=t;break}if(e&&n.label<e[2]){n.label=e[2],n.ops.push(t);break}e[2]&&n.ops.pop(),n.trys.pop();continue}t=l.call(o,n)}catch(u){t=[6,u],r=0}finally{a=e=0}if(t[0]&5)throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}};Object.defineProperty(y,"__esModule",{value:!0});y.blobToBase64=H;function H(o){return _(this,void 0,void 0,function(){return g(this,function(l){return[2,typeof FileReader=="function"?J(o):q(o)]})})}var h;(function(o){o.error="error",o.loadend="loadend"})(h||(h={}));function J(o){return _(this,void 0,void 0,function(){return g(this,function(l){return[2,new Promise(function(n,a){try{var r=new FileReader,e=function(){n(r.result),r.removeEventListener(h.loadend,e)};r.addEventListener(h.loadend,e);var i=function(){a(r.error),r.removeEventListener(h.error,i)};r.addEventListener(h.error,i),r.readAsDataURL(o)}catch(c){a(c)}})]})})}var Q="application/octet-stream";function q(o){return _(this,void 0,void 0,function(){var l,n,a,r;return g(this,function(e){switch(e.label){case 0:return a=(n=Buffer).from,[4,o.text()];case 1:return l=a.apply(n,[e.sent()]),r=o.type||Q,[2,"data:".concat(r,";base64,").concat(l.toString("base64"))]}})})}var F={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),o.fileToBase64=void 0;var l=y;Object.defineProperty(o,"fileToBase64",{enumerable:!0,get:function(){return l.blobToBase64}})})(F);(function(o){var l=s&&s.__createBinding||(Object.create?function(a,r,e,i){i===void 0&&(i=e);var c=Object.getOwnPropertyDescriptor(r,e);(!c||("get"in c?!r.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return r[e]}}),Object.defineProperty(a,i,c)}:function(a,r,e,i){i===void 0&&(i=e),a[i]=r[e]}),n=s&&s.__exportStar||function(a,r){for(var e in a)e!=="default"&&!Object.prototype.hasOwnProperty.call(r,e)&&l(r,a,e)};Object.defineProperty(o,"__esModule",{value:!0}),n(m,o),n(w,o),n(y,o),n(F,o)})(j);var K=function(o){O(l,o);function l(){return o!==null&&o.apply(this,arguments)||this}return l.prototype.uploadFile=function(n,a){return T(this,void 0,void 0,function(){var r,e,i;return x(this,function(c){switch(c.label){case 0:return r=k(a,"post"),r.data?[3,2]:(e=new FormData,[4,j.base64ToBlob(n)]);case 1:i=c.sent(),e.append("file",i,"signature.png"),r.data=e,c.label=2;case 2:return[2,this.props.env.fetcher(r,E(this.props.data,{file:n}))]}})})},l.prototype.handleChange=function(n){var a,r;return T(this,void 0,void 0,function(){var e,i,c,f,t,u,d,B;return x(this,function(v){switch(v.label){case 0:if(e=this.props,i=e.translate,c=e.uploadApi,f=e.embed,t=e.onChange,!f||!c||n===void 0)return t==null||t(n),[2];v.label=1;case 1:return v.trys.push([1,3,,4]),[4,this.uploadFile(n,c)];case 2:if(u=v.sent(),!u.ok||u.status&&u.status!=="0"||!u.data)throw new Error(u.msg||i("File.errorRetry"));return d=u.data.value||u.data.url||u.data,t==null||t(d),[3,4];case 3:return B=v.sent(),t==null||t(""),(r=(a=this.props.env)===null||a===void 0?void 0:a.alert)===null||r===void 0||r.call(a,B.message||i("File.errorRetry")),[3,4];case 4:return[2]}})})},l.prototype.render=function(){var n=this.props,a=n.classnames,r=n.className,e=I(this.props,["value","width","height","mobileUI","embed","color","bgColor","clearBtnLabel","clearBtnIcon","undoBtnLabel","undoBtnIcon","confirmBtnLabel","confirmBtnIcon","embedConfirmLabel","embedConfirmIcon","ebmedCancelLabel","ebmedCancelIcon","embedBtnIcon","embedBtnLabel","uploadApi"]);return C.createElement(L,R({classnames:a,className:r,onChange:this.handleChange},e))},p([S,b("design:type",Function),b("design:paramtypes",[String,String]),b("design:returntype",Promise)],l.prototype,"uploadFile",null),p([S,b("design:type",Function),b("design:paramtypes",[Object]),b("design:returntype",Promise)],l.prototype,"handleChange",null),l}(C.Component),X=function(o){O(l,o);function l(n,a){var r=o.call(this,n)||this,e=a;return e.registerComponent(r),r}return l.prototype.componentWillUnmount=function(){var n;(n=o.prototype.componentWillUnmount)===null||n===void 0||n.call(this);var a=this.context;a.unRegisterComponent(this)},l.contextType=$,l=p([M({type:"input-signature",sizeMutable:!1}),b("design:paramtypes",[Object,Object])],l),l}(K);export{X as InputSignatureRenderer,K as default};
|