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

@mt-kit/components

v1.0.4

Published

常用 js UI 组件

Readme

@mt-kit/components

npm version GitHub stars GitHub issues License Documentation

常用 JavaScript UI 组件库,提供 CSS 三角形生成、错误提示覆盖层、元素拖拽等功能。

安装

npm i @mt-kit/components

API

cssGenerateTriangle

生成 CSS 三角形的样式字符串。

参数:

| 参数名 | 说明 | 类型 | 是否必传 | 默认值 | |--------|------|------|----------|--------| | color | 三角形颜色 | string | 是 | - | | size | 三角形大小(像素) | number | 是 | - | | direction | 三角形方向 | "top" \| "bottom" \| "left" \| "right" | 否 | "bottom" |

返回值: string - CSS 样式字符串

使用示例:

import { cssGenerateTriangle } from "@mt-kit/components";

// 生成红色向下三角形样式(默认)
const triangleStyle = cssGenerateTriangle("red", 10);

// 生成向上三角形
const triangleTop = cssGenerateTriangle("blue", 15, "top");

// 在 HTML 中使用
const div = document.createElement('div');
div.setAttribute('style', triangleStyle);
document.body.appendChild(div);

imitationViteError

生成一个类似 Vite 报错的错误覆盖层。

参数:

| 参数名 | 说明 | 类型 | 是否必传 | 默认值 | |--------|------|------|----------|--------| | err | 错误对象或错误信息 | Error \| string | 是 | - | | dialog | 是否以对话框形式显示 | boolean | 否 | false |

返回值: HTMLElement - 错误覆盖层 DOM 元素

使用示例:

import { imitationViteError } from '@mt-kit/components';

// 创建错误覆盖层
const overlay = imitationViteError(err);

// 添加到页面
document.body.appendChild(overlay);

// 或添加到指定元素
const container = document.querySelector('.container');
container?.appendChild(overlay);

效果预览:

draggable

使 DOM 元素可拖拽。

参数:

| 参数名 | 说明 | 类型 | 是否必传 | 默认值 | |--------|------|------|----------|--------| | el | 要拖拽的 DOM 元素 | Element | 是 | - | | overflow | 是否允许拖出边界 | boolean | 否 | false | | options | 配置选项 | IOptions | 否 | - | | options.observer | 是否使用 IntersectionObserver 监听元素可见性 | boolean | 否 | false |

返回值: ITransform \| IDraggable - 元素位置信息或包含 offDraggable 方法的对象

注意: 使用前需要设置 html, body { height: 100%; width: 100%; overflow: hidden; }

使用示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>demo-draggable</title>
  <style>
    html, body {
      height: 100%;
      width: 100%;
      overflow: hidden;
      margin: 0;
    }
    div {
      display: inline-block;
      position: relative;
    }
  </style>
</head>
<body>
  <div>
    <div class="demo-draggable-test01">拖动1</div>
    <div class="demo-draggable-test02">拖动2</div>
  </div>
</body>
</html>
<script type="module">
  import { draggable } from '@mt-kit/components';
  
  // 普通拖拽(不允许拖出边界)
  const el = document.querySelector(".demo-draggable-test01");
  draggable(el);
  
  // 允许拖出边界
  const el2 = document.querySelector(".demo-draggable-test02");
  draggable(el2, true);
</script>