dsh-design-studio 1.2.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 +1 -0
- package/README.md +1 -0
- package/lib/bundle.js +19 -15
- package/lib/client.js +254 -10
- package/lib/fonts-index.json +320 -0
- package/lib/fonts-preview.json +1 -0
- package/lib/fonts.js +352 -0
- package/lib/gallery/pack.js +7 -0
- package/lib/handoff.js +7 -0
- package/lib/history.js +2 -0
- package/lib/htmlpack.js +30 -5
- package/lib/index.js +191 -9
- package/lib/picker.js +47 -4
- package/lib/serve.js +36 -2
- package/lib/tool.js +3 -2
- package/lib/tweaks.js +135 -4
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +3 -1
package/README.en.md
CHANGED
|
@@ -51,6 +51,7 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
|
|
|
51
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.
|
|
52
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.
|
|
53
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.
|
|
54
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.
|
|
55
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).
|
|
56
57
|
|
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
- **市场、我的作品、灵感**:首页顶上三个页签。以前做过的设计(还有自己存的外框,能改名、删除)在「我的作品」,收的参考图和风格在「灵感」;「市场」里逛大家分享的模板、设计系统和风格卡,点「用这个开始」复制一份接着改。自己做的从「分享」›「投稿到市场」交上去,查过打成 zip,审过就上架。市场目录从 npm 镜像取,签了名、核对过才用;不想让它联网,在插件页打开「设计库不联网」。
|
|
52
52
|
- **照品牌风格做、转成代码**:给官网地址,提一套品牌设计系统,以后都照它做;做好的设计转成 React / Vue / HTML,小程序直接转成 uni-app 或原生小程序代码(HBuilderX 建的项目也认得出),逐屏和设计稿比对。
|
|
53
53
|
- **自带照片库**:民宿酒店、餐饮、奶茶咖啡、健身、美妆、服饰、教育、旅行风景这些靠照片说话的设计,模型会直接用上照片,不再只画插画。第一次用到时下载约 8 MB。都是 AI 生成的示意图,上线前请换成真实照片。
|
|
54
|
+
- **自带字体库**:外观面板里点字体那行,就能从 18 款免费可商用字体里挑(思源黑体 / 宋体、得意黑、站酷系列、毛笔楷书、行书,加上 Inter 等英文字体),页面马上换,保存后字体文件放进设计目录,导出、远程看都带着。也可以直接跟模型说「标题用毛笔字」。第一次用到时下载约 19 MB。
|
|
54
55
|
- **按题材挑风格**:没定风格时,模型先按题材挑一张风格卡(配色、字体、圆角)再动手,民宿、奶茶店、复盘幻灯片不再都是一个米色调;你自己说了风格或配色就照你的。
|
|
55
56
|
- **业务标注(试验,默认关)**:在「插件」页的设计工作台里打开「业务标注」,模型做设计时同时写一份 `annotations.json`,记界面上看不出来的规则、状态和边界。页面上出编号,右侧栏列卡片,点哪边都能定位到另一边;转成代码时这些规则一起交给开发(#15)。
|
|
56
57
|
|
package/lib/bundle.js
CHANGED
|
@@ -133,24 +133,26 @@ function spriteOf(text, pre) {
|
|
|
133
133
|
* @param opts.read (rel) → Buffer | null:读设计目录里的文件(越界、不存在、太大返回 null)
|
|
134
134
|
* @param opts.tail 插在 </body> 前的东西(picker 和它的配置)
|
|
135
135
|
* @param opts.lead 插在 <head> 最前面(<base> 后面)的东西:报错记录
|
|
136
|
+
* @param opts.onSkip (rel) → 有这个文件、但太大 / 超了上限没内联上(整套演示据此提醒缺了哪些)
|
|
137
|
+
* @param opts.max 这一屏内联的总量上限(默认 MAX_TOTAL:远程看一屏一屏传;整套演示几屏共用一份,给得多些)
|
|
136
138
|
* @param opts.base 这一屏原来的地址:放一个 <base>,没内联上的相对地址照原样指过去(不指到 DSH 网页上)
|
|
137
139
|
* @returns string
|
|
138
140
|
*/
|
|
139
|
-
export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
140
|
-
let budget =
|
|
141
|
-
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
|
|
142
144
|
const cache = new Map()
|
|
143
145
|
const get = (rel) => {
|
|
144
146
|
if (cache.has(rel)) return cache.get(rel)
|
|
145
147
|
let buf = null
|
|
146
|
-
if (readLeft > 0) { try { buf = read(rel) } catch { buf = null } }
|
|
147
|
-
if (buf && buf.length > Math.min(
|
|
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) }
|
|
148
150
|
if (buf) readLeft -= buf.length
|
|
149
151
|
cache.set(rel, buf)
|
|
150
152
|
return buf
|
|
151
153
|
}
|
|
152
|
-
/**
|
|
153
|
-
const spend = (n) => { if (n > budget) return false
|
|
154
|
+
/** 花预算:够就扣掉;不够的告诉调用方(rel:哪个文件没放进去) */
|
|
155
|
+
const spend = (n, rel) => { if (n > budget) { if (onSkip && rel) onSkip(rel); return false } budget -= n; return true }
|
|
154
156
|
const typeOf = (rel) => {
|
|
155
157
|
const t = (MIME[path.posix.extname(rel).toLowerCase()] || 'application/octet-stream').replace(/;.*/, '')
|
|
156
158
|
return /^text\//.test(t) ? `${t};charset=utf-8` : t
|
|
@@ -162,7 +164,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
162
164
|
if (!buf) return ''
|
|
163
165
|
let d = encoded.get(rel)
|
|
164
166
|
if (!d) { d = `data:${typeOf(rel)};base64,${buf.toString('base64')}`; encoded.set(rel, d) }
|
|
165
|
-
return spend(d.length) ? d : ''
|
|
167
|
+
return spend(d.length, rel) ? d : ''
|
|
166
168
|
}
|
|
167
169
|
const dataUrl = (from, url) => {
|
|
168
170
|
const ref = localRef(url)
|
|
@@ -175,7 +177,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
175
177
|
if (!ref || depth >= MAX_DEPTH) return m
|
|
176
178
|
const rel = join(from, ref)
|
|
177
179
|
const buf = get(rel)
|
|
178
|
-
if (!buf || !spend(buf.length)) return m
|
|
180
|
+
if (!buf || !spend(buf.length, rel)) return m
|
|
179
181
|
const inner = css(buf.toString('utf8').replace(/^\ufeff/, ''), rel, depth + 1)
|
|
180
182
|
return media.trim() ? `@media ${media.trim()}{${inner}}` : inner
|
|
181
183
|
})
|
|
@@ -206,7 +208,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
206
208
|
return `${pre}${q}${absOf(dep)}${q}`
|
|
207
209
|
}) + `\n//# sourceURL=${abs}\n` // 每个文件一个 data:(内容一样的两个文件也是两个模块),报错时也看得出是哪个文件
|
|
208
210
|
const d = `data:text/javascript;charset=utf-8;base64,${Buffer.from(text).toString('base64')}`
|
|
209
|
-
if (!spend(d.length)) { mods.delete(abs); return '' }
|
|
211
|
+
if (!spend(d.length, rel)) { mods.delete(abs); return '' }
|
|
210
212
|
mods.set(abs, d)
|
|
211
213
|
return d
|
|
212
214
|
}
|
|
@@ -215,7 +217,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
215
217
|
|
|
216
218
|
let out = String(html)
|
|
217
219
|
// 样式表:<link rel="stylesheet" href="x.css"> → <style>
|
|
218
|
-
.replace(/<link\b[^>]*>/gi, (tag) => {
|
|
220
|
+
.replace(/<link\b(?:[^>"']|"[^"]*"|'[^']*')*>/gi, (tag) => {
|
|
219
221
|
if (!/\brel\s*=\s*["']?[^"'>]*stylesheet/i.test(tag)) {
|
|
220
222
|
// 图标之类的 <link href> 换成 data:
|
|
221
223
|
return tag.replace(/(\bhref\s*=\s*)(["'])([^"']*)\2/i, (m, a, q, u) => `${a}${q}${escAttr(dataUrl(key, u))}${q}`)
|
|
@@ -226,12 +228,12 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
226
228
|
if (!ref) return tag
|
|
227
229
|
const rel = join(key, ref)
|
|
228
230
|
const buf = get(rel)
|
|
229
|
-
if (!buf || !spend(buf.length)) return tag
|
|
231
|
+
if (!buf || !spend(buf.length, rel)) return tag
|
|
230
232
|
const media = /\bmedia\s*=\s*(["'])([^"']*)\1/i.exec(tag)
|
|
231
233
|
return `<style data-href="${escAttr(href)}"${media ? ` media="${escAttr(media[2])}"` : ''}>${css(buf.toString('utf8').replace(/^\ufeff/, ''), rel).replace(/<\/style/gi, '<\\/style')}</style>`
|
|
232
234
|
})
|
|
233
235
|
// 页面里的 <style>:url() 相对这一屏
|
|
234
|
-
.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))
|
|
235
237
|
// 脚本:本地的经典脚本换成 src="data:…"(defer、async、执行顺序都和原来一样);模块见上
|
|
236
238
|
.replace(/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi, (m, attrs, body) => {
|
|
237
239
|
const s = /\bsrc\s*=\s*(["'])([^"']*)\1/i.exec(attrs) || /\bsrc\s*=\s*([^\s>"']+)/i.exec(attrs)
|
|
@@ -250,7 +252,9 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
250
252
|
})
|
|
251
253
|
// 图片、视频、音频、SVG 里的 image
|
|
252
254
|
// 原来的 src 留在 data-dsh-src(体检比外框指纹时按它:换了张图也认得出)
|
|
253
|
-
|
|
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
|
|
254
258
|
let orig = null
|
|
255
259
|
let origSet = null
|
|
256
260
|
const tag = tag0
|
|
@@ -284,7 +288,7 @@ export function bundle(html, { key, read, tail = '', base = '', lead = '' }) {
|
|
|
284
288
|
const buf = get(rel)
|
|
285
289
|
const pre = `dsh${sprites.size + 1}-`
|
|
286
290
|
const text = buf ? spriteOf(buf.toString('utf8').replace(/^\ufeff/, '').replace(/<\?xml[\s\S]*?\?>|<!DOCTYPE[^>]*>/gi, '').trim(), pre) : ''
|
|
287
|
-
if (!/^<svg\b/i.test(text) || !spend(text.length)) return m
|
|
291
|
+
if (!/^<svg\b/i.test(text) || !spend(text.length, rel)) return m
|
|
288
292
|
sprites.set(rel, { pre, text })
|
|
289
293
|
}
|
|
290
294
|
let id = u.slice(i + 1)
|
package/lib/client.js
CHANGED
|
@@ -204,6 +204,7 @@ window.__ModuleLoader__.load({
|
|
|
204
204
|
exportedDocMiss: '已导出 {name}({n} 页,{miss} 屏没截到)',
|
|
205
205
|
exportedHtml: '已导出 {name}({n} 屏,发给别人双击就能看)',
|
|
206
206
|
exportedHtmlMiss: '已导出 {name}({n} 屏,{miss} 屏没读到)',
|
|
207
|
+
exportedHtmlSkip: '。{n} 个文件太大没放进去,演示里会缺({files}):单个文件最多 12 MB、一屏的图和字体加起来最多 48 MB',
|
|
207
208
|
htmlTooBig: '图片太多,演示包超过 150 MB,没导出。少放几屏再试',
|
|
208
209
|
htmlImgBig: '模拟数据(mock.json)里绑的图太大(单张最多 12 MB、加起来最多 60 MB),放不进演示,没导出。换小一点的图再试',
|
|
209
210
|
htmlMockBig: 'mock.json 太大(超过 1 MB),演示里的数据带不上,没导出。把里面的大段内容(比如图片的 base64)换成图片文件路径再试',
|
|
@@ -779,6 +780,27 @@ window.__ModuleLoader__.load({
|
|
|
779
780
|
lookStyle: '换风格',
|
|
780
781
|
lookBrand: '品牌',
|
|
781
782
|
lookTokTip: '点一下放进对话,接着说怎么改',
|
|
783
|
+
fpRowTip: '点开换字体:字体库(免费可商用)或电脑自带的',
|
|
784
|
+
fpTitle: '换{name}',
|
|
785
|
+
fpNow: '现在:{v}',
|
|
786
|
+
fpBack: '返回',
|
|
787
|
+
fpLib: '字体库 · 免费可商用',
|
|
788
|
+
fpLibTip: 'SIL 开放字体许可(OFL),个人、商用都免费。中文只带了常用的 6763 个字,生僻字由系统字体补上。存下时字体文件会复制进设计的 dsh-fonts/ 文件夹',
|
|
789
|
+
fpDl: '第一次用要下载字体库({mb} MB),之后不用再下',
|
|
790
|
+
fpOff: '「设计库不联网」开着,字体库下载不了',
|
|
791
|
+
fpNet: '字体库这会儿下载不了,稍后再试',
|
|
792
|
+
fpZh: '中文',
|
|
793
|
+
fpEn: '英文(只有英文和数字,中文用系统字体)',
|
|
794
|
+
fpSys: '电脑自带',
|
|
795
|
+
fpSysTip: '用的是这台电脑装的字体,别人电脑上没有时会换成相近的。商用海报要看字体授权',
|
|
796
|
+
fpAsk: '交给模型',
|
|
797
|
+
fpAskTip: '放进对话,说想要什么感觉,让模型挑',
|
|
798
|
+
fpNone: '这个版本的设计台没带字体库',
|
|
799
|
+
fpLoading: '正在读字体库…',
|
|
800
|
+
lookLibFont: '(字体库的「{name}」:调 use_fonts 放进来,var 填 {var})',
|
|
801
|
+
fontOffSave: '「设计库不联网」开着,字体库的字体放不进设计,没保存',
|
|
802
|
+
fontNetSave: '字体库下载不了,没保存(稍后再试)',
|
|
803
|
+
fontWriteSave: '设计目录的 dsh-fonts/ 写不进去,没保存',
|
|
782
804
|
lookShape: '形状',
|
|
783
805
|
lookPal: '配色',
|
|
784
806
|
lookNoColor: '没有颜色变量。',
|
|
@@ -814,7 +836,7 @@ window.__ModuleLoader__.load({
|
|
|
814
836
|
tkn_xs: '注释', tkn_sm: '小字', tkn_md: '中号字', tkn_body: '正文', tkn_lg: '大字', tkn_title: '标题', tkn_display: '大标题',
|
|
815
837
|
tkn_rSm: '小圆角', tkn_rMd: '中圆角', tkn_rLg: '大圆角', tkn_rFull: '全圆', tkn_r: '圆角',
|
|
816
838
|
tkn_space: '间距', tkn_gutter: '页边距',
|
|
817
|
-
tkn_fHead: '标题字体', tkn_fBody: '正文字体', tkn_fMono: '等宽字体',
|
|
839
|
+
tkn_fHead: '标题字体', tkn_fBody: '正文字体', tkn_fMono: '等宽字体', tkn_fArt: '书法字体',
|
|
818
840
|
tkn_shadow: '阴影', tkn_light: '浅', tkn_dark: '深', tkn_hover: '悬停',
|
|
819
841
|
sizesNoShort: '固定画幅',
|
|
820
842
|
working: '模型正在工作',
|
|
@@ -1198,6 +1220,7 @@ window.__ModuleLoader__.load({
|
|
|
1198
1220
|
pkNote_form: '{n} 个表单地址',
|
|
1199
1221
|
pkNote_ping: '{n} 个 ping',
|
|
1200
1222
|
pkNote_exif: '{n} 张图片的拍摄信息',
|
|
1223
|
+
pkNote_fontLib: '{n} 个文件里字体库的字体(字体不进包,分享出去用系统字体显示)',
|
|
1201
1224
|
pkFail: '有 {n} 个问题要先改:',
|
|
1202
1225
|
pkMore: '还有 {n} 个…',
|
|
1203
1226
|
pkFix: '让模型改',
|
|
@@ -1429,6 +1452,7 @@ window.__ModuleLoader__.load({
|
|
|
1429
1452
|
exportedDocMiss: 'Exported {name} ({n} pages, {miss} screens could not be captured)',
|
|
1430
1453
|
exportedHtml: 'Exported {name} ({n} screens; anyone can open it with a double-click)',
|
|
1431
1454
|
exportedHtmlMiss: 'Exported {name} ({n} screens, {miss} could not be read)',
|
|
1455
|
+
exportedHtmlSkip: '. {n} file(s) were too big to include and will be missing ({files}): 12 MB per file and 48 MB of images and fonts per screen at most',
|
|
1432
1456
|
htmlTooBig: 'Too many images: the demo would be over 150 MB, so nothing was exported. Try with fewer screens',
|
|
1433
1457
|
htmlImgBig: 'An image referenced in the mock data (mock.json) is too big (12 MB each, 60 MB in total at most) to fit in the demo, so nothing was exported. Try a smaller image',
|
|
1434
1458
|
htmlMockBig: 'mock.json is too big (over 1 MB) to carry its data into the demo, so nothing was exported. Replace large content (like base64 images) with image file paths and try again',
|
|
@@ -2003,6 +2027,27 @@ window.__ModuleLoader__.load({
|
|
|
2003
2027
|
lookStyle: 'Restyle',
|
|
2004
2028
|
lookBrand: 'Brand',
|
|
2005
2029
|
lookTokTip: 'Click to add it to the chat, then say how to change it',
|
|
2030
|
+
fpRowTip: 'Change the font: from the font library (free for commercial use) or this computer',
|
|
2031
|
+
fpTitle: 'Change {name}',
|
|
2032
|
+
fpNow: 'Now: {v}',
|
|
2033
|
+
fpBack: 'Back',
|
|
2034
|
+
fpLib: 'Font library · free for commercial use',
|
|
2035
|
+
fpLibTip: 'SIL Open Font License (OFL): free for personal and commercial use. Chinese fonts carry the 6,763 common characters; rare ones fall back to system fonts. Saving copies the font files into the design\'s dsh-fonts/ folder',
|
|
2036
|
+
fpDl: 'The first use downloads the font library ({mb} MB), once',
|
|
2037
|
+
fpOff: '"Design library offline" is on, so the font library cannot be downloaded',
|
|
2038
|
+
fpNet: 'The font library cannot be downloaded right now. Try again later',
|
|
2039
|
+
fpZh: 'Chinese',
|
|
2040
|
+
fpEn: 'Latin (letters and numbers only; Chinese uses system fonts)',
|
|
2041
|
+
fpSys: 'On this computer',
|
|
2042
|
+
fpSysTip: 'Fonts installed on this computer. Computers without them show a similar font. Check the font license for commercial posters',
|
|
2043
|
+
fpAsk: 'Ask the model',
|
|
2044
|
+
fpAskTip: 'Add it to the chat, describe the feel you want and let the model pick',
|
|
2045
|
+
fpNone: 'This version of the studio has no font library',
|
|
2046
|
+
fpLoading: 'Loading the font library…',
|
|
2047
|
+
lookLibFont: ' (font library "{name}": call use_fonts with var {var})',
|
|
2048
|
+
fontOffSave: '"Design library offline" is on, so library fonts cannot be added. Not saved',
|
|
2049
|
+
fontNetSave: 'The font library cannot be downloaded. Not saved (try again later)',
|
|
2050
|
+
fontWriteSave: 'Cannot write the design\'s dsh-fonts/ folder. Not saved',
|
|
2006
2051
|
lookShape: 'Shape',
|
|
2007
2052
|
lookPal: 'Colors',
|
|
2008
2053
|
lookNoColor: 'No color tokens.',
|
|
@@ -2038,7 +2083,7 @@ window.__ModuleLoader__.load({
|
|
|
2038
2083
|
tkn_xs: 'Caption', tkn_sm: 'Small', tkn_md: 'Medium', tkn_body: 'Body', tkn_lg: 'Large', tkn_title: 'Title', tkn_display: 'Display',
|
|
2039
2084
|
tkn_rSm: 'Small corners', tkn_rMd: 'Medium corners', tkn_rLg: 'Large corners', tkn_rFull: 'Pill', tkn_r: 'Corners',
|
|
2040
2085
|
tkn_space: 'Spacing', tkn_gutter: 'Page margin',
|
|
2041
|
-
tkn_fHead: 'Heading font', tkn_fBody: 'Body font', tkn_fMono: 'Mono font',
|
|
2086
|
+
tkn_fHead: 'Heading font', tkn_fBody: 'Body font', tkn_fMono: 'Mono font', tkn_fArt: 'Script font',
|
|
2042
2087
|
tkn_shadow: 'Shadow', tkn_light: 'light', tkn_dark: 'dark', tkn_hover: 'hover',
|
|
2043
2088
|
sizesNoShort: 'Fixed size',
|
|
2044
2089
|
working: 'The model is working',
|
|
@@ -2421,6 +2466,7 @@ window.__ModuleLoader__.load({
|
|
|
2421
2466
|
pkNote_form: '{n} form addresses',
|
|
2422
2467
|
pkNote_ping: '{n} pings',
|
|
2423
2468
|
pkNote_exif: 'photo metadata in {n} images',
|
|
2469
|
+
pkNote_fontLib: 'font-library fonts in {n} files (fonts are not packed; the shared copy shows system fonts)',
|
|
2424
2470
|
pkFail: '{n} things to fix first:',
|
|
2425
2471
|
pkMore: '{n} more…',
|
|
2426
2472
|
pkFix: 'Ask the model',
|
|
@@ -4367,6 +4413,32 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
4367
4413
|
.ddp .dd-tkr>.vl{flex:none;max-width:55%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;color:var(--dd-t3);font-variant-numeric:tabular-nums}
|
|
4368
4414
|
.ddp .dd-tkr>.shb{width:30px;height:20px;flex:none;border-radius:6px;background:#ececef;display:grid;place-items:center}
|
|
4369
4415
|
.ddp .dd-tkr>.shb>.sh{width:16px;height:10px;border-radius:3px;background:#fff}
|
|
4416
|
+
.ddp .dd-tkr.on{box-shadow:inset 0 0 0 1.5px var(--dd-acc)}
|
|
4417
|
+
.ddp .dd-tkr.on>.vl{color:var(--dd-acc)}
|
|
4418
|
+
.ddp .dd-tkr>.go{flex:none;display:grid;place-items:center;width:14px;height:14px;margin-right:-4px;color:var(--dd-t3);transform:rotate(180deg)}
|
|
4419
|
+
.ddp .dd-tkr>.go svg{width:14px;height:14px}
|
|
4420
|
+
.ddp .dd-fp{display:flex;flex-direction:column;gap:14px;min-width:0}
|
|
4421
|
+
.ddp .dd-fph{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-width:0}
|
|
4422
|
+
.ddp .dd-fph>b{font-size:14px;color:var(--dd-t1)}
|
|
4423
|
+
.ddp .dd-fph>.note{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
4424
|
+
.ddp .dd-fps{display:flex;flex-direction:column;gap:8px;min-width:0}
|
|
4425
|
+
.ddp .dd-fps>h6{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin:0;font-size:12px;font-weight:600;color:var(--dd-t2)}
|
|
4426
|
+
.ddp .dd-fps>h6>small{font-weight:400;font-size:11.5px;color:var(--dd-t3);letter-spacing:0;text-transform:none}
|
|
4427
|
+
.ddp .dd-fps>em{font-style:normal;font-size:11.5px;color:var(--dd-t3);margin-top:2px}
|
|
4428
|
+
.ddp .dd-fpg{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:6px}
|
|
4429
|
+
.ddp .dd-fnt{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:4px;position:relative;min-width:0;min-height:58px;padding:8px 30px 8px 12px;border:0;border-radius:var(--dd-r2);background:var(--dd-f1);box-shadow:inset 0 0 0 1px var(--dd-line);color:var(--dd-t1);font:inherit;text-align:left;cursor:pointer;transition:background-color .15s,box-shadow .15s,transform .12s var(--dd-out)}
|
|
4430
|
+
.ddp .dd-fnt:hover{background:var(--dd-f2);box-shadow:inset 0 0 0 1px var(--dd-line2)}
|
|
4431
|
+
.ddp .dd-fnt:active{transform:scale(.985)}
|
|
4432
|
+
.ddp .dd-fnt:focus-visible{outline:2px solid var(--dd-acc);outline-offset:-2px}
|
|
4433
|
+
.ddp .dd-fnt:disabled{opacity:.5;cursor:default}
|
|
4434
|
+
.ddp .dd-fnt.on{box-shadow:inset 0 0 0 1.5px var(--dd-acc)}
|
|
4435
|
+
.ddp .dd-fnt>.pv{display:flex;align-items:center;height:24px;max-width:100%;min-width:0;color:var(--dd-t1)}
|
|
4436
|
+
.ddp .dd-fnt>.pv svg{height:22px;width:auto;max-width:100%;overflow:visible}
|
|
4437
|
+
.ddp .dd-fnt>.pv path{fill:currentColor}
|
|
4438
|
+
.ddp .dd-fnt>.pv b{font-size:17px;font-weight:500;line-height:24px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
4439
|
+
.ddp .dd-fnt>.nt{display:flex;align-items:center;gap:6px;max-width:100%;min-width:0;font-size:11.5px;color:var(--dd-t3)}
|
|
4440
|
+
.ddp .dd-fnt>.nt>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
4441
|
+
.ddp .dd-fnt>svg{position:absolute;top:50%;right:10px;width:16px;height:16px;margin-top:-8px;color:var(--dd-acc)}
|
|
4370
4442
|
.ddp .dd-f>.lbl b.on{color:var(--dd-acc)}
|
|
4371
4443
|
.ddp .dd-sws.wr{flex-wrap:wrap}
|
|
4372
4444
|
.ddp .ddp-lktw .dd-seg{width:100%}
|
|
@@ -5447,6 +5519,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
5447
5519
|
const m = rest(/^$/).join(' ')
|
|
5448
5520
|
return m ? `${t('tkn_space')} ${m}` : t('tkn_space')
|
|
5449
5521
|
} else if (kind === 'font') {
|
|
5522
|
+
if (has(/^(brush|calligraphy|script|hand|handwriting)$/)) return t('tkn_fArt')
|
|
5450
5523
|
if (has(/^(head|heading|display|title|serif|brand)$/)) return t('tkn_fHead')
|
|
5451
5524
|
if (has(/^(mono|code)$/)) return t('tkn_fMono')
|
|
5452
5525
|
if (has(/^(body|text|sans|base|ui)$/)) return t('tkn_fBody')
|
|
@@ -7833,7 +7906,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
7833
7906
|
}
|
|
7834
7907
|
setErrs((m) => (JSON.stringify(m[id] || null) === JSON.stringify(fail) ? m : { ...m, [id]: fail }))
|
|
7835
7908
|
if (p.dark) postTo(id, { type: 'theme', dark: true })
|
|
7836
|
-
if (p.tweak) postTo(id, { type: 'tweak', vars: p.tweak.vars, attrs: p.tweak.attrs })
|
|
7909
|
+
if (p.tweak) postTo(id, { type: 'tweak', vars: p.tweak.vars, attrs: p.tweak.attrs, fonts: p.tweak.fonts || [] })
|
|
7837
7910
|
try { if (d.href) L.pageOf.set(id, keyOfPath(decodeURIComponent(new URL(d.href).pathname), true)) } catch { /* 地址不认识:当没跳 */ }
|
|
7838
7911
|
{
|
|
7839
7912
|
const list = annotsOf(p, id)
|
|
@@ -7989,7 +8062,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
7989
8062
|
useEffect(() => { if (cur) postTo(cur, { type: 'demo', on: !!props.demo }) }, [!!props.demo])
|
|
7990
8063
|
// 调节滑块:拖的时候改页面上的 CSS 变量 / <html> 属性(新载的一帧在 ready 时套上)
|
|
7991
8064
|
const twSig = JSON.stringify(props.tweak || null)
|
|
7992
|
-
useEffect(() => { if (cur) postTo(cur, { type: 'tweak', vars: (props.tweak || {}).vars || {}, attrs: (props.tweak || {}).attrs || {} }) }, [twSig])
|
|
8065
|
+
useEffect(() => { if (cur) postTo(cur, { type: 'tweak', vars: (props.tweak || {}).vars || {}, attrs: (props.tweak || {}).attrs || {}, fonts: (props.tweak || {}).fonts || [] }) }, [twSig])
|
|
7993
8066
|
// 业务标注:编号画在页面里(新载的一帧在 ready 时再发一次);点选、改字这些模式下 annots 是 null,编号收起
|
|
7994
8067
|
const anSig = JSON.stringify(props.annots || null)
|
|
7995
8068
|
useEffect(() => { if (cur) postTo(cur, { type: 'annots', list: annotsOf(props, cur) || [], sel: props.annotSel || '' }) }, [anSig, props.annotVer])
|
|
@@ -8900,6 +8973,143 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
8900
8973
|
return /^-?[\d.]+px$/.test(s) ? s.slice(0, -2) : s
|
|
8901
8974
|
}
|
|
8902
8975
|
|
|
8976
|
+
// ── 字体库(#31)─────────────────────────────────────────────────────────
|
|
8977
|
+
|
|
8978
|
+
let LIB_FONTS = [] // 字体库列表(发给页面试字体时要知道 id、字重;变量那行显示中文名)
|
|
8979
|
+
let libFontsP = null
|
|
8980
|
+
/** 读一次字体库列表(名字、说明、字体栈、预览图形);读完 onDone 让面板重画 */
|
|
8981
|
+
function loadLibFonts() {
|
|
8982
|
+
if (!libFontsP) libFontsP = getJson('fonts').then((d) => { LIB_FONTS = Array.isArray(d.fonts) ? d.fonts : []; return d }, (e) => { libFontsP = null; throw e })
|
|
8983
|
+
return libFontsP
|
|
8984
|
+
}
|
|
8985
|
+
const firstFam = (stack) => { const m = /^\s*(?:"([^"]*)"|'([^']*)'|([^,]*))/.exec(String(stack || '')); return m ? (m[1] ?? m[2] ?? m[3] ?? '').trim() : '' }
|
|
8986
|
+
const libOfStack = (v) => { const fam = firstFam(v).toLowerCase(); return (fam && LIB_FONTS.find((f) => f.family.toLowerCase() === fam)) || null }
|
|
8987
|
+
/** 面板里改的变量用到了哪些字体库的字体 → 发给页面,先从预览服务器加载着看(还没存进设计) */
|
|
8988
|
+
function tweakFontsOf(tv) {
|
|
8989
|
+
const out = []
|
|
8990
|
+
for (const v of Object.values(tv || {})) {
|
|
8991
|
+
const f = libOfStack(v)
|
|
8992
|
+
if (f && !out.some((x) => x.id === f.id)) out.push({ id: f.id, family: f.family, weights: f.weights })
|
|
8993
|
+
}
|
|
8994
|
+
return out
|
|
8995
|
+
}
|
|
8996
|
+
// 电脑自带的:Mac / Windows 成对写(同一种字,两边名字不一样),装了其中一个就列出来
|
|
8997
|
+
const SYS_FONTS = [
|
|
8998
|
+
{ k: 'pingfang', zh: '苹方 / 微软雅黑', en: 'PingFang / Microsoft YaHei', nzh: '系统默认的黑体', nen: 'The default Chinese sans', stack: '"PingFang SC", "Microsoft YaHei", system-ui, sans-serif', test: ['PingFang SC', 'Microsoft YaHei'] },
|
|
8999
|
+
{ k: 'heiti', zh: '黑体', en: 'Heiti', nzh: '老派一点的黑体', nen: 'Classic Chinese sans', stack: '"Heiti SC", "SimHei", sans-serif', test: ['Heiti SC', 'SimHei', 'STHeiti'] },
|
|
9000
|
+
{ k: 'songti', zh: '宋体', en: 'Songti', nzh: '书卷气的宋体', nen: 'Bookish Chinese serif', stack: '"Songti SC", "SimSun", serif', test: ['Songti SC', 'SimSun', 'STSong'] },
|
|
9001
|
+
{ k: 'kaiti', zh: '楷体', en: 'Kaiti', nzh: '手写感的楷体', nen: 'Brush-like regular script', stack: '"Kaiti SC", "KaiTi", "STKaiti", serif', test: ['Kaiti SC', 'KaiTi', 'STKaiti'] },
|
|
9002
|
+
{ k: 'fangsong', zh: '仿宋', en: 'Fangsong', nzh: '公文、古籍感', nen: 'Official documents, classics', stack: '"STFangsong", "FangSong", serif', test: ['STFangsong', 'FangSong'] },
|
|
9003
|
+
{ k: 'yuanti', zh: '圆体', en: 'Yuanti', nzh: '圆润亲和', nen: 'Rounded and friendly', stack: '"Yuanti SC", "SF Pro Rounded", sans-serif', test: ['Yuanti SC'] },
|
|
9004
|
+
{ k: 'harmony', zh: 'HarmonyOS Sans', en: 'HarmonyOS Sans', nzh: '华为的黑体', nen: 'Huawei sans', stack: '"HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif', test: ['HarmonyOS Sans SC'] },
|
|
9005
|
+
{ k: 'misans', zh: 'MiSans', en: 'MiSans', nzh: '小米的黑体', nen: 'Xiaomi sans', stack: '"MiSans", "PingFang SC", "Microsoft YaHei", sans-serif', test: ['MiSans'] },
|
|
9006
|
+
{ k: 'helvetica', zh: 'Helvetica / Arial', en: 'Helvetica / Arial', nzh: '经典无衬线', nen: 'Classic sans', stack: '"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif', test: ['Helvetica Neue', 'Arial'] },
|
|
9007
|
+
{ k: 'avenir', zh: 'Avenir Next', en: 'Avenir Next', nzh: '几何感无衬线', nen: 'Geometric sans', stack: '"Avenir Next", Avenir, "PingFang SC", "Microsoft YaHei", sans-serif', test: ['Avenir Next'] },
|
|
9008
|
+
{ k: 'georgia', zh: 'Georgia', en: 'Georgia', nzh: '耐看的衬线', nen: 'Readable serif', stack: 'Georgia, "Songti SC", "SimSun", serif', test: ['Georgia'] },
|
|
9009
|
+
{ k: 'times', zh: 'Times New Roman', en: 'Times New Roman', nzh: '报纸衬线', nen: 'Newspaper serif', stack: '"Times New Roman", Times, "Songti SC", "SimSun", serif', test: ['Times New Roman'] },
|
|
9010
|
+
{ k: 'mono', zh: 'Menlo / Consolas', en: 'Menlo / Consolas', nzh: '等宽,代码、数据', nen: 'Monospace for code and data', stack: '"SF Mono", Menlo, Consolas, monospace', test: ['Menlo', 'Consolas', 'SF Mono'] },
|
|
9011
|
+
]
|
|
9012
|
+
let sysSeen = null
|
|
9013
|
+
/** 这台电脑装了哪些(量一串字的宽度:装了的和后备字体量出来不一样);量不了就都列出来 */
|
|
9014
|
+
function sysInstalled() {
|
|
9015
|
+
if (sysSeen) return sysSeen
|
|
9016
|
+
const out = new Set()
|
|
9017
|
+
try {
|
|
9018
|
+
const c = document.createElement('canvas').getContext('2d')
|
|
9019
|
+
const s = 'mmmmmmmmmmlli1WAaQ@#'
|
|
9020
|
+
const w = (f) => { c.font = `48px ${f}`; return c.measureText(s).width }
|
|
9021
|
+
const bm = w('monospace')
|
|
9022
|
+
const bs = w('serif')
|
|
9023
|
+
for (const x of SYS_FONTS) if (x.test.some((n) => w(`"${n}", monospace`) !== bm || w(`"${n}", serif`) !== bs)) out.add(x.k)
|
|
9024
|
+
} catch { for (const x of SYS_FONTS) out.add(x.k) }
|
|
9025
|
+
sysSeen = out
|
|
9026
|
+
return out
|
|
9027
|
+
}
|
|
9028
|
+
/** 变量那行右边显示的字体名:字体库 / 电脑自带认得出的给中文名,别的给第一个名字 */
|
|
9029
|
+
function fontShort(t, v) {
|
|
9030
|
+
const en = t('lang') === 'en'
|
|
9031
|
+
const lf = libOfStack(v)
|
|
9032
|
+
if (lf) return en ? lf.en : lf.zh
|
|
9033
|
+
const fam = firstFam(v).toLowerCase()
|
|
9034
|
+
const sf = fam && SYS_FONTS.find((x) => firstFam(x.stack).toLowerCase() === fam)
|
|
9035
|
+
return sf ? (en ? sf.en : sf.zh) : tokenShort('font', v)
|
|
9036
|
+
}
|
|
9037
|
+
|
|
9038
|
+
/** 换字体(#31):字体库(预览是名字画成的图形,不用先下载)+ 电脑自带的;点一下页面马上换,「保存」才写进文件 */
|
|
9039
|
+
function FontPicker({ t, label, value, onPick, onBack, onAsk }) {
|
|
9040
|
+
const en = t('lang') === 'en'
|
|
9041
|
+
const [data, setData] = useState(null)
|
|
9042
|
+
const [err, setErr] = useState('')
|
|
9043
|
+
const [busy, setBusy] = useState('')
|
|
9044
|
+
const alive = useRef(true)
|
|
9045
|
+
useEffect(() => {
|
|
9046
|
+
alive.current = true
|
|
9047
|
+
loadLibFonts().then((d) => { if (alive.current) setData(d) }, (e) => { if (alive.current) setErr(t('failed', { msg: e.message })) })
|
|
9048
|
+
return () => { alive.current = false }
|
|
9049
|
+
}, [])
|
|
9050
|
+
const cur = firstFam(value).toLowerCase()
|
|
9051
|
+
const sys = sysInstalled()
|
|
9052
|
+
const pickLib = async (f) => {
|
|
9053
|
+
if (busy) return
|
|
9054
|
+
setErr('')
|
|
9055
|
+
if (!(data && data.ready)) {
|
|
9056
|
+
setBusy(f.id)
|
|
9057
|
+
let r
|
|
9058
|
+
try {
|
|
9059
|
+
r = await post('fonts', {})
|
|
9060
|
+
} catch (e) {
|
|
9061
|
+
r = { err: e }
|
|
9062
|
+
}
|
|
9063
|
+
if (r.ok && libFontsP) libFontsP = libFontsP.then((d) => ({ ...d, ready: true }))
|
|
9064
|
+
// 下载期间关了面板、换了设计:这次选择作废(不落到别的设计上)
|
|
9065
|
+
if (!alive.current) return
|
|
9066
|
+
setBusy('')
|
|
9067
|
+
if (r.err) return setErr(t('failed', { msg: r.err.message }))
|
|
9068
|
+
if (!r.ok) return setErr(t(r.reason === 'off' ? 'fpOff' : 'fpNet'))
|
|
9069
|
+
setData((d) => ({ ...d, ready: true }))
|
|
9070
|
+
}
|
|
9071
|
+
onPick(f.stack)
|
|
9072
|
+
}
|
|
9073
|
+
const libRow = (f) => {
|
|
9074
|
+
const on = cur === f.family.toLowerCase()
|
|
9075
|
+
const pv = f.pv
|
|
9076
|
+
const nm = en ? f.en : f.zh
|
|
9077
|
+
return h('button', { key: f.id, type: 'button', className: 'dd-fnt' + (on ? ' on' : ''), 'aria-pressed': on, 'aria-label': `${nm} · ${en ? f.nen : f.nzh}`, disabled: !!busy && busy !== f.id, onClick: () => pickLib(f) },
|
|
9078
|
+
h('span', { className: 'pv', 'aria-hidden': 'true' }, pv && pv.d ? h('svg', { viewBox: `0 0 ${pv.w} ${pv.h}`, preserveAspectRatio: 'xMinYMid meet' }, h('path', { d: pv.d })) : h('b', null, nm)),
|
|
9079
|
+
h('span', { className: 'nt' }, busy === f.id ? h('i', { className: 'dd-spin' }) : null, h('span', null, en ? f.nen : f.nzh)),
|
|
9080
|
+
on ? h(I.check) : null)
|
|
9081
|
+
}
|
|
9082
|
+
const sysRow = (x) => {
|
|
9083
|
+
const on = cur === firstFam(x.stack).toLowerCase()
|
|
9084
|
+
return h('button', { key: x.k, type: 'button', className: 'dd-fnt sys' + (on ? ' on' : ''), 'aria-pressed': on, disabled: !!busy, onClick: () => onPick(x.stack) },
|
|
9085
|
+
h('span', { className: 'pv' }, h('b', { style: { fontFamily: x.stack } }, en ? x.en : x.zh)),
|
|
9086
|
+
h('span', { className: 'nt' }, h('span', null, en ? x.nen : x.nzh)),
|
|
9087
|
+
on ? h(I.check) : null)
|
|
9088
|
+
}
|
|
9089
|
+
const fonts = (data && data.fonts) || []
|
|
9090
|
+
const zh = fonts.filter((f) => f.lang === 'zh')
|
|
9091
|
+
const lat = fonts.filter((f) => f.lang !== 'zh')
|
|
9092
|
+
const sysL = SYS_FONTS.filter((x) => sys.has(x.k))
|
|
9093
|
+
return h('div', { className: 'bd dd-fp', key: 'fp' },
|
|
9094
|
+
h('div', { className: 'dd-fph' },
|
|
9095
|
+
h('button', { type: 'button', className: 'dd-bt ghost', onClick: onBack }, h(I.back), t('fpBack')),
|
|
9096
|
+
h('b', null, t('fpTitle', { name: label })),
|
|
9097
|
+
h('span', { className: 'note' }, t('fpNow', { v: fontShort(t, value) })),
|
|
9098
|
+
h('button', { type: 'button', className: 'dd-bt ghost ask', ...tipA(t('fpAsk'), t('fpAskTip')), onClick: onAsk }, h(I.spark), t('fpAsk'))),
|
|
9099
|
+
err ? h('p', { className: 'note err' }, err) : null,
|
|
9100
|
+
!data && !err ? h('div', { className: 'dd-ckwait' }, h('i', { className: 'dd-spin' }), h('span', null, t('fpLoading'))) : null,
|
|
9101
|
+
data && data.none ? h('p', { className: 'note' }, t('fpNone')) : null,
|
|
9102
|
+
fonts.length ? h('section', { className: 'dd-fps' },
|
|
9103
|
+
h('h6', null, t('fpLib'), h(Help, { t, text: t('fpLibTip') }), data.ready ? null : h('small', null, t('fpDl', { mb: Math.round((data.size || 0) / 1024 / 1024) }))),
|
|
9104
|
+
zh.length ? h('em', null, t('fpZh')) : null,
|
|
9105
|
+
zh.length ? h('div', { className: 'dd-fpg' }, ...zh.map(libRow)) : null,
|
|
9106
|
+
lat.length ? h('em', null, t('fpEn')) : null,
|
|
9107
|
+
lat.length ? h('div', { className: 'dd-fpg' }, ...lat.map(libRow)) : null) : null,
|
|
9108
|
+
sysL.length ? h('section', { className: 'dd-fps' },
|
|
9109
|
+
h('h6', null, t('fpSys'), h(Help, { t, text: t('fpSysTip') })),
|
|
9110
|
+
h('div', { className: 'dd-fpg' }, ...sysL.map(sysRow))) : null)
|
|
9111
|
+
}
|
|
9112
|
+
|
|
8903
9113
|
/**
|
|
8904
9114
|
* 外观面板(1.0):四页——
|
|
8905
9115
|
* 整套:三列 配色(点色块直接改)/ 字体 / 形状(点一项放进对话);滑块:三列 整体 / 颜色 / 质感(模型给这套设计做的);
|
|
@@ -8907,7 +9117,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
8907
9117
|
* 换风格:推荐 / 全部 / 我的风格 + 一排风格卡,点一张选中、再点看原大样板,底栏「换成这个风格」。
|
|
8908
9118
|
* 品牌:两列 从网站或项目提一套 | 已有几套(设为默认、套用到当前设计)。
|
|
8909
9119
|
*/
|
|
8910
|
-
function LookPanel({ t, head, tab, tokens, tv, onTv, onTokAsk, onTokMake, tw, live, onTw, onTwMake, write, onReset, onAsk, onSave, onPickStyle, onRef, onSaveStyle, rec, brand }) {
|
|
9120
|
+
function LookPanel({ t, head, tab, scope = '', tokens, tv, onTv, onTokAsk, onTokMake, tw, live, onTw, onTwMake, write, onReset, onAsk, onSave, onPickStyle, onRef, onSaveStyle, rec, brand }) {
|
|
8911
9121
|
const en = t('lang') === 'en'
|
|
8912
9122
|
const groups = {}
|
|
8913
9123
|
for (const tok of tokens) (groups[tokenKind(tok)] = groups[tokenKind(tok)] || []).push(tok)
|
|
@@ -8920,6 +9130,11 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
8920
9130
|
const [grp, setGrp] = useState('rec')
|
|
8921
9131
|
const [sel, setSel] = useState(null)
|
|
8922
9132
|
const [view, setView] = useState(-1)
|
|
9133
|
+
const [fp, setFp] = useState('') // 正在换哪个字体变量(#31)
|
|
9134
|
+
const [, setLibTick] = useState(0)
|
|
9135
|
+
useEffect(() => { if (tab !== 'set') setFp('') }, [tab])
|
|
9136
|
+
// 字体变量那行要显示字体库的中文名:开面板时读一次列表
|
|
9137
|
+
useEffect(() => { if (tab === 'set' && !LIB_FONTS.length) loadLibFonts().then(() => setLibTick((n) => n + 1), () => {}) }, [tab])
|
|
8923
9138
|
// 进原大样板:焦点给样板(← → 翻、Esc 回去);回卡片:焦点回到选中的那张
|
|
8924
9139
|
const root = useRef(null)
|
|
8925
9140
|
const seen = useRef(false)
|
|
@@ -9005,8 +9220,28 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
9005
9220
|
h('button', { className: 'dd-bt pri', onClick: onTokMake }, h(I.sparkle), t('tokensAsk')))), foot)
|
|
9006
9221
|
}
|
|
9007
9222
|
const colors = groups.color || []
|
|
9223
|
+
const fpTok = fp && tokens.find((x) => x.name === fp)
|
|
9224
|
+
if (fpTok) {
|
|
9225
|
+
return box(h(FontPicker, {
|
|
9226
|
+
key: 'fp:' + scope + '\n' + fpTok.name, // 换了一套设计就是另一个(下载慢、回来晚的那次选择不会落到新设计上)
|
|
9227
|
+
t,
|
|
9228
|
+
label: names.get(fpTok.name),
|
|
9229
|
+
value: hasOwn(tv, fpTok.name) ? tv[fpTok.name] : fpTok.value,
|
|
9230
|
+
onPick: (v) => onTv(fpTok.name, v),
|
|
9231
|
+
onBack: () => setFp(''),
|
|
9232
|
+
onAsk: () => { setFp(''); onTokAsk(fpTok) },
|
|
9233
|
+
}), foot)
|
|
9234
|
+
}
|
|
9008
9235
|
const tokRow = (tok) => {
|
|
9009
9236
|
const k = tokenKind(tok)
|
|
9237
|
+
if (k === 'font') {
|
|
9238
|
+
const ch = hasOwn(tv, tok.name)
|
|
9239
|
+
const v = ch ? tv[tok.name] : tok.value
|
|
9240
|
+
return h('button', { key: tok.name, className: 'dd-tkr fnt' + (ch ? ' on' : ''), title: `${tok.name}: ${v}\n${t('fpRowTip')}`, onClick: () => setFp(tok.name) },
|
|
9241
|
+
h('span', { className: 'nm', style: libOfStack(v) ? null : { fontFamily: v } }, names.get(tok.name)),
|
|
9242
|
+
h('span', { className: 'vl' }, fontShort(t, v)),
|
|
9243
|
+
h('span', { className: 'go', 'aria-hidden': 'true' }, h(I.back)))
|
|
9244
|
+
}
|
|
9010
9245
|
const st = k === 'font' ? { fontFamily: tok.value } : k === 'size' ? { fontSize: Math.max(11, Math.min(17, pxOf(tok.value, tokens) || 13)) + 'px', fontWeight: (pxOf(tok.value, tokens) || 0) >= 20 ? 600 : 400 } : null
|
|
9011
9246
|
const short = tokenShort(k, tok.value)
|
|
9012
9247
|
return h('button', { key: tok.name, className: 'dd-tkr', title: `${tok.name}: ${tok.value}\n${t('lookTokTip')}`, onClick: () => onTokAsk(tok) },
|
|
@@ -9488,7 +9723,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
9488
9723
|
let out = Object.keys(live).length ? formatTweaks(t, list, live) : ''
|
|
9489
9724
|
const rows = Object.entries(tv).map(([name, v]) => {
|
|
9490
9725
|
const tok = tokens.find((x) => x.name === name)
|
|
9491
|
-
|
|
9726
|
+
const lf = libOfStack(v)
|
|
9727
|
+
return `- ${name}(${tok ? tokenLabel(t, tok) : name}):${tok ? tok.value : '?'} → ${v}${lf ? t('lookLibFont', { name: t('lang') === 'en' ? lf.en : lf.zh, var: name }) : ''}`
|
|
9492
9728
|
})
|
|
9493
9729
|
if (rows.length) out += t('lookAskHead') + '\n' + rows.join('\n') + '\n' + t('lookAskTail') + '\n'
|
|
9494
9730
|
return out
|
|
@@ -12632,7 +12868,8 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
12632
12868
|
const r = await post('htmlpack', { session: sid, ...b, name: (ver ? `v${ver.n}-` : '') + (b.title || 'design') + (dark ? '-dark' : '') })
|
|
12633
12869
|
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
12634
12870
|
const miss = Array.isArray(r.missing) ? r.missing.length : 0
|
|
12635
|
-
|
|
12871
|
+
const skip = Array.isArray(r.skipped) ? r.skipped : []
|
|
12872
|
+
say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + (skip.length ? t('exportedHtmlSkip', { n: r.skippedN || skip.length, files: skip.slice(0, 3).map((x) => String(x).split('/').pop()).join('、') + ((r.skippedN || skip.length) > 3 ? '…' : '') }) : '') + cutTail() + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
12636
12873
|
} catch (e) {
|
|
12637
12874
|
const m = String((e && e.message) || '')
|
|
12638
12875
|
if (m === 'designChanged' || m === 'not-file') sayErr(t('xoGone'))
|
|
@@ -13565,7 +13802,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
13565
13802
|
const twGen = useRef(0) // 换一次设计加一:晚到的保存回包认得出是上一套的
|
|
13566
13803
|
useEffect(() => { twGen.current++; setTw({}); setTv({}) }, [site])
|
|
13567
13804
|
// 拖的滑块 + 外观面板里直接改的颜色:一起发给页面先看效果
|
|
13568
|
-
const tweak = Object.keys(tw).length || Object.keys(tv).length ? (() => { const m = tweakMsg(tlist, tw); return { vars: { ...m.vars, ...tv }, attrs: m.attrs } })() : null
|
|
13805
|
+
const tweak = Object.keys(tw).length || Object.keys(tv).length ? (() => { const m = tweakMsg(tlist, tw); return { vars: { ...m.vars, ...tv }, attrs: m.attrs, fonts: tweakFontsOf(tv) } })() : null
|
|
13569
13806
|
// 业务标注:开关开着才有 st.annotations 这个键(null = 还没有文件)
|
|
13570
13807
|
const anOn = !!st && Object.prototype.hasOwnProperty.call(st, 'annotations')
|
|
13571
13808
|
const anFile = anOn ? st.annotations : null
|
|
@@ -14469,7 +14706,7 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
14469
14706
|
const sentTv = tv
|
|
14470
14707
|
const gen = twGen.current
|
|
14471
14708
|
const r = await post('tweak', { session: sid, root: st && st.target ? st.target.root : '', values: sentTw, vars: sentTv })
|
|
14472
|
-
if (!r.ok) return say(r.reason === 'busy' ? t('styleBusyTip') : r.reason === 'moved' ? t('twMoved') : t('twNoWrite'))
|
|
14709
|
+
if (!r.ok) return say(r.reason === 'busy' ? t('styleBusyTip') : r.reason === 'moved' ? t('twMoved') : r.reason === 'font-off' ? t('fontOffSave') : r.reason === 'font-net' ? t('fontNetSave') : r.reason === 'font-write' ? t('fontWriteSave') : t('twNoWrite'))
|
|
14473
14710
|
if (r.missed && r.missed.length) sayErr(t('twMissed', { names: r.missed.map((x) => { const tok = String(x.id).startsWith('--') && tokens.find((k) => k.name === x.id); return tok ? tokenLabel(t, tok) : x.label }).join(t('sep')) }))
|
|
14474
14711
|
else showFlash(t('twSaved', { n: r.changed.length }))
|
|
14475
14712
|
// 写进去的(设计变量、滑块):放掉,页面重新读文件就是新值了(滑块和配色管同一个颜色时以配色为准,滑块的旧值也得放掉);
|
|
@@ -14933,9 +15170,16 @@ body:not([data-ds-dark-theme]) .ddp .ddp-homebar .seg::before{box-shadow:var(--d
|
|
|
14933
15170
|
t,
|
|
14934
15171
|
head: hd({ icon: I.palette, title: t('look'), help: t({ tw: 'lookTwHint', style: 'stPickHint', brand: 'sysTip' }[lookTab] || 'hpLookSet'), tabs: [['set', t('lookSet')], ['tw', t('lookTw')], ['style', t('lookStyle')], ['brand', t('lookBrand')]], tab: lookTab, onTab: setLookTab }),
|
|
14935
15172
|
tab: lookTab,
|
|
15173
|
+
scope: targetKey,
|
|
14936
15174
|
tokens,
|
|
14937
15175
|
tv,
|
|
14938
|
-
onTv: (name, v) => setTv((c) =>
|
|
15176
|
+
onTv: (name, v) => setTv((c) => {
|
|
15177
|
+
const tok = tokens.find((x) => x.name === name)
|
|
15178
|
+
// 和文件里一样就不算改——除非选的是字体库的字体、页面里却还没有它的 @font-face(旧设计本来就写着 "Noto Serif SC" 当后备):存下时才会放进来
|
|
15179
|
+
const pending = !!libOfStack(v) && !(tok && tok.face)
|
|
15180
|
+
if (tok && String(tok.value).trim() === String(v).trim() && !pending) { if (!hasOwn(c, name)) return c; const out = { ...c }; delete out[name]; return out }
|
|
15181
|
+
return { ...c, [name]: v }
|
|
15182
|
+
}),
|
|
14939
15183
|
onTokAsk: (tok) => insert(formatToken(tok, stRef.current)),
|
|
14940
15184
|
onTokMake: () => insert(t('tokensAskText') + '\n', 'insertedSend'),
|
|
14941
15185
|
tw: tweaks,
|