UNPKG

@angular/common

Version:

Angular - commonly needed directives and services

48 lines (46 loc) 14.1 kB
/** * @license Angular v11.2.8 * (c) 2010-2021 Google LLC. https://angular.io/ * License: MIT */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("rxjs"),require("@angular/common"),require("@angular/core"),require("@angular/upgrade/static")):"function"==typeof define&&define.amd?define("@angular/common/upgrade",["exports","rxjs","@angular/common","@angular/core","@angular/upgrade/static"],e):e(((t=t||self).ng=t.ng||{},t.ng.common=t.ng.common||{},t.ng.common.upgrade={}),t.rxjs,t.ng.common,t.ng.core,t.ng.upgrade.static)}(this,(function(t,e,r,o,a){"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. ***************************************************************************** */var n=/^([^?#]*)(\?([^#]*))?(#(.*))?$/,i=/^\s*[\\/]{2,}/,s=/^\s*(javascript|mailto):/i,h={"http:":80,"https:":443,"ftp:":21},c=function(){function t(t,r,o,a,n){var i=this;this.location=r,this.platformLocation=o,this.urlCodec=a,this.locationStrategy=n,this.initalizing=!0,this.updateBrowser=!1,this.$$absUrl="",this.$$url="",this.$$host="",this.$$replace=!1,this.$$path="",this.$$search="",this.$$hash="",this.$$changeListeners=[],this.cachedState=null,this.urlChanges=new e.ReplaySubject(1),this.lastBrowserUrl="",this.lastCachedState=null;var s=this.browserUrl(),c=this.urlCodec.parse(s);if("string"==typeof c)throw"Invalid URL";this.$$protocol=c.protocol,this.$$host=c.hostname,this.$$port=parseInt(c.port)||h[c.protocol]||null,this.$$parseLinkUrl(s,s),this.cacheState(),this.$$state=this.browserState(),this.location.onUrlChange((function(t,e){i.urlChanges.next({newUrl:t,newState:e})})),function p(t){return!!t&&"function"==typeof t.then}(t)?t.then((function(t){return i.initialize(t)})):this.initialize(t)}return t.prototype.initialize=function(t){var e=this,r=t.get("$rootScope"),o=t.get("$rootElement");o.on("click",(function(t){if(!(t.ctrlKey||t.metaKey||t.shiftKey||2===t.which||2===t.button)){for(var a=t.target;a&&"a"!==a.nodeName.toLowerCase();)if(a===o[0]||!(a=a.parentNode))return;if(function n(t){return void 0!==t.href}(a)){var i=a.href,h=a.getAttribute("href");s.test(i)||!i||a.getAttribute("target")||t.isDefaultPrevented()||e.$$parseLinkUrl(i,h)&&(t.preventDefault(),e.absUrl()!==e.browserUrl()&&r.$apply())}}})),this.urlChanges.subscribe((function(t){var o=t.newUrl,a=t.newState,n=e.absUrl(),i=e.$$state;e.$$parse(o),o=e.absUrl(),e.$$state=a;var s=r.$broadcast("$locationChangeStart",o,n,a,i).defaultPrevented;e.absUrl()===o&&(s?(e.$$parse(n),e.state(i),e.setBrowserUrlWithFallback(n,!1,i),e.$$notifyChangeListeners(e.url(),e.$$state,n,i)):(e.initalizing=!1,r.$broadcast("$locationChangeSuccess",o,n,a,i),e.resetBrowserUpdate()),r.$$phase||r.$digest())})),r.$watch((function(){if(e.initalizing||e.updateBrowser){e.updateBrowser=!1;var t=e.browserUrl(),o=e.absUrl(),a=e.browserState(),n=e.$$replace,i=!e.urlCodec.areEqual(t,o)||a!==e.$$state;(e.initalizing||i)&&(e.initalizing=!1,r.$evalAsync((function(){var o=e.absUrl(),s=r.$broadcast("$locationChangeStart",o,t,e.$$state,a).defaultPrevented;e.absUrl()===o&&(s?(e.$$parse(t),e.$$state=a):(i&&(e.setBrowserUrlWithFallback(o,n,a===e.$$state?null:e.$$state),e.$$replace=!1),r.$broadcast("$locationChangeSuccess",o,t,e.$$state,a),i&&e.$$notifyChangeListeners(e.url(),e.$$state,t,a)))})))}e.$$replace=!1}))},t.prototype.resetBrowserUpdate=function(){this.$$replace=!1,this.$$state=this.browserState(),this.updateBrowser=!1,this.lastBrowserUrl=this.browserUrl()},t.prototype.browserUrl=function(t,e,r){if(void 0===r&&(r=null),t){var o=this.lastHistoryState===r;return t=this.urlCodec.parse(t).href,this.lastBrowserUrl===t&&o||(this.lastBrowserUrl=t,this.lastHistoryState=r,t=this.stripBaseUrl(this.getServerBase(),t)||t,e?this.locationStrategy.replaceState(r,"",t,""):this.locationStrategy.pushState(r,"",t,""),this.cacheState()),this}return this.platformLocation.href},t.prototype.cacheState=function(){this.cachedState=this.platformLocation.getState(),void 0===this.cachedState&&(this.cachedState=null),function t(e,r){if(e===r)return!0;if(!e||!r)return!1;try{return!(e.prototype!==r.prototype||Array.isArray(e)&&Array.isArray(r))&&JSON.stringify(e)===JSON.stringify(r)}catch(t){return!1}}(this.cachedState,this.lastCachedState)&&(this.cachedState=this.lastCachedState),this.lastCachedState=this.cachedState,this.lastHistoryState=this.cachedState},t.prototype.browserState=function(){return this.cachedState},t.prototype.stripBaseUrl=function(t,e){if(e.startsWith(t))return e.substr(t.length)},t.prototype.getServerBase=function(){var t=this.platformLocation,e=t.port,r=t.protocol+"//"+t.hostname+(e?":"+e:"")+(this.locationStrategy.getBaseHref()||"/");return r.endsWith("/")?r:r+"/"},t.prototype.parseAppUrl=function(t){if(i.test(t))throw new Error("Bad Path - URL cannot start with double slashes: "+t);var e="/"!==t.charAt(0);e&&(t="/"+t);var r=this.urlCodec.parse(t,this.getServerBase());if("string"==typeof r)throw new Error("Bad URL - Cannot parse URL: "+t);var o=e&&"/"===r.pathname.charAt(0)?r.pathname.substring(1):r.pathname;this.$$path=this.urlCodec.decodePath(o),this.$$search=this.urlCodec.decodeSearch(r.search),this.$$hash=this.urlCodec.decodeHash(r.hash),this.$$path&&"/"!==this.$$path.charAt(0)&&(this.$$path="/"+this.$$path)},t.prototype.onChange=function(t,e){void 0===e&&(e=function(t){}),this.$$changeListeners.push([t,e])},t.prototype.$$notifyChangeListeners=function(t,e,r,o){void 0===t&&(t=""),void 0===r&&(r=""),this.$$changeListeners.forEach((function(a){var n=function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,a,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){a={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return i}(a,2),s=n[0],h=n[1];try{s(t,e,r,o)}catch(t){h(t)}}))},t.prototype.$$parse=function(t){var e;if(void 0===(e=t.startsWith("/")?t:this.stripBaseUrl(this.getServerBase(),t)))throw new Error('Invalid url "'+t+'", missing path prefix "'+this.getServerBase()+'".');this.parseAppUrl(e),this.$$path||(this.$$path="/"),this.composeUrls()},t.prototype.$$parseLinkUrl=function(t,e){if(e&&"#"===e[0])return this.hash(e.slice(1)),!0;var r,o=this.stripBaseUrl(this.getServerBase(),t);return void 0!==o?r=this.getServerBase()+o:this.getServerBase()===t+"/"&&(r=this.getServerBase()),r&&this.$$parse(r),!!r},t.prototype.setBrowserUrlWithFallback=function(t,e,r){var o=this.url(),a=this.$$state;try{this.browserUrl(t,e,r),this.$$state=this.browserState()}catch(t){throw this.url(o),this.$$state=a,t}},t.prototype.composeUrls=function(){this.$$url=this.urlCodec.normalize(this.$$path,this.$$search,this.$$hash),this.$$absUrl=this.getServerBase()+this.$$url.substr(1),this.updateBrowser=!0},t.prototype.absUrl=function(){return this.$$absUrl},t.prototype.url=function(t){if("string"==typeof t){t.length||(t="/");var e=n.exec(t);return e?((e[1]||""===t)&&this.path(this.urlCodec.decodePath(e[1])),(e[2]||e[1]||""===t)&&this.search(e[3]||""),this.hash(e[5]||""),this):this}return this.$$url},t.prototype.protocol=function(){return this.$$protocol},t.prototype.host=function(){return this.$$host},t.prototype.port=function(){return this.$$port},t.prototype.path=function(t){return void 0===t?this.$$path:(t="/"===(t=null!==t?t.toString():"").charAt(0)?t:"/"+t,this.$$path=t,this.composeUrls(),this)},t.prototype.search=function(t,e){switch(arguments.length){case 0:return this.$$search;case 1:if("string"==typeof t||"number"==typeof t)this.$$search=this.urlCodec.decodeSearch(t.toString());else{if("object"!=typeof t||null===t)throw new Error("LocationProvider.search(): First argument must be a string or an object.");for(var r in t=Object.assign({},t))null==t[r]&&delete t[r];this.$$search=t}break;default:if("string"==typeof t){var o=this.search();return null==e?(delete o[t],this.search(o)):(o[t]=e,this.search(o))}}return this.composeUrls(),this},t.prototype.hash=function(t){return void 0===t?this.$$hash:(this.$$hash=null!==t?t.toString():"",this.composeUrls(),this)},t.prototype.replace=function(){return this.$$replace=!0,this},t.prototype.state=function(t){return void 0===t?this.$$state:(this.$$state=t,this)},t}(),p=function(){function t(t,e,r,o,a){this.ngUpgrade=t,this.location=e,this.platformLocation=r,this.urlCodec=o,this.locationStrategy=a}return t.prototype.$get=function(){return new c(this.ngUpgrade.$injector,this.location,this.platformLocation,this.urlCodec,this.locationStrategy)},t.prototype.hashPrefix=function(t){throw new Error("Configure LocationUpgrade through LocationUpgradeModule.config method.")},t.prototype.html5Mode=function(t){throw new Error("Configure LocationUpgrade through LocationUpgradeModule.config method.")},t}(),u=function u(){},l=function(){function t(){}return t.prototype.encodePath=function(t){for(var e=t.split("/"),r=e.length;r--;)e[r]=f(e[r].replace(/%2F/g,"/"));return function o(t){return t.replace(/\/index.html$/,"")}(((t=e.join("/"))&&"/"!==t[0]?"/":"")+t)},t.prototype.encodeSearch=function(t){return"string"==typeof t&&(t=d(t)),(t=function e(t){var e=[],r=function(r){var o=t[r];Array.isArray(o)?o.forEach((function(t){e.push(g(r,!0)+(!0===t?"":"="+g(t,!0)))})):e.push(g(r,!0)+(!0===o?"":"="+g(o,!0)))};for(var o in t)r(o);return e.length?e.join("&"):""}(t))?"?"+t:""},t.prototype.encodeHash=function(t){return(t=f(t))?"#"+t:""},t.prototype.decodePath=function(t,e){void 0===e&&(e=!0);for(var r=t.split("/"),o=r.length;o--;)r[o]=decodeURIComponent(r[o]),e&&(r[o]=r[o].replace(/\//g,"%2F"));return r.join("/")},t.prototype.decodeSearch=function(t){return d(t)},t.prototype.decodeHash=function(t){return"#"===(t=decodeURIComponent(t))[0]?t.substring(1):t},t.prototype.normalize=function(t,e,r,o){if(1===arguments.length){var a=this.parse(t,o);if("string"==typeof a)return a;var n=a.protocol+"://"+a.hostname+(a.port?":"+a.port:"");return this.normalize(this.decodePath(a.pathname),this.decodeSearch(a.search),this.decodeHash(a.hash),n)}var i=this.encodePath(t),s=e&&this.encodeSearch(e)||"",h=r&&this.encodeHash(r)||"",c=(o||"")+i;return c.length&&"/"===c[0]||(c="/"+c),c+s+h},t.prototype.areEqual=function(t,e){return this.normalize(t)===this.normalize(e)},t.prototype.parse=function(t,e){try{var r=e?new URL(t,e):new URL(t);return{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:"/"===r.pathname.charAt(0)?r.pathname:"/"+r.pathname}}catch(r){throw new Error("Invalid URL ("+t+") with base ("+e+")")}},t}();function $(t){try{return decodeURIComponent(t)}catch(t){return}}function d(t){var e={};return(t||"").split("&").forEach((function(t){var r,o,a;t&&(o=t=t.replace(/\+/g,"%20"),-1!==(r=t.indexOf("="))&&(o=t.substring(0,r),a=t.substring(r+1)),void 0!==(o=$(o))&&(a=void 0===a||$(a),e.hasOwnProperty(o)?Array.isArray(e[o])?e[o].push(a):e[o]=[e[o],a]:e[o]=a))})),e}function f(t){return g(t,!0).replace(/%26/g,"&").replace(/%3D/gi,"=").replace(/%2B/gi,"+")}function g(t,e){return void 0===e&&(e=!1),encodeURIComponent(t).replace(/%40/g,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%3B/gi,";").replace(/%20/g,e?"%20":"+")} /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */var y=new o.InjectionToken("LOCATION_UPGRADE_CONFIGURATION"),v=new o.InjectionToken("APP_BASE_HREF_RESOLVED"),m=function(){function t(){}return t.config=function(e){return{ngModule:t,providers:[r.Location,{provide:c,useFactory:b,deps:[a.UpgradeModule,r.Location,r.PlatformLocation,u,r.LocationStrategy]},{provide:y,useValue:e||{}},{provide:u,useFactory:U,deps:[y]},{provide:v,useFactory:S,deps:[y,[new o.Inject(r.APP_BASE_HREF),new o.Optional]]},{provide:r.LocationStrategy,useFactory:w,deps:[r.PlatformLocation,v,y]}]}},t}();function S(t,e){return t&&null!=t.appBaseHref?t.appBaseHref:null!=e?e:""}function U(t){return new(t&&t.urlCodec||l)}function w(t,e,o){return void 0===o&&(o={}),o.useHash?new r.HashLocationStrategy(t,e):new r.PathLocationStrategy(t,e)}function b(t,e,r,o,a){return new p(t,e,r,o,a).$get()} /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */m.decorators=[{type:o.NgModule,args:[{imports:[r.CommonModule]}]}],t.$locationShim=c,t.$locationShimProvider=p,t.AngularJSUrlCodec=l,t.LOCATION_UPGRADE_CONFIGURATION=y,t.LocationUpgradeModule=m,t.UrlCodec=u,t.ɵangular_packages_common_upgrade_upgrade_a=S,t.ɵangular_packages_common_upgrade_upgrade_b=U,t.ɵangular_packages_common_upgrade_upgrade_c=w,t.ɵangular_packages_common_upgrade_upgrade_d=b,Object.defineProperty(t,"__esModule",{value:!0})}));