npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@flyfish-group/file-viewer

v1.0.13

Published

基于 Vue 2.7 + TypeScript + Vite 的纯前端多格式文件预览组件

Readme

Flyfish Viewer

把 Word、Excel、PPT、PDF 和图片稳稳带进浏览器里。

@flyfish-group/file-viewer3 是一款基于 Vue 3、TypeScript 和 Vite 构建的纯前端文件预览组件。Vue2.7 项目请使用同能力包 @flyfish-group/file-viewer。两条 npm 包线保持一致的格式覆盖、示例体验和 API 语义,在线 Demo 始终使用 v3 分支产物作为最新体验基准。

它不依赖后端转码服务,适合接入 OA、知识库、附件中心、流程系统和需要离线能力的业务场景。这个项目的目标很直接: 让文档预览不再像临时拼出来的功能,而是像一个可以放心交付、能独立演示、能持续维护的产品模块。

当前发布版本

| 技术栈 | npm 包 | 最新版本 | 推荐分支 | 说明 | | --- | --- | --- | --- | --- | | Vue3 | @flyfish-group/file-viewer3 | 1.0.13 | v3 | 主推版本,在线 Demo 与后续上线均以此为准 | | Vue2.7 | @flyfish-group/file-viewer | 1.0.13 | main | 兼容 Vue2 项目,格式能力与 Vue3 保持一致 |

Flyfish Viewer demo

为什么值得接入

  • 纯前端 Serverless。 文档解析和展示全部在浏览器内完成,部署简单,不依赖 Office 服务端、LibreOffice 守护进程或额外转码链路。
  • 格式覆盖完整。 当前内置 59 个扩展名映射,覆盖 Word、Excel、PowerPoint、PDF、OFD、CAD、Markdown、图片、代码/文本和 MP4,能覆盖绝大多数业务附件场景。
  • 按需异步加载。 PDF、OFD、CAD、Office、Markdown 和代码高亮渲染器都按需加载,重型解析依赖不会进入其他格式的首屏路径。
  • 阅读体验更像产品。 .doc.docx、PDF 都保留灰色工作台、白色纸张、居中阅读和自适应缩放,避免“内容能打开但不好读”的落差。
  • Demo 更适合验收。 示例文件按文档、表格、图纸、代码、图片等类型分组展示,点击样例即可打开并自动收起选择器。
  • Vue2 / Vue3 体验一致。 main 分支面向 Vue2.7,v3 分支面向 Vue3;两边共享完整格式覆盖、示例文件盒子、文档站和 iframe 集成体验。
  • 组件和独立站两用。 既支持在 Vue 项目里直接作为组件使用,也支持独立部署后通过 iframe 嵌入到任意系统,方便多业务线复用。
  • 适合成品交付。 官方文档、在线 Demo、公开成品仓库、混淆压缩产物、npm tarball 和静态部署产物都一起维护,便于下载、验收和二次接入。

支持格式

当前版本内置 59 个扩展名映射,覆盖 11 条预览链路。

| 类别 | 扩展名 | 当前表现 | 适合场景 | | --- | --- | --- | --- | | Word | docx | docx-preview,更适合保留文档结构和版式 | 新生成的 Word 文档、正式文档 | | Word | doc | msdoc-viewer + Word 风格页面容器 | 历史 .doc 老文档 | | Excel | xlsx | styled-exceljs + 虚拟滚动,支持尺寸、合并和常见样式 | 需要保留表格结构和样式的业务 | | Excel 兼容格式 | xlsmxlsbxlscsvodsfodsnumbers | 统一解析,按格式可用信息渐进还原样式 | 老表格、轻量数据查看 | | PowerPoint | pptx | 浏览幻灯片内容 | 汇报材料、课件、方案 | | PDF | pdf | 基于 pdfjs-dist 预览,支持缩放工具栏、页码状态和可显隐导航窗格 | 合同、票据、版式成品 | | OFD | ofd | 基于 DLTech21/ofd.js 仓库源码在线预览国产版式文档,避开 npm dist 授权 wasm 分支 | 电子发票、公文、归档材料 | | CAD | dxf | 基于 @cadview/core 预览图纸,支持缩放、平移、图层控制 | 工程图纸、二维 CAD 附件 | | CAD 兼容入口 | dwg | 提示转换为 DXF 后预览,不内置 GPL DWG 解析器 | 需要兼容上传入口的业务 | | Markdown | mdmarkdown | Markdown 阅读样式 | README、知识文档、说明文档 | | 图片 | gifjpgjpegbmptifftifpngsvgwebp | 原生图片浏览 | 图片附件、设计稿、Logo | | 代码/文本 | txtjsonjsmjscjscssjavapyhtmlhtmjsxtstsxxmllogvueyamlymlinishbashsqlgorsphpccppcchhppcsdiff | 使用 highlight.js 轻量高亮,HTML 按源码展示 | 日志、配置、代码片段 | | 视频 | mp4 | 浏览器原生视频播放 | 演示视频、录屏 |

三条接入路线

1. Vue 3 组件集成

适合已经在 Vue 3 项目里开发,希望最短路径完成接入的团队。当前在线 Demo 和生产上线均以 v3 分支作为最终产物来源。

pnpm add @flyfish-group/file-viewer3
import { createApp } from 'vue'
import App from './App.vue'
import FileViewer from '@flyfish-group/file-viewer3'

createApp(App).use(FileViewer).mount('#app')

Vue3 入口会自动带上样式,不需要再额外 import CSS。

<script setup lang="ts">
import { ref } from 'vue'

const url = ref('https://example.com/demo.pdf')
</script>

<template>
  <div style="height: 100vh">
    <file-viewer :url="url" />
  </div>
</template>

2. Vue 2 组件集成

适合仍在 Vue2.7 技术栈上,希望直接以内嵌组件方式完成接入的团队。Vue2 入口也会自动带上样式,不需要再额外 import CSS。

pnpm add @flyfish-group/file-viewer
import Vue from 'vue'
import App from './App.vue'
import FileViewer from '@flyfish-group/file-viewer'

Vue.use(FileViewer)

new Vue({
  render: h => h(App)
}).$mount('#app')
<template>
  <div style="height: 100vh">
    <file-viewer :url="url" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      url: 'https://example.com/demo.pdf'
    }
  }
}
</script>

3. Iframe 嵌入

适合多系统共用一套预览器、想把预览能力独立部署、或者不希望把解析依赖带进业务包的场景。

<iframe
  id="viewer"
  src="https://viewer.flyfish.dev?url=https%3A%2F%2Fexample.com%2Fdemo.docx"
  style="width: 100%; height: 100%; border: 0"
></iframe>

更完整的二进制推送方案、from 安全校验和宿主页面示例,请查看文档站中的 Iframe 嵌入说明

使用说明

  • 组件支持两条主要输入路径: url?: stringfile?: File
  • fileurl 同时存在时,会优先渲染 file
  • 如果业务侧拿到的是 BlobArrayBuffer,推荐先包装成带扩展名的 File
  • 预览器会填满父容器,请为父容器提供稳定高度
  • 使用 url 预览时,目标资源需要允许浏览器访问;跨域场景下需要正确配置 CORS
  • 如果下载地址本身没有明确扩展名,建议先在业务侧取回文件,再包装成 File
  • OFD、CAD、PDF、Office、Markdown 和代码高亮渲染器都按需异步加载,只有命中格式时才拉取对应代码块
const blob = await response.blob()
const file = new File([blob], 'contract.pdf', { type: blob.type })

本地开发

下面的命令适用于源码开通后的完整项目。公开 GitHub 成品仓库不包含源码目录,普通用户建议直接通过 npm、dist/artifacts/ 里的 tarball 使用。

pnpm install
pnpm dev

常用脚本:

  • pnpm build: 构建示例站点
  • pnpm build-lib: 构建组件库产物
  • pnpm docs:dev: 启动 VitePress 文档站
  • pnpm docs:build: 构建文档站
  • pnpm type-check: 执行 TypeScript 类型检查

打包发布

Vue3 和 Vue2 发包时分别在对应分支执行同一套发布链路:

| 包 | 分支 | npm 名称 | | --- | --- | --- | | Vue3 | v3 | @flyfish-group/file-viewer3 | | Vue2.7 | main | @flyfish-group/file-viewer |

建议在发布前执行下面这组命令:

pnpm type-check
pnpm build
pnpm build-lib
pnpm obfuscate
pnpm docs:build
npm pack

其中:

  • dist/ 是库构建产物;执行 pnpm obfuscate 后会对其中的 .js / .mjs 进行压缩混淆
  • pnpm build 会生成可独立部署的 Demo 静态站点产物
  • docs/.vitepress/dist/ 是文档站静态产物
  • npm pack 会生成可直接发布或分发的 npm 包 tarball

如果只是准备 npm 包,可以直接执行:

pnpm release:pack

发布到 npm:

npm publish --dry-run --access public
npm publish --access public

如果 npm 账号启用了 MFA,请使用交互式终端完成浏览器确认后再等待发布结果。

公开 GitHub 仓库只提交可直接使用的构建产物、示例、文档和 npm tarball,不提交当前源码目录。需要源码、二开包或商业自助开通的用户,可以前往 https://dev.flyfish.group/shop,付费 4.99 后自助开通。

文档导航

开源说明

本项目使用 Apache-2.0 许可证。

二开或商用时,请按许可证要求保留版权、许可证和来源说明,并注明项目来源为 Flyfish Viewer / @flyfish-group/file-viewer3@flyfish-group/file-viewer。如果你基于本项目修复了通用问题或增强了通用能力,也欢迎通过 issue / PR 一起贡献回来,让这套预览能力继续变得更稳。