dsh-design-studio 0.16.1 → 0.18.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/lib/look.js CHANGED
@@ -147,7 +147,7 @@ export async function fitSize(browser, screens, kind, size) {
147
147
  const RULE_PROP = { contrast: 'color', tiny: 'font-size' }
148
148
  const MAX_RULES = 12
149
149
 
150
- export async function measureAll(browser, { screens, sizes, kind, dark, fetcher = globalThis.fetch, locate = null }) {
150
+ export async function measureAll(browser, { screens, sizes, kind, dark, fetcher = globalThis.fetch, locate = null, annots = null }) {
151
151
  const jobs = []
152
152
  for (const sc of screens) for (const [w, h] of sizes) jobs.push({ sc, w, h })
153
153
  const gone = new Map() // 地址 → Promise<是不是 404>(几屏、几种尺寸指着同一页只问一次)
@@ -185,6 +185,8 @@ export async function measureAll(browser, { screens, sizes, kind, dark, fetcher
185
185
  }
186
186
  }
187
187
  // 跳转:每屏只在第一种尺寸上收一次(几种尺寸下链接一样)
188
+ // 业务标注定位得到吗:也只在第一种尺寸上核对(annots:屏的文件名 → 这一屏的标注;关着是 null)
189
+ if (i % sizes.length === 0 && annots && annots.has(sc.key)) row.annots = await page.eval(`window.__dshDesign.annots ? window.__dshDesign.annots(${JSON.stringify(annots.get(sc.key))}) : null`).catch(() => null)
188
190
  if (i % sizes.length === 0 && fetcher) row.links = await page.eval('window.__dshDesign.links ? window.__dshDesign.links() : []').catch(() => [])
189
191
  })
190
192
  } catch (e) {
package/lib/photos.js CHANGED
@@ -113,6 +113,15 @@ export function searchPhotos(index, opts = {}) {
113
113
  return scan(index, opts).rows.slice(0, n).map((r) => r.p)
114
114
  }
115
115
 
116
+ const ORIENT_NAME = { landscape: '横图', portrait: '竖图', square: '方图' }
117
+
118
+ /** 要的比例不够、补了别的比例时照实说(每个题材横图只有四张,一套设计很容易用完) */
119
+ export function ratioNote(list, ratio) {
120
+ const off = ratio ? list.filter((p) => orientOf(p.w, p.h) !== ratio).length : 0
121
+ const name = ORIENT_NAME[ratio]
122
+ return off ? `其中 ${off} 张不是${name}(对得上又没用过的${name}不够):用 object-fit: cover 裁,看好主体别被裁掉;也可以接着用 assets 里已有的${name}。\n` : ''
123
+ }
124
+
116
125
  /** 这次只命中了题材、没有对得上的具体画面(工具要照实告诉模型,让它看描述再决定用不用) */
117
126
  export const onlyByTheme = (index, opts) => { const r = scan(index, opts); return r.rows.length > 0 && !r.specific }
118
127
 
package/lib/picker.js CHANGED
@@ -318,6 +318,7 @@
318
318
  if (fx) fx.host.style.setProperty('--k', K)
319
319
  if (editUi) editUi.host.style.setProperty('--k', K)
320
320
  placePin()
321
+ if (anMarks.length) placeAnnots()
321
322
  }
322
323
 
323
324
  function mount(hint) {
@@ -593,6 +594,14 @@
593
594
  transform:scale(var(--k, 1));transform-origin:0 0;box-shadow:0 2px 6px rgba(0,0,0,.25)}
594
595
  .ck.hi b{background:#e5484d}
595
596
  .ck.on{animation:ck-on 1.2s ease-out}
597
+ .an{position:absolute;pointer-events:none;border-radius:4px}
598
+ .an.sel{outline:calc(2px * var(--k, 1)) solid #4d6bfe;outline-offset:calc(1px * var(--k, 1));background:rgba(77,107,254,.07)}
599
+ .an b{position:absolute;left:calc((var(--i, 0) * 21px - 9px) * var(--k, 1));top:calc(-9px * var(--k, 1));min-width:18px;height:18px;padding:0 4px;box-sizing:border-box;border-radius:9px;
600
+ border:1.5px solid #4d6bfe;background:#fff;color:#4d6bfe;font:700 11px/15px -apple-system,BlinkMacSystemFont,system-ui,sans-serif;text-align:center;
601
+ transform:scale(var(--k, 1));transform-origin:0 0;box-shadow:0 2px 6px rgba(0,0,0,.25);pointer-events:auto;cursor:pointer}
602
+ .an.sel b{background:#4d6bfe;color:#fff}
603
+ .an.fl{animation:an-fl 1.2s ease-out}
604
+ @keyframes an-fl{0%,40%{box-shadow:0 0 0 calc(6px * var(--k, 1)) rgba(77,107,254,.35)}100%{box-shadow:0 0 0 0 rgba(77,107,254,0)}}
596
605
  .cut{position:absolute;pointer-events:none;border:calc(2px * var(--k, 1)) solid #e5484d;border-radius:4px;box-shadow:0 0 0 1px rgba(255,255,255,.85)}
597
606
  .cut.alt{border-color:#f59e0b;border-style:dashed}
598
607
  .cut b{position:absolute;left:calc(-2px * var(--k, 1));bottom:100%;margin-bottom:calc(3px * var(--k, 1));padding:0 6px;border-radius:4px;background:#e5484d;color:#fff;
@@ -4221,6 +4230,10 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
4221
4230
  try {
4222
4231
  goScrollHome('instant') // 量的时候要滚动,别把闪改动的回位打断、停在半路
4223
4232
  await settle()
4233
+ // 刚换上来的帧,ready 可能早于第一次排版(视口还是 0×0,量出来是空清单):等排好版再量,等不到就照实说没量成,别当成「没问题」
4234
+ const laidOut = () => innerWidth > 0 && innerHeight > 0 && document.documentElement.clientWidth > 0 && document.documentElement.getClientRects().length > 0
4235
+ for (let i = 0; i < 60 && !laidOut(); i++) await new Promise((res) => setTimeout(res, 50))
4236
+ if (!laidOut()) throw new Error('layout')
4224
4237
  r = runCheck(String(d.kind || 'web'))
4225
4238
  } catch (e) {
4226
4239
  // 量的时候出错了:照实说没量成,别当成「没问题」
@@ -4236,6 +4249,233 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
4236
4249
  post({ type: 'checked', id: d.id, issues: r.issues.map(({ el, ...rest }) => rest), metrics: r.metrics, width: r.metrics.w })
4237
4250
  }
4238
4251
 
4252
+ // ── 业务标注:编号圆点、选中才描框、点编号回报。内容(annotations.json)由右侧栏发来,全当数据:选择器只进 querySelector,文字只用 textContent ──
4253
+ let anMarks = [] // { a, el, node, dot }
4254
+ let anSel = ''
4255
+ let anRaf = 0
4256
+ let anMo = null
4257
+ let anRo = null
4258
+ let anReT = 0
4259
+ let anReGap = 250
4260
+ let anLast = ''
4261
+
4262
+ const flatText = (s) => String(s || '').replace(/\s+/g, '').toLowerCase()
4263
+ const shownBox = (el) => {
4264
+ const r = el.getBoundingClientRect()
4265
+ if (r.width <= 0 && r.height <= 0) return false
4266
+ return !hiddenChain(el) // 自己或祖先 display:none、visibility:hidden、完全透明
4267
+ }
4268
+
4269
+ /** el 里看得见的字:藏着的、完全透明的文字节点不算 */
4270
+ function seenText(el) {
4271
+ let s = ''
4272
+ const w = document.createTreeWalker(el, NodeFilter.SHOW_TEXT)
4273
+ for (let n = w.nextNode(); n; n = w.nextNode()) if (n.parentElement && !hiddenChain(n.parentElement)) s += n.nodeValue
4274
+ return s
4275
+ }
4276
+
4277
+ /** 文字里含这段字、看得见、最小的那个元素(一段字被 <a> 切开也认) */
4278
+ function annotByText(text) {
4279
+ const want = flatText(text)
4280
+ if (!want || !document.body) return null
4281
+ let best = null
4282
+ let bestLen = Infinity
4283
+ for (const el of document.body.querySelectorAll('*')) {
4284
+ if (SKIP_TAGS.has(el.tagName) || el.tagName === 'STYLE' || el.tagName === 'DSH-DESIGN-EDIT') continue
4285
+ const tx = flatText(el.textContent)
4286
+ if (tx.length > bestLen || !tx.includes(want)) continue
4287
+ if (tx.length === bestLen && !(best && best.contains(el))) continue // 一样长:子元素比父元素准,别的地方的同样文字不抢第一处
4288
+ if (!shownBox(el) || !flatText(el.innerText ?? el.textContent).includes(want) || !flatText(seenText(el)).includes(want)) continue // 容器看得见、字在藏着、折叠或透明的子元素里:不算
4289
+ best = el
4290
+ bestLen = tx.length
4291
+ }
4292
+ return best
4293
+ }
4294
+
4295
+ /** 一条标注对应页面上哪个元素 → { el, how: selector / text / page(整屏的说明)/ ''(定位不到), count: 选择器匹配到几个 } */
4296
+ function findAnnot(a) {
4297
+ const selector = String((a && a.selector) || '')
4298
+ const text = String((a && a.fallbackText) || '')
4299
+ if (!selector && !text) return { el: document.body, how: 'page', count: 0 } // 整屏的说明:编号放在页面左上角
4300
+ let count = 0
4301
+ let el = null
4302
+ if (selector) {
4303
+ try {
4304
+ const all = document.querySelectorAll(selector)
4305
+ count = all.length
4306
+ el = all[0] || null
4307
+ } catch { /* 选择器写法不对:当作没找到 */ }
4308
+ if (el) return { el, how: 'selector', count }
4309
+ }
4310
+ el = annotByText(text)
4311
+ return { el, how: el ? 'text' : '', count }
4312
+ }
4313
+
4314
+ /** 元素没被能滚、能裁的容器挡住的那块(视口坐标);全挡住了是 null:编号别飘在外面 */
4315
+ function annotVisible(el) {
4316
+ const r = el.getBoundingClientRect()
4317
+ const box = { left: r.left, top: r.top, right: r.right, bottom: r.bottom }
4318
+ let mode = getComputedStyle(el).position
4319
+ for (let p = el.parentElement; p && p !== document.body && p !== document.documentElement; p = p.parentElement) {
4320
+ const o = getComputedStyle(p)
4321
+ if ((mode === 'absolute' && !holds(o, false)) || (mode === 'fixed' && !holds(o, true))) continue // 这层不是它的包含块,裁不到它
4322
+ mode = o.position
4323
+ if (o.overflowX === 'visible' && o.overflowY === 'visible') continue
4324
+ const c = p.getBoundingClientRect()
4325
+ if (o.overflowX !== 'visible') { box.left = Math.max(box.left, c.left); box.right = Math.min(box.right, c.right) }
4326
+ if (o.overflowY !== 'visible') { box.top = Math.max(box.top, c.top); box.bottom = Math.min(box.bottom, c.bottom) }
4327
+ if ((r.width > 0 && box.right <= box.left) || (r.height > 0 && box.bottom <= box.top)) return null
4328
+ }
4329
+ // 再和视口取交集(整个在视口外就按版面位置算,滚到了自然对)
4330
+ const vp = { left: Math.max(box.left, 0), top: Math.max(box.top, 0), right: Math.min(box.right, innerWidth), bottom: Math.min(box.bottom, innerHeight) }
4331
+ const seen = vp.right > vp.left && vp.bottom > vp.top ? vp : box
4332
+ return { ...seen, partial: seen.left > r.left + 1 || seen.top > r.top + 1 || seen.right < r.right - 1 || seen.bottom < r.bottom - 1 }
4333
+ }
4334
+
4335
+ function placeAnnots() {
4336
+ for (const m of anMarks) {
4337
+ const vis = m.el && m.el.isConnected && shownBox(m.el) ? annotVisible(m.el) : null
4338
+ if (!vis) { m.node.style.display = 'none'; continue }
4339
+ const r = docRect(m.el)
4340
+ Object.assign(m.node.style, { display: '', left: r.left + 'px', top: r.top + 'px', width: r.width + 'px', height: r.height + 'px' })
4341
+ // 编号放在露出来的那块的左上角;贴着页面边的往里挪,描框位置不变
4342
+ const b = m.el.getBoundingClientRect()
4343
+ const inset = (hid, at) => (hid > 1 ? hid + 9 * K : Math.max(0, 9 * K - at))
4344
+ const ml = inset(vis.left - b.left, r.left)
4345
+ const mt = inset(vis.top - b.top, r.top)
4346
+ m.dot.style.marginLeft = ml ? `${ml}px` : ''
4347
+ m.dot.style.marginTop = mt ? `${mt}px` : ''
4348
+ }
4349
+ }
4350
+ const queueAnnots = () => { if (!anRaf) anRaf = requestAnimationFrame(() => { anRaf = 0; placeAnnots() }) }
4351
+
4352
+ // 同一个元素上的几条:编号往右排开
4353
+ function spreadDots() {
4354
+ const perEl = new Map()
4355
+ for (const m of anMarks) {
4356
+ if (!m.el) continue
4357
+ const i = perEl.get(m.el) || 0
4358
+ perEl.set(m.el, i + 1)
4359
+ m.dot.style.setProperty('--i', i)
4360
+ }
4361
+ }
4362
+ const postAnnotState = () => post({ type: 'annotState', list: anMarks.map((m) => ({ id: m.a.id, how: m.how, count: m.count })) })
4363
+
4364
+ /** 页面内容变了(切标签、脚本重画):每条重新对一遍,后冒出来的补上编号、选择器换了对象跟过去、状态报回右侧栏。这一轮太费时就放慢 */
4365
+ function relocateAnnots() {
4366
+ anReT = 0
4367
+ const t0 = performance.now()
4368
+ let moved = false
4369
+ let state = false
4370
+ for (const m of anMarks) {
4371
+ const f = findAnnot(m.a)
4372
+ if (f.el !== m.el) { m.el = f.el; moved = true }
4373
+ if (f.how !== m.how || f.count !== m.count) { m.how = f.how; m.count = f.count; state = true }
4374
+ }
4375
+ if (moved) spreadDots()
4376
+ if (moved || state) placeAnnots()
4377
+ if (state) postAnnotState()
4378
+ anReGap = Math.min(3000, Math.max(250, (performance.now() - t0) * 20))
4379
+ }
4380
+ const onAnnotDom = () => { queueAnnots(); if (!anReT) anReT = setTimeout(relocateAnnots, anReGap) }
4381
+
4382
+ function watchAnnots(on) {
4383
+ if (on && !anMo) {
4384
+ addEventListener('scroll', queueAnnots, true) // 捕获:里面能滚的区域也算
4385
+ addEventListener('resize', queueAnnots)
4386
+ document.addEventListener('load', onAnnotDom, true) // 图片晚到把版面推走(load 到不了 window,捕获挂在 document)
4387
+ addEventListener('change', onAnnotDom, true) // 纯 CSS 的切换(:checked 换标签内容)没有 DOM 变化
4388
+ addEventListener('input', onAnnotDom, true)
4389
+ addEventListener('transitionend', queueAnnots, true)
4390
+ addEventListener('animationend', queueAnnots, true)
4391
+ anMo = new MutationObserver(onAnnotDom)
4392
+ if (document.body) anMo.observe(document.body, { subtree: true, childList: true, characterData: true, attributes: true })
4393
+ anMo.observe(document.documentElement, { attributes: true }) // 根节点上切 class / data-view 换内容
4394
+ if (typeof ResizeObserver === 'function') {
4395
+ anRo = new ResizeObserver(queueAnnots) // 区域展开、字体换行,页面整体变高
4396
+ anRo.observe(document.documentElement)
4397
+ if (document.body) anRo.observe(document.body)
4398
+ }
4399
+ } else if (!on && anMo) {
4400
+ removeEventListener('scroll', queueAnnots, true)
4401
+ removeEventListener('resize', queueAnnots)
4402
+ document.removeEventListener('load', onAnnotDom, true)
4403
+ removeEventListener('change', onAnnotDom, true)
4404
+ removeEventListener('input', onAnnotDom, true)
4405
+ removeEventListener('transitionend', queueAnnots, true)
4406
+ removeEventListener('animationend', queueAnnots, true)
4407
+ anMo.disconnect()
4408
+ anMo = null
4409
+ if (anRo) anRo.disconnect()
4410
+ anRo = null
4411
+ }
4412
+ }
4413
+
4414
+ function clearAnnots() {
4415
+ for (const m of anMarks) m.node.remove()
4416
+ anMarks = []
4417
+ clearTimeout(anReT)
4418
+ anReT = 0
4419
+ watchAnnots(false)
4420
+ }
4421
+
4422
+ function setAnnotSel(id) {
4423
+ anSel = String(id || '')
4424
+ for (const m of anMarks) m.node.classList.toggle('sel', m.a.id === anSel)
4425
+ }
4426
+
4427
+ const pickAnnot = (m) => { setAnnotSel(m.a.id); post({ type: 'annotPick', id: m.a.id }) }
4428
+
4429
+ function showAnnots(list, sel) {
4430
+ clearAnnots()
4431
+ const items = Array.isArray(list) ? list.slice(0, 200) : []
4432
+ if (!items.length) { anSel = ''; return }
4433
+ const { root } = fxRoot()
4434
+ for (const a of items) {
4435
+ const f = findAnnot(a) // 这会儿定位不到的也留着:页面后面长出来时补上编号
4436
+ const node = document.createElement('div')
4437
+ node.className = 'an'
4438
+ const dot = document.createElement('b')
4439
+ dot.textContent = String(a.n)
4440
+ const m = { a, el: f.el, how: f.how, count: f.count, node, dot }
4441
+ dot.addEventListener('click', (e) => { e.stopPropagation(); e.preventDefault(); pickAnnot(m) })
4442
+ node.append(dot)
4443
+ root.append(node)
4444
+ anMarks.push(m)
4445
+ }
4446
+ spreadDots()
4447
+ setAnnotSel(sel)
4448
+ placeAnnots()
4449
+ watchAnnots(true)
4450
+ postAnnotState()
4451
+ // 字体、图片晚到会把版面推走
4452
+ setTimeout(placeAnnots, 400)
4453
+ if (document.fonts && document.fonts.ready) document.fonts.ready.then(placeAnnots).catch(() => {})
4454
+ }
4455
+
4456
+ /** 右侧栏点了这张卡片:滚过去,描框,闪一下 */
4457
+ function focusAnnot(id) {
4458
+ anLast = String(id || '')
4459
+ setAnnotSel(id)
4460
+ const m = anMarks.find((x) => x.a.id === id)
4461
+ if (!m || !m.el || !m.el.isConnected) return
4462
+ const go = () => { m.node.classList.remove('fl'); void m.node.offsetWidth; m.node.classList.add('fl') }
4463
+ if (m.how === 'page') { scrollAll(scrollAreas(), false); placeAnnots(); go(); return }
4464
+ const vis = annotVisible(m.el)
4465
+ if (inView(m.el) && vis && !vis.partial) { go(); return }
4466
+ try { m.el.scrollIntoView({ behavior: 'smooth', block: 'center' }) } catch { m.el.scrollIntoView() }
4467
+ setTimeout(() => { placeAnnots(); go() }, 450)
4468
+ }
4469
+
4470
+ /** 画布上每屏盖着一层挡板,点不到页面:右侧栏把点的位置告诉页面,点中编号就算点了它 */
4471
+ function hitAnnot(x, y) {
4472
+ for (const m of [...anMarks].reverse()) {
4473
+ if (m.node.style.display === 'none') continue
4474
+ const r = m.dot.getBoundingClientRect()
4475
+ if (x >= r.left - 3 && x <= r.right + 3 && y >= r.top - 3 && y <= r.bottom + 3) { pickAnnot(m); return }
4476
+ }
4477
+ }
4478
+
4239
4479
  // ── 深色模式:页面带了深色样式([data-theme="dark"] / .dark / prefers-color-scheme: dark)就能切 ──
4240
4480
 
4241
4481
  let darkOn = false
@@ -4344,6 +4584,10 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
4344
4584
  else if (d.type === 'check') onCheck(d)
4345
4585
  else if (d.type === 'checkClear') { clearMarks(); lastIssues = [] }
4346
4586
  else if (d.type === 'checkFocus') { holdScroll(); focusIssue(Number(d.i)) } // 用户点了别的地方要看,别再滚回去
4587
+ else if (d.type === 'annots') showAnnots(d.list, d.sel)
4588
+ else if (d.type === 'annotSel') setAnnotSel(d.id)
4589
+ else if (d.type === 'annotFocus') { holdScroll(); focusAnnot(String(d.id || '')) }
4590
+ else if (d.type === 'annotHit') hitAnnot(Number(d.x), Number(d.y))
4347
4591
  else if (d.type === 'theme') { setDark(d.dark); postTop(); setTimeout(postTop, 400) }
4348
4592
  else if (d.type === 'demo') demo = !!d.on
4349
4593
  else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false)
@@ -4374,6 +4618,15 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
4374
4618
  /** 调节滑块的值套到页面上(和右侧栏拖的时候一样) */
4375
4619
  tweak: (vars, attrs) => { applyTweak(vars, attrs); return true },
4376
4620
  settle: () => settle().then(() => true),
4621
+ /** 业务标注定位得到吗(只找,不画):[{ id, how, count }] */
4622
+ annots: async (list) => {
4623
+ await settle()
4624
+ return (Array.isArray(list) ? list.slice(0, 200) : []).map((a) => { const f = findAnnot(a); return { id: a.id, how: f.how, count: f.count } })
4625
+ },
4626
+ /** 页面上现在画着哪几条业务标注的编号(id) */
4627
+ annotMarks: () => anMarks.filter((m) => m.node.isConnected && m.node.style.display !== 'none').map((m) => m.a.id),
4628
+ /** 最后被右侧栏定位的是哪条 */
4629
+ annotLast: () => anLast,
4377
4630
  /** 跳到别的屏的地方(路径和按钮上的字),量完查一下目标在不在 */
4378
4631
  links: () => linksOf().map(({ path, text }) => ({ path, text })),
4379
4632
  info: () => {
package/lib/serve.js CHANGED
@@ -68,6 +68,7 @@ export const MIME = {
68
68
  // 改动通知里不算的:版本库、依赖、系统垃圾
69
69
  const EXPORTS = /^(exports([\\/][^\\/]+\.(png|pdf|pptx))?|refs([\\/][^\\/]+\.(png|jpe?g|gif|webp))?)$/i // 导出的图片 / PDF / PPT、参考图(和第一次建的 exports / refs 目录):不算设计改了
70
70
  const IGNORED = /(^|[\\/])(\.git|node_modules|\.DS_Store|\.next|\.cache|\.turbo)([\\/]|$)/
71
+ const ANNOTATIONS = /^annotations\.json(\.[0-9a-z]+\.tmp)?$/i // 业务标注(DSH 写文件时先写 .tmp 再改名):右侧栏靠轮询跟上,页面用不到它,别一改就整屏刷新
71
72
  const HANDOFF = /^handoff([\\/]|$)/i // 转成代码的交接包(说明和截图):不算设计改了,也别在截图时把页面刷掉
72
73
 
73
74
  /** 只认本机名 + 自己的端口(防 DNS 重绑定:外站把域名解析到 127.0.0.1 也进不来) */
@@ -305,7 +306,7 @@ export function draftInjector(tag) {
305
306
  }
306
307
  }
307
308
 
308
- export function createHub({ log = () => {}, onChange = () => {}, history = null, parents = () => [], strict = null, drafts = null } = {}) {
309
+ export function createHub({ log = () => {}, onChange = () => {}, history = null, parents = () => [], strict = null, drafts = null, skipAnnots = () => false } = {}) {
309
310
  const strictHtml = (buf) => { try { return !!(strict && strict.html && strict.html(buf)) } catch (e) { log(e); return true } }
310
311
  const strictRoot = (dir) => { try { return !!(strict && strict.root && strict.root(dir)) } catch (e) { log(e); return true } }
311
312
  const strictVer = (dir) => { try { return !!(strict && strict.versions && strict.versions(dir)) } catch (e) { log(e); return true } }
@@ -521,7 +522,7 @@ export function createHub({ log = () => {}, onChange = () => {}, history = null,
521
522
  try {
522
523
  entry.watcher = fs.watch(entry.root, { recursive: true }, (_type, name) => {
523
524
  const rel = String(name || '')
524
- if (IGNORED.test(rel) || /(^|[\\/])\./.test(rel) || EXPORTS.test(rel) || HANDOFF.test(rel)) return
525
+ if (IGNORED.test(rel) || /(^|[\\/])\./.test(rel) || EXPORTS.test(rel) || HANDOFF.test(rel) || (skipAnnots() && ANNOTATIONS.test(rel))) return
525
526
  last = rel
526
527
  batch.add(rel.split(path.sep).join('/'))
527
528
  clearTimeout(timer)
package/lib/styles.js ADDED
@@ -0,0 +1,203 @@
1
+ /**
2
+ * 风格卡的服务端一份:pick_style 工具用(模型自己定风格时,消费类题目总落回米色暖调)。
3
+ * 和右侧栏 client.js 里的 STYLES、autoStyle 是同一份内容:客户端是单文件、不能 import,
4
+ * 改了要两边一起改,test-client.mjs 会比对。
5
+ */
6
+ import { contrast, parseColor } from './system.js'
7
+
8
+ const SANS = '"PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif'
9
+ const SERIF = '"Songti SC", "Noto Serif SC", "Source Han Serif SC", serif'
10
+ const ROUND = '"SF Pro Rounded", "PingFang SC", "HarmonyOS Sans SC", system-ui, sans-serif'
11
+ const MONO = '"JetBrains Mono", "SF Mono", Menlo, Consolas, monospace'
12
+ const GROTESK = '"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif'
13
+ export const STYLES = [
14
+ { id: 'minimal', zh: '极简白', en: 'Minimal', dzh: '大留白、细线、黑白加一点蓝', den: 'Lots of space, hairlines, black and white with a touch of blue',
15
+ c: { bg: '#FAFAF9', surface: '#FFFFFF', text: '#18181B', muted: '#6B6B73', line: '#E4E4E7', primary: '#18181B', accent: '#2563EB', on: '#FFFFFF', link: '#2563EB' },
16
+ head: SANS, w: 600, radius: 10, shadow: '0 1px 2px rgba(24,24,27,.06)',
17
+ nzh: '靠字号和留白分层级,不靠色块;分隔用 1px 细线;蓝色只给链接和选中态;大标题字距收 -0.02em',
18
+ nen: 'Hierarchy from type size and whitespace, not color blocks; 1px hairlines; blue only for links and selection; tighten big headings to -0.02em' },
19
+ { id: 'warm', zh: '温暖手作', en: 'Warm craft', dzh: '纸感底色、圆润、手绘感', den: 'Paper tones, soft and rounded, hand-made feel',
20
+ c: { bg: '#F6EFE6', surface: '#FFF9F2', text: '#2B1D14', muted: '#6E5A4B', line: '#E7D9C8', primary: '#A9542A', accent: '#5E7A4A', on: '#FFFFFF', link: '#52703F' },
21
+ head: SERIF, w: 600, radius: 16, shadow: '0 8px 24px rgba(120,72,30,.12)',
22
+ nzh: '标题用衬线字,正文无衬线;插画用手绘线条和色块;阴影带暖色;中性色都偏暖,不用纯灰',
23
+ nen: 'Serif headings, sans body; hand-drawn line illustrations and color blocks; warm-tinted shadows; warm neutrals, no pure gray' },
24
+ { id: 'editorial', zh: '杂志编辑', en: 'Editorial', dzh: '大标题、黑线栅格、红色点题', den: 'Big headlines, black-rule grid, a red accent',
25
+ c: { bg: '#F4F1EA', surface: '#FFFFFF', text: '#111111', muted: '#555555', line: '#111111', primary: '#C8231B', accent: '#111111', on: '#FFFFFF', link: '#C8231B' },
26
+ head: SERIF, w: 700, radius: 2, shadow: 'none',
27
+ nzh: '标题很大、粗细对比强烈;用粗细两种黑线分栏;版式不对称、有留白;红色只在一两处;几乎没有圆角和阴影',
28
+ nen: 'Very large headlines with strong weight contrast; thick and thin black rules for columns; asymmetric layout; red in one or two places only; almost no radius or shadow' },
29
+ { id: 'dark', zh: '深色高级', en: 'Dark luxe', dzh: '近黑底、香槟金点缀、大图', den: 'Near-black, champagne gold accents, big imagery',
30
+ c: { bg: '#0E0E10', surface: '#18181B', text: '#F2EFE9', muted: '#A19C93', line: '#2C2C30', primary: '#C9A86A', accent: '#E8E2D6', on: '#17140E', link: '#C9A86A' },
31
+ head: SERIF, w: 500, radius: 12, shadow: '0 12px 40px rgba(0,0,0,.45)',
32
+ nzh: '金色只点在关键按钮和细线上;层级靠表面色深浅,不靠阴影;标题细一点、字距放开;留白要多',
33
+ nen: 'Gold only on key buttons and fine lines; layers from surface shades, not shadows; lighter, tracked-out headings; generous space' },
34
+ { id: 'playful', zh: '活泼年轻', en: 'Playful', dzh: '粗描边、硬阴影、贴纸感', den: 'Thick outlines, hard shadows, sticker feel',
35
+ c: { bg: '#FFF7E8', surface: '#FFFFFF', text: '#1D1B3A', muted: '#5D5A82', line: '#1D1B3A', primary: '#FF6A3D', accent: '#1F9E92', on: '#1D1B3A', link: '#137167' },
36
+ head: ROUND, w: 800, radius: 20, shadow: '4px 4px 0 #1D1B3A',
37
+ nzh: '卡片和按钮 2px 深色描边 + 不模糊的硬阴影;主色按钮上用深色字;元素可以略微倾斜、像贴纸;颜色最多三种',
38
+ nen: '2px dark outlines and hard, unblurred shadows on cards and buttons; dark text on the primary button; slightly tilted sticker-like bits; three colors max' },
39
+ { id: 'fresh', zh: '清新自然', en: 'Fresh', dzh: '浅绿底、圆角卡片、轻插画', den: 'Pale green, rounded cards, light illustration',
40
+ c: { bg: '#F3F7F2', surface: '#FFFFFF', text: '#1F2A22', muted: '#56665A', line: '#DCE6DA', primary: '#2F7D4F', accent: '#C9962A', on: '#FFFFFF', link: '#2F7D4F' },
41
+ head: SANS, w: 600, radius: 14, shadow: '0 6px 18px rgba(47,125,79,.10)',
42
+ nzh: '大面积浅色、卡片白底;插画用叶子、阳光这类自然元素;黄色只做小点缀;整体轻、透气',
43
+ nen: 'Large light areas with white cards; nature motifs (leaves, sunlight) in illustrations; yellow only as a small accent; light and airy' },
44
+ { id: 'tech', zh: '专业科技', en: 'Pro / tech', dzh: '冷灰蓝、信息密、数字清楚', den: 'Cool gray-blue, dense info, crisp numbers',
45
+ c: { bg: '#F5F7FB', surface: '#FFFFFF', text: '#0F172A', muted: '#55657D', line: '#E2E8F0', primary: '#2457F5', accent: '#0F8F8E', on: '#FFFFFF', link: '#2457F5' },
46
+ head: SANS, w: 600, radius: 8, shadow: '0 1px 3px rgba(15,23,42,.08)',
47
+ nzh: '信息密度高但对齐严格;数字用等宽(font-variant-numeric: tabular-nums);表格行高 44–48;状态用小色点和标签;主色只给主操作',
48
+ nen: 'Dense but strictly aligned; tabular numbers (font-variant-numeric: tabular-nums); 44–48px table rows; status as small dots and tags; primary color only for the main action' },
49
+ { id: 'glass', zh: '玻璃质感', en: 'Glass', dzh: '柔光底、浮层毛玻璃', den: 'Soft glow background, frosted overlays',
50
+ c: { bg: '#EAF0F6', surface: '#F7F9FC', text: '#10151C', muted: '#4F5B69', line: '#D5DEE8', primary: '#CC4520', accent: '#2B6CB0', on: '#FFFFFF', link: '#2B6CB0' },
51
+ bgImage: 'radial-gradient(circle at 20% 15%, #FFD9C7 0, transparent 45%), radial-gradient(circle at 85% 70%, #C9E2FF 0, transparent 50%)',
52
+ head: SANS, w: 600, radius: 18, shadow: '0 10px 30px rgba(16,21,28,.10)',
53
+ nzh: '底色加两三团柔和的光斑(别用紫蓝渐变);只有浮层、卡片、标签栏用毛玻璃(半透明白 + backdrop-filter: blur(20px) + 1px 白色描边),正文区是实色;毛玻璃上的字照样要够深',
54
+ nen: 'Two or three soft light blobs on the background (not a purple-blue gradient); frosted glass only on overlays, cards and tab bars (translucent white + backdrop-filter: blur(20px) + 1px white border), solid elsewhere; text on glass stays dark enough' },
55
+ { id: 'soft', zh: '柔和立体', en: 'Soft UI', dzh: '同色底、凸起凹陷的柔光阴影', den: 'Same-color surfaces with raised and pressed soft shadows',
56
+ c: { bg: '#E9EDF2', surface: '#E9EDF2', text: '#2D3440', muted: '#556072', line: '#D3D9E1', primary: '#3E5BD8', accent: '#22A06B', on: '#FFFFFF', link: '#3E5BD8' },
57
+ head: ROUND, w: 700, radius: 18, shadow: '6px 6px 14px #C8CED6, -6px -6px 14px #FFFFFF',
58
+ nzh: '卡片和底同色,靠一亮一暗两道阴影凸起,按下用内阴影;容易看不清,所以主按钮一定用主色实底、文字够深;别整屏都是凸起',
59
+ nen: 'Cards share the background color and rise with a light and a dark shadow; pressed states use inset shadows; it gets low-contrast fast, so the main button is solid primary with strong text; don\'t make everything raised' },
60
+ { id: 'guochao', zh: '国潮', en: 'Guochao', dzh: '中国红配金、粗宋体、传统纹样', den: 'Chinese red and gold, bold Song type, traditional patterns',
61
+ c: { bg: '#FBF3E4', surface: '#FFFAF0', text: '#2A1410', muted: '#6F4A3A', line: '#E8D3B5', primary: '#B8202A', accent: '#C8952E', on: '#FFF7E6', link: '#A31D26' },
62
+ head: SERIF, w: 800, radius: 6, shadow: '0 6px 18px rgba(140,30,20,.12)',
63
+ nzh: '中国红的大色块配金色细线;标题用粗宋体,可以竖排;祥云、回纹、印章这类纹样用 SVG 画,只做点缀别铺满;底色是米黄纸色,不用纯白',
64
+ nen: 'Big Chinese-red blocks with fine gold lines; bold Song headings, vertical text allowed; clouds, fret borders and seal stamps drawn in SVG as accents only; rice-paper background, not pure white' },
65
+ { id: 'ink', zh: '中式雅致', en: 'Ink & paper', dzh: '宣纸底、墨色字、朱砂点缀', den: 'Paper white, ink-black type, a touch of cinnabar',
66
+ c: { bg: '#F5F2EC', surface: '#FBF9F5', text: '#1E1E1C', muted: '#5F5B54', line: '#DAD4C8', primary: '#2F3B37', accent: '#8C2F2B', on: '#F5F2EC', link: '#8C2F2B' },
67
+ head: SERIF, w: 500, radius: 4, shadow: 'none',
68
+ nzh: '大量留白、细线分隔;标题细宋体、字距放开;朱砂红只像印章一样点一两处;插画用浅灰的水墨晕染(SVG 模糊色块),不用照片堆满',
69
+ nen: 'Lots of space and hairline dividers; light Song headings with open tracking; cinnabar red only in one or two seal-like spots; illustrations as pale ink washes (blurred SVG shapes), not photo walls' },
70
+ { id: 'cyber', zh: '赛博朋克', en: 'Cyberpunk', dzh: '近黑底、品红青色霓虹、等宽字', den: 'Near-black, magenta and cyan neon, monospace',
71
+ c: { bg: '#0B0B16', surface: '#151528', text: '#E9E6FF', muted: '#A09CC8', line: '#2E2B52', primary: '#FF2E88', accent: '#22E1FF', on: '#0B0B16', link: '#22E1FF' },
72
+ head: MONO, w: 700, radius: 2, shadow: '0 0 0 1px #FF2E88, 0 0 18px rgba(255,46,136,.45)',
73
+ nzh: '标题用等宽字、全大写,可以加一点故障错位(两层彩色 text-shadow);边框是 1px 霓虹线加外发光,发光只给主按钮和关键数字;背景可以叠细网格线;正文照样要清楚',
74
+ nen: 'Monospace, all-caps headings with a slight glitch (two colored text-shadows); 1px neon borders with glow, glow only on the main button and key numbers; a fine grid on the background is fine; body text stays readable' },
75
+ { id: 'cute', zh: '可爱卡通', en: 'Cute', dzh: '粉黄糖果色、大圆角、圆体字', den: 'Candy pink and yellow, big radii, rounded type',
76
+ c: { bg: '#FFF4F6', surface: '#FFFFFF', text: '#3A2540', muted: '#7A5E80', line: '#F3D3DD', primary: '#FF7AA8', accent: '#FFC93C', on: '#3A2540', link: '#C2366F' },
77
+ head: ROUND, w: 800, radius: 24, shadow: '0 6px 0 #F3C4D3',
78
+ nzh: '圆角很大、字胖胖的;按钮像糖果,底下一道同色系的厚阴影;配小动物或角色插画(SVG 简单几何画);粉色和黄色两种就够,主色按钮上用深色字',
79
+ nen: 'Very round corners and chubby type; candy-like buttons with a thick same-hue shadow underneath; small animal or mascot illustrations (simple SVG shapes); pink and yellow are enough; dark text on the primary button' },
80
+ { id: 'retro', zh: '复古', en: 'Retro', dzh: '焦橙芥末黄墨绿、粗衬线、颗粒感', den: 'Burnt orange, mustard and teal, fat serif, grain',
81
+ c: { bg: '#F3E6CF', surface: '#FBF2E2', text: '#2E1F14', muted: '#6A5240', line: '#DDC7A4', primary: '#B5471D', accent: '#E0A526', on: '#FFF6E8', link: '#2F5D50' },
82
+ head: SERIF, w: 800, radius: 14, shadow: '0 4px 0 #2E1F14',
83
+ nzh: '焦橙、芥末黄、墨绿三色;粗衬线大标题;彩虹条纹、圆形徽章做装饰;底色叠一层很淡的颗粒噪点(SVG feTurbulence);图片调成褪色暖调',
84
+ nen: 'Burnt orange, mustard and teal; fat serif headlines; rainbow stripes and round badges as decoration; a very light grain over the background (SVG feTurbulence); faded warm photos' },
85
+ { id: 'sale', zh: '电商促销', en: 'Sale', dzh: '红橙主色、大价格、优惠券', den: 'Red-orange, big prices, coupons',
86
+ c: { bg: '#FFF5F0', surface: '#FFFFFF', text: '#1F1A17', muted: '#6B5E57', line: '#F5DDD2', primary: '#CF2E0E', accent: '#FFB800', on: '#FFFFFF', link: '#C2290B' },
87
+ head: SANS, w: 800, radius: 12, shadow: '0 4px 12px rgba(207,46,14,.12)',
88
+ nzh: '价格用大号粗体数字(¥ 小一号),原价灰色划线;「限时」「包邮」这类小标签用色块;优惠券用金黄色、带锯齿边;倒计时醒目;信息多但分区清楚,主按钮通栏',
89
+ nen: 'Prices in big bold numerals (smaller currency sign), old price struck through in gray; small colored tags like "Limited" and "Free shipping"; gold coupons with notched edges; a prominent countdown; dense but clearly sectioned, full-width main button' },
90
+ { id: 'japandi', zh: '日系原木', en: 'Japandi', dzh: '米色原木、低饱和、小字大留白', den: 'Oat and wood tones, muted, small type and lots of space',
91
+ c: { bg: '#F2EEE6', surface: '#FAF8F3', text: '#2F2B26', muted: '#6B645A', line: '#DDD5C8', primary: '#4F4234', accent: '#8C9A6E', on: '#FAF8F3', link: '#6B4F33' },
92
+ head: SANS, w: 500, radius: 6, shadow: '0 2px 8px rgba(79,66,52,.06)',
93
+ nzh: '像杂货店和家居品牌:字号偏小、字重不重,留白很多;颜色只有米、原木棕、灰绿,饱和度都低;照片柔光、自然材质(木、麻、陶);细线分隔,几乎不用阴影;主按钮深棕实底',
94
+ nen: 'Like a lifestyle or homeware brand: smallish, light type and lots of space; only oat, wood brown and sage, all low saturation; soft-light photos of natural materials (wood, linen, ceramic); hairline dividers, almost no shadow; solid dark-brown main button' },
95
+ { id: 'swiss', zh: '瑞士网格', en: 'Swiss grid', dzh: '白底黑字红色块、严格网格', den: 'White, black type, red blocks, strict grid',
96
+ c: { bg: '#FFFFFF', surface: '#F1F1F1', text: '#0A0A0A', muted: '#545454', line: '#0A0A0A', primary: '#D9001B', accent: '#0A0A0A', on: '#FFFFFF', link: '#C2001A' },
97
+ head: GROTESK, w: 800, radius: 0, shadow: 'none',
98
+ nzh: '12 栏严格网格、全部左对齐(不居中);标题是超大粗无衬线、字距收紧(-0.03em);红色大色块只用一两处;用数字编号(01 02 03)和粗黑线分区;没有圆角、阴影和渐变',
99
+ nen: 'A strict 12-column grid, everything left-aligned (nothing centered); huge, bold, tightly tracked sans headings (-0.03em); one or two big red blocks; numbered sections (01 02 03) and heavy black rules; no radius, shadow or gradient' },
100
+ { id: 'brutal', zh: '粗野主义', en: 'Brutalist', dzh: '亮黄底、黑粗框、硬阴影、等宽字', den: 'Bright yellow, thick black borders, hard shadows, monospace',
101
+ c: { bg: '#FFEF5C', surface: '#FFFFFF', text: '#000000', muted: '#3B3B3B', line: '#000000', primary: '#000000', accent: '#FF5C39', on: '#FFEF5C', link: '#1F3FD1' },
102
+ head: MONO, w: 800, radius: 0, shadow: '5px 5px 0 #000000',
103
+ nzh: '卡片和按钮 3px 黑粗边框 + 大偏移的硬阴影(不模糊);标题等宽字、很大;亮黄、白、橙红高饱和撞色;元素可以故意错位、叠放;不用渐变、圆角和柔和阴影;链接带下划线',
104
+ nen: '3px black borders and big unblurred offset shadows on cards and buttons; large monospace headings; loud yellow, white and red-orange blocks; deliberate offsets and overlaps are fine; no gradients, radius or soft shadows; underlined links' },
105
+ { id: 'cream', zh: '奶油风', en: 'Cream', dzh: '奶白燕麦焦糖、大圆角、柔光', den: 'Milk, oat and caramel, big radii, soft light',
106
+ c: { bg: '#FAF5EE', surface: '#FFFDF9', text: '#3A2F28', muted: '#76675C', line: '#EEE3D5', primary: '#8C5E3C', accent: '#E7C9A6', on: '#FFFFFF', link: '#8A5A36' },
107
+ head: ROUND, w: 700, radius: 22, shadow: '0 10px 30px rgba(140,94,60,.10)',
108
+ nzh: '奶白、燕麦、焦糖三个色;圆角大,多用圆形和胶囊形;阴影又大又淡、带一点暖色;字是深咖啡色不用纯黑;照片和插画柔光、低对比;整体软、暖、安静',
109
+ nen: 'Milk, oat and caramel; big radii, lots of circles and pills; large, faint, warm-tinted shadows; dark coffee text, never pure black; soft, low-contrast photos and illustrations; soft, warm and calm overall' },
110
+ { id: 'sport', zh: '运动能量', en: 'Sport', dzh: '黑底荧光绿、粗斜体、大数字', den: 'Black with volt green, heavy italics, big numbers',
111
+ c: { bg: '#0E0F11', surface: '#1A1C20', text: '#F4F5F6', muted: '#A1A5AD', line: '#2B2E35', primary: '#C8FF2E', accent: '#FF5A1F', on: '#0E0F11', link: '#C8FF2E' },
112
+ head: SANS, w: 900, radius: 6, shadow: 'none',
113
+ nzh: '标题超粗斜体、全大写、字距收紧;荧光绿只给主按钮、进度和关键数字;配速、心率、卡路里这类数字做得很大(等宽数字);可以用斜切的色块(transform: skewX(-8deg));照片高对比、有动感;橙色只做警示和次要强调',
114
+ nen: 'Heavy italic, all-caps, tightly tracked headings; volt green only on the main button, progress and key numbers; big tabular numbers for pace, heart rate and calories; slanted blocks (transform: skewX(-8deg)) are fine; high-contrast action photos; orange only for alerts and secondary emphasis' },
115
+ ]
116
+
117
+ export const AUTO_STYLE = [
118
+ ['sport', /跑步|健身|运动|赛事|马拉松|骑行|瑜伽|球馆|\b(runners?|running|fitness|gym|workouts?|sports?|marathons?|cycling|athletes?)\b/i],
119
+ ['cyber', /电音|夜店|电竞|游戏|音乐节|livehouse|酒吧|\b(game|gaming|esports?|nightclub|club|rave|festival)\b/i],
120
+ ['sale', /促销|大促|双十一|双11|618|秒杀|优惠|团购|外卖|\b(sale|deals?|coupons?|promo|black friday)\b/i],
121
+ ['tech', /后台|管理系统|仪表盘|看板|数据|金融|理财|银行|证券|\b(saas|crm|erp|dashboard|admin|analytics|finance|fintech|bank|banking|crypto|b2b|devops|api)\b/i],
122
+ ['dark', /奢|高端|珠宝|腕表|名表|红酒|威士忌|私人|黑卡|\b(luxury|premium|jewel|jewelry|jewellery|wristwatch(es)?|timepieces?|wine|whisky|concierge)\b/i],
123
+ ['cute', /儿童|幼儿|宠物|猫|狗|萌|甜品|蛋糕|玩具|\b(kids?|children|pets?|cats?|dogs?|puppy|toys?|dessert|candy)\b/i],
124
+ ['fresh', /健康|医疗|医院|诊所|户外|露营|母婴|植物|花店|有机|环保|民宿|旅行|旅游|度假|\b(health|medical|clinic|hospital|outdoor|camping|baby|plants?|florist|organic|eco|travel|trip|stays?|vacation|hotel|bnb)\b/i],
125
+ ['playful', /奶茶|果茶|饮品|饮料|社交|交友|学生|校园|潮牌|\b(bubble tea|boba|drinks?|smoothie|social|dating|students?|campus|streetwear)\b/i],
126
+ ['guochao', /春节|新年|中秋|端午|国潮|老字号|文创|庙会/],
127
+ ['retro', /咖啡|黑胶|唱片|市集|古着|理发|面包|\b(vinyl|records?|vintage|barber|bakery|coffee)\b/i],
128
+ ['glass', /音乐|播放器|天气|智能家居|\b(music|player|weather|smart home|podcast)\b/i],
129
+ ['editorial', /新闻|杂志|博客|阅读|读书|书店|媒体|播客|\b(news|magazine|blog|reading|books?|media|newsletter)\b/i],
130
+ ['swiss', /设计工作室|建筑|展览|美术馆|画廊|作品集|\b(agency|studio|architecture|exhibition|gallery|museum|portfolio)\b/i],
131
+ ]
132
+ export const AUTO_BY_KIND = { slides: 'swiss', web: 'minimal', desktop: 'tech', email: 'minimal', poster: 'playful', tablet: 'minimal' }
133
+ export const AUTO_SPREAD = ['minimal', 'editorial', 'playful', 'fresh', 'tech', 'glass', 'dark', 'sport']
134
+ // 「北欧风」「清新风:首页…」「中国风的界面」算说了风格;先去掉「通风」「台风」「新风系统」「风控」「风景」这类不是风格的词
135
+ export const NOT_STYLE_FENG = /通风|台风|新风(系统|机|量)|风险|风控|风景|风扇|风味|风暴|风光|风速|风向|风筝|风铃|风车|吹风|防风|挡风|避风|屏风|旋风|狂风|微风|寒风|疾风|顺风|逆风|作风|中风|风湿|风水/g
136
+ export const SAID_STYLE = /风格|配色|色调|主色|色系|[红橙黄绿青蓝紫粉黑白灰棕金银米]色|蓝白|黑白|黑金|红白|绿白|深色|浅色|暗色|亮色|[^\s。,,、::;;((]风|\b(style|styled|aesthetic|vibe|palette|colou?r scheme|look and feel|dark|light)\b/i
137
+ export function autoStyle(text, kind) {
138
+ const s = String(text || '')
139
+ if (!s.trim()) return null
140
+ const said = s.replace(NOT_STYLE_FENG, ' ')
141
+ if (SAID_STYLE.test(said) || STYLES.some((x) => said.includes(x.zh) || new RegExp(`\\b${x.en}\\s+(style|look|theme|aesthetic|vibe)\\b`, 'i').test(said))) return null
142
+ return topicStyle(s, kind)
143
+ }
144
+
145
+ /** 只按题材和类型挑一张,不管用户说没说风格(说没说由调工具的模型判断) */
146
+ function topicStyle(s, kind) {
147
+ const by = (id) => STYLES.find((x) => x.id === id) || null
148
+ for (const [id, re] of AUTO_STYLE) if (re.test(s)) return by(id)
149
+ if (AUTO_BY_KIND[kind]) return by(AUTO_BY_KIND[kind])
150
+ let n = 0
151
+ for (const ch of s) n = (n * 31 + ch.codePointAt(0)) >>> 0
152
+ return by(AUTO_SPREAD[n % AUTO_SPREAD.length])
153
+ }
154
+
155
+ const hexRatio = (a, b) => contrast(parseColor(a), parseColor(b))
156
+
157
+ function accentUse(c, en) {
158
+ if (Math.min(hexRatio(c.accent, c.bg), hexRatio(c.accent, c.surface)) >= 3) return en ? 'graphics and large text only' : '图形、大字'
159
+ if (hexRatio(c.text, c.accent) >= 4.5) return en ? `graphics and color blocks only, not for text; text on those blocks uses ${c.text}` : `只做图形和色块,别拿来写字;色块上的字用 ${c.text}`
160
+ return en ? 'graphics only, not for text' : '只做图形,别拿来写字'
161
+ }
162
+
163
+ /** 一张卡写成给模型看的字(和点风格卡时放进输入框的内容一样全) */
164
+ function cardText(x, en) {
165
+ const c = x.c
166
+ const bgImage = x.bgImage ? (en ? `; on the background: ${x.bgImage}` : `;底色上叠 ${x.bgImage}`) : ''
167
+ return en
168
+ ? `${x.en}: ${x.den}\nColors: background ${c.bg}, cards ${c.surface}, text ${c.text}, muted text ${c.muted}, lines ${c.line}, primary ${c.primary} (text on it ${c.on}), accent ${c.accent} (${accentUse(c, true)}), links and small emphasis ${c.link}${bgImage}\nFonts: headings ${x.head} · ${x.w}; body ${SANS}\nShape: radius ${x.radius}px; shadow ${x.shadow}\nNotes: ${x.nen}`
169
+ : `${x.zh}——${x.dzh}\n配色:底色 ${c.bg},卡片 ${c.surface},文字 ${c.text},次要文字 ${c.muted},分隔线 ${c.line},主色 ${c.primary}(上面的字 ${c.on}),点缀 ${c.accent}(${accentUse(c, false)}),链接和小字强调 ${c.link}${bgImage}\n字体:标题 ${x.head} · ${x.w};正文 ${SANS}\n形状:圆角 ${x.radius}px;阴影 ${x.shadow}\n要点:${x.nzh}`
170
+ }
171
+
172
+ const hashOf = (s) => { let n = 0; for (const ch of s) n = (n * 31 + ch.codePointAt(0)) >>> 0; return n }
173
+
174
+ /**
175
+ * 按题材挑卡。第一张和首页「风格:自动」挑的一样;要几个方向就往后从不是米色的几张里接着取。
176
+ * 用户定没定风格由模型判断:调了就给卡(自然语言猜不全,猜错了会把用户指定的配色换掉)
177
+ */
178
+ export function pickStyles(subject, kind, count = 1) {
179
+ const first = topicStyle(String(subject), kind)
180
+ const n = Math.min(3, Math.max(1, Math.floor(Number(count)) || 1))
181
+ const out = [first]
182
+ const start = hashOf(String(subject))
183
+ for (let i = 0; out.length < n && i < AUTO_SPREAD.length; i++) {
184
+ const x = STYLES.find((s) => s.id === AUTO_SPREAD[(start + i) % AUTO_SPREAD.length])
185
+ if (x && !out.includes(x)) out.push(x)
186
+ }
187
+ return out
188
+ }
189
+
190
+ /** pick_style 工具的返回文字 */
191
+ export function pickStyleText(subject, kind, count = 1) {
192
+ const en = !/[一-鿿]/.test(String(subject))
193
+ const list = pickStyles(subject, kind, count)
194
+ const cards = list.map((x, i) => (list.length > 1 ? `${en ? 'Direction' : '方向'} ${'ABC'[i]}: ` : '') + cardText(x, en)).join('\n\n')
195
+ if (list.length > 1) {
196
+ return en
197
+ ? `${cards}\n\nIf the user already chose a specific style or colors, follow them and do not use these cards. Otherwise: each direction keeps its own colors and fonts: write the variables inside that page's own <style>. Create the shared tokens.css only after the user has chosen. Do not swap them for a beige or cream look. Say briefly what style each direction is.`
198
+ : `${cards}\n\n用户已经定了具体风格或配色的话,照用户的来,不用这些卡。否则:每个方向用各自的配色和字体,变量写在各自页面的 <style> 里;用户挑定以后再建公共的 tokens.css。别换成米色、奶油底。用一两句话说清每个方向是什么风格。`
199
+ }
200
+ return en
201
+ ? `${cards}\n\nIf the user already chose a specific style or colors, follow them and do not use this card. Otherwise: put these colors and fonts into tokens.css first and build the whole set with them. Do not swap them for a beige or cream look. In your first sentence, tell the user which style you are using; it is easy to change if they do not like it.`
202
+ : `${cards}\n\n用户已经定了具体风格或配色的话,照用户的来,不用这张卡。否则:先把这些配色和字体定进 tokens.css,整套照它做,别换成米色、奶油底。第一句话告诉用户用的是哪个风格,不喜欢可以换。`
203
+ }
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、find_photos 挂给模型。
2
+ * dsh-design-studio/tool:把 preview_page、check_design、look_design、extract_design_system、handoff_design、compare_design、find_photos、pick_style 挂给模型。
3
3
  * 放在 bundle 顶层 → 所有模式都能用;放进设计模式 → 只挂在那个模式里。工具本身见 index.js
4
4
  */
5
- import { previewTool, checkTool, lookTool, systemTool, handoffTool, compareTool, photoTool } from './index.js'
5
+ import { previewTool, checkTool, lookTool, systemTool, handoffTool, compareTool, photoTool, styleTool } from './index.js'
6
6
 
7
7
  export const name = 'dsh-design-studio-tool'
8
8
  export const inject = ['tools']
@@ -16,4 +16,5 @@ export function apply(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
18
  ctx.tools.register({ ...photoTool })
19
+ ctx.tools.register({ ...styleTool })
19
20
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Business annotations (experimental)",
4
+ "description": "When on, the model also writes annotations.json with the business rules, states and edge cases the UI does not show, which takes a little longer. The sidebar gains a Notes button: numbered markers on the page, cards on the right, each locating the other. The rules are included when you turn a design into code."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "业务标注(试验)",
4
+ "description": "打开后,模型做设计时会同时写一份 annotations.json,记下界面上看不出来的业务规则、状态和边界,会多花一些时间。右侧栏多一个「业务标注」按钮:页面上出编号,右边列卡片,两边能互相定位;转成代码时带上这些规则。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-design-studio",
3
- "version": "0.16.1",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1 test/*.mjs"
@@ -28,6 +28,9 @@
28
28
  "./offline": "./lib/offline.js",
29
29
  "./offline/locale/*.json": "./locale/offline/*.json",
30
30
  "./offline/icon": "./icon.svg",
31
+ "./annotations": "./lib/annotations-row.js",
32
+ "./annotations/locale/*.json": "./locale/annotations/*.json",
33
+ "./annotations/icon": "./icon.svg",
31
34
  "./tool": "./lib/tool.js",
32
35
  "./tool/locale/*.json": "./locale/tool/*.json",
33
36
  "./tool/icon": "./icon.svg",