@sevtech/kit 21.0.0 → 21.1.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/ui/index.d.ts CHANGED
@@ -1,8 +1,103 @@
1
1
  import * as i0 from '@angular/core';
2
- import { PipeTransform, Type } from '@angular/core';
3
- import { SafeAny, DeepKeys, PickKey } from '@sevtech/kit/misc';
2
+ import { PipeTransform, EnvironmentProviders, TemplateRef, Type } from '@angular/core';
3
+ import { MaybeFunction, SafeAny, DeepKeys, PickKey } from '@sevtech/kit/misc';
4
4
  import { SafeUrl, SafeHtml, SafeStyle, SafeScript, SafeResourceUrl } from '@angular/platform-browser';
5
5
 
6
+ interface BytesFormat {
7
+ /** Делитель разряда: 1024 для байтов, 1000 для битов и величин СИ */
8
+ base: number;
9
+ /** Знаков после запятой */
10
+ precision: number;
11
+ /** Единицы измерения от младшей к старшей */
12
+ units: readonly string[];
13
+ /** Шаблон вывода: `{{ value }}` - число, `{{ unit }}` - единица измерения */
14
+ template: string;
15
+ /** Что выводить вместо отрицательных, `NaN` и `Infinity` */
16
+ empty: string;
17
+ /** Что выводить вместо нуля; `null` - выводить его как обычное значение */
18
+ zero: string | null;
19
+ }
20
+ interface BytesConfig extends BytesFormat {
21
+ /**
22
+ * Именованные наборы правил для повторяющихся сценариев
23
+ * @example
24
+ * presets: {
25
+ * bitrate: {
26
+ * base: 1000,
27
+ * units: ['бит', 'Кбит', 'Мбит'],
28
+ * template: 'до {{ value }} {{ unit }}/с'
29
+ * }
30
+ *}
31
+ */
32
+ presets: Record<string, Partial<BytesFormat>>;
33
+ }
34
+
35
+ /**
36
+ * Переводит число в человекочитаемый размер с подбором единицы измерения
37
+ * @description
38
+ * Формат берётся из `BYTES_CONFIG`, аргумент перекрывает его именем пресета
39
+ * или объектом. Для отрицательных, `NaN` и `Infinity` выводится `empty`
40
+ *
41
+ * @example
42
+ * {{ file.size | bytes }} // 2 MB
43
+ * {{ speed | bytes: 'bitrate' }} // до 1.5 Мбит/с
44
+ * {{ speed | bytes: { precision: 2 } }}
45
+ */
46
+ declare class BytesPipe implements PipeTransform {
47
+ private readonly config;
48
+ transform(value: number, preset?: string | Partial<BytesFormat>): string;
49
+ static ɵfac: i0.ɵɵFactoryDeclaration<BytesPipe, never>;
50
+ static ɵpipe: i0.ɵɵPipeDeclaration<BytesPipe, "bytes", true>;
51
+ }
52
+
53
+ /**
54
+ * Настраивает `BytesPipe`.
55
+ * @description Задаёт формат по умолчанию и именованные пресеты. `presets`
56
+ * доливаются к уже объявленным, остальные поля перекрываются целиком.
57
+ * Фабрика вызывается в контексте инжектора, поэтому единицы можно взять
58
+ * из переводов.
59
+ * @example
60
+ * provideBytesConfig({
61
+ * precision: 1,
62
+ * presets: {
63
+ * bitrate: {
64
+ * base: 1000,
65
+ * units: ['бит', 'Кбит', 'Мбит', 'Гбит', 'Тбит'],
66
+ * template: 'до {{ value }} {{ unit }}/с',
67
+ * },
68
+ * },
69
+ * });
70
+ */
71
+ declare function provideBytesConfig(config: MaybeFunction<Partial<BytesConfig>>): EnvironmentProviders;
72
+
73
+ /**
74
+ * Оборачивает совпадения в `<mark>` с настраиваемым классом
75
+ * @description
76
+ * - По умолчанию подсвечиваются все совпадения без учёта регистра, флаги регулярки настраиваются
77
+ * - Текст экранируется, разметку добавляет только пайп - результат безопасен для `innerHTML`
78
+ * - Пустой запрос возвращает исходный текст
79
+ * - Класс по умолчанию берётся из `HIGHLIGHT_CLASS`, стилей пакет не поставляет
80
+ *
81
+ * @example
82
+ * <span [innerHTML]="label | highlight: query()"></span>
83
+ * <span [innerHTML]="label | highlight: query() : 'search-match'"></span>
84
+ * <span [innerHTML]="label | highlight: query() : 'search-match' : 'g'"></span> // с учётом регистра
85
+ */
86
+ declare class HighlightPipe implements PipeTransform {
87
+ private readonly defaultClass;
88
+ transform(value: string, search: string, flags?: string, className?: string): string;
89
+ static ɵfac: i0.ɵɵFactoryDeclaration<HighlightPipe, never>;
90
+ static ɵpipe: i0.ɵɵPipeDeclaration<HighlightPipe, "highlight", true>;
91
+ }
92
+
93
+ /**
94
+ * Задаёт css-класс, который `HighlightPipe` вешает на `<mark>`.
95
+ * @description Стилей пакет не поставляет - вид подсветки задаёт приложение.
96
+ * @example
97
+ * provideHighlightClass('search-match');
98
+ */
99
+ declare function provideHighlightClass(className: string): EnvironmentProviders;
100
+
6
101
  declare class PickKeyPipe implements PipeTransform {
7
102
  transform<const Object extends Record<string, SafeAny>, const Path extends DeepKeys<Object>, const Fallback extends unknown>(object: Object, path: Path, fallback?: Fallback): PickKey<Object, Path> extends Object ? Fallback : PickKey<Object, Path>;
8
103
  transform<const Object extends Record<string, SafeAny>, const Path extends DeepKeys<Object, Separator>, const Separator extends string, const Fallback extends unknown>(object: Object, path: Path, fallback?: Fallback, separator?: Separator): PickKey<Object, Path> extends Object ? Fallback : PickKey<Object, Path>;
@@ -41,6 +136,33 @@ declare class EllipsisDirective {
41
136
  static ɵdir: i0.ɵɵDirectiveDeclaration<EllipsisDirective, "[ellipsis]", ["ellipsis"], { "ellipsis": { "alias": "ellipsis"; "required": false; "isSignal": true; }; "showTitle": { "alias": "showTitle"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
42
137
  }
43
138
 
139
+ type ExcludeTemplate<T> = Exclude<T, TemplateRef<unknown>>;
140
+ type ImplicitContext<T> = {
141
+ $implicit: ExcludeTemplate<T>;
142
+ };
143
+ /**
144
+ * Рендерит переданный TemplateRef, либо собственный шаблон с контентом в `$implicit`
145
+ * @example
146
+ * <ng-container *slotOutlet="hintSlot$$() ?? hintMessage(); let-text">
147
+ * <span>{{ text }}</span>
148
+ * </ng-container>
149
+ */
150
+ declare class SlotOutletDirective<T, C = unknown> {
151
+ private readonly viewContainer;
152
+ private readonly fallbackRef;
153
+ private viewRef;
154
+ private renderedRef;
155
+ readonly slotOutlet: i0.InputSignal<T>;
156
+ readonly slotOutletContext: i0.InputSignal<C | null>;
157
+ constructor();
158
+ static ngTemplateContextGuard<T, C>(directive: SlotOutletDirective<T, C>, context: unknown): context is ImplicitContext<T>;
159
+ private render;
160
+ private resolveContext;
161
+ private patchContext;
162
+ static ɵfac: i0.ɵɵFactoryDeclaration<SlotOutletDirective<any, any>, never>;
163
+ static ɵdir: i0.ɵɵDirectiveDeclaration<SlotOutletDirective<any, any>, "[slotOutlet]", ["slotOutlet"], { "slotOutlet": { "alias": "slotOutlet"; "required": true; "isSignal": true; }; "slotOutletContext": { "alias": "slotOutletContext"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
164
+ }
165
+
44
166
  declare function withStylesDirective(component: Type<unknown>): undefined;
45
167
 
46
- export { EllipsisDirective, PickKeyPipe, SafePipe, withStylesDirective };
168
+ export { BytesPipe, EllipsisDirective, HighlightPipe, PickKeyPipe, SafePipe, SlotOutletDirective, provideBytesConfig, provideHighlightClass, withStylesDirective };