@ash-qw/dsh-theme-prts 0.1.99 → 0.1.101
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/CHANGELOG.md +12 -0
- package/lib/client.js +553 -35
- package/package.json +2 -2
- package/src/client/composer-glass-adapter.js +13 -3
- package/src/client/facility-geometry.js +12 -6
- package/src/client/facility-vector.js +44 -7
- package/src/client/index.js +24 -3
- package/src/client/preferences.js +68 -4
- package/src/client/session-lifeline.js +19 -4
- package/src/client/sidebar-control-adapter.js +201 -4
- package/src/client/theme-controller-v2.js +13 -0
- package/src/client/theme-controller.js +13 -0
- package/src/client/theme-settings-workbench.js +193 -6
- package/src/styles/facility-vector.css +320 -18
- package/src/styles/theme-settings-workbench.css +83 -4
|
@@ -17,6 +17,9 @@ const OWNED_ATTRIBUTES = [
|
|
|
17
17
|
'data-prts-session-menu',
|
|
18
18
|
'data-prts-session-time',
|
|
19
19
|
'data-prts-session-index',
|
|
20
|
+
'data-prts-session-state',
|
|
21
|
+
'data-prts-session-summary-header',
|
|
22
|
+
'data-prts-session-summary-label',
|
|
20
23
|
'data-prts-facility-face',
|
|
21
24
|
'data-prts-facility-spine',
|
|
22
25
|
'data-prts-facility-vector',
|
|
@@ -25,6 +28,54 @@ const OWNED_ATTRIBUTES = [
|
|
|
25
28
|
'data-prts-spine-vector',
|
|
26
29
|
]
|
|
27
30
|
|
|
31
|
+
const SESSION_STATES = Object.freeze(['warning', 'ongoing', 'error', 'done'])
|
|
32
|
+
|
|
33
|
+
function snapshotOf(source) {
|
|
34
|
+
try {
|
|
35
|
+
return source?.getSnapshot?.()
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function nativeSessionState(row) {
|
|
42
|
+
for (const state of SESSION_STATES) {
|
|
43
|
+
if (row.querySelector(`[data-state="${state}"]:not([data-prts-owned-session-status])`)) return state
|
|
44
|
+
}
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveSectionHeader(root) {
|
|
49
|
+
const tree = root?.querySelector?.('[role="tree"]')
|
|
50
|
+
if (!tree) return {}
|
|
51
|
+
for (const candidate of root.querySelectorAll('div')) {
|
|
52
|
+
if (candidate.contains(tree)) continue
|
|
53
|
+
const label = Array.from(candidate.children).find(child => (
|
|
54
|
+
child.tagName === 'SPAN'
|
|
55
|
+
&& child.textContent.trim()
|
|
56
|
+
&& !child.querySelector('button, input')
|
|
57
|
+
))
|
|
58
|
+
if (!label || candidate.querySelectorAll('button').length < 1) continue
|
|
59
|
+
return { header: candidate, label }
|
|
60
|
+
}
|
|
61
|
+
return {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function visibleSessionSummaries(sessions, workspaces) {
|
|
65
|
+
const list = snapshotOf(sessions?.list)
|
|
66
|
+
if (!list?.byId) return []
|
|
67
|
+
const workspaceList = snapshotOf(workspaces?.list)
|
|
68
|
+
const archived = new Set(workspaceList?.archivedSessionIds ?? [])
|
|
69
|
+
const ids = Array.isArray(list.ids) ? list.ids : Object.keys(list.byId)
|
|
70
|
+
return ids.flatMap(id => {
|
|
71
|
+
const summary = list.byId[id]
|
|
72
|
+
if (!summary || summary.blank || summary.origin === 'subagent' || archived.has(id)) return []
|
|
73
|
+
if (summary.running) return [{ id, title: summary.displayTitle || id, state: 'ongoing' }]
|
|
74
|
+
if (summary.completed === true) return [{ id, title: summary.displayTitle || id, state: 'done' }]
|
|
75
|
+
return []
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
28
79
|
function markSidebarNode(node, attribute, next) {
|
|
29
80
|
if (!node) return
|
|
30
81
|
node.setAttribute(attribute, '')
|
|
@@ -119,18 +170,134 @@ function ensureFacilitySpine(document, row, kind, next) {
|
|
|
119
170
|
}
|
|
120
171
|
|
|
121
172
|
|
|
122
|
-
export function createSidebarControlAdapter({ document, window }) {
|
|
173
|
+
export function createSidebarControlAdapter({ document, window, sessions, workspaces }) {
|
|
123
174
|
let observer
|
|
124
175
|
let resizeObserver
|
|
125
176
|
let resizeFrame
|
|
126
177
|
let resizeTimer
|
|
127
178
|
let scanFrame
|
|
179
|
+
let stopSessionList = () => {}
|
|
180
|
+
let stopWorkspaceList = () => {}
|
|
181
|
+
let statusSourcesStarted = false
|
|
182
|
+
let summaryRoot
|
|
183
|
+
let summarySignature = ''
|
|
128
184
|
let owned = new Set()
|
|
129
185
|
let vectorOwners = new Set()
|
|
130
186
|
const dirtyVectors = new Map()
|
|
131
187
|
const vectorSizes = new WeakMap()
|
|
132
188
|
const lifelineAnimator = createSessionLifelineAnimator({ document, window })
|
|
133
189
|
|
|
190
|
+
function openSession(sessionId) {
|
|
191
|
+
try {
|
|
192
|
+
if (typeof sessions?.open === 'function') {
|
|
193
|
+
sessions.open(sessionId)
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
} catch {}
|
|
197
|
+
const row = Array.from(document.querySelectorAll('[data-prts-session-row]')).find(candidate => (
|
|
198
|
+
candidate.querySelector('[data-prts-row-title]')?.textContent.trim() === sessionId
|
|
199
|
+
))
|
|
200
|
+
row?.click?.()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function statusSignal(document, state) {
|
|
204
|
+
const signal = document.createElement('span')
|
|
205
|
+
signal.setAttribute('data-prts-session-summary-signal', state)
|
|
206
|
+
signal.setAttribute('aria-hidden', 'true')
|
|
207
|
+
return signal
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function buildSummaryGroup(state, label, items) {
|
|
211
|
+
const group = document.createElement('span')
|
|
212
|
+
group.setAttribute('data-prts-session-summary-group', state)
|
|
213
|
+
|
|
214
|
+
const trigger = document.createElement('button')
|
|
215
|
+
trigger.type = 'button'
|
|
216
|
+
trigger.setAttribute('data-prts-session-summary-trigger', state)
|
|
217
|
+
trigger.setAttribute('aria-haspopup', 'menu')
|
|
218
|
+
trigger.setAttribute('aria-label', `${label} ${items.length}`)
|
|
219
|
+
trigger.append(statusSignal(document, state))
|
|
220
|
+
const count = document.createElement('span')
|
|
221
|
+
count.setAttribute('data-prts-session-summary-count', '')
|
|
222
|
+
count.textContent = String(items.length)
|
|
223
|
+
trigger.append(count)
|
|
224
|
+
|
|
225
|
+
const popover = document.createElement('span')
|
|
226
|
+
popover.setAttribute('data-prts-session-summary-popover', state)
|
|
227
|
+
popover.setAttribute('role', 'menu')
|
|
228
|
+
popover.setAttribute('aria-label', label)
|
|
229
|
+
const heading = document.createElement('span')
|
|
230
|
+
heading.setAttribute('data-prts-session-summary-heading', '')
|
|
231
|
+
const headingLabel = document.createElement('strong')
|
|
232
|
+
headingLabel.textContent = label
|
|
233
|
+
const hint = document.createElement('small')
|
|
234
|
+
hint.textContent = '选择会话'
|
|
235
|
+
heading.append(headingLabel, hint)
|
|
236
|
+
popover.append(heading)
|
|
237
|
+
for (const item of items) {
|
|
238
|
+
const button = document.createElement('button')
|
|
239
|
+
button.type = 'button'
|
|
240
|
+
button.setAttribute('role', 'menuitem')
|
|
241
|
+
button.setAttribute('data-prts-session-summary-item', item.id)
|
|
242
|
+
button.append(statusSignal(document, state))
|
|
243
|
+
const title = document.createElement('span')
|
|
244
|
+
title.textContent = item.title
|
|
245
|
+
button.append(title)
|
|
246
|
+
button.addEventListener('click', event => {
|
|
247
|
+
event.stopPropagation()
|
|
248
|
+
openSession(item.id)
|
|
249
|
+
})
|
|
250
|
+
popover.append(button)
|
|
251
|
+
}
|
|
252
|
+
group.append(trigger, popover)
|
|
253
|
+
return group
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function syncSummary(root, next) {
|
|
257
|
+
const { header, label } = resolveSectionHeader(root)
|
|
258
|
+
if (!header || !label) {
|
|
259
|
+
summaryRoot?.remove()
|
|
260
|
+
summaryRoot = undefined
|
|
261
|
+
summarySignature = ''
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
header.setAttribute('data-prts-session-summary-header', '')
|
|
265
|
+
label.setAttribute('data-prts-session-summary-label', '')
|
|
266
|
+
next.add(header)
|
|
267
|
+
next.add(label)
|
|
268
|
+
const fromService = visibleSessionSummaries(sessions, workspaces)
|
|
269
|
+
const rows = fromService.length ? fromService : Array.from(root.querySelectorAll('[data-prts-session-row]')).flatMap(row => {
|
|
270
|
+
const state = row.getAttribute('data-prts-session-state')
|
|
271
|
+
if (state !== 'ongoing' && state !== 'done') return []
|
|
272
|
+
const title = row.querySelector('[data-prts-row-title]')?.textContent.trim()
|
|
273
|
+
return title ? [{ id: title, title, state }] : []
|
|
274
|
+
})
|
|
275
|
+
const ongoing = rows.filter(item => item.state === 'ongoing')
|
|
276
|
+
const done = rows.filter(item => item.state === 'done')
|
|
277
|
+
const signature = JSON.stringify({
|
|
278
|
+
ongoing: ongoing.map(item => [item.id, item.title]),
|
|
279
|
+
done: done.map(item => [item.id, item.title]),
|
|
280
|
+
})
|
|
281
|
+
if (!summaryRoot) {
|
|
282
|
+
summaryRoot = document.createElement('span')
|
|
283
|
+
summaryRoot.setAttribute('data-prts-owned-session-summary', '')
|
|
284
|
+
summaryRoot.setAttribute('data-prts-session-summary', '')
|
|
285
|
+
summaryRoot.setAttribute('role', 'group')
|
|
286
|
+
summaryRoot.setAttribute('aria-label', '会话状态总览')
|
|
287
|
+
label.insertAdjacentElement('afterend', summaryRoot)
|
|
288
|
+
} else if (summaryRoot.parentElement !== header) {
|
|
289
|
+
label.insertAdjacentElement('afterend', summaryRoot)
|
|
290
|
+
}
|
|
291
|
+
const labelHidden = Array.from(label.classList).some(name => /hidden/i.test(name))
|
|
292
|
+
summaryRoot.toggleAttribute('data-prts-summary-search-hidden', labelHidden)
|
|
293
|
+
summaryRoot.hidden = ongoing.length === 0 && done.length === 0
|
|
294
|
+
if (signature === summarySignature) return
|
|
295
|
+
summarySignature = signature
|
|
296
|
+
summaryRoot.replaceChildren()
|
|
297
|
+
if (ongoing.length) summaryRoot.append(buildSummaryGroup('ongoing', '运行中的会话', ongoing))
|
|
298
|
+
if (done.length) summaryRoot.append(buildSummaryGroup('done', '完成未查看', done))
|
|
299
|
+
}
|
|
300
|
+
|
|
134
301
|
function scheduleVectors() {
|
|
135
302
|
if (resizeFrame !== undefined) return
|
|
136
303
|
const requestFrame = window?.requestAnimationFrame?.bind(window) ?? (callback => window?.setTimeout?.(callback, 0))
|
|
@@ -161,12 +328,17 @@ export function createSidebarControlAdapter({ document, window }) {
|
|
|
161
328
|
|
|
162
329
|
function registerVector(owner, options, next, nextVectorOwners) {
|
|
163
330
|
if (!owner) return
|
|
331
|
+
const previousSessionNotch = owner.querySelector?.(':scope > svg[data-prts-facility-svg]')
|
|
332
|
+
?.hasAttribute('data-prts-session-notch') ?? false
|
|
164
333
|
const graphic = ensureFacilityGraphic(document, owner, options)
|
|
165
334
|
if (!graphic) return
|
|
166
335
|
next.add(graphic)
|
|
167
336
|
nextVectorOwners.add(owner)
|
|
168
337
|
if (!vectorOwners.has(owner)) resizeObserver?.observe(owner)
|
|
169
|
-
if (
|
|
338
|
+
if (previousSessionNotch !== Boolean(options.sessionNotch)) vectorSizes.delete(owner)
|
|
339
|
+
if (!vectorSizes.has(owner)) {
|
|
340
|
+
dirtyVectors.set(owner, undefined)
|
|
341
|
+
}
|
|
170
342
|
}
|
|
171
343
|
|
|
172
344
|
function syncVectorOwners(next) {
|
|
@@ -222,15 +394,22 @@ export function createSidebarControlAdapter({ document, window }) {
|
|
|
222
394
|
for (const row of root.querySelectorAll('div[role="treeitem"][aria-selected]')) {
|
|
223
395
|
const sessionIndex = String(++sessionOrdinal).padStart(2, '0')
|
|
224
396
|
const controls = resolveRowControls(row, 'session')
|
|
397
|
+
const state = nativeSessionState(row)
|
|
225
398
|
const face = ensureFacilityFace(document, row, 'session', next)
|
|
226
399
|
const spine = ensureFacilitySpine(document, row, 'session', next)
|
|
227
|
-
registerVector(face, { kind: 'face', topNotch: true, texture: 'pickup' }, next, nextVectorOwners)
|
|
400
|
+
registerVector(face, { kind: 'face', topNotch: true, sessionNotch: true, texture: 'pickup' }, next, nextVectorOwners)
|
|
228
401
|
registerVector(spine, { kind: 'spine' }, next, nextVectorOwners)
|
|
229
402
|
if (!activeLifelineRow && row.getAttribute('aria-selected') === 'true') {
|
|
230
403
|
activeLifelineRow = row
|
|
231
404
|
activeLifeline = face.querySelector('[data-prts-session-lifeline]')
|
|
232
405
|
}
|
|
233
406
|
markSidebarNode(row, 'data-prts-session-row', next)
|
|
407
|
+
if (state) {
|
|
408
|
+
row.setAttribute('data-prts-session-state', state)
|
|
409
|
+
next.add(row)
|
|
410
|
+
} else {
|
|
411
|
+
row.removeAttribute('data-prts-session-state')
|
|
412
|
+
}
|
|
234
413
|
row.dataset.prtsSessionIndex = sessionIndex
|
|
235
414
|
const title = resolveRowTitle(row, 'session', controls.actions)
|
|
236
415
|
markSidebarNode(title, 'data-prts-row-title', next)
|
|
@@ -243,6 +422,11 @@ export function createSidebarControlAdapter({ document, window }) {
|
|
|
243
422
|
markSidebarNode(controls.menu, 'data-prts-session-menu', next)
|
|
244
423
|
registerVector(controls.menu, { kind: 'button' }, next, nextVectorOwners)
|
|
245
424
|
}
|
|
425
|
+
syncSummary(root, next)
|
|
426
|
+
} else {
|
|
427
|
+
summaryRoot?.remove()
|
|
428
|
+
summaryRoot = undefined
|
|
429
|
+
summarySignature = ''
|
|
246
430
|
}
|
|
247
431
|
lifelineAnimator.setTarget(activeLifelineRow, activeLifeline)
|
|
248
432
|
for (const node of owned) {
|
|
@@ -272,6 +456,9 @@ export function createSidebarControlAdapter({ document, window }) {
|
|
|
272
456
|
vectorOwners.clear()
|
|
273
457
|
dirtyVectors.clear()
|
|
274
458
|
owned.clear()
|
|
459
|
+
summaryRoot?.remove()
|
|
460
|
+
summaryRoot = undefined
|
|
461
|
+
summarySignature = ''
|
|
275
462
|
}
|
|
276
463
|
|
|
277
464
|
return {
|
|
@@ -294,6 +481,11 @@ export function createSidebarControlAdapter({ document, window }) {
|
|
|
294
481
|
})
|
|
295
482
|
}
|
|
296
483
|
scan()
|
|
484
|
+
if (!statusSourcesStarted) {
|
|
485
|
+
statusSourcesStarted = true
|
|
486
|
+
stopSessionList = sessions?.list?.subscribe?.(queueScan) ?? (() => {})
|
|
487
|
+
stopWorkspaceList = workspaces?.list?.subscribe?.(queueScan) ?? (() => {})
|
|
488
|
+
}
|
|
297
489
|
if (observer || !window?.MutationObserver) return
|
|
298
490
|
const observationRoot = document.querySelector('[data-prts-region="sessions"]')
|
|
299
491
|
if (!observationRoot) return
|
|
@@ -302,12 +494,17 @@ export function createSidebarControlAdapter({ document, window }) {
|
|
|
302
494
|
subtree: true,
|
|
303
495
|
childList: true,
|
|
304
496
|
attributes: true,
|
|
305
|
-
attributeFilter: ['aria-expanded', 'aria-selected', 'class'],
|
|
497
|
+
attributeFilter: ['aria-expanded', 'aria-selected', 'class', 'data-state'],
|
|
306
498
|
})
|
|
307
499
|
},
|
|
308
500
|
dispose() {
|
|
309
501
|
observer?.disconnect()
|
|
310
502
|
observer = undefined
|
|
503
|
+
stopSessionList()
|
|
504
|
+
stopSessionList = () => {}
|
|
505
|
+
stopWorkspaceList()
|
|
506
|
+
stopWorkspaceList = () => {}
|
|
507
|
+
statusSourcesStarted = false
|
|
311
508
|
if (scanFrame !== undefined) {
|
|
312
509
|
if (window?.cancelAnimationFrame) window.cancelAnimationFrame(scanFrame)
|
|
313
510
|
else window?.clearTimeout?.(scanFrame)
|
|
@@ -8,8 +8,16 @@ const ROOT_ATTRIBUTES = [
|
|
|
8
8
|
'data-prts-motion',
|
|
9
9
|
'data-prts-particle-pattern',
|
|
10
10
|
'data-prts-session-flow',
|
|
11
|
+
'data-prts-session-glow',
|
|
12
|
+
'data-prts-session-flow-palette',
|
|
13
|
+
'data-prts-session-flow-speed',
|
|
11
14
|
'data-prts-conversation-style',
|
|
12
15
|
]
|
|
16
|
+
const SESSION_FLOW_COLOR_PROPERTIES = {
|
|
17
|
+
'--prts-session-flow-back': 'sessionFlowColorBack',
|
|
18
|
+
'--prts-session-flow-core': 'sessionFlowColorCore',
|
|
19
|
+
'--prts-session-flow-front': 'sessionFlowColorFront',
|
|
20
|
+
}
|
|
13
21
|
|
|
14
22
|
const TRANSITION_ATTRIBUTE = 'data-prts-scheme-transition'
|
|
15
23
|
const TRANSITION_MODE_ATTRIBUTE = 'data-prts-scheme-transition-mode'
|
|
@@ -102,6 +110,7 @@ export function createThemeController({ document, window, cssText, service, onTr
|
|
|
102
110
|
|
|
103
111
|
function clearThemeState() {
|
|
104
112
|
for (const attribute of ROOT_ATTRIBUTES) root.removeAttribute(attribute)
|
|
113
|
+
for (const property of Object.keys(SESSION_FLOW_COLOR_PROPERTIES)) root.style.removeProperty(property)
|
|
105
114
|
clearTransitionState()
|
|
106
115
|
}
|
|
107
116
|
|
|
@@ -718,6 +727,10 @@ export function createThemeController({ document, window, cssText, service, onTr
|
|
|
718
727
|
root.dataset.prtsMotion = preferences.motion
|
|
719
728
|
root.dataset.prtsParticlePattern = 'orthogonal'
|
|
720
729
|
root.dataset.prtsSessionFlow = preferences.sessionFlow ? 'on' : 'off'
|
|
730
|
+
root.dataset.prtsSessionGlow = preferences.sessionGlow ? 'on' : 'off'
|
|
731
|
+
root.dataset.prtsSessionFlowPalette = preferences.sessionFlowPalette
|
|
732
|
+
root.dataset.prtsSessionFlowSpeed = String(preferences.sessionFlowSpeed)
|
|
733
|
+
for (const [property, key] of Object.entries(SESSION_FLOW_COLOR_PROPERTIES)) root.style.setProperty(property, preferences[key])
|
|
721
734
|
root.dataset.prtsConversationStyle = preferences.conversationStyle
|
|
722
735
|
refresh()
|
|
723
736
|
},
|
|
@@ -8,8 +8,16 @@ const ROOT_ATTRIBUTES = [
|
|
|
8
8
|
'data-prts-motion',
|
|
9
9
|
'data-prts-particle-pattern',
|
|
10
10
|
'data-prts-session-flow',
|
|
11
|
+
'data-prts-session-glow',
|
|
12
|
+
'data-prts-session-flow-palette',
|
|
13
|
+
'data-prts-session-flow-speed',
|
|
11
14
|
'data-prts-conversation-style',
|
|
12
15
|
]
|
|
16
|
+
const SESSION_FLOW_COLOR_PROPERTIES = {
|
|
17
|
+
'--prts-session-flow-back': 'sessionFlowColorBack',
|
|
18
|
+
'--prts-session-flow-core': 'sessionFlowColorCore',
|
|
19
|
+
'--prts-session-flow-front': 'sessionFlowColorFront',
|
|
20
|
+
}
|
|
13
21
|
|
|
14
22
|
function themeIdentity(value) {
|
|
15
23
|
if (typeof value === 'string') return value
|
|
@@ -37,6 +45,7 @@ export function createThemeController({ document, window, cssText, service }) {
|
|
|
37
45
|
|
|
38
46
|
function clearThemeState() {
|
|
39
47
|
for (const attribute of ROOT_ATTRIBUTES) root.removeAttribute(attribute)
|
|
48
|
+
for (const property of Object.keys(SESSION_FLOW_COLOR_PROPERTIES)) root.style.removeProperty(property)
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
function removeOwnedState() {
|
|
@@ -111,6 +120,10 @@ export function createThemeController({ document, window, cssText, service }) {
|
|
|
111
120
|
root.dataset.prtsMotion = preferences.motion
|
|
112
121
|
root.dataset.prtsParticlePattern = 'orthogonal'
|
|
113
122
|
root.dataset.prtsSessionFlow = preferences.sessionFlow ? 'on' : 'off'
|
|
123
|
+
root.dataset.prtsSessionGlow = preferences.sessionGlow ? 'on' : 'off'
|
|
124
|
+
root.dataset.prtsSessionFlowPalette = preferences.sessionFlowPalette
|
|
125
|
+
root.dataset.prtsSessionFlowSpeed = String(preferences.sessionFlowSpeed)
|
|
126
|
+
for (const [property, key] of Object.entries(SESSION_FLOW_COLOR_PROPERTIES)) root.style.setProperty(property, preferences[key])
|
|
114
127
|
root.dataset.prtsConversationStyle = preferences.conversationStyle
|
|
115
128
|
refresh()
|
|
116
129
|
},
|