dsh-design-studio 1.4.1 → 2.0.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.
Files changed (197) hide show
  1. package/README.en.md +11 -10
  2. package/README.md +17 -16
  3. package/THIRD_PARTY_NOTICES.md +108 -0
  4. package/assets/art/README.md +102 -0
  5. package/assets/art/brand-mark.webp +0 -0
  6. package/assets/art/check-clean.webp +0 -0
  7. package/assets/art/coach-markup.webp +0 -0
  8. package/assets/art/drop-file.webp +0 -0
  9. package/assets/art/empty-components.webp +0 -0
  10. package/assets/art/empty-data.webp +0 -0
  11. package/assets/art/empty-error.webp +0 -0
  12. package/assets/art/empty-frames.webp +0 -0
  13. package/assets/art/empty-history.webp +0 -0
  14. package/assets/art/empty-market.webp +0 -0
  15. package/assets/art/empty-notes.webp +0 -0
  16. package/assets/art/empty-search.webp +0 -0
  17. package/assets/art/empty-tokens.webp +0 -0
  18. package/assets/art/empty-works.webp +0 -0
  19. package/assets/art/guide-icon.webp +0 -0
  20. package/assets/art/kind-app.webp +0 -0
  21. package/assets/art/kind-desktop.webp +0 -0
  22. package/assets/art/kind-diagram.webp +0 -0
  23. package/assets/art/kind-dshplugin.webp +0 -0
  24. package/assets/art/kind-email.webp +0 -0
  25. package/assets/art/kind-embedded.webp +0 -0
  26. package/assets/art/kind-framed.webp +0 -0
  27. package/assets/art/kind-miniprogram.webp +0 -0
  28. package/assets/art/kind-poster.webp +0 -0
  29. package/assets/art/kind-slides.webp +0 -0
  30. package/assets/art/kind-tablet.webp +0 -0
  31. package/assets/art/kind-web.webp +0 -0
  32. package/assets/art/placeholder-inspire-img.webp +0 -0
  33. package/assets/art/wait-creating.webp +0 -0
  34. package/assets/motion/ai-capsule.html +124 -0
  35. package/assets/motion/ai-glow-input.html +112 -0
  36. package/assets/motion/balance-odometer.html +112 -0
  37. package/assets/motion/bottom-sheet.html +149 -0
  38. package/assets/motion/brightness-pill.html +114 -0
  39. package/assets/motion/comet-ring.html +95 -0
  40. package/assets/motion/copy-morph.html +116 -0
  41. package/assets/motion/cube-grid.html +103 -0
  42. package/assets/motion/day-night.html +120 -0
  43. package/assets/motion/dial-knob.html +130 -0
  44. package/assets/motion/dock-magnify.html +118 -0
  45. package/assets/motion/download-ring.html +135 -0
  46. package/assets/motion/expand-card.html +137 -0
  47. package/assets/motion/flip-card.html +100 -0
  48. package/assets/motion/hold-pay.html +137 -0
  49. package/assets/motion/holo-card.html +130 -0
  50. package/assets/motion/keycap.html +92 -0
  51. package/assets/motion/like-jelly.html +88 -0
  52. package/assets/motion/liquid-progress.html +113 -0
  53. package/assets/motion/liquid-segment.html +127 -0
  54. package/assets/motion/live-capsule.html +144 -0
  55. package/assets/motion/marker-highlight.html +94 -0
  56. package/assets/motion/marquee-logos.html +110 -0
  57. package/assets/motion/otp-code.html +111 -0
  58. package/assets/motion/password-eye.html +136 -0
  59. package/assets/motion/ruler-slider.html +140 -0
  60. package/assets/motion/search-expand.html +81 -0
  61. package/assets/motion/send-fly.html +121 -0
  62. package/assets/motion/skeleton-shine.html +124 -0
  63. package/assets/motion/star-rate.html +98 -0
  64. package/assets/motion/success-check.html +114 -0
  65. package/assets/motion/suggest-chips.html +134 -0
  66. package/assets/motion/swipe-row.html +126 -0
  67. package/assets/motion/tabbar-bounce.html +92 -0
  68. package/assets/motion/tactile-controls.html +89 -0
  69. package/assets/motion/text-scramble.html +173 -0
  70. package/assets/motion/toast-stack.html +115 -0
  71. package/assets/motion/token-stream.html +106 -0
  72. package/assets/motion/voice-orb.html +144 -0
  73. package/assets/showcase/alley-noodles-1.webp +0 -0
  74. package/assets/showcase/alley-noodles-2.webp +0 -0
  75. package/assets/showcase/alley-noodles-3.webp +0 -0
  76. package/assets/showcase/autumn-sale-1.webp +0 -0
  77. package/assets/showcase/bold-folio-1.webp +0 -0
  78. package/assets/showcase/bold-folio-2.webp +0 -0
  79. package/assets/showcase/book-club-1.webp +0 -0
  80. package/assets/showcase/book-club-2.webp +0 -0
  81. package/assets/showcase/book-club-3.webp +0 -0
  82. package/assets/showcase/flower-order-1.webp +0 -0
  83. package/assets/showcase/little-painter-1.webp +0 -0
  84. package/assets/showcase/little-painter-2.webp +0 -0
  85. package/assets/showcase/moon-fair-1.webp +0 -0
  86. package/assets/showcase/nail-booking-1.webp +0 -0
  87. package/assets/showcase/nail-booking-2.webp +0 -0
  88. package/assets/showcase/nail-booking-3.webp +0 -0
  89. package/assets/showcase/night-run-1.webp +0 -0
  90. package/assets/showcase/paw-diary-1.webp +0 -0
  91. package/assets/showcase/paw-diary-2.webp +0 -0
  92. package/assets/showcase/paw-diary-3.webp +0 -0
  93. package/assets/showcase/pixel-planet-1.webp +0 -0
  94. package/assets/showcase/pixel-planet-2.webp +0 -0
  95. package/assets/showcase/pixel-planet-3.webp +0 -0
  96. package/assets/showcase/pocket-ledger-1.webp +0 -0
  97. package/assets/showcase/pocket-ledger-2.webp +0 -0
  98. package/assets/showcase/shiftloom-1.webp +0 -0
  99. package/assets/showcase/shiftloom-2.webp +0 -0
  100. package/assets/showcase/slow-breath-1.webp +0 -0
  101. package/assets/showcase/slow-breath-2.webp +0 -0
  102. package/assets/showcase/slow-breath-3.webp +0 -0
  103. package/assets/showcase/slow-trip-1.webp +0 -0
  104. package/assets/showcase/slow-trip-2.webp +0 -0
  105. package/assets/showcase/slow-trip-3.webp +0 -0
  106. package/assets/showcase/slow-weekly-1.webp +0 -0
  107. package/assets/showcase/stay-confirm-1.webp +0 -0
  108. package/assets/showcase/stove-recipes-1.webp +0 -0
  109. package/assets/showcase/stove-recipes-2.webp +0 -0
  110. package/assets/showcase/strobewatch-1.webp +0 -0
  111. package/assets/showcase/strobewatch-2.webp +0 -0
  112. package/assets/showcase/tapeworks-1.webp +0 -0
  113. package/assets/showcase/tapeworks-2.webp +0 -0
  114. package/assets/showcase/tea-brand-pitch-1.webp +0 -0
  115. package/assets/showcase/tea-brand-pitch-2.webp +0 -0
  116. package/assets/showcase/tea-brand-pitch-3.webp +0 -0
  117. package/assets/showcase/time-bookshop-1.webp +0 -0
  118. package/assets/showcase/time-bookshop-2.webp +0 -0
  119. package/assets/showcase/water-journey-1.webp +0 -0
  120. package/assets/showcase/water-journey-2.webp +0 -0
  121. package/assets/showcase/water-journey-3.webp +0 -0
  122. package/assets/showcase/weekend-go-1.webp +0 -0
  123. package/assets/showcase/weekend-go-2.webp +0 -0
  124. package/assets/showcase/weekend-go-3.webp +0 -0
  125. package/assets/showcase/winter-soup-1.webp +0 -0
  126. package/assets/showcase/year-review-1.webp +0 -0
  127. package/assets/showcase/year-review-2.webp +0 -0
  128. package/assets/showcase/year-review-3.webp +0 -0
  129. package/lib/annotations.js +1 -1
  130. package/lib/browser.js +3 -1
  131. package/lib/bundle.js +8 -3
  132. package/lib/canvthumb.js +9 -6
  133. package/lib/client.js +7623 -2788
  134. package/lib/components.js +4 -2
  135. package/lib/core.js +763 -133
  136. package/lib/design-page-settings.js +48 -0
  137. package/lib/design-scope.js +36 -0
  138. package/lib/design-transactions.js +259 -0
  139. package/lib/drop-folder.js +25 -0
  140. package/lib/edits.js +125 -8
  141. package/lib/embedded/lvgl_shot.c +133 -0
  142. package/lib/embedded/qml_shot.py +66 -0
  143. package/lib/embedded-shot.js +400 -0
  144. package/lib/embedded-trust.js +76 -0
  145. package/lib/fonts.js +30 -21
  146. package/lib/frames.js +23 -23
  147. package/lib/gallery/css.js +9 -2
  148. package/lib/gallery/market-routes.js +23 -7
  149. package/lib/gallery/pack.js +25 -8
  150. package/lib/gallery/policy.js +6 -4
  151. package/lib/gallery/routes.js +255 -83
  152. package/lib/gallery/submit.js +285 -57
  153. package/lib/gallery/use.js +13 -4
  154. package/lib/handoff-embedded.js +1182 -0
  155. package/lib/handoff.js +212 -71
  156. package/lib/history.js +393 -43
  157. package/lib/htmlpack.js +35 -14
  158. package/lib/impl.js +3 -0
  159. package/lib/index.js +662 -137
  160. package/lib/inspire.js +73 -26
  161. package/lib/kinds.js +11 -2
  162. package/lib/look.js +45 -25
  163. package/lib/mock.js +41 -4
  164. package/lib/motion.js +90 -0
  165. package/lib/page-settings.js +103 -0
  166. package/lib/picker.js +348 -70
  167. package/lib/rules.js +85 -0
  168. package/lib/serve.js +154 -15
  169. package/lib/showcase.json +22 -0
  170. package/lib/styles.js +16 -7
  171. package/lib/system.js +19 -8
  172. package/lib/tool.js +2 -1
  173. package/lib/tweaks.js +146 -9
  174. package/lib/works.js +151 -19
  175. package/locale/annotations/en.json +2 -2
  176. package/locale/annotations/zh.json +2 -2
  177. package/locale/auto/en.json +1 -1
  178. package/locale/auto/zh.json +1 -1
  179. package/locale/en.json +1 -1
  180. package/locale/offline/en.json +1 -1
  181. package/locale/offline/zh.json +2 -2
  182. package/locale/tool/zh.json +1 -1
  183. package/locale/zh.json +1 -1
  184. package/package.json +3 -2
  185. package/skills/ui-design/SKILL.md +59 -47
  186. package/skills/ui-design/frames/dsh/frame.json +1 -1
  187. package/skills/ui-design/references/app.md +29 -2
  188. package/skills/ui-design/references/components.md +1 -1
  189. package/skills/ui-design/references/desktop.md +1 -1
  190. package/skills/ui-design/references/dshplugin.md +12 -12
  191. package/skills/ui-design/references/embedded.md +40 -0
  192. package/skills/ui-design/references/frames.md +20 -20
  193. package/skills/ui-design/references/miniprogram.md +2 -2
  194. package/skills/ui-design/references/mock.md +16 -0
  195. package/skills/ui-design/references/poster.md +2 -1
  196. package/skills/ui-design/references/tweaks.md +17 -0
  197. package/skills/ui-design/tokens.css +19 -5
@@ -0,0 +1,76 @@
1
+ import fs from 'node:fs/promises'
2
+ import { createReadStream } from 'node:fs'
3
+ import os from 'node:os'
4
+ import path from 'node:path'
5
+ import { createHash, createHmac, randomBytes } from 'node:crypto'
6
+
7
+ const inside = (dir, root) => {
8
+ const rel = path.relative(root, dir)
9
+ return !path.isAbsolute(rel) && rel !== '..' && !rel.startsWith('..' + path.sep)
10
+ }
11
+
12
+ export async function projectDirectory(dir, workspace) {
13
+ if (!workspace || !path.isAbsolute(workspace)) throw new Error('找不到当前会话的工作区目录,无法出图。')
14
+ const real = await fs.realpath(dir)
15
+ if (!inside(real, await fs.realpath(workspace))) throw new Error('工程出图只允许当前工作区内的目录。')
16
+ return real
17
+ }
18
+
19
+ // Hash the private copy that will actually be compiled. Later edits to the
20
+ // working tree cannot substitute different source bytes after approval.
21
+ export async function withProjectCopy(dir, workspace, use) {
22
+ const real = await projectDirectory(dir, workspace)
23
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-render-'))
24
+ const copy = path.join(tmp, 'project')
25
+ try {
26
+ if (inside(tmp, real)) throw new Error('请选择工作区里的具体工程目录。')
27
+ await fs.cp(real, copy, { recursive: true, verbatimSymlinks: true, filter: src => path.basename(src) !== '.git' })
28
+ async function visit(rel) {
29
+ const tree = createHash('sha256')
30
+ const at = path.join(copy, rel)
31
+ for (const name of (await fs.readdir(at)).sort()) {
32
+ const file = path.join(at, name)
33
+ const key = path.join(rel, name)
34
+ const stat = await fs.lstat(file)
35
+ if (stat.isDirectory()) {
36
+ tree.update(JSON.stringify(['dir', name, await visit(key)]))
37
+ } else if (stat.isSymbolicLink()) {
38
+ const link = await fs.readlink(file)
39
+ const target = path.resolve(real, rel, link)
40
+ if (!inside(target, real) || path.relative(real, target).split(path.sep).includes('.git')) throw new Error('工程链接指向出图目录外:' + key)
41
+ // Rebase absolute links onto this copy. Each link in a chain is checked.
42
+ const local = path.relative(path.dirname(path.join(real, key)), target) || '.'
43
+ await fs.unlink(file)
44
+ await fs.symlink(local, file)
45
+ tree.update(JSON.stringify(['link', key, local]))
46
+ } else if (stat.isFile()) {
47
+ const hash = createHash('sha256')
48
+ for await (const chunk of createReadStream(file)) hash.update(chunk)
49
+ tree.update(JSON.stringify(['file', key, stat.mode & 0o777, hash.digest('hex')]))
50
+ } else throw new Error('工程中有无法复制的特殊文件:' + key)
51
+ }
52
+ return tree.digest('hex')
53
+ }
54
+ const fingerprint = await visit('')
55
+ return await use({ dir: real, copy, fingerprint })
56
+ } finally {
57
+ await fs.rm(tmp, { recursive: true, force: true })
58
+ }
59
+ }
60
+
61
+ // Only the panel can return a challenge, bound to the session, design, screen
62
+ // and exact copy. The model tool never takes an approval field.
63
+ export function createRenderConsent() {
64
+ const secret = randomBytes(32)
65
+ const grants = new Map()
66
+ return (project, scope, reply) => {
67
+ const { dir, fingerprint } = project
68
+ if (grants.get(dir) === fingerprint) return { allowed: true }
69
+ const ticket = createHmac('sha256', secret).update(JSON.stringify([scope, dir, fingerprint])).digest('hex')
70
+ if (ticket === reply) {
71
+ grants.set(dir, fingerprint)
72
+ return { allowed: true }
73
+ }
74
+ return { allowed: false, ticket }
75
+ }
76
+ }
package/lib/fonts.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { designWriteScope } from './design-transactions.js'
1
2
  /**
2
3
  * 字体库(issue #31):免费可商用(SIL OFL 1.1)的网页字体。面板里点选、模型调 use_fonts,字体文件复制进设计目录的 dsh-fonts/
3
4
  * (设计台专用的文件夹:不和设计自己放字体的 fonts/ 撞名),变量所在的样式里加一段设计台管的 @font-face。
@@ -307,36 +308,44 @@ export function createFonts({ market, index = loadFontIndex(), cacheDir = FONTS_
307
308
  probe = up
308
309
  }
309
310
  if (!allowed(fs.realpathSync(probe))) throw denied()
311
+ const scope = designWriteScope.getStore()
310
312
  const sub = path.join(dir, FONT_DIR)
311
- fs.mkdirSync(sub, { recursive: true })
313
+ if (!scope?.put) fs.mkdirSync(sub, { recursive: true })
312
314
  const realDir = fs.realpathSync(dir)
313
- const realSub = fs.realpathSync(sub)
315
+ const realSub = fs.existsSync(sub) ? fs.realpathSync(sub) : path.join(realDir, FONT_DIR)
314
316
  if (!allowed(realDir) || realSub !== path.join(realDir, FONT_DIR)) throw denied()
317
+ const writes = []
315
318
  for (const f of fonts) {
316
319
  if (!okFile(f)) {
317
320
  try { fs.rmSync(fileOf(f), { force: true }) } catch (e) { log(e) }
318
- throw Object.assign(new Error(`bad cached font ${f.id}`), { code: 'mismatch' })
321
+ throw Object.assign(new Error('bad cached font ' + f.id), { code: 'mismatch' })
319
322
  }
320
- const to = path.join(realSub, `${f.id}.woff2`)
321
- let same = false
322
- try {
323
- const st = fs.lstatSync(to)
324
- if (!st.isFile()) throw denied() // 软链接、文件夹:不往里写
325
- same = st.size === f.size && sha256(fs.readFileSync(to)) === f.sha256
326
- } catch (e) {
327
- if (e && e.code === 'link') throw e
323
+ const to = path.join(realSub, f.id + '.woff2')
324
+ const st = fs.lstatSync(to, { throwIfNoEntry: false })
325
+ if (st) {
326
+ if (!st.isFile() || st.size > CAP) throw denied()
327
+ const original = fs.readFileSync(to)
328
+ const hash = sha256(original)
329
+ if (hash === f.sha256) continue
330
+ if (scope?.put) { writes.push({ from: fileOf(f), to }); continue }
331
+ // Managed font files are excluded from normal versions. Keep the exact original before repairing one.
332
+ const folder = path.join(realDir, '.dsh-font-backups')
333
+ fs.mkdirSync(folder, { recursive: true })
334
+ if (fs.realpathSync(folder) !== folder) throw denied()
335
+ const backup = path.join(folder, f.id + '-' + hash + '.woff2')
336
+ try { fs.writeFileSync(backup, original, { flag: 'wx', mode: 0o600 }) } catch (e) { if (e.code !== 'EEXIST') throw e }
337
+ if (!fs.lstatSync(backup).isFile() || !fs.readFileSync(backup).equals(original)) throw denied()
328
338
  }
329
- if (same) continue
330
- // 临时文件独占新建(同名的东西已经在了——哪怕是软链接——就先删掉它本身再建,不顺着它写出去)
331
- const tmp = `${to}.${process.pid}.tmp`
332
- try {
333
- fs.copyFileSync(fileOf(f), tmp, fs.constants.COPYFILE_EXCL)
334
- } catch (e) {
335
- if (!e || e.code !== 'EEXIST') throw e
336
- fs.rmSync(tmp, { force: true })
337
- fs.copyFileSync(fileOf(f), tmp, fs.constants.COPYFILE_EXCL)
339
+ writes.push({ from: fileOf(f), to })
340
+ }
341
+ for (const { from, to } of writes) {
342
+ if (scope?.put && fs.realpathSync(scope.root) === realDir) {
343
+ scope.put(path.relative(realDir, to).split(path.sep).join('/'), fs.readFileSync(from))
344
+ continue
338
345
  }
339
- fs.renameSync(tmp, to)
346
+ const tmp = to + '.' + crypto.randomUUID() + '.tmp'
347
+ fs.copyFileSync(from, tmp, fs.constants.COPYFILE_EXCL)
348
+ try { fs.renameSync(tmp, to) } finally { fs.rmSync(tmp, { force: true }) }
340
349
  }
341
350
  }
342
351
 
package/lib/frames.js CHANGED
@@ -42,11 +42,11 @@ export function readManifest(src) {
42
42
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return { m: null, problems: ['frame.json 要是一个对象'] }
43
43
  const id = String(raw.id || '')
44
44
  if (!ID_RE.test(id)) problems.push(`id「${id}」不行:只用小写字母、数字和连字符,40 个字以内(比如 chrome-popup)`)
45
- else if (RESERVED.has(id)) problems.push(`id「${id}」留给自带的 DSH 外框了,换一个`)
45
+ else if (RESERVED.has(id)) problems.push(`id「${id}」留给自带的 DSH 外壳了,换一个`)
46
46
  const name = String(raw.name || '').trim()
47
- if (!name || name.length > 30) problems.push('name 要写(外框叫什么,30 个字以内,如「Chrome 插件弹窗」)')
47
+ if (!name || name.length > 30) problems.push('name 要写(外壳叫什么,30 个字以内,如「Chrome 插件弹窗」)')
48
48
  const size = Array.isArray(raw.size) ? raw.size.map(Number) : []
49
- if (size.length !== 2 || !size.every((n) => Number.isInteger(n) && n >= 200 && n <= 4000)) problems.push('size 写成 [宽, 高],整数,200–4000(外框整个画面多大,如 [400, 600])')
49
+ if (size.length !== 2 || !size.every((n) => Number.isInteger(n) && n >= 200 && n <= 4000)) problems.push('size 写成 [宽, 高],整数,200–4000(外壳整个画面多大,如 [400, 600])')
50
50
  const css = (Array.isArray(raw.css) ? raw.css : raw.css ? [raw.css] : []).map(String)
51
51
  for (const f of css) {
52
52
  if (!plainFile(f) || !/\.css$/i.test(f)) problems.push(`css「${f}」要是这个文件夹里的 .css 文件名(不带目录)`)
@@ -314,12 +314,12 @@ async function measureFrame(browser, { url, w, h, m, f, want }, out) {
314
314
  await page.eval('window.__dshDesign.settle()')
315
315
  }
316
316
  const light = await page.eval(`window.__dshDesign.frameInfo(${Array.isArray(paths) && paths.length ? JSON.stringify(paths) : ''})`)
317
- if (!light || !light.found) { bad.push(`${f.file}:没找到外框的根元素。最外层包住整个外框的元素写 data-frame="${want}",槽位写 data-slot`); return }
317
+ if (!light || !light.found) { bad.push(`${f.file}:没找到外壳的根元素。最外层包住整个外壳的元素写 data-frame="${want}",槽位写 data-slot`); return }
318
318
  if (!light.id) { bad.push(`${f.file}:带 data-frame 的元素里没有 data-slot 槽位`); return }
319
319
  if (light.id !== want) bad.push(`${f.file}:根元素写的是 data-frame="${light.id}",要写 data-frame="${want}"`)
320
320
  // 写在 <html> / <body> 上:切深色会往 <html> 加属性、远程看会往 <body> 末尾塞图标,都算进外框指纹;
321
321
  // 写在 <dialog> / <details> 上:用户一开合整个外框就变了 → 都会误报
322
- if (['html', 'body', 'dialog', 'details'].includes(light.tag)) bad.push(`${f.file}:data-frame 写在了 <${light.tag}> 上。外面包一层 <div data-frame="${want}">,外框都放进去(铺满画面)`)
322
+ if (['html', 'body', 'dialog', 'details'].includes(light.tag)) bad.push(`${f.file}:data-frame 写在了 <${light.tag}> 上。外面包一层 <div data-frame="${want}">,外壳都放进去(铺满画面)`)
323
323
  const decl = Object.keys(f.slots)
324
324
  const miss = decl.filter((s) => !light.slots.includes(s))
325
325
  const extra = [...new Set(light.slots.filter((s) => !decl.includes(s)))]
@@ -328,8 +328,8 @@ async function measureFrame(browser, { url, w, h, m, f, want }, out) {
328
328
  if (extra.length) bad.push(`${f.file}:页面上的槽位 frame.json 没写:${extra.join('、')}(写进 slots 并说明放什么)`)
329
329
  if (dup.length) bad.push(`${f.file}:槽位重名:${dup.join('、')}`)
330
330
  if (light.nested && light.nested.length) bad.push(`${f.file}:槽位套在槽位里面(${light.nested.join('、')}):槽位要并排,不能嵌套`)
331
- if (light.rect.w < w * 0.9 || light.rect.h < h * 0.9) bad.push(`${f.file}:外框根元素只有 ${light.rect.w}×${light.rect.h},要铺满整个画面 ${w}×${h}`)
332
- images.push({ key: `${m.id}-${f.id}`, label: `${m.name} · ${f.name}(浅色)`, jpg: await page.shot() })
331
+ if (light.rect.w < w * 0.9 || light.rect.h < h * 0.9) bad.push(`${f.file}:外壳根元素只有 ${light.rect.w}×${light.rect.h},要铺满整个画面 ${w}×${h}`)
332
+ images.push({ key: `${m.id}-${f.id}`, label: `${m.name}:${f.name}(浅色)`, jpg: await page.shot() })
333
333
  const darks = [] // 每种深色量出来的 e(量不成的是 null)
334
334
  let atDark = true
335
335
  if (any) {
@@ -341,7 +341,7 @@ async function measureFrame(browser, { url, w, h, m, f, want }, out) {
341
341
  const okd = dk && dk.sig === light.sig && dk.probes
342
342
  darks.push(okd ? dk.probes.e : null)
343
343
  if (okd && JSON.stringify(dk.at) !== JSON.stringify(light.at)) atDark = false // 深色样式让外框挪了位置(居中的根变宽变窄):位置不记
344
- if (okd && hasDark && !images.some((x) => x.key === `${m.id}-${f.id}-dark`)) images.push({ key: `${m.id}-${f.id}-dark`, label: `${m.name} · ${f.name}(深色)`, jpg: await page.shot() })
344
+ if (okd && hasDark && !images.some((x) => x.key === `${m.id}-${f.id}-dark`)) images.push({ key: `${m.id}-${f.id}-dark`, label: `${m.name}:${f.name}(深色)`, jpg: await page.shot() })
345
345
  await page.eval('window.__dshDesign.dark(false)')
346
346
  }
347
347
  await media(false)
@@ -393,17 +393,17 @@ async function measureFrame(browser, { url, w, h, m, f, want }, out) {
393
393
  */
394
394
  export async function saveFrame({ browser, src, dir = FRAMES_DIR, hubFactory = createHub }) {
395
395
  const { m, problems } = readManifest(src)
396
- if (!m || problems.length) return { ok: false, text: `外框没存:frame.json 有问题\n${problems.map((x) => `- ${x}`).join('\n')}`, images: [] }
396
+ if (!m || problems.length) return { ok: false, text: `外壳没存:frame.json 有问题\n${problems.map((x) => `- ${x}`).join('\n')}`, images: [] }
397
397
  const assets = assetsOf(src)
398
- if (assets.total > MAX_ASSETS) return { ok: false, text: `外框没存:assets/ 太大(${Math.round(assets.total / 1024)} KB,最多 ${MAX_ASSETS / 1024 / 1024} MB)`, images: [] }
399
- if (assets.odd.length) return { ok: false, text: `外框没存:assets/ 里有收不了的:${assets.odd.slice(0, 5).join('、')}(只收图、字体、样式,最多套 3 层文件夹)`, images: [] }
400
- if (assets.files.length > MAX_ASSET_FILES) return { ok: false, text: `外框没存:assets/ 里文件太多(${assets.files.length} 个,最多 ${MAX_ASSET_FILES} 个):图标合成一个 svg 雪碧图,或者删掉用不到的`, images: [] }
398
+ if (assets.total > MAX_ASSETS) return { ok: false, text: `外壳没存:assets/ 太大(${Math.round(assets.total / 1024)} KB,最多 ${MAX_ASSETS / 1024 / 1024} MB)`, images: [] }
399
+ if (assets.odd.length) return { ok: false, text: `外壳没存:assets/ 里有收不了的:${assets.odd.slice(0, 5).join('、')}(只收图、字体、样式,最多套 3 层文件夹)`, images: [] }
400
+ if (assets.files.length > MAX_ASSET_FILES) return { ok: false, text: `外壳没存:assets/ 里文件太多(${assets.files.length} 个,最多 ${MAX_ASSET_FILES} 个):图标合成一个 svg 雪碧图,或者删掉用不到的`, images: [] }
401
401
  // 外框是固定的样子:不收脚本(<script>、onclick 这种、javascript: 地址)——脚本一改外框的属性、class,体检就报外框被改
402
402
  const scripted = m.frames.filter((fr) => { let t = ''; try { t = fs.readFileSync(path.join(src, fr.file), 'utf8').replace(/<!--[\s\S]*?-->/g, '') } catch { return false } return /<script\b/i.test(t) || /<[a-z][^>]*\son[a-z]+\s*=/i.test(t) || /=\s*["']?\s*javascript:/i.test(t) }).map((fr) => fr.file)
403
- if (scripted.length) return { ok: false, text: `外框没存:${scripted.join('、')} 里有脚本(<script>、onclick 这种、javascript: 地址)。外框只放固定的样子,去掉脚本再存;要点了有反应的写在设计的槽位里。`, images: [] }
403
+ if (scripted.length) return { ok: false, text: `外壳没存:${scripted.join('、')} 里有脚本(<script>、onclick 这种、javascript: 地址)。外壳只放固定的样子,去掉脚本再存;要点了有反应的写在设计的槽位里。`, images: [] }
404
404
  const lost = missingRefs(src, m, assets.files)
405
- if (lost.length) return { ok: false, text: `外框没存:这些文件引用了找不到、或不会复制进库的文件(存进库后会缺):\n${lost.slice(0, 12).map((x) => `- ${x}`).join('\n')}${lost.length > 12 ? `\n- …还有 ${lost.length - 12} 处` : ''}\n样式文件写进 frame.json 的 css,图、字体、别的样式放进 assets/,再存一次。`, images: [] }
406
- if (!browser || !browser.available()) return { ok: false, text: '外框没存:这台电脑上没找到能用的 Chrome / Edge,算不了外框的指纹。', images: [] }
405
+ if (lost.length) return { ok: false, text: `外壳没存:这些文件引用了找不到、或不会复制进库的文件(存进库后会缺):\n${lost.slice(0, 12).map((x) => `- ${x}`).join('\n')}${lost.length > 12 ? `\n- …还有 ${lost.length - 12} 处` : ''}\n样式文件写进 frame.json 的 css,图、字体、别的样式放进 assets/,再存一次。`, images: [] }
406
+ if (!browser || !browser.available()) return { ok: false, text: '外壳没存:这台电脑上没找到能用的 Chrome / Edge,算不了外壳的指纹。', images: [] }
407
407
  const [w, h] = m.size
408
408
  const hub = hubFactory({ parents: () => [] })
409
409
  const datas = new Map()
@@ -434,7 +434,7 @@ export async function saveFrame({ browser, src, dir = FRAMES_DIR, hubFactory = c
434
434
  } finally {
435
435
  hub.closeAll()
436
436
  }
437
- if (bad.length) return { ok: false, text: `外框没存:\n${bad.map((x) => `- ${x}`).join('\n')}`, images }
437
+ if (bad.length) return { ok: false, text: `外壳没存:\n${bad.map((x) => `- ${x}`).join('\n')}`, images }
438
438
 
439
439
  // 写进库:先写到旁边的临时目录,写完换上去(同名的旧外框整个换掉;已经用旧外框做的设计页面里带着旧指纹,照样能查)
440
440
  const out = path.join(dir, m.id)
@@ -462,16 +462,16 @@ export async function saveFrame({ browser, src, dir = FRAMES_DIR, hubFactory = c
462
462
  if (old) { try { fs.renameSync(old, out) } catch { /* 留着 .old 目录,至少没删 */ } }
463
463
  throw e
464
464
  }
465
- if (old) { try { fs.rmSync(old, { recursive: true, force: true }) } catch { /* 删不掉的旧目录名字带点、列外框时不认 */ } }
465
+ if (old) { try { fs.rmSync(old, { recursive: true, force: true }) } catch { /* 删不掉的旧目录名字带点、列外壳时不认 */ } }
466
466
  } catch (e) {
467
467
  fs.rmSync(tmp, { recursive: true, force: true })
468
- return { ok: false, text: `外框没存:写进外框库出错(${String((e && e.message) || e).slice(0, 160)})`, images }
468
+ return { ok: false, text: `外壳没存:写进外壳库出错(${String((e && e.message) || e).slice(0, 160)})`, images }
469
469
  }
470
470
  const lines = m.frames.map((f) => `- ${f.name}:${f.file}(槽位 ${Object.keys(f.slots).join('、')})`)
471
471
  const text = [
472
- `外框「${m.name}」(${m.id},${w}×${h})存进外框库了:${out}`,
472
+ `外壳「${m.name}」(${m.id},${w}×${h})存进外壳库了:${out}`,
473
473
  ...lines,
474
- `附上每个位置的截图(${images.some((x) => x.key.endsWith('-dark')) ? '浅色、深色' : '只有浅色:外框没写深色样式'}),对照用户给的截图 / 说明看一遍,不像就改源文件再存一次。`,
474
+ `附上每个位置的截图(${images.some((x) => x.key.endsWith('-dark')) ? '浅色、深色' : '只有浅色:外壳没写深色样式'}),对照用户给的截图 / 说明看一遍,不像就改源文件再存一次。`,
475
475
  `用它做设计:把 ${out} 里的 ${[...m.css, ...(assets.files.length ? ['assets/'] : [])].join('、') || '样式文件'} 和要用的位置 HTML 用复制命令原样复制进设计目录(别重新手写),只改 data-slot 里面;样式都从 [data-slot="main"] 开头。`,
476
476
  ].join('\n')
477
477
  return { ok: true, id: m.id, dir: out, text, images }
@@ -480,9 +480,9 @@ export async function saveFrame({ browser, src, dir = FRAMES_DIR, hubFactory = c
480
480
  /** 技能里加一段:库里有哪些外框(每次加载技能现读) */
481
481
  export function frameSection(dir = FRAMES_DIR) {
482
482
  const list = listFrames(dir)
483
- const head = '\n\n## 外框库(用户自己的外框)\n\n'
484
- const how = '用户要给某个软件 / 浏览器插件 / 平台做界面、说「套上 XX 的外框」「照这张截图做个外框」:读 `references/frames.md`,照截图或说明写外框,调 `save_frame` 存进库,再用它出设计。'
483
+ const head = '\n\n## 外壳库\n\n'
484
+ const how = '用户要给某个软件 / 浏览器插件 / 平台做界面、说「套上 XX 的外壳」「照这张截图做个外壳」:读 `references/frames.md`,照截图或说明写外壳,调 `save_frame` 存进库,再用它出设计。'
485
485
  if (!list.length) return head + how + '\n'
486
486
  const line = (x) => `- 「${x.name}」(${x.id},${x.size[0]}×${x.size[1]}):${x.dir};位置:${x.frames.map((f) => `${f.name}(${f.file},槽位 ${Object.keys(f.slots).join('、')})`).join(';')}`
487
- return `${head}${list.slice(0, 12).map(line).join('\n')}\n\n用户点名用某个外框(首页选了「套外框」再选外框,消息里会写「外框:名字(id)」):照 \`references/frames.md\` 的「用外框」做,类型标记写 framed。\n\n${how}\n`
487
+ return `${head}${list.slice(0, 12).map(line).join('\n')}\n\n用户点名用某个外壳(首页选了「自定义外壳」再选一个,消息里会写「外壳:名字(id)」,也兼容旧消息的「外框」叫法):照 \`references/frames.md\` 的「用外壳」做,类型标记写 framed。\n\n${how}\n`
488
488
  }
@@ -158,7 +158,7 @@ const BAD_PROPS = new Set(['behavior', '-ms-behavior', '-moz-binding', 'binding'
158
158
  * refs:所有会去拿的地址(kind:'url' 普通、'font' 在 @font-face 里);at:在这段 CSS 里的位置
159
159
  * problems:import(@import)、func(expression() 这类)、prop(behavior / -moz-binding)、bad(写坏的 url / 字符串,可能藏东西)、font-url
160
160
  */
161
- export function scanCss(src) {
161
+ export function scanCss(src, { importUrls = false } = {}) {
162
162
  const toks = cssTokens(src)
163
163
  const refs = []
164
164
  const problems = []
@@ -177,7 +177,14 @@ export function scanCss(src) {
177
177
  }
178
178
  switch (tk.t) {
179
179
  case 'at':
180
- if (low === 'import') problems.push({ code: 'import', at: tk.s })
180
+ if (low === 'import') {
181
+ problems.push({ code: 'import', at: tk.s })
182
+ if (importUrls) {
183
+ let i = k + 1
184
+ while (toks[i]?.t === 'ws' || toks[i]?.t === 'comment') i++
185
+ if (toks[i]?.t === 'str') refs.push({ url: toks[i].v, at: toks[i].s, kind: 'url' })
186
+ }
187
+ }
181
188
  else if (low === 'namespace') skipUntilSemi = true
182
189
  pendingAt = low
183
190
  break
@@ -163,13 +163,14 @@ export function installSystem(systemsDir, e, files, { name, url = '', now = Date
163
163
  * 重装同一版不会多占。版本快照本身的预览不靠这个:装好的设计系统的旧版本一律加规矩(works.strictVersions)
164
164
  */
165
165
  export function recordSystem(library, r, e, { name, url = '', now = Date.now() } = {}) {
166
- const hashes = Object.fromEntries(Object.entries(r.files || {}).filter(([p]) => /\.html?$/i.test(p)))
166
+ const hashes = Object.fromEntries(Object.entries(r.files || {}).filter(([p]) => /\.html?$/i.test(p) || /^rules\.md$/i.test(p)))
167
+ if (!Object.keys(hashes).some((k) => /^rules\.md$/i.test(k))) hashes['rules.md'] = '' // 包里没带 rules.md:以后用户写的都算用户的
167
168
  const prev = r.updated ? library.get(r.real) : null
168
169
  const keep = prev ? mergePast(prev.pastHashes, Object.values(prev.hashes || {}), new Set(Object.values(hashes))) : []
169
170
  return library.put(r.real, { title: name, kind: 'system', trust: 'market', hashes, pastHashes: keep.length ? keep : undefined, from: { id: e.id, rev: e.rev, author: (e.author && e.author.login) || '', license: e.license || '', url }, hidden: true, hiddenAt: now })
170
171
  }
171
172
 
172
- export function createMarketRoutes({ admit, readBody, json, tracker, library, market, open, systemsDir, log = () => {}, sessionCwd = async (id) => tracker.cwdOf(id) }) {
173
+ export function createMarketRoutes({ admit, readBody, json, tracker, library, market, open, systemsDir, renderMarketThumb, log = () => {}, sessionCwd = async (id) => tracker.cwdOf(id) }) {
173
174
  const lang = (body) => (body && body.lang === 'en' ? 'en' : 'zh')
174
175
  const fail = (res, e) => {
175
176
  if (e instanceof MarketError) return json(res, ERR[e.code] || 502, { error: e.code, x: e.x })
@@ -197,9 +198,24 @@ export function createMarketRoutes({ admit, readBody, json, tracker, library, ma
197
198
  res.end(buf)
198
199
  }
199
200
 
200
- function thumb(req, res) {
201
+ async function thumb(req, res) {
201
202
  if (!admit(req, res)) return
202
- const f = market.thumbFile(new URL(req.url, 'http://x').searchParams.get('id') || '')
203
+ const q = new URL(req.url, 'http://x').searchParams
204
+ const id = q.get('id') || ''
205
+ if (q.has('i')) {
206
+ try {
207
+ const i = q.get('i')
208
+ const entry = market.entry(id)
209
+ if (!/^[012]$/.test(i) || entry?.type !== 'template' || q.get('r') !== entry.rev || !entry.screens?.[i]) return json(res, 404, { error: 'no screen' })
210
+ const staged = await market.stage(id)
211
+ const screen = entry.screens[i].file
212
+ if (staged.entry.rev !== entry.rev || !staged.files.some(f => f.path === screen)) return json(res, 404, { error: 'no screen' })
213
+ const fullPage = entry.screens.length === 1 && (entry.kind === 'web' || entry.kind === 'email')
214
+ const shot = !fullPage && market.shotFile(id, '_shots/' + screen.replace(/\.html?$/i, '.jpg'))
215
+ return sendBuf(res, shot || await renderMarketThumb(staged, screen), 'image/jpeg')
216
+ } catch (e) { return fail(res, e) }
217
+ }
218
+ const f = market.thumbFile(id)
203
219
  if (!f) return json(res, 404, { error: 'no thumb' })
204
220
  sendBuf(res, f, 'image/webp')
205
221
  }
@@ -210,7 +226,7 @@ export function createMarketRoutes({ admit, readBody, json, tracker, library, ma
210
226
  if (!b) return
211
227
  try {
212
228
  const s = await market.stage(idOf(b))
213
- json(res, 200, { id: s.entry.id, rev: s.entry.rev, shots: s.shots })
229
+ json(res, 200, { id: s.entry.id, rev: s.entry.rev, shots: s.shots, ...(s.entry.type === 'system' ? { dir: s.dir } : {}) })
214
230
  } catch (e) { fail(res, e) }
215
231
  }
216
232
 
@@ -264,7 +280,7 @@ export function createMarketRoutes({ admit, readBody, json, tracker, library, ma
264
280
  if (e.type !== 'template') return json(res, 400, { error: 'type' })
265
281
  const s = await market.stage(e.id)
266
282
  const base = baseFor(await sessionCwd(session))
267
- const prepared = preparePack(s.files, { lang: lang(b) })
283
+ const prepared = preparePack(s.files, { lang: lang(b), localZip: false })
268
284
  const t = prepared.manifest.title
269
285
  // 最后一次 await 之后、落地之前紧挨着再查:等的这会儿可能被下架了
270
286
  stillListed(e)
@@ -275,7 +291,7 @@ export function createMarketRoutes({ admit, readBody, json, tracker, library, ma
275
291
  from: { id: e.id, rev: e.rev, author: (e.author && e.author.login) || '', license: e.license || '', url: market.url(e) },
276
292
  library,
277
293
  })
278
- await tracker.setTarget(session, { kind: 'file', file: r.first, root: r.dir }, { source: 'user', popup: false, kind: prepared.manifest.kind, size: prepared.manifest.size || '' })
294
+ await tracker.setTarget(session, { kind: 'file', file: r.first, root: r.dir, directory: true }, { source: 'user', popup: false, kind: prepared.manifest.kind, size: prepared.manifest.size || '' })
279
295
  json(res, 200, { snap: tracker.snapshot(session), dir: r.dir, title: t, screens: r.screens, license: prepared.manifest.license, kind: prepared.manifest.kind, flags: prepared.flags.slice(0, 20), from: { id: e.id, author: (e.author && e.author.login) || '' } })
280
296
  } catch (e) { fail(res, e) }
281
297
  }
@@ -10,11 +10,13 @@
10
10
 
11
11
  import fs from 'node:fs'
12
12
  import path from 'node:path'
13
+ import { readPages, portablePages } from '../page-settings.js'
13
14
  import { cleanPath, checkPack, normalizeHtml, titleOf, metaKind, message, LIMITS, capsOf, FORMAT, pctBytes, imageInfo } from './policy.js'
14
15
  import { writeZip } from './zip.js'
15
16
  import { isPhotoAsset } from '../photos.js'
16
17
  import { stripFontBlock } from '../fonts.js'
17
18
  import { decodeEntities } from './html.js'
19
+ import { sizeFits } from '../kinds.js'
18
20
 
19
21
  /** 页面文本 → 去掉注释、解开各种转义、全小写,用来判断提没提到某个文件 */
20
22
  function refsFold(s) {
@@ -77,7 +79,7 @@ function metaExtra(html) {
77
79
  const tag = /<meta\b[^>]*\bname\s*=\s*["']?dsh-design["']?[^>]*>/i.exec(html.slice(0, 65536))
78
80
  const c = tag && /\bcontent\s*=\s*(["'])([^"']*)\1/i.exec(tag[0])
79
81
  const words = c ? c[2].toLowerCase().split(/[\s,;]+/) : []
80
- const sz = words.map((w) => /^(\d{3,4})[x×*](\d{3,4})$/.exec(w)).find(Boolean)
82
+ const sz = words.map((w) => /^(\d{2,4})[x×*](\d{2,4})$/.exec(w)).find(Boolean) // 两位数:嵌入式小屏(160x80、128x64)
81
83
  return { size: sz ? `${sz[1]}x${sz[2]}` : '', os: words.includes('windows') ? 'windows' : words.includes('mac') ? 'mac' : '' }
82
84
  }
83
85
 
@@ -99,7 +101,8 @@ export function buildManifest({ existing = null, screens, htmls, version = '', l
99
101
  title: typed(textOf(title, 24), m.title) || (m.title && typeof m.title === 'object' ? m.title : textOf(product || titleOf(first), 24) || { zh: '我的设计' }),
100
102
  ...(typed(textOf(description, 120), m.description) ? { description: typed(textOf(description, 120), m.description) } : m.description ? { description: m.description } : {}),
101
103
  kind: m.kind || kinds[0] || 'web',
102
- ...(m.size || extra.size ? { size: m.size || extra.size } : {}),
104
+ // 画幅这个类型收不下(网页写了 160x80)就不写,导入后按页面写的
105
+ ...(() => { const s = [m.size, extra.size].find((x) => x && sizeFits(String(x), m.kind || kinds[0] || 'web')); return s ? { size: String(s) } : {} })(),
103
106
  ...(m.os || extra.os ? { os: m.os || extra.os } : {}),
104
107
  screens: screens.map((f) => {
105
108
  const old = Array.isArray(m.screens) ? m.screens.find((s) => s && s.file === f) : null
@@ -248,8 +251,10 @@ export function stripMeta(buf, ext) {
248
251
  * 打包前的全部步骤。screens:要打进包的屏(顺序就是包里的顺序)
249
252
  * 返回 { ok, errors: [{ code, x, line, msg, sev }], flags, notes: [自动修了什么], skipped, manifest, files: [{ path, data }] }
250
253
  */
251
- export function packDesign(root, { screens, version = '', license = '', author = '', mode = 'zip', lang = 'zh', title = '', description = '', categories, tags, designLang, shareHash = '', secrets = [] }) {
252
- const { files: picked, skipped, tooBig } = collectDesign(root)
254
+ export function packDesign(root, { screens, version = '', license = '', author = '', mode = 'zip', lang = 'zh', title = '', description = '', categories, tags, designLang, shareHash = '', secrets = [], archived, versionRow, single, dependencies, settings: savedSettings }) {
255
+ const scoped = archived || dependencies
256
+ const entries = archived ? [...archived].map(([key, data]) => ({ path: key, data })) : dependencies ? Object.entries(dependencies).map(([key, abs]) => ({ path: key, abs })) : null
257
+ const { files: picked, skipped, tooBig } = scoped ? { files: entries.filter(f => PACK_EXT.test(f.path)), skipped: [], tooBig: false } : collectDesign(root)
253
258
  const notes = []
254
259
  const errors = []
255
260
  if (tooBig) errors.push({ code: 'count', n: '2000+', max: capsOf(mode).files, sev: 'error' })
@@ -259,7 +264,7 @@ export function packDesign(root, { screens, version = '', license = '', author =
259
264
  const htmls = new Map()
260
265
  for (const f of picked) {
261
266
  if (f.path === 'design.json') {
262
- try { existing = JSON.parse(fs.readFileSync(f.abs, 'utf8')) } catch { existing = null }
267
+ try { if (!single) existing = JSON.parse(f.data?.toString('utf8') || fs.readFileSync(f.abs, 'utf8')) } catch { existing = null }
263
268
  continue
264
269
  }
265
270
  // 不在画布上的顶层页面(方向稿删掉了、改名前的旧文件):不打包
@@ -269,9 +274,9 @@ export function packDesign(root, { screens, version = '', license = '', author =
269
274
  if (/\.json$/i.test(f.path) && f.path !== 'tweaks.json' && f.path !== 'mock.json') { skipped.push(f.path); continue }
270
275
  let data
271
276
  try {
272
- const st = fs.statSync(f.abs)
273
- if (st.size > 4 * 1024 * 1024) { errors.push({ code: 'big', x: f.path, n: `${Math.ceil(st.size / 1024)}KB`, max: '400KB', sev: 'error' }); continue }
274
- data = fs.readFileSync(f.abs)
277
+ const size = f.data ? f.data.length : fs.statSync(f.abs).size
278
+ if (size > 4 * 1024 * 1024) { errors.push({ code: 'big', x: f.path, n: Math.ceil(size / 1024) + 'KB', max: '400KB', sev: 'error' }); continue }
279
+ data = f.data || fs.readFileSync(f.abs)
275
280
  } catch { continue }
276
281
  const ext = f.path.slice(f.path.lastIndexOf('.') + 1).toLowerCase()
277
282
  // 字体库(#31):字体文件不进包(市场只收系统字体),设计台管的 @font-face 那段去掉,字体栈后面的系统字体顶上
@@ -310,6 +315,18 @@ export function packDesign(root, { screens, version = '', license = '', author =
310
315
  }
311
316
  const order = screens.filter((s) => htmls.has(s))
312
317
  const manifest = buildManifest({ existing, screens: order, htmls, version, license, author, title, description, categories, tags, designLang, shareHash })
318
+ if (mode === 'zip') {
319
+ const settings = portablePages(savedSettings || (single ? {} : readPages(root, true)), order)
320
+ if (versionRow) {
321
+ const first = versionRow.viewports[order[0]]
322
+ if (first) { manifest.kind = first.kind; manifest.size = first.w + 'x' + first.h }
323
+ for (const row of manifest.screens) {
324
+ const v = versionRow.viewports[row.file]
325
+ if (v && !settings.screens[row.file]) settings.screens[row.file] = { original: { kind: v.kind, size: v.w + 'x' + v.h } }
326
+ }
327
+ }
328
+ if (Object.keys(settings.screens).length || settings.devices !== undefined) manifest.pageSettings = settings
329
+ }
313
330
  if (dropped.size && Array.isArray(manifest.assets)) manifest.assets = manifest.assets.filter((x) => !(x && typeof x.path === 'string' && dropped.has(String(cleanPath(x.path) || x.path).toLowerCase())))
314
331
  files.unshift({ path: 'design.json', data: Buffer.from(JSON.stringify(manifest, null, 2) + '\n', 'utf8') })
315
332
  const r = checkPack(files, { mode })
@@ -13,7 +13,7 @@
13
13
  import crypto from 'node:crypto'
14
14
  import { tokenize, scanTags, decodeEntities, lineAt, visibleText, rawEnd } from './html.js'
15
15
  import { scanCss, cssTokens, URL_FUNCS } from './css.js'
16
- import { KINDS, META_ALIAS } from '../kinds.js'
16
+ import { KINDS, META_ALIAS, sizeFits } from '../kinds.js'
17
17
 
18
18
  export const FORMAT = 1
19
19
  export const LIMITS = {
@@ -1260,7 +1260,9 @@ export function checkManifest(m, { mode = 'install', vocab = null } = {}) {
1260
1260
  if (!LICENSES.includes(m.license)) bad('license', `只能是 ${LICENSES.join(' / ')}`)
1261
1261
  if (m.type === 'template') {
1262
1262
  if (!KINDS.includes(m.kind)) bad('kind', `只能是 ${KINDS.join(' / ')}`)
1263
- if (m.size !== undefined && !/^\d{3,4}x\d{3,4}$/.test(String(m.size))) bad('size', '写成 1080x1920 这样')
1263
+ // 两位数:只有嵌入式小屏(160x80);别的类型每边 100 起(和右侧栏的画幅菜单一样)。
1264
+ // 导入时类型收不下的不拦(旧的网页模板写了 160x80):导入那边当没写,用页面写的;分享、投稿照样拦
1265
+ if (m.size !== undefined && (!/^\d{2,4}x\d{2,4}$/.test(String(m.size)) || (mode !== 'install' && !sizeFits(String(m.size), m.kind)))) bad('size', '写成 1080x1920 这样,每边至少 100 像素(嵌入式 64)')
1264
1266
  if (m.os !== undefined && !['mac', 'windows'].includes(m.os)) bad('os', '只能是 mac / windows')
1265
1267
  if (!Array.isArray(m.screens) || !m.screens.length) bad('screens', '至少一屏')
1266
1268
  else if (m.screens.length > capsOf(mode).screens) bad('screens', `最多 ${capsOf(mode).screens} 屏`)
@@ -1366,7 +1368,7 @@ export function hexRatio(a, b) {
1366
1368
  * @param opts.vocab 受控词表
1367
1369
  * @returns { ok, errors, flags, manifest, screens, bytes, kind }
1368
1370
  */
1369
- export function checkPack(files, { mode = 'install', vocab = null } = {}) {
1371
+ export function checkPack(files, { mode = 'install', vocab = null, localZip = mode === 'zip' } = {}) {
1370
1372
  const errors = []
1371
1373
  const flags = []
1372
1374
  const err = (p) => { if (errors.length < 300 && !errors.some((e) => e.code === p.code && e.x === p.x && e.line === p.line && e.n === p.n)) errors.push({ ...p, sev: 'error' }) }
@@ -1460,7 +1462,7 @@ export function checkPack(files, { mode = 'install', vocab = null } = {}) {
1460
1462
  }
1461
1463
  if (type === 'template' && screenSet.has(f.path.toLowerCase())) {
1462
1464
  const mk = metaKind(text)
1463
- if (!mk || (kind && mk !== kind)) err({ code: 'meta', x: f.path, n: kind || 'web' })
1465
+ if (!mk || (!localZip && kind && mk !== kind)) err({ code: 'meta', x: f.path, n: kind || 'web' })
1464
1466
  const title = titleOf(text)
1465
1467
  if (!/\S\s*·\s*\S/.test(title)) err({ code: 'titleFmt', x: f.path })
1466
1468
  }