@wsxjs/wsx-press 0.0.23 → 0.0.25
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/client.cjs +1 -1
- package/dist/client.js +521 -501
- package/dist/index-CHILmtM0.js +129 -0
- package/dist/index-mEWJapVH.cjs +1 -0
- package/dist/node.cjs +41 -41
- package/dist/node.js +529 -518
- package/package.json +7 -7
- package/src/client/components/DocPage.wsx +32 -16
- package/src/client/components/DocSidebar.css +98 -3
- package/src/client/components/DocSidebar.wsx +17 -2
- package/src/client/components/DocTOC.wsx +9 -3
- package/src/node/metadata.ts +30 -3
- package/src/types.ts +2 -0
- package/dist/index-C1_yVVPT.cjs +0 -1
- package/dist/index-RqS0LFTH.js +0 -263
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wsxjs/wsx-press",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "A VitePress-like documentation system built with WSXJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"fuse.js": "^7.0.0",
|
|
30
30
|
"marked": "^12.0.0",
|
|
31
|
-
"@wsxjs/wsx-core": "0.0.
|
|
32
|
-
"@wsxjs/wsx-logger": "0.0.
|
|
33
|
-
"@wsxjs/wsx-marked-components": "0.0.
|
|
34
|
-
"@wsxjs/wsx-router": "0.0.
|
|
31
|
+
"@wsxjs/wsx-core": "0.0.25",
|
|
32
|
+
"@wsxjs/wsx-logger": "0.0.25",
|
|
33
|
+
"@wsxjs/wsx-marked-components": "0.0.25",
|
|
34
|
+
"@wsxjs/wsx-router": "0.0.25"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript": "^5.0.0",
|
|
49
49
|
"vite": "^5.4.19",
|
|
50
50
|
"vitest": "^2.0.0",
|
|
51
|
-
"@wsxjs/
|
|
52
|
-
"@wsxjs/
|
|
51
|
+
"@wsxjs/wsx-vite-plugin": "0.0.25",
|
|
52
|
+
"@wsxjs/eslint-plugin-wsx": "0.0.25"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"typedoc": "^0.26.0",
|
|
@@ -252,29 +252,45 @@ export default class DocPage extends LightComponent {
|
|
|
252
252
|
// 创建新的 AbortController
|
|
253
253
|
this.loadingAbortController = new AbortController();
|
|
254
254
|
|
|
255
|
-
// 从 RouterUtils
|
|
255
|
+
// 从 RouterUtils 获取当前路由信息
|
|
256
256
|
const routeInfo = RouterUtils.getCurrentRoute();
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
//
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
257
|
+
|
|
258
|
+
// 从路径中提取文档路径(支持多级路径)
|
|
259
|
+
// 例如:/docs/guide/essentials/getting-started -> guide/essentials/getting-started
|
|
260
|
+
let docPath: string;
|
|
261
|
+
if (routeInfo.path.startsWith("/docs/")) {
|
|
262
|
+
// 移除 /docs/ 前缀,得到文档路径
|
|
263
|
+
docPath = routeInfo.path.slice(6); // 移除 "/docs/"
|
|
264
|
+
} else {
|
|
265
|
+
// 尝试从 params 获取(向后兼容)
|
|
266
|
+
const params = routeInfo.params as { category?: string; page?: string };
|
|
267
|
+
if (params.category && params.page) {
|
|
268
|
+
docPath = `${params.category}/${params.page}`;
|
|
269
|
+
} else {
|
|
270
|
+
logger.warn("Invalid document path:", { path: routeInfo.path, params });
|
|
271
|
+
// 如果参数为空,可能是路由还未初始化,保持 idle 状态
|
|
272
|
+
if (Object.keys(params).length === 0) {
|
|
273
|
+
logger.debug("Route params not yet initialized, keeping idle state");
|
|
274
|
+
this.loadingState = "idle";
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.loadingState = "error";
|
|
278
|
+
this.error = new DocumentLoadError(
|
|
279
|
+
"Invalid document path: path must start with /docs/",
|
|
280
|
+
"INVALID_PARAMS"
|
|
281
|
+
);
|
|
266
282
|
return;
|
|
267
283
|
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 验证文档路径不为空
|
|
287
|
+
if (!docPath || docPath.trim() === "") {
|
|
288
|
+
logger.warn("Empty document path:", { path: routeInfo.path });
|
|
268
289
|
this.loadingState = "error";
|
|
269
|
-
this.error = new DocumentLoadError(
|
|
270
|
-
"Missing route parameters: category and page are required",
|
|
271
|
-
"INVALID_PARAMS"
|
|
272
|
-
);
|
|
290
|
+
this.error = new DocumentLoadError("Document path is empty", "INVALID_PARAMS");
|
|
273
291
|
return;
|
|
274
292
|
}
|
|
275
293
|
|
|
276
|
-
const docPath = `${params.category}/${params.page}`;
|
|
277
|
-
|
|
278
294
|
// 防止竞态条件:记录当前加载路径
|
|
279
295
|
this.currentLoadingPath = docPath;
|
|
280
296
|
this.isLoading = true;
|
|
@@ -12,6 +12,28 @@ wsx-doc-sidebar {
|
|
|
12
12
|
max-height: calc(100vh - 70px);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/* 浅色模式(通过类名,覆盖媒体查询) */
|
|
16
|
+
.light wsx-doc-sidebar,
|
|
17
|
+
[data-theme="light"] wsx-doc-sidebar {
|
|
18
|
+
background: var(--wsx-press-sidebar-bg, #f9fafb);
|
|
19
|
+
border-right-color: var(--wsx-press-border, #e5e7eb);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* 暗色模式(通过类名) */
|
|
23
|
+
.dark wsx-doc-sidebar,
|
|
24
|
+
[data-theme="dark"] wsx-doc-sidebar {
|
|
25
|
+
background: var(--wsx-press-sidebar-bg, #1f2937);
|
|
26
|
+
border-right-color: var(--wsx-press-border, #374151);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* 暗色模式(通过媒体查询作为后备,仅当没有显式类名时) */
|
|
30
|
+
@media (prefers-color-scheme: dark) {
|
|
31
|
+
html:not(.light):not([data-theme="light"]) wsx-doc-sidebar {
|
|
32
|
+
background: var(--wsx-press-sidebar-bg, #1f2937);
|
|
33
|
+
border-right-color: var(--wsx-press-border, #374151);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
15
37
|
.doc-sidebar {
|
|
16
38
|
display: flex;
|
|
17
39
|
flex-direction: column;
|
|
@@ -48,6 +70,24 @@ wsx-doc-sidebar {
|
|
|
48
70
|
margin: 0 0 0.5rem 0;
|
|
49
71
|
}
|
|
50
72
|
|
|
73
|
+
/* 浅色模式分类标题(覆盖媒体查询) */
|
|
74
|
+
.light .doc-sidebar-category-title,
|
|
75
|
+
[data-theme="light"] .doc-sidebar-category-title {
|
|
76
|
+
color: var(--wsx-press-text-secondary, #6b7280);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* 暗色模式分类标题 */
|
|
80
|
+
.dark .doc-sidebar-category-title,
|
|
81
|
+
[data-theme="dark"] .doc-sidebar-category-title {
|
|
82
|
+
color: var(--wsx-press-text-secondary, #9ca3af);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (prefers-color-scheme: dark) {
|
|
86
|
+
html:not(.light):not([data-theme="light"]) .doc-sidebar-category-title {
|
|
87
|
+
color: var(--wsx-press-text-secondary, #9ca3af);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
51
91
|
.doc-sidebar-list {
|
|
52
92
|
list-style: none;
|
|
53
93
|
margin: 0;
|
|
@@ -75,12 +115,67 @@ wsx-doc-sidebar {
|
|
|
75
115
|
}
|
|
76
116
|
|
|
77
117
|
.doc-sidebar-link.active {
|
|
78
|
-
background: var(--wsx-press-sidebar-active-bg, #
|
|
79
|
-
color: var(--wsx-press-sidebar-active-color, #
|
|
80
|
-
border-left-color: var(--wsx-press-sidebar-active-color, #
|
|
118
|
+
background: var(--wsx-press-sidebar-active-bg, #fef2f2);
|
|
119
|
+
color: var(--wsx-press-sidebar-active-color, #dc2626);
|
|
120
|
+
border-left-color: var(--wsx-press-sidebar-active-color, #dc2626);
|
|
81
121
|
font-weight: 500;
|
|
82
122
|
}
|
|
83
123
|
|
|
124
|
+
/* 浅色模式链接样式(覆盖媒体查询) */
|
|
125
|
+
.light .doc-sidebar-link,
|
|
126
|
+
[data-theme="light"] .doc-sidebar-link {
|
|
127
|
+
color: var(--wsx-press-text-primary, #111827);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.light .doc-sidebar-link:hover,
|
|
131
|
+
[data-theme="light"] .doc-sidebar-link:hover {
|
|
132
|
+
background: var(--wsx-press-sidebar-hover-bg, #f3f4f6);
|
|
133
|
+
color: var(--wsx-press-text-primary, #111827);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.light .doc-sidebar-link.active,
|
|
137
|
+
[data-theme="light"] .doc-sidebar-link.active {
|
|
138
|
+
background: var(--wsx-press-sidebar-active-bg, #fef2f2);
|
|
139
|
+
color: var(--wsx-press-sidebar-active-color, #dc2626);
|
|
140
|
+
border-left-color: var(--wsx-press-sidebar-active-color, #dc2626);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* 暗色模式链接样式 */
|
|
144
|
+
.dark .doc-sidebar-link,
|
|
145
|
+
[data-theme="dark"] .doc-sidebar-link {
|
|
146
|
+
color: var(--wsx-press-text-primary, #e5e7eb);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.dark .doc-sidebar-link:hover,
|
|
150
|
+
[data-theme="dark"] .doc-sidebar-link:hover {
|
|
151
|
+
background: var(--wsx-press-sidebar-hover-bg, #374151);
|
|
152
|
+
color: var(--wsx-press-text-primary, #f3f4f6);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.dark .doc-sidebar-link.active,
|
|
156
|
+
[data-theme="dark"] .doc-sidebar-link.active {
|
|
157
|
+
background: var(--wsx-press-sidebar-active-bg, rgba(220, 38, 38, 0.15));
|
|
158
|
+
color: var(--wsx-press-sidebar-active-color, #f87171);
|
|
159
|
+
border-left-color: var(--wsx-press-sidebar-active-color, #f87171);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@media (prefers-color-scheme: dark) {
|
|
163
|
+
html:not(.light):not([data-theme="light"]) .doc-sidebar-link {
|
|
164
|
+
color: var(--wsx-press-text-primary, #e5e7eb);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
html:not(.light):not([data-theme="light"]) .doc-sidebar-link:hover {
|
|
168
|
+
background: var(--wsx-press-sidebar-hover-bg, #374151);
|
|
169
|
+
color: var(--wsx-press-text-primary, #f3f4f6);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
html:not(.light):not([data-theme="light"]) .doc-sidebar-link.active {
|
|
173
|
+
background: var(--wsx-press-sidebar-active-bg, rgba(220, 38, 38, 0.15));
|
|
174
|
+
color: var(--wsx-press-sidebar-active-color, #f87171);
|
|
175
|
+
border-left-color: var(--wsx-press-sidebar-active-color, #f87171);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
84
179
|
/* 响应式设计 */
|
|
85
180
|
@media (max-width: 1024px) {
|
|
86
181
|
wsx-doc-sidebar {
|
|
@@ -103,9 +103,24 @@ export default class DocSidebar extends LightComponent {
|
|
|
103
103
|
// 按分类名称排序
|
|
104
104
|
const sortedCategories = Object.keys(organized).sort();
|
|
105
105
|
|
|
106
|
-
//
|
|
106
|
+
// 对每个分类内的文档排序(优先按 order,然后按标题)
|
|
107
107
|
sortedCategories.forEach((category) => {
|
|
108
|
-
organized[category].sort((a, b) =>
|
|
108
|
+
organized[category].sort((a, b) => {
|
|
109
|
+
// 如果两个文档都有 order,按 order 排序
|
|
110
|
+
if (a.order !== undefined && b.order !== undefined) {
|
|
111
|
+
return a.order - b.order;
|
|
112
|
+
}
|
|
113
|
+
// 如果只有 a 有 order,a 排在前面
|
|
114
|
+
if (a.order !== undefined) {
|
|
115
|
+
return -1;
|
|
116
|
+
}
|
|
117
|
+
// 如果只有 b 有 order,b 排在前面
|
|
118
|
+
if (b.order !== undefined) {
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
// 都没有 order,按标题排序
|
|
122
|
+
return a.title.localeCompare(b.title);
|
|
123
|
+
});
|
|
109
124
|
});
|
|
110
125
|
|
|
111
126
|
return organized;
|
|
@@ -105,14 +105,20 @@ export default class DocTOC extends LightComponent {
|
|
|
105
105
|
private async loadTOC(): Promise<void> {
|
|
106
106
|
try {
|
|
107
107
|
const routeInfo = RouterUtils.getCurrentRoute();
|
|
108
|
-
|
|
108
|
+
// 从路径中提取 docPath(移除 /docs/ 前缀)
|
|
109
|
+
let docPath: string;
|
|
110
|
+
if (routeInfo.path.startsWith("/docs/")) {
|
|
111
|
+
docPath = routeInfo.path.slice(6); // 移除 "/docs/" 前缀
|
|
112
|
+
} else {
|
|
113
|
+
this.items = [];
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
109
116
|
|
|
110
|
-
if (!
|
|
117
|
+
if (!docPath || docPath.trim() === "") {
|
|
111
118
|
this.items = [];
|
|
112
119
|
return;
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
const docPath = `${params.category}/${params.page}`;
|
|
116
122
|
const tocData = await loadTOCData();
|
|
117
123
|
this.items = tocData[docPath] || [];
|
|
118
124
|
|
package/src/node/metadata.ts
CHANGED
|
@@ -27,7 +27,8 @@ export async function scanDocsMetadata(docsRoot: string): Promise<DocsMetaCollec
|
|
|
27
27
|
const dirname = path.dirname(relativePath);
|
|
28
28
|
metadata[key] = {
|
|
29
29
|
title: frontmatter.title || path.basename(file, ".md"),
|
|
30
|
-
|
|
30
|
+
// 优先使用 frontmatter 中的 category,如果没有则使用 dirname
|
|
31
|
+
category: frontmatter.category || (dirname === "." ? "." : dirname),
|
|
31
32
|
route: `/docs/${key}`,
|
|
32
33
|
...frontmatter,
|
|
33
34
|
};
|
|
@@ -64,7 +65,25 @@ export function extractFrontmatter(markdown: string): Partial<DocMetadata> {
|
|
|
64
65
|
if (key && value) {
|
|
65
66
|
// 类型安全的属性赋值
|
|
66
67
|
if (key === "title" || key === "description" || key === "category") {
|
|
67
|
-
|
|
68
|
+
// 移除值两端的引号(如果存在)
|
|
69
|
+
let cleanValue = value.replace(/^["']|["']$/g, "");
|
|
70
|
+
// 解码 HTML 实体(如 " -> ")
|
|
71
|
+
// 使用 Node.js 兼容的方法
|
|
72
|
+
if (cleanValue.includes("&")) {
|
|
73
|
+
cleanValue = cleanValue
|
|
74
|
+
.replace(/"/g, '"')
|
|
75
|
+
.replace(/'/g, "'")
|
|
76
|
+
.replace(/</g, "<")
|
|
77
|
+
.replace(/>/g, ">")
|
|
78
|
+
.replace(/&/g, "&");
|
|
79
|
+
}
|
|
80
|
+
(meta as Record<string, string>)[key] = cleanValue;
|
|
81
|
+
} else if (key === "order") {
|
|
82
|
+
// 解析 order 字段为数字
|
|
83
|
+
const orderNum = Number.parseInt(value, 10);
|
|
84
|
+
if (!Number.isNaN(orderNum)) {
|
|
85
|
+
meta.order = orderNum;
|
|
86
|
+
}
|
|
68
87
|
} else if (key === "tags") {
|
|
69
88
|
// 简单的数组解析(实际应使用 YAML 解析器)
|
|
70
89
|
meta.tags = value
|
|
@@ -101,7 +120,15 @@ export function addPrevNextLinks(metadata: DocsMetaCollection): DocsMetaCollecti
|
|
|
101
120
|
|
|
102
121
|
// 为每个类别添加 prev/next
|
|
103
122
|
for (const [_category, keys] of categories) {
|
|
104
|
-
|
|
123
|
+
// 按 order 字段排序(如果存在),然后按 key 排序
|
|
124
|
+
keys.sort((a, b) => {
|
|
125
|
+
const orderA = metadata[a].order ?? Number.MAX_SAFE_INTEGER;
|
|
126
|
+
const orderB = metadata[b].order ?? Number.MAX_SAFE_INTEGER;
|
|
127
|
+
if (orderA !== orderB) {
|
|
128
|
+
return orderA - orderB;
|
|
129
|
+
}
|
|
130
|
+
return a.localeCompare(b);
|
|
131
|
+
});
|
|
105
132
|
for (let i = 0; i < keys.length; i++) {
|
|
106
133
|
const key = keys[i];
|
|
107
134
|
metadata[key].prev = i > 0 ? `/docs/${keys[i - 1]}` : null;
|
package/src/types.ts
CHANGED
package/dist/index-C1_yVVPT.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var W=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var C={exports:{}};(function(i){(function(t,e){i.exports?i.exports=e():t.log=e()})(W,function(){var t=function(){},e="undefined",o=typeof window!==e&&typeof window.navigator!==e&&/Trident\/|MSIE /.test(window.navigator.userAgent),g=["trace","debug","info","warn","error"],u={},c=null;function b(r,s){var n=r[s];if(typeof n.bind=="function")return n.bind(r);try{return Function.prototype.bind.call(n,r)}catch{return function(){return Function.prototype.apply.apply(n,[r,arguments])}}}function _(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function R(r){return r==="debug"&&(r="log"),typeof console===e?!1:r==="trace"&&o?_:console[r]!==void 0?b(console,r):console.log!==void 0?b(console,"log"):t}function h(){for(var r=this.getLevel(),s=0;s<g.length;s++){var n=g[s];this[n]=s<r?t:this.methodFactory(n,r,this.name)}if(this.log=this.debug,typeof console===e&&r<this.levels.SILENT)return"No console available for logging"}function S(r){return function(){typeof console!==e&&(h.call(this),this[r].apply(this,arguments))}}function x(r,s,n){return R(r)||S.apply(this,arguments)}function E(r,s){var n=this,w,m,d,f="loglevel";typeof r=="string"?f+=":"+r:typeof r=="symbol"&&(f=void 0);function P(l){var a=(g[l]||"silent").toUpperCase();if(!(typeof window===e||!f)){try{window.localStorage[f]=a;return}catch{}try{window.document.cookie=encodeURIComponent(f)+"="+a+";"}catch{}}}function T(){var l;if(!(typeof window===e||!f)){try{l=window.localStorage[f]}catch{}if(typeof l===e)try{var a=window.document.cookie,y=encodeURIComponent(f),A=a.indexOf(y+"=");A!==-1&&(l=/^([^;]+)/.exec(a.slice(A+y.length+1))[1])}catch{}return n.levels[l]===void 0&&(l=void 0),l}}function U(){if(!(typeof window===e||!f)){try{window.localStorage.removeItem(f)}catch{}try{window.document.cookie=encodeURIComponent(f)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function p(l){var a=l;if(typeof a=="string"&&n.levels[a.toUpperCase()]!==void 0&&(a=n.levels[a.toUpperCase()]),typeof a=="number"&&a>=0&&a<=n.levels.SILENT)return a;throw new TypeError("log.setLevel() called with invalid level: "+l)}n.name=r,n.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},n.methodFactory=s||x,n.getLevel=function(){return d??m??w},n.setLevel=function(l,a){return d=p(l),a!==!1&&P(d),h.call(n)},n.setDefaultLevel=function(l){m=p(l),T()||n.setLevel(l,!1)},n.resetLevel=function(){d=null,U(),h.call(n)},n.enableAll=function(l){n.setLevel(n.levels.TRACE,l)},n.disableAll=function(l){n.setLevel(n.levels.SILENT,l)},n.rebuild=function(){if(c!==n&&(w=p(c.getLevel())),h.call(n),c===n)for(var l in u)u[l].rebuild()},w=p(c?c.getLevel():"WARN");var M=T();M!=null&&(d=p(M)),h.call(n)}c=new E,c.getLogger=function(s){if(typeof s!="symbol"&&typeof s!="string"||s==="")throw new TypeError("You must supply a name when creating a logger.");var n=u[s];return n||(n=u[s]=new E(s,c.methodFactory)),n};var N=typeof window!==e?window.log:void 0;return c.noConflict=function(){return typeof window!==e&&window.log===c&&(window.log=N),c},c.getLoggers=function(){return u},c.default=c,c})})(C);var G=C.exports;const V=$(G),F={trace:"trace",debug:"debug",info:"info",warn:"warn",error:"error",silent:"silent"},X={0:"trace",1:"debug",2:"info",3:"warn",4:"error",5:"silent"};function I(){var i,t;if(typeof process<"u")return process.env.NODE_ENV==="production"||process.env.MODE==="production";try{const e=globalThis;if((t=(i=e.import)==null?void 0:i.meta)!=null&&t.env){const o=e.import.meta.env;return o.MODE==="production"||o.PROD===!0}}catch{}return!1}const L={name:"WSX",level:I()?"info":"debug",pretty:!I()};function B(i={}){const{name:t,level:e}={...L,...i},o=t||L.name,g=V.getLogger(o),u=e||L.level;return g.setLevel(F[u]),g}function v(i,t){return i?`[${i}] ${t}`:t}class O{constructor(t={}){this.isProd=I(),this.name=t.name||L.name,this.currentLevel=t.level||L.level,this.logInstance=B(t)}debug(t,...e){if(!this.isProd||this.shouldLog("debug")){const o=v(this.name,t);e.length>0?this.logInstance.debug(o,...e):this.logInstance.debug(o)}}info(t,...e){if(this.shouldLog("info")){const o=v(this.name,t);e.length>0?this.logInstance.info(o,...e):this.logInstance.info(o)}}warn(t,...e){const o=v(this.name,t);e.length>0?this.logInstance.warn(o,...e):this.logInstance.warn(o)}error(t,...e){const o=v(this.name,t);e.length>0?this.logInstance.error(o,...e):this.logInstance.error(o)}fatal(t,...e){const o=v(this.name,t);e.length>0?this.logInstance.error(`[FATAL] ${o}`,...e):this.logInstance.error(`[FATAL] ${o}`)}trace(t,...e){if(!this.isProd||this.shouldLog("trace")){const o=v(this.name,t);e.length>0?this.logInstance.trace(o,...e):this.logInstance.trace(o)}}shouldLog(t){const e=["trace","debug","info","warn","error","silent"],o=e.indexOf(this.currentLevel);return e.indexOf(t)>=o}getLoglevelLogger(){return this.logInstance}setLevel(t){this.currentLevel=t,this.logInstance.setLevel(F[t])}getLevel(){const t=this.logInstance.getLevel();return X[t]||this.currentLevel}}new O;function k(i,t={}){return new O({...t,name:t.name||`WSX:${i}`})}exports.createLogger=k;
|
package/dist/index-RqS0LFTH.js
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
var W = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
2
|
-
function $(i) {
|
|
3
|
-
return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
|
|
4
|
-
}
|
|
5
|
-
var C = { exports: {} };
|
|
6
|
-
(function(i) {
|
|
7
|
-
(function(t, e) {
|
|
8
|
-
i.exports ? i.exports = e() : t.log = e();
|
|
9
|
-
})(W, function() {
|
|
10
|
-
var t = function() {
|
|
11
|
-
}, e = "undefined", o = typeof window !== e && typeof window.navigator !== e && /Trident\/|MSIE /.test(window.navigator.userAgent), g = [
|
|
12
|
-
"trace",
|
|
13
|
-
"debug",
|
|
14
|
-
"info",
|
|
15
|
-
"warn",
|
|
16
|
-
"error"
|
|
17
|
-
], u = {}, c = null;
|
|
18
|
-
function b(r, s) {
|
|
19
|
-
var n = r[s];
|
|
20
|
-
if (typeof n.bind == "function")
|
|
21
|
-
return n.bind(r);
|
|
22
|
-
try {
|
|
23
|
-
return Function.prototype.bind.call(n, r);
|
|
24
|
-
} catch {
|
|
25
|
-
return function() {
|
|
26
|
-
return Function.prototype.apply.apply(n, [r, arguments]);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function _() {
|
|
31
|
-
console.log && (console.log.apply ? console.log.apply(console, arguments) : Function.prototype.apply.apply(console.log, [console, arguments])), console.trace && console.trace();
|
|
32
|
-
}
|
|
33
|
-
function R(r) {
|
|
34
|
-
return r === "debug" && (r = "log"), typeof console === e ? !1 : r === "trace" && o ? _ : console[r] !== void 0 ? b(console, r) : console.log !== void 0 ? b(console, "log") : t;
|
|
35
|
-
}
|
|
36
|
-
function p() {
|
|
37
|
-
for (var r = this.getLevel(), s = 0; s < g.length; s++) {
|
|
38
|
-
var n = g[s];
|
|
39
|
-
this[n] = s < r ? t : this.methodFactory(n, r, this.name);
|
|
40
|
-
}
|
|
41
|
-
if (this.log = this.debug, typeof console === e && r < this.levels.SILENT)
|
|
42
|
-
return "No console available for logging";
|
|
43
|
-
}
|
|
44
|
-
function x(r) {
|
|
45
|
-
return function() {
|
|
46
|
-
typeof console !== e && (p.call(this), this[r].apply(this, arguments));
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function S(r, s, n) {
|
|
50
|
-
return R(r) || x.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
function E(r, s) {
|
|
53
|
-
var n = this, w, m, d, f = "loglevel";
|
|
54
|
-
typeof r == "string" ? f += ":" + r : typeof r == "symbol" && (f = void 0);
|
|
55
|
-
function P(l) {
|
|
56
|
-
var a = (g[l] || "silent").toUpperCase();
|
|
57
|
-
if (!(typeof window === e || !f)) {
|
|
58
|
-
try {
|
|
59
|
-
window.localStorage[f] = a;
|
|
60
|
-
return;
|
|
61
|
-
} catch {
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
window.document.cookie = encodeURIComponent(f) + "=" + a + ";";
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function T() {
|
|
70
|
-
var l;
|
|
71
|
-
if (!(typeof window === e || !f)) {
|
|
72
|
-
try {
|
|
73
|
-
l = window.localStorage[f];
|
|
74
|
-
} catch {
|
|
75
|
-
}
|
|
76
|
-
if (typeof l === e)
|
|
77
|
-
try {
|
|
78
|
-
var a = window.document.cookie, y = encodeURIComponent(f), A = a.indexOf(y + "=");
|
|
79
|
-
A !== -1 && (l = /^([^;]+)/.exec(
|
|
80
|
-
a.slice(A + y.length + 1)
|
|
81
|
-
)[1]);
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
return n.levels[l] === void 0 && (l = void 0), l;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function U() {
|
|
88
|
-
if (!(typeof window === e || !f)) {
|
|
89
|
-
try {
|
|
90
|
-
window.localStorage.removeItem(f);
|
|
91
|
-
} catch {
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
window.document.cookie = encodeURIComponent(f) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
95
|
-
} catch {
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function h(l) {
|
|
100
|
-
var a = l;
|
|
101
|
-
if (typeof a == "string" && n.levels[a.toUpperCase()] !== void 0 && (a = n.levels[a.toUpperCase()]), typeof a == "number" && a >= 0 && a <= n.levels.SILENT)
|
|
102
|
-
return a;
|
|
103
|
-
throw new TypeError("log.setLevel() called with invalid level: " + l);
|
|
104
|
-
}
|
|
105
|
-
n.name = r, n.levels = {
|
|
106
|
-
TRACE: 0,
|
|
107
|
-
DEBUG: 1,
|
|
108
|
-
INFO: 2,
|
|
109
|
-
WARN: 3,
|
|
110
|
-
ERROR: 4,
|
|
111
|
-
SILENT: 5
|
|
112
|
-
}, n.methodFactory = s || S, n.getLevel = function() {
|
|
113
|
-
return d ?? m ?? w;
|
|
114
|
-
}, n.setLevel = function(l, a) {
|
|
115
|
-
return d = h(l), a !== !1 && P(d), p.call(n);
|
|
116
|
-
}, n.setDefaultLevel = function(l) {
|
|
117
|
-
m = h(l), T() || n.setLevel(l, !1);
|
|
118
|
-
}, n.resetLevel = function() {
|
|
119
|
-
d = null, U(), p.call(n);
|
|
120
|
-
}, n.enableAll = function(l) {
|
|
121
|
-
n.setLevel(n.levels.TRACE, l);
|
|
122
|
-
}, n.disableAll = function(l) {
|
|
123
|
-
n.setLevel(n.levels.SILENT, l);
|
|
124
|
-
}, n.rebuild = function() {
|
|
125
|
-
if (c !== n && (w = h(c.getLevel())), p.call(n), c === n)
|
|
126
|
-
for (var l in u)
|
|
127
|
-
u[l].rebuild();
|
|
128
|
-
}, w = h(
|
|
129
|
-
c ? c.getLevel() : "WARN"
|
|
130
|
-
);
|
|
131
|
-
var M = T();
|
|
132
|
-
M != null && (d = h(M)), p.call(n);
|
|
133
|
-
}
|
|
134
|
-
c = new E(), c.getLogger = function(s) {
|
|
135
|
-
if (typeof s != "symbol" && typeof s != "string" || s === "")
|
|
136
|
-
throw new TypeError("You must supply a name when creating a logger.");
|
|
137
|
-
var n = u[s];
|
|
138
|
-
return n || (n = u[s] = new E(
|
|
139
|
-
s,
|
|
140
|
-
c.methodFactory
|
|
141
|
-
)), n;
|
|
142
|
-
};
|
|
143
|
-
var N = typeof window !== e ? window.log : void 0;
|
|
144
|
-
return c.noConflict = function() {
|
|
145
|
-
return typeof window !== e && window.log === c && (window.log = N), c;
|
|
146
|
-
}, c.getLoggers = function() {
|
|
147
|
-
return u;
|
|
148
|
-
}, c.default = c, c;
|
|
149
|
-
});
|
|
150
|
-
})(C);
|
|
151
|
-
var G = C.exports;
|
|
152
|
-
const V = /* @__PURE__ */ $(G), F = {
|
|
153
|
-
trace: "trace",
|
|
154
|
-
debug: "debug",
|
|
155
|
-
info: "info",
|
|
156
|
-
warn: "warn",
|
|
157
|
-
error: "error",
|
|
158
|
-
silent: "silent"
|
|
159
|
-
}, X = {
|
|
160
|
-
0: "trace",
|
|
161
|
-
1: "debug",
|
|
162
|
-
2: "info",
|
|
163
|
-
3: "warn",
|
|
164
|
-
4: "error",
|
|
165
|
-
5: "silent"
|
|
166
|
-
};
|
|
167
|
-
function I() {
|
|
168
|
-
var i, t;
|
|
169
|
-
if (typeof process < "u")
|
|
170
|
-
return process.env.NODE_ENV === "production" || process.env.MODE === "production";
|
|
171
|
-
try {
|
|
172
|
-
const e = globalThis;
|
|
173
|
-
if ((t = (i = e.import) == null ? void 0 : i.meta) != null && t.env) {
|
|
174
|
-
const o = e.import.meta.env;
|
|
175
|
-
return o.MODE === "production" || o.PROD === !0;
|
|
176
|
-
}
|
|
177
|
-
} catch {
|
|
178
|
-
}
|
|
179
|
-
return !1;
|
|
180
|
-
}
|
|
181
|
-
const L = {
|
|
182
|
-
name: "WSX",
|
|
183
|
-
level: I() ? "info" : "debug",
|
|
184
|
-
pretty: !I()
|
|
185
|
-
};
|
|
186
|
-
function B(i = {}) {
|
|
187
|
-
const { name: t, level: e } = { ...L, ...i }, o = t || L.name, g = V.getLogger(o), u = e || L.level;
|
|
188
|
-
return g.setLevel(F[u]), g;
|
|
189
|
-
}
|
|
190
|
-
function v(i, t) {
|
|
191
|
-
return i ? `[${i}] ${t}` : t;
|
|
192
|
-
}
|
|
193
|
-
class O {
|
|
194
|
-
constructor(t = {}) {
|
|
195
|
-
this.isProd = I(), this.name = t.name || L.name, this.currentLevel = t.level || L.level, this.logInstance = B(t);
|
|
196
|
-
}
|
|
197
|
-
debug(t, ...e) {
|
|
198
|
-
if (!this.isProd || this.shouldLog("debug")) {
|
|
199
|
-
const o = v(this.name, t);
|
|
200
|
-
e.length > 0 ? this.logInstance.debug(o, ...e) : this.logInstance.debug(o);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
info(t, ...e) {
|
|
204
|
-
if (this.shouldLog("info")) {
|
|
205
|
-
const o = v(this.name, t);
|
|
206
|
-
e.length > 0 ? this.logInstance.info(o, ...e) : this.logInstance.info(o);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
warn(t, ...e) {
|
|
210
|
-
const o = v(this.name, t);
|
|
211
|
-
e.length > 0 ? this.logInstance.warn(o, ...e) : this.logInstance.warn(o);
|
|
212
|
-
}
|
|
213
|
-
error(t, ...e) {
|
|
214
|
-
const o = v(this.name, t);
|
|
215
|
-
e.length > 0 ? this.logInstance.error(o, ...e) : this.logInstance.error(o);
|
|
216
|
-
}
|
|
217
|
-
fatal(t, ...e) {
|
|
218
|
-
const o = v(this.name, t);
|
|
219
|
-
e.length > 0 ? this.logInstance.error(`[FATAL] ${o}`, ...e) : this.logInstance.error(`[FATAL] ${o}`);
|
|
220
|
-
}
|
|
221
|
-
trace(t, ...e) {
|
|
222
|
-
if (!this.isProd || this.shouldLog("trace")) {
|
|
223
|
-
const o = v(this.name, t);
|
|
224
|
-
e.length > 0 ? this.logInstance.trace(o, ...e) : this.logInstance.trace(o);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Check if a log level should be logged based on current level
|
|
229
|
-
*/
|
|
230
|
-
shouldLog(t) {
|
|
231
|
-
const e = ["trace", "debug", "info", "warn", "error", "silent"], o = e.indexOf(this.currentLevel);
|
|
232
|
-
return e.indexOf(t) >= o;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Get the underlying loglevel logger instance
|
|
236
|
-
*/
|
|
237
|
-
getLoglevelLogger() {
|
|
238
|
-
return this.logInstance;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Set the log level dynamically
|
|
242
|
-
*/
|
|
243
|
-
setLevel(t) {
|
|
244
|
-
this.currentLevel = t, this.logInstance.setLevel(F[t]);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Get the current log level
|
|
248
|
-
*/
|
|
249
|
-
getLevel() {
|
|
250
|
-
const t = this.logInstance.getLevel();
|
|
251
|
-
return X[t] || this.currentLevel;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
new O();
|
|
255
|
-
function k(i, t = {}) {
|
|
256
|
-
return new O({
|
|
257
|
-
...t,
|
|
258
|
-
name: t.name || `WSX:${i}`
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
export {
|
|
262
|
-
k as c
|
|
263
|
-
};
|