🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@bamboocss/token-dictionary

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bamboocss/token-dictionary - npm Package Compare versions

Comparing version
1.12.0
to
1.12.1
+4
-4
package.json
{
"name": "@bamboocss/token-dictionary",
"version": "1.12.0",
"version": "1.12.1",
"description": "Common error messages for css bamboo",

@@ -38,5 +38,5 @@ "homepage": "https://bamboo-css.com",

"ts-pattern": "5.9.0",
"@bamboocss/logger": "^1.12.0",
"@bamboocss/shared": "1.12.0",
"@bamboocss/types": "1.12.0"
"@bamboocss/shared": "1.12.1",
"@bamboocss/logger": "^1.12.1",
"@bamboocss/types": "1.12.1"
},

@@ -43,0 +43,0 @@ "devDependencies": {

import { CssVar, CssVarOptions } from "@bamboocss/shared";
import { ColorPaletteOptions, SemanticTokens, ThemeVariantsMap, Token as Token$1, Tokens } from "@bamboocss/types";
//#region src/token.d.ts
interface ExtensionData {
category?: string;
references?: TokenReferences;
condition?: string;
conditions?: TokenConditions;
theme?: string;
}
interface TokenConditions {
[key: string]: string;
}
interface TokenReferences {
[key: string]: Token;
}
type TokenExtensions<T = {}> = ExtensionData & {
[key: string]: any;
} & T;
interface TokenInput {
name: string;
value: any;
type?: string;
path?: string[];
description?: string;
deprecated?: boolean | string;
extensions?: TokenExtensions;
}
/**
* Represents a design token in the dictionary
*/
declare class Token {
name: string;
value: any;
originalValue: any;
path: string[];
type?: string;
description?: string;
deprecated?: boolean | string;
extensions: TokenExtensions;
constructor(input: TokenInput);
/**
* The unique identifier of the token.
*/
get id(): string;
/**
* Whether the token is a conditional token.
* Conditional tokens are tokens that have multiple values based on a condition.
*/
get isConditional(): boolean;
/**
* Whether the token has a reference in its value.
* e.g. {color.gray.100}
*/
get hasReference(): boolean;
/**
* Whether the token is a complex or composite token.
*/
get isComposite(): boolean;
/**
* Returns the token value with the references expanded.
* e.g. {color.gray.100} => var(--colors-gray-100)
*
*/
expandReferences(): string;
/**
* Whether this token has a reference to another token
*/
get isReference(): boolean;
/**
* Returns the list of references in the token value
*/
get references(): string[];
clone(): Token;
/**
* Returns an array of tokens per conditions.
* It is commonly used in semantic tokens, and can have multiple values based on a condition.
* e.g. primary: { light: '#000', dark: '#fff' }
*/
getConditionTokens(): Token[] | undefined;
/**
* Add more extensions to the token
*/
setExtensions(extensions: TokenExtensions): this;
setType(): void;
}
declare const TOKEN_TYPES: {
readonly colors: "color";
readonly spacing: "dimension";
readonly sizes: "dimension";
readonly shadows: "shadow";
readonly fonts: "fontFamily";
readonly fontSizes: "fontSize";
readonly fontWeights: "fontWeight";
readonly letterSpacings: "letterSpacing";
readonly lineHeights: "lineHeight";
readonly durations: "duration";
readonly transitions: "transition";
readonly radii: "borderRadius";
readonly gradients: "gradient";
readonly easings: "cubicBezier";
readonly borders: "border";
readonly borderWidths: "borderWidth";
readonly zIndex: "zIndex";
readonly opacity: "opacity";
readonly blurs: "blur";
readonly aspectRatios: "aspectRatio";
readonly cursor: "cursor";
readonly assets: "asset";
};
type TokenCategory = keyof typeof TOKEN_TYPES;
declare const TOKEN_CATEGORIES: TokenCategory[];
//#endregion
//#region src/dictionary.d.ts
type EnforcePhase = 'pre' | 'post';
interface TokenTransformer {
name: string;
enforce?: EnforcePhase;
type?: 'value' | 'name' | 'extensions';
match?: (token: Token) => boolean;
transform: (token: Token, dictionary: TokenDictionary) => any;
}
interface TokenDictionaryOptions {
tokens?: Tokens;
semanticTokens?: SemanticTokens;
breakpoints?: Record<string, string>;
themes?: ThemeVariantsMap | undefined;
prefix?: string;
hash?: boolean;
colorPalette?: ColorPaletteOptions;
}
interface TokenMiddleware {
enforce?: EnforcePhase;
transform: (dict: TokenDictionary) => void;
}
declare class TokenDictionary {
private options;
allTokens: Token[];
byName: Map<string, Token>;
private deprecated;
constructor(options: TokenDictionaryOptions);
init(): this;
get prefix(): string | undefined;
get hash(): boolean | undefined;
get colorPalette(): ColorPaletteOptions | undefined;
getByName: (path: string) => Token | undefined;
formatTokenName: (path: string[]) => string;
formatCssVar: (path: string[], options: CssVarOptions) => CssVar;
registerTokens(): this;
registerToken: (token: Token, transformPhase?: "pre" | "post") => void;
private transforms;
registerTransform(...transforms: TokenTransformer[]): this;
private execTransform;
execTransformOnToken(transform: TokenTransformer, token: Token): void;
transformTokens(enforce: EnforcePhase): this;
private middlewares;
registerMiddleware(...middlewares: TokenMiddleware[]): this;
applyMiddlewares(enforce: EnforcePhase): void;
getReferences(value: string): Token[];
usesReference(value: any): boolean;
addReferences(): this;
filter(pattern: Partial<Token> | ((token: Token) => boolean)): Token[];
addConditionalTokens(): this;
expandTokenReferences(): this;
colorMix: (value: string, tokenFn: (path: string) => string) => {
invalid: boolean;
value: string;
color?: undefined;
} | {
invalid: boolean;
color: string;
value: string;
};
/**
* Expand token references to their CSS variable
*/
expandReferenceInValue(value: string): string;
/**
* Get the value of a token reference
*/
resolveReference(value: string): string;
/**
* Resolve token references to their actual raw value (recursively resolves references)
*/
deepResolveReference(originalValue: string): string | undefined;
isDeprecated(name: string): boolean;
build(): this;
get isEmpty(): boolean;
view: ReturnType<TokenDictionaryView['getTokensView']>;
setComputedView(): this;
}
declare class TokenDictionaryView {
private dictionary;
constructor(dictionary: TokenDictionary);
getTokensView(): {
conditionMap: Map<string, Set<Token>>;
categoryMap: Map<keyof import("@bamboocss/types").TokenDataTypes, Map<string, Token>>;
colorPalettes: Map<string, Map<string, string>>;
vars: Map<string, Map<string, string>>;
values: Map<string, string>;
nameByVar: Map<string, string>;
json: Record<string, Record<string, string>>;
valuesByCategory: Map<keyof import("@bamboocss/types").TokenDataTypes, Map<string, string>>;
get: (path: string, fallback?: string | number) => string;
getVar: (path: string, fallback?: string | number) => string;
getCategoryValues: (category: string) => Record<string, string> | undefined;
getColorPaletteValues: (palette: string) => string[];
};
private processCondition;
private processColorPalette;
private processCategory;
private processValue;
private processVars;
}
//#endregion
//#region src/utils.d.ts
/**
* Returns all references in a string
*
* @example
*
* `{colors.red.300} {sizes.sm}` => ['colors.red.300', 'sizes.sm']
*/
declare function getReferences(value: string): string[];
declare const hasReference: (value: string) => boolean;
declare function expandReferences(value: string, fn: (key: string) => string): string;
/**
* Converts a JS Map to an object
*/
declare function mapToJson(map: Map<string, any>): Record<string, unknown>;
declare const isToken: (value: any) => value is Token$1;
declare function assertTokenFormat(token: any): asserts token is Token$1;
//#endregion
export { TOKEN_CATEGORIES, Token, type TokenCategory, TokenDictionary, type TokenExtensions, assertTokenFormat, expandReferences, getReferences, hasReference, isToken, mapToJson };
import { CssVar, CssVarOptions } from "@bamboocss/shared";
import { ColorPaletteOptions, SemanticTokens, ThemeVariantsMap, Token as Token$1, Tokens } from "@bamboocss/types";
//#region src/token.d.ts
interface ExtensionData {
category?: string;
references?: TokenReferences;
condition?: string;
conditions?: TokenConditions;
theme?: string;
}
interface TokenConditions {
[key: string]: string;
}
interface TokenReferences {
[key: string]: Token;
}
type TokenExtensions<T = {}> = ExtensionData & {
[key: string]: any;
} & T;
interface TokenInput {
name: string;
value: any;
type?: string;
path?: string[];
description?: string;
deprecated?: boolean | string;
extensions?: TokenExtensions;
}
/**
* Represents a design token in the dictionary
*/
declare class Token {
name: string;
value: any;
originalValue: any;
path: string[];
type?: string;
description?: string;
deprecated?: boolean | string;
extensions: TokenExtensions;
constructor(input: TokenInput);
/**
* The unique identifier of the token.
*/
get id(): string;
/**
* Whether the token is a conditional token.
* Conditional tokens are tokens that have multiple values based on a condition.
*/
get isConditional(): boolean;
/**
* Whether the token has a reference in its value.
* e.g. {color.gray.100}
*/
get hasReference(): boolean;
/**
* Whether the token is a complex or composite token.
*/
get isComposite(): boolean;
/**
* Returns the token value with the references expanded.
* e.g. {color.gray.100} => var(--colors-gray-100)
*
*/
expandReferences(): string;
/**
* Whether this token has a reference to another token
*/
get isReference(): boolean;
/**
* Returns the list of references in the token value
*/
get references(): string[];
clone(): Token;
/**
* Returns an array of tokens per conditions.
* It is commonly used in semantic tokens, and can have multiple values based on a condition.
* e.g. primary: { light: '#000', dark: '#fff' }
*/
getConditionTokens(): Token[] | undefined;
/**
* Add more extensions to the token
*/
setExtensions(extensions: TokenExtensions): this;
setType(): void;
}
declare const TOKEN_TYPES: {
readonly colors: "color";
readonly spacing: "dimension";
readonly sizes: "dimension";
readonly shadows: "shadow";
readonly fonts: "fontFamily";
readonly fontSizes: "fontSize";
readonly fontWeights: "fontWeight";
readonly letterSpacings: "letterSpacing";
readonly lineHeights: "lineHeight";
readonly durations: "duration";
readonly transitions: "transition";
readonly radii: "borderRadius";
readonly gradients: "gradient";
readonly easings: "cubicBezier";
readonly borders: "border";
readonly borderWidths: "borderWidth";
readonly zIndex: "zIndex";
readonly opacity: "opacity";
readonly blurs: "blur";
readonly aspectRatios: "aspectRatio";
readonly cursor: "cursor";
readonly assets: "asset";
};
type TokenCategory = keyof typeof TOKEN_TYPES;
declare const TOKEN_CATEGORIES: TokenCategory[];
//#endregion
//#region src/dictionary.d.ts
type EnforcePhase = 'pre' | 'post';
interface TokenTransformer {
name: string;
enforce?: EnforcePhase;
type?: 'value' | 'name' | 'extensions';
match?: (token: Token) => boolean;
transform: (token: Token, dictionary: TokenDictionary) => any;
}
interface TokenDictionaryOptions {
tokens?: Tokens;
semanticTokens?: SemanticTokens;
breakpoints?: Record<string, string>;
themes?: ThemeVariantsMap | undefined;
prefix?: string;
hash?: boolean;
colorPalette?: ColorPaletteOptions;
}
interface TokenMiddleware {
enforce?: EnforcePhase;
transform: (dict: TokenDictionary) => void;
}
declare class TokenDictionary {
private options;
allTokens: Token[];
byName: Map<string, Token>;
private deprecated;
constructor(options: TokenDictionaryOptions);
init(): this;
get prefix(): string | undefined;
get hash(): boolean | undefined;
get colorPalette(): ColorPaletteOptions | undefined;
getByName: (path: string) => Token | undefined;
formatTokenName: (path: string[]) => string;
formatCssVar: (path: string[], options: CssVarOptions) => CssVar;
registerTokens(): this;
registerToken: (token: Token, transformPhase?: "pre" | "post") => void;
private transforms;
registerTransform(...transforms: TokenTransformer[]): this;
private execTransform;
execTransformOnToken(transform: TokenTransformer, token: Token): void;
transformTokens(enforce: EnforcePhase): this;
private middlewares;
registerMiddleware(...middlewares: TokenMiddleware[]): this;
applyMiddlewares(enforce: EnforcePhase): void;
getReferences(value: string): Token[];
usesReference(value: any): boolean;
addReferences(): this;
filter(pattern: Partial<Token> | ((token: Token) => boolean)): Token[];
addConditionalTokens(): this;
expandTokenReferences(): this;
colorMix: (value: string, tokenFn: (path: string) => string) => {
invalid: boolean;
value: string;
color?: undefined;
} | {
invalid: boolean;
color: string;
value: string;
};
/**
* Expand token references to their CSS variable
*/
expandReferenceInValue(value: string): string;
/**
* Get the value of a token reference
*/
resolveReference(value: string): string;
/**
* Resolve token references to their actual raw value (recursively resolves references)
*/
deepResolveReference(originalValue: string): string | undefined;
isDeprecated(name: string): boolean;
build(): this;
get isEmpty(): boolean;
view: ReturnType<TokenDictionaryView['getTokensView']>;
setComputedView(): this;
}
declare class TokenDictionaryView {
private dictionary;
constructor(dictionary: TokenDictionary);
getTokensView(): {
conditionMap: Map<string, Set<Token>>;
categoryMap: Map<keyof import("@bamboocss/types").TokenDataTypes, Map<string, Token>>;
colorPalettes: Map<string, Map<string, string>>;
vars: Map<string, Map<string, string>>;
values: Map<string, string>;
nameByVar: Map<string, string>;
json: Record<string, Record<string, string>>;
valuesByCategory: Map<keyof import("@bamboocss/types").TokenDataTypes, Map<string, string>>;
get: (path: string, fallback?: string | number) => string;
getVar: (path: string, fallback?: string | number) => string;
getCategoryValues: (category: string) => Record<string, string> | undefined;
getColorPaletteValues: (palette: string) => string[];
};
private processCondition;
private processColorPalette;
private processCategory;
private processValue;
private processVars;
}
//#endregion
//#region src/utils.d.ts
/**
* Returns all references in a string
*
* @example
*
* `{colors.red.300} {sizes.sm}` => ['colors.red.300', 'sizes.sm']
*/
declare function getReferences(value: string): string[];
declare const hasReference: (value: string) => boolean;
declare function expandReferences(value: string, fn: (key: string) => string): string;
/**
* Converts a JS Map to an object
*/
declare function mapToJson(map: Map<string, any>): Record<string, unknown>;
declare const isToken: (value: any) => value is Token$1;
declare function assertTokenFormat(token: any): asserts token is Token$1;
//#endregion
export { TOKEN_CATEGORIES, Token, type TokenCategory, TokenDictionary, type TokenExtensions, assertTokenFormat, expandReferences, getReferences, hasReference, isToken, mapToJson };