dsh-design-studio 0.14.0 → 0.16.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 +1 -0
- package/README.md +1 -0
- package/lib/client.js +314 -49
- package/lib/core.js +39 -17
- package/lib/gallery/market.js +23 -1
- package/lib/gallery/pack.js +23 -2
- package/lib/gallery/policy.js +14 -6
- package/lib/gallery/routes.js +3 -3
- package/lib/handoff.js +14 -2
- package/lib/index.js +78 -4
- package/lib/photos-index.json +1 -0
- package/lib/photos.js +265 -0
- package/lib/picker.js +21 -2
- package/lib/tool.js +3 -2
- package/lib/tweaks.js +3 -3
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +1 -1
package/lib/photos.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自带照片库:AI 提前生成、人工挑过的示意照片。模型调 find_photos 按描述找,图复制进设计目录,页面用本地文件。
|
|
3
|
+
*
|
|
4
|
+
* - 目录 photos-index.json 随插件发(描述、标签、尺寸、sha256),搜索不联网。
|
|
5
|
+
* - 图在 npm 包 dsh-design-photos 里,第一次用到才下载;每张按目录里钉死的 sha256 核对,镜像换了图也不认。
|
|
6
|
+
* - 「设计库不联网」开着就不下载(走 market 的 fetchPackage,开关在那边)。
|
|
7
|
+
* - 复制进设计目录的文件名都带 ai-photo- 前缀:转代码时认这个前缀提醒「上线前换成真实照片」,用户一眼也看得出。
|
|
8
|
+
*/
|
|
9
|
+
import crypto from 'node:crypto'
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
import { vcmp } from './gallery/market.js'
|
|
15
|
+
|
|
16
|
+
export const PHOTO_PREFIX = 'ai-photo-'
|
|
17
|
+
export const PHOTOS_CACHE = process.env.DSH_DESIGN_PHOTOS_CACHE || path.join(os.homedir(), '.dsh', 'cache', 'dsh-design-studio', 'photos')
|
|
18
|
+
export const MAX_PHOTOS = 8
|
|
19
|
+
const INDEX_FILE = fileURLToPath(new URL('./photos-index.json', import.meta.url))
|
|
20
|
+
const ID_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/
|
|
21
|
+
const CAP = 60 * 1024 * 1024
|
|
22
|
+
const LIMITS = { files: 1000, file: 4 * 1024 * 1024, total: 120 * 1024 * 1024 }
|
|
23
|
+
const RETRY_MS = 60e3 // 下载失败后隔多久才再试(模型连着调不用每次都等超时)
|
|
24
|
+
// 一次下一个大包:比市场目录的默认超时长得多,每个源 60 秒,总共 2 分钟
|
|
25
|
+
const TIMING = { stagger: 8000, each: 60000, total: 120000 }
|
|
26
|
+
|
|
27
|
+
const sha256 = (b) => crypto.createHash('sha256').update(b).digest('hex')
|
|
28
|
+
const norm = (s) => String(s || '').normalize('NFKC').toLowerCase()
|
|
29
|
+
const ascii = (s) => /^[a-z0-9 -]+$/.test(s)
|
|
30
|
+
|
|
31
|
+
export const orientOf = (w, h) => (w > h * 1.1 ? 'landscape' : h > w * 1.1 ? 'portrait' : 'square')
|
|
32
|
+
|
|
33
|
+
/** 读目录;格式不对的条目不要(目录随插件发,这里只防手滑) */
|
|
34
|
+
export function loadPhotoIndex(file = INDEX_FILE) {
|
|
35
|
+
let raw
|
|
36
|
+
try { raw = JSON.parse(fs.readFileSync(file, 'utf8')) } catch { return null }
|
|
37
|
+
if (!raw || raw.format !== 1 || typeof raw.package !== 'string' || typeof raw.version !== 'string' || !Array.isArray(raw.photos)) return null
|
|
38
|
+
const themes = raw.themes && typeof raw.themes === 'object' ? raw.themes : {}
|
|
39
|
+
const photos = raw.photos.filter((p) => p && ID_RE.test(String(p.id)) && /^[0-9a-f]{64}$/.test(String(p.sha256)) && p.w > 0 && p.h > 0 && themes[p.theme])
|
|
40
|
+
return { ...raw, themes, photos }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const dicts = new WeakMap()
|
|
44
|
+
/** 题材词表 + 全部中文词(长的在前);标签里含本题材词的也算题材词(「奶茶店」「健身房」「运动鞋」) */
|
|
45
|
+
function dictOf(index) {
|
|
46
|
+
let d = dicts.get(index)
|
|
47
|
+
if (d) return d
|
|
48
|
+
const base = {}
|
|
49
|
+
const words = {}
|
|
50
|
+
const cjk = new Set()
|
|
51
|
+
for (const [k, v] of Object.entries(index.themes)) {
|
|
52
|
+
base[k] = new Set((Array.isArray(v.words) ? v.words : []).map(norm).filter(Boolean))
|
|
53
|
+
words[k] = new Set(base[k])
|
|
54
|
+
}
|
|
55
|
+
for (const p of index.photos) {
|
|
56
|
+
for (const t of Array.isArray(p.tags) ? p.tags : []) {
|
|
57
|
+
const x = norm(t)
|
|
58
|
+
if (!x) continue
|
|
59
|
+
if (!ascii(x)) cjk.add(x)
|
|
60
|
+
if (!ascii(x) && [...base[p.theme]].some((w) => !ascii(w) && x.includes(w))) words[p.theme].add(x)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const set of Object.values(words)) for (const w of set) if (!ascii(w)) cjk.add(w)
|
|
64
|
+
const phrases = new Set()
|
|
65
|
+
for (const set of Object.values(words)) for (const w of set) if (ascii(w) && w.includes(' ')) phrases.add(w)
|
|
66
|
+
for (const p of index.photos) for (const t of Array.isArray(p.tags) ? p.tags : []) { const x = norm(t); if (ascii(x) && x.includes(' ')) phrases.add(x) }
|
|
67
|
+
const allBase = new Set(Object.values(base).flatMap((x) => [...x]))
|
|
68
|
+
const generic = new Set((Array.isArray(index.generic) ? index.generic : []).map(norm))
|
|
69
|
+
d = { base, allBase, generic, words, terms: [...cjk].sort((a, b) => b.length - a.length), phrases: [...phrases].sort((a, b) => b.length - a.length) }
|
|
70
|
+
dicts.set(index, d)
|
|
71
|
+
return d
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const singular = (w) => (w.length > 3 && w.endsWith('s') && !w.endsWith('ss') ? w.slice(0, -1) : w)
|
|
75
|
+
const singularAll = (s) => s.split(' ').map(singular).join(' ')
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 查询里命中了哪些词。中文最长词优先吃掉(「运动鞋」不再算「运动」);
|
|
79
|
+
* 单字词只认单独成段的(「海报」「水果」不算「海」「水」)。
|
|
80
|
+
* 英文先按原词归成单数,短语也先吃掉(「meal prep」不再算「meal」,「milk teas」算「milk tea」),其余按整词。
|
|
81
|
+
*/
|
|
82
|
+
function matcherOf(dict, query) {
|
|
83
|
+
const q = norm(query)
|
|
84
|
+
const got = new Set()
|
|
85
|
+
let plain = ` ${singularAll(q.replace(/[^a-z0-9]+/g, ' ').trim())} `
|
|
86
|
+
for (const t of dict.phrases) {
|
|
87
|
+
const needle = ` ${singularAll(t)} `
|
|
88
|
+
if (plain.includes(needle)) { got.add(t); plain = plain.split(needle).join(' ') }
|
|
89
|
+
}
|
|
90
|
+
const words = new Set(plain.split(/\s+/).filter((w) => w.length >= 2))
|
|
91
|
+
let rest = q
|
|
92
|
+
for (const t of dict.terms) {
|
|
93
|
+
if ([...t].length > 1 && rest.includes(t)) { got.add(t); rest = rest.split(t).join(' ') }
|
|
94
|
+
}
|
|
95
|
+
const singles = new Set(dict.terms.filter((t) => [...t].length === 1))
|
|
96
|
+
for (const seg of rest.split(/[^\p{Script=Han}]+/u)) if (singles.has(seg)) got.add(seg)
|
|
97
|
+
return (t) => {
|
|
98
|
+
const x = norm(t)
|
|
99
|
+
if (!x) return false
|
|
100
|
+
if (!ascii(x)) return got.has(x)
|
|
101
|
+
return x.includes(' ') ? got.has(x) : words.has(singular(x))
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 按描述搜:先看具体画面(标签),对上了的只要它们,同题材的优先(宁少勿滥,准确的画面不会被题材词挡掉);
|
|
107
|
+
* 一个都没对上才按题材挑。题材词本身、「特写」「内景」这类通用修饰词不算对上画面,只帮排序。
|
|
108
|
+
* 这套设计已经用过的排最后,内容比横竖要紧;同分时按 seed 打散(同一套设计结果稳定,不同设计不总是同几张)。
|
|
109
|
+
*/
|
|
110
|
+
export function searchPhotos(index, opts = {}) {
|
|
111
|
+
const { count = 3 } = opts
|
|
112
|
+
const n = Math.min(MAX_PHOTOS, Math.max(1, Math.floor(Number(count)) || 3))
|
|
113
|
+
return scan(index, opts).rows.slice(0, n).map((r) => r.p)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 这次只命中了题材、没有对得上的具体画面(工具要照实告诉模型,让它看描述再决定用不用) */
|
|
117
|
+
export const onlyByTheme = (index, opts) => { const r = scan(index, opts); return r.rows.length > 0 && !r.specific }
|
|
118
|
+
|
|
119
|
+
function scan(index, { query, ratio = '', used = new Set(), seed = '' } = {}) {
|
|
120
|
+
const dict = dictOf(index)
|
|
121
|
+
const hit = matcherOf(dict, query)
|
|
122
|
+
const themeScore = {}
|
|
123
|
+
let best = 0
|
|
124
|
+
for (const k of Object.keys(index.themes)) {
|
|
125
|
+
themeScore[k] = [...dict.words[k]].filter(hit).length
|
|
126
|
+
best = Math.max(best, themeScore[k])
|
|
127
|
+
}
|
|
128
|
+
const all = index.photos.map((p) => {
|
|
129
|
+
const hits = (Array.isArray(p.tags) ? p.tags : []).filter(hit).map(norm).filter((t) => !dict.allBase.has(t))
|
|
130
|
+
const core = hits.filter((t) => !dict.generic.has(t)).length
|
|
131
|
+
return { p, core, mods: hits.length - core, theme: themeScore[p.theme], seen: used.has(p.id) ? 1 : 0, fit: ratio && orientOf(p.w, p.h) === ratio ? 1 : 0, rank: sha256(`${seed}\n${p.id}`) }
|
|
132
|
+
})
|
|
133
|
+
const exact = all.filter((r) => r.core > 0)
|
|
134
|
+
const specific = exact.length > 0
|
|
135
|
+
const inBest = best ? exact.filter((r) => r.theme === best) : []
|
|
136
|
+
const rows = specific ? (inBest.length ? inBest : exact) : best ? all.filter((r) => r.theme === best) : []
|
|
137
|
+
rows.sort((a, b) => a.seen - b.seen || b.core - a.core || b.mods - a.mods || b.theme - a.theme || b.fit - a.fit || (a.rank < b.rank ? -1 : a.rank > b.rank ? 1 : 0))
|
|
138
|
+
return { rows, specific }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 设计目录里已经放了哪几张(按文件名认,同一套设计别老用同一张) */
|
|
142
|
+
export function usedPhotos(dir, index) {
|
|
143
|
+
const out = new Set()
|
|
144
|
+
let names = []
|
|
145
|
+
try { names = fs.readdirSync(path.join(dir, 'assets')) } catch { return out }
|
|
146
|
+
const ids = new Set(index.photos.map((p) => p.id))
|
|
147
|
+
for (const n of names) {
|
|
148
|
+
const m = n.startsWith(PHOTO_PREFIX) && n.endsWith('.jpg') ? n.slice(PHOTO_PREFIX.length, -4) : ''
|
|
149
|
+
if (m && ids.has(m)) out.add(m)
|
|
150
|
+
}
|
|
151
|
+
return out
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 目录(或它里面的页面)用了几张 AI 示意图:转代码时提醒 */
|
|
155
|
+
export const isPhotoAsset = (name) => path.basename(String(name)).startsWith(PHOTO_PREFIX)
|
|
156
|
+
|
|
157
|
+
export function createPhotos({ market, index = loadPhotoIndex(), cacheDir = PHOTOS_CACHE, log = () => {}, now = Date.now } = {}) {
|
|
158
|
+
let inflight = null
|
|
159
|
+
let failedAt = -Infinity
|
|
160
|
+
let lastErr = null
|
|
161
|
+
const dirOf = () => path.join(cacheDir, index.version)
|
|
162
|
+
const fileOf = (p) => path.join(dirOf(), `${p.id}.jpg`)
|
|
163
|
+
const okFile = (p) => {
|
|
164
|
+
try { return sha256(fs.readFileSync(fileOf(p))) === p.sha256 } catch { return false }
|
|
165
|
+
}
|
|
166
|
+
const ready = () => {
|
|
167
|
+
// 判断「下过了没有」只看大小(每次全算哈希没必要);真正复制之前逐张核对
|
|
168
|
+
return index.photos.every((p) => { try { return fs.statSync(fileOf(p)).size === p.size } catch { return false } })
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function download() {
|
|
172
|
+
const files = await market.fetchPackage(index.package, index.version, {
|
|
173
|
+
cap: CAP,
|
|
174
|
+
limits: LIMITS,
|
|
175
|
+
timing: TIMING,
|
|
176
|
+
// 在抢下载的回调里核对:哪个源的图不对,算它失败,接着等别的源
|
|
177
|
+
check: (list) => {
|
|
178
|
+
const by = new Map(list.map((f) => [f.path, f.data]))
|
|
179
|
+
const out = []
|
|
180
|
+
for (const p of index.photos) {
|
|
181
|
+
const data = by.get(`photos/${p.id}.jpg`)
|
|
182
|
+
if (!data || sha256(data) !== p.sha256) { const e = new Error('photo mismatch'); e.code = 'mismatch'; throw e }
|
|
183
|
+
out.push({ p, data })
|
|
184
|
+
}
|
|
185
|
+
return out
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
const dir = dirOf()
|
|
189
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
190
|
+
for (const { p, data } of files) {
|
|
191
|
+
const tmp = `${fileOf(p)}.${process.pid}.tmp`
|
|
192
|
+
fs.writeFileSync(tmp, data)
|
|
193
|
+
fs.renameSync(tmp, fileOf(p))
|
|
194
|
+
}
|
|
195
|
+
// 只清比自己旧的版本(另一个配置里更新的插件下的不能动)
|
|
196
|
+
for (const n of fs.readdirSync(cacheDir)) {
|
|
197
|
+
if (/^\d+\.\d+\.\d+/.test(n) && vcmp(n, index.version) < 0) try { fs.rmSync(path.join(cacheDir, n), { recursive: true, force: true }) } catch (e) { log(e) }
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** 保证图都在缓存里;失败抛错(err.code:off = 不联网开着) */
|
|
202
|
+
function ensure() {
|
|
203
|
+
if (ready()) return Promise.resolve()
|
|
204
|
+
if (inflight) return inflight
|
|
205
|
+
if (now() - failedAt < RETRY_MS && lastErr) return Promise.reject(lastErr)
|
|
206
|
+
inflight = download().then(
|
|
207
|
+
() => { failedAt = -Infinity; lastErr = null; inflight = null },
|
|
208
|
+
(e) => { inflight = null; log(e); if (e && e.code === 'off') { failedAt = -Infinity; lastErr = null } else { failedAt = now(); lastErr = e } throw e },
|
|
209
|
+
)
|
|
210
|
+
return inflight
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 把 picks 复制进 <dir>/assets/,返回 [{ p, rel }]。全程同步,真实路径就在写之前核对。
|
|
215
|
+
* allowed(真实路径) 说这个目录能不能写;同名文件已经在了就不动(可能是用户换成了自己的照片);assets 指到外面就不写。
|
|
216
|
+
*/
|
|
217
|
+
function place(dir, picks, allowed = () => true) {
|
|
218
|
+
const denied = () => Object.assign(new Error('outside'), { code: 'link' })
|
|
219
|
+
let probe = path.resolve(dir)
|
|
220
|
+
while (!fs.existsSync(probe)) {
|
|
221
|
+
const up = path.dirname(probe)
|
|
222
|
+
if (up === probe) break
|
|
223
|
+
probe = up
|
|
224
|
+
}
|
|
225
|
+
if (!allowed(fs.realpathSync(probe))) throw denied()
|
|
226
|
+
const assets = path.join(dir, 'assets')
|
|
227
|
+
fs.mkdirSync(assets, { recursive: true })
|
|
228
|
+
const realDir = fs.realpathSync(dir)
|
|
229
|
+
const realAssets = fs.realpathSync(assets)
|
|
230
|
+
if (!allowed(realDir) || realAssets !== path.join(realDir, 'assets')) throw denied()
|
|
231
|
+
const out = []
|
|
232
|
+
for (const p of picks) {
|
|
233
|
+
if (!okFile(p)) {
|
|
234
|
+
// 缓存里这张坏了:删掉,下次 ensure 会重新下
|
|
235
|
+
try { fs.rmSync(fileOf(p), { force: true }) } catch (e) { log(e) }
|
|
236
|
+
throw Object.assign(new Error(`bad cached photo ${p.id}`), { code: 'mismatch' })
|
|
237
|
+
}
|
|
238
|
+
const name = `${PHOTO_PREFIX}${p.id}.jpg`
|
|
239
|
+
try {
|
|
240
|
+
fs.copyFileSync(fileOf(p), path.join(realAssets, name), fs.constants.COPYFILE_EXCL)
|
|
241
|
+
} catch (e) {
|
|
242
|
+
if (!e || e.code !== 'EEXIST') throw e
|
|
243
|
+
}
|
|
244
|
+
out.push({ p, rel: `assets/${name}` })
|
|
245
|
+
}
|
|
246
|
+
return out
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 下载 → 看这套设计用过哪些 → 选图 → 复制。下载之后全程同步,同一目录并发调用不会选到同一批。
|
|
251
|
+
* pick(used) 返回要的图;缓存有坏图时重下一次。
|
|
252
|
+
*/
|
|
253
|
+
async function provide({ dir, allowed, pick }) {
|
|
254
|
+
await ensure()
|
|
255
|
+
try {
|
|
256
|
+
return place(dir, pick(usedPhotos(dir, index)), allowed)
|
|
257
|
+
} catch (e) {
|
|
258
|
+
if (!e || e.code !== 'mismatch') throw e
|
|
259
|
+
}
|
|
260
|
+
await ensure()
|
|
261
|
+
return place(dir, pick(usedPhotos(dir, index)), allowed)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return { index, ready, ensure, place, provide }
|
|
265
|
+
}
|
package/lib/picker.js
CHANGED
|
@@ -2501,13 +2501,32 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
2501
2501
|
return k
|
|
2502
2502
|
}
|
|
2503
2503
|
|
|
2504
|
+
/** 这一屏用了哪些自带照片库的 AI 示意图(<img>、背景图、伪元素背景都算,按文件名):导出时提醒上线前换真照片 */
|
|
2505
|
+
function aiPhotosNow() {
|
|
2506
|
+
const seen = new Set()
|
|
2507
|
+
const add = (u) => { for (const m of String(u || '').matchAll(/ai-photo-[a-z0-9-]+\.jpg/g)) seen.add(m[0]) }
|
|
2508
|
+
for (const im of document.images) add(im.currentSrc || im.src)
|
|
2509
|
+
for (const im of document.querySelectorAll('image')) add(im.getAttribute('href') || im.getAttribute('xlink:href'))
|
|
2510
|
+
// 打包预览时图片已经内联成 data:,名字记在这个 meta 里
|
|
2511
|
+
const noted = document.querySelector('meta[name="ddp-ai-photos"]')
|
|
2512
|
+
if (noted) add(noted.content)
|
|
2513
|
+
for (const el of [...document.querySelectorAll('*')].slice(0, 4000)) {
|
|
2514
|
+
for (const pseudo of [null, '::before', '::after']) {
|
|
2515
|
+
const cs = getComputedStyle(el, pseudo)
|
|
2516
|
+
if (cs.backgroundImage && cs.backgroundImage !== 'none') add(cs.backgroundImage)
|
|
2517
|
+
if (pseudo && cs.content && cs.content !== 'none' && cs.content !== 'normal') add(cs.content)
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
return [...seen]
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2504
2523
|
async function onCapture(d) {
|
|
2505
2524
|
try {
|
|
2506
2525
|
const r = await capture(d)
|
|
2507
2526
|
// 整页图从文档顶上画起,链接加上滚动距离;只截视口时就是视口里的位置
|
|
2508
2527
|
const links = linksOf().map((l) => (d.full ? { ...l, x: l.x + scrollX, y: l.y + scrollY } : l))
|
|
2509
2528
|
.filter((l) => l.x < r.w && l.y < r.h && l.x + l.w > 0 && l.y + l.h > 0)
|
|
2510
|
-
post({ type: 'captured', id: d.id, png: r.png, w: r.w, h: r.h, scale: r.scale, title: document.title, links, top: r.top, href: here() })
|
|
2529
|
+
post({ type: 'captured', id: d.id, png: r.png, w: r.w, h: r.h, scale: r.scale, title: document.title, links, top: r.top, href: here(), aiPhotos: aiPhotosNow() })
|
|
2511
2530
|
} catch (e) {
|
|
2512
2531
|
post({ type: 'captured', id: d.id, error: String((e && e.message) || e) })
|
|
2513
2532
|
}
|
|
@@ -2537,7 +2556,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
2537
2556
|
} catch { /* 查不了就不算 */ }
|
|
2538
2557
|
}))
|
|
2539
2558
|
for (const l of found) if (gone.get(l.path)) dead.push(l.y + scrollY)
|
|
2540
|
-
post({ type: 'measured', id: d.id, sy: scrollY, w: de.clientWidth || innerWidth, h: innerHeight, pageW: Math.max(de.scrollWidth, b ? b.scrollWidth : 0), pageH: Math.max(de.scrollHeight, b ? b.scrollHeight : 0), natural: naturalSize(), dead })
|
|
2559
|
+
post({ type: 'measured', id: d.id, sy: scrollY, aiPhotos: aiPhotosNow(), w: de.clientWidth || innerWidth, h: innerHeight, pageW: Math.max(de.scrollWidth, b ? b.scrollWidth : 0), pageH: Math.max(de.scrollHeight, b ? b.scrollHeight : 0), natural: naturalSize(), dead })
|
|
2541
2560
|
} catch (e) {
|
|
2542
2561
|
post({ type: 'measured', id: d.id, error: String((e && e.message) || e) })
|
|
2543
2562
|
}
|
package/lib/tool.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-design-studio/tool:把 preview_page、check_design、look_design、extract_design_system、handoff_design、compare_design 挂给模型。
|
|
2
|
+
* dsh-design-studio/tool:把 preview_page、check_design、look_design、extract_design_system、handoff_design、compare_design、find_photos 挂给模型。
|
|
3
3
|
* 放在 bundle 顶层 → 所有模式都能用;放进设计模式 → 只挂在那个模式里。工具本身见 index.js
|
|
4
4
|
*/
|
|
5
|
-
import { previewTool, checkTool, lookTool, systemTool, handoffTool, compareTool } from './index.js'
|
|
5
|
+
import { previewTool, checkTool, lookTool, systemTool, handoffTool, compareTool, photoTool } from './index.js'
|
|
6
6
|
|
|
7
7
|
export const name = 'dsh-design-studio-tool'
|
|
8
8
|
export const inject = ['tools']
|
|
@@ -15,4 +15,5 @@ export function apply(ctx) {
|
|
|
15
15
|
ctx.tools.register({ ...systemTool, execute: (args, exec) => systemTool.execute(args, exec, ctx) })
|
|
16
16
|
ctx.tools.register({ ...handoffTool, execute: (args, exec) => handoffTool.execute(args, exec, ctx) })
|
|
17
17
|
ctx.tools.register({ ...compareTool, execute: (args, exec) => compareTool.execute(args, exec, ctx) })
|
|
18
|
+
ctx.tools.register({ ...photoTool })
|
|
18
19
|
}
|
package/lib/tweaks.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import fs from 'node:fs'
|
|
17
17
|
import path from 'node:path'
|
|
18
|
-
import {
|
|
18
|
+
import { allScreens } from './core.js'
|
|
19
19
|
import { parseColor, hexOf } from './system.js'
|
|
20
20
|
|
|
21
21
|
export const TWEAKS_FILE = 'tweaks.json'
|
|
@@ -270,7 +270,7 @@ function cssFiles(root, realRoot = '') {
|
|
|
270
270
|
let names = []
|
|
271
271
|
try { names = fs.readdirSync(root) } catch { return [] }
|
|
272
272
|
const css = names.filter((n) => /\.css$/i.test(n) && !n.startsWith('.')).sort((a, b) => (a === 'tokens.css' ? -1 : b === 'tokens.css' ? 1 : a.localeCompare(b)))
|
|
273
|
-
return [...css, ...
|
|
273
|
+
return [...css, ...allScreens(root)].filter((rel) => ownFile(root, realRoot, rel))
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/** 外观面板里直接改的设计变量:{ '--名字': 值 } → [[名字, 值]](名字、值都要老实:值里不能有 ; { } < 换行) */
|
|
@@ -333,7 +333,7 @@ export function applyTweaks(root, values, vars) {
|
|
|
333
333
|
if (k.var) {
|
|
334
334
|
if (!writeVar(k.var, cssValue(k, v))) { missed.push({ id: k.id, label: k.label }); continue }
|
|
335
335
|
} else {
|
|
336
|
-
for (const rel of
|
|
336
|
+
for (const rel of allScreens(root)) {
|
|
337
337
|
if (!ownFile(root, realRoot, rel)) continue
|
|
338
338
|
const next = setHtmlAttr(read(rel), k.attr, v)
|
|
339
339
|
if (next !== null) texts.set(rel, next)
|
package/package.json
CHANGED
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
|
|
127
127
|
**界面语言跟着用户走**:用户用什么语言提需求,界面文案就用什么语言(英文提问做英文界面,中文提问做中文界面);用户点名了语言或市场(「给日本用户」「做英文版」)就照他说的。货币、日期格式、人名地名也跟着那个市场。跟用户说话仍用他的语言。
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
**图片**:用户给了照片就用用户的。靠照片说话的设计(民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景)需要头图、封面、商品图时,调 `find_photos` 从自带照片库拿,一次要够这几屏用的,别画插画冒充照片;库里没有合适的,或者题材本身不靠照片(工具、后台、数据类),才用 SVG 插画、几何构图或色块。不引用外网图片(预览离线也要好看)。库里的是 AI 生成的示意图:不写「实拍」,做完告诉用户上线前换成真实照片。
|
|
130
130
|
|
|
131
131
|
**图标**:用一套线性 SVG 图标(同样的线宽 1.75–2、圆角端点、24 网格),内联写进 HTML。不要用 emoji 当图标。
|
|
132
132
|
|