dsh-design-studio 0.29.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/picker.js CHANGED
@@ -429,6 +429,7 @@
429
429
  // 调样式:选中它(留虚线框),接着还能点别的
430
430
  const el = under(e.clientX, e.clientY)
431
431
  if (!el || el === document.body) return
432
+ rip(e.clientX, e.clientY)
432
433
  styleSelect(el)
433
434
  post({ type: 'stylePick', payload: { ...styleInfo(el), href: here() } })
434
435
  return
@@ -447,6 +448,7 @@
447
448
  const el = under(e.clientX, e.clientY)
448
449
  if (!el) return
449
450
  payload = { kind: 'element', ...describe(el) }
451
+ rip(e.clientX, e.clientY)
450
452
  place(el.getBoundingClientRect(), 'done')
451
453
  pin(null, el, nameOf(el))
452
454
  }
@@ -584,9 +586,12 @@
584
586
  @keyframes hl{0%{opacity:0;transform:scale(1.035)}9%{opacity:1;transform:scale(1)}78%{opacity:1}100%{opacity:0}}
585
587
  @keyframes sweep{to{transform:translateX(110%)}}
586
588
  .pin{position:absolute;pointer-events:none;border:calc(1.5px * var(--k, 1)) dashed #4d6bfe;border-radius:5px;background:rgba(77,107,254,.05);
587
- animation:pin-in .25s ease-out}
589
+ animation:pin-in .34s cubic-bezier(.3,1.4,.4,1)}
590
+ .rip{position:absolute;width:calc(36px * var(--k, 1));height:calc(36px * var(--k, 1));margin:calc(-18px * var(--k, 1)) 0 0 calc(-18px * var(--k, 1));border-radius:50%;
591
+ box-shadow:0 0 0 calc(2px * var(--k, 1)) #4d6bfe;opacity:0;pointer-events:none;animation:rip .5s cubic-bezier(.2,.8,.2,1)}
592
+ @keyframes rip{from{opacity:.75;transform:scale(.3)}to{opacity:0;transform:scale(1.5)}}
588
593
  .pin span{opacity:.92}
589
- @keyframes pin-in{from{opacity:0}}
594
+ @keyframes pin-in{from{opacity:0;transform:scale(1.12)}}
590
595
  .ck{position:absolute;pointer-events:none;border:calc(2px * var(--k, 1)) solid #f59e0b;border-radius:4px;background:rgba(245,158,11,.08)}
591
596
  .ck.hi{border-color:#e5484d;background:rgba(229,72,77,.08)}
592
597
  .ck b{position:absolute;left:calc(-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;
@@ -594,6 +599,8 @@
594
599
  transform:scale(var(--k, 1));transform-origin:0 0;box-shadow:0 2px 6px rgba(0,0,0,.25)}
595
600
  .ck.hi b{background:#e5484d}
596
601
  .ck.on{animation:ck-on 1.2s ease-out}
602
+ .ck.on b{animation:ck-pop .7s cubic-bezier(.2,.8,.2,1)}
603
+ @keyframes ck-pop{25%,75%{scale:1.3}50%{scale:1}}
597
604
  .an{position:absolute;pointer-events:none;border-radius:4px}
598
605
  .an.sel{outline:calc(2px * var(--k, 1)) solid #4d6bfe;outline-offset:calc(1px * var(--k, 1));background:rgba(77,107,254,.07)}
599
606
  .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;
@@ -608,6 +615,7 @@
608
615
  font:600 12px/18px -apple-system,BlinkMacSystemFont,system-ui,sans-serif;white-space:nowrap;transform:scale(var(--k, 1));transform-origin:0 100%}
609
616
  .cut.low b{bottom:auto;top:100%;margin:calc(3px * var(--k, 1)) 0 0;transform-origin:0 0}
610
617
  @keyframes ck-on{0%,40%{box-shadow:0 0 0 calc(6px * var(--k, 1)) rgba(229,72,77,.35)}100%{box-shadow:0 0 0 0 rgba(229,72,77,0)}}
618
+ @media (prefers-reduced-motion:reduce){.pin,.ck.on b{animation:none}.rip{display:none}}
611
619
  .scan{position:fixed;left:0;right:0;top:0;height:38vh;pointer-events:none;opacity:0;
612
620
  background:linear-gradient(180deg,rgba(77,107,254,0),rgba(77,107,254,.06) 55%,rgba(124,140,255,.22) 92%,rgba(77,107,254,0));
613
621
  animation:scan var(--dur, 1.2s) cubic-bezier(.45,0,.25,1) forwards}
@@ -667,6 +675,18 @@
667
675
  return { left: r.left + scrollX, top: r.top + scrollY, width: r.width, height: r.height }
668
676
  }
669
677
 
678
+ /** 点选落点一圈水波(选择、调样式点元素时) */
679
+ function rip(x, y) {
680
+ try { if (matchMedia('(prefers-reduced-motion: reduce)').matches) return } catch { /* 照常放 */ }
681
+ const { root } = fxRoot()
682
+ const r = document.createElement('i')
683
+ r.className = 'rip'
684
+ r.style.left = x + scrollX + 'px'
685
+ r.style.top = y + scrollY + 'px'
686
+ root.append(r)
687
+ setTimeout(() => r.remove(), 600)
688
+ }
689
+
670
690
  function flash(els) {
671
691
  const { root } = fxRoot()
672
692
  els.forEach((el, i) => {
@@ -1295,9 +1315,11 @@
1295
1315
  if (same && seed.scroll) scrollTo(seed.scroll.x, seed.scroll.y)
1296
1316
  pending = same && seed.sig ? compare(seed.sig, snapshot()) : null
1297
1317
  const meta = document.querySelector('meta[name="dsh-design"]')
1318
+ const err = document.querySelector('meta[name="dsh-error"]') // 预览服务器给的出错页(文件没了 / 开发服务器连不上)
1298
1319
  post({
1299
1320
  type: 'ready',
1300
1321
  title: document.title,
1322
+ err: err ? String(err.getAttribute('content') || 'missing').slice(0, 20) : '',
1301
1323
  href: here(),
1302
1324
  meta: meta ? String(meta.getAttribute('content') || '').slice(0, 80) : '',
1303
1325
  tokens: tokensOf(),
@@ -1614,6 +1636,12 @@
1614
1636
  let textEdit = false
1615
1637
  let editUi = null
1616
1638
  let editing = null // { span, node, before, nth }
1639
+ let editLang = 'zh'
1640
+ // 正在改的那段字上面的小标签:什么字 · 字号 / 粗细(和右侧栏灵动条上的按键提示一起看)
1641
+ const ED_TX = {
1642
+ zh: { h: '标题', p: '正文', button: '按钮', a: '链接', label: '标签', li: '列表', text: '文字', w7: '粗', w5: '中', w4: '常规' },
1643
+ en: { h: 'Heading', p: 'Body', button: 'Button', a: 'Link', label: 'Label', li: 'List', text: 'Text', w7: 'Bold', w5: 'Medium', w4: 'Regular' },
1644
+ }
1617
1645
 
1618
1646
  function countIn(hay, needle) {
1619
1647
  if (!needle) return 0
@@ -1661,11 +1689,16 @@
1661
1689
  hostEl.style.setProperty('--k', K)
1662
1690
  const root = hostEl.attachShadow({ mode: 'closed' })
1663
1691
  root.innerHTML = `<style>:host{all:initial}
1664
- .box{position:fixed;z-index:2147483646;pointer-events:none;display:none;border-radius:3px;border:calc(1.5px * var(--k, 1)) dashed #4d6bfe;background:rgba(77,107,254,.06)}
1692
+ .box{position:fixed;z-index:2147483646;pointer-events:none;display:none;border-radius:3px;border:calc(1.5px * var(--k, 1)) dashed #4fa8ff;background:rgba(79,168,255,.07)}
1693
+ .tag{position:fixed;z-index:2147483647;pointer-events:none;display:none;align-items:center;gap:4px;height:18px;padding:0 7px 0 5px;border-radius:6px;transform:translateY(-100%) scale(var(--k, 1));transform-origin:0 100%;
1694
+ background:linear-gradient(100deg,#a594ff,#5ec8f2 55%,#67e0c3);color:#0b1020;font:600 11px/18px -apple-system,system-ui,sans-serif;white-space:nowrap;box-shadow:0 4px 14px rgba(40,90,200,.28);animation:tg .22s cubic-bezier(.2,.8,.2,1) both}
1695
+ .tag svg{width:11px;height:11px}
1696
+ @keyframes tg{from{opacity:0;transform:translateY(calc(-100% + 4px)) scale(var(--k, 1))}}
1697
+ @media (prefers-reduced-motion:reduce){.tag{animation:none}}
1665
1698
  .hint{position:fixed;left:50%;top:10px;transform:translateX(-50%) scale(var(--k, 1));transform-origin:50% 0;z-index:2147483647;pointer-events:none;padding:6px 12px;border-radius:999px;
1666
1699
  background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-ui,sans-serif;white-space:nowrap;box-shadow:0 4px 16px rgba(0,0,0,.25)}</style>
1667
- <div class="box"></div><div class="hint">点文字直接改 · 回车保存 · Esc 退出</div>`
1668
- editUi = { host: hostEl, box: root.querySelector('.box'), hint: root.querySelector('.hint') }
1700
+ <div class="box"></div><div class="tag"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"><path d="M5 6h14M12 6v13"/></svg><span></span></div><div class="hint">点文字直接改 · 回车保存 · Esc 退出</div>`
1701
+ editUi = { host: hostEl, box: root.querySelector('.box'), hint: root.querySelector('.hint'), tag: root.querySelector('.tag') }
1669
1702
  if (!hint) editUi.hint.style.display = 'none'
1670
1703
  document.documentElement.appendChild(hostEl)
1671
1704
  }
@@ -1684,6 +1717,23 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1684
1717
  Object.assign(editUi.box.style, { display: 'block', left: r.left - 3 + 'px', top: r.top - 2 + 'px', width: r.width + 6 + 'px', height: r.height + 4 + 'px' })
1685
1718
  }
1686
1719
 
1720
+ /** 正在改的字上面挂标签(span 为空就收起);滚动时跟着挪 */
1721
+ function editTag(span) {
1722
+ if (!editUi) return
1723
+ const tg = editUi.tag
1724
+ if (!span || !span.isConnected) { tg.style.display = 'none'; return }
1725
+ const el = span.parentElement || span
1726
+ const tx = ED_TX[editLang] || ED_TX.zh
1727
+ const tn = el.closest('h1,h2,h3,h4,h5,h6,button,a,label,li,p')
1728
+ const kind = !tn ? tx.text : /^H\d$/.test(tn.tagName) ? tx.h : tx[tn.tagName.toLowerCase()] || tx.text
1729
+ const cs = getComputedStyle(el)
1730
+ const w = parseInt(cs.fontWeight, 10) || 400
1731
+ tg.querySelector('span').textContent = `${kind} · ${Math.round(parseFloat(cs.fontSize) || 0)} / ${w >= 600 ? tx.w7 : w >= 500 ? tx.w5 : tx.w4}`
1732
+ const r = span.getBoundingClientRect()
1733
+ Object.assign(tg.style, { display: 'flex', left: Math.max(2, r.left - 3) + 'px', top: Math.max(20 * K, r.top - 5) + 'px' })
1734
+ }
1735
+ function onEditScroll() { if (editing) editTag(editing.span) }
1736
+
1687
1737
  function onEditMove(e) {
1688
1738
  if (!textEdit || editing) return
1689
1739
  editBox(textAt(e.clientX, e.clientY))
@@ -1704,7 +1754,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1704
1754
  const nth = nthOf(node, before)
1705
1755
  const span = document.createElement('span')
1706
1756
  span.setAttribute('data-dsh-edit', '')
1707
- span.style.cssText = 'outline:calc(2px * var(--dsh-k, 1)) solid #4d6bfe;outline-offset:2px;border-radius:2px;cursor:text;caret-color:#4d6bfe'
1757
+ span.style.cssText = 'outline:calc(1.5px * var(--dsh-k, 1)) solid #4fa8ff;outline-offset:3px;border-radius:3px;cursor:text;caret-color:#4fa8ff;box-shadow:0 0 0 calc(5px * var(--dsh-k, 1)) rgba(79,168,255,.14)'
1708
1758
  span.style.setProperty('--dsh-k', K)
1709
1759
  try { span.contentEditable = 'plaintext-only' } catch { span.contentEditable = 'true' }
1710
1760
  if (span.contentEditable !== 'plaintext-only') span.contentEditable = 'true'
@@ -1712,6 +1762,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1712
1762
  span.appendChild(node)
1713
1763
  editing = { span, node, before, nth, raw: node.data }
1714
1764
  editBox(null)
1765
+ editTag(span)
1766
+ post({ type: 'editing', on: true })
1715
1767
  span.focus()
1716
1768
  const sel = getSelection()
1717
1769
  const range = document.createRange()
@@ -1726,6 +1778,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1726
1778
  const ed = editing
1727
1779
  if (!ed) return
1728
1780
  editing = null
1781
+ editTag(null)
1782
+ post({ type: 'editing', on: false })
1729
1783
  const after = normWs(ed.span.innerText)
1730
1784
  const text = document.createTextNode(save && after ? ed.raw.replace(ed.raw.trim(), after) : ed.raw)
1731
1785
  if (ed.span.parentNode) ed.span.parentNode.replaceChild(text, ed.span)
@@ -1734,6 +1788,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1734
1788
 
1735
1789
  function onEditKey(e) {
1736
1790
  if (!textEdit) return
1791
+ if (e.isComposing || e.keyCode === 229) return // 输入法还在选字:回车选词、Esc 取消组字都归输入法,别提前保存 / 丢掉这次改字
1737
1792
  if (editing) {
1738
1793
  if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); finishEdit(true) }
1739
1794
  else if (e.key === 'Escape') { e.preventDefault(); finishEdit(false) }
@@ -1742,7 +1797,8 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1742
1797
  if (e.key === 'Escape') { e.preventDefault(); post({ type: 'editDone' }) }
1743
1798
  }
1744
1799
 
1745
- function setTextEdit(on, hint = true) {
1800
+ function setTextEdit(on, hint = true, lang) {
1801
+ if (lang) editLang = lang === 'en' ? 'en' : 'zh'
1746
1802
  if (on === textEdit) return
1747
1803
  if (on && styleOn) setStyleMode(false)
1748
1804
  textEdit = on
@@ -1752,12 +1808,14 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
1752
1808
  addEventListener('mousemove', onEditMove, true)
1753
1809
  addEventListener('click', onEditClick, true)
1754
1810
  addEventListener('keydown', onEditKey, true)
1811
+ addEventListener('scroll', onEditScroll, true)
1755
1812
  } else {
1756
1813
  finishEdit(true)
1757
1814
  document.documentElement.style.removeProperty('cursor')
1758
1815
  removeEventListener('mousemove', onEditMove, true)
1759
1816
  removeEventListener('click', onEditClick, true)
1760
1817
  removeEventListener('keydown', onEditKey, true)
1818
+ removeEventListener('scroll', onEditScroll, true)
1761
1819
  editUnmount()
1762
1820
  }
1763
1821
  }
@@ -5557,7 +5615,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
5557
5615
  else if (d.type === 'annotHit') hitAnnot(Number(d.x), Number(d.y))
5558
5616
  else if (d.type === 'theme') { setDark(d.dark); postTop(); setTimeout(postTop, 400) }
5559
5617
  else if (d.type === 'demo') demo = !!d.on
5560
- else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false)
5618
+ else if (d.type === 'edit') setTextEdit(!!d.on, d.hint !== false, d.lang)
5561
5619
  else if (d.type === 'styleMode') setStyleMode(!!d.on)
5562
5620
  else if (d.type === 'styleSel') onStyleSel(d.selector)
5563
5621
  else if (d.type === 'style') { styleApply(d.css); queueTop() }
package/lib/serve.js CHANGED
@@ -185,8 +185,9 @@ function send(res, code, body, headers = {}) {
185
185
  res.end(body)
186
186
  }
187
187
 
188
- function errorPage(title, detail, retry) {
189
- return injectPicker(`<!doctype html><html><head><meta charset="utf-8">${retry ? '<meta http-equiv="refresh" content="2">' : ''}
188
+ // code:missing(文件没了)/ down(开发服务器连不上);页面里的设计台脚本报给右侧栏,那一屏换成出错卡(重试 / 让模型改)
189
+ function errorPage(title, detail, retry, code) {
190
+ return injectPicker(`<!doctype html><html><head><meta charset="utf-8"><meta name="dsh-error" content="${code || 'missing'}">${retry ? '<meta http-equiv="refresh" content="2">' : ''}
190
191
  <title>${title}</title><style>
191
192
  html,body{height:100%;margin:0}body{display:flex;align-items:center;justify-content:center;font:14px/1.6 -apple-system,system-ui,sans-serif;color:#8a8f98;background:transparent}
192
193
  div{text-align:center;max-width:360px;padding:24px}b{display:block;color:#c9ccd2;font-weight:500;margin-bottom:4px}
@@ -458,7 +459,7 @@ export function createHub({ log = () => {}, onChange = () => {}, onWatch = () =>
458
459
  }
459
460
  }
460
461
  if (!file) {
461
- const html = errorPage('找不到这个文件', String(pathname).replace(/[<>&]/g, ''), false)
462
+ const html = errorPage('找不到这个文件', String(pathname).replace(/[<>&]/g, ''), false, 'missing')
462
463
  return send(res, 404, html, { 'Content-Type': 'text/html; charset=utf-8' })
463
464
  }
464
465
  const ext = path.extname(file).toLowerCase()
@@ -642,7 +643,7 @@ export function createHub({ log = () => {}, onChange = () => {}, onWatch = () =>
642
643
  if (gone) return
643
644
  entry.upHost = ''
644
645
  if (res.headersSent) return res.destroy()
645
- const html = errorPage(`连不上 localhost:${entry.port}`, '开发服务器可能还没启动,起来后这里会自动刷新。', true)
646
+ const html = errorPage(`连不上 localhost:${entry.port}`, '开发服务器可能还没启动,起来后这里会自动刷新。', true, 'down')
646
647
  send(res, 502, html, { 'Content-Type': 'text/html; charset=utf-8' })
647
648
  })
648
649
  req.pipe(up)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-design-studio",
3
- "version": "0.29.0",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1 test/*.mjs"