@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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* Android system bridge; browsers keep the existing QR/manual connection paths. */
|
|
2
|
+
;(function(root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
root.DshLanDiscovery = { mount(button, paired) {
|
|
5
|
+
const bridge = root.NativeLan
|
|
6
|
+
if (!button || !bridge?.search) return
|
|
7
|
+
button.classList.remove('hidden')
|
|
8
|
+
const en = () => root.I18N?.lang === 'en'
|
|
9
|
+
const text = (zh, english) => en() ? english : zh
|
|
10
|
+
let modal, timer, selected = '', hosts = [], signature = '', busy = false, open = false
|
|
11
|
+
function status(value) { modal.querySelector('[data-lan-status]').textContent = value }
|
|
12
|
+
function close() {
|
|
13
|
+
open = false; clearTimeout(timer); bridge.cancel(); modal?.remove(); modal = null
|
|
14
|
+
button.focus()
|
|
15
|
+
}
|
|
16
|
+
function search() {
|
|
17
|
+
selected = ''; signature = ''; hosts = []; busy = false
|
|
18
|
+
modal.querySelector('[data-lan-pair]').classList.add('hidden')
|
|
19
|
+
modal.querySelector('[data-lan-list]').replaceChildren()
|
|
20
|
+
status(text('正在搜索同一 Wi-Fi 下开放配对的电脑…', 'Searching for computers accepting pairing on this Wi-Fi…'))
|
|
21
|
+
bridge.search()
|
|
22
|
+
clearTimeout(timer); tick()
|
|
23
|
+
}
|
|
24
|
+
function tick() {
|
|
25
|
+
if (!open || !modal) return
|
|
26
|
+
try {
|
|
27
|
+
const state = JSON.parse(bridge.getState() || '{}')
|
|
28
|
+
busy = state.phase === 'pairing'
|
|
29
|
+
modal.querySelector('[data-lan-search]').disabled = busy
|
|
30
|
+
modal.querySelector('[data-lan-connect]').disabled = busy
|
|
31
|
+
modal.querySelector('[data-lan-code]').disabled = busy
|
|
32
|
+
const entries = Array.isArray(state.hosts) ? state.hosts.slice(0, 32) : []
|
|
33
|
+
const next = JSON.stringify(entries)
|
|
34
|
+
if (next !== signature) {
|
|
35
|
+
signature = next; hosts = entries
|
|
36
|
+
const list = modal.querySelector('[data-lan-list]'); list.replaceChildren()
|
|
37
|
+
for (const host of hosts) {
|
|
38
|
+
const entry = document.createElement('button'); entry.type = 'button'; entry.className = 'btn subtle'
|
|
39
|
+
entry.textContent = String(host.name || 'DSH Remote') + ' · ' + String(host.server || '')
|
|
40
|
+
entry.addEventListener('click', () => {
|
|
41
|
+
if (busy) return
|
|
42
|
+
selected = host.id
|
|
43
|
+
modal.querySelector('[data-lan-selected]').textContent = String(host.name || host.server)
|
|
44
|
+
modal.querySelector('[data-lan-pair]').classList.remove('hidden')
|
|
45
|
+
modal.querySelector('[data-lan-code]').focus()
|
|
46
|
+
}); list.append(entry)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (state.phase === 'paired') {
|
|
50
|
+
const result = JSON.parse(bridge.takePairResult() || '{}')
|
|
51
|
+
if (!hosts.some(host => host.server === result.server) || typeof result.token !== 'string') throw Error('PAIRING_RESPONSE_INVALID')
|
|
52
|
+
// Close before applying credentials, so no stale poll can apply them a second time.
|
|
53
|
+
close(); paired(result); return
|
|
54
|
+
}
|
|
55
|
+
if (state.phase === 'pairing') status(text('正在验证配对码并连接…', 'Verifying the pairing code…'))
|
|
56
|
+
else if (state.phase === 'done') status(hosts.length ? text('请选择电脑并输入配对码。', 'Select a computer and enter its pairing code.')
|
|
57
|
+
: text('没有找到电脑。请在电脑端开启局域网配对,确认同一 Wi-Fi;也可继续扫码或手动连接。', 'No computers found. Open LAN pairing on the computer and check Wi-Fi, or use QR/manual connection.'))
|
|
58
|
+
else if (state.phase === 'error') {
|
|
59
|
+
const errors = {
|
|
60
|
+
WIFI_REQUIRED: text('请先连接 Wi-Fi。', 'Connect to Wi-Fi first.'),
|
|
61
|
+
NETWORK_PERMISSION_REQUIRED: text('请检查系统网络访问权限。', 'Check system network permissions.'),
|
|
62
|
+
PAIRING_CODE_INVALID: text('配对码不匹配,请核对电脑端显示的配对码。', 'Pairing code does not match the computer.'),
|
|
63
|
+
PAIRING_CLOSED: text('配对已关闭或过期,请在电脑端重新开启。', 'Pairing expired or closed. Reopen it on the computer.'),
|
|
64
|
+
}
|
|
65
|
+
status(errors[state.error] || text('搜索或配对失败,请检查网络后重试;也可扫码连接。', 'Search or pairing failed. Check the network or use QR pairing.'))
|
|
66
|
+
}
|
|
67
|
+
} catch { if (modal) status(text('无法读取搜索状态,请重新搜索。', 'Unable to read discovery status. Search again.')) }
|
|
68
|
+
timer = setTimeout(tick, 300)
|
|
69
|
+
}
|
|
70
|
+
button.addEventListener('click', () => {
|
|
71
|
+
if (open) return
|
|
72
|
+
open = true
|
|
73
|
+
modal = document.createElement('div'); modal.className = 'modal'; modal.setAttribute('role', 'dialog'); modal.setAttribute('aria-modal', 'true')
|
|
74
|
+
modal.innerHTML = '<div class="modal-card lan-discovery-card"><div class="modal-title" data-lan-title></div><p data-lan-status role="status" aria-live="polite"></p><div data-lan-list class="lan-host-list"></div><div data-lan-pair class="hidden"><p data-lan-selected></p><label><span data-lan-label></span><input data-lan-code type="password" maxlength="24" autocomplete="off" spellcheck="false" placeholder="XXXX-XXXX-XXXX-XXXX-XXXX"></label><button data-lan-connect class="btn primary" type="button"></button></div><div class="modal-actions"><button data-lan-search class="btn subtle" type="button"></button><button data-lan-close class="btn subtle" type="button"></button></div></div>'
|
|
75
|
+
modal.querySelector('[data-lan-title]').textContent = text('搜索局域网电脑', 'Find a computer on Wi-Fi')
|
|
76
|
+
modal.querySelector('[data-lan-label]').textContent = text('电脑端显示的限时配对码', 'One-time code shown on the computer')
|
|
77
|
+
modal.querySelector('[data-lan-connect]').textContent = text('配对连接', 'Pair and connect')
|
|
78
|
+
modal.querySelector('[data-lan-search]').textContent = text('重新搜索', 'Search again')
|
|
79
|
+
modal.querySelector('[data-lan-close]').textContent = text('关闭', 'Close')
|
|
80
|
+
modal.querySelector('[data-lan-close]').addEventListener('click', close)
|
|
81
|
+
modal.querySelector('[data-lan-search]').addEventListener('click', search)
|
|
82
|
+
modal.querySelector('[data-lan-connect]').addEventListener('click', () => {
|
|
83
|
+
if (busy) return
|
|
84
|
+
const input = modal.querySelector('[data-lan-code]'), code = input.value
|
|
85
|
+
if (!selected || !/^[a-f0-9]{20}$/i.test(code.replace(/[\s-]/g, ''))) return status(text('请选择电脑,输入完整的 20 位配对码。', 'Select a computer and enter the full 20-character code.'))
|
|
86
|
+
if (!bridge.pair(selected, code)) return status(text('无法开始配对,请重新搜索后重试。', 'Could not start pairing. Search again.'))
|
|
87
|
+
input.value = ''; busy = true; clearTimeout(timer); tick()
|
|
88
|
+
})
|
|
89
|
+
modal.addEventListener('keydown', event => { if (event.key === 'Escape') { event.preventDefault(); close() } })
|
|
90
|
+
document.body.append(modal); modal.querySelector('[data-lan-search]').focus(); search()
|
|
91
|
+
})
|
|
92
|
+
document.addEventListener('visibilitychange', () => { if (document.hidden && open) close() })
|
|
93
|
+
} }
|
|
94
|
+
})(typeof window === 'object' ? window : globalThis)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* Active overview checks. Reuses the existing WS reconnect policy; no extra heartbeat frames. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root){
|
|
4
|
+
class LinkCheck {
|
|
5
|
+
constructor(options){
|
|
6
|
+
this.options=options;this.timer=null;this.graceTimer=null;this.epoch=0;this.job=null;this.abort=null;this.attempt=0
|
|
7
|
+
this.model={phase:'idle',gateway:null,probing:false,checks:{gateway:false,dsh:false,mux:false,host:false}}
|
|
8
|
+
this.now=options.now||Date.now;this.setTimer=options.setTimer||((fn,delay)=>setTimeout(fn,delay));this.clearTimer=options.clearTimer||(id=>clearTimeout(id))
|
|
9
|
+
}
|
|
10
|
+
emit(){this.options.changed?.(this.model)}
|
|
11
|
+
clearTimers(){this.clearTimer(this.timer);this.clearTimer(this.graceTimer);this.timer=this.graceTimer=null}
|
|
12
|
+
pause(){this.epoch++;this.clearTimers();this.abort?.abort();this.abort=null;this.job=null;this.model.probing=false;this.model.phase='idle'}
|
|
13
|
+
start(force=false){
|
|
14
|
+
if(!this.options.active()){this.pause();return}
|
|
15
|
+
if(!force&&this.model.phase!=='idle'){this.observe();return}
|
|
16
|
+
if(force&&this.model.probing&&this.options.configured()&&this.options.online())return
|
|
17
|
+
this.pause();this.attempt=0;this.deadline=this.now()+20000;this.model.gateway=null
|
|
18
|
+
this.model.phase=!this.options.configured()?'unconfigured':!this.options.online()?'offline':'checking'
|
|
19
|
+
this.model.checks=this.options.snapshot();this.emit()
|
|
20
|
+
if(this.model.phase!=='checking')return
|
|
21
|
+
const epoch=this.epoch
|
|
22
|
+
this.graceTimer=this.setTimer(()=>{if(epoch!==this.epoch)return;this.graceTimer=null;if(this.model.phase==='checking'){this.model.phase='degraded';this.emit()}},20000)
|
|
23
|
+
void this.run()
|
|
24
|
+
}
|
|
25
|
+
observe(){
|
|
26
|
+
if(!this.options.active())return
|
|
27
|
+
const checks=this.options.snapshot(),key=JSON.stringify(checks),previous=JSON.stringify(this.model.checks)
|
|
28
|
+
this.model.checks=checks
|
|
29
|
+
if(this.options.configured()&&this.options.online()&&Object.values(checks).every(Boolean)){
|
|
30
|
+
if(this.model.phase!=='ready'){this.model.phase='ready';this.clearTimer(this.graceTimer);this.graceTimer=null;if(!this.model.probing)this.schedule(30000);this.emit()}
|
|
31
|
+
else if(key!==previous)this.emit()
|
|
32
|
+
}else if(this.model.phase==='ready'){
|
|
33
|
+
this.start(true)
|
|
34
|
+
}else if(key!==previous)this.emit()
|
|
35
|
+
}
|
|
36
|
+
schedule(delay){this.clearTimer(this.timer);const epoch=this.epoch;this.timer=this.setTimer(()=>{this.timer=null;if(epoch===this.epoch)void this.run()},delay)}
|
|
37
|
+
async run(){
|
|
38
|
+
if(!this.options.active()){this.pause();return}
|
|
39
|
+
if(!this.options.configured()||!this.options.online()){this.start(true);return}
|
|
40
|
+
if(this.job)return this.job
|
|
41
|
+
const epoch=this.epoch,abort=new AbortController();this.abort=abort;this.model.probing=true;this.emit()
|
|
42
|
+
const job=Promise.resolve().then(async()=>{
|
|
43
|
+
try{
|
|
44
|
+
this.options.repair()
|
|
45
|
+
const result=await this.options.probe(abort.signal)
|
|
46
|
+
if(epoch!==this.epoch)return
|
|
47
|
+
this.model.gateway=result.gateway===true
|
|
48
|
+
}catch{if(epoch===this.epoch)this.model.gateway=false}
|
|
49
|
+
if(epoch!==this.epoch)return
|
|
50
|
+
this.model.checks=this.options.snapshot()
|
|
51
|
+
const complete=Object.values(this.model.checks).every(Boolean)
|
|
52
|
+
this.model.phase=complete?'ready':this.now()<this.deadline?'checking':'degraded'
|
|
53
|
+
this.model.probing=false;this.emit()
|
|
54
|
+
if(complete){this.clearTimer(this.graceTimer);this.graceTimer=null}
|
|
55
|
+
if(this.options.active())this.schedule(complete||this.model.phase==='degraded'?30000:[2000,5000,10000][Math.min(this.attempt++,2)])
|
|
56
|
+
}).finally(()=>{if(epoch===this.epoch&&this.job===job){this.job=null;this.abort=null}})
|
|
57
|
+
this.job=job;return job
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/* Visual feedback never delays or changes network state. CSS owns the continuous sweep. */
|
|
61
|
+
class PulseVisual {
|
|
62
|
+
constructor(options){
|
|
63
|
+
this.card=options.card;this.active=options.active||(()=>!root.document?.hidden)
|
|
64
|
+
this.reduced=options.reduced||(()=>!!root.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
|
|
65
|
+
this.setTimer=options.setTimer||((fn,delay)=>setTimeout(fn,delay));this.clearTimer=options.clearTimer||(id=>clearTimeout(id))
|
|
66
|
+
this.checking=false;this.settleTimer=null;this.textJobs=new Map()
|
|
67
|
+
root.matchMedia?.('(prefers-reduced-motion: reduce)').addEventListener?.('change',event=>{if(event.matches)this.pause();else this.setChecking(this.card.classList.contains('status-checking'))})
|
|
68
|
+
}
|
|
69
|
+
setChecking(checking){
|
|
70
|
+
if(!this.active()||this.reduced()){this.pause();return}
|
|
71
|
+
if(checking===this.checking)return
|
|
72
|
+
this.checking=checking;this.clearTimer(this.settleTimer);this.settleTimer=null
|
|
73
|
+
if(checking)this.card.dataset.pulseRunning='true'
|
|
74
|
+
else this.settleTimer=this.setTimer(()=>{this.settleTimer=null;this.card.dataset.pulseRunning='false'},240)
|
|
75
|
+
}
|
|
76
|
+
setLinks(checks){
|
|
77
|
+
for(const segment of this.card.querySelectorAll('[data-pulse-link]'))segment.setAttribute('data-confirmed',String(checks[segment.getAttribute('data-pulse-link')]===true))
|
|
78
|
+
}
|
|
79
|
+
clearText(node){
|
|
80
|
+
const previous=this.textJobs.get(node);if(!previous)return
|
|
81
|
+
this.textJobs.delete(node);previous.enter?.cancel();previous.exit?.cancel();previous.echo?.remove()
|
|
82
|
+
}
|
|
83
|
+
text(node,value){
|
|
84
|
+
if(!node||node.textContent===value)return
|
|
85
|
+
const interrupted=this.textJobs.has(node),previous=node.textContent,style=root.getComputedStyle?.(node),opacity=style?.opacity||'1',transform=style?.transform||'none'
|
|
86
|
+
this.clearText(node)
|
|
87
|
+
const animate=!!previous&&previous!=='—'&&this.active()&&!this.reduced()&&typeof node.animate==='function'
|
|
88
|
+
let echo
|
|
89
|
+
if(animate){
|
|
90
|
+
echo=node.cloneNode(false);echo.removeAttribute('id');echo.removeAttribute('aria-live');echo.removeAttribute('data-i18n');echo.setAttribute('aria-hidden','true');echo.classList.add('pulse-text-echo');echo.textContent=previous
|
|
91
|
+
Object.assign(echo.style,{left:node.offsetLeft+'px',top:node.offsetTop+'px',width:node.offsetWidth+'px',margin:'0'})
|
|
92
|
+
node.parentElement.appendChild(echo)
|
|
93
|
+
}
|
|
94
|
+
node.textContent=value
|
|
95
|
+
if(!animate)return
|
|
96
|
+
const timing={duration:240,easing:'cubic-bezier(0.23, 1, 0.32, 1)'},job={echo}
|
|
97
|
+
job.enter=node.animate([{opacity:interrupted?opacity:0,transform:transform==='none'?'translateY(3px)':transform},{opacity:1,transform:'translateY(0)'}],timing)
|
|
98
|
+
job.exit=echo.animate([{opacity,transform},{opacity:0,transform:'translateY(-3px)'}],timing)
|
|
99
|
+
this.textJobs.set(node,job)
|
|
100
|
+
Promise.all([job.enter.finished,job.exit.finished]).catch(()=>{}).finally(()=>{if(this.textJobs.get(node)===job){this.textJobs.delete(node);echo.remove()}})
|
|
101
|
+
}
|
|
102
|
+
pause(){
|
|
103
|
+
this.clearTimer(this.settleTimer);this.settleTimer=null;this.checking=false;this.card.dataset.pulseRunning='false'
|
|
104
|
+
for(const node of [...this.textJobs.keys()])this.clearText(node)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if(typeof module!=='undefined'&&module.exports)module.exports={LinkCheck,PulseVisual}
|
|
108
|
+
else root.DshLinkCheck={LinkCheck,PulseVisual}
|
|
109
|
+
})(typeof window==='undefined'?globalThis:window)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DSH Remote",
|
|
3
|
+
"short_name": "DSH Remote",
|
|
4
|
+
"start_url": "/",
|
|
5
|
+
"display": "standalone",
|
|
6
|
+
"background_color": "#0b0e1a",
|
|
7
|
+
"theme_color": "#0b0e1a",
|
|
8
|
+
"icons": [
|
|
9
|
+
{
|
|
10
|
+
"src": "icon.svg",
|
|
11
|
+
"sizes": "any",
|
|
12
|
+
"type": "image/svg+xml",
|
|
13
|
+
"purpose": "any"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
package/public/md.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/* DSH Remote 轻量 Markdown 渲染器 · 零依赖
|
|
2
|
+
* 用法: mdToHtml(text) -> HTML 字符串
|
|
3
|
+
* 安全: 先 HTML 转义再转标记; 链接仅允许 http/https, 其余保留为纯文本。
|
|
4
|
+
* 支持: 代码块 / 行内代码 / #~### 标题 / **粗体** / *斜体* / - 无序列表 /
|
|
5
|
+
* 1. 有序列表 / > 引用 / GFM 表格 / [text](url) 链接 / 换行。
|
|
6
|
+
* 同时支持浏览器全局 window.mdToHtml 与 Node CommonJS module.exports。
|
|
7
|
+
*/
|
|
8
|
+
(function (root, factory) {
|
|
9
|
+
if (typeof module === 'object' && module.exports) module.exports = factory(require('./genui.js'), require('./chat-files.js'), () => require('./chat-copy.js'))
|
|
10
|
+
else root.mdToHtml = factory(root.DshGenUi, root.DshChatFiles, () => root.DshChatCopy)
|
|
11
|
+
})(typeof self !== 'undefined' ? self : this, function (genui, files, chatCopy) {
|
|
12
|
+
'use strict'
|
|
13
|
+
|
|
14
|
+
function escapeHtml(s) {
|
|
15
|
+
return String(s).replace(/[&<>"']/g, function (c) {
|
|
16
|
+
return {
|
|
17
|
+
'&': '&',
|
|
18
|
+
'<': '<',
|
|
19
|
+
'>': '>',
|
|
20
|
+
'"': '"',
|
|
21
|
+
"'": '''
|
|
22
|
+
}[c]
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function decodeEntities(s) {
|
|
27
|
+
const entities = { '&': '&', '"': '"', ''': "'", '<': '<', '>': '>' }
|
|
28
|
+
return String(s).replace(/&(?:amp|quot|lt|gt|#39);/g, entity => entities[entity])
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let imageLabel = '图片'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Markdown images become preview buttons. Remote/data URLs can load directly;
|
|
35
|
+
* local paths are placeholders that the client resolves through the authenticated file API.
|
|
36
|
+
* Returns null when the target is neither an image URL nor a local path.
|
|
37
|
+
*/
|
|
38
|
+
function imageHtml(altEscaped, urlEscaped, fileLinks, imageHosts) {
|
|
39
|
+
let raw = String(urlEscaped || '').trim()
|
|
40
|
+
if (raw.startsWith('<') && raw.endsWith('>')) raw = raw.slice(4, -4)
|
|
41
|
+
let target = decodeEntities(raw)
|
|
42
|
+
if (/^file:/i.test(target) && files?.pathOf) target = files.pathOf(target) || target
|
|
43
|
+
const alt = decodeEntities(String(altEscaped || '')).replace(/<[^>]*>/g, '').trim()
|
|
44
|
+
const label = escapeHtml(alt || imageLabel)
|
|
45
|
+
if (Array.isArray(imageHosts)) {
|
|
46
|
+
let allowed = false
|
|
47
|
+
try { const url = new URL(target); allowed = url.protocol === 'https:' && !url.username && !url.password && imageHosts.includes(url.hostname.toLowerCase()) } catch (_) {}
|
|
48
|
+
if (!allowed) return '<span class="md-image-blocked">' + label + '</span>'
|
|
49
|
+
return '<button type="button" class="chat-image" data-chat-image aria-label="' + label + '"><img src="' + escapeHtml(target) + '" alt="' + label + '" loading="lazy" referrerpolicy="no-referrer" draggable="false"></button>'
|
|
50
|
+
}
|
|
51
|
+
if (/^(?:data:image\/|https?:\/\/|\/api\/)/i.test(target)) {
|
|
52
|
+
return '<button type="button" class="chat-image" data-chat-image aria-label="' + label + '">' +
|
|
53
|
+
'<img src="' + escapeHtml(target) + '" alt="' + label + '" loading="lazy" draggable="false"></button>'
|
|
54
|
+
}
|
|
55
|
+
if (!fileLinks) return null
|
|
56
|
+
const local = /^(?:[A-Za-z]:[\\/]|\\\\|\/|\.{1,2}[\\/]|[^:\s]+[\\/])/.test(target)
|
|
57
|
+
|| /^[^:\s]+\.(?:png|jpe?g|gif|webp|bmp|svg|avif)$/i.test(target)
|
|
58
|
+
if (!local) return null
|
|
59
|
+
return '<button type="button" class="chat-image is-loading" data-chat-image data-chat-image-path="' + escapeHtml(target) +
|
|
60
|
+
'" data-chat-image-alt="' + label + '" aria-label="' + label + '"><span class="chat-image-status">' + label + '</span></button>'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function inline(s, fileLinks, imageHosts) {
|
|
64
|
+
// Pull images out before inline emphasis/link rules so alt text and URLs stay intact.
|
|
65
|
+
const images = []
|
|
66
|
+
s = s.replace(/!\[([^\]]*)\]\(([^)\n]+)\)/g, function (m, alt, url) {
|
|
67
|
+
const html = imageHtml(alt, url, fileLinks, imageHosts)
|
|
68
|
+
if (!html) return m
|
|
69
|
+
images.push(html)
|
|
70
|
+
return '\u0000IMAGE' + (images.length - 1) + '\u0000'
|
|
71
|
+
})
|
|
72
|
+
s = s.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
73
|
+
s = s.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
74
|
+
s = s.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1<em>$2</em>')
|
|
75
|
+
s = s.replace(/\[([^\]]+)\]\(([^)\n]+)\)/g, function (m, text, url) {
|
|
76
|
+
url = url.trim()
|
|
77
|
+
if (url.startsWith('<') && url.endsWith('>')) url = url.slice(4, -4)
|
|
78
|
+
let path
|
|
79
|
+
const entities = { '&': '&', '"': '"', ''': "'", '<': '<', '>': '>' }
|
|
80
|
+
try {
|
|
81
|
+
const raw = url.replace(/&(?:amp|quot|lt|gt);|'/g, entity => entities[entity])
|
|
82
|
+
path = /^file:/i.test(raw) ? files?.pathOf(raw) : decodeURIComponent(raw)
|
|
83
|
+
} catch { return m }
|
|
84
|
+
if (fileLinks && (files?.pathOf(path) || files?.relativePath(path))) return '<a href="#" data-dsh-file-path="' + escapeHtml(path) + '">' + text + '</a>'
|
|
85
|
+
if (!/^https?:\/\//i.test(url) || /\s/.test(url)) return m
|
|
86
|
+
return '<a href="' + url + '" target="_blank" rel="noopener noreferrer">' + text + '</a>'
|
|
87
|
+
})
|
|
88
|
+
return images.length ? s.replace(/\u0000IMAGE(\d+)\u0000/g, (m, index) => images[Number(index)] || '') : s
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function tableCells(line) {
|
|
92
|
+
var s = String(line || '').trim()
|
|
93
|
+
if (s.charAt(0) === '|') s = s.slice(1)
|
|
94
|
+
if (s.charAt(s.length - 1) === '|') s = s.slice(0, -1)
|
|
95
|
+
var cells = []
|
|
96
|
+
var cell = ''
|
|
97
|
+
var escaped = false
|
|
98
|
+
for (var i = 0; i < s.length; i++) {
|
|
99
|
+
var c = s.charAt(i)
|
|
100
|
+
if (escaped) { cell += c; escaped = false; continue }
|
|
101
|
+
if (c === '\\') { escaped = true; continue }
|
|
102
|
+
if (c === '|') { cells.push(cell.trim()); cell = ''; continue }
|
|
103
|
+
cell += c
|
|
104
|
+
}
|
|
105
|
+
if (escaped) cell += '\\'
|
|
106
|
+
cells.push(cell.trim())
|
|
107
|
+
return cells
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function tableAlignment(cell) {
|
|
111
|
+
var s = String(cell || '').trim()
|
|
112
|
+
if (!/^:?-{3,}:?$/.test(s)) return null
|
|
113
|
+
if (s.charAt(0) === ':' && s.charAt(s.length - 1) === ':') return 'center'
|
|
114
|
+
if (s.charAt(0) === ':') return 'left'
|
|
115
|
+
if (s.charAt(s.length - 1) === ':') return 'right'
|
|
116
|
+
return null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function tableAt(lines, start) {
|
|
120
|
+
if (start + 1 >= lines.length || !/\|/.test(lines[start]) || !/\|/.test(lines[start + 1])) return null
|
|
121
|
+
var headers = tableCells(lines[start])
|
|
122
|
+
var separators = tableCells(lines[start + 1])
|
|
123
|
+
if (headers.length < 2 || separators.length !== headers.length) return null
|
|
124
|
+
if (!separators.every(function (cell) { return /^:?-{3,}:?$/.test(String(cell || '').trim()) })) return null
|
|
125
|
+
var alignments = separators.map(tableAlignment)
|
|
126
|
+
var rows = []
|
|
127
|
+
var i = start + 2
|
|
128
|
+
while (i < lines.length && lines[i].trim() && /\|/.test(lines[i])) {
|
|
129
|
+
var cells = tableCells(lines[i])
|
|
130
|
+
if (cells.length !== headers.length) break
|
|
131
|
+
rows.push(cells)
|
|
132
|
+
i++
|
|
133
|
+
}
|
|
134
|
+
return { headers: headers, alignments: alignments, rows: rows, next: i }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function tableHtml(table, fileLinks, imageHosts) {
|
|
138
|
+
function cellTag(tag, value, align) {
|
|
139
|
+
var style = align ? ' style="text-align:' + align + '"' : ''
|
|
140
|
+
return '<' + tag + style + '>' + inline(value, fileLinks, imageHosts) + '</' + tag + '>'
|
|
141
|
+
}
|
|
142
|
+
var head = '<thead><tr>' + table.headers.map(function (value, i) {
|
|
143
|
+
return cellTag('th', value, table.alignments[i])
|
|
144
|
+
}).join('') + '</tr></thead>'
|
|
145
|
+
var body = table.rows.length
|
|
146
|
+
? '<tbody>' + table.rows.map(function (row) {
|
|
147
|
+
return '<tr>' + row.map(function (value, i) {
|
|
148
|
+
return cellTag('td', value, table.alignments[i])
|
|
149
|
+
}).join('') + '</tr>'
|
|
150
|
+
}).join('') + '</tbody>'
|
|
151
|
+
: ''
|
|
152
|
+
return '<div class="md-table-wrap"><table>' + head + body + '</table></div>'
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function listMarker(line) {
|
|
156
|
+
var match = line.match(/^( {0,3})(?:(\d{1,9})([.)])|([-+*]))( +)(.*)$/)
|
|
157
|
+
if (!match) return null
|
|
158
|
+
return {
|
|
159
|
+
indent: match[1].length,
|
|
160
|
+
kind: match[2] === undefined ? match[4] : match[3],
|
|
161
|
+
ordered: match[2] !== undefined,
|
|
162
|
+
start: Number(match[2]),
|
|
163
|
+
offset: match[0].length - match[6].length,
|
|
164
|
+
text: match[6]
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Keep blank-separated items in one list, and render indented blocks inside
|
|
169
|
+
// their parent item. Otherwise every loose item becomes a new list at 1.
|
|
170
|
+
function listHtml(lines, start, fileLinks, imageHosts, depth) {
|
|
171
|
+
var first = listMarker(lines[start])
|
|
172
|
+
var i = start
|
|
173
|
+
var items = []
|
|
174
|
+
var loose = false
|
|
175
|
+
function sibling(marker) {
|
|
176
|
+
return marker && marker.indent === first.indent && marker.kind === first.kind && marker.ordered === first.ordered
|
|
177
|
+
}
|
|
178
|
+
while (i < lines.length) {
|
|
179
|
+
var marker = listMarker(lines[i])
|
|
180
|
+
if (!sibling(marker)) break
|
|
181
|
+
var content = [marker.text]
|
|
182
|
+
i++
|
|
183
|
+
while (i < lines.length) {
|
|
184
|
+
if (!lines[i].trim()) {
|
|
185
|
+
var next = i + 1
|
|
186
|
+
while (next < lines.length && !lines[next].trim()) next++
|
|
187
|
+
if (next >= lines.length) break
|
|
188
|
+
if (sibling(listMarker(lines[next]))) { loose = true; i = next; break }
|
|
189
|
+
if (lines[next].search(/\S/) < marker.offset) break
|
|
190
|
+
loose = true
|
|
191
|
+
content.push('')
|
|
192
|
+
i = next
|
|
193
|
+
}
|
|
194
|
+
var current = lines[i]
|
|
195
|
+
if (current.search(/\S/) >= marker.offset) {
|
|
196
|
+
content.push(current.slice(marker.offset))
|
|
197
|
+
} else {
|
|
198
|
+
// Unindented continuation text is allowed until a new block starts.
|
|
199
|
+
if (listMarker(current) || /^(?:#{1,3}\s|>)/.test(current) || tableAt(lines, i)) break
|
|
200
|
+
content.push(current)
|
|
201
|
+
}
|
|
202
|
+
i++
|
|
203
|
+
}
|
|
204
|
+
items.push(renderLines(content, fileLinks, imageHosts, depth + 1))
|
|
205
|
+
}
|
|
206
|
+
var tag = first.ordered ? 'ol' : 'ul'
|
|
207
|
+
var attr = first.ordered && first.start !== 1 ? ' start="' + first.start + '"' : ''
|
|
208
|
+
return {
|
|
209
|
+
html: '<' + tag + attr + '>' + items.map(function (item) {
|
|
210
|
+
// Tight lists omit paragraph wrappers; nested block wrappers stay intact.
|
|
211
|
+
if (!loose) item = item.replace(/^<p>([\s\S]*?)<\/p>/, '$1')
|
|
212
|
+
return '<li>' + item + '</li>'
|
|
213
|
+
}).join('') + '</' + tag + '>',
|
|
214
|
+
next: i
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function renderLines(lines, fileLinks, imageHosts, depth = 0) {
|
|
219
|
+
var html = ''
|
|
220
|
+
var i = 0
|
|
221
|
+
while (i < lines.length) {
|
|
222
|
+
var line = lines[i]
|
|
223
|
+
var t = line.trim()
|
|
224
|
+
if (!t) { i++; continue }
|
|
225
|
+
var h = line.match(/^(#{1,3})\s+(.*)$/)
|
|
226
|
+
if (h) {
|
|
227
|
+
var level = h[1].length
|
|
228
|
+
html += '<h' + level + '>' + inline(h[2], fileLinks, imageHosts) + '</h' + level + '>'
|
|
229
|
+
i++
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
232
|
+
var table = tableAt(lines, i)
|
|
233
|
+
if (table) {
|
|
234
|
+
html += tableHtml(table, fileLinks, imageHosts)
|
|
235
|
+
i = table.next
|
|
236
|
+
continue
|
|
237
|
+
}
|
|
238
|
+
var q = line.match(/^>\s?(.*)$/)
|
|
239
|
+
if (q) {
|
|
240
|
+
html += '<blockquote>' + inline(q[1], fileLinks, imageHosts) + '</blockquote>'
|
|
241
|
+
i++
|
|
242
|
+
continue
|
|
243
|
+
}
|
|
244
|
+
if (depth < 32 && listMarker(line)) {
|
|
245
|
+
var list = listHtml(lines, i, fileLinks, imageHosts, depth)
|
|
246
|
+
html += list.html
|
|
247
|
+
i = list.next
|
|
248
|
+
continue
|
|
249
|
+
}
|
|
250
|
+
var para = []
|
|
251
|
+
while (i < lines.length) {
|
|
252
|
+
var cur = lines[i]
|
|
253
|
+
var ct = cur.trim()
|
|
254
|
+
if (!ct) break
|
|
255
|
+
if (/^(#{1,3})\s+/.test(cur) || /^>\s?/.test(cur) || (depth < 32 && listMarker(cur))) break
|
|
256
|
+
para.push(inline(cur, fileLinks, imageHosts))
|
|
257
|
+
i++
|
|
258
|
+
}
|
|
259
|
+
if (para.length) html += '<p>' + para.join('<br>') + '</p>'
|
|
260
|
+
else {
|
|
261
|
+
// A block-start check can match a line its full parser rejects. Keep
|
|
262
|
+
// that escaped line as text and always advance instead of spinning.
|
|
263
|
+
html += '<p>' + inline(line, fileLinks, imageHosts) + '</p>'
|
|
264
|
+
i++
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return html
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function codeHtml(code, options, language) {
|
|
271
|
+
var pre = '<pre><code>' + escapeHtml(code) + '</code></pre>'
|
|
272
|
+
return options?.copyCode && chatCopy()?.code ? chatCopy().code(code, language, { label: options.copyCodeLabel, scope: options.copyScope }) : pre
|
|
273
|
+
}
|
|
274
|
+
// Match complete fence lines so Markdown containing its own ``` blocks can
|
|
275
|
+
// use a longer outer fence without splitting the content being copied.
|
|
276
|
+
function fencedParts(raw) {
|
|
277
|
+
var parts = [], cursor = 0, open = /^ {0,3}(`{3,}|~{3,})([^\n]*)(?:\n|$)/gm, match
|
|
278
|
+
while ((match = open.exec(raw))) {
|
|
279
|
+
if (match[1][0] === '`' && match[2].includes('`')) continue
|
|
280
|
+
if (match.index > cursor) parts.push({ text: raw.slice(cursor, match.index) })
|
|
281
|
+
var close = new RegExp('^ {0,3}' + match[1][0] + '{' + match[1].length + ',}[ \\t]*(?:\\n|$)', 'gm')
|
|
282
|
+
close.lastIndex = open.lastIndex
|
|
283
|
+
var end = close.exec(raw)
|
|
284
|
+
var source = raw.slice(open.lastIndex, end ? end.index : raw.length).replace(/\n$/, '')
|
|
285
|
+
var indent = match[0].match(/^ */)[0].length
|
|
286
|
+
if (indent) source = source.replace(new RegExp('^ {0,' + indent + '}', 'gm'), '')
|
|
287
|
+
parts.push({ code: source, info: match[2].trim(), closed: !!end })
|
|
288
|
+
cursor = end ? close.lastIndex : raw.length
|
|
289
|
+
open.lastIndex = cursor
|
|
290
|
+
if (!end) break
|
|
291
|
+
}
|
|
292
|
+
if (cursor < raw.length) parts.push({ text: raw.slice(cursor) })
|
|
293
|
+
return parts
|
|
294
|
+
}
|
|
295
|
+
function mdToHtml(text, options) {
|
|
296
|
+
if (options?.imageLabel) imageLabel = String(options.imageLabel)
|
|
297
|
+
var raw = String(text == null ? '' : text).replace(/\r\n?/g, '\n')
|
|
298
|
+
var parts = fencedParts(raw)
|
|
299
|
+
var out = ''
|
|
300
|
+
for (var i = 0; i < parts.length; i++) {
|
|
301
|
+
var part = parts[i]
|
|
302
|
+
if (part.code !== undefined) {
|
|
303
|
+
var code = part.code
|
|
304
|
+
var language = part.info.toLowerCase()
|
|
305
|
+
// Wait for the closing fence: streaming partial JSON stays readable as source.
|
|
306
|
+
if (options?.richContent !== false && genui && part.closed && code.length <= 200000) {
|
|
307
|
+
try {
|
|
308
|
+
if (/^(?:dsh-ui|json dsh-ui|dsh-ui json)$/.test(language)) {
|
|
309
|
+
out += genui.render(JSON.parse(code)); continue
|
|
310
|
+
}
|
|
311
|
+
if (language === 'html' || language === 'htm') {
|
|
312
|
+
out += genui.html(code) + '<details><summary>HTML / 源码</summary>' + codeHtml(code, options, language) + '</details>'; continue
|
|
313
|
+
}
|
|
314
|
+
} catch (_) { /* Invalid or over-budget specs remain source, never execute. */ }
|
|
315
|
+
}
|
|
316
|
+
// A language header belongs to the fence, not to the copied source.
|
|
317
|
+
out += codeHtml(code, options, part.info.split(/\s+/)[0])
|
|
318
|
+
} else {
|
|
319
|
+
var escaped = escapeHtml(part.text)
|
|
320
|
+
out += renderLines(escaped.split('\n').map(function (line) {
|
|
321
|
+
return line.replace(/^[ \t]+/, function (indent) {
|
|
322
|
+
var spaces = ''
|
|
323
|
+
for (var j = 0; j < indent.length; j++) spaces += indent[j] === '\t' ? ' '.repeat(4 - spaces.length % 4) : ' '
|
|
324
|
+
return spaces
|
|
325
|
+
})
|
|
326
|
+
}), options?.fileLinks === true, options?.imageHosts)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return out
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return mdToHtml
|
|
333
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Local morphicons bridge for the zero-build WebUI.
|
|
3
|
+
*
|
|
4
|
+
* The vendored element keeps a static SVG child as its first-paint fallback.
|
|
5
|
+
* UI code only changes data-morph-state; this bridge turns that state change
|
|
6
|
+
* into a morph without coupling the application code to the vendor API.
|
|
7
|
+
*/
|
|
8
|
+
import { defineMorphIcon } from './vendor/morphicons/element.js'
|
|
9
|
+
|
|
10
|
+
defineMorphIcon()
|
|
11
|
+
|
|
12
|
+
function syncMorphIcon(element) {
|
|
13
|
+
if (!element || !('icon' in element)) return
|
|
14
|
+
const state = element.dataset.morphState === 'open' ? 'open' : 'closed'
|
|
15
|
+
const next = state === 'open' ? element.dataset.morphOpen : element.dataset.morphClosed
|
|
16
|
+
if (!next || element.icon === next) return
|
|
17
|
+
element.icon = next
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function syncMorphIcons(root = document) {
|
|
21
|
+
if (root.matches?.('morph-icon[data-morph-closed][data-morph-open]')) syncMorphIcon(root)
|
|
22
|
+
root.querySelectorAll?.('morph-icon[data-morph-closed][data-morph-open]').forEach(syncMorphIcon)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function bootMorphIcons() {
|
|
26
|
+
syncMorphIcons()
|
|
27
|
+
const observer = new MutationObserver(records => {
|
|
28
|
+
for (const record of records) syncMorphIcon(record.target)
|
|
29
|
+
})
|
|
30
|
+
observer.observe(document.documentElement, {
|
|
31
|
+
subtree: true,
|
|
32
|
+
attributes: true,
|
|
33
|
+
attributeFilter: ['data-morph-state']
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (document.readyState === 'loading') {
|
|
38
|
+
document.addEventListener('DOMContentLoaded', bootMorphIcons, { once: true })
|
|
39
|
+
} else {
|
|
40
|
+
bootMorphIcons()
|
|
41
|
+
}
|