@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.
@@ -1,185 +0,0 @@
1
- /**
2
- * CSS-selector helpers
3
- * @public
4
- */
5
- export abstract class MintSelectors {
6
- /**
7
- * The library name that will be added as a prefix
8
- */
9
- static lib: string = 'mint';
10
-
11
- /**
12
- * The prefix built from the library name
13
- */
14
- static pre: string = `${this.lib}-`;
15
-
16
- /**
17
- * CSS-selector for disabled elements
18
- */
19
- static disabled: string = '[disabled]';
20
-
21
- /**
22
- * CSS-selector for elements with an aria-controls attribute
23
- */
24
- static hasControls: string = '[aria-controls]';
25
-
26
- /**
27
- * CSS-selector for elements with an aria-expanded attribute
28
- */
29
- static hasExpanded: string = '[aria-expanded]';
30
-
31
- /**
32
- * CSS-selector for elements with an href attribute
33
- */
34
- static hasLink: string = '[href]';
35
-
36
- /**
37
- * CSS-selector for elements with a routerLink attribute
38
- */
39
- static hasRouterLink: string = '[routerLink]';
40
-
41
- /**
42
- * CSS-selector for elements with an id attribute
43
- */
44
- static hasId: string = '[id]';
45
-
46
- /**
47
- * CSS-selector for elements that aren't tabbable (i.e. tabindex is negative)
48
- */
49
- static notTabbable: string = '[tabindex^="-"]';
50
-
51
- /**
52
- * CSS-selector for elements that are tabbable (i.e. tabindex isn't negative)
53
- */
54
- static tabbable: string = `[tabindex]${this.neg(this.notTabbable)}`;
55
-
56
- /**
57
- * CSS-selector for elements that can receive focus
58
- */
59
- static focusable: string = `input${this.neg(this.disabled)}${this.neg(this.notTabbable)},
60
- select${this.neg(this.disabled)}${this.neg(this.notTabbable)},
61
- textarea${this.neg(this.disabled)}${this.neg(this.notTabbable)},
62
- button${this.neg(this.disabled)}${this.neg(this.notTabbable)},
63
- object${this.neg(this.disabled)}${this.neg(this.notTabbable)},
64
- a${this.hasLink}, a${this.hasRouterLink},
65
- area${this.hasLink},
66
- ${this.tabbable}`.replace(/\s/g, '');
67
-
68
- /**
69
- * CSS-selector for submenu buttons
70
- */
71
- static subMenuButtons: string = `button${this.hasControls}`;
72
-
73
- /**
74
- * CSS-selector for submenus
75
- */
76
- static subMenu: string = `${this.subMenuButtons} + ul${this.hasId}`;
77
-
78
- /**
79
- * Adds the library prefix to the beginning of the provided string
80
- * @param base - the string to be prefixed
81
- * @returns - the provided string prefixed with the library name
82
- */
83
- static prefix (base: string) : string {
84
- base = base.toLowerCase();
85
- return base.startsWith(this.pre) ? base : `${this.pre}${base}`;
86
- }
87
-
88
- /**
89
- * Adds two dashes to the beginning of the provided string
90
- * @param base - the string to be prefixed
91
- * @returns - the provided string prefixed with two dashes
92
- */
93
- static cssPrefix (base: string) : string {
94
- return `--${this.prefix(base.replace(/^-+/, ''))}`;
95
- }
96
-
97
- /**
98
- * Turns the provided string into a CSS variable call
99
- * @param base - the name of the CSS variable to call
100
- * @returns - the CSS variable call for the provided string
101
- */
102
- static cssVar (base: string) : string {
103
- return `var(${this.cssPrefix(base)})`;
104
- }
105
-
106
- /**
107
- * Negates the provided CSS selector
108
- * @param base - the CSS selector to negate
109
- * @returns - the negated CSS selector
110
- */
111
- static neg (base: string) : string {
112
- return `:not(${base})`;
113
- }
114
-
115
- /**
116
- * Generates a class CSS selector
117
- * @param base - the name of the class to generate
118
- * @returns - the generated CSS selector
119
- */
120
- static class (base: string) : string {
121
- return `.${this.prefix(base)}`;
122
- }
123
-
124
- /**
125
- * Generates an id CSS selector
126
- * @param base - the name of the id to generate
127
- * @returns - the generated CSS selector
128
- */
129
- static id (base: string) : string {
130
- return `#${this.prefix(base)}`;
131
- }
132
-
133
- /**
134
- * Generates an aria-controls CSS selector
135
- * @param id - the id of the controlled element
136
- * @returns - the generated CSS selector
137
- */
138
- static controls (id?: string | null) : string {
139
- return id ? `[aria-controls="${this.prefix(id)}"]` : this.hasControls;
140
- }
141
-
142
- /**
143
- * Generates an aria-expanded CSS selector
144
- * @param bool - whether the element is expanded or not
145
- * @returns - the generated CSS selector
146
- */
147
- static expanded (bool?: boolean | null) : string {
148
- return typeof bool === 'boolean' ? `[aria-expanded="${bool}"]` : this.hasExpanded;
149
- }
150
-
151
- /**
152
- * Returns a NodeList of HTMLElements within the given element that are focusable
153
- * @param el - the element whose focusable children will be returned
154
- * @returns - the elements within the given element that are focusable
155
- */
156
- static getFocusables (el?: HTMLElement) : HTMLElement[] {
157
- let focusables: HTMLElement[];
158
- if (el) {
159
- focusables = Array.from(el.querySelectorAll<HTMLElement>(this.focusable));
160
- } else {
161
- focusables = Array.from(document.querySelectorAll<HTMLElement>(this.focusable));
162
- }
163
- return focusables.filter((el: HTMLElement) => this.isFocusable(el));
164
- }
165
-
166
- /**
167
- * Returns true if an element is focusable and false if not,
168
- * based on styles (i.e. a parent has display: none;)
169
- * NOTE: Still need to determine what other styles may make an element un-focusable
170
- * @param el - the element
171
- * @returns - true if the element is focusable; false if not
172
- */
173
- static isFocusable (el: HTMLElement) : boolean {
174
- let current: HTMLElement | null = el;
175
-
176
- do {
177
- if (window.getComputedStyle(current).getPropertyValue('display').toLowerCase() === 'none') {
178
- return false;
179
- }
180
- current = current.parentElement;
181
- } while (current);
182
- return true;
183
- }
184
- };
185
- export default MintSelectors;
@@ -1,85 +0,0 @@
1
- /**
2
- * Settings management
3
- * @public
4
- */
5
- export abstract class MintSettings {
6
- /**
7
- * Value added to all delay variables
8
- */
9
- static delayBase: number = 0;
10
-
11
- /**
12
- * Value multiplied by delay variable index
13
- */
14
- static delayStep: number = 100;
15
-
16
- /**
17
- * Delay variables
18
- */
19
- static delay: {[key: string]: number} = {
20
- instant: this.delayBase + this.delayStep * 0,
21
- fast: this.delayBase + this.delayStep * 1,
22
- medFast: this.delayBase + this.delayStep * 2,
23
- default: this.delayBase + this.delayStep * 3,
24
- medSlow: this.delayBase + this.delayStep * 4,
25
- slow: this.delayBase + this.delayStep * 5
26
- };
27
-
28
- /**
29
- * Breakpoint variables
30
- */
31
- static break: {[key: string]: number} = {
32
- z: 0,
33
- xs: 480,
34
- sm: 768,
35
- md: 1024,
36
- lg: 1200,
37
- xl: 1440
38
- };
39
-
40
- /**
41
- * Update the provided settings variables
42
- * @param settings - Object of settings variables to update
43
- */
44
- static set (settings: {[key: string]: any}) : void {
45
- let newDelay: boolean = false;
46
- if (typeof settings.delayBase === 'number') {
47
- this.delayBase = settings.delayBase;
48
- newDelay = true;
49
- }
50
- if (typeof settings.delayStep === 'number') {
51
- this.delayStep = settings.delayStep;
52
- newDelay = true;
53
- }
54
- if (newDelay) {
55
- this.setDelay();
56
- }
57
-
58
- if (settings.delay && Object.keys(settings.delay).length) {
59
- if (Object.values(settings.delay).reduce((prev: any, next: any) => prev && typeof next === 'number', true)) {
60
- this.delay = {...this.delay, ...settings.delay};
61
- }
62
- }
63
-
64
- if (settings.break && Object.keys(settings.break).length) {
65
- if (Object.values(settings.break).reduce((prev: any, next: any) => prev && typeof next === 'number', true)) {
66
- this.break = {...this.break, ...settings.break};
67
- }
68
- }
69
- }
70
-
71
- /**
72
- * Updates the delay variables based on `this.delayBase` and `this.delayStep`
73
- */
74
- protected static setDelay () : void {
75
- this.delay = {
76
- instant: this.delayBase + this.delayStep * 0,
77
- fast: this.delayBase + this.delayStep * 1,
78
- medFast: this.delayBase + this.delayStep * 2,
79
- default: this.delayBase + this.delayStep * 3,
80
- medSlow: this.delayBase + this.delayStep * 4,
81
- slow: this.delayBase + this.delayStep * 5
82
- };
83
- }
84
- };
85
- export default MintSettings;
@@ -1,151 +0,0 @@
1
- /**
2
- * Functions for analyzing and manipulating text.
3
- */
4
- export abstract class MintText {
5
-
6
- /**
7
- * Generate a slug from a string
8
- * @param text - The string to slugify
9
- * @returns The slugified string
10
- */
11
- static slug (text?: string): string {
12
- return text?.trim()
13
- .toLowerCase()
14
- .replace(/'/g, '')
15
- .replace(/[^\w/-]+/g, '-')
16
- .replace(/-+/g, '-')
17
- .replace(/^-+|-+$/g, '')
18
- .replace(/^\/+|\/+$/g, '') ?? '';
19
- }
20
-
21
- /**
22
- * Generate a title from a slug
23
- * @param slug - The slug to generate a title from
24
- * @returns The title
25
- */
26
- static unslug (slug: string): string {
27
- return this.titleCase(slug.replace(/[-/]+/g, ' '));
28
- }
29
-
30
- /**
31
- * Format a phone number
32
- * @param phone - The phone number to format
33
- * @returns The formatted phone number
34
- */
35
- static phone (phone?: string | number): string {
36
- const given = phone?.toString().trim() ?? '';
37
- if (given === '(' || given === '') {
38
- return given;
39
- }
40
-
41
- let numbers = given.replace(/\D/g, '') ?? '',
42
- formatted = '';
43
-
44
- if (numbers.length > 10) {
45
- formatted += `+${numbers.slice(0, numbers.length - 10)} `;
46
- numbers = numbers.slice(numbers.length - 10);
47
- }
48
-
49
- for (var i = 0; i < numbers.length; i++) {
50
- switch (i) {
51
- case 0:
52
- formatted += '(';
53
- break;
54
- case 3:
55
- formatted += ') ';
56
- break;
57
- case 6:
58
- formatted += '-';
59
- break;
60
- }
61
- formatted += numbers[i];
62
- }
63
-
64
- switch (given[given.length - 1]) {
65
- case ')':
66
- if (i === 3) {
67
- formatted += ') ';
68
- }
69
- break;
70
- case '-':
71
- if (i === 6) {
72
- formatted += '-';
73
- }
74
- break;
75
- }
76
-
77
- return formatted;
78
- }
79
-
80
- /**
81
- * Pluralize the given word
82
- */
83
- static plural (word: string): string {
84
- if (word.endsWith('ies') ||
85
- word.endsWith('es') ||
86
- (word.endsWith('s') && !word.endsWith('us') && !word.endsWith('is') && !word.endsWith('ss'))) {
87
- return word;
88
- }
89
-
90
- if (word.endsWith('y') && !['a', 'e', 'i', 'o', 'u'].includes(word.charAt(word.length - 2))) {
91
- return word.slice(0, -1) + 'ies';
92
- }
93
-
94
- if (word.endsWith('s') || word.endsWith('sh') || word.endsWith('ch') || word.endsWith('x') || word.endsWith('z')) {
95
- return word + 'es';
96
- }
97
-
98
- return word + 's';
99
- }
100
-
101
- /**
102
- * Capitalize the first letter of the given word
103
- */
104
- static titleCase (text: string): string {
105
- return text
106
- .toLowerCase()
107
- .replace(/(?:^|\s)\S/g, a => a.toUpperCase());
108
- }
109
-
110
- /**
111
- * Copies the provided text to the clipboard
112
- * @param text - the text to copy
113
- * @returns - true if the text was successfully copied to the clipboard; else false
114
- */
115
- static copyText (text: string) : boolean {
116
- let textArea: HTMLTextAreaElement = document.createElement('textarea');
117
-
118
- if (!text || !textArea) {
119
- return false;
120
- }
121
-
122
- textArea.value = text;
123
- textArea.style.cssText = `
124
- position: fixed;
125
- top: 0;
126
- left: 0;
127
- transform: translate(-100%, -100%);
128
- opacity: 0;
129
- z-index: -1;
130
- `;
131
-
132
- document.body.appendChild(textArea);
133
- textArea.select();
134
- textArea.setSelectionRange(0, 99999);
135
- navigator.clipboard.writeText(textArea.value);
136
- document.body.removeChild(textArea);
137
-
138
- return true;
139
- }
140
-
141
- /**
142
- * Tests the validity of an email address
143
- * @see {@link https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression}
144
- * @param text - the string to test
145
- * @returns - true if the given string is an email address; false if not
146
- */
147
- static isEmail (text: string) : boolean {
148
- return null !== text.match(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/);
149
- }
150
- };
151
- export default MintText;
@@ -1,14 +0,0 @@
1
- /**
2
- * Functions related to the browser window.
3
- */
4
- export abstract class MintWindow {
5
- /**
6
- * Returns the width of the window, including fractional pixels
7
- * @returns the width of the window
8
- */
9
- static width () : number {
10
- const decimal: number = document.body.getBoundingClientRect().width % 1;
11
- return window.innerWidth + decimal;
12
- }
13
- };
14
- export default MintWindow;
package/src/ts/index.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * A library for building responsive web applications.
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- /**
8
- * Exports
9
- */
10
- export * from './imports';