@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.8
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.en.md +61 -0
- package/README.md +60 -2
- package/apk/dsh-remote.apk +0 -0
- package/approval-summary.mjs +115 -0
- package/client.js +197 -0
- package/cordis.patch.yml +5 -0
- package/doctor-skill.mjs +99 -0
- package/doctor-target.mjs +24 -0
- package/file-delivery.mjs +84 -0
- package/gateway-stats.cjs +501 -0
- package/gateway.cjs +8451 -0
- package/index.mjs +1784 -0
- package/insights.mjs +111 -0
- package/market.mjs +86 -0
- package/package.json +71 -4
- package/peak-reminders.mjs +50 -0
- package/plugin-center.mjs +777 -0
- package/plugin-transaction.mjs +300 -0
- package/public/activity.js +188 -0
- package/public/admin.html +820 -0
- package/public/admin.js +1167 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +464 -0
- package/public/app.js +8826 -0
- package/public/approval-records.js +301 -0
- package/public/approval-summary.js +78 -0
- package/public/build.json +5 -0
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/chat-files.js +87 -0
- package/public/desktop/desktop.css +816 -0
- package/public/desktop/desktop.html +871 -0
- package/public/desktop/desktop.js +4548 -0
- package/public/desktop/i18n.js +85 -0
- package/public/diagnostics.js +203 -0
- package/public/doctor-entry.js +94 -0
- package/public/doctor.css +205 -0
- package/public/doctor.js +769 -0
- package/public/donate.png +0 -0
- package/public/e2ee-transport.js +219 -0
- package/public/extensions.css +109 -0
- package/public/extensions.js +215 -0
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/genui.css +8 -0
- package/public/genui.js +254 -0
- package/public/history.js +304 -0
- package/public/i18n.js +57 -0
- package/public/icon.svg +12 -0
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +290 -0
- package/public/index.html +1548 -0
- package/public/insights.css +28 -0
- package/public/insights.js +290 -0
- package/public/jsqr.min.js +10104 -0
- package/public/lan-discovery.js +94 -0
- package/public/link-check.js +109 -0
- package/public/manifest.webmanifest +16 -0
- package/public/md.js +333 -0
- package/public/morphicons-init.js +41 -0
- package/public/motion.js +557 -0
- package/public/network.js +100 -0
- package/public/onboarding.css +36 -0
- package/public/onboarding.js +253 -0
- package/public/operations.js +141 -0
- package/public/permission-presets.js +159 -0
- package/public/plugin-center.css +120 -0
- package/public/plugin-center.js +666 -0
- package/public/plugin-icon.svg +5 -0
- package/public/plugin.html +68 -0
- package/public/plugin.js +211 -0
- package/public/qrcode.min.js +2297 -0
- package/public/relay-autopair.js +251 -0
- package/public/relay-devices.js +80 -0
- package/public/relay-settings.css +24 -0
- package/public/relay-settings.js +194 -0
- package/public/remote-state.js +27 -0
- package/public/remote-ui.css +148 -0
- package/public/remote-ui.js +243 -0
- package/public/session-deck.css +79 -0
- package/public/session-deck.js +180 -0
- package/public/session-presets.js +47 -0
- package/public/setup.css +18 -0
- package/public/setup.js +213 -0
- package/public/sha256.js +119 -0
- package/public/skills.css +81 -0
- package/public/skills.js +202 -0
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/face.png +0 -0
- package/public/skins/blue-fish/icon-blush.png +0 -0
- package/public/skins/blue-fish/icon-sleep.png +0 -0
- package/public/skins/blue-fish/icon-smile.png +0 -0
- package/public/skins/blue-fish/icon-star.png +0 -0
- package/public/skins/blue-fish/icon-wink.png +0 -0
- package/public/skins/blue-fish/icon.png +0 -0
- package/public/skins/blue-fish/mascot.png +0 -0
- package/public/skins/blue-fish/pattern.png +0 -0
- package/public/skins/blue-fish/preview.html +12 -0
- package/public/skins/blue-fish/skin.css +122 -0
- package/public/skins/blue-fish/sparkles.svg +18 -0
- package/public/skins/bocchi/DESIGN.md +99 -0
- package/public/skins/bocchi/face.png +0 -0
- package/public/skins/bocchi/grain.png +0 -0
- package/public/skins/bocchi/icon-blush.png +0 -0
- package/public/skins/bocchi/icon-sleep.png +0 -0
- package/public/skins/bocchi/icon-smile.png +0 -0
- package/public/skins/bocchi/icon-star.png +0 -0
- package/public/skins/bocchi/icon-wink.png +0 -0
- package/public/skins/bocchi/icon.png +0 -0
- package/public/skins/bocchi/pattern-soft.png +0 -0
- package/public/skins/bocchi/pattern.png +0 -0
- package/public/skins/bocchi/preview.html +55 -0
- package/public/skins/bocchi/skin.css +233 -0
- package/public/skins/bocchi/stage-bg.png +0 -0
- package/public/skins/bocchi/stage-soft.png +0 -0
- package/public/skins/bocchi/stand.png +0 -0
- package/public/skins/bocchi/sticker-guitar.png +0 -0
- package/public/skins/kessoku/DESIGN.md +38 -0
- package/public/skins/kessoku/grain.png +0 -0
- package/public/skins/kessoku/skin.css +212 -0
- package/public/skins/kita/SOURCES.json +51 -0
- package/public/skins/kita/face.png +0 -0
- package/public/skins/kita/icon-live.png +0 -0
- package/public/skins/kita/icon-reddress.png +0 -0
- package/public/skins/kita/icon-seifuku.png +0 -0
- package/public/skins/kita/pattern.png +0 -0
- package/public/skins/kita/preview.html +56 -0
- package/public/skins/kita/skin.css +26 -0
- package/public/skins/kita/stand.png +0 -0
- package/public/skins/kita/sticker-live.png +0 -0
- package/public/skins/nijika/SOURCES.json +51 -0
- package/public/skins/nijika/face.png +0 -0
- package/public/skins/nijika/icon-live.png +0 -0
- package/public/skins/nijika/icon-reddress.png +0 -0
- package/public/skins/nijika/icon-seifuku.png +0 -0
- package/public/skins/nijika/pattern.png +0 -0
- package/public/skins/nijika/preview.html +56 -0
- package/public/skins/nijika/skin.css +25 -0
- package/public/skins/nijika/stand.png +0 -0
- package/public/skins/nijika/sticker-live.png +0 -0
- package/public/skins/penguin/DESIGN.md +33 -0
- package/public/skins/penguin/SOURCES.json +22 -0
- package/public/skins/penguin/aic-blueprint.svg +24 -0
- package/public/skins/penguin/endfield-triangles.svg +4 -0
- package/public/skins/penguin/face.png +0 -0
- package/public/skins/penguin/icon-blush.png +0 -0
- package/public/skins/penguin/icon-dizzy.png +0 -0
- package/public/skins/penguin/icon-laugh.png +0 -0
- package/public/skins/penguin/icon-sleep.png +0 -0
- package/public/skins/penguin/icon-smile.png +0 -0
- package/public/skins/penguin/icon-star.png +0 -0
- package/public/skins/penguin/icon-wink.png +0 -0
- package/public/skins/penguin/icon.png +0 -0
- package/public/skins/penguin/mascot.png +0 -0
- package/public/skins/penguin/pattern-night.png +0 -0
- package/public/skins/penguin/pattern.png +0 -0
- package/public/skins/penguin/preview.html +12 -0
- package/public/skins/penguin/skin.css +212 -0
- package/public/skins/ryo/SOURCES.json +51 -0
- package/public/skins/ryo/face.png +0 -0
- package/public/skins/ryo/icon-live.png +0 -0
- package/public/skins/ryo/icon-reddress.png +0 -0
- package/public/skins/ryo/icon-seifuku.png +0 -0
- package/public/skins/ryo/pattern.png +0 -0
- package/public/skins/ryo/preview.html +56 -0
- package/public/skins/ryo/skin.css +25 -0
- package/public/skins/ryo/stand.png +0 -0
- package/public/skins/ryo/sticker-live.png +0 -0
- package/public/sponsor-entry.js +21 -0
- package/public/styles.css +1494 -0
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/task-board.js +109 -0
- package/public/teams.js +98 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +1044 -0
- package/public/theme.js +166 -0
- package/public/transcribe-core.js +74 -0
- package/public/turn-results.js +121 -0
- package/public/update.json +49 -0
- package/public/vendor/gsap/NOTICE.md +10 -0
- package/public/vendor/gsap/gsap.min.js +11 -0
- package/public/vendor/morphicons/LICENSE +21 -0
- package/public/vendor/morphicons/README.md +10 -0
- package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
- package/public/vendor/morphicons/dom.js +206 -0
- package/public/vendor/morphicons/element.js +261 -0
- package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
- package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
- package/public/version.json +3 -0
- package/public/voice-input.js +739 -0
- package/public/workflow.css +365 -0
- package/public/workflow.js +409 -0
- package/session-file.mjs +39 -0
- package/skills/dsh-remote-doctor/SKILL.md +186 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/skills.mjs +53 -0
- package/task-board.mjs +57 -0
- package/teams.mjs +58 -0
package/public/motion.js
ADDED
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
/* dsh-Remote motion layer: GSAP core + timeline, with reduced-motion and low-cost DOM updates. */
|
|
2
|
+
(function () {
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
const gsap = window.gsap
|
|
6
|
+
if (!gsap) return
|
|
7
|
+
|
|
8
|
+
const reduceQuery = window.matchMedia?.('(prefers-reduced-motion: reduce)')
|
|
9
|
+
let reduced = !!reduceQuery?.matches
|
|
10
|
+
const activePulses = new Set()
|
|
11
|
+
const recentRuns = new WeakMap()
|
|
12
|
+
|
|
13
|
+
reduceQuery?.addEventListener?.('change', event => {
|
|
14
|
+
reduced = !!event.matches
|
|
15
|
+
if (!reduced) return
|
|
16
|
+
const animated = document.querySelectorAll('.view, .ds-view, [data-motion-view], .modal, .ds-modal, .sheet, .ds-drawer, [data-motion-panel]')
|
|
17
|
+
gsap.killTweensOf(animated)
|
|
18
|
+
clear(animated)
|
|
19
|
+
for (const node of activePulses) {
|
|
20
|
+
gsap.killTweensOf(node)
|
|
21
|
+
clear(node)
|
|
22
|
+
}
|
|
23
|
+
activePulses.clear()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
function clear(targets) {
|
|
27
|
+
gsap.set(targets, { clearProps: 'opacity,visibility,transform,willChange' })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function motionKey(node) {
|
|
31
|
+
return node?.dataset?.motionKey || node?.dataset?.id || node?.dataset?.sessionSwipe || node?.dataset?.wbSession || node?.textContent?.slice(0, 80) || ''
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function motionSignature(items) {
|
|
35
|
+
return items.map(motionKey).join('|')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function startedRecently(node, threshold = 48) {
|
|
39
|
+
const now = window.performance?.now?.() || Date.now()
|
|
40
|
+
const previous = recentRuns.get(node) || 0
|
|
41
|
+
recentRuns.set(node, now)
|
|
42
|
+
return previous > 0 && now - previous < threshold
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function view(view) {
|
|
46
|
+
if (!view || startedRecently(view)) return
|
|
47
|
+
const children = [...view.children].filter(child => !child.classList.contains('hidden')).slice(0, 8)
|
|
48
|
+
const targets = children.length ? children : [view]
|
|
49
|
+
gsap.killTweensOf([view, ...targets])
|
|
50
|
+
gsap.set(view, { autoAlpha: 1, clearProps: 'transform' })
|
|
51
|
+
if (reduced || document.body?.classList?.contains('workflow-v8')) {
|
|
52
|
+
clear([view, ...targets])
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
gsap.fromTo(targets, { opacity: 0.72, y: 8 }, {
|
|
56
|
+
opacity: 1,
|
|
57
|
+
y: 0,
|
|
58
|
+
duration: 0.24,
|
|
59
|
+
ease: 'power2.out',
|
|
60
|
+
stagger: { each: 0.035, from: 'start' },
|
|
61
|
+
overwrite: 'auto',
|
|
62
|
+
clearProps: 'opacity,visibility,transform,willChange'
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function list(container, selector) {
|
|
67
|
+
if (!container) return
|
|
68
|
+
const items = [...container.querySelectorAll(selector)]
|
|
69
|
+
if (!items.length) {
|
|
70
|
+
delete container.dataset.motionListSignature
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
const signature = motionSignature(items)
|
|
74
|
+
if (container.dataset.motionListSignature === signature) return
|
|
75
|
+
container.dataset.motionListSignature = signature
|
|
76
|
+
gsap.killTweensOf(items)
|
|
77
|
+
if (reduced || document.body?.classList?.contains('workflow-v8')) {
|
|
78
|
+
clear(items)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
gsap.fromTo(items, { autoAlpha: 0, y: 8 }, {
|
|
82
|
+
autoAlpha: 1,
|
|
83
|
+
y: 0,
|
|
84
|
+
duration: 0.2,
|
|
85
|
+
ease: 'power2.out',
|
|
86
|
+
stagger: { each: 0.025, from: 'start' },
|
|
87
|
+
clearProps: 'transform'
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// FLIP-style reflow without the optional Flip plugin: read all positions,
|
|
92
|
+
// let the caller render once, then animate only transform/opacity.
|
|
93
|
+
function relayout(container, selector, render) {
|
|
94
|
+
if (!container || typeof render !== 'function') return false
|
|
95
|
+
const existing = [...container.querySelectorAll(selector)]
|
|
96
|
+
const before = new Map(existing.map(node => [motionKey(node), node.getBoundingClientRect()]))
|
|
97
|
+
gsap.killTweensOf(existing)
|
|
98
|
+
render()
|
|
99
|
+
const next = [...container.querySelectorAll(selector)]
|
|
100
|
+
if (reduced || document.body?.classList?.contains('workflow-v8')) {
|
|
101
|
+
clear(next)
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
const entering = []
|
|
105
|
+
const moving = []
|
|
106
|
+
for (const node of next) {
|
|
107
|
+
const previous = before.get(motionKey(node))
|
|
108
|
+
if (!previous) {
|
|
109
|
+
entering.push(node)
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
const current = node.getBoundingClientRect()
|
|
113
|
+
const x = previous.left - current.left
|
|
114
|
+
const y = previous.top - current.top
|
|
115
|
+
if (Math.abs(x) > 0.5 || Math.abs(y) > 0.5) {
|
|
116
|
+
gsap.set(node, { x, y })
|
|
117
|
+
moving.push(node)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (moving.length) {
|
|
121
|
+
gsap.to(moving, {
|
|
122
|
+
x: 0,
|
|
123
|
+
y: 0,
|
|
124
|
+
duration: 0.28,
|
|
125
|
+
ease: 'power2.out',
|
|
126
|
+
stagger: { each: 0.018, from: 'start' },
|
|
127
|
+
clearProps: 'transform'
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
if (entering.length) {
|
|
131
|
+
gsap.fromTo(entering, { autoAlpha: 0, y: 8 }, {
|
|
132
|
+
autoAlpha: 1,
|
|
133
|
+
y: 0,
|
|
134
|
+
duration: 0.2,
|
|
135
|
+
ease: 'power2.out',
|
|
136
|
+
stagger: { each: 0.025, from: 'start' },
|
|
137
|
+
clearProps: 'transform'
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
return true
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function bindLongPressReorder(container, selector, options = {}) {
|
|
144
|
+
if (!container || !selector) return
|
|
145
|
+
const registry = container.__dshReorderRegistry || (container.__dshReorderRegistry = new Map())
|
|
146
|
+
const existing = registry.get(selector)
|
|
147
|
+
if (existing) {
|
|
148
|
+
existing.options = options
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
const LONG_PRESS_MS = 300
|
|
152
|
+
const MOVE_TOLERANCE = 28
|
|
153
|
+
const state = { options, press: null, drag: null, suppressClickUntil: 0 }
|
|
154
|
+
const raf = callback => window.requestAnimationFrame ? window.requestAnimationFrame(callback) : setTimeout(callback, 16)
|
|
155
|
+
const caf = id => window.cancelAnimationFrame ? window.cancelAnimationFrame(id) : clearTimeout(id)
|
|
156
|
+
const itemFrom = target => target?.closest?.(selector)
|
|
157
|
+
const listFrom = item => item?.parentElement || container
|
|
158
|
+
const groupFrom = item => state.options.groupSelector ? (item.closest(state.options.groupSelector) || container) : container
|
|
159
|
+
const keyFrom = item => state.options.key ? state.options.key(item) : motionKey(item)
|
|
160
|
+
const itemsFrom = list => [...list.querySelectorAll(selector)].filter(item => item.parentElement === list)
|
|
161
|
+
const scrollTargetsFrom = item => {
|
|
162
|
+
const targets = []
|
|
163
|
+
let node = item?.parentElement
|
|
164
|
+
while (node && node !== document.body) {
|
|
165
|
+
const style = window.getComputedStyle(node)
|
|
166
|
+
if ((style.overflowY === 'auto' || style.overflowY === 'scroll') && node.scrollHeight > node.clientHeight + 1) targets.push(node)
|
|
167
|
+
node = node.parentElement
|
|
168
|
+
}
|
|
169
|
+
if (document.scrollingElement) targets.push(document.scrollingElement)
|
|
170
|
+
return targets
|
|
171
|
+
}
|
|
172
|
+
const reorderDraggedItems = (drag, clientY) => {
|
|
173
|
+
const items = itemsFrom(drag.list).filter(item => item !== drag.item)
|
|
174
|
+
if (!items.length) return
|
|
175
|
+
const firstRects = new Map(items.map(item => [item, item.getBoundingClientRect()]))
|
|
176
|
+
let target = null
|
|
177
|
+
let insertBeforeTarget = false
|
|
178
|
+
for (const item of items) {
|
|
179
|
+
const rect = item.getBoundingClientRect()
|
|
180
|
+
if (clientY < rect.top + rect.height / 2) {
|
|
181
|
+
target = item
|
|
182
|
+
insertBeforeTarget = true
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
target = item
|
|
186
|
+
}
|
|
187
|
+
if (!target) return
|
|
188
|
+
const reference = insertBeforeTarget ? target : target.nextElementSibling
|
|
189
|
+
if (reference !== drag.placeholder) drag.list.insertBefore(drag.placeholder, reference || null)
|
|
190
|
+
if (!reduced) {
|
|
191
|
+
for (const item of items) {
|
|
192
|
+
const first = firstRects.get(item)
|
|
193
|
+
const last = item.getBoundingClientRect()
|
|
194
|
+
const x = first.left - last.left
|
|
195
|
+
const y = first.top - last.top
|
|
196
|
+
if (Math.abs(x) > 0.5 || Math.abs(y) > 0.5) {
|
|
197
|
+
gsap.fromTo(item, { x, y }, { x: 0, y: 0, duration: 0.16, ease: 'power2.out', clearProps: 'transform' })
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const autoScroll = drag => {
|
|
203
|
+
if (!drag || state.drag !== drag) return
|
|
204
|
+
const pointerY = drag.pointerY
|
|
205
|
+
const targets = drag.scrollTargets || []
|
|
206
|
+
for (const target of targets) {
|
|
207
|
+
const root = target === document.scrollingElement
|
|
208
|
+
? { top: 0, bottom: window.innerHeight }
|
|
209
|
+
: target.getBoundingClientRect()
|
|
210
|
+
const threshold = Math.min(78, Math.max(42, (root.bottom - root.top) * 0.14))
|
|
211
|
+
let delta = 0
|
|
212
|
+
if (pointerY < root.top + threshold) {
|
|
213
|
+
const strength = 1 - Math.max(0, pointerY - root.top) / threshold
|
|
214
|
+
if (target.scrollTop > 0) delta = -Math.ceil(4 + strength * 14)
|
|
215
|
+
} else if (pointerY > root.bottom - threshold) {
|
|
216
|
+
const max = target.scrollHeight - target.clientHeight
|
|
217
|
+
const strength = 1 - Math.max(0, root.bottom - pointerY) / threshold
|
|
218
|
+
if (target.scrollTop < max) delta = Math.ceil(4 + strength * 14)
|
|
219
|
+
}
|
|
220
|
+
if (delta) {
|
|
221
|
+
target.scrollTop = Math.max(0, Math.min(target.scrollHeight - target.clientHeight, target.scrollTop + delta))
|
|
222
|
+
reorderDraggedItems(drag, pointerY)
|
|
223
|
+
break
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
drag.scrollRaf = raf(() => autoScroll(drag))
|
|
227
|
+
}
|
|
228
|
+
const restoreStyle = (item, style) => {
|
|
229
|
+
if (style == null) item.removeAttribute('style')
|
|
230
|
+
else item.setAttribute('style', style)
|
|
231
|
+
}
|
|
232
|
+
const orderFrom = drag => {
|
|
233
|
+
const order = []
|
|
234
|
+
for (const child of drag.list.children) {
|
|
235
|
+
if (child === drag.placeholder) order.push(keyFrom(drag.item))
|
|
236
|
+
else if (child !== drag.item && child.matches?.(selector)) order.push(keyFrom(child))
|
|
237
|
+
}
|
|
238
|
+
return order
|
|
239
|
+
}
|
|
240
|
+
const animateDrop = (drag, commit) => {
|
|
241
|
+
const floating = drag.item.getBoundingClientRect()
|
|
242
|
+
const order = orderFrom(drag)
|
|
243
|
+
drag.list.insertBefore(drag.item, drag.placeholder)
|
|
244
|
+
drag.placeholder.remove()
|
|
245
|
+
restoreStyle(drag.item, drag.originalStyle)
|
|
246
|
+
const finalRect = drag.item.getBoundingClientRect()
|
|
247
|
+
const dx = floating.left - finalRect.left
|
|
248
|
+
const dy = floating.top - finalRect.top
|
|
249
|
+
if (!reduced && (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5)) {
|
|
250
|
+
gsap.fromTo(drag.item, { x: dx, y: dy, scale: 1.02 }, {
|
|
251
|
+
x: 0,
|
|
252
|
+
y: 0,
|
|
253
|
+
scale: 1,
|
|
254
|
+
duration: 0.24,
|
|
255
|
+
ease: 'power2.out',
|
|
256
|
+
clearProps: 'transform'
|
|
257
|
+
})
|
|
258
|
+
} else if (reduced) clear(drag.item)
|
|
259
|
+
if (commit) {
|
|
260
|
+
const callback = drag.options.onCommit
|
|
261
|
+
const payload = { item: drag.item, list: drag.list, group: drag.group, order }
|
|
262
|
+
if (callback) setTimeout(() => callback(payload), reduced ? 0 : 240)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const restoreDrag = (drag, commit) => {
|
|
266
|
+
if (!commit) {
|
|
267
|
+
const originalNext = drag.originalNextSibling?.parentElement === drag.list ? drag.originalNextSibling : null
|
|
268
|
+
drag.list.insertBefore(drag.placeholder, originalNext)
|
|
269
|
+
}
|
|
270
|
+
animateDrop(drag, commit)
|
|
271
|
+
}
|
|
272
|
+
const setPageScrollLock = locked => {
|
|
273
|
+
document.documentElement.classList.toggle('reorder-scroll-lock', locked)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const cancelPress = () => {
|
|
277
|
+
if (!state.press) return
|
|
278
|
+
clearTimeout(state.press.timer)
|
|
279
|
+
state.press.item.classList.remove('reorder-pressing')
|
|
280
|
+
state.press = null
|
|
281
|
+
}
|
|
282
|
+
const finishDrag = (commit) => {
|
|
283
|
+
const drag = state.drag
|
|
284
|
+
if (!drag) return
|
|
285
|
+
state.drag = null
|
|
286
|
+
drag.item.classList.remove('reorder-dragging')
|
|
287
|
+
drag.item.removeAttribute('aria-grabbed')
|
|
288
|
+
drag.item.releasePointerCapture?.(drag.pointerId)
|
|
289
|
+
if (drag.scrollRaf != null) caf(drag.scrollRaf)
|
|
290
|
+
container.classList.remove('reorder-active')
|
|
291
|
+
setPageScrollLock(false)
|
|
292
|
+
if (commit) state.suppressClickUntil = Date.now() + 680
|
|
293
|
+
restoreDrag(drag, commit)
|
|
294
|
+
}
|
|
295
|
+
const activate = () => {
|
|
296
|
+
const press = state.press
|
|
297
|
+
if (!press) return
|
|
298
|
+
state.press = null
|
|
299
|
+
const rect = press.item.getBoundingClientRect()
|
|
300
|
+
const originalNextSibling = press.item.nextElementSibling
|
|
301
|
+
const placeholder = document.createElement('div')
|
|
302
|
+
placeholder.className = 'reorder-placeholder'
|
|
303
|
+
placeholder.setAttribute('aria-hidden', 'true')
|
|
304
|
+
placeholder.style.height = `${rect.height}px`
|
|
305
|
+
placeholder.style.width = `${rect.width}px`
|
|
306
|
+
press.item.before(placeholder)
|
|
307
|
+
state.drag = {
|
|
308
|
+
...press,
|
|
309
|
+
options: state.options,
|
|
310
|
+
placeholder,
|
|
311
|
+
originalStyle: press.item.getAttribute('style'),
|
|
312
|
+
originalNextSibling,
|
|
313
|
+
startY: press.y,
|
|
314
|
+
pointerY: press.y,
|
|
315
|
+
scrollTargets: scrollTargetsFrom(press.item)
|
|
316
|
+
}
|
|
317
|
+
press.item.setPointerCapture?.(press.pointerId)
|
|
318
|
+
press.item.classList.remove('reorder-pressing')
|
|
319
|
+
press.item.classList.add('reorder-dragging')
|
|
320
|
+
press.item.setAttribute('aria-grabbed', 'true')
|
|
321
|
+
press.item.style.position = 'fixed'
|
|
322
|
+
press.item.style.left = `${rect.left}px`
|
|
323
|
+
press.item.style.top = `${rect.top}px`
|
|
324
|
+
press.item.style.width = `${rect.width}px`
|
|
325
|
+
press.item.style.zIndex = '20'
|
|
326
|
+
press.item.style.pointerEvents = 'none'
|
|
327
|
+
if (!reduced) {
|
|
328
|
+
gsap.set(press.item, { scale: 1.02 })
|
|
329
|
+
state.drag.yTo = gsap.quickTo(press.item, 'y', { duration: 0.12, ease: 'power2.out' })
|
|
330
|
+
}
|
|
331
|
+
container.classList.add('reorder-active')
|
|
332
|
+
setPageScrollLock(true)
|
|
333
|
+
const drag = state.drag
|
|
334
|
+
drag.scrollRaf = raf(() => autoScroll(drag))
|
|
335
|
+
}
|
|
336
|
+
const onPointerDown = event => {
|
|
337
|
+
if (state.press || state.drag) return
|
|
338
|
+
if (event.button != null && event.button !== 0) return
|
|
339
|
+
const item = itemFrom(event.target)
|
|
340
|
+
if (!item || !container.contains(item)) return
|
|
341
|
+
const currentOptions = state.options || {}
|
|
342
|
+
if (currentOptions.handleSelector && !event.target.closest(currentOptions.handleSelector)) return
|
|
343
|
+
if (currentOptions.excludeSelector && event.target.closest(currentOptions.excludeSelector)) return
|
|
344
|
+
const list = listFrom(item)
|
|
345
|
+
const group = groupFrom(item)
|
|
346
|
+
if (!itemsFrom(list).includes(item)) return
|
|
347
|
+
const press = { item, list, group, pointerId: event.pointerId, x: event.clientX, y: event.clientY, timer: 0 }
|
|
348
|
+
press.timer = setTimeout(activate, LONG_PRESS_MS)
|
|
349
|
+
state.press = press
|
|
350
|
+
item.classList.add('reorder-pressing')
|
|
351
|
+
}
|
|
352
|
+
const onPointerMove = event => {
|
|
353
|
+
const press = state.press
|
|
354
|
+
if (press && !state.drag) {
|
|
355
|
+
if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > MOVE_TOLERANCE) cancelPress()
|
|
356
|
+
return
|
|
357
|
+
}
|
|
358
|
+
const drag = state.drag
|
|
359
|
+
if (!drag || drag.pointerId !== event.pointerId) return
|
|
360
|
+
event.preventDefault()
|
|
361
|
+
drag.pointerY = event.clientY
|
|
362
|
+
if (!reduced) drag.yTo?.(event.clientY - drag.startY)
|
|
363
|
+
reorderDraggedItems(drag, event.clientY)
|
|
364
|
+
}
|
|
365
|
+
const onPointerUp = event => {
|
|
366
|
+
if (state.press?.pointerId === event.pointerId) cancelPress()
|
|
367
|
+
if (state.drag?.pointerId === event.pointerId) finishDrag(true)
|
|
368
|
+
}
|
|
369
|
+
const onPointerCancel = event => {
|
|
370
|
+
if (state.press?.pointerId === event.pointerId) cancelPress()
|
|
371
|
+
if (state.drag?.pointerId === event.pointerId) finishDrag(false)
|
|
372
|
+
}
|
|
373
|
+
const touchPoint = event => event.changedTouches?.[0] || event.touches?.[0]
|
|
374
|
+
const touchPointerEvent = event => {
|
|
375
|
+
const point = touchPoint(event)
|
|
376
|
+
if (!point) return null
|
|
377
|
+
return {
|
|
378
|
+
target: event.target,
|
|
379
|
+
button: 0,
|
|
380
|
+
pointerId: 10000 + point.identifier,
|
|
381
|
+
clientX: point.clientX,
|
|
382
|
+
clientY: point.clientY,
|
|
383
|
+
preventDefault: () => event.preventDefault()
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const onTouchStart = event => {
|
|
387
|
+
const normalized = touchPointerEvent(event)
|
|
388
|
+
if (normalized) onPointerDown(normalized)
|
|
389
|
+
}
|
|
390
|
+
const onTouchMove = event => {
|
|
391
|
+
const normalized = touchPointerEvent(event)
|
|
392
|
+
if (normalized) onPointerMove(normalized)
|
|
393
|
+
}
|
|
394
|
+
const onTouchEnd = event => {
|
|
395
|
+
const normalized = touchPointerEvent(event)
|
|
396
|
+
if (normalized) onPointerUp(normalized)
|
|
397
|
+
}
|
|
398
|
+
const onTouchCancel = event => {
|
|
399
|
+
const normalized = touchPointerEvent(event)
|
|
400
|
+
if (normalized) onPointerCancel(normalized)
|
|
401
|
+
}
|
|
402
|
+
const onDocumentMove = event => {
|
|
403
|
+
if (state.drag) event.preventDefault()
|
|
404
|
+
}
|
|
405
|
+
const pointerIdFromEvent = event => {
|
|
406
|
+
if (event.pointerId != null) return event.pointerId
|
|
407
|
+
const point = touchPoint(event)
|
|
408
|
+
return point ? 10000 + point.identifier : null
|
|
409
|
+
}
|
|
410
|
+
const onDocumentEnd = (event, commit) => {
|
|
411
|
+
const pointerId = pointerIdFromEvent(event)
|
|
412
|
+
if (state.press && (pointerId == null || state.press.pointerId === pointerId)) cancelPress()
|
|
413
|
+
if (state.drag && (pointerId == null || state.drag.pointerId === pointerId)) finishDrag(commit)
|
|
414
|
+
}
|
|
415
|
+
const onWindowBlur = () => onDocumentEnd({}, false)
|
|
416
|
+
const onVisibilityChange = () => {
|
|
417
|
+
if (document.hidden) onDocumentEnd({}, false)
|
|
418
|
+
}
|
|
419
|
+
const onContextMenu = event => {
|
|
420
|
+
if (state.press || state.drag) event.preventDefault()
|
|
421
|
+
}
|
|
422
|
+
const onClick = event => {
|
|
423
|
+
if (Date.now() >= state.suppressClickUntil) return
|
|
424
|
+
if (itemFrom(event.target)) {
|
|
425
|
+
event.preventDefault()
|
|
426
|
+
event.stopPropagation()
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
container.addEventListener('pointerdown', onPointerDown)
|
|
430
|
+
container.addEventListener('pointermove', onPointerMove)
|
|
431
|
+
container.addEventListener('pointerup', onPointerUp)
|
|
432
|
+
container.addEventListener('pointercancel', onPointerCancel)
|
|
433
|
+
container.addEventListener('lostpointercapture', onPointerCancel)
|
|
434
|
+
container.addEventListener('touchstart', onTouchStart, { passive: false })
|
|
435
|
+
container.addEventListener('touchmove', onTouchMove, { passive: false })
|
|
436
|
+
container.addEventListener('touchend', onTouchEnd, { passive: false })
|
|
437
|
+
container.addEventListener('touchcancel', onTouchCancel, { passive: false })
|
|
438
|
+
container.addEventListener('contextmenu', onContextMenu)
|
|
439
|
+
container.addEventListener('click', onClick, true)
|
|
440
|
+
document.addEventListener('touchmove', onDocumentMove, { passive: false, capture: true })
|
|
441
|
+
document.addEventListener('pointermove', onDocumentMove, { passive: false, capture: true })
|
|
442
|
+
document.addEventListener('pointerup', event => onDocumentEnd(event, true), { passive: false, capture: true })
|
|
443
|
+
document.addEventListener('pointercancel', event => onDocumentEnd(event, false), { passive: false, capture: true })
|
|
444
|
+
document.addEventListener('touchend', event => onDocumentEnd(event, true), { passive: false, capture: true })
|
|
445
|
+
document.addEventListener('touchcancel', event => onDocumentEnd(event, false), { passive: false, capture: true })
|
|
446
|
+
window.addEventListener('blur', onWindowBlur)
|
|
447
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
448
|
+
registry.set(selector, state)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function panel(node) {
|
|
452
|
+
if (!node || startedRecently(node)) return
|
|
453
|
+
gsap.killTweensOf(node)
|
|
454
|
+
if (reduced) return clear(node)
|
|
455
|
+
gsap.fromTo(node, { autoAlpha: 0, y: 8 }, {
|
|
456
|
+
autoAlpha: 1,
|
|
457
|
+
y: 0,
|
|
458
|
+
duration: 0.2,
|
|
459
|
+
ease: 'power2.out',
|
|
460
|
+
overwrite: 'auto',
|
|
461
|
+
clearProps: 'opacity,visibility,transform,willChange'
|
|
462
|
+
})
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function popover(node) {
|
|
466
|
+
if (!node || startedRecently(node)) return
|
|
467
|
+
const opensUpward = !!(node.closest('.composer-wrap, .ds-composer') || node.style.bottom)
|
|
468
|
+
gsap.killTweensOf(node)
|
|
469
|
+
if (reduced) return clear(node)
|
|
470
|
+
gsap.fromTo(node, {
|
|
471
|
+
autoAlpha: 0,
|
|
472
|
+
y: opensUpward ? 7 : -7,
|
|
473
|
+
scale: 0.985,
|
|
474
|
+
transformOrigin: opensUpward ? 'bottom left' : 'top right'
|
|
475
|
+
}, {
|
|
476
|
+
autoAlpha: 1,
|
|
477
|
+
y: 0,
|
|
478
|
+
scale: 1,
|
|
479
|
+
duration: 0.18,
|
|
480
|
+
ease: 'power2.out',
|
|
481
|
+
overwrite: 'auto',
|
|
482
|
+
clearProps: 'opacity,visibility,transform,transformOrigin,willChange'
|
|
483
|
+
})
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function activate(node) {
|
|
487
|
+
if (!node || reduced || startedRecently(node, 90)) return
|
|
488
|
+
const target = node.querySelector('.nav-home-orb, .nav-ico, .ds-nav-ico') || node
|
|
489
|
+
gsap.killTweensOf(target)
|
|
490
|
+
gsap.fromTo(target, { scale: 0.9, y: 2 }, {
|
|
491
|
+
scale: 1,
|
|
492
|
+
y: 0,
|
|
493
|
+
duration: 0.22,
|
|
494
|
+
ease: 'power2.out',
|
|
495
|
+
overwrite: 'auto',
|
|
496
|
+
clearProps: 'transform,willChange'
|
|
497
|
+
})
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function overlay(node) {
|
|
501
|
+
if (!node || startedRecently(node)) return
|
|
502
|
+
const card = node.querySelector('.modal-card, .ds-modal-card, .sheet, .ds-drawer') || node
|
|
503
|
+
gsap.killTweensOf([node, card])
|
|
504
|
+
if (reduced) {
|
|
505
|
+
clear([node, card])
|
|
506
|
+
return
|
|
507
|
+
}
|
|
508
|
+
const isSideDrawer = card.classList.contains('ds-drawer')
|
|
509
|
+
const isSheet = card.classList.contains('sheet')
|
|
510
|
+
if (card === node) {
|
|
511
|
+
gsap.fromTo(card,
|
|
512
|
+
{ autoAlpha: 0, x: isSideDrawer ? 28 : 0, y: isSheet ? 24 : 8, scale: isSideDrawer || isSheet ? 1 : 0.985 },
|
|
513
|
+
{ autoAlpha: 1, x: 0, y: 0, scale: 1, duration: isSheet ? 0.24 : 0.2, ease: 'power3.out', overwrite: 'auto', clearProps: 'opacity,visibility,transform,willChange' }
|
|
514
|
+
)
|
|
515
|
+
return
|
|
516
|
+
}
|
|
517
|
+
const tl = gsap.timeline({ defaults: { ease: 'power3.out' } })
|
|
518
|
+
tl.fromTo(node, { autoAlpha: 0 }, { autoAlpha: 1, duration: 0.14, overwrite: 'auto', clearProps: 'opacity,visibility' })
|
|
519
|
+
.fromTo(card,
|
|
520
|
+
{ x: isSideDrawer ? 28 : 0, y: isSheet ? 24 : 8, scale: isSideDrawer || isSheet ? 1 : 0.985 },
|
|
521
|
+
{ x: 0, y: 0, scale: 1, duration: isSheet ? 0.24 : 0.2, overwrite: 'auto', clearProps: 'transform,willChange' },
|
|
522
|
+
'<'
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function pulse(targets) {
|
|
527
|
+
if (reduced) return clear(targets)
|
|
528
|
+
const nodes = typeof targets === 'string' ? document.querySelectorAll(targets) : targets
|
|
529
|
+
for (const node of nodes || []) {
|
|
530
|
+
if (activePulses.has(node)) continue
|
|
531
|
+
activePulses.add(node)
|
|
532
|
+
gsap.to(node, { scale: 1.12, autoAlpha: 0.62, duration: 0.85, ease: 'sine.inOut', repeat: -1, yoyo: true, transformOrigin: '50% 50%' })
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
window.DshMotion = { gsap, reduced: () => reduced, view, list, relayout, bindLongPressReorder, overlay, panel, popover, activate, pulse }
|
|
537
|
+
|
|
538
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
539
|
+
document.querySelectorAll('.view:not(.hidden), .ds-view:not(.hidden), [data-motion-view]:not(.hidden)').forEach(node => view(node))
|
|
540
|
+
}, { once: true })
|
|
541
|
+
|
|
542
|
+
const observer = new MutationObserver(records => {
|
|
543
|
+
for (const record of records) {
|
|
544
|
+
const node = record.target
|
|
545
|
+
if (!(node instanceof HTMLElement)) continue
|
|
546
|
+
const becameVisible = record.oldValue?.split(/\s+/).includes('hidden') && !node.classList.contains('hidden')
|
|
547
|
+
const becameActive = !record.oldValue?.split(/\s+/).includes('active') && node.classList.contains('active')
|
|
548
|
+
if (becameActive && node.matches('.nav-btn, .ds-nav-item')) activate(node)
|
|
549
|
+
if (!becameVisible) continue
|
|
550
|
+
if (node.matches('.view, .ds-view, [data-motion-view]')) view(node)
|
|
551
|
+
else if (node.matches('.modal, .ds-modal, .sheet-backdrop, .sheet, .ds-drawer')) overlay(node)
|
|
552
|
+
else if (node.matches('.composer-menu, .ds-group-menu, .fb-menu')) popover(node)
|
|
553
|
+
else if (node.matches('[data-motion-panel], .wb-panel, .ds-wb-panel, .doctor-body, .settings-subpage')) panel(node)
|
|
554
|
+
}
|
|
555
|
+
})
|
|
556
|
+
observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['class'], attributeOldValue: true })
|
|
557
|
+
})()
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* Small transport policy and independent fallback channels. No dependencies. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root){
|
|
4
|
+
let measuredLatency=0
|
|
5
|
+
const sharedReads=new Map()
|
|
6
|
+
// Bound the whole read (including response bodies), even if WebView fetch
|
|
7
|
+
// does not reject promptly after a network handoff or an abort.
|
|
8
|
+
function readWithDeadline(read,timeoutMs,signal){
|
|
9
|
+
const controller=new AbortController()
|
|
10
|
+
return new Promise((resolve,reject)=>{
|
|
11
|
+
let timer,settled=false
|
|
12
|
+
const finish=(error,value)=>{if(settled)return;settled=true;clearTimeout(timer);signal?.removeEventListener('abort',cancel);if(error)reject(error);else resolve(value)}
|
|
13
|
+
const cancel=()=>{controller.abort();finish(Object.assign(new Error('Read cancelled'),{name:'AbortError'}))}
|
|
14
|
+
signal?.addEventListener('abort',cancel,{once:true})
|
|
15
|
+
if(signal?.aborted){cancel();return}
|
|
16
|
+
timer=setTimeout(()=>{controller.abort();finish(Object.assign(new Error('Read timed out'),{name:'TimeoutError'}))},timeoutMs)
|
|
17
|
+
try{Promise.resolve(read(controller.signal)).then(value=>finish(null,value),error=>finish(error))}catch(error){finish(error)}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
function shareRead(key,read){
|
|
21
|
+
if(sharedReads.has(key))return sharedReads.get(key)
|
|
22
|
+
const job=Promise.resolve().then(read).finally(()=>{if(sharedReads.get(key)===job)sharedReads.delete(key)})
|
|
23
|
+
sharedReads.set(key,job);return job
|
|
24
|
+
}
|
|
25
|
+
function mode(){try{return ['auto','weak','normal'].includes(root.localStorage.getItem('dshNetworkModeV1'))?root.localStorage.getItem('dshNetworkModeV1'):'auto'}catch{return 'auto'}}
|
|
26
|
+
function profile(){
|
|
27
|
+
const selected=mode(),connection=root.navigator?.connection
|
|
28
|
+
const weak=selected==='weak'||selected==='auto'&&(!!connection?.saveData||/^(slow-2g|2g|3g)$/.test(connection?.effectiveType||'')||connection?.rtt>=500||connection?.downlink>0&&connection.downlink<0.8||measuredLatency>=800)
|
|
29
|
+
return {weak,historyPageSize:weak?20:60,readTimeout:weak?90000:45000,pingTimeout:weak?12000:6000,pollTimeout:weak?45000:30000}
|
|
30
|
+
}
|
|
31
|
+
function setMode(value){if(!['auto','weak','normal'].includes(value))return;try{root.localStorage.setItem('dshNetworkModeV1',value)}catch{};return profile()}
|
|
32
|
+
// 弱网下可选关闭流式输出:只保留已完成的消息与工具结果。
|
|
33
|
+
const STREAM_KEY='dshWeakStreamOff'
|
|
34
|
+
function streamSetting(){try{return root.localStorage.getItem(STREAM_KEY)!=='0'}catch{return true}}
|
|
35
|
+
function streamTrimmed(){return streamSetting()&&profile().weak}
|
|
36
|
+
class PollLoop {
|
|
37
|
+
constructor(options){this.options=options;this.jobs={};this.setTimer=options.setTimer||((fn,ms)=>setTimeout(fn,ms));this.clearTimer=options.clearTimer||(timer=>clearTimeout(timer))}
|
|
38
|
+
stop(){for(const job of Object.values(this.jobs)){job.controller.abort();this.clearTimer(job.timer)}this.jobs={}}
|
|
39
|
+
tick(){
|
|
40
|
+
if(!this.options.active()){this.stop();return Promise.resolve()}
|
|
41
|
+
const pending=[]
|
|
42
|
+
for(const kind of ['mux','host']){
|
|
43
|
+
const previous=this.jobs[kind]
|
|
44
|
+
if(previous?.identity.valid())continue
|
|
45
|
+
previous?.controller.abort();this.clearTimer(previous?.timer)
|
|
46
|
+
const job={identity:this.options.capture(),controller:new AbortController(),failures:0}
|
|
47
|
+
this.jobs[kind]=job;pending.push(this.run(kind,job))
|
|
48
|
+
}
|
|
49
|
+
return Promise.all(pending)
|
|
50
|
+
}
|
|
51
|
+
async run(kind,job){
|
|
52
|
+
let delay
|
|
53
|
+
try{delay=await this.options.read(kind,job.controller.signal)}catch{}
|
|
54
|
+
if(this.jobs[kind]!==job||!job.identity.valid()||!this.options.active()||job.controller.signal.aborted)return
|
|
55
|
+
if(Number.isFinite(delay)){job.failures=0;delay=Math.max(100,delay)}
|
|
56
|
+
else{job.failures++;delay=Math.min(30000,4000*2**Math.min(job.failures-1,3))}
|
|
57
|
+
job.timer=this.setTimer(()=>{job.timer=null;if(this.jobs[kind]===job&&job.identity.valid()&&this.options.active())void this.run(kind,job)},delay)
|
|
58
|
+
job.timer?.unref?.()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function preferences(){
|
|
62
|
+
const panel=root.document?.getElementById('settings-page-general');if(!panel)return
|
|
63
|
+
const desktop=panel.classList.contains('ds-settings')
|
|
64
|
+
let row=root.document.getElementById('network-preferences')
|
|
65
|
+
if(!row){
|
|
66
|
+
row=root.document.createElement('div');row.id='network-preferences';row.className=desktop?'ds-setting-row':'setting-row'
|
|
67
|
+
const copy=root.document.createElement('div'),title=root.document.createElement('div'),detail=root.document.createElement('div'),select=root.document.createElement('select')
|
|
68
|
+
title.dataset.networkTitle='';detail.dataset.networkDetail='';title.className=desktop?'ds-setting-name':'setting-name';detail.className=desktop?'ds-setting-desc':'setting-desc';select.id='network-mode';select.className='setting-select'
|
|
69
|
+
for(const value of ['auto','weak','normal']){const option=root.document.createElement('option');option.value=value;select.append(option)}
|
|
70
|
+
copy.append(title,detail);row.append(copy,select)
|
|
71
|
+
const target=panel.querySelector('[data-workflow-settings-slot="input"]')||panel
|
|
72
|
+
target.append(row)
|
|
73
|
+
const section=target.closest?.('.workflow-settings-section');if(section)section.hidden=false
|
|
74
|
+
select.addEventListener('change',()=>{setMode(select.value);root.applyStreamPreference?.();root.enhanceCustomSelect?.(select)})
|
|
75
|
+
}
|
|
76
|
+
let streamRow=root.document.getElementById('network-stream-preferences')
|
|
77
|
+
if(!streamRow){
|
|
78
|
+
streamRow=root.document.createElement('div');streamRow.id='network-stream-preferences';streamRow.className=desktop?'ds-setting-row':'setting-row'
|
|
79
|
+
const copy=root.document.createElement('div'),title=root.document.createElement('div'),detail=root.document.createElement('div'),label=root.document.createElement('label'),input=root.document.createElement('input'),slider=root.document.createElement('span')
|
|
80
|
+
title.dataset.streamTitle='';detail.dataset.streamDetail='';title.className=desktop?'ds-setting-name':'setting-name';detail.className=desktop?'ds-setting-desc':'setting-desc'
|
|
81
|
+
input.type='checkbox';input.id='opt-weak-stream-off';label.className=desktop?'ds-switch':'switch';slider.className=desktop?'ds-slider':'slider'
|
|
82
|
+
label.append(input,slider);copy.append(title,detail);streamRow.append(copy,label)
|
|
83
|
+
const target=panel.querySelector('[data-workflow-settings-slot="input"]')||panel
|
|
84
|
+
target.append(streamRow)
|
|
85
|
+
const section=target.closest?.('.workflow-settings-section');if(section)section.hidden=false
|
|
86
|
+
input.addEventListener('change',()=>{try{root.localStorage.setItem(STREAM_KEY,input.checked?'1':'0')}catch{};root.applyStreamPreference?.()})
|
|
87
|
+
}
|
|
88
|
+
const english=root.I18N?.lang==='en'
|
|
89
|
+
row.querySelector('[data-network-title]').textContent=english?'Network mode':'网络模式'
|
|
90
|
+
row.querySelector('[data-network-detail]').textContent=english?'Weak mode loads fewer history entries and allows longer read waits. Sending is never retried automatically.':'弱网模式减少每页历史条数、延长读取等待;发送操作不会自动重试。'
|
|
91
|
+
const select=row.querySelector('select');select.setAttribute('aria-label',english?'Network mode':'网络模式');['auto','weak','normal'].forEach((v,i)=>select.options[i].textContent=(english?['Automatic','Weak network','Standard']:['自动判断','弱网优先','标准模式'])[i]);select.value=mode();root.enhanceCustomSelect?.(select);root.syncCustomSelect?.(select)
|
|
92
|
+
const streamInput=streamRow.querySelector('input');if(streamInput){streamInput.checked=streamSetting();streamInput.setAttribute('aria-label',english?'Disable streaming on weak networks':'弱网时关闭流式输出')}
|
|
93
|
+
const streamTitle=streamRow.querySelector('[data-stream-title]'),streamDetail=streamRow.querySelector('[data-stream-detail]')
|
|
94
|
+
if(streamTitle)streamTitle.textContent=english?'No streaming on weak networks':'弱网时关闭流式输出'
|
|
95
|
+
if(streamDetail)streamDetail.textContent=english?'Show only finished messages and tool results on weak networks; live thinking and calls that have not returned stay hidden.':'弱网下只显示已完成的消息和工具结果,隐藏流式思考和尚未返回的工具调用;标准网络不受影响。'
|
|
96
|
+
}
|
|
97
|
+
const api={profile,setMode,PollLoop,shareRead,readWithDeadline,observeLatency:ms=>{if(Number.isFinite(ms))measuredLatency=ms},preferences,streamTrimmed}
|
|
98
|
+
if(typeof module!=='undefined'&&module.exports)module.exports=api
|
|
99
|
+
else{root.DshNetwork=api;root.document.addEventListener('DOMContentLoaded',()=>{preferences();new MutationObserver(preferences).observe(root.document.documentElement,{attributes:true,attributeFilter:['lang']})})}
|
|
100
|
+
})(typeof window==='undefined'?globalThis:window)
|