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/README.md +176 -173
- package/lib/client.js +1665 -1483
- package/lib/index.js +169 -248
- package/package.json +68 -68
- package/src/config.js +129 -140
- package/src/follow.js +68 -0
- package/src/keepawake.js +96 -70
- package/src/main.js +142 -136
- package/src/recycle.js +334 -262
- package/src/settings.js +201 -183
package/src/main.js
CHANGED
|
@@ -1,136 +1,142 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module face: install the page halves into one cordis plugin.
|
|
3
|
-
*
|
|
4
|
-
* Everything the page does hangs off this `apply`: the animation stylesheet, the
|
|
5
|
-
* transcript recycler, the settings section, and the debug handle that reports
|
|
6
|
-
* what they are doing.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const { installAnimations } = require('./animate.js')
|
|
10
|
-
const { LAYOUT_PROPERTIES, PAINT_PROPERTIES, classify, coarsen, planSheets, planSweep, readAnimations, readKeyframes } = require('./animations.js')
|
|
11
|
-
const { VERSION, cloneConfig,
|
|
12
|
-
const {
|
|
13
|
-
const {
|
|
14
|
-
const {
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
element
|
|
23
|
-
element.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return []
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
recycler.
|
|
97
|
-
syncThrottle()
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Module face: install the page halves into one cordis plugin.
|
|
3
|
+
*
|
|
4
|
+
* Everything the page does hangs off this `apply`: the animation stylesheet, the
|
|
5
|
+
* transcript recycler, the settings section, and the debug handle that reports
|
|
6
|
+
* what they are doing.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { installAnimations } = require('./animate.js')
|
|
10
|
+
const { LAYOUT_PROPERTIES, PAINT_PROPERTIES, classify, coarsen, planSheets, planSweep, readAnimations, readKeyframes } = require('./animations.js')
|
|
11
|
+
const { VERSION, cloneConfig, getConfig, loadConfig, onConfig } = require('./config.js')
|
|
12
|
+
const { createFollow } = require('./follow.js')
|
|
13
|
+
const { createKeepAwake } = require('./keepawake.js')
|
|
14
|
+
const { CONTAINMENT_CSS, createRecycler } = require('./recycle.js')
|
|
15
|
+
const { mainSessions, sliceHistory } = require('./release.js')
|
|
16
|
+
const { SETTINGS_CSS, SettingsSection } = require('./settings.js')
|
|
17
|
+
|
|
18
|
+
const CSS_ID = 'dsh-ui-smooth/css'
|
|
19
|
+
|
|
20
|
+
function installStyleSheet() {
|
|
21
|
+
if (document.getElementById(CSS_ID) !== null) return
|
|
22
|
+
const element = document.createElement('style')
|
|
23
|
+
element.id = CSS_ID
|
|
24
|
+
element.textContent = `${CONTAINMENT_CSS}\n${SETTINGS_CSS}`
|
|
25
|
+
;(document.head ?? document.documentElement).appendChild(element)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function apply(ctx) {
|
|
29
|
+
installStyleSheet()
|
|
30
|
+
const animations = installAnimations()
|
|
31
|
+
const recycler = createRecycler(ctx)
|
|
32
|
+
const follow = createFollow()
|
|
33
|
+
const keepAwake = createKeepAwake()
|
|
34
|
+
const slotIds = () => {
|
|
35
|
+
try {
|
|
36
|
+
return ctx?.slots?.entries?.('settings.section')?.map?.((entry) => entry.id) ?? []
|
|
37
|
+
} catch (reason) {
|
|
38
|
+
return []
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const handle = {
|
|
43
|
+
version: VERSION,
|
|
44
|
+
status: () => ({
|
|
45
|
+
animations: animations.status(),
|
|
46
|
+
recycling: recycler.stats(),
|
|
47
|
+
config: cloneConfig(getConfig()),
|
|
48
|
+
settingsSection: slotIds()
|
|
49
|
+
}),
|
|
50
|
+
rescan: () => animations.rescan(),
|
|
51
|
+
recycle: () => recycler.pass(),
|
|
52
|
+
refreshConfig: () => loadConfig().then(() => {
|
|
53
|
+
recycler.pass()
|
|
54
|
+
return cloneConfig(getConfig())
|
|
55
|
+
}),
|
|
56
|
+
restore: () => animations.restore(),
|
|
57
|
+
config: () => cloneConfig(getConfig()),
|
|
58
|
+
throttle: () => keepAwake.status(),
|
|
59
|
+
/** What the aggressive tier sees: the loaded window it would trim. */
|
|
60
|
+
history: () => {
|
|
61
|
+
const session = mainSessions(ctx?.sessions)[0]
|
|
62
|
+
if (session === undefined || session === null) return null
|
|
63
|
+
let entries = []
|
|
64
|
+
try {
|
|
65
|
+
entries = session.eventSource?.getSnapshot?.()?.entries ?? []
|
|
66
|
+
} catch (reason) {
|
|
67
|
+
entries = []
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
sessionId: session.sessionId,
|
|
71
|
+
entries: entries.length,
|
|
72
|
+
turns: entries.filter((entry) => entry?.event?.type === 'turn/start').length,
|
|
73
|
+
baseSeq: session.baseSeq,
|
|
74
|
+
hasMore: session.hasMore === true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
window.__dshUiSmooth = handle
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The switch reads "throttle me in the background". Off means the page keeps
|
|
82
|
+
* running there: the host half asks the shell when it is inside one, and the
|
|
83
|
+
* page holds an inaudible audio stream open for the case where it is not.
|
|
84
|
+
*/
|
|
85
|
+
const syncThrottle = () => {
|
|
86
|
+
// "Do not throttle in the background" is a request the page can honour
|
|
87
|
+
// whatever hosts it: the shell's own escape hatch is out of reach from a
|
|
88
|
+
// Node-mode host, so the audio stream is the only lever, and a browser
|
|
89
|
+
// tab wants the same thing. Asking for it twice would only cost an
|
|
90
|
+
// idle oscillator.
|
|
91
|
+
if (getConfig().backgroundThrottle === false) keepAwake.start()
|
|
92
|
+
else keepAwake.stop()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onConfig(() => {
|
|
96
|
+
recycler.restoreAll()
|
|
97
|
+
syncThrottle()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
loadConfig().then(() => {
|
|
101
|
+
recycler.pass()
|
|
102
|
+
syncThrottle()
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
if (ctx !== undefined && ctx !== null && typeof ctx.slots?.inject === 'function') {
|
|
106
|
+
ctx.slots.inject('settings.section', () =>
|
|
107
|
+
ctx.slots.register({
|
|
108
|
+
name: 'settings.section',
|
|
109
|
+
id: 'dsh-ui-smooth',
|
|
110
|
+
order: 60,
|
|
111
|
+
label: () => '流畅性',
|
|
112
|
+
registrant: 'dsh-ui-smooth'
|
|
113
|
+
}, SettingsSection)
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (ctx !== undefined && ctx !== null && typeof ctx.effect === 'function') {
|
|
118
|
+
ctx.effect(() => () => {
|
|
119
|
+
animations.dispose()
|
|
120
|
+
follow.dispose()
|
|
121
|
+
keepAwake.stop()
|
|
122
|
+
recycler.dispose()
|
|
123
|
+
const css = document.getElementById(CSS_ID)
|
|
124
|
+
if (css !== null) css.remove()
|
|
125
|
+
if (window.__dshUiSmooth === handle) delete window.__dshUiSmooth
|
|
126
|
+
}, 'dsh-ui-smooth: page passes')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
exports.apply = apply
|
|
131
|
+
exports.inject = ['slots', 'sessions']
|
|
132
|
+
exports.internals = {
|
|
133
|
+
LAYOUT_PROPERTIES,
|
|
134
|
+
PAINT_PROPERTIES,
|
|
135
|
+
classify,
|
|
136
|
+
coarsen,
|
|
137
|
+
planSheets,
|
|
138
|
+
planSweep,
|
|
139
|
+
readAnimations,
|
|
140
|
+
readKeyframes,
|
|
141
|
+
sliceHistory
|
|
142
|
+
}
|