lcap-frontend-library 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.
Files changed (84) hide show
  1. package/README.md +271 -0
  2. package/bin/lcap-frontend-library.mjs +3 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +27 -0
  5. package/dist/init.d.ts +6 -0
  6. package/dist/init.js +79 -0
  7. package/dist/sync.d.ts +4 -0
  8. package/dist/sync.js +70 -0
  9. package/dist/utils.d.ts +19 -0
  10. package/dist/utils.js +101 -0
  11. package/package.json +34 -0
  12. package/packages/lcap-frontend-library/LEARNINGS.md +11 -0
  13. package/packages/lcap-frontend-library/SKILL.md +86 -0
  14. package/packages/lcap-frontend-library/commands/migrate.check.md +287 -0
  15. package/packages/lcap-frontend-library/commands/migrate.green.md +190 -0
  16. package/packages/lcap-frontend-library/commands/migrate.plan.md +169 -0
  17. package/packages/lcap-frontend-library/commands/migrate.red.md +160 -0
  18. package/packages/lcap-frontend-library/commands/migrate.scan.md +151 -0
  19. package/packages/lcap-frontend-library/commands/migrate.spec.md +144 -0
  20. package/packages/lcap-frontend-library/commands/migrate.tasks.md +179 -0
  21. package/packages/lcap-frontend-library/commands/speckit.create.md +201 -0
  22. package/packages/lcap-frontend-library/commands/speckit.implement.md +88 -0
  23. package/packages/lcap-frontend-library/commands/speckit.plan.md +79 -0
  24. package/packages/lcap-frontend-library/commands/speckit.self-check.md +177 -0
  25. package/packages/lcap-frontend-library/commands/speckit.specify.md +91 -0
  26. package/packages/lcap-frontend-library/commands/speckit.tasks.md +61 -0
  27. package/packages/lcap-frontend-library/references/frontend-design/LICENSE.txt +177 -0
  28. package/packages/lcap-frontend-library/references/frontend-design/SKILL.md +42 -0
  29. package/packages/lcap-frontend-library/references/lcap-extension-component/SKILL.md +360 -0
  30. package/packages/lcap-frontend-library/references/lcap-extension-component/api.md +331 -0
  31. package/packages/lcap-frontend-library/references/lcap-extension-component/block.md +160 -0
  32. package/packages/lcap-frontend-library/references/lcap-extension-component/i18n.md +95 -0
  33. package/packages/lcap-frontend-library/references/lcap-extension-component/icon.md +27 -0
  34. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/container.md +728 -0
  35. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/element.md +312 -0
  36. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/expression.md +154 -0
  37. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/index.md +113 -0
  38. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/modal.md +189 -0
  39. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/popover.md +171 -0
  40. package/packages/lcap-frontend-library/references/lcap-extension-component/ide.md +799 -0
  41. package/packages/lcap-frontend-library/references/lcap-extension-component/implementation-rules.md +242 -0
  42. package/packages/lcap-frontend-library/references/lcap-extension-component/index.md +27 -0
  43. package/packages/lcap-frontend-library/references/lcap-extension-component/nasl-view-component.md +895 -0
  44. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/accessibility.md +185 -0
  45. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/child.md +82 -0
  46. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/data-source.md +261 -0
  47. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/event.md +171 -0
  48. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/form.md +266 -0
  49. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/function.md +80 -0
  50. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/link.md +137 -0
  51. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/slot.md +128 -0
  52. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-ant-design.md +1470 -0
  53. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-cloud-ui.md +259 -0
  54. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-element-plus.md +580 -0
  55. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-element-ui.md +1007 -0
  56. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-mobile-ui.md +85 -0
  57. package/packages/lcap-frontend-library/references/lcap-extension-component/theme.md +234 -0
  58. package/packages/lcap-frontend-library/references/lcap-extension-component/workflow-guardrails.md +328 -0
  59. package/packages/lcap-frontend-library/references/nasl-logic-authoring/SKILL.md +201 -0
  60. package/packages/lcap-frontend-library/scripts/bash/create-component-files.sh +95 -0
  61. package/packages/lcap-frontend-library/scripts/bash/create-extension-project.sh +109 -0
  62. package/packages/lcap-frontend-library/scripts/bash/create-logic-files.sh +149 -0
  63. package/packages/lcap-frontend-library/scripts/bash/create-spec.sh +109 -0
  64. package/packages/lcap-frontend-library/scripts/bash/get-available-port.sh +35 -0
  65. package/packages/lcap-frontend-library/scripts/bash/list-specs.sh +19 -0
  66. package/packages/lcap-frontend-library/scripts/node/setup-extension-project.mjs +166 -0
  67. package/packages/lcap-frontend-library/templates/component-self-check.md +31 -0
  68. package/packages/lcap-frontend-library/templates/component-template.md +96 -0
  69. package/packages/lcap-frontend-library/templates/library-report-template.md +52 -0
  70. package/packages/lcap-frontend-library/templates/logic-template.md +44 -0
  71. package/packages/lcap-frontend-library/templates/migration-manifest-template.md +84 -0
  72. package/packages/lcap-frontend-library/templates/migration-plan-template.md +138 -0
  73. package/packages/lcap-frontend-library/templates/migration-report-template.md +227 -0
  74. package/packages/lcap-frontend-library/templates/migration-spec-template.md +135 -0
  75. package/packages/lcap-frontend-library/templates/migration-tasks-template.md +129 -0
  76. package/packages/lcap-frontend-library/templates/plan-template.md +299 -0
  77. package/packages/lcap-frontend-library/templates/self-check-report-template.md +148 -0
  78. package/packages/lcap-frontend-library/templates/tasks-template.md +81 -0
  79. package/packages/lcap-frontend-library/workflows/create/flow.md +199 -0
  80. package/packages/lcap-frontend-library/workflows/evolve/flow.md +249 -0
  81. package/packages/lcap-frontend-library/workflows/generate/flow.md +10 -0
  82. package/packages/lcap-frontend-library/workflows/harness/flow.md +82 -0
  83. package/packages/lcap-frontend-library/workflows/migrate/flow.md +302 -0
  84. package/packages/lcap-frontend-library/workflows/migrate/knowledge-base.md +564 -0
@@ -0,0 +1,242 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+
5
+ # 组件实现规则
6
+
7
+ 实现扩展组件时需同时满足以下六条规则。**计划阶段**应在实现顺序或验收标准中体现,**实现阶段**应在代码与自检中逐条落实,**验收阶段**按清单逐条核对。详细说明如下。
8
+
9
+ ---
10
+
11
+ ## 1. 展示类属性必有默认值
12
+
13
+ ### 规则说明
14
+
15
+ 与展示直接相关的属性(如 `data`、`options`、`config` 等)必须设置**合理默认值**,确保组件在以下情况下也能正常渲染、不报错、不白屏:
16
+
17
+ - 未传入该属性;
18
+ - 传入 `undefined` / `null`;
19
+ - 传入空数据(空数组、空对象等)。
20
+
21
+ ### 为何重要
22
+
23
+ - 页面设计器中组件初次拖入画布时,往往尚未绑定数据源,若缺少默认值会导致报错或空白。
24
+ - 制品运行时若接口暂无数据或加载失败,空数据下组件也应有合理展示(空状态、占位等),而不是白屏或控制台报错。
25
+
26
+ ### 如何落实
27
+
28
+ | 属性类型 | 建议默认值 | 示例 |
29
+ |----------|------------|------|
30
+ | 列表/数据源 | 空数组 `[]` | `data: []`,表格、图表、列表等 |
31
+ | 配置对象 | 空对象 `{}` 或符合 spec 的最小结构 | `options: {}`,`config: { ... }` |
32
+ | 可选展示字段 | 空字符串或占位文案 | `placeholder: ''`,`emptyText: '暂无数据'` |
33
+
34
+ 可根据 spec 或业务含义给出空数组、空对象或占位内容;若 spec 已约定默认值,以 spec 为准。
35
+
36
+ ### 验收要点
37
+
38
+ - [ ] 所有与展示直接相关的 Props(data、options、config 及同类)在 api.ts 中均有默认值或示例数据。
39
+ - [ ] 未传或传空数据时,组件能正常渲染(含空状态),无未捕获异常、不白屏。
40
+
41
+ **异步加载组件**:凡依赖异步数据或资源的展示组件,必须包含完整的状态机与 UI 反馈:**Loading**(加载中)、**Error**(加载失败)、**Empty**(空数据)。严禁出现加载失败后界面无任何提示或仍显示空白的情况。
42
+
43
+ ---
44
+
45
+ ## 2. 表单类组件 value 双向绑定
46
+
47
+ ### 规则说明
48
+
49
+ 输入框、选择器、开关、日期选择等**表单类组件**的 `value`(或 spec 约定的“值”属性)必须支持**双向绑定**:用户操作导致内部值变化时,需通过事件将新值回写给父组件/绑定变量,使“组件显示的值”与“绑定变量的值”保持一致。
50
+
51
+ ### 为何重要
52
+
53
+ - 页面设计器需要“将组件输入赋值给变量”,发布后在制品中用户输入的内容会同步到绑定变量。
54
+ - 平台表单校验依赖值的同步,缺少回写会导致校验、提交与展示不一致。
55
+
56
+ ### 如何落实
57
+
58
+ - **api.ts**:为“值”属性设置 `sync: true`,表示允许平台将组件内部变更同步到绑定变量。
59
+
60
+ ```typescript
61
+ @Prop({
62
+ group: '数据属性',
63
+ title: '值',
64
+ sync: true,
65
+ })
66
+ value: V;
67
+ ```
68
+
69
+ - **实现层**:内部值变化时触发对应事件(如 `update:value`、`input`),具体事件名与框架约定见 **platform/form.md**。
70
+ - Vue2:需同时 `$emit('update:value', val)` 与 `$emit('input', val)`,必要时配置 `model: { prop: 'value', event: 'update:value' }`。
71
+ - Vue3 / React:按平台约定监听 onChange 等并回写即可。
72
+
73
+ 完整实现示例(Vue2/表单校验支持等)见 **component/platform/form.md**。
74
+
75
+ ### 验收要点
76
+
77
+ - [ ] api.ts 中“值”属性已设置 `sync: true`。
78
+ - [ ] 实现中在内部变更时正确 emit 回写,设计器绑定变量后输入能同步更新,表单校验可正常工作。
79
+
80
+ ---
81
+
82
+ ## 3. 默认 HTML 属性穿透
83
+
84
+ ### 规则说明
85
+
86
+ 组件**根节点**必须支持以下常规 HTML 属性的透传,不得在组件内部拦截或丢弃:
87
+
88
+ - `style`
89
+ - `class`
90
+ - `data-*`(任意 data 属性)
91
+
92
+ 这样父组件或设计器可以为组件设置样式、类名或 data 属性(如埋点、测试 id),而不会因组件未透传而失效。
93
+
94
+ ### 为何重要
95
+
96
+ - 设计器与制品中常通过 class、style 做布局、主题或响应式控制;若根节点不透传,这些设置会丢失。
97
+ - 平台与业务可能依赖 `data-*` 做自动化测试、埋点或无障碍等,不透传会破坏这些能力。
98
+
99
+ ### 如何落实
100
+
101
+ - 确保组件有**单一根节点**(或约定透传到主根节点)。
102
+ - 在根节点上绑定框架提供的“未声明属性”:
103
+ - **Vue2**:根节点使用 `v-bind="$attrs"`(若需排除部分属性,可用 `v-bind="filteredAttrs"`,但必须包含 style、class、data-*)。
104
+ - **Vue3**:根节点使用 `v-bind="$attrs"`;若存在多根节点,需在不会继承 attrs 的根上显式绑定。
105
+ - **React**:将上层传入的 `className`、`style` 以及 `data-*` 等合并到根 DOM 的 props 上,不丢弃。
106
+
107
+ 不要在自己的 props 里定义同名的 `class`/`style` 却不往根 DOM 传,也不要过滤掉 `data-*`。
108
+
109
+ ### 验收要点
110
+
111
+ - [ ] 在根节点上设置 `class`、`style` 或 `data-*` 后,能在 DOM 上看到对应属性生效。
112
+ - [ ] 未在组件内部拦截或覆盖这些属性。
113
+ - [ ] 组件使用 `<style scoped>` 或 `<style module>`,无裸 `<style>` 污染全局。
114
+
115
+ ---
116
+
117
+ ## 4. UI 样式规范
118
+
119
+ ### 规则说明
120
+
121
+ 组件的主题与样式必须优先使用对应 UI 框架的**全局主题变量**(CSS 变量),禁止在实现中随意写死颜色、间距等魔法值。需从本技能提供的 `platform/theme-variables-*.md` 中选择合适变量,以保证多主题与换肤能力正常工作。
122
+
123
+ ### 为何重要
124
+
125
+ - 平台支持多主题与换肤,写死颜色/尺寸会导致在深色主题或定制主题下表现不一致。
126
+ - 使用主题变量可保持与 Ant Design、Element Plus、Cloud UI 等框架的视觉体系一致。
127
+
128
+ ### 计划阶段要求 (Planning Requirement)
129
+
130
+ - **严禁仅在验收清单中勾选此项**;必须在写代码之前就在计划书中体现。
131
+ - **必须**在 `plan.md` 中建立「样式与主题适配」章节及**样式变量映射表**(见 plan-template 第三节)。
132
+ - **必须**在生成计划时主动查阅对应的 `platform/theme-variables-*.md` 文档,选定具体的全局变量(如 `--cw-color-primary`、`--el-bg-color-page`)填入映射表,不得推迟至实现阶段再决定。
133
+
134
+ ### 如何落实
135
+
136
+ - 查阅并引用与当前项目 UI 框架对应的主题变量文档:
137
+ - **platform/theme-variables-ant-design.md**
138
+ - **platform/theme-variables-element-ui.md**
139
+ - **platform/theme-variables-element-plus.md**
140
+ - **platform/theme-variables-cloud-ui.md**
141
+ - **platform/theme-variables-mobile-ui.md**
142
+ - 在组件样式中使用上述文档中的 CSS 变量(如 `--cw-color-primary`、`--cw-border-radius` 等),而不是写死 `#1677ff`、`6px` 等。
143
+ - 若组件需要暴露可配置样式(如颜色、尺寸),应在文档或 api 中声明可用的 **CSS 变量**,便于主题与定制。
144
+
145
+ ### 例外:Canvas 与 JS 绘图
146
+
147
+ 上述规则针对 **CSS 层** 的样式与变量;若组件使用 **Canvas、WebGL 或 JS 绘图 API**(如二维码、图表、离屏渲染),绘图上下文无法解析 `var(--*)`,须单独处理:
148
+
149
+ - **限制**:`ctx.fillStyle`、`fill()` 等绘图 API **无法直接使用** CSS 变量字符串,传入 `var(--el-xxx)` 不会得到预期颜色。
150
+ - **要求**:禁止将 CSS 变量名字符串直接传给绘图函数。
151
+ - **推荐**:在 JS 中通过 `getComputedStyle(el).getPropertyValue('--el-xxx')` 获取计算后的绝对颜色值,再传给绘图 API。
152
+ - **功能优先时**:对对比度要求严格的场景(如二维码识别),可选用硬编码高对比度颜色(如 `#ffffff`),在 plan.md 的「样式与主题适配」表中注明为 **JS 渲染** 即可。
153
+
154
+ ### 验收要点
155
+
156
+ - [ ] 组件内无写死的颜色、间距等魔法值(或仅用于与主题变量无关系的局部逻辑)。
157
+ - [ ] 样式主要来自 theme-variables-*.md 中的变量;若适用,已声明或文档化可定制的 CSS 变量。
158
+ - [ ] 样式验证:静态样式写在`<style scoped>` 或 `<style module>` 中,其渲染效果由 E2E 验证,**禁止**在 Vitest 中用 `getComputedStyle` 断言样式生效。
159
+
160
+ ---
161
+
162
+ ## 5. 图标规范
163
+
164
+ ### 规则说明
165
+
166
+ 组件**内部**图标渲染必须基于 **SVG** 语法(如 `<svg>`、`<use>`),并通过 IconSetter 或统一图标库名称驱动。禁止在实现中直接使用:
167
+
168
+ - 位图图标(如 `.png`、`.jpg` 作为图标)
169
+ - 内联 base64 图片
170
+ - 普通文字或 emoji 充当图标
171
+
172
+ ### 为何重要
173
+
174
+ - 平台与设计器依赖统一图标体系(IconSetter、图标库),文字/emoji/位图无法被设计器统一管理和换肤。
175
+ - SVG 可缩放、可着色,与主题变量配合更好,无障碍与多分辨率表现更稳定。
176
+
177
+ ### 如何落实
178
+
179
+ - 组件内部若需展示图标,使用:
180
+ - `<svg>` + `<use>` 引用图标库或已注册的 symbol;或
181
+ - 通过 IconSetter / 图标名称从统一图标库渲染。
182
+ - 组件**面板图标**(api.ts 中 `@Component({ icon: '...' })`)的选用规则见 SKILL.md「内置组件 icon 设置」;自定义面板图标见 **component/icon.md**(如 assets 下的 .svg)。
183
+ - 禁止使用 Unicode 字符、emoji 或图片 URL 作为组件内部图标。
184
+
185
+ ### 验收要点
186
+
187
+ - [ ] 组件内部所有图标均为 SVG 或通过 IconSetter/图标库渲染。
188
+ - [ ] 未使用位图、base64 图片或文字/emoji 充当图标。
189
+
190
+ ---
191
+
192
+ ## 6. Web Worker(Vite)
193
+
194
+ ### 规则说明
195
+
196
+ 在 Vite 中处理 **Web Worker**(含第三方库内置 worker)时,避免继续沿用「CDN 链接 / Webpack entry / 手写复制 `*.min.js`」等旧习惯,优先用构建器解析出的 **稳定 URL 或 Worker 构造**。
197
+
198
+ ### 为何重要
199
+
200
+ - Worker 脚本路径若写死或依赖外链,在换环境、换版本或生产资源哈希变化时易出现 404 或与主包版本不一致。
201
+ - 由 Vite 解析并打包的 worker 与主应用同源发布,利于缓存与可复现构建;SSR 场景若误在服务端初始化 `Worker`,会导致运行时报错。
202
+
203
+ ### 如何落实
204
+
205
+ **原则**
206
+
207
+ - **统一由 Vite 解析 worker 资源**:使用 `?url` 得到 worker 脚本 URL,或按需使用 `?worker` / `new URL(..., import.meta.url)` 等 [Vite 文档](https://vitejs.dev/guide/features.html#web-workers) 推荐写法。
208
+ - **前置初始化**:设置 `workerSrc`、`new Worker(...)` 等逻辑放在**实际消费方模块的顶部**(该文件内任何 `async` 业务逻辑执行之前),避免首次调用时 worker 尚未就绪。
209
+ - **SSR**:若该模块会在 SSR 阶段执行,对 `Worker` / `window` 相关代码加环境守卫,仅在浏览器侧初始化。
210
+
211
+ **第三方示例:`pdfjs-dist`**
212
+
213
+ 将 worker 脚本作为 URL 模块导入,并赋给官方全局配置(路径以当前安装的 `pdfjs-dist` 版本为准):
214
+
215
+ ```typescript
216
+ import * as pdfjsLib from 'pdfjs-dist';
217
+ import pdfWorker from 'pdfjs-dist/build/pdf.worker.mjs?url';
218
+
219
+ pdfjsLib.GlobalWorkerOptions.workerSrc = pdfWorker;
220
+ ```
221
+
222
+ 自研 worker 可类似使用 `import MyWorker from './my.worker?url'` 再 `new Worker(MyWorker, { type: 'module' })`(是否 `module` 以浏览器与打包目标为准)。
223
+
224
+ ### 验收要点
225
+
226
+ - [ ] Worker 脚本通过 Vite 推荐方式(如 `?url` / `?worker` / `import.meta.url`)引入,未依赖手写 CDN、复制 min 文件或仅适用于 Webpack 的 entry 配置。
227
+ - [ ] `workerSrc` 或 `new Worker` 在实际使用异步逻辑之前完成;若存在 SSR,浏览器 API 仅在客户端执行。
228
+
229
+ ---
230
+
231
+ ## 相关文档索引
232
+
233
+ | 规则 | 参考文档 |
234
+ |------|----------|
235
+ | 展示类默认值 | 各组件 spec、api.ts 默认值约定 |
236
+ | 表单 value 双向绑定 | **component/platform/form.md** |
237
+ | HTML 属性穿透 | 本文档 §3;插槽若涉及 EmptySlot 见 **component/platform/slot.md**、**component/ide/container.md** |
238
+ | UI 样式 / 主题变量 | **platform/theme-variables-ant-design.md** 等 theme-variables-*.md |
239
+ | 图标 | **component/icon.md**(面板图标);SKILL.md「内置组件 icon 设置」 |
240
+ | Web Worker(Vite) | 本文档 §6;[Vite - Web Workers](https://vitejs.dev/guide/features.html#web-workers) |
241
+
242
+ 计划与验收时可将上述六条与 **plan-template.md** 中「五、验收检查清单」的「组件实现规则」小节一起逐条核对。
@@ -0,0 +1,27 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+ <script setup>
5
+ import { VTCodeGroup, VTCodeGroupTab } from '../../.vitepress/components'
6
+ </script>
7
+
8
+ # 组件开发指南
9
+
10
+ ## 1. 初始化组件
11
+
12
+ 使用工具创建组件。
13
+
14
+
15
+ ## 2. 开发说明
16
+
17
+ 开发需要完成的内容如下图:
18
+
19
+ - \[必要配置] [api.ts](./api.md):组件配置说明, 描述用户组件的配置面板生成,应用翻译等。
20
+ - \[必要配置] [block.stories.{js|tsx|jsx}](./block.md):组件拖转到画布后初始生成的代码示例。
21
+ - \[必要配置] [页面编辑器适配](./ide.md):IDE 页面编辑画布适配,用于在页面上的展示。
22
+ - \[可选配置] IDE 功能适配 :主题配置、国际化能力等扩展能力适配。
23
+ - \[可选配置] 平台能力适配 :对平台提供能力的适配。
24
+
25
+
26
+
27
+