dsh-design-studio 0.23.0 → 0.24.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/browser.js +3 -0
- package/lib/bundle.js +67 -14
- package/lib/client.js +828 -739
- package/lib/core.js +1 -0
- package/lib/frames.js +436 -0
- package/lib/index.js +54 -2
- package/lib/kinds.js +2 -2
- package/lib/look.js +9 -3
- package/lib/picker.js +610 -21
- package/lib/styles.js +1 -1
- package/lib/tool.js +3 -2
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +2 -1
- package/skills/ui-design/references/dshplugin.md +1 -0
- package/skills/ui-design/references/frames.md +47 -0
package/lib/picker.js
CHANGED
|
@@ -3377,7 +3377,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
3377
3377
|
} })
|
|
3378
3378
|
|
|
3379
3379
|
// 5. 点击区太小(App / 小程序 / 平板 44,网页 24;文字中间的链接不算)
|
|
3380
|
-
const minTap = kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 44 : kind === 'web' || kind === 'email' || kind === 'desktop' || kind === 'dshplugin' ? 24 : 0
|
|
3380
|
+
const minTap = kind === 'app' || kind === 'miniprogram' || kind === 'tablet' ? 44 : kind === 'web' || kind === 'email' || kind === 'desktop' || kind === 'dshplugin' || kind === 'framed' ? 24 : 0
|
|
3381
3381
|
if (minTap) {
|
|
3382
3382
|
const small = []
|
|
3383
3383
|
for (const el of body.querySelectorAll(CLICKABLE)) {
|
|
@@ -3479,7 +3479,7 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
3479
3479
|
if (kind === 'diagram' || document.querySelector('.dg.mm, .dg.tr, .dg.rm, .dg.ar')) diagramCheck(add, kind, vw)
|
|
3480
3480
|
if (kind === 'diagram') smallTextCheck(add, vw)
|
|
3481
3481
|
// 17. DSH 插件:外框被改动(结构、文字、样式和模板对不上)
|
|
3482
|
-
frameCheck(add)
|
|
3482
|
+
frameCheck(add, kind)
|
|
3483
3483
|
|
|
3484
3484
|
issues.sort((x, y) => y.sev - x.sev)
|
|
3485
3485
|
const se0 = se()
|
|
@@ -3607,10 +3607,12 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
3607
3607
|
}
|
|
3608
3608
|
|
|
3609
3609
|
/**
|
|
3610
|
-
* DSH
|
|
3610
|
+
* 外框锁住(DSH 插件的四个外框、用户外框库里的外框都一样):模型只写 data-slot 里面。
|
|
3611
|
+
* 外框根 = 页面里第一个带 data-frame、里面有 data-slot 的元素(data-frame="外框 id/位置 id")。
|
|
3611
3612
|
* 结构指纹 = 外框里槽位以外的标签、class、style、data-slot 名和自己的字;和模板对不上就是外框被改了。
|
|
3612
|
-
*
|
|
3613
|
-
*
|
|
3613
|
+
* 该是什么指纹、量哪几处样式:外框库存外框时写进页面的 <template id="dsh-frame">(复制过来就带着,换台电脑也能查);
|
|
3614
|
+
* 0.22.0 起的 DSH 外框页面里没有这段,按下面 FRAME_SIGS / FRAME_PROBES 查。都没有 → 报「外框没登记」。
|
|
3615
|
+
* 改了 DSH 外框文件要重算 FRAME_SIGS(test-look 会报出新指纹)。
|
|
3614
3616
|
*/
|
|
3615
3617
|
const FRAME_SIGS = { 'dsh/sidebar': 'f6cf6564', 'dsh/settings': 'e85d0eca', 'dsh/view': '2522b3ea', 'dsh/panel': '0ea5d6de' }
|
|
3616
3618
|
const FRAME_PROBES = [ // [选择器, 样式, 浅色值, 深色值(一样就省略)]
|
|
@@ -3626,36 +3628,620 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
3626
3628
|
['.dsh-modal', 'width', '800px'],
|
|
3627
3629
|
['.dsh-scell', 'font-size', '14px'],
|
|
3628
3630
|
]
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
+
// 外框库的外框自动量的样式:插件样式漏出去(* / body / button 这种选择器、复用了外框的 class)多半改到这些。
|
|
3632
|
+
// 存外框时换几种槽位内容、换一种字体再量:跟着变的(标签宽度跟着插件名变、margin:auto 跟着挤)不记,只记稳的
|
|
3633
|
+
const FRAME_PROPS = ['display', 'visibility', 'opacity', 'position', 'top', 'left', 'transform', 'width', 'height', 'background-color', 'color', 'font-size', 'font-weight', 'font-family', 'line-height', 'padding', 'margin', 'border-top-width', 'border-radius', 'box-sizing', 'row-gap', 'column-gap', 'justify-content', 'align-items', 'flex-direction', 'fill', 'stroke', 'stroke-width', 'border-top-color', 'border-bottom-width', 'border-bottom-color', 'box-shadow', 'background-image', 'border-left-width', 'border-left-color', 'border-right-width', 'border-right-color', 'border-top-style', 'border-bottom-style', 'border-left-style', 'border-right-style',
|
|
3634
|
+
// 文字样子:插件写 body { letter-spacing / text-transform } 这种会漏到外框标题
|
|
3635
|
+
'letter-spacing', 'word-spacing', 'text-transform', 'text-align', 'font-style', 'text-decoration-line', 'text-shadow', 'white-space', 'filter', 'z-index', 'overflow-x', 'overflow-y',
|
|
3636
|
+
// 常见全局样式碰到的其余几样(都是写死的值,不跟内容变)
|
|
3637
|
+
'pointer-events', 'vertical-align', 'text-indent', 'text-overflow', 'font-variant-caps', 'list-style-type', 'clip-path', 'backdrop-filter', 'mix-blend-mode', 'outline-style',
|
|
3638
|
+
'background-size', 'background-position', 'object-fit', 'flex-wrap', 'flex-grow', 'flex-shrink', 'flex-basis', 'order', 'align-self', 'min-width', 'max-width', 'min-height', 'max-height',
|
|
3639
|
+
// 单独写的变换(scale: 0 / translate / rotate 不走 transform)
|
|
3640
|
+
'scale', 'translate', 'rotate',
|
|
3641
|
+
// SVG 图标透明、虚线;整体缩放、文字方向;遮罩图标;表单控件颜色、文字填充色
|
|
3642
|
+
'fill-opacity', 'stroke-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'zoom', 'direction', 'writing-mode', 'mask-image', 'accent-color', '-webkit-text-fill-color',
|
|
3643
|
+
// 靠右 / 靠下定位的(right: 16px 的标题);渐变的颜色
|
|
3644
|
+
'right', 'bottom', 'stop-color', 'stop-opacity', 'appearance']
|
|
3645
|
+
// 外框根元素的上层(body、html …):插件写 body { transform: scale(.5) / opacity: 0 } 整个外框跟着变。只量这几样(不跟着画幅、内容变)
|
|
3646
|
+
const ANC_PROPS = new Set(['display', 'visibility', 'opacity', 'transform', 'scale', 'rotate', 'translate', 'filter', 'backdrop-filter', 'clip-path', 'mask-image', 'mix-blend-mode', 'zoom', 'writing-mode', 'direction'])
|
|
3647
|
+
const ancAnchor = new WeakMap() // 上层元素 → ['^', 往上几层]
|
|
3648
|
+
// 外框用 ::before / ::after 画的图标、分隔线:伪元素也照普通元素那一套全量(插件写 .x::before { content: none / opacity: 0 } 图标就没了)。
|
|
3649
|
+
// 两个 content 放前面:没画伪元素的元素只记 content(none),后面全空、存的时候截掉,页面里那段不变大
|
|
3650
|
+
const BASE_PROPS = FRAME_PROPS.slice()
|
|
3651
|
+
FRAME_PROPS.push('::before content', '::after content')
|
|
3652
|
+
for (const ps of ['::before', '::after']) for (const k of BASE_PROPS) FRAME_PROPS.push(`${ps} ${k}`)
|
|
3653
|
+
// 换字体那一轮:除了字体名本身(是我们故意改的),跟着字宽变的都不记——宽高、margin:auto、translate(-50%) 居中、百分比位置……
|
|
3654
|
+
// (换台电脑系统字体不一样,这些值本来就会变)
|
|
3655
|
+
const FONT_NAME_PROPS = new Set(['font-family', 'letter-spacing'].flatMap((k) => [k, `::before ${k}`, `::after ${k}`])) // 换字体那轮连字距一起改,这两样本身照记
|
|
3656
|
+
const noPseudo = (c) => c === 'none' || c === 'normal' || c === ''
|
|
3657
|
+
// 伪元素没画出来时它那些值记成这个(不是 null:null 是「跟着内容变、不查」,会把别的主题里画出来的那套也抵消掉)
|
|
3658
|
+
const NO_PSEUDO = '-'
|
|
3659
|
+
/** 外框元素的一个样式值:'::before opacity' 这种量伪元素;伪元素没画出来(content 是 none)的除了 content 都是 NO_PSEUDO */
|
|
3660
|
+
function frameVal(el, cs, prop, pcs) {
|
|
3661
|
+
const m = /^(::before|::after) (.+)$/.exec(prop)
|
|
3662
|
+
if (!m) return cs.getPropertyValue(prop)
|
|
3663
|
+
if (!pcs[m[1]]) pcs[m[1]] = getComputedStyle(el, m[1])
|
|
3664
|
+
const c = pcs[m[1]]
|
|
3665
|
+
if (m[2] !== 'content' && noPseudo(c.getPropertyValue('content'))) return NO_PSEUDO
|
|
3666
|
+
return c.getPropertyValue(m[2])
|
|
3667
|
+
}
|
|
3668
|
+
const FRAME_MAX_PROBES = 200
|
|
3669
|
+
const frameRoots = new WeakMap()
|
|
3670
|
+
/** SVG 自带的动画(<animate> / <animateTransform> / <set> …)改的元素:不在 getAnimations() 里,量到的是半截的值 */
|
|
3671
|
+
function smilTargets() {
|
|
3631
3672
|
const out = []
|
|
3632
|
-
const
|
|
3633
|
-
if (
|
|
3673
|
+
for (const a of document.querySelectorAll('animate, animateTransform, animateMotion, animateColor, set')) {
|
|
3674
|
+
if (a.namespaceURI !== SVGNS) continue
|
|
3675
|
+
const h = a.getAttribute('href') || a.getAttributeNS('http://www.w3.org/1999/xlink', 'href') || ''
|
|
3676
|
+
const t = h.startsWith('#') ? document.getElementById(h.slice(1)) : a.parentElement
|
|
3677
|
+
if (t) out.push(t)
|
|
3678
|
+
}
|
|
3679
|
+
return out
|
|
3680
|
+
}
|
|
3681
|
+
const isFrameRoot = (f) => {
|
|
3682
|
+
if (!frameRoots.has(f)) frameRoots.set(f, !!f.querySelector('[data-slot]'))
|
|
3683
|
+
return frameRoots.get(f)
|
|
3684
|
+
}
|
|
3685
|
+
function frameRoot() {
|
|
3686
|
+
for (const f of document.querySelectorAll('[data-frame]')) if (isFrameRoot(f)) return f
|
|
3687
|
+
return null
|
|
3688
|
+
}
|
|
3689
|
+
// 入口图标、名字那些小槽位跟着外框的样式走,也不查
|
|
3690
|
+
// 只认登记过的外框(DSH 自带的、页面里有外框库那段 <template id="dsh-frame"> 的):普通设计里碰巧带 data-frame 的包裹层照常查
|
|
3691
|
+
const frameKnown = (f) => Object.prototype.hasOwnProperty.call(FRAME_SIGS, f.getAttribute('data-frame') || '') || !!document.getElementById('dsh-frame')
|
|
3692
|
+
const inFrame = (el) => {
|
|
3693
|
+
const f = el.closest && el.closest('[data-frame]')
|
|
3694
|
+
return !!(f && isFrameRoot(f) && frameKnown(f) && !el.closest('[data-slot="main"]'))
|
|
3695
|
+
}
|
|
3696
|
+
/**
|
|
3697
|
+
* <use> 引用的图标记成什么:本页里的 #x 记名字和那个图标的结构(id 改了、图标形状改了都变);
|
|
3698
|
+
* 别的文件里的(icons.svg#x)记文件和名字;远程看打包进页面的(#dsh1-x)按 bundle.js 留下的 data-dsh-href 记:两边一样
|
|
3699
|
+
*/
|
|
3700
|
+
// 第 2 版指纹记元素的全部属性(按名排序),只除开这些:class / style(单独记)、data-slot、
|
|
3701
|
+
// 图和引用的地址(src / srcset / href / xlink:href / poster:远程看会换成 data:,按 mediaSrc / svgRefs 里的原地址记)、
|
|
3702
|
+
// 用着会变的(open:用户点开 details;contenteditable / spellcheck:改字时)、插件自己加的 data-dsh-*
|
|
3703
|
+
const SIG_ATTR_SKIP = /^(class|style|data-slot|src|srcset|href|xlink:href|poster|open|contenteditable|spellcheck|data-dsh-.*)$/i
|
|
3704
|
+
const allAttrs = (el) => [...el.attributes].filter((a) => !SIG_ATTR_SKIP.test(a.name)).map((a) => `${a.name.toLowerCase()}=${a.value}`).sort().join('\u0001')
|
|
3705
|
+
/** 图 / 视频 / SVG image 的地址(远程看打包成 data: 的按 data-dsh-src 里原来的) */
|
|
3706
|
+
function mediaSrc(el) {
|
|
3707
|
+
const a = el.hasAttribute('src') ? 'src' : el.tagName.toLowerCase() === 'image' ? (el.hasAttribute('href') ? 'href' : 'xlink:href') : null
|
|
3708
|
+
const pick = (attr, keep) => el.getAttribute(keep) ?? (el.getAttribute(attr) || '') // 远程看打包过的按 bundle.js 留下的原值(连空格都不变)
|
|
3709
|
+
const s = a ? pick(a, 'data-dsh-src') : ''
|
|
3710
|
+
return el.hasAttribute('srcset') ? `${s}\u0001${pick('srcset', 'data-dsh-srcset')}` : s // <img srcset> / <source srcset> 换了图也认得出
|
|
3711
|
+
}
|
|
3712
|
+
const SIG_URL_RE = /url\(\s*(?:"[^"]*"|'[^']*'|[^)]*)\s*\)/gi
|
|
3713
|
+
/** SVG 元素引用的本页 id:渐变 / 图案的 href="#x",fill / stroke / clip-path / mask / filter / marker 里的 url(#x)(属性、行内样式;computed 时连 CSS 写的也算) */
|
|
3714
|
+
function svgUrlIds(el, computed) {
|
|
3715
|
+
const ids = []
|
|
3716
|
+
if (el.tagName.toLowerCase() !== 'use') {
|
|
3717
|
+
const h = el.getAttribute('href') || el.getAttribute('xlink:href') || ''
|
|
3718
|
+
if (h.startsWith('#')) ids.push(h.slice(1))
|
|
3719
|
+
}
|
|
3720
|
+
const txt = [...SVG_REF_ATTRS.map((a) => el.getAttribute(a) || ''), el.getAttribute('style') || '']
|
|
3721
|
+
if (computed) { const cs = getComputedStyle(el); txt.push(cs.fill, cs.stroke, cs.filter, cs.clipPath, cs.maskImage || '', cs.markerStart || '', cs.markerMid || '', cs.markerEnd || '') }
|
|
3722
|
+
for (const t of txt) for (const m of String(t || '').matchAll(/url\(\s*["']?#([^"')\s]+)["']?\s*\)/g)) ids.push(m[1])
|
|
3723
|
+
return [...new Set(ids)]
|
|
3724
|
+
}
|
|
3725
|
+
/** 一个被引用的本页图标 / 渐变 / 裁剪长什么样(找不到记 missing):每个元素记标签、class、行内样式、字、id、形状属性、第几层、它又引用的 */
|
|
3726
|
+
function refShape(id0, seen) {
|
|
3727
|
+
let id = id0
|
|
3728
|
+
try { id = decodeURIComponent(id) } catch { /* 原样 */ }
|
|
3729
|
+
const t = document.getElementById(id)
|
|
3730
|
+
if (!t) return `#${id}:missing`
|
|
3731
|
+
// 里面又引用别的:接着跟(seen 防绕圈,最多跟 20 个)
|
|
3732
|
+
if (seen.has(t) || seen.size >= 20) return `#${id}:seen`
|
|
3733
|
+
seen.add(t)
|
|
3734
|
+
const parts = []
|
|
3735
|
+
for (const x of [t, ...t.querySelectorAll('*')].slice(0, 60)) {
|
|
3736
|
+
let depth = 0
|
|
3737
|
+
for (let y = x; y && y !== t; y = y.parentElement) depth++
|
|
3738
|
+
parts.push([x.tagName.toLowerCase(), x.getAttribute('class') || '', (x.getAttribute('style') || '').replace(SIG_URL_RE, 'url()'), ownText(x), x.getAttribute('id') || '', allAttrs(x), depth, svgRefs(x, seen)].join('\u0001'))
|
|
3739
|
+
}
|
|
3740
|
+
return `#${id}:${parts.join('\u0002')}`
|
|
3741
|
+
}
|
|
3742
|
+
/**
|
|
3743
|
+
* 第 2 版指纹里 SVG 元素引用了什么:<use> 的图标(别的文件里的记文件和名字;远程看打包进页面的 #dsh1-x 按 bundle.js 留下的 data-dsh-href 记:两边一样),
|
|
3744
|
+
* 渐变、裁剪、遮罩……(属性、行内样式里的 url(#x))——本页的记目标长什么样,目标没了、改了形状都认得出。
|
|
3745
|
+
* CSS 里写的引用不进指纹(深浅色、聚焦时可能换成别的 id):那些按样式样本查,目标被删了 frameStyle 报
|
|
3746
|
+
*/
|
|
3747
|
+
function svgRefs(el, seen = new Set()) {
|
|
3748
|
+
if (el.namespaceURI !== SVGNS) return ''
|
|
3749
|
+
const out = []
|
|
3750
|
+
if (el.tagName.toLowerCase() === 'use') {
|
|
3751
|
+
const raw = el.getAttribute('href') || el.getAttribute('xlink:href') || ''
|
|
3752
|
+
const h = (/^#dsh\d+-/.test(raw) && el.getAttribute('data-dsh-href')) || raw
|
|
3753
|
+
out.push(h.indexOf('#') !== 0 ? `ext:${h}` : refShape(h.slice(1), seen))
|
|
3754
|
+
}
|
|
3755
|
+
for (const id of svgUrlIds(el, false)) out.push(refShape(id, seen))
|
|
3756
|
+
return out.join('\u0003')
|
|
3757
|
+
}
|
|
3758
|
+
function frameSig(root, ver = 1) {
|
|
3759
|
+
const out = []
|
|
3760
|
+
// 第 2 版每个元素还记第几层:元素挪到别的父元素下(先后顺序没变)也认得出
|
|
3761
|
+
const walk = (el, depth = 0) => {
|
|
3762
|
+
if ((SIG_SKIP.has(el.tagName) && !(ver >= 2 && el.tagName === 'BR')) || /^DSH-DESIGN-/.test(el.tagName)) return // 第 2 版连 <br> 也记(删了换行会变样)
|
|
3634
3763
|
const slot = el.getAttribute('data-slot')
|
|
3635
3764
|
// 槽位本身只记标签和名字:槽位上的 class、style(调样式改的内边距、底色)算插件的
|
|
3636
|
-
|
|
3637
|
-
|
|
3765
|
+
// 第 2 版:行内样式里的 url(...) 只记「有个地址」(远程看时本地图会换成 data: 地址)
|
|
3766
|
+
const style = el.getAttribute('style') || ''
|
|
3767
|
+
// 第 2 版:行内样式、图的地址按原来的写法记(远程看时 bundle.js 换成 data: 地址,原来的留在 data-dsh-style / data-dsh-src)
|
|
3768
|
+
const row = slot === null ? [el.tagName.toLowerCase(), el.getAttribute('class') || '', ver >= 2 ? (el.getAttribute('data-dsh-style') ?? style) : style, '', ownText(el)] : [el.tagName.toLowerCase(), '', '', slot, '']
|
|
3769
|
+
if (ver >= 2 && slot === null) row.push(allAttrs(el), mediaSrc(el))
|
|
3770
|
+
// SVG 里的 id(<use> 靠它找图标)、<use> 引用的是哪个图标
|
|
3771
|
+
if (ver >= 2 && slot === null && el.namespaceURI === SVGNS) row.push(el.getAttribute('id') || '', svgRefs(el))
|
|
3772
|
+
if (ver >= 2) row.push(String(depth))
|
|
3773
|
+
out.push(row.join('|'))
|
|
3774
|
+
if (slot === null) for (const c of el.children) walk(c, depth + 1)
|
|
3638
3775
|
}
|
|
3639
3776
|
walk(root)
|
|
3640
|
-
|
|
3777
|
+
return fnv(out.join('\n'))
|
|
3778
|
+
}
|
|
3779
|
+
function fnv(s) {
|
|
3641
3780
|
let h = 0x811c9dc5
|
|
3642
3781
|
for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 0x01000193) }
|
|
3643
3782
|
return (h >>> 0).toString(16).padStart(8, '0')
|
|
3644
3783
|
}
|
|
3645
|
-
|
|
3646
|
-
|
|
3784
|
+
/** 外框外面被引用(按 id 量的)那些目标的结构摘要 { id: 指纹 }:CSS 写的 filter: url(#x) 引用的滤镜参数改了也认得出(结构和深浅色无关) */
|
|
3785
|
+
const refDigests = (paths) => Object.fromEntries([...new Set(paths.filter((p) => Array.isArray(p) && typeof p[0] === 'string' && p[0].startsWith('#')).map((p) => p[0].slice(1)))].slice(0, 40).map((id) => [id, fnv(refShape(id, new Set()))]))
|
|
3786
|
+
/** 页面里外框库写的那段(该是什么指纹、量哪几处);没有或写坏了 → null */
|
|
3787
|
+
function frameData() {
|
|
3788
|
+
const tag = document.getElementById('dsh-frame')
|
|
3789
|
+
const text = !tag ? '' : tag.tagName === 'TEMPLATE' ? tag.content.textContent : tag.tagName === 'SCRIPT' ? tag.textContent : ''
|
|
3790
|
+
if (!text) return null
|
|
3791
|
+
try {
|
|
3792
|
+
const d = JSON.parse(text)
|
|
3793
|
+
return d && typeof d === 'object' && typeof d.sig === 'string' ? d : null
|
|
3794
|
+
} catch { return null }
|
|
3795
|
+
}
|
|
3796
|
+
/** 外框里一个元素的位置:从根往下每层是第几个孩子(外框结构锁着,位置就是稳的) */
|
|
3797
|
+
function framePath(root, el) {
|
|
3798
|
+
if (ancAnchor.has(el)) return ancAnchor.get(el).slice()
|
|
3799
|
+
if (refAnchor.has(el)) return refAnchor.get(el).slice() // 外框外面、<use> 引用的图标:['#id', 第几个孩子 …]
|
|
3800
|
+
const path = []
|
|
3801
|
+
for (let x = el; x && x !== root; x = x.parentElement) path.unshift(Array.prototype.indexOf.call(x.parentElement ? x.parentElement.children : [], x))
|
|
3802
|
+
return path
|
|
3803
|
+
}
|
|
3804
|
+
function byPath(root, path) {
|
|
3805
|
+
let x = root
|
|
3806
|
+
const p = Array.isArray(path) ? path : []
|
|
3807
|
+
let k = 0
|
|
3808
|
+
if (p[0] === '^') { // 外框根元素往上几层
|
|
3809
|
+
for (let n = Number(p[1]) || 0; n > 0 && x; n--) x = x.parentElement
|
|
3810
|
+
return x && x !== root ? x : null
|
|
3811
|
+
}
|
|
3812
|
+
if (typeof p[0] === 'string' && p[0].startsWith('#')) { x = document.getElementById(p[0].slice(1)); k = 1 }
|
|
3813
|
+
for (; k < p.length; k++) { x = x && x.children[p[k]]; if (!x) return null }
|
|
3814
|
+
return x
|
|
3815
|
+
}
|
|
3816
|
+
/** 外框自己的元素(槽位和里面的不算),按页面顺序 */
|
|
3817
|
+
function frameOwn(root) {
|
|
3818
|
+
const out = []
|
|
3819
|
+
const walk = (el) => {
|
|
3820
|
+
if (SIG_SKIP.has(el.tagName) || /^DSH-DESIGN-/.test(el.tagName) || el.hasAttribute('data-slot')) return
|
|
3821
|
+
out.push(el)
|
|
3822
|
+
// SVG 图标:里面画出来的前几个(path、circle …)也量(插件写 path { stroke: none } 图标就没了);图标里几百条线的只取前 6 个,不占满名额
|
|
3823
|
+
if (el.tagName.toLowerCase() === 'svg') { out.push(...[...el.querySelectorAll('*')].filter((x) => x.getClientRects().length).slice(0, 6)); return }
|
|
3824
|
+
for (const c of el.children) walk(c)
|
|
3825
|
+
}
|
|
3826
|
+
walk(root)
|
|
3827
|
+
// <use> 引用的本页图标(<defs> / <symbol> 里的,自己不画、getClientRects 是空的;外框里外都算):它和里面前 6 个也量
|
|
3828
|
+
// (插件写 path { fill: none !important } 时,<use> 画出来的图标跟着变)。外框外面的按 id 找:['#id', 第几个孩子 …]
|
|
3829
|
+
// 图标里面又 <use> 别的图标:接着跟(targets 防绕圈,最多 20 个)
|
|
3830
|
+
// 渐变、图案、滤镜、裁剪、遮罩(fill: url(#g) 这种)也一样跟:插件写 stop { stop-color: transparent } 图标就没了
|
|
3831
|
+
const seen = new Set(out), targets = new Set()
|
|
3832
|
+
const ids = []
|
|
3833
|
+
const addIds = (el, computed) => {
|
|
3834
|
+
// 伪元素(::before { clip-path: url(#cut) } 画的图标)和 HTML 元素:看算出来的 filter / clip-path / mask(工具栏写 filter: url(#blur) 这种)
|
|
3835
|
+
if (computed) {
|
|
3836
|
+
for (const ps of el.namespaceURI === SVGNS ? ['::before', '::after'] : [null, '::before', '::after']) {
|
|
3837
|
+
const cs = getComputedStyle(el, ps)
|
|
3838
|
+
for (const t of [cs.filter, cs.clipPath, cs.maskImage || '']) for (const m of String(t || '').matchAll(/url\(\s*["']?#([^"')\s]+)["']?\s*\)/g)) ids.push(m[1])
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
if (el.namespaceURI !== SVGNS) return
|
|
3842
|
+
if (el.tagName.toLowerCase() === 'use') { const h = el.getAttribute('href') || el.getAttribute('xlink:href') || ''; if (h.startsWith('#')) ids.push(h.slice(1)) }
|
|
3843
|
+
ids.push(...svgUrlIds(el, computed))
|
|
3844
|
+
}
|
|
3845
|
+
const ups = []
|
|
3846
|
+
for (let a = root.parentElement, n = 1; a && n <= 6; a = a.parentElement, n++) ups.push(a) // 上层(body { filter: url(#x) })也看
|
|
3847
|
+
for (const el of [...ups, root, ...[...root.querySelectorAll('*')].filter((x) => !x.closest('[data-slot]'))]) addIds(el, true)
|
|
3848
|
+
for (let k = 0; k < ids.length && targets.size < 20; k++) {
|
|
3849
|
+
let id = ids[k]
|
|
3850
|
+
try { id = decodeURIComponent(id) } catch { /* 原样 */ }
|
|
3851
|
+
const t = document.getElementById(id)
|
|
3852
|
+
if (!t || targets.has(t) || t.closest('[data-slot]')) continue
|
|
3853
|
+
targets.add(t)
|
|
3854
|
+
for (const x of [t, ...t.querySelectorAll('*')]) addIds(x, true)
|
|
3855
|
+
const inside = root.contains(t)
|
|
3856
|
+
for (const x of [t, ...t.querySelectorAll('*')].slice(0, 7)) {
|
|
3857
|
+
if (seen.has(x)) continue
|
|
3858
|
+
seen.add(x); out.push(x); refEls.add(x)
|
|
3859
|
+
if (!inside) {
|
|
3860
|
+
const rel = []
|
|
3861
|
+
for (let y = x; y && y !== t; y = y.parentElement) rel.unshift(Array.prototype.indexOf.call(y.parentElement.children, y))
|
|
3862
|
+
refAnchor.set(x, [`#${id}`, ...rel])
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
return out
|
|
3867
|
+
}
|
|
3868
|
+
const SVG_REF_ATTRS = ['fill', 'stroke', 'filter', 'clip-path', 'mask', 'marker-start', 'marker-mid', 'marker-end']
|
|
3869
|
+
const refEls = new WeakSet() // <use> 引用的图标:没画出来也量
|
|
3870
|
+
const refAnchor = new WeakMap() // 外框外面的被引用图标 → ['#id', 第几个孩子 …]
|
|
3871
|
+
// 外框里藏着的(display: none 的菜单、提示):只量 display、visibility(插件写 .menu { display: block } 菜单就露出来了)。
|
|
3872
|
+
// 浅色深色哪种下看得见就全量(shownEver)
|
|
3873
|
+
const hiddenEls = new WeakSet(), shownEver = new WeakSet()
|
|
3874
|
+
const frameVals = (el) => {
|
|
3875
|
+
const cs = getComputedStyle(el), pcs = {}, anc = ancAnchor.has(el), hid = hiddenEls.has(el) && !shownEver.has(el)
|
|
3876
|
+
return FRAME_PROPS.map((k) => ((anc && !ANC_PROPS.has(k)) || (hid && k !== 'display' && k !== 'visibility') ? null : frameVal(el, cs, k, pcs)))
|
|
3877
|
+
}
|
|
3878
|
+
/** 存外框时量哪些:外框自己的、看得见的元素(同类的也都量:插件可能只改到第二个按钮),再加藏着的(最多 30 个)和上层,最多 FRAME_MAX_PROBES 个 */
|
|
3879
|
+
function frameProbeEls(root) {
|
|
3880
|
+
const anc = []
|
|
3881
|
+
for (let a = root.parentElement, n = 1; a && n <= 6; a = a.parentElement, n++) { ancAnchor.set(a, ['^', n]); anc.push(a) }
|
|
3882
|
+
const own = frameOwn(root)
|
|
3883
|
+
const shown = own.filter((el) => el === root || refEls.has(el) || el.getClientRects().length).slice(0, FRAME_MAX_PROBES - anc.length)
|
|
3884
|
+
for (const el of shown) shownEver.add(el)
|
|
3885
|
+
const room = Math.min(30, FRAME_MAX_PROBES - anc.length - shown.length)
|
|
3886
|
+
const hidden = room > 0 ? own.filter((el) => !shown.includes(el) && !el.getClientRects().length).slice(0, room) : []
|
|
3887
|
+
for (const el of hidden) hiddenEls.add(el)
|
|
3888
|
+
return [...shown, ...hidden, ...anc]
|
|
3889
|
+
}
|
|
3890
|
+
// 颜色在不同版本的浏览器里写法可能不一样(rgb / oklch …):字不一样时,两边都放到同一个元素上让浏览器自己换算一遍再比
|
|
3891
|
+
// 屏幕缩放(Windows 125% / 150%、Retina 2 倍)下边框、跟着字走的高度会差零点几像素:带 px 的值逐个数比,差不到 1px 算一样
|
|
3892
|
+
const PX_NUM = /-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi
|
|
3893
|
+
// 宽高、位置跟着字的上下沿取整走,125% 下输入框能差整 1px:放到 2px;字号不受缩放影响,照字比
|
|
3894
|
+
const PX_LOOSE = new Set(['width', 'height', 'top', 'left', 'right', 'bottom'])
|
|
3895
|
+
function samePx(a, b, prop) {
|
|
3896
|
+
const sa = String(a), sb = String(b)
|
|
3897
|
+
if (prop === 'font-size' || !/px/.test(sa) || sa.replace(PX_NUM, '#') !== sb.replace(PX_NUM, '#')) return false
|
|
3898
|
+
const na = sa.match(PX_NUM) || [], nb = sb.match(PX_NUM) || []
|
|
3899
|
+
const tol = PX_LOOSE.has(prop) ? 2 : 1
|
|
3900
|
+
return na.length === nb.length && na.every((x, i) => Math.abs(parseFloat(x) - parseFloat(nb[i])) < tol)
|
|
3901
|
+
}
|
|
3902
|
+
// transform:缩放、旋转那几个数要一样,平移(translate(-50%) 居中按字高算)差不到 1px 算一样
|
|
3903
|
+
// anyTr:平移不管(存外框时记成 ~ 开头的那种:平移跟着字宽、槽位内容变)
|
|
3904
|
+
function sameMatrix(a, b, anyTr = false) {
|
|
3905
|
+
const m = (v) => { const x = /^matrix(3d)?\((.*)\)$/.exec(String(v).trim()); return x ? { d3: !!x[1], n: x[2].split(',').map(Number) } : null }
|
|
3906
|
+
const ma = m(a), mb = m(b)
|
|
3907
|
+
if (!ma || !mb || ma.d3 !== mb.d3 || ma.n.length !== mb.n.length) return false
|
|
3908
|
+
const tr = ma.d3 ? [12, 13, 14] : [4, 5]
|
|
3909
|
+
return ma.n.every((x, i) => (tr.includes(i) ? anyTr || Math.abs(x - mb.n[i]) < 1 : Math.abs(x - mb.n[i]) < 0.001))
|
|
3910
|
+
}
|
|
3911
|
+
// 图的地址:远程看时换成 data:(那张算对得上);本页的 #x 按片段名比;别的按相对页面目录的路径比
|
|
3912
|
+
// (外框库、设计目录里都是 assets/a/x.svg,绝对地址不一样;页面不在设计目录根上时按「结尾是这段路径」认)
|
|
3913
|
+
const VAL_URL_RE = /url\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^)]*?))\s*\)/g
|
|
3914
|
+
const urlKey = (u) => {
|
|
3915
|
+
u = String(u).trim().replace(/\\(.)/g, '$1')
|
|
3916
|
+
if (/^data:/i.test(u)) return '*'
|
|
3917
|
+
if (u.startsWith('#')) return u
|
|
3918
|
+
try {
|
|
3919
|
+
const x = new URL(u, location.href)
|
|
3920
|
+
if (x.origin === location.origin && x.pathname === location.pathname && x.hash) return x.hash
|
|
3921
|
+
const dir = location.pathname.replace(/[^/]*$/, '')
|
|
3922
|
+
const p = decodeURIComponent(x.pathname)
|
|
3923
|
+
const d = decodeURIComponent(dir)
|
|
3924
|
+
return (x.origin === location.origin && p.startsWith(d) ? p.slice(d.length) : `/${p.replace(/^\/+/, '')}`) + x.hash
|
|
3925
|
+
} catch { return u }
|
|
3926
|
+
}
|
|
3927
|
+
const sameKey = (k, w) => k === '*' || w === '*' || k === w || (k.startsWith('/') && !w.startsWith('/') && !w.startsWith('#') && k.endsWith(`/${w}`)) || (w.startsWith('/') && !k.startsWith('/') && !k.startsWith('#') && w.endsWith(`/${k}`))
|
|
3928
|
+
function sameUrls(a, b) {
|
|
3929
|
+
const ua = []; const ub = []
|
|
3930
|
+
const sa = String(a).replace(VAL_URL_RE, (m, x, y, z) => { ua.push(urlKey(x ?? y ?? z)); return 'url()' })
|
|
3931
|
+
const sb = String(b).replace(VAL_URL_RE, (m, x, y, z) => { ub.push(urlKey(x ?? y ?? z)); return 'url()' })
|
|
3932
|
+
return sa === sb && ua.length === ub.length && ua.every((k, i) => sameKey(k, ub[i]))
|
|
3933
|
+
}
|
|
3934
|
+
function sameVal(prop0, a, b) {
|
|
3935
|
+
if (a === b) return true
|
|
3936
|
+
const prop = String(prop0).replace(/^::(before|after) /, '') // 伪元素的按同名属性比
|
|
3937
|
+
// content 里的图(url(...))远程看时换成 data: 地址:只比「有个图」
|
|
3938
|
+
if (prop === 'content' || prop === 'background-image' || prop === 'mask-image') return sameUrls(a, b)
|
|
3939
|
+
if (prop === 'transform') return String(b).startsWith('~') ? sameMatrix(a, String(b).slice(1), true) : sameMatrix(a, b)
|
|
3940
|
+
// 引用外部文件的(fill: url("assets/paint.svg#g")、filter: url("assets/fx.svg#f")):外框库和设计目录端口不一样,地址按路径 + 片段比
|
|
3941
|
+
if (/^(fill|stroke|filter|backdrop-filter|clip-path|marker-start|marker-mid|marker-end)$/.test(prop) && /url\(/.test(a + b)) return sameUrls(a, b)
|
|
3942
|
+
if (/^(box-shadow|text-shadow|filter|backdrop-filter|clip-path|z-index|order|flex-grow|flex-shrink|scale|rotate)$/.test(prop)) return false // 阴影、滤镜里有颜色又有长度,照字比
|
|
3943
|
+
if (prop === 'fill' || prop === 'stroke') { if (/none|url\(/.test(a + b)) return false } else if (!/color$/.test(prop)) return samePx(a, b, prop)
|
|
3944
|
+
const tmp = document.createElement('dsh-design-norm')
|
|
3945
|
+
try {
|
|
3946
|
+
tmp.style.display = 'none'
|
|
3947
|
+
document.documentElement.appendChild(tmp)
|
|
3948
|
+
const conv = (v) => { tmp.style.removeProperty('color'); tmp.style.setProperty('color', v, 'important'); return getComputedStyle(tmp).color } // 行内 !important:页面里的 * { color: … !important } 盖不过它
|
|
3949
|
+
return conv(a) === conv(b)
|
|
3950
|
+
} catch { return false } finally { tmp.remove() }
|
|
3951
|
+
}
|
|
3952
|
+
/** 存外框用:现在看得见的外框元素的位置(深浅色各取一次、合起来再量) */
|
|
3953
|
+
// 存外框量默认样子:外框带 autofocus 的输入框先移走焦点(不然 :focus-within 的颜色记成了基准)
|
|
3954
|
+
// 正在用输入法组词(拼音还没选字):这时 blur 会把拼音直接提交掉,样式这次不查
|
|
3955
|
+
let composing = false
|
|
3956
|
+
try {
|
|
3957
|
+
document.addEventListener('compositionstart', () => { composing = true }, true)
|
|
3958
|
+
document.addEventListener('compositionend', () => { composing = false }, true)
|
|
3959
|
+
} catch { /* 没有 document */ }
|
|
3960
|
+
/** 页面旁边一个文件的指纹(和 frames.js assetHashes 一样:按字节 FNV、去掉 \r);读不到 → null */
|
|
3961
|
+
function fileHash(rel) {
|
|
3962
|
+
try {
|
|
3963
|
+
if (!/^https?:$/.test(location.protocol)) return null
|
|
3964
|
+
const x = new XMLHttpRequest()
|
|
3965
|
+
x.open('GET', new URL(rel, document.baseURI).href, false)
|
|
3966
|
+
x.overrideMimeType('text/plain; charset=x-user-defined')
|
|
3967
|
+
x.send()
|
|
3968
|
+
if (x.status !== 200) return null
|
|
3969
|
+
if (/\btext\/html\b/i.test(x.getResponseHeader('content-type') || '') && !/\.html?$/i.test(rel)) return null // 服务器拿网页顶替(远程看):不算
|
|
3970
|
+
const t = x.responseText
|
|
3971
|
+
let h = 0x811c9dc5
|
|
3972
|
+
for (let i = 0; i < t.length; i++) { const b = t.charCodeAt(i) & 0xff; if (b === 13) continue; h ^= b; h = Math.imul(h, 0x01000193) }
|
|
3973
|
+
return (h >>> 0).toString(16).padStart(8, '0')
|
|
3974
|
+
} catch { return null }
|
|
3975
|
+
}
|
|
3976
|
+
const unfocus = () => { const a = document.activeElement; if (a && a !== document.body && typeof a.blur === 'function') a.blur() }
|
|
3977
|
+
function framePaths() {
|
|
3978
|
+
unfocus()
|
|
3979
|
+
const root = frameRoot()
|
|
3980
|
+
return root ? frameProbeEls(root).map((el) => framePath(root, el)) : []
|
|
3981
|
+
}
|
|
3982
|
+
/** 存外框用:这个页面的外框长什么样(id、指纹、槽位、几处样式在现在的深浅色下的值;跟着槽位内容、字体变的记 null) */
|
|
3983
|
+
/** 外框根元素左上角在页面上的位置(加上滚动) */
|
|
3984
|
+
const frameAt = (root) => { const r = root.getBoundingClientRect(); return [Math.round(r.left + (window.scrollX || 0)), Math.round(r.top + (window.scrollY || 0))] }
|
|
3985
|
+
function frameInfo(paths) {
|
|
3986
|
+
unfocus()
|
|
3987
|
+
const root = frameRoot()
|
|
3988
|
+
if (!root) return { found: !!document.querySelector('[data-frame]'), id: '', sig: '', slots: [], probes: null }
|
|
3989
|
+
// 量的时候关掉过渡(刚切深色时颜色还在渐变,量到半截的值);动画直接跳到播完(和体检时一样:入场动画播完、停在最后一帧的样子),
|
|
3990
|
+
// 一直转的(infinite)跳不到头:它和它里面的这次都不记(体检时它们也在动、不查)
|
|
3991
|
+
const still = document.createElement('style')
|
|
3992
|
+
still.textContent = '*,*::before,*::after{transition:none!important}'
|
|
3993
|
+
;(document.head || document.documentElement).appendChild(still)
|
|
3994
|
+
const spin = []
|
|
3995
|
+
for (const a of typeof document.getAnimations === 'function' ? document.getAnimations() : []) {
|
|
3996
|
+
try { a.finish() } catch { if (a.effect && a.effect.target) spin.push(a.effect.target) }
|
|
3997
|
+
}
|
|
3998
|
+
spin.push(...smilTargets())
|
|
3999
|
+
try {
|
|
4000
|
+
// 深色那次按浅色挑的那些量(按位置配对):深浅色换图标的外框,浅色里那张深色下 display:none 也记下来
|
|
4001
|
+
const els = Array.isArray(paths) ? paths.map((p) => byPath(root, p) || root) : frameProbeEls(root)
|
|
4002
|
+
if (Array.isArray(paths)) paths.forEach((p, i) => { if (Array.isArray(p) && p[0] === '^' && els[i] !== root) ancAnchor.set(els[i], p.slice()) })
|
|
4003
|
+
const base = els.map(frameVals)
|
|
4004
|
+
const drop = base.map((v, i) => v.map(() => spin.some((t) => t === els[i] || (t.contains && t.contains(els[i])))))
|
|
4005
|
+
// transform 只是平移变了(translate(-50%) 居中跟着字宽、槽位内容走):不整个丢,记成「平移不查」(值前面加 ~),缩放、旋转、被改成 none 照查
|
|
4006
|
+
const trOnly = base.map((v) => v.map(() => false))
|
|
4007
|
+
// 外框根元素在页面上的位置(插件写 body { padding: 24px }、在外框前面塞东西,整个外框挪开):换槽位内容、换字体都不动才记
|
|
4008
|
+
const at0 = frameAt(root)
|
|
4009
|
+
let atOk = true
|
|
4010
|
+
const diff = (only, skip) => {
|
|
4011
|
+
els.forEach((el, i) => frameVals(el).forEach((x, k) => {
|
|
4012
|
+
const p = FRAME_PROPS[k]
|
|
4013
|
+
if ((only && !only.has(p)) || (skip && skip.has(p)) || x === base[i][k]) return
|
|
4014
|
+
if (/transform$/.test(p) && sameMatrix(x, base[i][k], true)) trOnly[i][k] = true
|
|
4015
|
+
else drop[i][k] = true
|
|
4016
|
+
}))
|
|
4017
|
+
const a = frameAt(root)
|
|
4018
|
+
if (a[0] !== at0[0] || a[1] !== at0[1]) atOk = false
|
|
4019
|
+
}
|
|
4020
|
+
const slots = [...root.querySelectorAll('[data-slot]')].filter((x) => !x.parentElement || !x.parentElement.closest('[data-slot]'))
|
|
4021
|
+
const saved = slots.map((x) => x.innerHTML)
|
|
4022
|
+
const TEXT = '示例文字示例文字 Sample text '.repeat(5)
|
|
4023
|
+
// 三种塞法:撑高(长段落)、撑宽(不换行的长字)、方块(48×48,比图标、按钮大一点)
|
|
4024
|
+
const big = (x, how) => (x.getAttribute('data-slot') === 'main'
|
|
4025
|
+
? (how === 'wide' ? '<div style="width:2400px;height:40px"></div>' : '<div style="height:2400px"></div>')
|
|
4026
|
+
: how === 'box' ? '<span style="display:inline-block;width:48px;height:48px;vertical-align:middle"></span>'
|
|
4027
|
+
: `<span${how === 'wide' ? ' style="white-space:nowrap"' : ''}>${TEXT}</span>`)
|
|
4028
|
+
try {
|
|
4029
|
+
// 全空、全塞满、每个槽位单独塞满(别的空着):哪种填法下变了的都不记
|
|
4030
|
+
slots.forEach((x) => { x.innerHTML = '' })
|
|
4031
|
+
diff()
|
|
4032
|
+
for (const wide of ['tall', 'wide', 'box']) {
|
|
4033
|
+
slots.forEach((x) => { x.innerHTML = big(x, wide) })
|
|
4034
|
+
diff()
|
|
4035
|
+
for (const one of slots.slice(0, 12)) {
|
|
4036
|
+
slots.forEach((x) => { x.innerHTML = x === one ? big(x, wide) : '' })
|
|
4037
|
+
diff()
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
} finally {
|
|
4041
|
+
slots.forEach((x, i) => { x.innerHTML = saved[i] })
|
|
4042
|
+
}
|
|
4043
|
+
const font = document.createElement('style')
|
|
4044
|
+
font.textContent = '[data-frame],[data-frame] *{font-family:monospace!important;letter-spacing:3px!important}'
|
|
4045
|
+
document.head.appendChild(font)
|
|
4046
|
+
try { diff(null, FONT_NAME_PROPS) } finally { font.remove() }
|
|
4047
|
+
const r = root.getBoundingClientRect()
|
|
4048
|
+
return {
|
|
4049
|
+
found: true,
|
|
4050
|
+
id: root.getAttribute('data-frame') || '',
|
|
4051
|
+
tag: root.tagName.toLowerCase(),
|
|
4052
|
+
sig: frameSig(root, 2),
|
|
4053
|
+
sv: 2,
|
|
4054
|
+
sig1: frameSig(root, 1),
|
|
4055
|
+
slots: [...root.querySelectorAll('[data-slot]')].map((x) => x.getAttribute('data-slot')),
|
|
4056
|
+
nested: [...root.querySelectorAll('[data-slot] [data-slot]')].map((x) => x.getAttribute('data-slot')),
|
|
4057
|
+
rect: { x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) },
|
|
4058
|
+
at: atOk ? at0 : null,
|
|
4059
|
+
// 外框里的 <details> 存的时候哪些是开着的(体检时按这个放回去量:用户点开菜单不算改了外框)
|
|
4060
|
+
od: (() => { const ds = [...root.querySelectorAll('details')].filter((d) => !d.closest('[data-slot]')); return ds.length ? ds.filter((d) => d.open).map((d) => framePath(root, d)) : null })(),
|
|
4061
|
+
// 外框里的 <dialog> 存的时候哪些开着(体检时开合跟这个不一样 = 用户开过 / 关过,这次不查样式)
|
|
4062
|
+
dl: (() => { const ds = [...root.querySelectorAll('dialog')].filter((d) => !d.closest('[data-slot]')); return ds.length ? ds.filter((d) => d.open).map((d) => framePath(root, d)) : null })(),
|
|
4063
|
+
probes: { p: FRAME_PROPS, e: els.map((el, i) => [framePath(root, el), base[i].map((x, k) => (drop[i][k] ? null : trOnly[i][k] ? `~${x}` : x))]) },
|
|
4064
|
+
refs: refDigests(els.map((el) => framePath(root, el))),
|
|
4065
|
+
}
|
|
4066
|
+
} finally {
|
|
4067
|
+
still.remove()
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
function frameCheck(add, kind) {
|
|
4071
|
+
const data = frameData()
|
|
4072
|
+
let root = frameRoot()
|
|
4073
|
+
if (!root && data && typeof data.id === 'string') {
|
|
4074
|
+
// 页面带着外框的指纹,槽位却全没了(或者根元素也没了):外框被改了
|
|
4075
|
+
root = [...document.querySelectorAll('[data-frame]')].find((x) => x.getAttribute('data-frame') === data.id) || null
|
|
4076
|
+
if (!root) { add('frame', null, { what: 'dom', frame: data.id, got: '' }, 2); return }
|
|
4077
|
+
}
|
|
4078
|
+
// DSH 自带外框(没有指纹那段)槽位全删了:按表里的 id 认出根
|
|
4079
|
+
if (!root) root = [...document.querySelectorAll('[data-frame]')].find((x) => Object.prototype.hasOwnProperty.call(FRAME_SIGS, x.getAttribute('data-frame'))) || null
|
|
3647
4080
|
if (!root) return
|
|
3648
|
-
const id = root.getAttribute('data-frame')
|
|
3649
|
-
|
|
3650
|
-
const
|
|
3651
|
-
if (
|
|
4081
|
+
const id = root.getAttribute('data-frame') || ''
|
|
4082
|
+
const known = Object.prototype.hasOwnProperty.call(FRAME_SIGS, id)
|
|
4083
|
+
const want = data ? data.sig : known ? FRAME_SIGS[id] : ''
|
|
4084
|
+
if (!want) { if (kind === 'framed' || kind === 'dshplugin') add('frame', root, { what: 'nosig', frame: id }, 1); return } // 别的类型的页面碰巧有 data-frame / data-slot:不管
|
|
4085
|
+
const got = frameSig(root, data && data.sv === 2 ? 2 : 1)
|
|
4086
|
+
if (got !== want || (data && data.id && data.id !== id)) { add('frame', root, { what: 'dom', frame: id, got }, 2); return }
|
|
4087
|
+
// 外框的样式文件、assets/(雪碧图、图、字体)被改了:和库里存的指纹对不上(读不到的不管:远程看时已经打包进页面)
|
|
4088
|
+
const ah = data && data.ah && typeof data.ah === 'object' && !Array.isArray(data.ah) ? data.ah : null
|
|
4089
|
+
if (ah) for (const [f, h] of Object.entries(ah).slice(0, 30)) {
|
|
4090
|
+
const g = typeof h === 'string' ? fileHash(f) : null
|
|
4091
|
+
if (g && g !== h) { add('frame', root, { what: 'asset', frame: id, got: f }, 2); return }
|
|
4092
|
+
}
|
|
4093
|
+
// 外框外面被引用的目标(CSS 里 filter / clip-path / fill: url(#x) 的那些):结构变了(滤镜参数、裁剪路径改了)或没了。
|
|
4094
|
+
// 和指纹一样是结构,鼠标停着、焦点在里面也查
|
|
4095
|
+
const rs = data && data.rs && typeof data.rs === 'object' && !Array.isArray(data.rs) ? data.rs : null
|
|
4096
|
+
if (rs) for (const [rid, h] of Object.entries(rs).slice(0, 40)) {
|
|
4097
|
+
if (typeof h === 'string' && fnv(refShape(rid, new Set())) !== h) { add('frame', root, { what: 'dom', frame: id, got: `#${rid}` }, 2); return }
|
|
4098
|
+
}
|
|
4099
|
+
if (data && data.probes && Array.isArray(data.probes.e)) {
|
|
4100
|
+
// 鼠标正停在外框上(槽位里也算:外框可能写了 .bar:hover)::hover 样式没法撤,这次不查样式,挪开再查
|
|
4101
|
+
const hov = [...document.querySelectorAll(':hover')].pop()
|
|
4102
|
+
if (hov && root.contains(hov)) return
|
|
4103
|
+
// 外框自己的原生弹层开着(popover 点开的气泡、对话框)、点了外框里的 #锚点(:target 切换):跟着用户点,这次不查样式
|
|
4104
|
+
const openLayer = (q) => { try { return root.matches(q) || [...root.querySelectorAll(q)].some((x) => !x.closest('[data-slot]')) } catch { return false } }
|
|
4105
|
+
if (openLayer(':popover-open') || openLayer(':modal') || openLayer(':target')) return
|
|
4106
|
+
const dlgs = [...root.querySelectorAll('dialog')].filter((d) => !d.closest('[data-slot]'))
|
|
4107
|
+
if (dlgs.length) {
|
|
4108
|
+
const was = new Set((Array.isArray(data.dl) ? data.dl : []).map((p) => byPath(root, p)))
|
|
4109
|
+
if (dlgs.some((d) => d.open !== was.has(d))) return
|
|
4110
|
+
}
|
|
4111
|
+
// 焦点在外框里(外框带 autofocus、用户点了外框的搜索框、或槽位里的输入框;外框可能写了 :focus-within):
|
|
4112
|
+
// 先移走焦点量默认样子,量完原样还回去(光标位置也还原)
|
|
4113
|
+
const ae = document.activeElement
|
|
4114
|
+
const fe = ae && root.contains(ae) ? ae : null // 根元素自己有焦点(tabindex + :focus)也算
|
|
4115
|
+
// 正在「直接改字」或在可编辑的地方打字:移走焦点会把半截字提交掉——这次不查样式,改完(写回文件、页面刷新)自然再查
|
|
4116
|
+
if (editing || composing || (fe && fe.isContentEditable)) return
|
|
4117
|
+
let sel = null
|
|
4118
|
+
if (fe) {
|
|
4119
|
+
try { if (typeof fe.selectionStart === 'number') sel = [fe.selectionStart, fe.selectionEnd, fe.selectionDirection] } catch { /* 不是文字框 */ }
|
|
4120
|
+
fe.blur()
|
|
4121
|
+
}
|
|
4122
|
+
// 外框自己的勾选框、单选、下拉被用户动过(input:checked + label 变色):先放回默认的样子量(存外框时量的就是默认样子),量完原样还回去。
|
|
4123
|
+
// 输入框里的字不动(改 value 会丢掉没打完的字和撤销记录)
|
|
4124
|
+
const mine = [...root.querySelectorAll('input[type="checkbox"], input[type="radio"], select')].filter((x) => !x.closest('[data-slot]'))
|
|
4125
|
+
// 单选按同组记:外框的单选放回默认会把同组(槽位里、外框外面的)选中的取消,这些也要原样还回去
|
|
4126
|
+
const ctl = mine.slice()
|
|
4127
|
+
for (const x of mine) {
|
|
4128
|
+
if (x.type !== 'radio' || !x.name) continue
|
|
4129
|
+
for (const y of document.querySelectorAll('input[type="radio"]')) if (y.name === x.name && y.form === x.form && !ctl.includes(y)) ctl.push(y)
|
|
4130
|
+
}
|
|
4131
|
+
const was = ctl.map((x) => (x.tagName === 'SELECT' ? [...x.options].map((o) => o.selected) : { c: x.checked, i: x.indeterminate }))
|
|
4132
|
+
// 外框里的 <details>(用户点开了菜单):按存外框时开没开放回去,查完还原
|
|
4133
|
+
// 同名的 <details name="g">(手风琴:开一个关别的)槽位里、外框外面的也一起记,查完先关后开还回去
|
|
4134
|
+
const dets = Array.isArray(data.od) ? [...root.querySelectorAll('details')].filter((d) => !d.closest('[data-slot]')) : []
|
|
4135
|
+
const detAll = dets.slice()
|
|
4136
|
+
for (const d of dets) { const n = d.getAttribute('name'); if (n) for (const y of document.querySelectorAll('details')) if (y.getAttribute('name') === n && !detAll.includes(y)) detAll.push(y) }
|
|
4137
|
+
const odSet = new Set((Array.isArray(data.od) ? data.od : []).map((p) => byPath(root, p)))
|
|
4138
|
+
const detWas = detAll.map((d) => d.open)
|
|
4139
|
+
try {
|
|
4140
|
+
dets.forEach((d) => { const w = odSet.has(d); if (d.open !== w) d.open = w })
|
|
4141
|
+
for (const x of mine) {
|
|
4142
|
+
if (x.tagName === 'SELECT') { for (const o of x.options) o.selected = o.defaultSelected; continue }
|
|
4143
|
+
if (x.type === 'checkbox' || x.type === 'radio') { x.indeterminate = false; x.checked = x.defaultChecked }
|
|
4144
|
+
}
|
|
4145
|
+
frameStyle(add, root, data, id)
|
|
4146
|
+
} finally {
|
|
4147
|
+
try {
|
|
4148
|
+
// 单选先还没选的、再还选中的(选中一个会把同组别的取消)
|
|
4149
|
+
const order = ctl.map((x, i) => i).sort((a, b) => Number(!!(was[b] && was[b].c === false)) - Number(!!(was[a] && was[a].c === false)))
|
|
4150
|
+
for (const i of order) {
|
|
4151
|
+
const x = ctl[i], w = was[i]
|
|
4152
|
+
if (x.tagName === 'SELECT') { [...x.options].forEach((o, k) => { o.selected = !!w[k] }); continue }
|
|
4153
|
+
if (x.type === 'checkbox' || x.type === 'radio') { x.checked = w.c; x.indeterminate = w.i }
|
|
4154
|
+
}
|
|
4155
|
+
} catch { /* 还不回去就算了 */ }
|
|
4156
|
+
detAll.forEach((d, i) => { if (!detWas[i] && d.open) d.open = false })
|
|
4157
|
+
detAll.forEach((d, i) => { if (detWas[i] && !d.open) d.open = true })
|
|
4158
|
+
if (fe) { try { fe.focus({ preventScroll: true }); if (sel) fe.setSelectionRange(sel[0], sel[1], sel[2] || 'none') } catch { /* 还不回去就算了 */ } }
|
|
4159
|
+
}
|
|
4160
|
+
return
|
|
4161
|
+
}
|
|
4162
|
+
if (!known) return
|
|
4163
|
+
frameDshProbes(add, root, id)
|
|
4164
|
+
}
|
|
4165
|
+
/** 外框库的外框:样式样本逐个对(存外框时记下的浅色、深色几套) */
|
|
4166
|
+
function frameStyle(add, root, data, id) {
|
|
4167
|
+
{
|
|
4168
|
+
const props = Array.isArray(data.probes.p) ? data.probes.p : FRAME_PROPS
|
|
4169
|
+
// 存的时候值去了重放进表 v,元素那里记的是表里第几个(-1 = 跟着内容变、不查)
|
|
4170
|
+
const table = Array.isArray(data.probes.v) ? data.probes.v : null
|
|
4171
|
+
// 末尾截掉的(没画伪元素那一大段)补回 NO_PSEUDO:不是「不查」
|
|
4172
|
+
const val = (i) => (typeof i === 'number' && i >= 0 ? table[i] : null)
|
|
4173
|
+
const dec = (a) => (table && Array.isArray(a) ? props.map((_, k) => (k >= a.length ? NO_PSEUDO : val(a[k]))) : a)
|
|
4174
|
+
// {第几个: 值} 是「和 base 一样,只有这几个不同」(浅色的 base 是上一个元素的浅色,深色的是自己的浅色)
|
|
4175
|
+
const decAny = (a, base) => (Array.isArray(a) ? dec(a) : table && a && typeof a === 'object' && Array.isArray(base) ? base.map((x, k) => (Object.prototype.hasOwnProperty.call(a, k) ? val(a[k]) : x)) : null)
|
|
4176
|
+
const rows = []
|
|
4177
|
+
let prevLv = null
|
|
4178
|
+
for (const [path, light, ...darkSets] of data.probes.e) {
|
|
4179
|
+
const lv = decAny(light, prevLv)
|
|
4180
|
+
if (Array.isArray(lv)) prevLv = lv
|
|
4181
|
+
rows.push([path, lv, darkSets.map((d) => decAny(d, lv)).filter(Array.isArray)])
|
|
4182
|
+
}
|
|
4183
|
+
// 刚切深色、颜色还在过渡:直接跳到过渡完(看着没区别);还在播的动画(和它里面继承颜色的)量到的是半截的值,这次不查
|
|
4184
|
+
const moving = []
|
|
4185
|
+
// 整页的(body 淡入、根元素滑入这种上层的动画也算)
|
|
4186
|
+
for (const a of typeof document.getAnimations === 'function' ? document.getAnimations() : []) {
|
|
4187
|
+
if (a.playState === 'finished') continue // 播完停在最后一帧的(入场动画)照查:存外框时量的也是播完的样子
|
|
4188
|
+
if (typeof CSSTransition === 'function' && a instanceof CSSTransition) { try { a.finish(); continue } catch { /* 下面当成还在动 */ } }
|
|
4189
|
+
if (a.effect && a.effect.target) moving.push(a.effect.target)
|
|
4190
|
+
}
|
|
4191
|
+
moving.push(...smilTargets())
|
|
4192
|
+
const isMoving = (el) => moving.some((m) => m === el || (m.contains && m.contains(el)))
|
|
4193
|
+
|
|
4194
|
+
// mode:'light' 只认浅色;'dark' 深色那几种(真深色媒体 / 浅色系统上切深色)哪种对上都行;'either' 浅色深色都行
|
|
4195
|
+
const miss = (mode) => {
|
|
4196
|
+
for (const [path, lv, ds0] of rows) {
|
|
4197
|
+
const ds = ds0.slice()
|
|
4198
|
+
if (!ds.length) ds.push(lv)
|
|
4199
|
+
const sets = mode === 'light' ? [lv] : mode === 'dark' ? ds : isDark ? [...ds, lv] : [lv, ...ds]
|
|
4200
|
+
const vals = sets[0]
|
|
4201
|
+
const el = byPath(root, path)
|
|
4202
|
+
// 外框外面被引用的图标 / 渐变 / 裁剪(按 id 记的)整个没了:CSS 里 fill: url(#x) 引用的删了也算
|
|
4203
|
+
if (!el && Array.isArray(path) && typeof path[0] === 'string' && path[0].startsWith('#')) return { gone: path[0] }
|
|
4204
|
+
if (!el || el.hasAttribute('data-slot') || !Array.isArray(vals)) continue
|
|
4205
|
+
if (moving.length && isMoving(el)) continue
|
|
4206
|
+
const cs = getComputedStyle(el), pcs = {}
|
|
4207
|
+
for (let i = 0; i < props.length; i++) {
|
|
4208
|
+
const v = frameVal(el, cs, props[i], pcs)
|
|
4209
|
+
if (sets.some((x) => !Array.isArray(x) || typeof x[i] !== 'string' || sameVal(props[i], v, x[i]))) continue
|
|
4210
|
+
return { el, prop: props[i], want: vals[i], got: v }
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
return null
|
|
4214
|
+
}
|
|
4215
|
+
// 按现在是深色还是浅色对:页面上写明了(data-theme / data-mode / class dark)就只认那一套;
|
|
4216
|
+
// 没写、系统是深色时说不准外框跟不跟系统(有的只认 data-theme)→ 哪套全对上都行
|
|
4217
|
+
const de = document.documentElement
|
|
4218
|
+
const attr = de.getAttribute('data-theme') || de.getAttribute('data-mode') || ''
|
|
4219
|
+
const darkSaid = attr === 'dark' || de.classList.contains('dark')
|
|
4220
|
+
const lightSaid = attr === 'light' || de.classList.contains('light')
|
|
4221
|
+
const sysDark = !darkSaid && !lightSaid && typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: dark)').matches
|
|
4222
|
+
const hasDarkSet = rows.some((x) => x[2].length > 0)
|
|
4223
|
+
const isDark = darkSaid || sysDark
|
|
4224
|
+
// 说不准时每个值浅色深色哪套对上都行:系统深色、页面没写明;外框自己没写深色(深色那套是 color-scheme:dark 下量的,页面自己写 data-theme="dark" 时不一定有)
|
|
4225
|
+
const loose = hasDarkSet && (sysDark || (data.fd === 1 && isDark))
|
|
4226
|
+
const bad = miss(loose ? 'either' : isDark ? 'dark' : 'light')
|
|
4227
|
+
if (bad && bad.gone) add('frame', root, { what: 'dom', frame: id, got: bad.gone }, 2)
|
|
4228
|
+
else if (bad) add('frame', bad.el, { what: 'style', frame: id, sel: cssPath(bad.el), prop: bad.prop, want: bad.want, got: bad.got }, 2)
|
|
4229
|
+
else if (Array.isArray(data.at) && data.at.length === 2 && !moving.some((m) => m === root || (m.contains && m.contains(root)))) {
|
|
4230
|
+
// 整个外框挪了位置(插件写 body { padding / margin }、在外框前面塞了东西)
|
|
4231
|
+
const a = frameAt(root)
|
|
4232
|
+
if (Math.abs(a[0] - data.at[0]) > 2 || Math.abs(a[1] - data.at[1]) > 2) add('frame', root, { what: 'style', frame: id, sel: cssPath(root), prop: '位置(左上角)', want: `x ${data.at[0]}, y ${data.at[1]}`, got: `x ${a[0]}, y ${a[1]}` }, 2)
|
|
4233
|
+
}
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
/** DSH 自带外框(0.22.0–0.23.1 的设计,页面里没有样本):按 FRAME_PROBES 那几处查 */
|
|
4237
|
+
function frameDshProbes(add, root, id) {
|
|
3652
4238
|
const dark = document.documentElement.getAttribute('data-theme') === 'dark'
|
|
3653
4239
|
for (const [sel, prop, light, darkV] of FRAME_PROBES) {
|
|
3654
4240
|
const el = [root, ...root.querySelectorAll(sel)].find((x) => x.matches(sel) && !x.closest('[data-slot]')) // 只量外框自己的(槽位里插件也可能用同名类)
|
|
3655
4241
|
if (!el) continue
|
|
3656
|
-
const
|
|
4242
|
+
const want2 = dark && darkV ? darkV : light
|
|
3657
4243
|
const v = getComputedStyle(el).getPropertyValue(prop)
|
|
3658
|
-
if (v !==
|
|
4244
|
+
if (v !== want2) { add('frame', el, { what: 'style', frame: id, sel, prop, want: want2, got: v }, 2); return }
|
|
3659
4245
|
}
|
|
3660
4246
|
}
|
|
3661
4247
|
|
|
@@ -4814,7 +5400,10 @@ background:rgba(20,20,22,.86);color:#e8e8ea;font:12px/18px -apple-system,system-
|
|
|
4814
5400
|
const r = runCheck(String(kind || 'web'))
|
|
4815
5401
|
return { issues: r.issues.map(({ el, ...rest }) => rest), metrics: r.metrics }
|
|
4816
5402
|
},
|
|
4817
|
-
dark: (on) => { const has = hasDark(); if (has) setDark(!!on); return has },
|
|
5403
|
+
dark: (on, force) => { const has = hasDark(); if (has || force || !on) setDark(!!on); return has }, // force:没写深色也切(存外框时量 color-scheme:dark 下的样子)
|
|
5404
|
+
/** 存外框用:外框的 id、指纹、槽位、几处样式(现在的深浅色下) */
|
|
5405
|
+
frameInfo: (paths) => frameInfo(paths),
|
|
5406
|
+
framePaths: () => framePaths(),
|
|
4818
5407
|
capsule: (how) => showCapsule(how),
|
|
4819
5408
|
winctl: (how) => showWinCtl(how),
|
|
4820
5409
|
/** 调节滑块的值套到页面上(和右侧栏拖的时候一样) */
|