@frontile/theme

中文文档
0.18.9发布于 2026/11/14MITTypeScriptCommonJS近 30 天下载 4912

Ember Octane apps 组件库:主题

中文使用文档
文档目录8 节
  1. @ frontile/ 主题
  2. 兼容性
  3. 安装
  4. 样式
  5. 颜色配置
  6. 自定义颜色
  7. 文档
  8. 许可证

@ frontile/ 主题

Ember Octane apps 组件库:主题

兼容性

  • Ember.js v3.16 或以上 (中文(简体) )
  • Ember CLI v2.13 或以上 (单位:千美元)
  • 节点.js v10 或以上

安装

ember install @frontile/theme

样式

尾风 CSS v3

// tailwind.config.js

const { frontile, safelist } = require('@frontile/theme/plugin');

module.exports = {
  content: [
    './app/**/*.{html,js,ts,hbs,gts,gjs}',
    './node_modules/@frontile/theme/dist/**/*.js',
  ],
  safelist: [
    ...safelist,
  ],
  darkMode: "class",
  theme: {
    extend: {},
  },
  plugins: [frontile()],
  // ...
};

尾风 CSS v4

使用默认主题

对于默认主题,请将此添加到您的 app/styles/app.css数字 :

@import "tailwindcss" source("../../");
@plugin "@frontile/theme/plugin/default";
@source '../../node_modules/@frontile';
自定义前置主题

要自定义前置主题, 请在您命名的项目根创建文件 frontile.js 内容如下:

const { frontile } = require('@frontile/theme/plugin');

module.exports = frontile({ /* your config */ });

那就更新你的 app/styles/app.css 来使用自定义配置 :

@import "tailwindcss" source("../../");
@plugin "./../../frontile.js";
@source '../../node_modules/@frontile';

颜色配置

您可以自定义前沿颜色的两种方式:

配置您的颜色 frontile.js 文档。 这种方法会自动生成最佳文本对比的"上"颜色:

const { frontile } = require('@frontile/theme/plugin');

module.exports = frontile({
  themes: {
    light: {
      colors: {
        primary: {
          subtle: '#3b82f6',
          DEFAULT: '#2563eb',
          strong: '#1d4ed8',
        }
      }
    },
    dark: {
      colors: {
        primary: {
          subtle: '#60a5fa',
          DEFAULT: '#3b82f6',
          strong: '#2563eb',
        }
      }
    }
  }
});

使用任何颜色格式(hex, rgb, hsl, oklch等). 插件会自动生成"上"的颜色来进行最优的文本对比.

CSS 可变引用 : 您也可以引用配置中的其他 CSS 变量 :

module.exports = frontile({
  themes: {
    light: {
      colors: {
        primary: {
          subtle: 'var(--color-surface-solid-6)',
        }
      }
    }
  }
});

说明: 在使用 CSS 变量引用时,自动"上"颜色生成被跳过,因为实际颜色值在构建时不为人所知. 需要时需要手动定义相应的"上"颜色.

自定义颜色

主题系统自动生成"上色"变体(如, on-primary, (中文(简体) ), on-success)用于语义颜色,以确保最佳文本对比. 这些颜色被作为语义背景上的文字/前色.

默认情况下,在彩色上使用WCAG对比指针来计算,并且会是纯白色或纯黑色. 然而,您可以覆盖这些自动生成的颜色,以符合您的品牌或设计要求:

const { frontile } = require('@frontile/theme/plugin');

module.exports = frontile({
  themes: {
    light: {
      colors: {
        // Define background colors as usual
        primary: {
          subtle: '#3b82f6',
          soft: '#2563eb',
          strong: '#1e3a8a',
          DEFAULT: '#1e40af'
        },
        // Override on-colors to use custom values
        'on-primary': {
          subtle: '#ffffff',      // Pure white
          soft: '#e0f2ff',        // Light blue tint instead of pure white
          strong: '#bfdbfe',      // Lighter blue
          DEFAULT: '#ffffff'      // Pure white
        }
      }
    }
  }
});

支持部分覆盖 - 你没有定义的任何变体仍将是自动生成的:

module.exports = frontile({
  themes: {
    light: {
      colors: {
        primary: {
          subtle: '#3b82f6',
          DEFAULT: '#1e40af',
          strong: '#1e3a8a',
        },
        'on-primary': {
          DEFAULT: '#e0f2ff',  // Only override the DEFAULT level, others auto-generate
        }
      }
    }
  }
});

您可以为任意语义色彩类别覆盖颜色 :

  • on-neutral, (中文(简体) ), on-primary, (中文(简体) ), on-secondary, (中文(简体) ), on-tertiary, (中文(简体) ), on-success, (中文(简体) ), on-warning, (中文(简体) ), on-danger
  • on-surface-modal

备选案文2:通过CSS变量

在您的 CSS 中直接覆盖颜色 :

@import "tailwindcss" source("../../");
@plugin "@frontile/theme/plugin/default";
@source '../../node_modules/@frontile';

@theme {
  /* Override primary colors */
  --color-primary-subtle: #3b82f6;
  --color-primary: #2563eb;
  --color-primary-strong: #1d4ed8;

  /* Manually define "on-" colors for text contrast */
  --color-on-primary-subtle: #ffffff;
  --color-on-primary: #ffffff;
  --color-on-primary-strong: #ffffff;
}

说明: 在通过 CSS 定义颜色时,必须手动定义相应的"上"颜色. 插件无法自动生成它们,因为CSS变量值在构建时无法访问.

文档

访问 前卫. dev 读取文件 并看到现场演示.

许可证

本项目根据以下规定获得许可证: MIT 许可证。 。 。 .

版本与发布记录

@frontile/theme 共发布 78 个版本,首次发布于 2024/01/10;过去 12 个月发布了 35 个版本。

版本发布日期距今
0.18.9latest2026/11/142 天前
0.18.82026/11/123 天前
0.18.72026/11/115 天前
0.18.62026/11/0411 天前
0.18.52026/11/0312 天前
0.18.32026/10/2026 天前

关于 @frontile/theme 的常见问题

@frontile/theme 是什么?

Ember Octane apps 组件库:主题

如何安装 @frontile/theme?

在项目目录运行 npm install @frontile/theme,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:tailwindcss(*)、ember-source(>= 4.12.0)、@babel/runtime(>= 7)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@frontile/theme 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@frontile/theme 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@frontile/theme 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 10.* || >= 12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@frontile/theme 可以商用吗?

@frontile/theme 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frontile/theme 的下载量有多少?

根据 npm 官方下载统计,@frontile/theme 在 2026/10/16 – 2026/11/14 这 30 天内被下载 4,912 次,日均约 164 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frontile/theme 还在维护吗?

最新版本 0.18.9 发布于 2026/11/14(2 天前);至今共发布 78 个版本,其中过去 12 个月发布了 35 个;首次发布于 2024/01/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。