useStyleRegister.d.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type * as CSS from 'csstype';
  2. import * as React from 'react';
  3. import type { Theme, Transformer } from '..';
  4. import type Keyframes from '../Keyframes';
  5. import type { Linter } from '../linters';
  6. import type { HashPriority } from '../StyleContext';
  7. import type { ExtractStyle } from './useGlobalCache';
  8. declare const SKIP_CHECK = "_skip_check_";
  9. declare const MULTI_VALUE = "_multi_value_";
  10. export interface LayerConfig {
  11. name: string;
  12. dependencies?: string[];
  13. }
  14. export type CSSProperties = Omit<CSS.PropertiesFallback<number | string>, 'animationName'> & {
  15. animationName?: CSS.PropertiesFallback<number | string>['animationName'] | Keyframes;
  16. };
  17. export type CSSPropertiesWithMultiValues = {
  18. [K in keyof CSSProperties]: CSSProperties[K] | readonly Extract<CSSProperties[K], string>[] | {
  19. [SKIP_CHECK]?: boolean;
  20. [MULTI_VALUE]?: boolean;
  21. value: CSSProperties[K] | CSSProperties[K][];
  22. };
  23. };
  24. export type CSSPseudos = {
  25. [K in CSS.Pseudos]?: CSSObject;
  26. };
  27. type ArrayCSSInterpolation = readonly CSSInterpolation[];
  28. export type InterpolationPrimitive = null | undefined | boolean | number | string | CSSObject;
  29. export type CSSInterpolation = InterpolationPrimitive | ArrayCSSInterpolation | Keyframes;
  30. export type CSSOthersObject = Record<string, CSSInterpolation>;
  31. export interface CSSObject extends CSSPropertiesWithMultiValues, CSSPseudos, CSSOthersObject {
  32. }
  33. export declare function normalizeStyle(styleStr: string): string;
  34. export interface ParseConfig {
  35. hashId?: string;
  36. hashPriority?: HashPriority;
  37. layer?: LayerConfig;
  38. path?: string;
  39. transformers?: Transformer[];
  40. linters?: Linter[];
  41. }
  42. export interface ParseInfo {
  43. root?: boolean;
  44. injectHash?: boolean;
  45. parentSelectors: string[];
  46. }
  47. export declare const parseStyle: (interpolation: CSSInterpolation, config?: ParseConfig, { root, injectHash, parentSelectors }?: ParseInfo) => [parsedStr: string, effectStyle: Record<string, string>];
  48. export declare function uniqueHash(path: (string | number)[], styleStr: string): string;
  49. export declare const STYLE_PREFIX = "style";
  50. type StyleCacheValue = [
  51. styleStr: string,
  52. tokenKey: string,
  53. styleId: string,
  54. effectStyle: Record<string, string>,
  55. clientOnly: boolean | undefined,
  56. order: number
  57. ];
  58. /**
  59. * Register a style to the global style sheet.
  60. */
  61. export default function useStyleRegister(info: {
  62. theme: Theme<any, any>;
  63. token: any;
  64. path: string[];
  65. hashId?: string;
  66. layer?: LayerConfig;
  67. nonce?: string | (() => string);
  68. clientOnly?: boolean;
  69. /**
  70. * Tell cssinjs the insert order of style.
  71. * It's useful when you need to insert style
  72. * before other style to overwrite for the same selector priority.
  73. */
  74. order?: number;
  75. }, styleFn: () => CSSInterpolation): (node: React.ReactElement) => React.JSX.Element;
  76. export declare const extract: ExtractStyle<StyleCacheValue>;
  77. export {};