dsh-design-studio 0.16.1 → 0.17.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/README.en.md CHANGED
@@ -45,9 +45,11 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
45
45
  - **Export and phone preview:** showcase images, PDF and PowerPoint (links between screens still work); scan a QR code to see it on your phone at real size. Slides and posters larger than the default canvas now use the page's real size. You can also set it by adding `WIDTHxHEIGHT` after the type, for example `<meta name="dsh-design" content="slides 1440x810">`. Export options let you pick the page size (16:9, 4:3, A3 landscape or custom), what each page shows (one screen, full page or a set height) and two screens per page. If anything would be cut off, you get a checklist first, with a one-click fix that fits the canvas to the content.
46
46
  - **Design library and gallery:** everything you've designed, plus saved references and styles, lives in the Library. Browse templates, design systems and style cards others shared, and "Start from this" copies one for you to keep editing. Share your own with "Share to the gallery": it's checked, zipped and submitted on a web page, and listed once reviewed. The gallery catalog comes from npm mirrors and is used only when its signature and checksums match; to keep it offline, turn on "Design library offline" on the Plugins page.
47
47
  - **Your brand, and real code:** give a site URL to extract a brand design system and design with it from then on; turn a finished design into React / Vue / HTML (mini programs straight into uni-app or native WeChat code, HBuilderX projects included), compared screen by screen against the design.
48
+ - **Built-in photo library:** for designs that rely on photos (hotels, food, cafes, fitness, beauty, fashion, education, travel), the model uses real-looking photos instead of only drawing illustrations. About 8 MB is downloaded the first time it is needed. All of them are AI-generated placeholders, so replace them with real photos before launch.
49
+ - **A style that fits the subject:** when you have not chosen a style, the model first picks a style card for the subject (colors, fonts, corner radius) and builds with it, so a homestay app, a bubble-tea shop and a review deck no longer all come out beige. If you name a style or colors, it follows yours.
50
+ - **Business annotations (experimental, off by default):** turn on "Business annotations" under Design Studio on the Plugins page, and the model also writes `annotations.json` with the rules, states and edge cases the UI does not show. Numbered markers appear on the page and cards in the sidebar, and clicking either one finds the other. Code handoff passes the rules on to developers (#15).
48
51
 
49
52
  See [all features](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/features.md) for every feature, the tool parameters and the security design, and [development](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/development.md) for dev setup and tests.
50
- - **Built-in photo library:** for designs that rely on photos (hotels, food, cafes, fitness, beauty, fashion, education, travel), the model uses real-looking photos instead of only drawing illustrations. About 8 MB is downloaded the first time it is needed. All of them are AI-generated placeholders, so replace them with real photos before launch.
51
53
 
52
54
  ## Feedback
53
55
 
package/README.md CHANGED
@@ -45,9 +45,11 @@
45
45
  - **导出和手机上看**:导出展示图、PDF、PPT(屏和屏之间的跳转照样能点);扫码在手机上按真机尺寸看。页面比默认画幅大的幻灯片、海报,画幅自动跟页面走;也可以在类型后面跟 `宽x高` 指定,比如 `<meta name="dsh-design" content="slides 1440x810">`。导出选项里可以选版面(16:9、4:3、A3 横向、自定义)、每页取景(一屏、整页、指定高度)和每页拼 2 屏;有内容会被裁时,导出前先给一张清单,可以一键按内容改画幅。
46
46
  - **设计库和设计市场**:以前做过的设计、收的参考图和风格都在「设计库」里;市场里逛大家分享的模板、设计系统和风格卡,点「用这个开始」复制一份接着改。自己做的点「分享到设计市场」,查过打成 zip,在网页里交上去,审过就上架。市场目录从 npm 镜像取,签了名、核对过才用;不想让它联网,在插件页打开「设计库不联网」。
47
47
  - **照品牌风格做、转成代码**:给官网地址,提一套品牌设计系统,以后都照它做;做好的设计转成 React / Vue / HTML,小程序直接转成 uni-app 或原生小程序代码(HBuilderX 建的项目也认得出),逐屏和设计稿比对。
48
+ - **自带照片库**:民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景这些靠照片说话的设计,模型会直接用上照片,不再只画插画。第一次用到时下载约 8 MB。都是 AI 生成的示意图,上线前请换成真实照片。
49
+ - **按题材挑风格**:没定风格时,模型先按题材挑一张风格卡(配色、字体、圆角)再动手,民宿、奶茶店、复盘幻灯片不再都是一个米色调;你自己说了风格或配色就照你的。
50
+ - **业务标注(试验,默认关)**:在「插件」页的设计工作台里打开「业务标注」,模型做设计时同时写一份 `annotations.json`,记界面上看不出来的规则、状态和边界。页面上出编号,右侧栏列卡片,点哪边都能定位到另一边;转成代码时这些规则一起交给开发(#15)。
48
51
 
49
52
  全部功能、工具参数和安全设计见[完整功能](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/功能详解.md);开发和测试见[开发说明](https://github.com/OrderG-X/dsh-design-studio/blob/main/docs/开发.md)。
50
- - **自带照片库**:民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景这些靠照片说话的设计,模型会直接用上照片,不再只画插画。第一次用到时下载约 8 MB。都是 AI 生成的示意图,上线前请换成真实照片。
51
53
 
52
54
  ## 反馈
53
55
 
package/cordis.patch.yml CHANGED
@@ -12,6 +12,10 @@
12
12
  - id: dsh-design-studio-offline
13
13
  name: dsh-design-studio/offline
14
14
  disabled: true
15
+ # 业务标注(试验,默认关):打开后模型随设计写 annotations.json,右侧栏多一个按钮
16
+ - id: dsh-design-studio-annotations
17
+ name: dsh-design-studio/annotations
18
+ disabled: true
15
19
  # 其他模式(标准、创造 …)也能用预览工具、设计技能;设计模式里自带一份,不受这两行影响
16
20
  - id: dsh-design-studio-tool
17
21
  name: dsh-design-studio/tool
@@ -0,0 +1,14 @@
1
+ /**
2
+ * dsh-design-studio/annotations:业务标注(试验,默认关)。
3
+ * 打开后模型做设计时同时写 annotations.json,右侧栏多一个「业务标注」按钮;关着时界面、技能说明、体检、交接说明都和没有这个功能一样
4
+ */
5
+ import { studio } from './index.js'
6
+
7
+ export const name = 'dsh-design-studio-annotations'
8
+
9
+ export function apply(ctx) {
10
+ ctx.effect(() => {
11
+ studio.annotations++
12
+ return () => { studio.annotations-- }
13
+ }, 'dsh-design-studio: annotations')
14
+ }
@@ -0,0 +1,214 @@
1
+ /**
2
+ * 业务标注(试验,插件页一行开关,默认关):模型随设计写一份 annotations.json,记界面上看不出来的规则、状态、边界、口径。
3
+ * 右侧栏列卡片、页面上出编号、两边互相定位,转成代码时写进交接说明。
4
+ *
5
+ * annotations.json 放在设计目录里、和 tweaks.json 并排(也可以直接是数组):
6
+ * { "annotations": [
7
+ * { "id": "room-03", "page": "room.html", "type": "rule", "title": "价格含双人早餐",
8
+ * "detail": "底栏价格是含早价", "selector": ".ab-price", "anchorLabel": "底栏价格",
9
+ * "fallbackText": "含双人早餐", "source": "PRD 2.6", "tags": ["价格"], "related": ["booking-02"], "status": "open" }
10
+ * ] }
11
+ *
12
+ * 文件是模型写的,一律当数据:选择器只进 querySelector(包 try),文字只走 React 文字节点和 textContent。
13
+ */
14
+
15
+ import fs from 'node:fs'
16
+ import path from 'node:path'
17
+ import crypto from 'node:crypto'
18
+ import { allScreens } from './core.js'
19
+
20
+ export const ANNOTATIONS_FILE = 'annotations.json'
21
+ export const MAX_ANNOTATIONS = 200
22
+ const MAX_FILE = 512 * 1024
23
+
24
+ // 单个字段的长度上限(超了这条报出来、不显示,别的照常)
25
+ const LIMITS = { id: 64, page: 200, type: 24, title: 200, detail: 4000, selector: 500, anchorLabel: 120, fallbackText: 200, source: 300, status: 24 }
26
+ const MAX_ITEMS = 20 // tags、related 各最多几个
27
+ const MAX_ITEM = 64 // tags、related 每个多长
28
+ const MAX_ERRORS = 30 // 写坏的最多列几条(一份 512 KB 的文件能写出几十万条错)
29
+
30
+ const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k)
31
+
32
+ /** 字段 → 去掉首尾空白的字符串(数字也认);没写是 '';类型不对或太长是 null */
33
+ function field(x, key) {
34
+ if (!hasOwn(x, key) || x[key] == null) return ''
35
+ const v = x[key]
36
+ if (typeof v !== 'string' && typeof v !== 'number') return null
37
+ const s = String(v).trim()
38
+ return s.length > LIMITS[key] ? null : s
39
+ }
40
+
41
+ /** tags / related → 字符串数组;没写是 [];类型不对或太多是 null */
42
+ function strings(x, key) {
43
+ if (!hasOwn(x, key) || x[key] == null) return []
44
+ const v = x[key]
45
+ if (!Array.isArray(v) || v.length > MAX_ITEMS) return null
46
+ const out = []
47
+ for (const it of v) {
48
+ if (typeof it !== 'string' && typeof it !== 'number') return null
49
+ const s = String(it).trim()
50
+ if (s.length > MAX_ITEM) return null
51
+ if (s) out.push(s)
52
+ }
53
+ return out
54
+ }
55
+
56
+ /** page → 设计目录里的相对路径(room.html、sub/room.html);不像一个 HTML 文件时是 '' */
57
+ export function normPage(s) {
58
+ const p = String(s || '').trim().replace(/\\/g, '/').replace(/^(\.\/)+/, '').replace(/^\/+/, '')
59
+ if (!/\.html?$/i.test(p) || /[?#]/.test(p) || p.split('/').some((x) => x === '..' || x === '')) return ''
60
+ return p
61
+ }
62
+
63
+ /**
64
+ * annotations.json 的内容 → { list, errors }。
65
+ * list:[{ id, n, page, type, title, detail, selector, anchorLabel, fallbackText, source, tags, related, status }];n 是这一屏的第几条(编号)
66
+ */
67
+ export function parseAnnotations(text) {
68
+ let raw
69
+ try { raw = JSON.parse(String(text || '')) } catch (e) { return { list: [], errors: [`annotations.json 不是合法的 JSON:${String(e.message).slice(0, 80)}`] } }
70
+ const arr = Array.isArray(raw) ? raw : raw && Array.isArray(raw.annotations) ? raw.annotations : null
71
+ if (!arr) return { list: [], errors: ['annotations.json 里要有 "annotations": [ … ]'] }
72
+ const list = []
73
+ const errors = []
74
+ const ids = new Set()
75
+ const perPage = new Map()
76
+ let more = 0
77
+ let tooMany = 0
78
+ const fail = (m) => { if (errors.length < MAX_ERRORS) errors.push(m); else more++ }
79
+ for (let i = 0; i < arr.length; i++) (() => {
80
+ const x = arr[i]
81
+ const at = `第 ${i + 1} 条`
82
+ if (!x || typeof x !== 'object' || Array.isArray(x)) { fail(`${at}不是对象`); return }
83
+ const f = {}
84
+ for (const k of Object.keys(LIMITS)) f[k] = field(x, k)
85
+ const name = f.id ? `${at}(${f.id})` : at
86
+ const bad = Object.keys(LIMITS).filter((k) => f[k] === null)
87
+ if (bad.length) { fail(`${name}的 ${bad.join('、')} 类型不对或太长`); return }
88
+ const tags = strings(x, 'tags')
89
+ const related = strings(x, 'related')
90
+ if (!tags || !related) { fail(`${name}的 ${!tags ? 'tags' : 'related'} 要是字符串数组,最多 ${MAX_ITEMS} 个,每个 ${MAX_ITEM} 字以内`); return }
91
+ if (!f.id) { fail(`${at}缺 id`); return }
92
+ if (!f.title) { fail(`${name}缺 title`); return }
93
+ if (!f.page) { fail(`${name}缺 page(这一屏的文件名,如 room.html)`); return }
94
+ const page = normPage(f.page)
95
+ if (!page) { fail(`${name}的 page 要写这一屏的文件名(如 room.html),现在是「${f.page.slice(0, 40)}」`); return }
96
+ if (ids.has(f.id)) { fail(`${name}的 id 和前面重复了`); return }
97
+ if (list.length >= MAX_ANNOTATIONS) { tooMany++; return }
98
+ ids.add(f.id)
99
+ const n = (perPage.get(page) || 0) + 1
100
+ perPage.set(page, n)
101
+ list.push({ ...f, page, n, status: f.status.toLowerCase(), tags, related })
102
+ })()
103
+ if (tooMany) errors.push(`最多 ${MAX_ANNOTATIONS} 条,后面的 ${tooMany} 条没显示`)
104
+ if (more) errors.push(`还有 ${more} 处写坏了,没列出来`)
105
+ return { list, errors }
106
+ }
107
+
108
+ const cache = new Map()
109
+
110
+ /** 读设计目录里的 annotations.json(改了才重新解析)→ { list, errors, mtime, sig };没有这个文件是 null */
111
+ export function readAnnotations(root) {
112
+ if (!root) return null
113
+ const file = path.join(root, ANNOTATIONS_FILE)
114
+ let st
115
+ try { st = fs.lstatSync(file) } catch { cache.delete(file); return null }
116
+ // 只认设计目录里的普通文件:软链接(可能指到目录外)当没有
117
+ if (!st.isFile()) return null
118
+ const hit = cache.get(file)
119
+ if (hit && hit.mtime === st.mtimeMs && hit.size === st.size) return hit.r
120
+ let r
121
+ let failed = false
122
+ try {
123
+ r = st.size > MAX_FILE ? { list: [], errors: ['annotations.json 太大了(最多 512 KB)'] } : parseAnnotations(fs.readFileSync(file, 'utf8'))
124
+ } catch (e) {
125
+ r = { list: [], errors: [`annotations.json 读不了:${String(e.message).slice(0, 80)}`] }
126
+ failed = true // 权限这类问题可能马上好:下一轮重读,不记缓存
127
+ }
128
+ // 签名带上目录:换了一套设计,哪怕文件大小和修改时间碰巧一样,也不能当成同一份
129
+ const dirId = crypto.createHash('sha1').update(path.resolve(root)).digest('hex').slice(0, 10)
130
+ r = { ...r, mtime: st.mtimeMs, sig: `${dirId}-${st.mtimeMs}-${st.size}` }
131
+ if (failed) r = { ...r, sig: `err-${r.sig}` }
132
+ else cache.set(file, { mtime: st.mtimeMs, size: st.size, r })
133
+ if (cache.size > 50) cache.delete(cache.keys().next().value)
134
+ return r
135
+ }
136
+
137
+ /**
138
+ * 只看文件:写坏的、指到不存在的屏的。
139
+ * @returns [文字](check_design 的结果里列出来)
140
+ */
141
+ export function lintAnnotations(root) {
142
+ const r = readAnnotations(root)
143
+ if (!r) return []
144
+ const out = [...r.errors]
145
+ if (!r.list.length) return out
146
+ const screens = new Set(allScreens(root))
147
+ for (const a of r.list) if (!screens.has(a.page)) out.push(`${a.id}:page 写的 ${a.page} 不是这套设计里的屏`)
148
+ return out
149
+ }
150
+
151
+ /** 无头浏览器核对的结果 → [文字]。found:[{ page, list: [{ id, how, count }] }];how:selector / text / page / '' */
152
+ export function annotationFindings(all, found) {
153
+ const byId = new Map(all.map((a) => [a.id, a]))
154
+ const out = []
155
+ for (const { page, list } of found) {
156
+ for (const f of list || []) {
157
+ const a = byId.get(f.id)
158
+ if (!a) continue
159
+ if (!f.how) out.push(`${page}:${a.id}「${a.title}」定位不到(${a.selector ? `选择器 ${a.selector}` : ''}${a.selector && a.fallbackText ? ' 和' : ''}${a.fallbackText ? `文字「${a.fallbackText}」` : ''}都没找到)`)
160
+ else if (f.how === 'text' && a.selector) out.push(`${page}:${a.id}「${a.title}」的选择器 ${a.selector} 失效了,现在靠文字找到的,把选择器改对`)
161
+ else if (f.how === 'selector' && f.count > 1) out.push(`${page}:${a.id}「${a.title}」的选择器 ${a.selector} 匹配到 ${f.count} 个,用的第一个,写得再具体一点`)
162
+ }
163
+ }
164
+ return out
165
+ }
166
+
167
+ /** 给 ui-design 技能补的一段(开关开着才加) */
168
+ export function annotationSection() {
169
+ return '\n\n## 业务标注(用户打开了这个试验开关)\n\n' +
170
+ '每套新设计都带一份 `annotations.json`(放在设计目录,和 `tokens.css` 并排),不用等用户说。字段、例子、选择器怎么写,看 `references/annotations.md`。\n\n' +
171
+ '- **什么时候写**:一套设计的屏都做完、最后一次 `check_design` 之前写;之后改了设计,同步改它。\n' +
172
+ '- **写什么**:界面上看不出来的规则、状态、边界、数据口径,每屏 3–8 条,不复述页面上的字。\n' +
173
+ '- **有需求文档**:用户给了 PRD 或需求文件就先读,照它写,`source` 记出处。没给就不编出处,`source` 留空;拿不准的 `status` 写 `open`。\n' +
174
+ '- **选择器**:用自己写的语义类名或 id;`fallbackText` 写这个元素上看得见的字。\n' +
175
+ '- **不为标注多跑体检**:`check_design` 末尾报了定位不到的,顺手修。\n' +
176
+ '- **用户说「room-03 改成…」**:直接改这个文件里 `id` 对得上的那条。\n'
177
+ }
178
+
179
+ const TYPE_NAME = { rule: '业务规则', state: '状态边界', logic: '逻辑', flow: '流程', metric: '口径', data: '口径' }
180
+
181
+ function ruleLine(a) {
182
+ const where = [a.anchorLabel, a.selector ? `\`${a.selector}\`` : '', a.fallbackText && !a.selector ? `「${a.fallbackText}」` : ''].filter(Boolean).join(' ')
183
+ const bits = [TYPE_NAME[a.type] || a.type, where, a.source ? `出处:${a.source}` : ''].filter(Boolean).join(';')
184
+ const body = a.detail ? `:${a.detail.replace(/\s*\n\s*/g, ' ')}` : ''
185
+ return `- **${a.id} ${a.title}**${bits ? `(${bits})` : ''}${body}`
186
+ }
187
+
188
+ /**
189
+ * 交接说明里「业务规则」那一节;没有标注(或开关关着,r 是 null)时是 []。
190
+ * pages:这次交接的屏(Set),只带这几屏的规则;不传是全部。
191
+ * known:这套设计所有的屏(Set):page 写错、对不上任何一屏的,单独列出来,别悄悄没了
192
+ */
193
+ export function annotationsMd(r, pages = null, known = null) {
194
+ if (!r) return []
195
+ const list = pages ? r.list.filter((a) => pages.has(a.page)) : r.list
196
+ const stray = known ? r.list.filter((a) => !known.has(a.page) && !(pages && pages.has(a.page))) : []
197
+ const errors = r.errors || []
198
+ if (!list.length && !errors.length && !stray.length) return []
199
+ const open = list.filter((a) => a.status === 'open')
200
+ const guessed = list.filter((a) => a.status !== 'open' && !a.source)
201
+ const sure = list.filter((a) => a.status !== 'open' && a.source)
202
+ const lines = ['## 业务规则', '']
203
+ if (errors.length) lines.push(`> annotations.json 有 ${errors.length} 处写坏了,这些规则下面没有,别当成已经交接完:`, ...errors.slice(0, 20).map((e) => `> - ${String(e).replace(/\s*\n\s*/g, ' ')}`), ...(errors.length > 20 ? [`> - 还有 ${errors.length - 20} 处`] : []), '')
204
+ if (list.length) lines.push(`来自设计目录的 annotations.json,共 ${list.length} 条。写代码时照着实现;选择器指的是设计稿里的元素。`, '')
205
+ const byPage = (list) => {
206
+ const keys = [...new Set(list.map((a) => a.page))]
207
+ return keys.flatMap((p) => [`**${p}**`, '', ...list.filter((a) => a.page === p).map(ruleLine), ''])
208
+ }
209
+ if (sure.length) lines.push(...byPage(sure))
210
+ if (guessed.length) lines.push('### 模型推断(没有出处,开发前和产品核对)', '', ...byPage(guessed))
211
+ if (open.length) lines.push('### 待确认(别当成定论)', '', ...byPage(open))
212
+ if (stray.length) lines.push('### 屏名对不上的(page 写错了,开发前核对)', '', ...byPage(stray))
213
+ return lines
214
+ }