UNPKG

6.91 kBTypeScriptView Raw
1import * as 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};
66export declare class StylableTransformer {
67 fileProcessor: FileProcessor<StylableMeta>;
68 diagnostics: Diagnostics;
69 resolver: StylableResolver;
70 delimiter: string;
71 keepValues: boolean;
72 replaceValueHook: replaceValueHook | undefined;
73 postProcessor: postProcessor | undefined;
74 mode: EnvMode;
75 private metaParts;
76 constructor(options: TransformerOptions);
77 transform(meta: StylableMeta): StylableResults;
78 transformAst(ast: postcss.Root, meta: StylableMeta, metaExports?: StylableExports, variableOverride?: Record<string, string>, path?: string[], mixinTransform?: boolean): void;
79 exportLocalVars(meta: StylableMeta, stVarsExport: Record<string, string>, variableOverride?: Record<string, string>): void;
80 exportCSSVars(cssVarsMapping: Record<string, string>, varsExport: Record<string, string>): void;
81 exportKeyframes(keyframeMapping: Record<string, string>, keyframesExport: Record<string, string>): void;
82 exportRootClass(meta: StylableMeta, classesExport: Record<string, string>): void;
83 exportClass(meta: StylableMeta, name: string, classSymbol: ClassSymbol, metaExports?: Record<string, string>): string;
84 scopeKeyframes(ast: postcss.Root, meta: StylableMeta): Record<string, string>;
85 createCSSVarsMapping(_ast: postcss.Root, meta: StylableMeta): Record<string, string>;
86 getScopedCSSVar(decl: postcss.Declaration, meta: StylableMeta, cssVarsMapping: Record<string, string>): string;
87 addGlobalsToMeta(selectorAst: SelectorAstNode[], meta?: StylableMeta): void;
88 transformGlobals(ast: postcss.Root, meta: StylableMeta): void;
89 resolveSelectorElements(meta: StylableMeta, selector: string): ResolvedElement[][];
90 scopeSelector(originMeta: StylableMeta, selector: string, classesExport?: Record<string, string>, calcPaths?: boolean, rule?: postcss.Rule): ScopedSelectorResults;
91 addAdditionalSelectors(addedSelectors: AdditionalSelector[], selectorAst: SelectorAstNode): void;
92 applyRootScoping(meta: StylableMeta, selectorAst: SelectorAstNode): void;
93 scopeRule(meta: StylableMeta, rule: postcss.Rule, _classesExport?: Record<string, string>): string;
94 handleClass(meta: StylableMeta, node: SelectorAstNode, name: string, classesExport?: Record<string, string>, rule?: postcss.Rule, originMeta?: StylableMeta): CSSResolve;
95 handleElement(meta: StylableMeta, node: SelectorAstNode, name: string, originMeta?: StylableMeta): CSSResolve<StylableSymbol> | {
96 meta: StylableMeta;
97 symbol: StylableSymbol;
98 };
99 handlePseudoElement(meta: StylableMeta, node: SelectorAstNode, name: string, selectorNode: SelectorAstNode, addedSelectors: AdditionalSelector[], rule?: postcss.Rule, originMeta?: StylableMeta): CSSResolve;
100 scope(name: string, namespace: string, delimiter?: string): string;
101 exportClasses(meta: StylableMeta): Record<string, string>;
102 getPartExports(resolved: Array<CSSResolve<ClassSymbol | ElementSymbol>>): string[];
103 scopeSelector2(originMeta: StylableMeta, selector: string, _classesExport?: Record<string, string>, _calcPaths?: boolean, rule?: postcss.Rule): {
104 selector: string;
105 elements: ResolvedElement[][];
106 targetSelectorAst: SelectorAstNode;
107 };
108 scopeSelectorAst(context: ScopeContext): SelectorAstNode;
109 private handleChunkNode;
110 private isDuplicateStScopeDiagnostic;
111 private handleCustomSelector;
112 private scopeClassNode;
113 private resolveMetaParts;
114 private addDevRules;
115 private resetTransformProperties;
116}
117export declare function removeSTDirective(root: postcss.Root): void;
118interface ScopeAnchor {
119 type: 'class' | 'element' | 'pseudo-element';
120 name: string;
121 resolved: Array<CSSResolve<ClassSymbol | ElementSymbol>>;
122}
123declare class ScopeContext {
124 originMeta: StylableMeta;
125 selectorAst: SelectorAstNode;
126 rule: postcss.Rule;
127 additionalSelectors: Array<() => void>;
128 selectorIndex: number;
129 elements: any[];
130 transformGlobals: boolean;
131 metaParts?: MetaParts;
132 chunks?: SelectorChunk2[];
133 chunk?: SelectorChunk2;
134 node?: SelectorAstNode;
135 currentAnchor?: ScopeAnchor;
136 constructor(originMeta: StylableMeta, selectorAst: SelectorAstNode, rule: postcss.Rule);
137 initRootAnchor(anchor: ScopeAnchor): void;
138 setCurrentAnchor(anchor: ScopeAnchor): void;
139 createNestedContext(selectorAst: SelectorAstNode): ScopeContext;
140}
141interface MetaParts {
142 class: Record<string, Array<CSSResolve<ClassSymbol | ElementSymbol>>>;
143 element: Record<string, Array<CSSResolve<ClassSymbol | ElementSymbol>>>;
144}
145export {};
146//# sourceMappingURL=stylable-transformer.d.ts.map
\No newline at end of file