@gallerist/renderer-dom

中文文档
0.5.2发布于 2026/11/09MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 2034

Default DOM renderer for Gallerist — the only ring that touches the DOM.

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Loading: placeholder
  4. Keys and host UI inside the viewer
  5. Markup init
  6. License

@gallerist/renderer-dom

Default DOM renderer for Gallerist — the only ring that touches the DOM.

Part of Gallerist — a headless, framework-agnostic media viewer for grouped / nested galleries with image-space overlays and virtualized rendering.

Install

npm i @gallerist/renderer-dom

Usage

import { createViewer } from '@gallerist/core'
import { mount } from '@gallerist/renderer-dom'
import '@gallerist/theme-default/gallerist.css'

const viewer = createViewer({ items: [{ id: 'a', type: 'image', source: 'a.jpg' }] })
mount(viewer) // overlay/lightbox mode; pass { container } for inline
viewer.open()

Full docs: the monorepo README and docs/.

Loading: placeholder

An item's placeholder shows the moment the item does, in the box the image will paint in (its naturalSize gives the box; without one, the placeholder image's own shape, or --gallerist-media-ratio). Pass the thumbnail URL the rail or the page has already loaded: it is in the browser's cache, so it paints in the same frame as the step, with no flash of an empty stage.

{ id: 'a', type: 'image', source: 'a-2400.jpg', thumb: 'a-320.jpg', placeholder: 'a-320.jpg',
  naturalSize: { w: 2400, h: 1350 } }
  • An image URL (or a data URI) is drawn blurred (--gallerist-placeholder-blur, 6px), clipped to the image's box; the image fades in over it (--gallerist-dur-reveal, 150ms) as the blur clears. A load still running after --gallerist-loading-delay (400ms) shows a pill in the box's bottom end corner: "Loading full size…" (strings.loadingFull), a polite role="status" line that stays empty until that delay (read from the token), so a fast load says nothing. A failed load keeps the placeholder, sharp, and the pill says "Couldn't load full size" (strings.loadFailed) with a Retry button (strings.retry) that loads the item afresh (focus on it goes to the viewer; if the load fails again and focus is still there, the new Retry takes it).
  • A colour (#2a3340, red, rgb(…): a value that reads as one and that the browser parses as a colour, CSS.supports('color', …); a bare word that isn't one, thumb, is a URL) fills the box, with no pill. A failure shows the error card.
  • None: a skeleton fills the box after 300ms, with a shimmer (--gallerist-placeholder, --gallerist-shimmer), gone the moment the image is in (it fades in over the stage). A failure shows the error card.

With reduced motion the placeholder isn't blurred, the skeleton and the spinner hold still, and the image still fades in. Zoom acts on the content layer, so a wheel, pinch or double tap before the image is in zooms the placeholder with it (and re-fits once the image's size is known); @gallerist/plugin-zoom's − + wait for the image.

Keys and host UI inside the viewer

The viewer's keys (arrows, Home/End, digits, +/-/0, t, plugin keys) do nothing in a text field inside the viewer (input, textarea, select, contenteditable), and nothing with a key a handler before the viewer's already took with preventDefault(). So a host popover closes on Escape before the viewer does: handle Escape on the popover (or its field) and call preventDefault(); an Escape nobody took still closes the viewer, from a field too. A plugin key that moves focus into a field (a "notes" key opening a note box) should preventDefault() too, or the field gets the character.

A plugin's keymap is asked before the viewer's own keys (0.5), so a plugin can rebind one for a layout: a handler that takes the key calls preventDefault(), and the viewer then does nothing with it; one that doesn't leaves the viewer's own key, if it has one, to run after. plugin-thumbnails' clusterKeys takes ↑/↓ this way on a flat rail. A plugin is not asked for a key typed with Ctrl, ⌘ or Alt (AltGr is fine: ? on some layouts), a key taken already, or one from a text field (Escape there is the viewer's alone); nor for an arrow key from a widget in the viewer that has arrow keys of its own: inside a dialog, a menu or a slider (role="dialog", "menu", "slider"; the overlay's root doesn't count), a host's listbox, tab list, radio group, menu bar, tree or grid (role="listbox", "tablist", "radiogroup", "menubar", "tree", "grid", "treegrid"; not the viewer's own rail or grid, whose arrows are the viewer's), or on a menu button (aria-haspopup, not "false"). A focused caption band that scrolls keeps ↑/↓/Home/End for scrolling before anyone is asked. So a host no longer needs a capture-phase listener to take an arrow key. A keymap handler that throws doesn't stop the viewer's own key (Escape still closes); its error is reported (reportError, else console.error).

Markup init

bind() opens a viewer from <a href="big.jpg" data-gallerist="trip"> links, with no collection to write. Attributes are listed in @gallerist/cdn, which puts it on a global for pages with no build step.

License

MIT © Shafayet Ahmmed

版本与发布记录

@gallerist/renderer-dom 共发布 10 个版本,首次发布于 2026/11/04;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.2latest2026/11/096 天前
0.5.12026/11/087 天前
0.5.02026/11/088 天前
0.4.12026/11/078 天前
0.4.02026/11/069 天前
0.3.32026/11/069 天前

关于 @gallerist/renderer-dom 的常见问题

@gallerist/renderer-dom 是什么?

Default DOM renderer for Gallerist — the only ring that touches the DOM.

如何安装 @gallerist/renderer-dom?

在项目目录运行 npm install @gallerist/renderer-dom,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@gallerist/core(>=0.3.0 <1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gallerist/renderer-dom 支持 TypeScript 吗?

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

@gallerist/renderer-dom 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gallerist/renderer-dom 可以商用吗?

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

@gallerist/renderer-dom 的下载量有多少?

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

@gallerist/renderer-dom 还在维护吗?

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