dsh-design-studio 0.24.0 → 0.25.1

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/lib/client.js CHANGED
@@ -162,6 +162,13 @@ window.__ModuleLoader__.load({
162
162
  szStd: '标准',
163
163
  szLarge: '大屏',
164
164
  kind: '类型',
165
+ canvasSize: '画幅',
166
+ sizeCustom: '自定义…',
167
+ sizeDefault: '默认',
168
+ sizeApply: '好',
169
+ sizeReset: '恢复默认',
170
+ sizeBad: '宽、高都填 100–8000',
171
+ szCustom: '自定义',
165
172
  kindWeb: '网页',
166
173
  kindApp: 'App',
167
174
  kindMini: '小程序',
@@ -855,6 +862,12 @@ window.__ModuleLoader__.load({
855
862
  shGh: '投稿要有 GitHub 账号',
856
863
  shTip: '交上去的东西是公开的:别人能看、能拿去用。先查一遍,过了就能投。',
857
864
  shName: '名字',
865
+ shCats: '分类(选 1–2 个)',
866
+ shTags: '标签(可选,最多 8 个)',
867
+ shLang: '设计里的文字',
868
+ shLangZh: '中文',
869
+ shLangEn: '英文',
870
+ shLangBoth: '中英都有',
858
871
  shDesc: '一句话介绍',
859
872
  shDescPh: '比如:街角茶饮店的三屏点单 App',
860
873
  shAgreeOwn: '是我自己(或用设计台)做的,图片都是自己做的或 CC0 / 公有领域',
@@ -1028,6 +1041,13 @@ window.__ModuleLoader__.load({
1028
1041
  szStd: 'Standard',
1029
1042
  szLarge: 'Large',
1030
1043
  kind: 'Type',
1044
+ canvasSize: 'Canvas',
1045
+ sizeCustom: 'Custom…',
1046
+ sizeDefault: 'default',
1047
+ sizeApply: 'OK',
1048
+ sizeReset: 'Reset',
1049
+ sizeBad: 'Width and height: 100–8000',
1050
+ szCustom: 'Custom',
1031
1051
  kindWeb: 'Web',
1032
1052
  kindApp: 'App',
1033
1053
  kindMini: 'Mini program',
@@ -1719,6 +1739,12 @@ window.__ModuleLoader__.load({
1719
1739
  shGh: 'You need a GitHub account to submit',
1720
1740
  shTip: 'What you share is public: anyone can see and reuse it. It is checked first; once it passes you can submit it.',
1721
1741
  shName: 'Name',
1742
+ shCats: 'Category (pick 1–2)',
1743
+ shTags: 'Tags (optional, up to 8)',
1744
+ shLang: 'Text in the design',
1745
+ shLangZh: 'Chinese',
1746
+ shLangEn: 'English',
1747
+ shLangBoth: 'Both',
1722
1748
  shDesc: 'One-line description',
1723
1749
  shDescPh: 'e.g. A three-screen ordering app for a corner tea shop',
1724
1750
  shAgreeOwn: 'I made it (or the design studio did); all images are mine or CC0 / public domain',
@@ -1852,6 +1878,16 @@ window.__ModuleLoader__.load({
1852
1878
  .ddp-menu .ddp-kinds button{flex-direction:column;justify-content:center;gap:4px;height:50px;padding:0 2px;font-size:11px;text-align:center}
1853
1879
  .ddp-menu .ddp-kinds button span{max-width:100%}
1854
1880
  .ddp-menu .ddp-kinds button.sel{background:rgba(77,107,254,.12)}
1881
+ .ddp-szrow{display:flex;align-items:center;gap:6px;min-height:30px;padding:0 4px 4px 9px;font-size:12px}
1882
+ .ddp-szrow>*{flex:none;white-space:nowrap}
1883
+ .ddp-szrow b{font-weight:500;font-variant-numeric:tabular-nums}
1884
+ .ddp-menu .ddp-szrow em{margin-left:0}
1885
+ .ddp-menu .ddp-szrow button{width:auto;height:26px;margin-left:auto;padding:0 8px;color:${ACCENT};white-space:nowrap}
1886
+ .ddp-menu .ddp-szrow button+button{margin-left:0}
1887
+ .ddp-szrow input{width:62px;box-sizing:border-box;height:26px;padding:0 7px;border:1px solid var(--dsw-alias-separator-primary,rgba(127,127,127,.3));border-radius:7px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-variant-numeric:tabular-nums}
1888
+ .ddp-szrow input:focus{outline:none;border-color:${ACCENT}}
1889
+ .ddp-szrow .bad{flex-basis:100%;white-space:normal;color:var(--dsw-alias-label-tertiary);font-size:11px}
1890
+ .ddp-szrow.ed{flex-wrap:wrap}
1855
1891
  /* 标注时它有自己的上下两条:浮块都收起来 */
1856
1892
  .ddp-stage:has(>.ddp-mark)>.ddp-top,.ddp-stage:has(>.ddp-mark)>.ddp-isl{display:none}
1857
1893
  /* 上下两排浮块让出来:提示、消息、横幅、生成中、右边的面板都挪到两排中间 */
@@ -2695,6 +2731,11 @@ window.__ModuleLoader__.load({
2695
2731
  .ddp-pack .lic input{flex:none;margin:3px 0 0;accent-color:${ACCENT}}
2696
2732
  .ddp-share .tip.gh{display:flex;align-items:center;gap:6px;margin-bottom:0;color:var(--dsw-alias-label-primary);font-weight:500}
2697
2733
  .ddp-share .tip.gh svg{width:14px;height:14px;flex:none;color:${ACCENT}}
2734
+ .ddp-share .chips{display:flex;flex-wrap:wrap;gap:6px}
2735
+ .ddp-share .chips button{height:26px;padding:0 10px;border:1px solid var(--dsw-alias-separator-primary,rgba(127,127,127,.3));border-radius:13px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer}
2736
+ .ddp-share .chips button:hover:not(:disabled){color:var(--dsw-alias-label-primary)}
2737
+ .ddp-share .chips button.on{border-color:${ACCENT};background:rgba(77,107,254,.12);color:${ACCENT}}
2738
+ .ddp-share .chips button:disabled{opacity:.45;cursor:default}
2698
2739
  .ddp-share .agree{display:flex;flex-direction:column;gap:2px;margin-top:10px}
2699
2740
  .ddp-share .agree label{display:flex;align-items:flex-start;gap:8px;padding:5px 8px;border-radius:8px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.5;cursor:pointer}
2700
2741
  .ddp-share .agree label:hover{color:var(--dsw-alias-label-primary)}
@@ -2869,6 +2910,19 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
2869
2910
  }
2870
2911
  /** 网页单看要不要按画幅缩放(#20):用户在屏名菜单切过(pref = 'fit' / 'fill')听用户的;没切过看这套设计写没写画幅 */
2871
2912
  const webFitOf = (kind, pref, sized) => kind === 'web' && (pref ? pref === 'fit' : !!sized)
2913
+ // 屏名菜单里自定义过画幅的设计(会话|目录 → 'WxH'):铺满的网页这几套按画幅显示(#23)
2914
+ const FIT_FOR = 'ddp-fit-for'
2915
+ const fitForMap = () => { try { const m = JSON.parse(localStorage.getItem(FIT_FOR) || '{}'); return m && typeof m === 'object' && !Array.isArray(m) ? m : {} } catch { return {} } }
2916
+ const fitForOf = (k) => { const v = k ? fitForMap()[k] : ''; return typeof v === 'string' ? v : '' }
2917
+ const setFitForOf = (k, v) => {
2918
+ if (!k) return
2919
+ const m = fitForMap()
2920
+ delete m[k]
2921
+ if (v) m[k] = v
2922
+ const ks = Object.keys(m)
2923
+ for (const x of ks.slice(0, Math.max(0, ks.length - 50))) delete m[x]
2924
+ try { localStorage.setItem(FIT_FOR, JSON.stringify(m)) } catch { /* 记不住就这次有效 */ }
2925
+ }
2872
2926
  const pageHidden = () => { try { return document.visibilityState === 'hidden' } catch { return false } }
2873
2927
  try {
2874
2928
  document.addEventListener('visibilitychange', () => { if (!pageHidden()) for (const p of pollers.values()) if (p.refs > 0) { p.stop(); p.start() } })
@@ -7134,7 +7188,30 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7134
7188
  }
7135
7189
 
7136
7190
  // 左上屏名 ▾:换屏(画布 / 某一屏)、多尺寸、类型、打开别的页面——「在看什么、怎么看」都在这一个菜单里
7137
- function ScreenMenu({ t, label, title, tip, src, busy, list, cur, canvas, open, setOpen, onPick, onAll, onOther, sizes, fit, kind, onKind, hidden, hiddenText }) {
7191
+ /** 屏名菜单里的「画幅」一行(#23):显示现在多大,点「自定义…」填宽×高,改过的能恢复默认 */
7192
+ function SizeRow({ t, size, custom, onSize, done }) {
7193
+ const [edit, setEdit] = useState(false)
7194
+ const [w, setW] = useState('')
7195
+ const [hh, setH] = useState('')
7196
+ const ok = (v) => /^\d{3,4}$/.test(v) && +v >= 100 && +v <= 8000
7197
+ const valid = ok(w) && ok(hh)
7198
+ const num = (set) => (e) => set(e.target.value.replace(/\D/g, '').slice(0, 4))
7199
+ if (!edit) {
7200
+ return h('div', { className: 'ddp-szrow' },
7201
+ h('b', null, size.join('×')),
7202
+ h('em', null, custom ? t('szCustom') : t('sizeDefault')),
7203
+ h('button', { type: 'button', onClick: () => { setW(String(size[0])); setH(String(size[1])); setEdit(true) } }, t('sizeCustom')),
7204
+ custom ? h('button', { type: 'button', onClick: () => { onSize(''); done() } }, t('sizeReset')) : null)
7205
+ }
7206
+ return h('form', { className: 'ddp-szrow ed', onSubmit: (e) => { e.preventDefault(); if (valid) { onSize(`${+w}x${+hh}`); done() } } },
7207
+ h('input', { value: w, inputMode: 'numeric', 'aria-label': t('canvasSize') + ' W', autoFocus: true, onChange: num(setW), onFocus: (e) => e.target.select() }),
7208
+ h('span', null, '×'),
7209
+ h('input', { value: hh, inputMode: 'numeric', 'aria-label': t('canvasSize') + ' H', onChange: num(setH), onFocus: (e) => e.target.select() }),
7210
+ h('button', { type: 'submit', disabled: !valid }, t('sizeApply')),
7211
+ valid ? null : h('span', { className: 'bad' }, t('sizeBad')))
7212
+ }
7213
+
7214
+ function ScreenMenu({ t, label, title, tip, src, busy, list, cur, canvas, open, setOpen, onPick, onAll, onOther, sizes, fit, kind, onKind, hidden, hiddenText, size, custom, onSize }) {
7138
7215
  const ref = useRef(null)
7139
7216
  useDismiss(open, setOpen, ref)
7140
7217
  const n = list.length
@@ -7157,6 +7234,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7157
7234
  onKind ? h('div', { className: 'hd' }, t('kind')) : null,
7158
7235
  onKind ? h('div', { className: 'ddp-kinds', role: 'group', 'aria-label': t('kind') }, ...KIND_LIST.map((k) => h('button', { key: k, role: 'menuitemradio', 'aria-checked': k === kind, className: k === kind ? 'sel' : '', title: KIND_SIZE[k].join('×'), onClick: close(() => onKind(k)) },
7159
7236
  h(I[k]), h('span', null, t(KIND_KEY[k]))))) : null,
7237
+ onSize && size ? h('div', { className: 'hd' }, t('canvasSize')) : null,
7238
+ onSize && size ? h(SizeRow, { t, size, custom, onSize, done: () => setOpen(false) }) : null,
7160
7239
  h('div', { className: 'sp', role: 'separator' }),
7161
7240
  h('button', { role: 'menuitem', onClick: close(onOther) }, h(I.folder), h('span', null, t('openOther')))) : null)
7162
7241
  }
@@ -7873,6 +7952,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7873
7952
  const [desc, setDesc] = useState('')
7874
7953
  const [lic, setLic] = useState('CC0-1.0')
7875
7954
  const [agree, setAgree] = useState({})
7955
+ const [cats, setCats] = useState([]) // 分类、标签:从市场词表里选(机器人按同一份词表查)
7956
+ const [tags, setTags] = useState([])
7957
+ const [dlang, setDlang] = useState('') // 设计里的文字是哪种语言
7876
7958
  const [res, setRes] = useState(null)
7877
7959
  const [busy, setBusy] = useState(false)
7878
7960
  const packSeq = useRef(0) // 每次查、每次换作品都加一:晚到的回包对不上就不认(不然 B 的面板会拿到 A 的包去投)
@@ -7888,6 +7970,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7888
7970
  setDesc('')
7889
7971
  setLic('CC0-1.0')
7890
7972
  setAgree({})
7973
+ setCats([])
7974
+ setTags([])
7975
+ setDlang('')
7891
7976
  if (!root) return undefined
7892
7977
  let on = true
7893
7978
  const my = packSeq.current
@@ -7897,18 +7982,25 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
7897
7982
  if (!edited.current.title) setTitle(d.title && d.title !== baseName(root) ? d.title : brand || d.title || '')
7898
7983
  if (!edited.current.desc) setDesc(d.description || '')
7899
7984
  if (!edited.current.lic) setLic(d.license === 'CC-BY-4.0' ? 'CC-BY-4.0' : 'CC0-1.0')
7985
+ if (!edited.current.cats) setCats(Array.isArray(d.categories) ? d.categories : [])
7986
+ if (!edited.current.tags) setTags(Array.isArray(d.tags) ? d.tags : [])
7987
+ if (!edited.current.dlang) setDlang(['zh', 'en', 'both'].includes(d.designLang) ? d.designLang : L)
7900
7988
  }, (e) => { if (on && packSeq.current === my) setInfo({ error: e.message }) })
7901
7989
  return () => { on = false }
7902
7990
  }, [root])
7903
7991
  // 预填回来之前不能查(不然用的是没对上这一套的表单)
7904
- const ready = !!root && !!info && !!title.trim() && !!desc.trim() && SHARE_AGREE.every(([k]) => agree[k])
7992
+ const voc = { categories: (info && info.vocab && Array.isArray(info.vocab.categories) && info.vocab.categories) || [], tags: (info && info.vocab && Array.isArray(info.vocab.tags) && info.vocab.tags) || [] }
7993
+ const ready = !!root && !!info && !!title.trim() && !!desc.trim() && (!voc.categories.length || cats.length > 0) && SHARE_AGREE.every(([k]) => agree[k])
7994
+ // 点一下选上、再点取消;选满了别的点不动
7995
+ const toggle = (set, key, max) => (id) => { edited.current[key] = true; set((cur) => (cur.includes(id) ? cur.filter((x) => x !== id) : cur.length < max ? [...cur, id] : cur)) }
7996
+ const chips = (k, list, set, max) => h('div', { key: k + 'c', className: 'chips', role: 'group', 'aria-label': t(k === 'categories' ? 'shCats' : 'shTags') }, ...voc[k].map((x) => h('button', { key: x.id, type: 'button', className: list.includes(x.id) ? 'on' : '', 'aria-pressed': list.includes(x.id), disabled: busy || (!list.includes(x.id) && list.length >= max), onClick: () => toggle(set, k === 'categories' ? 'cats' : 'tags', max)(x.id) }, L === 'en' ? x.en : x.zh)))
7905
7997
  const go = async () => {
7906
7998
  const my = ++packSeq.current
7907
7999
  setBusy(true)
7908
8000
  setRes(null)
7909
8001
  setLost(false)
7910
8002
  let r
7911
- try { r = await post('pack', { session: sid, dir: root, share: true, title: title.trim(), description: desc.trim(), license: lic, agree, lang: L }) } catch (e) { r = { error: e.message } }
8003
+ try { r = await post('pack', { session: sid, dir: root, share: true, title: title.trim(), description: desc.trim(), categories: cats, tags, designLang: dlang || L, license: lic, agree, lang: L }) } catch (e) { r = { error: e.message } }
7912
8004
  if (packSeq.current !== my) return
7913
8005
  setRes(r)
7914
8006
  setBusy(false)
@@ -8013,6 +8105,12 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
8013
8105
  h('input', { key: 'ni', className: 'who', value: title, maxLength: 24, disabled: busy, 'aria-label': t('shName'), onChange: (e) => { edited.current.title = true; setTitle(e.target.value) } }),
8014
8106
  h('h4', { key: 'd' }, t('shDesc')),
8015
8107
  h('input', { key: 'di', className: 'who', value: desc, maxLength: 120, disabled: busy, placeholder: t('shDescPh'), 'aria-label': t('shDesc'), onChange: (e) => { edited.current.desc = true; setDesc(e.target.value) } }),
8108
+ voc.categories.length ? h('h4', { key: 'c' }, t('shCats')) : null,
8109
+ voc.categories.length ? chips('categories', cats, setCats, 2) : null,
8110
+ voc.tags.length ? h('h4', { key: 'tg' }, t('shTags')) : null,
8111
+ voc.tags.length ? chips('tags', tags, setTags, 8) : null,
8112
+ h('h4', { key: 'lg' }, t('shLang')),
8113
+ h('div', { key: 'lgc', className: 'chips', role: 'radiogroup', 'aria-label': t('shLang') }, ...[['zh', 'shLangZh'], ['en', 'shLangEn'], ['both', 'shLangBoth']].map(([k, label]) => h('button', { key: k, type: 'button', role: 'radio', 'aria-checked': (dlang || L) === k, className: (dlang || L) === k ? 'on' : '', disabled: busy, onClick: () => { edited.current.dlang = true; setDlang(k) } }, t(label)))),
8016
8114
  h('h4', { key: 'l' }, t('pkLicense')),
8017
8115
  h('div', { key: 'li', className: 'lic' }, ...[['CC0-1.0', 'pkCC0'], ['CC-BY-4.0', 'pkBY']].map(([k, label]) => h('label', { key: k, className: lic === k ? 'on' : '' },
8018
8116
  h('input', { type: 'radio', name: 'ddp-shlic', checked: lic === k, disabled: busy, onChange: () => { edited.current.lic = true; setLic(k) } }), h('span', null, t(label))))),
@@ -9178,8 +9276,14 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9178
9276
  const size = sizeOf((st && st.size) || meta.size || autoSize(screens.map((sc) => (infoOf(ik(sc)) || {}).natural), kind), kind)
9179
9277
  // 网页单看、演示、对比(#20):写了画幅(meta 或 preview_page 的 size)就按画幅整屏缩放,没写就铺满右侧栏;用户在屏名菜单里切过就听用户的
9180
9278
  const [fitPref, setFitPref] = useState(() => { try { return localStorage.getItem('ddp-web-fit') || '' } catch { return '' } })
9181
- const webFit = webFitOf(kind, fitPref, !!((st && st.size) || meta.size))
9182
- const toggleFit = () => { const v = webFit ? 'fill' : 'fit'; setFitPref(v); try { localStorage.setItem('ddp-web-fit', v) } catch { /* 记不住就这次有效 */ } }
9279
+ const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
9280
+ // 在屏名菜单里自定义了画幅(#23):这个会话这套设计的画幅还是它就按画幅显示(记在本机,重开也在;不改记住的偏好;恢复默认 / 换了画幅就不算了)
9281
+ const fitKey = sid && targetKey ? `${sid}|${targetKey}` : ''
9282
+ const [fitTick, setFitTick] = useState(0)
9283
+ const fitFor = useMemo(() => fitForOf(fitKey), [fitKey, fitTick])
9284
+ const setFitFor = (v) => { setFitForOf(fitKey, v); setFitTick((n) => n + 1) }
9285
+ const webFit = kind === 'web' && !!fitFor && fitFor === ((st && st.size) || '') ? true : webFitOf(kind, fitPref, !!((st && st.size) || meta.size))
9286
+ const toggleFit = () => { const v = webFit ? 'fill' : 'fit'; setFitFor(''); setFitPref(v); try { localStorage.setItem('ddp-web-fit', v) } catch { /* 记不住就这次有效 */ } }
9183
9287
  const view = (st && st.view) || (screens.length >= 2 && screens.length <= 12 ? 'canvas' : 'single')
9184
9288
  const canvas = view === 'canvas'
9185
9289
  const writingNew = !!(st && st.writing) && /\.html?$/i.test(st.writing) && !screens.some((s) => s.key === st.writing)
@@ -9670,7 +9774,6 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9670
9774
  if (!api) throw new Error('not loaded')
9671
9775
  return api
9672
9776
  }
9673
- const targetKey = st && st.target ? (st.target.kind === 'file' ? `file|${st.target.root}` : `proxy|${st.target.port}`) : ''
9674
9777
  // ── 导出图片(makeExporter)──
9675
9778
  const { withFrames, measureAll, exportShots } = makeExporter({ apiOf, targetKey, sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned,
9676
9779
  onWarn: () => { if (pane !== 'export') openPane('export') } })
@@ -9751,7 +9854,14 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9751
9854
  move(e)
9752
9855
  }
9753
9856
 
9754
- const sizeSet = SIZE_SETS[kind] || null
9857
+ // 多尺寸:用户自定义了画幅(#23),并排的几档后面多一档「自定义」
9858
+ const sizeSet = (() => {
9859
+ const base = SIZE_SETS[kind] || null
9860
+ const cs = (st && st.size) || ''
9861
+ if (!base || !cs) return base
9862
+ const sz = sizeOf(cs, kind)
9863
+ return base.some(([, , x]) => x[0] === sz[0] && x[1] === sz[1]) ? base : [...base, ['szCustom', kind, sz]]
9864
+ })()
9755
9865
  const inMulti = multi && !!sizeSet && !ver
9756
9866
  // 单页看手机 / 平板时,选择、改字的提示条放在设备上方,给它让出一条(不然压住设备顶边)
9757
9867
  const hintTop = (picking || textEdit) && !canvas && !inMulti && !ver && !demo && (kind !== 'web' || webFit) // 网页按画幅缩放时也和设备一样让出一条(#20)
@@ -9974,7 +10084,10 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
9974
10084
  onPick: pickScreen, onAll: toCanvas, onOther: () => setEditing(true),
9975
10085
  sizes: mark ? null : { on: inMulti, off: !sizeSet || !!ver, tip: sizeSet ? t('sizes') : t('sizesNo'), note: sizeSet ? '' : t('sizesNoShort'), run: () => setMulti(!inMulti) },
9976
10086
  fit: kind === 'web' && !mark ? { on: webFit, note: size.join('×'), run: toggleFit } : null,
9977
- kind, onKind: mark ? null : (k) => change({ kind: k }) })),
10087
+ kind, onKind: mark ? null : (k) => change({ kind: k }),
10088
+ // 自定义画幅(#23):外框类型的画幅跟着外框走,不让改
10089
+ // 网页之前切成了铺满:填了画幅这回就按画幅显示(fitFor),不然单看看不出变化
10090
+ size, custom: (st && st.size) || '', onSize: mark || kind === 'framed' || kind === 'dshplugin' ? null : (v) => { setFitFor(v); change({ size: v }) } })),
9978
10091
  h('div', { className: 'ddp-isl tr' },
9979
10092
  h('button', { className: 'ddp-btn lab' + (panel ? ' sel' : ''), ...tipA(t('look'), t('dLook')), onClick: () => (panel ? setPanel(false) : openLook()) }, h(I.palette), h('span', { className: 'lb' }, t('look'))),
9980
10093
  h('button', { className: 'ddp-btn lab' + (ck ? ' sel' : ''), ...tipA(t('checkShort'), ckCount && !ck ? t('dCheckN', { n: ckCount }) : t('dCheck')), disabled: checkOff, onClick: () => (ck ? closeCheck() : runCheck()) },
@@ -419,6 +419,14 @@ export function createMarket({
419
419
  && !isRevoked(e, s))
420
420
  }
421
421
 
422
+ /** 投稿表单用的分类 / 标签词表(目录或自带种子里的;都没有就空着,表单不显示这两栏) */
423
+ function vocab() {
424
+ const c = current()
425
+ const md = c && c.index && c.index.metadata
426
+ const list = (a) => (Array.isArray(a) ? a.filter((x) => x && typeof x.id === 'string' && /^[a-z0-9-]{2,24}$/.test(x.id)).slice(0, 200).map((x) => ({ id: x.id, zh: String(x.zh || x.id).slice(0, 24), en: String(x.en || x.id).slice(0, 40) })) : [])
427
+ return { categories: list(md && md.categories), tags: list(md && md.tags) }
428
+ }
429
+
422
430
  /** 给界面的目录:三类条目 + 词表 + 状态 */
423
431
  function view() {
424
432
  const c = current()
@@ -641,5 +649,5 @@ export function createMarket({
641
649
  return r === base || r.startsWith(base + path.sep) || r.startsWith(path.resolve(stageDir) + path.sep)
642
650
  }
643
651
 
644
- return { fetchPackage, view, refresh, maybeRefresh, abort, entry, thumbFile, stage, shotFile, strictHtml, isStaging, state, url: (e) => e.submission || `${REPO_URL}/tree/main/${e.type === 'system' ? 'systems' : e.type === 'style' ? 'styles' : 'templates'}/${e.id}` }
652
+ return { fetchPackage, view, vocab, refresh, maybeRefresh, abort, entry, thumbFile, stage, shotFile, strictHtml, isStaging, state, url: (e) => e.submission || `${REPO_URL}/tree/main/${e.type === 'system' ? 'systems' : e.type === 'style' ? 'styles' : 'templates'}/${e.id}` }
645
653
  }
@@ -84,7 +84,7 @@ function metaExtra(html) {
84
84
  * 包的清单:有 design.json 就在它的基础上补(屏列表以现在目录里的为准,顺序先照清单),没有就从页面里读出来
85
85
  * screens:listScreens 排好的顶层页面文件名;htmls:文件名 → 内容
86
86
  */
87
- export function buildManifest({ existing = null, screens, htmls, version = '', license = '', author = '', title = '', description = '', shareHash = '' }) {
87
+ export function buildManifest({ existing = null, screens, htmls, version = '', license = '', author = '', title = '', description = '', categories, tags, designLang, shareHash = '' }) {
88
88
  const m = existing && typeof existing === 'object' && !Array.isArray(existing) ? { ...existing } : {}
89
89
  const first = htmls.get(screens[0]) || ''
90
90
  const kinds = screens.map((f) => metaKind(htmls.get(f) || '')).filter(Boolean)
@@ -107,6 +107,9 @@ export function buildManifest({ existing = null, screens, htmls, version = '', l
107
107
  }),
108
108
  }
109
109
  for (const k of ['style', 'categories', 'tags', 'lang', 'dark', 'assets']) if (m[k] !== undefined) out[k] = m[k]
110
+ // 分享表单这次选的分类、标签、语言(传了就以它为准;空列表 = 不要了)
111
+ for (const [k, v] of [['categories', categories], ['tags', tags]]) if (Array.isArray(v)) { if (v.length) out[k] = v; else delete out[k] }
112
+ if (designLang) out.lang = designLang
110
113
  out.license = license || m.license || 'CC0-1.0'
111
114
  // 署名:这次填了名字就用它;没填沿用清单里原来的(从市场装的模板改的,原作者在 derivedFrom 里,不在这)
112
115
  const who = oneLine(author, 40)
@@ -244,7 +247,7 @@ export function stripMeta(buf, ext) {
244
247
  * 打包前的全部步骤。screens:要打进包的屏(顺序就是包里的顺序)
245
248
  * 返回 { ok, errors: [{ code, x, line, msg, sev }], flags, notes: [自动修了什么], skipped, manifest, files: [{ path, data }] }
246
249
  */
247
- export function packDesign(root, { screens, version = '', license = '', author = '', mode = 'zip', lang = 'zh', title = '', description = '', shareHash = '', secrets = [] }) {
250
+ export function packDesign(root, { screens, version = '', license = '', author = '', mode = 'zip', lang = 'zh', title = '', description = '', categories, tags, designLang, shareHash = '', secrets = [] }) {
248
251
  const { files: picked, skipped, tooBig } = collectDesign(root)
249
252
  const notes = []
250
253
  const errors = []
@@ -297,7 +300,7 @@ export function packDesign(root, { screens, version = '', license = '', author =
297
300
  else { skipped.push(f.path); dropped.add(f.path.toLowerCase()); files.splice(i, 1) }
298
301
  }
299
302
  const order = screens.filter((s) => htmls.has(s))
300
- const manifest = buildManifest({ existing, screens: order, htmls, version, license, author, title, description, shareHash })
303
+ const manifest = buildManifest({ existing, screens: order, htmls, version, license, author, title, description, categories, tags, designLang, shareHash })
301
304
  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())))
302
305
  files.unshift({ path: 'design.json', data: Buffer.from(JSON.stringify(manifest, null, 2) + '\n', 'utf8') })
303
306
  const r = checkPack(files, { mode })
@@ -61,7 +61,16 @@ const SVG_ANIM = new Set(['set', 'animate', 'animatetransform', 'animatemotion',
61
61
 
62
62
  // ── 可疑字(只标出来给人看,不直接拒) ────────────────────────────────────────
63
63
  const PHISH = /登录|登陆|密码|验证码|银行卡|身份证|转账|汇款|客服|中奖|领取奖|充值|提现|\b(log ?in|sign ?in|password|passcode|verification code|bank card|credit card|wire transfer|account number|cvv)\b/i
64
- const BRANDS = /微信支付|支付宝|淘宝|天猫|京东|拼多多|抖音|快手|美团|饿了么|小红书|哔哩哔哩|bilibili|微博|知乎|百度|腾讯|阿里巴巴|字节跳动|中国银行|工商银行|建设银行|农业银行|招商银行|交通银行|邮政储蓄|中国移动|中国联通|中国电信|12306|\b(apple|icloud|google|gmail|microsoft|outlook|paypal|amazon|netflix|facebook|instagram|whatsapp|wechat|alipay|taobao|tiktok|steam|binance|coinbase)\b/i
64
+ // 真实品牌(只是初筛提醒,人工审核兜底):日常词(小米、苹果、大众、美的、联想、全家、三星、统一、光明…)不放;
65
+ // 短名会藏在常见词里的(精华为、内蒙牛肉、适宜家庭、完美团队、北京东路…)排除前后字;撞得太多的(盒马、宝马、索尼、安踏)只认全称 / 英文名
66
+ const BRANDS = new RegExp([
67
+ '微信支付|支付宝|淘宝(?![贝藏])|(?<![今每昨明当])天猫(?![咪粮砂])|(?<![北南])京东|拼多多|抖音|快手(?=直播|小店|短视频|视频|主播|账号|号|粉丝|平台|电商|极速版|带货|官方|app|$|[^\u4e00-\u9fff])|(?<![完精甜唯])美团(?![队建圆])|(?<![你我他她们子宝])饿了么|小红书|哔哩哔哩|微博|知乎|(?<![一二两三四五六七八九十几])百度|腾讯|阿里巴巴|字节跳动|网易(?=[云严游新邮考有])|爱奇艺|优酷|飞书|企业微信|携程|飞猪|(?<![休悠])闲鱼|唯品会|苏宁易购|大众点评|高德地图|滴滴出行|12306',
68
+ '中国银行|工商银行|建设银行|农业银行|招商银行|交通银行|邮政储蓄|中国移动|中国联通|中国电信',
69
+ '胖东来|盒马鲜生|山姆会员店|沃尔玛|永辉超市|(?<![合阖])家乐福|大润发|名创优品|优衣库|无印良品|(?<![居室便适皆相合不咸])宜家|屈臣氏|丝芙兰|叮咚买菜',
70
+ '星巴克|瑞幸咖啡|(?<![祥嘉])瑞幸(?![福运])|(?<![欢恭贺道惊双大])喜茶|奈雪的茶|蜜雪冰城|霸王茶姬|茶百道|海底捞(?!针)|麦当劳|肯德基|必胜客|汉堡王|农夫山泉|元气森林|娃哈哈|可口可乐|百事可乐|雀巢|(?<![内启])蒙牛|康师傅|茅台|五粮液|青岛啤酒|三只松鼠|良品铺子',
71
+ '(?<![升精才年荣中风光芳繁奢豪浮京韶清])华为|比亚迪|蔚来|小鹏汽车|理想汽车|特斯拉|大疆|任天堂|迪士尼|耐克|阿迪达斯',
72
+ '\\b(bilibili|apple|icloud|google|gmail|youtube|microsoft|outlook|linkedin|paypal|mastercard|amazon|netflix|spotify|facebook|instagram|whatsapp|twitter|wechat|alipay|taobao|tiktok|steam|binance|coinbase|starbucks|mcdonald\'?s|kfc|coca-?cola|pepsi|nike|adidas|uniqlo|ikea|costco|walmart|samsung|huawei|xiaomi|tesla|disney|airbnb|uber|bmw|sony|luckin)\\b',
73
+ ].join('|'), 'i')
65
74
  const INJECT = /忽略(之前|以上|前面|上面|先前)|无视(之前|以上|前面)|不要理会|你(现在)?是一个|你的新(任务|指令)|系统提示|提示词|\b(ignore (all |any )?(the )?(previous|prior|above|earlier)|disregard (all |the )?(previous|prior|above)|system prompt|you are now|new instructions|developer mode|jailbreak)\b|\b(preview_page|check_design|look_design|handoff_design|compare_design|extract_design_system|show_page|run_command|write_file|edit_file|read_file|ask_user_question|bash|shell)\b|rm -rf|\bsudo\b|\bcurl\s+-|\bwget\s|\|\s*(ba)?sh\b|powershell|chmod\s|\bnpm (i|install)\b|\bpip install\b/i
66
75
  const URLISH = /\bhttps?:\/\/|\bwww\.[a-z0-9-]+\.|\b[a-z0-9-]+\.(com|cn|net|org|io|xyz|top|cc|me|co|app|dev|site|shop|vip|info)\b/i
67
76
  const PERSONAL_MAIL = /@(qq|163|126|yeah|sina|sohu|139|189|foxmail|aliyun|gmail|googlemail|outlook|hotmail|live|msn|yahoo|icloud|me|mac|proton|protonmail)\.(com|cn|net|com\.cn)\b/i
@@ -56,6 +56,7 @@ function manifestTitle(dir) {
56
56
  return t && typeof t === 'object' ? String(t.zh || t.en || '').slice(0, 40) : ''
57
57
  }
58
58
  const TOKEN_RE = /^[0-9a-f]{32}$/
59
+ const DESIGN_LANGS = ['zh', 'en', 'both'] // design.json 的 lang:设计里的文字是哪种语言
59
60
  /** 分享记号 → 目录里的指纹(sha256 前 32 位)和给人看的短号 */
60
61
  export const shareHashOf = (token) => crypto.createHash('sha256').update(String(token)).digest('hex').slice(0, 32)
61
62
  function shareOf(dir) {
@@ -105,7 +106,7 @@ export function describeWork(w) {
105
106
  return { ...base, title: manifestTitle(dir) || product || w.title || path.basename(dir), kind, screens: screens.length, first: screens[0] || '', updated: Math.round(updated || w.updated || w.seen || 0), thumb: sig ? crypto.createHash('sha1').update(sig).digest('hex').slice(0, 10) : '' }
106
107
  }
107
108
 
108
- export function createLibraryRoutes({ admit, readBody, json, tracker, library, inspiration, studio, open, storeLoad, version = '', exported, log = () => {}, thumbDir = THUMB_DIR, downloads = path.join(os.homedir(), 'Downloads'), sessionCwd = async (id) => tracker.cwdOf(id), render = renderPack, github = createGitHub({ log }) }) {
109
+ export function createLibraryRoutes({ admit, readBody, json, tracker, library, inspiration, studio, open, storeLoad, version = '', exported, log = () => {}, thumbDir = THUMB_DIR, downloads = path.join(os.homedir(), 'Downloads'), sessionCwd = async (id) => tracker.cwdOf(id), render = renderPack, github = createGitHub({ log }), vocab = () => ({ categories: [], tags: [] }) }) {
109
110
  const lang = (body) => (body && body.lang === 'en' ? 'en' : 'zh')
110
111
  // 这次运行里「分享到市场」打出来的包(一键投稿只投这些):zip 路径 → { ref, slug, title, license }
111
112
  const shared = new Map()
@@ -210,6 +211,15 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
210
211
  fs.createReadStream(file).on('error', () => res.end()).pipe(res)
211
212
  }
212
213
 
214
+ // 分类、标签只收词表里有的(机器人按同一份词表查,不在里面会被拒);没传就沿用 design.json 里原来的
215
+ const vocabNow = () => { try { const v = vocab() || {}; return { categories: Array.isArray(v.categories) ? v.categories : [], tags: Array.isArray(v.tags) ? v.tags : [] } } catch { return { categories: [], tags: [] } } }
216
+ function shareMeta(body) {
217
+ const v = vocabNow()
218
+ // 词表拿不到(没联网也没种子):这两栏表单里不显示,design.json 里原来的留着
219
+ const ids = (k, max) => (Array.isArray(body[k]) && v[k].length ? [...new Set(body[k].filter((x) => typeof x === 'string' && v[k].some((y) => y.id === x)))].slice(0, max) : undefined)
220
+ return { categories: ids('categories', 2), tags: ids('tags', 8), designLang: DESIGN_LANGS.includes(body.designLang) ? body.designLang : undefined }
221
+ }
222
+
213
223
  async function pack(req, res) {
214
224
  if (!admit(req, res)) return
215
225
  if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
@@ -226,7 +236,9 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
226
236
  // 分享向导先要一份预填:名字、介绍、授权、分享过没有
227
237
  if (body.info === true) {
228
238
  const pick = (v) => (v && typeof v === 'object' ? String(v[lang(body)] || v.zh || v.en || '') : '')
229
- return json(res, 200, { title: pick(local && local.title) || manifestTitle(dir) || path.basename(dir), description: pick(local && local.description), license: local && local.license === 'CC-BY-4.0' ? 'CC-BY-4.0' : 'CC0-1.0', share: shareOf(dir), screens: screens.length })
239
+ const v = vocabNow()
240
+ const known = (k, max) => (local && Array.isArray(local[k]) ? local[k].filter((x) => v[k].some((y) => y.id === x)).slice(0, max) : [])
241
+ return json(res, 200, { title: pick(local && local.title) || manifestTitle(dir) || path.basename(dir), description: pick(local && local.description), license: local && local.license === 'CC-BY-4.0' ? 'CC-BY-4.0' : 'CC0-1.0', share: shareOf(dir), screens: screens.length, categories: known('categories', 2), tags: known('tags', 8), designLang: local && DESIGN_LANGS.includes(local.lang) ? local.lang : '', vocab: v })
230
242
  }
231
243
  const license = body.license === 'CC-BY-4.0' ? 'CC-BY-4.0' : 'CC0-1.0'
232
244
  // 分享到市场:四个确认都要勾;分享记号第一次分享时生成,存在作者自己的 design.json 里,包里只带它的指纹
@@ -236,7 +248,7 @@ export function createLibraryRoutes({ admit, readBody, json, tracker, library, i
236
248
  const shareHash = token ? shareHashOf(token) : ''
237
249
  let p
238
250
  try {
239
- p = packDesign(dir, { screens, version, license, author: license === 'CC-BY-4.0' ? String(body.author || '') : '', mode: share ? 'share' : 'zip', lang: lang(body), title: share ? String(body.title || '') : '', description: share ? String(body.description || '') : '', shareHash, secrets: [token, local && local.shareToken].filter(Boolean) })
251
+ p = packDesign(dir, { screens, version, license, author: license === 'CC-BY-4.0' ? String(body.author || '') : '', mode: share ? 'share' : 'zip', lang: lang(body), title: share ? String(body.title || '') : '', description: share ? String(body.description || '') : '', ...(share ? shareMeta(body) : {}), shareHash, secrets: [token, local && local.shareToken].filter(Boolean) })
240
252
  } catch (e) {
241
253
  log(e)
242
254
  return json(res, 500, { error: e.message })
package/lib/index.js CHANGED
@@ -1577,7 +1577,7 @@ export function apply(ctx) {
1577
1577
  } catch (e) { log(e) }
1578
1578
  return known
1579
1579
  }
1580
- const lib = createLibraryRoutes({ admit, readBody, json, tracker, library, inspiration, studio, open, storeLoad: fileStore.load, version: VERSION, exported, log, sessionCwd })
1580
+ const lib = createLibraryRoutes({ admit, readBody, json, tracker, library, inspiration, studio, open, storeLoad: fileStore.load, version: VERSION, exported, log, sessionCwd, vocab: () => market.vocab() })
1581
1581
  // 画布上睡着的屏的缩略图(issue #17)
1582
1582
  const canvasThumbs = createCanvasThumbs({
1583
1583
  tracker,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-design-studio",
3
- "version": "0.24.0",
3
+ "version": "0.25.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1 test/*.mjs"