"use strict";var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,o=(t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n;const i=require("../../../../common/vendor.js"),c=e=>/^data:image\/(\w+);base64/.test(e);let{platform:p,SDKVersion:u}=i.index.getSystemInfoSync();const l=/windows|mac/.test(p);let f={};function h(e){return function(e,t){e=e.split("."),t=t.split(".");const r=Math.max(e.length,t.length);for(;e.lengths)return 1;if(r=0}const g=()=>i.wx$1;function d(e){const[,t]=/^data:image\/(\w+);base64,/.exec(e)||[];return new Promise(((r,n)=>{const s=i.index.getFileSystemManager();t||n(new Error("ERROR_BASE64SRC_PARSE"));const a=(new Date).getTime();const o=`${g().env.USER_DATA_PATH}/${a}.${t}`;s.writeFile({filePath:o,data:e.split(",")[1],encoding:"base64",success(){r(o)},fail(e){n(e)}})}))}exports.base64ToPath=d,exports.canIUseCanvas2d=function(){return h("2.9.2")},exports.getImageInfo=function(e,p){const u=this&&this.canvas&&this.canvas.createImage;return new Promise(((p,h)=>{return g=this,m=null,x=function*(){let g=e.replace(/^@\//,"/");if(f[e]&&f[e].errMsg)p(f[e]);else{try{!c(e)||u&&!l||(g=yield d(e))}catch(x){h((m=((e,t)=>{for(var r in t||(t={}))s.call(t,r)&&o(e,r,t[r]);if(n)for(var r of n(t))a.call(t,r)&&o(e,r,t[r]);return e})({},x),t(m,r({src:g}))))}if(u&&!l){const t=this.canvas.createImage();return t.onload=function(){const r={path:t,width:t.width,height:t.height};f[e]=r,p(f[e])},t.onerror=function(t){h({err:t,path:e})},void(t.src=g)}i.index.getImageInfo({src:g,success:t=>{if(t.path=/^\.|^\/(?=[^\/])/.test(g)?`/${t.path}`:t.path,u){const r=this.canvas.createImage();return r.onload=function(){t.path=r,f[e]=t,p(f[e])},r.onerror=function(t){h({err:t,path:e})},void(r.src=g)}f[e]=t,p(f[e])},fail(t){h({err:t,path:e})}})}var m},new Promise(((e,t)=>{var r=e=>{try{s(x.next(e))}catch(r){t(r)}},n=e=>{try{s(x.throw(e))}catch(r){t(r)}},s=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,n);s((x=x.apply(g,m)).next())}));var g,m,x}))},exports.isBase64=c,exports.isPC=l,exports.pathToBase64=function(e){return/^data:/.test(e)?e:new Promise(((t,r)=>{i.index.canIUse("getFileSystemManager")&&i.index.getFileSystemManager().readFile({filePath:e,encoding:"base64",success:e=>{t("data:image/png;base64,"+e.data)},fail:e=>{r(e)}})}))},exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.toPx=function e(t,r,n=!1){if("number"==typeof t)return t;if(function(e){return/^-?\d+(\.\d+)?$/.test(e)}(t))return 1*t;if("string"==typeof t){const s=/^-?([0-9]+)?([.]{1}[0-9]+){0,1}(em|rpx|px|%)$/g.exec(t);if(!t||!s)return 0;const a=s[3];t=parseFloat(t);let o=0;return"rpx"===a?o=i.index.upx2px(t):"px"===a?o=1*t:"%"===a?o=t*e(r)/100:"em"===a&&(o=t*e(14)),n?1*o.toFixed(2):Math.round(o)}return 0};