dsh-design-studio 1.0.2 → 1.2.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 +2 -0
- package/README.md +2 -0
- package/lib/browser.js +4 -1
- package/lib/bundle.js +46 -0
- package/lib/canvthumb.js +5 -3
- package/lib/client.js +726 -90
- package/lib/core.js +7 -0
- package/lib/drift.js +222 -0
- package/lib/gallery/pack.js +4 -2
- package/lib/handoff.js +61 -0
- package/lib/htmlpack.js +146 -36
- package/lib/index.js +154 -18
- package/lib/look.js +28 -8
- package/lib/mock.js +793 -0
- package/lib/picker.js +142 -16
- package/lib/serve.js +47 -9
- package/lib/states.js +148 -0
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +19 -2
package/README.en.md
CHANGED
|
@@ -42,6 +42,8 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
|
|
|
42
42
|
- **Click to edit:** click an element or drag over an area, and a small chip lands in the input (hover it for details); just add how to change it. Markup, style changes, style cards and check lists land as chips too, not walls of text. The model still gets the full location and styles. Changed spots flash in the preview. You can also draw circles, arrows and notes right on the page and hand the marked-up screenshot to the model, or copy it to paste elsewhere. Adjust style can apply a change to every screen at once, and when you edit a design by hand in the sidebar, the model is told before its next step so it won't undo your edits.
|
|
43
43
|
- **Open what you have:** home + › Open HTML… picks an HTML file, or drop an HTML file or folder onto the sidebar (desktop app); you can also type a path or a dev-server port.
|
|
44
44
|
- **Design check:** one click finds overflowing text, low contrast, small tap targets and tiny text, marked right on the page. In Design mode the model also checks its own work and fixes what it finds.
|
|
45
|
+
- **Clickable prototypes:** back arrows marked `data-back` go back to wherever you came from; the different looks of one page (empty list, with data, paid) are states in one file instead of extra screens, switchable next to the screen name on the canvas, and checked and exported state by state. The design check also points out a shared part that is styled differently on different screens (#30).
|
|
46
|
+
- **Mock data:** ask for a prototype whose clicks really change things and survive page changes, and the model writes `mock.json` as the data source and binds the pages to it: "Accept offer" switches the whole app to its on-site stage, clocking in updates the time, and it all stays across pages and reloads; a global stage or role changes every page at once. **Data** in the bottom bar opens the data as a tree: edit any value, reset it, or save it as the initial data. The HTML demo carries the data too, with a Reset data button (#30).
|
|
45
47
|
- **Versions and compare:** every turn is saved; drag a slider to compare, and go back to any version.
|
|
46
48
|
- **Export and share:** Export makes showcase images, PDF and PowerPoint (links between screens still work), and designs with hundreds of screens export in full (up to 1000). Share has a clickable HTML demo that opens with a double-click (device frame included, ready to send to a client), a temporary public link (beta; opens in WeChat or any browser, closes after 2 hours), and 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.
|
|
47
49
|
- **Diagrams:** mind maps, technical route charts (the kind in grant proposals and theses), product roadmaps and system architecture diagrams. Lines, branches and arrows are laid out for you and re-flow when you change text or add nodes; colors follow the design style, and a high-resolution PNG or PDF export drops straight into Word or PowerPoint. For grant-proposal and final-report frameworks, the model first lists how the parts relate (which problem maps to which task) for you to confirm, then draws labelled arrows between the blocks, in a bold 3D-gradient "proposal" style by default or after a reference image you give it.
|
package/README.md
CHANGED
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
- **点一下就改**:点元素或框一块区域,输入框里出现一个小标签(悬停看详情),你只要补一句怎么改;标注、调样式、风格、体检清单这些放进输入框的也都是小标签,不再是一大段字;发出去模型拿到完整的位置和样式。改过的地方在预览里闪一下。也能直接在页面上画圈、画箭头、写字,拼成一张图交给模型,或者复制下来贴到别处。调样式可以「各屏一起改」;你在右侧栏亲手改过的地方,模型下一步会先知道,不会改回去。
|
|
43
43
|
- **打开已有的页面**:首页输入框左边的「+」→「打开 HTML…」选一个,或把 HTML 文件 / 文件夹拖进右侧栏就能预览(桌面版);也能输路径或开发服务器端口。
|
|
44
44
|
- **设计体检**:一键查文字溢出、对比度不够、按钮太小、字太小,问题直接标在页面上;模型做完也会自己查一遍再改。
|
|
45
|
+
- **点得动的原型**:返回按钮写上 `data-back` 就「从哪来回哪去」;同一个页面的几种样子(空列表 / 有数据 / 已付款)写成状态,不用另做一屏,画布上屏名旁边就能切,体检、导出每个状态都算;共用部件在各屏写得不一样时,体检会提醒(#30)。
|
|
46
|
+
- **模拟数据**:说「点了要真的变、换页还在」,模型会写一份 `mock.json` 当数据源,页面绑在上面——点「接受 Offer」整个 App 切到在项、打卡后时间变了,换页、刷新都还在;阶段、角色这种全局的东西一处改所有页一起变。底部「数据」打开就是一棵数据树:随手改、一键重置、存成初始数据;HTML 演示也带着数据和「重置数据」按钮(#30)。
|
|
45
47
|
- **版本和对比**:每轮自动存一版,左右拖动对比,随时回到任意一版。
|
|
46
48
|
- **导出和分享**:标题栏「导出」出展示图、PDF、PPT(屏和屏之间的跳转照样能点),几百屏的设计也全部导出(最多 1000 屏);「分享」里有双击就能开的 HTML 演示(带外壳、点得动,发给客户直接看)、临时公网链接(实验,微信里点开就能看,2 小时自动关),扫码在手机上按真机尺寸看。页面比默认画幅大的幻灯片、海报,画幅自动跟页面走;也可以在类型后面跟 `宽x高` 指定,比如 `<meta name="dsh-design" content="slides 1440x810">`。导出选项里可以选版面(16:9、4:3、A3 横向、自定义)、每页取景(一屏、整页、指定高度)和每页拼 2 屏;有内容会被裁时,导出前先给一张清单,可以一键按内容改画幅。
|
|
47
49
|
- **图表**:思维导图、技术路线图(申报书、开题报告那种)、产品路线图、系统架构图。连线、分叉、箭头自动排好,改字、加节点自己重排;配色跟着设计风格走,导出高清 PNG 或 PDF 贴进 Word / PPT。申报书、结题报告的框架图先帮你理清「哪个问题对应哪项内容」请你确认再画,版块之间画出带关系词的箭头;默认是立体渐变的「申报书炫酷样式」,也能照你给的参考图画。
|
package/lib/browser.js
CHANGED
|
@@ -223,7 +223,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
|
|
|
223
223
|
* allow(网址):给了就只让它说行的页面载入(主页面、iframe,连跳转、脚本改地址都算),别的拦下,记在 page.blocked
|
|
224
224
|
* offline:断网渲染(设计库的检查):所有请求(样式、图片、字体、接口 …)只放行和页面同源的,别的一律拦下,记在 page.blocked
|
|
225
225
|
*/
|
|
226
|
-
async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false, linger = idleMs }, fn) {
|
|
226
|
+
async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false, linger = idleMs, store = false }, fn) {
|
|
227
227
|
if (dead) throw new Error('browser closed')
|
|
228
228
|
if (open >= MAX_PAGES) await new Promise((r) => queue.push(r))
|
|
229
229
|
if (dead) throw new Error('browser closed')
|
|
@@ -254,6 +254,9 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
|
|
|
254
254
|
await c('Fetch.enable', { patterns: offline ? [{ urlPattern: '*', requestStage: 'Request' }] : [{ urlPattern: '*', resourceType: 'Document', requestStage: 'Request' }] })
|
|
255
255
|
}
|
|
256
256
|
await c('Page.enable')
|
|
257
|
+
// 告诉页面这是无头浏览器在量 / 截图(设计台的模拟数据只放内存、不存:同一个浏览器里开的几屏互不串,量的都是初始数据)。
|
|
258
|
+
// store:要像真人那样存(测整套演示跨屏保留时)
|
|
259
|
+
if (!store) await c('Page.addScriptToEvaluateOnNewDocument', { source: 'window.__dshHeadless=1' }).catch(() => {})
|
|
257
260
|
// 和右侧栏里一样按桌面方式排版(mobile: false):页面宽就是 w,不看 <meta viewport>
|
|
258
261
|
await c('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: scale, mobile: false })
|
|
259
262
|
await c('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: dark ? 'dark' : 'light' }, { name: 'prefers-reduced-motion', value: 'reduce' }] })
|
package/lib/bundle.js
CHANGED
|
@@ -32,6 +32,52 @@ function join(base, ref) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const escAttr = (s) => String(s).replace(/&/g, '&').replace(/"/g, '"')
|
|
35
|
+
|
|
36
|
+
const DATA_IMG = /\.(png|jpe?g|gif|webp|avif|bmp|ico|svg)$/i
|
|
37
|
+
/**
|
|
38
|
+
* 模拟数据(#30)里写的本地图片(「avatar": "img/me.png",页面用 data-mock-attr 绑到 src):打成单个文件时要换成 data: 地址,
|
|
39
|
+
* 不然演示里是坏图。数据本身不改(同一个字段拿来显示文件名还是文件名):回 { f: 真实路径 → data: 地址, r: 数据里写的那串 → 真实路径 },
|
|
40
|
+
* 运行时设 src / href 这类地址时查表。地址从设计目录根算;读不到的不进表(预览里本来也是坏的)。
|
|
41
|
+
* 同一张图(img/a.jpg、./img/a.jpg 写法不同也算)只放一份、只算一次大小。
|
|
42
|
+
* over:有这个文件、但太大换不下的放进这里(调用方据此报错,不能悄悄留个坏图);
|
|
43
|
+
* isBig(rel):read 给了 null 是因为文件太大(不是没有)——这种也算换不下
|
|
44
|
+
*/
|
|
45
|
+
export function dataAssets(data, read, max = 8 * 1024 * 1024, over = null, isBig = null) {
|
|
46
|
+
let left = max
|
|
47
|
+
let nodes = 0
|
|
48
|
+
const done = new Map() // 相对路径 → data: 地址(换不下 / 没有:'')
|
|
49
|
+
const f = {}
|
|
50
|
+
const r = {}
|
|
51
|
+
const one = (s) => {
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(r, s)) return
|
|
53
|
+
const ref = localRef(s)
|
|
54
|
+
if (!ref || !DATA_IMG.test(ref)) return
|
|
55
|
+
const rel = join('_', ref)
|
|
56
|
+
if (rel.startsWith('..')) return
|
|
57
|
+
if (!done.has(rel)) {
|
|
58
|
+
let buf = null
|
|
59
|
+
try { buf = read(rel) } catch { buf = null }
|
|
60
|
+
let d = ''
|
|
61
|
+
if (buf && buf.length * 1.4 < left) {
|
|
62
|
+
const ext = path.posix.extname(rel).toLowerCase()
|
|
63
|
+
const t = (MIME[ext] || (ext === '.bmp' ? 'image/bmp' : 'application/octet-stream')).replace(/;.*/, '')
|
|
64
|
+
d = `data:${t};base64,${buf.toString('base64')}`
|
|
65
|
+
left -= d.length
|
|
66
|
+
} else if (over && (buf || (isBig && isBig(rel)))) over.push(rel)
|
|
67
|
+
done.set(rel, d)
|
|
68
|
+
}
|
|
69
|
+
const d = done.get(rel)
|
|
70
|
+
if (d) { f[rel] = d; r[s] = rel }
|
|
71
|
+
}
|
|
72
|
+
const walk = (v, depth) => {
|
|
73
|
+
if (++nodes > 20000 || depth > 40) return
|
|
74
|
+
if (typeof v === 'string') { if (v.length < 600) one(v); return }
|
|
75
|
+
if (Array.isArray(v)) { for (const x of v) walk(x, depth + 1); return }
|
|
76
|
+
if (v && typeof v === 'object') for (const k of Object.keys(v)) walk(v[k], depth + 1)
|
|
77
|
+
}
|
|
78
|
+
walk(data, 0)
|
|
79
|
+
return { f, r }
|
|
80
|
+
}
|
|
35
81
|
const escScript = (s) => String(s).replace(/<\/(script)/gi, '<\\/$1').replace(/<!--/g, '<\\!--')
|
|
36
82
|
/** 属性值里的实体解回来(只管引号和 &,style 里用得到的就这些) */
|
|
37
83
|
const unAttr = (s) => String(s).replace(/&(quot|#0*34|#x0*22);/gi, '"').replace(/&(apos|#0*39|#x0*27);/gi, "'").replace(/&/gi, '&')
|
package/lib/canvthumb.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 画布上睡着的屏的缩略图(issue #17):屏多时画布只挂离镜头近的 LIVE_MAX 屏,别的屏先放一张无头浏览器截的图,挪近了再换成真页面。
|
|
3
3
|
*
|
|
4
|
-
* GET scrthumb ?session=&root=&key=&w=&h=&dark= → JPEG
|
|
4
|
+
* GET scrthumb ?session=&root=&key=&w=&h=&dark=&state= → JPEG(state:一页多状态 #30,画布上这屏切到的状态)(取不到 404 / 503,页面上照旧显示「挪近就加载」)。响应头:
|
|
5
5
|
* X-Dsh-Title 页面标题;X-Dsh-Thumb 这张图的名字(同一张页面就不换);X-Dsh-Recheck 目录没在监听(改了不会通知)时,过几秒再来要
|
|
6
6
|
* GET verthumb ?session=&n=&key=&w=&h=&dark= → 旧版本里某一屏的 JPEG(1.0 版本面板的卡片)。存下的版本不会再变,按「版本号 + 存的时间」缓存,不用看文件
|
|
7
7
|
*
|
|
@@ -17,6 +17,7 @@ import fs from 'node:fs'
|
|
|
17
17
|
import os from 'node:os'
|
|
18
18
|
import path from 'node:path'
|
|
19
19
|
import { prepare } from './look.js'
|
|
20
|
+
import { STATE_RE, withState } from './states.js'
|
|
20
21
|
|
|
21
22
|
export const THUMB_DIR = path.join(os.homedir(), '.dsh', 'cache', 'dsh-design-studio', 'canvas')
|
|
22
23
|
const WIDTH = 480 // 截出来最宽多少像素:睡着的屏都是缩得很小的时候看的
|
|
@@ -211,7 +212,7 @@ export function createCanvasThumbs({ tracker, browser, trust = () => '', strictR
|
|
|
211
212
|
|
|
212
213
|
/** 这屏的缩略图 { file, title }(要截就排队)。onLeave 交出「这个请求不等了」的回调 */
|
|
213
214
|
function thumb(o, onLeave) {
|
|
214
|
-
const id = sha1([path.resolve(o.root), o.key, o.w, o.h, o.dark ? 1 : 0, ...(o.v ? [`v${o.v}@${o.at}`] : [])].join('\0')).slice(0, 20)
|
|
215
|
+
const id = sha1([path.resolve(o.root), o.key, o.w, o.h, o.dark ? 1 : 0, ...(o.v ? [`v${o.v}@${o.at}`] : []), ...(o.state ? [`s:${o.state}`] : [])].join('\0')).slice(0, 20)
|
|
215
216
|
const stamp = o.v ? 'v' : stampOf(o) // 文件没了这里就抛
|
|
216
217
|
const file = path.join(dir, `${id}-${stamp}.jpg`)
|
|
217
218
|
if (fs.existsSync(file)) return Promise.resolve({ file, title: titleOf(file) })
|
|
@@ -249,6 +250,7 @@ export function createCanvasThumbs({ tracker, browser, trust = () => '', strictR
|
|
|
249
250
|
if (t.root !== root) return json(res, 404, { error: 'design changed' })
|
|
250
251
|
const sc = (snap.screens || []).find((x) => x.key === key)
|
|
251
252
|
if (!sc || !HTML_RE.test(key)) return json(res, 404, { error: 'no such screen' })
|
|
253
|
+
const state = STATE_RE.test(q.get('state') || '') ? q.get('state') : ''
|
|
252
254
|
const b = browser()
|
|
253
255
|
if (!b || !b.available()) return json(res, 503, { error: 'no browser' })
|
|
254
256
|
let got
|
|
@@ -256,7 +258,7 @@ export function createCanvasThumbs({ tracker, browser, trust = () => '', strictR
|
|
|
256
258
|
try {
|
|
257
259
|
// 先整张读进来再回:拿到路径和读之间,这张可能刚被同一屏的新图顶掉删了,那就再要一次(这回给的是新的)
|
|
258
260
|
for (let i = 0; i < 2 && !buf; i++) {
|
|
259
|
-
got = await thumb({ root: t.root, key, url: sc.url, w, h, dark: q.get('dark') === '1' }, (leave) => res.on('close', leave))
|
|
261
|
+
got = await thumb({ root: t.root, key, url: state ? withState(sc.url, state) : sc.url, state, w, h, dark: q.get('dark') === '1' }, (leave) => res.on('close', leave))
|
|
260
262
|
try { buf = await fs.promises.readFile(got.file) } catch (e) { if (e.code !== 'ENOENT') throw e }
|
|
261
263
|
}
|
|
262
264
|
} catch (e) {
|