1
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
MIT LICENSE
|
||||
|
||||
Copyright (c) 2018-present Ant UED, https://xtech.antfin.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<h1 align="center">Ant Design Colors</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
:art: Color palettes calculator of [Ant Design](https://ant.design/docs/spec/colors).
|
||||
|
||||
[![CI status][github-action-image]][github-action-url]
|
||||
[![codecov][codecov-image]][codecov-url]
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![NPM downloads][download-image]][download-url]
|
||||
[![][bundlephobia-image]][bundlephobia-url]
|
||||
|
||||

|
||||
|
||||
[npm-image]: http://img.shields.io/npm/v/@ant-design/colors.svg?style=flat-square
|
||||
[npm-url]: http://npmjs.org/package/@ant-design/colors
|
||||
[github-action-image]: https://github.com/ant-design/ant-design-colors/actions/workflows/ci.yml/badge.svg
|
||||
[github-action-url]: https://github.com/ant-design/ant-design-colors/actions/workflows/ci.yml
|
||||
[codecov-image]: https://img.shields.io/codecov/c/github/ant-design/ant-design-colors/main.svg?style=flat-square
|
||||
[codecov-url]: https://codecov.io/gh/ant-design/ant-design-colors/tree/main
|
||||
[download-image]: https://img.shields.io/npm/dm/@ant-design/colors.svg?style=flat-square
|
||||
[download-url]: https://npmjs.org/package/@ant-design/colors
|
||||
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@ant-design/colors?style=flat-square
|
||||
[bundlephobia-url]: https://bundlephobia.com/package/@ant-design/colors
|
||||
</div>
|
||||
|
||||

|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
$ npm install @ant-design/colors
|
||||
// or
|
||||
$ yarn add @ant-design/colors
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
$ npm install @ant-design/colors --save
|
||||
```
|
||||
|
||||
```js
|
||||
import {
|
||||
red,
|
||||
volcano,
|
||||
gold,
|
||||
yellow,
|
||||
lime,
|
||||
green,
|
||||
cyan,
|
||||
blue,
|
||||
geekblue,
|
||||
purple,
|
||||
magenta,
|
||||
grey,
|
||||
} from '@ant-design/colors';
|
||||
|
||||
console.log(blue); // ['#E6F4FF', '#BAE0FF', '#91CAFF', '#69B1FF', '#4096FF', '#1677FF', '#0958D9', '#003EB3', '#002C8C', '#001D66']
|
||||
console.log(blue.primary); // '#1677FF'
|
||||
```
|
||||
|
||||
```js
|
||||
import { generate, presetPalettes } from '@ant-design/colors';
|
||||
|
||||
// Generate color palettes by a given color
|
||||
const colors = generate('#1890ff');
|
||||
console.log(colors); // ['#E6F7FF', '#BAE7FF', '#91D5FF', ''#69C0FF', '#40A9FF', '#1890FF', '#096DD9', '#0050B3', '#003A8C', '#002766']
|
||||
console.log(presetPalettes);
|
||||
/*
|
||||
{
|
||||
red: [...],
|
||||
volcano: [...],
|
||||
orange: [...],
|
||||
gold: [...],
|
||||
yellow: [...],
|
||||
lime: [...],
|
||||
green: [...],
|
||||
cyan: [...],
|
||||
blue: [...],
|
||||
geekblue: [...],
|
||||
purple: [...],
|
||||
magenta: [...],
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
```js
|
||||
import { generate, presetDarkPalettes } from '@ant-design/colors';
|
||||
|
||||
// Generate dark color palettes by a given color
|
||||
const colors = generate('#1890ff', {
|
||||
theme: 'dark',
|
||||
backgroundColor: '#141414',
|
||||
});
|
||||
console.log(colors); // ['#111d2c', '#112a45', '#15395b', '#164c7e', '#1765ad', '#177ddc', '#3c9ae8', '#65b7f3', '#8dcff8', '#b7e3fa']
|
||||
console.log(presetDarkPalettes);
|
||||
/*
|
||||
{
|
||||
red: [...],
|
||||
volcano: [...],
|
||||
orange: [...],
|
||||
gold: [...],
|
||||
yellow: [...],
|
||||
lime: [...],
|
||||
green: [...],
|
||||
cyan: [...],
|
||||
blue: [...],
|
||||
geekblue: [...],
|
||||
purple: [...],
|
||||
magenta: [...],
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
## Articles
|
||||
|
||||
- [Ant Design Colors](https://ant.design/docs/spec/colors)
|
||||
- [Ant Design 色板生成算法演进之路](https://zhuanlan.zhihu.com/p/32422584)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { ColorInput } from '@ant-design/fast-color';
|
||||
interface Opts {
|
||||
theme?: 'dark' | 'default';
|
||||
backgroundColor?: string;
|
||||
}
|
||||
export default function generate(color: ColorInput, opts?: Opts): string[];
|
||||
export {};
|
||||
//# sourceMappingURL=generate.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAsFzD,UAAU,IAAI;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,GAAE,IAAS,GAAG,MAAM,EAAE,CA8B7E"}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
import { FastColor } from '@ant-design/fast-color';
|
||||
const hueStep = 2; // 色相阶梯
|
||||
const saturationStep = 0.16; // 饱和度阶梯,浅色部分
|
||||
const saturationStep2 = 0.05; // 饱和度阶梯,深色部分
|
||||
const brightnessStep1 = 0.05; // 亮度阶梯,浅色部分
|
||||
const brightnessStep2 = 0.15; // 亮度阶梯,深色部分
|
||||
const lightColorCount = 5; // 浅色数量,主色上
|
||||
const darkColorCount = 4; // 深色数量,主色下
|
||||
|
||||
// 暗色主题颜色映射关系表
|
||||
const darkColorMap = [{
|
||||
index: 7,
|
||||
amount: 15
|
||||
}, {
|
||||
index: 6,
|
||||
amount: 25
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 30
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 45
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 65
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 85
|
||||
}, {
|
||||
index: 4,
|
||||
amount: 90
|
||||
}, {
|
||||
index: 3,
|
||||
amount: 95
|
||||
}, {
|
||||
index: 2,
|
||||
amount: 97
|
||||
}, {
|
||||
index: 1,
|
||||
amount: 98
|
||||
}];
|
||||
function getHue(hsv, i, light) {
|
||||
let hue;
|
||||
// 根据色相不同,色相转向不同
|
||||
if (Math.round(hsv.h) >= 60 && Math.round(hsv.h) <= 240) {
|
||||
hue = light ? Math.round(hsv.h) - hueStep * i : Math.round(hsv.h) + hueStep * i;
|
||||
} else {
|
||||
hue = light ? Math.round(hsv.h) + hueStep * i : Math.round(hsv.h) - hueStep * i;
|
||||
}
|
||||
if (hue < 0) {
|
||||
hue += 360;
|
||||
} else if (hue >= 360) {
|
||||
hue -= 360;
|
||||
}
|
||||
return hue;
|
||||
}
|
||||
function getSaturation(hsv, i, light) {
|
||||
// grey color don't change saturation
|
||||
if (hsv.h === 0 && hsv.s === 0) {
|
||||
return hsv.s;
|
||||
}
|
||||
let saturation;
|
||||
if (light) {
|
||||
saturation = hsv.s - saturationStep * i;
|
||||
} else if (i === darkColorCount) {
|
||||
saturation = hsv.s + saturationStep;
|
||||
} else {
|
||||
saturation = hsv.s + saturationStep2 * i;
|
||||
}
|
||||
// 边界值修正
|
||||
if (saturation > 1) {
|
||||
saturation = 1;
|
||||
}
|
||||
// 第一格的 s 限制在 0.06-0.1 之间
|
||||
if (light && i === lightColorCount && saturation > 0.1) {
|
||||
saturation = 0.1;
|
||||
}
|
||||
if (saturation < 0.06) {
|
||||
saturation = 0.06;
|
||||
}
|
||||
return Math.round(saturation * 100) / 100;
|
||||
}
|
||||
function getValue(hsv, i, light) {
|
||||
let value;
|
||||
if (light) {
|
||||
value = hsv.v + brightnessStep1 * i;
|
||||
} else {
|
||||
value = hsv.v - brightnessStep2 * i;
|
||||
}
|
||||
// Clamp value between 0 and 1
|
||||
value = Math.max(0, Math.min(1, value));
|
||||
return Math.round(value * 100) / 100;
|
||||
}
|
||||
export default function generate(color, opts = {}) {
|
||||
const patterns = [];
|
||||
const pColor = new FastColor(color);
|
||||
const hsv = pColor.toHsv();
|
||||
for (let i = lightColorCount; i > 0; i -= 1) {
|
||||
const c = new FastColor({
|
||||
h: getHue(hsv, i, true),
|
||||
s: getSaturation(hsv, i, true),
|
||||
v: getValue(hsv, i, true)
|
||||
});
|
||||
patterns.push(c);
|
||||
}
|
||||
patterns.push(pColor);
|
||||
for (let i = 1; i <= darkColorCount; i += 1) {
|
||||
const c = new FastColor({
|
||||
h: getHue(hsv, i),
|
||||
s: getSaturation(hsv, i),
|
||||
v: getValue(hsv, i)
|
||||
});
|
||||
patterns.push(c);
|
||||
}
|
||||
|
||||
// dark theme patterns
|
||||
if (opts.theme === 'dark') {
|
||||
return darkColorMap.map(({
|
||||
index,
|
||||
amount
|
||||
}) => new FastColor(opts.backgroundColor || '#141414').mix(patterns[index], amount).toHexString());
|
||||
}
|
||||
return patterns.map(c => c.toHexString());
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export { default as generate } from './generate';
|
||||
export * from './presets';
|
||||
export type * from './types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,cAAc,WAAW,CAAA;AACzB,mBAAmB,SAAS,CAAA"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { default as generate } from "./generate";
|
||||
export * from "./presets";
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import type { Palette, PalettesProps } from './types';
|
||||
export declare const presetPrimaryColors: Record<string, string>;
|
||||
export declare const red: Palette;
|
||||
export declare const volcano: Palette;
|
||||
export declare const orange: Palette;
|
||||
export declare const gold: Palette;
|
||||
export declare const yellow: Palette;
|
||||
export declare const lime: Palette;
|
||||
export declare const green: Palette;
|
||||
export declare const cyan: Palette;
|
||||
export declare const blue: Palette;
|
||||
export declare const geekblue: Palette;
|
||||
export declare const purple: Palette;
|
||||
export declare const magenta: Palette;
|
||||
export declare const grey: Palette;
|
||||
export declare const gray: Palette;
|
||||
export declare const presetPalettes: PalettesProps;
|
||||
export declare const redDark: Palette;
|
||||
export declare const volcanoDark: Palette;
|
||||
export declare const orangeDark: Palette;
|
||||
export declare const goldDark: Palette;
|
||||
export declare const yellowDark: Palette;
|
||||
export declare const limeDark: Palette;
|
||||
export declare const greenDark: Palette;
|
||||
export declare const cyanDark: Palette;
|
||||
export declare const blueDark: Palette;
|
||||
export declare const geekblueDark: Palette;
|
||||
export declare const purpleDark: Palette;
|
||||
export declare const magentaDark: Palette;
|
||||
export declare const greyDark: Palette;
|
||||
export declare const presetDarkPalettes: PalettesProps;
|
||||
//# sourceMappingURL=presets.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["presets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CActD,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,OAWjB,CAAC;AAGF,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAGF,eAAO,MAAM,MAAM,EAAE,OAWpB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,MAAM,EAAE,OAWpB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,KAAK,EAAE,OAWnB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,MAAM,EAAE,OAWpB,CAAC;AAGF,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,IAAI,SAAO,CAAC;AAEzB,eAAO,MAAM,cAAc,EAAE,aAc5B,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,OAWzB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAWxB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAWxB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,SAAS,EAAE,OAWvB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OAW1B,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAWxB,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,OAWzB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,kBAAkB,EAAE,aAchC,CAAC"}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
// Generated by script. Do NOT modify!
|
||||
|
||||
export const presetPrimaryColors = {
|
||||
"red": "#F5222D",
|
||||
"volcano": "#FA541C",
|
||||
"orange": "#FA8C16",
|
||||
"gold": "#FAAD14",
|
||||
"yellow": "#FADB14",
|
||||
"lime": "#A0D911",
|
||||
"green": "#52C41A",
|
||||
"cyan": "#13C2C2",
|
||||
"blue": "#1677FF",
|
||||
"geekblue": "#2F54EB",
|
||||
"purple": "#722ED1",
|
||||
"magenta": "#EB2F96",
|
||||
"grey": "#666666"
|
||||
};
|
||||
export const red = ["#fff1f0", "#ffccc7", "#ffa39e", "#ff7875", "#ff4d4f", "#f5222d", "#cf1322", "#a8071a", "#820014", "#5c0011"];
|
||||
red.primary = red[5];
|
||||
export const volcano = ["#fff2e8", "#ffd8bf", "#ffbb96", "#ff9c6e", "#ff7a45", "#fa541c", "#d4380d", "#ad2102", "#871400", "#610b00"];
|
||||
volcano.primary = volcano[5];
|
||||
export const orange = ["#fff7e6", "#ffe7ba", "#ffd591", "#ffc069", "#ffa940", "#fa8c16", "#d46b08", "#ad4e00", "#873800", "#612500"];
|
||||
orange.primary = orange[5];
|
||||
export const gold = ["#fffbe6", "#fff1b8", "#ffe58f", "#ffd666", "#ffc53d", "#faad14", "#d48806", "#ad6800", "#874d00", "#613400"];
|
||||
gold.primary = gold[5];
|
||||
export const yellow = ["#feffe6", "#ffffb8", "#fffb8f", "#fff566", "#ffec3d", "#fadb14", "#d4b106", "#ad8b00", "#876800", "#614700"];
|
||||
yellow.primary = yellow[5];
|
||||
export const lime = ["#fcffe6", "#f4ffb8", "#eaff8f", "#d3f261", "#bae637", "#a0d911", "#7cb305", "#5b8c00", "#3f6600", "#254000"];
|
||||
lime.primary = lime[5];
|
||||
export const green = ["#f6ffed", "#d9f7be", "#b7eb8f", "#95de64", "#73d13d", "#52c41a", "#389e0d", "#237804", "#135200", "#092b00"];
|
||||
green.primary = green[5];
|
||||
export const cyan = ["#e6fffb", "#b5f5ec", "#87e8de", "#5cdbd3", "#36cfc9", "#13c2c2", "#08979c", "#006d75", "#00474f", "#002329"];
|
||||
cyan.primary = cyan[5];
|
||||
export const blue = ["#e6f4ff", "#bae0ff", "#91caff", "#69b1ff", "#4096ff", "#1677ff", "#0958d9", "#003eb3", "#002c8c", "#001d66"];
|
||||
blue.primary = blue[5];
|
||||
export const geekblue = ["#f0f5ff", "#d6e4ff", "#adc6ff", "#85a5ff", "#597ef7", "#2f54eb", "#1d39c4", "#10239e", "#061178", "#030852"];
|
||||
geekblue.primary = geekblue[5];
|
||||
export const purple = ["#f9f0ff", "#efdbff", "#d3adf7", "#b37feb", "#9254de", "#722ed1", "#531dab", "#391085", "#22075e", "#120338"];
|
||||
purple.primary = purple[5];
|
||||
export const magenta = ["#fff0f6", "#ffd6e7", "#ffadd2", "#ff85c0", "#f759ab", "#eb2f96", "#c41d7f", "#9e1068", "#780650", "#520339"];
|
||||
magenta.primary = magenta[5];
|
||||
export const grey = ["#a6a6a6", "#999999", "#8c8c8c", "#808080", "#737373", "#666666", "#404040", "#1a1a1a", "#000000", "#000000"];
|
||||
grey.primary = grey[5];
|
||||
export const gray = grey;
|
||||
export const presetPalettes = {
|
||||
red,
|
||||
volcano,
|
||||
orange,
|
||||
gold,
|
||||
yellow,
|
||||
lime,
|
||||
green,
|
||||
cyan,
|
||||
blue,
|
||||
geekblue,
|
||||
purple,
|
||||
magenta,
|
||||
grey
|
||||
};
|
||||
export const redDark = ["#2a1215", "#431418", "#58181c", "#791a1f", "#a61d24", "#d32029", "#e84749", "#f37370", "#f89f9a", "#fac8c3"];
|
||||
redDark.primary = redDark[5];
|
||||
export const volcanoDark = ["#2b1611", "#441d12", "#592716", "#7c3118", "#aa3e19", "#d84a1b", "#e87040", "#f3956a", "#f8b692", "#fad4bc"];
|
||||
volcanoDark.primary = volcanoDark[5];
|
||||
export const orangeDark = ["#2b1d11", "#442a11", "#593815", "#7c4a15", "#aa6215", "#d87a16", "#e89a3c", "#f3b765", "#f8cf8d", "#fae3b7"];
|
||||
orangeDark.primary = orangeDark[5];
|
||||
export const goldDark = ["#2b2111", "#443111", "#594214", "#7c5914", "#aa7714", "#d89614", "#e8b339", "#f3cc62", "#f8df8b", "#faedb5"];
|
||||
goldDark.primary = goldDark[5];
|
||||
export const yellowDark = ["#2b2611", "#443b11", "#595014", "#7c6e14", "#aa9514", "#d8bd14", "#e8d639", "#f3ea62", "#f8f48b", "#fafab5"];
|
||||
yellowDark.primary = yellowDark[5];
|
||||
export const limeDark = ["#1f2611", "#2e3c10", "#3e4f13", "#536d13", "#6f9412", "#8bbb11", "#a9d134", "#c9e75d", "#e4f88b", "#f0fab5"];
|
||||
limeDark.primary = limeDark[5];
|
||||
export const greenDark = ["#162312", "#1d3712", "#274916", "#306317", "#3c8618", "#49aa19", "#6abe39", "#8fd460", "#b2e58b", "#d5f2bb"];
|
||||
greenDark.primary = greenDark[5];
|
||||
export const cyanDark = ["#112123", "#113536", "#144848", "#146262", "#138585", "#13a8a8", "#33bcb7", "#58d1c9", "#84e2d8", "#b2f1e8"];
|
||||
cyanDark.primary = cyanDark[5];
|
||||
export const blueDark = ["#111a2c", "#112545", "#15325b", "#15417e", "#1554ad", "#1668dc", "#3c89e8", "#65a9f3", "#8dc5f8", "#b7dcfa"];
|
||||
blueDark.primary = blueDark[5];
|
||||
export const geekblueDark = ["#131629", "#161d40", "#1c2755", "#203175", "#263ea0", "#2b4acb", "#5273e0", "#7f9ef3", "#a8c1f8", "#d2e0fa"];
|
||||
geekblueDark.primary = geekblueDark[5];
|
||||
export const purpleDark = ["#1a1325", "#24163a", "#301c4d", "#3e2069", "#51258f", "#642ab5", "#854eca", "#ab7ae0", "#cda8f0", "#ebd7fa"];
|
||||
purpleDark.primary = purpleDark[5];
|
||||
export const magentaDark = ["#291321", "#40162f", "#551c3b", "#75204f", "#a02669", "#cb2b83", "#e0529c", "#f37fb7", "#f8a8cc", "#fad2e3"];
|
||||
magentaDark.primary = magentaDark[5];
|
||||
export const greyDark = ["#151515", "#1f1f1f", "#2d2d2d", "#393939", "#494949", "#5a5a5a", "#6a6a6a", "#7b7b7b", "#888888", "#969696"];
|
||||
greyDark.primary = greyDark[5];
|
||||
export const presetDarkPalettes = {
|
||||
red: redDark,
|
||||
volcano: volcanoDark,
|
||||
orange: orangeDark,
|
||||
gold: goldDark,
|
||||
yellow: yellowDark,
|
||||
lime: limeDark,
|
||||
green: greenDark,
|
||||
cyan: cyanDark,
|
||||
blue: blueDark,
|
||||
geekblue: geekblueDark,
|
||||
purple: purpleDark,
|
||||
magenta: magentaDark,
|
||||
grey: greyDark
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export type Palette = string[] & {
|
||||
primary?: string;
|
||||
};
|
||||
export type PalettesProps = Record<string, Palette>;
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { ColorInput } from '@ant-design/fast-color';
|
||||
interface Opts {
|
||||
theme?: 'dark' | 'default';
|
||||
backgroundColor?: string;
|
||||
}
|
||||
export default function generate(color: ColorInput, opts?: Opts): string[];
|
||||
export {};
|
||||
//# sourceMappingURL=generate.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAsFzD,UAAU,IAAI;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,GAAE,IAAS,GAAG,MAAM,EAAE,CA8B7E"}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = generate;
|
||||
var _fastColor = require("@ant-design/fast-color");
|
||||
const hueStep = 2; // 色相阶梯
|
||||
const saturationStep = 0.16; // 饱和度阶梯,浅色部分
|
||||
const saturationStep2 = 0.05; // 饱和度阶梯,深色部分
|
||||
const brightnessStep1 = 0.05; // 亮度阶梯,浅色部分
|
||||
const brightnessStep2 = 0.15; // 亮度阶梯,深色部分
|
||||
const lightColorCount = 5; // 浅色数量,主色上
|
||||
const darkColorCount = 4; // 深色数量,主色下
|
||||
|
||||
// 暗色主题颜色映射关系表
|
||||
const darkColorMap = [{
|
||||
index: 7,
|
||||
amount: 15
|
||||
}, {
|
||||
index: 6,
|
||||
amount: 25
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 30
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 45
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 65
|
||||
}, {
|
||||
index: 5,
|
||||
amount: 85
|
||||
}, {
|
||||
index: 4,
|
||||
amount: 90
|
||||
}, {
|
||||
index: 3,
|
||||
amount: 95
|
||||
}, {
|
||||
index: 2,
|
||||
amount: 97
|
||||
}, {
|
||||
index: 1,
|
||||
amount: 98
|
||||
}];
|
||||
function getHue(hsv, i, light) {
|
||||
let hue;
|
||||
// 根据色相不同,色相转向不同
|
||||
if (Math.round(hsv.h) >= 60 && Math.round(hsv.h) <= 240) {
|
||||
hue = light ? Math.round(hsv.h) - hueStep * i : Math.round(hsv.h) + hueStep * i;
|
||||
} else {
|
||||
hue = light ? Math.round(hsv.h) + hueStep * i : Math.round(hsv.h) - hueStep * i;
|
||||
}
|
||||
if (hue < 0) {
|
||||
hue += 360;
|
||||
} else if (hue >= 360) {
|
||||
hue -= 360;
|
||||
}
|
||||
return hue;
|
||||
}
|
||||
function getSaturation(hsv, i, light) {
|
||||
// grey color don't change saturation
|
||||
if (hsv.h === 0 && hsv.s === 0) {
|
||||
return hsv.s;
|
||||
}
|
||||
let saturation;
|
||||
if (light) {
|
||||
saturation = hsv.s - saturationStep * i;
|
||||
} else if (i === darkColorCount) {
|
||||
saturation = hsv.s + saturationStep;
|
||||
} else {
|
||||
saturation = hsv.s + saturationStep2 * i;
|
||||
}
|
||||
// 边界值修正
|
||||
if (saturation > 1) {
|
||||
saturation = 1;
|
||||
}
|
||||
// 第一格的 s 限制在 0.06-0.1 之间
|
||||
if (light && i === lightColorCount && saturation > 0.1) {
|
||||
saturation = 0.1;
|
||||
}
|
||||
if (saturation < 0.06) {
|
||||
saturation = 0.06;
|
||||
}
|
||||
return Math.round(saturation * 100) / 100;
|
||||
}
|
||||
function getValue(hsv, i, light) {
|
||||
let value;
|
||||
if (light) {
|
||||
value = hsv.v + brightnessStep1 * i;
|
||||
} else {
|
||||
value = hsv.v - brightnessStep2 * i;
|
||||
}
|
||||
// Clamp value between 0 and 1
|
||||
value = Math.max(0, Math.min(1, value));
|
||||
return Math.round(value * 100) / 100;
|
||||
}
|
||||
function generate(color, opts = {}) {
|
||||
const patterns = [];
|
||||
const pColor = new _fastColor.FastColor(color);
|
||||
const hsv = pColor.toHsv();
|
||||
for (let i = lightColorCount; i > 0; i -= 1) {
|
||||
const c = new _fastColor.FastColor({
|
||||
h: getHue(hsv, i, true),
|
||||
s: getSaturation(hsv, i, true),
|
||||
v: getValue(hsv, i, true)
|
||||
});
|
||||
patterns.push(c);
|
||||
}
|
||||
patterns.push(pColor);
|
||||
for (let i = 1; i <= darkColorCount; i += 1) {
|
||||
const c = new _fastColor.FastColor({
|
||||
h: getHue(hsv, i),
|
||||
s: getSaturation(hsv, i),
|
||||
v: getValue(hsv, i)
|
||||
});
|
||||
patterns.push(c);
|
||||
}
|
||||
|
||||
// dark theme patterns
|
||||
if (opts.theme === 'dark') {
|
||||
return darkColorMap.map(({
|
||||
index,
|
||||
amount
|
||||
}) => new _fastColor.FastColor(opts.backgroundColor || '#141414').mix(patterns[index], amount).toHexString());
|
||||
}
|
||||
return patterns.map(c => c.toHexString());
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export { default as generate } from './generate';
|
||||
export * from './presets';
|
||||
export type * from './types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,cAAc,WAAW,CAAA;AACzB,mBAAmB,SAAS,CAAA"}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _exportNames = {
|
||||
generate: true
|
||||
};
|
||||
Object.defineProperty(exports, "generate", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _generate.default;
|
||||
}
|
||||
});
|
||||
var _generate = _interopRequireDefault(require("./generate"));
|
||||
var _presets = require("./presets");
|
||||
Object.keys(_presets).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
if (key in exports && exports[key] === _presets[key]) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _presets[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import type { Palette, PalettesProps } from './types';
|
||||
export declare const presetPrimaryColors: Record<string, string>;
|
||||
export declare const red: Palette;
|
||||
export declare const volcano: Palette;
|
||||
export declare const orange: Palette;
|
||||
export declare const gold: Palette;
|
||||
export declare const yellow: Palette;
|
||||
export declare const lime: Palette;
|
||||
export declare const green: Palette;
|
||||
export declare const cyan: Palette;
|
||||
export declare const blue: Palette;
|
||||
export declare const geekblue: Palette;
|
||||
export declare const purple: Palette;
|
||||
export declare const magenta: Palette;
|
||||
export declare const grey: Palette;
|
||||
export declare const gray: Palette;
|
||||
export declare const presetPalettes: PalettesProps;
|
||||
export declare const redDark: Palette;
|
||||
export declare const volcanoDark: Palette;
|
||||
export declare const orangeDark: Palette;
|
||||
export declare const goldDark: Palette;
|
||||
export declare const yellowDark: Palette;
|
||||
export declare const limeDark: Palette;
|
||||
export declare const greenDark: Palette;
|
||||
export declare const cyanDark: Palette;
|
||||
export declare const blueDark: Palette;
|
||||
export declare const geekblueDark: Palette;
|
||||
export declare const purpleDark: Palette;
|
||||
export declare const magentaDark: Palette;
|
||||
export declare const greyDark: Palette;
|
||||
export declare const presetDarkPalettes: PalettesProps;
|
||||
//# sourceMappingURL=presets.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["presets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CActD,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,OAWjB,CAAC;AAGF,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAGF,eAAO,MAAM,MAAM,EAAE,OAWpB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,MAAM,EAAE,OAWpB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,KAAK,EAAE,OAWnB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,MAAM,EAAE,OAWpB,CAAC;AAGF,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAGF,eAAO,MAAM,IAAI,EAAE,OAWlB,CAAC;AAGF,eAAO,MAAM,IAAI,SAAO,CAAC;AAEzB,eAAO,MAAM,cAAc,EAAE,aAc5B,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,OAWrB,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,OAWzB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAWxB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAWxB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,SAAS,EAAE,OAWvB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OAW1B,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAWxB,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,OAWzB,CAAC;AAGF,eAAO,MAAM,QAAQ,EAAE,OAWtB,CAAC;AAGF,eAAO,MAAM,kBAAkB,EAAE,aAchC,CAAC"}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.yellowDark = exports.yellow = exports.volcanoDark = exports.volcano = exports.redDark = exports.red = exports.purpleDark = exports.purple = exports.presetPrimaryColors = exports.presetPalettes = exports.presetDarkPalettes = exports.orangeDark = exports.orange = exports.magentaDark = exports.magenta = exports.limeDark = exports.lime = exports.greyDark = exports.grey = exports.greenDark = exports.green = exports.gray = exports.goldDark = exports.gold = exports.geekblueDark = exports.geekblue = exports.cyanDark = exports.cyan = exports.blueDark = exports.blue = void 0;
|
||||
// Generated by script. Do NOT modify!
|
||||
|
||||
const presetPrimaryColors = exports.presetPrimaryColors = {
|
||||
"red": "#F5222D",
|
||||
"volcano": "#FA541C",
|
||||
"orange": "#FA8C16",
|
||||
"gold": "#FAAD14",
|
||||
"yellow": "#FADB14",
|
||||
"lime": "#A0D911",
|
||||
"green": "#52C41A",
|
||||
"cyan": "#13C2C2",
|
||||
"blue": "#1677FF",
|
||||
"geekblue": "#2F54EB",
|
||||
"purple": "#722ED1",
|
||||
"magenta": "#EB2F96",
|
||||
"grey": "#666666"
|
||||
};
|
||||
const red = exports.red = ["#fff1f0", "#ffccc7", "#ffa39e", "#ff7875", "#ff4d4f", "#f5222d", "#cf1322", "#a8071a", "#820014", "#5c0011"];
|
||||
red.primary = red[5];
|
||||
const volcano = exports.volcano = ["#fff2e8", "#ffd8bf", "#ffbb96", "#ff9c6e", "#ff7a45", "#fa541c", "#d4380d", "#ad2102", "#871400", "#610b00"];
|
||||
volcano.primary = volcano[5];
|
||||
const orange = exports.orange = ["#fff7e6", "#ffe7ba", "#ffd591", "#ffc069", "#ffa940", "#fa8c16", "#d46b08", "#ad4e00", "#873800", "#612500"];
|
||||
orange.primary = orange[5];
|
||||
const gold = exports.gold = ["#fffbe6", "#fff1b8", "#ffe58f", "#ffd666", "#ffc53d", "#faad14", "#d48806", "#ad6800", "#874d00", "#613400"];
|
||||
gold.primary = gold[5];
|
||||
const yellow = exports.yellow = ["#feffe6", "#ffffb8", "#fffb8f", "#fff566", "#ffec3d", "#fadb14", "#d4b106", "#ad8b00", "#876800", "#614700"];
|
||||
yellow.primary = yellow[5];
|
||||
const lime = exports.lime = ["#fcffe6", "#f4ffb8", "#eaff8f", "#d3f261", "#bae637", "#a0d911", "#7cb305", "#5b8c00", "#3f6600", "#254000"];
|
||||
lime.primary = lime[5];
|
||||
const green = exports.green = ["#f6ffed", "#d9f7be", "#b7eb8f", "#95de64", "#73d13d", "#52c41a", "#389e0d", "#237804", "#135200", "#092b00"];
|
||||
green.primary = green[5];
|
||||
const cyan = exports.cyan = ["#e6fffb", "#b5f5ec", "#87e8de", "#5cdbd3", "#36cfc9", "#13c2c2", "#08979c", "#006d75", "#00474f", "#002329"];
|
||||
cyan.primary = cyan[5];
|
||||
const blue = exports.blue = ["#e6f4ff", "#bae0ff", "#91caff", "#69b1ff", "#4096ff", "#1677ff", "#0958d9", "#003eb3", "#002c8c", "#001d66"];
|
||||
blue.primary = blue[5];
|
||||
const geekblue = exports.geekblue = ["#f0f5ff", "#d6e4ff", "#adc6ff", "#85a5ff", "#597ef7", "#2f54eb", "#1d39c4", "#10239e", "#061178", "#030852"];
|
||||
geekblue.primary = geekblue[5];
|
||||
const purple = exports.purple = ["#f9f0ff", "#efdbff", "#d3adf7", "#b37feb", "#9254de", "#722ed1", "#531dab", "#391085", "#22075e", "#120338"];
|
||||
purple.primary = purple[5];
|
||||
const magenta = exports.magenta = ["#fff0f6", "#ffd6e7", "#ffadd2", "#ff85c0", "#f759ab", "#eb2f96", "#c41d7f", "#9e1068", "#780650", "#520339"];
|
||||
magenta.primary = magenta[5];
|
||||
const grey = exports.grey = ["#a6a6a6", "#999999", "#8c8c8c", "#808080", "#737373", "#666666", "#404040", "#1a1a1a", "#000000", "#000000"];
|
||||
grey.primary = grey[5];
|
||||
const gray = exports.gray = grey;
|
||||
const presetPalettes = exports.presetPalettes = {
|
||||
red,
|
||||
volcano,
|
||||
orange,
|
||||
gold,
|
||||
yellow,
|
||||
lime,
|
||||
green,
|
||||
cyan,
|
||||
blue,
|
||||
geekblue,
|
||||
purple,
|
||||
magenta,
|
||||
grey
|
||||
};
|
||||
const redDark = exports.redDark = ["#2a1215", "#431418", "#58181c", "#791a1f", "#a61d24", "#d32029", "#e84749", "#f37370", "#f89f9a", "#fac8c3"];
|
||||
redDark.primary = redDark[5];
|
||||
const volcanoDark = exports.volcanoDark = ["#2b1611", "#441d12", "#592716", "#7c3118", "#aa3e19", "#d84a1b", "#e87040", "#f3956a", "#f8b692", "#fad4bc"];
|
||||
volcanoDark.primary = volcanoDark[5];
|
||||
const orangeDark = exports.orangeDark = ["#2b1d11", "#442a11", "#593815", "#7c4a15", "#aa6215", "#d87a16", "#e89a3c", "#f3b765", "#f8cf8d", "#fae3b7"];
|
||||
orangeDark.primary = orangeDark[5];
|
||||
const goldDark = exports.goldDark = ["#2b2111", "#443111", "#594214", "#7c5914", "#aa7714", "#d89614", "#e8b339", "#f3cc62", "#f8df8b", "#faedb5"];
|
||||
goldDark.primary = goldDark[5];
|
||||
const yellowDark = exports.yellowDark = ["#2b2611", "#443b11", "#595014", "#7c6e14", "#aa9514", "#d8bd14", "#e8d639", "#f3ea62", "#f8f48b", "#fafab5"];
|
||||
yellowDark.primary = yellowDark[5];
|
||||
const limeDark = exports.limeDark = ["#1f2611", "#2e3c10", "#3e4f13", "#536d13", "#6f9412", "#8bbb11", "#a9d134", "#c9e75d", "#e4f88b", "#f0fab5"];
|
||||
limeDark.primary = limeDark[5];
|
||||
const greenDark = exports.greenDark = ["#162312", "#1d3712", "#274916", "#306317", "#3c8618", "#49aa19", "#6abe39", "#8fd460", "#b2e58b", "#d5f2bb"];
|
||||
greenDark.primary = greenDark[5];
|
||||
const cyanDark = exports.cyanDark = ["#112123", "#113536", "#144848", "#146262", "#138585", "#13a8a8", "#33bcb7", "#58d1c9", "#84e2d8", "#b2f1e8"];
|
||||
cyanDark.primary = cyanDark[5];
|
||||
const blueDark = exports.blueDark = ["#111a2c", "#112545", "#15325b", "#15417e", "#1554ad", "#1668dc", "#3c89e8", "#65a9f3", "#8dc5f8", "#b7dcfa"];
|
||||
blueDark.primary = blueDark[5];
|
||||
const geekblueDark = exports.geekblueDark = ["#131629", "#161d40", "#1c2755", "#203175", "#263ea0", "#2b4acb", "#5273e0", "#7f9ef3", "#a8c1f8", "#d2e0fa"];
|
||||
geekblueDark.primary = geekblueDark[5];
|
||||
const purpleDark = exports.purpleDark = ["#1a1325", "#24163a", "#301c4d", "#3e2069", "#51258f", "#642ab5", "#854eca", "#ab7ae0", "#cda8f0", "#ebd7fa"];
|
||||
purpleDark.primary = purpleDark[5];
|
||||
const magentaDark = exports.magentaDark = ["#291321", "#40162f", "#551c3b", "#75204f", "#a02669", "#cb2b83", "#e0529c", "#f37fb7", "#f8a8cc", "#fad2e3"];
|
||||
magentaDark.primary = magentaDark[5];
|
||||
const greyDark = exports.greyDark = ["#151515", "#1f1f1f", "#2d2d2d", "#393939", "#494949", "#5a5a5a", "#6a6a6a", "#7b7b7b", "#888888", "#969696"];
|
||||
greyDark.primary = greyDark[5];
|
||||
const presetDarkPalettes = exports.presetDarkPalettes = {
|
||||
red: redDark,
|
||||
volcano: volcanoDark,
|
||||
orange: orangeDark,
|
||||
gold: goldDark,
|
||||
yellow: yellowDark,
|
||||
lime: limeDark,
|
||||
green: greenDark,
|
||||
cyan: cyanDark,
|
||||
blue: blueDark,
|
||||
geekblue: geekblueDark,
|
||||
purple: purpleDark,
|
||||
magenta: magentaDark,
|
||||
grey: greyDark
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export type Palette = string[] & {
|
||||
primary?: string;
|
||||
};
|
||||
export type PalettesProps = Record<string, Palette>;
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "@ant-design/colors",
|
||||
"version": "8.0.1",
|
||||
"description": "Color palettes calculator of Ant Design",
|
||||
"homepage": "https://github.com/ant-design/ant-design-colors#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ant-design/ant-design-colors/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ant-design/ant-design-colors.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "afc163 <afc163@gmail.com>",
|
||||
"main": "./lib/index",
|
||||
"module": "./es/index",
|
||||
"typings": "es/index.d.ts",
|
||||
"files": [
|
||||
"lib",
|
||||
"es"
|
||||
],
|
||||
"scripts": {
|
||||
"bench": "vitest bench",
|
||||
"coverage": "npm test -- --coverage",
|
||||
"compile": "father build",
|
||||
"lint": "eslint src --ext .ts",
|
||||
"prepare": "tsx generate-presets",
|
||||
"prepublishOnly": "npm run compile && rc-np",
|
||||
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/fast-color": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ctrl/tinycolor": "^3.6.1",
|
||||
"@rc-component/father-plugin": "^2.0.4",
|
||||
"@rc-component/np": "^1.0.0",
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/node": "^20.14.9",
|
||||
"@umijs/fabric": "^3.0.0",
|
||||
"eslint": "^7.32.0",
|
||||
"father": "^4.4.4",
|
||||
"jest": "^26.6.3",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^26.5.6",
|
||||
"tsx": "^4.16.1",
|
||||
"typescript": "~5.8.2",
|
||||
"vitest": "^1.6.0"
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# @ant-design/cssinjs-utils
|
||||
A cssinjs util library to support Ant Design (antd) and its ecosystem libraries.
|
||||
|
||||
## Install
|
||||
``` bash
|
||||
npm i @ant-design/cssinjs-utils --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
## Example
|
||||
http://localhost:8000
|
||||
|
||||
## Development
|
||||
``` bash
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
## Test Case
|
||||
```
|
||||
npm test
|
||||
npm run coverage
|
||||
```
|
||||
open coverage/ dir
|
||||
|
||||
## License
|
||||
cssinjs-util is released under the MIT license.
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
/**
|
||||
* Like `useMemo`, but this hook result will be shared across all instances.
|
||||
*/
|
||||
declare function useUniqueMemo<T>(memoFn: () => T, deps: React.DependencyList): T;
|
||||
export default useUniqueMemo;
|
||||
Generated
Vendored
+100
@@ -0,0 +1,100 @@
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
||||
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import React from 'react';
|
||||
var BEAT_LIMIT = 1000 * 60 * 10;
|
||||
|
||||
/**
|
||||
* A helper class to map keys to values.
|
||||
* It supports both primitive keys and object keys.
|
||||
*/
|
||||
var ArrayKeyMap = /*#__PURE__*/function () {
|
||||
function ArrayKeyMap() {
|
||||
_classCallCheck(this, ArrayKeyMap);
|
||||
_defineProperty(this, "map", new Map());
|
||||
// Use WeakMap to avoid memory leak
|
||||
_defineProperty(this, "objectIDMap", new WeakMap());
|
||||
_defineProperty(this, "nextID", 0);
|
||||
_defineProperty(this, "lastAccessBeat", new Map());
|
||||
// We will clean up the cache when reach the limit
|
||||
_defineProperty(this, "accessBeat", 0);
|
||||
}
|
||||
_createClass(ArrayKeyMap, [{
|
||||
key: "set",
|
||||
value: function set(keys, value) {
|
||||
// New set will trigger clear
|
||||
this.clear();
|
||||
|
||||
// Set logic
|
||||
var compositeKey = this.getCompositeKey(keys);
|
||||
this.map.set(compositeKey, value);
|
||||
this.lastAccessBeat.set(compositeKey, Date.now());
|
||||
}
|
||||
}, {
|
||||
key: "get",
|
||||
value: function get(keys) {
|
||||
var compositeKey = this.getCompositeKey(keys);
|
||||
var cache = this.map.get(compositeKey);
|
||||
this.lastAccessBeat.set(compositeKey, Date.now());
|
||||
this.accessBeat += 1;
|
||||
return cache;
|
||||
}
|
||||
}, {
|
||||
key: "getCompositeKey",
|
||||
value: function getCompositeKey(keys) {
|
||||
var _this = this;
|
||||
var ids = keys.map(function (key) {
|
||||
if (key && _typeof(key) === 'object') {
|
||||
return "obj_".concat(_this.getObjectID(key));
|
||||
}
|
||||
return "".concat(_typeof(key), "_").concat(key);
|
||||
});
|
||||
return ids.join('|');
|
||||
}
|
||||
}, {
|
||||
key: "getObjectID",
|
||||
value: function getObjectID(obj) {
|
||||
if (this.objectIDMap.has(obj)) {
|
||||
return this.objectIDMap.get(obj);
|
||||
}
|
||||
var id = this.nextID;
|
||||
this.objectIDMap.set(obj, id);
|
||||
this.nextID += 1;
|
||||
return id;
|
||||
}
|
||||
}, {
|
||||
key: "clear",
|
||||
value: function clear() {
|
||||
var _this2 = this;
|
||||
if (this.accessBeat > 10000) {
|
||||
var now = Date.now();
|
||||
this.lastAccessBeat.forEach(function (beat, key) {
|
||||
if (now - beat > BEAT_LIMIT) {
|
||||
_this2.map.delete(key);
|
||||
_this2.lastAccessBeat.delete(key);
|
||||
}
|
||||
});
|
||||
this.accessBeat = 0;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
return ArrayKeyMap;
|
||||
}();
|
||||
var uniqueMap = new ArrayKeyMap();
|
||||
|
||||
/**
|
||||
* Like `useMemo`, but this hook result will be shared across all instances.
|
||||
*/
|
||||
function useUniqueMemo(memoFn, deps) {
|
||||
return React.useMemo(function () {
|
||||
var cachedValue = uniqueMap.get(deps);
|
||||
if (cachedValue) {
|
||||
return cachedValue;
|
||||
}
|
||||
var newValue = memoFn();
|
||||
uniqueMap.set(deps, newValue);
|
||||
return newValue;
|
||||
}, deps);
|
||||
}
|
||||
export default useUniqueMemo;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export type UseCSP = () => {
|
||||
nonce?: string;
|
||||
};
|
||||
/**
|
||||
* Provide a default hook since not everyone needs to config this.
|
||||
*/
|
||||
declare const useDefaultCSP: UseCSP;
|
||||
export default useDefaultCSP;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Provide a default hook since not everyone needs to config this.
|
||||
*/
|
||||
var useDefaultCSP = function useDefaultCSP() {
|
||||
return {};
|
||||
};
|
||||
export default useDefaultCSP;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export type UsePrefix = () => {
|
||||
/**
|
||||
* All the component use `@ant-design/cssinjs-utils` should have same `rootPrefixCls`.
|
||||
*/
|
||||
rootPrefixCls: string;
|
||||
/**
|
||||
* `iconPrefixCls` comes from the setting of `@ant-design/icons`.
|
||||
* Here maybe little coupling but everyone need use this.
|
||||
*/
|
||||
iconPrefixCls: string;
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import type { Theme, TokenType } from '@ant-design/cssinjs';
|
||||
import type { OverrideTokenMap, TokenMap, GlobalToken } from '../interface';
|
||||
export type TokenMapWithTheme<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType> = {
|
||||
[key in keyof OverrideTokenMap<CompTokenMap, AliasToken>]?: OverrideTokenMap<CompTokenMap, AliasToken>[key] & {
|
||||
theme?: Theme<DesignToken, AliasToken>;
|
||||
};
|
||||
};
|
||||
export interface UseTokenReturn<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType> {
|
||||
token: GlobalToken<CompTokenMap, AliasToken>;
|
||||
realToken?: GlobalToken<CompTokenMap, AliasToken>;
|
||||
theme?: Theme<DesignToken, AliasToken>;
|
||||
components?: TokenMapWithTheme<CompTokenMap, DesignToken, AliasToken>;
|
||||
hashId?: string;
|
||||
hashed?: string | boolean;
|
||||
cssVar?: {
|
||||
prefix?: string;
|
||||
key?: string;
|
||||
};
|
||||
zeroRuntime?: boolean;
|
||||
}
|
||||
export type UseToken<CompTokenMap extends TokenMap, DesignToken extends TokenType, AliasToken extends TokenType> = () => UseTokenReturn<CompTokenMap, DesignToken, AliasToken>;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
export { default as genStyleUtils } from './util/genStyleUtils';
|
||||
export { default as genCalc } from './util/calc';
|
||||
export { default as statisticToken, merge as mergeToken, statistic } from './util/statistic';
|
||||
export type { OverrideTokenMap, TokenMap, TokenMapKey, GlobalTokenWithComponent, ComponentToken, ComponentTokenKey, GlobalToken, } from './interface';
|
||||
export type { default as AbstractCalculator } from './util/calc/calculator';
|
||||
export type { FullToken, GetDefaultToken, GetDefaultTokenFn, GenStyleFn, TokenWithCommonCls, CSSUtil, } from './util/genStyleUtils';
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { default as genStyleUtils } from "./util/genStyleUtils";
|
||||
export { default as genCalc } from "./util/calc";
|
||||
export { default as statisticToken, merge as mergeToken, statistic } from "./util/statistic";
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import type { TokenType } from '@ant-design/cssinjs';
|
||||
export type TokenMap = Record<PropertyKey, any>;
|
||||
export type TokenMapKey<CompTokenMap extends TokenMap> = Extract<keyof CompTokenMap, string>;
|
||||
export type GlobalToken<CompTokenMap extends TokenMap, AliasToken extends TokenType> = AliasToken & CompTokenMap;
|
||||
export type OverrideTokenMap<CompTokenMap extends TokenMap, AliasToken extends TokenType> = {
|
||||
[key in keyof CompTokenMap]: Partial<CompTokenMap[key]> & Partial<AliasToken>;
|
||||
};
|
||||
export type GlobalTokenWithComponent<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = GlobalToken<CompTokenMap, AliasToken> & CompTokenMap[C];
|
||||
export type ComponentToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = Exclude<OverrideTokenMap<CompTokenMap, AliasToken>[C], undefined>;
|
||||
export type ComponentTokenKey<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = keyof ComponentToken<CompTokenMap, AliasToken, C>;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export type { OverrideTokenMap, TokenMap, TokenMapKey, GlobalTokenWithComponent, ComponentToken, ComponentTokenKey, GlobalToken, } from './components';
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import AbstractCalculator from './calculator';
|
||||
export default class CSSCalculator extends AbstractCalculator {
|
||||
result: string;
|
||||
unitlessCssVar: Set<string>;
|
||||
lowPriority?: boolean;
|
||||
constructor(num: number | string | AbstractCalculator, unitlessCssVar: Set<string>);
|
||||
add(num: number | string | AbstractCalculator): this;
|
||||
sub(num: number | string | AbstractCalculator): this;
|
||||
mul(num: number | string | AbstractCalculator): this;
|
||||
div(num: number | string | AbstractCalculator): this;
|
||||
getResult(force?: boolean): string;
|
||||
equal(options?: {
|
||||
unit?: boolean;
|
||||
}): string;
|
||||
}
|
||||
Generated
Vendored
+116
@@ -0,0 +1,116 @@
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
||||
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
||||
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
||||
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
||||
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import AbstractCalculator from "./calculator";
|
||||
var CALC_UNIT = 'CALC_UNIT';
|
||||
var regexp = new RegExp(CALC_UNIT, 'g');
|
||||
function unit(value) {
|
||||
if (typeof value === 'number') {
|
||||
return "".concat(value).concat(CALC_UNIT);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
var CSSCalculator = /*#__PURE__*/function (_AbstractCalculator) {
|
||||
_inherits(CSSCalculator, _AbstractCalculator);
|
||||
var _super = _createSuper(CSSCalculator);
|
||||
function CSSCalculator(num, unitlessCssVar) {
|
||||
var _this;
|
||||
_classCallCheck(this, CSSCalculator);
|
||||
_this = _super.call(this);
|
||||
_defineProperty(_assertThisInitialized(_this), "result", '');
|
||||
_defineProperty(_assertThisInitialized(_this), "unitlessCssVar", void 0);
|
||||
_defineProperty(_assertThisInitialized(_this), "lowPriority", void 0);
|
||||
var numType = _typeof(num);
|
||||
_this.unitlessCssVar = unitlessCssVar;
|
||||
if (num instanceof CSSCalculator) {
|
||||
_this.result = "(".concat(num.result, ")");
|
||||
} else if (numType === 'number') {
|
||||
_this.result = unit(num);
|
||||
} else if (numType === 'string') {
|
||||
_this.result = num;
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
_createClass(CSSCalculator, [{
|
||||
key: "add",
|
||||
value: function add(num) {
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " + ").concat(num.getResult());
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " + ").concat(unit(num));
|
||||
}
|
||||
this.lowPriority = true;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "sub",
|
||||
value: function sub(num) {
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " - ").concat(num.getResult());
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " - ").concat(unit(num));
|
||||
}
|
||||
this.lowPriority = true;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "mul",
|
||||
value: function mul(num) {
|
||||
if (this.lowPriority) {
|
||||
this.result = "(".concat(this.result, ")");
|
||||
}
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " * ").concat(num.getResult(true));
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " * ").concat(num);
|
||||
}
|
||||
this.lowPriority = false;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "div",
|
||||
value: function div(num) {
|
||||
if (this.lowPriority) {
|
||||
this.result = "(".concat(this.result, ")");
|
||||
}
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " / ").concat(num.getResult(true));
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " / ").concat(num);
|
||||
}
|
||||
this.lowPriority = false;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "getResult",
|
||||
value: function getResult(force) {
|
||||
return this.lowPriority || force ? "(".concat(this.result, ")") : this.result;
|
||||
}
|
||||
}, {
|
||||
key: "equal",
|
||||
value: function equal(options) {
|
||||
var _this2 = this;
|
||||
var _ref = options || {},
|
||||
cssUnit = _ref.unit;
|
||||
var mergedUnit = true;
|
||||
if (typeof cssUnit === 'boolean') {
|
||||
mergedUnit = cssUnit;
|
||||
} else if (Array.from(this.unitlessCssVar).some(function (cssVar) {
|
||||
return _this2.result.includes(cssVar);
|
||||
})) {
|
||||
mergedUnit = false;
|
||||
}
|
||||
this.result = this.result.replace(regexp, mergedUnit ? 'px' : '');
|
||||
if (typeof this.lowPriority !== 'undefined') {
|
||||
return "calc(".concat(this.result, ")");
|
||||
}
|
||||
return this.result;
|
||||
}
|
||||
}]);
|
||||
return CSSCalculator;
|
||||
}(AbstractCalculator);
|
||||
export { CSSCalculator as default };
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import AbstractCalculator from './calculator';
|
||||
declare class NumCalculator extends AbstractCalculator {
|
||||
result: number;
|
||||
constructor(num: number | string | AbstractCalculator);
|
||||
add(num: number | string | AbstractCalculator): this;
|
||||
sub(num: number | string | AbstractCalculator): this;
|
||||
mul(num: number | string | AbstractCalculator): this;
|
||||
div(num: number | string | AbstractCalculator): this;
|
||||
equal(): number;
|
||||
}
|
||||
export default NumCalculator;
|
||||
Generated
Vendored
+71
@@ -0,0 +1,71 @@
|
||||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
||||
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
||||
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
||||
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
||||
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import AbstractCalculator from "./calculator";
|
||||
var NumCalculator = /*#__PURE__*/function (_AbstractCalculator) {
|
||||
_inherits(NumCalculator, _AbstractCalculator);
|
||||
var _super = _createSuper(NumCalculator);
|
||||
function NumCalculator(num) {
|
||||
var _this;
|
||||
_classCallCheck(this, NumCalculator);
|
||||
_this = _super.call(this);
|
||||
_defineProperty(_assertThisInitialized(_this), "result", 0);
|
||||
if (num instanceof NumCalculator) {
|
||||
_this.result = num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
_this.result = num;
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
_createClass(NumCalculator, [{
|
||||
key: "add",
|
||||
value: function add(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result += num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result += num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "sub",
|
||||
value: function sub(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result -= num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result -= num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "mul",
|
||||
value: function mul(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result *= num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result *= num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "div",
|
||||
value: function div(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result /= num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result /= num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "equal",
|
||||
value: function equal() {
|
||||
return this.result;
|
||||
}
|
||||
}]);
|
||||
return NumCalculator;
|
||||
}(AbstractCalculator);
|
||||
export default NumCalculator;
|
||||
Generated
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
declare abstract class AbstractCalculator {
|
||||
/**
|
||||
* @descCN 计算两数的和,例如:1 + 2
|
||||
* @descEN Calculate the sum of two numbers, e.g. 1 + 2
|
||||
*/
|
||||
abstract add(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 计算两数的差,例如:1 - 2
|
||||
* @descEN Calculate the difference between two numbers, e.g. 1 - 2
|
||||
*/
|
||||
abstract sub(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 计算两数的积,例如:1 * 2
|
||||
* @descEN Calculate the product of two numbers, e.g. 1 * 2
|
||||
*/
|
||||
abstract mul(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 计算两数的商,例如:1 / 2
|
||||
* @descEN Calculate the quotient of two numbers, e.g. 1 / 2
|
||||
*/
|
||||
abstract div(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 获取计算结果
|
||||
* @descEN Get the calculation result
|
||||
*/
|
||||
abstract equal(options?: {
|
||||
unit?: boolean;
|
||||
}): string | number;
|
||||
}
|
||||
export default AbstractCalculator;
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
||||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
||||
var AbstractCalculator = /*#__PURE__*/_createClass(function AbstractCalculator() {
|
||||
_classCallCheck(this, AbstractCalculator);
|
||||
});
|
||||
export default AbstractCalculator;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type AbstractCalculator from './calculator';
|
||||
import CSSCalculator from './CSSCalculator';
|
||||
import NumCalculator from './NumCalculator';
|
||||
declare const genCalc: (type: 'css' | 'js', unitlessCssVar: Set<string>) => (num: number | string | AbstractCalculator) => CSSCalculator | NumCalculator;
|
||||
export default genCalc;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import CSSCalculator from "./CSSCalculator";
|
||||
import NumCalculator from "./NumCalculator";
|
||||
var genCalc = function genCalc(type, unitlessCssVar) {
|
||||
var Calculator = type === 'css' ? CSSCalculator : NumCalculator;
|
||||
return function (num) {
|
||||
return new Calculator(num, unitlessCssVar);
|
||||
};
|
||||
};
|
||||
export default genCalc;
|
||||
Generated
Vendored
+140
@@ -0,0 +1,140 @@
|
||||
import type React from 'react';
|
||||
import type { CSSInterpolation, CSSObject, TokenType } from '@ant-design/cssinjs';
|
||||
import { useStyleRegister } from '@ant-design/cssinjs';
|
||||
import type { ComponentTokenKey, GlobalTokenWithComponent, TokenMap, TokenMapKey } from '../interface';
|
||||
import type AbstractCalculator from './calc/calculator';
|
||||
import type { UseCSP } from '../hooks/useCSP';
|
||||
import type { UsePrefix } from '../hooks/usePrefix';
|
||||
import type { UseToken } from '../hooks/useToken';
|
||||
type LayerConfig = Parameters<typeof useStyleRegister>[0]['layer'];
|
||||
export interface StyleInfo {
|
||||
hashId: string;
|
||||
prefixCls: string;
|
||||
rootPrefixCls: string;
|
||||
iconPrefixCls: string;
|
||||
}
|
||||
export type CSSUtil = {
|
||||
calc: (number: any) => AbstractCalculator;
|
||||
max: (...values: (number | string)[]) => number | string;
|
||||
min: (...values: (number | string)[]) => number | string;
|
||||
};
|
||||
export type TokenWithCommonCls<T> = T & {
|
||||
/** Wrap component class with `.` prefix */
|
||||
componentCls: string;
|
||||
/** Origin prefix which do not have `.` prefix */
|
||||
prefixCls: string;
|
||||
/** Wrap icon class with `.` prefix */
|
||||
iconCls: string;
|
||||
/** Wrap ant prefixCls class with `.` prefix */
|
||||
antCls: string;
|
||||
} & CSSUtil;
|
||||
export type FullToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = TokenWithCommonCls<GlobalTokenWithComponent<CompTokenMap, AliasToken, C>>;
|
||||
export type GenStyleFn<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = (token: FullToken<CompTokenMap, AliasToken, C>, info: StyleInfo) => CSSInterpolation;
|
||||
export type GetDefaultTokenFn<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = (token: AliasToken & Partial<CompTokenMap[C]>) => CompTokenMap[C];
|
||||
export type GetDefaultToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = null | CompTokenMap[C] | GetDefaultTokenFn<CompTokenMap, AliasToken, C>;
|
||||
export interface SubStyleComponentProps {
|
||||
prefixCls: string;
|
||||
rootCls?: string;
|
||||
}
|
||||
export type CSSVarRegisterProps = {
|
||||
rootCls: string;
|
||||
component: string;
|
||||
cssVar: {
|
||||
prefix?: string;
|
||||
key?: string;
|
||||
};
|
||||
};
|
||||
type GetResetStylesConfig = {
|
||||
prefix: ReturnType<UsePrefix>;
|
||||
csp: ReturnType<UseCSP>;
|
||||
};
|
||||
export type GetResetStyles<AliasToken extends TokenType> = (token: AliasToken, config?: GetResetStylesConfig) => CSSInterpolation;
|
||||
export type GetCompUnitless<CompTokenMap extends TokenMap, AliasToken extends TokenType> = <C extends TokenMapKey<CompTokenMap>>(component: C | [C, string]) => Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
|
||||
declare function genStyleUtils<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType>(config: {
|
||||
usePrefix: UsePrefix;
|
||||
useToken: UseToken<CompTokenMap, AliasToken, DesignToken>;
|
||||
useCSP?: UseCSP;
|
||||
getResetStyles?: GetResetStyles<AliasToken>;
|
||||
getCommonStyle?: (token: AliasToken, componentPrefixCls: string, rootCls?: string, resetFont?: boolean) => CSSObject;
|
||||
getCompUnitless?: GetCompUnitless<CompTokenMap, AliasToken>;
|
||||
layer?: LayerConfig;
|
||||
}): {
|
||||
genStyleHooks: <C extends TokenMapKey<CompTokenMap>>(component: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
|
||||
resetStyle?: boolean;
|
||||
resetFont?: boolean;
|
||||
deprecatedTokens?: [
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>,
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>
|
||||
][];
|
||||
/**
|
||||
* Component tokens that do not need unit.
|
||||
*/
|
||||
unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
|
||||
/**
|
||||
* Only use component style in client side. Ignore in SSR.
|
||||
*/
|
||||
clientOnly?: boolean;
|
||||
/**
|
||||
* Set order of component style.
|
||||
* @default -999
|
||||
*/
|
||||
order?: number;
|
||||
/**
|
||||
* Whether generate styles
|
||||
* @default true
|
||||
*/
|
||||
injectStyle?: boolean;
|
||||
/**
|
||||
* Extra prefixCls to inject CSS variables.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* {
|
||||
* extraCssVarPrefixCls: ['my-comp-compact', 'my-comp-large']
|
||||
* }
|
||||
* // or
|
||||
* {
|
||||
* extraCssVarPrefixCls: ({ prefixCls, rootCls }) => [`${prefixCls}-container`]
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
extraCssVarPrefixCls?: string[] | ((info: {
|
||||
prefixCls: string;
|
||||
rootCls: string;
|
||||
}) => string[]);
|
||||
}) => (prefixCls: string, rootCls?: string) => readonly [string, string];
|
||||
genSubStyleComponent: <C extends TokenMapKey<CompTokenMap>>(componentName: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
|
||||
resetStyle?: boolean;
|
||||
resetFont?: boolean;
|
||||
deprecatedTokens?: [
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>,
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>
|
||||
][];
|
||||
/**
|
||||
* Only use component style in client side. Ignore in SSR.
|
||||
*/
|
||||
clientOnly?: boolean;
|
||||
/**
|
||||
* Set order of component style. Default is -999.
|
||||
*/
|
||||
order?: number;
|
||||
injectStyle?: boolean;
|
||||
unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
|
||||
}) => React.FunctionComponent<SubStyleComponentProps>;
|
||||
genComponentStyleHook: <C_1 extends TokenMapKey<CompTokenMap>>(componentName: C_1 | [C_1, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C_1>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C_1>, options?: {
|
||||
resetStyle?: boolean;
|
||||
resetFont?: boolean;
|
||||
deprecatedTokens?: [keyof Exclude<import("../interface/components").OverrideTokenMap<CompTokenMap, AliasToken>[C_1], undefined>, keyof Exclude<import("../interface/components").OverrideTokenMap<CompTokenMap, AliasToken>[C_1], undefined>][];
|
||||
/**
|
||||
* Only use component style in client side. Ignore in SSR.
|
||||
*/
|
||||
clientOnly?: boolean;
|
||||
/**
|
||||
* Set order of component style. Default is -999.
|
||||
*/
|
||||
order?: number;
|
||||
injectStyle?: boolean;
|
||||
unitless?: Partial<Record<keyof Exclude<import("../interface/components").OverrideTokenMap<CompTokenMap, AliasToken>[C_1], undefined>, boolean>>;
|
||||
}) => (prefixCls: string, rootCls?: string) => string;
|
||||
};
|
||||
export default genStyleUtils;
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import { useMemo } from 'react';
|
||||
import { token2CSSVar, useCSSVarRegister, useStyleRegister } from '@ant-design/cssinjs';
|
||||
import genCalc from "./calc";
|
||||
import getCompVarPrefix from "./getCompVarPrefix";
|
||||
import getComponentToken from "./getComponentToken";
|
||||
import getDefaultComponentToken from "./getDefaultComponentToken";
|
||||
import genMaxMin from "./maxmin";
|
||||
import statisticToken, { merge as mergeToken } from "./statistic";
|
||||
import useUniqueMemo from "../_util/hooks/useUniqueMemo";
|
||||
import useDefaultCSP from "../hooks/useCSP";
|
||||
function genStyleUtils(config) {
|
||||
// Dependency inversion for preparing basic config.
|
||||
var _config$useCSP = config.useCSP,
|
||||
useCSP = _config$useCSP === void 0 ? useDefaultCSP : _config$useCSP,
|
||||
useToken = config.useToken,
|
||||
usePrefix = config.usePrefix,
|
||||
getResetStyles = config.getResetStyles,
|
||||
getCommonStyle = config.getCommonStyle,
|
||||
getCompUnitless = config.getCompUnitless;
|
||||
function genStyleHooks(component, styleFn, getDefaultToken, options) {
|
||||
var componentName = Array.isArray(component) ? component[0] : component;
|
||||
function prefixToken(key) {
|
||||
return "".concat(String(componentName)).concat(key.slice(0, 1).toUpperCase()).concat(key.slice(1));
|
||||
}
|
||||
|
||||
// Fill unitless
|
||||
var originUnitless = (options === null || options === void 0 ? void 0 : options.unitless) || {};
|
||||
var originCompUnitless = typeof getCompUnitless === 'function' ? getCompUnitless(component) : {};
|
||||
var compUnitless = _objectSpread(_objectSpread({}, originCompUnitless), {}, _defineProperty({}, prefixToken('zIndexPopup'), true));
|
||||
Object.keys(originUnitless).forEach(function (key) {
|
||||
compUnitless[prefixToken(key)] = originUnitless[key];
|
||||
});
|
||||
|
||||
// Options
|
||||
var mergedOptions = _objectSpread(_objectSpread({}, options), {}, {
|
||||
unitless: compUnitless,
|
||||
prefixToken: prefixToken
|
||||
});
|
||||
|
||||
// Hooks
|
||||
var useStyle = genComponentStyleHook(component, styleFn, getDefaultToken, mergedOptions);
|
||||
var useCSSVar = genCSSVarRegister(componentName, getDefaultToken, mergedOptions);
|
||||
return function (prefixCls) {
|
||||
var rootCls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prefixCls;
|
||||
var hashId = useStyle(prefixCls, rootCls);
|
||||
|
||||
// Resolve function type to get dynamic extra prefix
|
||||
var extraPrefixCls = options === null || options === void 0 ? void 0 : options.extraCssVarPrefixCls;
|
||||
var resolvedExtraPrefixCls = typeof extraPrefixCls === 'function' ? extraPrefixCls({
|
||||
prefixCls: prefixCls,
|
||||
rootCls: rootCls
|
||||
}) : extraPrefixCls;
|
||||
var cssVarCls = useCSSVar(resolvedExtraPrefixCls !== null && resolvedExtraPrefixCls !== void 0 && resolvedExtraPrefixCls.length ? [rootCls].concat(_toConsumableArray(resolvedExtraPrefixCls)) : rootCls);
|
||||
return [hashId, cssVarCls];
|
||||
};
|
||||
}
|
||||
function genCSSVarRegister(component, getDefaultToken, options) {
|
||||
var compUnitless = options.unitless,
|
||||
prefixToken = options.prefixToken,
|
||||
ignore = options.ignore;
|
||||
return function (rootCls) {
|
||||
var _useToken = useToken(),
|
||||
cssVar = _useToken.cssVar,
|
||||
realToken = _useToken.realToken;
|
||||
var csp = useCSP();
|
||||
useCSSVarRegister({
|
||||
path: [component],
|
||||
prefix: cssVar.prefix,
|
||||
key: cssVar.key,
|
||||
unitless: compUnitless,
|
||||
ignore: ignore,
|
||||
token: realToken,
|
||||
scope: rootCls,
|
||||
nonce: function nonce() {
|
||||
return csp.nonce;
|
||||
}
|
||||
}, function () {
|
||||
var defaultToken = getDefaultComponentToken(component, realToken, getDefaultToken);
|
||||
var componentToken = getComponentToken(component, realToken, defaultToken, {
|
||||
deprecatedTokens: options === null || options === void 0 ? void 0 : options.deprecatedTokens
|
||||
});
|
||||
if (defaultToken) {
|
||||
Object.keys(defaultToken).forEach(function (key) {
|
||||
componentToken[prefixToken(key)] = componentToken[key];
|
||||
delete componentToken[key];
|
||||
});
|
||||
}
|
||||
return componentToken;
|
||||
});
|
||||
return cssVar === null || cssVar === void 0 ? void 0 : cssVar.key;
|
||||
};
|
||||
}
|
||||
function genComponentStyleHook(componentName, styleFn, getDefaultToken) {
|
||||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
||||
var cells = Array.isArray(componentName) ? componentName : [componentName, componentName];
|
||||
var _cells = _slicedToArray(cells, 1),
|
||||
component = _cells[0];
|
||||
var concatComponent = cells.join('-');
|
||||
var mergedLayer = config.layer || {
|
||||
name: 'antd'
|
||||
};
|
||||
|
||||
// Return new style hook
|
||||
return function (prefixCls) {
|
||||
var rootCls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prefixCls;
|
||||
var _useToken2 = useToken(),
|
||||
theme = _useToken2.theme,
|
||||
realToken = _useToken2.realToken,
|
||||
hashId = _useToken2.hashId,
|
||||
token = _useToken2.token,
|
||||
cssVar = _useToken2.cssVar,
|
||||
zeroRuntime = _useToken2.zeroRuntime;
|
||||
|
||||
// Update of `disabledRuntimeStyle` would cause React hook error, so memoized it and never update.
|
||||
var memoizedZeroRuntime = useMemo(function () {
|
||||
return zeroRuntime;
|
||||
}, []);
|
||||
if (memoizedZeroRuntime) {
|
||||
return hashId;
|
||||
}
|
||||
var _usePrefix = usePrefix(),
|
||||
rootPrefixCls = _usePrefix.rootPrefixCls,
|
||||
iconPrefixCls = _usePrefix.iconPrefixCls;
|
||||
var csp = useCSP();
|
||||
var type = 'css';
|
||||
|
||||
// Use unique memo to share the result across all instances
|
||||
var calc = useUniqueMemo(function () {
|
||||
var unitlessCssVar = new Set();
|
||||
Object.keys(options.unitless || {}).forEach(function (key) {
|
||||
// Some component proxy the AliasToken (e.g. Image) and some not (e.g. Modal)
|
||||
// We should both pass in `unitlessCssVar` to make sure the CSSVar can be unitless.
|
||||
unitlessCssVar.add(token2CSSVar(key, cssVar.prefix));
|
||||
unitlessCssVar.add(token2CSSVar(key, getCompVarPrefix(component, cssVar.prefix)));
|
||||
});
|
||||
return genCalc(type, unitlessCssVar);
|
||||
}, [type, component, cssVar === null || cssVar === void 0 ? void 0 : cssVar.prefix]);
|
||||
var _genMaxMin = genMaxMin(type),
|
||||
max = _genMaxMin.max,
|
||||
min = _genMaxMin.min;
|
||||
|
||||
// Shared config
|
||||
var sharedConfig = {
|
||||
theme: theme,
|
||||
token: token,
|
||||
hashId: hashId,
|
||||
nonce: function nonce() {
|
||||
return csp.nonce;
|
||||
},
|
||||
clientOnly: options.clientOnly,
|
||||
layer: mergedLayer,
|
||||
// antd is always at top of styles
|
||||
order: options.order || -999
|
||||
};
|
||||
|
||||
// This if statement is safe, as it will only be used if the generator has the function. It's not dynamic.
|
||||
if (typeof getResetStyles === 'function') {
|
||||
// Generate style for all need reset tags.
|
||||
useStyleRegister(_objectSpread(_objectSpread({}, sharedConfig), {}, {
|
||||
clientOnly: false,
|
||||
path: ['Shared', rootPrefixCls]
|
||||
}), function () {
|
||||
return getResetStyles(token, {
|
||||
prefix: {
|
||||
rootPrefixCls: rootPrefixCls,
|
||||
iconPrefixCls: iconPrefixCls
|
||||
},
|
||||
csp: csp
|
||||
});
|
||||
});
|
||||
}
|
||||
useStyleRegister(_objectSpread(_objectSpread({}, sharedConfig), {}, {
|
||||
path: [concatComponent, prefixCls, iconPrefixCls]
|
||||
}), function () {
|
||||
if (options.injectStyle === false) {
|
||||
return [];
|
||||
}
|
||||
var _statisticToken = statisticToken(token),
|
||||
proxyToken = _statisticToken.token,
|
||||
flush = _statisticToken.flush;
|
||||
var defaultComponentToken = getDefaultComponentToken(component, realToken, getDefaultToken);
|
||||
var componentCls = ".".concat(prefixCls);
|
||||
var componentToken = getComponentToken(component, realToken, defaultComponentToken, {
|
||||
deprecatedTokens: options.deprecatedTokens
|
||||
});
|
||||
if (defaultComponentToken && _typeof(defaultComponentToken) === 'object') {
|
||||
Object.keys(defaultComponentToken).forEach(function (key) {
|
||||
defaultComponentToken[key] = "var(".concat(token2CSSVar(key, getCompVarPrefix(component, cssVar.prefix)), ")");
|
||||
});
|
||||
}
|
||||
var mergedToken = mergeToken(proxyToken, {
|
||||
componentCls: componentCls,
|
||||
prefixCls: prefixCls,
|
||||
iconCls: ".".concat(iconPrefixCls),
|
||||
antCls: ".".concat(rootPrefixCls),
|
||||
calc: calc,
|
||||
max: max,
|
||||
min: min
|
||||
}, defaultComponentToken);
|
||||
var styleInterpolation = styleFn(mergedToken, {
|
||||
hashId: hashId,
|
||||
prefixCls: prefixCls,
|
||||
rootPrefixCls: rootPrefixCls,
|
||||
iconPrefixCls: iconPrefixCls
|
||||
});
|
||||
flush(component, componentToken);
|
||||
var commonStyle = typeof getCommonStyle === 'function' ? getCommonStyle(mergedToken, prefixCls, rootCls, options.resetFont) : null;
|
||||
return [options.resetStyle === false ? null : commonStyle, styleInterpolation];
|
||||
});
|
||||
return hashId;
|
||||
};
|
||||
}
|
||||
function genSubStyleComponent(componentName, styleFn, getDefaultToken) {
|
||||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
||||
var useStyle = genComponentStyleHook(componentName, styleFn, getDefaultToken, _objectSpread({
|
||||
resetStyle: false,
|
||||
// Sub Style should default after root one
|
||||
order: -998
|
||||
}, options));
|
||||
var StyledComponent = function StyledComponent(_ref) {
|
||||
var prefixCls = _ref.prefixCls,
|
||||
_ref$rootCls = _ref.rootCls,
|
||||
rootCls = _ref$rootCls === void 0 ? prefixCls : _ref$rootCls;
|
||||
useStyle(prefixCls, rootCls);
|
||||
return null;
|
||||
};
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
StyledComponent.displayName = "SubStyle_".concat(String(Array.isArray(componentName) ? componentName.join('.') : componentName));
|
||||
}
|
||||
return StyledComponent;
|
||||
}
|
||||
return {
|
||||
genStyleHooks: genStyleHooks,
|
||||
genSubStyleComponent: genSubStyleComponent,
|
||||
genComponentStyleHook: genComponentStyleHook
|
||||
};
|
||||
}
|
||||
export default genStyleUtils;
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
declare const getCompVarPrefix: (component: string, prefix?: string) => string;
|
||||
export default getCompVarPrefix;
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
var getCompVarPrefix = function getCompVarPrefix(component, prefix) {
|
||||
return "".concat([prefix, component.replace(/([A-Z]+)([A-Z][a-z]+)/g, '$1-$2').replace(/([a-z])([A-Z])/g, '$1-$2')].filter(Boolean).join('-'));
|
||||
};
|
||||
export default getCompVarPrefix;
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import type { TokenMap, TokenMapKey, ComponentTokenKey, GlobalToken } from '../interface';
|
||||
import type { TokenType } from '@ant-design/cssinjs';
|
||||
declare function getComponentToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>>(component: C, token: GlobalToken<CompTokenMap, AliasToken>, defaultToken: CompTokenMap[C], options?: {
|
||||
deprecatedTokens?: [
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>,
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>
|
||||
][];
|
||||
}): any;
|
||||
export default getComponentToken;
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import { warning } from '@rc-component/util';
|
||||
function getComponentToken(component, token, defaultToken, options) {
|
||||
var customToken = _objectSpread({}, token[component]);
|
||||
if (options !== null && options !== void 0 && options.deprecatedTokens) {
|
||||
var deprecatedTokens = options.deprecatedTokens;
|
||||
deprecatedTokens.forEach(function (_ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
oldTokenKey = _ref2[0],
|
||||
newTokenKey = _ref2[1];
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
warning(!(customToken !== null && customToken !== void 0 && customToken[oldTokenKey]), "Component Token `".concat(String(oldTokenKey), "` of ").concat(String(component), " is deprecated. Please use `").concat(String(newTokenKey), "` instead."));
|
||||
}
|
||||
|
||||
// Should wrap with `if` clause, or there will be `undefined` in object.
|
||||
if (customToken !== null && customToken !== void 0 && customToken[oldTokenKey] || customToken !== null && customToken !== void 0 && customToken[newTokenKey]) {
|
||||
var _customToken$newToken;
|
||||
(_customToken$newToken = customToken[newTokenKey]) !== null && _customToken$newToken !== void 0 ? _customToken$newToken : customToken[newTokenKey] = customToken === null || customToken === void 0 ? void 0 : customToken[oldTokenKey];
|
||||
}
|
||||
});
|
||||
}
|
||||
var mergedToken = _objectSpread(_objectSpread({}, defaultToken), customToken);
|
||||
|
||||
// Remove same value as global token to minimize size
|
||||
Object.keys(mergedToken).forEach(function (key) {
|
||||
if (mergedToken[key] === token[key]) {
|
||||
delete mergedToken[key];
|
||||
}
|
||||
});
|
||||
return mergedToken;
|
||||
}
|
||||
export default getComponentToken;
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import type { TokenType } from '@ant-design/cssinjs';
|
||||
import type { GetDefaultToken } from './genStyleUtils';
|
||||
import type { GlobalToken, TokenMap, TokenMapKey } from '../interface';
|
||||
declare function getDefaultComponentToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>>(component: C, token: GlobalToken<CompTokenMap, AliasToken>, getDefaultToken: GetDefaultToken<CompTokenMap, AliasToken, C>): any;
|
||||
export default getDefaultComponentToken;
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import { merge as mergeToken } from "./statistic";
|
||||
function getDefaultComponentToken(component, token, getDefaultToken) {
|
||||
if (typeof getDefaultToken === 'function') {
|
||||
var _token$component;
|
||||
return getDefaultToken(mergeToken(token, (_token$component = token[component]) !== null && _token$component !== void 0 ? _token$component : {}));
|
||||
}
|
||||
return getDefaultToken !== null && getDefaultToken !== void 0 ? getDefaultToken : {};
|
||||
}
|
||||
export default getDefaultComponentToken;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
declare function genMaxMin(type: 'css' | 'js'): {
|
||||
max: (...values: number[]) => number;
|
||||
min: (...values: number[]) => number;
|
||||
} | {
|
||||
max: (...args: (string | number)[]) => string;
|
||||
min: (...args: (string | number)[]) => string;
|
||||
};
|
||||
export default genMaxMin;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { unit } from '@ant-design/cssinjs';
|
||||
function genMaxMin(type) {
|
||||
if (type === 'js') {
|
||||
return {
|
||||
max: Math.max,
|
||||
min: Math.min
|
||||
};
|
||||
}
|
||||
return {
|
||||
max: function max() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
return "max(".concat(args.map(function (value) {
|
||||
return unit(value);
|
||||
}).join(','), ")");
|
||||
},
|
||||
min: function min() {
|
||||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
||||
args[_key2] = arguments[_key2];
|
||||
}
|
||||
return "min(".concat(args.map(function (value) {
|
||||
return unit(value);
|
||||
}).join(','), ")");
|
||||
}
|
||||
};
|
||||
}
|
||||
export default genMaxMin;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import type { TokenMap } from '../interface';
|
||||
/**
|
||||
* This function will do as `Object.assign` in production. But will use Object.defineProperty:get to
|
||||
* pass all value access in development. To support statistic field usage with alias token.
|
||||
*/
|
||||
export declare function merge<CompTokenMap extends TokenMap>(...objs: Partial<CompTokenMap>[]): CompTokenMap;
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
export declare const statistic: Record<string, {
|
||||
global: string[];
|
||||
component: Record<string, string | number>;
|
||||
}>;
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
export declare const _statistic_build_: typeof statistic;
|
||||
/** Statistic token usage case. Should use `merge` function if you do not want spread record. */
|
||||
declare const statisticToken: <CompTokenMap extends TokenMap>(token: CompTokenMap) => {
|
||||
token: CompTokenMap;
|
||||
keys: Set<string>;
|
||||
flush: (componentName: string, componentToken: Record<string, string | number>) => void;
|
||||
};
|
||||
export default statisticToken;
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||||
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
||||
var enableStatistic = process.env.NODE_ENV !== 'production' || typeof CSSINJS_STATISTIC !== 'undefined';
|
||||
var recording = true;
|
||||
|
||||
/**
|
||||
* This function will do as `Object.assign` in production. But will use Object.defineProperty:get to
|
||||
* pass all value access in development. To support statistic field usage with alias token.
|
||||
*/
|
||||
export function merge() {
|
||||
for (var _len = arguments.length, objs = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
objs[_key] = arguments[_key];
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
if (!enableStatistic) {
|
||||
return Object.assign.apply(Object, [{}].concat(objs));
|
||||
}
|
||||
recording = false;
|
||||
var ret = {};
|
||||
objs.forEach(function (obj) {
|
||||
if (_typeof(obj) !== 'object') {
|
||||
return;
|
||||
}
|
||||
var keys = Object.keys(obj);
|
||||
keys.forEach(function (key) {
|
||||
Object.defineProperty(ret, key, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return obj[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
recording = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
export var statistic = {};
|
||||
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
export var _statistic_build_ = {};
|
||||
|
||||
/* istanbul ignore next */
|
||||
function noop() {}
|
||||
|
||||
/** Statistic token usage case. Should use `merge` function if you do not want spread record. */
|
||||
var statisticToken = function statisticToken(token) {
|
||||
var tokenKeys;
|
||||
var proxy = token;
|
||||
var flush = noop;
|
||||
if (enableStatistic && typeof Proxy !== 'undefined') {
|
||||
tokenKeys = new Set();
|
||||
proxy = new Proxy(token, {
|
||||
get: function get(obj, prop) {
|
||||
if (recording) {
|
||||
var _tokenKeys;
|
||||
(_tokenKeys = tokenKeys) === null || _tokenKeys === void 0 || _tokenKeys.add(prop);
|
||||
}
|
||||
return obj[prop];
|
||||
}
|
||||
});
|
||||
flush = function flush(componentName, componentToken) {
|
||||
var _statistic$componentN;
|
||||
statistic[componentName] = {
|
||||
global: Array.from(tokenKeys),
|
||||
component: _objectSpread(_objectSpread({}, (_statistic$componentN = statistic[componentName]) === null || _statistic$componentN === void 0 ? void 0 : _statistic$componentN.component), componentToken)
|
||||
};
|
||||
};
|
||||
}
|
||||
return {
|
||||
token: proxy,
|
||||
keys: tokenKeys,
|
||||
flush: flush
|
||||
};
|
||||
};
|
||||
export default statisticToken;
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
/**
|
||||
* Like `useMemo`, but this hook result will be shared across all instances.
|
||||
*/
|
||||
declare function useUniqueMemo<T>(memoFn: () => T, deps: React.DependencyList): T;
|
||||
export default useUniqueMemo;
|
||||
Generated
Vendored
+107
@@ -0,0 +1,107 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
||||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _react = _interopRequireDefault(require("react"));
|
||||
var BEAT_LIMIT = 1000 * 60 * 10;
|
||||
|
||||
/**
|
||||
* A helper class to map keys to values.
|
||||
* It supports both primitive keys and object keys.
|
||||
*/
|
||||
var ArrayKeyMap = /*#__PURE__*/function () {
|
||||
function ArrayKeyMap() {
|
||||
(0, _classCallCheck2.default)(this, ArrayKeyMap);
|
||||
(0, _defineProperty2.default)(this, "map", new Map());
|
||||
// Use WeakMap to avoid memory leak
|
||||
(0, _defineProperty2.default)(this, "objectIDMap", new WeakMap());
|
||||
(0, _defineProperty2.default)(this, "nextID", 0);
|
||||
(0, _defineProperty2.default)(this, "lastAccessBeat", new Map());
|
||||
// We will clean up the cache when reach the limit
|
||||
(0, _defineProperty2.default)(this, "accessBeat", 0);
|
||||
}
|
||||
(0, _createClass2.default)(ArrayKeyMap, [{
|
||||
key: "set",
|
||||
value: function set(keys, value) {
|
||||
// New set will trigger clear
|
||||
this.clear();
|
||||
|
||||
// Set logic
|
||||
var compositeKey = this.getCompositeKey(keys);
|
||||
this.map.set(compositeKey, value);
|
||||
this.lastAccessBeat.set(compositeKey, Date.now());
|
||||
}
|
||||
}, {
|
||||
key: "get",
|
||||
value: function get(keys) {
|
||||
var compositeKey = this.getCompositeKey(keys);
|
||||
var cache = this.map.get(compositeKey);
|
||||
this.lastAccessBeat.set(compositeKey, Date.now());
|
||||
this.accessBeat += 1;
|
||||
return cache;
|
||||
}
|
||||
}, {
|
||||
key: "getCompositeKey",
|
||||
value: function getCompositeKey(keys) {
|
||||
var _this = this;
|
||||
var ids = keys.map(function (key) {
|
||||
if (key && (0, _typeof2.default)(key) === 'object') {
|
||||
return "obj_".concat(_this.getObjectID(key));
|
||||
}
|
||||
return "".concat((0, _typeof2.default)(key), "_").concat(key);
|
||||
});
|
||||
return ids.join('|');
|
||||
}
|
||||
}, {
|
||||
key: "getObjectID",
|
||||
value: function getObjectID(obj) {
|
||||
if (this.objectIDMap.has(obj)) {
|
||||
return this.objectIDMap.get(obj);
|
||||
}
|
||||
var id = this.nextID;
|
||||
this.objectIDMap.set(obj, id);
|
||||
this.nextID += 1;
|
||||
return id;
|
||||
}
|
||||
}, {
|
||||
key: "clear",
|
||||
value: function clear() {
|
||||
var _this2 = this;
|
||||
if (this.accessBeat > 10000) {
|
||||
var now = Date.now();
|
||||
this.lastAccessBeat.forEach(function (beat, key) {
|
||||
if (now - beat > BEAT_LIMIT) {
|
||||
_this2.map.delete(key);
|
||||
_this2.lastAccessBeat.delete(key);
|
||||
}
|
||||
});
|
||||
this.accessBeat = 0;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
return ArrayKeyMap;
|
||||
}();
|
||||
var uniqueMap = new ArrayKeyMap();
|
||||
|
||||
/**
|
||||
* Like `useMemo`, but this hook result will be shared across all instances.
|
||||
*/
|
||||
function useUniqueMemo(memoFn, deps) {
|
||||
return _react.default.useMemo(function () {
|
||||
var cachedValue = uniqueMap.get(deps);
|
||||
if (cachedValue) {
|
||||
return cachedValue;
|
||||
}
|
||||
var newValue = memoFn();
|
||||
uniqueMap.set(deps, newValue);
|
||||
return newValue;
|
||||
}, deps);
|
||||
}
|
||||
var _default = exports.default = useUniqueMemo;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export type UseCSP = () => {
|
||||
nonce?: string;
|
||||
};
|
||||
/**
|
||||
* Provide a default hook since not everyone needs to config this.
|
||||
*/
|
||||
declare const useDefaultCSP: UseCSP;
|
||||
export default useDefaultCSP;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
/**
|
||||
* Provide a default hook since not everyone needs to config this.
|
||||
*/
|
||||
var useDefaultCSP = function useDefaultCSP() {
|
||||
return {};
|
||||
};
|
||||
var _default = exports.default = useDefaultCSP;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export type UsePrefix = () => {
|
||||
/**
|
||||
* All the component use `@ant-design/cssinjs-utils` should have same `rootPrefixCls`.
|
||||
*/
|
||||
rootPrefixCls: string;
|
||||
/**
|
||||
* `iconPrefixCls` comes from the setting of `@ant-design/icons`.
|
||||
* Here maybe little coupling but everyone need use this.
|
||||
*/
|
||||
iconPrefixCls: string;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import type { Theme, TokenType } from '@ant-design/cssinjs';
|
||||
import type { OverrideTokenMap, TokenMap, GlobalToken } from '../interface';
|
||||
export type TokenMapWithTheme<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType> = {
|
||||
[key in keyof OverrideTokenMap<CompTokenMap, AliasToken>]?: OverrideTokenMap<CompTokenMap, AliasToken>[key] & {
|
||||
theme?: Theme<DesignToken, AliasToken>;
|
||||
};
|
||||
};
|
||||
export interface UseTokenReturn<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType> {
|
||||
token: GlobalToken<CompTokenMap, AliasToken>;
|
||||
realToken?: GlobalToken<CompTokenMap, AliasToken>;
|
||||
theme?: Theme<DesignToken, AliasToken>;
|
||||
components?: TokenMapWithTheme<CompTokenMap, DesignToken, AliasToken>;
|
||||
hashId?: string;
|
||||
hashed?: string | boolean;
|
||||
cssVar?: {
|
||||
prefix?: string;
|
||||
key?: string;
|
||||
};
|
||||
zeroRuntime?: boolean;
|
||||
}
|
||||
export type UseToken<CompTokenMap extends TokenMap, DesignToken extends TokenType, AliasToken extends TokenType> = () => UseTokenReturn<CompTokenMap, DesignToken, AliasToken>;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
export { default as genStyleUtils } from './util/genStyleUtils';
|
||||
export { default as genCalc } from './util/calc';
|
||||
export { default as statisticToken, merge as mergeToken, statistic } from './util/statistic';
|
||||
export type { OverrideTokenMap, TokenMap, TokenMapKey, GlobalTokenWithComponent, ComponentToken, ComponentTokenKey, GlobalToken, } from './interface';
|
||||
export type { default as AbstractCalculator } from './util/calc/calculator';
|
||||
export type { FullToken, GetDefaultToken, GetDefaultTokenFn, GenStyleFn, TokenWithCommonCls, CSSUtil, } from './util/genStyleUtils';
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "genCalc", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _calc.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "genStyleUtils", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _genStyleUtils.default;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "mergeToken", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _statistic.merge;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "statistic", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _statistic.statistic;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "statisticToken", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _statistic.default;
|
||||
}
|
||||
});
|
||||
var _genStyleUtils = _interopRequireDefault(require("./util/genStyleUtils"));
|
||||
var _calc = _interopRequireDefault(require("./util/calc"));
|
||||
var _statistic = _interopRequireWildcard(require("./util/statistic"));
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import type { TokenType } from '@ant-design/cssinjs';
|
||||
export type TokenMap = Record<PropertyKey, any>;
|
||||
export type TokenMapKey<CompTokenMap extends TokenMap> = Extract<keyof CompTokenMap, string>;
|
||||
export type GlobalToken<CompTokenMap extends TokenMap, AliasToken extends TokenType> = AliasToken & CompTokenMap;
|
||||
export type OverrideTokenMap<CompTokenMap extends TokenMap, AliasToken extends TokenType> = {
|
||||
[key in keyof CompTokenMap]: Partial<CompTokenMap[key]> & Partial<AliasToken>;
|
||||
};
|
||||
export type GlobalTokenWithComponent<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = GlobalToken<CompTokenMap, AliasToken> & CompTokenMap[C];
|
||||
export type ComponentToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = Exclude<OverrideTokenMap<CompTokenMap, AliasToken>[C], undefined>;
|
||||
export type ComponentTokenKey<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = keyof ComponentToken<CompTokenMap, AliasToken, C>;
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
export type { OverrideTokenMap, TokenMap, TokenMapKey, GlobalTokenWithComponent, ComponentToken, ComponentTokenKey, GlobalToken, } from './components';
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import AbstractCalculator from './calculator';
|
||||
export default class CSSCalculator extends AbstractCalculator {
|
||||
result: string;
|
||||
unitlessCssVar: Set<string>;
|
||||
lowPriority?: boolean;
|
||||
constructor(num: number | string | AbstractCalculator, unitlessCssVar: Set<string>);
|
||||
add(num: number | string | AbstractCalculator): this;
|
||||
sub(num: number | string | AbstractCalculator): this;
|
||||
mul(num: number | string | AbstractCalculator): this;
|
||||
div(num: number | string | AbstractCalculator): this;
|
||||
getResult(force?: boolean): string;
|
||||
equal(options?: {
|
||||
unit?: boolean;
|
||||
}): string;
|
||||
}
|
||||
Generated
Vendored
+122
@@ -0,0 +1,122 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
||||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
||||
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
||||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
||||
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _calculator = _interopRequireDefault(require("./calculator"));
|
||||
var CALC_UNIT = 'CALC_UNIT';
|
||||
var regexp = new RegExp(CALC_UNIT, 'g');
|
||||
function unit(value) {
|
||||
if (typeof value === 'number') {
|
||||
return "".concat(value).concat(CALC_UNIT);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
var CSSCalculator = exports.default = /*#__PURE__*/function (_AbstractCalculator) {
|
||||
(0, _inherits2.default)(CSSCalculator, _AbstractCalculator);
|
||||
var _super = (0, _createSuper2.default)(CSSCalculator);
|
||||
function CSSCalculator(num, unitlessCssVar) {
|
||||
var _this;
|
||||
(0, _classCallCheck2.default)(this, CSSCalculator);
|
||||
_this = _super.call(this);
|
||||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "result", '');
|
||||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "unitlessCssVar", void 0);
|
||||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "lowPriority", void 0);
|
||||
var numType = (0, _typeof2.default)(num);
|
||||
_this.unitlessCssVar = unitlessCssVar;
|
||||
if (num instanceof CSSCalculator) {
|
||||
_this.result = "(".concat(num.result, ")");
|
||||
} else if (numType === 'number') {
|
||||
_this.result = unit(num);
|
||||
} else if (numType === 'string') {
|
||||
_this.result = num;
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
(0, _createClass2.default)(CSSCalculator, [{
|
||||
key: "add",
|
||||
value: function add(num) {
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " + ").concat(num.getResult());
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " + ").concat(unit(num));
|
||||
}
|
||||
this.lowPriority = true;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "sub",
|
||||
value: function sub(num) {
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " - ").concat(num.getResult());
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " - ").concat(unit(num));
|
||||
}
|
||||
this.lowPriority = true;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "mul",
|
||||
value: function mul(num) {
|
||||
if (this.lowPriority) {
|
||||
this.result = "(".concat(this.result, ")");
|
||||
}
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " * ").concat(num.getResult(true));
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " * ").concat(num);
|
||||
}
|
||||
this.lowPriority = false;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "div",
|
||||
value: function div(num) {
|
||||
if (this.lowPriority) {
|
||||
this.result = "(".concat(this.result, ")");
|
||||
}
|
||||
if (num instanceof CSSCalculator) {
|
||||
this.result = "".concat(this.result, " / ").concat(num.getResult(true));
|
||||
} else if (typeof num === 'number' || typeof num === 'string') {
|
||||
this.result = "".concat(this.result, " / ").concat(num);
|
||||
}
|
||||
this.lowPriority = false;
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "getResult",
|
||||
value: function getResult(force) {
|
||||
return this.lowPriority || force ? "(".concat(this.result, ")") : this.result;
|
||||
}
|
||||
}, {
|
||||
key: "equal",
|
||||
value: function equal(options) {
|
||||
var _this2 = this;
|
||||
var _ref = options || {},
|
||||
cssUnit = _ref.unit;
|
||||
var mergedUnit = true;
|
||||
if (typeof cssUnit === 'boolean') {
|
||||
mergedUnit = cssUnit;
|
||||
} else if (Array.from(this.unitlessCssVar).some(function (cssVar) {
|
||||
return _this2.result.includes(cssVar);
|
||||
})) {
|
||||
mergedUnit = false;
|
||||
}
|
||||
this.result = this.result.replace(regexp, mergedUnit ? 'px' : '');
|
||||
if (typeof this.lowPriority !== 'undefined') {
|
||||
return "calc(".concat(this.result, ")");
|
||||
}
|
||||
return this.result;
|
||||
}
|
||||
}]);
|
||||
return CSSCalculator;
|
||||
}(_calculator.default);
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import AbstractCalculator from './calculator';
|
||||
declare class NumCalculator extends AbstractCalculator {
|
||||
result: number;
|
||||
constructor(num: number | string | AbstractCalculator);
|
||||
add(num: number | string | AbstractCalculator): this;
|
||||
sub(num: number | string | AbstractCalculator): this;
|
||||
mul(num: number | string | AbstractCalculator): this;
|
||||
div(num: number | string | AbstractCalculator): this;
|
||||
equal(): number;
|
||||
}
|
||||
export default NumCalculator;
|
||||
Generated
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
||||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
||||
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
||||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
||||
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _calculator = _interopRequireDefault(require("./calculator"));
|
||||
var NumCalculator = /*#__PURE__*/function (_AbstractCalculator) {
|
||||
(0, _inherits2.default)(NumCalculator, _AbstractCalculator);
|
||||
var _super = (0, _createSuper2.default)(NumCalculator);
|
||||
function NumCalculator(num) {
|
||||
var _this;
|
||||
(0, _classCallCheck2.default)(this, NumCalculator);
|
||||
_this = _super.call(this);
|
||||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "result", 0);
|
||||
if (num instanceof NumCalculator) {
|
||||
_this.result = num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
_this.result = num;
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
(0, _createClass2.default)(NumCalculator, [{
|
||||
key: "add",
|
||||
value: function add(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result += num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result += num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "sub",
|
||||
value: function sub(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result -= num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result -= num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "mul",
|
||||
value: function mul(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result *= num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result *= num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "div",
|
||||
value: function div(num) {
|
||||
if (num instanceof NumCalculator) {
|
||||
this.result /= num.result;
|
||||
} else if (typeof num === 'number') {
|
||||
this.result /= num;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "equal",
|
||||
value: function equal() {
|
||||
return this.result;
|
||||
}
|
||||
}]);
|
||||
return NumCalculator;
|
||||
}(_calculator.default);
|
||||
var _default = exports.default = NumCalculator;
|
||||
Generated
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
declare abstract class AbstractCalculator {
|
||||
/**
|
||||
* @descCN 计算两数的和,例如:1 + 2
|
||||
* @descEN Calculate the sum of two numbers, e.g. 1 + 2
|
||||
*/
|
||||
abstract add(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 计算两数的差,例如:1 - 2
|
||||
* @descEN Calculate the difference between two numbers, e.g. 1 - 2
|
||||
*/
|
||||
abstract sub(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 计算两数的积,例如:1 * 2
|
||||
* @descEN Calculate the product of two numbers, e.g. 1 * 2
|
||||
*/
|
||||
abstract mul(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 计算两数的商,例如:1 / 2
|
||||
* @descEN Calculate the quotient of two numbers, e.g. 1 / 2
|
||||
*/
|
||||
abstract div(num: number | string | AbstractCalculator): this;
|
||||
/**
|
||||
* @descCN 获取计算结果
|
||||
* @descEN Get the calculation result
|
||||
*/
|
||||
abstract equal(options?: {
|
||||
unit?: boolean;
|
||||
}): string | number;
|
||||
}
|
||||
export default AbstractCalculator;
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
||||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
||||
var AbstractCalculator = /*#__PURE__*/(0, _createClass2.default)(function AbstractCalculator() {
|
||||
(0, _classCallCheck2.default)(this, AbstractCalculator);
|
||||
});
|
||||
var _default = exports.default = AbstractCalculator;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type AbstractCalculator from './calculator';
|
||||
import CSSCalculator from './CSSCalculator';
|
||||
import NumCalculator from './NumCalculator';
|
||||
declare const genCalc: (type: 'css' | 'js', unitlessCssVar: Set<string>) => (num: number | string | AbstractCalculator) => CSSCalculator | NumCalculator;
|
||||
export default genCalc;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _CSSCalculator = _interopRequireDefault(require("./CSSCalculator"));
|
||||
var _NumCalculator = _interopRequireDefault(require("./NumCalculator"));
|
||||
var genCalc = function genCalc(type, unitlessCssVar) {
|
||||
var Calculator = type === 'css' ? _CSSCalculator.default : _NumCalculator.default;
|
||||
return function (num) {
|
||||
return new Calculator(num, unitlessCssVar);
|
||||
};
|
||||
};
|
||||
var _default = exports.default = genCalc;
|
||||
Generated
Vendored
+140
@@ -0,0 +1,140 @@
|
||||
import type React from 'react';
|
||||
import type { CSSInterpolation, CSSObject, TokenType } from '@ant-design/cssinjs';
|
||||
import { useStyleRegister } from '@ant-design/cssinjs';
|
||||
import type { ComponentTokenKey, GlobalTokenWithComponent, TokenMap, TokenMapKey } from '../interface';
|
||||
import type AbstractCalculator from './calc/calculator';
|
||||
import type { UseCSP } from '../hooks/useCSP';
|
||||
import type { UsePrefix } from '../hooks/usePrefix';
|
||||
import type { UseToken } from '../hooks/useToken';
|
||||
type LayerConfig = Parameters<typeof useStyleRegister>[0]['layer'];
|
||||
export interface StyleInfo {
|
||||
hashId: string;
|
||||
prefixCls: string;
|
||||
rootPrefixCls: string;
|
||||
iconPrefixCls: string;
|
||||
}
|
||||
export type CSSUtil = {
|
||||
calc: (number: any) => AbstractCalculator;
|
||||
max: (...values: (number | string)[]) => number | string;
|
||||
min: (...values: (number | string)[]) => number | string;
|
||||
};
|
||||
export type TokenWithCommonCls<T> = T & {
|
||||
/** Wrap component class with `.` prefix */
|
||||
componentCls: string;
|
||||
/** Origin prefix which do not have `.` prefix */
|
||||
prefixCls: string;
|
||||
/** Wrap icon class with `.` prefix */
|
||||
iconCls: string;
|
||||
/** Wrap ant prefixCls class with `.` prefix */
|
||||
antCls: string;
|
||||
} & CSSUtil;
|
||||
export type FullToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = TokenWithCommonCls<GlobalTokenWithComponent<CompTokenMap, AliasToken, C>>;
|
||||
export type GenStyleFn<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = (token: FullToken<CompTokenMap, AliasToken, C>, info: StyleInfo) => CSSInterpolation;
|
||||
export type GetDefaultTokenFn<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = (token: AliasToken & Partial<CompTokenMap[C]>) => CompTokenMap[C];
|
||||
export type GetDefaultToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>> = null | CompTokenMap[C] | GetDefaultTokenFn<CompTokenMap, AliasToken, C>;
|
||||
export interface SubStyleComponentProps {
|
||||
prefixCls: string;
|
||||
rootCls?: string;
|
||||
}
|
||||
export type CSSVarRegisterProps = {
|
||||
rootCls: string;
|
||||
component: string;
|
||||
cssVar: {
|
||||
prefix?: string;
|
||||
key?: string;
|
||||
};
|
||||
};
|
||||
type GetResetStylesConfig = {
|
||||
prefix: ReturnType<UsePrefix>;
|
||||
csp: ReturnType<UseCSP>;
|
||||
};
|
||||
export type GetResetStyles<AliasToken extends TokenType> = (token: AliasToken, config?: GetResetStylesConfig) => CSSInterpolation;
|
||||
export type GetCompUnitless<CompTokenMap extends TokenMap, AliasToken extends TokenType> = <C extends TokenMapKey<CompTokenMap>>(component: C | [C, string]) => Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
|
||||
declare function genStyleUtils<CompTokenMap extends TokenMap, AliasToken extends TokenType, DesignToken extends TokenType>(config: {
|
||||
usePrefix: UsePrefix;
|
||||
useToken: UseToken<CompTokenMap, AliasToken, DesignToken>;
|
||||
useCSP?: UseCSP;
|
||||
getResetStyles?: GetResetStyles<AliasToken>;
|
||||
getCommonStyle?: (token: AliasToken, componentPrefixCls: string, rootCls?: string, resetFont?: boolean) => CSSObject;
|
||||
getCompUnitless?: GetCompUnitless<CompTokenMap, AliasToken>;
|
||||
layer?: LayerConfig;
|
||||
}): {
|
||||
genStyleHooks: <C extends TokenMapKey<CompTokenMap>>(component: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
|
||||
resetStyle?: boolean;
|
||||
resetFont?: boolean;
|
||||
deprecatedTokens?: [
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>,
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>
|
||||
][];
|
||||
/**
|
||||
* Component tokens that do not need unit.
|
||||
*/
|
||||
unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
|
||||
/**
|
||||
* Only use component style in client side. Ignore in SSR.
|
||||
*/
|
||||
clientOnly?: boolean;
|
||||
/**
|
||||
* Set order of component style.
|
||||
* @default -999
|
||||
*/
|
||||
order?: number;
|
||||
/**
|
||||
* Whether generate styles
|
||||
* @default true
|
||||
*/
|
||||
injectStyle?: boolean;
|
||||
/**
|
||||
* Extra prefixCls to inject CSS variables.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* {
|
||||
* extraCssVarPrefixCls: ['my-comp-compact', 'my-comp-large']
|
||||
* }
|
||||
* // or
|
||||
* {
|
||||
* extraCssVarPrefixCls: ({ prefixCls, rootCls }) => [`${prefixCls}-container`]
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
extraCssVarPrefixCls?: string[] | ((info: {
|
||||
prefixCls: string;
|
||||
rootCls: string;
|
||||
}) => string[]);
|
||||
}) => (prefixCls: string, rootCls?: string) => readonly [string, string];
|
||||
genSubStyleComponent: <C extends TokenMapKey<CompTokenMap>>(componentName: C | [C, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C>, options?: {
|
||||
resetStyle?: boolean;
|
||||
resetFont?: boolean;
|
||||
deprecatedTokens?: [
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>,
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>
|
||||
][];
|
||||
/**
|
||||
* Only use component style in client side. Ignore in SSR.
|
||||
*/
|
||||
clientOnly?: boolean;
|
||||
/**
|
||||
* Set order of component style. Default is -999.
|
||||
*/
|
||||
order?: number;
|
||||
injectStyle?: boolean;
|
||||
unitless?: Partial<Record<ComponentTokenKey<CompTokenMap, AliasToken, C>, boolean>>;
|
||||
}) => React.FunctionComponent<SubStyleComponentProps>;
|
||||
genComponentStyleHook: <C_1 extends TokenMapKey<CompTokenMap>>(componentName: C_1 | [C_1, string], styleFn: GenStyleFn<CompTokenMap, AliasToken, C_1>, getDefaultToken?: GetDefaultToken<CompTokenMap, AliasToken, C_1>, options?: {
|
||||
resetStyle?: boolean;
|
||||
resetFont?: boolean;
|
||||
deprecatedTokens?: [keyof Exclude<import("../interface/components").OverrideTokenMap<CompTokenMap, AliasToken>[C_1], undefined>, keyof Exclude<import("../interface/components").OverrideTokenMap<CompTokenMap, AliasToken>[C_1], undefined>][];
|
||||
/**
|
||||
* Only use component style in client side. Ignore in SSR.
|
||||
*/
|
||||
clientOnly?: boolean;
|
||||
/**
|
||||
* Set order of component style. Default is -999.
|
||||
*/
|
||||
order?: number;
|
||||
injectStyle?: boolean;
|
||||
unitless?: Partial<Record<keyof Exclude<import("../interface/components").OverrideTokenMap<CompTokenMap, AliasToken>[C_1], undefined>, boolean>>;
|
||||
}) => (prefixCls: string, rootCls?: string) => string;
|
||||
};
|
||||
export default genStyleUtils;
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
||||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
||||
var _react = require("react");
|
||||
var _cssinjs = require("@ant-design/cssinjs");
|
||||
var _calc = _interopRequireDefault(require("./calc"));
|
||||
var _getCompVarPrefix = _interopRequireDefault(require("./getCompVarPrefix"));
|
||||
var _getComponentToken = _interopRequireDefault(require("./getComponentToken"));
|
||||
var _getDefaultComponentToken = _interopRequireDefault(require("./getDefaultComponentToken"));
|
||||
var _maxmin = _interopRequireDefault(require("./maxmin"));
|
||||
var _statistic = _interopRequireWildcard(require("./statistic"));
|
||||
var _useUniqueMemo = _interopRequireDefault(require("../_util/hooks/useUniqueMemo"));
|
||||
var _useCSP = _interopRequireDefault(require("../hooks/useCSP"));
|
||||
function genStyleUtils(config) {
|
||||
// Dependency inversion for preparing basic config.
|
||||
var _config$useCSP = config.useCSP,
|
||||
useCSP = _config$useCSP === void 0 ? _useCSP.default : _config$useCSP,
|
||||
useToken = config.useToken,
|
||||
usePrefix = config.usePrefix,
|
||||
getResetStyles = config.getResetStyles,
|
||||
getCommonStyle = config.getCommonStyle,
|
||||
getCompUnitless = config.getCompUnitless;
|
||||
function genStyleHooks(component, styleFn, getDefaultToken, options) {
|
||||
var componentName = Array.isArray(component) ? component[0] : component;
|
||||
function prefixToken(key) {
|
||||
return "".concat(String(componentName)).concat(key.slice(0, 1).toUpperCase()).concat(key.slice(1));
|
||||
}
|
||||
|
||||
// Fill unitless
|
||||
var originUnitless = (options === null || options === void 0 ? void 0 : options.unitless) || {};
|
||||
var originCompUnitless = typeof getCompUnitless === 'function' ? getCompUnitless(component) : {};
|
||||
var compUnitless = (0, _objectSpread3.default)((0, _objectSpread3.default)({}, originCompUnitless), {}, (0, _defineProperty2.default)({}, prefixToken('zIndexPopup'), true));
|
||||
Object.keys(originUnitless).forEach(function (key) {
|
||||
compUnitless[prefixToken(key)] = originUnitless[key];
|
||||
});
|
||||
|
||||
// Options
|
||||
var mergedOptions = (0, _objectSpread3.default)((0, _objectSpread3.default)({}, options), {}, {
|
||||
unitless: compUnitless,
|
||||
prefixToken: prefixToken
|
||||
});
|
||||
|
||||
// Hooks
|
||||
var useStyle = genComponentStyleHook(component, styleFn, getDefaultToken, mergedOptions);
|
||||
var useCSSVar = genCSSVarRegister(componentName, getDefaultToken, mergedOptions);
|
||||
return function (prefixCls) {
|
||||
var rootCls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prefixCls;
|
||||
var hashId = useStyle(prefixCls, rootCls);
|
||||
|
||||
// Resolve function type to get dynamic extra prefix
|
||||
var extraPrefixCls = options === null || options === void 0 ? void 0 : options.extraCssVarPrefixCls;
|
||||
var resolvedExtraPrefixCls = typeof extraPrefixCls === 'function' ? extraPrefixCls({
|
||||
prefixCls: prefixCls,
|
||||
rootCls: rootCls
|
||||
}) : extraPrefixCls;
|
||||
var cssVarCls = useCSSVar(resolvedExtraPrefixCls !== null && resolvedExtraPrefixCls !== void 0 && resolvedExtraPrefixCls.length ? [rootCls].concat((0, _toConsumableArray2.default)(resolvedExtraPrefixCls)) : rootCls);
|
||||
return [hashId, cssVarCls];
|
||||
};
|
||||
}
|
||||
function genCSSVarRegister(component, getDefaultToken, options) {
|
||||
var compUnitless = options.unitless,
|
||||
prefixToken = options.prefixToken,
|
||||
ignore = options.ignore;
|
||||
return function (rootCls) {
|
||||
var _useToken = useToken(),
|
||||
cssVar = _useToken.cssVar,
|
||||
realToken = _useToken.realToken;
|
||||
var csp = useCSP();
|
||||
(0, _cssinjs.useCSSVarRegister)({
|
||||
path: [component],
|
||||
prefix: cssVar.prefix,
|
||||
key: cssVar.key,
|
||||
unitless: compUnitless,
|
||||
ignore: ignore,
|
||||
token: realToken,
|
||||
scope: rootCls,
|
||||
nonce: function nonce() {
|
||||
return csp.nonce;
|
||||
}
|
||||
}, function () {
|
||||
var defaultToken = (0, _getDefaultComponentToken.default)(component, realToken, getDefaultToken);
|
||||
var componentToken = (0, _getComponentToken.default)(component, realToken, defaultToken, {
|
||||
deprecatedTokens: options === null || options === void 0 ? void 0 : options.deprecatedTokens
|
||||
});
|
||||
if (defaultToken) {
|
||||
Object.keys(defaultToken).forEach(function (key) {
|
||||
componentToken[prefixToken(key)] = componentToken[key];
|
||||
delete componentToken[key];
|
||||
});
|
||||
}
|
||||
return componentToken;
|
||||
});
|
||||
return cssVar === null || cssVar === void 0 ? void 0 : cssVar.key;
|
||||
};
|
||||
}
|
||||
function genComponentStyleHook(componentName, styleFn, getDefaultToken) {
|
||||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
||||
var cells = Array.isArray(componentName) ? componentName : [componentName, componentName];
|
||||
var _cells = (0, _slicedToArray2.default)(cells, 1),
|
||||
component = _cells[0];
|
||||
var concatComponent = cells.join('-');
|
||||
var mergedLayer = config.layer || {
|
||||
name: 'antd'
|
||||
};
|
||||
|
||||
// Return new style hook
|
||||
return function (prefixCls) {
|
||||
var rootCls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : prefixCls;
|
||||
var _useToken2 = useToken(),
|
||||
theme = _useToken2.theme,
|
||||
realToken = _useToken2.realToken,
|
||||
hashId = _useToken2.hashId,
|
||||
token = _useToken2.token,
|
||||
cssVar = _useToken2.cssVar,
|
||||
zeroRuntime = _useToken2.zeroRuntime;
|
||||
|
||||
// Update of `disabledRuntimeStyle` would cause React hook error, so memoized it and never update.
|
||||
var memoizedZeroRuntime = (0, _react.useMemo)(function () {
|
||||
return zeroRuntime;
|
||||
}, []);
|
||||
if (memoizedZeroRuntime) {
|
||||
return hashId;
|
||||
}
|
||||
var _usePrefix = usePrefix(),
|
||||
rootPrefixCls = _usePrefix.rootPrefixCls,
|
||||
iconPrefixCls = _usePrefix.iconPrefixCls;
|
||||
var csp = useCSP();
|
||||
var type = 'css';
|
||||
|
||||
// Use unique memo to share the result across all instances
|
||||
var calc = (0, _useUniqueMemo.default)(function () {
|
||||
var unitlessCssVar = new Set();
|
||||
Object.keys(options.unitless || {}).forEach(function (key) {
|
||||
// Some component proxy the AliasToken (e.g. Image) and some not (e.g. Modal)
|
||||
// We should both pass in `unitlessCssVar` to make sure the CSSVar can be unitless.
|
||||
unitlessCssVar.add((0, _cssinjs.token2CSSVar)(key, cssVar.prefix));
|
||||
unitlessCssVar.add((0, _cssinjs.token2CSSVar)(key, (0, _getCompVarPrefix.default)(component, cssVar.prefix)));
|
||||
});
|
||||
return (0, _calc.default)(type, unitlessCssVar);
|
||||
}, [type, component, cssVar === null || cssVar === void 0 ? void 0 : cssVar.prefix]);
|
||||
var _genMaxMin = (0, _maxmin.default)(type),
|
||||
max = _genMaxMin.max,
|
||||
min = _genMaxMin.min;
|
||||
|
||||
// Shared config
|
||||
var sharedConfig = {
|
||||
theme: theme,
|
||||
token: token,
|
||||
hashId: hashId,
|
||||
nonce: function nonce() {
|
||||
return csp.nonce;
|
||||
},
|
||||
clientOnly: options.clientOnly,
|
||||
layer: mergedLayer,
|
||||
// antd is always at top of styles
|
||||
order: options.order || -999
|
||||
};
|
||||
|
||||
// This if statement is safe, as it will only be used if the generator has the function. It's not dynamic.
|
||||
if (typeof getResetStyles === 'function') {
|
||||
// Generate style for all need reset tags.
|
||||
(0, _cssinjs.useStyleRegister)((0, _objectSpread3.default)((0, _objectSpread3.default)({}, sharedConfig), {}, {
|
||||
clientOnly: false,
|
||||
path: ['Shared', rootPrefixCls]
|
||||
}), function () {
|
||||
return getResetStyles(token, {
|
||||
prefix: {
|
||||
rootPrefixCls: rootPrefixCls,
|
||||
iconPrefixCls: iconPrefixCls
|
||||
},
|
||||
csp: csp
|
||||
});
|
||||
});
|
||||
}
|
||||
(0, _cssinjs.useStyleRegister)((0, _objectSpread3.default)((0, _objectSpread3.default)({}, sharedConfig), {}, {
|
||||
path: [concatComponent, prefixCls, iconPrefixCls]
|
||||
}), function () {
|
||||
if (options.injectStyle === false) {
|
||||
return [];
|
||||
}
|
||||
var _statisticToken = (0, _statistic.default)(token),
|
||||
proxyToken = _statisticToken.token,
|
||||
flush = _statisticToken.flush;
|
||||
var defaultComponentToken = (0, _getDefaultComponentToken.default)(component, realToken, getDefaultToken);
|
||||
var componentCls = ".".concat(prefixCls);
|
||||
var componentToken = (0, _getComponentToken.default)(component, realToken, defaultComponentToken, {
|
||||
deprecatedTokens: options.deprecatedTokens
|
||||
});
|
||||
if (defaultComponentToken && (0, _typeof2.default)(defaultComponentToken) === 'object') {
|
||||
Object.keys(defaultComponentToken).forEach(function (key) {
|
||||
defaultComponentToken[key] = "var(".concat((0, _cssinjs.token2CSSVar)(key, (0, _getCompVarPrefix.default)(component, cssVar.prefix)), ")");
|
||||
});
|
||||
}
|
||||
var mergedToken = (0, _statistic.merge)(proxyToken, {
|
||||
componentCls: componentCls,
|
||||
prefixCls: prefixCls,
|
||||
iconCls: ".".concat(iconPrefixCls),
|
||||
antCls: ".".concat(rootPrefixCls),
|
||||
calc: calc,
|
||||
max: max,
|
||||
min: min
|
||||
}, defaultComponentToken);
|
||||
var styleInterpolation = styleFn(mergedToken, {
|
||||
hashId: hashId,
|
||||
prefixCls: prefixCls,
|
||||
rootPrefixCls: rootPrefixCls,
|
||||
iconPrefixCls: iconPrefixCls
|
||||
});
|
||||
flush(component, componentToken);
|
||||
var commonStyle = typeof getCommonStyle === 'function' ? getCommonStyle(mergedToken, prefixCls, rootCls, options.resetFont) : null;
|
||||
return [options.resetStyle === false ? null : commonStyle, styleInterpolation];
|
||||
});
|
||||
return hashId;
|
||||
};
|
||||
}
|
||||
function genSubStyleComponent(componentName, styleFn, getDefaultToken) {
|
||||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
||||
var useStyle = genComponentStyleHook(componentName, styleFn, getDefaultToken, (0, _objectSpread3.default)({
|
||||
resetStyle: false,
|
||||
// Sub Style should default after root one
|
||||
order: -998
|
||||
}, options));
|
||||
var StyledComponent = function StyledComponent(_ref) {
|
||||
var prefixCls = _ref.prefixCls,
|
||||
_ref$rootCls = _ref.rootCls,
|
||||
rootCls = _ref$rootCls === void 0 ? prefixCls : _ref$rootCls;
|
||||
useStyle(prefixCls, rootCls);
|
||||
return null;
|
||||
};
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
StyledComponent.displayName = "SubStyle_".concat(String(Array.isArray(componentName) ? componentName.join('.') : componentName));
|
||||
}
|
||||
return StyledComponent;
|
||||
}
|
||||
return {
|
||||
genStyleHooks: genStyleHooks,
|
||||
genSubStyleComponent: genSubStyleComponent,
|
||||
genComponentStyleHook: genComponentStyleHook
|
||||
};
|
||||
}
|
||||
var _default = exports.default = genStyleUtils;
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
declare const getCompVarPrefix: (component: string, prefix?: string) => string;
|
||||
export default getCompVarPrefix;
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var getCompVarPrefix = function getCompVarPrefix(component, prefix) {
|
||||
return "".concat([prefix, component.replace(/([A-Z]+)([A-Z][a-z]+)/g, '$1-$2').replace(/([a-z])([A-Z])/g, '$1-$2')].filter(Boolean).join('-'));
|
||||
};
|
||||
var _default = exports.default = getCompVarPrefix;
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import type { TokenMap, TokenMapKey, ComponentTokenKey, GlobalToken } from '../interface';
|
||||
import type { TokenType } from '@ant-design/cssinjs';
|
||||
declare function getComponentToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>>(component: C, token: GlobalToken<CompTokenMap, AliasToken>, defaultToken: CompTokenMap[C], options?: {
|
||||
deprecatedTokens?: [
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>,
|
||||
ComponentTokenKey<CompTokenMap, AliasToken, C>
|
||||
][];
|
||||
}): any;
|
||||
export default getComponentToken;
|
||||
Generated
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
||||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
||||
var _util = require("@rc-component/util");
|
||||
function getComponentToken(component, token, defaultToken, options) {
|
||||
var customToken = (0, _objectSpread2.default)({}, token[component]);
|
||||
if (options !== null && options !== void 0 && options.deprecatedTokens) {
|
||||
var deprecatedTokens = options.deprecatedTokens;
|
||||
deprecatedTokens.forEach(function (_ref) {
|
||||
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
||||
oldTokenKey = _ref2[0],
|
||||
newTokenKey = _ref2[1];
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
(0, _util.warning)(!(customToken !== null && customToken !== void 0 && customToken[oldTokenKey]), "Component Token `".concat(String(oldTokenKey), "` of ").concat(String(component), " is deprecated. Please use `").concat(String(newTokenKey), "` instead."));
|
||||
}
|
||||
|
||||
// Should wrap with `if` clause, or there will be `undefined` in object.
|
||||
if (customToken !== null && customToken !== void 0 && customToken[oldTokenKey] || customToken !== null && customToken !== void 0 && customToken[newTokenKey]) {
|
||||
var _customToken$newToken;
|
||||
(_customToken$newToken = customToken[newTokenKey]) !== null && _customToken$newToken !== void 0 ? _customToken$newToken : customToken[newTokenKey] = customToken === null || customToken === void 0 ? void 0 : customToken[oldTokenKey];
|
||||
}
|
||||
});
|
||||
}
|
||||
var mergedToken = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultToken), customToken);
|
||||
|
||||
// Remove same value as global token to minimize size
|
||||
Object.keys(mergedToken).forEach(function (key) {
|
||||
if (mergedToken[key] === token[key]) {
|
||||
delete mergedToken[key];
|
||||
}
|
||||
});
|
||||
return mergedToken;
|
||||
}
|
||||
var _default = exports.default = getComponentToken;
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import type { TokenType } from '@ant-design/cssinjs';
|
||||
import type { GetDefaultToken } from './genStyleUtils';
|
||||
import type { GlobalToken, TokenMap, TokenMapKey } from '../interface';
|
||||
declare function getDefaultComponentToken<CompTokenMap extends TokenMap, AliasToken extends TokenType, C extends TokenMapKey<CompTokenMap>>(component: C, token: GlobalToken<CompTokenMap, AliasToken>, getDefaultToken: GetDefaultToken<CompTokenMap, AliasToken, C>): any;
|
||||
export default getDefaultComponentToken;
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _statistic = require("./statistic");
|
||||
function getDefaultComponentToken(component, token, getDefaultToken) {
|
||||
if (typeof getDefaultToken === 'function') {
|
||||
var _token$component;
|
||||
return getDefaultToken((0, _statistic.merge)(token, (_token$component = token[component]) !== null && _token$component !== void 0 ? _token$component : {}));
|
||||
}
|
||||
return getDefaultToken !== null && getDefaultToken !== void 0 ? getDefaultToken : {};
|
||||
}
|
||||
var _default = exports.default = getDefaultComponentToken;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
declare function genMaxMin(type: 'css' | 'js'): {
|
||||
max: (...values: number[]) => number;
|
||||
min: (...values: number[]) => number;
|
||||
} | {
|
||||
max: (...args: (string | number)[]) => string;
|
||||
min: (...args: (string | number)[]) => string;
|
||||
};
|
||||
export default genMaxMin;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _cssinjs = require("@ant-design/cssinjs");
|
||||
function genMaxMin(type) {
|
||||
if (type === 'js') {
|
||||
return {
|
||||
max: Math.max,
|
||||
min: Math.min
|
||||
};
|
||||
}
|
||||
return {
|
||||
max: function max() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
return "max(".concat(args.map(function (value) {
|
||||
return (0, _cssinjs.unit)(value);
|
||||
}).join(','), ")");
|
||||
},
|
||||
min: function min() {
|
||||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
||||
args[_key2] = arguments[_key2];
|
||||
}
|
||||
return "min(".concat(args.map(function (value) {
|
||||
return (0, _cssinjs.unit)(value);
|
||||
}).join(','), ")");
|
||||
}
|
||||
};
|
||||
}
|
||||
var _default = exports.default = genMaxMin;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import type { TokenMap } from '../interface';
|
||||
/**
|
||||
* This function will do as `Object.assign` in production. But will use Object.defineProperty:get to
|
||||
* pass all value access in development. To support statistic field usage with alias token.
|
||||
*/
|
||||
export declare function merge<CompTokenMap extends TokenMap>(...objs: Partial<CompTokenMap>[]): CompTokenMap;
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
export declare const statistic: Record<string, {
|
||||
global: string[];
|
||||
component: Record<string, string | number>;
|
||||
}>;
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
export declare const _statistic_build_: typeof statistic;
|
||||
/** Statistic token usage case. Should use `merge` function if you do not want spread record. */
|
||||
declare const statisticToken: <CompTokenMap extends TokenMap>(token: CompTokenMap) => {
|
||||
token: CompTokenMap;
|
||||
keys: Set<string>;
|
||||
flush: (componentName: string, componentToken: Record<string, string | number>) => void;
|
||||
};
|
||||
export default statisticToken;
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = exports._statistic_build_ = void 0;
|
||||
exports.merge = merge;
|
||||
exports.statistic = void 0;
|
||||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
var enableStatistic = process.env.NODE_ENV !== 'production' || typeof CSSINJS_STATISTIC !== 'undefined';
|
||||
var recording = true;
|
||||
|
||||
/**
|
||||
* This function will do as `Object.assign` in production. But will use Object.defineProperty:get to
|
||||
* pass all value access in development. To support statistic field usage with alias token.
|
||||
*/
|
||||
function merge() {
|
||||
for (var _len = arguments.length, objs = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
objs[_key] = arguments[_key];
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
if (!enableStatistic) {
|
||||
return Object.assign.apply(Object, [{}].concat(objs));
|
||||
}
|
||||
recording = false;
|
||||
var ret = {};
|
||||
objs.forEach(function (obj) {
|
||||
if ((0, _typeof2.default)(obj) !== 'object') {
|
||||
return;
|
||||
}
|
||||
var keys = Object.keys(obj);
|
||||
keys.forEach(function (key) {
|
||||
Object.defineProperty(ret, key, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return obj[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
recording = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
var statistic = exports.statistic = {};
|
||||
|
||||
/** @internal Internal Usage. Not use in your production. */
|
||||
var _statistic_build_ = exports._statistic_build_ = {};
|
||||
|
||||
/* istanbul ignore next */
|
||||
function noop() {}
|
||||
|
||||
/** Statistic token usage case. Should use `merge` function if you do not want spread record. */
|
||||
var statisticToken = function statisticToken(token) {
|
||||
var tokenKeys;
|
||||
var proxy = token;
|
||||
var flush = noop;
|
||||
if (enableStatistic && typeof Proxy !== 'undefined') {
|
||||
tokenKeys = new Set();
|
||||
proxy = new Proxy(token, {
|
||||
get: function get(obj, prop) {
|
||||
if (recording) {
|
||||
var _tokenKeys;
|
||||
(_tokenKeys = tokenKeys) === null || _tokenKeys === void 0 || _tokenKeys.add(prop);
|
||||
}
|
||||
return obj[prop];
|
||||
}
|
||||
});
|
||||
flush = function flush(componentName, componentToken) {
|
||||
var _statistic$componentN;
|
||||
statistic[componentName] = {
|
||||
global: Array.from(tokenKeys),
|
||||
component: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (_statistic$componentN = statistic[componentName]) === null || _statistic$componentN === void 0 ? void 0 : _statistic$componentN.component), componentToken)
|
||||
};
|
||||
};
|
||||
}
|
||||
return {
|
||||
token: proxy,
|
||||
keys: tokenKeys,
|
||||
flush: flush
|
||||
};
|
||||
};
|
||||
var _default = exports.default = statisticToken;
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"name": "@ant-design/cssinjs-utils",
|
||||
"version": "2.1.2",
|
||||
"description": "A cssinjs util library to support Ant Design (antd) and its ecosystem libraries.",
|
||||
"keywords": [
|
||||
"react",
|
||||
"cssinjs",
|
||||
"cssinjs-util",
|
||||
"antd",
|
||||
"ant-design"
|
||||
],
|
||||
"homepage": "https://github.com/ant-design/cssinjs-util",
|
||||
"author": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ant-design/cssinjs-util.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ant-design/cssinjs-util/issues"
|
||||
},
|
||||
"files": [
|
||||
"es",
|
||||
"lib",
|
||||
"dist"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/index",
|
||||
"module": "./es/index",
|
||||
"scripts": {
|
||||
"start": "dumi dev",
|
||||
"compile": "father build",
|
||||
"prepublishOnly": "npm run compile && np --yolo --any-branch --no-publish",
|
||||
"lint": "eslint src/ --ext .tsx,.ts,.jsx,.js",
|
||||
"test": "rc-test",
|
||||
"coverage": "rc-test --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rc-component/father-plugin": "^1.0.1",
|
||||
"@testing-library/jest-dom": "^6.1.4",
|
||||
"@testing-library/react": "^16.0.0",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^22.0.2",
|
||||
"@types/react": "^18.0.0",
|
||||
"@types/react-dom": "^18.0.11",
|
||||
"@umijs/fabric": "^4.0.1",
|
||||
"cross-env": "^7.0.1",
|
||||
"dumi": "^2.1.0",
|
||||
"eslint": "^8.51.0",
|
||||
"father": "^4.0.0",
|
||||
"less": "^4.2.0",
|
||||
"np": "^10.0.5",
|
||||
"prettier": "^3.3.3",
|
||||
"rc-test": "^7.0.13",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0",
|
||||
"regenerator-runtime": "^0.14.0",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/cssinjs": "^2.1.2",
|
||||
"@babel/runtime": "^7.23.2",
|
||||
"@rc-component/util": "^1.4.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18",
|
||||
"react-dom": ">=18"
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019-present afc163
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
# @ant-design/cssinjs
|
||||
|
||||
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
||||
|
||||
[npm-image]: http://img.shields.io/npm/v/@ant-design/cssinjs.svg?style=flat-square
|
||||
[npm-url]: http://npmjs.org/package/@ant-design/cssinjs
|
||||
[github-actions-image]: https://github.com/ant-design/cssinjs/workflows/CI/badge.svg
|
||||
[github-actions-url]: https://github.com/ant-design/cssinjs/actions
|
||||
[codecov-image]: https://img.shields.io/codecov/c/github/ant-design/cssinjs/master.svg?style=flat-square
|
||||
[codecov-url]: https://codecov.io/gh/ant-design/cssinjs/branch/master
|
||||
[download-image]: https://img.shields.io/npm/dm/@ant-design/cssinjs.svg?style=flat-square
|
||||
[download-url]: https://npmjs.org/package/@ant-design/cssinjs
|
||||
[bundlephobia-url]: https://bundlephobia.com/result?p=@ant-design/cssinjs
|
||||
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@ant-design/cssinjs
|
||||
|
||||
Component level cssinjs solution used in [ant.design](https://ant.design). It's a subset of [Emotion](https://emotion.sh/) with design token logic wrapper. Please feel free to use emotion directly if you want to find a web cssinjs solution. cssinjs related dep packages:
|
||||
|
||||
- stylis
|
||||
- @emotion/hash
|
||||
- @emotion/unitless
|
||||
|
||||
## Live Demo
|
||||
|
||||
https://ant-design.github.io/cssinjs/
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install @ant-design/cssinjs
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
yarn add @ant-design/cssinjs
|
||||
```
|
||||
|
||||
```bash
|
||||
pnpm add @ant-design/cssinjs
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```
|
||||
npm install
|
||||
npm start
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@ant-design/cssinjs is released under the MIT license.
|
||||
|
||||
## API
|
||||
|
||||
### StyleProvider
|
||||
|
||||
| Prop | Desc | Type | Default |
|
||||
| --- | --- | --- | --- |
|
||||
| autoClear | Clear inject style element when component remove. | boolean | false |
|
||||
| cache | Config cssinjs cache entity. Only set when you need ssr to extract style on you own. | CacheEntity | - |
|
||||
| hashPriority | Use `:where` selector to reduce hashId css selector priority | `'low' \| 'high'` | `'low'` |
|
||||
| container | Tell cssinjs where to inject style in. | Element \| ShadowRoot | `document.head` |
|
||||
| ssrInline | Component wil render inline `<style />` for fallback in SSR. Not recommend. | boolean | false |
|
||||
| transformers | Transform css before inject in document. Please note that `transformers` do not support dynamic update | Transformer[] | - |
|
||||
|
||||
### createCache
|
||||
|
||||
return CacheEntity for StyleProvider.
|
||||
|
||||
### createTheme
|
||||
|
||||
Create theme object. When same algorithm provided, it will return same object.
|
||||
|
||||
### Design Token related API
|
||||
|
||||
Since `@ant-design/cssinjs` use strong constraints for cache hit performance, we recommend to view demo `basic.tsx` for usage and `animation.tsx` for animation usage.
|
||||
|
||||
### extractStyle
|
||||
|
||||
Extracts the styles from the cache and returns them as a string.
|
||||
|
||||
#### Parameters
|
||||
|
||||
- `cache` (Cache): The cache instance containing the styles.
|
||||
- `options` (object | boolean, optional): Options for extracting the styles.
|
||||
- `plain` (boolean, optional): If true, the styles will be returned in plain format. Default is false.
|
||||
- `types` (string | string[], optional): The types of styles to extract. Default is ['style', 'token', 'cssVar'].
|
||||
|
||||
#### Returns
|
||||
|
||||
- (string): The extracted styles as a string.
|
||||
|
||||
#### Example
|
||||
|
||||
```typescript
|
||||
import { extractStyle, createCache } from '@ant-design/cssinjs';
|
||||
|
||||
// 创建并填充缓存
|
||||
const cache = createCache();
|
||||
// 注意:在实际使用中,缓存通常会在渲染组件时自动填充
|
||||
|
||||
// 提取样式
|
||||
const styles = extractStyle(cache, { plain: true, types: ['style', 'token'] });
|
||||
|
||||
// 使用提取的样式
|
||||
const styleElement = document.createElement('style');
|
||||
styleElement.innerHTML = styles;
|
||||
document.head.appendChild(styleElement);
|
||||
```
|
||||
|
||||
## Transform
|
||||
|
||||
When you need transform CSSObject before inject style. You can use `transformers` to handle this:
|
||||
|
||||
```tsx | pure
|
||||
import {
|
||||
legacyLogicalPropertiesTransformer,
|
||||
StyleProvider,
|
||||
} from '@ant-design/cssinjs';
|
||||
|
||||
export default () => (
|
||||
<StyleProvider transformers={[legacyLogicalPropertiesTransformer]}>
|
||||
<MyApp />
|
||||
</StyleProvider>
|
||||
);
|
||||
```
|
||||
|
||||
Follow are the transform we provide:
|
||||
|
||||
#### legacyLogicalPropertiesTransformer
|
||||
|
||||
Convert logical properties to legacy properties. e.g. `marginBlockStart` to `marginTop`:
|
||||
|
||||
- inset
|
||||
- margin
|
||||
- padding
|
||||
- border
|
||||
|
||||
#### px2remTransformer
|
||||
|
||||
Convert pixel units to rem units. [px2remTransformer.options](./src/transformers/px2rem.ts)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user