UNPKG

6.98 kBTypeScriptView Raw
1import postcss from 'postcss';
2import { FileProcessor } from './cached-process-file';
3import { Diagnostics } from './diagnostics';
4import { SelectorAstNode, SelectorChunk2 } from './selector-utils';
5import { ClassSymbol, ElementSymbol, StylableMeta, StylableSymbol } from './stylable-processor';
6import { CSSResolve, StylableResolver } from './stylable-resolver';
7export interface ResolvedElement {
8 name: string;
9 type: string;
10 resolved: Array<CSSResolve<ClassSymbol | ElementSymbol>>;
11}
12export interface KeyFrameWithNode {
13 value: string;
14 node: postcss.Node;
15}
16export interface StylableExports {
17 classes: Record<string, string>;
18 vars: Record<string, string>;
19 stVars: Record<string, string>;
20 keyframes: Record<string, string>;
21}
22export interface StylableResults {
23 meta: StylableMeta;
24 exports: StylableExports;
25}
26export interface ScopedSelectorResults {
27 current: StylableMeta;
28 symbol: StylableSymbol | null;
29 selectorAst: SelectorAstNode;
30 selector: string;
31 elements: ResolvedElement[][];
32}
33export declare type replaceValueHook = (value: string, name: string | {
34 name: string;
35 args: string[];
36}, isLocal: boolean, passedThrough: string[]) => string;
37export declare type postProcessor<T = {}> = (stylableResults: StylableResults, transformer: StylableTransformer) => StylableResults & T;
38export interface TransformHooks {
39 postProcessor?: postProcessor;
40 replaceValueHook?: replaceValueHook;
41}
42declare type EnvMode = 'production' | 'development';
43export interface TransformerOptions {
44 fileProcessor: FileProcessor<StylableMeta>;
45 requireModule: (modulePath: string) => any;
46 diagnostics: Diagnostics;
47 delimiter?: string;
48 keepValues?: boolean;
49 replaceValueHook?: replaceValueHook;
50 postProcessor?: postProcessor;
51 mode?: EnvMode;
52}
53export interface AdditionalSelector {
54 selectorNode: SelectorAstNode;
55 node: SelectorAstNode;
56 customElementChunk: string;
57}
58export declare const transformerWarnings: {
59 UNKNOWN_PSEUDO_ELEMENT(name: string): string;
60 IMPORT_ISNT_EXTENDABLE(): string;
61 CANNOT_EXTEND_UNKNOWN_SYMBOL(name: string): string;
62 CANNOT_EXTEND_JS(): string;
63 KEYFRAME_NAME_RESERVED(name: string): string;
64 UNKNOWN_IMPORT_ALIAS(name: string): string;
65 SCOPE_PARAM_NOT_ROOT(name: string): string;
66 SCOPE_PARAM_NOT_CSS(name: string): string;
67 UNKNOWN_SCOPING_PARAM(name: string): string;
68};
69export declare class StylableTransformer {
70 fileProcessor: FileProcessor<StylableMeta>;
71 diagnostics: Diagnostics;
72 resolver: StylableResolver;
73 delimiter: string;
74 keepValues: boolean;
75 replaceValueHook: replaceValueHook | undefined;
76 postProcessor: postProcessor | undefined;
77 mode: EnvMode;
78 private metaParts;
79 constructor(options: TransformerOptions);
80 transform(meta: StylableMeta): StylableResults;
81 transformAst(ast: postcss.Root, meta: StylableMeta, metaExports?: StylableExports, variableOverride?: Record<string, string>, path?: string[], mixinTransform?: boolean): void;
82 exportLocalVars(meta: StylableMeta, stVarsExport: Record<string, string>, variableOverride?: Record<string, string>): void;
83 exportCSSVars(cssVarsMapping: Record<string, string>, varsExport: Record<string, string>): void;
84 exportKeyframes(keyframeMapping: Record<string, KeyFrameWithNode>, keyframesExport: Record<string, string>): void;
85 exportRootClass(meta: StylableMeta, classesExport: Record<string, string>): void;
86 exportClass(meta: StylableMeta, name: string, classSymbol: ClassSymbol, metaExports?: Record<string, string>): string;
87 scopeKeyframes(ast: postcss.Root, meta: StylableMeta): Record<string, KeyFrameWithNode>;
88 createCSSVarsMapping(_ast: postcss.Root, meta: StylableMeta): Record<string, string>;
89 getScopedCSSVar(decl: postcss.Declaration, meta: StylableMeta, cssVarsMapping: Record<string, string>): string;
90 addGlobalsToMeta(selectorAst: SelectorAstNode[], meta?: StylableMeta): void;
91 transformGlobals(ast: postcss.Root, meta: StylableMeta): void;
92 resolveSelectorElements(meta: StylableMeta, selector: string): ResolvedElement[][];
93 scopeSelector(originMeta: StylableMeta, selector: string, classesExport?: Record<string, string>, calcPaths?: boolean, rule?: postcss.Rule): ScopedSelectorResults;
94 addAdditionalSelectors(addedSelectors: AdditionalSelector[], selectorAst: SelectorAstNode): void;
95 applyRootScoping(meta: StylableMeta, selectorAst: SelectorAstNode): void;
96 scopeRule(meta: StylableMeta, rule: postcss.Rule, _classesExport?: Record<string, string>): string;
97 handleClass(meta: StylableMeta, node: SelectorAstNode, name: string, classesExport?: Record<string, string>, rule?: postcss.Rule, originMeta?: StylableMeta): CSSResolve;
98 handleElement(meta: StylableMeta, node: SelectorAstNode, name: string, originMeta?: StylableMeta): CSSResolve<StylableSymbol> | {
99 meta: StylableMeta;
100 symbol: StylableSymbol;
101 };
102 handlePseudoElement(meta: StylableMeta, node: SelectorAstNode, name: string, selectorNode: SelectorAstNode, addedSelectors: AdditionalSelector[], rule?: postcss.Rule, originMeta?: StylableMeta): CSSResolve;
103 scope(name: string, namespace: string, delimiter?: string): string;
104 exportClasses(meta: StylableMeta): Record<string, string>;
105 getPartExports(resolved: Array<CSSResolve<ClassSymbol | ElementSymbol>>): string[];
106 scopeSelector2(originMeta: StylableMeta, selector: string, _classesExport?: Record<string, string>, _calcPaths?: boolean, rule?: postcss.Rule): {
107 selector: string;
108 elements: ResolvedElement[][];
109 };
110 scopeSelectorAst(context: ScopeContext): SelectorAstNode;
111 private handleChunkNode;
112 private handleCustomSelector;
113 private scopeClassNode;
114 private resolveMetaParts;
115 private addDevRules;
116 private resetTransformProperties;
117}
118export declare function removeSTDirective(root: postcss.Root): void;
119interface ScopeAnchor {
120 type: 'class' | 'element' | 'pseudo-element';
121 name: string;
122 resolved: Array<CSSResolve<ClassSymbol | ElementSymbol>>;
123}
124declare class ScopeContext {
125 originMeta: StylableMeta;
126 selectorAst: SelectorAstNode;
127 rule: postcss.Rule;
128 additionalSelectors: Array<() => void>;
129 selectorIndex: number;
130 elements: any[];
131 transformGlobals: boolean;
132 metaParts?: MetaParts;
133 chunks?: SelectorChunk2[];
134 chunk?: SelectorChunk2;
135 node?: SelectorAstNode;
136 currentAnchor?: ScopeAnchor;
137 constructor(originMeta: StylableMeta, selectorAst: SelectorAstNode, rule: postcss.Rule);
138 initRootAnchor(anchor: ScopeAnchor): void;
139 setCurrentAnchor(anchor: ScopeAnchor): void;
140 createNestedContext(selectorAst: SelectorAstNode): ScopeContext;
141}
142interface MetaParts {
143 class: Record<string, Array<CSSResolve<ClassSymbol | ElementSymbol>>>;
144 element: Record<string, Array<CSSResolve<ClassSymbol | ElementSymbol>>>;
145}
146export {};
147//# sourceMappingURL=stylable-transformer.d.ts.map
\No newline at end of file