@yelon/util 16.2.5 → 16.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -21
- package/README.md +22 -22
- package/analysis/global-event.subject.d.ts +7 -7
- package/analysis/index.d.ts +1 -1
- package/array/array-type.service.d.ts +68 -68
- package/array/array.service.d.ts +78 -78
- package/array/index.d.ts +2 -2
- package/browser/cookie.service.d.ts +67 -67
- package/browser/copy.d.ts +6 -6
- package/browser/index.d.ts +5 -5
- package/browser/is-empty.d.ts +6 -6
- package/browser/scroll.service.d.ts +37 -37
- package/browser/style.d.ts +21 -21
- package/config/abc/cell.type.d.ts +118 -0
- package/config/abc/date-picker.type.d.ts +52 -52
- package/config/abc/error-collect.type.d.ts +10 -10
- package/config/abc/exception.type.d.ts +9 -9
- package/config/abc/image.type.d.ts +15 -15
- package/config/abc/index.d.ts +18 -17
- package/config/abc/loading.type.d.ts +31 -31
- package/config/abc/lodop.type.d.ts +33 -33
- package/config/abc/media.type.d.ts +11 -11
- package/config/abc/onboarding.type.d.ts +4 -4
- package/config/abc/page-header.type.d.ts +39 -39
- package/config/abc/pdf.type.d.ts +35 -35
- package/config/abc/qr.type.d.ts +25 -25
- package/config/abc/se.type.d.ts +32 -32
- package/config/abc/sg.type.d.ts +10 -10
- package/config/abc/st.type.d.ts +465 -465
- package/config/abc/sv.type.d.ts +14 -14
- package/config/abc/xlsx.type.d.ts +12 -12
- package/config/abc/zip.type.d.ts +10 -10
- package/config/acl/acl.type.d.ts +32 -32
- package/config/auth/auth.type.d.ts +55 -55
- package/config/bis/bis.type.d.ts +11 -11
- package/config/cache/cache.type.d.ts +40 -40
- package/config/chart/chart.type.d.ts +33 -33
- package/config/config.service.d.ts +13 -13
- package/config/config.types.d.ts +49 -48
- package/config/index.d.ts +14 -14
- package/config/mock/mock.type.d.ts +18 -18
- package/config/sf/sf.type.d.ts +133 -133
- package/config/socket/socket.type.d.ts +4 -4
- package/config/theme/http.type.d.ts +14 -14
- package/config/theme/i18n.type.d.ts +14 -14
- package/config/theme/index.d.ts +3 -3
- package/config/theme/responsive.type.d.ts +12 -12
- package/config/util/array.type.d.ts +22 -22
- package/config/util/currency.type.d.ts +39 -39
- package/date-time/index.d.ts +2 -2
- package/date-time/picker.d.ts +68 -68
- package/date-time/time.d.ts +31 -29
- package/decorator/convert.d.ts +24 -24
- package/decorator/index.d.ts +2 -2
- package/decorator/zone-outside.d.ts +35 -35
- package/esm2022/analysis/analysis.mjs +4 -4
- package/esm2022/analysis/global-event.subject.mjs +16 -16
- package/esm2022/analysis/index.mjs +1 -1
- package/esm2022/array/array-type.service.mjs +1 -1
- package/esm2022/array/array.mjs +4 -4
- package/esm2022/array/array.service.mjs +276 -276
- package/esm2022/array/index.mjs +2 -2
- package/esm2022/browser/browser.mjs +4 -4
- package/esm2022/browser/cookie.service.mjs +102 -102
- package/esm2022/browser/copy.mjs +27 -27
- package/esm2022/browser/index.mjs +5 -5
- package/esm2022/browser/is-empty.mjs +18 -18
- package/esm2022/browser/scroll.service.mjs +87 -87
- package/esm2022/browser/style.mjs +37 -37
- package/esm2022/config/abc/cell.type.mjs +2 -0
- package/esm2022/config/abc/date-picker.type.mjs +1 -1
- package/esm2022/config/abc/error-collect.type.mjs +1 -1
- package/esm2022/config/abc/exception.type.mjs +1 -1
- package/esm2022/config/abc/image.type.mjs +1 -1
- package/esm2022/config/abc/index.mjs +19 -18
- package/esm2022/config/abc/loading.type.mjs +1 -1
- package/esm2022/config/abc/lodop.type.mjs +1 -1
- package/esm2022/config/abc/media.type.mjs +1 -1
- package/esm2022/config/abc/onboarding.type.mjs +1 -1
- package/esm2022/config/abc/page-header.type.mjs +1 -1
- package/esm2022/config/abc/pdf.type.mjs +1 -1
- package/esm2022/config/abc/qr.type.mjs +1 -1
- package/esm2022/config/abc/se.type.mjs +1 -1
- package/esm2022/config/abc/sg.type.mjs +1 -1
- package/esm2022/config/abc/st.type.mjs +1 -1
- package/esm2022/config/abc/sv.type.mjs +2 -2
- package/esm2022/config/abc/xlsx.type.mjs +1 -1
- package/esm2022/config/abc/zip.type.mjs +1 -1
- package/esm2022/config/acl/acl.type.mjs +1 -1
- package/esm2022/config/auth/auth.type.mjs +1 -1
- package/esm2022/config/bis/bis.type.mjs +1 -1
- package/esm2022/config/cache/cache.type.mjs +1 -1
- package/esm2022/config/chart/chart.type.mjs +1 -1
- package/esm2022/config/config.mjs +4 -4
- package/esm2022/config/config.service.mjs +36 -36
- package/esm2022/config/config.types.mjs +9 -9
- package/esm2022/config/index.mjs +14 -14
- package/esm2022/config/mock/mock.type.mjs +1 -1
- package/esm2022/config/sf/sf.type.mjs +1 -1
- package/esm2022/config/socket/socket.type.mjs +1 -1
- package/esm2022/config/theme/http.type.mjs +1 -1
- package/esm2022/config/theme/i18n.type.mjs +1 -1
- package/esm2022/config/theme/index.mjs +3 -3
- package/esm2022/config/theme/responsive.type.mjs +1 -1
- package/esm2022/config/util/array.type.mjs +1 -1
- package/esm2022/config/util/currency.type.mjs +1 -1
- package/esm2022/date-time/date-time.mjs +4 -4
- package/esm2022/date-time/index.mjs +2 -2
- package/esm2022/date-time/picker.mjs +115 -115
- package/esm2022/date-time/time.mjs +96 -89
- package/esm2022/decorator/convert.mjs +57 -57
- package/esm2022/decorator/decorator.mjs +4 -4
- package/esm2022/decorator/index.mjs +2 -2
- package/esm2022/decorator/zone-outside.mjs +56 -56
- package/esm2022/form/form.mjs +4 -4
- package/esm2022/form/index.mjs +2 -2
- package/esm2022/form/match-control.mjs +29 -29
- package/esm2022/form/validators.mjs +80 -80
- package/esm2022/format/currency.service.mjs +237 -237
- package/esm2022/format/currency.types.mjs +8 -8
- package/esm2022/format/format.mjs +4 -4
- package/esm2022/format/index.mjs +4 -4
- package/esm2022/format/string.mjs +84 -84
- package/esm2022/format/validate.mjs +93 -93
- package/esm2022/index.mjs +14 -14
- package/esm2022/math/in-range.mjs +24 -24
- package/esm2022/math/index.mjs +2 -2
- package/esm2022/math/math.mjs +4 -4
- package/esm2022/math/round.mjs +52 -52
- package/esm2022/mcache/index.mjs +1 -1
- package/esm2022/mcache/localStorageUtils.mjs +58 -58
- package/esm2022/mcache/mcache.mjs +4 -4
- package/esm2022/mtypes/authority.type.mjs +1 -1
- package/esm2022/mtypes/header-menu.type.mjs +1 -1
- package/esm2022/mtypes/index.mjs +9 -9
- package/esm2022/mtypes/menu.type.mjs +1 -1
- package/esm2022/mtypes/mtypes.mjs +4 -4
- package/esm2022/mtypes/nav.types.mjs +6 -6
- package/esm2022/mtypes/page.mjs +41 -41
- package/esm2022/mtypes/project-info.types.mjs +1 -1
- package/esm2022/mtypes/response.mjs +1 -1
- package/esm2022/mtypes/role.type.mjs +1 -1
- package/esm2022/mtypes/user.types.mjs +1 -1
- package/esm2022/other/assert.mjs +66 -66
- package/esm2022/other/deep.mjs +77 -77
- package/esm2022/other/favicon.mjs +28 -28
- package/esm2022/other/index.mjs +7 -7
- package/esm2022/other/lazy.service.mjs +131 -131
- package/esm2022/other/logger.mjs +32 -32
- package/esm2022/other/other.mjs +4 -4
- package/esm2022/other/path-to-regexp.service.mjs +238 -238
- package/esm2022/other/resize.mjs +3 -3
- package/esm2022/pipes/currency/cny.pipe.mjs +22 -22
- package/esm2022/pipes/currency/index.mjs +4 -4
- package/esm2022/pipes/currency/mega.pipe.mjs +28 -28
- package/esm2022/pipes/currency/module.mjs +18 -18
- package/esm2022/pipes/currency/pipe-currency.mjs +4 -4
- package/esm2022/pipes/currency/price.pipe.mjs +26 -26
- package/esm2022/pipes/filter/filter.pipe.mjs +18 -18
- package/esm2022/pipes/filter/index.mjs +2 -2
- package/esm2022/pipes/filter/module.mjs +16 -16
- package/esm2022/pipes/filter/pipe-filter.mjs +4 -4
- package/esm2022/pipes/format/index.mjs +2 -2
- package/esm2022/pipes/format/mask.pipe.mjs +33 -33
- package/esm2022/pipes/format/module.mjs +16 -16
- package/esm2022/pipes/format/pipe-format.mjs +4 -4
- package/esm2022/pipes/index.mjs +3 -3
- package/esm2022/pipes/pipes.mjs +4 -4
- package/esm2022/token/index.mjs +2 -2
- package/esm2022/token/page-visibility.mjs +14 -14
- package/esm2022/token/token.mjs +4 -4
- package/esm2022/token/window.mjs +16 -16
- package/esm2022/yelon-util.mjs +4 -4
- package/fesm2022/analysis.mjs +24 -24
- package/fesm2022/array.mjs +284 -284
- package/fesm2022/browser.mjs +279 -279
- package/fesm2022/config.mjs +54 -54
- package/fesm2022/config.mjs.map +1 -1
- package/fesm2022/date-time.mjs +218 -211
- package/fesm2022/date-time.mjs.map +1 -1
- package/fesm2022/decorator.mjs +121 -121
- package/fesm2022/form.mjs +118 -118
- package/fesm2022/format.mjs +431 -431
- package/fesm2022/format.mjs.map +1 -1
- package/fesm2022/math.mjs +85 -85
- package/fesm2022/mcache.mjs +65 -65
- package/fesm2022/mtypes.mjs +55 -55
- package/fesm2022/other.mjs +586 -586
- package/fesm2022/pipe-currency.mjs +94 -94
- package/fesm2022/pipe-filter.mjs +40 -40
- package/fesm2022/pipe-format.mjs +55 -55
- package/fesm2022/pipes.mjs +8 -8
- package/fesm2022/token.mjs +37 -37
- package/fesm2022/yelon-util.mjs +19 -19
- package/form/index.d.ts +2 -2
- package/form/match-control.d.ts +15 -15
- package/form/validators.d.ts +62 -62
- package/format/currency.service.d.ts +37 -37
- package/format/currency.types.d.ts +82 -77
- package/format/index.d.ts +4 -4
- package/format/string.d.ts +44 -44
- package/format/validate.d.ts +72 -72
- package/index.d.ts +14 -14
- package/math/in-range.d.ts +14 -14
- package/math/index.d.ts +2 -2
- package/math/round.d.ts +33 -33
- package/mcache/index.d.ts +1 -1
- package/mcache/localStorageUtils.d.ts +18 -18
- package/mtypes/authority.type.d.ts +3 -3
- package/mtypes/header-menu.type.d.ts +12 -12
- package/mtypes/index.d.ts +9 -9
- package/mtypes/menu.type.d.ts +40 -40
- package/mtypes/nav.types.d.ts +27 -27
- package/mtypes/page.d.ts +46 -46
- package/mtypes/project-info.types.d.ts +21 -21
- package/mtypes/response.d.ts +7 -7
- package/mtypes/role.type.d.ts +10 -10
- package/mtypes/user.types.d.ts +22 -22
- package/other/assert.d.ts +36 -36
- package/other/deep.d.ts +35 -35
- package/other/favicon.d.ts +2 -2
- package/other/index.d.ts +7 -7
- package/other/lazy.service.d.ts +48 -48
- package/other/logger.d.ts +5 -5
- package/other/path-to-regexp.service.d.ts +26 -26
- package/other/resize.d.ts +1 -1
- package/package.json +141 -141
- package/pipes/currency/cny.pipe.d.ts +15 -15
- package/pipes/currency/index.d.ts +4 -4
- package/pipes/currency/mega.pipe.d.ts +16 -16
- package/pipes/currency/module.d.ts +9 -9
- package/pipes/currency/price.pipe.d.ts +19 -19
- package/pipes/filter/filter.pipe.d.ts +13 -13
- package/pipes/filter/index.d.ts +2 -2
- package/pipes/filter/module.d.ts +7 -7
- package/pipes/format/index.d.ts +2 -2
- package/pipes/format/mask.pipe.d.ts +27 -27
- package/pipes/format/module.d.ts +7 -7
- package/pipes/index.d.ts +3 -3
- package/token/index.d.ts +2 -2
- package/token/page-visibility.d.ts +8 -8
- package/token/window.d.ts +7 -7
package/fesm2022/other.mjs
CHANGED
@@ -1,586 +1,586 @@
|
|
1
|
-
import extend from 'extend';
|
2
|
-
import { DOCUMENT } from '@angular/common';
|
3
|
-
import * as i0 from '@angular/core';
|
4
|
-
import { Injectable, Inject } from '@angular/core';
|
5
|
-
import { BehaviorSubject, share, filter, isObservable } from 'rxjs';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Gets the value at `path` of `object`, like `_.get` in lodash.
|
9
|
-
*
|
10
|
-
* 类似 `_.get`,根据 `path` 获取安全值
|
11
|
-
*/
|
12
|
-
function deepGet(obj, path, defaultValue) {
|
13
|
-
if (!obj || path == null || path.length === 0)
|
14
|
-
return defaultValue;
|
15
|
-
if (!Array.isArray(path)) {
|
16
|
-
path = ~path.indexOf('.') ? path.split('.') : [path];
|
17
|
-
}
|
18
|
-
if (path.length === 1) {
|
19
|
-
const checkObj = obj[path[0]];
|
20
|
-
return typeof checkObj === 'undefined' ? defaultValue : checkObj;
|
21
|
-
}
|
22
|
-
const res = path.reduce((o, k) => (o || {})[k], obj);
|
23
|
-
return typeof res === 'undefined' ? defaultValue : res;
|
24
|
-
}
|
25
|
-
/**
|
26
|
-
* Base on [extend](https://github.com/justmoon/node-extend) deep copy.
|
27
|
-
*
|
28
|
-
* 基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝
|
29
|
-
*
|
30
|
-
* NOTE: Don't a lot of recursion, maybe performance issues
|
31
|
-
*/
|
32
|
-
function deepCopy(obj) {
|
33
|
-
const result = extend(true, {}, { _: obj });
|
34
|
-
return result._;
|
35
|
-
}
|
36
|
-
/**
|
37
|
-
* Deep merge object.
|
38
|
-
*
|
39
|
-
* 深度合并对象
|
40
|
-
*
|
41
|
-
* @param original 原始对象
|
42
|
-
* @param arrayProcessMethod 数组处理方式
|
43
|
-
* - `true` 表示替换新值,不管新值为哪种类型
|
44
|
-
* - `false` 表示会合并整个数组(将旧数据与新数据合并成新数组)
|
45
|
-
* @param objects 要合并的对象
|
46
|
-
*/
|
47
|
-
function deepMergeKey(original, arrayProcessMethod, ...objects) {
|
48
|
-
if (Array.isArray(original) || typeof original !== 'object')
|
49
|
-
return original;
|
50
|
-
const isObject = (v) => typeof v === 'object';
|
51
|
-
const merge = (target, obj) => {
|
52
|
-
Object.keys(obj)
|
53
|
-
.filter(key => key !== '__proto__' && Object.prototype.hasOwnProperty.call(obj, key))
|
54
|
-
.forEach(key => {
|
55
|
-
const fromValue = obj[key];
|
56
|
-
const toValue = target[key];
|
57
|
-
if (Array.isArray(toValue)) {
|
58
|
-
target[key] = arrayProcessMethod ? fromValue : [...toValue, ...fromValue];
|
59
|
-
}
|
60
|
-
else if (typeof fromValue === 'function') {
|
61
|
-
target[key] = fromValue;
|
62
|
-
}
|
63
|
-
else if (fromValue != null && isObject(fromValue) && toValue != null && isObject(toValue)) {
|
64
|
-
target[key] = merge(toValue, fromValue);
|
65
|
-
}
|
66
|
-
else {
|
67
|
-
target[key] = deepCopy(fromValue);
|
68
|
-
}
|
69
|
-
});
|
70
|
-
return target;
|
71
|
-
};
|
72
|
-
objects.filter(v => v != null && isObject(v)).forEach(v => merge(original, v));
|
73
|
-
return original;
|
74
|
-
}
|
75
|
-
/**
|
76
|
-
* Deep merge object.
|
77
|
-
*
|
78
|
-
* 深度合并对象
|
79
|
-
*/
|
80
|
-
function deepMerge(original, ...objects) {
|
81
|
-
return deepMergeKey(original, false, ...objects);
|
82
|
-
}
|
83
|
-
|
84
|
-
const record = {};
|
85
|
-
const PREFIX = '[@YELON]:';
|
86
|
-
function notRecorded(...args) {
|
87
|
-
const asRecord = args.reduce((acc, c) => acc + c.toString(), '');
|
88
|
-
if (record[asRecord]) {
|
89
|
-
return false;
|
90
|
-
}
|
91
|
-
else {
|
92
|
-
record[asRecord] = true;
|
93
|
-
return true;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
function consoleCommonBehavior(consoleFunc, ...args) {
|
97
|
-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && notRecorded(...args)) {
|
98
|
-
consoleFunc(...args);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
// Warning should only be printed in dev mode and only once.
|
102
|
-
const warn = (...args) => consoleCommonBehavior((...arg) => console.warn(PREFIX, ...arg), ...args);
|
103
|
-
const warnDeprecation = (...args) => {
|
104
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
105
|
-
return () => { };
|
106
|
-
}
|
107
|
-
const stack = new Error().stack;
|
108
|
-
return consoleCommonBehavior((...arg) => console.warn(PREFIX, 'deprecated:', ...arg, stack), ...args);
|
109
|
-
};
|
110
|
-
// Log should only be printed in dev mode.
|
111
|
-
const log = (...args) => {
|
112
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
113
|
-
console.log(PREFIX, ...args);
|
114
|
-
}
|
115
|
-
};
|
116
|
-
|
117
|
-
/**
|
118
|
-
* `LazyService` delay loading JS or CSS files.
|
119
|
-
*
|
120
|
-
* 延迟加载资源(js 或 css)服务
|
121
|
-
*/
|
122
|
-
class LazyService {
|
123
|
-
constructor(doc) {
|
124
|
-
this.doc = doc;
|
125
|
-
this.list = {};
|
126
|
-
this.cached = {};
|
127
|
-
this._notify = new BehaviorSubject([]);
|
128
|
-
}
|
129
|
-
get change() {
|
130
|
-
return this._notify.asObservable().pipe(share(), filter(ls => ls.length !== 0));
|
131
|
-
}
|
132
|
-
clear() {
|
133
|
-
this.list = {};
|
134
|
-
this.cached = {};
|
135
|
-
}
|
136
|
-
attachAttributes(el, attributes) {
|
137
|
-
if (attributes == null)
|
138
|
-
return;
|
139
|
-
Object.entries(attributes).forEach(([key, value]) => {
|
140
|
-
el.setAttribute(key, value);
|
141
|
-
});
|
142
|
-
}
|
143
|
-
/**
|
144
|
-
* Load script or style files
|
145
|
-
*/
|
146
|
-
load(paths) {
|
147
|
-
if (!Array.isArray(paths)) {
|
148
|
-
paths = [paths];
|
149
|
-
}
|
150
|
-
const promises = [];
|
151
|
-
paths
|
152
|
-
.map(v => (typeof v !== 'object' ? { path: v } : v))
|
153
|
-
.forEach(item => {
|
154
|
-
if (item.path.endsWith('.js')) {
|
155
|
-
promises.push(this.loadScript(item.path, item.options));
|
156
|
-
}
|
157
|
-
else {
|
158
|
-
promises.push(this.loadStyle(item.path, item.options));
|
159
|
-
}
|
160
|
-
});
|
161
|
-
return Promise.all(promises).then(res => {
|
162
|
-
this._notify.next(res);
|
163
|
-
return Promise.resolve(res);
|
164
|
-
});
|
165
|
-
}
|
166
|
-
loadScript(path, innerContent, attributes) {
|
167
|
-
const options = typeof innerContent === 'object'
|
168
|
-
? innerContent
|
169
|
-
: {
|
170
|
-
innerContent,
|
171
|
-
attributes
|
172
|
-
};
|
173
|
-
return new Promise(resolve => {
|
174
|
-
if (this.list[path] === true) {
|
175
|
-
resolve({ ...this.cached[path], status: 'loading' });
|
176
|
-
return;
|
177
|
-
}
|
178
|
-
this.list[path] = true;
|
179
|
-
const onSuccess = (item) => {
|
180
|
-
this.cached[path] = item;
|
181
|
-
resolve(item);
|
182
|
-
this._notify.next([item]);
|
183
|
-
};
|
184
|
-
const node = this.doc.createElement('script');
|
185
|
-
node.type = 'text/javascript';
|
186
|
-
node.src = path;
|
187
|
-
this.attachAttributes(node, options.attributes);
|
188
|
-
if (options.innerContent) {
|
189
|
-
node.innerHTML = options.innerContent;
|
190
|
-
}
|
191
|
-
node.onload = () => onSuccess({
|
192
|
-
path,
|
193
|
-
status: 'ok'
|
194
|
-
});
|
195
|
-
node.onerror = error => onSuccess({
|
196
|
-
path,
|
197
|
-
status: 'error',
|
198
|
-
error
|
199
|
-
});
|
200
|
-
this.doc.getElementsByTagName('head')[0].appendChild(node);
|
201
|
-
});
|
202
|
-
}
|
203
|
-
loadStyle(path, rel, innerContent, attributes) {
|
204
|
-
const options = typeof rel === 'object'
|
205
|
-
? rel
|
206
|
-
: {
|
207
|
-
rel,
|
208
|
-
innerContent,
|
209
|
-
attributes
|
210
|
-
};
|
211
|
-
return new Promise(resolve => {
|
212
|
-
if (this.list[path] === true) {
|
213
|
-
resolve(this.cached[path]);
|
214
|
-
return;
|
215
|
-
}
|
216
|
-
this.list[path] = true;
|
217
|
-
const node = this.doc.createElement('link');
|
218
|
-
node.rel = options.rel ?? 'stylesheet';
|
219
|
-
node.type = 'text/css';
|
220
|
-
node.href = path;
|
221
|
-
this.attachAttributes(node, options.attributes);
|
222
|
-
if (options.innerContent) {
|
223
|
-
node.innerHTML = options.innerContent;
|
224
|
-
}
|
225
|
-
this.doc.getElementsByTagName('head')[0].appendChild(node);
|
226
|
-
const item = {
|
227
|
-
path,
|
228
|
-
status: 'ok'
|
229
|
-
};
|
230
|
-
this.cached[path] = item;
|
231
|
-
resolve(item);
|
232
|
-
});
|
233
|
-
}
|
234
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.
|
235
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.
|
236
|
-
}
|
237
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.
|
238
|
-
type: Injectable,
|
239
|
-
args: [{ providedIn: 'root' }]
|
240
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
241
|
-
type: Inject,
|
242
|
-
args: [DOCUMENT]
|
243
|
-
}] }]; } });
|
244
|
-
|
245
|
-
function throwError(msg, actual, expected, comparison) {
|
246
|
-
if (ngDevMode) {
|
247
|
-
throw new Error(`ASSERTION ERROR: ${msg}${comparison == null ? '' : ` [Expected=> ${expected} ${comparison} ${actual} <=Actual]`}`);
|
248
|
-
}
|
249
|
-
}
|
250
|
-
/**
|
251
|
-
* Assert whether the expression and throw an error into console in dev mode
|
252
|
-
*
|
253
|
-
* 断言表达式是否符合预期,并在开发模式下会在控制台抛出一个错误
|
254
|
-
*/
|
255
|
-
function assert(expression, msg) {
|
256
|
-
if (!expression) {
|
257
|
-
throwError(msg);
|
258
|
-
}
|
259
|
-
}
|
260
|
-
/**
|
261
|
-
* Assert whether empty (`null` or `undefined`)
|
262
|
-
*
|
263
|
-
* 断言是否空值(`null` 或 `undefined`)
|
264
|
-
*/
|
265
|
-
function assertEmpty(actual, msg) {
|
266
|
-
if (actual == null) {
|
267
|
-
throwError(msg, typeof actual, 'NULL', '==');
|
268
|
-
}
|
269
|
-
}
|
270
|
-
/**
|
271
|
-
* Assert whether `number` type
|
272
|
-
*
|
273
|
-
* 断言是否 `number` 类型
|
274
|
-
*/
|
275
|
-
function assertNumber(actual, msg) {
|
276
|
-
if (!(typeof actual === 'number')) {
|
277
|
-
throwError(msg, typeof actual, 'number', '===');
|
278
|
-
}
|
279
|
-
}
|
280
|
-
/**
|
281
|
-
* Assert whether `string` type
|
282
|
-
*
|
283
|
-
* 断言是否 `string` 类型
|
284
|
-
*/
|
285
|
-
function assertString(actual, msg) {
|
286
|
-
if (!(typeof actual === 'string')) {
|
287
|
-
throwError(msg, actual === null ? 'null' : typeof actual, 'string', '===');
|
288
|
-
}
|
289
|
-
}
|
290
|
-
/**
|
291
|
-
* Assert whether `array` type
|
292
|
-
*
|
293
|
-
* 断言是否 `array` 类型
|
294
|
-
*/
|
295
|
-
function assertArray(actual, msg) {
|
296
|
-
if (!Array.isArray(actual)) {
|
297
|
-
throwError(msg, actual === null ? 'null' : typeof actual, 'array', '===');
|
298
|
-
}
|
299
|
-
}
|
300
|
-
/**
|
301
|
-
* Assert whether `Observable` type
|
302
|
-
*
|
303
|
-
* 断言是否 `Observable` 类型
|
304
|
-
*/
|
305
|
-
function assertObservable(obj, msg) {
|
306
|
-
if (!isObservable(obj)) {
|
307
|
-
throwError(msg, obj === null ? 'null' : typeof obj, 'Observable', '===');
|
308
|
-
}
|
309
|
-
}
|
310
|
-
|
311
|
-
const resizeWindow = () => {
|
312
|
-
window.dispatchEvent(new Event('resize'));
|
313
|
-
};
|
314
|
-
|
315
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
316
|
-
class PathToRegexpService {
|
317
|
-
constructor() {
|
318
|
-
this.DEFAULT_DELIMITER = '/';
|
319
|
-
this.PATH_REGEXP = new RegExp(['(\\\\.)', '(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'].join('|'), 'g');
|
320
|
-
}
|
321
|
-
parse(str, options) {
|
322
|
-
const tokens = [];
|
323
|
-
let key = 0;
|
324
|
-
let index = 0;
|
325
|
-
let path = '';
|
326
|
-
const defaultDelimiter = (options && options.delimiter) || this.DEFAULT_DELIMITER;
|
327
|
-
const whitelist = (options && options.whitelist) || undefined;
|
328
|
-
let pathEscaped = false;
|
329
|
-
let res;
|
330
|
-
while ((res = this.PATH_REGEXP.exec(str)) !== null) {
|
331
|
-
const m = res[0];
|
332
|
-
const escaped = res[1];
|
333
|
-
const offset = res.index;
|
334
|
-
path += str.slice(index, offset);
|
335
|
-
index = offset + m.length;
|
336
|
-
// Ignore already escaped sequences.
|
337
|
-
if (escaped) {
|
338
|
-
path += escaped[1];
|
339
|
-
pathEscaped = true;
|
340
|
-
continue;
|
341
|
-
}
|
342
|
-
let prev = '';
|
343
|
-
const name = res[2];
|
344
|
-
const capture = res[3];
|
345
|
-
const group = res[4];
|
346
|
-
const modifier = res[5];
|
347
|
-
if (!pathEscaped && path.length) {
|
348
|
-
const k = path.length - 1;
|
349
|
-
const c = path[k];
|
350
|
-
const matches = whitelist ? whitelist.indexOf(c) > -1 : true;
|
351
|
-
if (matches) {
|
352
|
-
prev = c;
|
353
|
-
path = path.slice(0, k);
|
354
|
-
}
|
355
|
-
}
|
356
|
-
// Push the current path onto the tokens.
|
357
|
-
if (path) {
|
358
|
-
tokens.push(path);
|
359
|
-
path = '';
|
360
|
-
pathEscaped = false;
|
361
|
-
}
|
362
|
-
const repeat = modifier === '+' || modifier === '*';
|
363
|
-
const optional = modifier === '?' || modifier === '*';
|
364
|
-
const pattern = capture || group;
|
365
|
-
const delimiter = prev || defaultDelimiter;
|
366
|
-
tokens.push({
|
367
|
-
name: name || key++,
|
368
|
-
prefix: prev,
|
369
|
-
delimiter: delimiter,
|
370
|
-
optional: optional,
|
371
|
-
repeat: repeat,
|
372
|
-
pattern: pattern
|
373
|
-
? this.escapeGroup(pattern)
|
374
|
-
: `[^${this.escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter)}]+?`
|
375
|
-
});
|
376
|
-
}
|
377
|
-
// Push any remaining characters.
|
378
|
-
if (path || index < str.length) {
|
379
|
-
tokens.push(path + str.substr(index));
|
380
|
-
}
|
381
|
-
return tokens;
|
382
|
-
}
|
383
|
-
compile(str, options) {
|
384
|
-
return this.tokensToFunction(this.parse(str, options), options);
|
385
|
-
}
|
386
|
-
tokensToFunction(tokens, options) {
|
387
|
-
const matches = new Array(tokens.length);
|
388
|
-
for (let i = 0; i < tokens.length; i++) {
|
389
|
-
if (typeof tokens[i] === 'object') {
|
390
|
-
matches[i] = new RegExp(`^(?:${tokens[i].pattern})$`, this.flags(options));
|
391
|
-
}
|
392
|
-
}
|
393
|
-
return function (data, options) {
|
394
|
-
let path = '';
|
395
|
-
const encode = (options && options.encode) || encodeURIComponent;
|
396
|
-
const validate = options ? options.validate !== false : true;
|
397
|
-
for (let i = 0; i < tokens.length; i++) {
|
398
|
-
const token = tokens[i];
|
399
|
-
if (typeof token === 'string') {
|
400
|
-
path += token;
|
401
|
-
continue;
|
402
|
-
}
|
403
|
-
const value = data ? data[token.name] : undefined;
|
404
|
-
let segment;
|
405
|
-
if (Array.isArray(value)) {
|
406
|
-
if (!token.repeat) {
|
407
|
-
throw new TypeError(`Expected "${token.name}" to not repeat, but got array`);
|
408
|
-
}
|
409
|
-
if (value.length === 0) {
|
410
|
-
if (token.optional) {
|
411
|
-
continue;
|
412
|
-
}
|
413
|
-
throw new TypeError(`Expected "${token.name}" to not be empty`);
|
414
|
-
}
|
415
|
-
for (let j = 0; j < value.length; j++) {
|
416
|
-
segment = encode(value[j], token);
|
417
|
-
if (validate && !matches[i].test(segment)) {
|
418
|
-
throw new TypeError(`Expected all "${token.name}" to match "${token.pattern}"`);
|
419
|
-
}
|
420
|
-
path += (j === 0 ? token.prefix : token.delimiter) + segment;
|
421
|
-
}
|
422
|
-
continue;
|
423
|
-
}
|
424
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
425
|
-
segment = encode(String(value), token);
|
426
|
-
if (validate && !matches[i].test(segment)) {
|
427
|
-
throw new TypeError(`Expected "${token.name}" to match "${token.pattern}", but got "${segment}"`);
|
428
|
-
}
|
429
|
-
path += token.prefix + segment;
|
430
|
-
continue;
|
431
|
-
}
|
432
|
-
if (token.optional) {
|
433
|
-
continue;
|
434
|
-
}
|
435
|
-
throw new TypeError(`Expected "${token.name}" to be ${token.repeat ? 'an array' : 'a string'}`);
|
436
|
-
}
|
437
|
-
return path;
|
438
|
-
};
|
439
|
-
}
|
440
|
-
escapeString(str) {
|
441
|
-
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
|
442
|
-
}
|
443
|
-
escapeGroup(group) {
|
444
|
-
return group.replace(/([=!:$/()])/g, '\\$1');
|
445
|
-
}
|
446
|
-
flags(options) {
|
447
|
-
return options && options.sensitive ? '' : 'i';
|
448
|
-
}
|
449
|
-
regexpToRegexp(path, keys) {
|
450
|
-
if (!keys) {
|
451
|
-
return path;
|
452
|
-
}
|
453
|
-
const groups = path.source.match(/\((?!\?)/g);
|
454
|
-
if (groups) {
|
455
|
-
for (let i = 0; i < groups.length; i++) {
|
456
|
-
keys.push({
|
457
|
-
name: i,
|
458
|
-
prefix: null,
|
459
|
-
delimiter: null,
|
460
|
-
optional: false,
|
461
|
-
repeat: false,
|
462
|
-
pattern: null
|
463
|
-
});
|
464
|
-
}
|
465
|
-
}
|
466
|
-
return path;
|
467
|
-
}
|
468
|
-
arrayToRegexp(path, keys, options) {
|
469
|
-
const parts = [];
|
470
|
-
for (let i = 0; i < path.length; i++) {
|
471
|
-
parts.push(this.pathToRegexp(path[i], keys, options).source);
|
472
|
-
}
|
473
|
-
return new RegExp(`(?:${parts.join('|')})`, this.flags(options));
|
474
|
-
}
|
475
|
-
stringToRegexp(path, keys, options) {
|
476
|
-
return this.tokensToRegExp(this.parse(path, options), keys, options);
|
477
|
-
}
|
478
|
-
tokensToRegExp(tokens, keys, options) {
|
479
|
-
options = options || {};
|
480
|
-
const strict = options.strict;
|
481
|
-
const start = options.start !== false;
|
482
|
-
const end = options.end !== false;
|
483
|
-
const delimiter = options.delimiter || this.DEFAULT_DELIMITER;
|
484
|
-
const endsWith = []
|
485
|
-
.concat(options.endsWith || [])
|
486
|
-
.map(this.escapeString)
|
487
|
-
.concat('$')
|
488
|
-
.join('|');
|
489
|
-
let route = start ? '^' : '';
|
490
|
-
for (let i = 0; i < tokens.length; i++) {
|
491
|
-
const token = tokens[i];
|
492
|
-
if (typeof token === 'string') {
|
493
|
-
route += this.escapeString(token);
|
494
|
-
}
|
495
|
-
else {
|
496
|
-
const capture = token.repeat
|
497
|
-
? `(?:${token.pattern})(?:${this.escapeString(token.delimiter)}(?:${token.pattern}))*`
|
498
|
-
: token.pattern;
|
499
|
-
if (keys) {
|
500
|
-
keys.push(token);
|
501
|
-
}
|
502
|
-
if (token.optional) {
|
503
|
-
if (!token.prefix) {
|
504
|
-
route += `(${capture})?`;
|
505
|
-
}
|
506
|
-
else {
|
507
|
-
route += `(?:${this.escapeString(token.prefix)}(${capture}))?`;
|
508
|
-
}
|
509
|
-
}
|
510
|
-
else {
|
511
|
-
route += `${this.escapeString(token.prefix)}(${capture})`;
|
512
|
-
}
|
513
|
-
}
|
514
|
-
}
|
515
|
-
if (end) {
|
516
|
-
if (!strict) {
|
517
|
-
route += `(?:${this.escapeString(delimiter)})?`;
|
518
|
-
}
|
519
|
-
route += endsWith === '$' ? '$' : `(?=${endsWith})`;
|
520
|
-
}
|
521
|
-
else {
|
522
|
-
const endToken = tokens[tokens.length - 1];
|
523
|
-
const isEndDelimited = typeof endToken === 'string' ? endToken[endToken.length - 1] === delimiter : endToken === undefined;
|
524
|
-
if (!strict) {
|
525
|
-
route += `(?:${this.escapeString(delimiter)}(?=${endsWith}))?`;
|
526
|
-
}
|
527
|
-
if (!isEndDelimited) {
|
528
|
-
route += `(?=${this.escapeString(delimiter)}|${endsWith})`;
|
529
|
-
}
|
530
|
-
}
|
531
|
-
return new RegExp(route, this.flags(options));
|
532
|
-
}
|
533
|
-
pathToRegexp(path, keys, options) {
|
534
|
-
if (path instanceof RegExp) {
|
535
|
-
return this.regexpToRegexp(path, keys);
|
536
|
-
}
|
537
|
-
if (Array.isArray(path)) {
|
538
|
-
return this.arrayToRegexp(/** @type {!Array} */ path, keys, options);
|
539
|
-
}
|
540
|
-
return this.stringToRegexp(/** @type {string} */ path, keys, options);
|
541
|
-
}
|
542
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.
|
543
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.
|
544
|
-
}
|
545
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.
|
546
|
-
type: Injectable,
|
547
|
-
args: [{
|
548
|
-
providedIn: 'root'
|
549
|
-
}]
|
550
|
-
}], ctorParameters: function () { return []; } });
|
551
|
-
|
552
|
-
function setFavicon(path) {
|
553
|
-
const link = document.querySelector("link[rel*='icon']") || document.createElement('link');
|
554
|
-
link.type = 'image/x-icon';
|
555
|
-
link.rel = 'shortcut icon';
|
556
|
-
link.href = path;
|
557
|
-
document.getElementsByTagName('head')[0].appendChild(link);
|
558
|
-
}
|
559
|
-
function hasFavicon(url) {
|
560
|
-
return new Promise(resolve => {
|
561
|
-
let xmlHttp;
|
562
|
-
if (window['XMLHttpRequest']) {
|
563
|
-
xmlHttp = new XMLHttpRequest();
|
564
|
-
}
|
565
|
-
if (xmlHttp) {
|
566
|
-
xmlHttp.open('Get', url, false);
|
567
|
-
xmlHttp.send();
|
568
|
-
if (xmlHttp.status == 404) {
|
569
|
-
resolve(false);
|
570
|
-
}
|
571
|
-
else {
|
572
|
-
resolve(true);
|
573
|
-
}
|
574
|
-
}
|
575
|
-
else {
|
576
|
-
resolve(false);
|
577
|
-
}
|
578
|
-
});
|
579
|
-
}
|
580
|
-
|
581
|
-
/**
|
582
|
-
* Generated bundle index. Do not edit.
|
583
|
-
*/
|
584
|
-
|
585
|
-
export { LazyService, PREFIX, PathToRegexpService, assert, assertArray, assertEmpty, assertNumber, assertObservable, assertString, deepCopy, deepGet, deepMerge, deepMergeKey, hasFavicon, log, resizeWindow, setFavicon, warn, warnDeprecation };
|
586
|
-
//# sourceMappingURL=other.mjs.map
|
1
|
+
import extend from 'extend';
|
2
|
+
import { DOCUMENT } from '@angular/common';
|
3
|
+
import * as i0 from '@angular/core';
|
4
|
+
import { Injectable, Inject } from '@angular/core';
|
5
|
+
import { BehaviorSubject, share, filter, isObservable } from 'rxjs';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Gets the value at `path` of `object`, like `_.get` in lodash.
|
9
|
+
*
|
10
|
+
* 类似 `_.get`,根据 `path` 获取安全值
|
11
|
+
*/
|
12
|
+
function deepGet(obj, path, defaultValue) {
|
13
|
+
if (!obj || path == null || path.length === 0)
|
14
|
+
return defaultValue;
|
15
|
+
if (!Array.isArray(path)) {
|
16
|
+
path = ~path.indexOf('.') ? path.split('.') : [path];
|
17
|
+
}
|
18
|
+
if (path.length === 1) {
|
19
|
+
const checkObj = obj[path[0]];
|
20
|
+
return typeof checkObj === 'undefined' ? defaultValue : checkObj;
|
21
|
+
}
|
22
|
+
const res = path.reduce((o, k) => (o || {})[k], obj);
|
23
|
+
return typeof res === 'undefined' ? defaultValue : res;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Base on [extend](https://github.com/justmoon/node-extend) deep copy.
|
27
|
+
*
|
28
|
+
* 基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝
|
29
|
+
*
|
30
|
+
* NOTE: Don't a lot of recursion, maybe performance issues
|
31
|
+
*/
|
32
|
+
function deepCopy(obj) {
|
33
|
+
const result = extend(true, {}, { _: obj });
|
34
|
+
return result._;
|
35
|
+
}
|
36
|
+
/**
|
37
|
+
* Deep merge object.
|
38
|
+
*
|
39
|
+
* 深度合并对象
|
40
|
+
*
|
41
|
+
* @param original 原始对象
|
42
|
+
* @param arrayProcessMethod 数组处理方式
|
43
|
+
* - `true` 表示替换新值,不管新值为哪种类型
|
44
|
+
* - `false` 表示会合并整个数组(将旧数据与新数据合并成新数组)
|
45
|
+
* @param objects 要合并的对象
|
46
|
+
*/
|
47
|
+
function deepMergeKey(original, arrayProcessMethod, ...objects) {
|
48
|
+
if (Array.isArray(original) || typeof original !== 'object')
|
49
|
+
return original;
|
50
|
+
const isObject = (v) => typeof v === 'object';
|
51
|
+
const merge = (target, obj) => {
|
52
|
+
Object.keys(obj)
|
53
|
+
.filter(key => key !== '__proto__' && Object.prototype.hasOwnProperty.call(obj, key))
|
54
|
+
.forEach(key => {
|
55
|
+
const fromValue = obj[key];
|
56
|
+
const toValue = target[key];
|
57
|
+
if (Array.isArray(toValue)) {
|
58
|
+
target[key] = arrayProcessMethod ? fromValue : [...toValue, ...fromValue];
|
59
|
+
}
|
60
|
+
else if (typeof fromValue === 'function') {
|
61
|
+
target[key] = fromValue;
|
62
|
+
}
|
63
|
+
else if (fromValue != null && isObject(fromValue) && toValue != null && isObject(toValue)) {
|
64
|
+
target[key] = merge(toValue, fromValue);
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
target[key] = deepCopy(fromValue);
|
68
|
+
}
|
69
|
+
});
|
70
|
+
return target;
|
71
|
+
};
|
72
|
+
objects.filter(v => v != null && isObject(v)).forEach(v => merge(original, v));
|
73
|
+
return original;
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* Deep merge object.
|
77
|
+
*
|
78
|
+
* 深度合并对象
|
79
|
+
*/
|
80
|
+
function deepMerge(original, ...objects) {
|
81
|
+
return deepMergeKey(original, false, ...objects);
|
82
|
+
}
|
83
|
+
|
84
|
+
const record = {};
|
85
|
+
const PREFIX = '[@YELON]:';
|
86
|
+
function notRecorded(...args) {
|
87
|
+
const asRecord = args.reduce((acc, c) => acc + c.toString(), '');
|
88
|
+
if (record[asRecord]) {
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
record[asRecord] = true;
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
function consoleCommonBehavior(consoleFunc, ...args) {
|
97
|
+
if ((typeof ngDevMode === 'undefined' || ngDevMode) && notRecorded(...args)) {
|
98
|
+
consoleFunc(...args);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
// Warning should only be printed in dev mode and only once.
|
102
|
+
const warn = (...args) => consoleCommonBehavior((...arg) => console.warn(PREFIX, ...arg), ...args);
|
103
|
+
const warnDeprecation = (...args) => {
|
104
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
105
|
+
return () => { };
|
106
|
+
}
|
107
|
+
const stack = new Error().stack;
|
108
|
+
return consoleCommonBehavior((...arg) => console.warn(PREFIX, 'deprecated:', ...arg, stack), ...args);
|
109
|
+
};
|
110
|
+
// Log should only be printed in dev mode.
|
111
|
+
const log = (...args) => {
|
112
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
113
|
+
console.log(PREFIX, ...args);
|
114
|
+
}
|
115
|
+
};
|
116
|
+
|
117
|
+
/**
|
118
|
+
* `LazyService` delay loading JS or CSS files.
|
119
|
+
*
|
120
|
+
* 延迟加载资源(js 或 css)服务
|
121
|
+
*/
|
122
|
+
class LazyService {
|
123
|
+
constructor(doc) {
|
124
|
+
this.doc = doc;
|
125
|
+
this.list = {};
|
126
|
+
this.cached = {};
|
127
|
+
this._notify = new BehaviorSubject([]);
|
128
|
+
}
|
129
|
+
get change() {
|
130
|
+
return this._notify.asObservable().pipe(share(), filter(ls => ls.length !== 0));
|
131
|
+
}
|
132
|
+
clear() {
|
133
|
+
this.list = {};
|
134
|
+
this.cached = {};
|
135
|
+
}
|
136
|
+
attachAttributes(el, attributes) {
|
137
|
+
if (attributes == null)
|
138
|
+
return;
|
139
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
140
|
+
el.setAttribute(key, value);
|
141
|
+
});
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* Load script or style files
|
145
|
+
*/
|
146
|
+
load(paths) {
|
147
|
+
if (!Array.isArray(paths)) {
|
148
|
+
paths = [paths];
|
149
|
+
}
|
150
|
+
const promises = [];
|
151
|
+
paths
|
152
|
+
.map(v => (typeof v !== 'object' ? { path: v } : v))
|
153
|
+
.forEach(item => {
|
154
|
+
if (item.path.endsWith('.js')) {
|
155
|
+
promises.push(this.loadScript(item.path, item.options));
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
promises.push(this.loadStyle(item.path, item.options));
|
159
|
+
}
|
160
|
+
});
|
161
|
+
return Promise.all(promises).then(res => {
|
162
|
+
this._notify.next(res);
|
163
|
+
return Promise.resolve(res);
|
164
|
+
});
|
165
|
+
}
|
166
|
+
loadScript(path, innerContent, attributes) {
|
167
|
+
const options = typeof innerContent === 'object'
|
168
|
+
? innerContent
|
169
|
+
: {
|
170
|
+
innerContent,
|
171
|
+
attributes
|
172
|
+
};
|
173
|
+
return new Promise(resolve => {
|
174
|
+
if (this.list[path] === true) {
|
175
|
+
resolve({ ...this.cached[path], status: 'loading' });
|
176
|
+
return;
|
177
|
+
}
|
178
|
+
this.list[path] = true;
|
179
|
+
const onSuccess = (item) => {
|
180
|
+
this.cached[path] = item;
|
181
|
+
resolve(item);
|
182
|
+
this._notify.next([item]);
|
183
|
+
};
|
184
|
+
const node = this.doc.createElement('script');
|
185
|
+
node.type = 'text/javascript';
|
186
|
+
node.src = path;
|
187
|
+
this.attachAttributes(node, options.attributes);
|
188
|
+
if (options.innerContent) {
|
189
|
+
node.innerHTML = options.innerContent;
|
190
|
+
}
|
191
|
+
node.onload = () => onSuccess({
|
192
|
+
path,
|
193
|
+
status: 'ok'
|
194
|
+
});
|
195
|
+
node.onerror = error => onSuccess({
|
196
|
+
path,
|
197
|
+
status: 'error',
|
198
|
+
error
|
199
|
+
});
|
200
|
+
this.doc.getElementsByTagName('head')[0].appendChild(node);
|
201
|
+
});
|
202
|
+
}
|
203
|
+
loadStyle(path, rel, innerContent, attributes) {
|
204
|
+
const options = typeof rel === 'object'
|
205
|
+
? rel
|
206
|
+
: {
|
207
|
+
rel,
|
208
|
+
innerContent,
|
209
|
+
attributes
|
210
|
+
};
|
211
|
+
return new Promise(resolve => {
|
212
|
+
if (this.list[path] === true) {
|
213
|
+
resolve(this.cached[path]);
|
214
|
+
return;
|
215
|
+
}
|
216
|
+
this.list[path] = true;
|
217
|
+
const node = this.doc.createElement('link');
|
218
|
+
node.rel = options.rel ?? 'stylesheet';
|
219
|
+
node.type = 'text/css';
|
220
|
+
node.href = path;
|
221
|
+
this.attachAttributes(node, options.attributes);
|
222
|
+
if (options.innerContent) {
|
223
|
+
node.innerHTML = options.innerContent;
|
224
|
+
}
|
225
|
+
this.doc.getElementsByTagName('head')[0].appendChild(node);
|
226
|
+
const item = {
|
227
|
+
path,
|
228
|
+
status: 'ok'
|
229
|
+
};
|
230
|
+
this.cached[path] = item;
|
231
|
+
resolve(item);
|
232
|
+
});
|
233
|
+
}
|
234
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.7", ngImport: i0, type: LazyService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
235
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.7", ngImport: i0, type: LazyService, providedIn: 'root' }); }
|
236
|
+
}
|
237
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.7", ngImport: i0, type: LazyService, decorators: [{
|
238
|
+
type: Injectable,
|
239
|
+
args: [{ providedIn: 'root' }]
|
240
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
241
|
+
type: Inject,
|
242
|
+
args: [DOCUMENT]
|
243
|
+
}] }]; } });
|
244
|
+
|
245
|
+
function throwError(msg, actual, expected, comparison) {
|
246
|
+
if (ngDevMode) {
|
247
|
+
throw new Error(`ASSERTION ERROR: ${msg}${comparison == null ? '' : ` [Expected=> ${expected} ${comparison} ${actual} <=Actual]`}`);
|
248
|
+
}
|
249
|
+
}
|
250
|
+
/**
|
251
|
+
* Assert whether the expression and throw an error into console in dev mode
|
252
|
+
*
|
253
|
+
* 断言表达式是否符合预期,并在开发模式下会在控制台抛出一个错误
|
254
|
+
*/
|
255
|
+
function assert(expression, msg) {
|
256
|
+
if (!expression) {
|
257
|
+
throwError(msg);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
/**
|
261
|
+
* Assert whether empty (`null` or `undefined`)
|
262
|
+
*
|
263
|
+
* 断言是否空值(`null` 或 `undefined`)
|
264
|
+
*/
|
265
|
+
function assertEmpty(actual, msg) {
|
266
|
+
if (actual == null) {
|
267
|
+
throwError(msg, typeof actual, 'NULL', '==');
|
268
|
+
}
|
269
|
+
}
|
270
|
+
/**
|
271
|
+
* Assert whether `number` type
|
272
|
+
*
|
273
|
+
* 断言是否 `number` 类型
|
274
|
+
*/
|
275
|
+
function assertNumber(actual, msg) {
|
276
|
+
if (!(typeof actual === 'number')) {
|
277
|
+
throwError(msg, typeof actual, 'number', '===');
|
278
|
+
}
|
279
|
+
}
|
280
|
+
/**
|
281
|
+
* Assert whether `string` type
|
282
|
+
*
|
283
|
+
* 断言是否 `string` 类型
|
284
|
+
*/
|
285
|
+
function assertString(actual, msg) {
|
286
|
+
if (!(typeof actual === 'string')) {
|
287
|
+
throwError(msg, actual === null ? 'null' : typeof actual, 'string', '===');
|
288
|
+
}
|
289
|
+
}
|
290
|
+
/**
|
291
|
+
* Assert whether `array` type
|
292
|
+
*
|
293
|
+
* 断言是否 `array` 类型
|
294
|
+
*/
|
295
|
+
function assertArray(actual, msg) {
|
296
|
+
if (!Array.isArray(actual)) {
|
297
|
+
throwError(msg, actual === null ? 'null' : typeof actual, 'array', '===');
|
298
|
+
}
|
299
|
+
}
|
300
|
+
/**
|
301
|
+
* Assert whether `Observable` type
|
302
|
+
*
|
303
|
+
* 断言是否 `Observable` 类型
|
304
|
+
*/
|
305
|
+
function assertObservable(obj, msg) {
|
306
|
+
if (!isObservable(obj)) {
|
307
|
+
throwError(msg, obj === null ? 'null' : typeof obj, 'Observable', '===');
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
const resizeWindow = () => {
|
312
|
+
window.dispatchEvent(new Event('resize'));
|
313
|
+
};
|
314
|
+
|
315
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
316
|
+
class PathToRegexpService {
|
317
|
+
constructor() {
|
318
|
+
this.DEFAULT_DELIMITER = '/';
|
319
|
+
this.PATH_REGEXP = new RegExp(['(\\\\.)', '(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?'].join('|'), 'g');
|
320
|
+
}
|
321
|
+
parse(str, options) {
|
322
|
+
const tokens = [];
|
323
|
+
let key = 0;
|
324
|
+
let index = 0;
|
325
|
+
let path = '';
|
326
|
+
const defaultDelimiter = (options && options.delimiter) || this.DEFAULT_DELIMITER;
|
327
|
+
const whitelist = (options && options.whitelist) || undefined;
|
328
|
+
let pathEscaped = false;
|
329
|
+
let res;
|
330
|
+
while ((res = this.PATH_REGEXP.exec(str)) !== null) {
|
331
|
+
const m = res[0];
|
332
|
+
const escaped = res[1];
|
333
|
+
const offset = res.index;
|
334
|
+
path += str.slice(index, offset);
|
335
|
+
index = offset + m.length;
|
336
|
+
// Ignore already escaped sequences.
|
337
|
+
if (escaped) {
|
338
|
+
path += escaped[1];
|
339
|
+
pathEscaped = true;
|
340
|
+
continue;
|
341
|
+
}
|
342
|
+
let prev = '';
|
343
|
+
const name = res[2];
|
344
|
+
const capture = res[3];
|
345
|
+
const group = res[4];
|
346
|
+
const modifier = res[5];
|
347
|
+
if (!pathEscaped && path.length) {
|
348
|
+
const k = path.length - 1;
|
349
|
+
const c = path[k];
|
350
|
+
const matches = whitelist ? whitelist.indexOf(c) > -1 : true;
|
351
|
+
if (matches) {
|
352
|
+
prev = c;
|
353
|
+
path = path.slice(0, k);
|
354
|
+
}
|
355
|
+
}
|
356
|
+
// Push the current path onto the tokens.
|
357
|
+
if (path) {
|
358
|
+
tokens.push(path);
|
359
|
+
path = '';
|
360
|
+
pathEscaped = false;
|
361
|
+
}
|
362
|
+
const repeat = modifier === '+' || modifier === '*';
|
363
|
+
const optional = modifier === '?' || modifier === '*';
|
364
|
+
const pattern = capture || group;
|
365
|
+
const delimiter = prev || defaultDelimiter;
|
366
|
+
tokens.push({
|
367
|
+
name: name || key++,
|
368
|
+
prefix: prev,
|
369
|
+
delimiter: delimiter,
|
370
|
+
optional: optional,
|
371
|
+
repeat: repeat,
|
372
|
+
pattern: pattern
|
373
|
+
? this.escapeGroup(pattern)
|
374
|
+
: `[^${this.escapeString(delimiter === defaultDelimiter ? delimiter : delimiter + defaultDelimiter)}]+?`
|
375
|
+
});
|
376
|
+
}
|
377
|
+
// Push any remaining characters.
|
378
|
+
if (path || index < str.length) {
|
379
|
+
tokens.push(path + str.substr(index));
|
380
|
+
}
|
381
|
+
return tokens;
|
382
|
+
}
|
383
|
+
compile(str, options) {
|
384
|
+
return this.tokensToFunction(this.parse(str, options), options);
|
385
|
+
}
|
386
|
+
tokensToFunction(tokens, options) {
|
387
|
+
const matches = new Array(tokens.length);
|
388
|
+
for (let i = 0; i < tokens.length; i++) {
|
389
|
+
if (typeof tokens[i] === 'object') {
|
390
|
+
matches[i] = new RegExp(`^(?:${tokens[i].pattern})$`, this.flags(options));
|
391
|
+
}
|
392
|
+
}
|
393
|
+
return function (data, options) {
|
394
|
+
let path = '';
|
395
|
+
const encode = (options && options.encode) || encodeURIComponent;
|
396
|
+
const validate = options ? options.validate !== false : true;
|
397
|
+
for (let i = 0; i < tokens.length; i++) {
|
398
|
+
const token = tokens[i];
|
399
|
+
if (typeof token === 'string') {
|
400
|
+
path += token;
|
401
|
+
continue;
|
402
|
+
}
|
403
|
+
const value = data ? data[token.name] : undefined;
|
404
|
+
let segment;
|
405
|
+
if (Array.isArray(value)) {
|
406
|
+
if (!token.repeat) {
|
407
|
+
throw new TypeError(`Expected "${token.name}" to not repeat, but got array`);
|
408
|
+
}
|
409
|
+
if (value.length === 0) {
|
410
|
+
if (token.optional) {
|
411
|
+
continue;
|
412
|
+
}
|
413
|
+
throw new TypeError(`Expected "${token.name}" to not be empty`);
|
414
|
+
}
|
415
|
+
for (let j = 0; j < value.length; j++) {
|
416
|
+
segment = encode(value[j], token);
|
417
|
+
if (validate && !matches[i].test(segment)) {
|
418
|
+
throw new TypeError(`Expected all "${token.name}" to match "${token.pattern}"`);
|
419
|
+
}
|
420
|
+
path += (j === 0 ? token.prefix : token.delimiter) + segment;
|
421
|
+
}
|
422
|
+
continue;
|
423
|
+
}
|
424
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
425
|
+
segment = encode(String(value), token);
|
426
|
+
if (validate && !matches[i].test(segment)) {
|
427
|
+
throw new TypeError(`Expected "${token.name}" to match "${token.pattern}", but got "${segment}"`);
|
428
|
+
}
|
429
|
+
path += token.prefix + segment;
|
430
|
+
continue;
|
431
|
+
}
|
432
|
+
if (token.optional) {
|
433
|
+
continue;
|
434
|
+
}
|
435
|
+
throw new TypeError(`Expected "${token.name}" to be ${token.repeat ? 'an array' : 'a string'}`);
|
436
|
+
}
|
437
|
+
return path;
|
438
|
+
};
|
439
|
+
}
|
440
|
+
escapeString(str) {
|
441
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1');
|
442
|
+
}
|
443
|
+
escapeGroup(group) {
|
444
|
+
return group.replace(/([=!:$/()])/g, '\\$1');
|
445
|
+
}
|
446
|
+
flags(options) {
|
447
|
+
return options && options.sensitive ? '' : 'i';
|
448
|
+
}
|
449
|
+
regexpToRegexp(path, keys) {
|
450
|
+
if (!keys) {
|
451
|
+
return path;
|
452
|
+
}
|
453
|
+
const groups = path.source.match(/\((?!\?)/g);
|
454
|
+
if (groups) {
|
455
|
+
for (let i = 0; i < groups.length; i++) {
|
456
|
+
keys.push({
|
457
|
+
name: i,
|
458
|
+
prefix: null,
|
459
|
+
delimiter: null,
|
460
|
+
optional: false,
|
461
|
+
repeat: false,
|
462
|
+
pattern: null
|
463
|
+
});
|
464
|
+
}
|
465
|
+
}
|
466
|
+
return path;
|
467
|
+
}
|
468
|
+
arrayToRegexp(path, keys, options) {
|
469
|
+
const parts = [];
|
470
|
+
for (let i = 0; i < path.length; i++) {
|
471
|
+
parts.push(this.pathToRegexp(path[i], keys, options).source);
|
472
|
+
}
|
473
|
+
return new RegExp(`(?:${parts.join('|')})`, this.flags(options));
|
474
|
+
}
|
475
|
+
stringToRegexp(path, keys, options) {
|
476
|
+
return this.tokensToRegExp(this.parse(path, options), keys, options);
|
477
|
+
}
|
478
|
+
tokensToRegExp(tokens, keys, options) {
|
479
|
+
options = options || {};
|
480
|
+
const strict = options.strict;
|
481
|
+
const start = options.start !== false;
|
482
|
+
const end = options.end !== false;
|
483
|
+
const delimiter = options.delimiter || this.DEFAULT_DELIMITER;
|
484
|
+
const endsWith = []
|
485
|
+
.concat(options.endsWith || [])
|
486
|
+
.map(this.escapeString)
|
487
|
+
.concat('$')
|
488
|
+
.join('|');
|
489
|
+
let route = start ? '^' : '';
|
490
|
+
for (let i = 0; i < tokens.length; i++) {
|
491
|
+
const token = tokens[i];
|
492
|
+
if (typeof token === 'string') {
|
493
|
+
route += this.escapeString(token);
|
494
|
+
}
|
495
|
+
else {
|
496
|
+
const capture = token.repeat
|
497
|
+
? `(?:${token.pattern})(?:${this.escapeString(token.delimiter)}(?:${token.pattern}))*`
|
498
|
+
: token.pattern;
|
499
|
+
if (keys) {
|
500
|
+
keys.push(token);
|
501
|
+
}
|
502
|
+
if (token.optional) {
|
503
|
+
if (!token.prefix) {
|
504
|
+
route += `(${capture})?`;
|
505
|
+
}
|
506
|
+
else {
|
507
|
+
route += `(?:${this.escapeString(token.prefix)}(${capture}))?`;
|
508
|
+
}
|
509
|
+
}
|
510
|
+
else {
|
511
|
+
route += `${this.escapeString(token.prefix)}(${capture})`;
|
512
|
+
}
|
513
|
+
}
|
514
|
+
}
|
515
|
+
if (end) {
|
516
|
+
if (!strict) {
|
517
|
+
route += `(?:${this.escapeString(delimiter)})?`;
|
518
|
+
}
|
519
|
+
route += endsWith === '$' ? '$' : `(?=${endsWith})`;
|
520
|
+
}
|
521
|
+
else {
|
522
|
+
const endToken = tokens[tokens.length - 1];
|
523
|
+
const isEndDelimited = typeof endToken === 'string' ? endToken[endToken.length - 1] === delimiter : endToken === undefined;
|
524
|
+
if (!strict) {
|
525
|
+
route += `(?:${this.escapeString(delimiter)}(?=${endsWith}))?`;
|
526
|
+
}
|
527
|
+
if (!isEndDelimited) {
|
528
|
+
route += `(?=${this.escapeString(delimiter)}|${endsWith})`;
|
529
|
+
}
|
530
|
+
}
|
531
|
+
return new RegExp(route, this.flags(options));
|
532
|
+
}
|
533
|
+
pathToRegexp(path, keys, options) {
|
534
|
+
if (path instanceof RegExp) {
|
535
|
+
return this.regexpToRegexp(path, keys);
|
536
|
+
}
|
537
|
+
if (Array.isArray(path)) {
|
538
|
+
return this.arrayToRegexp(/** @type {!Array} */ path, keys, options);
|
539
|
+
}
|
540
|
+
return this.stringToRegexp(/** @type {string} */ path, keys, options);
|
541
|
+
}
|
542
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.7", ngImport: i0, type: PathToRegexpService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
543
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.7", ngImport: i0, type: PathToRegexpService, providedIn: 'root' }); }
|
544
|
+
}
|
545
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.7", ngImport: i0, type: PathToRegexpService, decorators: [{
|
546
|
+
type: Injectable,
|
547
|
+
args: [{
|
548
|
+
providedIn: 'root'
|
549
|
+
}]
|
550
|
+
}], ctorParameters: function () { return []; } });
|
551
|
+
|
552
|
+
function setFavicon(path) {
|
553
|
+
const link = document.querySelector("link[rel*='icon']") || document.createElement('link');
|
554
|
+
link.type = 'image/x-icon';
|
555
|
+
link.rel = 'shortcut icon';
|
556
|
+
link.href = path;
|
557
|
+
document.getElementsByTagName('head')[0].appendChild(link);
|
558
|
+
}
|
559
|
+
function hasFavicon(url) {
|
560
|
+
return new Promise(resolve => {
|
561
|
+
let xmlHttp;
|
562
|
+
if (window['XMLHttpRequest']) {
|
563
|
+
xmlHttp = new XMLHttpRequest();
|
564
|
+
}
|
565
|
+
if (xmlHttp) {
|
566
|
+
xmlHttp.open('Get', url, false);
|
567
|
+
xmlHttp.send();
|
568
|
+
if (xmlHttp.status == 404) {
|
569
|
+
resolve(false);
|
570
|
+
}
|
571
|
+
else {
|
572
|
+
resolve(true);
|
573
|
+
}
|
574
|
+
}
|
575
|
+
else {
|
576
|
+
resolve(false);
|
577
|
+
}
|
578
|
+
});
|
579
|
+
}
|
580
|
+
|
581
|
+
/**
|
582
|
+
* Generated bundle index. Do not edit.
|
583
|
+
*/
|
584
|
+
|
585
|
+
export { LazyService, PREFIX, PathToRegexpService, assert, assertArray, assertEmpty, assertNumber, assertObservable, assertString, deepCopy, deepGet, deepMerge, deepMergeKey, hasFavicon, log, resizeWindow, setFavicon, warn, warnDeprecation };
|
586
|
+
//# sourceMappingURL=other.mjs.map
|