@rspress/core 0.0.13 → 0.2.0

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 (39) hide show
  1. package/dist/index.js +90 -50
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +3 -0
  4. package/dist/loader.js +28 -72
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.d.ts +8 -0
  7. package/dist/runtime/App.js +1 -0
  8. package/dist/runtime/Content.d.ts +6 -0
  9. package/dist/runtime/Content.js +7 -2
  10. package/dist/runtime/NoSSR.d.ts +4 -0
  11. package/dist/runtime/clientEntry.d.ts +1 -0
  12. package/dist/runtime/hooks.d.ts +29 -0
  13. package/dist/runtime/hooks.js +23 -1
  14. package/dist/runtime/index.d.ts +6 -0
  15. package/dist/runtime/ssrEntry.d.ts +6 -0
  16. package/dist/runtime/tsconfig.json +9 -0
  17. package/dist/runtime/utils.d.ts +6 -0
  18. package/dist/theme/bundle.css +94 -53
  19. package/dist/theme/bundle.d.ts +12 -1
  20. package/dist/theme/bundle.js +527 -489
  21. package/dist/theme/bundle.js.map +1 -1
  22. package/package.json +14 -14
  23. package/src/runtime/App.tsx +1 -0
  24. package/src/runtime/Content.tsx +11 -2
  25. package/src/runtime/global.d.ts +49 -0
  26. package/src/runtime/hooks.ts +47 -1
  27. package/src/runtime/tsconfig.json +9 -0
  28. package/src/theme-default/components/LocalSideBar/{index.module.scss → index.scss} +6 -5
  29. package/src/theme-default/components/LocalSideBar/index.tsx +4 -4
  30. package/src/theme-default/components/Nav/index.tsx +19 -5
  31. package/src/theme-default/components/Search/SearchPanel.tsx +339 -0
  32. package/src/theme-default/components/Search/index.tsx +6 -326
  33. package/src/theme-default/index.ts +3 -1
  34. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +8 -23
  35. package/src/theme-default/layout/DocLayout/index.module.scss +52 -3
  36. package/src/theme-default/layout/DocLayout/index.tsx +9 -7
  37. package/src/theme-default/logic/index.ts +1 -0
  38. package/src/theme-default/logic/useAppearance.ts +0 -1
  39. package/src/theme-default/logic/usePathUtils.ts +72 -0
package/dist/loader.js CHANGED
@@ -3519,7 +3519,7 @@ var require_parse = __commonJS({
3519
3519
  var require_gray_matter = __commonJS({
3520
3520
  "../../node_modules/.pnpm/gray-matter@4.0.3/node_modules/gray-matter/index.js"(exports2, module2) {
3521
3521
  "use strict";
3522
- var fs2 = __require("fs");
3522
+ var fs = __require("fs");
3523
3523
  var sections = require_section_matter();
3524
3524
  var defaults = require_defaults();
3525
3525
  var stringify = require_stringify();
@@ -3609,7 +3609,7 @@ var require_gray_matter = __commonJS({
3609
3609
  return stringify(file, data, options2);
3610
3610
  };
3611
3611
  matter.read = function(filepath, options2) {
3612
- const str2 = fs2.readFileSync(filepath, "utf8");
3612
+ const str2 = fs.readFileSync(filepath, "utf8");
3613
3613
  const file = matter(str2, options2);
3614
3614
  file.path = filepath;
3615
3615
  return file;
@@ -3639,7 +3639,7 @@ var require_gray_matter = __commonJS({
3639
3639
 
3640
3640
  // src/node/mdx/loader.ts
3641
3641
  var import_gray_matter = __toESM(require_gray_matter());
3642
- import path7 from "path";
3642
+ import path6 from "path";
3643
3643
  import { createProcessor } from "@mdx-js/mdx";
3644
3644
 
3645
3645
  // src/node/utils/normalizePath.ts
@@ -3653,19 +3653,8 @@ function normalizePath(id) {
3653
3653
  return path.posix.normalize(isWindows ? slash(id) : id);
3654
3654
  }
3655
3655
 
3656
- // src/node/constants.ts
3657
- import path2 from "path";
3658
- import { fileURLToPath } from "url";
3659
- import { RSPRESS_TEMP_DIR } from "@rspress/shared";
3660
- var dirname = path2.dirname(fileURLToPath(new URL(import.meta.url)));
3661
- var PACKAGE_ROOT = path2.join(dirname, "..");
3662
- var CLIENT_ENTRY = path2.join(PACKAGE_ROOT, "dist", "runtime", "clientEntry.js");
3663
- var SSR_ENTRY = path2.join(PACKAGE_ROOT, "dist", "runtime", "ssrEntry.js");
3664
- var PUBLIC_DIR = "public";
3665
- var TEMP_DIR = path2.join(process.cwd(), "node_modules", RSPRESS_TEMP_DIR);
3666
-
3667
3656
  // src/node/mdx/options.ts
3668
- import path6 from "path";
3657
+ import path5 from "path";
3669
3658
  import remarkGFM from "remark-gfm";
3670
3659
  import rehypeSlug from "rehype-slug";
3671
3660
  import rehypeAutoLink from "rehype-autolink-headings";
@@ -3733,10 +3722,9 @@ var rehypePluginCodeMeta = () => {
3733
3722
  };
3734
3723
 
3735
3724
  // src/node/mdx/remarkPlugins/normalizeLink.ts
3736
- import path3 from "path";
3725
+ import path2 from "path";
3737
3726
  import { visit as visit2 } from "unist-util-visit";
3738
- import fs from "@modern-js/utils/fs-extra";
3739
- import { addLeadingSlash, normalizeHref, parseUrl, isExternalUrl, slash as slash2 } from "@rspress/shared";
3727
+ import { normalizeHref, parseUrl, isExternalUrl, slash as slash2 } from "@rspress/shared";
3740
3728
 
3741
3729
  // src/node/utils/getASTNodeImport.ts
3742
3730
  var getASTNodeImport = (name, from) => ({
@@ -3770,25 +3758,7 @@ var getASTNodeImport = (name, from) => ({
3770
3758
  });
3771
3759
 
3772
3760
  // src/node/mdx/remarkPlugins/normalizeLink.ts
3773
- function extractLangFromFilePath(filePath) {
3774
- const [lang] = filePath.split(path3.sep);
3775
- return lang;
3776
- }
3777
- function normalizeLangPrefix(rawUrl, lang, defaultLang) {
3778
- if (!defaultLang) {
3779
- return rawUrl;
3780
- }
3781
- const url = addLeadingSlash(rawUrl);
3782
- const hasLangPrefix = url.startsWith(`/${lang}/`);
3783
- if (hasLangPrefix && lang === defaultLang) {
3784
- return url.replace(`/${lang}`, "");
3785
- }
3786
- if (hasLangPrefix || lang === defaultLang) {
3787
- return url;
3788
- }
3789
- return `/${lang}${url}`;
3790
- }
3791
- var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) => {
3761
+ var remarkPluginNormalizeLink = ({ base, root }) => (tree, file) => {
3792
3762
  const images = [];
3793
3763
  visit2(tree, (node) => node.type === "link", (node) => {
3794
3764
  if (!node.url) {
@@ -3803,36 +3773,25 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
3803
3773
  node.url = url + (hash ? `#${hash}` : "");
3804
3774
  return;
3805
3775
  }
3806
- const extname = path3.extname(url);
3776
+ const extname = path2.extname(url);
3807
3777
  if (extname === ".md" || extname === ".mdx") {
3808
3778
  url = url.replace(extname, "");
3809
3779
  }
3810
- const relativePath = path3.relative(root, file.path);
3780
+ const relativePath = path2.relative(root, file.path);
3811
3781
  if (url.startsWith(".")) {
3812
- url = path3.posix.join(slash2(path3.dirname(relativePath)), url);
3782
+ url = path2.posix.join(slash2(path2.dirname(relativePath)), url);
3813
3783
  }
3814
- const lang = extractLangFromFilePath(relativePath);
3815
- url = normalizeLangPrefix(normalizeHref(url), lang, defaultLang);
3784
+ url = normalizeHref(url);
3816
3785
  if (hash) {
3817
3786
  url += `#${hash}`;
3818
3787
  }
3819
- node.url = path3.posix.join(base, url);
3788
+ node.url = path2.posix.join(base, url);
3820
3789
  });
3821
3790
  const normalizeImageUrl = (imageUrl) => {
3822
- if (isExternalUrl(imageUrl)) {
3791
+ if (isExternalUrl(imageUrl) || imageUrl.startsWith("/")) {
3823
3792
  return "";
3824
3793
  }
3825
- if (imageUrl.startsWith("/")) {
3826
- const publicDir = path3.join(root, PUBLIC_DIR);
3827
- const imagePath = path3.join(publicDir, imageUrl);
3828
- if (!fs.existsSync(imagePath)) {
3829
- console.error(`Image not found: ${imagePath}`);
3830
- return "";
3831
- }
3832
- return imagePath;
3833
- } else {
3834
- return imageUrl;
3835
- }
3794
+ return imageUrl;
3836
3795
  };
3837
3796
  const getMdxSrcAttrbute = (tempVar) => {
3838
3797
  return {
@@ -3864,9 +3823,6 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
3864
3823
  if (!url) {
3865
3824
  return;
3866
3825
  }
3867
- if (isExternalUrl(url)) {
3868
- return;
3869
- }
3870
3826
  const imagePath = normalizeImageUrl(url);
3871
3827
  if (!imagePath) {
3872
3828
  return;
@@ -3910,16 +3866,16 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
3910
3866
  };
3911
3867
 
3912
3868
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
3913
- import path4 from "path";
3869
+ import path3 from "path";
3914
3870
  import { visit as visit3 } from "unist-util-visit";
3915
3871
  import logUtils from "@modern-js/utils/logger";
3916
3872
  import { cleanUrl, isProduction } from "@rspress/shared";
3917
3873
 
3918
3874
  // src/node/runtimeModule/routeData.ts
3919
- import { addLeadingSlash as addLeadingSlash2 } from "@rspress/shared";
3875
+ import { addLeadingSlash } from "@rspress/shared";
3920
3876
  var normalizeRoutePath = (routePath) => {
3921
3877
  const result = routePath.replace(/\.(.*)?$/, "").replace(/index$/, "");
3922
- return addLeadingSlash2(result);
3878
+ return addLeadingSlash(result);
3923
3879
  };
3924
3880
 
3925
3881
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
@@ -3928,7 +3884,7 @@ var IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
3928
3884
  function checkLinks(links, filepath, root, routeService) {
3929
3885
  const errorInfos = [];
3930
3886
  links.filter((link) => !IGNORE_REGEXP.test(link)).map((link) => normalizePath(link)).forEach((link) => {
3931
- const relativePath = path4.relative(root, filepath);
3887
+ const relativePath = path3.relative(root, filepath);
3932
3888
  if (!routeService.isExistRoute(cleanUrl(link))) {
3933
3889
  errorInfos.push(`Internal link to ${link} is dead, check it in ${relativePath}`);
3934
3890
  }
@@ -3957,7 +3913,7 @@ var remarkCheckDeadLinks = (checkLink) => {
3957
3913
  if (!url.startsWith("http") && !url.startsWith("https")) {
3958
3914
  const normalizeUrl = normalizeRoutePath(
3959
3915
  // fix: windows path
3960
- url?.split(path4.sep).join("/")?.split("#")[0]
3916
+ url?.split(path3.sep).join("/")?.split("#")[0]
3961
3917
  );
3962
3918
  internalLinks.add(normalizeUrl);
3963
3919
  }
@@ -3967,11 +3923,11 @@ var remarkCheckDeadLinks = (checkLink) => {
3967
3923
  };
3968
3924
 
3969
3925
  // src/node/mdx/remarkPlugins/builtin.ts
3970
- import path5 from "path";
3926
+ import path4 from "path";
3971
3927
  var remarkBuiltin = ({ globalComponents }) => {
3972
3928
  return (tree) => {
3973
3929
  const demos = globalComponents.map((componentPath) => {
3974
- const filename = path5.parse(componentPath).name;
3930
+ const filename = path4.parse(componentPath).name;
3975
3931
  const componentName = filename[0].toUpperCase() + filename.slice(1);
3976
3932
  return getASTNodeImport(componentName, componentPath);
3977
3933
  });
@@ -3980,9 +3936,9 @@ var remarkBuiltin = ({ globalComponents }) => {
3980
3936
  };
3981
3937
 
3982
3938
  // src/node/mdx/options.ts
3983
- async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath) {
3939
+ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
3984
3940
  const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = config?.markdown || {};
3985
- const rspressPlugins = config?.plugins || [];
3941
+ const rspressPlugins = pluginDriver.getPlugins();
3986
3942
  const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.remarkPlugins || []);
3987
3943
  const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.rehypePlugins || []);
3988
3944
  const globalComponents = [
@@ -3992,7 +3948,7 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
3992
3948
  const defaultLang = config?.lang || "";
3993
3949
  return {
3994
3950
  providerImportSource: "@mdx-js/react",
3995
- format: path6.extname(filepath).slice(1),
3951
+ format: path5.extname(filepath).slice(1),
3996
3952
  remarkPlugins: [
3997
3953
  remarkGFM,
3998
3954
  remarkPluginToc,
@@ -4060,12 +4016,12 @@ async function mdxLoader(context, source, callback) {
4060
4016
  toc: [],
4061
4017
  frontmatter: {}
4062
4018
  };
4063
- const { config, docDirectory, checkDeadLinks, routeService, enableMdxRs } = options2;
4019
+ const { config, docDirectory, checkDeadLinks, routeService, enableMdxRs, pluginDriver } = options2;
4064
4020
  const { data: frontmatter, content } = (0, import_gray_matter.default)(source);
4065
4021
  try {
4066
4022
  let compileResult;
4067
4023
  if (!enableMdxRs) {
4068
- const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath);
4024
+ const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver);
4069
4025
  const compiler = createProcessor(mdxOptions);
4070
4026
  compiler.data("pageMeta", {
4071
4027
  toc: [],
@@ -4081,7 +4037,7 @@ async function mdxLoader(context, source, callback) {
4081
4037
  frontmatter
4082
4038
  };
4083
4039
  } else {
4084
- const { compile } = __require("@modern-js/mdx-rs-binding");
4040
+ const { compile } = __require("@rspress/mdx-rs");
4085
4041
  const { toc, links, title, code } = await compile({
4086
4042
  value: content,
4087
4043
  filepath,
@@ -4099,7 +4055,7 @@ async function mdxLoader(context, source, callback) {
4099
4055
  }
4100
4056
  }
4101
4057
  const result = `globalThis.__RSPRESS_PAGE_META ||= {};
4102
- globalThis.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(path7.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
4058
+ globalThis.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(path6.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
4103
4059
  ${compileResult}`;
4104
4060
  callback(null, result);
4105
4061
  } catch (e) {