@anov/cic-standard-sdk 0.0.1 → 0.0.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/README.md CHANGED
@@ -30,16 +30,9 @@ CIC-Standard-1.0/
30
30
  └── vite.config.ts # Vite 构建配置
31
31
  ```
32
32
 
33
- ## 1. 协议核心概念
33
+ ## 1. 简介
34
34
 
35
- CIC 协议通过 JSON 描述一个完整的应用页面结构与行为:
36
-
37
- - **Config**: 全局配置根节点,包含页面列表、全局变量、资源依赖等。
38
- - **Page**: 页面定义,包含布局配置、组件树、页面级数据源。
39
- - **Component**: 组件实例,分为 View (视图)、Container (容器)、Logic (逻辑) 三类。
40
- - **Event**: 强大的事件 DSL,支持变量操作、页面跳转、组件控制、自定义脚本等,支持条件执行与调度(Order/Delay)。
41
- - **Variable**: 多级作用域(Global > Page > Component)的变量管理,支持 string/number/object/array/function。
42
- - **DataSource**: 统一的数据源定义(REST, WebSocket, Static),支持轮询与依赖。
35
+ 提供 CIC 标准的 TypeScript 类型与 SDK,支持 JSON Schema 校验、页面/组件/数据源等核心能力,适用于发布后的使用者。
43
36
 
44
37
  ## 2. SDK 使用指南
45
38
 
@@ -50,12 +43,12 @@ SDK 提供了操作 CIC 标准的常用工具方法,现已重构为面向对
50
43
  推荐使用 `pnpm` 安装依赖:
51
44
 
52
45
  ```bash
53
- pnpm install cic-standard-sdk
46
+ pnpm add @anov/cic-standard-sdk
54
47
  ```
55
48
 
56
49
  ```typescript
57
- import { CICSDK } from 'cic-standard-sdk';
58
- import { CICConfig } from 'cic-standard-sdk/types';
50
+ import { CICSDK } from '@anov/cic-standard-sdk'
51
+ import { CICConfig } from '@anov/cic-standard-sdk/types';
59
52
 
60
53
  const config: CICConfig = { ... };
61
54
  const sdk = new CICSDK(config); // 实例化时自动执行 Schema 校验
@@ -63,7 +56,7 @@ const sdk = new CICSDK(config); // 实例化时自动执行 Schema 校验
63
56
 
64
57
  ### 常用 API
65
58
 
66
- **1. 验证配置**(`sdk/CICSDK.ts:174`)
59
+ **1. 验证配置**
67
60
 
68
61
  SDK 集成了完整的 JSON Schema (Draft-07),可验证字段类型、必填项、枚举值等。
69
62
 
@@ -83,7 +76,7 @@ try {
83
76
  }
84
77
  ```
85
78
 
86
- **2. 查找组件**(`sdk/CICSDK.ts:47`、`sdk/CICSDK.ts:62`)
79
+ **2. 查找组件**
87
80
 
88
81
  ```typescript
89
82
  // 按 ID 查找(支持跨页面)
@@ -97,7 +90,7 @@ const page = sdk.findPageByComponent('comp_btn_01')
97
90
  console.log('所在页面:', page?.id)
98
91
  ```
99
92
 
100
- **3. 获取变量值(自动处理作用域)**(`sdk/CICSDK.ts:80`、`sdk/CICSDK.ts:109`)
93
+ **3. 获取变量值(自动处理作用域)**
101
94
 
102
95
  ```typescript
103
96
  // 优先查找组件级 -> 页面级 -> 全局
@@ -107,7 +100,7 @@ const val = sdk.getVariable({ pageId: 'p1', componentId: 'c1' }, 'theme')
107
100
  const val2 = sdk.getVariableByRef('global.theme')
108
101
  ```
109
102
 
110
- **4. 遍历组件树**(`sdk/CICSDK.ts:125`、`sdk/CICSDK.ts:220`)
103
+ **4. 遍历组件树**
111
104
 
112
105
  ```typescript
113
106
  // 遍历整个配置的所有组件
@@ -118,7 +111,7 @@ sdk.walkComponents((comp, page, parent) => {
118
111
  })
119
112
  ```
120
113
 
121
- **5. 静态工具**(`sdk/CICSDK.ts:199`、`sdk/CICSDK.ts:220`)
114
+ **5. 静态工具**
122
115
 
123
116
  ### 生成器 API(严格校验 + 规范化)
124
117
 
@@ -143,30 +136,22 @@ CICSDK.traverseTree(someComponent, c => {
143
136
  })
144
137
  ```
145
138
 
146
- ## 3. 开发与测试
147
-
148
- 本项目使用 Vite 进行构建,Vitest 进行单元测试,推荐使用 `pnpm` 管理依赖。
149
-
150
- ### 命令脚本
151
-
152
- - `pnpm install`: 安装依赖
153
- - `pnpm run dev`: 启动开发模式
154
- - `pnpm run build`: 构建 SDK(输出 `dist/`)
155
- - `pnpm test`: 运行单元测试
139
+ ## 3. 构建与类型
156
140
 
157
141
  ### 构建产物
158
142
 
159
- - `dist/cic-sdk.es.js`: ESM 格式,适用于现代前端项目(Vite/Webpack)。
160
- - `dist/cic-sdk.cjs.js`: CJS 格式,适用于 Node.js `require`。
161
- - `dist/cic-sdk.umd.js`: UMD 格式,适用于 `<script>` 引入。
143
+ - `dist/cic-sdk.es.js`(ESM
144
+ - `dist/cic-sdk.cjs.js`(CJS
145
+ - `dist/cic-sdk.umd.js`(UMD
146
+ - 类型声明:`dist/sdk/CICSDK.d.ts`
162
147
 
163
- `package.json` 中已配置 `exports` 字段与 `sideEffects: false`,支持 Tree‑shaking 与正确的导入解析。
148
+ `package.json` 设置了 `sideEffects: false` 并使用 `exports` 指定导入/require 入口,方便 Tree‑shaking
164
149
 
165
150
  ## 4. JSON Schema 校验
166
151
 
167
152
  `schema/cic.schema.json` 提供了完整的协议约束。
168
153
 
169
- ### VS Code 中启用智能提示
154
+ ### VS Code 智能提示
170
155
 
171
156
  在你的 JSON 配置文件头部添加 `$schema` 字段:
172
157
 
@@ -184,7 +169,7 @@ CICSDK.traverseTree(someComponent, c => {
184
169
  - 枚举值提示(如 `type`: `view` | `container`)
185
170
  - 结构校验(必填字段检查)
186
171
 
187
- ### 常见报错与排查
172
+ ### 报错与排查
188
173
 
189
174
  - Ajv 错误输出包含 `instancePath`:根据路径定位到具体字段(如 `/pages/0/components/1/role must be equal to constant`)。
190
175
  - 组件判别联合:`view` 必须提供 `component`;`container` 必须提供 `children`;`logic` 必须提供 `component`(`LogicRef`)。
@@ -196,34 +181,9 @@ CICSDK.traverseTree(someComponent, c => {
196
181
  - 按需引入:仅从 `CICSDK` 静态导出使用所需生成器函数,减少打包体积。
197
182
  - ID 规范:通过生成器的 `generateId` 自动生成 `uuid`,避免冲突。
198
183
 
199
- ## 5. Schema 与 Mock 脚本
200
-
201
- ### Schema 生成脚本(`scripts/generate-schema.ts`)
202
-
203
- - 通过配置项裁剪复杂度、保留必要字段,输出更简洁可用的 JSON Schema。
204
-
205
- ### Mock 生成与清洗(`scripts/generate-mock.ts`)
206
-
207
- - 基于 Schema 随机生成后,使用 `deepClean` 进行规范化:
208
- - 修正非法数组项、补齐 `id`(uuid)、规范 `url`/`ws` 链接。
209
- - 为 `code` 字段提供可执行的默认实现。
210
-
211
- 示例输出能直接通过 Ajv 校验并用于演示与测试。
212
-
213
- ## 5. 示例说明
214
-
215
- 请查看 `examples/full-demo.json`,它展示了:
216
-
217
- - 如何定义全局主题变量。
218
- - 如何引入外部 ECharts 库与字体资源。
219
- - 如何配置 REST 数据源。
220
- - 如何构建包含图表与按钮的组件树。
221
- - 如何通过点击事件触发变量更新与自定义逻辑。
222
-
223
- ## 安全声明
184
+ ## 5. 许可与版本
224
185
 
225
- CIC 允许执行动态代码(Custom Events, Logic Components)。在生产环境中渲染不可信的 CIC 配置时,请务必:
186
+ - 语义化版本(SemVer)发布
187
+ - 请在 issue 中反馈使用问题与建议
226
188
 
227
- 1. 使用 iframe 或 Web Worker 隔离渲染环境。
228
- 2. 限制代码执行的上下文访问权限。
229
- 3. 对 `CustomRemoteEvent` 加载的外部脚本进行域名白名单控制。
189
+ (本 README 为发布版自述,专注使用信息;开发演示与内部脚本说明已省略。)
@@ -0,0 +1,71 @@
1
+ import { CICConfig } from '../types';
2
+ import { ComponentInstance } from '../types/componets';
3
+ import { ICICSDK } from './ICICSDK';
4
+ import { CICPage } from '../types/page';
5
+ /**
6
+ * CIC SDK 类
7
+ * 提供对 CIC 配置的封装访问与操作
8
+ */
9
+ export declare class CICSDK implements ICICSDK {
10
+ private config;
11
+ private static validator;
12
+ private static validate;
13
+ private static schemaHash;
14
+ constructor(config: CICConfig);
15
+ getConfig(): CICConfig;
16
+ findComponent(id: string): ComponentInstance | undefined;
17
+ findPageByComponent(componentId: string): CICPage | undefined;
18
+ getVariable(scopeContext: {
19
+ pageId?: string;
20
+ componentId?: string;
21
+ }, key: string): any;
22
+ getVariableByRef(ref: string): any;
23
+ walkComponents(callback: (component: ComponentInstance, page: CICPage, parent?: ComponentInstance) => void | boolean): void;
24
+ /**
25
+ * 全面配置校验 (基于 JSON Schema)
26
+ */
27
+ static validateConfig(config: CICConfig): {
28
+ valid: boolean;
29
+ error?: string;
30
+ };
31
+ /**
32
+ * 按路径获取对象值(支持 a.b[0].c 语法)
33
+ */
34
+ static getValueByPath(obj: any, path: string, fallback?: any): any;
35
+ /**
36
+ * 深度遍历组件树(纯函数递归版本)
37
+ * 用于单独处理某个组件树片段
38
+ */
39
+ static traverseTree(root: ComponentInstance | ComponentInstance[], callback: (component: ComponentInstance, parent?: ComponentInstance) => void | boolean, parent?: ComponentInstance): void;
40
+ /** 创建 DataSource */
41
+ static createDataSource: (input: unknown, options?: import("./generators/common").CreateOptions) => import("./generators/common").Result<import("../types/dataSources").DataSourceItem>;
42
+ static validateDataSource: (input: unknown) => import("./generators/common").Result<null>;
43
+ static normalizeDataSource: (input: unknown, options?: import("./generators/common").CreateOptions) => import("../types/dataSources").DataSourceItem;
44
+ /** 创建 Component */
45
+ static createComponent: (input: unknown, options?: import("./generators/common").CreateOptions) => import("./generators/common").Result<ComponentInstance>;
46
+ static validateComponent: (input: unknown) => import("./generators/common").Result<null>;
47
+ static normalizeComponent: (input: unknown, options?: import("./generators/common").CreateOptions) => ComponentInstance;
48
+ /** 创建 Page */
49
+ static createPage: (input: unknown, options?: import("./generators/common").CreateOptions) => import("./generators/common").Result<CICPage>;
50
+ static validatePage: (input: unknown) => import("./generators/common").Result<null>;
51
+ static normalizePage: (input: unknown, options?: import("./generators/common").CreateOptions) => CICPage;
52
+ /** 创建 Meta/Layout */
53
+ static createMeta: (input: unknown) => import("./generators/common").Result<import("../types/meta").MetaInfo>;
54
+ static createLayout: (input: unknown) => import("./generators/common").Result<import("../types/meta").LayoutConfig>;
55
+ static validateMeta: (input: unknown) => import("./generators/common").Result<null>;
56
+ static validateLayout: (input: unknown) => import("./generators/common").Result<null>;
57
+ static normalizeMeta: (input: unknown) => import("../types/meta").MetaInfo;
58
+ static normalizeLayout: (input: unknown) => import("../types/meta").LayoutConfig;
59
+ /** 创建 Variables */
60
+ static createVariables: (input: unknown) => import("./generators/common").Result<import("../types/variables").Variables>;
61
+ static validateVariables: (input: unknown) => import("./generators/common").Result<null>;
62
+ static normalizeVariables: (input: unknown) => import("../types/variables").Variables;
63
+ /** 创建 Dependency */
64
+ static createDependency: (input: unknown) => import("./generators/common").Result<import("../types/deps").Dependency>;
65
+ static validateDependency: (input: unknown) => import("./generators/common").Result<null>;
66
+ static normalizeDependency: (input: unknown) => import("../types/deps").Dependency;
67
+ /** 创建 Registry 组件项 */
68
+ static createRegistryComponent: (input: unknown) => import("./generators/common").Result<import("../types/registry").RegistryComponents>;
69
+ static validateRegistryComponent: (input: unknown) => import("./generators/common").Result<null>;
70
+ static normalizeRegistryComponent: (input: unknown) => import("../types/registry").RegistryComponents;
71
+ }
@@ -0,0 +1,43 @@
1
+ import { CICConfig } from '../types';
2
+ import { CICPage } from '../types/page';
3
+ import { ComponentInstance } from '../types/componets';
4
+ /**
5
+ * CIC SDK 接口定义
6
+ * 定义了 SDK 必须提供的核心能力,实现与定义解耦。
7
+ */
8
+ export interface ICICSDK {
9
+ /**
10
+ * 获取当前完整的配置对象
11
+ */
12
+ getConfig(): CICConfig;
13
+ /**
14
+ * 按 ID 查找组件实例
15
+ * @param id 组件 ID
16
+ */
17
+ findComponent(id: string): ComponentInstance | undefined;
18
+ /**
19
+ * 查找组件所属的页面
20
+ * @param componentId 组件 ID
21
+ */
22
+ findPageByComponent(componentId: string): CICPage | undefined;
23
+ /**
24
+ * 获取变量值
25
+ * 遵循作用域链:Component -> Page -> Global
26
+ * @param scopeContext 作用域上下文 { pageId?, componentId? }
27
+ * @param key 变量名
28
+ */
29
+ getVariable(scopeContext: {
30
+ pageId?: string;
31
+ componentId?: string;
32
+ }, key: string): any;
33
+ /**
34
+ * 通过引用字符串获取变量
35
+ * @param ref 引用字符串 (e.g. "global.theme", "page:p1.title")
36
+ */
37
+ getVariableByRef(ref: string): any;
38
+ /**
39
+ * 遍历所有组件
40
+ * @param callback 回调函数,返回 false 可终止遍历
41
+ */
42
+ walkComponents(callback: (component: ComponentInstance, page: CICPage, parent?: ComponentInstance) => void | boolean): void;
43
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Ajv 单例与子 Schema 校验器
3
+ * 说明:复用项目主 Schema(Draft-07),按需编译子定义(#/definitions/...)。
4
+ * 注意:strict 关闭以兼容联合与 const/enum 的复杂组合。
5
+ */
6
+ import Ajv from 'ajv';
7
+ export declare const getAjv: () => Ajv;
8
+ export declare const getValidator: (ref: string) => any;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 生成器通用工具与类型
3
+ * 说明:统一 Result/Options 定义与常用规范化工具(uuid/url/数组/数值)。
4
+ * 原则:严格模式默认不做隐式容错;仅在 defaults 显式提供时才补齐默认值。
5
+ */
6
+ export type Result<T> = {
7
+ ok: boolean;
8
+ value?: T;
9
+ errors?: any[];
10
+ };
11
+ export type CreateOptions = {
12
+ defaults?: Record<string, any>;
13
+ generateId?: boolean;
14
+ strict?: boolean;
15
+ throw?: boolean;
16
+ };
17
+ /** 将值规范为数组 */
18
+ export declare const ensureArray: <T>(v: any) => T[];
19
+ /** 判断为有限正数 */
20
+ export declare const isPositive: (n: any) => boolean;
21
+ /** 生成 uuid(浏览器环境降级) */
22
+ export declare const uuid: () => any;
23
+ /** 规范 http(s) 链接 */
24
+ export declare const httpUrl: (s: any, fallback?: string) => string;
25
+ /** 规范 ws(s) 链接 */
26
+ export declare const wsUrl: (s: any, fallback?: string) => string;
@@ -0,0 +1,5 @@
1
+ import { Result, CreateOptions } from './common';
2
+ import { ComponentInstance } from '../../types/componets';
3
+ export declare const validateComponent: (input: unknown) => Result<null>;
4
+ export declare const createComponent: (input: unknown, options?: CreateOptions) => Result<ComponentInstance>;
5
+ export declare const normalizeComponent: (input: unknown, options?: CreateOptions) => ComponentInstance;
@@ -0,0 +1,5 @@
1
+ import { Result, CreateOptions } from './common';
2
+ import { DataSourceItem } from '../../types/dataSources';
3
+ export declare const validateDataSource: (input: unknown) => Result<null>;
4
+ export declare const createDataSource: (input: unknown, options?: CreateOptions) => Result<DataSourceItem>;
5
+ export declare const normalizeDataSource: (input: unknown, options?: CreateOptions) => DataSourceItem;
@@ -0,0 +1,5 @@
1
+ import { Result } from './common';
2
+ import { Dependency } from '../../types/deps';
3
+ export declare const validateDependency: (input: unknown) => Result<null>;
4
+ export declare const createDependency: (input: unknown) => Result<Dependency>;
5
+ export declare const normalizeDependency: (input: unknown) => Dependency;
@@ -0,0 +1,8 @@
1
+ import { Result } from './common';
2
+ import { MetaInfo, LayoutConfig } from '../../types/meta';
3
+ export declare const validateMeta: (input: unknown) => Result<null>;
4
+ export declare const validateLayout: (input: unknown) => Result<null>;
5
+ export declare const createMeta: (input: unknown) => Result<MetaInfo>;
6
+ export declare const createLayout: (input: unknown) => Result<LayoutConfig>;
7
+ export declare const normalizeMeta: (input: unknown) => MetaInfo;
8
+ export declare const normalizeLayout: (input: unknown) => LayoutConfig;
@@ -0,0 +1,5 @@
1
+ import { Result, CreateOptions } from './common';
2
+ import { CICPage } from '../../types/page';
3
+ export declare const validatePage: (input: unknown) => Result<null>;
4
+ export declare const createPage: (input: unknown, options?: CreateOptions) => Result<CICPage>;
5
+ export declare const normalizePage: (input: unknown, options?: CreateOptions) => CICPage;
@@ -0,0 +1,5 @@
1
+ import { Result } from './common';
2
+ import { RegistryComponents } from '../../types/registry';
3
+ export declare const validateRegistryComponent: (input: unknown) => Result<null>;
4
+ export declare const createRegistryComponent: (input: unknown) => Result<RegistryComponents>;
5
+ export declare const normalizeRegistryComponent: (input: unknown) => RegistryComponents;
@@ -0,0 +1,5 @@
1
+ import { Result } from './common';
2
+ import { Variables } from '../../types/variables';
3
+ export declare const validateVariables: (input: unknown) => Result<null>;
4
+ export declare const createVariables: (input: unknown) => Result<Variables>;
5
+ export declare const normalizeVariables: (input: unknown) => Variables;
@@ -0,0 +1,48 @@
1
+ import { CICEventMap } from './events';
2
+ import { Data } from './data';
3
+ /** 通用表达式(用于条件、模板等) */
4
+ export type Expr = string;
5
+ /** 样式值可以是静态或表达式 */
6
+ export type StyleValue = string | number | Expr;
7
+ /** component 引用:字符串或 object 描述 */
8
+ export type ComponentRef = string | {
9
+ type: "id";
10
+ value: string;
11
+ };
12
+ export type LogicRef = string | {
13
+ type: "url" | "code";
14
+ value: string;
15
+ };
16
+ /**
17
+ * 组件的语义分类(view/container/logic)
18
+ * - view: 可视化渲染组件
19
+ * - container: 容器,包含 children
20
+ * - logic: 逻辑/脚本组件
21
+ */
22
+ export type ComponentType = 'view' | 'container' | 'logic';
23
+ /** 组件实例 */
24
+ export interface ComponentBase {
25
+ id: string;
26
+ props?: Record<string, any>;
27
+ style?: Record<string, StyleValue>;
28
+ events?: CICEventMap;
29
+ data?: Data;
30
+ deps?: string[];
31
+ extensions?: Record<string, any>;
32
+ }
33
+ export interface ViewComponentInstance extends ComponentBase {
34
+ role: 'view';
35
+ component: ComponentRef;
36
+ children?: never;
37
+ }
38
+ export interface ContainerComponentInstance extends ComponentBase {
39
+ role: 'container';
40
+ children: ComponentInstance[];
41
+ component?: never;
42
+ }
43
+ export interface LogicComponentInstanceRef extends ComponentBase {
44
+ role: 'logic';
45
+ component: LogicRef;
46
+ children?: never;
47
+ }
48
+ export type ComponentInstance = ViewComponentInstance | ContainerComponentInstance | LogicComponentInstanceRef;
@@ -0,0 +1,35 @@
1
+ /** 字段映射配置 */
2
+ export interface IMapping {
3
+ use: boolean;
4
+ mapFields: Array<{
5
+ /** 源字段名 */
6
+ field: string;
7
+ /** 目标字段名 */
8
+ mapField: string;
9
+ /** 映射值或公式 */
10
+ value?: any;
11
+ /** 映射类型:默认(普通映射)、copy(复制) const(常量)、formula(公式) */
12
+ type?: 'copy' | 'const' | 'formula';
13
+ /** 描述 */
14
+ description?: string;
15
+ }>;
16
+ }
17
+ /** 转换规则配置 */
18
+ export interface IConverse {
19
+ use: boolean;
20
+ data: Array<{
21
+ /** 转换代码 */
22
+ code: string;
23
+ /** 依赖变量列表(用于响应式重执行) */
24
+ depeedVars?: Array<string>;
25
+ }>;
26
+ }
27
+ /** 数据配置 */
28
+ export interface Data {
29
+ /** 数据ID */
30
+ id: string;
31
+ /** 字段映射配置 */
32
+ mapping?: IMapping;
33
+ /** 转换规则配置 */
34
+ converse?: IConverse;
35
+ }
@@ -0,0 +1,37 @@
1
+ export type Milliseconds = number;
2
+ export interface DataSourceBase {
3
+ id: string;
4
+ type: string;
5
+ order?: number;
6
+ pollInterval?: Milliseconds;
7
+ transform?: string | ((res: any) => any);
8
+ }
9
+ export interface DataSourceRest extends DataSourceBase {
10
+ type: "rest";
11
+ url: string;
12
+ method: "GET" | "POST" | "PUT" | "DELETE";
13
+ headers?: Record<string, string>;
14
+ params?: Record<string, any>;
15
+ body?: any;
16
+ timeout?: Milliseconds;
17
+ }
18
+ export interface DataSourceWebSocket extends DataSourceBase {
19
+ type: "websocket";
20
+ url: string;
21
+ protocols?: string | string[];
22
+ subscribeMessage?: any;
23
+ heartbeat?: {
24
+ interval: Milliseconds;
25
+ message: any;
26
+ };
27
+ }
28
+ export interface DataSourceStatic extends DataSourceBase {
29
+ type: "static";
30
+ value: any;
31
+ }
32
+ export interface DataSourceFunction extends DataSourceBase {
33
+ type: "function";
34
+ code: string;
35
+ timeout?: Milliseconds;
36
+ }
37
+ export type DataSourceItem = DataSourceRest | DataSourceWebSocket | DataSourceStatic | DataSourceFunction;
@@ -0,0 +1,73 @@
1
+ /** 资源类型 */
2
+ export type ResourceType = 'js' | 'css' | 'font' | 'image' | 'json' | 'wasm' | 'other';
3
+ /** JS 格式 */
4
+ export type JSFormat = 'esm' | 'umd' | 'iife' | 'cjs';
5
+ /**
6
+ * 公共字段
7
+ */
8
+ export interface BaseDependency {
9
+ /** 全局唯一 ID,用于运行时索引 */
10
+ id: string;
11
+ /** 可选:人类可读名称(展示用) */
12
+ name?: string;
13
+ /** 版本号(语义化版本 / 字体权重皆可) */
14
+ version?: string;
15
+ /** 资源 URL,可以是绝对地址或相对地址 */
16
+ url?: string;
17
+ /** 本地路径(构建后使用) */
18
+ localPath?: string;
19
+ /** 分组:方便批量加载 */
20
+ group?: string;
21
+ /** 加载策略 */
22
+ strategy?: {
23
+ /** 预加载/预取 */
24
+ preload?: boolean | 'module' | 'style';
25
+ prefetch?: boolean;
26
+ /** 是否异步加载 */
27
+ async?: boolean;
28
+ /** 仅在某些条件下加载(如主题) */
29
+ when?: string;
30
+ };
31
+ }
32
+ /** JS 资源 */
33
+ export interface JSDependency extends BaseDependency {
34
+ type: 'js';
35
+ format: JSFormat;
36
+ crossOrigin?: 'anonymous' | 'use-credentials';
37
+ module?: boolean;
38
+ }
39
+ /** CSS */
40
+ export interface CSSDependency extends BaseDependency {
41
+ type: 'css';
42
+ media?: string;
43
+ }
44
+ /** 字体 */
45
+ export interface FontDependency extends BaseDependency {
46
+ type: 'font';
47
+ family?: string;
48
+ weight?: number | string;
49
+ style?: 'normal' | 'italic';
50
+ }
51
+ /** 图片 */
52
+ export interface ImageDependency extends BaseDependency {
53
+ type: 'image';
54
+ mime?: string;
55
+ }
56
+ /** JSON */
57
+ export interface JSONDependency extends BaseDependency {
58
+ type: 'json';
59
+ }
60
+ /** WASM */
61
+ export interface WasmDependency extends BaseDependency {
62
+ type: 'wasm';
63
+ init?: 'async' | 'sync';
64
+ }
65
+ /** 其他 */
66
+ export interface OtherDependency extends BaseDependency {
67
+ type: 'other';
68
+ kind?: string;
69
+ }
70
+ /** 判别联合 */
71
+ export type Dependency = JSDependency | CSSDependency | FontDependency | ImageDependency | JSONDependency | WasmDependency | OtherDependency;
72
+ /** 依赖数组 */
73
+ export type Dependencies = Dependency[];
@@ -0,0 +1,133 @@
1
+ /** 所有事件大类 */
2
+ export type EventType = 'vars' | 'navigate' | 'comp' | 'toggle' | 'camera' | 'material' | 'custom' | string;
3
+ /** 变量事件动作 */
4
+ export type VarsAction = 'add' | 'update' | 'delete';
5
+ /** 跳转事件动作 */
6
+ export type NavigateAction = 'internal' | 'external';
7
+ /** 组件事件动作 */
8
+ export type CompAction = 'add' | 'update' | 'delete';
9
+ /** 切换事件动作 */
10
+ export type ToggleAction = 'visibility';
11
+ /** 相机动作 */
12
+ export type CameraAction = 'focus';
13
+ /** 材质动作 */
14
+ export type MaterialAction = 'change';
15
+ /** 自定义动作 */
16
+ export type CustomAction = 'local' | 'remote';
17
+ export interface VarsParams {
18
+ key: string;
19
+ value: any;
20
+ exclude?: string[];
21
+ }
22
+ export interface NavigateInternalParams {
23
+ name: string;
24
+ params?: Record<string, any>;
25
+ }
26
+ export interface NavigateExternalParams {
27
+ url: string;
28
+ openNewTab?: boolean;
29
+ }
30
+ export interface CompParams {
31
+ comps: string[];
32
+ props?: Record<string, any>;
33
+ }
34
+ export interface ToggleParams {
35
+ show?: string[];
36
+ hide?: string[];
37
+ }
38
+ export interface CameraFocusParams {
39
+ target: string | number;
40
+ duration?: number;
41
+ }
42
+ export interface MaterialChangeParams {
43
+ target: string;
44
+ materials: string;
45
+ }
46
+ export interface CustomLocalParams {
47
+ code: string;
48
+ depends?: string[];
49
+ }
50
+ export interface CustomRemoteParams {
51
+ url: string;
52
+ depends?: string[];
53
+ }
54
+ export type ConditionOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not-in' | 'exists' | 'not-exists';
55
+ export interface KeyCondition {
56
+ key: string;
57
+ op?: ConditionOperator;
58
+ value?: any;
59
+ }
60
+ /** 表达式条件:支持如 "ctx.id === 5 && ctx.level > 1" */
61
+ export interface ExpressionCondition {
62
+ expression: string;
63
+ }
64
+ /** 多条件(AND) + 表达式 */
65
+ export type EventCondition = KeyCondition | KeyCondition[] | ExpressionCondition;
66
+ /** 不同事件类型对应不同结构 */
67
+ /** 变量事件 */
68
+ export interface VarsEvent {
69
+ type: 'vars';
70
+ action: VarsAction;
71
+ params: VarsParams;
72
+ }
73
+ /** 内部跳转事件 */
74
+ export interface NavigateInternalEvent {
75
+ type: 'navigate';
76
+ action: 'internal';
77
+ params: NavigateInternalParams;
78
+ }
79
+ /** 外部跳转事件 */
80
+ export interface NavigateExternalEvent {
81
+ type: 'navigate';
82
+ action: 'external';
83
+ params: NavigateExternalParams;
84
+ }
85
+ /** 组件事件 */
86
+ export interface CompEvent {
87
+ type: 'comp';
88
+ action: CompAction;
89
+ params: CompParams;
90
+ }
91
+ /** 显示隐藏切换事件 */
92
+ export interface ToggleEvent {
93
+ type: 'toggle';
94
+ action: 'visibility';
95
+ params: ToggleParams;
96
+ }
97
+ /** 相机事件 */
98
+ export interface CameraEvent {
99
+ type: 'camera';
100
+ action: 'focus';
101
+ params: CameraFocusParams;
102
+ }
103
+ /** 材质事件 */
104
+ export interface MaterialEvent {
105
+ type: 'material';
106
+ action: 'change';
107
+ params: MaterialChangeParams;
108
+ }
109
+ /** 自定义本地事件 */
110
+ export interface CustomLocalEvent {
111
+ type: 'custom';
112
+ action: 'local';
113
+ params: CustomLocalParams;
114
+ }
115
+ /** 自定义远程事件 */
116
+ export interface CustomRemoteEvent {
117
+ type: 'custom';
118
+ action: 'remote';
119
+ params: CustomRemoteParams;
120
+ }
121
+ /** 最终事件联合类型 */
122
+ export type CICEvent = VarsEvent | NavigateInternalEvent | NavigateExternalEvent | CompEvent | ToggleEvent | CameraEvent | MaterialEvent | CustomLocalEvent | CustomRemoteEvent;
123
+ /** 带调度信息 */
124
+ export type CICEventWithMeta = CICEvent & {
125
+ order: number;
126
+ delay?: number;
127
+ condition?: EventCondition;
128
+ };
129
+ /** 某组件的所有事件
130
+ * 说明:定义了 CIC 项目中组件的所有事件,包含事件类型、动作、参数、调度顺序、延迟时间和条件。
131
+ * (key: 事件名, value: 处理逻辑数组)
132
+ */
133
+ export type CICEventMap = Record<string, CICEventWithMeta[]>;
@@ -0,0 +1,18 @@
1
+ import { MetaInfo } from './meta';
2
+ import { Registry } from './registry';
3
+ import { Variables } from './variables';
4
+ import { Dependencies } from './deps';
5
+ import { CICPage } from './page';
6
+ /**
7
+ * CIC 配置定义
8
+ * 说明:定义了 CIC 项目的全局配置,包含版本、元数据、页面、组件、变量、依赖等。
9
+ */
10
+ export interface CICConfig {
11
+ version: string;
12
+ meta: MetaInfo;
13
+ pages: CICPage[];
14
+ registry?: Registry;
15
+ variables?: Variables;
16
+ deps?: Dependencies;
17
+ extensions?: Record<string, any>;
18
+ }
@@ -0,0 +1,53 @@
1
+ export interface LayoutConfig {
2
+ /** 布局类型: free(自由布局) 或 grid(网格布局) */
3
+ type: "free" | "grid";
4
+ config: {
5
+ /**
6
+ * 设计稿宽度
7
+ * @minimum 1
8
+ * @default 1920
9
+ */
10
+ width: number;
11
+ /**
12
+ * 设计稿高度
13
+ * @minimum 1
14
+ * @default 1080
15
+ */
16
+ height: number;
17
+ /**
18
+ * 缩放模式
19
+ * @default "aspectFit"
20
+ */
21
+ scaleMode: "aspectFit" | "fill";
22
+ };
23
+ }
24
+ /**
25
+ * 项目元信息
26
+ * 包含项目的基本信息、布局配置、语言、创建时间、更新时间、作者和扩展信息。
27
+ */
28
+ export interface MetaInfo {
29
+ /** 项目唯一标识符 */
30
+ projectId?: string;
31
+ /** 项目名称 */
32
+ projectName?: string;
33
+ /** 项目描述 */
34
+ description?: string;
35
+ /** 布局配置 */
36
+ layout?: LayoutConfig;
37
+ /** 语言代码 (e.g. zh-CN, en-US) */
38
+ language?: string;
39
+ /**
40
+ * 创建时间 (ISO 8601)
41
+ * @format date-time
42
+ */
43
+ createTime?: string;
44
+ /**
45
+ * 更新时间 (ISO 8601)
46
+ * @format date-time
47
+ */
48
+ updateTime?: string;
49
+ /** 作者 */
50
+ author?: string;
51
+ /** 扩展字段 */
52
+ extensions?: Record<string, any>;
53
+ }
@@ -0,0 +1,16 @@
1
+ import { ComponentInstance } from './componets';
2
+ import { DataSourceItem } from './dataSources';
3
+ import { LayoutConfig } from './meta';
4
+ /**
5
+ * CIC 页面定义
6
+ * 说明:定义了 CIC 中页面的结构,包含页面 ID、名称、路径、布局、组件等。
7
+ */
8
+ export interface CICPage {
9
+ id: string;
10
+ name: string;
11
+ path: string;
12
+ layout?: LayoutConfig;
13
+ components?: ComponentInstance[];
14
+ dataSources?: DataSourceItem[];
15
+ extensions?: Record<string, any>;
16
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * 注册中心组件项
3
+ * 说明:定义了 CIC 项目中组件注册中心的组件项,包含组件 ID、类型和配置。
4
+ * @example
5
+ * {
6
+ * "id": "comp_echarts_line",
7
+ * "name": "折线图",
8
+ * "description": "用于展示时间序列数据的折线图组件",
9
+ * "version": "1.0.0",
10
+ * "author": "component_dev",
11
+ * "defaultProps": {
12
+ * "title": {
13
+ * "type": "string",
14
+ * "default": "折线图标题",
15
+ * "description": "图表的标题"
16
+ * },
17
+ * "xAxis": {
18
+ * "type": "array",
19
+ * "default": [],
20
+ * "description": "X轴数据"
21
+ * },
22
+ * "yAxis": {
23
+ * "type": "array",
24
+ * "default": [],
25
+ * "description": "Y轴数据"
26
+ * },
27
+ * "lineColor": {
28
+ * "type": "string",
29
+ * "default": "#5470C6",
30
+ * "description": "折线颜色"
31
+ * }
32
+ * },
33
+ * "data": {
34
+ * "x": 123,
35
+ * "y": 456
36
+ * },
37
+ * "deps": ["1", "2"]
38
+ * }
39
+ */
40
+ export interface RegistryComponents {
41
+ id: string;
42
+ name?: string;
43
+ description?: string;
44
+ version?: string;
45
+ author?: string;
46
+ defaultProps?: Record<string, any>;
47
+ data?: any;
48
+ deps?: string[];
49
+ }
50
+ /**
51
+ * 注册表
52
+ */
53
+ export interface Registry {
54
+ components?: RegistryComponents[];
55
+ /**插件后期可扩展 */
56
+ plugins?: Record<string, any>;
57
+ }
@@ -0,0 +1,58 @@
1
+ /** 变量类型枚举,限定变量的基础类型:字符串、数字、布尔、数组、对象和函数。 */
2
+ export type VariableType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'function';
3
+ /** 字符串变量,包含当前值与默认值,可选描述。 */
4
+ export interface StringVariable {
5
+ type: 'string';
6
+ value: string;
7
+ default: string;
8
+ description?: string;
9
+ }
10
+ /** 数字变量,包含当前值与默认值,可选描述。 */
11
+ export interface NumberVariable {
12
+ type: 'number';
13
+ value: number;
14
+ default: number;
15
+ description?: string;
16
+ }
17
+ /** 布尔变量,包含当前值与默认值,可选描述。 */
18
+ export interface BooleanVariable {
19
+ type: 'boolean';
20
+ value: boolean;
21
+ default: boolean;
22
+ description?: string;
23
+ }
24
+ /** 数组变量,元素类型不做限制,包含当前值与默认值,可选描述。 */
25
+ export interface ArrayVariable {
26
+ type: 'array';
27
+ value: unknown[];
28
+ default: unknown[];
29
+ description?: string;
30
+ }
31
+ /** 函数变量,以字符串保存函数实现;支持 `args` 指定入参名列表。 */
32
+ export interface FunctionVariable {
33
+ type: 'function';
34
+ value: string;
35
+ default: string;
36
+ description?: string;
37
+ args?: string[];
38
+ }
39
+ /** 对象变量,键到变量的映射;支持递归嵌套。 */
40
+ export interface ObjectVariable {
41
+ type: 'object';
42
+ value: Record<string, Variable>;
43
+ default: Record<string, Variable>;
44
+ description?: string;
45
+ }
46
+ /** 变量联合类型,涵盖五类变量定义。 */
47
+ export type Variable = StringVariable | NumberVariable | BooleanVariable | ArrayVariable | FunctionVariable | ObjectVariable;
48
+ /** 变量映射,键为变量名,值为变量定义。 */
49
+ export type VariablesMap = Record<string, Variable>;
50
+ /** 变量集合,按作用域组织:global/page/component。 */
51
+ export interface Variables {
52
+ /** 全局变量,对所有页面和组件均生效。 */
53
+ global: VariablesMap;
54
+ /** 页面级变量,键为页面 ID,值为该页面的变量映射。 */
55
+ page: Record<string, VariablesMap>;
56
+ /** 组件级变量,键为组件 ID,值为该组件的变量映射。 */
57
+ component: Record<string, VariablesMap>;
58
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@anov/cic-standard-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "CIC Standard SDK with TypeScript support",
5
5
  "main": "dist/cic-sdk.cjs.js",
6
6
  "module": "dist/cic-sdk.es.js",
7
- "types": "dist/index.d.ts",
7
+ "types": "dist/sdk/CICSDK.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./dist/cic-sdk.es.js",
@@ -20,7 +20,8 @@
20
20
  "sideEffects": false,
21
21
  "scripts": {
22
22
  "dev": "vite",
23
- "build": "vite build",
23
+ "build": "vite build && npm run build:types",
24
+ "build:types": "tsc -p tsconfig.json",
24
25
  "test": "vitest",
25
26
  "test:coverage": "vitest run --coverage",
26
27
  "gen:schema": "tsx scripts/generate-schema.ts",