@energycap/components 0.46.13 → 0.46.14-highlighting-normalized-pattern.20260701-1417
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.
|
@@ -2411,16 +2411,63 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2411
2411
|
}], ctorParameters: () => [{ type: i1$1.Overlay }] });
|
|
2412
2412
|
|
|
2413
2413
|
class HighlightTextPipe {
|
|
2414
|
-
transform(value, searchText) {
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2414
|
+
transform(value, searchText, normalizePattern) {
|
|
2415
|
+
if (!value || !searchText) {
|
|
2416
|
+
return value;
|
|
2417
|
+
}
|
|
2418
|
+
if (normalizePattern) {
|
|
2419
|
+
return this.transformNormalized(value, searchText, normalizePattern);
|
|
2420
|
+
}
|
|
2421
|
+
const regex = new RegExp(this.escapeRegex(searchText), 'gi');
|
|
2422
|
+
return value.replace(regex, this.strongWrap);
|
|
2423
|
+
}
|
|
2424
|
+
transformNormalized(value, searchText, normalizePattern) {
|
|
2425
|
+
const stripRegex = new RegExp(normalizePattern, 'g');
|
|
2426
|
+
// Build normalized value and a position map (normalized index → original index)
|
|
2427
|
+
const positionMap = [];
|
|
2428
|
+
let normalizedValue = '';
|
|
2429
|
+
for (let i = 0; i < value.length; i++) {
|
|
2430
|
+
if (!value[i].match(stripRegex)) {
|
|
2431
|
+
positionMap.push(i);
|
|
2432
|
+
normalizedValue += value[i];
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
// Normalize the search text using the same pattern
|
|
2436
|
+
const normalizedSearch = searchText.replace(stripRegex, '');
|
|
2437
|
+
if (!normalizedSearch) {
|
|
2438
|
+
return value;
|
|
2439
|
+
}
|
|
2440
|
+
// Find all matches in the normalized value
|
|
2441
|
+
const searchRegex = new RegExp(this.escapeRegex(normalizedSearch), 'gi');
|
|
2442
|
+
const matchedOriginalIndices = new Set();
|
|
2443
|
+
let match;
|
|
2444
|
+
while ((match = searchRegex.exec(normalizedValue)) !== null) {
|
|
2445
|
+
for (let i = match.index; i < match.index + match[0].length; i++) {
|
|
2446
|
+
matchedOriginalIndices.add(positionMap[i]);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
if (matchedOriginalIndices.size === 0) {
|
|
2450
|
+
return value;
|
|
2451
|
+
}
|
|
2452
|
+
// Build result, grouping consecutive matched characters into single <strong> tags
|
|
2453
|
+
let result = '';
|
|
2454
|
+
let inHighlight = false;
|
|
2455
|
+
for (let i = 0; i < value.length; i++) {
|
|
2456
|
+
const isMatched = matchedOriginalIndices.has(i);
|
|
2457
|
+
if (isMatched && !inHighlight) {
|
|
2458
|
+
result += `<strong class="text-highlight">`;
|
|
2459
|
+
inHighlight = true;
|
|
2460
|
+
}
|
|
2461
|
+
else if (!isMatched && inHighlight) {
|
|
2462
|
+
result += `</strong>`;
|
|
2463
|
+
inHighlight = false;
|
|
2464
|
+
}
|
|
2465
|
+
result += value[i];
|
|
2466
|
+
}
|
|
2467
|
+
if (inHighlight) {
|
|
2468
|
+
result += `</strong>`;
|
|
2419
2469
|
}
|
|
2420
|
-
|
|
2421
|
-
transformedValue = value;
|
|
2422
|
-
}
|
|
2423
|
-
return transformedValue;
|
|
2470
|
+
return result;
|
|
2424
2471
|
}
|
|
2425
2472
|
strongWrap(match) {
|
|
2426
2473
|
return `<strong class="text-highlight">${match}</strong>`;
|