UNPKG

2.31 kBTypeScriptView Raw
1import { StylableMeta } from './stylable-meta';
2import { StylableResolver } from './stylable-resolver';
3import { ParsedValue } from './types';
4export interface Box<Type extends string, Value extends any> {
5 type: Type;
6 value: Value;
7}
8export declare function box<Type extends string, Value extends any>(type: Type, value: Value): Box<Type, Value>;
9export declare function unbox<B extends Box<string, unknown>>(boxed: B | string): any;
10export interface BoxedValueMap {
11 [k: string]: string | Box<string, unknown>;
12}
13export declare type BoxedValueArray = Array<string | Box<string, unknown>>;
14declare type CustomTypes = Record<string, CustomValueExtension<any>>;
15export interface CustomValueExtension<T> {
16 evalVarAst(valueAst: ParsedValue, customTypes: {
17 [typeID: string]: CustomValueExtension<unknown>;
18 }): Box<string, T>;
19 getValue(path: string[], value: Box<string, T>, node: ParsedValue, customTypes: CustomTypes): string;
20}
21export declare const stTypes: CustomTypes;
22export declare const CustomValueStrategy: {
23 args: (fnNode: ParsedValue, customTypes: CustomTypes) => (string | Box<string, any>)[];
24 named: (fnNode: ParsedValue, customTypes: CustomTypes) => BoxedValueMap;
25};
26export interface JSValueExtension<Value> {
27 _kind: 'CustomValue';
28 register(localTypeSymbol: string): CustomValueExtension<Value>;
29}
30interface ExtensionApi<Value, Args> {
31 processArgs: (fnNode: ParsedValue, customTypes: CustomTypes) => Args;
32 createValue: (args: Args) => Value;
33 getValue: (v: Value, key: string) => string | Box<string, unknown>;
34 flattenValue?: (v: Box<string, Value>) => {
35 parts: Array<string | Box<string, unknown>>;
36 delimiter: ',' | ' ';
37 };
38}
39export declare function resolveCustomValues(meta: StylableMeta, resolver: StylableResolver): {
40 [x: string]: CustomValueExtension<any>;
41};
42export declare function createCustomValue<Value, Args>({ processArgs, createValue, flattenValue, getValue, }: ExtensionApi<Value, Args>): JSValueExtension<Value>;
43export declare function getBoxValue(path: string[], value: string | Box<string, unknown>, node: ParsedValue, customTypes: CustomTypes): string;
44export declare function isCustomValue(symbol: any): symbol is JSValueExtension<unknown>;
45export {};
46//# sourceMappingURL=custom-values.d.ts.map
\No newline at end of file