@gesslar/sassy 0.21.3 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -5
- package/src/Command.js +0 -33
- package/types/BuildCommand.d.ts +40 -0
- package/types/Colour.d.ts +126 -0
- package/types/Command.d.ts +135 -0
- package/types/Compiler.d.ts +16 -0
- package/types/Evaluator.d.ts +86 -0
- package/types/LintCommand.d.ts +58 -0
- package/types/ResolveCommand.d.ts +58 -0
- package/types/Session.d.ts +132 -0
- package/types/Theme.d.ts +336 -0
- package/types/ThemePool.d.ts +81 -0
- package/types/ThemeToken.d.ts +150 -0
- package/types/cli.d.ts +2 -0
- package/types/index.d.ts +9 -0
package/package.json
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gesslar/sassy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"displayName": "Sassy",
|
|
5
5
|
"description": "Make gorgeous themes that speak as boldly as you do.",
|
|
6
6
|
"publisher": "gesslar",
|
|
7
7
|
"license": "Unlicense",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "src/index.js",
|
|
10
|
+
"types": "types/index.d.ts",
|
|
10
11
|
"bin": "src/cli.js",
|
|
11
12
|
"exports": {
|
|
12
|
-
".":
|
|
13
|
-
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./types/index.d.ts",
|
|
15
|
+
"import": "./src/index.js"
|
|
16
|
+
}
|
|
14
17
|
},
|
|
15
18
|
"files": [
|
|
16
19
|
"src/",
|
|
20
|
+
"types/",
|
|
17
21
|
"UNLICENSE.txt"
|
|
18
22
|
],
|
|
19
23
|
"scripts": {
|
|
20
24
|
"clean": "rm -rfv ./dist",
|
|
21
|
-
"
|
|
25
|
+
"clean-types": "rm -rfv ./types",
|
|
26
|
+
"types": "npx tsc src/*.js types-helper.d.ts --allowJs --declaration --emitDeclarationOnly --outDir types --target ES2022 --module ESNext --moduleResolution Node --esModuleInterop --skipLibCheck --resolveJsonModule && node fix-types.js",
|
|
27
|
+
"build": "npm run clean && npm run types && mkdir -pv ./dist && npm pack --pack-destination ./dist/",
|
|
22
28
|
"exec": "node ./src/cli.js",
|
|
23
29
|
"lint": "eslint src/",
|
|
24
|
-
"submit": "npm publish --access public",
|
|
30
|
+
"submit": "npm run build && npm publish --access public",
|
|
25
31
|
"examples": "node ./examples/validator.js",
|
|
26
32
|
"test": "node -p \"require('fs').readFileSync('TESTING.txt', 'utf8')\"",
|
|
27
33
|
"update": "npx npm-check-updates -u && npm install"
|
package/src/Command.js
CHANGED
|
@@ -234,37 +234,4 @@ export default class Command {
|
|
|
234
234
|
return fileObject
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
/**
|
|
238
|
-
* Emits an event asynchronously and waits for all listeners to complete.
|
|
239
|
-
* Unlike the standard EventEmitter.emit() which is synchronous, this method
|
|
240
|
-
* properly handles async event listeners by waiting for all of them to
|
|
241
|
-
* resolve or reject using Promise.allSettled().
|
|
242
|
-
*
|
|
243
|
-
* @param {string} event - The event name to emit
|
|
244
|
-
* @param {...unknown} [arg] - Arguments to pass to event listeners
|
|
245
|
-
* @returns {Promise<void>} Resolves when all listeners have completed
|
|
246
|
-
*/
|
|
247
|
-
async asyncEmit(event, arg) {
|
|
248
|
-
try {
|
|
249
|
-
arg = arg || new Array()
|
|
250
|
-
const listeners = this.emitter.listeners(event)
|
|
251
|
-
|
|
252
|
-
const settled =
|
|
253
|
-
await Promise.allSettled(listeners.map(listener => listener(arg)))
|
|
254
|
-
|
|
255
|
-
const rejected = settled.filter(reject => reject.status === "rejected")
|
|
256
|
-
|
|
257
|
-
if(rejected.length > 0) {
|
|
258
|
-
if(rejected[0].reason instanceof Error)
|
|
259
|
-
throw rejected[0].reason
|
|
260
|
-
else
|
|
261
|
-
throw Sass.new(rejected[0].reason)
|
|
262
|
-
}
|
|
263
|
-
} catch(error) {
|
|
264
|
-
throw Sass.new(
|
|
265
|
-
`Processing '${event}' event with ${arg&&arg.length?`'${arg}'`:"no arguments"}.`,
|
|
266
|
-
error
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
237
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command handler for building VS Code themes from source files.
|
|
3
|
+
* Handles compilation, watching for changes, and output generation.
|
|
4
|
+
*/
|
|
5
|
+
export default class BuildCommand extends Command {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new BuildCommand instance.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} base - Base configuration object
|
|
10
|
+
* @param {string} base.cwd - Current working directory path
|
|
11
|
+
* @param {object} base.packageJson - Package.json configuration data
|
|
12
|
+
*/
|
|
13
|
+
constructor(base: {
|
|
14
|
+
cwd: string;
|
|
15
|
+
packageJson: object;
|
|
16
|
+
});
|
|
17
|
+
/** @type {EventEmitter} Internal event emitter for watch mode coordination */
|
|
18
|
+
emitter: EventEmitter;
|
|
19
|
+
/**
|
|
20
|
+
* Executes the build command for the provided theme files.
|
|
21
|
+
* Processes each file in parallel, optionally watching for changes.
|
|
22
|
+
*
|
|
23
|
+
* @param {string[]} fileNames - Array of theme file paths to process
|
|
24
|
+
* @param {object} options - Build options
|
|
25
|
+
* @param {boolean} [options.watch] - Enable watch mode for file changes
|
|
26
|
+
* @param {string} [options.output-dir] - Custom output directory path
|
|
27
|
+
* @param {boolean} [options.dry-run] - Print JSON to stdout without writing files
|
|
28
|
+
* @param {boolean} [options.silent] - Silent mode, only show errors or dry-run output
|
|
29
|
+
* @returns {Promise<void>} Resolves when all files are processed
|
|
30
|
+
* @throws {Error} When theme compilation fails
|
|
31
|
+
*/
|
|
32
|
+
execute(fileNames: string[], options: {
|
|
33
|
+
watch?: boolean;
|
|
34
|
+
output?: string;
|
|
35
|
+
dry?: boolean;
|
|
36
|
+
silent?: boolean;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
#private;
|
|
39
|
+
}
|
|
40
|
+
import Command from "./Command.js";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colour manipulation utility class providing static methods for colour operations.
|
|
3
|
+
* Handles hex colour parsing, alpha manipulation, mixing, and format conversions.
|
|
4
|
+
*/
|
|
5
|
+
export default class Colour {
|
|
6
|
+
/**
|
|
7
|
+
* Regular expression for matching long hex colour codes with optional alpha.
|
|
8
|
+
* Matches patterns like #ff0000 or #ff0000ff
|
|
9
|
+
*
|
|
10
|
+
* @type {RegExp}
|
|
11
|
+
*/
|
|
12
|
+
static longHex: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* Regular expression for matching short hex colour codes with optional alpha.
|
|
15
|
+
* Matches patterns like #f00 or #f00f
|
|
16
|
+
*
|
|
17
|
+
* @type {RegExp}
|
|
18
|
+
*/
|
|
19
|
+
static shortHex: RegExp;
|
|
20
|
+
/**
|
|
21
|
+
* Lightens or darkens a hex colour by a specified amount.
|
|
22
|
+
* Always uses OKLCH as the working color space for consistent perceptual results.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} hex - The hex colour code (e.g., "#ff0000" or "#f00")
|
|
25
|
+
* @param {number} amount - The amount to lighten (+) or darken (-) as a percentage
|
|
26
|
+
* @returns {string} The modified hex colour with preserved alpha
|
|
27
|
+
*/
|
|
28
|
+
static lightenOrDarken(hex: string, amount?: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* Lightens or darkens a color using OKLCH as working space for consistent results.
|
|
31
|
+
* Preserves original color information from tokens when available.
|
|
32
|
+
*
|
|
33
|
+
* @param {ThemeToken|object|string} tokenOrColor - ThemeToken, Culori color object, or hex string
|
|
34
|
+
* @param {number} amount - The amount to lighten (+) or darken (-) as a percentage
|
|
35
|
+
* @returns {string} The modified hex colour
|
|
36
|
+
*/
|
|
37
|
+
static lightenOrDarkenWithToken(tokenOrColor: ThemeToken | object | string, amount?: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* Inverts a hex colour by flipping its lightness value.
|
|
40
|
+
* Preserves hue and saturation while inverting the lightness component.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} hex - The hex colour code to invert
|
|
43
|
+
* @returns {string} The inverted hex colour with preserved alpha
|
|
44
|
+
*/
|
|
45
|
+
static invert(hex: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a hex alpha value to a decimal percentage.
|
|
48
|
+
* Takes a 2-digit hex alpha value and converts it to a percentage (0-100).
|
|
49
|
+
*
|
|
50
|
+
* @param {string} hex - The hex alpha value (e.g., "ff", "80")
|
|
51
|
+
* @returns {number} The alpha as a percentage rounded to 2 decimal places
|
|
52
|
+
*/
|
|
53
|
+
static hexAlphaToDecimal(hex: string): number;
|
|
54
|
+
/**
|
|
55
|
+
* Converts a decimal percentage to a hex alpha value.
|
|
56
|
+
* Takes a percentage (0-100) and converts it to a 2-digit hex alpha value.
|
|
57
|
+
*
|
|
58
|
+
* @param {number} dec - The alpha percentage (0-100)
|
|
59
|
+
* @returns {string} The hex alpha value (e.g., "ff", "80")
|
|
60
|
+
*/
|
|
61
|
+
static decimalAlphaToHex(dec: number): string;
|
|
62
|
+
static isHex(value: any): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Normalises a short hex colour code to a full 6-character format.
|
|
65
|
+
* Converts 3-character hex codes like "#f00" to "#ff0000".
|
|
66
|
+
*
|
|
67
|
+
* @param {string} code - The short hex colour code
|
|
68
|
+
* @returns {string} The normalized 6-character hex colour code
|
|
69
|
+
*/
|
|
70
|
+
static normaliseHex(code: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Parses a hex colour string and extracts colour and alpha components.
|
|
73
|
+
* Supports both short (#f00) and long (#ff0000) formats with optional alpha.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} hex - The hex colour string to parse
|
|
76
|
+
* @returns {object} Object containing colour and optional alpha information
|
|
77
|
+
* @throws {Sass} If the hex value is invalid or missing
|
|
78
|
+
*/
|
|
79
|
+
static parseHexColour(hex: string): object;
|
|
80
|
+
/**
|
|
81
|
+
* Sets the alpha transparency of a hex colour to a specific value.
|
|
82
|
+
* Replaces any existing alpha with the new value.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} hex - The hex colour code
|
|
85
|
+
* @param {number} amount - The alpha value (0-1, where 0 is transparent and 1 is opaque)
|
|
86
|
+
* @returns {string} The hex colour with the new alpha value
|
|
87
|
+
*/
|
|
88
|
+
static setAlpha(hex: string, amount: number): string;
|
|
89
|
+
/**
|
|
90
|
+
* Adjusts the alpha transparency of a hex colour by a relative amount.
|
|
91
|
+
* Multiplies the current alpha by (1 + amount) and clamps the result.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} hex - The hex colour code
|
|
94
|
+
* @param {number} amount - The relative amount to adjust alpha (-1 to make transparent, positive to increase)
|
|
95
|
+
* @returns {string} The hex colour with adjusted alpha
|
|
96
|
+
*/
|
|
97
|
+
static addAlpha(hex: string, amount: number): string;
|
|
98
|
+
/**
|
|
99
|
+
* Removes alpha channel from a hex colour, returning only the solid colour.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} hex - The hex colour code with or without alpha
|
|
102
|
+
* @returns {string} The solid hex colour without alpha
|
|
103
|
+
*/
|
|
104
|
+
static solid(hex: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* Mixes two hex colours together in a specified ratio.
|
|
107
|
+
* Blends both the colours and their alpha channels if present.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} colourA - The first hex colour
|
|
110
|
+
* @param {string} colourB - The second hex colour
|
|
111
|
+
* @param {number} ratio - The mixing ratio as percentage (0-100, where 50 is equal mix)
|
|
112
|
+
* @returns {string} The mixed hex colour with blended alpha
|
|
113
|
+
*/
|
|
114
|
+
static mix(colourA: string, colourB: string, ratio?: number): string;
|
|
115
|
+
static getColourParser(name: any): Promise<any>;
|
|
116
|
+
/**
|
|
117
|
+
* Converts colour values from various formats to hex.
|
|
118
|
+
* Supports RGB, RGBA, HSL, HSLA, OKLCH, and OKLCHA colour modes, and MORE!
|
|
119
|
+
*
|
|
120
|
+
* @param {string} input - The colour expression
|
|
121
|
+
* @returns {string} The resulting hex colour
|
|
122
|
+
* @throws {Sass} If the wrong function or value is provided
|
|
123
|
+
*/
|
|
124
|
+
static toHex(input: string): string;
|
|
125
|
+
}
|
|
126
|
+
import ThemeToken from "./ThemeToken.js";
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { FileObject, DirectoryObject, Cache } from '@gesslar/toolkit';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for command-line interface commands.
|
|
4
|
+
* Provides common functionality for CLI option handling and file resolution.
|
|
5
|
+
*/
|
|
6
|
+
export default class Command {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new Command instance.
|
|
9
|
+
*
|
|
10
|
+
* @param {object} config - Configuration object
|
|
11
|
+
* @param {DirectoryObject} config.cwd - Current working directory object
|
|
12
|
+
* @param {object} config.packageJson - Package.json data
|
|
13
|
+
*/
|
|
14
|
+
constructor({ cwd, packageJson }: {
|
|
15
|
+
cwd: DirectoryObject;
|
|
16
|
+
packageJson: object;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current working directory object.
|
|
20
|
+
*
|
|
21
|
+
* @returns {DirectoryObject} The current working directory
|
|
22
|
+
*/
|
|
23
|
+
getCwd(): DirectoryObject;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the package.json data.
|
|
26
|
+
*
|
|
27
|
+
* @returns {object} The package.json object
|
|
28
|
+
*/
|
|
29
|
+
getPackageJson(): object;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the cache instance for the command.
|
|
32
|
+
*
|
|
33
|
+
* @param {Cache} cache - The cache instance to set
|
|
34
|
+
* @returns {this} Returns this instance for method chaining
|
|
35
|
+
*/
|
|
36
|
+
setCache(cache: Cache): this;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the cache instance.
|
|
39
|
+
*
|
|
40
|
+
* @returns {Cache|null} The cache instance or null if not set
|
|
41
|
+
*/
|
|
42
|
+
getCache(): Cache | null;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the CLI command string.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} data - The CLI command string
|
|
47
|
+
* @returns {this} Returns this instance for method chaining
|
|
48
|
+
*/
|
|
49
|
+
setCliCommand(data: string): this;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the CLI command string.
|
|
52
|
+
*
|
|
53
|
+
* @returns {string|null} The CLI command string
|
|
54
|
+
*/
|
|
55
|
+
getCliCommand(): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Sets the CLI options object.
|
|
58
|
+
*
|
|
59
|
+
* @param {object} data - The CLI options configuration
|
|
60
|
+
* @returns {this} Returns this instance for method chaining
|
|
61
|
+
*/
|
|
62
|
+
setCliOptions(data: object): this;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the CLI options object.
|
|
65
|
+
*
|
|
66
|
+
* @returns {object|null} The CLI options configuration
|
|
67
|
+
*/
|
|
68
|
+
getCliOptions(): object | null;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the array of CLI option names.
|
|
71
|
+
*
|
|
72
|
+
* @returns {string[]} Array of option names
|
|
73
|
+
*/
|
|
74
|
+
getCliOptionNames(): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Checks if the command has a cache instance.
|
|
77
|
+
*
|
|
78
|
+
* @returns {boolean} True if cache is available
|
|
79
|
+
*/
|
|
80
|
+
hasCache(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the command has a CLI command string configured.
|
|
83
|
+
*
|
|
84
|
+
* @returns {boolean} True if CLI command is set
|
|
85
|
+
*/
|
|
86
|
+
hasCliCommand(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if the command has CLI options configured.
|
|
89
|
+
*
|
|
90
|
+
* @returns {boolean} True if CLI options are set
|
|
91
|
+
*/
|
|
92
|
+
hasCliOptions(): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Checks if the command is ready to be built.
|
|
95
|
+
* Requires both CLI command and options to be set.
|
|
96
|
+
*
|
|
97
|
+
* @returns {boolean} True if command can be built
|
|
98
|
+
*/
|
|
99
|
+
canBuild(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Builds the CLI command interface using the commander.js program instance.
|
|
102
|
+
* Initializes the command with its options and action handler.
|
|
103
|
+
*
|
|
104
|
+
* @param {object} program - The commander.js program instance
|
|
105
|
+
* @returns {Promise<this>} Returns this instance for method chaining
|
|
106
|
+
*/
|
|
107
|
+
buildCli(program: object): Promise<this>;
|
|
108
|
+
/**
|
|
109
|
+
* Adds a single CLI option to the command.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} name - The option name
|
|
112
|
+
* @param {string[]} options - Array containing option flag and description
|
|
113
|
+
* @param {boolean} preserve - Whether to preserve this option name in the list
|
|
114
|
+
* @returns {Promise<this>} Returns this instance for method chaining
|
|
115
|
+
*/
|
|
116
|
+
addCliOption(name: string, options: string[], preserve: boolean): Promise<this>;
|
|
117
|
+
/**
|
|
118
|
+
* Adds multiple CLI options to the command.
|
|
119
|
+
*
|
|
120
|
+
* @param {object} options - Object mapping option names to [flag, description] arrays
|
|
121
|
+
* @param {boolean} preserve - Whether to preserve option names in the list
|
|
122
|
+
* @returns {this} Returns this instance for method chaining
|
|
123
|
+
*/
|
|
124
|
+
addCliOptions(options: object, preserve: boolean): this;
|
|
125
|
+
/**
|
|
126
|
+
* Resolves a theme file name to a FileObject and validates its existence.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} fileName - The theme file name or path
|
|
129
|
+
* @param {object} cwd - The current working directory object
|
|
130
|
+
* @returns {Promise<FileObject>} The resolved and validated FileObject
|
|
131
|
+
* @throws {Sass} If the file does not exist
|
|
132
|
+
*/
|
|
133
|
+
resolveThemeFileName(fileName: string, cwd: object): Promise<FileObject>;
|
|
134
|
+
#private;
|
|
135
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main compiler class for processing theme source files.
|
|
3
|
+
* Handles the complete compilation pipeline from source to VS Code theme output.
|
|
4
|
+
*/
|
|
5
|
+
export default class Compiler {
|
|
6
|
+
/**
|
|
7
|
+
* Compiles a theme source file into a VS Code colour theme.
|
|
8
|
+
* Processes configuration, variables, imports, and theme definitions.
|
|
9
|
+
*
|
|
10
|
+
* @param {Theme} theme - The file object containing source data and metadata
|
|
11
|
+
* @returns {Promise<void>} Resolves when compilation is complete
|
|
12
|
+
*/
|
|
13
|
+
compile(theme: Theme): Promise<void>;
|
|
14
|
+
#private;
|
|
15
|
+
}
|
|
16
|
+
import Theme from "./Theme.js";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluator class for resolving variables and colour tokens in theme objects.
|
|
3
|
+
* Handles recursive substitution of token references in arrays of objects
|
|
4
|
+
* with support for colour manipulation functions.
|
|
5
|
+
*/
|
|
6
|
+
export default class Evaluator {
|
|
7
|
+
/**
|
|
8
|
+
* Regular expression used to locate variable substitution tokens. Supports:
|
|
9
|
+
* - POSIX-ish: $(variable.path)
|
|
10
|
+
* - Legacy: $variable.path
|
|
11
|
+
* - Braced: ${variable.path}
|
|
12
|
+
*
|
|
13
|
+
* Capturing groups allow extraction of the inner path variant irrespective
|
|
14
|
+
* of wrapping style. The pattern captures (entireMatch, posix, legacy,
|
|
15
|
+
* braced).
|
|
16
|
+
*
|
|
17
|
+
* @type {RegExp}
|
|
18
|
+
*/
|
|
19
|
+
static sub: RegExp;
|
|
20
|
+
/**
|
|
21
|
+
* Regular expression for matching colour / transformation function calls
|
|
22
|
+
* within token strings, e.g. `darken($(std.accent), 10)`.
|
|
23
|
+
*
|
|
24
|
+
* @type {RegExp}
|
|
25
|
+
*/
|
|
26
|
+
static func: RegExp;
|
|
27
|
+
/**
|
|
28
|
+
* Extracts a variable name from a string containing variable syntax.
|
|
29
|
+
* Supports $(var), $var, and ${var} patterns.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} [str] - String that may contain a variable reference
|
|
32
|
+
* @returns {string|null} The variable name or null if none found
|
|
33
|
+
*/
|
|
34
|
+
static extractVariableName(str?: string): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts function name and arguments from a string containing function syntax.
|
|
37
|
+
* Supports functionName(args) patterns.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} [str] - String that may contain a function call
|
|
40
|
+
* @returns {{func:string, args:string}|null} Object with {func, args} or null if none found
|
|
41
|
+
*/
|
|
42
|
+
static extractFunctionCall(str?: string): {
|
|
43
|
+
func: string;
|
|
44
|
+
args: string;
|
|
45
|
+
} | null;
|
|
46
|
+
get pool(): ThemePool;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve variables and theme token entries in two distinct passes to ensure
|
|
49
|
+
* deterministic scoping and to prevent partially-resolved values from
|
|
50
|
+
* leaking between stages:
|
|
51
|
+
*
|
|
52
|
+
* 1. Variable pass: each variable is resolved only with access to the
|
|
53
|
+
* variable set itself (no theme values yet). This ensures variables are
|
|
54
|
+
* self-contained building blocks.
|
|
55
|
+
* 2. Theme pass: theme entries are then resolved against the union of the
|
|
56
|
+
* fully-resolved variables plus (progressively) the theme entries. This
|
|
57
|
+
* allows theme keys to reference variables and other theme keys.
|
|
58
|
+
*
|
|
59
|
+
* Implementation details:
|
|
60
|
+
* - The internal lookup map persists for the lifetime of this instance; new
|
|
61
|
+
* entries overwrite prior values (last write wins) so previously resolved
|
|
62
|
+
* data can seed later evaluations without a rebuild.
|
|
63
|
+
* - Input array is mutated in-place (`value` fields change).
|
|
64
|
+
* - No return value. Evident by the absence of a return statement.
|
|
65
|
+
*
|
|
66
|
+
* @param {Array<{flatPath:string,value:unknown}>} decomposed - Variable entries to resolve.
|
|
67
|
+
* @example
|
|
68
|
+
* // Example decomposed input with variables and theme references
|
|
69
|
+
* const evaluator = new Evaluator();
|
|
70
|
+
* const decomposed = [
|
|
71
|
+
* { flatPath: 'vars.primary', value: '#3366cc' },
|
|
72
|
+
* { flatPath: 'theme.colors.background', value: '$(vars.primary)' },
|
|
73
|
+
* { flatPath: 'theme.colors.accent', value: 'lighten($(vars.primary), 20)' }
|
|
74
|
+
* ];
|
|
75
|
+
* evaluator.evaluate(decomposed);
|
|
76
|
+
* // After evaluation, values are resolved:
|
|
77
|
+
* // decomposed[1].value === '#3366cc'
|
|
78
|
+
* // decomposed[2].value === '#5588dd' (lightened color)
|
|
79
|
+
*/
|
|
80
|
+
evaluate(decomposed: Array<{
|
|
81
|
+
flatPath: string;
|
|
82
|
+
value: unknown;
|
|
83
|
+
}>): void;
|
|
84
|
+
#private;
|
|
85
|
+
}
|
|
86
|
+
import ThemePool from "./ThemePool.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command handler for linting theme files for potential issues.
|
|
3
|
+
* Validates tokenColors for duplicate scopes, undefined variables, unused
|
|
4
|
+
* variables, and precedence issues that could cause unexpected theme
|
|
5
|
+
* behaviour.
|
|
6
|
+
*/
|
|
7
|
+
export default class LintCommand extends Command {
|
|
8
|
+
static SECTIONS: {
|
|
9
|
+
VARS: string;
|
|
10
|
+
COLORS: string;
|
|
11
|
+
TOKEN_COLORS: string;
|
|
12
|
+
SEMANTIC_TOKEN_COLORS: string;
|
|
13
|
+
};
|
|
14
|
+
static SEVERITY: {
|
|
15
|
+
HIGH: string;
|
|
16
|
+
MEDIUM: string;
|
|
17
|
+
LOW: string;
|
|
18
|
+
};
|
|
19
|
+
static ISSUE_TYPES: {
|
|
20
|
+
DUPLICATE_SCOPE: string;
|
|
21
|
+
UNDEFINED_VARIABLE: string;
|
|
22
|
+
UNUSED_VARIABLE: string;
|
|
23
|
+
PRECEDENCE_ISSUE: string;
|
|
24
|
+
};
|
|
25
|
+
static TEMPLATES: {
|
|
26
|
+
ENTRY_NAME: (index: any) => string;
|
|
27
|
+
OBJECT_NAME: (index: any) => string;
|
|
28
|
+
VARIABLE_PREFIX: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new LintCommand instance.
|
|
32
|
+
*
|
|
33
|
+
* @param {object} base - Base configuration containing cwd and packageJson
|
|
34
|
+
*/
|
|
35
|
+
constructor(base: object);
|
|
36
|
+
/**
|
|
37
|
+
* Executes the lint command for a given theme file.
|
|
38
|
+
* Validates the theme and reports any issues found.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} inputArg - Path to the theme file to lint
|
|
41
|
+
* @param {object} options - Linting options
|
|
42
|
+
* @returns {Promise<void>} Resolves when linting is complete
|
|
43
|
+
*/
|
|
44
|
+
execute(inputArg: string, options?: object): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Public method to lint a theme and return structured results for external
|
|
47
|
+
* consumption.
|
|
48
|
+
*
|
|
49
|
+
* Returns categorized lint results for tokenColors, semanticTokenColors, and colors.
|
|
50
|
+
*
|
|
51
|
+
* @param {Theme} theme - The compiled theme object
|
|
52
|
+
* @returns {Promise<object>} Object containing categorized lint results
|
|
53
|
+
*/
|
|
54
|
+
lint(theme: Theme): Promise<object>;
|
|
55
|
+
#private;
|
|
56
|
+
}
|
|
57
|
+
import Command from "./Command.js";
|
|
58
|
+
import Theme from "./Theme.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command handler for resolving theme tokens and variables to their final values.
|
|
3
|
+
* Provides introspection into the theme resolution process and variable dependencies.
|
|
4
|
+
*/
|
|
5
|
+
export default class ResolveCommand extends Command {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new ResolveCommand instance.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} base - Base configuration containing cwd and packageJson
|
|
10
|
+
*/
|
|
11
|
+
constructor(base: object);
|
|
12
|
+
/**
|
|
13
|
+
* Executes the resolve command for a given theme file and option.
|
|
14
|
+
* Validates mutual exclusivity of options and delegates to appropriate resolver.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} inputArg - Path to the theme file to resolve
|
|
17
|
+
* @param {object} options - Resolution options (token, etc.)
|
|
18
|
+
* @returns {Promise<void>} Resolves when resolution is complete
|
|
19
|
+
*/
|
|
20
|
+
execute(inputArg: string, options?: object): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves a specific color to its final value and displays the resolution trail.
|
|
23
|
+
* Shows the complete dependency chain for the requested color.
|
|
24
|
+
*
|
|
25
|
+
* @param {object} theme - The compiled theme object with pool
|
|
26
|
+
* @param {string} colorName - The color key to resolve
|
|
27
|
+
* @returns {void}
|
|
28
|
+
* @example
|
|
29
|
+
* // Resolve a color variable from a compiled theme
|
|
30
|
+
* await resolveCommand.resolveColor(theme, 'colors.primary');
|
|
31
|
+
* // Output:
|
|
32
|
+
* // colors.primary:
|
|
33
|
+
* // $(vars.accent)
|
|
34
|
+
* // → #3366cc
|
|
35
|
+
* // Resolution: #3366cc
|
|
36
|
+
*/
|
|
37
|
+
resolveColor(theme: object, colorName: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Resolves a specific tokenColors scope to its final value and displays the resolution trail.
|
|
40
|
+
* Shows all matching scopes with disambiguation when multiple matches are found.
|
|
41
|
+
*
|
|
42
|
+
* @param {object} theme - The compiled theme object with output
|
|
43
|
+
* @param {string} scopeName - The scope to resolve (e.g., "entity.name.class" or "entity.name.class.1")
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
resolveTokenColor(theme: object, scopeName: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves a specific semanticTokenColors scope to its final value.
|
|
49
|
+
* Uses the same logic as tokenColors since they have identical structure.
|
|
50
|
+
*
|
|
51
|
+
* @param {object} theme - The compiled theme object with output
|
|
52
|
+
* @param {string} scopeName - The scope to resolve (e.g., "keyword" or "keyword.1")
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
resolveSemanticTokenColor(theme: object, scopeName: string): void;
|
|
56
|
+
#private;
|
|
57
|
+
}
|
|
58
|
+
import Command from "./Command.js";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} SessionOptions
|
|
3
|
+
* @property {boolean} [watch] - Whether to enable file watching
|
|
4
|
+
* @property {boolean} [nerd] - Whether to show verbose output
|
|
5
|
+
* @property {boolean} [dryRun] - Whether to skip file writes
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} BuildRecord
|
|
9
|
+
* @property {number} timestamp - Epoch ms when the build started
|
|
10
|
+
* @property {number} loadTime - Time (ms) spent loading theme sources
|
|
11
|
+
* @property {number} buildTime - Time (ms) spent compiling the theme
|
|
12
|
+
* @property {number} writeTime - Time (ms) spent writing the output file
|
|
13
|
+
* @property {boolean} success - Whether the build completed successfully
|
|
14
|
+
* @property {string} [error] - Error message when success is false
|
|
15
|
+
*/
|
|
16
|
+
export default class Session {
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new Session instance for managing theme compilation lifecycle.
|
|
19
|
+
* Sessions provide persistent state across rebuilds, error tracking, and
|
|
20
|
+
* individual theme management within the build system.
|
|
21
|
+
*
|
|
22
|
+
* @param {Command} command - The parent build command instance
|
|
23
|
+
* @param {Theme} theme - The theme instance to manage
|
|
24
|
+
* @param {SessionOptions} options - Build configuration options
|
|
25
|
+
*/
|
|
26
|
+
constructor(command: Command, theme: Theme, options: SessionOptions);
|
|
27
|
+
get theme(): Theme;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the theme instance managed by this session.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Theme} The theme instance
|
|
32
|
+
*/
|
|
33
|
+
getTheme(): Theme;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the command instance orchestrating this session.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Command} The command instance
|
|
38
|
+
*/
|
|
39
|
+
getCommand(): Command;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the session options.
|
|
42
|
+
*
|
|
43
|
+
* @returns {SessionOptions} The session options
|
|
44
|
+
*/
|
|
45
|
+
getOptions(): SessionOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the build history for this session.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Array<BuildRecord>} Array of build records
|
|
50
|
+
*/
|
|
51
|
+
getHistory(): Array<BuildRecord>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the build statistics for this session.
|
|
54
|
+
*
|
|
55
|
+
* @returns {{builds: number, failures: number}} Build statistics
|
|
56
|
+
*/
|
|
57
|
+
getStats(): {
|
|
58
|
+
builds: number;
|
|
59
|
+
failures: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a build is currently in progress.
|
|
63
|
+
*
|
|
64
|
+
* @returns {boolean} True if building
|
|
65
|
+
*/
|
|
66
|
+
isBuilding(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if watch mode is enabled.
|
|
69
|
+
*
|
|
70
|
+
* @returns {boolean} True if watching
|
|
71
|
+
*/
|
|
72
|
+
isWatching(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if there's an active file watcher.
|
|
75
|
+
*
|
|
76
|
+
* @returns {boolean} True if watcher exists
|
|
77
|
+
*/
|
|
78
|
+
hasWatcher(): boolean;
|
|
79
|
+
run(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Displays a formatted summary of the session's build statistics and performance.
|
|
82
|
+
* Shows total builds, success/failure counts, success rate percentage, and timing
|
|
83
|
+
* information from the most recent build. Used during session cleanup to provide
|
|
84
|
+
* final statistics to the user.
|
|
85
|
+
*
|
|
86
|
+
* @returns {void}
|
|
87
|
+
*/
|
|
88
|
+
showSummary(): void;
|
|
89
|
+
#private;
|
|
90
|
+
}
|
|
91
|
+
export type SessionOptions = {
|
|
92
|
+
/**
|
|
93
|
+
* - Whether to enable file watching
|
|
94
|
+
*/
|
|
95
|
+
watch?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* - Whether to show verbose output
|
|
98
|
+
*/
|
|
99
|
+
nerd?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* - Whether to skip file writes
|
|
102
|
+
*/
|
|
103
|
+
dryRun?: boolean;
|
|
104
|
+
};
|
|
105
|
+
export type BuildRecord = {
|
|
106
|
+
/**
|
|
107
|
+
* - Epoch ms when the build started
|
|
108
|
+
*/
|
|
109
|
+
timestamp: number;
|
|
110
|
+
/**
|
|
111
|
+
* - Time (ms) spent loading theme sources
|
|
112
|
+
*/
|
|
113
|
+
loadTime: number;
|
|
114
|
+
/**
|
|
115
|
+
* - Time (ms) spent compiling the theme
|
|
116
|
+
*/
|
|
117
|
+
buildTime: number;
|
|
118
|
+
/**
|
|
119
|
+
* - Time (ms) spent writing the output file
|
|
120
|
+
*/
|
|
121
|
+
writeTime: number;
|
|
122
|
+
/**
|
|
123
|
+
* - Whether the build completed successfully
|
|
124
|
+
*/
|
|
125
|
+
success: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* - Error message when success is false
|
|
128
|
+
*/
|
|
129
|
+
error?: string;
|
|
130
|
+
};
|
|
131
|
+
import Theme from "./Theme.js";
|
|
132
|
+
import Command from "./Command.js";
|
package/types/Theme.d.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import type { FileObject, DirectoryObject, Cache } from '@gesslar/toolkit';
|
|
2
|
+
/**
|
|
3
|
+
* Theme class: manages the lifecycle of a theme compilation unit.
|
|
4
|
+
* See file-level docstring for responsibilities.
|
|
5
|
+
*/
|
|
6
|
+
export default class Theme {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new Theme instance.
|
|
9
|
+
*
|
|
10
|
+
* @param {FileObject} themeFile - The source theme file object
|
|
11
|
+
* @param {DirectoryObject} cwd - The project's directory.
|
|
12
|
+
* @param {object} options - Compilation options
|
|
13
|
+
*/
|
|
14
|
+
constructor(themeFile: FileObject, cwd: DirectoryObject, options: object);
|
|
15
|
+
/**
|
|
16
|
+
* Resets the theme's compilation state, clearing output and lookup data.
|
|
17
|
+
* Used when recompiling in watch mode or clearing previous state.
|
|
18
|
+
*/
|
|
19
|
+
reset(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the current working directory.
|
|
22
|
+
*
|
|
23
|
+
* @returns {DirectoryObject} The current working directory
|
|
24
|
+
*/
|
|
25
|
+
getCwd(): DirectoryObject;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the compilation options.
|
|
28
|
+
*
|
|
29
|
+
* @returns {object} The compilation options object
|
|
30
|
+
*/
|
|
31
|
+
getOptions(): object;
|
|
32
|
+
/**
|
|
33
|
+
* Gets a specific compilation option.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} option - The option name to retrieve
|
|
36
|
+
* @returns {unknown} The option value or undefined if not set
|
|
37
|
+
*/
|
|
38
|
+
getOption(option: string): unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the cache instance for theme compilation.
|
|
41
|
+
*
|
|
42
|
+
* @param {Cache} cache - The cache instance to use for file operations
|
|
43
|
+
* @returns {this} Returns this instance for method chaining
|
|
44
|
+
*/
|
|
45
|
+
setCache(cache: Cache): this;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the cache instance.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Cache|null} The cache instance or null if not set
|
|
50
|
+
*/
|
|
51
|
+
getCache(): Cache | null;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the theme name.
|
|
54
|
+
*
|
|
55
|
+
* @returns {string} The theme name derived from the source file
|
|
56
|
+
*/
|
|
57
|
+
getName(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the output file name for the compiled theme.
|
|
60
|
+
*
|
|
61
|
+
* @returns {string} The output file name with extension
|
|
62
|
+
*/
|
|
63
|
+
getOutputFileName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Gets the source file object.
|
|
66
|
+
*
|
|
67
|
+
* @returns {FileObject} The source theme file
|
|
68
|
+
*/
|
|
69
|
+
getSourceFile(): FileObject;
|
|
70
|
+
/**
|
|
71
|
+
* Sets the compiled theme output object and updates derived JSON and hash.
|
|
72
|
+
*
|
|
73
|
+
* @param {object} data - The compiled theme output object
|
|
74
|
+
* @returns {this} Returns this instance for method chaining
|
|
75
|
+
*/
|
|
76
|
+
setOutput(data: object): this;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the compiled theme output object.
|
|
79
|
+
*
|
|
80
|
+
* @returns {object|null} The compiled theme output
|
|
81
|
+
*/
|
|
82
|
+
getOutput(): object | null;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the source has colors defined.
|
|
85
|
+
*
|
|
86
|
+
* @returns {boolean} True if source has theme colors
|
|
87
|
+
*/
|
|
88
|
+
sourceHasColors(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the source has token colors defined.
|
|
91
|
+
*
|
|
92
|
+
* @returns {boolean} True if source has theme token colors
|
|
93
|
+
*/
|
|
94
|
+
sourceHasTokenColors(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if the source has semantic token colors defined.
|
|
97
|
+
*
|
|
98
|
+
* @returns {boolean} True if source has theme semantic token colors
|
|
99
|
+
*/
|
|
100
|
+
sourceHasSemanticTokenColors(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Checks if the source has theme configuration.
|
|
103
|
+
*
|
|
104
|
+
* @returns {boolean} True if source has theme data
|
|
105
|
+
*/
|
|
106
|
+
sourceHasTheme(): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if the source has variables.
|
|
109
|
+
*
|
|
110
|
+
* @returns {boolean} True if source has vars section
|
|
111
|
+
*/
|
|
112
|
+
sourceHasVars(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the source has config section.
|
|
115
|
+
*
|
|
116
|
+
* @returns {boolean} True if source has config
|
|
117
|
+
*/
|
|
118
|
+
sourceHasConfig(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the source colors data.
|
|
121
|
+
*
|
|
122
|
+
* @returns {object|null} The colors object or null if not defined
|
|
123
|
+
*/
|
|
124
|
+
getSourceColors(): object | null;
|
|
125
|
+
/**
|
|
126
|
+
* Gets the source token colors data.
|
|
127
|
+
*
|
|
128
|
+
* @returns {Array|null} The token colors array or null if not defined
|
|
129
|
+
*/
|
|
130
|
+
getSourceTokenColors(): any[] | null;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the source semantic token colors data.
|
|
133
|
+
*
|
|
134
|
+
* @returns {object|null} The semantic token colors object or null if not defined
|
|
135
|
+
*/
|
|
136
|
+
getSourceSemanticTokenColors(): object | null;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the set of file dependencies.
|
|
139
|
+
*
|
|
140
|
+
* @returns {Set<Dependency>} Set of dependency files
|
|
141
|
+
*/
|
|
142
|
+
getDependencies(): Set<Dependency>;
|
|
143
|
+
/**
|
|
144
|
+
* Adds a dependency to the theme with its source data.
|
|
145
|
+
*
|
|
146
|
+
* @param {FileObject} file - The dependency file object
|
|
147
|
+
* @param {object} source - The parsed source data from the file
|
|
148
|
+
* @returns {this} Returns this instance for method chaining
|
|
149
|
+
*/
|
|
150
|
+
addDependency(file: FileObject, source: object): this;
|
|
151
|
+
/**
|
|
152
|
+
* Checks if the theme has any dependencies.
|
|
153
|
+
*
|
|
154
|
+
* @returns {boolean} True if theme has dependencies
|
|
155
|
+
*/
|
|
156
|
+
hasDependencies(): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Gets the parsed source data from the theme file.
|
|
159
|
+
*
|
|
160
|
+
* @returns {object|null} The parsed source data
|
|
161
|
+
*/
|
|
162
|
+
getSource(): object | null;
|
|
163
|
+
/**
|
|
164
|
+
* Gets the variable lookup data for theme compilation.
|
|
165
|
+
*
|
|
166
|
+
* @returns {object|null} The lookup data object
|
|
167
|
+
*/
|
|
168
|
+
getLookup(): object | null;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the variable lookup data for theme compilation.
|
|
171
|
+
*
|
|
172
|
+
* @param {object} data - The lookup data object
|
|
173
|
+
* @returns {this} Returns this instance for method chaining
|
|
174
|
+
*/
|
|
175
|
+
setLookup(data: object): this;
|
|
176
|
+
/**
|
|
177
|
+
* Gets the pool data for variable resolution tracking or null if one has
|
|
178
|
+
* not been set.
|
|
179
|
+
*
|
|
180
|
+
* @returns {ThemePool|null} The pool for this theme.
|
|
181
|
+
*/
|
|
182
|
+
getPool(): ThemePool | null;
|
|
183
|
+
/**
|
|
184
|
+
* Sets the pool data for variable resolution tracking. May not be over-
|
|
185
|
+
* written publicly. May only be reset
|
|
186
|
+
*
|
|
187
|
+
* @see reset
|
|
188
|
+
*
|
|
189
|
+
* @param {ThemePool} pool - The pool to assign to this theme
|
|
190
|
+
* @throws {Error} If there is already a pool.
|
|
191
|
+
* @returns {this} Returns this instance for method chaining
|
|
192
|
+
*/
|
|
193
|
+
setPool(pool: ThemePool): this;
|
|
194
|
+
/**
|
|
195
|
+
* Method to return true or false if this theme has a pool.
|
|
196
|
+
*
|
|
197
|
+
* @returns {boolean} True if a pool has been set, false otherwise.
|
|
198
|
+
*/
|
|
199
|
+
hasPool(): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Checks if the theme has compiled output.
|
|
202
|
+
*
|
|
203
|
+
* @returns {boolean} True if theme has been compiled
|
|
204
|
+
*/
|
|
205
|
+
hasOutput(): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Checks if the theme has loaded source data.
|
|
208
|
+
*
|
|
209
|
+
* @returns {boolean} True if source data is available
|
|
210
|
+
*/
|
|
211
|
+
hasSource(): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if the theme has a cache instance.
|
|
214
|
+
*
|
|
215
|
+
* @returns {boolean} True if cache is available
|
|
216
|
+
*/
|
|
217
|
+
hasCache(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Checks if the theme has lookup data.
|
|
220
|
+
*
|
|
221
|
+
* @returns {boolean} True if lookup data exists
|
|
222
|
+
*/
|
|
223
|
+
hasLookup(): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Checks if the theme is ready to be compiled.
|
|
226
|
+
* Requires source data and cache to be available.
|
|
227
|
+
*
|
|
228
|
+
* @returns {boolean} True if theme can be compiled
|
|
229
|
+
*/
|
|
230
|
+
isReady(): boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Checks if the theme has been fully compiled.
|
|
233
|
+
* Requires output, pool, and lookup data to be present.
|
|
234
|
+
*
|
|
235
|
+
* @returns {boolean} True if theme is fully compiled
|
|
236
|
+
*/
|
|
237
|
+
isCompiled(): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Checks if the theme can be built/compiled.
|
|
240
|
+
* Same as isReady() but with more semantic naming.
|
|
241
|
+
*
|
|
242
|
+
* @returns {boolean} True if build can proceed
|
|
243
|
+
*/
|
|
244
|
+
canBuild(): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Checks if the theme can be written to output.
|
|
247
|
+
* Requires the theme to be compiled.
|
|
248
|
+
*
|
|
249
|
+
* @returns {boolean} True if write can proceed
|
|
250
|
+
*/
|
|
251
|
+
canWrite(): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Checks if the theme is in a valid state for operation.
|
|
254
|
+
* Basic validation that core properties are set.
|
|
255
|
+
*
|
|
256
|
+
* @returns {boolean} True if theme state is valid
|
|
257
|
+
*/
|
|
258
|
+
isValid(): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Loads and parses the theme source file.
|
|
261
|
+
* Validates that the source contains required configuration.
|
|
262
|
+
* Skips loading if no cache is available (extension use case).
|
|
263
|
+
*
|
|
264
|
+
* @returns {Promise<this>} Returns this instance for method chaining
|
|
265
|
+
* @throws {Sass} If source file lacks required 'config' property
|
|
266
|
+
*/
|
|
267
|
+
load(): Promise<this>;
|
|
268
|
+
/**
|
|
269
|
+
* Builds the theme by compiling source data into final output.
|
|
270
|
+
* Main entry point for theme compilation process.
|
|
271
|
+
*
|
|
272
|
+
* @returns {Promise<this>} Returns this instance for method chaining
|
|
273
|
+
*/
|
|
274
|
+
build(): Promise<this>;
|
|
275
|
+
/**
|
|
276
|
+
* Writes the compiled theme output to a file or stdout.
|
|
277
|
+
* Handles dry-run mode, output directory creation, and duplicate write prevention.
|
|
278
|
+
*
|
|
279
|
+
* @param {boolean} [force] - Force a write. Used by the rebuild CLI option.
|
|
280
|
+
* @returns {Promise<void>} Resolves when write operation is complete
|
|
281
|
+
*/
|
|
282
|
+
write(force?: boolean): Promise<void>;
|
|
283
|
+
#private;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Dependency class represents a theme file dependency.
|
|
287
|
+
* Manages the relationship between a file reference and its parsed source data.
|
|
288
|
+
*/
|
|
289
|
+
export class Dependency {
|
|
290
|
+
/**
|
|
291
|
+
* Sets the file object for this dependency.
|
|
292
|
+
*
|
|
293
|
+
* @param {FileObject} file - The file object of this dependency.
|
|
294
|
+
* @returns {this} This.
|
|
295
|
+
*/
|
|
296
|
+
setSourceFile(file: FileObject): this;
|
|
297
|
+
/**
|
|
298
|
+
* Get the file object for this depenency.
|
|
299
|
+
*
|
|
300
|
+
* @returns {FileObject} The file object of this dependency.
|
|
301
|
+
*/
|
|
302
|
+
getSourceFile(): FileObject;
|
|
303
|
+
/**
|
|
304
|
+
* Sets the source object for this dependency.
|
|
305
|
+
*
|
|
306
|
+
* @param {object} source - The parsed JSON from the file after loading.
|
|
307
|
+
* @returns {this} This.
|
|
308
|
+
*/
|
|
309
|
+
setSource(source: object): this;
|
|
310
|
+
/**
|
|
311
|
+
* Gets the parsed source data for this dependency.
|
|
312
|
+
*
|
|
313
|
+
* @returns {object|null} The parsed source data
|
|
314
|
+
*/
|
|
315
|
+
getSource(): object | null;
|
|
316
|
+
/**
|
|
317
|
+
* Checks if the dependency has a source file.
|
|
318
|
+
*
|
|
319
|
+
* @returns {boolean} True if source file is set
|
|
320
|
+
*/
|
|
321
|
+
hasSourceFile(): boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Checks if the dependency has parsed source data.
|
|
324
|
+
*
|
|
325
|
+
* @returns {boolean} True if source data is available
|
|
326
|
+
*/
|
|
327
|
+
hasSource(): boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Checks if the dependency is fully initialized.
|
|
330
|
+
*
|
|
331
|
+
* @returns {boolean} True if both file and source are set
|
|
332
|
+
*/
|
|
333
|
+
isComplete(): boolean;
|
|
334
|
+
#private;
|
|
335
|
+
}
|
|
336
|
+
import ThemePool from "./ThemePool.js";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThemePool represents a collection of ThemeTokens serving both as a
|
|
3
|
+
* lookup of string>ThemeToken and dependencies.
|
|
4
|
+
*
|
|
5
|
+
* @class ThemePool
|
|
6
|
+
*/
|
|
7
|
+
export default class ThemePool {
|
|
8
|
+
/**
|
|
9
|
+
* Returns the map of encoded theme token ids to their token object.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Map<string, ThemeToken>} Map of tokens to their children.
|
|
12
|
+
*/
|
|
13
|
+
getTokens(): Map<string, ThemeToken>;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves a resolved token by its name.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} name - The token to look up.
|
|
18
|
+
* @returns {string|undefined} The resolved token string or undefined.
|
|
19
|
+
*/
|
|
20
|
+
lookup(name: string): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Sets a resolved value for a token key.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} key - The token key.
|
|
25
|
+
* @param {string} value - The resolved value.
|
|
26
|
+
*/
|
|
27
|
+
resolve(key: string, value: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Sets a raw resolved value for a token key.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} key - The token key.
|
|
32
|
+
* @param {string} value - The raw resolved value.
|
|
33
|
+
*/
|
|
34
|
+
rawResolve(key: string, value: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a token name exists in resolved map.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} name - The token name to check.
|
|
39
|
+
* @returns {boolean} True if the token exists.
|
|
40
|
+
*/
|
|
41
|
+
has(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a token exists by its name.
|
|
44
|
+
*
|
|
45
|
+
* @param {ThemeToken} token - The token to check.
|
|
46
|
+
* @returns {boolean} True if the token exists.
|
|
47
|
+
*/
|
|
48
|
+
hasToken(token: ThemeToken): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves a token's dependency.
|
|
51
|
+
*
|
|
52
|
+
* @param {ThemeToken} token - The token to look up.
|
|
53
|
+
* @returns {ThemeToken?} The dependent token with the given token, or undefined.
|
|
54
|
+
*/
|
|
55
|
+
reverseLookup(token: ThemeToken): ThemeToken | null;
|
|
56
|
+
/**
|
|
57
|
+
* Adds a token to the pool, optionally setting up dependencies if required.
|
|
58
|
+
*
|
|
59
|
+
* @param {ThemeToken} token - The token to add.
|
|
60
|
+
* @param {ThemeToken} [dependency] - The dependent token.
|
|
61
|
+
* @returns {ThemeToken} The token that was added.
|
|
62
|
+
*/
|
|
63
|
+
addToken(token: ThemeToken, dependency?: ThemeToken): ThemeToken;
|
|
64
|
+
/**
|
|
65
|
+
* Finds a token by its value.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} value - The value to search for.
|
|
68
|
+
* @returns {ThemeToken|undefined} The found token or undefined.
|
|
69
|
+
*/
|
|
70
|
+
findToken(value: string): ThemeToken | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if one token is an ancestor of another using reverse lookup.
|
|
73
|
+
*
|
|
74
|
+
* @param {ThemeToken} candidate - Potential ancestor token.
|
|
75
|
+
* @param {ThemeToken} token - Potential descendant token.
|
|
76
|
+
* @returns {boolean} True if candidate is an ancestor of token.
|
|
77
|
+
*/
|
|
78
|
+
isAncestorOf(candidate: ThemeToken, token: ThemeToken): boolean;
|
|
79
|
+
#private;
|
|
80
|
+
}
|
|
81
|
+
import ThemeToken from "./ThemeToken.js";
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThemeToken represents a single token in a theme tree, encapsulating theme
|
|
3
|
+
* token data and relationships.
|
|
4
|
+
*
|
|
5
|
+
* Provides property management, factory methods, tree integration, and
|
|
6
|
+
* serialization.
|
|
7
|
+
*
|
|
8
|
+
* @class ThemeToken
|
|
9
|
+
*/
|
|
10
|
+
export default class ThemeToken {
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a ThemeToken with a given token name.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} name - The token name for this token.
|
|
15
|
+
*/
|
|
16
|
+
constructor(name: string);
|
|
17
|
+
/**
|
|
18
|
+
* Adds this token to a ThemePool with optional dependency.
|
|
19
|
+
*
|
|
20
|
+
* @param {ThemePool} pool - The pool to add to.
|
|
21
|
+
* @param {ThemeToken} [dependency] - Optional dependency token.
|
|
22
|
+
* @returns {ThemeToken} This token instance.
|
|
23
|
+
*/
|
|
24
|
+
addToPool(pool?: ThemePool, dependency?: ThemeToken): ThemeToken;
|
|
25
|
+
/**
|
|
26
|
+
* Sets the name of this token (only if not already set).
|
|
27
|
+
*
|
|
28
|
+
* @param {string} name - The token name.
|
|
29
|
+
* @returns {ThemeToken} This token instance.
|
|
30
|
+
*/
|
|
31
|
+
setName(name: string): ThemeToken;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the name of this token.
|
|
34
|
+
*
|
|
35
|
+
* @returns {string} The token name.
|
|
36
|
+
*/
|
|
37
|
+
getName(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the kind of this token (only if not already set).
|
|
40
|
+
*
|
|
41
|
+
* @param {string} kind - The token kind.
|
|
42
|
+
* @returns {ThemeToken} This token instance.
|
|
43
|
+
*/
|
|
44
|
+
setKind(kind: string): ThemeToken;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the kind of this token.
|
|
47
|
+
*
|
|
48
|
+
* @returns {string} The token kind.
|
|
49
|
+
*/
|
|
50
|
+
getKind(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the value of this token.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} value - The token value.
|
|
55
|
+
* @returns {ThemeToken} This token instance.
|
|
56
|
+
*/
|
|
57
|
+
setValue(value: string): ThemeToken;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the value of this token.
|
|
60
|
+
*
|
|
61
|
+
* @returns {string} The token value.
|
|
62
|
+
*/
|
|
63
|
+
getValue(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the raw value of this token (only if not already set).
|
|
66
|
+
*
|
|
67
|
+
* @param {string} raw - The raw token value.
|
|
68
|
+
* @returns {ThemeToken} This token instance.
|
|
69
|
+
*/
|
|
70
|
+
setRawValue(raw: string): ThemeToken;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the raw value of this token.
|
|
73
|
+
*
|
|
74
|
+
* @returns {string} The raw token value.
|
|
75
|
+
*/
|
|
76
|
+
getRawValue(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Sets the dependency of this token (only if not already set).
|
|
79
|
+
*
|
|
80
|
+
* @param {ThemeToken} dependency - The dependency token.
|
|
81
|
+
* @returns {ThemeToken} This token instance.
|
|
82
|
+
*/
|
|
83
|
+
setDependency(dependency: ThemeToken): ThemeToken;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the dependency of this token.
|
|
86
|
+
*
|
|
87
|
+
* @returns {ThemeToken|null} The dependency token or null.
|
|
88
|
+
*/
|
|
89
|
+
getDependency(): ThemeToken | null;
|
|
90
|
+
/**
|
|
91
|
+
* Sets the parent token key.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} tokenKey - The parent token key.
|
|
94
|
+
* @returns {ThemeToken} This token instance.
|
|
95
|
+
*/
|
|
96
|
+
setParentTokenKey(tokenKey: string): ThemeToken;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the parent token key.
|
|
99
|
+
*
|
|
100
|
+
* @returns {string|null} The parent token key or null.
|
|
101
|
+
*/
|
|
102
|
+
getParentTokenKey(): string | null;
|
|
103
|
+
/**
|
|
104
|
+
* Adds a trail of tokens to this token's trail array.
|
|
105
|
+
*
|
|
106
|
+
* @param {Array<ThemeToken>} trail - Array of tokens to add.
|
|
107
|
+
* @returns {ThemeToken} This token instance.
|
|
108
|
+
*/
|
|
109
|
+
addTrail(trail: Array<ThemeToken>): ThemeToken;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the trail array of this token.
|
|
112
|
+
*
|
|
113
|
+
* @returns {Array<ThemeToken>} The trail array.
|
|
114
|
+
*/
|
|
115
|
+
getTrail(): Array<ThemeToken>;
|
|
116
|
+
/**
|
|
117
|
+
* Sets the parsed color object for this token.
|
|
118
|
+
*
|
|
119
|
+
* @param {object} parsedColor - The parsed Culori color object
|
|
120
|
+
* @returns {ThemeToken} This token instance.
|
|
121
|
+
*/
|
|
122
|
+
setParsedColor(parsedColor: object): ThemeToken;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the parsed color object of this token.
|
|
125
|
+
*
|
|
126
|
+
* @returns {object|null} The parsed Culori color object or null.
|
|
127
|
+
*/
|
|
128
|
+
getParsedColor(): object | null;
|
|
129
|
+
/**
|
|
130
|
+
* Checks if this token has an ancestor with the given token name.
|
|
131
|
+
*
|
|
132
|
+
* @param {string} name - The name of the ancestor token to check for.
|
|
133
|
+
* @returns {boolean} True if ancestor exists.
|
|
134
|
+
*/
|
|
135
|
+
hasDependency(name: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Gets the ThemePool associated with this token.
|
|
138
|
+
*
|
|
139
|
+
* @returns {ThemePool} The associated pool.
|
|
140
|
+
*/
|
|
141
|
+
getPool(): ThemePool;
|
|
142
|
+
/**
|
|
143
|
+
* Returns a JSON representation of the ThemeToken.
|
|
144
|
+
*
|
|
145
|
+
* @returns {object} JSON representation of the ThemeToken
|
|
146
|
+
*/
|
|
147
|
+
toJSON(): object;
|
|
148
|
+
#private;
|
|
149
|
+
}
|
|
150
|
+
import ThemePool from "./ThemePool.js";
|
package/types/cli.d.ts
ADDED
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as Theme } from "./Theme.js";
|
|
2
|
+
export { default as Compiler } from "./Compiler.js";
|
|
3
|
+
export { default as Evaluator } from "./Evaluator.js";
|
|
4
|
+
export { default as Command } from "./Command.js";
|
|
5
|
+
export { default as BuildCommand } from "./BuildCommand.js";
|
|
6
|
+
export { default as LintCommand } from "./LintCommand.js";
|
|
7
|
+
export { default as ResolveCommand } from "./ResolveCommand.js";
|
|
8
|
+
export { default as Session } from "./Session.js";
|
|
9
|
+
export { default as Colour } from "./Colour.js";
|