ng-web-share
Version:
This library helps to use native webshare framework in angular apps
16 lines (14 loc) • 4.32 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ng-web-share",["exports","@angular/core"],t):t((e=e||self)["ng-web-share"]={},e.ng.core)}(this,(function(e,t){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function r(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{s(n.next(e))}catch(e){a(e)}}function u(e){try{s(n.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}s((n=n.apply(e,t||[])).next())}))}function n(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var o=function(){function e(){this.webNavigator=null,this.webNavigator=window.navigator}return e.prototype.canShare=function(){return null!==this.webNavigator&&void 0!==this.webNavigator.share},e.prototype.canShareFile=function(e){return null!==this.webNavigator&&void 0!==this.webNavigator.share&&this.webNavigator.canShare({files:e})},e.prototype.share=function(e){var t=this,o=e.title,a=e.text,i=e.url,u=e.files;return new Promise((function(e,s){return r(t,void 0,void 0,(function(){var t,r;return n(this,(function(n){switch(n.label){case 0:return null===this.webNavigator||void 0===this.webNavigator.share?[3,5]:null!=a||null!=i?[3,1]:(console.warn("text and url both can't be empty, at least provide either text or url"),[3,4]);case 1:return n.trys.push([1,3,,4]),t={title:o,text:a,url:i},u&&0!==u.length&&(t.files=u),[4,this.webNavigator.share(t)];case 2:return n.sent(),e({shared:!0}),[3,4];case 3:return r=n.sent(),s({shared:!1,error:r}),[3,4];case 4:return[3,6];case 5:s({shared:!1,error:"This service/api is not supported in your Browser"}),n.label=6;case 6:return[2]}}))}))}))},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}();var a=function(){function e(){}return e.prototype.ngOnInit=function(){},e.decorators=[{type:t.Component,args:[{selector:"lib-web-share",template:"\n <p>\n web-share works!\n </p>\n "}]}],e.ctorParameters=function(){return[]},e}(),i=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{declarations:[a],imports:[],exports:[a],providers:[o]}]}],e}();e.WebShareComponent=a,e.WebShareModule=i,e.WebShareService=o,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-web-share.umd.min.js.map