UNPKG

ng-navigator-share

Version:

Lightweight Angular wrapper on Web Share API to share PWA apps, Text, URL.

16 lines (14 loc) 4.32 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ng-navigator-share",["exports","@angular/core"],t):t((e=e||self)["ng-navigator-share"]={},e.ng.core)}(this,(function(e,t){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function r(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function n(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function u(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))}function o(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=i.trys,(o=o.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 a=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,r=e.title,a=e.text,i=e.url,u=e.files;return new Promise((function(e,c){return n(t,void 0,void 0,(function(){var t,n;return o(this,(function(o){switch(o.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 o.trys.push([1,3,,4]),t={title:r,text:a,url:i},u&&0!==u.length&&(t.files=u),[4,this.webNavigator.share(t)];case 2:return o.sent(),e({shared:!0}),[3,4];case 3:return n=o.sent(),c({shared:!1,error:n}),[3,4];case 4:return[3,6];case 5:c({shared:!1,error:"This service/api is not supported in your Browser"}),o.label=6;case 6:return[2]}}))}))}))},e.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e=function(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i}([t.Injectable({providedIn:"root"}),r("design:paramtypes",[])],e)}();e.NgNavigatorShareService=a,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ng-navigator-share.umd.min.js.map