UNPKG

@pshurygin/ngx-quicklink

Version:
2 lines 5.79 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/router"),require("rxjs")):"function"==typeof define&&define.amd?define("@pshurygin/ngx-quicklink",["exports","@angular/core","@angular/router","rxjs"],t):t(((e=e||self).pshurygin=e.pshurygin||{},e.pshurygin["ngx-quicklink"]={}),e.ng.core,e.ng.router,e.rxjs)}(this,function(e,t,n,r){"use strict";function i(e,t,n,r){var i,o=arguments.length,u=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(u=(o<3?i(u):o>3?i(t,n,u):i(t,n))||u);return o>3&&u&&Object.defineProperty(t,n,u),u}function o(e,t){return function(n,r){t(n,r,e)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}var s=[],a=function(){function e(e){this.router=e,this.trees=s}return e.prototype.add=function(e){this.trees.push(e)},e.prototype.remove=function(e){this.trees.splice(this.trees.indexOf(e),1)},e.prototype.shouldPrefetch=function(e){var t=this.router.parseUrl(e);return this.trees.some(function(e,t){return function(e,t){return Object.keys(t).length<=Object.keys(e).length&&Object.keys(t).every(function(n){return t[n]===e[n]})}(t.queryParams,e.queryParams)&&function e(t,r,i){if(t.segments.length>i.length){var o=t.segments.slice(0,i.length);return!!l(o,i)&&!r.hasChildren()}if(t.segments.length===i.length){if(!l(t.segments,i))return!1;if(!r.hasChildren())return!0;for(var u in r.children){if(!t.children[u])break;if(e(t.children[u],r.children[u],r.children[u].segments))return!0}return!1}var o=i.slice(0,t.segments.length),s=i.slice(t.segments.length);return!!l(t.segments,o)&&(!!t.children[n.PRIMARY_OUTLET]&&e(t.children[n.PRIMARY_OUTLET],r,s))}(t.root,e.root,e.root.segments)}.bind(null,t))},e=i([t.Injectable(),u("design:paramtypes",[n.Router])],e)}();function l(e,t){return e.length===t.length&&e.every(function(e,n){return e.path===t[n].path||e.path.startsWith(":")||t[n].path.startsWith(":")})}var c="undefined"!=typeof window?window.requestIdleCallback||function(e){var t=Date.now();return setTimeout(function(){e({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-t))}})},1)}:function(){},f=function(){return"undefined"!=typeof window&&!!window.IntersectionObserver},d=new t.InjectionToken("LinkHandler"),h=function(){function e(e,t,n){var r=this;this.loader=e,this.queue=t,this.ngZone=n,this.elementLink=new Map,this.observer=f()?new IntersectionObserver(function(e){e.forEach(function(e){if(e.isIntersecting){var t=e.target,n=r.elementLink.get(t);if(!n||!n.urlTree)return;r.queue.add(n.urlTree),r.observer.unobserve(t),c(function(){r.loader.preload().subscribe(function(){}),r.queue.remove(n.urlTree)})}})}):null}return e.prototype.register=function(e){var t=this;this.elementLink.set(e.element,e),this.ngZone.runOutsideAngular(function(){t.observer.observe(e.element)})},e.prototype.unregister=function(e){this.elementLink.has(e.element)&&(this.observer.unobserve(e.element),this.elementLink.delete(e.element))},e.prototype.supported=function(){return f()},e=i([t.Injectable(),u("design:paramtypes",[n.RouterPreloader,a,t.NgZone])],e)}(),p=function(){function e(e,t){this.loader=e,this.queue=t}return e.prototype.register=function(e){var t=this;this.queue.add(e.urlTree),c(function(){return t.loader.preload().subscribe(function(){})})},e.prototype.unregister=function(e){},e.prototype.supported=function(){return!0},e=i([t.Injectable(),u("design:paramtypes",[n.RouterPreloader,a])],e)}(),g=function(){function e(e,t,n,r){this.linkHandlers=e,this.el=t,this.linkHandler=this.linkHandlers.filter(function(e){return e.supported()}).shift(),this.rl=n||r}return e.prototype.ngOnChanges=function(e){e.routerLink&&(this.linkHandler.unregister(this),this.linkHandler.register(this))},e.prototype.ngOnDestroy=function(){this.linkHandler.unregister(this)},Object.defineProperty(e.prototype,"element",{get:function(){return this.el.nativeElement},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"urlTree",{get:function(){return this.rl.urlTree},enumerable:!0,configurable:!0}),i([t.Input(),u("design:type",Object)],e.prototype,"routerLink",void 0),e=i([t.Directive({selector:"[routerLink]"}),o(0,t.Inject(d)),o(2,t.Optional()),o(3,t.Optional()),u("design:paramtypes",[Array,t.ElementRef,n.RouterLink,n.RouterLinkWithHref])],e)}(),y=function(){function e(e,t){this.queue=e,this.router=t,this.loading=new Set}return e.prototype.preload=function(e,t){if(this.loading.has(e))return r.EMPTY;var n="undefined"!=typeof window?navigator.connection:void 0;if(n&&((n.effectiveType||"").includes("2g")||n.saveData))return r.EMPTY;if(e.data&&!1===e.data.preload)return r.EMPTY;var i=m(this.router.config,e);return this.queue.shouldPrefetch(i)?(this.loading.add(e),t()):r.EMPTY},e=i([t.Injectable(),u("design:paramtypes",[a,n.Router])],e)}(),m=function(e,t){e=e.slice();for(var n=new Map,r=new Set,i=function(){var i=e.shift();if(r.add(i),i===t)return"break";var o=i.children||[],u=i._loadedConfig;u&&u.routes&&(o=o.concat(u.routes)),o.forEach(function(t){r.has(t)||(n.set(t,i),e.push(t))})};e.length;){if("break"===i())break}for(var o="",u=t;u;)o=v(u)?"/"+u.path+o:"/("+u.outlet+":"+u.path+o+")",u=n.get(u);return o};function v(e){return e.outlet===n.PRIMARY_OUTLET||!e.outlet}var b=function(){function e(){}return e=i([t.NgModule({declarations:[g],providers:[{provide:d,useClass:h,multi:!0},{provide:d,useClass:p,multi:!0},a,y],exports:[g]})],e)}();e.QuicklinkModule=b,e.QuicklinkStrategy=y,e.ɵa=d,e.ɵb=h,e.ɵc=p,e.ɵe=a,e.ɵɵLinkDirective=g,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=pshurygin-ngx-quicklink.umd.min.js.map