@maz-ui/utils 4.0.0-beta.0

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/dist/formatters/camelCase.js +6 -0
  3. package/dist/formatters/capitalize.js +6 -0
  4. package/dist/formatters/formatCurrency.js +34 -0
  5. package/dist/formatters/formatDate.js +21 -0
  6. package/dist/formatters/formatNumber.js +23 -0
  7. package/dist/formatters/formatPhoneNumber.js +10 -0
  8. package/dist/formatters/index.js +14 -0
  9. package/dist/formatters/pascalCase.js +8 -0
  10. package/dist/index.js +54 -0
  11. package/dist/types/formatters/camelCase.d.ts +2 -0
  12. package/dist/types/formatters/camelCase.d.ts.map +1 -0
  13. package/dist/types/formatters/capitalize.d.ts +2 -0
  14. package/dist/types/formatters/capitalize.d.ts.map +1 -0
  15. package/dist/types/formatters/formatCurrency.d.ts +5 -0
  16. package/dist/types/formatters/formatCurrency.d.ts.map +1 -0
  17. package/dist/types/formatters/formatDate.d.ts +2 -0
  18. package/dist/types/formatters/formatDate.d.ts.map +1 -0
  19. package/dist/types/formatters/formatNumber.d.ts +2 -0
  20. package/dist/types/formatters/formatNumber.d.ts.map +1 -0
  21. package/dist/types/formatters/formatPhoneNumber.d.ts +2 -0
  22. package/dist/types/formatters/formatPhoneNumber.d.ts.map +1 -0
  23. package/dist/types/formatters/index.d.ts +7 -0
  24. package/dist/types/formatters/index.d.ts.map +1 -0
  25. package/dist/types/formatters/pascalCase.d.ts +2 -0
  26. package/dist/types/formatters/pascalCase.d.ts.map +1 -0
  27. package/dist/types/index.d.ts +4 -0
  28. package/dist/types/index.d.ts.map +1 -0
  29. package/dist/types/ts-helpers/DeepKeyOf.d.ts +4 -0
  30. package/dist/types/ts-helpers/DeepKeyOf.d.ts.map +1 -0
  31. package/dist/types/ts-helpers/DeepPartial.d.ts +4 -0
  32. package/dist/types/ts-helpers/DeepPartial.d.ts.map +1 -0
  33. package/dist/types/ts-helpers/FlattenObjectKeys.d.ts +4 -0
  34. package/dist/types/ts-helpers/FlattenObjectKeys.d.ts.map +1 -0
  35. package/dist/types/ts-helpers/InferMaybeRef.d.ts +3 -0
  36. package/dist/types/ts-helpers/InferMaybeRef.d.ts.map +1 -0
  37. package/dist/types/ts-helpers/index.d.ts +5 -0
  38. package/dist/types/ts-helpers/index.d.ts.map +1 -0
  39. package/dist/types/utils/TextareaAutogrow.d.ts +10 -0
  40. package/dist/types/utils/TextareaAutogrow.d.ts.map +1 -0
  41. package/dist/types/utils/checkAvailability.d.ts +8 -0
  42. package/dist/types/utils/checkAvailability.d.ts.map +1 -0
  43. package/dist/types/utils/countryCodeToUnicodeFlag.d.ts +2 -0
  44. package/dist/types/utils/countryCodeToUnicodeFlag.d.ts.map +1 -0
  45. package/dist/types/utils/debounce.d.ts +2 -0
  46. package/dist/types/utils/debounce.d.ts.map +1 -0
  47. package/dist/types/utils/debounceCallback.d.ts +2 -0
  48. package/dist/types/utils/debounceCallback.d.ts.map +1 -0
  49. package/dist/types/utils/debounceId.d.ts +7 -0
  50. package/dist/types/utils/debounceId.d.ts.map +1 -0
  51. package/dist/types/utils/fetchLocaleIp.d.ts +40 -0
  52. package/dist/types/utils/fetchLocaleIp.d.ts.map +1 -0
  53. package/dist/types/utils/getBrowserLocale.d.ts +2 -0
  54. package/dist/types/utils/getBrowserLocale.d.ts.map +1 -0
  55. package/dist/types/utils/getCountryFlagUrl.d.ts +9 -0
  56. package/dist/types/utils/getCountryFlagUrl.d.ts.map +1 -0
  57. package/dist/types/utils/idleTimeout.d.ts +57 -0
  58. package/dist/types/utils/idleTimeout.d.ts.map +1 -0
  59. package/dist/types/utils/index.d.ts +21 -0
  60. package/dist/types/utils/index.d.ts.map +1 -0
  61. package/dist/types/utils/isClient.d.ts +2 -0
  62. package/dist/types/utils/isClient.d.ts.map +1 -0
  63. package/dist/types/utils/isEqual.d.ts +2 -0
  64. package/dist/types/utils/isEqual.d.ts.map +1 -0
  65. package/dist/types/utils/isServer.d.ts +2 -0
  66. package/dist/types/utils/isServer.d.ts.map +1 -0
  67. package/dist/types/utils/isStandaloneMode.d.ts +2 -0
  68. package/dist/types/utils/isStandaloneMode.d.ts.map +1 -0
  69. package/dist/types/utils/normalizeString.d.ts +48 -0
  70. package/dist/types/utils/normalizeString.d.ts.map +1 -0
  71. package/dist/types/utils/scriptLoader.d.ts +20 -0
  72. package/dist/types/utils/scriptLoader.d.ts.map +1 -0
  73. package/dist/types/utils/sleep.d.ts +2 -0
  74. package/dist/types/utils/sleep.d.ts.map +1 -0
  75. package/dist/types/utils/swipeHandler.d.ts +103 -0
  76. package/dist/types/utils/swipeHandler.d.ts.map +1 -0
  77. package/dist/types/utils/throttle.d.ts +2 -0
  78. package/dist/types/utils/throttle.d.ts.map +1 -0
  79. package/dist/types/utils/throttleId.d.ts +7 -0
  80. package/dist/types/utils/throttleId.d.ts.map +1 -0
  81. package/dist/types/utils/truthyFilter.d.ts +3 -0
  82. package/dist/types/utils/truthyFilter.d.ts.map +1 -0
  83. package/dist/types/utils/userVisibility.d.ts +40 -0
  84. package/dist/types/utils/userVisibility.d.ts.map +1 -0
  85. package/dist/utils/TextareaAutogrow.js +25 -0
  86. package/dist/utils/checkAvailability.js +16 -0
  87. package/dist/utils/countryCodeToUnicodeFlag.js +10 -0
  88. package/dist/utils/debounce.js +11 -0
  89. package/dist/utils/debounceCallback.js +7 -0
  90. package/dist/utils/debounceId.js +21 -0
  91. package/dist/utils/fetchLocaleIp.js +12 -0
  92. package/dist/utils/getBrowserLocale.js +11 -0
  93. package/dist/utils/getCountryFlagUrl.js +9 -0
  94. package/dist/utils/idleTimeout.js +111 -0
  95. package/dist/utils/index.js +42 -0
  96. package/dist/utils/isClient.js +6 -0
  97. package/dist/utils/isEqual.js +26 -0
  98. package/dist/utils/isServer.js +6 -0
  99. package/dist/utils/isStandaloneMode.js +10 -0
  100. package/dist/utils/normalizeString.js +69 -0
  101. package/dist/utils/scriptLoader.js +43 -0
  102. package/dist/utils/sleep.js +6 -0
  103. package/dist/utils/swipeHandler.js +80 -0
  104. package/dist/utils/throttle.js +11 -0
  105. package/dist/utils/throttleId.js +19 -0
  106. package/dist/utils/truthyFilter.js +6 -0
  107. package/dist/utils/userVisibility.js +50 -0
  108. package/package.json +88 -0
@@ -0,0 +1,48 @@
1
+ export interface NormalizeStringOptions {
2
+ /**
3
+ * Remove accents from the string
4
+ * @default true
5
+ */
6
+ removeAccents?: boolean;
7
+ /**
8
+ * Keep the case of the string
9
+ * @default false
10
+ */
11
+ caseSensitive?: boolean;
12
+ /**
13
+ * Replace spaces with `-`
14
+ * @default true
15
+ */
16
+ replaceSpaces?: boolean;
17
+ /**
18
+ * Remove special characters
19
+ * Be careful, only for languages that use the Latin alphabet
20
+ * @default false
21
+ */
22
+ removeSpecialCharacters?: boolean;
23
+ /**
24
+ * Remove leading and trailing whitespaces
25
+ * @default true
26
+ */
27
+ trim?: boolean;
28
+ /**
29
+ * Normalize spaces
30
+ * Will replace multiple spaces with a single space
31
+ * @default true
32
+ */
33
+ normalizeSpaces?: boolean;
34
+ /**
35
+ * Remove numbers
36
+ * @default false
37
+ */
38
+ removeNumbers?: boolean;
39
+ /**
40
+ * Normalize the string with custom normalization forms
41
+ * @default ['NFC', 'NFKD']
42
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
43
+ * options: 'NFC', 'NFD', 'NFKC', 'NFKD'
44
+ */
45
+ customNormalizationForms?: string[];
46
+ }
47
+ export declare function normalizeString(input: string | number | boolean, options?: NormalizeStringOptions): string;
48
+ //# sourceMappingURL=normalizeString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeString.d.ts","sourceRoot":"","sources":["../../../src/utils/normalizeString.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;CACpC;AAaD,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,EAChC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,MAAM,CAmDR"}
@@ -0,0 +1,20 @@
1
+ export interface ScriptLoaderOptions {
2
+ identifier: string;
3
+ src: string;
4
+ once?: boolean;
5
+ async?: boolean;
6
+ defer?: boolean;
7
+ }
8
+ export declare class ScriptLoader {
9
+ private src;
10
+ private script?;
11
+ private once;
12
+ private async;
13
+ private defer;
14
+ private identifier;
15
+ constructor({ src, identifier, once, async, defer }: ScriptLoaderOptions);
16
+ removeTag(tag: Element | string): void;
17
+ load(): Promise<unknown>;
18
+ private injectScript;
19
+ }
20
+ //# sourceMappingURL=scriptLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptLoader.d.ts","sourceRoot":"","sources":["../../../src/utils/scriptLoader.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,MAAM,CAAC,CAAO;IACtB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAQ;gBAEd,EAAE,GAAG,EAAE,UAAU,EAAE,IAAW,EAAE,KAAY,EAAE,KAAY,EAAE,EAAE,mBAAmB;IAoBtF,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM;IAS/B,IAAI;IAmBX,OAAO,CAAC,YAAY;CA4BrB"}
@@ -0,0 +1,2 @@
1
+ export declare function sleep(duration: number): Promise<unknown>;
2
+ //# sourceMappingURL=sleep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../../src/utils/sleep.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,oBAErC"}
@@ -0,0 +1,103 @@
1
+ export interface SwipeValues {
2
+ xStart: number | undefined;
3
+ yStart: number | undefined;
4
+ xEnd: number | undefined;
5
+ yEnd: number | undefined;
6
+ xDiff: number | undefined;
7
+ yDiff: number | undefined;
8
+ }
9
+ export type SwipeEventCallback = (event: TouchEvent) => void;
10
+ export type SwipeValuesCallback = (values: SwipeValues) => void;
11
+ /**
12
+ * Options for handling swipe events.
13
+ */
14
+ export interface SwipeOptions {
15
+ /**
16
+ * The element on which the swipe events will be handled.
17
+ * @default null
18
+ */
19
+ element?: HTMLElement | string | null;
20
+ /**
21
+ * Callback function to be executed when a left swipe is detected.
22
+ * @default undefined
23
+ */
24
+ onLeft?: SwipeEventCallback;
25
+ /**
26
+ * Callback function to be executed when a right swipe is detected.
27
+ * @default undefined
28
+ */
29
+ onRight?: SwipeEventCallback;
30
+ /**
31
+ * Callback function to be executed when an up swipe is detected.
32
+ * @default undefined
33
+ */
34
+ onUp?: SwipeEventCallback;
35
+ /**
36
+ * Callback function to be executed when a down swipe is detected.
37
+ * @default undefined
38
+ */
39
+ onDown?: SwipeEventCallback;
40
+ /**
41
+ * Callback function to be executed when values are changed.
42
+ * @default undefined
43
+ */
44
+ onValuesChanged?: SwipeValuesCallback;
45
+ /**
46
+ * The minimum distance the swipe needs to travel to be considered valid.
47
+ * @default 50
48
+ */
49
+ threshold?: number;
50
+ /**
51
+ * Whether to prevent the default behavior of touchmove event.
52
+ * @default false
53
+ */
54
+ preventDefaultOnTouchMove?: boolean;
55
+ /**
56
+ * Whether to prevent the default behavior of mousewheel event.
57
+ * @default false
58
+ */
59
+ preventDefaultOnMouseWheel?: boolean;
60
+ /**
61
+ * Whether to trigger the swipe event immediately on touchstart/mousedown.
62
+ * @default false
63
+ */
64
+ immediate?: boolean;
65
+ /**
66
+ * Whether to trigger the swipe event on touchend/mouseup.
67
+ * If set to true, the swipe event will be triggered only when the user lifts their finger/mouse.
68
+ * @default false
69
+ */
70
+ triggerOnEnd?: boolean;
71
+ }
72
+ type DefaultSwipeOptions = Required<Pick<SwipeOptions, 'preventDefaultOnTouchMove' | 'preventDefaultOnMouseWheel' | 'threshold' | 'immediate' | 'triggerOnEnd'>>;
73
+ type SwipeOptionsWithDefaults = SwipeOptions & DefaultSwipeOptions;
74
+ export declare class Swipe {
75
+ readonly inputOption: SwipeOptions;
76
+ element: HTMLElement | undefined;
77
+ xStart: number | undefined;
78
+ yStart: number | undefined;
79
+ xEnd: number | undefined;
80
+ yEnd: number | undefined;
81
+ xDiff: number | undefined;
82
+ yDiff: number | undefined;
83
+ private readonly onToucheStartCallback;
84
+ private readonly onToucheMoveCallback;
85
+ private readonly onToucheEndCallback;
86
+ private readonly onMouseWheelCallback;
87
+ readonly start: (element?: typeof this.options.element) => void;
88
+ readonly stop: () => void;
89
+ options: SwipeOptionsWithDefaults;
90
+ constructor(inputOption: SwipeOptions);
91
+ private startListening;
92
+ private stopListening;
93
+ private setElement;
94
+ private handleMouseWheel;
95
+ private toucheStartHandler;
96
+ private emitValuesChanged;
97
+ private handleTouchMove;
98
+ private handleTouchEnd;
99
+ private runCallbacks;
100
+ private resetValues;
101
+ }
102
+ export {};
103
+ //# sourceMappingURL=swipeHandler.d.ts.map
@@ -0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parameters<T>) => void;
2
+ //# sourceMappingURL=throttle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/utils/throttle.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAC1E,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAqBlC"}
@@ -0,0 +1,7 @@
1
+ type AsyncFunction<T, Args extends unknown[]> = (...args: Args) => T | Promise<T>;
2
+ /**
3
+ * Throttle an async function - called at first call and then at intervals (only the last call is executed)
4
+ */
5
+ export declare function throttleId<T, Args extends unknown[]>(identifier: string, func: AsyncFunction<T, Args>, interval: number): (...args: Args) => Promise<T>;
6
+ export {};
7
+ //# sourceMappingURL=throttleId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttleId.d.ts","sourceRoot":"","sources":["../../../src/utils/throttleId.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAQjF;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAAE,EAClD,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,EAC5B,QAAQ,EAAE,MAAM,GACf,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAkC/B"}
@@ -0,0 +1,3 @@
1
+ export type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T;
2
+ export declare function truthyFilter<T>(value: T): value is Truthy<T>;
3
+ //# sourceMappingURL=truthyFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truthyFilter.d.ts","sourceRoot":"","sources":["../../../src/utils/truthyFilter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,GAAG,CAAC,CAAA;AAC/E,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAE5D"}
@@ -0,0 +1,40 @@
1
+ export type UserVisibilyCallback = ({ isVisible }: {
2
+ isVisible: boolean;
3
+ }) => void;
4
+ export interface UserVisibilyStrictOptions {
5
+ /**
6
+ * Watch immediately
7
+ * @default true
8
+ */
9
+ immediate: boolean;
10
+ /**
11
+ * Timeout visibility in ms
12
+ * @default 5000 // 5 sec
13
+ */
14
+ timeout: number;
15
+ /**
16
+ * Watch once
17
+ * @default false
18
+ */
19
+ once: boolean;
20
+ }
21
+ export type UserVisibilyOptions = Partial<UserVisibilyStrictOptions>;
22
+ export declare class UserVisibility {
23
+ private readonly callback;
24
+ private eventHandlerFunction;
25
+ private event;
26
+ private timeoutHandler?;
27
+ private options;
28
+ private readonly defaultOptions;
29
+ private isVisible;
30
+ constructor(callback: UserVisibilyCallback, options?: UserVisibilyOptions);
31
+ start(): void;
32
+ private emitCallback;
33
+ private eventHandler;
34
+ private clearTimeout;
35
+ private initTimeout;
36
+ private addEventListener;
37
+ private removeEventListener;
38
+ destroy(): void;
39
+ }
40
+ //# sourceMappingURL=userVisibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userVisibility.d.ts","sourceRoot":"","sources":["../../../src/utils/userVisibility.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAA;AAElF,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAA;CACd;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;AAEpE,qBAAa,cAAc;IAkBvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAjB3B,OAAO,CAAC,oBAAoB,CAAY;IAExC,OAAO,CAAC,KAAK,CAAqB;IAElC,OAAO,CAAC,cAAc,CAAC,CAA+B;IAEtD,OAAO,CAAC,OAAO,CAA2B;IAE1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAI9B;IAED,OAAO,CAAC,SAAS,CAAQ;gBAGN,QAAQ,EAAE,oBAAoB,EAC/C,OAAO,CAAC,EAAE,mBAAmB;IAcxB,KAAK;IAaZ,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,mBAAmB;IAI3B,OAAO;CAOR"}
@@ -0,0 +1,25 @@
1
+ import { debounce as t } from "./debounce.js";
2
+ class o {
3
+ element;
4
+ constructor(e) {
5
+ this.element = e, this.onFocus = this.onFocus.bind(this), this.autogrow = this.autogrow.bind(this), this.onResize = t(this.onResize.bind(this), 200), this.connect();
6
+ }
7
+ connect() {
8
+ this.element.addEventListener("focus", this.onFocus), this.element.style.resize = "none", this.element.style.boxSizing = "border-box";
9
+ }
10
+ disconnect() {
11
+ window.removeEventListener("resize", this.onResize), this.element.removeEventListener("input", this.autogrow);
12
+ }
13
+ onFocus() {
14
+ this.autogrow(), this.element.addEventListener("input", this.autogrow), window.addEventListener("resize", this.onResize), this.element.removeEventListener("focus", this.onFocus);
15
+ }
16
+ onResize() {
17
+ this.autogrow();
18
+ }
19
+ autogrow() {
20
+ this.element.style.height = "auto", this.element.style.overflow = "hidden", this.element.style.height = `${this.element.scrollHeight}px`;
21
+ }
22
+ }
23
+ export {
24
+ o as TextareaAutogrow
25
+ };
@@ -0,0 +1,16 @@
1
+ function l(r, o, s) {
2
+ const e = {
3
+ maxAttempts: 20,
4
+ interval: 100,
5
+ ...s
6
+ };
7
+ let t = 0;
8
+ function a() {
9
+ const i = r();
10
+ i != null ? e.expectedValue !== void 0 && i !== e.expectedValue ? t < e.maxAttempts ? (t++, setTimeout(a, e.interval)) : e.onError?.(new Error(e.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${e.maxAttempts} attempts`)) : o(i) : t < e.maxAttempts ? (t++, setTimeout(a, e.interval)) : e.onError?.(new Error(e.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${e.maxAttempts} attempts`));
11
+ }
12
+ a();
13
+ }
14
+ export {
15
+ l as checkAvailability
16
+ };
@@ -0,0 +1,10 @@
1
+ import { truthyFilter as n } from "./truthyFilter.js";
2
+ function i(r) {
3
+ return [...r].map((o) => {
4
+ const t = o.codePointAt(0);
5
+ return t ? t % 32 + 127461 : void 0;
6
+ }).filter(n).map((o) => String.fromCodePoint(o)).join("");
7
+ }
8
+ export {
9
+ i as countryCodeToUnicodeFlag
10
+ };
@@ -0,0 +1,11 @@
1
+ function i(e, o) {
2
+ let t;
3
+ return function(...u) {
4
+ clearTimeout(t), t = setTimeout(() => {
5
+ e.apply(this, u);
6
+ }, o);
7
+ };
8
+ }
9
+ export {
10
+ i as debounce
11
+ };
@@ -0,0 +1,7 @@
1
+ let e = null;
2
+ function o(t, l) {
3
+ e && clearTimeout(e), e = setTimeout(t, l);
4
+ }
5
+ export {
6
+ o as debounceCallback
7
+ };
@@ -0,0 +1,21 @@
1
+ function i(o, n, r) {
2
+ const t = {};
3
+ return function(...c) {
4
+ t[o] || (t[o] = { timer: null, promise: null });
5
+ const e = t[o];
6
+ return e.timer && clearTimeout(e.timer), e.promise = new Promise((u, m) => {
7
+ e.timer = setTimeout(async () => {
8
+ try {
9
+ u(await n(...c));
10
+ } catch (s) {
11
+ m(s);
12
+ } finally {
13
+ delete t[o];
14
+ }
15
+ }, r);
16
+ }), e.promise;
17
+ };
18
+ }
19
+ export {
20
+ i as debounceId
21
+ };
@@ -0,0 +1,12 @@
1
+ async function c() {
2
+ try {
3
+ const o = await fetch("https://ipwho.is"), { country_code: t } = await o.json();
4
+ return t;
5
+ } catch (o) {
6
+ console.error(`[maz-ui](fetchLocaleIp) ${o}`);
7
+ return;
8
+ }
9
+ }
10
+ export {
11
+ c as fetchLocaleIp
12
+ };
@@ -0,0 +1,11 @@
1
+ import { isServer as e } from "./isServer.js";
2
+ function t() {
3
+ try {
4
+ return e() ? void 0 : window.navigator.language;
5
+ } catch (r) {
6
+ throw new Error(`[MazInputPhoneNumber] (browserLocale) ${r}`);
7
+ }
8
+ }
9
+ export {
10
+ t as getBrowserLocale
11
+ };
@@ -0,0 +1,9 @@
1
+ const t = ["ad", "ae", "af", "ag", "ai", "al", "am", "ao", "aq", "ar", "as", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bl", "bm", "bn", "bo", "bq", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cw", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", "eu", "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gb-eng", "gb-nir", "gb-sct", "gb-wls", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", "je", "jm", "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me", "mf", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", "rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "ss", "st", "sv", "sx", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "un", "us", "us-ak", "us-al", "us-ar", "us-az", "us-ca", "us-co", "us-ct", "us-de", "us-fl", "us-ga", "us-hi", "us-ia", "us-id", "us-il", "us-in", "us-ks", "us-ky", "us-la", "us-ma", "us-md", "us-me", "us-mi", "us-mn", "us-mo", "us-ms", "us-mt", "us-nc", "us-nd", "us-ne", "us-nh", "us-nj", "us-nm", "us-nv", "us-ny", "us-oh", "us-ok", "us-or", "us-pa", "us-ri", "us-sc", "us-sd", "us-tn", "us-tx", "us-ut", "us-va", "us-vt", "us-wa", "us-wi", "us-wv", "us-wy", "uy", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "xk", "ye", "yt", "za", "zm", "zw"];
2
+ function n(m, u) {
3
+ const s = m.toLowerCase();
4
+ if (t.includes(s))
5
+ return u ? `https://flagcdn.com/${u}/${s}.png` : `https://flagcdn.com/${s}.svg`;
6
+ }
7
+ export {
8
+ n as getCountryFlagUrl
9
+ };
@@ -0,0 +1,111 @@
1
+ import { isClient as s } from "./isClient.js";
2
+ class l {
3
+ constructor(t, e) {
4
+ this.callback = t, this.options = {
5
+ ...this.defaultOptions,
6
+ ...e
7
+ }, s() && this.start();
8
+ }
9
+ defaultOptions = {
10
+ element: void 0,
11
+ timeout: 60 * 1e3 * 5,
12
+ // 5 minutes
13
+ once: !1,
14
+ immediate: !0
15
+ };
16
+ options;
17
+ timeoutHandler;
18
+ isIdle = !1;
19
+ isDestroy = !1;
20
+ startTime = 0;
21
+ remainingTime = 0;
22
+ lastClientX = -1;
23
+ lastClientY = -1;
24
+ eventNames = [
25
+ "DOMMouseScroll",
26
+ "mousedown",
27
+ "mousemove",
28
+ "mousewheel",
29
+ "MSPointerDown",
30
+ "MSPointerMove",
31
+ "keydown",
32
+ "touchmove",
33
+ "touchstart",
34
+ "wheel",
35
+ "click"
36
+ ];
37
+ get element() {
38
+ return this.options.element ?? document.body;
39
+ }
40
+ start() {
41
+ if (!s()) {
42
+ console.warn("[IdleTimeout](start) you should run this method on client side");
43
+ return;
44
+ }
45
+ for (const t of this.eventNames)
46
+ this.element.addEventListener(t, this.handleEvent);
47
+ this.resetTimeout(), this.options.immediate && this.callback({ isIdle: !1, instance: this });
48
+ }
49
+ pause() {
50
+ const t = this.startTime + this.options.timeout - Date.now();
51
+ t <= 0 || (this.remainingTime = t, this.timeoutHandler && (clearTimeout(this.timeoutHandler), this.timeoutHandler = void 0));
52
+ }
53
+ resume() {
54
+ this.remainingTime <= 0 || (this.resetTimeout(), this.callback({ isIdle: this.isIdle, instance: this }), this.remainingTime = 0);
55
+ }
56
+ reset() {
57
+ this.isDestroy = !1, this.isIdle = !1, this.remainingTime = 0, this.resetTimeout(), this.callback({ isIdle: this.isIdle, instance: this });
58
+ }
59
+ destroy() {
60
+ if (!s()) {
61
+ console.warn("[IdleTimeout](destroy) you should run this method on client side");
62
+ return;
63
+ }
64
+ this.isDestroy = !0;
65
+ for (const t of this.eventNames)
66
+ this.element.removeEventListener(t, this.handleEvent);
67
+ this.timeoutHandler && clearTimeout(this.timeoutHandler);
68
+ }
69
+ resetTimeout() {
70
+ this.isIdle = !1, this.timeoutHandler && (clearTimeout(this.timeoutHandler), this.timeoutHandler = void 0), this.timeoutHandler = setTimeout(
71
+ this.handleTimeout.bind(this),
72
+ this.remainingTime || this.options.timeout
73
+ ), this.startTime = Date.now();
74
+ }
75
+ handleEvent = (t) => {
76
+ try {
77
+ if (this.remainingTime > 0)
78
+ return;
79
+ if (t.type === "mousemove") {
80
+ const { clientX: e, clientY: i } = t;
81
+ if (e === void 0 && i === void 0 || e === this.lastClientX && i === this.lastClientY)
82
+ return;
83
+ this.lastClientX = e, this.lastClientY = i;
84
+ }
85
+ this.resetTimeout(), this.callback({ isIdle: this.isIdle, eventType: t.type, instance: this });
86
+ } catch (e) {
87
+ throw new Error(`[IdleTimeout](handleEvent) ${e}`);
88
+ }
89
+ };
90
+ handleTimeout() {
91
+ this.isIdle = !0, this.callback({ isIdle: this.isIdle, instance: this }), this.options.once && this.destroy();
92
+ }
93
+ get destroyed() {
94
+ return this.isDestroy;
95
+ }
96
+ get timeout() {
97
+ return this.options.timeout;
98
+ }
99
+ set timeout(t) {
100
+ this.options.timeout = t;
101
+ }
102
+ get idle() {
103
+ return this.isIdle;
104
+ }
105
+ set idle(t) {
106
+ t ? this.handleTimeout() : this.reset(), this.callback({ isIdle: this.isIdle, instance: this });
107
+ }
108
+ }
109
+ export {
110
+ l as IdleTimeout
111
+ };
@@ -0,0 +1,42 @@
1
+ import { checkAvailability as e } from "./checkAvailability.js";
2
+ import { countryCodeToUnicodeFlag as p } from "./countryCodeToUnicodeFlag.js";
3
+ import { debounce as x } from "./debounce.js";
4
+ import { debounceCallback as i } from "./debounceCallback.js";
5
+ import { debounceId as a } from "./debounceId.js";
6
+ import { getCountryFlagUrl as n } from "./getCountryFlagUrl.js";
7
+ import { IdleTimeout as u } from "./idleTimeout.js";
8
+ import { isClient as b } from "./isClient.js";
9
+ import { isEqual as y } from "./isEqual.js";
10
+ import { isServer as h } from "./isServer.js";
11
+ import { isStandaloneMode as F } from "./isStandaloneMode.js";
12
+ import { normalizeString as T } from "./normalizeString.js";
13
+ import { ScriptLoader as k } from "./scriptLoader.js";
14
+ import { sleep as w } from "./sleep.js";
15
+ import { Swipe as q } from "./swipeHandler.js";
16
+ import { TextareaAutogrow as E } from "./TextareaAutogrow.js";
17
+ import { throttle as M } from "./throttle.js";
18
+ import { throttleId as j } from "./throttleId.js";
19
+ import { truthyFilter as D } from "./truthyFilter.js";
20
+ import { UserVisibility as H } from "./userVisibility.js";
21
+ export {
22
+ u as IdleTimeout,
23
+ k as ScriptLoader,
24
+ q as Swipe,
25
+ E as TextareaAutogrow,
26
+ H as UserVisibility,
27
+ e as checkAvailability,
28
+ p as countryCodeToUnicodeFlag,
29
+ x as debounce,
30
+ i as debounceCallback,
31
+ a as debounceId,
32
+ n as getCountryFlagUrl,
33
+ b as isClient,
34
+ y as isEqual,
35
+ h as isServer,
36
+ F as isStandaloneMode,
37
+ T as normalizeString,
38
+ w as sleep,
39
+ M as throttle,
40
+ j as throttleId,
41
+ D as truthyFilter
42
+ };
@@ -0,0 +1,6 @@
1
+ function e() {
2
+ return typeof document < "u";
3
+ }
4
+ export {
5
+ e as isClient
6
+ };
@@ -0,0 +1,26 @@
1
+ function i(e) {
2
+ return e == null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "symbol" || typeof e == "bigint";
3
+ }
4
+ function o(e, r) {
5
+ if (e.length !== r.length)
6
+ return !1;
7
+ for (const [t, n] of e.entries())
8
+ if (!s(n, r[t]))
9
+ return !1;
10
+ return !0;
11
+ }
12
+ function y(e, r) {
13
+ const t = Object.keys(e), n = Object.keys(r);
14
+ if (t.length !== n.length)
15
+ return !1;
16
+ for (const f of t)
17
+ if (!n.includes(f) || !s(e[f], r[f]))
18
+ return !1;
19
+ return !0;
20
+ }
21
+ function s(e, r) {
22
+ return i(e) || i(r) ? e === r : e instanceof Date && r instanceof Date ? e.getTime() === r.getTime() : typeof e != typeof r || Array.isArray(e) !== Array.isArray(r) ? !1 : Array.isArray(e) && Array.isArray(r) ? o(e, r) : typeof e == "object" && typeof r == "object" ? y(e, r) : !1;
23
+ }
24
+ export {
25
+ s as isEqual
26
+ };
@@ -0,0 +1,6 @@
1
+ function e() {
2
+ return typeof document > "u" || typeof window > "u";
3
+ }
4
+ export {
5
+ e as isServer
6
+ };
@@ -0,0 +1,10 @@
1
+ import { isClient as t } from "./isClient.js";
2
+ function e() {
3
+ if (!t())
4
+ return !1;
5
+ const n = navigator, a = window.matchMedia("(display-mode: standalone)").matches;
6
+ return n.standalone || a;
7
+ }
8
+ export {
9
+ e as isStandaloneMode
10
+ };