@absolutejs/absolute 0.18.0 → 0.18.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.
@@ -1,253 +0,0 @@
1
- /**
2
- * @license Angular v21.1.5
3
- * (c) 2010-2026 Google LLC. https://angular.dev/
4
- * License: MIT
5
- */
6
-
7
- import * as i0 from '@angular/core';
8
- import { inject, Injectable, InjectionToken, DOCUMENT, Optional, Inject, ɵɵinject as __inject } from '@angular/core';
9
- import { Subject } from 'rxjs';
10
- import { PlatformLocation } from './_platform_location-chunk.mjs';
11
- function joinWithSlash(start, end) {
12
- if (!start) return end;
13
- if (!end) return start;
14
- if (start.endsWith('/')) {
15
- return end.startsWith('/') ? start + end.slice(1) : start + end;
16
- }
17
- return end.startsWith('/') ? start + end : `${start}/${end}`;
18
- }
19
- function stripTrailingSlash(url) {
20
- const pathEndIdx = url.search(/#|\?|$/);
21
- return url[pathEndIdx - 1] === '/' ? url.slice(0, pathEndIdx - 1) + url.slice(pathEndIdx) : url;
22
- }
23
- function normalizeQueryParams(params) {
24
- return params && params[0] !== '?' ? `?${params}` : params;
25
- }
26
- class LocationStrategy {
27
- historyGo(relativePosition) {
28
- throw new Error(ngDevMode ? 'Not implemented' : '');
29
- }
30
- static ɵfac = function LocationStrategy_Factory(__ngFactoryType__) {
31
- return new (__ngFactoryType__ || LocationStrategy)();
32
- };
33
- static ɵprov = /* @__PURE__ */i0.ɵɵdefineInjectable({
34
- providedIn: 'root',
35
- token: LocationStrategy,
36
- factory: () => (() => inject(PathLocationStrategy))()
37
- });
38
- }
39
- (() => {
40
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LocationStrategy, [{
41
- args: [{
42
- providedIn: 'root',
43
- useFactory: () => inject(PathLocationStrategy)
44
- }],
45
- type: Injectable
46
- }], null, null);
47
- })();
48
- const APP_BASE_HREF = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'appBaseHref' : '');
49
- class PathLocationStrategy extends LocationStrategy {
50
- _platformLocation;
51
- _baseHref;
52
- _removeListenerFns = [];
53
- constructor(_platformLocation, href) {
54
- super();
55
- this._platformLocation = _platformLocation;
56
- this._baseHref = href ?? this._platformLocation.getBaseHrefFromDOM() ?? inject(DOCUMENT).location?.origin ?? '';
57
- }
58
- ngOnDestroy() {
59
- while (this._removeListenerFns.length) {
60
- this._removeListenerFns.pop()();
61
- }
62
- }
63
- onPopState(fn) {
64
- this._removeListenerFns.push(this._platformLocation.onPopState(fn), this._platformLocation.onHashChange(fn));
65
- }
66
- getBaseHref() {
67
- return this._baseHref;
68
- }
69
- prepareExternalUrl(internal) {
70
- return joinWithSlash(this._baseHref, internal);
71
- }
72
- path(includeHash = false) {
73
- const pathname = this._platformLocation.pathname + normalizeQueryParams(this._platformLocation.search);
74
- const {hash} = this._platformLocation;
75
- return hash && includeHash ? `${pathname}${hash}` : pathname;
76
- }
77
- pushState(state, title, url, queryParams) {
78
- const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
79
- this._platformLocation.pushState(state, title, externalUrl);
80
- }
81
- replaceState(state, title, url, queryParams) {
82
- const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
83
- this._platformLocation.replaceState(state, title, externalUrl);
84
- }
85
- forward() {
86
- this._platformLocation.forward();
87
- }
88
- back() {
89
- this._platformLocation.back();
90
- }
91
- getState() {
92
- return this._platformLocation.getState();
93
- }
94
- historyGo(relativePosition = 0) {
95
- this._platformLocation.historyGo?.(relativePosition);
96
- }
97
- static ɵfac = function PathLocationStrategy_Factory(__ngFactoryType__) {
98
- return new (__ngFactoryType__ || PathLocationStrategy)(i0.ɵɵinject(PlatformLocation), i0.ɵɵinject(APP_BASE_HREF, 8));
99
- };
100
- static ɵprov = /* @__PURE__ */i0.ɵɵdefineInjectable({
101
- factory: PathLocationStrategy.ɵfac,
102
- providedIn: 'root',
103
- token: PathLocationStrategy
104
- });
105
- }
106
- (() => {
107
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PathLocationStrategy, [{
108
- args: [{
109
- providedIn: 'root'
110
- }],
111
- type: Injectable
112
- }], () => [{
113
- type: PlatformLocation
114
- }, {
115
- decorators: [{
116
- type: Optional
117
- }, {
118
- args: [APP_BASE_HREF],
119
- type: Inject
120
- }],
121
- type: undefined
122
- }], null);
123
- })();
124
- class Location {
125
- _subject = new Subject();
126
- _basePath;
127
- _locationStrategy;
128
- _urlChangeListeners = [];
129
- _urlChangeSubscription = null;
130
- constructor(locationStrategy) {
131
- this._locationStrategy = locationStrategy;
132
- const baseHref = this._locationStrategy.getBaseHref();
133
- this._basePath = _stripOrigin(stripTrailingSlash(_stripIndexHtml(baseHref)));
134
- this._locationStrategy.onPopState(ev => {
135
- this._subject.next({
136
- 'pop': true,
137
- 'state': ev.state,
138
- 'type': ev.type,
139
- 'url': this.path(true)
140
- });
141
- });
142
- }
143
- ngOnDestroy() {
144
- this._urlChangeSubscription?.unsubscribe();
145
- this._urlChangeListeners = [];
146
- }
147
- path(includeHash = false) {
148
- return this.normalize(this._locationStrategy.path(includeHash));
149
- }
150
- getState() {
151
- return this._locationStrategy.getState();
152
- }
153
- isCurrentPathEqualTo(path, query = '') {
154
- return this.path() == this.normalize(path + normalizeQueryParams(query));
155
- }
156
- normalize(url) {
157
- return Location.stripTrailingSlash(_stripBasePath(this._basePath, _stripIndexHtml(url)));
158
- }
159
- prepareExternalUrl(url) {
160
- if (url && url[0] !== '/') {
161
- url = `/${ url}`;
162
- }
163
- return this._locationStrategy.prepareExternalUrl(url);
164
- }
165
- go(path, query = '', state = null) {
166
- this._locationStrategy.pushState(state, '', path, query);
167
- this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
168
- }
169
- replaceState(path, query = '', state = null) {
170
- this._locationStrategy.replaceState(state, '', path, query);
171
- this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
172
- }
173
- forward() {
174
- this._locationStrategy.forward();
175
- }
176
- back() {
177
- this._locationStrategy.back();
178
- }
179
- historyGo(relativePosition = 0) {
180
- this._locationStrategy.historyGo?.(relativePosition);
181
- }
182
- onUrlChange(fn) {
183
- this._urlChangeListeners.push(fn);
184
- this._urlChangeSubscription ??= this.subscribe(v => {
185
- this._notifyUrlChangeListeners(v.url, v.state);
186
- });
187
- return () => {
188
- const fnIndex = this._urlChangeListeners.indexOf(fn);
189
- this._urlChangeListeners.splice(fnIndex, 1);
190
- if (this._urlChangeListeners.length === 0) {
191
- this._urlChangeSubscription?.unsubscribe();
192
- this._urlChangeSubscription = null;
193
- }
194
- };
195
- }
196
- _notifyUrlChangeListeners(url = '', state) {
197
- this._urlChangeListeners.forEach(fn => fn(url, state));
198
- }
199
- subscribe(onNext, onThrow, onReturn) {
200
- return this._subject.subscribe({
201
- complete: onReturn ?? undefined,
202
- error: onThrow ?? undefined,
203
- next: onNext
204
- });
205
- }
206
- static normalizeQueryParams = normalizeQueryParams;
207
- static joinWithSlash = joinWithSlash;
208
- static stripTrailingSlash = stripTrailingSlash;
209
- static ɵfac = function Location_Factory(__ngFactoryType__) {
210
- return new (__ngFactoryType__ || Location)(i0.ɵɵinject(LocationStrategy));
211
- };
212
- static ɵprov = /* @__PURE__ */i0.ɵɵdefineInjectable({
213
- providedIn: 'root',
214
- token: Location,
215
- factory: () => createLocation()
216
- });
217
- }
218
- (() => {
219
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(Location, [{
220
- args: [{
221
- providedIn: 'root',
222
- useFactory: createLocation
223
- }],
224
- type: Injectable
225
- }], () => [{
226
- type: LocationStrategy
227
- }], null);
228
- })();
229
- function createLocation() {
230
- return new Location(__inject(LocationStrategy));
231
- }
232
- function _stripBasePath(basePath, url) {
233
- if (!basePath || !url.startsWith(basePath)) {
234
- return url;
235
- }
236
- const strippedUrl = url.substring(basePath.length);
237
- if (strippedUrl === '' || ['/', ';', '?', '#'].includes(strippedUrl[0])) {
238
- return strippedUrl;
239
- }
240
- return url;
241
- }
242
- function _stripIndexHtml(url) {
243
- return url.replace(/\/index.html$/, '');
244
- }
245
- function _stripOrigin(baseHref) {
246
- const isAbsoluteUrl = new RegExp('^(https?:)?//').test(baseHref);
247
- if (isAbsoluteUrl) {
248
- const [, pathname] = baseHref.split(/\/\/[^\/]+/);
249
- return pathname;
250
- }
251
- return baseHref;
252
- }
253
- export { APP_BASE_HREF, Location, LocationStrategy, PathLocationStrategy, joinWithSlash, normalizeQueryParams };