@ouroboros/browser 0.5.4 → 0.5.6
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/ouroboros-browser-0.5.6.tgz +0 -0
- package/package.json +2 -3
- package/pageVisibility.d.ts +12 -0
- package/pageVisibility.js +31 -18
- package/size.d.ts +48 -0
- package/size.js +60 -2
- package/src/pageVisibility.ts +34 -20
- package/src/size.ts +67 -3
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouroboros/browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "Package to handle common browser functionality.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -33,10 +33,9 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"tslint": "^6.1.3",
|
|
35
35
|
"tslint-config-prettier": "^1.18.0",
|
|
36
|
-
"typescript": "^
|
|
36
|
+
"typescript": "^5.9.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ouroboros/clone": "^1.1.0",
|
|
40
39
|
"@ouroboros/subscribe": "^1.3.2",
|
|
41
40
|
"@ouroboros/tools": "^0.7.1"
|
|
42
41
|
}
|
package/pageVisibility.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import Subscribe, { SubscribeCallback, SubscribeReturn } from '@ouroboros/subscr
|
|
|
17
17
|
* @extends Subscribe
|
|
18
18
|
*/
|
|
19
19
|
declare class PageVisibility extends Subscribe {
|
|
20
|
+
#private;
|
|
20
21
|
/**
|
|
21
22
|
* Constructor
|
|
22
23
|
*
|
|
@@ -27,6 +28,17 @@ declare class PageVisibility extends Subscribe {
|
|
|
27
28
|
* @returns PageVisibility
|
|
28
29
|
*/
|
|
29
30
|
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Set
|
|
33
|
+
*
|
|
34
|
+
* Overrides Subscribe.set to make sure no one can call it without a failure
|
|
35
|
+
*
|
|
36
|
+
* @name set
|
|
37
|
+
* @access public
|
|
38
|
+
* @param data The new data to set and then send
|
|
39
|
+
* @returns void
|
|
40
|
+
*/
|
|
41
|
+
set(data: any): boolean;
|
|
30
42
|
/**
|
|
31
43
|
* Subscribe
|
|
32
44
|
*
|
package/pageVisibility.js
CHANGED
|
@@ -35,22 +35,6 @@ else {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Track
|
|
40
|
-
*
|
|
41
|
-
* The actual function passed to the event so that we only have one event
|
|
42
|
-
* listener
|
|
43
|
-
*
|
|
44
|
-
* @name track
|
|
45
|
-
* @access private
|
|
46
|
-
*/
|
|
47
|
-
function track() {
|
|
48
|
-
// Set the data so the instance notifies subscribers
|
|
49
|
-
pageVisibility.set({
|
|
50
|
-
property: document[properties.property],
|
|
51
|
-
state: document[properties.state]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
38
|
/**
|
|
55
39
|
* Page Visibility
|
|
56
40
|
*
|
|
@@ -76,6 +60,19 @@ class PageVisibility extends Subscribe {
|
|
|
76
60
|
state: document[properties.state]
|
|
77
61
|
} : null);
|
|
78
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Set
|
|
65
|
+
*
|
|
66
|
+
* Overrides Subscribe.set to make sure no one can call it without a failure
|
|
67
|
+
*
|
|
68
|
+
* @name set
|
|
69
|
+
* @access public
|
|
70
|
+
* @param data The new data to set and then send
|
|
71
|
+
* @returns void
|
|
72
|
+
*/
|
|
73
|
+
set(data) {
|
|
74
|
+
throw new Error('Calling PageVisibility.set() is forbidden');
|
|
75
|
+
}
|
|
79
76
|
/**
|
|
80
77
|
* Subscribe
|
|
81
78
|
*
|
|
@@ -90,11 +87,27 @@ class PageVisibility extends Subscribe {
|
|
|
90
87
|
// If we have no current subscribers
|
|
91
88
|
if (apiAvailable && this.subscribeCallbacks.length === 0) {
|
|
92
89
|
// Add the event listener
|
|
93
|
-
document.addEventListener(properties.event, track);
|
|
90
|
+
document.addEventListener(properties.event, this.#track);
|
|
94
91
|
}
|
|
95
92
|
// Call the parent subscribe and return
|
|
96
93
|
return super.subscribe(callback);
|
|
97
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Track
|
|
97
|
+
*
|
|
98
|
+
* The actual function passed to the event so that we only have one event
|
|
99
|
+
* listener
|
|
100
|
+
*
|
|
101
|
+
* @name track
|
|
102
|
+
* @access private
|
|
103
|
+
*/
|
|
104
|
+
#track = () => {
|
|
105
|
+
// Set the data so the instance notifies subscribers
|
|
106
|
+
super.set({
|
|
107
|
+
property: document[properties.property],
|
|
108
|
+
state: document[properties.state]
|
|
109
|
+
});
|
|
110
|
+
};
|
|
98
111
|
/**
|
|
99
112
|
* Unsubscribe
|
|
100
113
|
*
|
|
@@ -115,7 +128,7 @@ class PageVisibility extends Subscribe {
|
|
|
115
128
|
// If it was successful and we have no more callbacks
|
|
116
129
|
if (bRet && this.subscribeCallbacks.length === 0) {
|
|
117
130
|
// Remove the event listener
|
|
118
|
-
document.removeEventListener(properties.event, track);
|
|
131
|
+
document.removeEventListener(properties.event, this.#track);
|
|
119
132
|
}
|
|
120
133
|
// Return
|
|
121
134
|
return bRet;
|
package/size.d.ts
CHANGED
|
@@ -65,6 +65,18 @@ declare class Size extends Subscribe {
|
|
|
65
65
|
* @returns number
|
|
66
66
|
*/
|
|
67
67
|
greaterThan(against: SIZE): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Greater Than or Equal
|
|
70
|
+
*
|
|
71
|
+
* Calls the module's `greaterThanOrEqual` method with the current size and
|
|
72
|
+
* the `against` param.
|
|
73
|
+
*
|
|
74
|
+
* @name greaterThanOrEqual
|
|
75
|
+
* @access public
|
|
76
|
+
* @param against The size to compare the current size against
|
|
77
|
+
* @returns number
|
|
78
|
+
*/
|
|
79
|
+
greaterThanOrEqual(against: SIZE): boolean;
|
|
68
80
|
/**
|
|
69
81
|
* Less Than
|
|
70
82
|
*
|
|
@@ -77,6 +89,18 @@ declare class Size extends Subscribe {
|
|
|
77
89
|
* @returns number
|
|
78
90
|
*/
|
|
79
91
|
lessThan(against: SIZE): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Less Than or Equal
|
|
94
|
+
*
|
|
95
|
+
* Calls the module's `lessThanOrEqual` method with the current size and
|
|
96
|
+
* the `against` param.
|
|
97
|
+
*
|
|
98
|
+
* @name lessThanOrEqual
|
|
99
|
+
* @access public
|
|
100
|
+
* @param against The size to compare the current size against
|
|
101
|
+
* @returns number
|
|
102
|
+
*/
|
|
103
|
+
lessThanOrEqual(against: SIZE): boolean;
|
|
80
104
|
/**
|
|
81
105
|
* Subscribe
|
|
82
106
|
*
|
|
@@ -127,6 +151,18 @@ export declare function compare(a: SIZE, b: SIZE): 0 | 1 | -1;
|
|
|
127
151
|
* @returns boolean
|
|
128
152
|
*/
|
|
129
153
|
export declare function greaterThan(a: SIZE, b: SIZE): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Greater Than or Equal
|
|
156
|
+
*
|
|
157
|
+
* Returns true only if `a` is a larger or equal width to `b`
|
|
158
|
+
*
|
|
159
|
+
* @name greaterThanOrEqual
|
|
160
|
+
* @access public
|
|
161
|
+
* @param a The size to compare as greater than or equal to `b`
|
|
162
|
+
* @param b The size to compare against `a`
|
|
163
|
+
* @returns boolean
|
|
164
|
+
*/
|
|
165
|
+
export declare function greaterThanOrEqual(a: SIZE, b: SIZE): boolean;
|
|
130
166
|
/**
|
|
131
167
|
* Less Than
|
|
132
168
|
*
|
|
@@ -139,3 +175,15 @@ export declare function greaterThan(a: SIZE, b: SIZE): boolean;
|
|
|
139
175
|
* @returns boolean
|
|
140
176
|
*/
|
|
141
177
|
export declare function lessThan(a: SIZE, b: SIZE): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Less Than or Equal
|
|
180
|
+
*
|
|
181
|
+
* Returns true only if `a` is a smaller or equal width to `b`
|
|
182
|
+
*
|
|
183
|
+
* @name lessThanOrEqual
|
|
184
|
+
* @access public
|
|
185
|
+
* @param a The size to compare as less than or equal to `b`
|
|
186
|
+
* @param b The size to compare against `a`
|
|
187
|
+
* @returns boolean
|
|
188
|
+
*/
|
|
189
|
+
export declare function lessThanOrEqual(a: SIZE, b: SIZE): boolean;
|
package/size.js
CHANGED
|
@@ -110,6 +110,20 @@ class Size extends Subscribe {
|
|
|
110
110
|
greaterThan(against) {
|
|
111
111
|
return greaterThan(this.subscribeData, against);
|
|
112
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Greater Than or Equal
|
|
115
|
+
*
|
|
116
|
+
* Calls the module's `greaterThanOrEqual` method with the current size and
|
|
117
|
+
* the `against` param.
|
|
118
|
+
*
|
|
119
|
+
* @name greaterThanOrEqual
|
|
120
|
+
* @access public
|
|
121
|
+
* @param against The size to compare the current size against
|
|
122
|
+
* @returns number
|
|
123
|
+
*/
|
|
124
|
+
greaterThanOrEqual(against) {
|
|
125
|
+
return greaterThanOrEqual(this.subscribeData, against);
|
|
126
|
+
}
|
|
113
127
|
/**
|
|
114
128
|
* Less Than
|
|
115
129
|
*
|
|
@@ -124,6 +138,20 @@ class Size extends Subscribe {
|
|
|
124
138
|
lessThan(against) {
|
|
125
139
|
return lessThan(this.subscribeData, against);
|
|
126
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Less Than or Equal
|
|
143
|
+
*
|
|
144
|
+
* Calls the module's `lessThanOrEqual` method with the current size and
|
|
145
|
+
* the `against` param.
|
|
146
|
+
*
|
|
147
|
+
* @name lessThanOrEqual
|
|
148
|
+
* @access public
|
|
149
|
+
* @param against The size to compare the current size against
|
|
150
|
+
* @returns number
|
|
151
|
+
*/
|
|
152
|
+
lessThanOrEqual(against) {
|
|
153
|
+
return lessThanOrEqual(this.subscribeData, against);
|
|
154
|
+
}
|
|
127
155
|
/**
|
|
128
156
|
* Subscribe
|
|
129
157
|
*
|
|
@@ -203,9 +231,24 @@ export function compare(a, b) {
|
|
|
203
231
|
* @returns boolean
|
|
204
232
|
*/
|
|
205
233
|
export function greaterThan(a, b) {
|
|
206
|
-
// If the
|
|
234
|
+
// If the `a` value is greater than the `b` value
|
|
207
235
|
return SIZES[a] > SIZES[b];
|
|
208
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Greater Than or Equal
|
|
239
|
+
*
|
|
240
|
+
* Returns true only if `a` is a larger or equal width to `b`
|
|
241
|
+
*
|
|
242
|
+
* @name greaterThanOrEqual
|
|
243
|
+
* @access public
|
|
244
|
+
* @param a The size to compare as greater than or equal to `b`
|
|
245
|
+
* @param b The size to compare against `a`
|
|
246
|
+
* @returns boolean
|
|
247
|
+
*/
|
|
248
|
+
export function greaterThanOrEqual(a, b) {
|
|
249
|
+
// If the `a` value is greater than or equal to the `b` value
|
|
250
|
+
return SIZES[a] >= SIZES[b];
|
|
251
|
+
}
|
|
209
252
|
/**
|
|
210
253
|
* Less Than
|
|
211
254
|
*
|
|
@@ -218,6 +261,21 @@ export function greaterThan(a, b) {
|
|
|
218
261
|
* @returns boolean
|
|
219
262
|
*/
|
|
220
263
|
export function lessThan(a, b) {
|
|
221
|
-
// If the `a`
|
|
264
|
+
// If the `a` value is less than the `b` value
|
|
222
265
|
return SIZES[a] < SIZES[b];
|
|
223
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Less Than or Equal
|
|
269
|
+
*
|
|
270
|
+
* Returns true only if `a` is a smaller or equal width to `b`
|
|
271
|
+
*
|
|
272
|
+
* @name lessThanOrEqual
|
|
273
|
+
* @access public
|
|
274
|
+
* @param a The size to compare as less than or equal to `b`
|
|
275
|
+
* @param b The size to compare against `a`
|
|
276
|
+
* @returns boolean
|
|
277
|
+
*/
|
|
278
|
+
export function lessThanOrEqual(a, b) {
|
|
279
|
+
// If the `a` value is less than or equal to the `b` value
|
|
280
|
+
return SIZES[a] <= SIZES[b];
|
|
281
|
+
}
|
package/src/pageVisibility.ts
CHANGED
|
@@ -45,24 +45,6 @@ else {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* Track
|
|
50
|
-
*
|
|
51
|
-
* The actual function passed to the event so that we only have one event
|
|
52
|
-
* listener
|
|
53
|
-
*
|
|
54
|
-
* @name track
|
|
55
|
-
* @access private
|
|
56
|
-
*/
|
|
57
|
-
function track(): void {
|
|
58
|
-
|
|
59
|
-
// Set the data so the instance notifies subscribers
|
|
60
|
-
pageVisibility.set({
|
|
61
|
-
property: document[properties.property as keyof Document],
|
|
62
|
-
state: document[properties.state as keyof Document]
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
48
|
/**
|
|
67
49
|
* Page Visibility
|
|
68
50
|
*
|
|
@@ -91,6 +73,20 @@ class PageVisibility extends Subscribe {
|
|
|
91
73
|
} : null);
|
|
92
74
|
}
|
|
93
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Set
|
|
78
|
+
*
|
|
79
|
+
* Overrides Subscribe.set to make sure no one can call it without a failure
|
|
80
|
+
*
|
|
81
|
+
* @name set
|
|
82
|
+
* @access public
|
|
83
|
+
* @param data The new data to set and then send
|
|
84
|
+
* @returns void
|
|
85
|
+
*/
|
|
86
|
+
set(data: any): boolean {
|
|
87
|
+
throw new Error('Calling PageVisibility.set() is forbidden');
|
|
88
|
+
}
|
|
89
|
+
|
|
94
90
|
/**
|
|
95
91
|
* Subscribe
|
|
96
92
|
*
|
|
@@ -107,13 +103,31 @@ class PageVisibility extends Subscribe {
|
|
|
107
103
|
if(apiAvailable && this.subscribeCallbacks.length === 0) {
|
|
108
104
|
|
|
109
105
|
// Add the event listener
|
|
110
|
-
document.addEventListener(properties.event, track);
|
|
106
|
+
document.addEventListener(properties.event, this.#track);
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
// Call the parent subscribe and return
|
|
114
110
|
return super.subscribe(callback);
|
|
115
111
|
}
|
|
116
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Track
|
|
115
|
+
*
|
|
116
|
+
* The actual function passed to the event so that we only have one event
|
|
117
|
+
* listener
|
|
118
|
+
*
|
|
119
|
+
* @name track
|
|
120
|
+
* @access private
|
|
121
|
+
*/
|
|
122
|
+
#track = () => {
|
|
123
|
+
|
|
124
|
+
// Set the data so the instance notifies subscribers
|
|
125
|
+
super.set({
|
|
126
|
+
property: document[properties.property as keyof Document],
|
|
127
|
+
state: document[properties.state as keyof Document]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
117
131
|
/**
|
|
118
132
|
* Unsubscribe
|
|
119
133
|
*
|
|
@@ -138,7 +152,7 @@ class PageVisibility extends Subscribe {
|
|
|
138
152
|
if(bRet && this.subscribeCallbacks.length === 0) {
|
|
139
153
|
|
|
140
154
|
// Remove the event listener
|
|
141
|
-
document.removeEventListener(properties.event, track);
|
|
155
|
+
document.removeEventListener(properties.event, this.#track);
|
|
142
156
|
}
|
|
143
157
|
|
|
144
158
|
// Return
|
package/src/size.ts
CHANGED
|
@@ -120,6 +120,21 @@ class Size extends Subscribe {
|
|
|
120
120
|
return greaterThan(this.subscribeData, against);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Greater Than or Equal
|
|
125
|
+
*
|
|
126
|
+
* Calls the module's `greaterThanOrEqual` method with the current size and
|
|
127
|
+
* the `against` param.
|
|
128
|
+
*
|
|
129
|
+
* @name greaterThanOrEqual
|
|
130
|
+
* @access public
|
|
131
|
+
* @param against The size to compare the current size against
|
|
132
|
+
* @returns number
|
|
133
|
+
*/
|
|
134
|
+
greaterThanOrEqual(against: SIZE): boolean {
|
|
135
|
+
return greaterThanOrEqual(this.subscribeData, against);
|
|
136
|
+
}
|
|
137
|
+
|
|
123
138
|
/**
|
|
124
139
|
* Less Than
|
|
125
140
|
*
|
|
@@ -135,6 +150,21 @@ class Size extends Subscribe {
|
|
|
135
150
|
return lessThan(this.subscribeData, against);
|
|
136
151
|
}
|
|
137
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Less Than or Equal
|
|
155
|
+
*
|
|
156
|
+
* Calls the module's `lessThanOrEqual` method with the current size and
|
|
157
|
+
* the `against` param.
|
|
158
|
+
*
|
|
159
|
+
* @name lessThanOrEqual
|
|
160
|
+
* @access public
|
|
161
|
+
* @param against The size to compare the current size against
|
|
162
|
+
* @returns number
|
|
163
|
+
*/
|
|
164
|
+
lessThanOrEqual(against: SIZE): boolean {
|
|
165
|
+
return lessThanOrEqual(this.subscribeData, against);
|
|
166
|
+
}
|
|
167
|
+
|
|
138
168
|
/**
|
|
139
169
|
* Subscribe
|
|
140
170
|
*
|
|
@@ -227,10 +257,27 @@ export function compare(a: SIZE, b: SIZE) {
|
|
|
227
257
|
*/
|
|
228
258
|
export function greaterThan(a: SIZE, b: SIZE): boolean {
|
|
229
259
|
|
|
230
|
-
// If the
|
|
260
|
+
// If the `a` value is greater than the `b` value
|
|
231
261
|
return SIZES[a] > SIZES[b];
|
|
232
262
|
}
|
|
233
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Greater Than or Equal
|
|
266
|
+
*
|
|
267
|
+
* Returns true only if `a` is a larger or equal width to `b`
|
|
268
|
+
*
|
|
269
|
+
* @name greaterThanOrEqual
|
|
270
|
+
* @access public
|
|
271
|
+
* @param a The size to compare as greater than or equal to `b`
|
|
272
|
+
* @param b The size to compare against `a`
|
|
273
|
+
* @returns boolean
|
|
274
|
+
*/
|
|
275
|
+
export function greaterThanOrEqual(a: SIZE, b: SIZE): boolean {
|
|
276
|
+
|
|
277
|
+
// If the `a` value is greater than or equal to the `b` value
|
|
278
|
+
return SIZES[a] >= SIZES[b];
|
|
279
|
+
}
|
|
280
|
+
|
|
234
281
|
/**
|
|
235
282
|
* Less Than
|
|
236
283
|
*
|
|
@@ -244,6 +291,23 @@ export function greaterThan(a: SIZE, b: SIZE): boolean {
|
|
|
244
291
|
*/
|
|
245
292
|
export function lessThan(a: SIZE, b: SIZE): boolean {
|
|
246
293
|
|
|
247
|
-
// If the `a`
|
|
294
|
+
// If the `a` value is less than the `b` value
|
|
248
295
|
return SIZES[a] < SIZES[b];
|
|
249
|
-
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Less Than or Equal
|
|
300
|
+
*
|
|
301
|
+
* Returns true only if `a` is a smaller or equal width to `b`
|
|
302
|
+
*
|
|
303
|
+
* @name lessThanOrEqual
|
|
304
|
+
* @access public
|
|
305
|
+
* @param a The size to compare as less than or equal to `b`
|
|
306
|
+
* @param b The size to compare against `a`
|
|
307
|
+
* @returns boolean
|
|
308
|
+
*/
|
|
309
|
+
export function lessThanOrEqual(a: SIZE, b: SIZE): boolean {
|
|
310
|
+
|
|
311
|
+
// If the `a` value is less than or equal to the `b` value
|
|
312
|
+
return SIZES[a] <= SIZES[b];
|
|
313
|
+
}
|