@dxtmisha/functional-basic 0.1.1 → 0.1.4

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 (125) hide show
  1. package/dist/functions/copyObjectLite.d.ts +9 -0
  2. package/dist/library.d.ts +1 -0
  3. package/dist/library.js +405 -411
  4. package/package.json +1 -3
  5. package/src/classes/Api.ts +0 -407
  6. package/src/classes/ApiDefault.ts +0 -83
  7. package/src/classes/ApiHeaders.ts +0 -52
  8. package/src/classes/ApiPreparation.ts +0 -114
  9. package/src/classes/ApiResponse.ts +0 -293
  10. package/src/classes/ApiStatus.ts +0 -173
  11. package/src/classes/BroadcastMessage.ts +0 -73
  12. package/src/classes/Cache.ts +0 -60
  13. package/src/classes/CacheItem.ts +0 -95
  14. package/src/classes/CacheStatic.ts +0 -30
  15. package/src/classes/Cookie.ts +0 -135
  16. package/src/classes/CookieBlock.ts +0 -31
  17. package/src/classes/DataStorage.ts +0 -194
  18. package/src/classes/Datetime.ts +0 -891
  19. package/src/classes/EventItem.ts +0 -373
  20. package/src/classes/Geo.ts +0 -320
  21. package/src/classes/GeoFlag.ts +0 -386
  22. package/src/classes/GeoIntl.ts +0 -839
  23. package/src/classes/GeoPhone.ts +0 -272
  24. package/src/classes/Global.ts +0 -32
  25. package/src/classes/Hash.ts +0 -142
  26. package/src/classes/Icons.ts +0 -165
  27. package/src/classes/Loading.ts +0 -90
  28. package/src/classes/Meta.ts +0 -284
  29. package/src/classes/MetaManager.ts +0 -200
  30. package/src/classes/MetaOg.ts +0 -147
  31. package/src/classes/MetaTwitter.ts +0 -154
  32. package/src/classes/ScrollbarWidth.ts +0 -86
  33. package/src/classes/Translate.ts +0 -293
  34. package/src/classes/__tests__/Api.test.ts +0 -728
  35. package/src/classes/__tests__/ApiDefault.test.ts +0 -222
  36. package/src/classes/__tests__/ApiHeaders.test.ts +0 -447
  37. package/src/classes/__tests__/ApiPreparation.test.ts +0 -257
  38. package/src/classes/__tests__/ApiResponse.test.ts +0 -547
  39. package/src/classes/__tests__/ApiStatus.test.ts +0 -403
  40. package/src/classes/__tests__/Meta.test.ts +0 -629
  41. package/src/classes/__tests__/MetaManager.test.ts +0 -836
  42. package/src/classes/__tests__/MetaOg.test.ts +0 -677
  43. package/src/classes/__tests__/MetaTwitter.test.ts +0 -423
  44. package/src/functions/anyToString.ts +0 -36
  45. package/src/functions/applyTemplate.ts +0 -63
  46. package/src/functions/arrFill.ts +0 -10
  47. package/src/functions/copyObject.ts +0 -10
  48. package/src/functions/createElement.ts +0 -40
  49. package/src/functions/domQuerySelector.ts +0 -15
  50. package/src/functions/domQuerySelectorAll.ts +0 -15
  51. package/src/functions/encodeAttribute.ts +0 -15
  52. package/src/functions/eventStopPropagation.ts +0 -10
  53. package/src/functions/executeFunction.ts +0 -13
  54. package/src/functions/executePromise.ts +0 -19
  55. package/src/functions/forEach.ts +0 -39
  56. package/src/functions/frame.ts +0 -38
  57. package/src/functions/getAttributes.ts +0 -27
  58. package/src/functions/getClipboardData.ts +0 -13
  59. package/src/functions/getColumn.ts +0 -18
  60. package/src/functions/getElement.ts +0 -35
  61. package/src/functions/getElementId.ts +0 -39
  62. package/src/functions/getElementItem.ts +0 -27
  63. package/src/functions/getElementOrWindow.ts +0 -23
  64. package/src/functions/getExp.ts +0 -21
  65. package/src/functions/getItemByPath.ts +0 -24
  66. package/src/functions/getKey.ts +0 -9
  67. package/src/functions/getLengthOfAllArray.ts +0 -13
  68. package/src/functions/getMaxLengthAllArray.ts +0 -13
  69. package/src/functions/getMinLengthAllArray.ts +0 -13
  70. package/src/functions/getMouseClient.ts +0 -17
  71. package/src/functions/getMouseClientX.ts +0 -9
  72. package/src/functions/getMouseClientY.ts +0 -9
  73. package/src/functions/getObjectByKeys.ts +0 -24
  74. package/src/functions/getObjectNoUndefined.ts +0 -23
  75. package/src/functions/getObjectOrNone.ts +0 -11
  76. package/src/functions/getRandomText.ts +0 -29
  77. package/src/functions/getRequestString.ts +0 -21
  78. package/src/functions/getStepPercent.ts +0 -19
  79. package/src/functions/getStepValue.ts +0 -19
  80. package/src/functions/goScroll.ts +0 -40
  81. package/src/functions/inArray.ts +0 -10
  82. package/src/functions/initScrollbarOffset.ts +0 -14
  83. package/src/functions/intersectKey.ts +0 -34
  84. package/src/functions/isArray.ts +0 -9
  85. package/src/functions/isDifferent.ts +0 -27
  86. package/src/functions/isDomRuntime.ts +0 -12
  87. package/src/functions/isFilled.ts +0 -49
  88. package/src/functions/isFloat.ts +0 -16
  89. package/src/functions/isFunction.ts +0 -11
  90. package/src/functions/isInDom.ts +0 -15
  91. package/src/functions/isIntegerBetween.ts +0 -11
  92. package/src/functions/isNull.ts +0 -11
  93. package/src/functions/isNumber.ts +0 -16
  94. package/src/functions/isObject.ts +0 -9
  95. package/src/functions/isObjectNotArray.ts +0 -11
  96. package/src/functions/isSelected.ts +0 -32
  97. package/src/functions/isSelectedByList.ts +0 -19
  98. package/src/functions/isString.ts +0 -9
  99. package/src/functions/isWindow.ts +0 -11
  100. package/src/functions/random.ts +0 -10
  101. package/src/functions/replaceRecursive.ts +0 -60
  102. package/src/functions/replaceTemplate.ts +0 -22
  103. package/src/functions/secondToTime.ts +0 -20
  104. package/src/functions/setElementItem.ts +0 -56
  105. package/src/functions/setValues.ts +0 -59
  106. package/src/functions/splice.ts +0 -59
  107. package/src/functions/strFill.ts +0 -12
  108. package/src/functions/toArray.ts +0 -19
  109. package/src/functions/toCamelCase.ts +0 -16
  110. package/src/functions/toCamelCaseFirst.ts +0 -12
  111. package/src/functions/toDate.ts +0 -44
  112. package/src/functions/toKebabCase.ts +0 -25
  113. package/src/functions/toNumber.ts +0 -35
  114. package/src/functions/toNumberByMax.ts +0 -33
  115. package/src/functions/toPercent.ts +0 -10
  116. package/src/functions/toPercentBy100.ts +0 -12
  117. package/src/functions/transformation.ts +0 -59
  118. package/src/functions/uniqueArray.ts +0 -9
  119. package/src/functions/writeClipboardData.ts +0 -17
  120. package/src/library.ts +0 -116
  121. package/src/types/apiTypes.ts +0 -143
  122. package/src/types/basicTypes.ts +0 -155
  123. package/src/types/geoTypes.ts +0 -109
  124. package/src/types/metaTypes.ts +0 -764
  125. package/src/vite-env.d.ts +0 -1
@@ -1,272 +0,0 @@
1
- import { forEach } from '../functions/forEach'
2
- import { isFilled } from '../functions/isFilled'
3
- import { toArray } from '../functions/toArray'
4
-
5
- import { Geo } from './Geo'
6
- import {
7
- type GeoPhoneValue,
8
- type GeoPhoneMap,
9
- type GeoPhoneMapInfo
10
- } from '../types/geoTypes'
11
-
12
- /**
13
- * A class for storing and processing phone number masks.
14
- *
15
- * Класс для хранения и обработка маски телефона.
16
- */
17
- export class GeoPhone {
18
- protected static list: GeoPhoneValue[] = []
19
- protected static map: Record<string, GeoPhoneMap> = {}
20
-
21
- /**
22
- * Getting an object with information about the phone code and country.
23
- *
24
- * Получение объекта с информацией о телефонном коде и стране.
25
- * @param code country and language code/ код страны и языка
26
- */
27
- static get(code: string): GeoPhoneValue | undefined {
28
- return this.list.find(item => code === item.value)
29
- }
30
-
31
- /**
32
- * Getting information by phone.
33
- *
34
- * Получение информации по телефону.
35
- * @param phone phone number/ номер телефон
36
- */
37
- static getByPhone(phone: string): GeoPhoneMapInfo {
38
- let focus = this.map
39
- let item: GeoPhoneMap | undefined
40
- let value = ''
41
-
42
- this.toNumber(phone).forEach((number) => {
43
- if (
44
- value === ''
45
- && number in focus
46
- ) {
47
- item = focus[number]
48
- focus = item?.next ?? {}
49
- } else {
50
- value += number
51
- }
52
- })
53
-
54
- return {
55
- item,
56
- phone: value
57
- }
58
- }
59
-
60
- /**
61
- * Retrieves complete mask data by country code.
62
- *
63
- * Получает полные данные о маске по коду страны.
64
- * @param code country and language code/ код страны и языка
65
- */
66
- static getByCode(code: string): GeoPhoneMap | undefined {
67
- const item = this.get(code)
68
-
69
- if (item) {
70
- return this.getByPhone(item.phone.toString())?.item
71
- }
72
-
73
- return undefined
74
- }
75
-
76
- /**
77
- * We get an array from a list of all phone numbers.
78
- *
79
- * Получаем массив из списка всех телефонных кодов.
80
- */
81
- static getList(): GeoPhoneValue[] {
82
- return this.list
83
- }
84
-
85
- /**
86
- * We get a map of a tree, sorted by its code.
87
- *
88
- * Получаем карту дерева, отсортированную по его коду.
89
- */
90
- static getMap(): Record<string, GeoPhoneMap> {
91
- return this.map
92
- }
93
-
94
- /**
95
- * Convert to phone mask.
96
- *
97
- * Преобразовать в маску телефона.
98
- * @param phone phone number/ номер телефон
99
- * @param masks a mask to transform a phone number/ маска для преобразования номер телефон
100
- */
101
- static toMask(
102
- phone: string,
103
- masks?: string[]
104
- ): string | undefined {
105
- if (
106
- isFilled(phone)
107
- && Array.isArray(masks)
108
- && masks.length > 0
109
- ) {
110
- const value = this.removeZero(phone)
111
- const length = value.length
112
-
113
- for (const mask of masks) {
114
- if (this.getUnnecessaryLength(mask) === length) {
115
- return this.toStandard(value, mask)
116
- }
117
- }
118
- }
119
-
120
- return undefined
121
- }
122
-
123
- /**
124
- * Deletes the country code from the input number.
125
- *
126
- * Удаляет код страны по входному номеру.
127
- * @param phone phone number/ номер телефон
128
- */
129
- static removeZero(phone: string): string {
130
- if (phone.match(/^0/)) {
131
- return phone.replace(/^0/, '')
132
- } else if (phone.match(/^89/)) {
133
- return phone.replace(/^8/, '')
134
- }
135
-
136
- return phone
137
- }
138
-
139
- /**
140
- * Returns the symbol by the internal country code.
141
- *
142
- * Возвращает символ по коду внутри страны.
143
- * @param within internal country code/ код внутри страны
144
- */
145
- protected static getWithinSymbol(within: number | string): string {
146
- switch (within) {
147
- case 4:
148
- case '4':
149
- return '$'
150
- case 8:
151
- case '8':
152
- return '~'
153
- }
154
-
155
- return '='
156
- }
157
-
158
- /**
159
- * Deletes all characters that do not belong to the mask.
160
- *
161
- * Удаляет все символы, не относящиеся к маске.
162
- * @param mask A mask to transform a phone number/ маска для преобразования номер телефон
163
- */
164
- protected static getUnnecessaryLength(mask: string): number {
165
- return mask.replace(/[^*]+/ig, '').length
166
- }
167
-
168
- /**
169
- * Creating a list for the map.
170
- *
171
- * Формирование списка для карты.
172
- */
173
- protected static makeList(): void {
174
- const list = forEach(Geo.getList(), (item) => {
175
- if (item?.phoneMask) {
176
- return {
177
- phone: (item?.phoneCode && Number(item.phoneCode.replace(/[^0-9]+/, ''))) || undefined,
178
- within: item?.phoneWithin || 0,
179
- mask: toArray(item.phoneMask),
180
- value: item.country
181
- }
182
- }
183
-
184
- return undefined
185
- }) as GeoPhoneValue[]
186
-
187
- this.list = list.sort((a, b) => (a.phone - b.phone))
188
- }
189
-
190
- /**
191
- * Creating a map for search.
192
- *
193
- * Создание карты для поиска.
194
- */
195
- protected static makeMap(): void {
196
- this.list.forEach((item) => {
197
- item.mask.forEach((mask) => {
198
- let focus = this.map
199
- let value: GeoPhoneMap | undefined
200
-
201
- this.toNumber(mask).forEach((number) => {
202
- if (!(number in focus)) {
203
- focus[number] = {
204
- items: [],
205
- info: undefined,
206
- value: undefined,
207
- mask: [],
208
- maskFull: [],
209
- next: {}
210
- }
211
- }
212
-
213
- value = focus[number]
214
- focus = value?.next ?? {}
215
- })
216
-
217
- if (value) {
218
- if (value.value === undefined) {
219
- value.info = item
220
- value.value = item.value
221
- }
222
-
223
- const maskWithin = this.toWithin(mask, item.within)
224
-
225
- value.mask.push(maskWithin)
226
- value.maskFull.push(maskWithin.replace(/\d/ig, '*'))
227
- value.items.push(item)
228
- }
229
- })
230
- })
231
- }
232
-
233
- /**
234
- * The method parses a string argument and returns a floating point number.
235
- *
236
- * Метод принимает строку в качестве аргумента и возвращает десятичное число.
237
- * @param value the value to parse/ текстовая строка
238
- */
239
- protected static toNumber(value: string): string[] {
240
- return value
241
- .replace(/\D+/ig, '')
242
- .split('')
243
- }
244
-
245
- /**
246
- * Converts the phone to a standard.
247
- *
248
- * Преобразовывает телефон в стандарт.
249
- * @param phone phone number/ номер телефон
250
- * @param mask a mask to transform a phone number/ маска для преобразования номер телефон
251
- */
252
- protected static toStandard(phone: string, mask: string): string {
253
- let character = 0
254
- return mask.replace(/\*/ig, () => String(phone[character++]))
255
- }
256
-
257
- /**
258
- * Replaces the first character with the internal country code
259
- *
260
- * Заменяет первый символ на код внутри страны.
261
- * @param mask a mask to transform a phone number/ маска для преобразования номер телефон
262
- * @param within internal country code/ код внутри страны
263
- */
264
- protected static toWithin(mask: string, within: number | string): string {
265
- return mask.replace(/\*/, this.getWithinSymbol(within))
266
- }
267
-
268
- static {
269
- this.makeList()
270
- this.makeMap()
271
- }
272
- }
@@ -1,32 +0,0 @@
1
- let global: Record<string, any>
2
-
3
- /**
4
- * Class for obtaining global data.
5
- *
6
- * Класс для получения глобальных данных.
7
- */
8
- export class Global {
9
- /**
10
- * Returns the value by its name.
11
- *
12
- * Возвращает значение по его имени.
13
- * @param name property name/ название свойства
14
- */
15
- static get<R = any>(name: string): R {
16
- return global && global?.[name]
17
- }
18
-
19
- /**
20
- * Adds data, this method works only once.
21
- *
22
- * Добавляет данные, этот метод работает только 1 раз.
23
- * @param data global data/ глобальные данные
24
- */
25
- static add(data: Record<string, any>) {
26
- if (global !== undefined) {
27
- return
28
- }
29
-
30
- global = { ...data }
31
- }
32
- }
@@ -1,142 +0,0 @@
1
- import { executeFunction } from '../functions/executeFunction'
2
- import { forEach } from '../functions/forEach'
3
- import { getRequestString } from '../functions/getRequestString'
4
- import { isDomRuntime } from '../functions/isDomRuntime'
5
- import { transformation } from '../functions/transformation'
6
-
7
- /**
8
- * Working with data stored in hash.
9
- *
10
- * Работа с данными сохраненными в хеш.
11
- */
12
- export class Hash {
13
- private static hash: Record<string, any> = {}
14
- private static watch: Record<string, ((value: any) => void)[]> = {}
15
- private static block = false
16
-
17
- /**
18
- * Get data from hash.
19
- *
20
- * Получение данных из хэша.
21
- * @param name variable names/ названия переменных
22
- * @param defaultValue value or function to change data/ значение или функция для изменения данных
23
- */
24
- static get<T>(
25
- name: string,
26
- defaultValue?: T | (() => T)
27
- ): T {
28
- if (
29
- !(name in this.hash)
30
- && defaultValue
31
- ) {
32
- this.set(name, defaultValue)
33
- }
34
-
35
- return this.hash[name]
36
- }
37
-
38
- /**
39
- * Change data in hash.
40
- *
41
- * Изменение данных в хэше.
42
- * @param name variable names/ названия переменных
43
- * @param callback value or function to change data/ значение или функция для изменения данных
44
- */
45
- static set<T>(
46
- name: string,
47
- callback: T | (() => T)
48
- ): void {
49
- const value = executeFunction(callback)
50
-
51
- if (value !== this.hash?.[name]) {
52
- this.hash[name] = value
53
- this.update()
54
- }
55
- }
56
-
57
- /**
58
- * Adding an event when data is changed.
59
- *
60
- * Добавление события при изменении данных.
61
- * @param name variable names/ названия переменных
62
- * @param callback the function is called when the data is changed/ функция вызывается при изменении данных
63
- */
64
- static addWatch<T>(
65
- name: string,
66
- callback: (value: T) => void
67
- ): void {
68
- if (name in this.watch) {
69
- this.watch[name]?.push(callback)
70
- } else {
71
- this.watch[name] = [callback]
72
- }
73
- }
74
-
75
- /**
76
- * Update hash variable from URL string.
77
- *
78
- * Обновление переменной хэша из строки URL.
79
- */
80
- static reload(): void {
81
- if (!this.block) {
82
- const location = this.getLocation()
83
-
84
- this.makeWatch(location)
85
- this.hash = location
86
- }
87
- }
88
-
89
- /**
90
- * Obtaining data from the URL string.
91
- *
92
- * Получение данных из строки URL.
93
- */
94
- private static getLocation(): Record<string, any> {
95
- const hash: Record<string, any> = {}
96
-
97
- location.hash.replace(
98
- /([\w-]+)[:=]([^;]+)/ig,
99
- (...item: string[]) => {
100
- hash[String(item[1])] = transformation(item[2])
101
- return ''
102
- }
103
- )
104
-
105
- return hash
106
- }
107
-
108
- /**
109
- * Update hash string in URL.
110
- *
111
- * Обновление строки хэша в URL.
112
- */
113
- private static update(): void {
114
- this.block = true
115
- history.replaceState(null, '', `#${getRequestString(this.hash, '=', ';')}`)
116
-
117
- requestAnimationFrame(() => {
118
- this.block = false
119
- })
120
- }
121
-
122
- /**
123
- * Calling all functions whose data has changed.
124
- *
125
- * Вызов всех функций, у которых были изменены данные.
126
- * @param location fresh data/ свежий данные
127
- */
128
- private static makeWatch(location: Record<string, any>): void {
129
- forEach(this.watch, (item, name) => {
130
- if (this.hash?.[name] !== location?.[name]) {
131
- item.forEach(callback => callback(location[name]))
132
- }
133
- })
134
- }
135
-
136
- static {
137
- if (isDomRuntime()) {
138
- this.reload()
139
- addEventListener('hashchange', () => this.reload())
140
- }
141
- }
142
- }
@@ -1,165 +0,0 @@
1
- import { forEach } from '../functions/forEach'
2
- import { isDomRuntime } from '../functions/isDomRuntime'
3
-
4
- import { Api } from './Api'
5
-
6
- export type IconsItem = string | Promise<string | any>
7
-
8
- const ICONS_KEY = '__UI_ICON'
9
- const ICONS_WAIT = 320
10
- const ICONS_LOAD = '--LOAD--'
11
-
12
- /**
13
- * Class for managing icons.
14
- *
15
- * Класс для управления иконками.
16
- */
17
- export class Icons {
18
- protected static icons: Record<string, IconsItem> = {}
19
- protected static url: string = '/icons/'
20
-
21
- static {
22
- if (isDomRuntime()) {
23
- if (!(ICONS_KEY in window)) {
24
- (window as any)[ICONS_KEY] = {}
25
- }
26
-
27
- this.icons = (window as any)[ICONS_KEY]
28
- }
29
- }
30
-
31
- /**
32
- * Checks if the given icon is in the list of connected icons.
33
- *
34
- * Проверяет, есть ли данная иконка в списке подключенных иконок.
35
- * @param index icon name/ название иконки
36
- */
37
- static is(index: string): boolean {
38
- return index in this.icons || this.getName(index) in this.icons
39
- }
40
-
41
- /**
42
- * Returns the icon by the name.
43
- *
44
- * Возвращает иконку по названию.
45
- * @param index icon name/ название иконки
46
- * @param url path to the storage location of the icon, if the icon does not exist/
47
- * путь к месту хранения иконки, если иконка не существует
48
- * @param wait waiting time for picture loading/
49
- * время ожидания загрузки картинки
50
- */
51
- static async get(
52
- index: string,
53
- url = '',
54
- wait: number = 1000 * 60 * 3
55
- ): Promise<string> {
56
- const icon = this.icons?.[this.getName(index)]
57
- ?? this.icons?.[index]
58
- ?? `${index.replace(/^@/, url ?? this.url)}.svg`
59
-
60
- if (typeof icon === 'string') {
61
- if (
62
- icon === ICONS_LOAD
63
- && wait > 0
64
- ) {
65
- await this.wait()
66
- return this.get(index, url, wait - ICONS_WAIT)
67
- }
68
-
69
- return icon
70
- }
71
-
72
- return await icon
73
- }
74
-
75
- /**
76
- * Returns a list of names of all registered icons.
77
- *
78
- * Возвращает список названий всех зарегистрированных иконок.
79
- */
80
- static getNameList(): string[] {
81
- return forEach(this.icons, (_, name) => {
82
- return name.replace(/^@/, '')
83
- })
84
- }
85
-
86
- /**
87
- * Returns a global link.
88
- *
89
- * Возвращает глобальную ссылку.
90
- */
91
- static getUrlGlobal() {
92
- return `${Api.isLocalhost() ? '' : ''}${this.url}`
93
- }
94
-
95
- /**
96
- * Adding custom icons.
97
- *
98
- * Добавление пользовательских иконок.
99
- * @param index icon name/ название иконки
100
- * @param file path to the file/ путь к файлу
101
- */
102
- static add(index: string, file: IconsItem): void {
103
- this.icons[this.getName(index)] = file
104
- }
105
-
106
- /**
107
- * Adding custom icons in loading mode.
108
- *
109
- * Добавление пользовательских иконок в режиме загрузки.
110
- * @param index icon name/ название иконки
111
- */
112
- static addLoad(index: string): void {
113
- this.icons[this.getName(index)] = ICONS_LOAD
114
- }
115
-
116
- /**
117
- * Adding custom global icons.
118
- *
119
- * Добавление пользовательских глобальных иконок.
120
- * @param index icon name/ название иконки
121
- * @param file path to the file/ путь к файлу
122
- */
123
- static addGlobal(index: string, file: string): void {
124
- this.icons[this.getName(index)] = `${this.getUrlGlobal()}${file}`
125
- }
126
-
127
- /**
128
- * Adding an icon by the list.
129
- *
130
- * Добавление иконки по списку.
131
- * @param list list of icons/ список иконки
132
- */
133
- static addByList(list: Record<string, IconsItem>): void {
134
- forEach(list, (file, index) => this.add(index, file))
135
- }
136
-
137
- /**
138
- * Changes the file path.
139
- *
140
- * Изменяет путь к файлу.
141
- * @param url new file path/ новый путь к файлу
142
- */
143
- static setUrl(url: string): void {
144
- this.url = url
145
- }
146
-
147
- /**
148
- * Returns the icon name.
149
- *
150
- * Возвращает название иконки.
151
- * @param index icon name/ название иконки
152
- */
153
- protected static getName(index: string): string {
154
- return `@${index}`
155
- }
156
-
157
- /**
158
- * Script execution delay.
159
- *
160
- * Задержка выполнения скрипта.
161
- */
162
- protected static wait(): Promise<void> {
163
- return new Promise(resolve => setTimeout(() => resolve(), ICONS_WAIT))
164
- }
165
- }
@@ -1,90 +0,0 @@
1
- import { isDomRuntime } from '../functions/isDomRuntime'
2
-
3
- import { EventItem } from './EventItem'
4
-
5
- import {
6
- type ElementOrString,
7
- type EventListenerDetail
8
- } from '../types/basicTypes'
9
-
10
- type LoadingDetail = {
11
- loading: boolean
12
- }
13
-
14
- const LOADING_EVENT_NAME = 'ui-loading'
15
-
16
- /**
17
- * Class for working with global loading.
18
- *
19
- * Класс для работы с глобальной загрузкой.
20
- */
21
- export class Loading {
22
- protected static value = 0
23
- protected static event?: EventItem<Window, CustomEvent>
24
-
25
- /**
26
- * Check if the loader is active now.
27
- *
28
- * Проверить, активен ли сейчас загрузчик.
29
- */
30
- static is(): boolean {
31
- return this.value > 0
32
- }
33
-
34
- /**
35
- * Shows the loader.
36
- *
37
- * Показывает загрузчик.
38
- */
39
- static show(): void {
40
- this.value++
41
- this.dispatch()
42
- }
43
-
44
- /**
45
- * Hides the loader.
46
- *
47
- * Скрывает загрузчик.
48
- */
49
- static hide(): void {
50
- if (this.is()) {
51
- this.value--
52
- this.dispatch()
53
- }
54
- }
55
-
56
- /**
57
- * Event registration to listen for data changes.
58
- *
59
- * Регистрация события для прослушивания изменений данных.
60
- * @param listener the object that receives a notification (an object that implements the
61
- * Event interface) when an event of the specified type occurs/ объект, который принимает
62
- * уведомление, когда событие указанного типа произошло
63
- * @param element element/ элемент
64
- */
65
- static registrationEvent(
66
- listener: EventListenerDetail<CustomEvent, LoadingDetail>,
67
- element?: ElementOrString<HTMLElement>
68
- ) {
69
- if (isDomRuntime()) {
70
- new EventItem(window, LOADING_EVENT_NAME, listener)
71
- .setElementControl(element)
72
- .start()
73
- }
74
- }
75
-
76
- /**
77
- * Calls the event listener.
78
- *
79
- * Вызывает слушателя событий.
80
- */
81
- protected static dispatch(): void {
82
- this.event?.dispatch({ loading: this.is() } as LoadingDetail)
83
- }
84
-
85
- static {
86
- if (isDomRuntime()) {
87
- this.event = new EventItem(window, LOADING_EVENT_NAME)
88
- }
89
- }
90
- }