docs: API 文档目录

This commit is contained in:
unanmed 2025-03-21 16:49:46 +08:00
parent dc82010e85
commit c94cb97c2c
31 changed files with 710 additions and 87 deletions

View File

@ -65,6 +65,255 @@ export default defineConfig({
}
]
}
],
'/api/': [
{
text: 'API 列表',
items: [
{ text: '目录', link: '/api/' },
{
text: '@motajs/client',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-client/' }
]
},
{
text: '@motajs/client-base',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-client-base/'
},
{
text: 'KeyCode',
link: '/api/motajs-client-base/KeyCode'
}
]
},
{
text: '@motajs/common',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-common/' },
{
text: '函数',
link: '/api/motajs-common/functions'
},
{
text: 'Logger',
link: '/api/motajs-common/Logger'
}
]
},
{
text: '@motajs/legacy-client',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-legacy-client/'
}
]
},
{
text: '@motajs/legacy-common',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-legacy-common/'
}
]
},
{
text: '@motajs/legacy-system',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-legacy-system/'
}
]
},
{
text: '@motajs/legacy-ui',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-legacy-ui/' }
]
},
{
text: '@motajs/render',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-render/' }
]
},
{
text: '@motajs/render-core',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-render-core/'
}
]
},
{
text: '@motajs/render-elements',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-render-elements/'
}
]
},
{
text: '@motajs/render-style',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-render-style/'
}
]
},
{
text: '@motajs/render-vue',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-render-vue/'
}
]
},
{
text: '@motajs/system',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-system/' }
]
},
{
text: '@motajs/system-action',
collapsed: true,
items: [
{
text: '目录',
link: '/api/motajs-system-action/'
}
]
},
{
text: '@motajs/system-ui',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-system-ui/' }
]
},
{
text: '@motajs/types',
collapsed: true,
items: [
{ text: '目录', link: '/api/motajs-types/' }
]
},
{
text: '@user/client-modules',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-client-modules/'
}
]
},
{
text: '@user/data-base',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-data-base/'
}
]
},
{
text: '@user/data-fallback',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-data-fallback/'
}
]
},
{
text: '@user/data-state',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-data-state/'
}
]
},
{
text: '@user/data-utils',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-data-utils/'
}
]
},
{
text: '@user/entry-client',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-entry-client/'
}
]
},
{
text: '@user/entry-data',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-entry-data/'
}
]
},
{
text: '@user/legacy-plugin-client',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-legacy-plugin-client/'
}
]
},
{
text: '@user/legacy-plugin-data',
collapsed: true,
items: [
{
text: '目录',
link: '/api/user-legacy-plugin-data/'
}
]
}
]
}
]
},
socialLinks: [

View File

@ -3,3 +3,30 @@ lang: zh-CN
---
# API 列表
- [@motajs/client](./motajs-client) 渲染层代码
- [@motajs/client-base](./motajs-client-base) 渲染层底层代码
- [@motajs/common](./motajs-common) 渲染层和数据层通用代码
- [@motajs/legacy-client](./motajs-legacy-client) 遗留渲染层代码
- [@motajs/legacy-common](./motajs-legacy-common) 遗留通用代码
- [@motajs/legacy-data](./motajs-legacy-data) 遗留数据层代码
- [@motajs/legacy-system](./motajs-legacy-system) 遗留渲染层系统代码
- [@motajs/legacy-ui](./motajs-legacy-ui) 遗留 UI 相关代码
- [@motajs/render](./motajs-render) 渲染系统代码
- [@motajs/render-core](./motajs-render-core) 渲染系统核心代码
- [@motajs/render-elements](./motajs-render-elements) 渲染系统内置元素代码
- [@motajs/render-style](./motajs-render-style) 渲染系统样式代码
- [@motajs/render-vue](./motajs-render-vue) 渲染系统 vue 支持代码
- [@motajs/system](./motajs-system) 渲染层系统代码
- [@motajs/system-action](./motajs-system-action) 渲染层交互系统代码
- [@motajs/system-ui](./motajs-system-ui) 渲染层 UI 系统代码
- [@motajs/types](./motajs-types) 渲染层类型代码
- [@user/client-modules](./user-client-modules) 用户渲染层主要代码
- [@user/data-base](./user-data-base) 用户数据层底层代码
- [@user/data-fallback](./user-data-fallback) 用户数据层向后兼容代码
- [@user/data-state](./user-data-state) 用户数据层状态代码
- [@user/data-utils](./user-data-utils) 用户数据层工具代码
- [@user/entry-client](./user-entry-client) 用户渲染层入口
- [@user/entry-data](./user-entry-data) 用户数据层入口
- [@user/legacy-plugin-client](./user-legacy-plugin-client) 用户遗留渲染层代码
- [@user/legacy-plugin-data](./user-legacy-plugin-data) 用户遗留数据层代码

View File

@ -0,0 +1,3 @@
# KeyCode
参考 `monaco-editor` 文档 [KeyCode](https://microsoft.github.io/monaco-editor/docs.html#enums/KeyCode.html)

View File

@ -0,0 +1,5 @@
# @motajs/client-base
目录:
- [KeyCode](./KeyCode.md)

View File

@ -0,0 +1,13 @@
# @motajs/client
`@motajs/client` 包含多个模块:
- [ClientBase](../motajs-client-base/)
示例:
```ts
import { ClientBase } from '@motajs/client';
const { ClientBase } = Mota.require('@motajs/client');
```

View File

@ -0,0 +1,212 @@
# Logger
本文档由 `DeepSeek R1` 模型生成并微调。
## 属性说明
| 属性名 | 类型 | 默认值 | 说明 |
| --------- | ------------- | ------ | ---------------------------------------------------------------- |
| `enabled` | `boolean` | `true` | 控制日志输出是否启用。设为 `false` 可临时关闭日志输出。 |
| `level` | `LogLevel` | - | 日志级别,决定输出的最低日志等级(通过构造函数传入,不可修改)。 |
| `info` | `ILoggerInfo` | - | 包含错误和警告信息的配置对象(通过构造函数传入,不可修改)。 |
## 方法说明
### `constructor`
```ts
function constructor(level: LogLevel, info: ILoggerInfo): Logger;
```
#### 描述
构造一个 `Logger` 实例。
#### 参数
- `level`: 日志对象输出等级。
- `info`: 日志内容。
### `error`
```ts
function error(code: number, ...params: string[]): void;
```
#### 描述
记录一个错误信息。
#### 参数
- `code`: 错误代码,对应 `info.error` 中的键值。
- `...params`: 替换错误信息中的占位符(如 $1, $2的参数。
#### 行为
- 如果未找到对应 `code` 的错误信息,会触发 `error(16)` 表示代码未定义。
- 根据日志级别 `level` 决定是否输出到控制台,并在页面右下角显示提示。
### `warn`
```ts
function warn(code: number, ...params: string[]): void;
```
#### 描述
记录一个警告信息。
#### 参数
- `code`: 警告代码,对应 `info.warn` 中的键值。
- `...params`: 替换警告信息中的占位符的参数。
#### 行为
- 如果未找到对应 `code` 的警告信息,会触发 `error(16)`
- 仅在 `level <= LogLevel.WARNING` 时输出。
### `log`
```ts
function log(text: string): void;
```
#### 描述
记录一条普通日志。
#### 参数
`text`: 日志文本内容。 ####行为
- 仅在 `level <= LogLevel.LOG` 时输出到控制台。
### `catch`
```ts
function catch<T>(fn: () => T): LoggerCatchReturns<T>;
```
#### 描述
捕获函数执行期间产生的日志信息,并抑制日志输出。
#### 参数
- `fn`: 需要执行的函数。
#### 返回值
- `ret`: 函数 `fn` 的返回值。
- `info`: 捕获的日志信息数组。
#### 行为
- 执行期间会临时禁用日志输出,执行完成后恢复原有状态。
### `disable`
```ts
function disable(): void;
```
#### 描述
禁用日志输出(设置 `enabled = false`)。
### `enable`
```ts
function enable(): void;
```
#### 描述
启用日志输出(设置 `enabled = true`)。
## 接口说明
### `LoggerCatchInfo`
#### 结构
```ts
interface LoggerCatchInfo {
/** 错误/警告代码(仅 error/warn 方法存在) */
code?: number;
/** 日志等级 */
level: LogLevel;
/** 解析后的完整信息 */
message: string;
}
```
### `LoggerCatchReturns<T>`
#### 结构
```ts
interface LoggerCatchReturns<T> {
/** 被捕获函数的返回值 */
ret: T;
/** 捕获的日志信息列表 */
info: LoggerCatchInfo[];
}
```
## 使用示例
- 初始化 Logger
```ts
import { LogLevel, Logger } from './logger';
const logInfo = {
error: {
404: 'Page $1 not found.',
500: 'Internal server error: $1'
},
warn: {
101: 'Deprecated API: $1'
}
};
const logger = new Logger(LogLevel.WARNING, logInfo);
```
- 记录错误
```ts
logger.error(404, 'home');
// 控制台输出: [ERROR Code 404] Page home not found.
// 页面右下角显示红色提示5 秒后消失)
```
- 记录警告
```ts
logger.warn(101, '/old-api');
// 控制台输出: [WARNING Code 101] Deprecated API: /old-api
// 页面右下角显示金色提示
```
- 捕获日志
```ts
const result = logger.catch(() => {
logger.error(500, 'database timeout');
return { success: false };
});
console.log(result.info[0].message); // "Internal server error: database timeout"
```
- 禁用日志
```ts
logger.disable();
logger.log('This will not be printed'); // 无输出
logger.enable();
```

View File

@ -0,0 +1,24 @@
# @motajs/common 函数
## `sleep`
```ts
function sleep(time: number): Promise<void>;
```
#### 描述
创建一个等待指定时长的异步。
#### 参数
- `time`: 等待时长
#### 使用示例
```ts
async function myFunc() {
await sleep(1000);
// 这后面的内容会在 1 秒之后执行
}
```

View File

@ -0,0 +1,11 @@
# @motajs/common
目录:
- [函数](./functions.md)
---
类目录:
- [Logger](./Logger.md)

View File

@ -0,0 +1,3 @@
# @motajs/legacy-client
目录:

View File

@ -0,0 +1,3 @@
# @motajs/legacy-common
目录:

View File

@ -0,0 +1,3 @@
# @motajs/legacy-system
目录:

View File

@ -0,0 +1,3 @@
# @motajs/legacy-ui
目录:

View File

@ -0,0 +1,3 @@
# @motajs/render-core
目录:

View File

@ -0,0 +1,3 @@
# @motajs/render-elements
目录:

View File

@ -0,0 +1,3 @@
# @motajs/render-style
目录:

View File

@ -0,0 +1,3 @@
# @motajs/render-vue
目录:

View File

@ -0,0 +1,16 @@
# @motajs/render
此模块包含如下模块的内容,可以直接引用:
- [@motajs/render-core](../motajs-render-core/)
- [@motajs/render-elements](../motajs-render-elements/)
- [@motajs/render-style](../motajs-render-style/)
- [@motajs/render-vue](../motajs-render-vue/)
引入示例:
```ts
import { Container } from '@motajs/render';
// 二者等价,不需要单独使用一个量来接收,注意与 @motajs/client 引入方式区分
import { Container } from '@motajs/render-core';
```

View File

@ -0,0 +1,3 @@
# @motajs/system-action
目录:

View File

@ -0,0 +1,3 @@
# @motajs/system-ui
目录:

View File

@ -0,0 +1,3 @@
# @motajs/system
目录:

View File

@ -0,0 +1,3 @@
# @motajs/types
目录:

View File

@ -0,0 +1,3 @@
# @user/client-modules
目录:

View File

@ -0,0 +1,3 @@
# @user/data-base
目录:

View File

@ -0,0 +1,3 @@
# @user/data-fallback
目录:

View File

@ -0,0 +1,3 @@
# @user/data-state
目录:

View File

@ -0,0 +1,3 @@
# @user/data-utils
目录:

View File

@ -0,0 +1,3 @@
# @user/entry-client
目录:

View File

@ -0,0 +1,3 @@
# @user/entry-data
目录:

View File

@ -0,0 +1,3 @@
# @user/legacy-plugin-client
目录:

View File

@ -0,0 +1,3 @@
# @user/legacy-plugin-data
目录:

View File

@ -1,88 +1,88 @@
{
"name": "mota-ts",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "tsx script/dev.ts",
"build": "vue-tsc && vite build && tsx script/build.ts dist",
"build-local": "vue-tsc && vite build && tsx script/build.ts local",
"preview": "vite preview",
"update": "tsx script/update.ts",
"declare": "tsx script/declare.ts",
"type": "vue-tsc --noEmit",
"lines": "tsx script/lines.ts",
"build:packages": "vue-tsx --noEmit && tsx script/build-packages.ts",
"build:game": "vue-tsx --noEmit && tsx script/build-game.ts",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
},
"dependencies": {
"@ant-design/icons-vue": "^6.1.0",
"@vueuse/core": "^10.11.1",
"@wasm-audio-decoders/ogg-vorbis": "^0.1.16",
"anon-tokyo": "0.0.0-alpha.0",
"ant-design-vue": "^3.2.20",
"axios": "^1.8.4",
"chart.js": "^4.4.8",
"codec-parser": "^2.5.0",
"eventemitter3": "^5.0.1",
"gl-matrix": "^3.4.3",
"jszip": "^3.10.1",
"lodash-es": "^4.17.21",
"lz-string": "^1.5.0",
"mutate-animate": "^1.4.2",
"ogg-opus-decoder": "^1.6.14",
"opus-decoder": "^0.7.7",
"vue": "^3.5.13"
},
"devDependencies": {
"@babel/cli": "^7.26.4",
"@babel/core": "^7.26.10",
"@babel/preset-env": "^7.26.9",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.1",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/babel__core": "^7.20.5",
"@types/fontmin": "^0.9.5",
"@types/fs-extra": "^9.0.13",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18.19.80",
"@types/ws": "^8.18.0",
"@vitejs/plugin-legacy": "^6.0.2",
"@vitejs/plugin-vue": "^5.2.3",
"@vitejs/plugin-vue-jsx": "^4.1.2",
"chokidar": "^3.6.0",
"compressing": "^1.10.1",
"eslint": "^9.22.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-vue": "^9.33.0",
"fontmin": "^0.9.9",
"form-data": "^4.0.2",
"fs-extra": "^10.1.0",
"glob": "^11.0.1",
"globals": "^15.15.0",
"less": "^4.2.2",
"madge": "^8.0.0",
"markdown-it-mathjax3": "^4.3.2",
"mermaid": "^11.5.0",
"postcss-preset-env": "^9.6.0",
"rollup": "^3.29.5",
"terser": "^5.39.0",
"tsx": "^4.19.3",
"typescript": "^5.8.2",
"typescript-eslint": "^8.27.0",
"unplugin-vue-components": "^0.22.12",
"vite": "^6.2.2",
"vite-plugin-dts": "^4.5.3",
"vitepress": "^1.6.3",
"vitepress-plugin-mermaid": "^2.0.17",
"vue-tsc": "^2.2.8",
"ws": "^8.18.1"
}
}
"name": "mota-ts",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "tsx script/dev.ts",
"build": "vue-tsc && vite build && tsx script/build.ts dist",
"build-local": "vue-tsc && vite build && tsx script/build.ts local",
"preview": "vite preview",
"update": "tsx script/update.ts",
"declare": "tsx script/declare.ts",
"type": "vue-tsc --noEmit",
"lines": "tsx script/lines.ts packages packages-user",
"build:packages": "vue-tsx --noEmit && tsx script/build-packages.ts",
"build:game": "vue-tsx --noEmit && tsx script/build-game.ts",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
},
"dependencies": {
"@ant-design/icons-vue": "^6.1.0",
"@vueuse/core": "^10.11.1",
"@wasm-audio-decoders/ogg-vorbis": "^0.1.16",
"anon-tokyo": "0.0.0-alpha.0",
"ant-design-vue": "^3.2.20",
"axios": "^1.8.4",
"chart.js": "^4.4.8",
"codec-parser": "^2.5.0",
"eventemitter3": "^5.0.1",
"gl-matrix": "^3.4.3",
"jszip": "^3.10.1",
"lodash-es": "^4.17.21",
"lz-string": "^1.5.0",
"mutate-animate": "^1.4.2",
"ogg-opus-decoder": "^1.6.14",
"opus-decoder": "^0.7.7",
"vue": "^3.5.13"
},
"devDependencies": {
"@babel/cli": "^7.26.4",
"@babel/core": "^7.26.10",
"@babel/preset-env": "^7.26.9",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.1",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/babel__core": "^7.20.5",
"@types/fontmin": "^0.9.5",
"@types/fs-extra": "^9.0.13",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18.19.80",
"@types/ws": "^8.18.0",
"@vitejs/plugin-legacy": "^6.0.2",
"@vitejs/plugin-vue": "^5.2.3",
"@vitejs/plugin-vue-jsx": "^4.1.2",
"chokidar": "^3.6.0",
"compressing": "^1.10.1",
"eslint": "^9.22.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-vue": "^9.33.0",
"fontmin": "^0.9.9",
"form-data": "^4.0.2",
"fs-extra": "^10.1.0",
"glob": "^11.0.1",
"globals": "^15.15.0",
"less": "^4.2.2",
"madge": "^8.0.0",
"markdown-it-mathjax3": "^4.3.2",
"mermaid": "^11.5.0",
"postcss-preset-env": "^9.6.0",
"rollup": "^3.29.5",
"terser": "^5.39.0",
"tsx": "^4.19.3",
"typescript": "^5.8.2",
"typescript-eslint": "^8.27.0",
"unplugin-vue-components": "^0.22.12",
"vite": "^6.2.2",
"vite-plugin-dts": "^4.5.3",
"vitepress": "^1.6.3",
"vitepress-plugin-mermaid": "^2.0.17",
"vue-tsc": "^2.2.8",
"ws": "^8.18.1"
}
}