Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(turnrewind): emit px units in css-render trees (root cause of the square card)

yingtianlandf78137d36bb
diff --git a/.gitignore b/.gitignore
index e3510c31..0b7c5ecf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,7 +18,8 @@ release-msi-version.tmp.json
skills
.serena
.cargo/config.toml
-# 参考源码克隆(如 source/dsh-automation),不作为本仓库内容提交
+# 参考源码克隆(�?source/dsh-automation),不作为本仓库内容提交
source/
.gitmodules
-.tmp-alpha-inspect.playwright-cli/
+.tmp-alpha-inspect
+.playwright-cli/
diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/styles/command-view.ts b/packages/dsh-tauri-turnrewind-ts/src/client/styles/command-view.ts
index 18ce69a4..afafc069 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/client/styles/command-view.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/client/styles/command-view.ts
@@ -13,27 +13,28 @@ let cardCssr: ReturnType<typeof CssRender> | undefined
const P = TURNREWIND_CLASS_PREFIX
-/** 挂载 undo 卡片样式,返回 disposer。 */
-export function mountCommandViewStyles(): () => void {
- const cssr = cardCssr ??= CssRender()
- const styleId = `${TURNREWIND_STYLE_ID}-command-view`
- if (typeof document !== 'undefined' && document.getElementById(styleId) !== null)
- return () => {}
-
- const style = cardCssr.c([
+/**
+ * 构建 undo 卡片样式节点。独立导出供测试渲染断言:css-render 不会给数字
+ * 自动补 px,这里所有尺寸必须是带单位字符串(曾因裸数字导致 gap /
+ * border-radius / font-size 全部失效)。
+ */
+export function buildCommandViewStyleNodes(cssr: ReturnType<typeof CssRender>) {
+ return cssr.c([
// 折叠态:无边框原生风格行
+ // 注意:css-render 不会给数字自动补 px,所有尺寸必须写成带单位字符串,
+ // 否则生成非法声明被浏览器丢弃(gap/border-radius/font-size 曾因此全部失效)。
cssr.c(`.${P}-card`, {
display: 'flex',
alignItems: 'center',
- gap: 6,
+ gap: '6px',
padding: '2px 12px 2px 4px',
margin: '2px 0 2px 4px',
- fontSize: 13,
+ fontSize: '13px',
}),
cssr.c(`.${P}-card-header`, {
display: 'flex',
alignItems: 'center',
- gap: 8,
+ gap: '8px',
width: '100%',
textAlign: 'left',
background: 'transparent',
@@ -41,7 +42,7 @@ export function mountCommandViewStyles(): () => void {
cursor: 'pointer',
padding: '8px 12px',
color: 'var(--dsw-alias-label-primary, #cccccc)',
- fontSize: 13,
+ fontSize: '13px',
}),
cssr.c(`.${P}-card-caret`, {
transform: 'rotate(0deg)',
@@ -100,22 +101,22 @@ export function mountCommandViewStyles(): () => void {
}),
// 展开态容器:diff 面板(圆角对齐 DSH 原生嵌入卡片档位:.dpte-card 10px)
cssr.c(`.${P}-panel`, {
- marginTop: 8,
+ marginTop: '8px',
border: '1px solid var(--dsw-alias-border-l2, #30363d)',
- borderRadius: 10,
+ borderRadius: '10px',
overflow: 'hidden',
background: 'var(--dsw-alias-bg-layer-2, #161b22)',
}),
cssr.c(`.${P}-panel-file`, {
display: 'flex',
- gap: 8,
+ gap: '8px',
padding: '2px 0',
fontFamily: 'var(--ds-font-family-code, monospace)',
- fontSize: 12,
+ fontSize: '12px',
}),
cssr.c(`.${P}-panel-file-change`, {
color: 'var(--dsw-alias-label-tertiary, #8b8b8b)',
- width: 64,
+ width: '64px',
flex: 'none',
}),
cssr.c(`.${P}-panel-file-path`, {
@@ -125,7 +126,7 @@ export function mountCommandViewStyles(): () => void {
whiteSpace: 'nowrap',
}),
cssr.c(`.${P}-panel-diff`, {
- maxHeight: 260,
+ maxHeight: '260px',
overflowY: 'auto',
padding: '3px 0',
borderTop: '1px solid var(--dsw-alias-border-l2, #30363d)',
@@ -136,10 +137,10 @@ export function mountCommandViewStyles(): () => void {
// 数字徽标
cssr.c(`.${P}-numbadge`, {
display: 'inline-flex',
- gap: 6,
+ gap: '6px',
flex: 'none',
fontFamily: 'var(--ds-font-family-code, monospace)',
- fontSize: 11,
+ fontSize: '11px',
}),
cssr.c(`.${P}-numbadge-add`, {
color: 'var(--dsw-alias-state-success-primary, #3fb950)',
@@ -151,12 +152,12 @@ export function mountCommandViewStyles(): () => void {
cssr.c(`.${P}-diffline`, {
display: 'flex',
fontFamily: 'var(--ds-font-family-code, monospace)',
- fontSize: 12,
+ fontSize: '12px',
lineHeight: 1.5,
whiteSpace: 'pre-wrap',
}),
cssr.c(`.${P}-diffline-sign`, {
- width: 14,
+ width: '14px',
flex: 'none',
textAlign: 'center',
}),
@@ -184,7 +185,7 @@ export function mountCommandViewStyles(): () => void {
cssr.c(`.${P}-card-actions`, {
display: 'flex',
alignItems: 'center',
- gap: 8,
+ gap: '8px',
padding: '6px 12px 10px',
borderTop: '1px solid var(--dsw-alias-border-l2, #30363d)',
}),
@@ -192,26 +193,36 @@ export function mountCommandViewStyles(): () => void {
background: 'var(--dsw-alias-button-primary-fill, #2ea043)',
color: 'var(--dsw-alias-label-primary-foreground, #ffffff)',
border: 'none',
- borderRadius: 6,
+ borderRadius: '6px',
padding: '4px 14px',
- fontSize: 12,
+ fontSize: '12px',
cursor: 'pointer',
}),
cssr.c(`.${P}-card-cancel`, {
background: 'transparent',
color: 'var(--dsw-alias-label-secondary, #cccccc)',
border: '1px solid var(--dsw-alias-border-l2, #30363d)',
- borderRadius: 6,
+ borderRadius: '6px',
padding: '4px 14px',
- fontSize: 12,
+ fontSize: '12px',
cursor: 'pointer',
}),
cssr.c(`.${P}-card-result`, {
padding: '6px 12px 10px',
color: 'var(--dsw-alias-label-secondary, #cccccc)',
- fontSize: 12,
+ fontSize: '12px',
}),
])
+}
+
+/** 挂载 undo 卡片样式,返回 disposer。 */
+export function mountCommandViewStyles(): () => void {
+ const cssr = cardCssr ??= CssRender()
+ const styleId = `${TURNREWIND_STYLE_ID}-command-view`
+ if (typeof document !== 'undefined' && document.getElementById(styleId) !== null)
+ return () => {}
+
+ const style = buildCommandViewStyleNodes(cssr)
style.mount({ id: styleId, head: true })
return () => style.unmount({ id: styleId })
}
diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/styles/index.ts b/packages/dsh-tauri-turnrewind-ts/src/client/styles/index.ts
index 808faccc..d8a5909f 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/client/styles/index.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/client/styles/index.ts
@@ -22,13 +22,9 @@ function ensureDialogCssr(): ReturnType<typeof CssRender> {
}
/** 挂载不可用弹窗样式,返回 disposer。 */
-export function mountDialogStyles(): () => void {
- const cssr = ensureDialogCssr()
+export function buildDialogStyleNodes(cssr: ReturnType<typeof CssRender>) {
const p = TURNREWIND_CLASS_PREFIX
- const styleId = `${TURNREWIND_STYLE_ID}-dialog`
- if (typeof document !== 'undefined' && document.getElementById(styleId) !== null)
- return () => {}
- const style = cssr.c([
+ return cssr.c([
cssr.c(`.${p}-dialog-backdrop`, {
display: 'none',
position: 'fixed',
@@ -97,6 +93,15 @@ export function mountDialogStyles(): () => void {
background: 'var(--dsw-alias-button-primary-hover, #4338ca)',
}),
])
+}
+
+/** 挂载不可用弹窗样式,返回 disposer。 */
+export function mountDialogStyles(): () => void {
+ const styleId = `${TURNREWIND_STYLE_ID}-dialog`
+ if (typeof document !== 'undefined' && document.getElementById(styleId) !== null)
+ return () => {}
+ const cssr = ensureDialogCssr()
+ const style = buildDialogStyleNodes(cssr)
style.mount({ id: styleId, head: true })
return () => style.unmount({ id: styleId })
}
diff --git a/packages/dsh-tauri-turnrewind-ts/test/styles.test.js b/packages/dsh-tauri-turnrewind-ts/test/styles.test.js
new file mode 100644
index 00000000..ec1392fd
--- /dev/null
+++ b/packages/dsh-tauri-turnrewind-ts/test/styles.test.js
@@ -0,0 +1,50 @@
+import assert from 'node:assert/strict'
+import { CssRender } from 'dsh-tauri/client'
+import { it } from 'vitest'
+import { buildDialogStyleNodes } from '../src/client/styles'
+import { buildCommandViewStyleNodes } from '../src/client/styles/command-view'
+
+/** css-render 不给数字补 px:裸数字会生成非法声明并被浏览器静默丢弃。 */
+const UNITLESS = new Set([
+ 'flex',
+ 'opacity',
+ 'font-weight',
+ 'line-height',
+ 'z-index',
+ 'order',
+ 'zoom',
+ 'min-width',
+ 'column-count',
+ 'inset',
+])
+
+function assertNoBareNumbers(css, label) {
+ for (const match of css.matchAll(/([a-z-]+)\s*:\s*([^;{}]+)/g)) {
+ const prop = match[1]
+ const value = match[2].trim()
+ if (UNITLESS.has(prop))
+ continue
+ assert.doesNotMatch(
+ value,
+ /^\d+(\.\d+)?$/,
+ `${label}: ${prop}: ${value} is a bare number — css-render will not append px and the browser drops the declaration`,
+ )
+ }
+}
+
+it('renders command-view styles with explicit px units', () => {
+ const css = buildCommandViewStyleNodes(CssRender()).render()
+ assertNoBareNumbers(css, 'command-view')
+ // The dimensional properties that silently failed before the fix.
+ assert.match(css, /gap:\s*8px/u)
+ assert.match(css, /border-radius:\s*10px/u)
+ assert.match(css, /font-size:\s*12px/u)
+ assert.match(css, /max-height:\s*260px/u)
+})
+
+it('renders dialog styles with explicit px units', () => {
+ const css = buildDialogStyleNodes(CssRender()).render()
+ assertNoBareNumbers(css, 'dialog')
+ assert.match(css, /border-radius:\s*12px/u)
+ assert.match(css, /max-height:\s*160px/u)
+})