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

@lytjs/web

v6.9.6

Published

LytJS web platform utilities - CSS variables and web-specific features

Downloads

1,332

Readme

@lytjs/web

Web 平台工具包,提供 CSS 变量管理、ResizeObserver、Web Components 等 Web 特定功能

安装

npm install @lytjs/web

核心功能

CSS 变量管理

import { setCssVar, getCssVar, removeCssVar, setCssVars, watchCssVar } from '@lytjs/web';

// 设置 CSS 变量
setCssVar('--primary-color', '#1890ff');
setCssVar('--font-size', '14px', document.documentElement);

// 获取 CSS 变量
const color = getCssVar('--primary-color');

// 移除 CSS 变量
removeCssVar('--primary-color');

// 批量设置
setCssVars({
  '--primary-color': '#1890ff',
  '--secondary-color': '#52c41a',
  '--font-size': '14px',
});

// 监听 CSS 变量变化
const unwatch = watchCssVar('--primary-color', (newVal, oldVal) => {
  console.log('CSS 变量变化:', oldVal, '->', newVal);
});

ResizeObserver

import { useResizeObserver, createResizeObserver, type ResizeObserverEntry } from '@lytjs/web';

// 使用 ResizeObserver
const cleanup = useResizeObserver(
  document.getElementById('container'),
  (entries: ResizeObserverEntry[]) => {
    for (const entry of entries) {
      console.log('尺寸变化:', entry.contentRect);
    }
  },
);

// 停止监听
cleanup();

// 创建可复用的 ResizeObserver
const observer = createResizeObserver((entries) => {
  // 处理尺寸变化
});

observer.observe(element1);
observer.observe(element2);
observer.disconnect();

Web Components

import {
  defineLytElement,
  useShadowRoot,
  useHost,
  useWebComponentSlots,
  injectChildStyles,
} from '@lytjs/web';

// 定义 Web Component
const MyElement = defineLytElement({
  name: 'my-element',
  props: {
    title: String,
    count: Number,
  },
  setup(props) {
    const shadowRoot = useShadowRoot();
    const host = useHost();
    const slots = useWebComponentSlots();

    return () => h('div', [h('h1', props.title), h('p', `Count: ${props.count}`), h('slot')]);
  },
});

// 注册自定义元素
customElements.define('my-element', MyElement);

媒体查询

import { useMediaQuery, usePreferredColorScheme, usePreferredReducedMotion } from '@lytjs/web';

// 响应式断点
const isMobile = useMediaQuery('(max-width: 768px)');
const isTablet = useMediaQuery('(min-width: 769px) and (max-width: 1024px)');
const isDesktop = useMediaQuery('(min-width: 1025px)');

// 系统主题偏好
const colorScheme = usePreferredColorScheme(); // 'light' | 'dark'
const reducedMotion = usePreferredReducedMotion(); // boolean

网络状态

import { useOnline, useNetworkStatus } from '@lytjs/web';

// 在线状态
const isOnline = useOnline();

// 详细网络状态
const network = useNetworkStatus();
// {
//   online: boolean,
//   type: 'wifi' | '4g' | '3g' | '2g' | 'slow-2g',
//   downlink: number,
//   rtt: number,
// }

页面可见性

import { usePageVisibility } from '@lytjs/web';

const isVisible = usePageVisibility();

// 页面可见性变化时
if (isVisible) {
  // 恢复动画、轮询等
} else {
  // 暂停动画、轮询等
}

鼠标/触摸位置

import { useMousePosition, useMouseInElement, useWindowScroll } from '@lytjs/web';

// 鼠标位置
const { x, y } = useMousePosition();

// 元素内相对位置
const { x: elX, y: elY, isOutside } = useMouseInElement(elementRef);

// 窗口滚动
const { x: scrollX, y: scrollY } = useWindowScroll();

类型定义

import type {
  ResizeObserverEntry,
  ResizeObserverCallback,
  LytElementOptions,
  LytElementConstructor,
  NetworkStatus,
} from '@lytjs/web';

相关包

依赖版本

本包为纯工具包,无外部 @lytjs 依赖