@zeplin/extension-model
Version:
Models exposed to Zeplin extensions
199 lines (198 loc) • 8.21 kB
TypeScript
import { Color } from "./color.js";
import { TextStyle } from "./textStyle.js";
import { SpacingSection } from "./spacingSection.js";
import { Barrel, RemPreferences } from "./utils/barrel.js";
import { VariableCollection } from "./variableCollection.js";
import { Component } from "./component.js";
import { SpacingToken } from "./spacingToken.js";
/**
* Enum for styleguide types
*/
export declare enum StyleguideType {
ANDROID = "android",
IOS = "ios",
MACOS = "osx",
WEB = "web",
BASE = "base"
}
/**
* Interface for styleguide data
*/
export interface StyleguideData {
type: StyleguideType;
name: string;
density: string;
colors: any[];
parent?: any;
textStyles: any[];
componentSections: any[];
spacingSections: any[];
remPreferences?: RemPreferences;
variableCollections?: any[];
}
/**
* An interface to represent a Zeplin styleguide.
*/
export declare class Styleguide extends Barrel {
/**
* Type of the styleguide, one of "web", "android", "ios", "macos", "base"
*/
type: StyleguideType;
/**
* Name of the styleguide.
*/
name: string;
/**
* Pixel density used in styleguide's designs.
*/
density: string;
/**
* The unit of length specific to the styleguide's type. e.g., "px" for web styleguides.
*/
lengthUnit: string;
/**
* The unit of font sizes.
*/
textLengthUnit: string;
/**
* Parent of the styleguide.
*/
parent?: Styleguide;
/**
* Components in the styleguide.
*/
components: Component[];
/**
* Text styles in the styleguide.
*/
textStyles: TextStyle[];
/**
* Colors in the styleguide.
*/
colors: Color[];
/**
* This value is used to obtain actual length from the unit length for a density.
*/
densityDivisor: number;
/**
* Spacing sections (with spacing tokens) defined in the styleguide.
*/
spacingSections: SpacingSection[];
/**
* Preferences to specify rem usage in the styleguide (web styleguides only).
*/
remPreferences?: RemPreferences;
/**
* Variable collections in the styleguide.
*/
variableCollections: VariableCollection[];
static get TYPE(): typeof StyleguideType;
static get ALLOWED_FIELDS(): string[];
constructor(data: StyleguideData);
/**
* Creates a Styleguide instance from a JSON string
*
* @param json JSON string representing a styleguide
* @returns A new Styleguide instance
*/
static fromJSON(json: string): Styleguide;
/**
* Finds any text style in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose name is equal to `name`
*
* @param name Name of the text style to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found text style or undefined if not found
*/
findTextStyleByName(name: string, useLinkedStyleguides?: boolean): TextStyle | undefined;
/**
* Finds any text style in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) which is equal to `textStyle`
*
* @param textStyle Text style to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found text style or undefined if not found
*/
findTextStyleEqual(textStyle: TextStyle, useLinkedStyleguides?: boolean): TextStyle | undefined;
/**
* Finds the best match for a text style in the styleguide or in the parent styleguides (if useLinkedStyleguides is true)
*
* @param textStyle Text style to find a match for
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found text style or undefined if not found
*/
findBestConformingTextStyle(textStyle: TextStyle, useLinkedStyleguides?: boolean): TextStyle | undefined;
/**
* Finds any color in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose name is equal to `name`
*
* @param name Name of the color to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found color or undefined if not found
*/
findColorByName(name: string, useLinkedStyleguides?: boolean): Color | undefined;
/**
* Finds any color in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose sourceId equals to `sourceId`
*
* @param sourceId Source ID of the color to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found color or undefined if not found
*/
findColorBySourceId(sourceId: string, useLinkedStyleguides?: boolean): Color | undefined;
/**
* Finds any color in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) which is equal to `color`
*
* @param color Color to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found color or undefined if not found
*/
findColorEqual(color: Color, useLinkedStyleguides?: boolean): Color | undefined;
/**
* Finds any color variable in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) which is equal to `color`
*
* @param color Color to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found color or undefined if not found
*/
findLinkedColorVariableEqual(color: Color, useLinkedStyleguides?: boolean): Color | undefined;
/**
* Finds any color in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose hex and alpha values are equal to `values`
*
* @param values Object containing hex and alpha values
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found color or undefined if not found
*/
findColorByHexAndAlpha(values: {
hex?: string;
alpha?: number;
}, useLinkedStyleguides?: boolean): Color | undefined;
/**
* Finds any spacing token in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose value is equal to `value`
*
* @param value Value of the spacing token to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found spacing token or undefined if not found
*/
findSpacingTokenByValue(value: number, useLinkedStyleguides?: boolean): SpacingToken | undefined;
/**
* Finds any spacing token in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose name is equal to `name`
*
* @param name Name of the spacing token to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found spacing token or undefined if not found
*/
findSpacingTokenByName(name: string, useLinkedStyleguides?: boolean): SpacingToken | undefined;
/**
* Finds any component in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose name equals to `name`
*
* @param name Name of the component to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found component or undefined if not found
*/
findComponentByName(name: string, useLinkedStyleguides?: boolean): Component | undefined;
/**
* Finds any component in the styleguide or in the parent styleguides (if useLinkedStyleguides is true) whose sourceId equals to `sourceId`
*
* @param sourceId Source ID of the component to find
* @param useLinkedStyleguides Whether to search in parent styleguides (defaults to true)
* @returns The found component or undefined if not found
*/
findComponentBySourceId(sourceId: string, useLinkedStyleguides?: boolean): Component | undefined;
}