dsh-design-studio 0.16.0 → 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 +3 -1
- package/README.md +3 -1
- package/cordis.patch.yml +4 -0
- package/lib/annotations-row.js +14 -0
- package/lib/annotations.js +214 -0
- package/lib/browser.js +14 -3
- package/lib/client.js +353 -40
- package/lib/core.js +9 -2
- package/lib/handoff.js +16 -4
- package/lib/index.js +81 -10
- package/lib/look.js +19 -7
- package/lib/photos.js +9 -0
- package/lib/picker.js +337 -8
- package/lib/serve.js +3 -2
- package/lib/styles.js +203 -0
- package/lib/tool.js +3 -2
- package/locale/annotations/en.json +6 -0
- package/locale/annotations/zh.json +6 -0
- package/package.json +4 -1
- package/skills/ui-design/SKILL.md +5 -3
- package/skills/ui-design/references/annotations.md +64 -0
package/lib/core.js
CHANGED
|
@@ -67,8 +67,13 @@ export function parseSize(input) {
|
|
|
67
67
|
|
|
68
68
|
/** 右侧显示的几屏:超过上限时留最新生成的,最早的先收起来。keep:正打开的那屏,不在里面也留着(挤掉最早的一屏) */
|
|
69
69
|
export function listScreens(root, keep = '') {
|
|
70
|
-
const
|
|
71
|
-
|
|
70
|
+
const born = screensByBirth(root)
|
|
71
|
+
let kept = born.slice(-MAX_SCREENS)
|
|
72
|
+
if (keep && !kept.includes(keep)) {
|
|
73
|
+
if (kept.length >= MAX_SCREENS) kept.shift()
|
|
74
|
+
// 按创建顺序放回原位(打开文件夹取的是最早的一屏,别排到最后);不在顶层的(一般不会有)放最后
|
|
75
|
+
kept = born.includes(keep) ? born.filter((x) => x === keep || kept.includes(x)) : [...kept, keep]
|
|
76
|
+
}
|
|
72
77
|
return inManifestOrder(root, kept)
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -922,6 +927,8 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
922
927
|
if (p) settle(sessionId, st, part, absOf(sessionId, p))
|
|
923
928
|
}
|
|
924
929
|
}
|
|
930
|
+
// 第一屏的草稿开始流了:右侧栏关着就什么都看不到,弹一次(规矩和模型开了新页面一样,「自动打开预览」关着不弹)
|
|
931
|
+
if (draft && !st.target && autoOpen()) st.openRev++
|
|
925
932
|
if (draft && !draft.origin) {
|
|
926
933
|
open({ kind: 'file', file: draft.serve, root }).then((r) => {
|
|
927
934
|
if (st.draft === draft) draft.origin = r.origin
|
package/lib/handoff.js
CHANGED
|
@@ -17,6 +17,7 @@ import { pathToFileURL } from 'node:url'
|
|
|
17
17
|
import { prepare } from './look.js'
|
|
18
18
|
import { allScreens } from './core.js'
|
|
19
19
|
import { readTweaks, shownValue } from './tweaks.js'
|
|
20
|
+
import { annotationsMd } from './annotations.js'
|
|
20
21
|
import { tokensOf } from './system.js'
|
|
21
22
|
|
|
22
23
|
export const HANDOFF_DIR = 'handoff'
|
|
@@ -181,6 +182,14 @@ export function within(p, root) {
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
/** 把允许的目录当场解析成真实路径钉住,返回判断函数(之后目录被换成软链,边界也不跟着变) */
|
|
185
|
+
/** 本机时间,写明时区:2026-11-10 12:07(UTC+8) */
|
|
186
|
+
export function localStamp(d) {
|
|
187
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
188
|
+
const off = -d.getTimezoneOffset()
|
|
189
|
+
const a = Math.abs(off)
|
|
190
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}(UTC${off < 0 ? '-' : '+'}${Math.floor(a / 60)}${a % 60 ? ':' + p(a % 60) : ''})`
|
|
191
|
+
}
|
|
192
|
+
|
|
184
193
|
export function pinRoots(roots) {
|
|
185
194
|
const pins = roots.filter(Boolean).map((r) => fold(realish(r)))
|
|
186
195
|
return (p) => {
|
|
@@ -325,7 +334,7 @@ export function unlinkIfLink(file) {
|
|
|
325
334
|
* 生成交接包。screens:[{ key, url, label }](预览服务器上的地址);root:设计目录。
|
|
326
335
|
* @returns { file, dir, md, shots, rows }
|
|
327
336
|
*/
|
|
328
|
-
export async function buildHandoff(browser, { root, screens, kind = 'web', size = [1280, 800], framework = 'react', dest = '', project = null, system = '', now = new Date() }) {
|
|
337
|
+
export async function buildHandoff(browser, { root, screens, kind = 'web', size = [1280, 800], framework = 'react', dest = '', project = null, system = '', annotations = null, now = new Date() }) {
|
|
329
338
|
const dir = path.join(root, HANDOFF_DIR)
|
|
330
339
|
const shotDir = path.join(dir, 'shots')
|
|
331
340
|
// handoff/、handoff/shots/ 得是设计目录里真的文件夹:是软链接就可能删到、写到别处去
|
|
@@ -339,7 +348,7 @@ export async function buildHandoff(browser, { root, screens, kind = 'web', size
|
|
|
339
348
|
const rows = browser && browser.available() ? await shootScreens(browser, list, size, kind, shotDir) : list.map((sc) => ({ key: sc.key, label: sc.label, title: '', links: [], shots: [], error: '没有 Chrome / Edge,没截图' }))
|
|
340
349
|
const htmlByKey = new Map()
|
|
341
350
|
for (const sc of list) { try { htmlByKey.set(sc.key, fs.readFileSync(path.join(root, sc.key), 'utf8')) } catch { /* 读不了 */ } }
|
|
342
|
-
const md = handoffMd({ root, rows, kind, size, framework, dest, project, system, htmlByKey, more: Math.max(0, screens.length - MAX_SCREENS), now })
|
|
351
|
+
const md = handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations, htmlByKey, more: Math.max(0, screens.length - MAX_SCREENS), now })
|
|
343
352
|
const file = path.join(dir, 'HANDOFF.md')
|
|
344
353
|
unlinkIfLink(file)
|
|
345
354
|
fs.writeFileSync(file, md)
|
|
@@ -347,7 +356,7 @@ export async function buildHandoff(browser, { root, screens, kind = 'web', size
|
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
/** 交接说明 */
|
|
350
|
-
export function handoffMd({ root, rows, kind, size, framework, dest, project, system, htmlByKey, more = 0, now = new Date() }) {
|
|
359
|
+
export function handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations = null, htmlByKey, more = 0, now = new Date() }) {
|
|
351
360
|
const fw = FRAMEWORKS[framework] || null
|
|
352
361
|
const same = framework === 'same' && project && project.framework
|
|
353
362
|
const fwLabel = same ? `${project.label}(跟项目一样)` : fw ? fw.label : framework
|
|
@@ -385,7 +394,7 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
|
|
|
385
394
|
else lines.push(`- 做到:\`${dest}\``)
|
|
386
395
|
lines.push(`- 框架:${fwLabel}`)
|
|
387
396
|
if (system) lines.push(`- 设计系统:${system}(设计用的是它的 tokens.css / components.css,项目里也照它)`)
|
|
388
|
-
lines.push(`- 生成时间:${now
|
|
397
|
+
lines.push(`- 生成时间:${localStamp(now)}`, '')
|
|
389
398
|
if (kind === 'miniprogram' && !mini) {
|
|
390
399
|
// 小程序的设计、选的是网页框架:做成手机网页,别混进小程序的写法
|
|
391
400
|
lines.push('## 小程序设计做成网页(H5)', '')
|
|
@@ -510,6 +519,9 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
|
|
|
510
519
|
if (tw && tw.list.length) lines.push(`- 调节滑块(tweaks.json):${tw.list.map((k) => `${k.label}(${k.var || k.attr},现在是 ${shownValue(k, k.value)})`).join('、')}。最终值已经写在样式里;要在产品里留着可调,就做成主题设置(改同一个 CSS 变量 / <html> 属性)。`)
|
|
511
520
|
lines.push('')
|
|
512
521
|
|
|
522
|
+
// 业务规则(业务标注开着才有)
|
|
523
|
+
lines.push(...annotationsMd(annotations, new Set(htmlByKey.keys()), annotations ? new Set(allScreens(root)) : null))
|
|
524
|
+
|
|
513
525
|
// 素材
|
|
514
526
|
const assets = []
|
|
515
527
|
const walk = (d, rel, depth) => {
|
package/lib/index.js
CHANGED
|
@@ -50,10 +50,11 @@ import { createHub, webOrigins, trustedOrigins, resolveInRoot, ERR_CATCHER, defa
|
|
|
50
50
|
import { bundle, inlinePicker, strictMeta, MAX_TOTAL as BUNDLE_MAX } from './bundle.js'
|
|
51
51
|
import { createLibrary } from './works.js'
|
|
52
52
|
import { createInspiration } from './inspire.js'
|
|
53
|
+
import { pickStyleText } from './styles.js'
|
|
53
54
|
import { createLibraryRoutes } from './gallery/routes.js'
|
|
54
55
|
import { createMarket } from './gallery/market.js'
|
|
55
56
|
import { createMarketRoutes } from './gallery/market-routes.js'
|
|
56
|
-
import { createPhotos, loadPhotoIndex, searchPhotos, onlyByTheme, isPhotoAsset, orientOf, MAX_PHOTOS } from './photos.js'
|
|
57
|
+
import { createPhotos, loadPhotoIndex, searchPhotos, onlyByTheme, ratioNote, isPhotoAsset, orientOf, MAX_PHOTOS } from './photos.js'
|
|
57
58
|
import { createTracker, parseTarget, findRule, KINDS } from './core.js'
|
|
58
59
|
import { createDrafts } from './draft.js'
|
|
59
60
|
import { createHistory } from './history.js'
|
|
@@ -64,6 +65,7 @@ import { createBrowser } from './browser.js'
|
|
|
64
65
|
import { designOf, fitSize, metaOfFile, sizeOf, pickScreens, measureAll, shootAll, cropIssues, formatMeasure, issueSnapshot, formatShots, whereOf, MAX_SCREENS, MAX_SIZES, MAX_SHOTS, MAX_CROPS } from './look.js'
|
|
65
66
|
import { SYSTEMS_DIR, extractSystem, listSystems, setDefault, skillSection } from './system.js'
|
|
66
67
|
import { readTweaks, applyTweaks, lintTweaks } from './tweaks.js'
|
|
68
|
+
import { readAnnotations, lintAnnotations, annotationFindings, annotationSection } from './annotations.js'
|
|
67
69
|
import { FRAMEWORKS, detectProject, projectFor, defaultFramework, buildHandoff, compareScreens, implUrl, defaultDest, pickedDest, within, pinRoots } from './handoff.js'
|
|
68
70
|
|
|
69
71
|
export const name = 'dsh-design-studio'
|
|
@@ -90,7 +92,7 @@ const SKILL_RANK = 600 // 和 DSH 自带的技能同一档;用户 / 项目里
|
|
|
90
92
|
* 几行之间靠这个互通(同一个包里的模块 Node 只加载一次):工作台起来后放 tracker、无头浏览器(browser);
|
|
91
93
|
* 「自动打开预览」那行开着时 autoOpen > 0
|
|
92
94
|
*/
|
|
93
|
-
export const studio = { tracker: null, autoOpen: 0, offline: 0, check: null, browser: null, market: null, photos: null, sessionCwd: null, log: () => {} }
|
|
95
|
+
export const studio = { tracker: null, autoOpen: 0, offline: 0, annotations: 0, check: null, browser: null, market: null, photos: null, sessionCwd: null, log: () => {} }
|
|
94
96
|
|
|
95
97
|
/** 设计技能:模型做界面设计时加载(DSH 的 skill 工具),也能让用户手动调 */
|
|
96
98
|
export const designSkill = {
|
|
@@ -116,6 +118,7 @@ export const skillProvider = {
|
|
|
116
118
|
// 用户的设计系统(默认用哪套、库里有哪些)每次现读,提了新的下次加载技能就知道
|
|
117
119
|
let extra = ''
|
|
118
120
|
try { extra = skillSection() } catch (e) { studio.log(e) }
|
|
121
|
+
if (studio.annotations > 0) extra += annotationSection()
|
|
119
122
|
return { name, description, whenToUse, invocation, provider, source, resourceBase, content: (await fs.promises.readFile(designSkill.locator, 'utf8')) + extra }
|
|
120
123
|
},
|
|
121
124
|
}
|
|
@@ -245,12 +248,13 @@ export const checkTool = {
|
|
|
245
248
|
const { snap, kind } = design
|
|
246
249
|
const want = sizesFrom(a.sizes, kind)
|
|
247
250
|
const b = studio.browser
|
|
251
|
+
const anAt = annotationsAt(id) // 开始量时的设计目录和标注:量的过程中换了设计也不串
|
|
248
252
|
if (b && b.available()) {
|
|
249
253
|
try {
|
|
250
254
|
const pick = pickScreens(snap, a.screens, MAX_SCREENS)
|
|
251
255
|
if (!pick.list.length) return { text: `没找到要量的屏:${pick.missing.join('、')}。现在有:${(snap.screens || []).map((x) => x.key).join('、') || snap.focus}` }
|
|
252
256
|
const sizes = want.sizes.length ? want.sizes : [await fitted(b, design, a.screens)]
|
|
253
|
-
const rows = await measureAll(b, { screens: pick.list, sizes, kind, dark: !!a.dark, locate: (items) => locateRules(studio.tracker.stateOf(id), items) })
|
|
257
|
+
const rows = await measureAll(b, { screens: pick.list, sizes, kind, dark: !!a.dark, annots: annotsByPage(anAt.ann), locate: (items) => locateRules(studio.tracker.stateOf(id), items) })
|
|
254
258
|
if (rows.some((r) => !r.error)) {
|
|
255
259
|
// 同一个会话上次量的结果:这次比一比修好了几个、新出了几个
|
|
256
260
|
const prev = lastChecks.get(id) || null
|
|
@@ -269,7 +273,7 @@ export const checkTool = {
|
|
|
269
273
|
while (lastChecks.size > 20) lastChecks.delete(lastChecks.keys().next().value)
|
|
270
274
|
if (want.bad.length) text += `\n认不出的尺寸(没量):${want.bad.join('、')},写成 375x667 或 375`
|
|
271
275
|
if (want.more) text += `\n尺寸太多,只量了前 ${MAX_SIZES} 种`
|
|
272
|
-
text += tweakNotes(id)
|
|
276
|
+
text += tweakNotes(id) + annotationNotes(anAt, rows)
|
|
273
277
|
return kept && kept.images ? { text, images: kept.images } : { text }
|
|
274
278
|
}
|
|
275
279
|
studio.log(new Error(`check_design 无头浏览器没量成:${rows[0] && rows[0].error}`))
|
|
@@ -283,10 +287,41 @@ export const checkTool = {
|
|
|
283
287
|
const note = want.sizes.length || a.dark ? '(这台电脑上没找到能用的 Chrome / Edge,没法按指定尺寸 / 深色量;下面是右侧栏按它现在显示的尺寸量的)\n' : ''
|
|
284
288
|
if (!r) return { text: '右侧栏「设计工作台」现在没开着,量不了。照 ui-design 技能里的「自查」清单自己过一遍。' }
|
|
285
289
|
if (!r.error && !r.measured) return { text: '右侧栏开着,但预览页面没回应,这次没量成(可能还在加载)。过一会儿再调一次,或照 ui-design 技能里的「自查」清单自己过一遍。' }
|
|
286
|
-
return { text: note + (r.error || r.text) + tweakNotes(id) }
|
|
290
|
+
return { text: note + (r.error || r.text) + tweakNotes(id) + annotationNotes(anAt, null) }
|
|
287
291
|
},
|
|
288
292
|
}
|
|
289
293
|
|
|
294
|
+
/** 这个会话现在的设计目录和里面的业务标注(开关关着、不是本地文件时 root 是 '') */
|
|
295
|
+
function annotationsAt(id) {
|
|
296
|
+
if (!(studio.annotations > 0)) return { root: '', ann: null }
|
|
297
|
+
try {
|
|
298
|
+
const t = studio.tracker.stateOf(id).target
|
|
299
|
+
if (t && t.kind === 'file') return { root: t.root, ann: readAnnotations(t.root) }
|
|
300
|
+
} catch (e) { studio.log(e) }
|
|
301
|
+
return { root: '', ann: null }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** 按屏分好的业务标注:无头浏览器量的时候顺手核对定位 */
|
|
305
|
+
function annotsByPage(r) {
|
|
306
|
+
if (!r || !r.list.length) return null
|
|
307
|
+
const m = new Map()
|
|
308
|
+
for (const a of r.list) { if (!m.has(a.page)) m.set(a.page, []); m.get(a.page).push({ id: a.id, selector: a.selector, fallbackText: a.fallbackText }) }
|
|
309
|
+
return m
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** 业务标注写坏的、定位不到的:check_design 末尾附上(at:开始量时的目录和标注;rows:无头浏览器量的结果,没量成是 null) */
|
|
313
|
+
function annotationNotes(at, rows) {
|
|
314
|
+
if (!at.root) return ''
|
|
315
|
+
let list = []
|
|
316
|
+
try {
|
|
317
|
+
list = lintAnnotations(at.root)
|
|
318
|
+
const r = at.ann
|
|
319
|
+
if (r && rows) list.push(...annotationFindings(r.list, rows.filter((x) => Array.isArray(x.annots)).map((x) => ({ page: x.key, list: x.annots }))))
|
|
320
|
+
else if (r && r.list.length) list.push('这次没有无头浏览器,选择器定位不到的情况没核对;右侧栏「业务标注」面板里能看到')
|
|
321
|
+
} catch (e) { studio.log(e) }
|
|
322
|
+
return list.length ? `\n\n业务标注(annotations.json):\n${list.map((x) => `- ${x}`).join('\n')}` : ''
|
|
323
|
+
}
|
|
324
|
+
|
|
290
325
|
/** 调节滑块(tweaks.json)有没有真接上:check_design 末尾附上 */
|
|
291
326
|
function tweakNotes(id) {
|
|
292
327
|
let list = []
|
|
@@ -490,7 +525,7 @@ export const handoffTool = {
|
|
|
490
525
|
if (framework === 'same' && !project.framework) return { text: `${dest} 里没有认得出的前端项目(package.json 里没有 React / Vue / Next / uni-app …,也不是 HBuilderX 或微信原生小程序的项目):framework 选 react、vue、next、html、uniapp 或 weapp。` }
|
|
491
526
|
let r
|
|
492
527
|
try {
|
|
493
|
-
r = await buildHandoff(studio.browser, { root: t.root, screens: pick.list, kind, size, framework, dest, project, system: systemOfDir(t.root) })
|
|
528
|
+
r = await buildHandoff(studio.browser, { root: t.root, screens: pick.list, kind, size, framework, dest, project, system: systemOfDir(t.root), annotations: studio.annotations > 0 ? readAnnotations(t.root) : null })
|
|
494
529
|
} catch (e) {
|
|
495
530
|
return { text: `没写成交接包:${String((e && e.message) || e).slice(0, 200)}` }
|
|
496
531
|
}
|
|
@@ -552,7 +587,7 @@ export const photoTool = {
|
|
|
552
587
|
const list = placed.map(({ p, rel }, i) => `${i + 1}. ${rel}(${ORIENT[orientOf(p.w, p.h)]} ${p.w}×${p.h})alt:${p.alt} / ${p.altEn}`)
|
|
553
588
|
return {
|
|
554
589
|
text:
|
|
555
|
-
`${broad ? `按题材找到 ${placed.length} 张(没有和「${query}」里具体画面对得上的标签,看描述合不合适再用;不合适就用 CSS / SVG 画,并告诉用户这里需要什么样的照片)` : `找到 ${placed.length} 张`},已放进 ${path.join(dir, 'assets')}:\n${list.join('\n')}\n${few}` +
|
|
590
|
+
`${broad ? `按题材找到 ${placed.length} 张(没有和「${query}」里具体画面对得上的标签,看描述合不合适再用;不合适就用 CSS / SVG 画,并告诉用户这里需要什么样的照片)` : `找到 ${placed.length} 张`},已放进 ${path.join(dir, 'assets')}:\n${list.join('\n')}\n${few}${ratioNote(placed.map((x) => x.p), ratio)}` +
|
|
556
591
|
'这是按关键词找的,先看上面的描述和需求对不对得上,对不上的别用(没用上的图不会进分享包)。\n' +
|
|
557
592
|
'用法:<img src="assets/文件名" alt="…"> 配 object-fit: cover;alt 按界面语言选一个;HTML 不在这个文件夹时改相对路径。\n' +
|
|
558
593
|
'这些是 AI 生成的示意图,不是用户真实的店铺或产品:别写「实拍」,也别把图上的场景当事实写进文案;做完告诉用户上线前换成真实照片。',
|
|
@@ -567,6 +602,29 @@ export const photoTool = {
|
|
|
567
602
|
},
|
|
568
603
|
}
|
|
569
604
|
|
|
605
|
+
/** pick_style 工具:用户没定风格时按题材挑一张风格卡(模型自己定,消费类题目总落回米色暖调;给了具体配色它照做得很好) */
|
|
606
|
+
export const styleTool = {
|
|
607
|
+
name: 'pick_style',
|
|
608
|
+
description:
|
|
609
|
+
'新做一套设计、用户没定风格时,开工前先调这个:按题材挑一张风格卡,返回整套配色、字体、圆角阴影和要点,照它定进 tokens.css。' +
|
|
610
|
+
'用户点了风格卡(消息里有〔风格〕)、自己定了具体的风格或配色、或有默认的品牌设计系统时不用调;只说「你定」「帮我推荐一个」「出几个风格挑」算没定,要调。',
|
|
611
|
+
parameters: specToJsonSchema({
|
|
612
|
+
subject: { type: 'string', required: true, description: '这次要做什么,直接写用户的原话' },
|
|
613
|
+
kind: { type: 'string', enum: ['web', 'app', 'miniprogram', 'tablet', 'desktop', 'poster', 'slides', 'email'], description: '设计类型' },
|
|
614
|
+
count: { type: 'number', description: '要几个方向,1–3,默认 1;要先出三个方向时填 3,每个方向一张不同的卡' },
|
|
615
|
+
}),
|
|
616
|
+
output: {
|
|
617
|
+
schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string' } }, required: ['text'] },
|
|
618
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
619
|
+
},
|
|
620
|
+
async execute(args) {
|
|
621
|
+
const a = args || {}
|
|
622
|
+
const subject = typeof a.subject === 'string' ? a.subject.trim() : ''
|
|
623
|
+
if (!subject) return { text: 'subject 不能空:写这次要做什么,用用户的原话。' }
|
|
624
|
+
return { text: pickStyleText(subject, typeof a.kind === 'string' ? a.kind : '', a.count) }
|
|
625
|
+
},
|
|
626
|
+
}
|
|
627
|
+
|
|
570
628
|
/** compare_design 工具:设计稿的一屏和做出来的页面按同样尺寸截图,逐像素比 */
|
|
571
629
|
export const compareTool = {
|
|
572
630
|
name: 'compare_design',
|
|
@@ -736,6 +794,7 @@ export function apply(ctx) {
|
|
|
736
794
|
log,
|
|
737
795
|
history,
|
|
738
796
|
drafts,
|
|
797
|
+
skipAnnots: () => studio.annotations > 0, // 业务标注开着时这个文件只给右侧栏看,改了不刷新页面
|
|
739
798
|
strict: { html: (buf) => library.strictHtml(buf) || market.strictHtml(buf), root: (dir) => library.strictRoot(dir) || market.isStaging(dir), versions: (dir) => library.strictVersions(dir) },
|
|
740
799
|
// 桌面版的 dsh-app://app 是默认就认的;这里补上 DSH 网页端的地址,和 DSH 配置里声明的对外地址(反向代理 / 域名)
|
|
741
800
|
parents: () => {
|
|
@@ -844,6 +903,18 @@ export function apply(ctx) {
|
|
|
844
903
|
}
|
|
845
904
|
}, 'dsh-design-studio: check')
|
|
846
905
|
|
|
906
|
+
/** 业务标注:开关开着才有这个键(null = 还没有文件)。an 是右侧栏手上那份的签名,没变就不再传一遍(一份可能上百 KB,轮询很勤) */
|
|
907
|
+
function annotsField(session, an = '') {
|
|
908
|
+
const t = tracker.stateOf(session).target
|
|
909
|
+
if (!(studio.annotations > 0) || !t || t.kind !== 'file') return {}
|
|
910
|
+
let annotations = null
|
|
911
|
+
try {
|
|
912
|
+
const r = readAnnotations(t.root)
|
|
913
|
+
annotations = r && an && r.sig === an ? { sig: r.sig, same: true } : r
|
|
914
|
+
} catch (e) { log(e) }
|
|
915
|
+
return { annotations }
|
|
916
|
+
}
|
|
917
|
+
|
|
847
918
|
function state(req, res) {
|
|
848
919
|
if (!admit(req, res)) return
|
|
849
920
|
const session = new URL(req.url, 'http://x').searchParams.get('session') || ''
|
|
@@ -854,7 +925,7 @@ export function apply(ctx) {
|
|
|
854
925
|
let tweaks = null
|
|
855
926
|
if (t && t.kind === 'file') { try { tweaks = readTweaks(t.root) } catch (e) { log(e) } }
|
|
856
927
|
const snap = tracker.snapshot(session)
|
|
857
|
-
json(res, 200, { ...snap, strict: strictScreens(snap), phone: { on: ph.on, seen: ph.seen || 0 }, tweaks, ...(c ? { checkReq: c.id } : {}) })
|
|
928
|
+
json(res, 200, { ...snap, strict: strictScreens(snap), phone: { on: ph.on, seen: ph.seen || 0 }, tweaks, ...annotsField(session, new URL(req.url, 'http://x').searchParams.get('an')), ...(c ? { checkReq: c.id } : {}) })
|
|
858
929
|
}
|
|
859
930
|
|
|
860
931
|
/** 正在看的几屏里,哪些是别人做的、没改过的(地址列表):右侧栏给它们的 iframe 加沙盒、不给剪贴板 */
|
|
@@ -988,7 +1059,7 @@ export function apply(ctx) {
|
|
|
988
1059
|
// 输入框里写的相对路径按会话目录算(新会话也问 DSH 要)
|
|
989
1060
|
const target = parseTarget(body.target, await sessionCwd(session))
|
|
990
1061
|
await tracker.setTarget(session, target, { source: 'user', popup: false })
|
|
991
|
-
json(res, 200, tracker.snapshot(session))
|
|
1062
|
+
json(res, 200, { ...tracker.snapshot(session), ...annotsField(session) })
|
|
992
1063
|
} catch (e) {
|
|
993
1064
|
json(res, 400, { error: e.message })
|
|
994
1065
|
}
|
|
@@ -1005,7 +1076,7 @@ export function apply(ctx) {
|
|
|
1005
1076
|
for (const k of ['kind', 'size', 'view', 'focus']) if (typeof body[k] === 'string') patch[k] = body[k]
|
|
1006
1077
|
try {
|
|
1007
1078
|
await tracker.setView(session, patch)
|
|
1008
|
-
json(res, 200, tracker.snapshot(session))
|
|
1079
|
+
json(res, 200, { ...tracker.snapshot(session), ...annotsField(session) })
|
|
1009
1080
|
} catch (e) {
|
|
1010
1081
|
json(res, 400, { error: e.message })
|
|
1011
1082
|
}
|
package/lib/look.js
CHANGED
|
@@ -147,7 +147,7 @@ export async function fitSize(browser, screens, kind, size) {
|
|
|
147
147
|
const RULE_PROP = { contrast: 'color', tiny: 'font-size' }
|
|
148
148
|
const MAX_RULES = 12
|
|
149
149
|
|
|
150
|
-
export async function measureAll(browser, { screens, sizes, kind, dark, fetcher = globalThis.fetch, locate = null }) {
|
|
150
|
+
export async function measureAll(browser, { screens, sizes, kind, dark, fetcher = globalThis.fetch, locate = null, annots = null }) {
|
|
151
151
|
const jobs = []
|
|
152
152
|
for (const sc of screens) for (const [w, h] of sizes) jobs.push({ sc, w, h })
|
|
153
153
|
const gone = new Map() // 地址 → Promise<是不是 404>(几屏、几种尺寸指着同一页只问一次)
|
|
@@ -185,6 +185,8 @@ export async function measureAll(browser, { screens, sizes, kind, dark, fetcher
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
// 跳转:每屏只在第一种尺寸上收一次(几种尺寸下链接一样)
|
|
188
|
+
// 业务标注定位得到吗:也只在第一种尺寸上核对(annots:屏的文件名 → 这一屏的标注;关着是 null)
|
|
189
|
+
if (i % sizes.length === 0 && annots && annots.has(sc.key)) row.annots = await page.eval(`window.__dshDesign.annots ? window.__dshDesign.annots(${JSON.stringify(annots.get(sc.key))}) : null`).catch(() => null)
|
|
188
190
|
if (i % sizes.length === 0 && fetcher) row.links = await page.eval('window.__dshDesign.links ? window.__dshDesign.links() : []').catch(() => [])
|
|
189
191
|
})
|
|
190
192
|
} catch (e) {
|
|
@@ -478,12 +480,14 @@ function metricsLine(m) {
|
|
|
478
480
|
*/
|
|
479
481
|
/** 一条问题认得出是同一个(复查时比上次修好了哪些、新出了哪些) */
|
|
480
482
|
const issueKey = (it) => `${it.type}|${it.sel}|${it.text || ''}|${it.msg || ''}|${it.src || ''}`
|
|
483
|
+
// 复查时比较用:同一个原因的叠字,叠在哪儿都算同一个
|
|
484
|
+
const compareKey = (it) => (it.type === 'overlap' && it.cause && it.cause.sel ? `overlap|cause|${it.cause.sel}|${it.cause.prop}` : issueKey(it))
|
|
481
485
|
const rowKey = (r, dark) => `${r.key}|${r.w}x${r.h}${dark ? '|dark' : ''}`
|
|
482
486
|
|
|
483
487
|
/** 这次量出来的(每屏每种尺寸一组问题),下次复查拿来比 */
|
|
484
488
|
export function issueSnapshot(rows, dark = false) {
|
|
485
489
|
const out = new Map()
|
|
486
|
-
for (const r of rows) if (!r.error) out.set(rowKey(r, dark), new Set(r.issues.map(
|
|
490
|
+
for (const r of rows) if (!r.error) out.set(rowKey(r, dark), new Set(r.issues.map(compareKey)))
|
|
487
491
|
return out
|
|
488
492
|
}
|
|
489
493
|
|
|
@@ -508,18 +512,26 @@ export function formatMeasure(rows, { sizes, where, missing = [], more = 0, dark
|
|
|
508
512
|
const failed = rows.filter((r) => r.error).length
|
|
509
513
|
// 和上次同样的屏、同样的尺寸比:修好了几个、新出了几个(新的在清单里标出来)
|
|
510
514
|
const fresh = new Set()
|
|
511
|
-
|
|
515
|
+
const gone = new Set()
|
|
516
|
+
const wasThere = new Set()
|
|
517
|
+
const unsure = new Set() // 上次有、这次这个尺寸没量成:不知道还在不在
|
|
518
|
+
const nowThere = new Set(rows.flatMap((r) => r.issues.map((it) => `${r.key}|${compareKey(it)}`)))
|
|
512
519
|
let compared = 0
|
|
513
520
|
if (prev) {
|
|
514
521
|
for (const r of rows) {
|
|
515
|
-
const before =
|
|
522
|
+
const before = prev.get(rowKey(r, dark))
|
|
516
523
|
if (!before) continue
|
|
524
|
+
for (const k of before) (r.error ? unsure : wasThere).add(`${r.key}|${k}`)
|
|
525
|
+
if (r.error) continue
|
|
517
526
|
compared++
|
|
518
|
-
const now = new Set(r.issues.map(
|
|
519
|
-
for (const k of before) if (!now.has(k))
|
|
527
|
+
const now = new Set(r.issues.map(compareKey))
|
|
528
|
+
for (const k of before) if (!now.has(k)) gone.add(`${r.key}|${k}`)
|
|
520
529
|
for (const k of now) if (!before.has(k)) fresh.add(`${r.key}|${k}`)
|
|
521
530
|
}
|
|
522
531
|
}
|
|
532
|
+
// 和「发现 N 个」同一个单位:一个问题在几种尺寸上都出现算一个。这屏别的尺寸上还在的不算修好,换了个尺寸出现的也不算新出
|
|
533
|
+
const fixed = [...gone].filter((k) => !nowThere.has(k) && !unsure.has(k)).length
|
|
534
|
+
for (const k of fresh) if (wasThere.has(k) || unsure.has(k)) fresh.delete(k)
|
|
523
535
|
const sz = sizes.map(([w, h]) => sizeText(w, h)).join('、')
|
|
524
536
|
const status = failed === rows.length
|
|
525
537
|
? '一次都没量成,这次检查没完成(原因见下)。'
|
|
@@ -557,7 +569,7 @@ export function formatMeasure(rows, { sizes, where, missing = [], more = 0, dark
|
|
|
557
569
|
let i = 0
|
|
558
570
|
for (const [k, { it, at }] of seen) {
|
|
559
571
|
if (sameCause.has(`${key}|${k}`)) continue
|
|
560
|
-
const tag = (fresh.has(`${key}|${
|
|
572
|
+
const tag = (fresh.has(`${key}|${compareKey(it)}`) ? '[新] ' : '') + (at.length < ok && mine.length > 1 ? `[${at.join('、')}] ` : '')
|
|
561
573
|
const what = [it.sel, it.text ? `「${it.text}」` : ''].filter(Boolean).join('')
|
|
562
574
|
const pic = pics.get(`${key}|${k}`)
|
|
563
575
|
const upper = pic && pic.k === `${key}|${k}` && pic.upper ? `;${pic.upper === 'self' ? `「${String(it.text || '').slice(0, 12)}」` : `「${String(it.otherText || '').slice(0, 12)}」`}画在上面` : ''
|
package/lib/photos.js
CHANGED
|
@@ -113,6 +113,15 @@ export function searchPhotos(index, opts = {}) {
|
|
|
113
113
|
return scan(index, opts).rows.slice(0, n).map((r) => r.p)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
const ORIENT_NAME = { landscape: '横图', portrait: '竖图', square: '方图' }
|
|
117
|
+
|
|
118
|
+
/** 要的比例不够、补了别的比例时照实说(每个题材横图只有四张,一套设计很容易用完) */
|
|
119
|
+
export function ratioNote(list, ratio) {
|
|
120
|
+
const off = ratio ? list.filter((p) => orientOf(p.w, p.h) !== ratio).length : 0
|
|
121
|
+
const name = ORIENT_NAME[ratio]
|
|
122
|
+
return off ? `其中 ${off} 张不是${name}(对得上又没用过的${name}不够):用 object-fit: cover 裁,看好主体别被裁掉;也可以接着用 assets 里已有的${name}。\n` : ''
|
|
123
|
+
}
|
|
124
|
+
|
|
116
125
|
/** 这次只命中了题材、没有对得上的具体画面(工具要照实告诉模型,让它看描述再决定用不用) */
|
|
117
126
|
export const onlyByTheme = (index, opts) => { const r = scan(index, opts); return r.rows.length > 0 && !r.specific }
|
|
118
127
|
|