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

@gantfdt/2d-viewer-vue

v0.1.1

Published

gant-2d 的 Vue 薄壳:DrawingViewer 组件与 composables,业务逻辑全部在 @gantfdt/2d-viewer-core

Readme

@gantfdt/2d-viewer-vue

@gantfdt/2d-viewer-core 的 Vue 3 薄壳:提供 DrawingViewer 组件与三个 composables。组件只负责挂载 / 销毁 Viewer 并把 props 映射到 core API,业务逻辑全部在 core。

当前版本 0.1.0。许可证为 UNLICENSED(源码可见,使用需单独授权),见包内 LICENSE。

安装

pnpm add @gantfdt/2d-viewer-vue vue

vue 是 peer 依赖(vue >= 3.3),由宿主提供;@gantfdt/2d-viewer-core 会作为依赖自动安装。

引入样式

import '@gantfdt/2d-viewer-vue/style.css';

该文件只转发 @gantfdt/2d-viewer-core/style.css(内置 UI 样式与字体),不需要再单独引入 core 的样式。样式不会自动注入。

最小示例

<script setup lang="ts">
import { ref } from 'vue';
import { DrawingViewer } from '@gantfdt/2d-viewer-vue';
import '@gantfdt/2d-viewer-vue/style.css';

const theme = ref<'light' | 'dark'>('light');
const locale = ref<'zh' | 'en'>('zh');

function onLoad(result: { stats: { entityCount: number } }): void {
  console.log('实体数', result.stats.entityCount);
}
</script>

<template>
  <DrawingViewer
    height="calc(100vh - 64px)"
    :theme="theme"
    :locale="locale"
    :source="{ type: 'url', url: '/samples/plan.dxf' }"
    @load="onLoad"
    @error="(error) => console.error(error.code, error.messageKey)"
  />
</template>

source 的引用变化会自动重新加载;上传、URL 输入等取图控件由宿主自己提供(组件不内置上传)。

组件属性

| 属性 | 说明 | | --- | --- | | source | 图纸来源(url / file / base64 / gdf),引用变化时自动重新加载 | | options | ViewerOptions(去掉 ui / slots);仅挂载时读取一次,运行时变更请用暴露的 viewer 方法 | | height | 根元素高度:数字按 px,字符串原样;受控,变化时调用 setHeight | | theme | light / dark;受控,变化时调用 setTheme,自身变化通过 theme-change 通知 | | locale | zh / en;受控,变化时调用 setLocale | | messages | 外部语言包,局部覆盖内置文案 | | ui | UIConfig;仅挂载时读取一次 | | infoTabs | 追加到信息面板的自定义页签(UISlotEntry[],对应 core 的 info-tab 插槽) | | class / style | 根元素 class 与内联样式 |

事件

kebab-case,载荷与 core 事件一致:

ready、load-progress、load、degraded、error、view-change、layer-change、layout-change、selection-change、search、theme-change、locale-change、renderer-change。

获取 Viewer 实例

<script setup lang="ts">
import { ref } from 'vue';
import { DrawingViewer } from '@gantfdt/2d-viewer-vue';

const viewerRef = ref<InstanceType<typeof DrawingViewer> | null>(null);

function fit(): void {
  viewerRef.value?.viewer?.fit();
}
</script>

<template>
  <button type="button" @click="fit">适配</button>
  <DrawingViewer ref="viewerRef" :source="source" />
</template>

viewerRef.value.viewer 就是 core 的 Viewer 实例。

模板插槽

三个模板插槽:toolbar-start、toolbar-end、layer-panel-footer。info-tab 用 info-tabs 属性追加(每条含 title 与 render)。

<DrawingViewer :source="source">
  <template #toolbar-end>
    <button type="button" @click="viewerRef?.viewer?.fit()">适配</button>
  </template>
</DrawingViewer>

composables

| Composable | 说明 | | --- | --- | | useDrawingViewer(container, options) | container 出现时创建 Viewer、消失 / 卸载时销毁;返回 { viewer, state } | | useLayers(viewer) | 图层快照,随 layerchange / load 更新 | | useSelection(viewer) | 选择快照,随 selectionchange 更新 |

<script setup lang="ts">
import { ref } from 'vue';
import { useDrawingViewer } from '@gantfdt/2d-viewer-vue';

const host = ref<HTMLElement | null>(null);
const { state } = useDrawingViewer(host, { height: 480 });
</script>

<template>
  <div ref="host" />
  <span>{{ state.activeLayout }}</span>
</template>

useLayers / useSelection 接收 MaybeRef<Viewer | null>,可直接传组件暴露的 viewer 或单独创建的实例。

注意事项

  • options / ui 只在挂载时读取一次;运行时改配置请用暴露的 viewer 方法。
  • theme / locale / messages 是单向受控属性:组件不会回写宿主状态,需要同步时监听 theme-change / locale-change 事件。