@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appartmint/mint",
3
3
  "author": "App Art Mint LLC",
4
- "version": "1.2.12",
4
+ "version": "1.3.1",
5
5
  "license": "MIT",
6
6
  "description": "The front-end TS/SCSS framework of App Art Mint",
7
7
  "keywords": [
@@ -19,10 +19,11 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/App-Art-Mint/npm-mint/issues"
21
21
  },
22
- "main": "src/ts/index.ts",
22
+ "main": "dist/js/index.min.js",
23
+ "types": "dist/js/index.d.ts",
23
24
  "type": "module",
24
25
  "files": [
25
- "src/**/*.{ts,scss}",
26
+ "src/**/*.scss",
26
27
  "dist/**/*.{css,js,d.ts,map}"
27
28
  ],
28
29
  "directories": {
@@ -1,408 +0,0 @@
1
- /**
2
- * Imports
3
- */
4
- import { EMintSide } from '../enums';
5
- import {
6
- MintDisplay,
7
- MintEvent,
8
- MintSelectors,
9
- MintSettings,
10
- MintWindow
11
- } from '../util';
12
-
13
-
14
- /**
15
- * Main header functionality
16
- * @public
17
- */
18
- export class MintHeader {
19
- /**
20
- * Navbar settings
21
- */
22
- settings: {[key: string]: any} = {
23
- from: EMintSide.Top,
24
- fixed: true
25
- };
26
-
27
- /**
28
- * Frequently-referenced elements
29
- */
30
- el: {[key: string]: HTMLElement | null} = {};
31
-
32
- /**
33
- * Initializes and closes the menu
34
- */
35
- constructor (settings?: {[key: string]: any}) {
36
- this.settings = {...this.settings, ...settings};
37
-
38
- this.attachElements();
39
- this.attachEvents();
40
- this.addClasses();
41
- }
42
-
43
- /**
44
- * Adds elements to {@link el | `this.el`}
45
- */
46
- attachElements () : void {
47
- this.el.html = document.querySelector('html');
48
- this.el.body = document.querySelector('body');
49
- this.el.header = document.getElementById('mint-header');
50
- this.el.mobileButton = this.el.header?.querySelector(MintSelectors.controls('mint-wrapper')) || null;
51
- this.el.wrapper = document.getElementById('mint-wrapper');
52
- }
53
-
54
- /**
55
- * Adds events to the dom
56
- */
57
- attachEvents () : void {
58
- window.addEventListener('resize', MintEvent.throttleEvent(this.eHandleResize.bind(this), MintSettings.delay.default));
59
- window.addEventListener('scroll', MintEvent.throttleEvent(this.eHandleScroll.bind(this), MintSettings.delay.default, { trailing: false }));
60
-
61
- let focusables = this.el.header?.querySelectorAll(MintSelectors.focusable),
62
- lastFocusable = focusables?.[focusables?.length - 1];
63
- lastFocusable?.addEventListener('keydown', MintEvent.throttleEvent(this.eWrapTab.bind(this)));
64
- focusables?.forEach((focusable) => {
65
- focusable.addEventListener('keydown', MintEvent.throttleEvent(this.eHandleKeypress.bind(this)));
66
- });
67
-
68
- let menuButtons = this.el.wrapper?.querySelectorAll(MintSelectors.controls());
69
- menuButtons?.forEach((menuButton) => {
70
- menuButton.addEventListener('click', MintEvent.throttleEvent(this.eToggleMenu.bind(this), MintSettings.delay.slow, { trailing: false }));
71
- });
72
-
73
- this.el.mobileButton?.addEventListener('click', MintEvent.throttleEvent(this.eToggleMobileMenu.bind(this), MintSettings.delay.slow, { trailing: false }));
74
- this.el.wrapper?.addEventListener('transitionend', this.eTransitionEnd.bind(this));
75
- }
76
-
77
- /**
78
- * Adds classes that inform the styles based on settings
79
- */
80
- addClasses () : void {
81
- this.el.header?.classList.remove('mint-top', 'mint-right', 'mint-bottom', 'mint-left');
82
- this.el.header?.classList.add(`mint-${EMintSide[this.settings.from ?? 0].toLowerCase()}`);
83
-
84
- if (this.settings.fixed) {
85
- this.el.body?.classList.add('mint-fixed');
86
- }
87
- if (this.settings.tray) {
88
- this.el.header?.classList.add('mint-tray');
89
- }
90
- }
91
-
92
- /**
93
- * Sets the state of the mobile menu
94
- * @param open - `true` to open the menu or `false` to close it
95
- */
96
- setMobileMenu (open: boolean = false) : void {
97
- let ariaExpanded: string = open ? 'true' : 'false',
98
- ariaLabel: string = open ? 'close menu' : 'open menu';
99
-
100
- this.el.mobileButton?.setAttribute('aria-expanded', ariaExpanded);
101
- setTimeout(() => {
102
- this.el.mobileButton?.setAttribute('aria-label', ariaLabel);
103
- }, MintSettings.delay.fast);
104
-
105
- if (open) {
106
- if (this.settings.fixed !== true) {
107
- window.scroll({
108
- top: 0,
109
- left: 0,
110
- behavior: 'smooth'
111
- });
112
- }
113
-
114
- setTimeout(() => {
115
- if (this.el.html) {
116
- let isMobile = MintWindow.width() <= MintSettings.break.sm,
117
- overflow = 'auto';
118
-
119
- if (this.settings.tray) {
120
- if (isMobile) {
121
- overflow = 'hidden';
122
- }
123
- } else {
124
- overflow = 'hidden';
125
- }
126
- this.el.html.style.overflow = overflow;
127
- }
128
- }, this.settings.from === EMintSide.Left ? MintSettings.delay.default : MintSettings.delay.instant);
129
-
130
- if (this.el.wrapper) {
131
- this.el.wrapper.style.display = 'flex';
132
- }
133
-
134
- requestAnimationFrame(() => {
135
- this.el.wrapper?.classList.add('mint-open');
136
- });
137
- } else {
138
- if (this.el.html) {
139
- this.el.html.style.overflow = 'auto';
140
- }
141
-
142
- requestAnimationFrame(() => {
143
- this.el.wrapper?.classList.remove('mint-open');
144
- });
145
-
146
- this.closeAllMenus();
147
- }
148
- }
149
-
150
- /**
151
- * Toggles the state of the mobile menu
152
- */
153
- toggleMobileMenu () : void {
154
- this.setMobileMenu(this.el.mobileButton?.getAttribute('aria-expanded')?.toLowerCase() === 'false');
155
- }
156
-
157
- /**
158
- * Sets the state of the provided button's menu
159
- * @param button - Button element to set
160
- * @param open - `true` to open the menu or `false` to close it
161
- */
162
- setMenu (button?: HTMLElement | null,
163
- open: boolean = false) : void {
164
- let ariaExpanded: string = open ? 'true' : 'false',
165
- menu: HTMLElement | null = button?.nextElementSibling as HTMLElement | null;
166
- if (button && menu) {
167
- button.setAttribute('aria-expanded', ariaExpanded);
168
- if (open) {
169
- MintDisplay.show(menu);
170
- } else {
171
- MintDisplay.hide(menu);
172
- this.closeSubMenus(button);
173
- }
174
- }
175
- }
176
-
177
- /**
178
- * Toggles the state of the provided button's menu
179
- * @param button - Button element to toggle
180
- */
181
- toggleMenu (button?: HTMLElement | null) : void {
182
- this.setMenu(button, button?.getAttribute('aria-expanded')?.toLowerCase() !== 'true');
183
- }
184
-
185
- /**
186
- * Closes all submenus of the provided button's menu
187
- * @param button - Button element of the parent menu
188
- */
189
- closeSubMenus (button?: HTMLElement | null) : void {
190
- let menu: HTMLElement | null | undefined = button?.nextElementSibling as HTMLElement,
191
- subMenus: NodeListOf<HTMLElement> = menu?.querySelectorAll(MintSelectors.subMenuButtons) as NodeListOf<HTMLElement>;
192
- subMenus.forEach((child: HTMLElement) => {
193
- // setMenu calls this function, so ignore subsub menus
194
- if (child.parentElement?.parentElement === menu) {
195
- this.setMenu(child);
196
- }
197
- });
198
- }
199
-
200
- /**
201
- * Closes all sibling menus of the provided button's menu
202
- * @param button - Button element of the sibling menus
203
- */
204
- closeSiblingMenus (button?: HTMLElement | null) : void {
205
- let menu: HTMLElement | null | undefined = button?.parentElement as HTMLElement,
206
- siblingMenus: NodeListOf<HTMLElement> = menu?.parentElement?.querySelectorAll(MintSelectors.subMenuButtons) as NodeListOf<HTMLElement>;
207
- siblingMenus.forEach((child: HTMLElement) => {
208
- if (child !== button) {
209
- this.setMenu(child);
210
- }
211
- });
212
- }
213
-
214
- /**
215
- * Closes all submenus of the n4vbar
216
- */
217
- closeAllMenus () : void {
218
- let menuButtons: NodeListOf<HTMLElement> | undefined = this.el.wrapper?.querySelectorAll(MintSelectors.subMenuButtons);
219
- menuButtons?.forEach((menuButton: HTMLElement) => {
220
- this.setMenu(menuButton);
221
- });
222
- }
223
-
224
- /**
225
- * Opens the menu closest to the document's focus
226
- */
227
- openClosestMenu () : void {
228
- let activeButton: HTMLElement | null = document.activeElement as HTMLElement | null,
229
- activeMenu: HTMLElement | null = activeButton?.nextElementSibling as HTMLElement | null,
230
- showing: boolean = activeButton?.getAttribute('aria-expanded')?.toLowerCase() === 'true';
231
- if (activeButton?.getAttribute('aria-controls') === 'mint-wrapper') {
232
- activeMenu = this.el.wrapper;
233
- }
234
-
235
- if (activeButton?.getAttribute('aria-controls') && activeMenu && !showing) {
236
- activeButton.click();
237
- let firstFocusable: HTMLElement | null = activeMenu.querySelector(MintSelectors.focusable);
238
- firstFocusable?.focus();
239
- }
240
- }
241
-
242
- /**
243
- * Closes the menu closest to the document's focus
244
- */
245
- closeClosestMenu () : void {
246
- let activeElement: HTMLElement | null = document.activeElement as HTMLElement | null,
247
- activeMenu: HTMLElement | null = activeElement?.closest(MintSelectors.subMenu) as HTMLElement | null,
248
- activeButton: HTMLElement | null = activeMenu?.previousElementSibling ? activeMenu.previousElementSibling as HTMLElement : this.el.mobileButton;
249
- if (activeElement?.getAttribute('aria-controls') && activeElement?.getAttribute('aria-expanded')?.toLowerCase() === 'true') {
250
- activeButton = activeElement;
251
- }
252
-
253
- if (activeButton?.getAttribute('aria-expanded')?.toLowerCase() === 'true') {
254
- activeButton?.click();
255
- activeButton?.focus();
256
- }
257
- }
258
-
259
- /**
260
- * Toggles the menu closest to the document's focus
261
- */
262
- toggleClosestMenu () : void {
263
- if (document.activeElement?.getAttribute('aria-expanded')?.toLowerCase() === 'true') {
264
- this.closeClosestMenu();
265
- } else {
266
- this.openClosestMenu();
267
- }
268
- }
269
-
270
- /**
271
- * Closes the mobile menu when the window resizes
272
- */
273
- eHandleResize () : void {
274
- let isOpen = this.el.mobileButton?.getAttribute('aria-expanded')?.toLowerCase() === 'true',
275
- isMobile = MintWindow.width() <= MintSettings.break.sm,
276
- overflow = 'auto';
277
-
278
- if (isOpen) {
279
- if (this.settings.tray) {
280
- if (isMobile) {
281
- overflow = 'hidden';
282
- }
283
- } else {
284
- overflow = 'hidden';
285
- }
286
- }
287
-
288
- if (this.el.html) {
289
- this.el.html.style.overflow = overflow;
290
- }
291
- }
292
-
293
- /**
294
- * Closes all submenus when the page is scrolled
295
- */
296
- eHandleScroll () : void {
297
- this.closeAllMenus();
298
- }
299
-
300
- /**
301
- * Sends the focus to the menu button after tabbing past the last menu item
302
- * @param e - Keyboard event
303
- */
304
- eWrapTab (e: KeyboardEvent) : void {
305
- if (e.key.toLowerCase() === 'tab' && !e.shiftKey) {
306
- this.el.mobileButton?.focus();
307
- if (document.activeElement === this.el.mobileButton) {
308
- e.preventDefault();
309
- }
310
- }
311
- }
312
-
313
- /**
314
- * Handles keypresses on n4vbar buttons
315
- * @param e - Keyboard event
316
- */
317
- eHandleButtonKeypress (e: KeyboardEvent) : void {
318
- let target = e.target as HTMLElement | null,
319
- subMenu = target?.closest('li');
320
- switch (e.key.toLowerCase()) {
321
- case 'escape':
322
- if (subMenu?.classList.contains('mint-open')) {
323
- this.setMenu(subMenu);
324
- } else {
325
- this.setMobileMenu();
326
- this.el.menuButton?.focus();
327
- }
328
- break;
329
- case 'arrowleft':
330
- this.closeClosestMenu();
331
- break;
332
- case 'arrowright':
333
- this.openClosestMenu();
334
- break;
335
- case 'enter':
336
- case 'space':
337
- target?.click();
338
- break;
339
- }
340
- }
341
-
342
- /**
343
- * Handles keypresses on n4vbar links
344
- * @param e - Keyboard event
345
- */
346
- eHandleLinkKeypress (e: KeyboardEvent) : void {
347
- let target = e.target as HTMLElement | null;
348
- switch (e.key.toLowerCase()) {
349
- case 'escape':
350
- case 'arrowleft':
351
- this.closeClosestMenu();
352
- break;
353
- case 'arrowright':
354
- this.openClosestMenu();
355
- break;
356
- case 'enter':
357
- case 'space':
358
- target?.click();
359
- break;
360
- }
361
- }
362
-
363
- /**
364
- * Handles keypresses on the n4vbar
365
- * @param e - Keyboard event
366
- */
367
- eHandleKeypress (e: KeyboardEvent) : void {
368
- if (e.key.toLowerCase() !== 'tab') {
369
- e.preventDefault();
370
- }
371
- const target = e.target as HTMLElement | null;
372
- switch (target?.tagName.toLowerCase()) {
373
- case 'a':
374
- this.eHandleLinkKeypress(e);
375
- break;
376
- case 'button':
377
- this.eHandleButtonKeypress(e);
378
- break;
379
- }
380
- }
381
-
382
- /**
383
- * Toggles the mobile menu
384
- */
385
- eToggleMobileMenu () : void {
386
- this.toggleMobileMenu();
387
- }
388
-
389
- /**
390
- * Toggles the clicked submenu
391
- * @param e - Mouse event
392
- */
393
- eToggleMenu (e: MouseEvent) : void {
394
- let target = e.target as HTMLElement | null;
395
- this.closeSiblingMenus(target);
396
- this.toggleMenu(target);
397
- }
398
-
399
- /**
400
- * Runs after the mobile menu transitions
401
- */
402
- eTransitionEnd () : void {
403
- if (this.el.wrapper?.classList.contains('mint-open') === false ) {
404
- this.el.wrapper.style.display = 'none';
405
- }
406
- };
407
- };
408
- export default MintHeader;
@@ -1,4 +0,0 @@
1
- /**
2
- * Forward all exports from the components directory
3
- */
4
- export * from './header';
@@ -1,4 +0,0 @@
1
- /**
2
- * Forward all exports from the enums directory
3
- */
4
- export * from './side';
@@ -1,9 +0,0 @@
1
- /**
2
- * Side Enum
3
- */
4
- export enum EMintSide {
5
- Top,
6
- Right,
7
- Bottom,
8
- Left
9
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * Forward all exports from the imports directory
3
- */
4
- export * from './components';
5
- export * from './enums';
6
- export * from './models';
7
- export * from './util';
@@ -1,96 +0,0 @@
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,16 +0,0 @@
1
- /**
2
- * File model for Amplify Storage
3
- */
4
- export interface IMintFile {
5
- path?: string;
6
- eTag?: string;
7
- lastModified?: string;
8
- size?: number;
9
- progress?: number;
10
- error?: boolean;
11
- fetched?: boolean;
12
- empty?: boolean;
13
- files?: { [key: string]: IMintFile }
14
- metadata?: { [key: string]: string }
15
- }
16
- export default IMintFile;
@@ -1,9 +0,0 @@
1
- /**
2
- * Forward all exports from the models directory
3
- */
4
- export * from './color';
5
- export * from './file';
6
- export * from './item';
7
- export * from './minify';
8
- export * from './page';
9
- export * from './recaptcha';
@@ -1,72 +0,0 @@
1
- /**
2
- * A generic item
3
- * @note - this class must be convertable with JSON
4
- * - only add strings, numbers, booleans, arrays, and objects
5
- */
6
- export class MintItem {
7
- /**
8
- * Item settings
9
- */
10
- version?: number = 0;
11
- priority?: number = 0;
12
- price?: number = 0;
13
- level?: number = 0;
14
- size?: number = 0;
15
- num?: number = 0;
16
- width?: number = 0;
17
- height?: number = 0;
18
-
19
- active?: boolean = false;
20
- centered?: boolean = false;
21
- disabled?: boolean = false;
22
- private?: boolean = false;
23
-
24
- /**
25
- * Item properties
26
- */
27
- id?: string;
28
- slug?: string;
29
- name?: string;
30
- title?: string;
31
- subtitle?: string;
32
- description?: string;
33
- category?: string;
34
- type?: string;
35
- unit?: string;
36
- logo?: MintItem;
37
- icon?: string;
38
- position?: string;
39
- transform?: string;
40
- date?: string;
41
-
42
- /**
43
- * Item links
44
- */
45
- src?: string;
46
- href?: string;
47
- target?: string;
48
- routerLink?: string[];
49
-
50
- /**
51
- * Item data
52
- */
53
- attr?: { [key: string]: string } = {};
54
- params?: { [key: string]: string } = {};
55
- options?: { [key: string]: string } = {};
56
- lists?: { [key: string]: string[] } = {};
57
-
58
- /**
59
- * Item lists
60
- */
61
- paragraphs?: string[] = [];
62
- classes?: string[] = [];
63
- items?: MintItem[] = [];
64
- images?: MintItem[] = [];
65
- buttons?: MintItem[] = [];
66
-
67
- /**
68
- * Item functions
69
- */
70
- click?: Function;
71
- };
72
- export default MintItem;
@@ -1,11 +0,0 @@
1
- /**
2
- * Minify Interface
3
- */
4
- export interface IMintMinify {
5
- url: string,
6
- format?: string[],
7
- method?: string,
8
- width?: number,
9
- height?: number
10
- }
11
- export default IMintMinify;
@@ -1,19 +0,0 @@
1
- /**
2
- * Imports
3
- */
4
- import MintItem from "./item";
5
-
6
-
7
- /**
8
- * Page Interface
9
- */
10
- export interface IMintPage {
11
- slug: string;
12
- title?: string;
13
- description?: string;
14
- image?: string;
15
- items?: MintItem[];
16
- createdAt?: string;
17
- updatedAt?: string;
18
- }
19
- export default IMintPage;
@@ -1,8 +0,0 @@
1
- /**
2
- * Recaptcha Interface
3
- */
4
- export interface IMintRecaptcha {
5
- token: string;
6
- action: string;
7
- };
8
- export default IMintRecaptcha;