@appartmint/mint 0.14.1 → 0.14.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.
Files changed (45) hide show
  1. package/README.md +3 -3
  2. package/dist/css/mint.css +19 -1
  3. package/dist/css/mint.css.map +1 -1
  4. package/dist/css/mint.min.css +1 -1
  5. package/dist/css/mint.min.css.map +1 -1
  6. package/dist/js/imports/components/header.d.ts +124 -124
  7. package/dist/js/imports/enum.d.ts +9 -9
  8. package/dist/js/imports/models/color.d.ts +31 -31
  9. package/dist/js/imports/models/item.d.ts +69 -69
  10. package/dist/js/imports/util/display.d.ts +6 -6
  11. package/dist/js/imports/util/event.d.ts +6 -6
  12. package/dist/js/imports/util/icon.d.ts +28 -28
  13. package/dist/js/imports/util/list.d.ts +12 -12
  14. package/dist/js/imports/util/math.d.ts +13 -13
  15. package/dist/js/imports/util/object.d.ts +65 -58
  16. package/dist/js/imports/util/object.d.ts.map +1 -1
  17. package/dist/js/imports/util/selectors.d.ts +121 -121
  18. package/dist/js/imports/util/settings.d.ts +38 -38
  19. package/dist/js/imports/util/text.d.ts +16 -16
  20. package/dist/js/imports/util/window.d.ts +6 -6
  21. package/dist/js/index.d.ts +23 -23
  22. package/dist/js/index.js +360 -317
  23. package/dist/js/index.js.map +1 -1
  24. package/dist/js/index.min.js +1 -1
  25. package/dist/js/index.min.js.map +1 -1
  26. package/dist/js/util.d.ts +77 -77
  27. package/dist/js/util.js +67 -67
  28. package/dist/js/util.js.map +1 -1
  29. package/dist/js/util.min.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/scss/imports/_index.scss +8 -8
  32. package/src/scss/imports/components/_buttons.scss +2 -0
  33. package/src/scss/imports/components/_cards.scss +23 -1
  34. package/src/scss/imports/components/_index.scss +7 -7
  35. package/src/scss/imports/global/_icons.scss +6 -6
  36. package/src/scss/imports/util/_index.scss +8 -8
  37. package/src/ts/imports/enum.ts +9 -9
  38. package/src/ts/imports/models/color.ts +96 -96
  39. package/src/ts/imports/util/display.ts +6 -6
  40. package/src/ts/imports/util/event.ts +7 -7
  41. package/src/ts/imports/util/list.ts +19 -19
  42. package/src/ts/imports/util/math.ts +17 -17
  43. package/src/ts/imports/util/object.ts +43 -0
  44. package/src/ts/imports/util/window.ts +6 -6
  45. package/src/ts/index.ts +33 -33
@@ -1,96 +1,96 @@
1
- /**
2
- * Color
3
- */
4
- export class mintColor {
5
- protected static hexBase: number = 16;
6
- protected static hexMax: string = 'FF';
7
- public r: number;
8
- public g: number;
9
- public b: number;
10
- public a: number;
11
-
12
- constructor (args: {[key: string]: number | string}) {
13
- this.r = typeof args.r === 'number' ? Math.max(Math.min(args.r, mintColor.hexBase ** 2 - 1), 0) : 0;
14
- this.g = typeof args.g === 'number' ? Math.max(Math.min(args.g, mintColor.hexBase ** 2 - 1), 0) : 0;
15
- this.b = typeof args.b === 'number' ? Math.max(Math.min(args.b, mintColor.hexBase ** 2 - 1), 0) : 0;
16
- this.a = typeof args.a === 'number' ? Math.max(Math.min(args.a, 1), 0) : 1;
17
- if (typeof args.color === 'string') {
18
- this.stringConstructor(args.color);
19
- }
20
- }
21
-
22
- /**
23
- * Constructor from a string argument
24
- */
25
- protected stringConstructor (str: string) : void {
26
- if (str.startsWith('#')) {
27
- this.hexConstructor(str);
28
- } else {
29
- if (~str.indexOf('linear-gradient')) {
30
- str = str.substring(str.indexOf('linear-gradient'), str.length);
31
- }
32
- this.rgbConstructor(str);
33
- }
34
- }
35
-
36
- /**
37
- * Constructor from a hex argument
38
- */
39
- protected hexConstructor (hex: string) : void {
40
- switch (hex.length) {
41
- case 1:
42
- case 5:
43
- case 6:
44
- return;
45
- case 2:
46
- hex = '#' + hex[1] + hex[1] + hex[1] + hex[1] + hex[1] + hex[1] + mintColor.hexMax;
47
- break;
48
- case 3:
49
- hex = '#' + hex[1] + hex[1] + hex[1] + hex[2] + hex[2] + hex[2] + mintColor.hexMax;
50
- break;
51
- case 4:
52
- hex = '#' + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3] + mintColor.hexMax;
53
- break;
54
- case 7:
55
- hex += mintColor.hexMax;
56
- break;
57
- case 8:
58
- hex += hex[hex.length - 1];
59
- break;
60
- default:
61
- hex = hex.substring(0, 9);
62
- }
63
-
64
- this.r = parseInt(hex.substring(1, 3), mintColor.hexBase);
65
- this.g = parseInt(hex.substring(3, 5), mintColor.hexBase);
66
- this.b = parseInt(hex.substring(5, 7), mintColor.hexBase);
67
- this.a = parseInt(hex.substring(7, 9), mintColor.hexBase) / mintColor.hexBase ** 2;
68
- }
69
-
70
- /**
71
- * Constructor from an rgba argument
72
- */
73
- protected rgbConstructor (rgb: string) : void {
74
- let match: RegExpMatchArray | null = rgb.match(/rgba?\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)?(?:, ?(\d(?:\.\d*)?)\))?/);
75
- if (match) {
76
- this.r = parseInt(match[1]);
77
- this.g = parseInt(match[2]);
78
- this.b = parseInt(match[3]);
79
- this.a = parseFloat(match[4]);
80
- }
81
- }
82
-
83
- /**
84
- * Returns the perceived brightness of the color
85
- */
86
- getBrightness () : number {
87
- if (this.a === 0) {
88
- return 262;
89
- }
90
- if (!isNaN(this.r) && !isNaN(this.g) && !isNaN(this.b)) {
91
- return Math.round((this.r * 299 + this.g * 587 + this.b * 144) / 1000);
92
- }
93
- return -1;
94
- }
95
- }
96
- export default mintColor;
1
+ /**
2
+ * Color
3
+ */
4
+ export class mintColor {
5
+ protected static hexBase: number = 16;
6
+ protected static hexMax: string = 'FF';
7
+ public r: number;
8
+ public g: number;
9
+ public b: number;
10
+ public a: number;
11
+
12
+ constructor (args: {[key: string]: number | string}) {
13
+ this.r = typeof args.r === 'number' ? Math.max(Math.min(args.r, mintColor.hexBase ** 2 - 1), 0) : 0;
14
+ this.g = typeof args.g === 'number' ? Math.max(Math.min(args.g, mintColor.hexBase ** 2 - 1), 0) : 0;
15
+ this.b = typeof args.b === 'number' ? Math.max(Math.min(args.b, mintColor.hexBase ** 2 - 1), 0) : 0;
16
+ this.a = typeof args.a === 'number' ? Math.max(Math.min(args.a, 1), 0) : 1;
17
+ if (typeof args.color === 'string') {
18
+ this.stringConstructor(args.color);
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Constructor from a string argument
24
+ */
25
+ protected stringConstructor (str: string) : void {
26
+ if (str.startsWith('#')) {
27
+ this.hexConstructor(str);
28
+ } else {
29
+ if (~str.indexOf('linear-gradient')) {
30
+ str = str.substring(str.indexOf('linear-gradient'), str.length);
31
+ }
32
+ this.rgbConstructor(str);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Constructor from a hex argument
38
+ */
39
+ protected hexConstructor (hex: string) : void {
40
+ switch (hex.length) {
41
+ case 1:
42
+ case 5:
43
+ case 6:
44
+ return;
45
+ case 2:
46
+ hex = '#' + hex[1] + hex[1] + hex[1] + hex[1] + hex[1] + hex[1] + mintColor.hexMax;
47
+ break;
48
+ case 3:
49
+ hex = '#' + hex[1] + hex[1] + hex[1] + hex[2] + hex[2] + hex[2] + mintColor.hexMax;
50
+ break;
51
+ case 4:
52
+ hex = '#' + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3] + mintColor.hexMax;
53
+ break;
54
+ case 7:
55
+ hex += mintColor.hexMax;
56
+ break;
57
+ case 8:
58
+ hex += hex[hex.length - 1];
59
+ break;
60
+ default:
61
+ hex = hex.substring(0, 9);
62
+ }
63
+
64
+ this.r = parseInt(hex.substring(1, 3), mintColor.hexBase);
65
+ this.g = parseInt(hex.substring(3, 5), mintColor.hexBase);
66
+ this.b = parseInt(hex.substring(5, 7), mintColor.hexBase);
67
+ this.a = parseInt(hex.substring(7, 9), mintColor.hexBase) / mintColor.hexBase ** 2;
68
+ }
69
+
70
+ /**
71
+ * Constructor from an rgba argument
72
+ */
73
+ protected rgbConstructor (rgb: string) : void {
74
+ let match: RegExpMatchArray | null = rgb.match(/rgba?\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)?(?:, ?(\d(?:\.\d*)?)\))?/);
75
+ if (match) {
76
+ this.r = parseInt(match[1]);
77
+ this.g = parseInt(match[2]);
78
+ this.b = parseInt(match[3]);
79
+ this.a = parseFloat(match[4]);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Returns the perceived brightness of the color
85
+ */
86
+ getBrightness () : number {
87
+ if (this.a === 0) {
88
+ return 262;
89
+ }
90
+ if (!isNaN(this.r) && !isNaN(this.g) && !isNaN(this.b)) {
91
+ return Math.round((this.r * 299 + this.g * 587 + this.b * 144) / 1000);
92
+ }
93
+ return -1;
94
+ }
95
+ }
96
+ export default mintColor;
@@ -1,7 +1,7 @@
1
- /**
2
- * Handles the display of elements
3
- */
4
- export abstract class mintDisplay {
5
-
6
- };
1
+ /**
2
+ * Handles the display of elements
3
+ */
4
+ export abstract class mintDisplay {
5
+
6
+ };
7
7
  export default mintDisplay;
@@ -1,7 +1,7 @@
1
- /**
2
- * Event helper functions
3
- */
4
- export abstract class mintEvent {
5
-
6
- };
7
- export default mintEvent;
1
+ /**
2
+ * Event helper functions
3
+ */
4
+ export abstract class mintEvent {
5
+
6
+ };
7
+ export default mintEvent;
@@ -1,19 +1,19 @@
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 shuffle (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
- export default mintList;
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 shuffle (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
+ export default mintList;
@@ -1,17 +1,17 @@
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
+ /**
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;
@@ -137,5 +137,48 @@ export abstract class mintObject {
137
137
  return obj;
138
138
  }, {});
139
139
  };
140
+
141
+ /**
142
+ * Update two sets of objects
143
+ * @param original - the original object
144
+ * @param update - the object to update the original with
145
+ * @returns - the original objects with updated data from the update
146
+ */
147
+ static updateArray (original: any[], update?: any[], key = 'id') : any {
148
+
149
+ // If there are no originals, push the updates
150
+ if (!update?.length) {
151
+ update?.forEach((object) => original.push(object));
152
+
153
+ // If there are existing objects
154
+ } else {
155
+
156
+ // Create a dictionary of the updated objects
157
+ const updateObjects = update.reduce<{ [key: string]: Object }>((objects, object) => ({
158
+ ...objects,
159
+ [object?.[key] ?? '']: object
160
+ }), {});
161
+
162
+ // Remove any objects that aren't in the updated objects
163
+ const missingObjects = original.filter((object) => !updateObjects[object?.[key] ?? '']);
164
+ missingObjects?.forEach((object) => {
165
+ const index = original.indexOf(object);
166
+ if (typeof index == 'number' && index !== -1) {
167
+ original.splice(index, 1);
168
+ }
169
+ });
170
+
171
+ // Update the existing objects with updates
172
+ original.forEach((object) => {
173
+ if (updateObjects[object?.[key] ?? '']) {
174
+ Object.assign(object, updateObjects[object?.[key] ?? '']);
175
+ }
176
+ });
177
+ }
178
+
179
+ // Push any new objects
180
+ const newObjects = update?.filter((object) => !original.some((existingObject) => existingObject?.[key] === object?.[key]));
181
+ newObjects?.forEach(newObject => original.push(newObject));
182
+ }
140
183
  };
141
184
  export default mintObject;
@@ -1,7 +1,7 @@
1
- /**
2
- * Functions related to the browser window.
3
- */
4
- export abstract class mintWindow {
5
-
6
- };
1
+ /**
2
+ * Functions related to the browser window.
3
+ */
4
+ export abstract class mintWindow {
5
+
6
+ };
7
7
  export default mintWindow;
package/src/ts/index.ts CHANGED
@@ -1,33 +1,33 @@
1
- /**
2
- * A library for building responsive web applications.
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- /**
8
- * Exports
9
- */
10
- // Enums
11
- export { mintSide } from './imports/enum';
12
-
13
- // Components
14
- export { mintHeader } from './imports/components/header';
15
-
16
- // Models
17
- export { mintColor } from './imports/models/color';
18
- export { mintItem } from './imports/models/item';
19
-
20
- // Utilities
21
- export { mintDisplay } from './imports/util/display';
22
- export { mintEvent } from './imports/util/event';
23
- export { mintIcon } from './imports/util/icon';
24
- export { mintList } from './imports/util/list';
25
- export { mintMath } from './imports/util/math';
26
- export { mintObject } from './imports/util/object';
27
- export { mintText } from './imports/util/text';
28
- export { mintWindow } from './imports/util/window';
29
-
30
- // Objects
31
- export { mintSelectors } from './imports/util/selectors';
32
- export { mintSettings } from './imports/util/settings';
33
- export { mintUtil, default } from './util';
1
+ /**
2
+ * A library for building responsive web applications.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ /**
8
+ * Exports
9
+ */
10
+ // Enums
11
+ export { mintSide } from './imports/enum';
12
+
13
+ // Components
14
+ export { mintHeader } from './imports/components/header';
15
+
16
+ // Models
17
+ export { mintColor } from './imports/models/color';
18
+ export { mintItem } from './imports/models/item';
19
+
20
+ // Utilities
21
+ export { mintDisplay } from './imports/util/display';
22
+ export { mintEvent } from './imports/util/event';
23
+ export { mintIcon } from './imports/util/icon';
24
+ export { mintList } from './imports/util/list';
25
+ export { mintMath } from './imports/util/math';
26
+ export { mintObject } from './imports/util/object';
27
+ export { mintText } from './imports/util/text';
28
+ export { mintWindow } from './imports/util/window';
29
+
30
+ // Objects
31
+ export { mintSelectors } from './imports/util/selectors';
32
+ export { mintSettings } from './imports/util/settings';
33
+ export { mintUtil, default } from './util';