UNPKG

8.89 kBTypeScriptView Raw
1import type { Abbreviation } from '@emmetio/abbreviation';
2import type { CSSSnippet } from './stylesheet/snippets.js';
3export type SyntaxType = 'markup' | 'stylesheet';
4export type FieldOutput = (index: number, placeholder: string, offset: number, line: number, column: number) => string;
5export type TextOutput = (text: string, offset: number, line: number, column: number) => string;
6export type StringCase = '' | 'lower' | 'upper';
7export interface SnippetsMap {
8 [name: string]: string;
9}
10export interface AbbreviationContext {
11 name: string;
12 attributes?: {
13 [name: string]: string | null;
14 };
15}
16/**
17 * Raw config which contains per-syntax options. `markup` and `syntax` keys are
18 * reserved for global settings for all markup and stylesheet syntaxes
19 */
20export interface GlobalConfig {
21 [syntax: string]: Partial<BaseConfig>;
22}
23export interface BaseConfig {
24 type: SyntaxType;
25 /** Options for abbreviation output */
26 options: Partial<Options>;
27 /** Substitutions for variable names */
28 variables: SnippetsMap;
29 /** Abbreviation name to snippets mapping */
30 snippets: SnippetsMap;
31}
32interface ResolvedConfig extends BaseConfig {
33 /** Host syntax */
34 syntax: string;
35 /**
36 * Context of abbreviation. For markup abbreviation, it contains parent tag
37 * name with attributes, for stylesheet abbreviation it contains property name
38 * if abbreviation is expanded as value
39 */
40 context?: AbbreviationContext;
41 /** Text to wrap with abbreviation */
42 text?: string | string[];
43 /** Max amount of repeated elements (fool proof) */
44 maxRepeat?: number;
45 /**
46 * Object for storing internal cache data to be shared across Emmet methods
47 * invocation. If provided, Emmet will store compute-intensive data in this
48 * object and will re-use it during editor session.
49 * Every time user settings are changed, you should empty cache by passing
50 * new object.
51 */
52 cache?: Cache;
53}
54export type Config = ResolvedConfig & {
55 options: Options;
56};
57export type UserConfig = Partial<ResolvedConfig>;
58export interface Cache {
59 stylesheetSnippets?: CSSSnippet[];
60 markupSnippets?: {
61 [name: string]: Abbreviation | null;
62 };
63}
64export interface Options {
65 /** A list of inline-level elements */
66 inlineElements: string[];
67 /** A string for one level indent */
68 'output.indent': string;
69 /**
70 * A string for base indent, e.g. context indentation which will be added
71 * for every generated line
72 */
73 'output.baseIndent': string;
74 /** A string to use as a new line */
75 'output.newline': string;
76 /** Tag case: lower, upper or '' (keep as-is) */
77 'output.tagCase': StringCase;
78 /** Attribute name case: lower, upper or '' (keep as-is) */
79 'output.attributeCase': StringCase;
80 /** Attribute value quotes: 'single' or 'double' */
81 'output.attributeQuotes': 'single' | 'double';
82 /** Enable output formatting (indentation and line breaks) */
83 'output.format': boolean;
84 /** When enabled, automatically adds inner line breaks for leaf (e.g. without children) nodes */
85 'output.formatLeafNode': boolean;
86 /** A list of tag names that should not get inner indentation */
87 'output.formatSkip': string[];
88 /** A list of tag names that should *always* get inner indentation. */
89 'output.formatForce': string[];
90 /**
91 * How many inline sibling elements should force line break for each tag.
92 * Set to `0` to output all inline elements without formatting.
93 * Set to `1` to output all inline elements with formatting (same as block-level).
94 */
95 'output.inlineBreak': number;
96 /**
97 * Produce compact notation of boolean attributes: attributes which doesn’t have value.
98 * With this option enabled, outputs `<div contenteditable>` instead of
99 * `<div contenteditable="contenteditable">`
100 */
101 'output.compactBoolean': boolean;
102 /** A list of boolean attributes */
103 'output.booleanAttributes': string[];
104 /** Reverses attribute merging directions when resolving snippets */
105 'output.reverseAttributes': boolean;
106 /** Style of self-closing tags: html (`<br>`), xml (`<br/>`) or xhtml (`<br />`) */
107 'output.selfClosingStyle': 'html' | 'xml' | 'xhtml';
108 /**
109 * A function that takes field index and optional placeholder and returns
110 * a string field (tabstop) for host editor. For example, a TextMate-style
111 * field is `$index` or `${index:placeholder}`
112 * @param index Field index
113 * @param placeholder Field placeholder (default value), if any
114 * @param offset Current character offset from the beginning of generated content
115 * @param line Current line of generated output
116 * @param column Current column in line
117 */
118 'output.field': FieldOutput;
119 /**
120 * A function for processing text chunk passed to `OutputStream`.
121 * May be used by editor for escaping characters, if necessary
122 */
123 'output.text': TextOutput;
124 /**
125 * Automatically update value of <a> element's href attribute
126 * if inserting URL or email
127 */
128 'markup.href': boolean;
129 /**
130 * Attribute name mapping. Can be used to change attribute names for output.
131 * For example, `class` -> `className` in JSX. If a key ends with `*`, this
132 * value will be used for multi-attributes: currentry, it’s a `class` and `id`
133 * since `multiple` marker is added for shorthand attributes only.
134 * Example: `{ "class*": "styleName" }`
135 */
136 'markup.attributes'?: Record<string, string>;
137 /**
138 * Prefixes for attribute values.
139 * If specified, a value is treated as prefix for object notation and
140 * automatically converts attribute value into expression if `jsx` is enabled.
141 * Same as in `markup.attributes` option, a `*` can be used.
142 */
143 'markup.valuePrefix'?: Record<string, string>;
144 /**
145 * Enable/disable element commenting: generate comments before open and/or
146 * after close tag
147 */
148 'comment.enabled': boolean;
149 /**
150 * Attributes that should trigger node commenting on specific node,
151 * if commenting is enabled
152 */
153 'comment.trigger': string[];
154 /**
155 * Template string for comment to be placed *before* opening tag
156 */
157 'comment.before': string;
158 /**
159 * Template string for comment to be placed *after* closing tag.
160 * Example: `\n<!-- /[#ID][.CLASS] -->`
161 */
162 'comment.after': string;
163 /** Enable/disable BEM addon */
164 'bem.enabled': boolean;
165 /** A string for separating elements in output class */
166 'bem.element': string;
167 /** A string for separating modifiers in output class */
168 'bem.modifier': string;
169 /** Enable/disable JSX addon */
170 'jsx.enabled': boolean;
171 /** List of globally available keywords for properties */
172 'stylesheet.keywords': string[];
173 /**
174 * List of unitless properties, e.g. properties where numeric values without
175 * explicit unit will be outputted as is, without default value
176 */
177 'stylesheet.unitless': string[];
178 /** Use short hex notation where possible, e.g. `#000` instead of `#000000` */
179 'stylesheet.shortHex': boolean;
180 /** A string between property name and value */
181 'stylesheet.between': string;
182 /** A string after property value */
183 'stylesheet.after': string;
184 /** A unit suffix to output by default after integer values, 'px' by default */
185 'stylesheet.intUnit': string;
186 /** A unit suffix to output by default after float values, 'em' by default */
187 'stylesheet.floatUnit': string;
188 /**
189 * Aliases for custom units in abbreviation. For example, `r: 'rem'` will
190 * output `10rem` for abbreviation `10r`
191 */
192 'stylesheet.unitAliases': SnippetsMap;
193 /** Output abbreviation as JSON object properties (for CSS-in-JS syntaxes) */
194 'stylesheet.json': boolean;
195 /** Use double quotes for JSON values */
196 'stylesheet.jsonDoubleQuotes': boolean;
197 /**
198 * A float number between 0 and 1 to pick fuzzy-matched abbreviations.
199 * Lower value will pick more abbreviations (and less accurate)
200 */
201 'stylesheet.fuzzySearchMinScore': number;
202}
203/**
204 * Default syntaxes for abbreviation types
205 */
206export declare const defaultSyntaxes: {
207 [name in SyntaxType]: string;
208};
209/**
210 * List of all known syntaxes
211 */
212export declare const syntaxes: {
213 markup: string[];
214 stylesheet: string[];
215};
216export declare const defaultOptions: Options;
217export declare const defaultConfig: Config;
218/**
219 * Default per-syntax config
220 */
221export declare const syntaxConfig: GlobalConfig;
222/**
223 * Parses raw snippets definitions with possibly multiple keys into a plan
224 * snippet map
225 */
226export declare function parseSnippets(snippets: SnippetsMap): SnippetsMap;
227export default function resolveConfig(config?: UserConfig, globals?: GlobalConfig): Config;
228export {};