@appartmint/mint 1.2.12 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/ts/imports/components/header.ts +0 -408
- package/src/ts/imports/components/index.ts +0 -4
- package/src/ts/imports/enums/index.ts +0 -4
- package/src/ts/imports/enums/side.ts +0 -9
- package/src/ts/imports/index.ts +0 -7
- package/src/ts/imports/models/color.ts +0 -96
- package/src/ts/imports/models/file.ts +0 -16
- package/src/ts/imports/models/index.ts +0 -9
- package/src/ts/imports/models/item.ts +0 -72
- package/src/ts/imports/models/minify.ts +0 -11
- package/src/ts/imports/models/page.ts +0 -19
- package/src/ts/imports/models/recaptcha.ts +0 -8
- package/src/ts/imports/util/async.ts +0 -12
- package/src/ts/imports/util/display.ts +0 -72
- package/src/ts/imports/util/event.ts +0 -93
- package/src/ts/imports/util/icon.ts +0 -67
- package/src/ts/imports/util/index.ts +0 -15
- package/src/ts/imports/util/list.ts +0 -39
- package/src/ts/imports/util/math.ts +0 -17
- package/src/ts/imports/util/object.ts +0 -234
- package/src/ts/imports/util/scroll.ts +0 -53
- package/src/ts/imports/util/selectors.ts +0 -185
- package/src/ts/imports/util/settings.ts +0 -85
- package/src/ts/imports/util/text.ts +0 -151
- package/src/ts/imports/util/window.ts +0 -14
- package/src/ts/index.ts +0 -10
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handles asynchronous operations
|
|
3
|
-
*/
|
|
4
|
-
export abstract class MintAsync {
|
|
5
|
-
/**
|
|
6
|
-
* Wait n milliseconds
|
|
7
|
-
*/
|
|
8
|
-
static wait(ms: number): Promise<void> {
|
|
9
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
export default MintAsync;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Imports
|
|
3
|
-
*/
|
|
4
|
-
import { EMintSide } from '../enums';
|
|
5
|
-
import { MintSettings } from './settings';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Handles the display of elements
|
|
9
|
-
*/
|
|
10
|
-
export abstract class MintDisplay {
|
|
11
|
-
/**
|
|
12
|
-
* Sets the element's height to its `innerHeight`, then to `auto` after a delay
|
|
13
|
-
* @param el - the element whose height will be set
|
|
14
|
-
* @param delay - the amount of time in milliseconds that the show animation will be active
|
|
15
|
-
* @param from - the side that the element is animating from
|
|
16
|
-
*/
|
|
17
|
-
static show (el?: HTMLElement | null, delay: number = MintSettings.delay.default, from: EMintSide = EMintSide.Top) : void {
|
|
18
|
-
if (el) {
|
|
19
|
-
el.style.display = '';
|
|
20
|
-
requestAnimationFrame(() => {
|
|
21
|
-
if (from === EMintSide.Top || from === EMintSide.Bottom) {
|
|
22
|
-
el.style.height = `${el.scrollHeight}px`;
|
|
23
|
-
} else {
|
|
24
|
-
el.style.width = `${el.scrollWidth}px`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
if (from === EMintSide.Top || from === EMintSide.Bottom) {
|
|
29
|
-
el.style.height = 'auto';
|
|
30
|
-
} else {
|
|
31
|
-
el.style.width = 'auto';
|
|
32
|
-
}
|
|
33
|
-
}, delay);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Sets the element's height to 0
|
|
40
|
-
* @param el - the element whose height will be set
|
|
41
|
-
* @param delay - the amount of time in milliseconds that the show animation will be active
|
|
42
|
-
* @param from - the side that the element is animating from
|
|
43
|
-
*/
|
|
44
|
-
static hide (el?: HTMLElement | null, delay: number = MintSettings.delay.default, from: EMintSide = EMintSide.Top) : void {
|
|
45
|
-
if (el) {
|
|
46
|
-
let height = el.scrollHeight,
|
|
47
|
-
width = el.scrollWidth,
|
|
48
|
-
transition = el.style.transition;
|
|
49
|
-
el.style.transition = '';
|
|
50
|
-
requestAnimationFrame(() => {
|
|
51
|
-
if (from === EMintSide.Top || from === EMintSide.Bottom) {
|
|
52
|
-
el.style.height = `${height}px`;
|
|
53
|
-
} else {
|
|
54
|
-
el.style.width = `${width}px`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
el.style.transition = transition;
|
|
58
|
-
requestAnimationFrame(() => {
|
|
59
|
-
if (from === EMintSide.Top || from === EMintSide.Bottom) {
|
|
60
|
-
el.style.height = '0';
|
|
61
|
-
} else {
|
|
62
|
-
el.style.width = '0';
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
el.style.display = 'none';
|
|
68
|
-
}, delay);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
export default MintDisplay;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import MintSettings from "./settings";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Event helper functions
|
|
5
|
-
*/
|
|
6
|
-
export abstract class MintEvent {
|
|
7
|
-
/**
|
|
8
|
-
* Ensures that a function `func` is run only after not being called for `wait` milliseconds
|
|
9
|
-
* @param func - the function to debounce
|
|
10
|
-
* @param wait - the amount of time to wait before running the function
|
|
11
|
-
* @returns - the debounced function
|
|
12
|
-
*/
|
|
13
|
-
static debounce (func: Function, wait: number = MintSettings.delay.default) : Function {
|
|
14
|
-
let timer: number;
|
|
15
|
-
return function (e: any) {
|
|
16
|
-
if (timer) {
|
|
17
|
-
clearTimeout(timer);
|
|
18
|
-
}
|
|
19
|
-
timer = setTimeout(func, wait, e);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Ensures that a function `func` is run only after not being called for `wait` milliseconds
|
|
25
|
-
* @param func - the function to debounce
|
|
26
|
-
* @param wait - the amount of time to wait before running the function
|
|
27
|
-
* @returns - the debounced function as an EventListener
|
|
28
|
-
*/
|
|
29
|
-
static debounceEvent (func: Function, wait: number = MintSettings.delay.default) : EventListener {
|
|
30
|
-
return MintEvent.debounce(func, wait) as EventListener;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Ensures that a function `func` is called at most every `wait` milliseconds with optional leading and trailing calls
|
|
35
|
-
* @param func - the function to throttle
|
|
36
|
-
* @param wait - the amount of time between function calls
|
|
37
|
-
* @param options - leading and trailing options: default = \{ leading: true, trailing, true \}
|
|
38
|
-
* @returns - the throttled function
|
|
39
|
-
*/
|
|
40
|
-
static throttle (func: Function,
|
|
41
|
-
wait: number = MintSettings.delay.default,
|
|
42
|
-
options?: {[key: string]: boolean}) : Function {
|
|
43
|
-
let context: any, args: any, result: any,
|
|
44
|
-
timeout: number, previous: number = 0,
|
|
45
|
-
later: Function = function () {
|
|
46
|
-
previous = options?.leading === false ? 0 : new Date().getTime();
|
|
47
|
-
timeout = 0;
|
|
48
|
-
result = func.apply(context, args);
|
|
49
|
-
if (!timeout) {
|
|
50
|
-
context = args = null;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
throttled: Function = function (this: any): any {
|
|
54
|
-
let now: number = new Date().getTime();
|
|
55
|
-
if (!previous && options?.leading === false) {
|
|
56
|
-
previous = now;
|
|
57
|
-
}
|
|
58
|
-
let remaining: number = wait - now + previous;
|
|
59
|
-
context = this;
|
|
60
|
-
args = arguments;
|
|
61
|
-
if (remaining <= 0 || remaining > wait) {
|
|
62
|
-
if (timeout) {
|
|
63
|
-
clearTimeout(timeout);
|
|
64
|
-
timeout = 0;
|
|
65
|
-
}
|
|
66
|
-
previous = now;
|
|
67
|
-
result = func.apply(context, args);
|
|
68
|
-
if (!timeout) {
|
|
69
|
-
context = args = null;
|
|
70
|
-
}
|
|
71
|
-
} else if (!timeout && options?.trailing !== false) {
|
|
72
|
-
timeout = window.setTimeout(later, remaining);
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return throttled;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Ensures that a function `func` is called at most every `wait` milliseconds with optional leading and trailing calls
|
|
82
|
-
* @param func - the function to throttle
|
|
83
|
-
* @param wait - the amount of time between function calls
|
|
84
|
-
* @param options - leading and trailing options: default = \{ leading: true, trailing, true \}
|
|
85
|
-
* @returns - the throttled function as an EventListener
|
|
86
|
-
*/
|
|
87
|
-
static throttleEvent (func: Function,
|
|
88
|
-
wait: number = MintSettings.delay.default,
|
|
89
|
-
options?: {[key: string]: boolean}) : EventListener {
|
|
90
|
-
return MintEvent.throttle(func, wait, options) as EventListener;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
export default MintEvent;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Imports
|
|
3
|
-
*/
|
|
4
|
-
import mintObject from "./object";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Icon helper functions
|
|
8
|
-
*/
|
|
9
|
-
export abstract class MintIcon {
|
|
10
|
-
/**
|
|
11
|
-
* Default icons
|
|
12
|
-
*/
|
|
13
|
-
static icons: {[key: string]: string} = {
|
|
14
|
-
'a[href^="mailto:"]': 'far fa-envelope',
|
|
15
|
-
'a[href^="tel:"]': 'fas fa-phone-flip',
|
|
16
|
-
'a[href^="sms:"]': 'far fa-message',
|
|
17
|
-
'a[href^="https://maps"]': 'fas fa-map-location-dot',
|
|
18
|
-
'a[href^="http"]': 'fas fa-up-right-from-square'
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Appends the given icon to the given selector if there is not already an icon appended
|
|
23
|
-
*/
|
|
24
|
-
static append (icon: string, selector: string): void {
|
|
25
|
-
let items: NodeListOf<HTMLElement> = document.querySelectorAll(selector);
|
|
26
|
-
items.forEach((item: HTMLElement) => {
|
|
27
|
-
let iconElement: HTMLElement = document.createElement('i');
|
|
28
|
-
iconElement.classList.add(...icon.split(' '));
|
|
29
|
-
if (!item.querySelector('i')) {
|
|
30
|
-
item.appendChild(iconElement);
|
|
31
|
-
}
|
|
32
|
-
if (iconElement.classList.contains('fa-up-right-from-square')) {
|
|
33
|
-
item.setAttribute('target', '_blank');
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Updates the icons
|
|
40
|
-
* @param icons - the icons to update
|
|
41
|
-
*/
|
|
42
|
-
static update (icons?: {[key: string]: string | false}): void {
|
|
43
|
-
let activeIcons: {[key: string]: string} = mintObject.removeValues({
|
|
44
|
-
...this.icons,
|
|
45
|
-
...icons
|
|
46
|
-
}, [false]);
|
|
47
|
-
|
|
48
|
-
Object.keys(activeIcons).forEach((selector: string) => {
|
|
49
|
-
this.append(activeIcons[selector], selector);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Removes the given icon from the given selector
|
|
55
|
-
* @param icon - the icon to remove
|
|
56
|
-
*/
|
|
57
|
-
static remove (icon: string, selector: string): void {
|
|
58
|
-
let items: NodeListOf<HTMLElement> = document.querySelectorAll(selector);
|
|
59
|
-
items.forEach((item: HTMLElement) => {
|
|
60
|
-
let iconElement: HTMLElement | null = item.querySelector('i');
|
|
61
|
-
if (iconElement) {
|
|
62
|
-
iconElement.remove();
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
export default MintIcon;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Forward all exports from the util directory
|
|
3
|
-
*/
|
|
4
|
-
export * from './async';
|
|
5
|
-
export * from './display';
|
|
6
|
-
export * from './event';
|
|
7
|
-
export * from './icon';
|
|
8
|
-
export * from './list';
|
|
9
|
-
export * from './math';
|
|
10
|
-
export * from './object';
|
|
11
|
-
export * from './scroll';
|
|
12
|
-
export * from './selectors';
|
|
13
|
-
export * from './settings';
|
|
14
|
-
export * from './text';
|
|
15
|
-
export * from './window';
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* List functions for the util library
|
|
3
|
-
*/
|
|
4
|
-
export abstract class MintList {
|
|
5
|
-
/**
|
|
6
|
-
* Returns a copy of the provided list with the items in random order
|
|
7
|
-
* @param list - the list to shuffle
|
|
8
|
-
* @returns - the shuffled list
|
|
9
|
-
*/
|
|
10
|
-
static shuffleCopy (list: any[]): any[] {
|
|
11
|
-
let copy = [...list];
|
|
12
|
-
for (let i = copy.length - 1; i > 0; i--) {
|
|
13
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
14
|
-
[copy[i], copy[j]] = [copy[j], copy[i]];
|
|
15
|
-
}
|
|
16
|
-
return copy;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Filters the array in place based on a test condition and returns the filtered array.
|
|
21
|
-
* This method modifies the original array by removing elements that do not pass the test implemented by the provided function.
|
|
22
|
-
*
|
|
23
|
-
* @template T The type of elements in the array.
|
|
24
|
-
* @param {T[]} list The array to filter, which will be modified in place.
|
|
25
|
-
* @param {(item: T) => boolean} test A function that tests each element of the array. Return `true` to keep the element, `false` otherwise.
|
|
26
|
-
* @returns {T[]} The original array with only the elements that passed the test.
|
|
27
|
-
*/
|
|
28
|
-
static filter<T> (list: T[], test: (item: T) => boolean): T[] {
|
|
29
|
-
let newLength = 0;
|
|
30
|
-
for (let i = 0; i < list.length; i++) {
|
|
31
|
-
if (test(list[i])) {
|
|
32
|
-
list[newLength++] = list[i];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
list.length = newLength;
|
|
36
|
-
return list;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
export default MintList;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Math functions for the util library
|
|
3
|
-
*/
|
|
4
|
-
export abstract class MintMath {
|
|
5
|
-
/**
|
|
6
|
-
* Get a random integer between min and max
|
|
7
|
-
* @param max Maximum value to return
|
|
8
|
-
* @param min Minimum value to return (default is 0)
|
|
9
|
-
* @returns a random integer between min and max
|
|
10
|
-
*/
|
|
11
|
-
static randomInt (max: number, min: number = 0): number {
|
|
12
|
-
min = Math.ceil(min);
|
|
13
|
-
max = Math.floor(max);
|
|
14
|
-
return Math.floor(Math.random() * (max - min) + min);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export default MintMath;
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Object functions for the util library
|
|
3
|
-
*/
|
|
4
|
-
export abstract class MintObject {
|
|
5
|
-
/**
|
|
6
|
-
* Returns true if the provided objects have the same entries
|
|
7
|
-
*/
|
|
8
|
-
static isSimilar (obj1: any, obj2: any) : boolean {
|
|
9
|
-
let keys: string[] = Object.keys(obj1);
|
|
10
|
-
if (keys.length !== Object.keys(obj2).length) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
let isSimilar: boolean = true;
|
|
14
|
-
keys.forEach((key: string) => {
|
|
15
|
-
if (obj1[key] !== obj2[key]) {
|
|
16
|
-
isSimilar = false;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return isSimilar;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Returns true if the first object has at least the same
|
|
24
|
-
* entries as the second object
|
|
25
|
-
* @param superset - the object to check
|
|
26
|
-
* @param subset - the object whose entries are required
|
|
27
|
-
* @returns - true if the first object is a superset of the second
|
|
28
|
-
* @recursive
|
|
29
|
-
*/
|
|
30
|
-
static isSuperset (superset: any, subset: any) : boolean {
|
|
31
|
-
let isSuperset: boolean = true;
|
|
32
|
-
|
|
33
|
-
// Base case - if the objects are equal, it is a superset
|
|
34
|
-
if (superset === subset) {
|
|
35
|
-
return isSuperset;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// If the subset isn't an object or array, and doesn't
|
|
39
|
-
// satisfy the base case, it isn't a superset
|
|
40
|
-
try {
|
|
41
|
-
if (Object.keys(subset).length === 0) {
|
|
42
|
-
return !isSuperset;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// If the subset is null or undefined, and doesn't satisfy
|
|
46
|
-
// the base case, it isn't a superset
|
|
47
|
-
// TODO: Check if other exceptions could occur
|
|
48
|
-
catch (e) {
|
|
49
|
-
return !isSuperset;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// If the children of the subset are subsets of the
|
|
53
|
-
// respective children of the superset, it is a superset
|
|
54
|
-
Object.keys(subset).forEach((key: string) => {
|
|
55
|
-
isSuperset = isSuperset && MintObject.isSuperset(superset[key], subset[key]);
|
|
56
|
-
});
|
|
57
|
-
return isSuperset;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Removes object entries by key
|
|
62
|
-
* @alias mintObject.removeKeys
|
|
63
|
-
* @param object - the object to remove entries from
|
|
64
|
-
* @param keys - the keys to remove
|
|
65
|
-
*/
|
|
66
|
-
static remove (object: any, keys: string[]) : Object {
|
|
67
|
-
return this.removeKeys(object, keys);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Removes object entries by key
|
|
72
|
-
* @param object - the object to remove entries from
|
|
73
|
-
* @param keys - the keys to remove
|
|
74
|
-
*/
|
|
75
|
-
static removeKeys (object: any, keys: string[]) : any {
|
|
76
|
-
return Object.keys(object).reduce((obj: any, key: string) => {
|
|
77
|
-
if (!keys.includes(key)) {
|
|
78
|
-
obj[key] = object[key];
|
|
79
|
-
}
|
|
80
|
-
return obj;
|
|
81
|
-
}, {});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Removes object entries by value
|
|
86
|
-
*/
|
|
87
|
-
static removeValues (object: any, values: any[]) : any {
|
|
88
|
-
return Object.keys(object).reduce((obj: any, key: string) => {
|
|
89
|
-
if (!values.includes(object[key])) {
|
|
90
|
-
obj[key] = object[key];
|
|
91
|
-
}
|
|
92
|
-
return obj;
|
|
93
|
-
}, {});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Sorts an object's entries alphabetically by key
|
|
98
|
-
*/
|
|
99
|
-
static sort (object: any, compareFn?: (a: string, b: string) => number) : any {
|
|
100
|
-
return this.sortKeys(object, compareFn);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Sorts an object's entries alphabetically by key
|
|
105
|
-
*/
|
|
106
|
-
static sortKeys (object: any, compareFn?: (a: string, b: string) => number) : any {
|
|
107
|
-
return Object.keys(object).sort(compareFn).reduce((obj: any, key: string) => {
|
|
108
|
-
obj[key] = object[key];
|
|
109
|
-
return obj;
|
|
110
|
-
}, {});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Sorts an object's entries alphabetically by value
|
|
115
|
-
*/
|
|
116
|
-
static sortValues (object: any, compareFn: (a: any, b: any) => number) : any {
|
|
117
|
-
return Object.keys(object).sort((a: string, b: string) => compareFn(object[a], object[b])).reduce((obj: any, key: string) => {
|
|
118
|
-
obj[key] = object[key];
|
|
119
|
-
return obj;
|
|
120
|
-
}, {});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* @alias mintObject.filterKeys
|
|
125
|
-
*/
|
|
126
|
-
static filter (object: any, keys: string[]) : Object {
|
|
127
|
-
return this.filterKeys(object, keys);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Filters an object by its keys
|
|
132
|
-
* @param object - the object to filter
|
|
133
|
-
* @param keys - the keys to keep
|
|
134
|
-
* @returns - the filtered object
|
|
135
|
-
*/
|
|
136
|
-
static filterKeys (object: any, keys: string[]) : Object {
|
|
137
|
-
return keys.reduce((obj: any, key: string) => {
|
|
138
|
-
obj[key] = object[key];
|
|
139
|
-
return obj;
|
|
140
|
-
}, {});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Filters an object by its values
|
|
145
|
-
* @param object - the object to filter
|
|
146
|
-
* @param values - the values to keep
|
|
147
|
-
* @returns - the filtered object
|
|
148
|
-
*/
|
|
149
|
-
static filterValues (object: any, values: any[]) : Object {
|
|
150
|
-
return Object.keys(object).reduce((obj: any, key: string) => {
|
|
151
|
-
if (values.includes(object[key])) {
|
|
152
|
-
obj[key] = object[key];
|
|
153
|
-
}
|
|
154
|
-
return obj;
|
|
155
|
-
}, {});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Update two sets of objects
|
|
160
|
-
* @param original - the original object
|
|
161
|
-
* @param update - the object to update the original with
|
|
162
|
-
* @returns - the original objects with updated data from the update
|
|
163
|
-
*/
|
|
164
|
-
static updateArray (original: any[], update?: any[], key = 'id') : any {
|
|
165
|
-
|
|
166
|
-
// If there are no originals, push the updates
|
|
167
|
-
if (!update?.length) {
|
|
168
|
-
update?.forEach((object) => original.push(object));
|
|
169
|
-
|
|
170
|
-
// If there are existing objects
|
|
171
|
-
} else {
|
|
172
|
-
|
|
173
|
-
// Create a dictionary of the updated objects
|
|
174
|
-
const updateObjects = update.reduce<{ [key: string]: Object }>((objects, object) => ({
|
|
175
|
-
...objects,
|
|
176
|
-
[object?.[key] ?? '']: object
|
|
177
|
-
}), {});
|
|
178
|
-
|
|
179
|
-
// Remove any objects that aren't in the updated objects
|
|
180
|
-
const missingObjects = original.filter((object) => !updateObjects[object?.[key] ?? '']);
|
|
181
|
-
missingObjects?.forEach((object) => {
|
|
182
|
-
const index = original.indexOf(object);
|
|
183
|
-
if (typeof index == 'number' && index !== -1) {
|
|
184
|
-
original.splice(index, 1);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Update the existing objects with updates
|
|
189
|
-
original.forEach((object) => {
|
|
190
|
-
if (updateObjects[object?.[key] ?? '']) {
|
|
191
|
-
Object.assign(object, updateObjects[object?.[key] ?? '']);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Push any new objects
|
|
197
|
-
const newObjects = update?.filter((object) => !original.some((existingObject) => existingObject?.[key] === object?.[key]));
|
|
198
|
-
newObjects?.forEach(newObject => original.push(newObject));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Get an object's key by value
|
|
203
|
-
*/
|
|
204
|
-
static getKeyByValue(object: any, value: any): string | undefined {
|
|
205
|
-
return Object.keys(object).find((key) => object[key] === value);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Create a deep copy of an object
|
|
210
|
-
* @recursive
|
|
211
|
-
*/
|
|
212
|
-
static deepClone(object: any): any {
|
|
213
|
-
|
|
214
|
-
// Clone every property
|
|
215
|
-
const clone: any = {};
|
|
216
|
-
for (const key in object) {
|
|
217
|
-
|
|
218
|
-
// Functions
|
|
219
|
-
if (typeof object[key] === 'function') {
|
|
220
|
-
clone[key] = object[key].bind(clone);
|
|
221
|
-
|
|
222
|
-
// Objects
|
|
223
|
-
} else if (object[key] && typeof object[key] === 'object') {
|
|
224
|
-
clone[key] = this.deepClone(object[key]);
|
|
225
|
-
|
|
226
|
-
// Primitives
|
|
227
|
-
} else {
|
|
228
|
-
clone[key] = object[key];
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return clone;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
export default MintObject;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Imports
|
|
3
|
-
*/
|
|
4
|
-
import MintEvent from './event';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Scroll functions
|
|
8
|
-
*/
|
|
9
|
-
export abstract class MintScroll {
|
|
10
|
-
/**
|
|
11
|
-
* Scroll to the top of the page
|
|
12
|
-
*/
|
|
13
|
-
static toTop(): void {
|
|
14
|
-
window.scrollTo(0, 0);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Scroll to the bottom of the page
|
|
19
|
-
*/
|
|
20
|
-
static toBottom(): void {
|
|
21
|
-
window.scrollTo(0, document.body.scrollHeight);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Show visible elements
|
|
26
|
-
*/
|
|
27
|
-
static showElements(): void {
|
|
28
|
-
requestAnimationFrame(() => {
|
|
29
|
-
let elements = document.querySelectorAll('.mint-fall-in:not(.mint-show)'),
|
|
30
|
-
elementsToShow: Element[] = [];
|
|
31
|
-
for (let i = 0; i < elements.length; i++) {
|
|
32
|
-
if (elements[i].getBoundingClientRect().top < 0) {
|
|
33
|
-
elements[i].classList.add('mint-show');
|
|
34
|
-
} else if (elements[i].getBoundingClientRect().top < window.innerHeight * 3 / 4) {
|
|
35
|
-
elementsToShow.push(elements[i]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
for (let i = 0; i < elementsToShow.length; i++) {
|
|
39
|
-
setTimeout(() => {
|
|
40
|
-
elementsToShow[i].classList.add('mint-show');
|
|
41
|
-
}, i * 100);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Show visible elements on scroll
|
|
48
|
-
*/
|
|
49
|
-
static showElementsOnScroll(): void {
|
|
50
|
-
window.addEventListener('scroll', MintEvent.throttleEvent(this.showElements, 200));
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
export default MintScroll;
|