@ui5/webcomponents-base 2.27.2 → 2.28.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.
@@ -0,0 +1,55 @@
1
+ // @ts-expect-error
2
+ import encodeXML from "../sap/base/security/encodeXML.js";
3
+ function createLowerCaseIndexMap(text) {
4
+ const originalStart = [];
5
+ const originalEnd = [];
6
+ let originalIndex = 0;
7
+ Array.from(text).forEach(character => {
8
+ const lowerCharacter = character.toLowerCase();
9
+ const end = originalIndex + character.length;
10
+ Array.from({ length: lowerCharacter.length }).forEach(() => {
11
+ originalStart.push(originalIndex);
12
+ originalEnd.push(end);
13
+ });
14
+ originalIndex = end;
15
+ });
16
+ return {
17
+ originalStart,
18
+ originalEnd,
19
+ };
20
+ }
21
+ /**
22
+ * Highlights the occurrences of the highlightedText in the text by wrapping them in a span with the provided class.
23
+ * @param text The original text in which to highlight occurrences.
24
+ * @param highlightedText The text to highlight within the original text.
25
+ * @param sClass The CSS class to apply to the highlighted spans.
26
+ * @returns The text with the highlighted occurrences wrapped in a span with the specified class.
27
+ * @since 2.28.0
28
+ */
29
+ const highlightText = (text, highlightedText, sClass) => {
30
+ text = text || "";
31
+ highlightedText = highlightedText || "";
32
+ const lowerText = text.toLowerCase();
33
+ const lowerHighlight = highlightedText.toLowerCase();
34
+ const highlightLength = lowerHighlight.length;
35
+ let index = lowerText.indexOf(lowerHighlight);
36
+ if (!highlightLength || index === -1) {
37
+ return encodeXML(text);
38
+ }
39
+ // Lowercasing can expand a single character (for example Turkish dotted İ).
40
+ // The index map keeps the lowercase search positions aligned with the original text slices.
41
+ const indexMap = createLowerCaseIndexMap(text);
42
+ let result = "";
43
+ let lastEnd = 0;
44
+ while (index > -1) {
45
+ const start = indexMap.originalStart[index];
46
+ const end = indexMap.originalEnd[index + highlightLength - 1];
47
+ result += `${encodeXML(text.slice(lastEnd, start))}<span class="${sClass}">${encodeXML(text.slice(start, end))}</span>`;
48
+ lastEnd = end;
49
+ index = lowerText.indexOf(lowerHighlight, index + highlightLength);
50
+ }
51
+ result += encodeXML(text.slice(lastEnd));
52
+ return result;
53
+ };
54
+ export default highlightText;
55
+ //# sourceMappingURL=highlightText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlightText.js","sourceRoot":"","sources":["../../src/util/highlightText.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,SAAS,MAAM,mCAAmC,CAAC;AAE1D,SAAS,uBAAuB,CAAC,IAAY;IAC5C,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACpC,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC;QAE7C,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YAC1D,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAClC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,aAAa,GAAG,GAAG,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,OAAO;QACN,aAAa;QACb,WAAW;KACX,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,aAAa,GAAG,CAAC,IAA+B,EAAE,eAA0C,EAAE,MAAc,EAAE,EAAE;IACrH,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAClB,eAAe,GAAG,eAAe,IAAI,EAAE,CAAC;IAExC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,cAAc,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC;IACrD,MAAM,eAAe,GAAG,cAAc,CAAC,MAAM,CAAC;IAC9C,IAAI,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAE9C,IAAI,CAAC,eAAe,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACtC,OAAO,SAAS,CAAC,IAAI,CAAW,CAAC;IAClC,CAAC;IAED,4EAA4E;IAC5E,4FAA4F;IAC5F,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,OAAO,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QACnB,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,GAAG,eAAe,GAAG,CAAC,CAAC,CAAC;QAE9D,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,gBAAgB,MAAM,KAAK,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC;QACxH,OAAO,GAAG,GAAG,CAAC;QACd,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,cAAc,EAAE,KAAK,GAAG,eAAe,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAEzC,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["// @ts-expect-error\nimport encodeXML from \"../sap/base/security/encodeXML.js\";\n\nfunction createLowerCaseIndexMap(text: string) {\n\tconst originalStart: number[] = [];\n\tconst originalEnd: number[] = [];\n\tlet originalIndex = 0;\n\n\tArray.from(text).forEach(character => {\n\t\tconst lowerCharacter = character.toLowerCase();\n\t\tconst end = originalIndex + character.length;\n\n\t\tArray.from({ length: lowerCharacter.length }).forEach(() => {\n\t\t\toriginalStart.push(originalIndex);\n\t\t\toriginalEnd.push(end);\n\t\t});\n\n\t\toriginalIndex = end;\n\t});\n\n\treturn {\n\t\toriginalStart,\n\t\toriginalEnd,\n\t};\n}\n\n/**\n * Highlights the occurrences of the highlightedText in the text by wrapping them in a span with the provided class.\n * @param text The original text in which to highlight occurrences.\n * @param highlightedText The text to highlight within the original text.\n * @param sClass The CSS class to apply to the highlighted spans.\n * @returns The text with the highlighted occurrences wrapped in a span with the specified class.\n * @since 2.28.0\n */\nconst highlightText = (text: string | null | undefined, highlightedText: string | null | undefined, sClass: string) => {\n\ttext = text || \"\";\n\thighlightedText = highlightedText || \"\";\n\n\tconst lowerText = text.toLowerCase();\n\tconst lowerHighlight = highlightedText.toLowerCase();\n\tconst highlightLength = lowerHighlight.length;\n\tlet index = lowerText.indexOf(lowerHighlight);\n\n\tif (!highlightLength || index === -1) {\n\t\treturn encodeXML(text) as string;\n\t}\n\n\t// Lowercasing can expand a single character (for example Turkish dotted İ).\n\t// The index map keeps the lowercase search positions aligned with the original text slices.\n\tconst indexMap = createLowerCaseIndexMap(text);\n\n\tlet result = \"\";\n\tlet lastEnd = 0;\n\n\twhile (index > -1) {\n\t\tconst start = indexMap.originalStart[index];\n\t\tconst end = indexMap.originalEnd[index + highlightLength - 1];\n\n\t\tresult += `${encodeXML(text.slice(lastEnd, start))}<span class=\"${sClass}\">${encodeXML(text.slice(start, end))}</span>`;\n\t\tlastEnd = end;\n\t\tindex = lowerText.indexOf(lowerHighlight, index + highlightLength);\n\t}\n\n\tresult += encodeXML(text.slice(lastEnd));\n\n\treturn result;\n};\n\nexport default highlightText;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-base",
3
- "version": "2.27.2",
3
+ "version": "2.28.1",
4
4
  "description": "UI5 Web Components: webcomponents.base",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -66,7 +66,7 @@
66
66
  "@openui5/sap.ui.core": "1.151.0",
67
67
  "@sap-theming/theming-base-content": "11.36.4",
68
68
  "@ui5/cypress-internal": "0.1.0",
69
- "@ui5/webcomponents-tools": "2.27.2",
69
+ "@ui5/webcomponents-tools": "2.28.1",
70
70
  "clean-css": "^5.2.2",
71
71
  "cypress": "15.18.1",
72
72
  "mocha": "^11.7.2",
@@ -85,5 +85,5 @@
85
85
  }
86
86
  },
87
87
  "customElements": "dist/custom-elements.json",
88
- "gitHead": "5529f5dc2aa697c9152ca73f5b0c0211bd0b557e"
88
+ "gitHead": "a1c8be3fdb2b6ece9f6f0a3c0e03a90cfe3878f3"
89
89
  }
@@ -12,7 +12,7 @@
12
12
  --_ui5-cozy-size: var(--_ui5-f2d95f8);
13
13
 
14
14
  --_ui5-compact-size: ;
15
- --_ui5_content_density: cozy;
15
+ --ui5_content_density: cozy;
16
16
  }
17
17
 
18
18
  [data-ui5-compact-size],
@@ -30,5 +30,5 @@
30
30
  always considered invalid and undefined.
31
31
  */
32
32
  --_ui5-compact-size: var(--_ui5-f2d95f8);
33
- --_ui5_content_density: compact;
33
+ --ui5_content_density: compact;
34
34
  }