@dongmingzhixiu/vuexir-compiler 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 panvu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @vrn/compiler
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue SFC → IR → 原生源码(SwiftUI / Compose)的编译器核心。**纯函数、零 IO**。
4
+
5
+ ```ts
6
+ import { vueToIr, validateIr, generateScreenSource, buildNavHost } from '@vrn/compiler'
7
+
8
+ const { screen, runtime, warnings } = vueToIr(sfcSource, { screenId: 'Home' })
9
+ if (!validateIr(screen).ok) throw new Error('IR 校验失败')
10
+ const swift = generateScreenSource(screen, { runtime: 'Runtime.forPage("Home")' })
11
+ ```
12
+
13
+ | 导出 | 用途 |
14
+ |---|---|
15
+ | `vueToIr` | SFC(含 `<script setup>` / `<style>` / 组件)→ IR + runtime.js |
16
+ | `validateIr` / `parseAndValidateIr` | IR 结构与交叉引用校验(R15:宁编译期报错,不静默降级) |
17
+ | `parseCss` / `mergeIrProps` | CSS 子集 → IR props(含单边边框/内距的按边深合并) |
18
+ | `generateScreenSource` / `generateComponentSource` | IR → SwiftUI 源码 |
19
+ | `emitNode` / `buildNavHost` / `parseRouter` | IR → Compose 源码与导航宿主 |
20
+
21
+ > 形态说明:本包不产出运行时可 `import` 的组件——产物是**原生工程源码**;预览器与 Vite 集成见 `@vrn/vite-plugin`。
@@ -0,0 +1,94 @@
1
+ import type { IrNode } from '../ir/schema.js';
2
+ declare const MANIFEST: (label: string) => string;
3
+ declare const STYLES_XML = "<resources>\n <!-- R-SYSTEMBAR\uFF1A\u56FA\u5B9A\u6DF1\u8272\u4E3B\u9898 \u2192 \u7CFB\u7EDF\u680F\u56FE\u6807\u56FA\u5B9A\u6D45\u8272\uFF08windowLightStatusBar=false\uFF09\uFF0C\u4E0D\u8DDF\u968F\u7CFB\u7EDF\u660E\u6697 -->\n <style name=\"Theme.Vuexir\" parent=\"android:Theme.Material.NoActionBar\">\n <item name=\"android:windowBackground\">#0A0F1E</item>\n <item name=\"android:statusBarColor\">#0A0F1E</item>\n <item name=\"android:navigationBarColor\">#0A0F1E</item>\n <item name=\"android:windowLightStatusBar\">false</item>\n </style>\n</resources>\n";
4
+ declare const MAIN_ACTIVITY: (projectName: string) => string;
5
+ declare const THEME_KT: (bundleId: string) => string;
6
+ declare const RUNTIME_KT: (bundleId: string) => string;
7
+ declare const NAV_TEST_KT: (bundleId: string) => string;
8
+ interface ComposeCtx {
9
+ warnings: string[];
10
+ pageId: string;
11
+ /** R72 异步:本页是否需要协程作用域(async handler / async onMounted)→ 页面 composable 声明 vrnScope */
12
+ needsScope?: boolean;
13
+ /** 常量数组(v-for 数据,首版生成 Kotlin 内联列表) */
14
+ lists?: Record<string, string[]>;
15
+ /** 页面状态(script setup ref → remember mutableStateOf) */
16
+ states?: {
17
+ name: string;
18
+ type: 'string' | 'number' | 'boolean';
19
+ init: string | number | boolean;
20
+ }[];
21
+ /** M3 handler 函数(@click="fn()" 引用;body 已做 .value → stateStore 重写,Kotlin 侧反向内联)
22
+ * R72:async:true → 走协程形状翻译(fetch/setTimeout/await 子集),形状外回退 TODO 注释 + warning */
23
+ handlers?: {
24
+ name: string;
25
+ params: string;
26
+ body: string;
27
+ async?: boolean;
28
+ }[];
29
+ /** v-for 循环上下文(item 字段引用展开) */
30
+ loop?: {
31
+ itemKey: string;
32
+ indexKey?: string;
33
+ };
34
+ /** R72:onMounted 回调体与其 async 标记(生成 LaunchedEffect + 协程) */
35
+ onMountedBody?: string;
36
+ onMountedAsync?: boolean;
37
+ }
38
+ /** 纯字符串拼接生成节点(避免嵌套模板转译问题);v-if(node.condition)在此统一包裹 */
39
+ declare function emitNode(node: IrNode, ctx: ComposeCtx, depth: number, loop?: {
40
+ itemKey: string;
41
+ indexKey?: string;
42
+ }, useParamModifier?: boolean, parentStretch?: boolean): string;
43
+ /** R40 组件表:页面同目录 + 向上逐级查找 components/*.vue(对位 gen-ios loadComponents,支持样例根共享组件)
44
+ * 优先级:页面本地 components/ 覆盖祖先目录同名组件(先收集祖先、最后收集本地) */
45
+ declare function loadComponents(pageFile: string): Record<string, string>;
46
+ /** 组件 → 独立 Composable 文件(对位 iOS 组件独立 Swift 文件) */
47
+ declare function emitComponentFile(name: string, ui: IrNode, bundleId: string): string;
48
+ declare function parseRouter(src: string, dir: string): {
49
+ tabs: {
50
+ id: string;
51
+ title: string;
52
+ file: string;
53
+ icon: string;
54
+ path: string;
55
+ }[];
56
+ details: {
57
+ id: string;
58
+ title: string;
59
+ file: string;
60
+ path: string;
61
+ }[];
62
+ };
63
+ export interface RunTabsOptions {
64
+ /** 产物根(默认 <repo>/compiler/generated/android 或 VRN_OUT_DIR) */
65
+ outDirRoot?: string;
66
+ /** 工程名(默认入口目录名 PascalCase) */
67
+ projectName?: string;
68
+ /** bundle id(默认 com.vrn.<projectname 小写>) */
69
+ bundleId?: string;
70
+ /** P2:工程骨架模板由 @dongmingzhixiu/vuexir-templates 提供、CLI 注入(避免 compiler → templates 的依赖倒挂)
71
+ * 回调式:runTabs 计算完 projectName/bundleId 后再渲染模板,避免调用方拿不到最终值 */
72
+ renderGradle?: (projectName: string, bundleId: string) => string;
73
+ templateVersion?: string;
74
+ }
75
+ declare function runTabs(appDir: string, opts?: RunTabsOptions): string;
76
+ declare function buildNavHost(bundleId: string, tabs: {
77
+ id: string;
78
+ title: string;
79
+ icon: string;
80
+ path: string;
81
+ }[], details: {
82
+ id: string;
83
+ title: string;
84
+ path: string;
85
+ bg?: string;
86
+ backText?: string;
87
+ mode?: string;
88
+ }[]): string;
89
+ /**
90
+ * 输入解析(R-PKG):CLI 通过 VRN_SAMPLES_ROOT 注入样例根(默认 <repo>/examples)。
91
+ * 依次尝试:样例名 → 目录 → 直接路径;都不存在时原样返回由调用方报错。
92
+ */
93
+ declare function resolveInput(arg: string | undefined): string;
94
+ export { runTabs, emitNode, emitComponentFile, loadComponents, parseRouter, buildNavHost, resolveInput, RUNTIME_KT, THEME_KT, NAV_TEST_KT, MAIN_ACTIVITY, MANIFEST, STYLES_XML, };