@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.
Files changed (210) hide show
  1. package/README.en.md +61 -0
  2. package/README.md +60 -2
  3. package/apk/dsh-remote.apk +0 -0
  4. package/approval-summary.mjs +115 -0
  5. package/client.js +197 -0
  6. package/cordis.patch.yml +5 -0
  7. package/doctor-skill.mjs +99 -0
  8. package/doctor-target.mjs +24 -0
  9. package/file-delivery.mjs +84 -0
  10. package/gateway-stats.cjs +501 -0
  11. package/gateway.cjs +8451 -0
  12. package/index.mjs +1784 -0
  13. package/insights.mjs +111 -0
  14. package/market.mjs +86 -0
  15. package/package.json +71 -4
  16. package/peak-reminders.mjs +50 -0
  17. package/plugin-center.mjs +777 -0
  18. package/plugin-transaction.mjs +300 -0
  19. package/public/activity.js +188 -0
  20. package/public/admin.html +820 -0
  21. package/public/admin.js +1167 -0
  22. package/public/announcement-forms.js +89 -0
  23. package/public/announcements.json +464 -0
  24. package/public/app.js +8826 -0
  25. package/public/approval-records.js +301 -0
  26. package/public/approval-summary.js +78 -0
  27. package/public/build.json +5 -0
  28. package/public/cache-upgrade.js +51 -0
  29. package/public/chat-copy.js +59 -0
  30. package/public/chat-files.js +87 -0
  31. package/public/desktop/desktop.css +816 -0
  32. package/public/desktop/desktop.html +871 -0
  33. package/public/desktop/desktop.js +4548 -0
  34. package/public/desktop/i18n.js +85 -0
  35. package/public/diagnostics.js +203 -0
  36. package/public/doctor-entry.js +94 -0
  37. package/public/doctor.css +205 -0
  38. package/public/doctor.js +769 -0
  39. package/public/donate.png +0 -0
  40. package/public/e2ee-transport.js +219 -0
  41. package/public/extensions.css +109 -0
  42. package/public/extensions.js +215 -0
  43. package/public/file-inbox.css +66 -0
  44. package/public/file-inbox.js +289 -0
  45. package/public/genui.css +8 -0
  46. package/public/genui.js +254 -0
  47. package/public/history.js +304 -0
  48. package/public/i18n.js +57 -0
  49. package/public/icon.svg +12 -0
  50. package/public/image-cache.js +141 -0
  51. package/public/image-preview.js +290 -0
  52. package/public/index.html +1548 -0
  53. package/public/insights.css +28 -0
  54. package/public/insights.js +290 -0
  55. package/public/jsqr.min.js +10104 -0
  56. package/public/lan-discovery.js +94 -0
  57. package/public/link-check.js +109 -0
  58. package/public/manifest.webmanifest +16 -0
  59. package/public/md.js +333 -0
  60. package/public/morphicons-init.js +41 -0
  61. package/public/motion.js +557 -0
  62. package/public/network.js +100 -0
  63. package/public/onboarding.css +36 -0
  64. package/public/onboarding.js +253 -0
  65. package/public/operations.js +141 -0
  66. package/public/permission-presets.js +159 -0
  67. package/public/plugin-center.css +120 -0
  68. package/public/plugin-center.js +666 -0
  69. package/public/plugin-icon.svg +5 -0
  70. package/public/plugin.html +68 -0
  71. package/public/plugin.js +211 -0
  72. package/public/qrcode.min.js +2297 -0
  73. package/public/relay-autopair.js +251 -0
  74. package/public/relay-devices.js +80 -0
  75. package/public/relay-settings.css +24 -0
  76. package/public/relay-settings.js +194 -0
  77. package/public/remote-state.js +27 -0
  78. package/public/remote-ui.css +148 -0
  79. package/public/remote-ui.js +243 -0
  80. package/public/session-deck.css +79 -0
  81. package/public/session-deck.js +180 -0
  82. package/public/session-presets.js +47 -0
  83. package/public/setup.css +18 -0
  84. package/public/setup.js +213 -0
  85. package/public/sha256.js +119 -0
  86. package/public/skills.css +81 -0
  87. package/public/skills.js +202 -0
  88. package/public/skins/blue-fish/DESIGN.md +24 -0
  89. package/public/skins/blue-fish/face.png +0 -0
  90. package/public/skins/blue-fish/icon-blush.png +0 -0
  91. package/public/skins/blue-fish/icon-sleep.png +0 -0
  92. package/public/skins/blue-fish/icon-smile.png +0 -0
  93. package/public/skins/blue-fish/icon-star.png +0 -0
  94. package/public/skins/blue-fish/icon-wink.png +0 -0
  95. package/public/skins/blue-fish/icon.png +0 -0
  96. package/public/skins/blue-fish/mascot.png +0 -0
  97. package/public/skins/blue-fish/pattern.png +0 -0
  98. package/public/skins/blue-fish/preview.html +12 -0
  99. package/public/skins/blue-fish/skin.css +122 -0
  100. package/public/skins/blue-fish/sparkles.svg +18 -0
  101. package/public/skins/bocchi/DESIGN.md +99 -0
  102. package/public/skins/bocchi/face.png +0 -0
  103. package/public/skins/bocchi/grain.png +0 -0
  104. package/public/skins/bocchi/icon-blush.png +0 -0
  105. package/public/skins/bocchi/icon-sleep.png +0 -0
  106. package/public/skins/bocchi/icon-smile.png +0 -0
  107. package/public/skins/bocchi/icon-star.png +0 -0
  108. package/public/skins/bocchi/icon-wink.png +0 -0
  109. package/public/skins/bocchi/icon.png +0 -0
  110. package/public/skins/bocchi/pattern-soft.png +0 -0
  111. package/public/skins/bocchi/pattern.png +0 -0
  112. package/public/skins/bocchi/preview.html +55 -0
  113. package/public/skins/bocchi/skin.css +233 -0
  114. package/public/skins/bocchi/stage-bg.png +0 -0
  115. package/public/skins/bocchi/stage-soft.png +0 -0
  116. package/public/skins/bocchi/stand.png +0 -0
  117. package/public/skins/bocchi/sticker-guitar.png +0 -0
  118. package/public/skins/kessoku/DESIGN.md +38 -0
  119. package/public/skins/kessoku/grain.png +0 -0
  120. package/public/skins/kessoku/skin.css +212 -0
  121. package/public/skins/kita/SOURCES.json +51 -0
  122. package/public/skins/kita/face.png +0 -0
  123. package/public/skins/kita/icon-live.png +0 -0
  124. package/public/skins/kita/icon-reddress.png +0 -0
  125. package/public/skins/kita/icon-seifuku.png +0 -0
  126. package/public/skins/kita/pattern.png +0 -0
  127. package/public/skins/kita/preview.html +56 -0
  128. package/public/skins/kita/skin.css +26 -0
  129. package/public/skins/kita/stand.png +0 -0
  130. package/public/skins/kita/sticker-live.png +0 -0
  131. package/public/skins/nijika/SOURCES.json +51 -0
  132. package/public/skins/nijika/face.png +0 -0
  133. package/public/skins/nijika/icon-live.png +0 -0
  134. package/public/skins/nijika/icon-reddress.png +0 -0
  135. package/public/skins/nijika/icon-seifuku.png +0 -0
  136. package/public/skins/nijika/pattern.png +0 -0
  137. package/public/skins/nijika/preview.html +56 -0
  138. package/public/skins/nijika/skin.css +25 -0
  139. package/public/skins/nijika/stand.png +0 -0
  140. package/public/skins/nijika/sticker-live.png +0 -0
  141. package/public/skins/penguin/DESIGN.md +33 -0
  142. package/public/skins/penguin/SOURCES.json +22 -0
  143. package/public/skins/penguin/aic-blueprint.svg +24 -0
  144. package/public/skins/penguin/endfield-triangles.svg +4 -0
  145. package/public/skins/penguin/face.png +0 -0
  146. package/public/skins/penguin/icon-blush.png +0 -0
  147. package/public/skins/penguin/icon-dizzy.png +0 -0
  148. package/public/skins/penguin/icon-laugh.png +0 -0
  149. package/public/skins/penguin/icon-sleep.png +0 -0
  150. package/public/skins/penguin/icon-smile.png +0 -0
  151. package/public/skins/penguin/icon-star.png +0 -0
  152. package/public/skins/penguin/icon-wink.png +0 -0
  153. package/public/skins/penguin/icon.png +0 -0
  154. package/public/skins/penguin/mascot.png +0 -0
  155. package/public/skins/penguin/pattern-night.png +0 -0
  156. package/public/skins/penguin/pattern.png +0 -0
  157. package/public/skins/penguin/preview.html +12 -0
  158. package/public/skins/penguin/skin.css +212 -0
  159. package/public/skins/ryo/SOURCES.json +51 -0
  160. package/public/skins/ryo/face.png +0 -0
  161. package/public/skins/ryo/icon-live.png +0 -0
  162. package/public/skins/ryo/icon-reddress.png +0 -0
  163. package/public/skins/ryo/icon-seifuku.png +0 -0
  164. package/public/skins/ryo/pattern.png +0 -0
  165. package/public/skins/ryo/preview.html +56 -0
  166. package/public/skins/ryo/skin.css +25 -0
  167. package/public/skins/ryo/stand.png +0 -0
  168. package/public/skins/ryo/sticker-live.png +0 -0
  169. package/public/sponsor-entry.js +21 -0
  170. package/public/styles.css +1494 -0
  171. package/public/subagents.css +61 -0
  172. package/public/subagents.js +275 -0
  173. package/public/task-board.js +109 -0
  174. package/public/teams.js +98 -0
  175. package/public/theme-picker.css +58 -0
  176. package/public/theme-vars.css +1044 -0
  177. package/public/theme.js +166 -0
  178. package/public/transcribe-core.js +74 -0
  179. package/public/turn-results.js +121 -0
  180. package/public/update.json +49 -0
  181. package/public/vendor/gsap/NOTICE.md +10 -0
  182. package/public/vendor/gsap/gsap.min.js +11 -0
  183. package/public/vendor/morphicons/LICENSE +21 -0
  184. package/public/vendor/morphicons/README.md +10 -0
  185. package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
  186. package/public/vendor/morphicons/dom.js +206 -0
  187. package/public/vendor/morphicons/element.js +261 -0
  188. package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
  189. package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
  190. package/public/version.json +3 -0
  191. package/public/voice-input.js +739 -0
  192. package/public/workflow.css +365 -0
  193. package/public/workflow.js +409 -0
  194. package/session-file.mjs +39 -0
  195. package/skills/dsh-remote-doctor/SKILL.md +186 -0
  196. package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
  197. package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
  198. package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
  199. package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
  200. package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
  201. package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
  202. package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
  203. package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
  204. package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
  205. package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
  206. package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
  207. package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
  208. package/skills.mjs +53 -0
  209. package/task-board.mjs +57 -0
  210. package/teams.mjs +58 -0
@@ -0,0 +1,290 @@
1
+ /* Shared chat image lightbox. No dependencies, mobile and desktop. */
2
+ 'use strict';
3
+ ;(function(root){
4
+ const english=()=>root.I18N?.lang==='en'
5
+ let lightbox=null,stage=null,image=null,closeButton=null,hint=null,opener=null
6
+ let resolver=null,attachmentResolver=null,capture=null,observer=null,mutation=null,generation=0,saver=null
7
+ let currentRef=null,saveMenu=null,saveMenuRef=null,pressTimer=null,pressOrigin=null,pressPointer=null,suppressClickUntil=0
8
+ const objectUrls=new Map()
9
+ const escape=value=>String(value??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]))
10
+ function attachmentRef(attachment){
11
+ if(!attachment||typeof attachment!=='object')return null
12
+ const attachmentId=String(attachment.attachmentId||'')
13
+ if(!/^(?:sha256:)?[a-f0-9]{64}$/.test(attachmentId))return null
14
+ // DSH modern RPC validates the whole reference, not only the storage id.
15
+ return { attachmentId, mediaType:String(attachment.mediaType||''), bytes:Number(attachment.bytes)||0,
16
+ width:Number(attachment.width)||0, height:Number(attachment.height)||0, ...(attachment.name?{name:String(attachment.name)}:{}) }
17
+ }
18
+ function attachmentHtml(attachment,label,sessionId){
19
+ const ref=attachmentRef(attachment)
20
+ if(!ref)return '<span class="chat-image-status">'+escape(label)+'</span>'
21
+ const alt=escape(attachment.name||label)
22
+ return '<button type="button" class="chat-image is-loading" data-chat-image data-chat-image-attachment="'+ref.attachmentId+'" data-chat-image-ref="'+escape(JSON.stringify(ref))+'" data-chat-image-session="'+escape(sessionId)+'" data-chat-image-alt="'+alt+'" aria-label="'+alt+'"><span class="chat-image-status">'+escape(label)+'</span></button>'
23
+ }
24
+ function labels(){
25
+ if(!lightbox)return
26
+ lightbox.setAttribute('aria-label',english()?'Image preview':'图片预览')
27
+ if(closeButton)closeButton.setAttribute('aria-label',english()?'Close':'关闭')
28
+ if(hint)hint.textContent=isZoomed()?(english()?'Double-tap to fit · tap outside to close':'双击还原 · 点空白处关闭'):(english()?'Double-tap to zoom · tap outside to close':'双击放大 · 点空白处关闭')
29
+ }
30
+ function isZoomed(){return !!lightbox?.classList.contains('is-zoomed')}
31
+ function setZoom(on){
32
+ if(!lightbox)return
33
+ lightbox.classList.toggle('is-zoomed',!!on)
34
+ if(image){
35
+ if(on&&image.naturalWidth){image.style.width=image.naturalWidth*2+'px';image.style.height=image.naturalHeight*2+'px'}
36
+ else{image.style.width='';image.style.height=''}
37
+ }
38
+ if(on&&stage)root.requestAnimationFrame?.(()=>{stage.scrollLeft=(stage.scrollWidth-stage.clientWidth)/2;stage.scrollTop=(stage.scrollHeight-stage.clientHeight)/2})
39
+ labels()
40
+ }
41
+ function toggleZoom(){setZoom(!isZoomed())}
42
+ function isOpen(){return !!lightbox&&!lightbox.classList.contains('hidden')}
43
+ function open(src,alt='',ref=null){
44
+ if(!src||!elements())return
45
+ opener=root.document.activeElement||null
46
+ currentRef=ref||null
47
+ image.src=src
48
+ image.alt=alt||(english()?'Image':'图片')
49
+ lightbox.classList.remove('hidden')
50
+ root.document.body?.classList.add('image-preview-open')
51
+ setZoom(false)
52
+ root.requestAnimationFrame?.(()=>lightbox.focus?.({preventScroll:true}))
53
+ }
54
+ function close(){
55
+ if(!lightbox||lightbox.classList.contains('hidden'))return
56
+ closeSaveMenu()
57
+ setZoom(false)
58
+ lightbox.classList.add('hidden')
59
+ root.document.body?.classList.remove('image-preview-open')
60
+ image.removeAttribute?.('src')
61
+ const target=opener;opener=null
62
+ target?.focus?.({preventScroll:true})
63
+ }
64
+ function descriptorFor(trigger){
65
+ if(!trigger)return null
66
+ const attachmentId=trigger.dataset?.chatImageAttachment
67
+ if(attachmentId){
68
+ let ref=null
69
+ try{ref=JSON.parse(trigger.dataset.chatImageRef||'null')}catch{}
70
+ return {kind:'attachment',attachmentId,sessionId:trigger.dataset.chatImageSession||'',name:(ref&&ref.name)||trigger.dataset.chatImageAlt||'',mediaType:ref?.mediaType||''}
71
+ }
72
+ const path=trigger.dataset?.chatImagePath
73
+ return path?{kind:'path',path,name:trigger.dataset.chatImageAlt||''}:null
74
+ }
75
+ function cancelPress(){
76
+ if(pressTimer){clearTimeout(pressTimer);pressTimer=null}
77
+ pressOrigin=null;pressPointer=null
78
+ }
79
+ function closeSaveMenu(){
80
+ if(!saveMenu||saveMenu.classList.contains('hidden'))return false
81
+ saveMenu.classList.add('hidden');saveMenuRef=null;return true
82
+ }
83
+ function openSaveMenu(ref){
84
+ if(!saveMenu||!ref)return
85
+ saveMenuRef=ref
86
+ saveMenu.classList.remove('hidden')
87
+ }
88
+ async function saveRef(ref){
89
+ if(!ref)return
90
+ try{
91
+ if(saver)return await saver(ref)
92
+ // Browser shells without a host-specific saver can still keep the rendered image.
93
+ const src=image?.src
94
+ if(!src)return
95
+ const link=root.document.createElement('a')
96
+ link.href=src;link.download=(ref.name||'image').replace(/[\\/\x00-\x1f]/g,'_').slice(0,200)||'image'
97
+ root.document.body.append(link);link.click();link.remove()
98
+ }catch{}
99
+ }
100
+ // Markdown images may point at a local file. The host shell supplies an authenticated
101
+ // request for that path; load lazily and swap the placeholder for a real previewable image.
102
+ function configure(options={}){
103
+ if(typeof options.resolvePath==='function')resolver=options.resolvePath
104
+ if(typeof options.resolveAttachment==='function')attachmentResolver=options.resolveAttachment
105
+ if(typeof options.capture==='function')capture=options.capture
106
+ if(typeof options.save==='function')saver=options.save
107
+ if(!mutation&&typeof root.MutationObserver==='function'&&root.document?.body){
108
+ // History renders (paging, streaming, cache restore) replace nodes without a full render call.
109
+ mutation=new root.MutationObserver(records=>{
110
+ for(const record of records){
111
+ for(const node of record.addedNodes)if(node?.nodeType===1)hydrate(node)
112
+ if(record.removedNodes?.length)Promise.resolve().then(()=>{
113
+ for(const [button,url] of objectUrls)if(button.isConnected===false){root.URL?.revokeObjectURL?.(url);objectUrls.delete(button)}
114
+ })
115
+ }
116
+ })
117
+ mutation.observe(root.document.body,{childList:true,subtree:true})
118
+ }
119
+ hydrate(root.document)
120
+ }
121
+ function watcher(){
122
+ if(observer)return observer
123
+ if(typeof root.IntersectionObserver!=='function')return null
124
+ observer=new root.IntersectionObserver(entries=>{
125
+ for(const entry of entries){
126
+ if(!entry.isIntersecting)continue
127
+ observer.unobserve(entry.target)
128
+ void loadPathImage(entry.target)
129
+ }
130
+ },{rootMargin:'320px'})
131
+ return observer
132
+ }
133
+ function hydrate(scope){
134
+ if((!resolver&&!attachmentResolver)||!scope?.querySelectorAll)return
135
+ const candidates=[...(scope.matches?.('[data-chat-image][data-chat-image-path]')||scope.matches?.('[data-chat-image][data-chat-image-attachment]')?[scope]:[]),...scope.querySelectorAll('[data-chat-image][data-chat-image-path]'),...scope.querySelectorAll('[data-chat-image][data-chat-image-attachment]')]
136
+ for(const button of candidates){
137
+ if(button.dataset.chatImageAttachment?!attachmentResolver:!resolver)continue
138
+ if(button.dataset.chatImageLoading||button.dataset.chatImageLoaded)continue
139
+ button.dataset.chatImageLoading='1'
140
+ const watch=watcher()
141
+ if(watch)watch.observe(button)
142
+ else void loadPathImage(button)
143
+ }
144
+ }
145
+ async function loadPathImage(button){
146
+ const path=button.dataset.chatImagePath
147
+ const attachmentId=button.dataset.chatImageAttachment
148
+ let attachment=null
149
+ if(attachmentId){
150
+ try{const parsed=JSON.parse(button.dataset.chatImageRef||'null');if(parsed&&parsed.attachmentId===attachmentId)attachment=parsed}catch{}
151
+ if(!attachment)attachment={attachmentId}
152
+ }
153
+ if(attachmentId?!attachmentResolver:(!path||!resolver))return
154
+ const identity=capture?.(),version=generation
155
+ const valid=()=>version===generation&&button.isConnected!==false&&(!identity||identity.valid())
156
+ try{
157
+ let url
158
+ if(root.DshImageCache&&identity?.scope){
159
+ // Scope includes the connection credential hash; attachments are also session-scoped.
160
+ const request=attachmentId?null:await resolver(path)
161
+ if(!valid())return
162
+ const target=typeof request==='string'?{url:request}:request||{}
163
+ const id=attachmentId?JSON.stringify(['attachment',button.dataset.chatImageSession,attachmentId]):JSON.stringify(['path',target.url])
164
+ const value=await root.DshImageCache.load(identity.scope,id,async cached=>{
165
+ if(!valid())throw Error('stale image')
166
+ if(attachmentId){
167
+ const result=await attachmentResolver(attachment,button.dataset.chatImageSession)
168
+ if(result?.attachment?.attachmentId!==attachment.attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw Object.assign(Error('invalid image attachment'),{status:422})
169
+ const binary=root.atob(result.data),bytes=new Uint8Array(binary.length)
170
+ for(let i=0;i<binary.length;i++)bytes[i]=binary.charCodeAt(i)
171
+ return {blob:new root.Blob([bytes],{type:result.attachment.mediaType})}
172
+ }
173
+ const headers={...target.headers}
174
+ if(cached?.etag)headers['If-None-Match']=cached.etag
175
+ else if(cached?.lastModified)headers['If-Modified-Since']=cached.lastModified
176
+ const read=async signal=>{
177
+ const response=await (root.fetch||fetch)(target.url,{headers,signal,cache:'no-cache'})
178
+ if(response.status===304&&cached)return cached
179
+ if(!response.ok)throw Object.assign(Error('HTTP '+response.status),{status:response.status})
180
+ return {blob:await response.blob(),etag:response.headers?.get('etag'),lastModified:response.headers?.get('last-modified')}
181
+ }
182
+ return root.DshNetwork?.readWithDeadline?root.DshNetwork.readWithDeadline(read,45000):read(root.AbortSignal?.timeout?.(45000))
183
+ },{revalidate:!attachmentId,valid})
184
+ if(!valid())return
185
+ url=root.URL.createObjectURL(value.blob)
186
+ objectUrls.set(button,url)
187
+ }else if(attachmentId){
188
+ const result=await attachmentResolver(attachment,button.dataset.chatImageSession)
189
+ if(result?.attachment?.attachmentId!==attachment.attachmentId||!/^image\/(?:png|jpeg|webp|gif)$/.test(result.attachment.mediaType)||typeof result.data!=='string'||!result.data||result.data.length>16*1024*1024||!/^[A-Za-z0-9+/]*={0,2}$/.test(result.data))throw new Error('invalid image attachment')
190
+ url='data:'+result.attachment.mediaType+';base64,'+result.data
191
+ }else{
192
+ const source=await resolver(path)
193
+ const request=typeof source==='string'?{url:source}:source||{}
194
+ const response=await (root.fetch||fetch)(request.url,{headers:request.headers||{}})
195
+ if(!response.ok)throw new Error('HTTP '+response.status)
196
+ const blob=await response.blob()
197
+ if(!blob||!blob.size)throw new Error('empty image')
198
+ url=root.URL?.createObjectURL?root.URL.createObjectURL(blob):''
199
+ if(!url)throw new Error('no blob url')
200
+ objectUrls.set(button,url)
201
+ }
202
+ if(!valid()){release(button);return}
203
+ const node=root.document.createElement('img')
204
+ node.src=url;node.alt=button.dataset.chatImageAlt||'';node.draggable=false;node.loading='lazy'
205
+ node.addEventListener('error',()=>pathImageFailed(button))
206
+ node.addEventListener('load',()=>{button.classList.remove('is-loading');button.classList.add('is-loaded')})
207
+ button.replaceChildren(node)
208
+ button.dataset.chatImageLoaded='1'
209
+ }catch(error){if(valid())pathImageFailed(button)}
210
+ }
211
+ function release(button){const url=objectUrls.get(button);if(url)root.URL?.revokeObjectURL?.(url);objectUrls.delete(button)}
212
+ function reset(){generation++;close();closeSaveMenu();for(const button of objectUrls.keys())release(button)}
213
+ function pathImageFailed(button){
214
+ release(button)
215
+ button.classList.remove('is-loading')
216
+ button.classList.add('is-error')
217
+ const status=button.querySelector?.('.chat-image-status')
218
+ if(status)status.textContent=english()?'Image unavailable':'图片无法加载'
219
+ }
220
+ function elements(){
221
+ if(lightbox)return lightbox
222
+ lightbox=root.document?.getElementById('image-lightbox')
223
+ if(!lightbox)return null
224
+ stage=lightbox.querySelector('[data-image-lightbox-stage]')
225
+ image=lightbox.querySelector('[data-image-lightbox-img]')
226
+ closeButton=lightbox.querySelector('[data-image-lightbox-close]')
227
+ hint=lightbox.querySelector('[data-image-lightbox-hint]')
228
+ closeButton?.addEventListener('click',close)
229
+ lightbox.addEventListener('click',event=>{const target=event.target;if(target===lightbox||target===stage)close()})
230
+ stage?.addEventListener('click',event=>{if(event.target===stage)close()})
231
+ image?.addEventListener('dblclick',event=>{event.preventDefault?.();toggleZoom()})
232
+ root.document.addEventListener('keydown',event=>{if(event.key==='Escape'&&isOpen()){event.preventDefault?.();if(closeSaveMenu())return;close()}})
233
+ // A long press opens a two-action sheet; the preview click below is suppressed after it.
234
+ saveMenu=root.document.getElementById('image-save-menu')
235
+ if(!saveMenu){
236
+ saveMenu=root.document.createElement('div')
237
+ saveMenu.id='image-save-menu'
238
+ saveMenu.className='image-save-menu hidden'
239
+ saveMenu.setAttribute('role','menu')
240
+ saveMenu.innerHTML='<button type="button" role="menuitem" data-image-save-action="save"></button><button type="button" role="menuitem" data-image-save-action="cancel"></button>'
241
+ const mount = root.document.body
242
+ if (mount && typeof mount.appendChild === 'function') mount.appendChild(saveMenu)
243
+ else if (mount && typeof mount.append === 'function') mount.append(saveMenu)
244
+ saveMenu.addEventListener('click',event=>{
245
+ const action=event.target?.closest?.('[data-image-save-action]')?.dataset.imageSaveAction
246
+ if(!action)return
247
+ event.preventDefault?.();event.stopPropagation?.()
248
+ const ref=saveMenuRef
249
+ closeSaveMenu()
250
+ if(action==='save')void saveRef(ref)
251
+ })
252
+ }
253
+ const saveLabel=saveMenu.querySelector('[data-image-save-action="save"]'),cancelLabel=saveMenu.querySelector('[data-image-save-action="cancel"]')
254
+ if(saveLabel)saveLabel.textContent=english()?'Save image':'保存图片'
255
+ if(cancelLabel)cancelLabel.textContent=english()?'Cancel':'取消'
256
+ root.document.addEventListener('pointerdown',event=>{
257
+ if(event.button!==undefined&&event.button!==0)return
258
+ if(saveMenu&&!saveMenu.classList.contains('hidden'))return
259
+ const trigger=event.target?.closest?.('[data-chat-image]')
260
+ const inPreview=event.target===image
261
+ if(!trigger&&!inPreview)return
262
+ if(pressTimer){cancelPress();return}
263
+ const ref=inPreview?currentRef:descriptorFor(trigger)
264
+ if(!ref)return
265
+ pressPointer=event.pointerId
266
+ pressOrigin={x:event.clientX,y:event.clientY}
267
+ pressTimer=setTimeout(()=>{pressTimer=null;suppressClickUntil=Date.now()+900;openSaveMenu(ref)},520)
268
+ },true)
269
+ root.document.addEventListener('pointermove',event=>{
270
+ if(!pressTimer||!pressOrigin)return
271
+ if(Math.hypot(event.clientX-pressOrigin.x,event.clientY-pressOrigin.y)>10)cancelPress()
272
+ },true)
273
+ root.document.addEventListener('pointerup',cancelPress,true)
274
+ root.document.addEventListener('pointercancel',cancelPress,true)
275
+ root.document.addEventListener('contextmenu',event=>{
276
+ if(event.target?.closest?.('[data-chat-image]')||event.target===image)event.preventDefault?.()
277
+ })
278
+ // Chat images live inside rendered history: delegate instead of rebinding per message.
279
+ root.document.addEventListener('click',event=>{
280
+ if(Date.now()<suppressClickUntil)return
281
+ const trigger=event.target?.closest?.('[data-chat-image]')
282
+ if(!trigger)return
283
+ const img=trigger.querySelector?.('img')
284
+ if(img?.src)open(img.src,img.alt||'',descriptorFor(trigger))
285
+ })
286
+ return lightbox
287
+ }
288
+ root.DshImagePreview={open,close,isOpen,zoom:toggleZoom,mount:elements,configure,hydrate,attachmentHtml,reset,closeSaveMenu}
289
+ root.document?.addEventListener('DOMContentLoaded',()=>{elements();hydrate(root.document)})
290
+ })(typeof window==='undefined'?globalThis:window)