@proteus-vue/component-ir 0.1.0

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/map.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { BackendId } from '@proteus-vue/render-backend';
2
+ /** 语义类型 → 各端 Backend 控件(布局原语 + UI 原语 + 能力入口——G-31 §3 组件清单)
3
+ * ★G-31 B5:vue-dom 列与 render-backend SEMANTIC_WEB_MAP 实际产出一致(div.proteus-* 语义类)——
4
+ * 参考表即门禁标准,component-conformance 机器校验「快照 control == 参考表」 */
5
+ export declare const SEMANTIC_BACKEND_MAP: Record<string, Partial<Record<BackendId | 'web', string>>>;
6
+ /**
7
+ * 语义 → 指定后端控件(未映射 → null,由后端自定义)
8
+ * ★关键:Backend 映射的是 semantic 字段(layout.grid),不是 tag 字符串(p-grid)——
9
+ * 同一 semantic 在不同后端得到不同原生控件,这就是「语义收敛 + 后端实现」
10
+ */
11
+ export declare function mapSemanticToBackend(semantic: string, backendId: string): string | null;
@@ -0,0 +1,35 @@
1
+ export type PrimitiveKind = 'layout' | 'ui' | 'shell' | 'gesture' | 'capability' | 'engineering';
2
+ /** 状态:implemented = 已在 SEMANTIC_BACKEND_MAP 登记 ≥3 端(G-31.4/G-32.3 门禁适用);planned = 已冻结待实现(L2 生态) */
3
+ export type PrimitiveStatus = 'implemented' | 'planned';
4
+ export interface PrimitiveDef {
5
+ /** 清单编号(L1..L12 / U1..U18 / S1..S10 / G1..G10 / C1..C50 / E1..E28) */
6
+ id: string;
7
+ kind: PrimitiveKind;
8
+ /** 语义标识(<domain>.<kind>——C-IR semantic / 能力属性) */
9
+ semantic: string;
10
+ /** 组件原语标签(p-*;非组件原语缺省) */
11
+ tag?: string;
12
+ /** API/Hook/指令形态(useXxx() / router.push / v-gesture:tap;组件原语缺省) */
13
+ api?: string;
14
+ /** 关键约束属性(G-32.5:属性是约束描述,非 CSS/平台名) */
15
+ props?: string[];
16
+ /** 小程序能力对等(完整性标尺) */
17
+ mpEquiv: string;
18
+ /** L1/L2 层级 */
19
+ tier: 'L1' | 'L2';
20
+ status: PrimitiveStatus;
21
+ }
22
+ /** ★G-32 B1:128 原语冻结清单(唯一事实源) */
23
+ export declare const PRIMITIVE_CATALOG: PrimitiveDef[];
24
+ /** 组件原语(p-* 标签 → C-IR 语义的来源) */
25
+ export declare function componentPrimitives(kinds?: PrimitiveKind[]): PrimitiveDef[];
26
+ /** 已实现状态原语(语义必须在 SEMANTIC_BACKEND_MAP ≥3 端——G-31.4/G-32.3 门禁适用) */
27
+ export declare function implementedPrimitives(): PrimitiveDef[];
28
+ /** 按 id 查原语 */
29
+ export declare function primitiveById(id: string): PrimitiveDef | undefined;
30
+ /** 按语义查原语 */
31
+ export declare function primitiveBySemantic(semantic: string): PrimitiveDef | undefined;
32
+ /** 按 p-* 标签查原语 */
33
+ export declare function primitiveByTag(tag: string): PrimitiveDef | undefined;
34
+ /** 清单自检:128 项 / id 唯一 / semantic 唯一 / 编号连续 */
35
+ export declare function checkPrimitiveCatalog(): string[];
@@ -0,0 +1,62 @@
1
+ export interface ComponentIR {
2
+ /** 组件标签名(如 p-grid)——仅用于源码定位,不参与后端映射 */
3
+ tag: string;
4
+ /** 语义类型(后端映射依据),格式:<domain>.<kind> */
5
+ semantic: string;
6
+ /** 已校验的约束属性(不是平台样式指令) */
7
+ props: Record<string, unknown>;
8
+ children: ComponentIR[];
9
+ /** 引用的原生能力(G-28) */
10
+ capabilities?: Array<{
11
+ name: string;
12
+ [key: string]: unknown;
13
+ }>;
14
+ /** 属性降级声明(G-31.2 / CMP006):每个能力属性须声明 supported/fallback/unsupported */
15
+ degradation?: Record<string, 'supported' | 'fallback' | 'unsupported'>;
16
+ }
17
+ /** 语义枚举(与 plan component-ir.schema.json 一致)——<domain>.<kind> */
18
+ export declare const SEMANTIC_ENUM: readonly ["layout.box", "layout.inline", "layout.stack", "layout.grid", "layout.fluid", "layout.adaptive", "layout.fit", "layout.spacer", "layout.divider", "layout.scroll", "layout.virtual-list", "layout.masonry", "layout.split", "layout.safe", "layout.sidebar", "ui.text", "ui.heading", "ui.rich-text", "ui.icon", "ui.image", "ui.avatar", "ui.media", "ui.canvas", "ui.svg", "ui.input", "ui.textarea", "ui.select", "ui.checkbox", "ui.radio", "ui.switch", "ui.slider", "ui.picker", "ui.form", "ui.button", "ui.list", "ui.nav", "shell.page", "shell.nav", "shell.tabbar", "shell.segment", "shell.drawer", "shell.modal", "shell.popover", "shell.toast", "shell.action-sheet", "gesture.draggable", "gesture.scrollable", "engineering.router-link", "engineering.transition", "engineering.animate", "capability.scan-qr", "capability.pick-photo", "capability.location"];
19
+ /** C-IR JSON Schema(等价于 plan component-ir.schema.json——TS 内嵌供校验/工具消费) */
20
+ export declare const COMPONENT_IR_SCHEMA: {
21
+ readonly $schema: "https://json-schema.org/draft/2020-12/schema";
22
+ readonly $id: "https://proteus.dev/schemas/component-ir.json";
23
+ readonly title: "Proteus Component IR (C-IR)";
24
+ readonly type: "object";
25
+ readonly required: readonly ["tag", "semantic", "props", "children"];
26
+ readonly properties: {
27
+ readonly tag: {
28
+ readonly type: "string";
29
+ readonly pattern: "^p-[a-z0-9-]+$";
30
+ };
31
+ readonly semantic: {
32
+ readonly type: "string";
33
+ readonly enum: readonly ["layout.box", "layout.inline", "layout.stack", "layout.grid", "layout.fluid", "layout.adaptive", "layout.fit", "layout.spacer", "layout.divider", "layout.scroll", "layout.virtual-list", "layout.masonry", "layout.split", "layout.safe", "layout.sidebar", "ui.text", "ui.heading", "ui.rich-text", "ui.icon", "ui.image", "ui.avatar", "ui.media", "ui.canvas", "ui.svg", "ui.input", "ui.textarea", "ui.select", "ui.checkbox", "ui.radio", "ui.switch", "ui.slider", "ui.picker", "ui.form", "ui.button", "ui.list", "ui.nav", "shell.page", "shell.nav", "shell.tabbar", "shell.segment", "shell.drawer", "shell.modal", "shell.popover", "shell.toast", "shell.action-sheet", "gesture.draggable", "gesture.scrollable", "engineering.router-link", "engineering.transition", "engineering.animate", "capability.scan-qr", "capability.pick-photo", "capability.location"];
34
+ };
35
+ readonly props: {
36
+ readonly type: "object";
37
+ readonly additionalProperties: true;
38
+ };
39
+ readonly children: {
40
+ readonly type: "array";
41
+ readonly items: {
42
+ readonly $ref: "#";
43
+ };
44
+ readonly default: readonly [];
45
+ };
46
+ readonly capabilities: {
47
+ readonly type: "array";
48
+ readonly items: {
49
+ readonly type: "object";
50
+ readonly required: readonly ["name"];
51
+ };
52
+ };
53
+ readonly degradation: {
54
+ readonly type: "object";
55
+ readonly additionalProperties: {
56
+ readonly enum: readonly ["supported", "fallback", "unsupported"];
57
+ };
58
+ };
59
+ };
60
+ };
61
+ /** C-IR 组件标签 → 语义类型(组件清单映射——G-32 ①-③ 组件原语 + G-31 L1 布局/UI 原语 + ★B4 现有组件对齐) */
62
+ export declare const TAG_SEMANTIC_MAP: Record<string, string>;
@@ -0,0 +1,13 @@
1
+ import type { ComponentIR } from './schema';
2
+ /**
3
+ * 单标签 → C-IR(未映射标签 → null——兼容层标签不产生 Layer 0 C-IR)
4
+ * - p-* 语义组件:TAG_SEMANTIC_MAP 提供 semantic
5
+ * - 未知 p-* 标签:semantic 缺省 'layout.box'(原子容器兜底)?——不,返回 null(未知语义不臆造)
6
+ */
7
+ export declare function toComponentIR(tag: string, props?: Record<string, unknown>, children?: ComponentIR[]): ComponentIR | null;
8
+ /** 递归转换(子节点非 p- 标签丢弃——兼容层标签在 Layer 0 树中不产生 C-IR 节点) */
9
+ export declare function toComponentTree(tag: string, props?: Record<string, unknown>, children?: Array<{
10
+ tag: string;
11
+ props: Record<string, unknown>;
12
+ children?: unknown[];
13
+ }>): ComponentIR | null;
@@ -0,0 +1,21 @@
1
+ export interface CIRDiagnostic {
2
+ code: string;
3
+ message: string;
4
+ path?: string;
5
+ }
6
+ /** 默认设计稿宽度(grid 冲突校验基准) */
7
+ export declare const DEFAULT_DESIGN_WIDTH = 375;
8
+ /**
9
+ * 校验单个 C-IR 节点(含 children 递归):
10
+ * - CIR_INVALID_TAG:tag 非 p- 前缀(G-31.1 语义命名铁律)
11
+ * - CIR_INVALID_SEMANTIC:semantic 非枚举
12
+ * - CMP006:capabilities 属性缺 degradation 声明(G-31.2)
13
+ */
14
+ export declare function validateComponentIR(ir: unknown): CIRDiagnostic[];
15
+ /**
16
+ * ★grid 属性约束冲突(plan 单测 grid-conflict.spec.ts):min-col-width × max-cols > 设计宽
17
+ * → max-cols 永不达(永远单列)——编译期 warning(验证先于运行,支柱 ③)
18
+ */
19
+ export declare function validateGridConstraints(props: Record<string, unknown>, designWidth?: number): CIRDiagnostic[];
20
+ /** 校验整棵组件树(根 + grid 约束,children 递归) */
21
+ export declare function validateComponentTree(ir: unknown, designWidth?: number): CIRDiagnostic[];
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@proteus-vue/component-ir",
3
+ "version": "0.1.0",
4
+ "description": "G-31 组件与 API 语义化(component-semantics-plan B1):Component IR(C-IR)schema + 属性约束校验 + semantic 映射——组件=语义、属性=约束、Backend 消费 semantic 而非 tag(零依赖纯逻辑)",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.build.json --emitDeclarationOnly && esbuild src/index.ts --bundle --format=esm --platform=neutral --outfile=dist/index.js"
23
+ },
24
+ "devDependencies": {
25
+ "@proteus-vue/render-backend": "0.1.0"
26
+ }
27
+ }