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 🙏

© 2025 – Pkg Stats / Ryan Hefner

color-star-custom-methods

v0.0.10

Published

## 安装

Readme

color-star-custom-methods

安装

pnpm add color-star-custom-methods

使用方法

usePageZoomController

页面缩放控制器 Hook,用于根据屏幕分辨率自动缩放页面,确保在不同分辨率下的一致显示效果。

基本用法

<template>
  <div
    class="app-container"
    :class="containerClasses"
    :style="containerStyles"
  >
    <!-- 你的应用内容 -->
  </div>
</template>

<script setup>
import { usePageZoomController } from 'color-star-custom-methods'

// 使用页面缩放控制器
const { containerStyles, containerClasses } = usePageZoomController()
</script>

<style scoped>
.app-container {
  width: 100%;
  height: 100%;
}
</style>

配置选项

const { containerStyles, containerClasses, scaleValue, updateScale } = usePageZoomController({
  minScale: 0.9,                // 最小缩放比例,默认为0.9
  enableZoomPrevention: false   // 是否启用浏览器缩放防止,默认为false
})

返回值

| 属性 | 类型 | 说明 | |------|------|------| | containerStyles | ComputedRef<Object> | 容器样式对象,包含 transform、transformOrigin、position、top、left、width、height | | containerClasses | ComputedRef<Object> | 容器类名对象,包含 app-container 和 relative | | scaleValue | Ref<number> | 当前缩放比例值 | | defaultScale | number | 默认缩放比例(常量:1) | | minScale | number | 最小缩放比例(配置值) | | updateScale | Function | 手动更新缩放比例的方法 |

样式说明

Hook 会自动处理以下样式:

  1. 缩放变换:通过 transform: scale() 实现页面缩放
  2. 定位调整:当缩放比例不为1时,自动设置 position: fixed 和相关定位属性
  3. 尺寸计算:自动计算容器的宽高,确保缩放后内容完整显示
  4. 字体优化:自动为 .app-container 添加字体渲染优化样式,防止缩放时字体模糊

自动注入的CSS样式:

.app-container * {
  /* 优化字体渲染,防止缩放时字体模糊 */
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale !important;
  text-rendering: optimizeLegibility !important;
}

这些样式会在 hook 挂载时自动添加到页面的 <head> 中,卸载时自动移除,无需手动编写。

高级用法

<template>
  <div
    class="app"
    :class="{
      'custom-class': true,
      ...containerClasses
    }"
    :style="{
      ...containerStyles,
      backgroundColor: '#f0f0f0'
    }"
  >
    <div>当前缩放比例: {{ scaleValue }}</div>
    <button @click="updateScale">手动更新缩放</button>
  </div>
</template>

<script setup>
import { usePageZoomController } from 'color-star-custom-methods'

const { 
  containerStyles, 
  containerClasses, 
  scaleValue, 
  defaultScale,
  minScale,
  updateScale 
} = usePageZoomController({
  minScale: 0.8, // 设置最小缩放比例为 0.8
  enableZoomPrevention: true // 启用浏览器缩放防止
})

// 在模板中使用
console.log(`默认缩放比例: ${defaultScale}`) // 输出: 1(常量)
console.log(`最小缩放比例: ${minScale}`)     // 输出: 0.8
</script>

注意事项

  1. 基准分辨率:默认基准分辨率为 1920x1080
  2. 缩放范围:默认缩放比例固定为 1,最小缩放比例默认为 0.9(可通过 minScale 参数配置)
  3. 响应式:自动监听窗口大小变化并更新缩放比例
  4. CSS变量:会设置 --app-scale CSS变量,可用于其他需要反向缩放的元素

示例:配合Element Plus使用

<template>
  <ElConfigProvider :locale="zhCn">
    <div
      class="app-wrapper"
      :class="containerClasses"
      :style="containerStyles"
    >
      <!-- 应用内容 -->
    </div>
  </ElConfigProvider>
</template>

<script setup>
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn'
import { usePageZoomController } from 'color-star-custom-methods'

const { containerStyles, containerClasses } = usePageZoomController()
</script>

calculateScale

单独计算缩放比例的工具函数。

import { calculateScale } from 'color-star-custom-methods'

const scale = calculateScale()
console.log('当前缩放比例:', scale)

开发

构建

pnpm run build

开发模式

pnpm run dev

License

MIT