| |
|
|
| type Exclude<A, B> = A; |
| |
| type $FlowGen$If<X: boolean, Then, Else = empty> = $Call< |
| ((true, Then, Else) => Then) & ((false, Then, Else) => Else), |
| X, |
| Then, |
| Else |
| >; |
|
|
| type $FlowGen$Assignable<A, B> = $Call< |
| ((...r: [B]) => true) & ((...r: [A]) => false), |
| A |
| >; |
|
|
| import type { |
| Angle, |
| CssColor, |
| Rule, |
| CustomProperty, |
| EnvironmentVariable, |
| Function, |
| Image, |
| LengthValue, |
| MediaQuery, |
| Declaration, |
| Ratio, |
| Resolution, |
| Selector, |
| SupportsCondition, |
| Time, |
| Token, |
| TokenOrValue, |
| UnknownAtRule, |
| Url, |
| Variable, |
| StyleRule, |
| DeclarationBlock, |
| ParsedComponent, |
| Multiplier, |
| StyleSheet, |
| Location2, |
| } from "./ast.js.flow"; |
| import { Targets, Features } from "./targets.js.flow"; |
| declare export * from "./ast.js.flow"; |
| declare export { Targets, Features }; |
| export type TransformOptions<C: CustomAtRules> = {| |
| |
| |
| |
| filename: string, |
|
|
| |
| |
| |
| code: Uint8Array, |
|
|
| |
| |
| |
| minify?: boolean, |
|
|
| |
| |
| |
| sourceMap?: boolean, |
|
|
| |
| |
| |
| inputSourceMap?: string, |
|
|
| |
| |
| |
| |
| projectRoot?: string, |
|
|
| |
| |
| |
| targets?: Targets, |
|
|
| |
| |
| |
| include?: number, |
|
|
| |
| |
| |
| exclude?: number, |
|
|
| |
| |
| |
| drafts?: Drafts, |
|
|
| |
| |
| |
| nonStandard?: NonStandard, |
|
|
| |
| |
| |
| cssModules?: boolean | CSSModulesConfig, |
|
|
| |
| |
| |
| |
| |
| |
| analyzeDependencies?: boolean | DependencyOptions, |
|
|
| |
| |
| |
| |
| pseudoClasses?: PseudoClasses, |
|
|
| |
| |
| |
| |
| |
| unusedSymbols?: string[], |
|
|
| |
| |
| |
| |
| |
| errorRecovery?: boolean, |
|
|
| |
| |
| |
| |
| |
| |
| visitor?: Visitor<C>, |
|
|
| |
| |
| |
| |
| |
| |
| customAtRules?: C, |
| |}; |
| declare type PropertyStart = |
| | "-" |
| | "_" |
| | "a" |
| | "b" |
| | "c" |
| | "d" |
| | "e" |
| | "f" |
| | "g" |
| | "h" |
| | "i" |
| | "j" |
| | "k" |
| | "l" |
| | "m" |
| | "n" |
| | "o" |
| | "p" |
| | "q" |
| | "r" |
| | "s" |
| | "t" |
| | "u" |
| | "v" |
| | "w" |
| | "x" |
| | "y" |
| | "z"; |
| export type ReturnedDeclaration = |
| | Declaration |
| | {| |
| |
| |
| |
| property: string, |
|
|
| |
| |
| |
| raw: string, |
| |}; |
| export type ReturnedMediaQuery = |
| | MediaQuery |
| | {| |
| |
| |
| |
| raw: string, |
| |}; |
| declare type FindByType<Union, Name> = $FlowGen$If< |
| $FlowGen$Assignable< |
| Union, |
| {| |
| type: Name, |
| |} |
| >, |
| Union, |
| empty |
| >; |
| export type ReturnedRule = Rule<ReturnedDeclaration, ReturnedMediaQuery>; |
| declare type RequiredValue<Rule> = $FlowGen$If< |
| $FlowGen$Assignable< |
| Rule, |
| {| |
| value: { [key: string]: any }, |
| |} |
| >, |
| $FlowGen$If< |
| $FlowGen$Assignable<$PropertyType<Rule, "value">, StyleRule>, |
| {| |
| ...Rule, |
| ...{| |
| value: {| |
| ...Required<StyleRule>, |
| ...{| |
| declarations: Required<DeclarationBlock>, |
| |}, |
| |}, |
| |}, |
| |}, |
| {| |
| ...Rule, |
| ...{| |
| value: Required<$PropertyType<Rule, "value">>, |
| |}, |
| |} |
| >, |
| Rule |
| >; |
| declare type RuleVisitor<R = RequiredValue<Rule>> = ( |
| rule: R |
| ) => ReturnedRule | ReturnedRule[] | void; |
| declare type MappedRuleVisitors = $ObjMapi< |
| { [k: Exclude<$PropertyType<Rule, "type">, "unknown" | "custom">]: any }, |
| <Name>(Name) => RuleVisitor<RequiredValue<FindByType<Rule, Name>>> |
| >; |
| declare type UnknownVisitors<T> = { |
| [name: string]: RuleVisitor<T>, |
| }; |
| declare type CustomVisitors<T: CustomAtRules> = $ObjMapi< |
| T, |
| <Name>(Name) => RuleVisitor<CustomAtRule<Name, $ElementType<T, Name>>> |
| >; |
| declare type AnyCustomAtRule<C: CustomAtRules> = $ElementType< |
| $ObjMapi<C, <Key>(Key) => CustomAtRule<Key, $ElementType<C, Key>>>, |
| $Keys<C> |
| >; |
| declare type RuleVisitors<C: CustomAtRules> = {| |
| ...MappedRuleVisitors, |
| ...{| |
| unknown?: |
| | UnknownVisitors<UnknownAtRule> |
| | $Diff< |
| RuleVisitor<UnknownAtRule>, |
| { [key: $Keys<CallableFunction>]: any } |
| >, |
| custom?: |
| | CustomVisitors<C> |
| | $Diff< |
| RuleVisitor<AnyCustomAtRule<C>>, |
| { [key: $Keys<CallableFunction>]: any } |
| >, |
| |}, |
| |}; |
| declare type PreludeTypes = Exclude< |
| $PropertyType<ParsedComponent, "type">, |
| "literal" | "repeated" | "token" |
| >; |
| declare type SyntaxString = string | string; |
| declare type ComponentTypes = $ObjMapi< |
| { [k: PreludeTypes]: any }, |
| <Key>(Key) => FindByType<ParsedComponent, Key> |
| >; |
| declare type Repetitions = $ObjMapi< |
| { [k: PreludeTypes]: any }, |
| <Key>(Key) => {| |
| type: "repeated", |
| value: {| |
| components: FindByType<ParsedComponent, Key>[], |
| multiplier: Multiplier, |
| |}, |
| |} |
| >; |
| declare type MappedPrelude = {| ...ComponentTypes, ...Repetitions |}; |
| declare type MappedBody<P: $PropertyType<CustomAtRuleDefinition, "body">> = |
| $FlowGen$If<$FlowGen$Assignable<P, "style-block">, "rule-list", P>; |
| declare type CustomAtRule<N, R: CustomAtRuleDefinition> = {| |
| name: N, |
| prelude: $FlowGen$If< |
| $FlowGen$Assignable<$PropertyType<R, "prelude">, $Keys<MappedPrelude>>, |
| $ElementType<MappedPrelude, $PropertyType<R, "prelude">>, |
| ParsedComponent |
| >, |
| body: FindByType<CustomAtRuleBody, MappedBody<$PropertyType<R, "body">>>, |
| loc: Location2, |
| |}; |
| declare type CustomAtRuleBody = |
| | {| |
| type: "declaration-list", |
| value: Required<DeclarationBlock>, |
| |} |
| | {| |
| type: "rule-list", |
| value: RequiredValue<Rule>[], |
| |}; |
| declare type FindProperty<Union, Name> = $FlowGen$If< |
| $FlowGen$Assignable< |
| Union, |
| {| |
| property: Name, |
| |} |
| >, |
| Union, |
| empty |
| >; |
| declare type DeclarationVisitor<P = Declaration> = ( |
| property: P |
| ) => ReturnedDeclaration | ReturnedDeclaration[] | void; |
| declare type MappedDeclarationVisitors = $ObjMapi< |
| { |
| [k: Exclude< |
| $PropertyType<Declaration, "property">, |
| "unparsed" | "custom" |
| >]: any, |
| }, |
| <Name>( |
| Name |
| ) => DeclarationVisitor< |
| FindProperty<Declaration, Name> | FindProperty<Declaration, "unparsed"> |
| > |
| >; |
| declare type CustomPropertyVisitors = { |
| [name: string]: DeclarationVisitor<CustomProperty>, |
| }; |
| declare type DeclarationVisitors = {| |
| ...MappedDeclarationVisitors, |
| ...{| |
| custom?: CustomPropertyVisitors | DeclarationVisitor<CustomProperty>, |
| |}, |
| |}; |
| declare type RawValue = {| |
| |
| |
| |
| raw: string, |
| |}; |
| declare type TokenReturnValue = TokenOrValue | TokenOrValue[] | RawValue | void; |
| declare type TokenVisitor = (token: Token) => TokenReturnValue; |
| declare type VisitableTokenTypes = |
| | "ident" |
| | "at-keyword" |
| | "hash" |
| | "id-hash" |
| | "string" |
| | "number" |
| | "percentage" |
| | "dimension"; |
| declare type TokenVisitors = $ObjMapi< |
| { [k: VisitableTokenTypes]: any }, |
| <Name>(Name) => (token: FindByType<Token, Name>) => TokenReturnValue |
| >; |
| declare type FunctionVisitor = (fn: Function) => TokenReturnValue; |
| declare type EnvironmentVariableVisitor = ( |
| env: EnvironmentVariable |
| ) => TokenReturnValue; |
| declare type EnvironmentVariableVisitors = { |
| [name: string]: EnvironmentVariableVisitor, |
| }; |
| export type Visitor<C: CustomAtRules> = {| |
| StyleSheet?: ( |
| stylesheet: StyleSheet |
| ) => StyleSheet<ReturnedDeclaration, ReturnedMediaQuery> | void, |
| StyleSheetExit?: ( |
| stylesheet: StyleSheet |
| ) => StyleSheet<ReturnedDeclaration, ReturnedMediaQuery> | void, |
| Rule?: RuleVisitor<> | RuleVisitors<C>, |
| RuleExit?: RuleVisitor<> | RuleVisitors<C>, |
| Declaration?: DeclarationVisitor<> | DeclarationVisitors, |
| DeclarationExit?: DeclarationVisitor<> | DeclarationVisitors, |
| Url?: (url: Url) => Url | void, |
| Color?: (color: CssColor) => CssColor | void, |
| Image?: (image: Image) => Image | void, |
| ImageExit?: (image: Image) => Image | void, |
| Length?: (length: LengthValue) => LengthValue | void, |
| Angle?: (angle: Angle) => Angle | void, |
| Ratio?: (ratio: Ratio) => Ratio | void, |
| Resolution?: (resolution: Resolution) => Resolution | void, |
| Time?: (time: Time) => Time | void, |
| CustomIdent?: (ident: string) => string | void, |
| DashedIdent?: (ident: string) => string | void, |
| MediaQuery?: ( |
| query: MediaQuery |
| ) => ReturnedMediaQuery | ReturnedMediaQuery[] | void, |
| MediaQueryExit?: ( |
| query: MediaQuery |
| ) => ReturnedMediaQuery | ReturnedMediaQuery[] | void, |
| SupportsCondition?: (condition: SupportsCondition) => SupportsCondition, |
| SupportsConditionExit?: (condition: SupportsCondition) => SupportsCondition, |
| Selector?: (selector: Selector) => Selector | Selector[] | void, |
| Token?: TokenVisitor | TokenVisitors, |
| Function?: |
| | FunctionVisitor |
| | { |
| [name: string]: FunctionVisitor, |
| }, |
| FunctionExit?: |
| | FunctionVisitor |
| | { |
| [name: string]: FunctionVisitor, |
| }, |
| Variable?: (variable: Variable) => TokenReturnValue, |
| VariableExit?: (variable: Variable) => TokenReturnValue, |
| EnvironmentVariable?: |
| | EnvironmentVariableVisitor |
| | EnvironmentVariableVisitors, |
| EnvironmentVariableExit?: |
| | EnvironmentVariableVisitor |
| | EnvironmentVariableVisitors, |
| |}; |
| export type CustomAtRules = {| |
| [name: string]: CustomAtRuleDefinition, |
| |}; |
| export type CustomAtRuleDefinition = {| |
| |
| |
| |
| |
| |
| |
| prelude?: SyntaxString | null, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| body?: "declaration-list" | "rule-list" | "style-block" | null, |
| |}; |
| export type DependencyOptions = {| |
| |
| |
| |
| preserveImports?: boolean, |
| |}; |
| export type BundleOptions<C: CustomAtRules> = $Diff< |
| TransformOptions<C>, |
| {| code: any |} |
| >; |
| export type BundleAsyncOptions<C: CustomAtRules> = {| |
| ...$Exact<BundleOptions<C>>, |
|
|
| resolver?: Resolver, |
| |}; |
|
|
| |
| |
| |
| export type Resolver = {| |
| |
| |
| |
| read?: (file: string) => string | Promise<string>, |
|
|
| |
| |
| |
| |
| resolve?: ( |
| specifier: string, |
| originatingFile: string |
| ) => string | Promise<string>, |
| |}; |
| export type Drafts = {| |
| |
| |
| |
| customMedia?: boolean, |
| |}; |
| export type NonStandard = {| |
| |
| |
| |
| deepSelectorCombinator?: boolean, |
| |}; |
| export type PseudoClasses = {| |
| hover?: string, |
| active?: string, |
| focus?: string, |
| focusVisible?: string, |
| focusWithin?: string, |
| |}; |
| export type TransformResult = {| |
| |
| |
| |
| code: Uint8Array, |
|
|
| |
| |
| |
| map: Uint8Array | void, |
|
|
| |
| |
| |
| exports: CSSModuleExports | void, |
|
|
| |
| |
| |
| references: CSSModuleReferences, |
|
|
| |
| |
| |
| dependencies: Dependency[] | void, |
|
|
| |
| |
| |
| warnings: Warning[], |
| |}; |
| export type Warning = {| |
| message: string, |
| type: string, |
| value?: any, |
| loc: ErrorLocation, |
| |}; |
| export type CSSModulesConfig = {| |
| |
| |
| |
| pattern?: string, |
|
|
| |
| |
| |
| dashedIdents?: boolean, |
|
|
| |
| |
| |
| animation?: boolean, |
|
|
| |
| |
| |
| grid?: boolean, |
|
|
| |
| |
| |
| container?: boolean, |
|
|
| |
| |
| |
| customIdents?: boolean, |
|
|
| |
| |
| |
| pure?: boolean, |
| |}; |
| export type CSSModuleExports = { |
| |
| |
| |
| [name: string]: CSSModuleExport, |
| }; |
| export type CSSModuleExport = {| |
| |
| |
| |
| name: string, |
|
|
| |
| |
| |
| isReferenced: boolean, |
|
|
| |
| |
| |
| composes: CSSModuleReference[], |
| |}; |
| export type CSSModuleReferences = { |
| |
| |
| |
| [name: string]: DependencyCSSModuleReference, |
| }; |
| export type CSSModuleReference = |
| | LocalCSSModuleReference |
| | GlobalCSSModuleReference |
| | DependencyCSSModuleReference; |
| export type LocalCSSModuleReference = {| |
| type: "local", |
|
|
| |
| |
| |
| name: string, |
| |}; |
| export type GlobalCSSModuleReference = {| |
| type: "global", |
|
|
| |
| |
| |
| name: string, |
| |}; |
| export type DependencyCSSModuleReference = {| |
| type: "dependency", |
|
|
| |
| |
| |
| name: string, |
|
|
| |
| |
| |
| specifier: string, |
| |}; |
| export type Dependency = ImportDependency | UrlDependency; |
| export type ImportDependency = {| |
| type: "import", |
|
|
| |
| |
| |
| url: string, |
|
|
| |
| |
| |
| media: string | null, |
|
|
| |
| |
| |
| supports: string | null, |
|
|
| |
| |
| |
| loc: SourceLocation, |
|
|
| |
| |
| |
| placeholder: string, |
| |}; |
| export type UrlDependency = {| |
| type: "url", |
|
|
| |
| |
| |
| url: string, |
|
|
| |
| |
| |
| loc: SourceLocation, |
|
|
| |
| |
| |
| placeholder: string, |
| |}; |
| export type SourceLocation = {| |
| |
| |
| |
| filePath: string, |
|
|
| |
| |
| |
| start: Location, |
|
|
| |
| |
| |
| end: Location, |
| |}; |
| export type Location = {| |
| |
| |
| |
| line: number, |
|
|
| |
| |
| |
| column: number, |
| |}; |
| export type ErrorLocation = {| |
| ...$Exact<Location>, |
|
|
| filename: string, |
| |}; |
|
|
| |
| |
| |
| |
| declare export function transform<C: CustomAtRules>( |
| options: TransformOptions<C> |
| ): TransformResult; |
| export type TransformAttributeOptions = {| |
| |
| |
| |
| filename?: string, |
|
|
| |
| |
| |
| code: Uint8Array, |
|
|
| |
| |
| |
| minify?: boolean, |
|
|
| |
| |
| |
| targets?: Targets, |
|
|
| |
| |
| |
| |
| |
| |
| analyzeDependencies?: boolean, |
|
|
| |
| |
| |
| |
| |
| errorRecovery?: boolean, |
|
|
| |
| |
| |
| |
| |
| |
| visitor?: Visitor<empty>, |
| |}; |
| export type TransformAttributeResult = {| |
| |
| |
| |
| code: Uint8Array, |
|
|
| |
| |
| |
| dependencies: Dependency[] | void, |
|
|
| |
| |
| |
| warnings: Warning[], |
| |}; |
|
|
| |
| |
| |
| declare export function transformStyleAttribute( |
| options: TransformAttributeOptions |
| ): TransformAttributeResult; |
|
|
| /** |
| * Converts a browserslist result into targets that can be passed to lightningcss. |
| * @param browserslist the result of calling string |
| */ |
| declare export function browserslistToTargets(browserslist: string[]): Targets; |
|
|
| /** |
| * Bundles a CSS file and its dependencies, inlining @import rules. |
| */ |
| declare export function bundle<C: CustomAtRules>( |
| options: BundleOptions<C> |
| ): TransformResult; |
|
|
| /** |
| * Bundles a CSS file and its dependencies asynchronously, inlining @import rules. |
| */ |
| declare export function bundleAsync<C: CustomAtRules>( |
| options: BundleAsyncOptions<C> |
| ): Promise<TransformResult>; |
|
|
| /** |
| * Composes multiple visitor objects into a single one. |
| */ |
| declare export function composeVisitors<C: CustomAtRules>( |
| visitors: Visitor<C>[] |
| ): Visitor<C>; |
|
|