@rspress/core 0.0.12 → 0.1.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.
Files changed (40) hide show
  1. package/dist/index.js +34 -26
  2. package/dist/index.js.map +1 -1
  3. package/dist/loader.d.ts +2 -0
  4. package/dist/loader.js +24 -49
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.d.ts +8 -0
  7. package/dist/runtime/Content.d.ts +6 -0
  8. package/dist/runtime/NoSSR.d.ts +4 -0
  9. package/dist/runtime/clientEntry.d.ts +1 -0
  10. package/dist/runtime/hooks.d.ts +22 -0
  11. package/dist/runtime/index.d.ts +6 -0
  12. package/dist/runtime/ssrEntry.d.ts +6 -0
  13. package/dist/runtime/tsconfig.json +9 -0
  14. package/dist/runtime/utils.d.ts +6 -0
  15. package/dist/theme/bundle.css +85 -52
  16. package/dist/theme/bundle.d.ts +24 -2
  17. package/dist/theme/bundle.js +1425 -897
  18. package/dist/theme/bundle.js.map +1 -1
  19. package/package.json +14 -16
  20. package/src/runtime/global.d.ts +49 -0
  21. package/src/runtime/tsconfig.json +9 -0
  22. package/src/theme-default/components/LocalSideBar/{index.module.scss → index.scss} +6 -5
  23. package/src/theme-default/components/LocalSideBar/index.tsx +4 -4
  24. package/src/theme-default/components/PackageManagerTabs/icons/Bun.tsx +101 -0
  25. package/src/theme-default/components/PackageManagerTabs/icons/Npm.tsx +16 -0
  26. package/src/theme-default/components/PackageManagerTabs/icons/Pnpm.tsx +22 -0
  27. package/src/theme-default/components/PackageManagerTabs/icons/Yarn.tsx +18 -0
  28. package/src/theme-default/components/PackageManagerTabs/index.scss +5 -0
  29. package/src/theme-default/components/PackageManagerTabs/index.tsx +110 -0
  30. package/src/theme-default/components/Search/SearchPanel.tsx +339 -0
  31. package/src/theme-default/components/Search/index.tsx +6 -326
  32. package/src/theme-default/components/Tabs/index.module.scss +1 -0
  33. package/src/theme-default/components/Tabs/index.tsx +30 -41
  34. package/src/theme-default/components/Toc/index.css +18 -0
  35. package/src/theme-default/components/Toc/index.tsx +42 -0
  36. package/src/theme-default/index.ts +8 -7
  37. package/src/theme-default/layout/DocLayout/docComponents/code.tsx +1 -1
  38. package/src/theme-default/layout/DocLayout/index.module.scss +6 -3
  39. package/src/theme-default/layout/DocLayout/index.tsx +9 -7
  40. package/src/theme-default/logic/useAppearance.ts +0 -1
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,9 +3722,8 @@ 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
3727
  import { addLeadingSlash, normalizeHref, parseUrl, isExternalUrl, slash as slash2 } from "@rspress/shared";
3740
3728
 
3741
3729
  // src/node/utils/getASTNodeImport.ts
@@ -3771,7 +3759,7 @@ var getASTNodeImport = (name, from) => ({
3771
3759
 
3772
3760
  // src/node/mdx/remarkPlugins/normalizeLink.ts
3773
3761
  function extractLangFromFilePath(filePath) {
3774
- const [lang] = filePath.split(path3.sep);
3762
+ const [lang] = filePath.split(path2.sep);
3775
3763
  return lang;
3776
3764
  }
3777
3765
  function normalizeLangPrefix(rawUrl, lang, defaultLang) {
@@ -3803,36 +3791,26 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
3803
3791
  node.url = url + (hash ? `#${hash}` : "");
3804
3792
  return;
3805
3793
  }
3806
- const extname = path3.extname(url);
3794
+ const extname = path2.extname(url);
3807
3795
  if (extname === ".md" || extname === ".mdx") {
3808
3796
  url = url.replace(extname, "");
3809
3797
  }
3810
- const relativePath = path3.relative(root, file.path);
3798
+ const relativePath = path2.relative(root, file.path);
3811
3799
  if (url.startsWith(".")) {
3812
- url = path3.posix.join(slash2(path3.dirname(relativePath)), url);
3800
+ url = path2.posix.join(slash2(path2.dirname(relativePath)), url);
3813
3801
  }
3814
3802
  const lang = extractLangFromFilePath(relativePath);
3815
3803
  url = normalizeLangPrefix(normalizeHref(url), lang, defaultLang);
3816
3804
  if (hash) {
3817
3805
  url += `#${hash}`;
3818
3806
  }
3819
- node.url = path3.posix.join(base, url);
3807
+ node.url = path2.posix.join(base, url);
3820
3808
  });
3821
3809
  const normalizeImageUrl = (imageUrl) => {
3822
- if (isExternalUrl(imageUrl)) {
3810
+ if (isExternalUrl(imageUrl) || imageUrl.startsWith("/")) {
3823
3811
  return "";
3824
3812
  }
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
- }
3813
+ return imageUrl;
3836
3814
  };
3837
3815
  const getMdxSrcAttrbute = (tempVar) => {
3838
3816
  return {
@@ -3864,9 +3842,6 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
3864
3842
  if (!url) {
3865
3843
  return;
3866
3844
  }
3867
- if (isExternalUrl(url)) {
3868
- return;
3869
- }
3870
3845
  const imagePath = normalizeImageUrl(url);
3871
3846
  if (!imagePath) {
3872
3847
  return;
@@ -3910,7 +3885,7 @@ var remarkPluginNormalizeLink = ({ base, defaultLang, root }) => (tree, file) =>
3910
3885
  };
3911
3886
 
3912
3887
  // src/node/mdx/remarkPlugins/checkDeadLink.ts
3913
- import path4 from "path";
3888
+ import path3 from "path";
3914
3889
  import { visit as visit3 } from "unist-util-visit";
3915
3890
  import logUtils from "@modern-js/utils/logger";
3916
3891
  import { cleanUrl, isProduction } from "@rspress/shared";
@@ -3928,7 +3903,7 @@ var IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
3928
3903
  function checkLinks(links, filepath, root, routeService) {
3929
3904
  const errorInfos = [];
3930
3905
  links.filter((link) => !IGNORE_REGEXP.test(link)).map((link) => normalizePath(link)).forEach((link) => {
3931
- const relativePath = path4.relative(root, filepath);
3906
+ const relativePath = path3.relative(root, filepath);
3932
3907
  if (!routeService.isExistRoute(cleanUrl(link))) {
3933
3908
  errorInfos.push(`Internal link to ${link} is dead, check it in ${relativePath}`);
3934
3909
  }
@@ -3957,7 +3932,7 @@ var remarkCheckDeadLinks = (checkLink) => {
3957
3932
  if (!url.startsWith("http") && !url.startsWith("https")) {
3958
3933
  const normalizeUrl = normalizeRoutePath(
3959
3934
  // fix: windows path
3960
- url?.split(path4.sep).join("/")?.split("#")[0]
3935
+ url?.split(path3.sep).join("/")?.split("#")[0]
3961
3936
  );
3962
3937
  internalLinks.add(normalizeUrl);
3963
3938
  }
@@ -3967,11 +3942,11 @@ var remarkCheckDeadLinks = (checkLink) => {
3967
3942
  };
3968
3943
 
3969
3944
  // src/node/mdx/remarkPlugins/builtin.ts
3970
- import path5 from "path";
3945
+ import path4 from "path";
3971
3946
  var remarkBuiltin = ({ globalComponents }) => {
3972
3947
  return (tree) => {
3973
3948
  const demos = globalComponents.map((componentPath) => {
3974
- const filename = path5.parse(componentPath).name;
3949
+ const filename = path4.parse(componentPath).name;
3975
3950
  const componentName = filename[0].toUpperCase() + filename.slice(1);
3976
3951
  return getASTNodeImport(componentName, componentPath);
3977
3952
  });
@@ -3980,9 +3955,9 @@ var remarkBuiltin = ({ globalComponents }) => {
3980
3955
  };
3981
3956
 
3982
3957
  // src/node/mdx/options.ts
3983
- async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath) {
3958
+ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
3984
3959
  const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = config?.markdown || {};
3985
- const rspressPlugins = config?.plugins || [];
3960
+ const rspressPlugins = pluginDriver.getPlugins();
3986
3961
  const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.remarkPlugins || []);
3987
3962
  const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin) => plugin.markdown?.rehypePlugins || []);
3988
3963
  const globalComponents = [
@@ -3992,7 +3967,7 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
3992
3967
  const defaultLang = config?.lang || "";
3993
3968
  return {
3994
3969
  providerImportSource: "@mdx-js/react",
3995
- format: path6.extname(filepath).slice(1),
3970
+ format: path5.extname(filepath).slice(1),
3996
3971
  remarkPlugins: [
3997
3972
  remarkGFM,
3998
3973
  remarkPluginToc,
@@ -4060,12 +4035,12 @@ async function mdxLoader(context, source, callback) {
4060
4035
  toc: [],
4061
4036
  frontmatter: {}
4062
4037
  };
4063
- const { config, docDirectory, checkDeadLinks, routeService, enableMdxRs } = options2;
4038
+ const { config, docDirectory, checkDeadLinks, routeService, enableMdxRs, pluginDriver } = options2;
4064
4039
  const { data: frontmatter, content } = (0, import_gray_matter.default)(source);
4065
4040
  try {
4066
4041
  let compileResult;
4067
4042
  if (!enableMdxRs) {
4068
- const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath);
4043
+ const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver);
4069
4044
  const compiler = createProcessor(mdxOptions);
4070
4045
  compiler.data("pageMeta", {
4071
4046
  toc: [],
@@ -4081,7 +4056,7 @@ async function mdxLoader(context, source, callback) {
4081
4056
  frontmatter
4082
4057
  };
4083
4058
  } else {
4084
- const { compile } = __require("@modern-js/mdx-rs-binding");
4059
+ const { compile } = __require("@rspress/mdx-rs");
4085
4060
  const { toc, links, title, code } = await compile({
4086
4061
  value: content,
4087
4062
  filepath,
@@ -4099,7 +4074,7 @@ async function mdxLoader(context, source, callback) {
4099
4074
  }
4100
4075
  }
4101
4076
  const result = `globalThis.__RSPRESS_PAGE_META ||= {};
4102
- globalThis.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(path7.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
4077
+ globalThis.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(path6.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
4103
4078
  ${compileResult}`;
4104
4079
  callback(null, result);
4105
4080
  } catch (e) {