dsh-design-studio 0.28.0 → 0.29.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 +2 -2
- package/README.md +2 -2
- package/cordis.patch.yml +1 -1
- package/lib/client.js +212 -53
- package/lib/core.js +346 -28
- package/lib/edits.js +69 -0
- package/lib/handoff.js +19 -4
- package/lib/htmlpack.js +1 -1
- package/lib/index.js +177 -21
- package/lib/picker.js +48 -3
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +1 -1
package/lib/core.js
CHANGED
|
@@ -81,6 +81,26 @@ export function listScreens(root, keep = '') {
|
|
|
81
81
|
return inManifestOrder(root, kept)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* 导出用的全部屏(#29):右侧栏显示的(拖过顺序的照拖过的)+ 收起来的,照全部屏的顺序(order:设计清单 / 生成先后)把收起来的插回原位,
|
|
86
|
+
* 打开的是最早那屏(index)时它还排第一。不在 order 里的收起来的接在最后;同一屏只出一次
|
|
87
|
+
*/
|
|
88
|
+
export function exportOrder(shown, hidden, order) {
|
|
89
|
+
const rank = new Map((order || []).map((k, i) => [k, i]))
|
|
90
|
+
const hid = [...new Set(hidden || [])]
|
|
91
|
+
const out = []
|
|
92
|
+
const seen = new Set()
|
|
93
|
+
const put = (k) => { if (!seen.has(k)) { seen.add(k); out.push(k) } }
|
|
94
|
+
let j = 0
|
|
95
|
+
for (const k of shown || []) {
|
|
96
|
+
const r = rank.get(k)
|
|
97
|
+
if (r !== undefined) while (j < hid.length && (rank.has(hid[j]) ? rank.get(hid[j]) : Infinity) < r) put(hid[j++])
|
|
98
|
+
put(k)
|
|
99
|
+
}
|
|
100
|
+
while (j < hid.length) put(hid[j++])
|
|
101
|
+
return out
|
|
102
|
+
}
|
|
103
|
+
|
|
84
104
|
/** 目录里所有的屏。按文件名找、改全套的时候用这个,别漏掉收起来的 */
|
|
85
105
|
export function allScreens(root) {
|
|
86
106
|
return inManifestOrder(root, screensByBirth(root))
|
|
@@ -400,12 +420,7 @@ function splitDecls(s) {
|
|
|
400
420
|
* 写 background 时去掉 background-color / -image(不然前后打架)。自定义属性(--x)区分大小写,原样留着。
|
|
401
421
|
*/
|
|
402
422
|
export function mergeStyle(style, css) {
|
|
403
|
-
const decls =
|
|
404
|
-
const i = d.indexOf(':')
|
|
405
|
-
if (i <= 0) return null
|
|
406
|
-
const p = d.slice(0, i).trim()
|
|
407
|
-
return [p.startsWith('--') ? p : p.toLowerCase(), d.slice(i + 1).trim()]
|
|
408
|
-
}).filter(Boolean)
|
|
423
|
+
const decls = declsOf(style)
|
|
409
424
|
for (const [k, v] of Object.entries(css || {})) {
|
|
410
425
|
const prop = k.toLowerCase()
|
|
411
426
|
if (prop === 'background') for (let i = decls.length - 1; i >= 0; i--) if (/^background-(color|image)$/.test(decls[i][0])) decls.splice(i, 1)
|
|
@@ -446,9 +461,18 @@ const normSel = (s) => String(s || '').replace(/["']/g, '').replace(/::/g, ':').
|
|
|
446
461
|
* n:同样选择器的第几条(源码顺序,@media 里的也算)。找不到给 0
|
|
447
462
|
*/
|
|
448
463
|
export function findRule(text, sel, n = 0) {
|
|
464
|
+
const r = ruleAt(text, sel, n)
|
|
465
|
+
return r ? r.src.slice(0, r.at).split('\n').length : 0
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** 注释换成空格(位置、行号不变),找规则、拆声明时用它,改的时候照位置改原文 */
|
|
469
|
+
const blankComments = (text) => String(text || '').replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '))
|
|
470
|
+
|
|
471
|
+
/** 第 n 条选择器是 sel 的规则:{ at: 选择器开头, brace: 「{」的位置, src: 去掉注释的全文 };找不到给 null */
|
|
472
|
+
function ruleAt(text, sel, n = 0) {
|
|
449
473
|
const want = normSel(sel)
|
|
450
|
-
if (!want || want.length > 400) return
|
|
451
|
-
const src =
|
|
474
|
+
if (!want || want.length > 400) return null
|
|
475
|
+
const src = blankComments(text)
|
|
452
476
|
// HTML 只看 <style> 里面(脚本、正文里像 CSS 的字不算)
|
|
453
477
|
const regions = []
|
|
454
478
|
if (/<style\b/i.test(src)) {
|
|
@@ -464,6 +488,8 @@ export function findRule(text, sel, n = 0) {
|
|
|
464
488
|
let k = 0
|
|
465
489
|
for (const [from, to] of regions) {
|
|
466
490
|
let start = from
|
|
491
|
+
// 外面套着的是 @规则(@media、@layer…,里面的照常数)还是样式规则(.dark { .btn {} } 这种嵌套的:右侧栏不数,这里也不数,不然第 n 条对不上、改错规则)
|
|
492
|
+
const stack = []
|
|
467
493
|
for (let i = from; i < to; i++) {
|
|
468
494
|
const ch = src[i]
|
|
469
495
|
if (ch === '"' || ch === "'") { // 字符串里的 { } ; 不算
|
|
@@ -472,34 +498,241 @@ export function findRule(text, sel, n = 0) {
|
|
|
472
498
|
i = j
|
|
473
499
|
} else if (ch === '{') {
|
|
474
500
|
const pre = src.slice(start, i)
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
}
|
|
501
|
+
const at = pre.trimStart().startsWith('@')
|
|
502
|
+
if (!at && !stack.includes('s') && normSel(pre) === want && k++ === n) return { at: start + (pre.length - pre.trimStart().length), brace: i, src }
|
|
503
|
+
stack.push(at ? 'a' : 's')
|
|
479
504
|
start = i + 1
|
|
480
|
-
} else if (ch === '}'
|
|
505
|
+
} else if (ch === '}') { stack.pop(); start = i + 1 } else if (ch === ';') start = i + 1
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return null
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** 从 i(引号)跳到字符串结尾 */
|
|
512
|
+
function skipString(src, i, to) {
|
|
513
|
+
const q = src[i]
|
|
514
|
+
let j = i + 1
|
|
515
|
+
while (j < to && src[j] !== q && src[j] !== '\n') j += src[j] === '\\' ? 2 : 1
|
|
516
|
+
return j
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** 从「{」跳到配对的「}」;没配上给 -1 */
|
|
520
|
+
function closeOf(src, brace) {
|
|
521
|
+
let depth = 0
|
|
522
|
+
for (let i = brace; i < src.length; i++) {
|
|
523
|
+
const ch = src[i]
|
|
524
|
+
if (ch === '"' || ch === "'") i = skipString(src, i, src.length)
|
|
525
|
+
else if (ch === '{') depth++
|
|
526
|
+
else if (ch === '}' && !--depth) return i
|
|
527
|
+
}
|
|
528
|
+
return -1
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** 写 background 时一起去掉的(和 mergeStyle 一样:不然前后打架) */
|
|
532
|
+
const killsOf = (props) => new Set(props.flatMap((p) => (p === 'background' ? ['background', 'background-color', 'background-image'] : [p])))
|
|
533
|
+
|
|
534
|
+
/** 行内 style 写了这些,就会盖过样式表里的 p(简写、分写都算) */
|
|
535
|
+
const CORNERS = ['border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius']
|
|
536
|
+
const OVERRIDERS = {
|
|
537
|
+
background: ['background', 'background-color', 'background-image'],
|
|
538
|
+
'font-size': ['font-size', 'font'],
|
|
539
|
+
'font-weight': ['font-weight', 'font'],
|
|
540
|
+
'border-radius': ['border-radius', ...CORNERS],
|
|
541
|
+
gap: ['gap', 'grid-gap', 'row-gap', 'column-gap', 'grid-row-gap', 'grid-column-gap'],
|
|
542
|
+
'padding-top': ['padding-top', 'padding', 'padding-block', 'padding-block-start'],
|
|
543
|
+
'padding-right': ['padding-right', 'padding', 'padding-inline', 'padding-inline-end'],
|
|
544
|
+
'padding-bottom': ['padding-bottom', 'padding', 'padding-block', 'padding-block-end'],
|
|
545
|
+
'padding-left': ['padding-left', 'padding', 'padding-inline', 'padding-inline-start'],
|
|
546
|
+
}
|
|
547
|
+
/** 逻辑内边距(跟书写方向走):拆不准,行内写了就别改共用规则 */
|
|
548
|
+
const LOGICAL_PAD = /^padding-(block|inline)(-start|-end)?$/
|
|
549
|
+
const overridersOf = (props) => new Set(props.flatMap((p) => OVERRIDERS[p] || [p]))
|
|
550
|
+
|
|
551
|
+
/** padding 简写拆成上右下左四个值(括号里的空格不拆);用了 var()/env()、个数不对:null(拆不准) */
|
|
552
|
+
function expandBox(v) {
|
|
553
|
+
let s = String(v || '').trim()
|
|
554
|
+
const imp = /!\s*important\s*$/i.test(s)
|
|
555
|
+
if (imp) s = s.replace(/!\s*important\s*$/i, '').trim()
|
|
556
|
+
if (/\b(var|env|attr)\s*\(/i.test(s)) return null
|
|
557
|
+
const t = []
|
|
558
|
+
let depth = 0
|
|
559
|
+
let cur = ''
|
|
560
|
+
for (const ch of s) {
|
|
561
|
+
if (ch === '(') depth++
|
|
562
|
+
else if (ch === ')') depth = Math.max(0, depth - 1)
|
|
563
|
+
if (/\s/.test(ch) && !depth) { if (cur) t.push(cur); cur = '' } else cur += ch
|
|
564
|
+
}
|
|
565
|
+
if (cur) t.push(cur)
|
|
566
|
+
if (t.length < 1 || t.length > 4) return null
|
|
567
|
+
const [a, b = a, c = a, d = b] = t
|
|
568
|
+
return [a, b, c, d].map((x) => (imp ? `${x} !important` : x))
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** 拆好的行内 style:[[属性, 值], …](属性小写,--x 原样) */
|
|
572
|
+
const declsOf = (style) => splitDecls(String(style || '')).map((d) => {
|
|
573
|
+
const i = d.indexOf(':')
|
|
574
|
+
if (i <= 0) return null
|
|
575
|
+
const p = d.slice(0, i).trim()
|
|
576
|
+
return [p.startsWith('--') ? p : p.toLowerCase(), d.slice(i + 1).trim()]
|
|
577
|
+
}).filter(Boolean)
|
|
578
|
+
|
|
579
|
+
/** 把新的 style 文字(已解开实体)写回 x 这个开头标签;空的就去掉 style 属性 */
|
|
580
|
+
function putStyle(html, x, a, style) {
|
|
581
|
+
const next = String(style || '').replace(/&/g, '&').replace(/"/g, '"')
|
|
582
|
+
let attrs
|
|
583
|
+
if (a) attrs = (next ? x.attrs.slice(0, a.at) + `style="${next}"` : x.attrs.slice(0, a.at).replace(/\s+$/, '')) + x.attrs.slice(a.at + a.len)
|
|
584
|
+
// 自闭合的 / 前面得是空白或引号(src=a.png/ 里的 / 是属性值的一部分)
|
|
585
|
+
else if (next) attrs = /(^|["'\s])\/\s*$/.test(x.attrs) ? x.attrs.replace(/\s*\/\s*$/, ` style="${next}" /`) : x.attrs + ` style="${next}"`
|
|
586
|
+
else attrs = x.attrs
|
|
587
|
+
return html.slice(0, x.start) + `<${x.name}${attrs}>` + html.slice(x.end)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* 共用规则改了 props 以后,页面上那个元素(loc,见 findTag)行内 style 里会盖过它的都去掉(见 OVERRIDERS),不然改了规则这里看着没变。
|
|
592
|
+
* 行内 padding 简写只改了其中几边:拆成四边,只去掉改了的那几边,别的边照旧。
|
|
593
|
+
* 拆不了(简写里用了 var()、个数不对),或行内写了 font 简写又改了字号 / 粗细:{ ok: false, reason: 'inline' },调用方别改共用规则(改了这里也看不出变化)。
|
|
594
|
+
* 找不到元素、行内没写:原样给回。
|
|
595
|
+
* @returns {{ ok: true, html } | { ok: false, reason: 'inline' }}
|
|
596
|
+
*/
|
|
597
|
+
export function clearInline(html, loc, props) {
|
|
598
|
+
const x = findTag(html, loc || {})
|
|
599
|
+
const a = x && attrsOf(x.attrs).style
|
|
600
|
+
if (!a) return { ok: true, html }
|
|
601
|
+
const style = unAttr(a.v)
|
|
602
|
+
const decls = declsOf(style)
|
|
603
|
+
const has = (p) => decls.some(([q]) => q === p)
|
|
604
|
+
const list = (Array.isArray(props) ? props : []).map((p) => String(p).toLowerCase())
|
|
605
|
+
if (list.some((p) => p === 'font-size' || p === 'font-weight') && has('font')) return { ok: false, reason: 'inline' }
|
|
606
|
+
if (list.some((p) => p.startsWith('padding-')) && decls.some(([q]) => LOGICAL_PAD.test(q))) return { ok: false, reason: 'inline' }
|
|
607
|
+
const css = {}
|
|
608
|
+
const sides = ['top', 'right', 'bottom', 'left']
|
|
609
|
+
const changed = sides.filter((s) => list.includes(`padding-${s}`))
|
|
610
|
+
if (changed.length && has('padding')) {
|
|
611
|
+
// 照先后算出每一边实际的值(后写的赢),简写拆掉、没改的那几边写成分写
|
|
612
|
+
// 带 !important 的不让后面不带的盖掉(padding: 8px !important; padding-top: 2px → 上边还是 8px)
|
|
613
|
+
const eff = {}
|
|
614
|
+
const imp = (v) => /!\s*important\s*$/i.test(v)
|
|
615
|
+
const take = (side, v) => { if (eff[side] && imp(eff[side]) && !imp(v)) return; eff[side] = v }
|
|
616
|
+
for (const [p, v] of decls) {
|
|
617
|
+
if (p === 'padding') { const four = expandBox(v); if (!four) return { ok: false, reason: 'inline' }; sides.forEach((s, i) => take(s, four[i])) }
|
|
618
|
+
else if (/^padding-(top|right|bottom|left)$/.test(p)) take(p.slice(8), v)
|
|
481
619
|
}
|
|
620
|
+
css.padding = ''
|
|
621
|
+
for (const s of sides) css[`padding-${s}`] = changed.includes(s) ? '' : eff[s] || ''
|
|
482
622
|
}
|
|
483
|
-
|
|
623
|
+
for (const q of overridersOf(list)) if (q !== 'padding' && q !== 'font' && !(q in css)) css[q] = ''
|
|
624
|
+
const next = mergeStyle(style, css)
|
|
625
|
+
if (next === mergeStyle(style, {})) return { ok: true, html }
|
|
626
|
+
return { ok: true, html: putStyle(html, x, a, next) }
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* 把 css(调样式面板那几项)写进样式表里第 n 条选择器是 sel 的规则:这条规则里同名的先删掉(写 background 时连 background-color / -image),
|
|
631
|
+
* 新的放在规则最后(同一条规则里后写的赢)。原来那条带 !important 的,新的也带上。嵌套的子规则(&:hover {…})、注释、字符串里的 ; { } 都不动;
|
|
632
|
+
* 缩进、换行(CRLF)照这条规则原来的样子。
|
|
633
|
+
* @returns {{ ok: true, text } | { ok: false, reason: 'empty' | 'not-found' }}
|
|
634
|
+
*/
|
|
635
|
+
export function setRuleProps(text, sel, n, css) {
|
|
636
|
+
const clean = cleanCss(css)
|
|
637
|
+
if (!clean) return { ok: false, reason: 'empty' }
|
|
638
|
+
const orig = String(text || '')
|
|
639
|
+
const r = ruleAt(orig, sel, Math.max(0, Math.floor(Number(n) || 0)))
|
|
640
|
+
if (!r) return { ok: false, reason: 'not-found' }
|
|
641
|
+
const { src, brace } = r
|
|
642
|
+
const close = closeOf(src, brace)
|
|
643
|
+
if (close < 0) return { ok: false, reason: 'not-found' }
|
|
644
|
+
const kills = killsOf(Object.keys(clean))
|
|
645
|
+
// 这条规则里顶层的一段段:声明(含结尾的 ;,和它前面的空白)/ 嵌套的子规则
|
|
646
|
+
const segs = []
|
|
647
|
+
let start = brace + 1
|
|
648
|
+
let depth = 0
|
|
649
|
+
for (let i = brace + 1; i < close; i++) {
|
|
650
|
+
const ch = src[i]
|
|
651
|
+
if (ch === '"' || ch === "'") { i = skipString(src, i, close); continue }
|
|
652
|
+
if (ch === '(') depth++
|
|
653
|
+
else if (ch === ')') depth = Math.max(0, depth - 1)
|
|
654
|
+
else if (ch === ';' && !depth) { segs.push({ s: start, e: i + 1, semi: true }); start = i + 1 }
|
|
655
|
+
else if (ch === '{' && !depth) { const c = closeOf(src, i); if (c < 0 || c > close) return { ok: false, reason: 'not-found' }; segs.push({ s: start, e: c + 1, nested: true }); i = c; start = c + 1 }
|
|
656
|
+
}
|
|
657
|
+
// 最后一条没写分号:它后面的空白(「}」前的换行)留给 tail
|
|
658
|
+
let tail = start
|
|
659
|
+
if (src.slice(start, close).trim()) { tail = start + src.slice(start, close).trimEnd().length; segs.push({ s: start, e: tail, semi: false }) }
|
|
660
|
+
// 这条规则里会盖过新写的那项的(同名的、简写:padding 盖 padding-left、font 盖 font-size……)带 !important:新的那项也带上,不然白写
|
|
661
|
+
const important = new Set()
|
|
662
|
+
let indent = ''
|
|
663
|
+
let multi = false
|
|
664
|
+
const kept = []
|
|
665
|
+
for (const g of segs) {
|
|
666
|
+
if (g.nested) { kept.push(g); continue }
|
|
667
|
+
const body = src.slice(g.s, g.e)
|
|
668
|
+
if (!indent) { const m = /\n([ \t]*)\S/.exec(body); if (m) { indent = m[1]; multi = true } }
|
|
669
|
+
const i = body.indexOf(':')
|
|
670
|
+
const prop = i > 0 ? body.slice(0, i).trim().toLowerCase() : ''
|
|
671
|
+
if (prop && /!\s*important/i.test(body)) for (const p of Object.keys(clean)) if (overridersOf([p]).has(prop) || killsOf([p]).has(prop)) important.add(p)
|
|
672
|
+
if (prop && kills.has(prop)) continue
|
|
673
|
+
kept.push(g)
|
|
674
|
+
}
|
|
675
|
+
const eol = orig.includes('\r\n') ? '\r\n' : '\n'
|
|
676
|
+
if (!multi && /\n/.test(src.slice(brace + 1, close))) { multi = true; indent = ' ' }
|
|
677
|
+
let out = orig.slice(0, brace + 1)
|
|
678
|
+
let last = null
|
|
679
|
+
for (const g of kept) { out += orig.slice(g.s, g.e); last = g }
|
|
680
|
+
if (last && !last.nested && !last.semi) out += ';'
|
|
681
|
+
const decls = Object.entries(clean).filter(([, v]) => v).map(([p, v]) => `${p}: ${v}${important.has(p) ? ' !important' : ''};`)
|
|
682
|
+
// 最后一段和「}」之间:注释照原样留着,新的写在注释后面、「}」前的空白前面
|
|
683
|
+
const mid = orig.slice(tail, close)
|
|
684
|
+
const ws = mid.slice(mid.trimEnd().length)
|
|
685
|
+
out += mid.slice(0, mid.length - ws.length)
|
|
686
|
+
out += multi ? decls.map((d) => `${eol}${indent}${d}`).join('') : ' ' + decls.join(' ')
|
|
687
|
+
out += multi ? (/\n/.test(ws) ? ws : eol) : (ws || ' ')
|
|
688
|
+
out += orig.slice(close)
|
|
689
|
+
return { ok: true, text: out, imp: [...important] }
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/** 像状态的 class(is-active、on、selected……):比「是不是同一种元素」时不算(和 picker 的 STATE_CLS 一字不差) */
|
|
693
|
+
const STATE_CLS = /^(is-|has-)|^(active|on|sel|selected|current|hidden|show|open|disabled|checked|focus|hover)$/
|
|
694
|
+
|
|
695
|
+
/** 这份 HTML 里带 class cls 的元素各是哪种:「标签大写|去掉状态 class 后排好的 class」,和 picker 的 sharedOf 一样算 */
|
|
696
|
+
export function classSigs(html, cls) {
|
|
697
|
+
const out = new Set()
|
|
698
|
+
if (!cls) return out
|
|
699
|
+
for (const m of String(html || '').matchAll(/<([a-z][a-z0-9-]*)\b([^>]*)>/gi)) {
|
|
700
|
+
const a = attrsOf(m[2])
|
|
701
|
+
if (!a.class) continue
|
|
702
|
+
const list = [...new Set(unAttr(a.class.v).split(/\s+/).filter(Boolean))]
|
|
703
|
+
if (!list.includes(cls)) continue
|
|
704
|
+
out.add(m[1].toUpperCase() + '|' + list.filter((c) => !STATE_CLS.test(c)).sort().join(' '))
|
|
705
|
+
}
|
|
706
|
+
return out
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/** 这份 HTML 里有几个元素带着 class cls、行内 style 又写了 props 里的哪一项(之前「直接保存」写的,盖过样式表) */
|
|
710
|
+
export function inlineOverrides(html, cls, props) {
|
|
711
|
+
if (!cls) return 0
|
|
712
|
+
const kills = overridersOf(props)
|
|
713
|
+
let n = 0
|
|
714
|
+
for (const m of String(html || '').matchAll(/<[a-z][a-z0-9-]*\b([^>]*)>/gi)) {
|
|
715
|
+
const a = attrsOf(m[1])
|
|
716
|
+
if (!a.class || !a.style || !unAttr(a.class.v).split(/\s+/).includes(cls)) continue
|
|
717
|
+
if (splitDecls(unAttr(a.style.v)).some((d) => kills.has(d.slice(0, d.indexOf(':')).trim().toLowerCase()))) n++
|
|
718
|
+
}
|
|
719
|
+
return n
|
|
484
720
|
}
|
|
485
721
|
|
|
486
722
|
/**
|
|
487
723
|
* 把 css 写进页面上那个元素(loc,见 findTag)在源码里的 style 属性。
|
|
488
724
|
* @returns {{ ok: true, html } | { ok: false, reason: 'empty' | 'not-found' }}
|
|
489
725
|
*/
|
|
490
|
-
export function setStyle(html, loc, css) {
|
|
726
|
+
export function setStyle(html, loc, css, imp = []) {
|
|
491
727
|
const clean = cleanCss(css)
|
|
492
728
|
if (!clean) return { ok: false, reason: 'empty' }
|
|
493
729
|
const x = findTag(html, loc)
|
|
494
730
|
if (!x) return { ok: false, reason: 'not-found' }
|
|
495
731
|
const a = attrsOf(x.attrs).style
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
else if (next) attrs = /(^|["'\s])\/\s*$/.test(x.attrs) ? x.attrs.replace(/\s*\/\s*$/, ` style="${next}" /`) : x.attrs + ` style="${next}"`
|
|
501
|
-
else attrs = x.attrs
|
|
502
|
-
return { ok: true, html: html.slice(0, x.start) + `<${x.name}${attrs}>` + html.slice(x.end) }
|
|
732
|
+
// imp:盖着它的规则带 !important 的那几项,行内也带上(不然白写)
|
|
733
|
+
const hi = new Set(Array.isArray(imp) ? imp.map((p) => String(p).toLowerCase()) : [])
|
|
734
|
+
const vals = Object.fromEntries(Object.entries(clean).map(([k, v]) => [k, v && hi.has(k) ? `${v} !important` : v]))
|
|
735
|
+
return { ok: true, html: putStyle(html, x, a, mergeStyle(a ? unAttr(a.v) : '', vals)) }
|
|
503
736
|
}
|
|
504
737
|
|
|
505
738
|
export function serverUrlIn(text, skipPorts = new Set()) {
|
|
@@ -1068,13 +1301,80 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1068
1301
|
function editText(id, { key, before, after, nth = 0 } = {}) {
|
|
1069
1302
|
const short = String(after).replace(/\s+/g, ' ').trim()
|
|
1070
1303
|
return rewrite(id, key, (html) => replaceText(html, before, after, Math.max(0, Math.floor(Number(nth) || 0))),
|
|
1071
|
-
`改字「${short.length > 16 ? short.slice(0, 16) + '…' : short}
|
|
1304
|
+
`改字「${short.length > 16 ? short.slice(0, 16) + '…' : short}」`,
|
|
1305
|
+
{ kind: 'text', before: String(before).replace(/\s+/g, ' ').trim().slice(0, 60), after: short.slice(0, 60) })
|
|
1072
1306
|
}
|
|
1073
1307
|
|
|
1074
1308
|
/** 预览里调样式:把 css 写进这一屏(key)里那个元素(loc,见 findTag)的 style 属性,改前改后各存一版 */
|
|
1075
|
-
function editStyle(id, { key, loc, css, name } = {}) {
|
|
1309
|
+
function editStyle(id, { key, loc, css, name, imp } = {}) {
|
|
1076
1310
|
const short = String(name || (loc && loc.tag) || '').trim()
|
|
1077
|
-
|
|
1311
|
+
const clean = cleanCss(css)
|
|
1312
|
+
return rewrite(id, key, (html) => setStyle(html, loc || {}, css, imp), `调样式「${short.length > 24 ? short.slice(0, 24) + '…' : short}」`,
|
|
1313
|
+
{ kind: 'style', name: short, css: clean || {}, inline: true })
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* 调样式写进共用的样式表(各屏一起变):file 是设计目录里的 .css(调用方已核对过在目录里),把 css 写进第 n 条 sel 规则;
|
|
1318
|
+
* 这一屏(key)那个元素(loc)行内 style 里同名的几项去掉(不然盖过样式表,看着没变)。改前改后各存一版。
|
|
1319
|
+
* cls:选择器里元素带的那个 class,数一数别的屏还有几处行内写着自己的值(之前直接保存的),告诉用户没跟着变。
|
|
1320
|
+
*/
|
|
1321
|
+
function editRule(id, { key, loc, file, sel, n = 0, css, name, cls = '' } = {}) {
|
|
1322
|
+
const st = states.get(id)
|
|
1323
|
+
const t = st && st.target
|
|
1324
|
+
if (!t || t.kind !== 'file') return { ok: false, reason: 'not-file' }
|
|
1325
|
+
if (busyRoot(t.root)) return { ok: false, reason: 'busy' }
|
|
1326
|
+
const rootReal = fs.realpathSync(t.root)
|
|
1327
|
+
let real = ''
|
|
1328
|
+
try { real = fs.realpathSync(String(file || '')) } catch { real = '' }
|
|
1329
|
+
if (!real || !real.startsWith(rootReal + path.sep) || !/\.css$/i.test(real)) return { ok: false, reason: 'no-rule' }
|
|
1330
|
+
const stat = fs.statSync(real)
|
|
1331
|
+
if (!stat.isFile() || stat.size > 2 * 1024 * 1024) return { ok: false, reason: 'no-rule' }
|
|
1332
|
+
const r = setRuleProps(fs.readFileSync(real, 'utf8'), sel, n, css)
|
|
1333
|
+
if (!r.ok) return r
|
|
1334
|
+
const props = Object.keys(cleanCss(css) || {})
|
|
1335
|
+
// 这一屏那个元素行内同名的去掉(找不到元素、没写过行内就不动)
|
|
1336
|
+
const screen = String(key || path.basename(t.file))
|
|
1337
|
+
const sfile = path.join(t.root, screen)
|
|
1338
|
+
let html = null
|
|
1339
|
+
try {
|
|
1340
|
+
const sreal = fs.realpathSync(sfile)
|
|
1341
|
+
if (path.dirname(sfile) === t.root && HTML_EXT.test(screen) && sreal.startsWith(rootReal + path.sep)) {
|
|
1342
|
+
const cur = fs.readFileSync(sfile, 'utf8')
|
|
1343
|
+
const x = clearInline(cur, loc || {}, props)
|
|
1344
|
+
if (!x.ok) return x // 行内写法拆不开:共用规则不改,调用方退回只改这一处
|
|
1345
|
+
if (x.html !== cur) html = x.html
|
|
1346
|
+
}
|
|
1347
|
+
} catch { html = null }
|
|
1348
|
+
keepVersion(st, '')
|
|
1349
|
+
fs.writeFileSync(real, r.text)
|
|
1350
|
+
if (html != null) fs.writeFileSync(sfile, html)
|
|
1351
|
+
const rel = path.relative(rootReal, real).split(path.sep).join('/')
|
|
1352
|
+
const short = String(name || (loc && loc.tag) || '').trim()
|
|
1353
|
+
keepVersion(st, `调样式「${short.length > 20 ? short.slice(0, 20) + '…' : short}」→ ${path.basename(rel)}`)
|
|
1354
|
+
let others = 0
|
|
1355
|
+
for (const k of allScreens(t.root)) {
|
|
1356
|
+
if (k === screen) continue
|
|
1357
|
+
try { if (inlineOverrides(fs.readFileSync(path.join(t.root, k), 'utf8'), cls, props)) others++ } catch { /* 读不了不算 */ }
|
|
1358
|
+
}
|
|
1359
|
+
noteEdit(st, { kind: 'rule', files: html != null ? [rel, screen] : [rel], name: short, css: cleanCss(css) || {}, sel: String(sel || '').slice(0, 120), file: rel })
|
|
1360
|
+
return { ok: true, file: rel, sel: String(sel || ''), others, imp: r.imp || [] }
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* 用户在右侧栏亲手改了设计文件(调样式、改字、调节滑块、回到某一版):记在会话上,模型下一步开始前由插件告诉它(见 index.js 的 agent/pre-step),
|
|
1365
|
+
* 免得它凭自己之前写的内容接着改、或做进项目时用旧样子。只留最近 20 条
|
|
1366
|
+
*/
|
|
1367
|
+
function noteEdit(st, e) {
|
|
1368
|
+
st.edits = [...(st.edits || []), { at: now(), root: st.target && st.target.root, ...e }].slice(-20)
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/** 取走这个会话攒着的手改记录(取了就清) */
|
|
1372
|
+
function takeEdits(id) {
|
|
1373
|
+
const st = states.get(id)
|
|
1374
|
+
if (!st || !st.edits || !st.edits.length) return []
|
|
1375
|
+
const out = st.edits
|
|
1376
|
+
st.edits = []
|
|
1377
|
+
return out
|
|
1078
1378
|
}
|
|
1079
1379
|
|
|
1080
1380
|
/**
|
|
@@ -1082,7 +1382,7 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1082
1382
|
* 开发服务器的页面源码在项目里、不一定是这份 HTML,不在这里改(右侧栏改成让模型去改)。
|
|
1083
1383
|
* 模型正在干活时不改:它可能正整份重写这个文件,改了也会被盖掉。
|
|
1084
1384
|
*/
|
|
1085
|
-
function rewrite(id, key, fn, label) {
|
|
1385
|
+
function rewrite(id, key, fn, label, detail = null) {
|
|
1086
1386
|
const st = states.get(id)
|
|
1087
1387
|
const t = st && st.target
|
|
1088
1388
|
if (!t || t.kind !== 'file') return { ok: false, reason: 'not-file' }
|
|
@@ -1099,6 +1399,7 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1099
1399
|
keepVersion(st, '')
|
|
1100
1400
|
fs.writeFileSync(file, r.html)
|
|
1101
1401
|
keepVersion(st, label)
|
|
1402
|
+
if (detail) noteEdit(st, { ...detail, files: [name] })
|
|
1102
1403
|
return { ok: true, file: name }
|
|
1103
1404
|
}
|
|
1104
1405
|
|
|
@@ -1123,7 +1424,11 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1123
1424
|
if (busyRoot(t.root)) return { ok: false, reason: 'busy' }
|
|
1124
1425
|
keepVersion(st, '')
|
|
1125
1426
|
const r = fn(t.root)
|
|
1126
|
-
if (r && r.ok && r.files && r.files.length)
|
|
1427
|
+
if (r && r.ok && r.files && r.files.length) {
|
|
1428
|
+
const name = typeof label === 'function' ? label(r) : label
|
|
1429
|
+
keepVersion(st, name)
|
|
1430
|
+
noteEdit(st, { kind: 'dir', label: String(name || ''), files: r.files.map(String).slice(0, 8), more: Math.max(0, r.files.length - 8) })
|
|
1431
|
+
}
|
|
1127
1432
|
return r
|
|
1128
1433
|
}
|
|
1129
1434
|
|
|
@@ -1141,6 +1446,7 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1141
1446
|
const root = st.target.root
|
|
1142
1447
|
const r = history.restore(root, n, { before: (html) => beforeRestore(root, html) })
|
|
1143
1448
|
st.vrev++
|
|
1449
|
+
if (r && r.restored) noteEdit(st, { kind: 'restore', n: Number(n), count: r.restored })
|
|
1144
1450
|
return r
|
|
1145
1451
|
}
|
|
1146
1452
|
|
|
@@ -1208,5 +1514,17 @@ export function createTracker({ open, drafts = null, skipPorts = () => new Set()
|
|
|
1208
1514
|
}
|
|
1209
1515
|
}
|
|
1210
1516
|
|
|
1211
|
-
|
|
1517
|
+
/**
|
|
1518
|
+
* 右侧栏收起来没显示的那几屏(屏多过上限时最早的那些,#29):按设计清单 / 创建顺序,导出全部屏时接在显示的前面。
|
|
1519
|
+
* 不是本地文件的设计、没收起来的给 []
|
|
1520
|
+
*/
|
|
1521
|
+
function hiddenScreens(id) {
|
|
1522
|
+
const st = states.get(id)
|
|
1523
|
+
const t = st && st.target
|
|
1524
|
+
if (!t || t.kind !== 'file') return [] // 不看 st.hidden:刚加的屏目录监听还没报上来时,现扫的才准
|
|
1525
|
+
const on = new Set(st.screens)
|
|
1526
|
+
return allScreens(t.root).filter((k) => !on.has(k))
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
return { observe, stream, setTarget, setView, clear, changed, snapshot, cwdOf, stateOf, versions, restoreVersion, editText, editStyle, editRule, editDir, takeEdits, hiddenScreens, keepVersion: (id, label) => keepVersion(stateOf(id), label) }
|
|
1212
1530
|
}
|
package/lib/edits.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用户在右侧栏亲手改了设计(调样式、改字、调节滑块、回到某一版)之后,模型下一步开始前插件补给它的一段说明。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要:模型记得的是自己上次写的内容,不一定重读文件;用户手调的颜色、字,它接着改或做进项目时会用回旧样子(#28)。
|
|
5
|
+
* 走 DSH 的 agent/pre-step(和 DSH 自带的时间、操作卡片提醒一样),以「通知」的样子进对话:用户看得到一行,模型拿到全文。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const CJK = /[㐀-鿿豈-]/
|
|
10
|
+
|
|
11
|
+
/** 用户这一轮说的话里有中文就用中文写说明,否则英文(DSH 没告诉插件界面语言) */
|
|
12
|
+
export function langOf(messages) {
|
|
13
|
+
for (const m of [...(messages || [])].reverse()) {
|
|
14
|
+
if (!m || !m.source || m.source.kind !== 'user') continue
|
|
15
|
+
const c = m.content
|
|
16
|
+
const text = typeof c === 'string' ? c : Array.isArray(c) ? c.filter((b) => b && b.type === 'text').map((b) => b.text).join('\n') : ''
|
|
17
|
+
if (text.trim()) return CJK.test(text) ? 'zh' : 'en'
|
|
18
|
+
}
|
|
19
|
+
return 'zh'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const cssText = (css) => Object.entries(css || {}).map(([k, v]) => `${k}: ${v || '(去掉)'}`).join('; ')
|
|
23
|
+
const cssTextEn = (css) => Object.entries(css || {}).map(([k, v]) => `${k}: ${v || '(removed)'}`).join('; ')
|
|
24
|
+
|
|
25
|
+
/** 一条手改记录说成一行 */
|
|
26
|
+
function line(e, zh) {
|
|
27
|
+
const files = (e.files || []).join(zh ? '、' : ', ') + (e.more ? (zh ? ` 等 ${e.files.length + e.more} 个文件` : ` and ${e.more} more`) : '')
|
|
28
|
+
if (e.kind === 'style') return zh
|
|
29
|
+
? `- ${files}:调样式「${e.name}」→ ${cssText(e.css)}(写在这个元素的行内 style 上)`
|
|
30
|
+
: `- ${files}: restyled "${e.name}" → ${cssTextEn(e.css)} (written as an inline style on that element)`
|
|
31
|
+
if (e.kind === 'rule') return zh
|
|
32
|
+
? `- ${files}:调样式「${e.name}」→ 写进 ${e.file} 的 ${e.sel} 规则:${cssText(e.css)}(用这条规则的各屏一起变)`
|
|
33
|
+
: `- ${files}: restyled "${e.name}" → written into the ${e.sel} rule in ${e.file}: ${cssTextEn(e.css)} (every screen using that rule changes)`
|
|
34
|
+
if (e.kind === 'text') return zh
|
|
35
|
+
? `- ${files}:改字「${e.before}」→「${e.after}」`
|
|
36
|
+
: `- ${files}: changed the text "${e.before}" to "${e.after}"`
|
|
37
|
+
if (e.kind === 'restore') return zh
|
|
38
|
+
? `- 整套设计回到了第 ${e.n} 版(${e.count} 个文件换回那一版的内容)`
|
|
39
|
+
: `- The whole design was restored to version ${e.n} (${e.count} files now hold that version's content)`
|
|
40
|
+
return zh ? `- ${files}:${e.label || '改了'}` : `- ${files}: ${e.label || 'edited'}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param edits 核心记下的手改(见 core.js 的 noteEdit),旧的在前
|
|
45
|
+
* @returns {{ text, summary } | null}
|
|
46
|
+
*/
|
|
47
|
+
export function editsNotice(edits, lang = 'zh') {
|
|
48
|
+
const list = (edits || []).filter(Boolean)
|
|
49
|
+
if (!list.length) return null
|
|
50
|
+
const zh = lang !== 'en'
|
|
51
|
+
const roots = [...new Set(list.map((e) => e.root).filter(Boolean))]
|
|
52
|
+
const where = roots.length ? roots.map((r) => `\`${r}\``).join(zh ? '、' : ', ') : ''
|
|
53
|
+
const lines = list.map((e) => line(e, zh))
|
|
54
|
+
const text = zh
|
|
55
|
+
? [`〔设计工作台〕你上次写完之后,用户自己在右侧设计工作台里改了设计${where ? `(${where})` : ''},这些就是用户要的样子:`, ...lines,
|
|
56
|
+
'接着改这套设计、或者把它做进项目里之前:先重新读上面这些文件,以文件现在的内容为准,别照你之前写的内容来,也别把这些改回去(除非用户这次就是要你改)。行内 style 上的值是用户手调的:做成组件时把它并进组件的样式。'].join('\n')
|
|
57
|
+
: [`[Design Studio] Since you last wrote, the user edited the design by hand in the Design Studio sidebar${where ? ` (${where})` : ''}. This is how the user wants it:`, ...lines,
|
|
58
|
+
'Before you change this design again or build it into a project: re-read the files above and treat their current content as the truth. Do not go by what you wrote earlier, and do not undo these edits (unless the user asks for that now). Values in inline styles were tuned by the user: when you turn the element into a component, carry those values into the component\'s styles.'].join('\n')
|
|
59
|
+
const n = list.length
|
|
60
|
+
const summary = zh ? `用户在设计工作台里手改了 ${n} 处` : `The user hand-edited the design (${n} ${n === 1 ? 'edit' : 'edits'})`
|
|
61
|
+
return { text, summary }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 给 DSH 的一条「通知」消息(和 @deepseek-ai/dsh-llm 的 createUserMessage 出来的一样:有 id、冻住) */
|
|
65
|
+
export function noticeMessage({ text, summary }, id) {
|
|
66
|
+
const deepFreeze = (o) => { Object.freeze(o); for (const v of Object.values(o)) if (v && typeof v === 'object' && !Object.isFrozen(v)) deepFreeze(v); return o }
|
|
67
|
+
return deepFreeze({ id, role: 'user', source: { kind: 'design-studio', form: 'notice', summary }, content: [{ type: 'text', text }] })
|
|
68
|
+
}
|
|
69
|
+
|
package/lib/handoff.js
CHANGED
|
@@ -23,6 +23,8 @@ import { FRAMES_DIR } from './frames.js'
|
|
|
23
23
|
import { FRAME_MAIN, SLOT_BOX } from './slot.js'
|
|
24
24
|
|
|
25
25
|
export const HANDOFF_DIR = 'handoff'
|
|
26
|
+
/** 版本名里哪些是用户在右侧栏亲手改的(见 core.js:改字、调样式、调节滑块) */
|
|
27
|
+
const TUNED = /^(改字「|调样式「|调节:)/
|
|
26
28
|
const MAX_SCREENS = 12
|
|
27
29
|
const MAX_PARTS = 3 // 每屏最多截几段
|
|
28
30
|
|
|
@@ -383,7 +385,7 @@ export function unlinkIfLink(file) {
|
|
|
383
385
|
* 生成交接包。screens:[{ key, url, label }](预览服务器上的地址);root:设计目录。
|
|
384
386
|
* @returns { file, dir, md, shots, rows }
|
|
385
387
|
*/
|
|
386
|
-
export async function buildHandoff(browser, { root, screens, kind = 'web', size = [1280, 800], framework = 'react', dest = '', project = null, system = '', annotations = null, now = new Date() }) {
|
|
388
|
+
export async function buildHandoff(browser, { root, screens, kind = 'web', size = [1280, 800], framework = 'react', dest = '', project = null, system = '', annotations = null, tuned = [], now = new Date() }) {
|
|
387
389
|
const dir = path.join(root, HANDOFF_DIR)
|
|
388
390
|
const shotDir = path.join(dir, 'shots')
|
|
389
391
|
// handoff/、handoff/shots/ 得是设计目录里真的文件夹:是软链接就可能删到、写到别处去
|
|
@@ -397,7 +399,7 @@ export async function buildHandoff(browser, { root, screens, kind = 'web', size
|
|
|
397
399
|
const rows = browser && browser.available() ? await shootScreens(browser, list, size, kind, shotDir) : list.map((sc) => ({ key: sc.key, label: sc.label, title: '', links: [], shots: [], error: '没有 Chrome / Edge,没截图' }))
|
|
398
400
|
const htmlByKey = new Map()
|
|
399
401
|
for (const sc of list) { try { htmlByKey.set(sc.key, fs.readFileSync(path.join(root, sc.key), 'utf8')) } catch { /* 读不了 */ } }
|
|
400
|
-
const md = handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations, htmlByKey, more: Math.max(0, screens.length - MAX_SCREENS), now })
|
|
402
|
+
const md = handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations, tuned, htmlByKey, more: Math.max(0, screens.length - MAX_SCREENS), now })
|
|
401
403
|
const file = path.join(dir, 'HANDOFF.md')
|
|
402
404
|
unlinkIfLink(file)
|
|
403
405
|
fs.writeFileSync(file, md)
|
|
@@ -405,7 +407,7 @@ export async function buildHandoff(browser, { root, screens, kind = 'web', size
|
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
/** 交接说明 */
|
|
408
|
-
export function handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations = null, htmlByKey, more = 0, now = new Date() }) {
|
|
410
|
+
export function handoffMd({ root, rows, kind, size, framework, dest, project, system, annotations = null, tuned = [], htmlByKey, more = 0, now = new Date() }) {
|
|
409
411
|
const fw = FRAMEWORKS[framework] || null
|
|
410
412
|
const same = framework === 'same' && project && project.framework
|
|
411
413
|
const fwLabel = same ? `${project.label}(跟项目一样)` : fw ? fw.label : framework
|
|
@@ -431,7 +433,7 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
|
|
|
431
433
|
const keyOfLink = (p) => String(p || '').replace(/^\/+/, '').split(/[?#]/)[0]
|
|
432
434
|
const lines = []
|
|
433
435
|
lines.push(`# 交接:${name} → ${fwLabel}`, '')
|
|
434
|
-
lines.push(`> 给写代码的模型看:照这份把设计稿做成真页面。设计稿就是源码——每屏一个 HTML,样式在 tokens.css
|
|
436
|
+
lines.push(`> 给写代码的模型看:照这份把设计稿做成真页面。设计稿就是源码——每屏一个 HTML,样式在 tokens.css 等样式表里;元素上的行内 \`style="…"\` 多半是用户在工作台里手调的,值以它为准(做成组件时并进组件的样式)。先读源文件(现在的,别照你之前写过的内容),截图只用来对照,别凭截图猜数值。`, '')
|
|
435
437
|
lines.push('## 做什么', '')
|
|
436
438
|
lines.push(`- 设计目录:\`${root}\`(${rows.length} 屏${more ? `,另有 ${more} 屏没列进来` : ''},${kind} ${size[0]}×${size[1]})`)
|
|
437
439
|
// 目录里已经有别的东西、又不是 Node 项目(别的语言的仓库、后端……):别在原地或旁边跑脚手架
|
|
@@ -568,6 +570,19 @@ export function handoffMd({ root, rows, kind, size, framework, dest, project, sy
|
|
|
568
570
|
}
|
|
569
571
|
lines.push('')
|
|
570
572
|
|
|
573
|
+
// 用户在工作台里亲手改过的(#28):模型做组件时常照样式表里的那条规则来,手调写在行内的值就丢了
|
|
574
|
+
const hand = (tuned || []).filter((v) => v && TUNED.test(String(v.label || ''))).slice(0, 12)
|
|
575
|
+
if (hand.length) {
|
|
576
|
+
lines.push('## 用户手调过的(以这些为准)', '')
|
|
577
|
+
for (const v of hand) {
|
|
578
|
+
const d = new Date(v.at)
|
|
579
|
+
const p = (x) => String(x).padStart(2, '0')
|
|
580
|
+
const files = (v.changed || []).slice(0, 4).join('、') + ((v.changed || []).length > 4 ? ` 等 ${v.changed.length} 个文件` : '')
|
|
581
|
+
lines.push(`- ${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())} ${v.label}${files ? `(${files})` : ''}`)
|
|
582
|
+
}
|
|
583
|
+
lines.push('- 这些是用户在右侧栏亲手改的,文件里已经是改过的样子:照文件现在的内容做;写在行内 style 上的值要带进对应的组件,别按样式表里的旧值做。', '')
|
|
584
|
+
}
|
|
585
|
+
|
|
571
586
|
// 交互和状态
|
|
572
587
|
lines.push('## 交互和状态', '')
|
|
573
588
|
const inter = []
|
package/lib/htmlpack.js
CHANGED
|
@@ -18,7 +18,7 @@ import { defang } from './serve.js'
|
|
|
18
18
|
/** 每屏的 <base>:一个不存在的地址(.invalid 不会被解析),屏里的相对链接都落在它下面,小脚本据此认出「站内跳转」 */
|
|
19
19
|
export const PACK_ORIGIN = 'https://ddp-pack.invalid'
|
|
20
20
|
export const PACK_MAX = 150 * 1024 * 1024 // 整个文件的上限(字符数):再大浏览器打开就很慢了
|
|
21
|
-
export const PACK_SCREENS =
|
|
21
|
+
export const PACK_SCREENS = 1000 // 画布只显示 60 屏,导出要全部(#29:有人的设计 400 多屏);真正拦的是 PACK_MAX
|
|
22
22
|
const ASSET_MIN = 2048 // 这么长以上的 data: 地址单独存一份(几屏共用的只存一次)
|
|
23
23
|
|
|
24
24
|
// ── 和 client.js 同一份数(测试比着)────────────────────────────────────────
|