@ssv/ngx.ux 2.0.1-dev198 → 2.0.2
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.
- package/CHANGELOG.md +149 -142
- package/LICENSE +21 -21
- package/README.md +297 -297
- package/bundles/ssv-ngx.ux.umd.js +1154 -1154
- package/bundles/ssv-ngx.ux.umd.js.map +1 -1
- package/bundles/ssv-ngx.ux.umd.min.js +1 -1
- package/bundles/ssv-ngx.ux.umd.min.js.map +1 -1
- package/config.d.ts +7 -7
- package/esm2015/config.js +7 -7
- package/esm2015/index.js +5 -5
- package/esm2015/internal/internal.model.js +2 -2
- package/esm2015/module.js +50 -50
- package/esm2015/platform/window.js +28 -28
- package/esm2015/ssv-ngx.ux.js +7 -7
- package/esm2015/version.js +2 -2
- package/esm2015/viewport/index.js +9 -9
- package/esm2015/viewport/viewport-data/index.js +4 -4
- package/esm2015/viewport/viewport-data/viewport-data-matcher.js +108 -108
- package/esm2015/viewport/viewport-data/viewport-data.pipe.js +43 -43
- package/esm2015/viewport/viewport-data/viewport-data.service.js +38 -38
- package/esm2015/viewport/viewport-data/viewport-data.utils.js +100 -100
- package/esm2015/viewport/viewport-matcher-var.directive.js +64 -64
- package/esm2015/viewport/viewport-matcher.directive.js +134 -134
- package/esm2015/viewport/viewport-server-size.service.js +38 -38
- package/esm2015/viewport/viewport.const.js +18 -18
- package/esm2015/viewport/viewport.model.js +31 -31
- package/esm2015/viewport/viewport.service.js +69 -69
- package/esm2015/viewport/viewport.util.js +117 -117
- package/esm2020/config.mjs +7 -0
- package/esm2020/index.mjs +5 -0
- package/esm2020/internal/internal.model.mjs +2 -0
- package/esm2020/module.mjs +65 -0
- package/esm2020/platform/window.mjs +30 -0
- package/esm2020/ssv-ngx.ux.mjs +5 -0
- package/esm2020/version.mjs +2 -0
- package/esm2020/viewport/index.mjs +9 -0
- package/esm2020/viewport/viewport-data/index.mjs +4 -0
- package/esm2020/viewport/viewport-data/viewport-data-matcher.mjs +108 -0
- package/esm2020/viewport/viewport-data/viewport-data.pipe.mjs +43 -0
- package/esm2020/viewport/viewport-data/viewport-data.service.mjs +37 -0
- package/esm2020/viewport/viewport-data/viewport-data.utils.mjs +100 -0
- package/esm2020/viewport/viewport-matcher-var.directive.mjs +63 -0
- package/esm2020/viewport/viewport-matcher.directive.mjs +131 -0
- package/esm2020/viewport/viewport-server-size.service.mjs +43 -0
- package/esm2020/viewport/viewport.const.mjs +18 -0
- package/esm2020/viewport/viewport.model.mjs +31 -0
- package/esm2020/viewport/viewport.service.mjs +67 -0
- package/esm2020/viewport/viewport.util.mjs +117 -0
- package/fesm2015/ssv-ngx.ux.js +770 -770
- package/fesm2015/ssv-ngx.ux.js.map +1 -1
- package/fesm2015/ssv-ngx.ux.mjs +829 -0
- package/fesm2015/ssv-ngx.ux.mjs.map +1 -0
- package/fesm2020/ssv-ngx.ux.mjs +823 -0
- package/fesm2020/ssv-ngx.ux.mjs.map +1 -0
- package/index.d.ts +4 -4
- package/internal/internal.model.d.ts +9 -9
- package/module.d.ts +19 -12
- package/package.json +21 -9
- package/platform/window.d.ts +13 -10
- package/ssv-ngx.ux.d.ts +6 -6
- package/ssv-ngx.ux.metadata.json +1 -1
- package/version.d.ts +1 -1
- package/viewport/index.d.ts +8 -8
- package/viewport/viewport-data/index.d.ts +3 -3
- package/viewport/viewport-data/viewport-data-matcher.d.ts +32 -32
- package/viewport/viewport-data/viewport-data.pipe.d.ts +18 -15
- package/viewport/viewport-data/viewport-data.service.d.ts +20 -17
- package/viewport/viewport-data/viewport-data.utils.d.ts +21 -21
- package/viewport/viewport-matcher-var.directive.d.ts +25 -22
- package/viewport/viewport-matcher.directive.d.ts +33 -30
- package/viewport/viewport-server-size.service.d.ts +12 -9
- package/viewport/viewport.const.d.ts +5 -5
- package/viewport/viewport.model.d.ts +57 -57
- package/viewport/viewport.service.d.ts +37 -34
- package/viewport/viewport.util.d.ts +25 -25
package/fesm2015/ssv-ngx.ux.js
CHANGED
|
@@ -2,805 +2,805 @@ import { InjectionToken, ɵɵdefineInjectable, ɵɵinject, Injectable, Inject, O
|
|
|
2
2
|
import { map, share, auditTime, startWith, distinctUntilChanged, shareReplay, tap, takeUntil, filter, pairwise } from 'rxjs/operators';
|
|
3
3
|
import { fromEvent, of, Subscription, Subject, ReplaySubject, combineLatest } from 'rxjs';
|
|
4
4
|
|
|
5
|
-
var ViewportDataMatchStrategy;
|
|
6
|
-
(function (ViewportDataMatchStrategy) {
|
|
7
|
-
/** Indicates that size should match exact or default. */
|
|
8
|
-
ViewportDataMatchStrategy[ViewportDataMatchStrategy["exact"] = 0] = "exact";
|
|
9
|
-
/** Indicates that size matches when exact match, first match smaller (down) or default. */
|
|
10
|
-
ViewportDataMatchStrategy[ViewportDataMatchStrategy["smaller"] = 1] = "smaller";
|
|
11
|
-
/** Indicates that size matches when exact match, first match larger (up) or default. */
|
|
12
|
-
ViewportDataMatchStrategy[ViewportDataMatchStrategy["larger"] = 2] = "larger";
|
|
13
|
-
/** Indicates that size matches when exact match, or it tries both smaller/larger (smaller is preferred) until match or default. */
|
|
14
|
-
ViewportDataMatchStrategy[ViewportDataMatchStrategy["closestSmallerFirst"] = 3] = "closestSmallerFirst";
|
|
15
|
-
/** Indicates that size matches when exact match, or it tries both larger/smaller (larger is preferred) until match or default. */
|
|
16
|
-
ViewportDataMatchStrategy[ViewportDataMatchStrategy["closestLargerFirst"] = 4] = "closestLargerFirst";
|
|
17
|
-
})(ViewportDataMatchStrategy || (ViewportDataMatchStrategy = {}));
|
|
18
|
-
/**
|
|
19
|
-
* Utility function to match data based on strategy and size.
|
|
20
|
-
*
|
|
21
|
-
* @param dataConfig Data config to generate rules based on.
|
|
22
|
-
* @param sizeType Size type to get data for.
|
|
23
|
-
* @param strategy Strategy to use when building rules.
|
|
24
|
-
* @param sizeTypes Available size types ordered by index type. (Can be obtained from `ViewportService`)
|
|
25
|
-
* @param sizeTypeMap Available size type map. (Can be obtained from `ViewportService`)
|
|
26
|
-
* @returns Returns the matched data value.
|
|
27
|
-
*/
|
|
28
|
-
function matchViewportData(dataConfig, sizeType, strategy, sizeTypes, sizeTypeMap) {
|
|
29
|
-
const matchFn = matchStrategyHandlerMap[strategy];
|
|
30
|
-
if (!matchFn) {
|
|
31
|
-
throw Error(`matchViewportData: Viewport Data strategy not implemented. Strategy: '${strategy}'`);
|
|
32
|
-
}
|
|
33
|
-
const data = matchFn(dataConfig, sizeType, sizeTypes, sizeTypeMap);
|
|
34
|
-
if (data !== undefined) {
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
return dataConfig.default;
|
|
38
|
-
}
|
|
39
|
-
const matchStrategyHandlerMap = {
|
|
40
|
-
[ViewportDataMatchStrategy.exact]: matchWithExact,
|
|
41
|
-
[ViewportDataMatchStrategy.larger]: matchWithLargerMatch,
|
|
42
|
-
[ViewportDataMatchStrategy.smaller]: matchWithSmallerMatch,
|
|
43
|
-
[ViewportDataMatchStrategy.closestSmallerFirst]: matchWithClosestSmallerFirstMatch,
|
|
44
|
-
[ViewportDataMatchStrategy.closestLargerFirst]: matchWithClosestLargerFirstMatch,
|
|
45
|
-
};
|
|
46
|
-
function matchWithExact(dataConfig, currentSizeType) {
|
|
47
|
-
return dataConfig[currentSizeType.name];
|
|
48
|
-
}
|
|
49
|
-
function matchWithLargerMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
50
|
-
let data = dataConfig[currentSizeType.name];
|
|
51
|
-
if (data !== undefined) {
|
|
52
|
-
return data;
|
|
53
|
-
}
|
|
54
|
-
const largestTypeIdx = sizeTypes[sizeTypes.length - 1].type;
|
|
55
|
-
if (currentSizeType.type >= largestTypeIdx) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
for (let index = currentSizeType.type; index < sizeTypes.length; index++) {
|
|
59
|
-
const sizeType = sizeTypes[index];
|
|
60
|
-
data = dataConfig[sizeType.name];
|
|
61
|
-
if (data !== undefined) {
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
function matchWithSmallerMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
68
|
-
let data = dataConfig[currentSizeType.name];
|
|
69
|
-
if (data !== undefined) {
|
|
70
|
-
return data;
|
|
71
|
-
}
|
|
72
|
-
if (currentSizeType.type <= 0) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
// eslint-disable-next-line for-direction
|
|
76
|
-
for (let index = currentSizeType.type; index < sizeTypes.length; index--) {
|
|
77
|
-
const sizeType = sizeTypes[index];
|
|
78
|
-
data = dataConfig[sizeType.name];
|
|
79
|
-
if (data !== undefined) {
|
|
80
|
-
return data;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
function matchWithClosestSmallerFirstMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
86
|
-
return closestMatch(dataConfig, currentSizeType, sizeTypes, true);
|
|
87
|
-
}
|
|
88
|
-
function matchWithClosestLargerFirstMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
89
|
-
return closestMatch(dataConfig, currentSizeType, sizeTypes, false);
|
|
90
|
-
}
|
|
91
|
-
function closestMatch(dataConfig, currentSizeType, sizeTypes, isSmallerFirst) {
|
|
92
|
-
let data = dataConfig[currentSizeType.name];
|
|
93
|
-
if (data !== undefined) {
|
|
94
|
-
return data;
|
|
95
|
-
}
|
|
96
|
-
let downIndex = currentSizeType.type;
|
|
97
|
-
let upIndex = currentSizeType.type;
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
99
|
-
for (let index = 0; index < sizeTypes.length; index++) {
|
|
100
|
-
for (const idx of isSmallerFirst ? [--downIndex, ++upIndex] : [++upIndex, --downIndex]) {
|
|
101
|
-
const sizeType = sizeTypes[idx];
|
|
102
|
-
if (sizeType) {
|
|
103
|
-
data = dataConfig[sizeType.name];
|
|
104
|
-
if (data !== undefined) {
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return undefined;
|
|
5
|
+
var ViewportDataMatchStrategy;
|
|
6
|
+
(function (ViewportDataMatchStrategy) {
|
|
7
|
+
/** Indicates that size should match exact or default. */
|
|
8
|
+
ViewportDataMatchStrategy[ViewportDataMatchStrategy["exact"] = 0] = "exact";
|
|
9
|
+
/** Indicates that size matches when exact match, first match smaller (down) or default. */
|
|
10
|
+
ViewportDataMatchStrategy[ViewportDataMatchStrategy["smaller"] = 1] = "smaller";
|
|
11
|
+
/** Indicates that size matches when exact match, first match larger (up) or default. */
|
|
12
|
+
ViewportDataMatchStrategy[ViewportDataMatchStrategy["larger"] = 2] = "larger";
|
|
13
|
+
/** Indicates that size matches when exact match, or it tries both smaller/larger (smaller is preferred) until match or default. */
|
|
14
|
+
ViewportDataMatchStrategy[ViewportDataMatchStrategy["closestSmallerFirst"] = 3] = "closestSmallerFirst";
|
|
15
|
+
/** Indicates that size matches when exact match, or it tries both larger/smaller (larger is preferred) until match or default. */
|
|
16
|
+
ViewportDataMatchStrategy[ViewportDataMatchStrategy["closestLargerFirst"] = 4] = "closestLargerFirst";
|
|
17
|
+
})(ViewportDataMatchStrategy || (ViewportDataMatchStrategy = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Utility function to match data based on strategy and size.
|
|
20
|
+
*
|
|
21
|
+
* @param dataConfig Data config to generate rules based on.
|
|
22
|
+
* @param sizeType Size type to get data for.
|
|
23
|
+
* @param strategy Strategy to use when building rules.
|
|
24
|
+
* @param sizeTypes Available size types ordered by index type. (Can be obtained from `ViewportService`)
|
|
25
|
+
* @param sizeTypeMap Available size type map. (Can be obtained from `ViewportService`)
|
|
26
|
+
* @returns Returns the matched data value.
|
|
27
|
+
*/
|
|
28
|
+
function matchViewportData(dataConfig, sizeType, strategy, sizeTypes, sizeTypeMap) {
|
|
29
|
+
const matchFn = matchStrategyHandlerMap[strategy];
|
|
30
|
+
if (!matchFn) {
|
|
31
|
+
throw Error(`matchViewportData: Viewport Data strategy not implemented. Strategy: '${strategy}'`);
|
|
32
|
+
}
|
|
33
|
+
const data = matchFn(dataConfig, sizeType, sizeTypes, sizeTypeMap);
|
|
34
|
+
if (data !== undefined) {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
return dataConfig.default;
|
|
38
|
+
}
|
|
39
|
+
const matchStrategyHandlerMap = {
|
|
40
|
+
[ViewportDataMatchStrategy.exact]: matchWithExact,
|
|
41
|
+
[ViewportDataMatchStrategy.larger]: matchWithLargerMatch,
|
|
42
|
+
[ViewportDataMatchStrategy.smaller]: matchWithSmallerMatch,
|
|
43
|
+
[ViewportDataMatchStrategy.closestSmallerFirst]: matchWithClosestSmallerFirstMatch,
|
|
44
|
+
[ViewportDataMatchStrategy.closestLargerFirst]: matchWithClosestLargerFirstMatch,
|
|
45
|
+
};
|
|
46
|
+
function matchWithExact(dataConfig, currentSizeType) {
|
|
47
|
+
return dataConfig[currentSizeType.name];
|
|
48
|
+
}
|
|
49
|
+
function matchWithLargerMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
50
|
+
let data = dataConfig[currentSizeType.name];
|
|
51
|
+
if (data !== undefined) {
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
const largestTypeIdx = sizeTypes[sizeTypes.length - 1].type;
|
|
55
|
+
if (currentSizeType.type >= largestTypeIdx) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
for (let index = currentSizeType.type; index < sizeTypes.length; index++) {
|
|
59
|
+
const sizeType = sizeTypes[index];
|
|
60
|
+
data = dataConfig[sizeType.name];
|
|
61
|
+
if (data !== undefined) {
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
function matchWithSmallerMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
68
|
+
let data = dataConfig[currentSizeType.name];
|
|
69
|
+
if (data !== undefined) {
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
if (currentSizeType.type <= 0) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
// eslint-disable-next-line for-direction
|
|
76
|
+
for (let index = currentSizeType.type; index < sizeTypes.length; index--) {
|
|
77
|
+
const sizeType = sizeTypes[index];
|
|
78
|
+
data = dataConfig[sizeType.name];
|
|
79
|
+
if (data !== undefined) {
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
function matchWithClosestSmallerFirstMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
86
|
+
return closestMatch(dataConfig, currentSizeType, sizeTypes, true);
|
|
87
|
+
}
|
|
88
|
+
function matchWithClosestLargerFirstMatch(dataConfig, currentSizeType, sizeTypes) {
|
|
89
|
+
return closestMatch(dataConfig, currentSizeType, sizeTypes, false);
|
|
90
|
+
}
|
|
91
|
+
function closestMatch(dataConfig, currentSizeType, sizeTypes, isSmallerFirst) {
|
|
92
|
+
let data = dataConfig[currentSizeType.name];
|
|
93
|
+
if (data !== undefined) {
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
let downIndex = currentSizeType.type;
|
|
97
|
+
let upIndex = currentSizeType.type;
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
99
|
+
for (let index = 0; index < sizeTypes.length; index++) {
|
|
100
|
+
for (const idx of isSmallerFirst ? [--downIndex, ++upIndex] : [++upIndex, --downIndex]) {
|
|
101
|
+
const sizeType = sizeTypes[idx];
|
|
102
|
+
if (sizeType) {
|
|
103
|
+
data = dataConfig[sizeType.name];
|
|
104
|
+
if (data !== undefined) {
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
/** Default viewport breakpoints. */
|
|
114
|
-
const UX_VIEWPORT_DEFAULT_BREAKPOINTS = {
|
|
115
|
-
xsmall: 450,
|
|
116
|
-
small: 767,
|
|
117
|
-
medium: 992,
|
|
118
|
-
large: 1280,
|
|
119
|
-
fhd: 1920,
|
|
120
|
-
qhd: 2560,
|
|
121
|
-
uhd4k: 3840,
|
|
122
|
-
uhd8k: 7680,
|
|
123
|
-
};
|
|
124
|
-
const UX_VIEWPORT_DEFAULT_CONFIG = {
|
|
125
|
-
resizePollingSpeed: 33,
|
|
126
|
-
breakpoints: UX_VIEWPORT_DEFAULT_BREAKPOINTS,
|
|
127
|
-
defaultDataMatchStrategy: ViewportDataMatchStrategy.smaller,
|
|
113
|
+
/** Default viewport breakpoints. */
|
|
114
|
+
const UX_VIEWPORT_DEFAULT_BREAKPOINTS = {
|
|
115
|
+
xsmall: 450,
|
|
116
|
+
small: 767,
|
|
117
|
+
medium: 992,
|
|
118
|
+
large: 1280,
|
|
119
|
+
fhd: 1920,
|
|
120
|
+
qhd: 2560,
|
|
121
|
+
uhd4k: 3840,
|
|
122
|
+
uhd8k: 7680,
|
|
123
|
+
};
|
|
124
|
+
const UX_VIEWPORT_DEFAULT_CONFIG = {
|
|
125
|
+
resizePollingSpeed: 33,
|
|
126
|
+
breakpoints: UX_VIEWPORT_DEFAULT_BREAKPOINTS,
|
|
127
|
+
defaultDataMatchStrategy: ViewportDataMatchStrategy.smaller,
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
-
const UX_DEFAULT_CONFIG = {
|
|
131
|
-
viewport: UX_VIEWPORT_DEFAULT_CONFIG,
|
|
132
|
-
};
|
|
130
|
+
const UX_DEFAULT_CONFIG = {
|
|
131
|
+
viewport: UX_VIEWPORT_DEFAULT_CONFIG,
|
|
132
|
+
};
|
|
133
133
|
const UX_CONFIG = new InjectionToken("@ssv/ngx.ux-config");
|
|
134
134
|
|
|
135
|
-
const WINDOW = new InjectionToken("Window");
|
|
136
|
-
class WindowRef {
|
|
137
|
-
constructor(
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
139
|
-
window) {
|
|
140
|
-
this.window = window;
|
|
141
|
-
}
|
|
142
|
-
/** Window underlying native object. */
|
|
143
|
-
get native() {
|
|
144
|
-
return this.window;
|
|
145
|
-
}
|
|
146
|
-
/** Determines whether native element is supported or not. Generally `false` when executing in SSR. */
|
|
147
|
-
get hasNative() {
|
|
148
|
-
return !!this.native.window;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
WindowRef.ɵprov = ɵɵdefineInjectable({ factory: function WindowRef_Factory() { return new WindowRef(ɵɵinject(WINDOW)); }, token: WindowRef, providedIn: "root" });
|
|
152
|
-
WindowRef.decorators = [
|
|
153
|
-
{ type: Injectable, args: [{
|
|
154
|
-
providedIn: "root",
|
|
155
|
-
},] }
|
|
156
|
-
];
|
|
157
|
-
WindowRef.ctorParameters = () => [
|
|
158
|
-
{ type: undefined, decorators: [{ type: Inject, args: [WINDOW,] }] }
|
|
135
|
+
const WINDOW = new InjectionToken("Window");
|
|
136
|
+
class WindowRef {
|
|
137
|
+
constructor(
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
139
|
+
window) {
|
|
140
|
+
this.window = window;
|
|
141
|
+
}
|
|
142
|
+
/** Window underlying native object. */
|
|
143
|
+
get native() {
|
|
144
|
+
return this.window;
|
|
145
|
+
}
|
|
146
|
+
/** Determines whether native element is supported or not. Generally `false` when executing in SSR. */
|
|
147
|
+
get hasNative() {
|
|
148
|
+
return !!this.native.window;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
WindowRef.ɵprov = ɵɵdefineInjectable({ factory: function WindowRef_Factory() { return new WindowRef(ɵɵinject(WINDOW)); }, token: WindowRef, providedIn: "root" });
|
|
152
|
+
WindowRef.decorators = [
|
|
153
|
+
{ type: Injectable, args: [{
|
|
154
|
+
providedIn: "root",
|
|
155
|
+
},] }
|
|
156
|
+
];
|
|
157
|
+
WindowRef.ctorParameters = () => [
|
|
158
|
+
{ type: undefined, decorators: [{ type: Inject, args: [WINDOW,] }] }
|
|
159
159
|
];
|
|
160
160
|
|
|
161
|
-
/**
|
|
162
|
-
* The indices of each breakpoint provided based on the `UX_VIEWPORT_DEFAULT_BREAKPOINTS`.
|
|
163
|
-
* @see UX_VIEWPORT_DEFAULT_BREAKPOINTS
|
|
164
|
-
*/
|
|
165
|
-
var ViewportSizeType;
|
|
166
|
-
(function (ViewportSizeType) {
|
|
167
|
-
ViewportSizeType[ViewportSizeType["xsmall"] = 0] = "xsmall";
|
|
168
|
-
ViewportSizeType[ViewportSizeType["small"] = 1] = "small";
|
|
169
|
-
ViewportSizeType[ViewportSizeType["medium"] = 2] = "medium";
|
|
170
|
-
ViewportSizeType[ViewportSizeType["large"] = 3] = "large";
|
|
171
|
-
ViewportSizeType[ViewportSizeType["fhd"] = 4] = "fhd";
|
|
172
|
-
ViewportSizeType[ViewportSizeType["qhd"] = 6] = "qhd";
|
|
173
|
-
ViewportSizeType[ViewportSizeType["uhd4k"] = 7] = "uhd4k";
|
|
174
|
-
ViewportSizeType[ViewportSizeType["uhd8k"] = 8] = "uhd8k";
|
|
175
|
-
})(ViewportSizeType || (ViewportSizeType = {}));
|
|
176
|
-
var ComparisonOperation;
|
|
177
|
-
(function (ComparisonOperation) {
|
|
178
|
-
ComparisonOperation["equals"] = "=";
|
|
179
|
-
ComparisonOperation["notEquals"] = "<>";
|
|
180
|
-
ComparisonOperation["lessThan"] = "<";
|
|
181
|
-
ComparisonOperation["lessOrEqualThan"] = "<=";
|
|
182
|
-
ComparisonOperation["greaterThan"] = ">";
|
|
183
|
-
ComparisonOperation["greaterOrEqualThan"] = ">=";
|
|
184
|
-
})(ComparisonOperation || (ComparisonOperation = {}));
|
|
185
|
-
var DeviceType;
|
|
186
|
-
(function (DeviceType) {
|
|
187
|
-
DeviceType["desktop"] = "desktop";
|
|
188
|
-
DeviceType["mobile"] = "mobile";
|
|
189
|
-
DeviceType["tablet"] = "tablet";
|
|
161
|
+
/**
|
|
162
|
+
* The indices of each breakpoint provided based on the `UX_VIEWPORT_DEFAULT_BREAKPOINTS`.
|
|
163
|
+
* @see UX_VIEWPORT_DEFAULT_BREAKPOINTS
|
|
164
|
+
*/
|
|
165
|
+
var ViewportSizeType;
|
|
166
|
+
(function (ViewportSizeType) {
|
|
167
|
+
ViewportSizeType[ViewportSizeType["xsmall"] = 0] = "xsmall";
|
|
168
|
+
ViewportSizeType[ViewportSizeType["small"] = 1] = "small";
|
|
169
|
+
ViewportSizeType[ViewportSizeType["medium"] = 2] = "medium";
|
|
170
|
+
ViewportSizeType[ViewportSizeType["large"] = 3] = "large";
|
|
171
|
+
ViewportSizeType[ViewportSizeType["fhd"] = 4] = "fhd";
|
|
172
|
+
ViewportSizeType[ViewportSizeType["qhd"] = 6] = "qhd";
|
|
173
|
+
ViewportSizeType[ViewportSizeType["uhd4k"] = 7] = "uhd4k";
|
|
174
|
+
ViewportSizeType[ViewportSizeType["uhd8k"] = 8] = "uhd8k";
|
|
175
|
+
})(ViewportSizeType || (ViewportSizeType = {}));
|
|
176
|
+
var ComparisonOperation;
|
|
177
|
+
(function (ComparisonOperation) {
|
|
178
|
+
ComparisonOperation["equals"] = "=";
|
|
179
|
+
ComparisonOperation["notEquals"] = "<>";
|
|
180
|
+
ComparisonOperation["lessThan"] = "<";
|
|
181
|
+
ComparisonOperation["lessOrEqualThan"] = "<=";
|
|
182
|
+
ComparisonOperation["greaterThan"] = ">";
|
|
183
|
+
ComparisonOperation["greaterOrEqualThan"] = ">=";
|
|
184
|
+
})(ComparisonOperation || (ComparisonOperation = {}));
|
|
185
|
+
var DeviceType;
|
|
186
|
+
(function (DeviceType) {
|
|
187
|
+
DeviceType["desktop"] = "desktop";
|
|
188
|
+
DeviceType["mobile"] = "mobile";
|
|
189
|
+
DeviceType["tablet"] = "tablet";
|
|
190
190
|
})(DeviceType || (DeviceType = {}));
|
|
191
191
|
|
|
192
|
-
// todo: make this configurable
|
|
193
|
-
/** Viewport size for SSR. */
|
|
194
|
-
const viewportSizeSSR = {
|
|
195
|
-
[DeviceType.desktop]: {
|
|
196
|
-
width: 1366,
|
|
197
|
-
height: 768,
|
|
198
|
-
},
|
|
199
|
-
[DeviceType.tablet]: {
|
|
200
|
-
width: 768,
|
|
201
|
-
height: 1024,
|
|
202
|
-
},
|
|
203
|
-
[DeviceType.mobile]: {
|
|
204
|
-
width: 414,
|
|
205
|
-
height: 736,
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
const UX_VIEWPORT_SSR_DEVICE = new InjectionToken("@ssv/ngx.ux-config/viewport/ssr-device");
|
|
209
|
-
class ViewportServerSizeService {
|
|
210
|
-
constructor(deviceType) {
|
|
211
|
-
this.deviceType = deviceType;
|
|
212
|
-
}
|
|
213
|
-
get() {
|
|
214
|
-
return viewportSizeSSR[this.deviceType] || viewportSizeSSR[DeviceType.desktop];
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
ViewportServerSizeService.ɵprov = ɵɵdefineInjectable({ factory: function ViewportServerSizeService_Factory() { return new ViewportServerSizeService(ɵɵinject(UX_VIEWPORT_SSR_DEVICE, 8)); }, token: ViewportServerSizeService, providedIn: "root" });
|
|
218
|
-
ViewportServerSizeService.decorators = [
|
|
219
|
-
{ type: Injectable, args: [{
|
|
220
|
-
providedIn: "root",
|
|
221
|
-
},] }
|
|
222
|
-
];
|
|
223
|
-
ViewportServerSizeService.ctorParameters = () => [
|
|
224
|
-
{ type: DeviceType, decorators: [{ type: Optional }, { type: Inject, args: [UX_VIEWPORT_SSR_DEVICE,] }] }
|
|
192
|
+
// todo: make this configurable
|
|
193
|
+
/** Viewport size for SSR. */
|
|
194
|
+
const viewportSizeSSR = {
|
|
195
|
+
[DeviceType.desktop]: {
|
|
196
|
+
width: 1366,
|
|
197
|
+
height: 768,
|
|
198
|
+
},
|
|
199
|
+
[DeviceType.tablet]: {
|
|
200
|
+
width: 768,
|
|
201
|
+
height: 1024,
|
|
202
|
+
},
|
|
203
|
+
[DeviceType.mobile]: {
|
|
204
|
+
width: 414,
|
|
205
|
+
height: 736,
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
const UX_VIEWPORT_SSR_DEVICE = new InjectionToken("@ssv/ngx.ux-config/viewport/ssr-device");
|
|
209
|
+
class ViewportServerSizeService {
|
|
210
|
+
constructor(deviceType) {
|
|
211
|
+
this.deviceType = deviceType;
|
|
212
|
+
}
|
|
213
|
+
get() {
|
|
214
|
+
return viewportSizeSSR[this.deviceType] || viewportSizeSSR[DeviceType.desktop];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
ViewportServerSizeService.ɵprov = ɵɵdefineInjectable({ factory: function ViewportServerSizeService_Factory() { return new ViewportServerSizeService(ɵɵinject(UX_VIEWPORT_SSR_DEVICE, 8)); }, token: ViewportServerSizeService, providedIn: "root" });
|
|
218
|
+
ViewportServerSizeService.decorators = [
|
|
219
|
+
{ type: Injectable, args: [{
|
|
220
|
+
providedIn: "root",
|
|
221
|
+
},] }
|
|
222
|
+
];
|
|
223
|
+
ViewportServerSizeService.ctorParameters = () => [
|
|
224
|
+
{ type: DeviceType, decorators: [{ type: Optional }, { type: Inject, args: [UX_VIEWPORT_SSR_DEVICE,] }] }
|
|
225
225
|
];
|
|
226
226
|
|
|
227
|
-
function isViewportSizeMatcherExpression(value) {
|
|
228
|
-
if (typeof value !== "object" || !value) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
const args = value;
|
|
232
|
-
if (args.size && args.operation) {
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
function isViewportSizeMatcherTupleExpression(arg) {
|
|
238
|
-
if (!arg) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
if (Array.isArray(arg)) {
|
|
242
|
-
if (arg.length === 2) {
|
|
243
|
-
const [op] = arg;
|
|
244
|
-
return operations.includes(op);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
const operations = Object.values(ComparisonOperation);
|
|
250
|
-
const COMPARISON_OPERATION_FUNC_MAPPING = {
|
|
251
|
-
[ComparisonOperation.equals]: (a, b) => a === b,
|
|
252
|
-
[ComparisonOperation.notEquals]: (a, b) => a !== b,
|
|
253
|
-
[ComparisonOperation.lessThan]: (a, b) => a < b,
|
|
254
|
-
[ComparisonOperation.lessOrEqualThan]: (a, b) => a <= b,
|
|
255
|
-
[ComparisonOperation.greaterThan]: (a, b) => a > b,
|
|
256
|
-
[ComparisonOperation.greaterOrEqualThan]: (a, b) => a >= b,
|
|
257
|
-
};
|
|
258
|
-
function isViewportConditionMatch(evaluateSize, conditions, viewportSizeTypeInfoRefs) {
|
|
259
|
-
const isExcluded = match(conditions.sizeTypeExclude, evaluateSize.name, false);
|
|
260
|
-
let isIncluded;
|
|
261
|
-
let isExpressionTruthy;
|
|
262
|
-
if (!isExcluded && conditions.expression) {
|
|
263
|
-
const ref = viewportSizeTypeInfoRefs[conditions.expression.size];
|
|
264
|
-
if (!ref) {
|
|
265
|
-
throw new Error(`Viewport size type is invalid. Size type: '${conditions.expression.size}'`);
|
|
266
|
-
}
|
|
267
|
-
const expMatcher = COMPARISON_OPERATION_FUNC_MAPPING[conditions.expression.operation];
|
|
268
|
-
isExpressionTruthy = expMatcher(evaluateSize.type, ref.type);
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
isIncluded = match(conditions.sizeType, evaluateSize.name, true);
|
|
272
|
-
}
|
|
273
|
-
const shouldRender = (isExpressionTruthy || isIncluded) && !isExcluded;
|
|
274
|
-
// console.warn(">>> shouldRender", { evaluateSize, conditions, shouldRender });
|
|
275
|
-
return !!shouldRender;
|
|
276
|
-
}
|
|
277
|
-
function match(value, targetValue, defaultValue) {
|
|
278
|
-
if (!value) {
|
|
279
|
-
return defaultValue;
|
|
280
|
-
}
|
|
281
|
-
return Array.isArray(value)
|
|
282
|
-
? value.includes(targetValue)
|
|
283
|
-
: value === targetValue;
|
|
284
|
-
}
|
|
285
|
-
function getSizeTypeInfo(width, sizeTypes) {
|
|
286
|
-
const lastEntryIndex = sizeTypes.length - 1;
|
|
287
|
-
for (let idx = 0; idx < lastEntryIndex; idx++) {
|
|
288
|
-
const viewportSizeTypeInfo = sizeTypes[idx];
|
|
289
|
-
if (width <= viewportSizeTypeInfo.widthThreshold) {
|
|
290
|
-
return viewportSizeTypeInfo;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return sizeTypes[lastEntryIndex];
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Converts the breakpoints into a 2 dimensional array containing the name and width, and sorted from
|
|
297
|
-
* smallest to largest.
|
|
298
|
-
* @param breakpoints the breakpoints obtained from the config
|
|
299
|
-
* @internal
|
|
300
|
-
*/
|
|
301
|
-
function getSortedBreakpoints(breakpoints) {
|
|
302
|
-
return Object.entries(breakpoints)
|
|
303
|
-
.sort(([, widthA], [, widthB]) => widthA - widthB);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* A util function which generates the ViewportSizeTypeInfo.type for each breakpoint.
|
|
307
|
-
* @param breakpoints the custom breakpoints
|
|
308
|
-
*/
|
|
309
|
-
function generateViewportSizeType(breakpoints) {
|
|
310
|
-
return Object.freeze(getSortedBreakpoints(breakpoints).reduce((dictionary, [name], index) => {
|
|
311
|
-
dictionary[name] = index;
|
|
312
|
-
dictionary[index] = name;
|
|
313
|
-
return dictionary;
|
|
314
|
-
}, {}));
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Pre-processes the given breakpoints into an ordered list from smallest to largest while generating
|
|
318
|
-
* all the necessary information on the viewport.
|
|
319
|
-
* @param breakpoints the breakpoints obtained from the config
|
|
320
|
-
* @internal
|
|
321
|
-
*/
|
|
322
|
-
function generateViewportSizeTypeInfoList(breakpoints) {
|
|
323
|
-
return getSortedBreakpoints(breakpoints)
|
|
324
|
-
.map(([name, width], index) => (Object.freeze({
|
|
325
|
-
name,
|
|
326
|
-
type: index,
|
|
327
|
-
widthThreshold: width
|
|
328
|
-
})));
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Converts the breakpoint list into a dictionary while using the name as key.
|
|
332
|
-
* @param breakpointList the list of breakpoints
|
|
333
|
-
* @internal
|
|
334
|
-
*/
|
|
335
|
-
function generateViewportSizeTypeInfoRefs(breakpointList) {
|
|
336
|
-
return Object.freeze(breakpointList.reduce((dictionary, breakpoint) => {
|
|
337
|
-
dictionary[breakpoint.name] = breakpoint;
|
|
338
|
-
dictionary[breakpoint.type] = breakpoint;
|
|
339
|
-
return dictionary;
|
|
340
|
-
}, {}));
|
|
227
|
+
function isViewportSizeMatcherExpression(value) {
|
|
228
|
+
if (typeof value !== "object" || !value) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
const args = value;
|
|
232
|
+
if (args.size && args.operation) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
function isViewportSizeMatcherTupleExpression(arg) {
|
|
238
|
+
if (!arg) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if (Array.isArray(arg)) {
|
|
242
|
+
if (arg.length === 2) {
|
|
243
|
+
const [op] = arg;
|
|
244
|
+
return operations.includes(op);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
const operations = Object.values(ComparisonOperation);
|
|
250
|
+
const COMPARISON_OPERATION_FUNC_MAPPING = {
|
|
251
|
+
[ComparisonOperation.equals]: (a, b) => a === b,
|
|
252
|
+
[ComparisonOperation.notEquals]: (a, b) => a !== b,
|
|
253
|
+
[ComparisonOperation.lessThan]: (a, b) => a < b,
|
|
254
|
+
[ComparisonOperation.lessOrEqualThan]: (a, b) => a <= b,
|
|
255
|
+
[ComparisonOperation.greaterThan]: (a, b) => a > b,
|
|
256
|
+
[ComparisonOperation.greaterOrEqualThan]: (a, b) => a >= b,
|
|
257
|
+
};
|
|
258
|
+
function isViewportConditionMatch(evaluateSize, conditions, viewportSizeTypeInfoRefs) {
|
|
259
|
+
const isExcluded = match(conditions.sizeTypeExclude, evaluateSize.name, false);
|
|
260
|
+
let isIncluded;
|
|
261
|
+
let isExpressionTruthy;
|
|
262
|
+
if (!isExcluded && conditions.expression) {
|
|
263
|
+
const ref = viewportSizeTypeInfoRefs[conditions.expression.size];
|
|
264
|
+
if (!ref) {
|
|
265
|
+
throw new Error(`Viewport size type is invalid. Size type: '${conditions.expression.size}'`);
|
|
266
|
+
}
|
|
267
|
+
const expMatcher = COMPARISON_OPERATION_FUNC_MAPPING[conditions.expression.operation];
|
|
268
|
+
isExpressionTruthy = expMatcher(evaluateSize.type, ref.type);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
isIncluded = match(conditions.sizeType, evaluateSize.name, true);
|
|
272
|
+
}
|
|
273
|
+
const shouldRender = (isExpressionTruthy || isIncluded) && !isExcluded;
|
|
274
|
+
// console.warn(">>> shouldRender", { evaluateSize, conditions, shouldRender });
|
|
275
|
+
return !!shouldRender;
|
|
276
|
+
}
|
|
277
|
+
function match(value, targetValue, defaultValue) {
|
|
278
|
+
if (!value) {
|
|
279
|
+
return defaultValue;
|
|
280
|
+
}
|
|
281
|
+
return Array.isArray(value)
|
|
282
|
+
? value.includes(targetValue)
|
|
283
|
+
: value === targetValue;
|
|
284
|
+
}
|
|
285
|
+
function getSizeTypeInfo(width, sizeTypes) {
|
|
286
|
+
const lastEntryIndex = sizeTypes.length - 1;
|
|
287
|
+
for (let idx = 0; idx < lastEntryIndex; idx++) {
|
|
288
|
+
const viewportSizeTypeInfo = sizeTypes[idx];
|
|
289
|
+
if (width <= viewportSizeTypeInfo.widthThreshold) {
|
|
290
|
+
return viewportSizeTypeInfo;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return sizeTypes[lastEntryIndex];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Converts the breakpoints into a 2 dimensional array containing the name and width, and sorted from
|
|
297
|
+
* smallest to largest.
|
|
298
|
+
* @param breakpoints the breakpoints obtained from the config
|
|
299
|
+
* @internal
|
|
300
|
+
*/
|
|
301
|
+
function getSortedBreakpoints(breakpoints) {
|
|
302
|
+
return Object.entries(breakpoints)
|
|
303
|
+
.sort(([, widthA], [, widthB]) => widthA - widthB);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* A util function which generates the ViewportSizeTypeInfo.type for each breakpoint.
|
|
307
|
+
* @param breakpoints the custom breakpoints
|
|
308
|
+
*/
|
|
309
|
+
function generateViewportSizeType(breakpoints) {
|
|
310
|
+
return Object.freeze(getSortedBreakpoints(breakpoints).reduce((dictionary, [name], index) => {
|
|
311
|
+
dictionary[name] = index;
|
|
312
|
+
dictionary[index] = name;
|
|
313
|
+
return dictionary;
|
|
314
|
+
}, {}));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Pre-processes the given breakpoints into an ordered list from smallest to largest while generating
|
|
318
|
+
* all the necessary information on the viewport.
|
|
319
|
+
* @param breakpoints the breakpoints obtained from the config
|
|
320
|
+
* @internal
|
|
321
|
+
*/
|
|
322
|
+
function generateViewportSizeTypeInfoList(breakpoints) {
|
|
323
|
+
return getSortedBreakpoints(breakpoints)
|
|
324
|
+
.map(([name, width], index) => (Object.freeze({
|
|
325
|
+
name,
|
|
326
|
+
type: index,
|
|
327
|
+
widthThreshold: width
|
|
328
|
+
})));
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Converts the breakpoint list into a dictionary while using the name as key.
|
|
332
|
+
* @param breakpointList the list of breakpoints
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
function generateViewportSizeTypeInfoRefs(breakpointList) {
|
|
336
|
+
return Object.freeze(breakpointList.reduce((dictionary, breakpoint) => {
|
|
337
|
+
dictionary[breakpoint.name] = breakpoint;
|
|
338
|
+
dictionary[breakpoint.type] = breakpoint;
|
|
339
|
+
return dictionary;
|
|
340
|
+
}, {}));
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
class ViewportService {
|
|
344
|
-
constructor(windowRef, viewportServerSize, config) {
|
|
345
|
-
this.windowRef = windowRef;
|
|
346
|
-
this.viewportServerSize = viewportServerSize;
|
|
347
|
-
this._sizeTypes = generateViewportSizeTypeInfoList(config.viewport.breakpoints);
|
|
348
|
-
this._sizeTypeMap = generateViewportSizeTypeInfoRefs(this._sizeTypes);
|
|
349
|
-
if (windowRef.hasNative) {
|
|
350
|
-
this.resizeSnap$ = fromEvent(window, "resize").pipe(map(() => this.getViewportSize()), share());
|
|
351
|
-
this.resize$ = this.resizeSnap$.pipe(auditTime(config.viewport.resizePollingSpeed), share());
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
this.resizeSnap$ = this.resize$ = of(viewportServerSize.get());
|
|
355
|
-
}
|
|
356
|
-
const size = this.getViewportSize();
|
|
357
|
-
this._sizeTypeSnapshot = getSizeTypeInfo(size.width, this.sizeTypes);
|
|
358
|
-
const sizeFn = (obs$) => obs$.pipe(startWith(size), distinctUntilChanged((a, b) => a.width === b.width && a.height === b.height), shareReplay(1));
|
|
359
|
-
this.sizeSnap$ = sizeFn(this.resizeSnap$);
|
|
360
|
-
this.size$ = sizeFn(this.resize$);
|
|
361
|
-
const sizeTypeFn = (obs$) => obs$.pipe(distinctUntilChanged((a, b) => a.width === b.width), map(x => getSizeTypeInfo(x.width, this.sizeTypes)), distinctUntilChanged(), tap(x => this._sizeTypeSnapshot = x), shareReplay(1));
|
|
362
|
-
this.sizeType$ = sizeTypeFn(this.size$);
|
|
363
|
-
this.sizeTypeSnap$ = sizeTypeFn(this.sizeSnap$);
|
|
364
|
-
}
|
|
365
|
-
/** Viewport size type snapshot of the last value. (Prefer use `sizeType$` observable when possible.) */
|
|
366
|
-
get sizeTypeSnapshot() { return this._sizeTypeSnapshot; }
|
|
367
|
-
/** Size types refs of the generated viewport size type info. */
|
|
368
|
-
get sizeTypeMap() { return this._sizeTypeMap; }
|
|
369
|
-
/** Viewport size types list ordered by type, smallest to largest. */
|
|
370
|
-
get sizeTypes() { return this._sizeTypes; }
|
|
371
|
-
/** Returns the current viewport size */
|
|
372
|
-
getViewportSize() {
|
|
373
|
-
if (!this.windowRef.hasNative) {
|
|
374
|
-
return this.viewportServerSize.get();
|
|
375
|
-
}
|
|
376
|
-
const ua = navigator.userAgent.toLowerCase();
|
|
377
|
-
if (ua.indexOf("safari") !== -1 && ua.indexOf("chrome") === -1) { // safari subtracts the scrollbar width
|
|
378
|
-
return {
|
|
379
|
-
width: this.windowRef.native.document.documentElement.clientWidth,
|
|
380
|
-
height: this.windowRef.native.document.documentElement.clientHeight,
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
return {
|
|
384
|
-
width: this.windowRef.native.innerWidth,
|
|
385
|
-
height: this.windowRef.native.innerHeight,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
ViewportService.ɵprov = ɵɵdefineInjectable({ factory: function ViewportService_Factory() { return new ViewportService(ɵɵinject(WindowRef), ɵɵinject(ViewportServerSizeService), ɵɵinject(UX_CONFIG)); }, token: ViewportService, providedIn: "root" });
|
|
390
|
-
ViewportService.decorators = [
|
|
391
|
-
{ type: Injectable, args: [{
|
|
392
|
-
providedIn: "root",
|
|
393
|
-
},] }
|
|
394
|
-
];
|
|
395
|
-
ViewportService.ctorParameters = () => [
|
|
396
|
-
{ type: WindowRef },
|
|
397
|
-
{ type: ViewportServerSizeService },
|
|
398
|
-
{ type: undefined, decorators: [{ type: Inject, args: [UX_CONFIG,] }] }
|
|
343
|
+
class ViewportService {
|
|
344
|
+
constructor(windowRef, viewportServerSize, config) {
|
|
345
|
+
this.windowRef = windowRef;
|
|
346
|
+
this.viewportServerSize = viewportServerSize;
|
|
347
|
+
this._sizeTypes = generateViewportSizeTypeInfoList(config.viewport.breakpoints);
|
|
348
|
+
this._sizeTypeMap = generateViewportSizeTypeInfoRefs(this._sizeTypes);
|
|
349
|
+
if (windowRef.hasNative) {
|
|
350
|
+
this.resizeSnap$ = fromEvent(window, "resize").pipe(map(() => this.getViewportSize()), share());
|
|
351
|
+
this.resize$ = this.resizeSnap$.pipe(auditTime(config.viewport.resizePollingSpeed), share());
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
this.resizeSnap$ = this.resize$ = of(viewportServerSize.get());
|
|
355
|
+
}
|
|
356
|
+
const size = this.getViewportSize();
|
|
357
|
+
this._sizeTypeSnapshot = getSizeTypeInfo(size.width, this.sizeTypes);
|
|
358
|
+
const sizeFn = (obs$) => obs$.pipe(startWith(size), distinctUntilChanged((a, b) => a.width === b.width && a.height === b.height), shareReplay(1));
|
|
359
|
+
this.sizeSnap$ = sizeFn(this.resizeSnap$);
|
|
360
|
+
this.size$ = sizeFn(this.resize$);
|
|
361
|
+
const sizeTypeFn = (obs$) => obs$.pipe(distinctUntilChanged((a, b) => a.width === b.width), map(x => getSizeTypeInfo(x.width, this.sizeTypes)), distinctUntilChanged(), tap(x => this._sizeTypeSnapshot = x), shareReplay(1));
|
|
362
|
+
this.sizeType$ = sizeTypeFn(this.size$);
|
|
363
|
+
this.sizeTypeSnap$ = sizeTypeFn(this.sizeSnap$);
|
|
364
|
+
}
|
|
365
|
+
/** Viewport size type snapshot of the last value. (Prefer use `sizeType$` observable when possible.) */
|
|
366
|
+
get sizeTypeSnapshot() { return this._sizeTypeSnapshot; }
|
|
367
|
+
/** Size types refs of the generated viewport size type info. */
|
|
368
|
+
get sizeTypeMap() { return this._sizeTypeMap; }
|
|
369
|
+
/** Viewport size types list ordered by type, smallest to largest. */
|
|
370
|
+
get sizeTypes() { return this._sizeTypes; }
|
|
371
|
+
/** Returns the current viewport size */
|
|
372
|
+
getViewportSize() {
|
|
373
|
+
if (!this.windowRef.hasNative) {
|
|
374
|
+
return this.viewportServerSize.get();
|
|
375
|
+
}
|
|
376
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
377
|
+
if (ua.indexOf("safari") !== -1 && ua.indexOf("chrome") === -1) { // safari subtracts the scrollbar width
|
|
378
|
+
return {
|
|
379
|
+
width: this.windowRef.native.document.documentElement.clientWidth,
|
|
380
|
+
height: this.windowRef.native.document.documentElement.clientHeight,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
width: this.windowRef.native.innerWidth,
|
|
385
|
+
height: this.windowRef.native.innerHeight,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
ViewportService.ɵprov = ɵɵdefineInjectable({ factory: function ViewportService_Factory() { return new ViewportService(ɵɵinject(WindowRef), ɵɵinject(ViewportServerSizeService), ɵɵinject(UX_CONFIG)); }, token: ViewportService, providedIn: "root" });
|
|
390
|
+
ViewportService.decorators = [
|
|
391
|
+
{ type: Injectable, args: [{
|
|
392
|
+
providedIn: "root",
|
|
393
|
+
},] }
|
|
394
|
+
];
|
|
395
|
+
ViewportService.ctorParameters = () => [
|
|
396
|
+
{ type: WindowRef },
|
|
397
|
+
{ type: ViewportServerSizeService },
|
|
398
|
+
{ type: undefined, decorators: [{ type: Inject, args: [UX_CONFIG,] }] }
|
|
399
399
|
];
|
|
400
400
|
|
|
401
|
-
/**
|
|
402
|
-
* Utility function to generate rules based on strategies.
|
|
403
|
-
*
|
|
404
|
-
* @param dataConfig Data config to generate rules based on.
|
|
405
|
-
* @param strategy Strategy to use when building rules.
|
|
406
|
-
* @param sizeTypes Available size types ordered by index type. (Can be obtained from `ViewportService`)
|
|
407
|
-
* @param sizeTypeMap Available size type map. (Can be obtained from `ViewportService`)
|
|
408
|
-
* @returns Returns a collection of rules (ordered).
|
|
409
|
-
*/
|
|
410
|
-
function generateViewportRulesRangeFromDataMatcher(dataConfig, strategy, sizeTypes, sizeTypeMap) {
|
|
411
|
-
const ruleBuilderFn = matchStrategyHandlerMap$1[strategy];
|
|
412
|
-
if (!ruleBuilderFn) {
|
|
413
|
-
throw Error(`generateViewportRulesRangeFromDataMatcher: Viewport Data strategy not implemented. Strategy: '${strategy}'`);
|
|
414
|
-
}
|
|
415
|
-
let dataSizes = [];
|
|
416
|
-
for (const key in dataConfig) {
|
|
417
|
-
if (Object.prototype.hasOwnProperty.call(dataConfig, key)) {
|
|
418
|
-
const data = dataConfig[key];
|
|
419
|
-
if (data === undefined) {
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
const size = sizeTypeMap[key];
|
|
423
|
-
if (size) {
|
|
424
|
-
dataSizes.push(size);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
dataSizes = dataSizes.sort(({ type: typeA }, { type: typeB }) => typeA - typeB);
|
|
429
|
-
const rules = [];
|
|
430
|
-
if (dataConfig.default) {
|
|
431
|
-
rules.push({ value: dataConfig.default, min: undefined, max: undefined });
|
|
432
|
-
}
|
|
433
|
-
let prevRule;
|
|
434
|
-
for (let index = 0; index < dataSizes.length; index++) {
|
|
435
|
-
const prevDataSize = dataSizes[index - 1];
|
|
436
|
-
const nextDataSize = dataSizes[index + 1];
|
|
437
|
-
const dataSize = dataSizes[index];
|
|
438
|
-
const prevSize = sizeTypes[dataSize.type - 1];
|
|
439
|
-
// const nextSize = sizeTypes[dataSize.type + 1];
|
|
440
|
-
const data = dataConfig[dataSize.name];
|
|
441
|
-
const rule = {
|
|
442
|
-
value: data,
|
|
443
|
-
min: undefined,
|
|
444
|
-
max: undefined,
|
|
445
|
-
};
|
|
446
|
-
ruleBuilderFn(rule, dataSize, nextDataSize, prevDataSize, prevSize, prevRule, sizeTypes);
|
|
447
|
-
prevRule = rule;
|
|
448
|
-
rules.push(rule);
|
|
449
|
-
}
|
|
450
|
-
return rules;
|
|
451
|
-
}
|
|
452
|
-
const matchStrategyHandlerMap$1 = {
|
|
453
|
-
[ViewportDataMatchStrategy.exact]: (rule, dataSize, _nextDataSize, _prevDataSize, prevSize) => {
|
|
454
|
-
rule.max = dataSize.widthThreshold;
|
|
455
|
-
if (prevSize) {
|
|
456
|
-
rule.min = prevSize.widthThreshold + 1;
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
[ViewportDataMatchStrategy.smaller]: (rule, dataSize, nextDataSize, _prevDataSize, prevSize) => {
|
|
460
|
-
if (nextDataSize) {
|
|
461
|
-
rule.max = dataSize.widthThreshold;
|
|
462
|
-
}
|
|
463
|
-
if (prevSize) {
|
|
464
|
-
rule.min = prevSize.widthThreshold + 1;
|
|
465
|
-
}
|
|
466
|
-
},
|
|
467
|
-
[ViewportDataMatchStrategy.larger]: (rule, dataSize, _nextDataSize, prevDataSize) => {
|
|
468
|
-
if (dataSize) {
|
|
469
|
-
rule.max = dataSize.widthThreshold;
|
|
470
|
-
}
|
|
471
|
-
if (prevDataSize) {
|
|
472
|
-
rule.min = prevDataSize.widthThreshold + 1;
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
[ViewportDataMatchStrategy.closestSmallerFirst]: (rule, dataSize, nextDataSize, _prevDataSize, _prevSize, prevRule, sizeTypes) => {
|
|
476
|
-
if (nextDataSize) {
|
|
477
|
-
rule.max = calculateClosestWidthThreshold(nextDataSize, dataSize, sizeTypes, true);
|
|
478
|
-
}
|
|
479
|
-
if (prevRule === null || prevRule === void 0 ? void 0 : prevRule.max) {
|
|
480
|
-
rule.min = prevRule.max + 1;
|
|
481
|
-
}
|
|
482
|
-
},
|
|
483
|
-
[ViewportDataMatchStrategy.closestLargerFirst]: (rule, dataSize, nextDataSize, _prevDataSize, _prevSize, prevRule, sizeTypes) => {
|
|
484
|
-
if (nextDataSize) {
|
|
485
|
-
rule.max = calculateClosestWidthThreshold(nextDataSize, dataSize, sizeTypes, false);
|
|
486
|
-
}
|
|
487
|
-
if (prevRule === null || prevRule === void 0 ? void 0 : prevRule.max) {
|
|
488
|
-
rule.min = prevRule.max + 1;
|
|
489
|
-
}
|
|
490
|
-
},
|
|
491
|
-
};
|
|
492
|
-
function calculateClosestWidthThreshold(nextDataSize, dataSize, sizeTypes, isSmallerPreferred) {
|
|
493
|
-
const fn = isSmallerPreferred ? Math.ceil : Math.floor;
|
|
494
|
-
// get closest between curr and next
|
|
495
|
-
const diffIndex = fn((nextDataSize.type - dataSize.type - 1) / 2);
|
|
496
|
-
const diffNextSize = sizeTypes[dataSize.type + diffIndex];
|
|
497
|
-
return (diffNextSize || dataSize).widthThreshold;
|
|
401
|
+
/**
|
|
402
|
+
* Utility function to generate rules based on strategies.
|
|
403
|
+
*
|
|
404
|
+
* @param dataConfig Data config to generate rules based on.
|
|
405
|
+
* @param strategy Strategy to use when building rules.
|
|
406
|
+
* @param sizeTypes Available size types ordered by index type. (Can be obtained from `ViewportService`)
|
|
407
|
+
* @param sizeTypeMap Available size type map. (Can be obtained from `ViewportService`)
|
|
408
|
+
* @returns Returns a collection of rules (ordered).
|
|
409
|
+
*/
|
|
410
|
+
function generateViewportRulesRangeFromDataMatcher(dataConfig, strategy, sizeTypes, sizeTypeMap) {
|
|
411
|
+
const ruleBuilderFn = matchStrategyHandlerMap$1[strategy];
|
|
412
|
+
if (!ruleBuilderFn) {
|
|
413
|
+
throw Error(`generateViewportRulesRangeFromDataMatcher: Viewport Data strategy not implemented. Strategy: '${strategy}'`);
|
|
414
|
+
}
|
|
415
|
+
let dataSizes = [];
|
|
416
|
+
for (const key in dataConfig) {
|
|
417
|
+
if (Object.prototype.hasOwnProperty.call(dataConfig, key)) {
|
|
418
|
+
const data = dataConfig[key];
|
|
419
|
+
if (data === undefined) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const size = sizeTypeMap[key];
|
|
423
|
+
if (size) {
|
|
424
|
+
dataSizes.push(size);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
dataSizes = dataSizes.sort(({ type: typeA }, { type: typeB }) => typeA - typeB);
|
|
429
|
+
const rules = [];
|
|
430
|
+
if (dataConfig.default) {
|
|
431
|
+
rules.push({ value: dataConfig.default, min: undefined, max: undefined });
|
|
432
|
+
}
|
|
433
|
+
let prevRule;
|
|
434
|
+
for (let index = 0; index < dataSizes.length; index++) {
|
|
435
|
+
const prevDataSize = dataSizes[index - 1];
|
|
436
|
+
const nextDataSize = dataSizes[index + 1];
|
|
437
|
+
const dataSize = dataSizes[index];
|
|
438
|
+
const prevSize = sizeTypes[dataSize.type - 1];
|
|
439
|
+
// const nextSize = sizeTypes[dataSize.type + 1];
|
|
440
|
+
const data = dataConfig[dataSize.name];
|
|
441
|
+
const rule = {
|
|
442
|
+
value: data,
|
|
443
|
+
min: undefined,
|
|
444
|
+
max: undefined,
|
|
445
|
+
};
|
|
446
|
+
ruleBuilderFn(rule, dataSize, nextDataSize, prevDataSize, prevSize, prevRule, sizeTypes);
|
|
447
|
+
prevRule = rule;
|
|
448
|
+
rules.push(rule);
|
|
449
|
+
}
|
|
450
|
+
return rules;
|
|
451
|
+
}
|
|
452
|
+
const matchStrategyHandlerMap$1 = {
|
|
453
|
+
[ViewportDataMatchStrategy.exact]: (rule, dataSize, _nextDataSize, _prevDataSize, prevSize) => {
|
|
454
|
+
rule.max = dataSize.widthThreshold;
|
|
455
|
+
if (prevSize) {
|
|
456
|
+
rule.min = prevSize.widthThreshold + 1;
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
[ViewportDataMatchStrategy.smaller]: (rule, dataSize, nextDataSize, _prevDataSize, prevSize) => {
|
|
460
|
+
if (nextDataSize) {
|
|
461
|
+
rule.max = dataSize.widthThreshold;
|
|
462
|
+
}
|
|
463
|
+
if (prevSize) {
|
|
464
|
+
rule.min = prevSize.widthThreshold + 1;
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
[ViewportDataMatchStrategy.larger]: (rule, dataSize, _nextDataSize, prevDataSize) => {
|
|
468
|
+
if (dataSize) {
|
|
469
|
+
rule.max = dataSize.widthThreshold;
|
|
470
|
+
}
|
|
471
|
+
if (prevDataSize) {
|
|
472
|
+
rule.min = prevDataSize.widthThreshold + 1;
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
[ViewportDataMatchStrategy.closestSmallerFirst]: (rule, dataSize, nextDataSize, _prevDataSize, _prevSize, prevRule, sizeTypes) => {
|
|
476
|
+
if (nextDataSize) {
|
|
477
|
+
rule.max = calculateClosestWidthThreshold(nextDataSize, dataSize, sizeTypes, true);
|
|
478
|
+
}
|
|
479
|
+
if (prevRule === null || prevRule === void 0 ? void 0 : prevRule.max) {
|
|
480
|
+
rule.min = prevRule.max + 1;
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
[ViewportDataMatchStrategy.closestLargerFirst]: (rule, dataSize, nextDataSize, _prevDataSize, _prevSize, prevRule, sizeTypes) => {
|
|
484
|
+
if (nextDataSize) {
|
|
485
|
+
rule.max = calculateClosestWidthThreshold(nextDataSize, dataSize, sizeTypes, false);
|
|
486
|
+
}
|
|
487
|
+
if (prevRule === null || prevRule === void 0 ? void 0 : prevRule.max) {
|
|
488
|
+
rule.min = prevRule.max + 1;
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
function calculateClosestWidthThreshold(nextDataSize, dataSize, sizeTypes, isSmallerPreferred) {
|
|
493
|
+
const fn = isSmallerPreferred ? Math.ceil : Math.floor;
|
|
494
|
+
// get closest between curr and next
|
|
495
|
+
const diffIndex = fn((nextDataSize.type - dataSize.type - 1) / 2);
|
|
496
|
+
const diffNextSize = sizeTypes[dataSize.type + diffIndex];
|
|
497
|
+
return (diffNextSize || dataSize).widthThreshold;
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
-
class ViewportDataService {
|
|
501
|
-
constructor(viewport, config) {
|
|
502
|
-
this.viewport = viewport;
|
|
503
|
-
this.config = config;
|
|
504
|
-
}
|
|
505
|
-
/** Get data for match. */
|
|
506
|
-
get(dataConfig, strategy = this.config.viewport.defaultDataMatchStrategy, sizeType = this.viewport.sizeTypeSnapshot) {
|
|
507
|
-
return matchViewportData(dataConfig, sizeType, strategy, this.viewport.sizeTypes, this.viewport.sizeTypeMap);
|
|
508
|
-
}
|
|
509
|
-
/** Get data for match as observable. */
|
|
510
|
-
get$(dataConfig, strategy, throttle = true) {
|
|
511
|
-
return (throttle ? this.viewport.sizeType$ : this.viewport.sizeTypeSnap$).pipe(map(sizeType => this.get(dataConfig, strategy, sizeType)), distinctUntilChanged());
|
|
512
|
-
}
|
|
513
|
-
/** Generate rules based on strategies for data. */
|
|
514
|
-
generateRules(dataConfig, strategy = this.config.viewport.defaultDataMatchStrategy) {
|
|
515
|
-
return generateViewportRulesRangeFromDataMatcher(dataConfig, strategy, this.viewport.sizeTypes, this.viewport.sizeTypeMap);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
ViewportDataService.ɵprov = ɵɵdefineInjectable({ factory: function ViewportDataService_Factory() { return new ViewportDataService(ɵɵinject(ViewportService), ɵɵinject(UX_CONFIG)); }, token: ViewportDataService, providedIn: "root" });
|
|
519
|
-
ViewportDataService.decorators = [
|
|
520
|
-
{ type: Injectable, args: [{
|
|
521
|
-
providedIn: "root",
|
|
522
|
-
},] }
|
|
523
|
-
];
|
|
524
|
-
ViewportDataService.ctorParameters = () => [
|
|
525
|
-
{ type: ViewportService },
|
|
526
|
-
{ type: undefined, decorators: [{ type: Inject, args: [UX_CONFIG,] }] }
|
|
500
|
+
class ViewportDataService {
|
|
501
|
+
constructor(viewport, config) {
|
|
502
|
+
this.viewport = viewport;
|
|
503
|
+
this.config = config;
|
|
504
|
+
}
|
|
505
|
+
/** Get data for match. */
|
|
506
|
+
get(dataConfig, strategy = this.config.viewport.defaultDataMatchStrategy, sizeType = this.viewport.sizeTypeSnapshot) {
|
|
507
|
+
return matchViewportData(dataConfig, sizeType, strategy, this.viewport.sizeTypes, this.viewport.sizeTypeMap);
|
|
508
|
+
}
|
|
509
|
+
/** Get data for match as observable. */
|
|
510
|
+
get$(dataConfig, strategy, throttle = true) {
|
|
511
|
+
return (throttle ? this.viewport.sizeType$ : this.viewport.sizeTypeSnap$).pipe(map(sizeType => this.get(dataConfig, strategy, sizeType)), distinctUntilChanged());
|
|
512
|
+
}
|
|
513
|
+
/** Generate rules based on strategies for data. */
|
|
514
|
+
generateRules(dataConfig, strategy = this.config.viewport.defaultDataMatchStrategy) {
|
|
515
|
+
return generateViewportRulesRangeFromDataMatcher(dataConfig, strategy, this.viewport.sizeTypes, this.viewport.sizeTypeMap);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
ViewportDataService.ɵprov = ɵɵdefineInjectable({ factory: function ViewportDataService_Factory() { return new ViewportDataService(ɵɵinject(ViewportService), ɵɵinject(UX_CONFIG)); }, token: ViewportDataService, providedIn: "root" });
|
|
519
|
+
ViewportDataService.decorators = [
|
|
520
|
+
{ type: Injectable, args: [{
|
|
521
|
+
providedIn: "root",
|
|
522
|
+
},] }
|
|
523
|
+
];
|
|
524
|
+
ViewportDataService.ctorParameters = () => [
|
|
525
|
+
{ type: ViewportService },
|
|
526
|
+
{ type: undefined, decorators: [{ type: Inject, args: [UX_CONFIG,] }] }
|
|
527
527
|
];
|
|
528
528
|
|
|
529
|
-
/* eslint-disable @angular-eslint/no-pipe-impure */
|
|
530
|
-
class ViewportDataPipe {
|
|
531
|
-
constructor(viewportData, cdr) {
|
|
532
|
-
this.viewportData = viewportData;
|
|
533
|
-
this.cdr = cdr;
|
|
534
|
-
this.markForTransform = true;
|
|
535
|
-
this.data$$ = Subscription.EMPTY;
|
|
536
|
-
}
|
|
537
|
-
transform(data, strategy) {
|
|
538
|
-
if (!this.markForTransform && data === this.data && strategy === this.strategy) {
|
|
539
|
-
return this.value;
|
|
540
|
-
}
|
|
541
|
-
this.data = data;
|
|
542
|
-
this.strategy = strategy;
|
|
543
|
-
this.data$$.unsubscribe();
|
|
544
|
-
this.data$$ = this.viewportData.get$(data, ViewportDataMatchStrategy[strategy]).pipe(tap(value => {
|
|
545
|
-
this.markForTransform = true;
|
|
546
|
-
this.value = value;
|
|
547
|
-
this.cdr.markForCheck();
|
|
548
|
-
})).subscribe();
|
|
549
|
-
this.markForTransform = false;
|
|
550
|
-
return this.value;
|
|
551
|
-
}
|
|
552
|
-
ngOnDestroy() {
|
|
553
|
-
this.data$$.unsubscribe();
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
ViewportDataPipe.decorators = [
|
|
557
|
-
{ type: Pipe, args: [{
|
|
558
|
-
name: "ssvViewportData",
|
|
559
|
-
pure: false
|
|
560
|
-
},] }
|
|
561
|
-
];
|
|
562
|
-
ViewportDataPipe.ctorParameters = () => [
|
|
563
|
-
{ type: ViewportDataService },
|
|
564
|
-
{ type: ChangeDetectorRef }
|
|
529
|
+
/* eslint-disable @angular-eslint/no-pipe-impure */
|
|
530
|
+
class ViewportDataPipe {
|
|
531
|
+
constructor(viewportData, cdr) {
|
|
532
|
+
this.viewportData = viewportData;
|
|
533
|
+
this.cdr = cdr;
|
|
534
|
+
this.markForTransform = true;
|
|
535
|
+
this.data$$ = Subscription.EMPTY;
|
|
536
|
+
}
|
|
537
|
+
transform(data, strategy) {
|
|
538
|
+
if (!this.markForTransform && data === this.data && strategy === this.strategy) {
|
|
539
|
+
return this.value;
|
|
540
|
+
}
|
|
541
|
+
this.data = data;
|
|
542
|
+
this.strategy = strategy;
|
|
543
|
+
this.data$$.unsubscribe();
|
|
544
|
+
this.data$$ = this.viewportData.get$(data, ViewportDataMatchStrategy[strategy]).pipe(tap(value => {
|
|
545
|
+
this.markForTransform = true;
|
|
546
|
+
this.value = value;
|
|
547
|
+
this.cdr.markForCheck();
|
|
548
|
+
})).subscribe();
|
|
549
|
+
this.markForTransform = false;
|
|
550
|
+
return this.value;
|
|
551
|
+
}
|
|
552
|
+
ngOnDestroy() {
|
|
553
|
+
this.data$$.unsubscribe();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
ViewportDataPipe.decorators = [
|
|
557
|
+
{ type: Pipe, args: [{
|
|
558
|
+
name: "ssvViewportData",
|
|
559
|
+
pure: false
|
|
560
|
+
},] }
|
|
561
|
+
];
|
|
562
|
+
ViewportDataPipe.ctorParameters = () => [
|
|
563
|
+
{ type: ViewportDataService },
|
|
564
|
+
{ type: ChangeDetectorRef }
|
|
565
565
|
];
|
|
566
566
|
|
|
567
|
-
const NAME_CAMEL = "ssvViewportMatcherVar";
|
|
568
|
-
class SsvViewportMatcherVarContext {
|
|
569
|
-
constructor($implicit = false) {
|
|
570
|
-
this.$implicit = $implicit;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
class SsvViewportMatcherVarDirective {
|
|
574
|
-
constructor(viewport, viewContainer, templateRef) {
|
|
575
|
-
this.viewport = viewport;
|
|
576
|
-
this.viewContainer = viewContainer;
|
|
577
|
-
this.templateRef = templateRef;
|
|
578
|
-
this._matchConditions = {};
|
|
579
|
-
this._context = new SsvViewportMatcherVarContext();
|
|
580
|
-
this._destroy$ = new Subject();
|
|
581
|
-
this._update$ = new ReplaySubject(1);
|
|
582
|
-
}
|
|
583
|
-
set condition(value) {
|
|
584
|
-
if (isViewportSizeMatcherExpression(value)) {
|
|
585
|
-
this._matchConditions.expression = value;
|
|
586
|
-
}
|
|
587
|
-
else if (isViewportSizeMatcherTupleExpression(value)) {
|
|
588
|
-
const [op, size] = value;
|
|
589
|
-
this._matchConditions.expression = {
|
|
590
|
-
operation: op,
|
|
591
|
-
size
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
else {
|
|
595
|
-
this._matchConditions.sizeType = value;
|
|
596
|
-
}
|
|
597
|
-
this._update$.next();
|
|
598
|
-
}
|
|
599
|
-
ngOnInit() {
|
|
600
|
-
this.updateView();
|
|
601
|
-
combineLatest([this.viewport.sizeType$, this._update$]).pipe(map(([sizeType]) => isViewportConditionMatch(sizeType, this._matchConditions, this.viewport.sizeTypeMap)), tap(x => this._context.$implicit = x), tap(() => this._viewRef.markForCheck()), takeUntil(this._destroy$)).subscribe();
|
|
602
|
-
}
|
|
603
|
-
ngOnDestroy() {
|
|
604
|
-
this._destroy$.next();
|
|
605
|
-
this._destroy$.complete();
|
|
606
|
-
}
|
|
607
|
-
updateView() {
|
|
608
|
-
this.viewContainer.clear();
|
|
609
|
-
this._viewRef = this.viewContainer.createEmbeddedView(this.templateRef, this._context);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
SsvViewportMatcherVarDirective.decorators = [
|
|
613
|
-
{ type: Directive, args: [{
|
|
614
|
-
selector: `[${NAME_CAMEL}]`,
|
|
615
|
-
},] }
|
|
616
|
-
];
|
|
617
|
-
SsvViewportMatcherVarDirective.ctorParameters = () => [
|
|
618
|
-
{ type: ViewportService },
|
|
619
|
-
{ type: ViewContainerRef },
|
|
620
|
-
{ type: TemplateRef }
|
|
621
|
-
];
|
|
622
|
-
SsvViewportMatcherVarDirective.propDecorators = {
|
|
623
|
-
condition: [{ type: Input, args: [`${NAME_CAMEL}When`,] }]
|
|
567
|
+
const NAME_CAMEL = "ssvViewportMatcherVar";
|
|
568
|
+
class SsvViewportMatcherVarContext {
|
|
569
|
+
constructor($implicit = false) {
|
|
570
|
+
this.$implicit = $implicit;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
class SsvViewportMatcherVarDirective {
|
|
574
|
+
constructor(viewport, viewContainer, templateRef) {
|
|
575
|
+
this.viewport = viewport;
|
|
576
|
+
this.viewContainer = viewContainer;
|
|
577
|
+
this.templateRef = templateRef;
|
|
578
|
+
this._matchConditions = {};
|
|
579
|
+
this._context = new SsvViewportMatcherVarContext();
|
|
580
|
+
this._destroy$ = new Subject();
|
|
581
|
+
this._update$ = new ReplaySubject(1);
|
|
582
|
+
}
|
|
583
|
+
set condition(value) {
|
|
584
|
+
if (isViewportSizeMatcherExpression(value)) {
|
|
585
|
+
this._matchConditions.expression = value;
|
|
586
|
+
}
|
|
587
|
+
else if (isViewportSizeMatcherTupleExpression(value)) {
|
|
588
|
+
const [op, size] = value;
|
|
589
|
+
this._matchConditions.expression = {
|
|
590
|
+
operation: op,
|
|
591
|
+
size
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
this._matchConditions.sizeType = value;
|
|
596
|
+
}
|
|
597
|
+
this._update$.next();
|
|
598
|
+
}
|
|
599
|
+
ngOnInit() {
|
|
600
|
+
this.updateView();
|
|
601
|
+
combineLatest([this.viewport.sizeType$, this._update$]).pipe(map(([sizeType]) => isViewportConditionMatch(sizeType, this._matchConditions, this.viewport.sizeTypeMap)), tap(x => this._context.$implicit = x), tap(() => this._viewRef.markForCheck()), takeUntil(this._destroy$)).subscribe();
|
|
602
|
+
}
|
|
603
|
+
ngOnDestroy() {
|
|
604
|
+
this._destroy$.next();
|
|
605
|
+
this._destroy$.complete();
|
|
606
|
+
}
|
|
607
|
+
updateView() {
|
|
608
|
+
this.viewContainer.clear();
|
|
609
|
+
this._viewRef = this.viewContainer.createEmbeddedView(this.templateRef, this._context);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
SsvViewportMatcherVarDirective.decorators = [
|
|
613
|
+
{ type: Directive, args: [{
|
|
614
|
+
selector: `[${NAME_CAMEL}]`,
|
|
615
|
+
},] }
|
|
616
|
+
];
|
|
617
|
+
SsvViewportMatcherVarDirective.ctorParameters = () => [
|
|
618
|
+
{ type: ViewportService },
|
|
619
|
+
{ type: ViewContainerRef },
|
|
620
|
+
{ type: TemplateRef }
|
|
621
|
+
];
|
|
622
|
+
SsvViewportMatcherVarDirective.propDecorators = {
|
|
623
|
+
condition: [{ type: Input, args: [`${NAME_CAMEL}When`,] }]
|
|
624
624
|
};
|
|
625
625
|
|
|
626
|
-
class SsvViewportMatcherContext {
|
|
627
|
-
constructor() {
|
|
628
|
-
this.sizeType = null;
|
|
629
|
-
this.sizeTypeExclude = null;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
class SsvViewportMatcherDirective {
|
|
633
|
-
constructor(viewport, renderer, viewContainer, cdr, templateRef) {
|
|
634
|
-
this.viewport = viewport;
|
|
635
|
-
this.renderer = renderer;
|
|
636
|
-
this.viewContainer = viewContainer;
|
|
637
|
-
this.cdr = cdr;
|
|
638
|
-
this._context = new SsvViewportMatcherContext();
|
|
639
|
-
this._thenTemplateRef = null;
|
|
640
|
-
this._elseTemplateRef = null;
|
|
641
|
-
this._thenViewRef = null;
|
|
642
|
-
this._elseViewRef = null;
|
|
643
|
-
this.sizeType$$ = Subscription.EMPTY;
|
|
644
|
-
this.cssClass$$ = Subscription.EMPTY;
|
|
645
|
-
this._update$ = new Subject();
|
|
646
|
-
this._thenTemplateRef = templateRef;
|
|
647
|
-
}
|
|
648
|
-
set ssvViewportMatcher(value) {
|
|
649
|
-
if (isViewportSizeMatcherExpression(value)) {
|
|
650
|
-
this._context.expression = value;
|
|
651
|
-
}
|
|
652
|
-
else if (isViewportSizeMatcherTupleExpression(value)) {
|
|
653
|
-
const [op, size] = value;
|
|
654
|
-
this._context.expression = {
|
|
655
|
-
operation: op,
|
|
656
|
-
size
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
this._context.sizeType = value;
|
|
661
|
-
}
|
|
662
|
-
if (this.sizeInfo) {
|
|
663
|
-
this._update$.next(this._context);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
set ssvViewportMatcherExclude(value) {
|
|
667
|
-
this._context.sizeTypeExclude = value;
|
|
668
|
-
if (this.sizeInfo) {
|
|
669
|
-
this._update$.next(this._context);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
set ssvViewportMatcherElse(templateRef) {
|
|
673
|
-
this._elseTemplateRef = templateRef;
|
|
674
|
-
this._elseViewRef = null; // clear previous view if any.
|
|
675
|
-
if (this.sizeInfo) {
|
|
676
|
-
this._update$.next(this._context);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
ngOnInit() {
|
|
680
|
-
// console.log("ssvViewportMatcher init");
|
|
681
|
-
this._update$
|
|
682
|
-
.pipe(
|
|
683
|
-
// tap(x => console.log(">>> ssvViewportMatcher - update triggered", x)),
|
|
684
|
-
filter(() => !!this.sizeInfo),
|
|
685
|
-
// tap(x => console.log(">>> ssvViewportMatcher - updating...", x)),
|
|
686
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
687
|
-
tap(() => this._updateView(this.sizeInfo)), tap(() => this.cdr.markForCheck()))
|
|
688
|
-
.subscribe();
|
|
689
|
-
this.sizeType$$ = this.viewport.sizeType$
|
|
690
|
-
.pipe(
|
|
691
|
-
// tap(x => console.log("ssvViewportMatcher - sizeType changed", x)),
|
|
692
|
-
tap(x => this.sizeInfo = x), tap(() => this._update$.next(this._context)))
|
|
693
|
-
.subscribe();
|
|
694
|
-
this.cssClass$$ = this.viewport.sizeType$
|
|
695
|
-
.pipe(startWith(undefined), filter(() => !!(this._thenViewRef || this._elseViewRef)), pairwise(), tap(([prev, curr]) => {
|
|
696
|
-
var _a;
|
|
697
|
-
const el = this._thenViewRef
|
|
698
|
-
? this._thenViewRef.rootNodes[0]
|
|
699
|
-
: (_a = this._elseViewRef) === null || _a === void 0 ? void 0 : _a.rootNodes[0];
|
|
700
|
-
if (!el.classList) {
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
if (prev) {
|
|
704
|
-
this.renderer.removeClass(el, `ssv-vp-size--${prev.name}`);
|
|
705
|
-
}
|
|
706
|
-
this.renderer.addClass(el, `ssv-vp-size--${curr === null || curr === void 0 ? void 0 : curr.name}`);
|
|
707
|
-
}))
|
|
708
|
-
.subscribe();
|
|
709
|
-
}
|
|
710
|
-
ngOnDestroy() {
|
|
711
|
-
this.cssClass$$.unsubscribe();
|
|
712
|
-
this.sizeType$$.unsubscribe();
|
|
713
|
-
this._update$.complete();
|
|
714
|
-
}
|
|
715
|
-
_updateView(sizeInfo) {
|
|
716
|
-
if (isViewportConditionMatch(sizeInfo, this._context, this.viewport.sizeTypeMap)) {
|
|
717
|
-
if (!this._thenViewRef) {
|
|
718
|
-
this.viewContainer.clear();
|
|
719
|
-
this._elseViewRef = null;
|
|
720
|
-
if (this._thenTemplateRef) {
|
|
721
|
-
this._thenViewRef = this.viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
if (!this._elseViewRef) {
|
|
727
|
-
this.viewContainer.clear();
|
|
728
|
-
this._thenViewRef = null;
|
|
729
|
-
if (this._elseTemplateRef) {
|
|
730
|
-
this._elseViewRef = this.viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
SsvViewportMatcherDirective.decorators = [
|
|
737
|
-
{ type: Directive, args: [{
|
|
738
|
-
selector: "[ssvViewportMatcher]",
|
|
739
|
-
exportAs: "ssvViewportMatcher",
|
|
740
|
-
},] }
|
|
741
|
-
];
|
|
742
|
-
SsvViewportMatcherDirective.ctorParameters = () => [
|
|
743
|
-
{ type: ViewportService },
|
|
744
|
-
{ type: Renderer2 },
|
|
745
|
-
{ type: ViewContainerRef },
|
|
746
|
-
{ type: ChangeDetectorRef },
|
|
747
|
-
{ type: TemplateRef }
|
|
748
|
-
];
|
|
749
|
-
SsvViewportMatcherDirective.propDecorators = {
|
|
750
|
-
ssvViewportMatcher: [{ type: Input }],
|
|
751
|
-
ssvViewportMatcherExclude: [{ type: Input }],
|
|
752
|
-
ssvViewportMatcherElse: [{ type: Input }]
|
|
626
|
+
class SsvViewportMatcherContext {
|
|
627
|
+
constructor() {
|
|
628
|
+
this.sizeType = null;
|
|
629
|
+
this.sizeTypeExclude = null;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
class SsvViewportMatcherDirective {
|
|
633
|
+
constructor(viewport, renderer, viewContainer, cdr, templateRef) {
|
|
634
|
+
this.viewport = viewport;
|
|
635
|
+
this.renderer = renderer;
|
|
636
|
+
this.viewContainer = viewContainer;
|
|
637
|
+
this.cdr = cdr;
|
|
638
|
+
this._context = new SsvViewportMatcherContext();
|
|
639
|
+
this._thenTemplateRef = null;
|
|
640
|
+
this._elseTemplateRef = null;
|
|
641
|
+
this._thenViewRef = null;
|
|
642
|
+
this._elseViewRef = null;
|
|
643
|
+
this.sizeType$$ = Subscription.EMPTY;
|
|
644
|
+
this.cssClass$$ = Subscription.EMPTY;
|
|
645
|
+
this._update$ = new Subject();
|
|
646
|
+
this._thenTemplateRef = templateRef;
|
|
647
|
+
}
|
|
648
|
+
set ssvViewportMatcher(value) {
|
|
649
|
+
if (isViewportSizeMatcherExpression(value)) {
|
|
650
|
+
this._context.expression = value;
|
|
651
|
+
}
|
|
652
|
+
else if (isViewportSizeMatcherTupleExpression(value)) {
|
|
653
|
+
const [op, size] = value;
|
|
654
|
+
this._context.expression = {
|
|
655
|
+
operation: op,
|
|
656
|
+
size
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
this._context.sizeType = value;
|
|
661
|
+
}
|
|
662
|
+
if (this.sizeInfo) {
|
|
663
|
+
this._update$.next(this._context);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
set ssvViewportMatcherExclude(value) {
|
|
667
|
+
this._context.sizeTypeExclude = value;
|
|
668
|
+
if (this.sizeInfo) {
|
|
669
|
+
this._update$.next(this._context);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
set ssvViewportMatcherElse(templateRef) {
|
|
673
|
+
this._elseTemplateRef = templateRef;
|
|
674
|
+
this._elseViewRef = null; // clear previous view if any.
|
|
675
|
+
if (this.sizeInfo) {
|
|
676
|
+
this._update$.next(this._context);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
ngOnInit() {
|
|
680
|
+
// console.log("ssvViewportMatcher init");
|
|
681
|
+
this._update$
|
|
682
|
+
.pipe(
|
|
683
|
+
// tap(x => console.log(">>> ssvViewportMatcher - update triggered", x)),
|
|
684
|
+
filter(() => !!this.sizeInfo),
|
|
685
|
+
// tap(x => console.log(">>> ssvViewportMatcher - updating...", x)),
|
|
686
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
687
|
+
tap(() => this._updateView(this.sizeInfo)), tap(() => this.cdr.markForCheck()))
|
|
688
|
+
.subscribe();
|
|
689
|
+
this.sizeType$$ = this.viewport.sizeType$
|
|
690
|
+
.pipe(
|
|
691
|
+
// tap(x => console.log("ssvViewportMatcher - sizeType changed", x)),
|
|
692
|
+
tap(x => this.sizeInfo = x), tap(() => this._update$.next(this._context)))
|
|
693
|
+
.subscribe();
|
|
694
|
+
this.cssClass$$ = this.viewport.sizeType$
|
|
695
|
+
.pipe(startWith(undefined), filter(() => !!(this._thenViewRef || this._elseViewRef)), pairwise(), tap(([prev, curr]) => {
|
|
696
|
+
var _a;
|
|
697
|
+
const el = this._thenViewRef
|
|
698
|
+
? this._thenViewRef.rootNodes[0]
|
|
699
|
+
: (_a = this._elseViewRef) === null || _a === void 0 ? void 0 : _a.rootNodes[0];
|
|
700
|
+
if (!el.classList) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
if (prev) {
|
|
704
|
+
this.renderer.removeClass(el, `ssv-vp-size--${prev.name}`);
|
|
705
|
+
}
|
|
706
|
+
this.renderer.addClass(el, `ssv-vp-size--${curr === null || curr === void 0 ? void 0 : curr.name}`);
|
|
707
|
+
}))
|
|
708
|
+
.subscribe();
|
|
709
|
+
}
|
|
710
|
+
ngOnDestroy() {
|
|
711
|
+
this.cssClass$$.unsubscribe();
|
|
712
|
+
this.sizeType$$.unsubscribe();
|
|
713
|
+
this._update$.complete();
|
|
714
|
+
}
|
|
715
|
+
_updateView(sizeInfo) {
|
|
716
|
+
if (isViewportConditionMatch(sizeInfo, this._context, this.viewport.sizeTypeMap)) {
|
|
717
|
+
if (!this._thenViewRef) {
|
|
718
|
+
this.viewContainer.clear();
|
|
719
|
+
this._elseViewRef = null;
|
|
720
|
+
if (this._thenTemplateRef) {
|
|
721
|
+
this._thenViewRef = this.viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
if (!this._elseViewRef) {
|
|
727
|
+
this.viewContainer.clear();
|
|
728
|
+
this._thenViewRef = null;
|
|
729
|
+
if (this._elseTemplateRef) {
|
|
730
|
+
this._elseViewRef = this.viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
SsvViewportMatcherDirective.decorators = [
|
|
737
|
+
{ type: Directive, args: [{
|
|
738
|
+
selector: "[ssvViewportMatcher]",
|
|
739
|
+
exportAs: "ssvViewportMatcher",
|
|
740
|
+
},] }
|
|
741
|
+
];
|
|
742
|
+
SsvViewportMatcherDirective.ctorParameters = () => [
|
|
743
|
+
{ type: ViewportService },
|
|
744
|
+
{ type: Renderer2 },
|
|
745
|
+
{ type: ViewContainerRef },
|
|
746
|
+
{ type: ChangeDetectorRef },
|
|
747
|
+
{ type: TemplateRef }
|
|
748
|
+
];
|
|
749
|
+
SsvViewportMatcherDirective.propDecorators = {
|
|
750
|
+
ssvViewportMatcher: [{ type: Input }],
|
|
751
|
+
ssvViewportMatcherExclude: [{ type: Input }],
|
|
752
|
+
ssvViewportMatcherElse: [{ type: Input }]
|
|
753
753
|
};
|
|
754
754
|
|
|
755
|
-
/** @internal */
|
|
756
|
-
const MODULE_CONFIG_DATA = new InjectionToken("@ssv/ngx.ux/configData");
|
|
757
|
-
const components = [
|
|
758
|
-
SsvViewportMatcherDirective,
|
|
759
|
-
SsvViewportMatcherVarDirective,
|
|
760
|
-
ViewportDataPipe,
|
|
761
|
-
];
|
|
762
|
-
// todo: create module for Viewport
|
|
763
|
-
class SsvUxModule {
|
|
764
|
-
static forRoot(config) {
|
|
765
|
-
return {
|
|
766
|
-
ngModule: SsvUxModule,
|
|
767
|
-
providers: [
|
|
768
|
-
{ provide: MODULE_CONFIG_DATA, useValue: config },
|
|
769
|
-
],
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
SsvUxModule.decorators = [
|
|
774
|
-
{ type: NgModule, args: [{
|
|
775
|
-
declarations: [components],
|
|
776
|
-
providers: [
|
|
777
|
-
{ provide: UX_CONFIG, useFactory: _moduleConfigFactory, deps: [[MODULE_CONFIG_DATA, new Optional()]] },
|
|
778
|
-
{ provide: WINDOW, useFactory: _window },
|
|
779
|
-
],
|
|
780
|
-
exports: [...components],
|
|
781
|
-
},] }
|
|
782
|
-
];
|
|
783
|
-
/** @internal */
|
|
784
|
-
function _moduleConfigFactory(config) {
|
|
785
|
-
if (!config) {
|
|
786
|
-
return UX_DEFAULT_CONFIG;
|
|
787
|
-
}
|
|
788
|
-
const uxOptions = typeof config === "function" ? config() : config;
|
|
789
|
-
const viewport = Object.assign(Object.assign({}, UX_DEFAULT_CONFIG.viewport), uxOptions.viewport); // breakpoints shouldn't be merged
|
|
790
|
-
return { viewport };
|
|
791
|
-
}
|
|
792
|
-
/** @internal */
|
|
793
|
-
function _window() {
|
|
794
|
-
if (typeof window !== "undefined") {
|
|
795
|
-
return window;
|
|
796
|
-
}
|
|
797
|
-
return {};
|
|
755
|
+
/** @internal */
|
|
756
|
+
const MODULE_CONFIG_DATA = new InjectionToken("@ssv/ngx.ux/configData");
|
|
757
|
+
const components = [
|
|
758
|
+
SsvViewportMatcherDirective,
|
|
759
|
+
SsvViewportMatcherVarDirective,
|
|
760
|
+
ViewportDataPipe,
|
|
761
|
+
];
|
|
762
|
+
// todo: create module for Viewport
|
|
763
|
+
class SsvUxModule {
|
|
764
|
+
static forRoot(config) {
|
|
765
|
+
return {
|
|
766
|
+
ngModule: SsvUxModule,
|
|
767
|
+
providers: [
|
|
768
|
+
{ provide: MODULE_CONFIG_DATA, useValue: config },
|
|
769
|
+
],
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
SsvUxModule.decorators = [
|
|
774
|
+
{ type: NgModule, args: [{
|
|
775
|
+
declarations: [components],
|
|
776
|
+
providers: [
|
|
777
|
+
{ provide: UX_CONFIG, useFactory: _moduleConfigFactory, deps: [[MODULE_CONFIG_DATA, new Optional()]] },
|
|
778
|
+
{ provide: WINDOW, useFactory: _window },
|
|
779
|
+
],
|
|
780
|
+
exports: [...components],
|
|
781
|
+
},] }
|
|
782
|
+
];
|
|
783
|
+
/** @internal */
|
|
784
|
+
function _moduleConfigFactory(config) {
|
|
785
|
+
if (!config) {
|
|
786
|
+
return UX_DEFAULT_CONFIG;
|
|
787
|
+
}
|
|
788
|
+
const uxOptions = typeof config === "function" ? config() : config;
|
|
789
|
+
const viewport = Object.assign(Object.assign({}, UX_DEFAULT_CONFIG.viewport), uxOptions.viewport); // breakpoints shouldn't be merged
|
|
790
|
+
return { viewport };
|
|
791
|
+
}
|
|
792
|
+
/** @internal */
|
|
793
|
+
function _window() {
|
|
794
|
+
if (typeof window !== "undefined") {
|
|
795
|
+
return window;
|
|
796
|
+
}
|
|
797
|
+
return {};
|
|
798
798
|
}
|
|
799
799
|
|
|
800
|
-
const VERSION = "
|
|
800
|
+
const VERSION = "0.0.0-PLACEHOLDER";
|
|
801
801
|
|
|
802
|
-
/**
|
|
803
|
-
* Generated bundle index. Do not edit.
|
|
802
|
+
/**
|
|
803
|
+
* Generated bundle index. Do not edit.
|
|
804
804
|
*/
|
|
805
805
|
|
|
806
806
|
export { ComparisonOperation, DeviceType, MODULE_CONFIG_DATA, SsvUxModule, SsvViewportMatcherContext, SsvViewportMatcherDirective, SsvViewportMatcherVarContext, SsvViewportMatcherVarDirective, UX_CONFIG, UX_DEFAULT_CONFIG, UX_VIEWPORT_DEFAULT_BREAKPOINTS, UX_VIEWPORT_SSR_DEVICE, VERSION, ViewportDataMatchStrategy, ViewportDataPipe, ViewportDataService, ViewportServerSizeService, ViewportService, ViewportSizeType, _moduleConfigFactory, _window, generateViewportSizeType, UX_VIEWPORT_DEFAULT_CONFIG as ɵa, WINDOW as ɵb, WindowRef as ɵc };
|