dsh-ui-smooth 0.1.0 → 0.1.1

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/src/settings.js CHANGED
@@ -1,183 +1,201 @@
1
- /**
2
- * The 流畅性 settings panel.
3
- *
4
- * Rendered into the app's own settings section slot, so it inherits the shell's
5
- * tokens and needs no portal of its own. Every switch here maps to one field of
6
- * the shared config, and each card states what the switch does to the page.
7
- */
8
-
9
- const react = require('react')
10
- const h = react.createElement
11
-
12
- const { VERSION, cloneConfig, desktop, getConfig, hostElectron, onConfig, saveConfig } = require('./config.js')
13
-
14
- function Switch({ checked, disabled, onChange }) {
15
- return h('button', {
16
- type: 'button',
17
- role: 'switch',
18
- 'aria-checked': checked ? 'true' : 'false',
19
- disabled: disabled === true,
20
- className: `uis-switch${checked ? ' is-on' : ''}`,
21
- onClick: () => onChange(!checked)
22
- }, h('span', { className: 'uis-knob' }))
23
- }
24
-
25
- function NumberField({ value, min, max, suffix, onChange }) {
26
- return h('label', { className: 'uis-number' },
27
- h('input', {
28
- type: 'number',
29
- value: String(value),
30
- min: String(min),
31
- max: String(max),
32
- onChange: (event) => {
33
- const next = Number(event.target.value)
34
- if (!Number.isFinite(next)) return
35
- onChange(Math.min(max, Math.max(min, Math.floor(next))))
36
- }
37
- }),
38
- suffix !== undefined ? h('span', { className: 'uis-suffix' }, suffix) : null
39
- )
40
- }
41
-
42
- function Card({ title, hint, control, children }) {
43
- return h('div', { className: 'uis-card' }, [
44
- h('div', { className: 'uis-row' }, [
45
- h('div', { className: 'uis-text' }, [
46
- h('div', { className: 'uis-title' }, title),
47
- hint === undefined ? null : h('div', { className: 'uis-hint' }, hint)
48
- ]),
49
- control
50
- ]),
51
- children === undefined ? null : h('div', { className: 'uis-thresholds' }, children)
52
- ])
53
- }
54
-
55
- function SettingsSection() {
56
- const [state, setState] = react.useState(getConfig)
57
- const electron = hostElectron() || desktop()
58
- react.useEffect(() => onConfig((next) => setState(cloneConfig(next))), [])
59
-
60
- const patch = (next) => {
61
- saveConfig(next)
62
- setState((current) => cloneConfig({ ...current, ...next }))
63
- }
64
- const patchTier = (key, changes) => patch({ [key]: { ...state[key], ...changes } })
65
- const toggle = (key) => h(Switch, {
66
- checked: state[key],
67
- onChange: (checked) => patch({ [key]: checked })
68
- })
69
-
70
- return h('div', { className: 'uis-section' }, [
71
- h('div', { className: 'uis-head' }, [
72
- h('span', { className: 'uis-brand' }, 'DSH-UI-Smooth'),
73
- h('span', { className: 'uis-version' }, `v${VERSION}`)
74
- ]),
75
- h(Card, {
76
- title: '启用动画优化',
77
- hint: '降低无限循环动画布局/重绘次数。DSH 已经对自身的旧动画进行了优化,此项主要解决其他插件/后续引入的动画每帧布局/重绘问题。',
78
- control: toggle('animations')
79
- }),
80
-
81
- h(Card, {
82
- title: '后台节流',
83
- hint: electron
84
- ? '当关闭后 DSH 不是前台窗口时仍然保持界面照常推进,这样的好处是可以在切换回前台窗口时不用一次性加载积压的内容,保证观感流畅。'
85
- : '当关闭后 DSH 不是前台窗口时仍然保持界面照常推进,这样的好处是可以在切换回前台窗口时不用一次性加载积压的内容,保证观感流畅。该项仅在 Electron 壳的桌面端有效。',
86
- control: h(Switch, {
87
- checked: state.backgroundThrottle,
88
- disabled: !electron,
89
- onChange: (checked) => patch({ backgroundThrottle: checked })
90
- })
91
- }),
92
-
93
- h(Card, {
94
- title: '流式输出期间回收',
95
- hint: '在流式输出期间仍按下方阈值处理。',
96
- control: toggle('duringStream')
97
- }),
98
-
99
- h(Card, {
100
- title: '旧轮次跳过渲染',
101
- hint: '当满足以下设置条件时,将不再渲染该条目的子树,在滚动接近时恢复渲染。',
102
- control: h(Switch, {
103
- checked: state.skip.enabled,
104
- onChange: (checked) => patchTier('skip', { enabled: checked })
105
- }),
106
- children: [
107
- h(NumberField, {
108
- value: state.skip.turns, min: 1, max: 200, suffix: '轮以前',
109
- onChange: (turns) => patchTier('skip', { turns })
110
- }),
111
- h('span', { className: 'uis-label' }, '且'),
112
- h(NumberField, {
113
- value: state.skip.minutes, min: 1, max: 1440, suffix: '分钟未查看',
114
- onChange: (minutes) => patchTier('skip', { minutes })
115
- })
116
- ]
117
- }),
118
-
119
- h(Card, {
120
- title: '旧轮次从文档流摘除',
121
- hint: '当满足以下设置条件时,将条目从文档流摘除,在滚动接近时重新填入。',
122
- control: h(Switch, {
123
- checked: state.unmount.enabled,
124
- onChange: (checked) => patchTier('unmount', { enabled: checked })
125
- }),
126
- children: [
127
- h(NumberField, {
128
- value: state.unmount.turns, min: 1, max: 500, suffix: '轮以前',
129
- onChange: (turns) => patchTier('unmount', { turns })
130
- }),
131
- h('span', { className: 'uis-label' }, '且'),
132
- h(NumberField, {
133
- value: state.unmount.minutes, min: 1, max: 4320, suffix: '分钟未查看',
134
- onChange: (minutes) => patchTier('unmount', { minutes })
135
- })
136
- ]
137
- }),
138
-
139
- h(Card, {
140
- title: '激进策略:旧轮次从内存卸载',
141
- hint: '当满足以下设置条件时,将条目从内存卸载,重新加载需要从硬盘获取。',
142
- control: h(Switch, {
143
- checked: state.release.enabled,
144
- onChange: (checked) => patch({ release: { ...state.release, enabled: checked } })
145
- }),
146
- children: [
147
- h(NumberField, {
148
- value: state.release.turns, min: 2, max: 500, suffix: '轮以前',
149
- onChange: (turns) => patch({ release: { ...state.release, turns } })
150
- }),
151
- h('span', { className: 'uis-label' }, '且重新加载后'),
152
- h(NumberField, {
153
- value: state.release.minutes, min: 1, max: 4320, suffix: '分钟未查看',
154
- onChange: (minutes) => patch({ release: { ...state.release, minutes } })
155
- })
156
- ]
157
- })
158
- ])
159
- }
160
-
161
- const SETTINGS_CSS = `
162
- .uis-section { display: flex; flex-direction: column; gap: 12px; font-size: 13px; color: var(--dsw-alias-label-primary, inherit); }
163
- .uis-head { display: flex; align-items: baseline; gap: 8px; }
164
- .uis-brand { font-weight: 600; letter-spacing: .01em; }
165
- .uis-version { color: var(--dsw-alias-label-tertiary, inherit); font-family: var(--dsw-font-mono, ui-monospace, monospace); font-size: 12px; }
166
- .uis-card { border: 1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.24)); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
167
- .uis-row { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; }
168
- .uis-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
169
- .uis-title { font-weight: 600; }
170
- .uis-hint { color: var(--dsw-alias-label-tertiary, inherit); line-height: 1.5; }
171
- .uis-thresholds { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--dsw-alias-label-secondary, inherit); }
172
- .uis-label { white-space: nowrap; }
173
- .uis-number { display: inline-flex; align-items: center; gap: 4px; }
174
- .uis-number input { width: 62px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.32)); background: var(--dsw-alias-fill-secondary, transparent); color: inherit; font: inherit; }
175
- .uis-suffix { color: var(--dsw-alias-label-tertiary, inherit); white-space: nowrap; }
176
- .uis-switch { width: 38px; height: 22px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.32)); background: var(--dsw-alias-fill-secondary, rgba(127,127,127,.2)); padding: 2px; cursor: pointer; flex: none; transition: background .15s ease; }
177
- .uis-switch.is-on { background: var(--dsw-alias-state-success-primary, #3b82f6); border-color: transparent; }
178
- .uis-switch:disabled { opacity: .5; cursor: not-allowed; }
179
- .uis-knob { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s ease; }
180
- .uis-switch.is-on .uis-knob { transform: translateX(16px); }
181
- `
182
-
183
- module.exports = { SETTINGS_CSS, SettingsSection }
1
+ /**
2
+ * The 流畅性 settings panel.
3
+ *
4
+ * Rendered into the app's own settings section slot, so it inherits the shell's
5
+ * tokens and needs no portal of its own. Every switch here maps to one field of
6
+ * the shared config, and each card states what the switch does to the page.
7
+ */
8
+
9
+ const react = require('react')
10
+ const h = react.createElement
11
+
12
+ const { VERSION, cloneConfig, getConfig, onConfig, saveConfig } = require('./config.js')
13
+
14
+ function Switch({ checked, disabled, onChange }) {
15
+ return h('button', {
16
+ type: 'button',
17
+ role: 'switch',
18
+ 'aria-checked': checked ? 'true' : 'false',
19
+ disabled: disabled === true,
20
+ className: `uis-switch${checked ? ' is-on' : ''}`,
21
+ onClick: () => onChange(!checked)
22
+ }, h('span', { className: 'uis-knob' }))
23
+ }
24
+
25
+ function NumberField({ value, min, max, suffix, onChange }) {
26
+ return h('label', { className: 'uis-number' },
27
+ h('input', {
28
+ type: 'number',
29
+ value: String(value),
30
+ min: String(min),
31
+ max: String(max),
32
+ onChange: (event) => {
33
+ const next = Number(event.target.value)
34
+ if (!Number.isFinite(next)) return
35
+ onChange(Math.min(max, Math.max(min, Math.floor(next))))
36
+ }
37
+ }),
38
+ suffix !== undefined ? h('span', { className: 'uis-suffix' }, suffix) : null
39
+ )
40
+ }
41
+
42
+ function Card({ title, hint, control, children }) {
43
+ return h('div', { className: 'uis-card' }, [
44
+ h('div', { className: 'uis-row' }, [
45
+ h('div', { className: 'uis-text' }, [
46
+ h('div', { className: 'uis-title' }, title),
47
+ hint === undefined ? null : h('div', { className: 'uis-hint' }, hint)
48
+ ]),
49
+ control
50
+ ]),
51
+ children === undefined ? null : h('div', { className: 'uis-thresholds' }, children)
52
+ ])
53
+ }
54
+
55
+ function Group({ title, children }) {
56
+ return h('div', { className: 'uis-group' }, [
57
+ h('div', { className: 'uis-group-title' }, title),
58
+ ...children
59
+ ])
60
+ }
61
+
62
+ function SettingsSection() {
63
+ const [state, setState] = react.useState(getConfig)
64
+ react.useEffect(() => onConfig((next) => setState(cloneConfig(next))), [])
65
+
66
+ const patch = (next) => {
67
+ saveConfig(next)
68
+ setState((current) => cloneConfig({ ...current, ...next }))
69
+ }
70
+ const patchTier = (key, changes) => patch({ [key]: { ...state[key], ...changes } })
71
+ const toggle = (key) => h(Switch, {
72
+ checked: state[key],
73
+ onChange: (checked) => patch({ [key]: checked })
74
+ })
75
+
76
+ return h('div', { className: 'uis-section' }, [
77
+ h('div', { className: 'uis-head' }, [
78
+ h('span', { className: 'uis-brand' }, 'DSH-UI-Smooth'),
79
+ h('span', { className: 'uis-version' }, `v${VERSION}`)
80
+ ]),
81
+
82
+ h(Group, { title: '渲染' }, [
83
+ h(Card, {
84
+ title: '启用动画优化',
85
+ hint: '降低无限循环动画布局/重绘次数。DSH 已经对自身的旧动画进行了优化,此项主要解决其他插件/后续引入的动画每帧布局/重绘问题。',
86
+ control: toggle('animations')
87
+ })
88
+ ]),
89
+
90
+ h(Group, { title: '前台与后台' }, [
91
+ h(Card, {
92
+ title: '后台节流',
93
+ hint: '当关闭后 DSH 不是前台窗口时仍然保持界面照常推进,这样的好处是可以在切换回前台窗口时不用一次性加载积压的内容,保证观感流畅。',
94
+ control: h(Switch, {
95
+ checked: state.backgroundThrottle,
96
+ onChange: (checked) => patch({ backgroundThrottle: checked })
97
+ })
98
+ }),
99
+ h(Card, {
100
+ title: '切回前台滚动到最新',
101
+ hint: '切出前停在对话最底部时,切回前台后自动滚动到最新内容;切出前正在翻看历史时保持原位置不动。',
102
+ control: toggle('follow')
103
+ })
104
+ ]),
105
+
106
+ h(Group, { title: '旧轮次回收' }, [
107
+ h(Card, {
108
+ title: '流式输出期间回收',
109
+ hint: '在流式输出期间仍按下方阈值处理。',
110
+ control: toggle('duringStream')
111
+ }),
112
+
113
+ h(Card, {
114
+ title: '旧轮次跳过渲染',
115
+ hint: '当满足以下设置条件时,将不再渲染该条目的子树,在滚动接近时恢复渲染。',
116
+ control: h(Switch, {
117
+ checked: state.skip.enabled,
118
+ onChange: (checked) => patchTier('skip', { enabled: checked })
119
+ }),
120
+ children: [
121
+ h(NumberField, {
122
+ value: state.skip.turns, min: 1, max: 200, suffix: '轮以前',
123
+ onChange: (turns) => patchTier('skip', { turns })
124
+ }),
125
+ h('span', { className: 'uis-label' }, '且'),
126
+ h(NumberField, {
127
+ value: state.skip.minutes, min: 1, max: 1440, suffix: '分钟未查看',
128
+ onChange: (minutes) => patchTier('skip', { minutes })
129
+ })
130
+ ]
131
+ }),
132
+
133
+ h(Card, {
134
+ title: '旧轮次从文档流摘除',
135
+ hint: '当满足以下设置条件时,将条目从文档流摘除,在滚动接近时重新填入。',
136
+ control: h(Switch, {
137
+ checked: state.unmount.enabled,
138
+ onChange: (checked) => patchTier('unmount', { enabled: checked })
139
+ }),
140
+ children: [
141
+ h(NumberField, {
142
+ value: state.unmount.turns, min: 1, max: 500, suffix: '轮以前',
143
+ onChange: (turns) => patchTier('unmount', { turns })
144
+ }),
145
+ h('span', { className: 'uis-label' }, '且'),
146
+ h(NumberField, {
147
+ value: state.unmount.minutes, min: 1, max: 4320, suffix: '分钟未查看',
148
+ onChange: (minutes) => patchTier('unmount', { minutes })
149
+ })
150
+ ]
151
+ }),
152
+
153
+ h(Card, {
154
+ title: '激进策略:旧轮次从内存卸载',
155
+ hint: '当满足以下设置条件时,将条目从内存卸载,重新加载需要从硬盘获取。',
156
+ control: h(Switch, {
157
+ checked: state.release.enabled,
158
+ onChange: (checked) => patch({ release: { ...state.release, enabled: checked } })
159
+ }),
160
+ children: [
161
+ h(NumberField, {
162
+ value: state.release.turns, min: 2, max: 500, suffix: '轮以前',
163
+ onChange: (turns) => patch({ release: { ...state.release, turns } })
164
+ }),
165
+ h('span', { className: 'uis-label' }, '且重新加载后'),
166
+ h(NumberField, {
167
+ value: state.release.minutes, min: 1, max: 4320, suffix: '分钟未查看',
168
+ onChange: (minutes) => patch({ release: { ...state.release, minutes } })
169
+ })
170
+ ]
171
+ })
172
+ ])
173
+ ])
174
+ }
175
+
176
+ const SETTINGS_CSS = `
177
+ .uis-group { display: flex; flex-direction: column; gap: 8px; }
178
+ .uis-group + .uis-group { margin-top: 10px; }
179
+ .uis-group-title { color: var(--dsw-alias-label-secondary, inherit); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
180
+ .uis-section { display: flex; flex-direction: column; gap: 12px; font-size: 13px; color: var(--dsw-alias-label-primary, inherit); }
181
+ .uis-head { display: flex; align-items: baseline; gap: 8px; }
182
+ .uis-brand { font-weight: 600; letter-spacing: .01em; }
183
+ .uis-version { color: var(--dsw-alias-label-tertiary, inherit); font-family: var(--dsw-font-mono, ui-monospace, monospace); font-size: 12px; }
184
+ .uis-card { border: 1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.24)); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
185
+ .uis-row { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; }
186
+ .uis-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
187
+ .uis-title { font-weight: 600; }
188
+ .uis-hint { color: var(--dsw-alias-label-tertiary, inherit); line-height: 1.5; }
189
+ .uis-thresholds { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--dsw-alias-label-secondary, inherit); }
190
+ .uis-label { white-space: nowrap; }
191
+ .uis-number { display: inline-flex; align-items: center; gap: 4px; }
192
+ .uis-number input { width: 62px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.32)); background: var(--dsw-alias-fill-secondary, transparent); color: inherit; font: inherit; }
193
+ .uis-suffix { color: var(--dsw-alias-label-tertiary, inherit); white-space: nowrap; }
194
+ .uis-switch { width: 38px; height: 22px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-secondary, rgba(127,127,127,.32)); background: var(--dsw-alias-fill-secondary, rgba(127,127,127,.2)); padding: 2px; cursor: pointer; flex: none; transition: background .15s ease; }
195
+ .uis-switch.is-on { background: var(--dsw-alias-state-success-primary, #3b82f6); border-color: transparent; }
196
+ .uis-switch:disabled { opacity: .5; cursor: not-allowed; }
197
+ .uis-knob { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s ease; }
198
+ .uis-switch.is-on .uis-knob { transform: translateX(16px); }
199
+ `
200
+
201
+ module.exports = { SETTINGS_CSS, SettingsSection }