dsh-featured 0.1.2 → 0.1.3
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/lib/client.js +97 -16
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -199,6 +199,10 @@ window.__ModuleLoader__.load({
|
|
|
199
199
|
},
|
|
200
200
|
// ── 自建详情弹窗(README 从 npm 包 jsdelivr 读取) ──
|
|
201
201
|
overlay: { position: 'fixed', inset: 0, zIndex: 1000, background: 'rgba(0,0,0,0.4)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24 },
|
|
202
|
+
viewer: { position: 'fixed', inset: 0, zIndex: 1100, background: 'rgba(0,0,0,0.72)', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
203
|
+
viewerImg: { maxWidth: '82vw', maxHeight: '82vh', borderRadius: 10, boxShadow: '0 12px 48px rgba(0,0,0,0.5)', background: 'var(--dsw-alias-bg-layer-1)' },
|
|
204
|
+
viewerBtn: { position: 'absolute', width: 34, height: 34, borderRadius: '50%', border: 'none', background: 'rgba(0,0,0,0.55)', color: '#fff', fontSize: 16, lineHeight: 1, cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
|
205
|
+
viewerCount: { position: 'absolute', bottom: 18, left: '50%', transform: 'translateX(-50%)', color: 'rgba(255,255,255,0.85)', fontSize: 12 },
|
|
202
206
|
panel: {
|
|
203
207
|
width: 'min(860px, 92vw)', maxHeight: '84vh', display: 'flex', flexDirection: 'column',
|
|
204
208
|
background: 'var(--dsw-alias-bg-layer-2)', border: '1px solid var(--dsw-alias-border-l1)',
|
|
@@ -269,18 +273,93 @@ window.__ModuleLoader__.load({
|
|
|
269
273
|
meta ? h('span', { style: S.meta }, meta) : null)
|
|
270
274
|
}
|
|
271
275
|
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
// 截图来源:不依赖目录 screenshots 字段(可能指向别的仓库),直接读
|
|
277
|
+
// 插件自己 npm 包里的 README,提取其中的图片作为截图。
|
|
278
|
+
function readmeBase(entry) {
|
|
279
|
+
return `https://cdn.jsdelivr.net/npm/${entry.package}${entry.version ? '@' + entry.version : ''}/`
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function extractReadmeImages(txt, base) {
|
|
283
|
+
const out = []
|
|
284
|
+
const push = (u) => {
|
|
285
|
+
const a = mdAbsUrl(u, base)
|
|
286
|
+
if (out.indexOf(a) < 0) out.push(a)
|
|
287
|
+
}
|
|
288
|
+
const s = String(txt)
|
|
289
|
+
s.replace(/!\[[^\]]*\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g, (m0, u) => { push(u); return m0 })
|
|
290
|
+
s.replace(/<img[^>]*\ssrc=["']([^"']+)["']/gi, (m0, u) => { push(u); return m0 })
|
|
291
|
+
// 过滤徽章类小图:svg / shields / badge / CI 字样
|
|
292
|
+
return out.filter((u) => !/\.svg(?:[?#]|$)|shields\.io|badge|travis|circleci|codecov/i.test(u)).slice(0, 8)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 尺寸过滤阈值:加载后 宽<240 或 高<160 视为太小(徽章/图标),不进截图区。
|
|
296
|
+
const SHOT_MIN_W = 240
|
|
297
|
+
const SHOT_MIN_H = 160
|
|
298
|
+
|
|
299
|
+
function ReadmeShots(props) {
|
|
300
|
+
const entry = props.entry
|
|
301
|
+
const onOpen = props.onOpen
|
|
302
|
+
const pair = React.useState({ status: 'loading', urls: [] })
|
|
303
|
+
const state = pair[0], setState = pair[1]
|
|
304
|
+
const dropPair = React.useState({})
|
|
305
|
+
const drop = dropPair[0], setDrop = dropPair[1]
|
|
306
|
+
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
let alive = true
|
|
309
|
+
const base = readmeBase(entry)
|
|
310
|
+
fetchText(base + 'README.md', 10000).then((txt) => {
|
|
311
|
+
if (alive) setState({ status: 'ready', urls: extractReadmeImages(txt, base) })
|
|
312
|
+
}).catch(() => {
|
|
313
|
+
const gh = entry.homepage && /^https?:\/\/github\.com\/([^/]+)\/([^/]+)/i.exec(entry.homepage)
|
|
314
|
+
if (!gh) { if (alive) setState({ status: 'error', urls: [] }); return }
|
|
315
|
+
const ghBase = `https://cdn.jsdelivr.net/gh/${gh[1]}/${gh[2]}@main/`
|
|
316
|
+
fetchText(ghBase + 'README.md', 10000).then((txt) => {
|
|
317
|
+
if (alive) setState({ status: 'ready', urls: extractReadmeImages(txt, ghBase) })
|
|
318
|
+
}).catch(() => { if (alive) setState({ status: 'error', urls: [] }) })
|
|
319
|
+
})
|
|
320
|
+
return () => { alive = false }
|
|
321
|
+
}, [entry.package])
|
|
322
|
+
|
|
323
|
+
const visible = state.urls.filter((u) => !drop[u]).slice(0, 2)
|
|
324
|
+
if (!visible.length) return null
|
|
325
|
+
return h('div', { style: S.shots }, visible.map((url, i) =>
|
|
326
|
+
h('img', {
|
|
327
|
+
key: url, src: url, alt: '', style: S.shot, loading: 'lazy',
|
|
328
|
+
onLoad: (ev) => {
|
|
329
|
+
const im = ev.target || {}
|
|
330
|
+
if (im.naturalWidth && (im.naturalWidth < SHOT_MIN_W || im.naturalHeight < SHOT_MIN_H)) {
|
|
331
|
+
setDrop(Object.assign({}, drop, { [url]: true }))
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
onError: () => setDrop(Object.assign({}, drop, { [url]: true })),
|
|
335
|
+
onClick: () => onOpen && onOpen(visible, i),
|
|
336
|
+
})))
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 截图灯箱:点击缩略图弹出大图,左右按钮切换,Esc/←/→ 键盘可用。
|
|
340
|
+
function ShotViewer(props) {
|
|
341
|
+
const list = props.list
|
|
342
|
+
const onClose = props.onClose
|
|
343
|
+
const pair = React.useState(props.index || 0)
|
|
276
344
|
const idx = pair[0], setIdx = pair[1]
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
345
|
+
React.useEffect(() => {
|
|
346
|
+
const onKey = (ev) => {
|
|
347
|
+
if (ev.key === 'Escape') onClose()
|
|
348
|
+
else if (ev.key === 'ArrowLeft') setIdx((i) => (i + list.length - 1) % list.length)
|
|
349
|
+
else if (ev.key === 'ArrowRight') setIdx((i) => (i + 1) % list.length)
|
|
350
|
+
}
|
|
351
|
+
window.addEventListener('keydown', onKey)
|
|
352
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
353
|
+
}, [onClose, list.length])
|
|
354
|
+
if (!list.length) return null
|
|
355
|
+
const i = Math.min(idx, list.length - 1)
|
|
356
|
+
const go = (d) => setIdx((i + d + list.length) % list.length)
|
|
357
|
+
return h('div', { style: S.viewer, onClick: (ev) => { if (ev.target === ev.currentTarget) onClose() } },
|
|
358
|
+
h('img', { src: list[i], alt: '', style: S.viewerImg }),
|
|
359
|
+
h('button', { type: 'button', style: Object.assign({}, S.viewerBtn, { top: 16, right: 16 }), onClick: onClose }, '✕'),
|
|
360
|
+
list.length > 1 ? h('button', { type: 'button', style: Object.assign({}, S.viewerBtn, { top: '50%', left: 16, marginTop: -16 }), onClick: () => go(-1) }, '‹') : null,
|
|
361
|
+
list.length > 1 ? h('button', { type: 'button', style: Object.assign({}, S.viewerBtn, { top: '50%', right: 16, marginTop: -16 }), onClick: () => go(1) }, '›') : null,
|
|
362
|
+
list.length > 1 ? h('div', { style: S.viewerCount }, (i + 1) + ' / ' + list.length) : null)
|
|
284
363
|
}
|
|
285
364
|
|
|
286
365
|
// 卡片布局对齐官方 Discover:
|
|
@@ -301,6 +380,7 @@ window.__ModuleLoader__.load({
|
|
|
301
380
|
const t = props.t
|
|
302
381
|
const install = props.install
|
|
303
382
|
const onDetail = props.onDetail // 打开自建详情弹窗
|
|
383
|
+
const onShots = props.onShots // 打开截图灯箱(list, idx)
|
|
304
384
|
const installed = !!props.installed // 宿主侧 pluginManager.listBundles 判定
|
|
305
385
|
const pair = React.useState(false) // busy
|
|
306
386
|
const busy = pair[0], setBusy = pair[1]
|
|
@@ -340,9 +420,7 @@ window.__ModuleLoader__.load({
|
|
|
340
420
|
}, btnLabel)),
|
|
341
421
|
h(FeaturedAuthor, { pkg: e.package, meta: metaText, onDetail }),
|
|
342
422
|
e.description ? h('p', { style: S.desc, onClick: onDetail }, e.description) : null,
|
|
343
|
-
e
|
|
344
|
-
? h('div', { style: S.shots }, e.screenshots.map((url) => h(FeaturedShot, { key: url, url })))
|
|
345
|
-
: null,
|
|
423
|
+
h(ReadmeShots, { entry: e, onOpen: onShots }),
|
|
346
424
|
h('div', { style: S.foot },
|
|
347
425
|
h('div', { style: S.chips },
|
|
348
426
|
chips.map((c) => h('span', { key: c, style: S.chip, title: c }, c)),
|
|
@@ -598,6 +676,8 @@ window.__ModuleLoader__.load({
|
|
|
598
676
|
const query = queryPair[0], setQuery = queryPair[1]
|
|
599
677
|
const tagPair = React.useState('')
|
|
600
678
|
const activeTag = tagPair[0], setActiveTag = tagPair[1]
|
|
679
|
+
const viewerPair = React.useState(null)
|
|
680
|
+
const viewer = viewerPair[0], setViewer = viewerPair[1]
|
|
601
681
|
|
|
602
682
|
React.useEffect(() => {
|
|
603
683
|
let alive = true
|
|
@@ -673,7 +753,7 @@ window.__ModuleLoader__.load({
|
|
|
673
753
|
}
|
|
674
754
|
if (visible.length) {
|
|
675
755
|
kids.push(h('ul', { key: 'grid', style: S.grid }, visible.map((e) => (
|
|
676
|
-
h(FeaturedCard, { key: e.package, entry: e, t, install, onDetail: () => setDetail(e), installed: !!state.installed[e.package] })
|
|
756
|
+
h(FeaturedCard, { key: e.package, entry: e, t, install, onDetail: () => setDetail(e), onShots: (list, idx) => setViewer({ list, idx }), installed: !!state.installed[e.package] })
|
|
677
757
|
))))
|
|
678
758
|
} else {
|
|
679
759
|
kids.push(h('p', { key: 'nomatch', style: S.note }, t('noMatch')))
|
|
@@ -682,7 +762,8 @@ window.__ModuleLoader__.load({
|
|
|
682
762
|
|
|
683
763
|
return h('div', { style: S.wrap }, kids,
|
|
684
764
|
detail ? h(FeaturedModal, { key: 'detail-' + detail.package, entry: detail, t, onClose: () => setDetail(null) }) : null,
|
|
685
|
-
applyOpen ? h(ApplyModal, { key: 'apply', t, onClose: () => setApplyOpen(false) }) : null
|
|
765
|
+
applyOpen ? h(ApplyModal, { key: 'apply', t, onClose: () => setApplyOpen(false) }) : null,
|
|
766
|
+
viewer ? h(ShotViewer, { key: 'viewer', list: viewer.list, index: viewer.idx, onClose: () => setViewer(null) }) : null)
|
|
686
767
|
}
|
|
687
768
|
|
|
688
769
|
// 独立插件是唯一「官方完整版」:
|
package/package.json
CHANGED