@tixxin/nuxt-theme-engine 0.0.1

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 TixXin
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 ADDED
@@ -0,0 +1,171 @@
1
+ <div align="center">
2
+
3
+ # @tixxin/nuxt-theme-engine
4
+
5
+ **面向 Nuxt 4 的主题引擎:支持主题继承、运行时分发、类型安全契约与自定义契约入口**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@tixxin/nuxt-theme-engine.svg)](https://npmjs.com/package/@tixxin/nuxt-theme-engine)
8
+ [![Nuxt 4 Compatible](https://img.shields.io/badge/Nuxt-4.x-00C58E.svg)](https://nuxt.com)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
10
+
11
+ </div>
12
+
13
+ ## 这个项目解决什么问题
14
+
15
+ 如果你的站点不只是“换一套颜色”,而是需要在运行时切换:
16
+
17
+ - 不同主题下的布局结构
18
+ - 不同主题下的组件实现
19
+ - 不同主题下的样式体系和主题配置
20
+
21
+ 那么 `@tixxin/nuxt-theme-engine` 的目标就是把这些能力从具体业务里抽离出来,变成一套可复用的 Nuxt 模块。
22
+
23
+ ## 适用场景
24
+
25
+ - 博客、内容站、多主题门户
26
+ - 同一套业务模型,需要支持多套前台主题
27
+ - 需要主题继承、组件 fallback 和按需加载
28
+ - 需要在 IDE 中保留 `<ThemeComponent>` 的类型提示和 Props 校验
29
+
30
+ ## 核心能力
31
+
32
+ - **分层主题**:每个主题都是独立目录,包含 `theme.json`、组件和 CSS,可通过 `extends` 继承父主题
33
+ - **运行时分发**:统一使用 `<ThemeComponent>` 按逻辑组件名渲染当前主题实现
34
+ - **构建时注册**:自动生成主题前缀别名和继承 fallback,减少运行时查找成本
35
+ - **类型安全**:基于契约自动生成类型声明,给 `name` 和 Props 提供补全与校验
36
+ - **自定义契约**:支持通过 `contractsEntry` / `contractsImportId` 接入你自己的契约入口
37
+ - **主题配置隔离**:`useThemeConfig()` 按主题维护独立展示配置
38
+ - **样式治理**:按 `[data-theme="..."]` 作用域管理 CSS 变量,并支持必需变量校验
39
+ - **调试能力**:可接入 Nuxt DevTools 查看主题、继承链和 CSS 变量覆盖情况
40
+
41
+ ## 快速开始
42
+
43
+ ```bash
44
+ pnpm add @tixxin/nuxt-theme-engine
45
+ ```
46
+
47
+ ```ts
48
+ // nuxt.config.ts
49
+ export default defineNuxtConfig({
50
+ modules: ['@tixxin/nuxt-theme-engine'],
51
+ themeEngine: {
52
+ themesDir: './themes',
53
+ defaultTheme: 'base',
54
+ cookieKey: 'site-theme',
55
+ lazyLoadThemes: true,
56
+ requiredCssVars: ['--theme-bg', '--theme-text', '--theme-accent', '--theme-muted']
57
+ }
58
+ })
59
+ ```
60
+
61
+ ```vue
62
+ <template>
63
+ <ThemeComponent name="HomeLayout">
64
+ <template #nav>
65
+ <ThemeComponent name="SidebarNav" :items="navItems" />
66
+ </template>
67
+ <template #default>
68
+ <ThemeComponent name="PostList" :posts="posts" />
69
+ </template>
70
+ <template #aside>
71
+ <ThemeComponent name="SiteStats" :stats="stats" />
72
+ </template>
73
+ </ThemeComponent>
74
+ </template>
75
+ ```
76
+
77
+ ## 自定义契约
78
+
79
+ 引擎本身不强绑定某一套业务契约。
80
+
81
+ 仓库里的 `@tixxin/theme-contracts` 只是**默认博客示例契约**。如果你的项目是电商、文档站、社区或其他业务,可以直接换成自己的契约入口。
82
+
83
+ ### 使用本地契约文件
84
+
85
+ ```ts
86
+ import { fileURLToPath } from 'node:url'
87
+
88
+ const contractsEntry = fileURLToPath(new URL('./theme-contracts/index.ts', import.meta.url))
89
+
90
+ export default defineNuxtConfig({
91
+ alias: {
92
+ '#theme-contracts': contractsEntry
93
+ },
94
+ modules: ['@tixxin/nuxt-theme-engine'],
95
+ themeEngine: {
96
+ contractsEntry: '#theme-contracts',
97
+ contractsImportId: '#theme-contracts'
98
+ }
99
+ })
100
+ ```
101
+
102
+ ### 使用你自己的契约包
103
+
104
+ ```ts
105
+ export default defineNuxtConfig({
106
+ modules: ['@tixxin/nuxt-theme-engine'],
107
+ themeEngine: {
108
+ contractsEntry: '@your-scope/theme-contracts',
109
+ contractsImportId: '@your-scope/theme-contracts'
110
+ }
111
+ })
112
+ ```
113
+
114
+ 你的契约入口至少需要导出:
115
+
116
+ - `ThemeComponentContracts`
117
+ - `themeContractNames`
118
+
119
+ ## 示例主题与 Playground
120
+
121
+ `playground/` 中提供了完整示例,既覆盖默认博客契约,也演示了项目内本地契约入口:
122
+
123
+ | 主题 | 布局 | 说明 |
124
+ |---|---|---|
125
+ | `base` | 单栏 | 基础回退主题 |
126
+ | `aurora` | 单栏 | 继承 `base`,以卡片风格重写列表 |
127
+ | `tix-three-column` | 三栏 | 复刻 tix.xin 风格布局,浏览器无滚动条 |
128
+ | `tix-classic` | 双栏 + 顶部导航 | 继承三栏主题,经典博客布局 |
129
+
130
+ ```bash
131
+ pnpm install
132
+ pnpm dev
133
+ ```
134
+
135
+ ## 文档导航
136
+
137
+ - [用户使用指南](./docs/用户使用指南.md)
138
+ - [架构与目录结构说明](./docs/架构与目录结构说明.md)
139
+ - [设计提案:主题引擎架构](./docs/设计提案-主题引擎架构.md)
140
+ - [NPM 发布指南](./docs/NPM-发布指南.md)
141
+
142
+ ## 开发与发布
143
+
144
+ ```bash
145
+ pnpm dev # 启动 playground
146
+ pnpm dev:prepare # 生成 .nuxt 类型声明
147
+ pnpm typecheck # 类型检查模块与 playground
148
+ pnpm build # 构建契约包和模块
149
+ ```
150
+
151
+ 仓库结构:
152
+
153
+ ```text
154
+ nuxt-theme-engine/
155
+ ├── src/ # 模块源码
156
+ ├── packages/theme-contracts # 默认博客示例契约
157
+ ├── playground/ # 示例应用与主题
158
+ └── docs/ # 面向公开仓库的长期文档
159
+ ```
160
+
161
+ ## 贡献
162
+
163
+ 欢迎通过 Issue 和 Pull Request 参与改进。开始前可先阅读:
164
+
165
+ - [贡献指南](./CONTRIBUTING.md)
166
+ - [架构与目录结构说明](./docs/架构与目录结构说明.md)
167
+
168
+ ## 许可证
169
+
170
+ 本项目采用 [MIT License](./LICENSE)。
171
+ 这是一种宽松开源许可证,允许你在保留原始版权与许可证声明的前提下自由使用、修改、分发,甚至用于商业项目。
@@ -0,0 +1,15 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ interface ThemeEngineOptions {
4
+ themesDir?: string;
5
+ defaultTheme?: string;
6
+ cookieKey?: string;
7
+ lazyLoadThemes?: boolean;
8
+ requiredCssVars?: string[];
9
+ contractsEntry?: string;
10
+ contractsImportId?: string;
11
+ }
12
+
13
+ declare const _default: _nuxt_schema.NuxtModule<ThemeEngineOptions, ThemeEngineOptions, false>;
14
+
15
+ export { _default as default };
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@tixxin/nuxt-theme-engine",
3
+ "configKey": "themeEngine",
4
+ "compatibility": {
5
+ "nuxt": ">=4.0.0"
6
+ },
7
+ "version": "0.0.1",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.2",
10
+ "unbuild": "3.6.1"
11
+ }
12
+ }