@rspress-theme-anatole/theme-default 0.7.51 → 0.7.52

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 (2) hide show
  1. package/dist/bundle.js +40 -18
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -6520,34 +6520,54 @@ const ICON_MAP = {
6520
6520
  header: __WEBPACK_EXTERNAL_MODULE__theme_assets_header_54924fa3__["default"],
6521
6521
  content: __WEBPACK_EXTERNAL_MODULE__theme_assets_file_9182f35f__["default"]
6522
6522
  };
6523
- function SuggestItem({ suggestion, closeSearch, isCurrent, setCurrentSuggestionIndex, inCurrentDocIndex, scrollTo, onMouseMove }) {
6523
+ function SuggestItem({ suggestion, query, closeSearch, isCurrent, setCurrentSuggestionIndex, inCurrentDocIndex, scrollTo, onMouseMove }) {
6524
6524
  const HitIcon = ICON_MAP[suggestion.type];
6525
6525
  const link = inCurrentDocIndex && !(0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isProduction)() ? removeDomain(suggestion.link) : suggestion.link;
6526
6526
  const selfRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
6527
6527
  if (isCurrent && selfRef.current?.offsetTop) scrollTo(selfRef.current?.offsetTop, selfRef.current?.offsetHeight);
6528
- const getHighlightedFragments = (rawText, highlights) => {
6528
+ const getHighlightedFragments = (rawText) => {
6529
+ if (!rawText || !query) return [rawText];
6530
+ const terms = [...new Set(
6531
+ query.trim().split(/\s+/).filter(Boolean)
6532
+ .sort((a, b) => b.length - a.length)
6533
+ )];
6534
+ if (terms.length === 0) return [rawText];
6535
+
6536
+ const pattern = new RegExp(
6537
+ `(${terms.map(t => t.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')).join('|')})`,
6538
+ 'giu'
6539
+ );
6540
+
6529
6541
  const fragmentList = [];
6530
6542
  let lastIndex = 0;
6531
- for (const highlightInfo of highlights) {
6532
- const { start, length } = highlightInfo;
6533
- const prefix = rawText.slice(lastIndex, start);
6534
- const queryStr = getSlicedStrByByteLength(rawText, start, length);
6535
- fragmentList.push(prefix);
6536
- fragmentList.push((0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
6537
- className: Search_index_module.mark,
6538
- children: queryStr
6539
- }, start));
6540
- lastIndex = start + queryStr.length;
6543
+ let match;
6544
+ pattern.lastIndex = 0;
6545
+
6546
+ while ((match = pattern.exec(rawText)) !== null) {
6547
+ if (match.index > lastIndex) {
6548
+ fragmentList.push(rawText.slice(lastIndex, match.index));
6549
+ }
6550
+ fragmentList.push(
6551
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(
6552
+ "span",
6553
+ { className: Search_index_module.mark, children: match[0] },
6554
+ match.index
6555
+ )
6556
+ );
6557
+ lastIndex = match.index + match[0].length;
6558
+ }
6559
+
6560
+ if (lastIndex < rawText.length) {
6561
+ fragmentList.push(rawText.slice(lastIndex));
6541
6562
  }
6542
- if (lastIndex < rawText.length) fragmentList.push(rawText.slice(lastIndex));
6543
6563
  return fragmentList;
6544
6564
  };
6565
+
6545
6566
  const renderHeaderMatch = () => {
6546
6567
  if ('header' === suggestion.type || 'title' === suggestion.type) {
6547
- const { header, highlightInfoList } = suggestion;
6548
6568
  return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
6549
6569
  className: "font-medium",
6550
- children: getHighlightedFragments(header, highlightInfoList)
6570
+ children: getHighlightedFragments(suggestion.header)
6551
6571
  });
6552
6572
  }
6553
6573
  return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
@@ -6555,19 +6575,20 @@ function SuggestItem({ suggestion, closeSearch, isCurrent, setCurrentSuggestionI
6555
6575
  children: suggestion.header
6556
6576
  });
6557
6577
  };
6578
+
6558
6579
  const renderStatementMatch = () => {
6559
6580
  if ('content' !== suggestion.type) return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {});
6560
- const { statement, highlightInfoList } = suggestion;
6561
6581
  return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
6562
6582
  className: "text-sm text-gray-light w-full",
6563
- children: getHighlightedFragments(statement, highlightInfoList)
6583
+ children: getHighlightedFragments(suggestion.statement)
6564
6584
  });
6565
6585
  };
6566
6586
  const renderLink = () => {
6567
6587
  const displayLink = removeDomain(suggestion.link);
6588
+ const cleanDisplayLink = displayLink.replace(/([?&])kb_highlight=[^&#]*/,'').replace(/\?$/,'') ;
6568
6589
  return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("p", {
6569
6590
  className: "text-xs text-gray-400 mt-1 truncate opacity-70",
6570
- children: displayLink
6591
+ children: cleanDisplayLink
6571
6592
  });
6572
6593
  };
6573
6594
  let hitContent = null;
@@ -7145,6 +7166,7 @@ function SearchPanel({ focused, setFocused }) {
7145
7166
  const suggestionIndex = accumulateIndex;
7146
7167
  return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SuggestItem, {
7147
7168
  suggestion: suggestion,
7169
+ query: query,
7148
7170
  isCurrent: suggestionIndex === currentSuggestionIndex,
7149
7171
  setCurrentSuggestionIndex: (event) => {
7150
7172
  if (mousePositionRef.current.pageX === event.pageX && mousePositionRef.current.pageY === event.pageY) return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rspress-theme-anatole/theme-default",
3
3
  "author": "Anatole Tong",
4
- "version": "0.7.51",
4
+ "version": "0.7.52",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
7
7
  "*.css",
@@ -21,8 +21,8 @@
21
21
  "types": "./dist/bundle.d.ts",
22
22
  "dependencies": {
23
23
  "@mdx-js/react": "2.3.0",
24
- "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.51",
25
- "@rspress-theme-anatole/shared": "0.7.51",
24
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.52",
25
+ "@rspress-theme-anatole/shared": "0.7.52",
26
26
  "@rspress/runtime": "1.43.8",
27
27
  "body-scroll-lock": "4.0.0-beta.0",
28
28
  "copy-to-clipboard": "^3.3.3",