@flumens/utils 0.8.0 → 0.8.1
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/dist/image.js +1 -1
- package/package.json +1 -1
package/dist/image.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createImage=void 0,exports.getObjectURL=a,exports.saveFile=function(e,o){return t.__awaiter(this,void 0,void 0,(function*(){if(!r.Capacitor.isNativePlatform())return a(e);yield i.Filesystem.writeFile({path:o,data:e,directory:i.Directory.Data});const{uri:t}=yield i.Filesystem.stat({path:o,directory:i.Directory.Data});return t}))},exports.deleteFile=function(e){return t.__awaiter(this,void 0,void 0,(function*(){r.Capacitor.isNativePlatform()&&(yield i.Filesystem.deleteFile({path:e,directory:i.Directory.Data}))}))},exports.resizeImage=o,exports.cropImage=function(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=0){const i=yield(0,exports.createImage)(t),a=document.createElement("canvas"),o=a.getContext("2d");if(!o)return"";const s=n(r),{width:c,height:l}=function(t,e,r){const i=n(r),a=Math.abs(Math.cos(i)*t)+Math.abs(Math.sin(i)*e),o=Math.abs(Math.sin(i)*t)+Math.abs(Math.cos(i)*e);return{width:a,height:o}}(i.width,i.height,r);a.width=c,a.height=l,o.translate(c/2,l/2),o.rotate(s),o.translate(-i.width/2,-i.height/2),o.drawImage(i,0,0);const u=document.createElement("canvas"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createImage=void 0,exports.getObjectURL=a,exports.saveFile=function(e,o){return t.__awaiter(this,void 0,void 0,(function*(){if(!r.Capacitor.isNativePlatform())return a(e);yield i.Filesystem.writeFile({path:o,data:e,directory:i.Directory.Data});const{uri:t}=yield i.Filesystem.stat({path:o,directory:i.Directory.Data});return t}))},exports.deleteFile=function(e){return t.__awaiter(this,void 0,void 0,(function*(){r.Capacitor.isNativePlatform()&&(yield i.Filesystem.deleteFile({path:e,directory:i.Directory.Data}))}))},exports.resizeImage=o,exports.cropImage=function(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=0){const i=yield(0,exports.createImage)(t),a=document.createElement("canvas"),o=a.getContext("2d");if(!o)return"";const s=n(r),{width:c,height:l}=function(t,e,r){const i=n(r),a=Math.abs(Math.cos(i)*t)+Math.abs(Math.sin(i)*e),o=Math.abs(Math.sin(i)*t)+Math.abs(Math.cos(i)*e);return{width:a,height:o}}(i.width,i.height,r);a.width=c,a.height=l,o.translate(c/2,l/2),o.rotate(s),o.translate(-i.width/2,-i.height/2),o.drawImage(i,0,0);const u=document.createElement("canvas"),d=u.getContext("2d");return d?(u.width=e.width,u.height=e.height,d.drawImage(a,e.x,e.y,e.width,e.height,0,0,e.width,e.height),u.toDataURL()):""}))},exports.isDataURL=c,exports.dataURItoBlob=l,exports.getBlobFromURL=function(t,e){if(c(t)){const r=l(t,e);return Promise.resolve(r)}return new Promise((e=>{const r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="blob",r.onload=()=>{const t=r.response;e(t)},r.send()}))},exports.captureImage=function(){return t.__awaiter(this,arguments,void 0,(function*(r={}){const a=yield function(r){return t.__awaiter(this,void 0,void 0,(function*(){const{camera:i,multiple:a,getPhoto:o}=r,n=t.__rest(r,["camera","multiple","getPhoto"]);if(o){const t=yield o();return t?[t]:[]}if(a)try{const t=Object.assign({quality:40,correctOrientation:!0,limit:30},n);return(yield e.Camera.pickImages(t)).photos}catch(t){if(t.message.includes("User cancelled photos app")||t.message.includes("No images picked"))return[];throw t}try{const t=Object.assign({quality:40,allowEditing:!1,saveToGallery:!0,webUseInput:!0,correctOrientation:!0,resultType:e.CameraResultType.Uri,source:i?e.CameraSource.Camera:e.CameraSource.Photos},n);return[yield e.Camera.getPhoto(t)]}catch(t){if(t.message.includes("User cancelled photos app")||t.message.includes("No image picked"))return[];throw t}}))}(r),o=[];for(const t of a){const{path:e}=t;if(!e){t.webPath&&o.push(t.webPath);continue}const r=yield s(e);if(e.includes("/tmp/")||e.includes("/cache/"))try{yield i.Filesystem.deleteFile({path:e})}catch(t){}o.push(r)}return o}))};const t=require("tslib"),e=require("@capacitor/camera"),r=require("@capacitor/core"),i=require("@capacitor/filesystem");function a(t){const e=t.split(",")[0].split(":")[1].split(";")[0],r=window.atob(t.split(",")[1]),i=[];for(let t=0;t<r.length;t++)i.push(r.charCodeAt(t));const a=new Blob([new Uint8Array(i)],{type:e});return window.URL.createObjectURL(a)}function o({url:t,fileType:e="image/jpeg",MAX_WIDTH:r=2e3,MAX_HEIGHT:i=2e3}){return new Promise((a=>{const o=new window.Image;o.onload=()=>{var t;let{width:n}=o,{height:s}=o;let c=null;c=n>s?n/(r>n?n:r):s/(i>s?s:i),n/=c,s/=c;const l=document.createElement("canvas");l.width=n,l.height=s,null===(t=l.getContext("2d"))||void 0===t||t.drawImage(o,0,0,n,s),a([o,l.toDataURL(e)])},o.src=t}))}function n(t){return t*Math.PI/180}function s(e){return t.__awaiter(this,void 0,void 0,(function*(){const t=`${Date.now()}.jpeg`,[,a]=yield o({url:r.Capacitor.convertFileSrc(e)});yield i.Filesystem.writeFile({path:t,data:a,directory:i.Directory.Data});const{uri:n}=yield i.Filesystem.stat({path:t,directory:i.Directory.Data});return n}))}function c(t){if(!t)return!1;return!!t.toString().match(/^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i)}function l(t,e){const r=atob(t.split(",")[1]),i=[];for(let t=0;t<r.length;t++)i.push(r.charCodeAt(t));return new Blob([new Uint8Array(i)],{type:e})}exports.createImage=t=>new Promise(((e,r)=>{const i=new window.Image;i.onload=()=>e(i),i.onerror=t=>r(t),i.src=t}));
|