@rspress/shared 1.41.1 → 1.41.2

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.
package/dist/index.js CHANGED
@@ -1,273 +1,223 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- APPEARANCE_KEY: () => APPEARANCE_KEY,
24
- DEFAULT_HIGHLIGHT_LANGUAGES: () => DEFAULT_HIGHLIGHT_LANGUAGES,
25
- HASH_REGEXP: () => HASH_REGEXP,
26
- MDX_REGEXP: () => MDX_REGEXP,
27
- QUERY_REGEXP: () => QUERY_REGEXP,
28
- RSPRESS_TEMP_DIR: () => RSPRESS_TEMP_DIR,
29
- SEARCH_INDEX_NAME: () => SEARCH_INDEX_NAME,
30
- addLeadingSlash: () => addLeadingSlash,
31
- addTrailingSlash: () => addTrailingSlash,
32
- cleanUrl: () => cleanUrl,
33
- inBrowser: () => inBrowser,
34
- isDataUrl: () => isDataUrl,
35
- isDebugMode: () => isDebugMode,
36
- isDevDebugMode: () => isDevDebugMode,
37
- isExternalUrl: () => isExternalUrl,
38
- isProduction: () => isProduction,
39
- isSCM: () => isSCM,
40
- normalizeHref: () => normalizeHref,
41
- normalizePosixPath: () => normalizePosixPath,
42
- normalizeSlash: () => normalizeSlash,
43
- parseUrl: () => parseUrl,
44
- removeBase: () => removeBase,
45
- removeHash: () => removeHash,
46
- removeLeadingSlash: () => removeLeadingSlash,
47
- removeTrailingSlash: () => removeTrailingSlash,
48
- replaceLang: () => replaceLang,
49
- replaceVersion: () => replaceVersion,
50
- slash: () => slash,
51
- withBase: () => withBase,
52
- withoutBase: () => withoutBase,
53
- withoutLang: () => withoutLang
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = function(exports1, definition) {
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = function(obj, prop) {
13
+ return Object.prototype.hasOwnProperty.call(obj, prop);
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.r = function(exports1) {
18
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
19
+ value: 'Module'
20
+ });
21
+ Object.defineProperty(exports1, '__esModule', {
22
+ value: true
23
+ });
24
+ };
25
+ })();
26
+ var __webpack_exports__ = {};
27
+ __webpack_require__.r(__webpack_exports__);
28
+ __webpack_require__.d(__webpack_exports__, {
29
+ SEARCH_INDEX_NAME: ()=>SEARCH_INDEX_NAME,
30
+ RSPRESS_TEMP_DIR: ()=>RSPRESS_TEMP_DIR,
31
+ QUERY_REGEXP: ()=>QUERY_REGEXP,
32
+ isDebugMode: ()=>isDebugMode,
33
+ addTrailingSlash: ()=>addTrailingSlash,
34
+ slash: ()=>slash,
35
+ removeLeadingSlash: ()=>removeLeadingSlash,
36
+ withoutBase: ()=>withoutBase,
37
+ replaceVersion: ()=>replaceVersion,
38
+ MDX_REGEXP: ()=>MDX_REGEXP,
39
+ HASH_REGEXP: ()=>HASH_REGEXP,
40
+ isSCM: ()=>isSCM,
41
+ normalizeHref: ()=>normalizeHref,
42
+ normalizeSlash: ()=>normalizeSlash,
43
+ normalizePosixPath: ()=>normalizePosixPath,
44
+ inBrowser: ()=>inBrowser,
45
+ isDataUrl: ()=>isDataUrl,
46
+ replaceLang: ()=>replaceLang,
47
+ removeHash: ()=>removeHash,
48
+ cleanUrl: ()=>runtime_utils_cleanUrl,
49
+ withBase: ()=>withBase,
50
+ isDevDebugMode: ()=>isDevDebugMode,
51
+ removeTrailingSlash: ()=>removeTrailingSlash,
52
+ APPEARANCE_KEY: ()=>APPEARANCE_KEY,
53
+ isExternalUrl: ()=>isExternalUrl,
54
+ removeBase: ()=>removeBase,
55
+ DEFAULT_HIGHLIGHT_LANGUAGES: ()=>DEFAULT_HIGHLIGHT_LANGUAGES,
56
+ parseUrl: ()=>parseUrl,
57
+ withoutLang: ()=>withoutLang,
58
+ isProduction: ()=>isProduction,
59
+ addLeadingSlash: ()=>addLeadingSlash
54
60
  });
55
- module.exports = __toCommonJS(src_exports);
56
-
57
- // src/runtime-utils/index.ts
58
- var QUERY_REGEXP = /\?.*$/s;
59
- var HASH_REGEXP = /#.*$/s;
60
- var MDX_REGEXP = /\.mdx?$/;
61
- var APPEARANCE_KEY = "rspress-theme-appearance";
62
- var SEARCH_INDEX_NAME = "search_index";
63
- var RSPRESS_TEMP_DIR = ".rspress";
64
- var DEFAULT_HIGHLIGHT_LANGUAGES = [
65
- ["js", "javascript"],
66
- ["ts", "typescript"],
67
- ["jsx", "tsx"],
68
- ["xml", "xml-doc"],
69
- ["md", "markdown"],
70
- ["mdx", "tsx"]
61
+ const QUERY_REGEXP = /\?.*$/s;
62
+ const HASH_REGEXP = /#.*$/s;
63
+ const MDX_REGEXP = /\.mdx?$/;
64
+ const APPEARANCE_KEY = 'rspress-theme-appearance';
65
+ const SEARCH_INDEX_NAME = 'search_index';
66
+ const RSPRESS_TEMP_DIR = '.rspress';
67
+ const DEFAULT_HIGHLIGHT_LANGUAGES = [
68
+ [
69
+ 'js',
70
+ "javascript"
71
+ ],
72
+ [
73
+ 'ts',
74
+ "typescript"
75
+ ],
76
+ [
77
+ 'jsx',
78
+ 'tsx'
79
+ ],
80
+ [
81
+ 'xml',
82
+ 'xml-doc'
83
+ ],
84
+ [
85
+ 'md',
86
+ 'markdown'
87
+ ],
88
+ [
89
+ 'mdx',
90
+ 'tsx'
91
+ ]
71
92
  ];
72
- var isSCM = () => Boolean(process.env.BUILD_VERSION);
73
- var isProduction = () => process.env.NODE_ENV === "production";
74
- var isDebugMode = () => {
75
- if (!process.env.DEBUG) {
76
- return false;
77
- }
78
- const values = process.env.DEBUG?.toLocaleLowerCase().split(",") ?? [];
79
- return ["rsbuild", "builder", "*"].some((key) => values.includes(key));
93
+ const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
94
+ const isProduction = ()=>'production' === process.env.NODE_ENV;
95
+ const isDebugMode = ()=>{
96
+ if (!process.env.DEBUG) return false;
97
+ const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
98
+ return [
99
+ 'rsbuild',
100
+ 'builder',
101
+ '*'
102
+ ].some((key)=>values.includes(key));
80
103
  };
81
- var isDevDebugMode = () => process.env.DEBUG === "rspress-dev";
82
- var cleanUrl = (url) => url.replace(HASH_REGEXP, "").replace(QUERY_REGEXP, "");
104
+ const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
105
+ const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
83
106
  function slash(str) {
84
- return str.replace(/\\/g, "/");
107
+ return str.replace(/\\/g, '/');
85
108
  }
86
109
  function removeHash(str) {
87
- return str.replace(/#.*$/, "");
110
+ return str.replace(/#.*$/, '');
88
111
  }
89
112
  function normalizePosixPath(id) {
90
- const path = slash(id);
91
- const isAbsolutePath = path.startsWith("/");
92
- const parts = path.split("/");
93
- const normalizedParts = [];
94
- for (const part of parts) {
95
- if (part === "." || part === "") {
96
- } else if (part === "..") {
97
- if (normalizedParts.length > 0 && normalizedParts[normalizedParts.length - 1] !== "..") {
98
- normalizedParts.pop();
99
- } else if (isAbsolutePath) {
100
- normalizedParts.push("..");
101
- }
102
- } else {
103
- normalizedParts.push(part);
104
- }
105
- }
106
- let normalizedPath = normalizedParts.join("/");
107
- if (isAbsolutePath) {
108
- normalizedPath = `/${normalizedPath}`;
109
- }
110
- return normalizedPath;
111
- }
112
- var inBrowser = () => !process.env.__SSR__;
113
+ const path = slash(id);
114
+ const isAbsolutePath = path.startsWith('/');
115
+ const parts = path.split('/');
116
+ const normalizedParts = [];
117
+ for (const part of parts)if ('.' === part || '' === part) ;
118
+ else if ('..' === part) {
119
+ if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
120
+ else if (isAbsolutePath) normalizedParts.push('..');
121
+ } else normalizedParts.push(part);
122
+ let normalizedPath = normalizedParts.join('/');
123
+ if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
124
+ return normalizedPath;
125
+ }
126
+ const inBrowser = ()=>!process.env.__SSR__;
113
127
  function addLeadingSlash(url) {
114
- return url.charAt(0) === "/" || isExternalUrl(url) ? url : `/${url}`;
128
+ return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
115
129
  }
116
130
  function removeLeadingSlash(url) {
117
- return url.charAt(0) === "/" ? url.slice(1) : url;
131
+ return '/' === url.charAt(0) ? url.slice(1) : url;
118
132
  }
119
133
  function addTrailingSlash(url) {
120
- return url.charAt(url.length - 1) === "/" ? url : `${url}/`;
134
+ return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
121
135
  }
122
136
  function removeTrailingSlash(url) {
123
- return url.charAt(url.length - 1) === "/" ? url.slice(0, -1) : url;
137
+ return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
124
138
  }
125
139
  function normalizeSlash(url) {
126
- return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
127
- }
128
- function isExternalUrl(url = "") {
129
- return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
130
- }
131
- function isDataUrl(url = "") {
132
- return /^\s*data:/i.test(url);
133
- }
134
- function replaceLang(rawUrl, lang, version, base = "", cleanUrls = false, isPageNotFound = false) {
135
- let url = removeBase(rawUrl, base);
136
- if (!url || isPageNotFound) {
137
- url = cleanUrls ? "/index" : "/index.html";
138
- }
139
- if (url.endsWith("/")) {
140
- url += cleanUrls ? "/index" : "/index.html";
141
- }
142
- let versionPart = "";
143
- let langPart = "";
144
- let purePathPart = "";
145
- const parts = url.split("/").filter(Boolean);
146
- if (version.current && version.current !== version.default) {
147
- versionPart = parts.shift() || "";
148
- }
149
- if (lang.target !== lang.default) {
150
- langPart = lang.target;
151
- if (lang.current !== lang.default) {
152
- parts.shift();
153
- }
154
- } else {
155
- parts.shift();
156
- }
157
- purePathPart = parts.join("/") || "";
158
- if ((versionPart || langPart) && !purePathPart) {
159
- purePathPart = cleanUrls ? "index" : "index.html";
160
- }
161
- return withBase(
162
- addLeadingSlash(
163
- [versionPart, langPart, purePathPart].filter(Boolean).join("/")
164
- ),
165
- base
166
- );
167
- }
168
- function replaceVersion(rawUrl, version, base = "", cleanUrls = false, isPageNotFound = false) {
169
- let url = removeBase(rawUrl, base);
170
- if (!url || isPageNotFound) {
171
- url = cleanUrls ? "/index" : "/index.html";
172
- }
173
- let versionPart = "";
174
- const parts = url.split("/").filter(Boolean);
175
- if (version.target !== version.default) {
176
- versionPart = version.target;
177
- if (version.current !== version.default) {
178
- parts.shift();
179
- }
180
- } else {
181
- parts.shift();
182
- }
183
- let restPart = parts.join("/") || "";
184
- if (versionPart && !restPart) {
185
- restPart = cleanUrls ? "index" : "index.html";
186
- }
187
- return withBase(
188
- addLeadingSlash([versionPart, restPart].filter(Boolean).join("/")),
189
- base
190
- );
191
- }
192
- var parseUrl = (url) => {
193
- const [withoutHash, hash = ""] = url.split("#");
194
- return {
195
- url: withoutHash,
196
- hash
197
- };
140
+ return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
141
+ }
142
+ function isExternalUrl(url = '') {
143
+ return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
144
+ }
145
+ function isDataUrl(url = '') {
146
+ return /^\s*data:/i.test(url);
147
+ }
148
+ function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
149
+ let url = removeBase(rawUrl, base);
150
+ if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
151
+ if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
152
+ let versionPart = '';
153
+ let langPart = '';
154
+ let purePathPart = '';
155
+ const parts = url.split('/').filter(Boolean);
156
+ if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
157
+ if (lang.target !== lang.default) {
158
+ langPart = lang.target;
159
+ if (lang.current !== lang.default) parts.shift();
160
+ } else parts.shift();
161
+ purePathPart = parts.join('/') || '';
162
+ if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
163
+ return withBase(addLeadingSlash([
164
+ versionPart,
165
+ langPart,
166
+ purePathPart
167
+ ].filter(Boolean).join('/')), base);
168
+ }
169
+ function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
170
+ let url = removeBase(rawUrl, base);
171
+ if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
172
+ let versionPart = '';
173
+ const parts = url.split('/').filter(Boolean);
174
+ if (version.target !== version.default) {
175
+ versionPart = version.target;
176
+ if (version.current !== version.default) parts.shift();
177
+ } else parts.shift();
178
+ let restPart = parts.join('/') || '';
179
+ if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
180
+ return withBase(addLeadingSlash([
181
+ versionPart,
182
+ restPart
183
+ ].filter(Boolean).join('/')), base);
184
+ }
185
+ const parseUrl = (url)=>{
186
+ const [withoutHash, hash = ''] = url.split('#');
187
+ return {
188
+ url: withoutHash,
189
+ hash
190
+ };
198
191
  };
199
192
  function normalizeHref(url, cleanUrls = false) {
200
- if (!url) {
201
- return "/";
202
- }
203
- if (isExternalUrl(url)) {
204
- return url;
205
- }
206
- let { url: cleanUrl2, hash } = parseUrl(decodeURIComponent(url));
207
- if (!cleanUrls && !cleanUrl2.endsWith(".html")) {
208
- if (cleanUrl2.endsWith("/")) {
209
- cleanUrl2 += "index.html";
210
- } else {
211
- cleanUrl2 += ".html";
193
+ if (!url) return '/';
194
+ if (isExternalUrl(url)) return url;
195
+ let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
196
+ if (!cleanUrls && !cleanUrl.endsWith('.html')) {
197
+ if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
198
+ else cleanUrl += '.html';
212
199
  }
213
- }
214
- if (cleanUrls && cleanUrl2.endsWith("/")) {
215
- cleanUrl2 += "index";
216
- }
217
- if (cleanUrls && cleanUrl2.endsWith(".html")) {
218
- cleanUrl2 = cleanUrl2.replace(/\.html$/, "");
219
- }
220
- return addLeadingSlash(hash ? `${cleanUrl2}#${hash}` : cleanUrl2);
200
+ if (cleanUrls && cleanUrl.endsWith('/')) cleanUrl += 'index';
201
+ if (cleanUrls && cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
202
+ return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
221
203
  }
222
204
  function withoutLang(path, langs) {
223
- const langRegexp = new RegExp(`^\\/(${langs.join("|")})`);
224
- return addLeadingSlash(path.replace(langRegexp, ""));
205
+ const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
206
+ return addLeadingSlash(path.replace(langRegexp, ''));
225
207
  }
226
208
  function withoutBase(path, base) {
227
- return addLeadingSlash(path).replace(normalizeSlash(base), "");
209
+ return addLeadingSlash(path).replace(normalizeSlash(base), '');
228
210
  }
229
211
  function withBase(url, base) {
230
- const normalizedUrl = addLeadingSlash(url);
231
- const normalizedBase = normalizeSlash(base);
232
- return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
212
+ const normalizedUrl = addLeadingSlash(url);
213
+ const normalizedBase = normalizeSlash(base);
214
+ return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
233
215
  }
234
216
  function removeBase(url, base) {
235
- return addLeadingSlash(url).replace(
236
- new RegExp(`^${normalizeSlash(base)}`),
237
- ""
238
- );
217
+ return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
239
218
  }
240
- // Annotate the CommonJS export names for ESM import in node:
241
- 0 && (module.exports = {
242
- APPEARANCE_KEY,
243
- DEFAULT_HIGHLIGHT_LANGUAGES,
244
- HASH_REGEXP,
245
- MDX_REGEXP,
246
- QUERY_REGEXP,
247
- RSPRESS_TEMP_DIR,
248
- SEARCH_INDEX_NAME,
249
- addLeadingSlash,
250
- addTrailingSlash,
251
- cleanUrl,
252
- inBrowser,
253
- isDataUrl,
254
- isDebugMode,
255
- isDevDebugMode,
256
- isExternalUrl,
257
- isProduction,
258
- isSCM,
259
- normalizeHref,
260
- normalizePosixPath,
261
- normalizeSlash,
262
- parseUrl,
263
- removeBase,
264
- removeHash,
265
- removeLeadingSlash,
266
- removeTrailingSlash,
267
- replaceLang,
268
- replaceVersion,
269
- slash,
270
- withBase,
271
- withoutBase,
272
- withoutLang
219
+ var __webpack_export_target__ = exports;
220
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
221
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
222
+ value: true
273
223
  });