@djangocfg/widget-media

中文文档
0.1.49发布于 2026/11/11MITTypeScriptES Module近 30 天下载 7604

Media viewers for a conversation or a file preview: zoom/pan image lightbox, mermaid diagrams, markdown and code listings

原始使用文档
文档目录6 节
  1. Install
  2. Exports
  3. Copy
  4. Image lightbox
  5. Image viewer
  6. Verify

@djangocfg/widget-media

Media viewers for a conversation or a file preview: a zoom/pan image lightbox, mermaid diagrams, markdown for a reader, and read-only code listings.

Install

pnpm add @djangocfg/widget-media @djangocfg/ui-core streamdown

Exports

Each viewer is its own subpath, and that is the contract. The root barrel carries the image viewer only; the other three pull a parser or a highlighter, and a host mounting a lightbox must not pay for any of them.

SubpathWhat it isWhat it costs
.ImageLightbox, LazyImageLightbox, ImageViewer, LazyImageViewer, hooks, types, constantsyet-another-react-lightbox (lightbox), react-zoom-pan-pinch (viewer)
./diagramLazyDiagram, DiagramSource, diagramPluginmermaid (~2.5 MB) — always deferred
./markdownMarkdown — for a reader, outside any conversationstreamdown
./codeCode — a read-only listingstreamdown + shiki
./i18nMediaCopy, DEFAULT_MEDIA_COPY, MEDIA_DICTIONARIES, useMediaCopy—
import { ImageViewer } from '@djangocfg/widget-media';
import { LazyDiagram } from '@djangocfg/widget-media/diagram';

<ImageViewer images={[{ name: 'chart.png', src }]} lightbox />
<LazyDiagram chart={source} streaming={isStreaming} />

Copy

The package owns its copy, typed, in the 17 @djangocfg/i18n locales. The language comes from the @djangocfg/i18n provider (English without one). Pass copy to override any subset; keys you omit keep the dictionary's text, so changing one label does not blank the rest.

<ImageViewer images={images} copy={{ zoomIn: 'Приблизить', close: 'Закрыть' }} />

MediaCopy is the schema of record — a misspelled key is a tsc error, not undefined rendered into a toolbar button.

Image lightbox

The modal gallery a click on a picture opens, on yet-another-react-lightbox: focus trap, swipe, preload of the neighbours, keyboard, wheel/pinch zoom, thumbnails and a counter. Double-click zooms in at the pointer and the next one zooms back out; the cursor is a magnifier at rest and a hand only while zoomed. The skin is src/image-viewer/lightbox/lightbox.css: YARL's --yarl__* variables mapped to ui-core tokens, so it follows light/dark and every preset.

import { LazyImageLightbox } from '@djangocfg/widget-media';

<LazyImageLightbox
  images={[{ name: 'a.jpg', src, downloadSrc }]}
  open={index !== null}
  index={index ?? 0}
  onIndexChange={setIndex}
  onClose={() => setIndex(null)}
/>

It takes addresses (LightboxImage), never raw bytes; an in-memory image goes through ImageViewer. LazyImageLightbox renders nothing until open.

Image viewer

The embedded editor: zoom (wheel + presets 25/50/100/200/400%), pan by drag, rotate 90°, flip H/V, fullscreen dialog, keyboard shortcuts (+/-, 0 reset, r rotate), progressive loading with LQIP, checkerboard transparency ground, cached dimension display. Double-click zooms to the pointer from fit and back to fit from anywhere else. The lightbox prop is the older fullscreen presentation, superseded by ImageLightbox and kept so existing hosts compile.

Verify

pnpm --filter @djangocfg/widget-media check-types test

版本与发布记录

@djangocfg/widget-media 共发布 45 个版本,首次发布于 2026/09/09;过去 12 个月发布了 45 个版本。

版本发布日期距今
0.1.49latest2026/11/111 天前
0.1.482026/11/111 天前
0.1.472026/11/102 天前
0.1.462026/11/102 天前
0.1.452026/11/092 天前
0.1.442026/11/092 天前

关于 @djangocfg/widget-media 的常见问题

@djangocfg/widget-media 是什么?

Media viewers for a conversation or a file preview: zoom/pan image lightbox, mermaid diagrams, markdown and code listings

如何安装 @djangocfg/widget-media?

在项目目录运行 npm install @djangocfg/widget-media,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、streamdown(^2.6.0)、lucide-react(^1.68.0)、@djangocfg/i18n(^2.1.648)、@djangocfg/ui-core(^2.1.648)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@djangocfg/widget-media 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@djangocfg/widget-media 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@djangocfg/widget-media 可以商用吗?

@djangocfg/widget-media 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@djangocfg/widget-media 的下载量有多少?

根据 npm 官方下载统计,@djangocfg/widget-media 在 2026/10/13 – 2026/11/11 这 30 天内被下载 7,604 次,日均约 253 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@djangocfg/widget-media 还在维护吗?

最新版本 0.1.49 发布于 2026/11/11(1 天前);至今共发布 45 个版本,其中过去 12 个月发布了 45 个;首次发布于 2026/09/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。