dsh-design-studio 1.1.0 → 1.3.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
@@ -43,6 +43,7 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
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
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).
46
47
  - **Versions and compare:** every turn is saved; drag a slider to compare, and go back to any version.
47
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.
48
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.
@@ -50,6 +51,7 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
50
51
  - **Gallery, My designs, Inspiration:** three tabs on the home page. My designs has everything you've designed (and your saved frames, which you can rename or delete); Inspiration holds saved references and styles; the Gallery has templates, design systems and style cards others shared, and "Start from this" copies one for you to keep editing. Submit your own with Share › Submit to gallery: it's checked, zipped and submitted, 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.
51
52
  - **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.
52
53
  - **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.
54
+ - **Built-in font library:** click a font row in the Look panel to pick from 18 free, commercially usable fonts (Noto Sans / Serif SC, Smiley Sans, the ZCOOL family, brush and running-script calligraphy, plus Latin faces such as Inter). The page updates at once; saving copies the font files into the design folder, so exports and remote viewing keep them. You can also just ask the model, e.g. "use brush calligraphy for the headline". About 19 MB is downloaded the first time it is needed.
53
55
  - **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.
54
56
  - **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).
55
57
 
package/README.md CHANGED
@@ -43,6 +43,7 @@
43
43
  - **打开已有的页面**:首页输入框左边的「+」→「打开 HTML…」选一个,或把 HTML 文件 / 文件夹拖进右侧栏就能预览(桌面版);也能输路径或开发服务器端口。
44
44
  - **设计体检**:一键查文字溢出、对比度不够、按钮太小、字太小,问题直接标在页面上;模型做完也会自己查一遍再改。
45
45
  - **点得动的原型**:返回按钮写上 `data-back` 就「从哪来回哪去」;同一个页面的几种样子(空列表 / 有数据 / 已付款)写成状态,不用另做一屏,画布上屏名旁边就能切,体检、导出每个状态都算;共用部件在各屏写得不一样时,体检会提醒(#30)。
46
+ - **模拟数据**:说「点了要真的变、换页还在」,模型会写一份 `mock.json` 当数据源,页面绑在上面——点「接受 Offer」整个 App 切到在项、打卡后时间变了,换页、刷新都还在;阶段、角色这种全局的东西一处改所有页一起变。底部「数据」打开就是一棵数据树:随手改、一键重置、存成初始数据;HTML 演示也带着数据和「重置数据」按钮(#30)。
46
47
  - **版本和对比**:每轮自动存一版,左右拖动对比,随时回到任意一版。
47
48
  - **导出和分享**:标题栏「导出」出展示图、PDF、PPT(屏和屏之间的跳转照样能点),几百屏的设计也全部导出(最多 1000 屏);「分享」里有双击就能开的 HTML 演示(带外壳、点得动,发给客户直接看)、临时公网链接(实验,微信里点开就能看,2 小时自动关),扫码在手机上按真机尺寸看。页面比默认画幅大的幻灯片、海报,画幅自动跟页面走;也可以在类型后面跟 `宽x高` 指定,比如 `<meta name="dsh-design" content="slides 1440x810">`。导出选项里可以选版面(16:9、4:3、A3 横向、自定义)、每页取景(一屏、整页、指定高度)和每页拼 2 屏;有内容会被裁时,导出前先给一张清单,可以一键按内容改画幅。
48
49
  - **图表**:思维导图、技术路线图(申报书、开题报告那种)、产品路线图、系统架构图。连线、分叉、箭头自动排好,改字、加节点自己重排;配色跟着设计风格走,导出高清 PNG 或 PDF 贴进 Word / PPT。申报书、结题报告的框架图先帮你理清「哪个问题对应哪项内容」请你确认再画,版块之间画出带关系词的箭头;默认是立体渐变的「申报书炫酷样式」,也能照你给的参考图画。
@@ -50,6 +51,7 @@
50
51
  - **市场、我的作品、灵感**:首页顶上三个页签。以前做过的设计(还有自己存的外框,能改名、删除)在「我的作品」,收的参考图和风格在「灵感」;「市场」里逛大家分享的模板、设计系统和风格卡,点「用这个开始」复制一份接着改。自己做的从「分享」›「投稿到市场」交上去,查过打成 zip,审过就上架。市场目录从 npm 镜像取,签了名、核对过才用;不想让它联网,在插件页打开「设计库不联网」。
51
52
  - **照品牌风格做、转成代码**:给官网地址,提一套品牌设计系统,以后都照它做;做好的设计转成 React / Vue / HTML,小程序直接转成 uni-app 或原生小程序代码(HBuilderX 建的项目也认得出),逐屏和设计稿比对。
52
53
  - **自带照片库**:民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景这些靠照片说话的设计,模型会直接用上照片,不再只画插画。第一次用到时下载约 8 MB。都是 AI 生成的示意图,上线前请换成真实照片。
54
+ - **自带字体库**:外观面板里点字体那行,就能从 18 款免费可商用字体里挑(思源黑体 / 宋体、得意黑、站酷系列、毛笔楷书、行书,加上 Inter 等英文字体),页面马上换,保存后字体文件放进设计目录,导出、远程看都带着。也可以直接跟模型说「标题用毛笔字」。第一次用到时下载约 19 MB。
53
55
  - **按题材挑风格**:没定风格时,模型先按题材挑一张风格卡(配色、字体、圆角)再动手,民宿、奶茶店、复盘幻灯片不再都是一个米色调;你自己说了风格或配色就照你的。
54
56
  - **业务标注(试验,默认关)**:在「插件」页的设计工作台里打开「业务标注」,模型做设计时同时写一份 `annotations.json`,记界面上看不出来的规则、状态和边界。页面上出编号,右侧栏列卡片,点哪边都能定位到另一边;转成代码时这些规则一起交给开发(#15)。
55
57
 
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, '&amp;').replace(/"/g, '&quot;')
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(/&amp;/gi, '&')
@@ -87,24 +133,26 @@ function spriteOf(text, pre) {
87
133
  * @param opts.read (rel) → Buffer | null:读设计目录里的文件(越界、不存在、太大返回 null)
88
134
  * @param opts.tail 插在 </body> 前的东西(picker 和它的配置)
89
135
  * @param opts.lead 插在 <head> 最前面(<base> 后面)的东西:报错记录
136
+ * @param opts.onSkip (rel) → 有这个文件、但太大 / 超了上限没内联上(整套演示据此提醒缺了哪些)
137
+ * @param opts.max 这一屏内联的总量上限(默认 MAX_TOTAL:远程看一屏一屏传;整套演示几屏共用一份,给得多些)
90
138
  * @param opts.base 这一屏原来的地址:放一个 <base>,没内联上的相对地址照原样指过去(不指到 DSH 网页上)
91
139
  * @returns string
92
140
  */
93
- export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
94
- let budget = MAX_TOTAL
95
- let readLeft = MAX_READ
141
+ export function bundle(html, { key, read, tail = '', base = '', lead = '', max = MAX_TOTAL, onSkip = null }) {
142
+ let budget = max
143
+ let readLeft = max === MAX_TOTAL ? MAX_READ : 2 * max
96
144
  const cache = new Map()
97
145
  const get = (rel) => {
98
146
  if (cache.has(rel)) return cache.get(rel)
99
147
  let buf = null
100
- if (readLeft > 0) { try { buf = read(rel) } catch { buf = null } }
101
- if (buf && buf.length > Math.min(MAX_TOTAL, readLeft)) buf = null
148
+ if (readLeft > 0) { try { buf = read(rel) } catch { buf = null } } else if (onSkip) onSkip(rel)
149
+ if (buf && buf.length > Math.min(max, readLeft)) { buf = null; if (onSkip) onSkip(rel) }
102
150
  if (buf) readLeft -= buf.length
103
151
  cache.set(rel, buf)
104
152
  return buf
105
153
  }
106
- /** 花预算:够就扣掉 */
107
- const spend = (n) => { if (n > budget) return false; budget -= n; return true }
154
+ /** 花预算:够就扣掉;不够的告诉调用方(rel:哪个文件没放进去) */
155
+ const spend = (n, rel) => { if (n > budget) { if (onSkip && rel) onSkip(rel); return false } budget -= n; return true }
108
156
  const typeOf = (rel) => {
109
157
  const t = (MIME[path.posix.extname(rel).toLowerCase()] || 'application/octet-stream').replace(/;.*/, '')
110
158
  return /^text\//.test(t) ? `${t};charset=utf-8` : t
@@ -116,7 +164,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
116
164
  if (!buf) return ''
117
165
  let d = encoded.get(rel)
118
166
  if (!d) { d = `data:${typeOf(rel)};base64,${buf.toString('base64')}`; encoded.set(rel, d) }
119
- return spend(d.length) ? d : ''
167
+ return spend(d.length, rel) ? d : ''
120
168
  }
121
169
  const dataUrl = (from, url) => {
122
170
  const ref = localRef(url)
@@ -129,7 +177,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
129
177
  if (!ref || depth >= MAX_DEPTH) return m
130
178
  const rel = join(from, ref)
131
179
  const buf = get(rel)
132
- if (!buf || !spend(buf.length)) return m
180
+ if (!buf || !spend(buf.length, rel)) return m
133
181
  const inner = css(buf.toString('utf8').replace(/^\ufeff/, ''), rel, depth + 1)
134
182
  return media.trim() ? `@media ${media.trim()}{${inner}}` : inner
135
183
  })
@@ -160,7 +208,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
160
208
  return `${pre}${q}${absOf(dep)}${q}`
161
209
  }) + `\n//# sourceURL=${abs}\n` // 每个文件一个 data:(内容一样的两个文件也是两个模块),报错时也看得出是哪个文件
162
210
  const d = `data:text/javascript;charset=utf-8;base64,${Buffer.from(text).toString('base64')}`
163
- if (!spend(d.length)) { mods.delete(abs); return '' }
211
+ if (!spend(d.length, rel)) { mods.delete(abs); return '' }
164
212
  mods.set(abs, d)
165
213
  return d
166
214
  }
@@ -169,7 +217,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
169
217
 
170
218
  let out = String(html)
171
219
  // 样式表:<link rel="stylesheet" href="x.css"> → <style>
172
- .replace(/<link\b[^>]*>/gi, (tag) => {
220
+ .replace(/<link\b(?:[^>"']|"[^"]*"|'[^']*')*>/gi, (tag) => {
173
221
  if (!/\brel\s*=\s*["']?[^"'>]*stylesheet/i.test(tag)) {
174
222
  // 图标之类的 <link href> 换成 data:
175
223
  return tag.replace(/(\bhref\s*=\s*)(["'])([^"']*)\2/i, (m, a, q, u) => `${a}${q}${escAttr(dataUrl(key, u))}${q}`)
@@ -180,12 +228,12 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
180
228
  if (!ref) return tag
181
229
  const rel = join(key, ref)
182
230
  const buf = get(rel)
183
- if (!buf || !spend(buf.length)) return tag
231
+ if (!buf || !spend(buf.length, rel)) return tag
184
232
  const media = /\bmedia\s*=\s*(["'])([^"']*)\1/i.exec(tag)
185
233
  return `<style data-href="${escAttr(href)}"${media ? ` media="${escAttr(media[2])}"` : ''}>${css(buf.toString('utf8').replace(/^\ufeff/, ''), rel).replace(/<\/style/gi, '<\\/style')}</style>`
186
234
  })
187
235
  // 页面里的 <style>:url() 相对这一屏
188
- .replace(/(<style\b[^>]*>)([\s\S]*?)(<\/style\s*>)/gi, (m, a, body, b) => (/\bdata-href=/.test(a) ? m : a + css(body, key) + b))
236
+ .replace(/(<style\b(?:[^>"']|"[^"]*"|'[^']*')*>)([\s\S]*?)(<\/style\s*>)/gi, (m, a, body, b) => (/\bdata-href=/.test(a) ? m : a + css(body, key) + b))
189
237
  // 脚本:本地的经典脚本换成 src="data:…"(defer、async、执行顺序都和原来一样);模块见上
190
238
  .replace(/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi, (m, attrs, body) => {
191
239
  const s = /\bsrc\s*=\s*(["'])([^"']*)\1/i.exec(attrs) || /\bsrc\s*=\s*([^\s>"']+)/i.exec(attrs)
@@ -204,7 +252,9 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
204
252
  })
205
253
  // 图片、视频、音频、SVG 里的 image
206
254
  // 原来的 src 留在 data-dsh-src(体检比外框指纹时按它:换了张图也认得出)
207
- .replace(/(<(?:img|source|video|audio|input|image|embed|track)\b[^>]*>)/gi, (tag0) => {
255
+ // 属性值里的 > 不算标签结束(<source media="(width >= 900px)" srcset=…>);跳过 HTML 注释,避免注释掉的旧图吃掉预算
256
+ .replace(/<!--[\s\S]*?-->|(<(?:img|source|video|audio|input|image|embed|track)\b(?:[^>"']|"[^"]*"|'[^']*')*>)/gi, (all, tag0) => {
257
+ if (!tag0) return all
208
258
  let orig = null
209
259
  let origSet = null
210
260
  const tag = tag0
@@ -238,7 +288,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
238
288
  const buf = get(rel)
239
289
  const pre = `dsh${sprites.size + 1}-`
240
290
  const text = buf ? spriteOf(buf.toString('utf8').replace(/^\ufeff/, '').replace(/<\?xml[\s\S]*?\?>|<!DOCTYPE[^>]*>/gi, '').trim(), pre) : ''
241
- if (!/^<svg\b/i.test(text) || !spend(text.length)) return m
291
+ if (!/^<svg\b/i.test(text) || !spend(text.length, rel)) return m
242
292
  sprites.set(rel, { pre, text })
243
293
  }
244
294
  let id = u.slice(i + 1)