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

lightningcss-plugin-fluid

v0.0.7

Published

lightningcss-plugin-fluid is clump function generator

Readme

lightningcss-plugin-fluid

CSSのclamp関数を生成する、fluid() 関数を提供するLightningCSSのプラグインです。

インストール

NPM

npm i -D lightningcss-plugin-fluid

セットアップ

visitorcomposeVisitors を使って登録します。 以下は、vite を使っている場合の例です。

vite.config.js

import { defineConfig } from "vite";
import { composeVisitors } from "lightningcss";
import fluidVisitor from "lightningcss-plugin-fluid";

export default defineConfig({
  css: {
    transformer: "lightningcss",
    lightningcss: {
      visitor: composeVisitors([fluidVisitor()]),
    },
  },
});

なお、vite のドキュメントには css.lightningcss のオプションに、visitor は用意されていないようです。 TypeScriptを使うと型エラーになりますが、内部的には設定ができます。

使い方

font-size: fluid(最小値 最大値 最小ビューポート値 最大ビューポート値);

最小値と最大値は必須で、px または rem で指定します。

最小ビューポート値と最大ビューポート値は任意で、px で指定します。 省略した場合は既定値である、375px (オプションで変更可能)と、1920px (オプションで変更可能)が指定されます。(最小ビューポート値のみを省略することはできません)

font-size: fluid(24px 40px);
margin-block: fluid(2.5rem 4rem) fluid(24px 32px 768px 1024px);

ビルド結果

font-size: clamp(1.5rem, 1.25728rem + 1.0356vi, 2.5rem);
margin-block: clamp(2.5rem, 2.13592rem + 1.5534vi, 4rem) clamp(1.5rem, 0rem + 3.125vi, 2rem);

個別単位指定

fluid() 関数で個別に単位を指定することで、グローバルの単位設定を上書きできます:

/* 個別にvw単位を指定 */
font-size: fluid(16px, 32px, vw);

ビルド結果

font-size: clamp(1rem, 0.2rem + 4.27vw, 2rem);

ビューポートと単位を両方指定することも可能です:

/* ビューポートとcqi単位を指定 */
font-size: fluid(16px, 32px, 320px, 1280px, cqi);

ビルド結果

font-size: clamp(1rem, 0.33rem + 1.67cqi, 2rem);

単位の優先順位:個別指定の単位 > グローバル設定の単位 > デフォルト(vi)

カスタムプロパティ

カスタムプロパティは、単位なしのpx値のみ対応しています。

--font-sm: 14;
--font-lg: 20;

font-size: fluid(var(--font-sm) var(--font-lg));

ビルド結果

font-size: clamp((var(--font-sm) * (1rem / 16)), (((var(--font-sm)  - ((var(--font-lg)  - var(--font-sm)) / (1920 - 375)) * 375 ) * (1rem / 16))  + ( ((var(--font-lg)  - var(--font-sm)) / (1920 - 375)) * 100vi)), (var(--font-lg) * (1rem / 16)));

カスタムプロパティでも個別単位指定が可能です:

font-size: fluid(var(--font-sm), var(--font-lg), vw);

ビルド結果

font-size: clamp((var(--font-sm) * (1rem / 16)), (((var(--font-sm)  - ((var(--font-lg)  - var(--font-sm)) / (1920 - 375)) * 375 ) * (1rem / 16))  + ( ((var(--font-lg)  - var(--font-sm)) / (1920 - 375)) * 100vw)), (var(--font-lg) * (1rem / 16)));

オプション

以下のオプションが利用できます。

| オプション名 | 値 | 型 | | --- | --- | --- | | minViewPort | デフォルトとして使う最小ビューポートのpx値(既定値: 375) | number / undefined | | maxViewPort | デフォルトとして使う最大ビューポートのpx値(既定値: 1920) | number / undefined | | baseFontSize | デフォルトとしてルート要素のフォントサイズpx値(既定値: 16) | number / undefined | | unit | 推奨値に利用する単位(既定値: "vi") | "vi" / "vw" / "cqw" / "cqi" |

vite.config.js

import { defineConfig } from "vite";
import { composeVisitors } from "lightningcss";
import fluidVisitor from "lightningcss-plugin-fluid";

export default defineConfig({
  css: {
    transformer: "lightningcss",
    lightningcss: {
      visitor: composeVisitors([fluidVisitor({
        minViewPort: 320,
        maxViewPort: 1440
      })]),
    },
  },
});