@tectra-ng/utils 0.0.1 → 0.2.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/LICENSE +21 -0
- package/README.md +40 -1
- package/auto-focus/README.md +19 -0
- package/breakpoint/README.md +23 -0
- package/clipboard/README.md +37 -0
- package/clock/README.md +21 -0
- package/currency/README.md +17 -0
- package/date/README.md +46 -0
- package/debounce-input/README.md +31 -0
- package/drag-scroll/README.md +25 -0
- package/fesm2022/tectra-ng-utils-auto-focus.mjs +100 -0
- package/fesm2022/tectra-ng-utils-auto-focus.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-breakpoint.mjs +54 -0
- package/fesm2022/tectra-ng-utils-breakpoint.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-clipboard.mjs +225 -0
- package/fesm2022/tectra-ng-utils-clipboard.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-clock.mjs +59 -0
- package/fesm2022/tectra-ng-utils-clock.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-currency.mjs +63 -0
- package/fesm2022/tectra-ng-utils-currency.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-date.mjs +200 -0
- package/fesm2022/tectra-ng-utils-date.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-debounce-input.mjs +156 -0
- package/fesm2022/tectra-ng-utils-debounce-input.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-drag-scroll.mjs +199 -0
- package/fesm2022/tectra-ng-utils-drag-scroll.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-file.mjs +78 -0
- package/fesm2022/tectra-ng-utils-file.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-filter-state.mjs +238 -0
- package/fesm2022/tectra-ng-utils-filter-state.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-filter.mjs +88 -0
- package/fesm2022/tectra-ng-utils-filter.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-form-changes.mjs +70 -0
- package/fesm2022/tectra-ng-utils-form-changes.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-form-validation.mjs +162 -0
- package/fesm2022/tectra-ng-utils-form-validation.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-go-back.mjs +117 -0
- package/fesm2022/tectra-ng-utils-go-back.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-http.mjs +189 -0
- package/fesm2022/tectra-ng-utils-http.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-in-view.mjs +297 -0
- package/fesm2022/tectra-ng-utils-in-view.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-plural.mjs +98 -0
- package/fesm2022/tectra-ng-utils-plural.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-polling.mjs +109 -0
- package/fesm2022/tectra-ng-utils-polling.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-random.mjs +20 -0
- package/fesm2022/tectra-ng-utils-random.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-relative-time.mjs +87 -0
- package/fesm2022/tectra-ng-utils-relative-time.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-scroll-end.mjs +136 -0
- package/fesm2022/tectra-ng-utils-scroll-end.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-selection.mjs +52 -0
- package/fesm2022/tectra-ng-utils-selection.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-stop-propagation.mjs +92 -0
- package/fesm2022/tectra-ng-utils-stop-propagation.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-stream.mjs +30 -0
- package/fesm2022/tectra-ng-utils-stream.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-style-class.mjs +350 -0
- package/fesm2022/tectra-ng-utils-style-class.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-text.mjs +173 -0
- package/fesm2022/tectra-ng-utils-text.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-title.mjs +99 -0
- package/fesm2022/tectra-ng-utils-title.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils-validators.mjs +232 -0
- package/fesm2022/tectra-ng-utils-validators.mjs.map +1 -0
- package/fesm2022/tectra-ng-utils.mjs +4 -0
- package/fesm2022/tectra-ng-utils.mjs.map +1 -0
- package/file/README.md +19 -0
- package/filter/README.md +22 -0
- package/filter-state/README.md +36 -0
- package/form-changes/README.md +26 -0
- package/form-validation/README.md +40 -0
- package/go-back/README.md +28 -0
- package/http/README.md +34 -0
- package/in-view/README.md +34 -0
- package/package.json +173 -3
- package/plural/README.md +21 -0
- package/polling/README.md +34 -0
- package/random/README.md +10 -0
- package/relative-time/README.md +29 -0
- package/scroll-end/README.md +25 -0
- package/selection/README.md +24 -0
- package/stop-propagation/README.md +15 -0
- package/stream/README.md +14 -0
- package/style-class/README.md +34 -0
- package/text/README.md +25 -0
- package/title/README.md +26 -0
- package/types/tectra-ng-utils-auto-focus.d.ts +22 -0
- package/types/tectra-ng-utils-auto-focus.d.ts.map +1 -0
- package/types/tectra-ng-utils-breakpoint.d.ts +15 -0
- package/types/tectra-ng-utils-breakpoint.d.ts.map +1 -0
- package/types/tectra-ng-utils-clipboard.d.ts +48 -0
- package/types/tectra-ng-utils-clipboard.d.ts.map +1 -0
- package/types/tectra-ng-utils-clock.d.ts +18 -0
- package/types/tectra-ng-utils-clock.d.ts.map +1 -0
- package/types/tectra-ng-utils-currency.d.ts +11 -0
- package/types/tectra-ng-utils-currency.d.ts.map +1 -0
- package/types/tectra-ng-utils-date.d.ts +65 -0
- package/types/tectra-ng-utils-date.d.ts.map +1 -0
- package/types/tectra-ng-utils-debounce-input.d.ts +38 -0
- package/types/tectra-ng-utils-debounce-input.d.ts.map +1 -0
- package/types/tectra-ng-utils-drag-scroll.d.ts +41 -0
- package/types/tectra-ng-utils-drag-scroll.d.ts.map +1 -0
- package/types/tectra-ng-utils-file.d.ts +18 -0
- package/types/tectra-ng-utils-file.d.ts.map +1 -0
- package/types/tectra-ng-utils-filter-state.d.ts +55 -0
- package/types/tectra-ng-utils-filter-state.d.ts.map +1 -0
- package/types/tectra-ng-utils-filter.d.ts +21 -0
- package/types/tectra-ng-utils-filter.d.ts.map +1 -0
- package/types/tectra-ng-utils-form-changes.d.ts +22 -0
- package/types/tectra-ng-utils-form-changes.d.ts.map +1 -0
- package/types/tectra-ng-utils-form-validation.d.ts +45 -0
- package/types/tectra-ng-utils-form-validation.d.ts.map +1 -0
- package/types/tectra-ng-utils-go-back.d.ts +25 -0
- package/types/tectra-ng-utils-go-back.d.ts.map +1 -0
- package/types/tectra-ng-utils-http.d.ts +47 -0
- package/types/tectra-ng-utils-http.d.ts.map +1 -0
- package/types/tectra-ng-utils-in-view.d.ts +80 -0
- package/types/tectra-ng-utils-in-view.d.ts.map +1 -0
- package/types/tectra-ng-utils-plural.d.ts +21 -0
- package/types/tectra-ng-utils-plural.d.ts.map +1 -0
- package/types/tectra-ng-utils-polling.d.ts +61 -0
- package/types/tectra-ng-utils-polling.d.ts.map +1 -0
- package/types/tectra-ng-utils-random.d.ts +4 -0
- package/types/tectra-ng-utils-random.d.ts.map +1 -0
- package/types/tectra-ng-utils-relative-time.d.ts +22 -0
- package/types/tectra-ng-utils-relative-time.d.ts.map +1 -0
- package/types/tectra-ng-utils-scroll-end.d.ts +38 -0
- package/types/tectra-ng-utils-scroll-end.d.ts.map +1 -0
- package/types/tectra-ng-utils-selection.d.ts +21 -0
- package/types/tectra-ng-utils-selection.d.ts.map +1 -0
- package/types/tectra-ng-utils-stop-propagation.d.ts +22 -0
- package/types/tectra-ng-utils-stop-propagation.d.ts.map +1 -0
- package/types/tectra-ng-utils-stream.d.ts +3 -0
- package/types/tectra-ng-utils-stream.d.ts.map +1 -0
- package/types/tectra-ng-utils-style-class.d.ts +91 -0
- package/types/tectra-ng-utils-style-class.d.ts.map +1 -0
- package/types/tectra-ng-utils-text.d.ts +26 -0
- package/types/tectra-ng-utils-text.d.ts.map +1 -0
- package/types/tectra-ng-utils-title.d.ts +31 -0
- package/types/tectra-ng-utils-title.d.ts.map +1 -0
- package/types/tectra-ng-utils-validators.d.ts +67 -0
- package/types/tectra-ng-utils-validators.d.ts.map +1 -0
- package/types/tectra-ng-utils.d.ts +2 -0
- package/types/tectra-ng-utils.d.ts.map +1 -0
- package/validators/README.md +42 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
async function* textChunks(response) {
|
|
2
|
+
const reader = response.body?.getReader();
|
|
3
|
+
if (!reader) return;
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
try {
|
|
6
|
+
for (;;) {
|
|
7
|
+
const { done, value } = await reader.read();
|
|
8
|
+
if (done) {
|
|
9
|
+
const rest = decoder.decode();
|
|
10
|
+
if (rest) yield rest;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
14
|
+
if (chunk) yield chunk;
|
|
15
|
+
}
|
|
16
|
+
} finally {
|
|
17
|
+
reader.releaseLock();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function readTextStream(response, onChunk) {
|
|
21
|
+
let text = "";
|
|
22
|
+
for await (const chunk of textChunks(response)) {
|
|
23
|
+
text += chunk;
|
|
24
|
+
onChunk(chunk, text);
|
|
25
|
+
}
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
export { readTextStream, textChunks };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=tectra-ng-utils-stream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-stream.mjs","names":[],"sources":["../../../../packages/utils/stream/src/stream.ts"],"sourcesContent":["export async function* textChunks(response: Response): AsyncGenerator<string> {\n const reader = response.body?.getReader();\n if (!reader) {\n return;\n }\n const decoder = new TextDecoder();\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) {\n const rest = decoder.decode();\n if (rest) {\n yield rest;\n }\n return;\n }\n const chunk = decoder.decode(value, { stream: true });\n if (chunk) {\n yield chunk;\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nexport async function readTextStream(response: Response, onChunk: (chunk: string, text: string) => void): Promise<string> {\n let text = '';\n for await (const chunk of textChunks(response)) {\n text += chunk;\n onChunk(chunk, text);\n }\n return text;\n}\n"],"mappings":"AAAA,gBAAuB,WAAW,UAAkB;CAClD,MAAM,SAAS,SAAS,MAAM,UAAS;CACvC,IAAI,CAAC,QACH;CAEF,MAAM,UAAU,IAAI,YAAW;CAC/B,IAAI;EACF,SAAS;GACP,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,KAAI;GACzC,IAAI,MAAM;IACR,MAAM,OAAO,QAAQ,OAAM;IAC3B,IAAI,MACF,MAAM;IAER;GACF;GACA,MAAM,QAAQ,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAI,CAAE;GACpD,IAAI,OACF,MAAM;EAEV;CACF,UAAU;EACR,OAAO,YAAW;CACpB;AACF;AAEA,eAAsB,eAAe,UAAoB,SAA8C;CACrG,IAAI,OAAO;CACX,WAAW,MAAM,SAAS,WAAW,QAAQ,GAAG;EAC9C,QAAQ;EACR,QAAQ,OAAO,IAAI;CACrB;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { DOCUMENT } from "@angular/common";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { DestroyRef, Directive, ElementRef, Renderer2, booleanAttribute, inject, input, signal } from "@angular/core";
|
|
4
|
+
function toSelector(value) {
|
|
5
|
+
return typeof value === "string" && value.trim() ? value.trim() : "@next";
|
|
6
|
+
}
|
|
7
|
+
const split = (classes) => (classes ?? "").split(/\s+/).filter(Boolean);
|
|
8
|
+
var TxStyleClass = class TxStyleClass {
|
|
9
|
+
host = inject(ElementRef).nativeElement;
|
|
10
|
+
renderer = inject(Renderer2);
|
|
11
|
+
document = inject(DOCUMENT);
|
|
12
|
+
listeners = [];
|
|
13
|
+
animating = false;
|
|
14
|
+
endTimer;
|
|
15
|
+
selector = input("@next", {
|
|
16
|
+
...ngDevMode ? { debugName: "selector" } : /* istanbul ignore next */ {},
|
|
17
|
+
alias: "txStyleClass",
|
|
18
|
+
transform: toSelector
|
|
19
|
+
});
|
|
20
|
+
enterFromClass = input(void 0, ...ngDevMode ? [{ debugName: "enterFromClass" }] : /* istanbul ignore next */ []);
|
|
21
|
+
enterActiveClass = input(void 0, ...ngDevMode ? [{ debugName: "enterActiveClass" }] : /* istanbul ignore next */ []);
|
|
22
|
+
enterToClass = input(void 0, ...ngDevMode ? [{ debugName: "enterToClass" }] : /* istanbul ignore next */ []);
|
|
23
|
+
leaveFromClass = input(void 0, ...ngDevMode ? [{ debugName: "leaveFromClass" }] : /* istanbul ignore next */ []);
|
|
24
|
+
leaveActiveClass = input(void 0, ...ngDevMode ? [{ debugName: "leaveActiveClass" }] : /* istanbul ignore next */ []);
|
|
25
|
+
leaveToClass = input(void 0, ...ngDevMode ? [{ debugName: "leaveToClass" }] : /* istanbul ignore next */ []);
|
|
26
|
+
toggleClass = input(void 0, ...ngDevMode ? [{ debugName: "toggleClass" }] : /* istanbul ignore next */ []);
|
|
27
|
+
hideOnOutsideClick = input(false, {
|
|
28
|
+
...ngDevMode ? { debugName: "hideOnOutsideClick" } : /* istanbul ignore next */ {},
|
|
29
|
+
transform: booleanAttribute
|
|
30
|
+
});
|
|
31
|
+
hideOnEscape = input(false, {
|
|
32
|
+
...ngDevMode ? { debugName: "hideOnEscape" } : /* istanbul ignore next */ {},
|
|
33
|
+
transform: booleanAttribute
|
|
34
|
+
});
|
|
35
|
+
hideOnResize = input(false, {
|
|
36
|
+
...ngDevMode ? { debugName: "hideOnResize" } : /* istanbul ignore next */ {},
|
|
37
|
+
transform: booleanAttribute
|
|
38
|
+
});
|
|
39
|
+
expanded = signal(false, ...ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []);
|
|
40
|
+
constructor() {
|
|
41
|
+
inject(DestroyRef).onDestroy(() => {
|
|
42
|
+
this.unbind();
|
|
43
|
+
clearTimeout(this.endTimer);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
target() {
|
|
47
|
+
const selector = this.selector();
|
|
48
|
+
switch (selector) {
|
|
49
|
+
case "@next": return this.host.nextElementSibling;
|
|
50
|
+
case "@prev": return this.host.previousElementSibling;
|
|
51
|
+
case "@parent": return this.host.parentElement;
|
|
52
|
+
case "@grandparent": return this.host.parentElement?.parentElement ?? null;
|
|
53
|
+
default: return this.document.querySelector(selector);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
toggle() {
|
|
57
|
+
const target = this.target();
|
|
58
|
+
if (!target || this.animating) return;
|
|
59
|
+
const toggleClass = this.toggleClass();
|
|
60
|
+
if (toggleClass) {
|
|
61
|
+
split(toggleClass).forEach((name) => target.classList.contains(name) ? this.renderer.removeClass(target, name) : this.renderer.addClass(target, name));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (this.isHidden(target)) this.enter(target);
|
|
65
|
+
else this.leave(target);
|
|
66
|
+
}
|
|
67
|
+
enter(target = this.target()) {
|
|
68
|
+
if (!target) return;
|
|
69
|
+
this.swap(target, [...split(this.leaveToClass()), ...split(this.enterFromClass())], split(this.enterToClass()));
|
|
70
|
+
this.expanded.set(true);
|
|
71
|
+
this.bind(target);
|
|
72
|
+
this.animate(target, split(this.enterActiveClass()));
|
|
73
|
+
}
|
|
74
|
+
leave(target = this.target()) {
|
|
75
|
+
if (!target) return;
|
|
76
|
+
const active = split(this.leaveActiveClass());
|
|
77
|
+
this.unbind();
|
|
78
|
+
this.expanded.set(false);
|
|
79
|
+
this.renderer.addClass(target, "__tx-leaving");
|
|
80
|
+
split(this.leaveFromClass()).forEach((name) => this.renderer.addClass(target, name));
|
|
81
|
+
this.animate(target, active, () => {
|
|
82
|
+
this.renderer.removeClass(target, "__tx-leaving");
|
|
83
|
+
this.swap(target, [...split(this.enterToClass()), ...split(this.leaveFromClass())], split(this.leaveToClass()));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
animate(target, active, done) {
|
|
87
|
+
const reduced = this.document.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
88
|
+
if (!active.length || reduced) {
|
|
89
|
+
done?.();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.animating = true;
|
|
93
|
+
active.forEach((name) => this.renderer.addClass(target, name));
|
|
94
|
+
const finish = () => {
|
|
95
|
+
if (!this.animating) return;
|
|
96
|
+
this.animating = false;
|
|
97
|
+
clearTimeout(this.endTimer);
|
|
98
|
+
stopAnimation();
|
|
99
|
+
stopTransition();
|
|
100
|
+
active.forEach((name) => this.renderer.removeClass(target, name));
|
|
101
|
+
done?.();
|
|
102
|
+
};
|
|
103
|
+
const stopAnimation = this.renderer.listen(target, "animationend", finish);
|
|
104
|
+
const stopTransition = this.renderer.listen(target, "transitionend", finish);
|
|
105
|
+
this.endTimer = setTimeout(finish, this.duration(target) + 50);
|
|
106
|
+
}
|
|
107
|
+
duration(target) {
|
|
108
|
+
const style = this.document.defaultView?.getComputedStyle(target);
|
|
109
|
+
const toMs = (value) => Math.max(0, ...(value ?? "0s").split(",").map((part) => parseFloat(part) * (part.trim().endsWith("ms") ? 1 : 1e3) || 0));
|
|
110
|
+
return Math.max(toMs(style?.animationDuration), toMs(style?.transitionDuration));
|
|
111
|
+
}
|
|
112
|
+
swap(target, remove, add) {
|
|
113
|
+
remove.forEach((name) => this.renderer.removeClass(target, name));
|
|
114
|
+
add.forEach((name) => this.renderer.addClass(target, name));
|
|
115
|
+
}
|
|
116
|
+
isHidden(target) {
|
|
117
|
+
if (target.classList.contains("__tx-leaving")) return true;
|
|
118
|
+
const hiddenBy = split(this.leaveToClass());
|
|
119
|
+
if (hiddenBy.length) return hiddenBy.every((name) => target.classList.contains(name));
|
|
120
|
+
return target.offsetParent === null && this.document.defaultView?.getComputedStyle(target).position !== "fixed";
|
|
121
|
+
}
|
|
122
|
+
bind(target) {
|
|
123
|
+
this.unbind();
|
|
124
|
+
if (this.hideOnOutsideClick()) this.listeners.push(this.renderer.listen(this.document, "click", (event) => {
|
|
125
|
+
const node = event.target;
|
|
126
|
+
if (node && !target.contains(node) && !this.host.contains(node) && !this.isHidden(target)) this.leave(target);
|
|
127
|
+
}));
|
|
128
|
+
if (this.hideOnEscape()) this.listeners.push(this.renderer.listen(this.document, "keydown", (event) => {
|
|
129
|
+
if (event.key === "Escape" && !this.isHidden(target)) {
|
|
130
|
+
this.leave(target);
|
|
131
|
+
this.host.focus?.();
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
if (this.hideOnResize()) this.listeners.push(this.renderer.listen("window", "resize", () => !this.isHidden(target) && this.leave(target)));
|
|
135
|
+
}
|
|
136
|
+
unbind() {
|
|
137
|
+
this.listeners.splice(0).forEach((stop) => stop());
|
|
138
|
+
}
|
|
139
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
140
|
+
minVersion: "12.0.0",
|
|
141
|
+
version: "22.2.3",
|
|
142
|
+
ngImport: i0,
|
|
143
|
+
type: TxStyleClass,
|
|
144
|
+
deps: [],
|
|
145
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
146
|
+
});
|
|
147
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
148
|
+
minVersion: "17.1.0",
|
|
149
|
+
version: "22.2.3",
|
|
150
|
+
type: TxStyleClass,
|
|
151
|
+
isStandalone: true,
|
|
152
|
+
selector: "[txStyleClass]",
|
|
153
|
+
inputs: {
|
|
154
|
+
selector: {
|
|
155
|
+
classPropertyName: "selector",
|
|
156
|
+
publicName: "txStyleClass",
|
|
157
|
+
isSignal: true,
|
|
158
|
+
isRequired: false,
|
|
159
|
+
transformFunction: null
|
|
160
|
+
},
|
|
161
|
+
enterFromClass: {
|
|
162
|
+
classPropertyName: "enterFromClass",
|
|
163
|
+
publicName: "enterFromClass",
|
|
164
|
+
isSignal: true,
|
|
165
|
+
isRequired: false,
|
|
166
|
+
transformFunction: null
|
|
167
|
+
},
|
|
168
|
+
enterActiveClass: {
|
|
169
|
+
classPropertyName: "enterActiveClass",
|
|
170
|
+
publicName: "enterActiveClass",
|
|
171
|
+
isSignal: true,
|
|
172
|
+
isRequired: false,
|
|
173
|
+
transformFunction: null
|
|
174
|
+
},
|
|
175
|
+
enterToClass: {
|
|
176
|
+
classPropertyName: "enterToClass",
|
|
177
|
+
publicName: "enterToClass",
|
|
178
|
+
isSignal: true,
|
|
179
|
+
isRequired: false,
|
|
180
|
+
transformFunction: null
|
|
181
|
+
},
|
|
182
|
+
leaveFromClass: {
|
|
183
|
+
classPropertyName: "leaveFromClass",
|
|
184
|
+
publicName: "leaveFromClass",
|
|
185
|
+
isSignal: true,
|
|
186
|
+
isRequired: false,
|
|
187
|
+
transformFunction: null
|
|
188
|
+
},
|
|
189
|
+
leaveActiveClass: {
|
|
190
|
+
classPropertyName: "leaveActiveClass",
|
|
191
|
+
publicName: "leaveActiveClass",
|
|
192
|
+
isSignal: true,
|
|
193
|
+
isRequired: false,
|
|
194
|
+
transformFunction: null
|
|
195
|
+
},
|
|
196
|
+
leaveToClass: {
|
|
197
|
+
classPropertyName: "leaveToClass",
|
|
198
|
+
publicName: "leaveToClass",
|
|
199
|
+
isSignal: true,
|
|
200
|
+
isRequired: false,
|
|
201
|
+
transformFunction: null
|
|
202
|
+
},
|
|
203
|
+
toggleClass: {
|
|
204
|
+
classPropertyName: "toggleClass",
|
|
205
|
+
publicName: "toggleClass",
|
|
206
|
+
isSignal: true,
|
|
207
|
+
isRequired: false,
|
|
208
|
+
transformFunction: null
|
|
209
|
+
},
|
|
210
|
+
hideOnOutsideClick: {
|
|
211
|
+
classPropertyName: "hideOnOutsideClick",
|
|
212
|
+
publicName: "hideOnOutsideClick",
|
|
213
|
+
isSignal: true,
|
|
214
|
+
isRequired: false,
|
|
215
|
+
transformFunction: null
|
|
216
|
+
},
|
|
217
|
+
hideOnEscape: {
|
|
218
|
+
classPropertyName: "hideOnEscape",
|
|
219
|
+
publicName: "hideOnEscape",
|
|
220
|
+
isSignal: true,
|
|
221
|
+
isRequired: false,
|
|
222
|
+
transformFunction: null
|
|
223
|
+
},
|
|
224
|
+
hideOnResize: {
|
|
225
|
+
classPropertyName: "hideOnResize",
|
|
226
|
+
publicName: "hideOnResize",
|
|
227
|
+
isSignal: true,
|
|
228
|
+
isRequired: false,
|
|
229
|
+
transformFunction: null
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
host: {
|
|
233
|
+
listeners: { "click": "toggle()" },
|
|
234
|
+
properties: { "attr.aria-expanded": "toggleClass() ? null : expanded()" }
|
|
235
|
+
},
|
|
236
|
+
exportAs: ["txStyleClass"],
|
|
237
|
+
ngImport: i0
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
241
|
+
minVersion: "12.0.0",
|
|
242
|
+
version: "22.2.3",
|
|
243
|
+
ngImport: i0,
|
|
244
|
+
type: TxStyleClass,
|
|
245
|
+
decorators: [{
|
|
246
|
+
type: Directive,
|
|
247
|
+
args: [{
|
|
248
|
+
selector: "[txStyleClass]",
|
|
249
|
+
exportAs: "txStyleClass",
|
|
250
|
+
host: {
|
|
251
|
+
"(click)": "toggle()",
|
|
252
|
+
"[attr.aria-expanded]": "toggleClass() ? null : expanded()"
|
|
253
|
+
}
|
|
254
|
+
}]
|
|
255
|
+
}],
|
|
256
|
+
ctorParameters: () => [],
|
|
257
|
+
propDecorators: {
|
|
258
|
+
selector: [{
|
|
259
|
+
type: i0.Input,
|
|
260
|
+
args: [{
|
|
261
|
+
isSignal: true,
|
|
262
|
+
alias: "txStyleClass",
|
|
263
|
+
required: false
|
|
264
|
+
}]
|
|
265
|
+
}],
|
|
266
|
+
enterFromClass: [{
|
|
267
|
+
type: i0.Input,
|
|
268
|
+
args: [{
|
|
269
|
+
isSignal: true,
|
|
270
|
+
alias: "enterFromClass",
|
|
271
|
+
required: false
|
|
272
|
+
}]
|
|
273
|
+
}],
|
|
274
|
+
enterActiveClass: [{
|
|
275
|
+
type: i0.Input,
|
|
276
|
+
args: [{
|
|
277
|
+
isSignal: true,
|
|
278
|
+
alias: "enterActiveClass",
|
|
279
|
+
required: false
|
|
280
|
+
}]
|
|
281
|
+
}],
|
|
282
|
+
enterToClass: [{
|
|
283
|
+
type: i0.Input,
|
|
284
|
+
args: [{
|
|
285
|
+
isSignal: true,
|
|
286
|
+
alias: "enterToClass",
|
|
287
|
+
required: false
|
|
288
|
+
}]
|
|
289
|
+
}],
|
|
290
|
+
leaveFromClass: [{
|
|
291
|
+
type: i0.Input,
|
|
292
|
+
args: [{
|
|
293
|
+
isSignal: true,
|
|
294
|
+
alias: "leaveFromClass",
|
|
295
|
+
required: false
|
|
296
|
+
}]
|
|
297
|
+
}],
|
|
298
|
+
leaveActiveClass: [{
|
|
299
|
+
type: i0.Input,
|
|
300
|
+
args: [{
|
|
301
|
+
isSignal: true,
|
|
302
|
+
alias: "leaveActiveClass",
|
|
303
|
+
required: false
|
|
304
|
+
}]
|
|
305
|
+
}],
|
|
306
|
+
leaveToClass: [{
|
|
307
|
+
type: i0.Input,
|
|
308
|
+
args: [{
|
|
309
|
+
isSignal: true,
|
|
310
|
+
alias: "leaveToClass",
|
|
311
|
+
required: false
|
|
312
|
+
}]
|
|
313
|
+
}],
|
|
314
|
+
toggleClass: [{
|
|
315
|
+
type: i0.Input,
|
|
316
|
+
args: [{
|
|
317
|
+
isSignal: true,
|
|
318
|
+
alias: "toggleClass",
|
|
319
|
+
required: false
|
|
320
|
+
}]
|
|
321
|
+
}],
|
|
322
|
+
hideOnOutsideClick: [{
|
|
323
|
+
type: i0.Input,
|
|
324
|
+
args: [{
|
|
325
|
+
isSignal: true,
|
|
326
|
+
alias: "hideOnOutsideClick",
|
|
327
|
+
required: false
|
|
328
|
+
}]
|
|
329
|
+
}],
|
|
330
|
+
hideOnEscape: [{
|
|
331
|
+
type: i0.Input,
|
|
332
|
+
args: [{
|
|
333
|
+
isSignal: true,
|
|
334
|
+
alias: "hideOnEscape",
|
|
335
|
+
required: false
|
|
336
|
+
}]
|
|
337
|
+
}],
|
|
338
|
+
hideOnResize: [{
|
|
339
|
+
type: i0.Input,
|
|
340
|
+
args: [{
|
|
341
|
+
isSignal: true,
|
|
342
|
+
alias: "hideOnResize",
|
|
343
|
+
required: false
|
|
344
|
+
}]
|
|
345
|
+
}]
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
export { TxStyleClass };
|
|
349
|
+
|
|
350
|
+
//# sourceMappingURL=tectra-ng-utils-style-class.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-style-class.mjs","names":[],"sources":["../../../../packages/utils/style-class/src/style-class.directive.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport { DestroyRef, Directive, ElementRef, Renderer2, booleanAttribute, inject, input, signal } from '@angular/core';\n\nfunction toSelector(value: unknown): string {\n return typeof value === 'string' && value.trim() ? value.trim() : '@next';\n}\n\nconst split = (classes: string | undefined): string[] => (classes ?? '').split(/\\s+/).filter(Boolean);\n\n@Directive({\n selector: '[txStyleClass]',\n exportAs: 'txStyleClass',\n host: {\n '(click)': 'toggle()',\n '[attr.aria-expanded]': 'toggleClass() ? null : expanded()',\n },\n})\nexport class TxStyleClass {\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly renderer = inject(Renderer2);\n private readonly document = inject(DOCUMENT);\n private readonly listeners: (() => void)[] = [];\n private animating = false;\n private endTimer: ReturnType<typeof setTimeout> | undefined;\n\n readonly selector = input<string, unknown>('@next', { alias: 'txStyleClass', transform: toSelector });\n readonly enterFromClass = input<string | undefined>(undefined);\n readonly enterActiveClass = input<string | undefined>(undefined);\n readonly enterToClass = input<string | undefined>(undefined);\n readonly leaveFromClass = input<string | undefined>(undefined);\n readonly leaveActiveClass = input<string | undefined>(undefined);\n readonly leaveToClass = input<string | undefined>(undefined);\n readonly toggleClass = input<string | undefined>(undefined);\n readonly hideOnOutsideClick = input<boolean, unknown>(false, { transform: booleanAttribute });\n readonly hideOnEscape = input<boolean, unknown>(false, { transform: booleanAttribute });\n readonly hideOnResize = input<boolean, unknown>(false, { transform: booleanAttribute });\n\n readonly expanded = signal(false);\n\n constructor() {\n inject(DestroyRef).onDestroy(() => {\n this.unbind();\n clearTimeout(this.endTimer);\n });\n }\n\n target(): HTMLElement | null {\n const selector = this.selector();\n switch (selector) {\n case '@next':\n return this.host.nextElementSibling as HTMLElement | null;\n case '@prev':\n return this.host.previousElementSibling as HTMLElement | null;\n case '@parent':\n return this.host.parentElement;\n case '@grandparent':\n return this.host.parentElement?.parentElement ?? null;\n default:\n return this.document.querySelector<HTMLElement>(selector);\n }\n }\n\n toggle(): void {\n const target = this.target();\n if (!target || this.animating) {\n return;\n }\n const toggleClass = this.toggleClass();\n if (toggleClass) {\n split(toggleClass).forEach((name) => (target.classList.contains(name) ? this.renderer.removeClass(target, name) : this.renderer.addClass(target, name)));\n return;\n }\n if (this.isHidden(target)) {\n this.enter(target);\n } else {\n this.leave(target);\n }\n }\n\n enter(target = this.target()): void {\n if (!target) {\n return;\n }\n this.swap(target, [...split(this.leaveToClass()), ...split(this.enterFromClass())], split(this.enterToClass()));\n this.expanded.set(true);\n this.bind(target);\n this.animate(target, split(this.enterActiveClass()));\n }\n\n leave(target = this.target()): void {\n if (!target) {\n return;\n }\n const active = split(this.leaveActiveClass());\n this.unbind();\n this.expanded.set(false);\n this.renderer.addClass(target, '__tx-leaving');\n split(this.leaveFromClass()).forEach((name) => this.renderer.addClass(target, name));\n this.animate(target, active, () => {\n this.renderer.removeClass(target, '__tx-leaving');\n this.swap(target, [...split(this.enterToClass()), ...split(this.leaveFromClass())], split(this.leaveToClass()));\n });\n }\n\n private animate(target: HTMLElement, active: string[], done?: () => void): void {\n const reduced = this.document.defaultView?.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;\n if (!active.length || reduced) {\n done?.();\n return;\n }\n this.animating = true;\n active.forEach((name) => this.renderer.addClass(target, name));\n const finish = () => {\n if (!this.animating) {\n return;\n }\n this.animating = false;\n clearTimeout(this.endTimer);\n stopAnimation();\n stopTransition();\n active.forEach((name) => this.renderer.removeClass(target, name));\n done?.();\n };\n const stopAnimation = this.renderer.listen(target, 'animationend', finish);\n const stopTransition = this.renderer.listen(target, 'transitionend', finish);\n this.endTimer = setTimeout(finish, this.duration(target) + 50);\n }\n\n private duration(target: HTMLElement): number {\n const style = this.document.defaultView?.getComputedStyle(target);\n const toMs = (value: string | undefined) => Math.max(0, ...(value ?? '0s').split(',').map((part) => parseFloat(part) * (part.trim().endsWith('ms') ? 1 : 1000) || 0));\n return Math.max(toMs(style?.animationDuration), toMs(style?.transitionDuration));\n }\n\n private swap(target: HTMLElement, remove: string[], add: string[]): void {\n remove.forEach((name) => this.renderer.removeClass(target, name));\n add.forEach((name) => this.renderer.addClass(target, name));\n }\n\n private isHidden(target: HTMLElement): boolean {\n if (target.classList.contains('__tx-leaving')) {\n return true;\n }\n const hiddenBy = split(this.leaveToClass());\n if (hiddenBy.length) {\n return hiddenBy.every((name) => target.classList.contains(name));\n }\n return target.offsetParent === null && this.document.defaultView?.getComputedStyle(target).position !== 'fixed';\n }\n\n private bind(target: HTMLElement): void {\n this.unbind();\n if (this.hideOnOutsideClick()) {\n this.listeners.push(\n this.renderer.listen(this.document, 'click', (event: Event) => {\n const node = event.target as Node | null;\n if (node && !target.contains(node) && !this.host.contains(node) && !this.isHidden(target)) {\n this.leave(target);\n }\n }),\n );\n }\n if (this.hideOnEscape()) {\n this.listeners.push(\n this.renderer.listen(this.document, 'keydown', (event: KeyboardEvent) => {\n if (event.key === 'Escape' && !this.isHidden(target)) {\n this.leave(target);\n this.host.focus?.();\n }\n }),\n );\n }\n if (this.hideOnResize()) {\n this.listeners.push(this.renderer.listen('window', 'resize', () => !this.isHidden(target) && this.leave(target)));\n }\n }\n\n private unbind(): void {\n this.listeners.splice(0).forEach((stop) => stop());\n }\n}\n"],"mappings":";;;AAGA,SAAS,WAAW,OAAc;CAChC,OAAO,OAAO,UAAU,YAAY,MAAM,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AA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,cAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA;GAAA,WAAA,EAAA,SAAA,WAAA;GAAA,YAAA,EAAA,sBAAA,oCAAA;EAAA;EAAA,UAAA,CAAA,cAAA;EAAA,UAAA;CAAA,CAAA;;AAAZ,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAY,YAAA,CAAA;EARxB,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;GACV,MAAM;IACJ,WAAW;IACX,wBAAwB;GACzB;EACF,CAAA"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Pipe } from "@angular/core";
|
|
3
|
+
const CYRILLIC_TO_LATIN = {
|
|
4
|
+
а: "a",
|
|
5
|
+
б: "b",
|
|
6
|
+
в: "v",
|
|
7
|
+
г: "g",
|
|
8
|
+
ґ: "g",
|
|
9
|
+
д: "d",
|
|
10
|
+
е: "e",
|
|
11
|
+
ё: "e",
|
|
12
|
+
є: "ye",
|
|
13
|
+
ж: "zh",
|
|
14
|
+
з: "z",
|
|
15
|
+
и: "i",
|
|
16
|
+
і: "i",
|
|
17
|
+
ї: "yi",
|
|
18
|
+
й: "y",
|
|
19
|
+
к: "k",
|
|
20
|
+
л: "l",
|
|
21
|
+
м: "m",
|
|
22
|
+
н: "n",
|
|
23
|
+
о: "o",
|
|
24
|
+
п: "p",
|
|
25
|
+
р: "r",
|
|
26
|
+
с: "s",
|
|
27
|
+
т: "t",
|
|
28
|
+
у: "u",
|
|
29
|
+
ф: "f",
|
|
30
|
+
х: "kh",
|
|
31
|
+
ц: "ts",
|
|
32
|
+
ч: "ch",
|
|
33
|
+
ш: "sh",
|
|
34
|
+
щ: "shch",
|
|
35
|
+
ъ: "",
|
|
36
|
+
ы: "y",
|
|
37
|
+
ь: "",
|
|
38
|
+
э: "e",
|
|
39
|
+
ю: "yu",
|
|
40
|
+
я: "ya"
|
|
41
|
+
};
|
|
42
|
+
function truncate(value, limit = 15, trail = "...", position = "end", empty = "-") {
|
|
43
|
+
if (!value) return empty;
|
|
44
|
+
const chars = Array.from(value);
|
|
45
|
+
if (chars.length <= limit) return value;
|
|
46
|
+
if (position === "middle") {
|
|
47
|
+
const head = Math.ceil(limit / 2);
|
|
48
|
+
const tail = Math.floor(limit / 2);
|
|
49
|
+
return chars.slice(0, head).join("") + trail + (tail ? chars.slice(-tail).join("") : "");
|
|
50
|
+
}
|
|
51
|
+
return chars.slice(0, limit).join("") + trail;
|
|
52
|
+
}
|
|
53
|
+
function capitalize(value) {
|
|
54
|
+
return value ? value.charAt(0).toLocaleUpperCase() + value.slice(1) : value ?? "";
|
|
55
|
+
}
|
|
56
|
+
function normalizeKeyword(value) {
|
|
57
|
+
return String(value ?? "").trim().toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
function withHttpPrefix(link, protocol = "https") {
|
|
60
|
+
const value = link?.trim() ?? "";
|
|
61
|
+
if (!value) return "";
|
|
62
|
+
return /^[a-z][a-z\d+.-]*:/i.test(value) ? value : `${protocol}://${value.replace(/^\/\//, "")}`;
|
|
63
|
+
}
|
|
64
|
+
function transliterate(value) {
|
|
65
|
+
return Array.from(value).map((char) => {
|
|
66
|
+
const lower = char.toLowerCase();
|
|
67
|
+
const latin = CYRILLIC_TO_LATIN[lower];
|
|
68
|
+
if (latin === void 0 || latin === "") return latin ?? char;
|
|
69
|
+
return char === lower ? latin : latin.charAt(0).toUpperCase() + latin.slice(1);
|
|
70
|
+
}).join("");
|
|
71
|
+
}
|
|
72
|
+
function slugify(value, separator = "-") {
|
|
73
|
+
return transliterate(value).normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, separator).replace(new RegExp(`^\\${separator}+|\\${separator}+$`, "g"), "");
|
|
74
|
+
}
|
|
75
|
+
function escapeHtml(value) {
|
|
76
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
77
|
+
}
|
|
78
|
+
var TxTruncatePipe = class TxTruncatePipe {
|
|
79
|
+
transform(value, limit = 15, trail = "...", position = "end") {
|
|
80
|
+
return truncate(value, limit, trail, position);
|
|
81
|
+
}
|
|
82
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
83
|
+
minVersion: "12.0.0",
|
|
84
|
+
version: "22.2.3",
|
|
85
|
+
ngImport: i0,
|
|
86
|
+
type: TxTruncatePipe,
|
|
87
|
+
deps: [],
|
|
88
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
89
|
+
});
|
|
90
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
91
|
+
minVersion: "14.0.0",
|
|
92
|
+
version: "22.2.3",
|
|
93
|
+
ngImport: i0,
|
|
94
|
+
type: TxTruncatePipe,
|
|
95
|
+
isStandalone: true,
|
|
96
|
+
name: "txTruncate"
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
100
|
+
minVersion: "12.0.0",
|
|
101
|
+
version: "22.2.3",
|
|
102
|
+
ngImport: i0,
|
|
103
|
+
type: TxTruncatePipe,
|
|
104
|
+
decorators: [{
|
|
105
|
+
type: Pipe,
|
|
106
|
+
args: [{ name: "txTruncate" }]
|
|
107
|
+
}]
|
|
108
|
+
});
|
|
109
|
+
var TxCapitalizePipe = class TxCapitalizePipe {
|
|
110
|
+
transform(value) {
|
|
111
|
+
return capitalize(value);
|
|
112
|
+
}
|
|
113
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
114
|
+
minVersion: "12.0.0",
|
|
115
|
+
version: "22.2.3",
|
|
116
|
+
ngImport: i0,
|
|
117
|
+
type: TxCapitalizePipe,
|
|
118
|
+
deps: [],
|
|
119
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
120
|
+
});
|
|
121
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
122
|
+
minVersion: "14.0.0",
|
|
123
|
+
version: "22.2.3",
|
|
124
|
+
ngImport: i0,
|
|
125
|
+
type: TxCapitalizePipe,
|
|
126
|
+
isStandalone: true,
|
|
127
|
+
name: "txCapitalize"
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
131
|
+
minVersion: "12.0.0",
|
|
132
|
+
version: "22.2.3",
|
|
133
|
+
ngImport: i0,
|
|
134
|
+
type: TxCapitalizePipe,
|
|
135
|
+
decorators: [{
|
|
136
|
+
type: Pipe,
|
|
137
|
+
args: [{ name: "txCapitalize" }]
|
|
138
|
+
}]
|
|
139
|
+
});
|
|
140
|
+
var TxHttpPrefixPipe = class TxHttpPrefixPipe {
|
|
141
|
+
transform(link, protocol = "https") {
|
|
142
|
+
return withHttpPrefix(link, protocol);
|
|
143
|
+
}
|
|
144
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
145
|
+
minVersion: "12.0.0",
|
|
146
|
+
version: "22.2.3",
|
|
147
|
+
ngImport: i0,
|
|
148
|
+
type: TxHttpPrefixPipe,
|
|
149
|
+
deps: [],
|
|
150
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
151
|
+
});
|
|
152
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
153
|
+
minVersion: "14.0.0",
|
|
154
|
+
version: "22.2.3",
|
|
155
|
+
ngImport: i0,
|
|
156
|
+
type: TxHttpPrefixPipe,
|
|
157
|
+
isStandalone: true,
|
|
158
|
+
name: "txHttpPrefix"
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
162
|
+
minVersion: "12.0.0",
|
|
163
|
+
version: "22.2.3",
|
|
164
|
+
ngImport: i0,
|
|
165
|
+
type: TxHttpPrefixPipe,
|
|
166
|
+
decorators: [{
|
|
167
|
+
type: Pipe,
|
|
168
|
+
args: [{ name: "txHttpPrefix" }]
|
|
169
|
+
}]
|
|
170
|
+
});
|
|
171
|
+
export { TxCapitalizePipe, TxHttpPrefixPipe, TxTruncatePipe, capitalize, escapeHtml, normalizeKeyword, slugify, transliterate, truncate, withHttpPrefix };
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=tectra-ng-utils-text.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tectra-ng-utils-text.mjs","names":[],"sources":["../../../../packages/utils/text/src/text.ts"],"sourcesContent":["import { Pipe, PipeTransform } from '@angular/core';\n\nexport type TxTruncatePosition = 'end' | 'middle';\n\nconst CYRILLIC_TO_LATIN: Record<string, string> = {\n а: 'a', б: 'b', в: 'v', г: 'g', ґ: 'g', д: 'd', е: 'e', ё: 'e', є: 'ye', ж: 'zh', з: 'z', и: 'i', і: 'i', ї: 'yi', й: 'y', к: 'k', л: 'l', м: 'm', н: 'n', о: 'o', п: 'p', р: 'r', с: 's', т: 't', у: 'u', ф: 'f', х: 'kh', ц: 'ts', ч: 'ch', ш: 'sh', щ: 'shch', ъ: '', ы: 'y', ь: '', э: 'e', ю: 'yu', я: 'ya',\n};\n\nexport function truncate(value: string | null | undefined, limit = 15, trail = '...', position: TxTruncatePosition = 'end', empty = '-'): string {\n if (!value) {\n return empty;\n }\n const chars = Array.from(value);\n if (chars.length <= limit) {\n return value;\n }\n if (position === 'middle') {\n const head = Math.ceil(limit / 2);\n const tail = Math.floor(limit / 2);\n return chars.slice(0, head).join('') + trail + (tail ? chars.slice(-tail).join('') : '');\n }\n return chars.slice(0, limit).join('') + trail;\n}\n\nexport function capitalize(value: string | null | undefined): string {\n return value ? value.charAt(0).toLocaleUpperCase() + value.slice(1) : (value ?? '');\n}\n\nexport function normalizeKeyword(value: string | null | undefined): string {\n return String(value ?? '').trim().toLowerCase();\n}\n\nexport function withHttpPrefix(link: string | null | undefined, protocol: 'https' | 'http' = 'https'): string {\n const value = link?.trim() ?? '';\n if (!value) {\n return '';\n }\n return /^[a-z][a-z\\d+.-]*:/i.test(value) ? value : `${protocol}://${value.replace(/^\\/\\//, '')}`;\n}\n\nexport function transliterate(value: string): string {\n return Array.from(value)\n .map((char) => {\n const lower = char.toLowerCase();\n const latin = CYRILLIC_TO_LATIN[lower];\n if (latin === undefined || latin === '') {\n return latin ?? char;\n }\n return char === lower ? latin : latin.charAt(0).toUpperCase() + latin.slice(1);\n })\n .join('');\n}\n\nexport function slugify(value: string, separator = '-'): string {\n return transliterate(value)\n .normalize('NFD')\n .replace(/\\p{Diacritic}/gu, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, separator)\n .replace(new RegExp(`^\\\\${separator}+|\\\\${separator}+$`, 'g'), '');\n}\n\nexport function escapeHtml(value: string): string {\n return value.replace(/&/g, '&').replace(/\"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>');\n}\n\n@Pipe({ name: 'txTruncate' })\nexport class TxTruncatePipe implements PipeTransform {\n transform(value: string | null | undefined, limit = 15, trail = '...', position: TxTruncatePosition = 'end'): string {\n return truncate(value, limit, trail, position);\n }\n}\n\n@Pipe({ name: 'txCapitalize' })\nexport class TxCapitalizePipe implements PipeTransform {\n transform(value: string | null | undefined): string {\n return capitalize(value);\n }\n}\n\n@Pipe({ name: 'txHttpPrefix' })\nexport class TxHttpPrefixPipe implements PipeTransform {\n transform(link: string | null | undefined, protocol: 'https' | 'http' = 'https'): string {\n return withHttpPrefix(link, protocol);\n }\n}\n"],"mappings":";;AAIA,MAAM,oBAA4C;CAChD,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAM,GAAG;CAAM,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAM,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;CAAK,GAAG;C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