@antdv-next/cssinjs 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Cache.d.ts +20 -0
- package/es/Keyframes.d.ts +9 -0
- package/es/StyleContext.d.ts +40 -0
- package/es/extractStyle.d.ts +12 -0
- package/es/hooks/useCSSVarRegister.d.ts +21 -0
- package/es/hooks/useCacheToken.d.ts +69 -0
- package/es/hooks/useEffectCleanupRegister.d.ts +2 -0
- package/es/hooks/useGlobalCache.d.ts +7 -0
- package/es/hooks/useHMR.d.ts +3 -0
- package/es/hooks/useStyleRegister.d.ts +81 -0
- package/es/index.d.ts +18 -0
- package/es/interface.d.ts +2 -0
- package/es/linters/NaNLinter.d.ts +3 -0
- package/es/linters/contentQuotesLinter.d.ts +3 -0
- package/es/linters/hashedAnimationLinter.d.ts +3 -0
- package/es/linters/index.d.ts +7 -0
- package/es/linters/interface.d.ts +8 -0
- package/es/linters/legacyNotSelectorLinter.d.ts +3 -0
- package/es/linters/logicalPropertiesLinter.d.ts +3 -0
- package/es/linters/parentSelectorLinter.d.ts +3 -0
- package/es/linters/utils.d.ts +2 -0
- package/es/theme/Theme.d.ts +11 -0
- package/es/theme/ThemeCache.d.ts +20 -0
- package/es/theme/calc/CSSCalculator.d.ts +15 -0
- package/es/theme/calc/NumCalculator.d.ts +10 -0
- package/es/theme/calc/calculator.d.ts +30 -0
- package/es/theme/calc/index.d.ts +5 -0
- package/es/theme/createTheme.d.ts +6 -0
- package/es/theme/index.d.ts +6 -0
- package/es/theme/interface.d.ts +2 -0
- package/es/transformers/interface.d.ts +4 -0
- package/es/transformers/legacyLogicalProperties.d.ts +12 -0
- package/es/transformers/px2rem.d.ts +20 -0
- package/es/util/cacheMapUtil.d.ts +14 -0
- package/es/util/css-variables.d.ts +20 -0
- package/es/util/index.d.ts +15 -0
- package/lib/Cache.d.ts +20 -0
- package/lib/Keyframes.d.ts +9 -0
- package/lib/StyleContext.d.ts +40 -0
- package/lib/extractStyle.d.ts +12 -0
- package/lib/hooks/useCSSVarRegister.d.ts +21 -0
- package/lib/hooks/useCacheToken.d.ts +69 -0
- package/lib/hooks/useEffectCleanupRegister.d.ts +2 -0
- package/lib/hooks/useGlobalCache.d.ts +7 -0
- package/lib/hooks/useHMR.d.ts +3 -0
- package/lib/hooks/useStyleRegister.d.ts +81 -0
- package/lib/index.d.ts +18 -0
- package/lib/interface.d.ts +2 -0
- package/lib/linters/NaNLinter.d.ts +3 -0
- package/lib/linters/contentQuotesLinter.d.ts +3 -0
- package/lib/linters/hashedAnimationLinter.d.ts +3 -0
- package/lib/linters/index.d.ts +7 -0
- package/lib/linters/interface.d.ts +8 -0
- package/lib/linters/legacyNotSelectorLinter.d.ts +3 -0
- package/lib/linters/logicalPropertiesLinter.d.ts +3 -0
- package/lib/linters/parentSelectorLinter.d.ts +3 -0
- package/lib/linters/utils.d.ts +2 -0
- package/lib/theme/Theme.d.ts +11 -0
- package/lib/theme/ThemeCache.d.ts +20 -0
- package/lib/theme/calc/CSSCalculator.d.ts +15 -0
- package/lib/theme/calc/NumCalculator.d.ts +10 -0
- package/lib/theme/calc/calculator.d.ts +30 -0
- package/lib/theme/calc/index.d.ts +5 -0
- package/lib/theme/createTheme.d.ts +6 -0
- package/lib/theme/index.d.ts +6 -0
- package/lib/theme/interface.d.ts +2 -0
- package/lib/transformers/interface.d.ts +4 -0
- package/lib/transformers/legacyLogicalProperties.d.ts +12 -0
- package/lib/transformers/px2rem.d.ts +20 -0
- package/lib/util/cacheMapUtil.d.ts +14 -0
- package/lib/util/css-variables.d.ts +20 -0
- package/lib/util/index.d.ts +15 -0
- package/package.json +3 -2
package/es/Cache.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type KeyType = string | number;
|
|
2
|
+
type ValueType = [number, any];
|
|
3
|
+
/** Connect key with `SPLIT` */
|
|
4
|
+
export declare function pathKey(keys: KeyType[]): string;
|
|
5
|
+
declare class Entity {
|
|
6
|
+
instanceId: string;
|
|
7
|
+
constructor(instanceId: string);
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
* Internal cache map. Do not access this directly
|
|
11
|
+
*/
|
|
12
|
+
cache: Map<string, ValueType>;
|
|
13
|
+
get(keys: KeyType[]): ValueType | null;
|
|
14
|
+
/** A fast get cache with `get` concat. */
|
|
15
|
+
opGet(keyPathStr: string): ValueType | null;
|
|
16
|
+
update(keys: KeyType[], valueFn: (origin: ValueType | null) => ValueType | null): void;
|
|
17
|
+
/** A fast get cache with `get` concat. */
|
|
18
|
+
opUpdate(keyPathStr: string, valueFn: (origin: ValueType | null) => ValueType | null): void;
|
|
19
|
+
}
|
|
20
|
+
export default Entity;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSInterpolation } from './hooks/useStyleRegister';
|
|
2
|
+
declare class Keyframe {
|
|
3
|
+
private readonly name;
|
|
4
|
+
style: CSSInterpolation;
|
|
5
|
+
constructor(name: string, style: CSSInterpolation);
|
|
6
|
+
getName(hashId?: string): string;
|
|
7
|
+
_keyframe: boolean;
|
|
8
|
+
}
|
|
9
|
+
export default Keyframe;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { Linter } from './linters';
|
|
3
|
+
import { Transformer } from './transformers/interface';
|
|
4
|
+
import { default as CacheEntity } from './Cache';
|
|
5
|
+
export declare const ATTR_TOKEN = "data-token-hash";
|
|
6
|
+
export declare const ATTR_MARK = "data-css-hash";
|
|
7
|
+
export declare const ATTR_CACHE_PATH = "data-cache-path";
|
|
8
|
+
export declare const CSS_IN_JS_INSTANCE = "__cssinjs_instance__";
|
|
9
|
+
export declare function createCache(): CacheEntity;
|
|
10
|
+
export type HashPriority = 'low' | 'high';
|
|
11
|
+
export interface StyleContextProps {
|
|
12
|
+
autoClear?: boolean;
|
|
13
|
+
mock?: 'server' | 'client';
|
|
14
|
+
/**
|
|
15
|
+
* Only set when you need ssr to extract style on you own.
|
|
16
|
+
* If not provided, it will auto create <style /> on the end of Provider in server side.
|
|
17
|
+
*/
|
|
18
|
+
cache: CacheEntity;
|
|
19
|
+
/** Tell children that this context is default generated context */
|
|
20
|
+
defaultCache: boolean;
|
|
21
|
+
/** Use `:where` selector to reduce hashId css selector priority */
|
|
22
|
+
hashPriority?: HashPriority;
|
|
23
|
+
/** Tell cssinjs where to inject style in */
|
|
24
|
+
container?: Element | ShadowRoot;
|
|
25
|
+
/** Component wil render inline `<style />` for fallback in SSR. Not recommend. */
|
|
26
|
+
ssrInline?: boolean;
|
|
27
|
+
/** Transform css before inject in document. Please note that `transformers` do not support dynamic update */
|
|
28
|
+
transformers?: Transformer[];
|
|
29
|
+
/**
|
|
30
|
+
* Linters to lint css before inject in document.
|
|
31
|
+
* Styles will be linted after transforming.
|
|
32
|
+
* Please note that `linters` do not support dynamic update.
|
|
33
|
+
*/
|
|
34
|
+
linters?: Linter[];
|
|
35
|
+
/** Wrap css in a layer to avoid global style conflict */
|
|
36
|
+
layer?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export type StyleProviderProps = Partial<StyleContextProps>;
|
|
39
|
+
export declare const StyleProvider: import('vue').DefineSetupFnComponent<Partial<StyleContextProps>, {}, {}, Partial<StyleContextProps> & {}, import('vue').PublicProps>;
|
|
40
|
+
export declare function useStyleContext(): ComputedRef<StyleContextProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as Cache } from './Cache';
|
|
2
|
+
declare const ExtractStyleFns: {
|
|
3
|
+
style: import('./hooks/useGlobalCache').ExtractStyle<[styleStr: string, tokenKey: string, styleId: string, effectStyle: Record<string, string>, clientOnly: boolean | undefined, order: number]>;
|
|
4
|
+
token: import('./hooks/useGlobalCache').ExtractStyle<[token: any, hashId: string, realToken: any, cssVarStr: string, cssVarKey: string]>;
|
|
5
|
+
cssVar: import('./hooks/useGlobalCache').ExtractStyle<[cssVarToken: import('./util/css-variables').TokenWithCSSVar<any, Record<string, any>>, cssVarStr: string, styleId: string, cssVarKey: string]>;
|
|
6
|
+
};
|
|
7
|
+
type ExtractStyleType = keyof typeof ExtractStyleFns;
|
|
8
|
+
export default function extractStyle(cache: Cache, options?: boolean | {
|
|
9
|
+
plain?: boolean;
|
|
10
|
+
types?: ExtractStyleType | ExtractStyleType[];
|
|
11
|
+
}): string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MaybeRef } from 'vue';
|
|
2
|
+
import { TokenWithCSSVar } from '../util/css-variables';
|
|
3
|
+
import { ExtractStyle } from './useGlobalCache';
|
|
4
|
+
export declare const CSS_VAR_PREFIX = "cssVar";
|
|
5
|
+
type CSSVarCacheValue<V, T extends Record<string, V> = Record<string, V>> = [
|
|
6
|
+
cssVarToken: TokenWithCSSVar<V, T>,
|
|
7
|
+
cssVarStr: string,
|
|
8
|
+
styleId: string,
|
|
9
|
+
cssVarKey: string
|
|
10
|
+
];
|
|
11
|
+
declare function useCSSVarRegister<V, T extends Record<string, V>>(config: MaybeRef<{
|
|
12
|
+
path: string[];
|
|
13
|
+
key: string;
|
|
14
|
+
prefix?: string;
|
|
15
|
+
unitless?: Record<string, boolean>;
|
|
16
|
+
ignore?: Record<string, boolean>;
|
|
17
|
+
scope?: string;
|
|
18
|
+
token: any;
|
|
19
|
+
}>, fn: MaybeRef<() => T>): import('vue').ComputedRef<CSSVarCacheValue<V, T>>;
|
|
20
|
+
export declare const extract: ExtractStyle<CSSVarCacheValue<any>>;
|
|
21
|
+
export default useCSSVarRegister;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ComputedRef, MaybeRef } from 'vue';
|
|
2
|
+
import { default as Theme } from '../theme/Theme';
|
|
3
|
+
import { ExtractStyle } from './useGlobalCache';
|
|
4
|
+
export interface Option<DerivativeToken, DesignToken> {
|
|
5
|
+
/**
|
|
6
|
+
* Generate token with salt.
|
|
7
|
+
* This is used to generate different hashId even same derivative token for different version.
|
|
8
|
+
*/
|
|
9
|
+
salt?: string;
|
|
10
|
+
override?: object;
|
|
11
|
+
/**
|
|
12
|
+
* Format token as you need. Such as:
|
|
13
|
+
*
|
|
14
|
+
* - rename token
|
|
15
|
+
* - merge token
|
|
16
|
+
* - delete token
|
|
17
|
+
*
|
|
18
|
+
* This should always be the same since it's one time process.
|
|
19
|
+
* It's ok to useMemo outside but this has better cache strategy.
|
|
20
|
+
*/
|
|
21
|
+
formatToken?: (mergedToken: any) => DerivativeToken;
|
|
22
|
+
/**
|
|
23
|
+
* Get final token with origin token, override token and theme.
|
|
24
|
+
* The parameters do not contain formatToken since it's passed by user.
|
|
25
|
+
* @param origin The original token.
|
|
26
|
+
* @param override Extra tokens to override.
|
|
27
|
+
* @param theme Theme instance. Could get derivative token by `theme.getDerivativeToken`
|
|
28
|
+
*/
|
|
29
|
+
getComputedToken?: (origin: DesignToken, override: object, theme: Theme<any, any>) => DerivativeToken;
|
|
30
|
+
/**
|
|
31
|
+
* Transform token to css variables.
|
|
32
|
+
*/
|
|
33
|
+
cssVar?: {
|
|
34
|
+
/** Prefix for css variables */
|
|
35
|
+
prefix?: string;
|
|
36
|
+
/** Tokens that should not be appended with unit */
|
|
37
|
+
unitless?: Record<string, boolean>;
|
|
38
|
+
/** Tokens that should not be transformed to css variables */
|
|
39
|
+
ignore?: Record<string, boolean>;
|
|
40
|
+
/** Tokens that preserves origin value */
|
|
41
|
+
preserve?: Record<string, boolean>;
|
|
42
|
+
/** Key for current theme. Useful for customizing and should be unique */
|
|
43
|
+
key?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare function getComputedToken<DerivativeToken = object, DesignToken = DerivativeToken>(originToken: DesignToken, overrideToken: object, theme: Theme<any, any>, format?: (token: DesignToken) => DerivativeToken): any;
|
|
47
|
+
export declare const TOKEN_PREFIX = "token";
|
|
48
|
+
type TokenCacheValue<DerivativeToken> = [
|
|
49
|
+
token: DerivativeToken & {
|
|
50
|
+
_tokenKey: string;
|
|
51
|
+
_themeKey: string;
|
|
52
|
+
},
|
|
53
|
+
hashId: string,
|
|
54
|
+
realToken: DerivativeToken & {
|
|
55
|
+
_tokenKey: string;
|
|
56
|
+
},
|
|
57
|
+
cssVarStr: string,
|
|
58
|
+
cssVarKey: string
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* Cache theme derivative token as global shared one
|
|
62
|
+
* @param theme Theme entity
|
|
63
|
+
* @param tokens List of tokens, used for cache. Please do not dynamic generate object directly
|
|
64
|
+
* @param option Additional config
|
|
65
|
+
* @returns Call Theme.getDerivativeToken(tokenObject) to get token
|
|
66
|
+
*/
|
|
67
|
+
export default function useCacheToken<DerivativeToken = object, DesignToken = DerivativeToken>(theme: MaybeRef<Theme<any, any>>, tokens: MaybeRef<Partial<DesignToken>[]>, option?: MaybeRef<Option<DerivativeToken, DesignToken>>): ComputedRef<TokenCacheValue<DerivativeToken>>;
|
|
68
|
+
export declare const extract: ExtractStyle<TokenCacheValue<any>>;
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { MaybeRef } from '../interface.ts';
|
|
3
|
+
import { KeyType } from '../Cache';
|
|
4
|
+
export type ExtractStyle<CacheValue> = (cache: CacheValue, effectStyles: Record<string, boolean>, options?: {
|
|
5
|
+
plain?: boolean;
|
|
6
|
+
}) => [order: number, styleId: string, style: string] | null;
|
|
7
|
+
export default function useGlobalCache<CacheType>(prefix: MaybeRef<string>, keyPath: MaybeRef<KeyType[]>, cacheFn: () => CacheType, onCacheRemove?: (cache: CacheType, fromHMR: boolean) => void, onCacheEffect?: (cachedValue: CacheType) => void): ComputedRef<CacheType>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { MaybeRef } from 'vue';
|
|
3
|
+
import { Theme, Transformer } from '..';
|
|
4
|
+
import { default as Keyframes } from '../Keyframes';
|
|
5
|
+
import { Linter } from '../linters';
|
|
6
|
+
import { HashPriority } from '../StyleContext';
|
|
7
|
+
import { ExtractStyle } from './useGlobalCache';
|
|
8
|
+
import type * as CSS from 'csstype';
|
|
9
|
+
declare const SKIP_CHECK = "_skip_check_";
|
|
10
|
+
declare const MULTI_VALUE = "_multi_value_";
|
|
11
|
+
export interface LayerConfig {
|
|
12
|
+
name: string;
|
|
13
|
+
dependencies?: string[];
|
|
14
|
+
}
|
|
15
|
+
export type CSSProperties = Omit<CSS.PropertiesFallback<number | string>, 'animationName'> & {
|
|
16
|
+
animationName?: CSS.PropertiesFallback<number | string>['animationName'] | Keyframes;
|
|
17
|
+
};
|
|
18
|
+
export type CSSPropertiesWithMultiValues = {
|
|
19
|
+
[K in keyof CSSProperties]: CSSProperties[K] | readonly Extract<CSSProperties[K], string>[] | {
|
|
20
|
+
[SKIP_CHECK]?: boolean;
|
|
21
|
+
[MULTI_VALUE]?: boolean;
|
|
22
|
+
value: CSSProperties[K] | CSSProperties[K][];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type CSSPseudos = {
|
|
26
|
+
[K in CSS.Pseudos]?: CSSObject;
|
|
27
|
+
};
|
|
28
|
+
type ArrayCSSInterpolation = readonly CSSInterpolation[];
|
|
29
|
+
export type InterpolationPrimitive = null | undefined | boolean | number | string | CSSObject;
|
|
30
|
+
export type CSSInterpolation = InterpolationPrimitive | ArrayCSSInterpolation | Keyframes;
|
|
31
|
+
export type CSSOthersObject = Record<string, CSSInterpolation>;
|
|
32
|
+
export interface CSSObject extends CSSPropertiesWithMultiValues, CSSPseudos, CSSOthersObject {
|
|
33
|
+
}
|
|
34
|
+
export declare function normalizeStyle(styleStr: string): string;
|
|
35
|
+
export interface ParseConfig {
|
|
36
|
+
hashId?: string;
|
|
37
|
+
hashPriority?: HashPriority;
|
|
38
|
+
layer?: LayerConfig;
|
|
39
|
+
path?: string;
|
|
40
|
+
transformers?: Transformer[];
|
|
41
|
+
linters?: Linter[];
|
|
42
|
+
}
|
|
43
|
+
export interface ParseInfo {
|
|
44
|
+
root?: boolean;
|
|
45
|
+
injectHash?: boolean;
|
|
46
|
+
parentSelectors: string[];
|
|
47
|
+
}
|
|
48
|
+
export declare function parseStyle(interpolation: CSSInterpolation, config?: ParseConfig, { root, injectHash, parentSelectors }?: ParseInfo): [
|
|
49
|
+
parsedStr: string,
|
|
50
|
+
effectStyle: Record<string, string>
|
|
51
|
+
];
|
|
52
|
+
export declare function uniqueHash(path: (string | number)[], styleStr: string): string;
|
|
53
|
+
export declare const STYLE_PREFIX = "style";
|
|
54
|
+
type StyleCacheValue = [
|
|
55
|
+
styleStr: string,
|
|
56
|
+
tokenKey: string,
|
|
57
|
+
styleId: string,
|
|
58
|
+
effectStyle: Record<string, string>,
|
|
59
|
+
clientOnly: boolean | undefined,
|
|
60
|
+
order: number
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* Register a style to the global style sheet.
|
|
64
|
+
*/
|
|
65
|
+
export default function useStyleRegister(info: MaybeRef<{
|
|
66
|
+
theme: Theme<any, any>;
|
|
67
|
+
token: any;
|
|
68
|
+
path: string[];
|
|
69
|
+
hashId?: string;
|
|
70
|
+
layer?: LayerConfig;
|
|
71
|
+
nonce?: string | (() => string);
|
|
72
|
+
clientOnly?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Tell cssinjs the insert order of style.
|
|
75
|
+
* It's useful when you need to insert style
|
|
76
|
+
* before other style to overwrite for the same selector priority.
|
|
77
|
+
*/
|
|
78
|
+
order?: number;
|
|
79
|
+
}>, styleFn: MaybeRef<() => CSSInterpolation>): (node: VueNode) => any;
|
|
80
|
+
export declare const extract: ExtractStyle<StyleCacheValue>;
|
|
81
|
+
export {};
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CSSInterpolation, CSSObject, default as useStyleRegister } from './hooks/useStyleRegister';
|
|
2
|
+
import { Linter, legacyNotSelectorLinter, logicalPropertiesLinter, NaNLinter, parentSelectorLinter } from './linters';
|
|
3
|
+
import { StyleProviderProps, createCache, StyleProvider } from './StyleContext';
|
|
4
|
+
import { AbstractCalculator, DerivativeFunc, TokenType, createTheme, genCalc, Theme } from './theme';
|
|
5
|
+
import { Transformer } from './transformers/interface';
|
|
6
|
+
import { default as extractStyle } from './extractStyle';
|
|
7
|
+
import { default as useCacheToken, getComputedToken } from './hooks/useCacheToken';
|
|
8
|
+
import { default as useCSSVarRegister } from './hooks/useCSSVarRegister';
|
|
9
|
+
import { default as Keyframes } from './Keyframes';
|
|
10
|
+
import { default as legacyLogicalPropertiesTransformer } from './transformers/legacyLogicalProperties';
|
|
11
|
+
import { default as px2remTransformer } from './transformers/px2rem';
|
|
12
|
+
import { unit } from './util';
|
|
13
|
+
import { token2CSSVar } from './util/css-variables';
|
|
14
|
+
export { createCache, createTheme, extractStyle, genCalc, getComputedToken, Keyframes, legacyLogicalPropertiesTransformer, legacyNotSelectorLinter, logicalPropertiesLinter, NaNLinter, parentSelectorLinter, px2remTransformer, StyleProvider, Theme, token2CSSVar, unit, useCacheToken, useCSSVarRegister, useStyleRegister, };
|
|
15
|
+
export type { AbstractCalculator, CSSInterpolation, CSSObject, DerivativeFunc, Linter, StyleProviderProps, TokenType, Transformer, };
|
|
16
|
+
export declare const _experimental: {
|
|
17
|
+
supportModernCSS: () => boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as contentQuotesLinter } from './contentQuotesLinter';
|
|
2
|
+
export { default as hashedAnimationLinter } from './hashedAnimationLinter';
|
|
3
|
+
export type { Linter } from './interface';
|
|
4
|
+
export { default as legacyNotSelectorLinter } from './legacyNotSelectorLinter';
|
|
5
|
+
export { default as logicalPropertiesLinter } from './logicalPropertiesLinter';
|
|
6
|
+
export { default as NaNLinter } from './NaNLinter';
|
|
7
|
+
export { default as parentSelectorLinter } from './parentSelectorLinter';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DerivativeFunc, TokenType } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Theme with algorithms to derive tokens from design tokens.
|
|
4
|
+
* Use `createTheme` first which will help to manage the theme instance cache.
|
|
5
|
+
*/
|
|
6
|
+
export default class Theme<DesignToken extends TokenType, DerivativeToken extends TokenType> {
|
|
7
|
+
private derivatives;
|
|
8
|
+
readonly id: number;
|
|
9
|
+
constructor(derivatives: DerivativeFunc<DesignToken, DerivativeToken> | DerivativeFunc<DesignToken, DerivativeToken>[]);
|
|
10
|
+
getDerivativeToken(token: DesignToken): DerivativeToken;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DerivativeFunc } from './interface';
|
|
2
|
+
import { default as Theme } from './Theme';
|
|
3
|
+
type DerivativeOptions = DerivativeFunc<any, any>[];
|
|
4
|
+
export declare function sameDerivativeOption(left: DerivativeOptions, right: DerivativeOptions): boolean;
|
|
5
|
+
export default class ThemeCache {
|
|
6
|
+
static MAX_CACHE_SIZE: number;
|
|
7
|
+
static MAX_CACHE_OFFSET: number;
|
|
8
|
+
private readonly cache;
|
|
9
|
+
private keys;
|
|
10
|
+
private cacheCallTimes;
|
|
11
|
+
constructor();
|
|
12
|
+
size(): number;
|
|
13
|
+
private internalGet;
|
|
14
|
+
get(derivativeOption: DerivativeOptions): Theme<any, any> | undefined;
|
|
15
|
+
has(derivativeOption: DerivativeOptions): boolean;
|
|
16
|
+
set(derivativeOption: DerivativeOptions, value: Theme<any, any>): void;
|
|
17
|
+
private deleteByPath;
|
|
18
|
+
delete(derivativeOption: DerivativeOptions): Theme<any, any> | undefined;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as AbstractCalculator } from './calculator';
|
|
2
|
+
export default class CSSCalculator extends AbstractCalculator {
|
|
3
|
+
result: string;
|
|
4
|
+
unitlessCssVar: Set<string>;
|
|
5
|
+
lowPriority?: boolean;
|
|
6
|
+
constructor(num: number | string | AbstractCalculator, unitlessCssVar: Set<string>);
|
|
7
|
+
add(num: number | string | AbstractCalculator): this;
|
|
8
|
+
sub(num: number | string | AbstractCalculator): this;
|
|
9
|
+
mul(num: number | string | AbstractCalculator): this;
|
|
10
|
+
div(num: number | string | AbstractCalculator): this;
|
|
11
|
+
getResult(force?: boolean): string;
|
|
12
|
+
equal(options?: {
|
|
13
|
+
unit?: boolean;
|
|
14
|
+
}): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as AbstractCalculator } from './calculator';
|
|
2
|
+
export default class NumCalculator extends AbstractCalculator {
|
|
3
|
+
result: number;
|
|
4
|
+
constructor(num: number | string | AbstractCalculator);
|
|
5
|
+
add(num: number | string | AbstractCalculator): this;
|
|
6
|
+
sub(num: number | string | AbstractCalculator): this;
|
|
7
|
+
mul(num: number | string | AbstractCalculator): this;
|
|
8
|
+
div(num: number | string | AbstractCalculator): this;
|
|
9
|
+
equal(): number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare abstract class AbstractCalculator {
|
|
2
|
+
/**
|
|
3
|
+
* @descCN 计算两数的和,例如:1 + 2
|
|
4
|
+
* @descEN Calculate the sum of two numbers, e.g. 1 + 2
|
|
5
|
+
*/
|
|
6
|
+
abstract add(num: number | string | AbstractCalculator): this;
|
|
7
|
+
/**
|
|
8
|
+
* @descCN 计算两数的差,例如:1 - 2
|
|
9
|
+
* @descEN Calculate the difference between two numbers, e.g. 1 - 2
|
|
10
|
+
*/
|
|
11
|
+
abstract sub(num: number | string | AbstractCalculator): this;
|
|
12
|
+
/**
|
|
13
|
+
* @descCN 计算两数的积,例如:1 * 2
|
|
14
|
+
* @descEN Calculate the product of two numbers, e.g. 1 * 2
|
|
15
|
+
*/
|
|
16
|
+
abstract mul(num: number | string | AbstractCalculator): this;
|
|
17
|
+
/**
|
|
18
|
+
* @descCN 计算两数的商,例如:1 / 2
|
|
19
|
+
* @descEN Calculate the quotient of two numbers, e.g. 1 / 2
|
|
20
|
+
*/
|
|
21
|
+
abstract div(num: number | string | AbstractCalculator): this;
|
|
22
|
+
/**
|
|
23
|
+
* @descCN 获取计算结果
|
|
24
|
+
* @descEN Get the calculation result
|
|
25
|
+
*/
|
|
26
|
+
abstract equal(options?: {
|
|
27
|
+
unit?: boolean;
|
|
28
|
+
}): string | number;
|
|
29
|
+
}
|
|
30
|
+
export default AbstractCalculator;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as AbstractCalculator } from './calculator';
|
|
2
|
+
import { default as CSSCalculator } from './CSSCalculator';
|
|
3
|
+
import { default as NumCalculator } from './NumCalculator';
|
|
4
|
+
declare function genCalc(type: 'css' | 'js', unitlessCssVar: Set<string>): (num: number | string | AbstractCalculator) => CSSCalculator | NumCalculator;
|
|
5
|
+
export default genCalc;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DerivativeFunc, TokenType } from './interface';
|
|
2
|
+
import { default as Theme } from './Theme';
|
|
3
|
+
/**
|
|
4
|
+
* Same as new Theme, but will always return same one if `derivative` not changed.
|
|
5
|
+
*/
|
|
6
|
+
export default function createTheme<DesignToken extends TokenType, DerivativeToken extends TokenType>(derivatives: DerivativeFunc<DesignToken, DerivativeToken>[] | DerivativeFunc<DesignToken, DerivativeToken>): Theme<any, any>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as genCalc } from './calc';
|
|
2
|
+
export type { default as AbstractCalculator } from './calc/calculator';
|
|
3
|
+
export { default as createTheme } from './createTheme';
|
|
4
|
+
export type { DerivativeFunc, TokenType } from './interface';
|
|
5
|
+
export { default as Theme } from './Theme';
|
|
6
|
+
export { default as ThemeCache } from './ThemeCache';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Transformer } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Convert css logical properties to legacy properties.
|
|
4
|
+
* Such as: `margin-block-start` to `margin-top`.
|
|
5
|
+
* Transform list:
|
|
6
|
+
* - inset
|
|
7
|
+
* - margin
|
|
8
|
+
* - padding
|
|
9
|
+
* - border
|
|
10
|
+
*/
|
|
11
|
+
declare const transform: Transformer;
|
|
12
|
+
export default transform;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Transformer } from './interface';
|
|
2
|
+
interface Options {
|
|
3
|
+
/**
|
|
4
|
+
* The root font size.
|
|
5
|
+
* @default 16
|
|
6
|
+
*/
|
|
7
|
+
rootValue?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The decimal numbers to allow the REM units to grow to.
|
|
10
|
+
* @default 5
|
|
11
|
+
*/
|
|
12
|
+
precision?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to allow px to be converted in media queries.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
mediaQuery?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare function transform(options?: Options): Transformer;
|
|
20
|
+
export default transform;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ATTR_CACHE_MAP = "data-ant-cssinjs-cache-path";
|
|
2
|
+
/**
|
|
3
|
+
* This marks style from the css file.
|
|
4
|
+
* Which means not exist in `<style />` tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CSS_FILE_STYLE = "_FILE_STYLE__";
|
|
7
|
+
export declare function serialize(cachePathMap: Record<string, string>): string;
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export declare function reset(mockCache?: Record<string, string>, fromFile?: boolean): void;
|
|
12
|
+
export declare function prepare(): void;
|
|
13
|
+
export declare function existPath(path: string): boolean;
|
|
14
|
+
export declare function getStyleAndHash(path: string): [style: string | null, hash: string];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function token2CSSVar(token: string, prefix?: string): string;
|
|
2
|
+
export declare function serializeCSSVar<T extends Record<string, any>>(cssVars: T, hashId: string, options?: {
|
|
3
|
+
scope?: string;
|
|
4
|
+
}): string;
|
|
5
|
+
export type TokenWithCSSVar<V, T extends Record<string, V> = Record<string, V>> = {
|
|
6
|
+
[key in keyof T]?: string | V;
|
|
7
|
+
};
|
|
8
|
+
export declare function transformToken<V, T extends Record<string, V> = Record<string, V>>(token: T, themeKey: string, config?: {
|
|
9
|
+
prefix?: string;
|
|
10
|
+
ignore?: {
|
|
11
|
+
[key in keyof T]?: boolean;
|
|
12
|
+
};
|
|
13
|
+
unitless?: {
|
|
14
|
+
[key in keyof T]?: boolean;
|
|
15
|
+
};
|
|
16
|
+
preserve?: {
|
|
17
|
+
[key in keyof T]?: boolean;
|
|
18
|
+
};
|
|
19
|
+
scope?: string;
|
|
20
|
+
}): [TokenWithCSSVar<V, T>, string];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function memoResult<T extends object, R>(callback: () => R, deps: T[]): R;
|
|
2
|
+
/**
|
|
3
|
+
* Flatten token to string, this will auto cache the result when token not change
|
|
4
|
+
*/
|
|
5
|
+
export declare function flattenToken(token: any, hashed?: boolean): string;
|
|
6
|
+
/**
|
|
7
|
+
* Convert derivative token to key string
|
|
8
|
+
*/
|
|
9
|
+
export declare function token2key(token: any, salt: string): string;
|
|
10
|
+
export declare function supportLayer(): boolean;
|
|
11
|
+
export declare function supportWhere(): boolean;
|
|
12
|
+
export declare function supportLogicProps(): boolean;
|
|
13
|
+
export declare const isClientSide: boolean;
|
|
14
|
+
export declare function unit(num: string | number): string;
|
|
15
|
+
export declare function toStyleStr(style: string, tokenKey?: string, styleId?: string, customizeAttrs?: Record<string, string>, plain?: boolean): string;
|
package/lib/Cache.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type KeyType = string | number;
|
|
2
|
+
type ValueType = [number, any];
|
|
3
|
+
/** Connect key with `SPLIT` */
|
|
4
|
+
export declare function pathKey(keys: KeyType[]): string;
|
|
5
|
+
declare class Entity {
|
|
6
|
+
instanceId: string;
|
|
7
|
+
constructor(instanceId: string);
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
* Internal cache map. Do not access this directly
|
|
11
|
+
*/
|
|
12
|
+
cache: Map<string, ValueType>;
|
|
13
|
+
get(keys: KeyType[]): ValueType | null;
|
|
14
|
+
/** A fast get cache with `get` concat. */
|
|
15
|
+
opGet(keyPathStr: string): ValueType | null;
|
|
16
|
+
update(keys: KeyType[], valueFn: (origin: ValueType | null) => ValueType | null): void;
|
|
17
|
+
/** A fast get cache with `get` concat. */
|
|
18
|
+
opUpdate(keyPathStr: string, valueFn: (origin: ValueType | null) => ValueType | null): void;
|
|
19
|
+
}
|
|
20
|
+
export default Entity;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSInterpolation } from './hooks/useStyleRegister';
|
|
2
|
+
declare class Keyframe {
|
|
3
|
+
private readonly name;
|
|
4
|
+
style: CSSInterpolation;
|
|
5
|
+
constructor(name: string, style: CSSInterpolation);
|
|
6
|
+
getName(hashId?: string): string;
|
|
7
|
+
_keyframe: boolean;
|
|
8
|
+
}
|
|
9
|
+
export default Keyframe;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { Linter } from './linters';
|
|
3
|
+
import { Transformer } from './transformers/interface';
|
|
4
|
+
import { default as CacheEntity } from './Cache';
|
|
5
|
+
export declare const ATTR_TOKEN = "data-token-hash";
|
|
6
|
+
export declare const ATTR_MARK = "data-css-hash";
|
|
7
|
+
export declare const ATTR_CACHE_PATH = "data-cache-path";
|
|
8
|
+
export declare const CSS_IN_JS_INSTANCE = "__cssinjs_instance__";
|
|
9
|
+
export declare function createCache(): CacheEntity;
|
|
10
|
+
export type HashPriority = 'low' | 'high';
|
|
11
|
+
export interface StyleContextProps {
|
|
12
|
+
autoClear?: boolean;
|
|
13
|
+
mock?: 'server' | 'client';
|
|
14
|
+
/**
|
|
15
|
+
* Only set when you need ssr to extract style on you own.
|
|
16
|
+
* If not provided, it will auto create <style /> on the end of Provider in server side.
|
|
17
|
+
*/
|
|
18
|
+
cache: CacheEntity;
|
|
19
|
+
/** Tell children that this context is default generated context */
|
|
20
|
+
defaultCache: boolean;
|
|
21
|
+
/** Use `:where` selector to reduce hashId css selector priority */
|
|
22
|
+
hashPriority?: HashPriority;
|
|
23
|
+
/** Tell cssinjs where to inject style in */
|
|
24
|
+
container?: Element | ShadowRoot;
|
|
25
|
+
/** Component wil render inline `<style />` for fallback in SSR. Not recommend. */
|
|
26
|
+
ssrInline?: boolean;
|
|
27
|
+
/** Transform css before inject in document. Please note that `transformers` do not support dynamic update */
|
|
28
|
+
transformers?: Transformer[];
|
|
29
|
+
/**
|
|
30
|
+
* Linters to lint css before inject in document.
|
|
31
|
+
* Styles will be linted after transforming.
|
|
32
|
+
* Please note that `linters` do not support dynamic update.
|
|
33
|
+
*/
|
|
34
|
+
linters?: Linter[];
|
|
35
|
+
/** Wrap css in a layer to avoid global style conflict */
|
|
36
|
+
layer?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export type StyleProviderProps = Partial<StyleContextProps>;
|
|
39
|
+
export declare const StyleProvider: import('vue').DefineSetupFnComponent<Partial<StyleContextProps>, {}, {}, Partial<StyleContextProps> & {}, import('vue').PublicProps>;
|
|
40
|
+
export declare function useStyleContext(): ComputedRef<StyleContextProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as Cache } from './Cache';
|
|
2
|
+
declare const ExtractStyleFns: {
|
|
3
|
+
style: import('./hooks/useGlobalCache').ExtractStyle<[styleStr: string, tokenKey: string, styleId: string, effectStyle: Record<string, string>, clientOnly: boolean | undefined, order: number]>;
|
|
4
|
+
token: import('./hooks/useGlobalCache').ExtractStyle<[token: any, hashId: string, realToken: any, cssVarStr: string, cssVarKey: string]>;
|
|
5
|
+
cssVar: import('./hooks/useGlobalCache').ExtractStyle<[cssVarToken: import('./util/css-variables').TokenWithCSSVar<any, Record<string, any>>, cssVarStr: string, styleId: string, cssVarKey: string]>;
|
|
6
|
+
};
|
|
7
|
+
type ExtractStyleType = keyof typeof ExtractStyleFns;
|
|
8
|
+
export default function extractStyle(cache: Cache, options?: boolean | {
|
|
9
|
+
plain?: boolean;
|
|
10
|
+
types?: ExtractStyleType | ExtractStyleType[];
|
|
11
|
+
}): string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MaybeRef } from 'vue';
|
|
2
|
+
import { TokenWithCSSVar } from '../util/css-variables';
|
|
3
|
+
import { ExtractStyle } from './useGlobalCache';
|
|
4
|
+
export declare const CSS_VAR_PREFIX = "cssVar";
|
|
5
|
+
type CSSVarCacheValue<V, T extends Record<string, V> = Record<string, V>> = [
|
|
6
|
+
cssVarToken: TokenWithCSSVar<V, T>,
|
|
7
|
+
cssVarStr: string,
|
|
8
|
+
styleId: string,
|
|
9
|
+
cssVarKey: string
|
|
10
|
+
];
|
|
11
|
+
declare function useCSSVarRegister<V, T extends Record<string, V>>(config: MaybeRef<{
|
|
12
|
+
path: string[];
|
|
13
|
+
key: string;
|
|
14
|
+
prefix?: string;
|
|
15
|
+
unitless?: Record<string, boolean>;
|
|
16
|
+
ignore?: Record<string, boolean>;
|
|
17
|
+
scope?: string;
|
|
18
|
+
token: any;
|
|
19
|
+
}>, fn: MaybeRef<() => T>): import('vue').ComputedRef<CSSVarCacheValue<V, T>>;
|
|
20
|
+
export declare const extract: ExtractStyle<CSSVarCacheValue<any>>;
|
|
21
|
+
export default useCSSVarRegister;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ComputedRef, MaybeRef } from 'vue';
|
|
2
|
+
import { default as Theme } from '../theme/Theme';
|
|
3
|
+
import { ExtractStyle } from './useGlobalCache';
|
|
4
|
+
export interface Option<DerivativeToken, DesignToken> {
|
|
5
|
+
/**
|
|
6
|
+
* Generate token with salt.
|
|
7
|
+
* This is used to generate different hashId even same derivative token for different version.
|
|
8
|
+
*/
|
|
9
|
+
salt?: string;
|
|
10
|
+
override?: object;
|
|
11
|
+
/**
|
|
12
|
+
* Format token as you need. Such as:
|
|
13
|
+
*
|
|
14
|
+
* - rename token
|
|
15
|
+
* - merge token
|
|
16
|
+
* - delete token
|
|
17
|
+
*
|
|
18
|
+
* This should always be the same since it's one time process.
|
|
19
|
+
* It's ok to useMemo outside but this has better cache strategy.
|
|
20
|
+
*/
|
|
21
|
+
formatToken?: (mergedToken: any) => DerivativeToken;
|
|
22
|
+
/**
|
|
23
|
+
* Get final token with origin token, override token and theme.
|
|
24
|
+
* The parameters do not contain formatToken since it's passed by user.
|
|
25
|
+
* @param origin The original token.
|
|
26
|
+
* @param override Extra tokens to override.
|
|
27
|
+
* @param theme Theme instance. Could get derivative token by `theme.getDerivativeToken`
|
|
28
|
+
*/
|
|
29
|
+
getComputedToken?: (origin: DesignToken, override: object, theme: Theme<any, any>) => DerivativeToken;
|
|
30
|
+
/**
|
|
31
|
+
* Transform token to css variables.
|
|
32
|
+
*/
|
|
33
|
+
cssVar?: {
|
|
34
|
+
/** Prefix for css variables */
|
|
35
|
+
prefix?: string;
|
|
36
|
+
/** Tokens that should not be appended with unit */
|
|
37
|
+
unitless?: Record<string, boolean>;
|
|
38
|
+
/** Tokens that should not be transformed to css variables */
|
|
39
|
+
ignore?: Record<string, boolean>;
|
|
40
|
+
/** Tokens that preserves origin value */
|
|
41
|
+
preserve?: Record<string, boolean>;
|
|
42
|
+
/** Key for current theme. Useful for customizing and should be unique */
|
|
43
|
+
key?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare function getComputedToken<DerivativeToken = object, DesignToken = DerivativeToken>(originToken: DesignToken, overrideToken: object, theme: Theme<any, any>, format?: (token: DesignToken) => DerivativeToken): any;
|
|
47
|
+
export declare const TOKEN_PREFIX = "token";
|
|
48
|
+
type TokenCacheValue<DerivativeToken> = [
|
|
49
|
+
token: DerivativeToken & {
|
|
50
|
+
_tokenKey: string;
|
|
51
|
+
_themeKey: string;
|
|
52
|
+
},
|
|
53
|
+
hashId: string,
|
|
54
|
+
realToken: DerivativeToken & {
|
|
55
|
+
_tokenKey: string;
|
|
56
|
+
},
|
|
57
|
+
cssVarStr: string,
|
|
58
|
+
cssVarKey: string
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* Cache theme derivative token as global shared one
|
|
62
|
+
* @param theme Theme entity
|
|
63
|
+
* @param tokens List of tokens, used for cache. Please do not dynamic generate object directly
|
|
64
|
+
* @param option Additional config
|
|
65
|
+
* @returns Call Theme.getDerivativeToken(tokenObject) to get token
|
|
66
|
+
*/
|
|
67
|
+
export default function useCacheToken<DerivativeToken = object, DesignToken = DerivativeToken>(theme: MaybeRef<Theme<any, any>>, tokens: MaybeRef<Partial<DesignToken>[]>, option?: MaybeRef<Option<DerivativeToken, DesignToken>>): ComputedRef<TokenCacheValue<DerivativeToken>>;
|
|
68
|
+
export declare const extract: ExtractStyle<TokenCacheValue<any>>;
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { MaybeRef } from '../interface.ts';
|
|
3
|
+
import { KeyType } from '../Cache';
|
|
4
|
+
export type ExtractStyle<CacheValue> = (cache: CacheValue, effectStyles: Record<string, boolean>, options?: {
|
|
5
|
+
plain?: boolean;
|
|
6
|
+
}) => [order: number, styleId: string, style: string] | null;
|
|
7
|
+
export default function useGlobalCache<CacheType>(prefix: MaybeRef<string>, keyPath: MaybeRef<KeyType[]>, cacheFn: () => CacheType, onCacheRemove?: (cache: CacheType, fromHMR: boolean) => void, onCacheEffect?: (cachedValue: CacheType) => void): ComputedRef<CacheType>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { MaybeRef } from 'vue';
|
|
3
|
+
import { Theme, Transformer } from '..';
|
|
4
|
+
import { default as Keyframes } from '../Keyframes';
|
|
5
|
+
import { Linter } from '../linters';
|
|
6
|
+
import { HashPriority } from '../StyleContext';
|
|
7
|
+
import { ExtractStyle } from './useGlobalCache';
|
|
8
|
+
import type * as CSS from 'csstype';
|
|
9
|
+
declare const SKIP_CHECK = "_skip_check_";
|
|
10
|
+
declare const MULTI_VALUE = "_multi_value_";
|
|
11
|
+
export interface LayerConfig {
|
|
12
|
+
name: string;
|
|
13
|
+
dependencies?: string[];
|
|
14
|
+
}
|
|
15
|
+
export type CSSProperties = Omit<CSS.PropertiesFallback<number | string>, 'animationName'> & {
|
|
16
|
+
animationName?: CSS.PropertiesFallback<number | string>['animationName'] | Keyframes;
|
|
17
|
+
};
|
|
18
|
+
export type CSSPropertiesWithMultiValues = {
|
|
19
|
+
[K in keyof CSSProperties]: CSSProperties[K] | readonly Extract<CSSProperties[K], string>[] | {
|
|
20
|
+
[SKIP_CHECK]?: boolean;
|
|
21
|
+
[MULTI_VALUE]?: boolean;
|
|
22
|
+
value: CSSProperties[K] | CSSProperties[K][];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type CSSPseudos = {
|
|
26
|
+
[K in CSS.Pseudos]?: CSSObject;
|
|
27
|
+
};
|
|
28
|
+
type ArrayCSSInterpolation = readonly CSSInterpolation[];
|
|
29
|
+
export type InterpolationPrimitive = null | undefined | boolean | number | string | CSSObject;
|
|
30
|
+
export type CSSInterpolation = InterpolationPrimitive | ArrayCSSInterpolation | Keyframes;
|
|
31
|
+
export type CSSOthersObject = Record<string, CSSInterpolation>;
|
|
32
|
+
export interface CSSObject extends CSSPropertiesWithMultiValues, CSSPseudos, CSSOthersObject {
|
|
33
|
+
}
|
|
34
|
+
export declare function normalizeStyle(styleStr: string): string;
|
|
35
|
+
export interface ParseConfig {
|
|
36
|
+
hashId?: string;
|
|
37
|
+
hashPriority?: HashPriority;
|
|
38
|
+
layer?: LayerConfig;
|
|
39
|
+
path?: string;
|
|
40
|
+
transformers?: Transformer[];
|
|
41
|
+
linters?: Linter[];
|
|
42
|
+
}
|
|
43
|
+
export interface ParseInfo {
|
|
44
|
+
root?: boolean;
|
|
45
|
+
injectHash?: boolean;
|
|
46
|
+
parentSelectors: string[];
|
|
47
|
+
}
|
|
48
|
+
export declare function parseStyle(interpolation: CSSInterpolation, config?: ParseConfig, { root, injectHash, parentSelectors }?: ParseInfo): [
|
|
49
|
+
parsedStr: string,
|
|
50
|
+
effectStyle: Record<string, string>
|
|
51
|
+
];
|
|
52
|
+
export declare function uniqueHash(path: (string | number)[], styleStr: string): string;
|
|
53
|
+
export declare const STYLE_PREFIX = "style";
|
|
54
|
+
type StyleCacheValue = [
|
|
55
|
+
styleStr: string,
|
|
56
|
+
tokenKey: string,
|
|
57
|
+
styleId: string,
|
|
58
|
+
effectStyle: Record<string, string>,
|
|
59
|
+
clientOnly: boolean | undefined,
|
|
60
|
+
order: number
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* Register a style to the global style sheet.
|
|
64
|
+
*/
|
|
65
|
+
export default function useStyleRegister(info: MaybeRef<{
|
|
66
|
+
theme: Theme<any, any>;
|
|
67
|
+
token: any;
|
|
68
|
+
path: string[];
|
|
69
|
+
hashId?: string;
|
|
70
|
+
layer?: LayerConfig;
|
|
71
|
+
nonce?: string | (() => string);
|
|
72
|
+
clientOnly?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Tell cssinjs the insert order of style.
|
|
75
|
+
* It's useful when you need to insert style
|
|
76
|
+
* before other style to overwrite for the same selector priority.
|
|
77
|
+
*/
|
|
78
|
+
order?: number;
|
|
79
|
+
}>, styleFn: MaybeRef<() => CSSInterpolation>): (node: VueNode) => any;
|
|
80
|
+
export declare const extract: ExtractStyle<StyleCacheValue>;
|
|
81
|
+
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CSSInterpolation, CSSObject, default as useStyleRegister } from './hooks/useStyleRegister';
|
|
2
|
+
import { Linter, legacyNotSelectorLinter, logicalPropertiesLinter, NaNLinter, parentSelectorLinter } from './linters';
|
|
3
|
+
import { StyleProviderProps, createCache, StyleProvider } from './StyleContext';
|
|
4
|
+
import { AbstractCalculator, DerivativeFunc, TokenType, createTheme, genCalc, Theme } from './theme';
|
|
5
|
+
import { Transformer } from './transformers/interface';
|
|
6
|
+
import { default as extractStyle } from './extractStyle';
|
|
7
|
+
import { default as useCacheToken, getComputedToken } from './hooks/useCacheToken';
|
|
8
|
+
import { default as useCSSVarRegister } from './hooks/useCSSVarRegister';
|
|
9
|
+
import { default as Keyframes } from './Keyframes';
|
|
10
|
+
import { default as legacyLogicalPropertiesTransformer } from './transformers/legacyLogicalProperties';
|
|
11
|
+
import { default as px2remTransformer } from './transformers/px2rem';
|
|
12
|
+
import { unit } from './util';
|
|
13
|
+
import { token2CSSVar } from './util/css-variables';
|
|
14
|
+
export { createCache, createTheme, extractStyle, genCalc, getComputedToken, Keyframes, legacyLogicalPropertiesTransformer, legacyNotSelectorLinter, logicalPropertiesLinter, NaNLinter, parentSelectorLinter, px2remTransformer, StyleProvider, Theme, token2CSSVar, unit, useCacheToken, useCSSVarRegister, useStyleRegister, };
|
|
15
|
+
export type { AbstractCalculator, CSSInterpolation, CSSObject, DerivativeFunc, Linter, StyleProviderProps, TokenType, Transformer, };
|
|
16
|
+
export declare const _experimental: {
|
|
17
|
+
supportModernCSS: () => boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as contentQuotesLinter } from './contentQuotesLinter';
|
|
2
|
+
export { default as hashedAnimationLinter } from './hashedAnimationLinter';
|
|
3
|
+
export type { Linter } from './interface';
|
|
4
|
+
export { default as legacyNotSelectorLinter } from './legacyNotSelectorLinter';
|
|
5
|
+
export { default as logicalPropertiesLinter } from './logicalPropertiesLinter';
|
|
6
|
+
export { default as NaNLinter } from './NaNLinter';
|
|
7
|
+
export { default as parentSelectorLinter } from './parentSelectorLinter';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DerivativeFunc, TokenType } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Theme with algorithms to derive tokens from design tokens.
|
|
4
|
+
* Use `createTheme` first which will help to manage the theme instance cache.
|
|
5
|
+
*/
|
|
6
|
+
export default class Theme<DesignToken extends TokenType, DerivativeToken extends TokenType> {
|
|
7
|
+
private derivatives;
|
|
8
|
+
readonly id: number;
|
|
9
|
+
constructor(derivatives: DerivativeFunc<DesignToken, DerivativeToken> | DerivativeFunc<DesignToken, DerivativeToken>[]);
|
|
10
|
+
getDerivativeToken(token: DesignToken): DerivativeToken;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DerivativeFunc } from './interface';
|
|
2
|
+
import { default as Theme } from './Theme';
|
|
3
|
+
type DerivativeOptions = DerivativeFunc<any, any>[];
|
|
4
|
+
export declare function sameDerivativeOption(left: DerivativeOptions, right: DerivativeOptions): boolean;
|
|
5
|
+
export default class ThemeCache {
|
|
6
|
+
static MAX_CACHE_SIZE: number;
|
|
7
|
+
static MAX_CACHE_OFFSET: number;
|
|
8
|
+
private readonly cache;
|
|
9
|
+
private keys;
|
|
10
|
+
private cacheCallTimes;
|
|
11
|
+
constructor();
|
|
12
|
+
size(): number;
|
|
13
|
+
private internalGet;
|
|
14
|
+
get(derivativeOption: DerivativeOptions): Theme<any, any> | undefined;
|
|
15
|
+
has(derivativeOption: DerivativeOptions): boolean;
|
|
16
|
+
set(derivativeOption: DerivativeOptions, value: Theme<any, any>): void;
|
|
17
|
+
private deleteByPath;
|
|
18
|
+
delete(derivativeOption: DerivativeOptions): Theme<any, any> | undefined;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as AbstractCalculator } from './calculator';
|
|
2
|
+
export default class CSSCalculator extends AbstractCalculator {
|
|
3
|
+
result: string;
|
|
4
|
+
unitlessCssVar: Set<string>;
|
|
5
|
+
lowPriority?: boolean;
|
|
6
|
+
constructor(num: number | string | AbstractCalculator, unitlessCssVar: Set<string>);
|
|
7
|
+
add(num: number | string | AbstractCalculator): this;
|
|
8
|
+
sub(num: number | string | AbstractCalculator): this;
|
|
9
|
+
mul(num: number | string | AbstractCalculator): this;
|
|
10
|
+
div(num: number | string | AbstractCalculator): this;
|
|
11
|
+
getResult(force?: boolean): string;
|
|
12
|
+
equal(options?: {
|
|
13
|
+
unit?: boolean;
|
|
14
|
+
}): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as AbstractCalculator } from './calculator';
|
|
2
|
+
export default class NumCalculator extends AbstractCalculator {
|
|
3
|
+
result: number;
|
|
4
|
+
constructor(num: number | string | AbstractCalculator);
|
|
5
|
+
add(num: number | string | AbstractCalculator): this;
|
|
6
|
+
sub(num: number | string | AbstractCalculator): this;
|
|
7
|
+
mul(num: number | string | AbstractCalculator): this;
|
|
8
|
+
div(num: number | string | AbstractCalculator): this;
|
|
9
|
+
equal(): number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare abstract class AbstractCalculator {
|
|
2
|
+
/**
|
|
3
|
+
* @descCN 计算两数的和,例如:1 + 2
|
|
4
|
+
* @descEN Calculate the sum of two numbers, e.g. 1 + 2
|
|
5
|
+
*/
|
|
6
|
+
abstract add(num: number | string | AbstractCalculator): this;
|
|
7
|
+
/**
|
|
8
|
+
* @descCN 计算两数的差,例如:1 - 2
|
|
9
|
+
* @descEN Calculate the difference between two numbers, e.g. 1 - 2
|
|
10
|
+
*/
|
|
11
|
+
abstract sub(num: number | string | AbstractCalculator): this;
|
|
12
|
+
/**
|
|
13
|
+
* @descCN 计算两数的积,例如:1 * 2
|
|
14
|
+
* @descEN Calculate the product of two numbers, e.g. 1 * 2
|
|
15
|
+
*/
|
|
16
|
+
abstract mul(num: number | string | AbstractCalculator): this;
|
|
17
|
+
/**
|
|
18
|
+
* @descCN 计算两数的商,例如:1 / 2
|
|
19
|
+
* @descEN Calculate the quotient of two numbers, e.g. 1 / 2
|
|
20
|
+
*/
|
|
21
|
+
abstract div(num: number | string | AbstractCalculator): this;
|
|
22
|
+
/**
|
|
23
|
+
* @descCN 获取计算结果
|
|
24
|
+
* @descEN Get the calculation result
|
|
25
|
+
*/
|
|
26
|
+
abstract equal(options?: {
|
|
27
|
+
unit?: boolean;
|
|
28
|
+
}): string | number;
|
|
29
|
+
}
|
|
30
|
+
export default AbstractCalculator;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as AbstractCalculator } from './calculator';
|
|
2
|
+
import { default as CSSCalculator } from './CSSCalculator';
|
|
3
|
+
import { default as NumCalculator } from './NumCalculator';
|
|
4
|
+
declare function genCalc(type: 'css' | 'js', unitlessCssVar: Set<string>): (num: number | string | AbstractCalculator) => CSSCalculator | NumCalculator;
|
|
5
|
+
export default genCalc;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DerivativeFunc, TokenType } from './interface';
|
|
2
|
+
import { default as Theme } from './Theme';
|
|
3
|
+
/**
|
|
4
|
+
* Same as new Theme, but will always return same one if `derivative` not changed.
|
|
5
|
+
*/
|
|
6
|
+
export default function createTheme<DesignToken extends TokenType, DerivativeToken extends TokenType>(derivatives: DerivativeFunc<DesignToken, DerivativeToken>[] | DerivativeFunc<DesignToken, DerivativeToken>): Theme<any, any>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as genCalc } from './calc';
|
|
2
|
+
export type { default as AbstractCalculator } from './calc/calculator';
|
|
3
|
+
export { default as createTheme } from './createTheme';
|
|
4
|
+
export type { DerivativeFunc, TokenType } from './interface';
|
|
5
|
+
export { default as Theme } from './Theme';
|
|
6
|
+
export { default as ThemeCache } from './ThemeCache';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Transformer } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Convert css logical properties to legacy properties.
|
|
4
|
+
* Such as: `margin-block-start` to `margin-top`.
|
|
5
|
+
* Transform list:
|
|
6
|
+
* - inset
|
|
7
|
+
* - margin
|
|
8
|
+
* - padding
|
|
9
|
+
* - border
|
|
10
|
+
*/
|
|
11
|
+
declare const transform: Transformer;
|
|
12
|
+
export default transform;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Transformer } from './interface';
|
|
2
|
+
interface Options {
|
|
3
|
+
/**
|
|
4
|
+
* The root font size.
|
|
5
|
+
* @default 16
|
|
6
|
+
*/
|
|
7
|
+
rootValue?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The decimal numbers to allow the REM units to grow to.
|
|
10
|
+
* @default 5
|
|
11
|
+
*/
|
|
12
|
+
precision?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to allow px to be converted in media queries.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
mediaQuery?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare function transform(options?: Options): Transformer;
|
|
20
|
+
export default transform;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ATTR_CACHE_MAP = "data-ant-cssinjs-cache-path";
|
|
2
|
+
/**
|
|
3
|
+
* This marks style from the css file.
|
|
4
|
+
* Which means not exist in `<style />` tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CSS_FILE_STYLE = "_FILE_STYLE__";
|
|
7
|
+
export declare function serialize(cachePathMap: Record<string, string>): string;
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export declare function reset(mockCache?: Record<string, string>, fromFile?: boolean): void;
|
|
12
|
+
export declare function prepare(): void;
|
|
13
|
+
export declare function existPath(path: string): boolean;
|
|
14
|
+
export declare function getStyleAndHash(path: string): [style: string | null, hash: string];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function token2CSSVar(token: string, prefix?: string): string;
|
|
2
|
+
export declare function serializeCSSVar<T extends Record<string, any>>(cssVars: T, hashId: string, options?: {
|
|
3
|
+
scope?: string;
|
|
4
|
+
}): string;
|
|
5
|
+
export type TokenWithCSSVar<V, T extends Record<string, V> = Record<string, V>> = {
|
|
6
|
+
[key in keyof T]?: string | V;
|
|
7
|
+
};
|
|
8
|
+
export declare function transformToken<V, T extends Record<string, V> = Record<string, V>>(token: T, themeKey: string, config?: {
|
|
9
|
+
prefix?: string;
|
|
10
|
+
ignore?: {
|
|
11
|
+
[key in keyof T]?: boolean;
|
|
12
|
+
};
|
|
13
|
+
unitless?: {
|
|
14
|
+
[key in keyof T]?: boolean;
|
|
15
|
+
};
|
|
16
|
+
preserve?: {
|
|
17
|
+
[key in keyof T]?: boolean;
|
|
18
|
+
};
|
|
19
|
+
scope?: string;
|
|
20
|
+
}): [TokenWithCSSVar<V, T>, string];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function memoResult<T extends object, R>(callback: () => R, deps: T[]): R;
|
|
2
|
+
/**
|
|
3
|
+
* Flatten token to string, this will auto cache the result when token not change
|
|
4
|
+
*/
|
|
5
|
+
export declare function flattenToken(token: any, hashed?: boolean): string;
|
|
6
|
+
/**
|
|
7
|
+
* Convert derivative token to key string
|
|
8
|
+
*/
|
|
9
|
+
export declare function token2key(token: any, salt: string): string;
|
|
10
|
+
export declare function supportLayer(): boolean;
|
|
11
|
+
export declare function supportWhere(): boolean;
|
|
12
|
+
export declare function supportLogicProps(): boolean;
|
|
13
|
+
export declare const isClientSide: boolean;
|
|
14
|
+
export declare function unit(num: string | number): string;
|
|
15
|
+
export declare function toStyleStr(style: string, tokenKey?: string, styleId?: string, customizeAttrs?: Record<string, string>, plain?: boolean): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antdv-next/cssinjs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "Component level cssinjs resolution for antdv-next",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "aibayanyu20",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"test:watch": "vitest",
|
|
82
82
|
"coverage": "vitest run --coverage",
|
|
83
83
|
"lint": "eslint . --fix",
|
|
84
|
-
"release": "bumpp"
|
|
84
|
+
"release": "bumpp",
|
|
85
|
+
"prepublish": "pnpm build"
|
|
85
86
|
}
|
|
86
87
|
}
|