@gesslar/sassy 0.21.1 → 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 +18 -7
- package/src/BuildCommand.js +1 -2
- package/src/Colour.js +1 -3
- package/src/Command.js +1 -37
- package/src/Compiler.js +1 -6
- package/src/Evaluator.js +1 -1
- package/src/LintCommand.js +1 -2
- package/src/ResolveCommand.js +3 -6
- package/src/Session.js +1 -4
- package/src/Theme.js +1 -7
- package/src/ThemePool.js +1 -1
- package/src/ThemeToken.js +1 -1
- package/src/cli.js +1 -5
- package/src/index.js +40 -0
- 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/src/Cache.js +0 -74
- package/src/Data.js +0 -533
- package/src/DirectoryObject.js +0 -188
- package/src/File.js +0 -346
- package/src/FileObject.js +0 -226
- package/src/Sass.js +0 -166
- package/src/Term.js +0 -175
- package/src/Type.js +0 -207
- package/src/Util.js +0 -132
- package/src/Valid.js +0 -50
|
@@ -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";
|
package/src/Cache.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import Sass from "./Sass.js"
|
|
2
|
-
import File from "./File.js"
|
|
3
|
-
import FileObject from "./FileObject.js"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* File system cache for theme compilation data with automatic invalidation.
|
|
7
|
-
* Provides intelligent caching of parsed JSON5/YAML files with mtime-based
|
|
8
|
-
* cache invalidation to optimize parallel theme compilation performance.
|
|
9
|
-
*
|
|
10
|
-
* The cache eliminates redundant file reads and parsing when multiple themes
|
|
11
|
-
* import the same dependency files, while ensuring data freshness through
|
|
12
|
-
* modification time checking.
|
|
13
|
-
*/
|
|
14
|
-
export default class Cache {
|
|
15
|
-
/** @type {Map<string, Date>} Map of file paths to last modification times */
|
|
16
|
-
#modifiedTimes = new Map()
|
|
17
|
-
/** @type {Map<string, object>} Map of file paths to parsed file data */
|
|
18
|
-
#dataCache = new Map()
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Removes cached data for a specific file from both time and data maps.
|
|
22
|
-
* Used when files are modified or when cache consistency needs to be
|
|
23
|
-
* maintained.
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
26
|
-
* @param {FileObject} file - The file object to remove from cache
|
|
27
|
-
* @returns {void}
|
|
28
|
-
*/
|
|
29
|
-
#cleanup(file) {
|
|
30
|
-
this.#modifiedTimes.delete(file.path)
|
|
31
|
-
this.#dataCache.delete(file.path)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Loads and caches parsed file data with automatic invalidation based on
|
|
36
|
-
* modification time.
|
|
37
|
-
*
|
|
38
|
-
* Implements a sophisticated caching strategy that checks file modification
|
|
39
|
-
* times to determine whether cached data is still valid, ensuring data
|
|
40
|
-
* freshness while optimizing performance for repeated file access during
|
|
41
|
-
* parallel theme compilation.
|
|
42
|
-
*
|
|
43
|
-
* @param {FileObject} fileObject - The file object to load and cache
|
|
44
|
-
* @returns {Promise<object>} The parsed file data (JSON5 or YAML)
|
|
45
|
-
* @throws {Sass} If the file cannot be found or accessed
|
|
46
|
-
*/
|
|
47
|
-
async loadCachedData(fileObject) {
|
|
48
|
-
const lastModified = await File.fileModified(fileObject)
|
|
49
|
-
|
|
50
|
-
if(lastModified === null)
|
|
51
|
-
throw Sass.new(`Unable to find file '${fileObject.path}'`)
|
|
52
|
-
|
|
53
|
-
if(this.#modifiedTimes.has(fileObject.path)) {
|
|
54
|
-
const lastCached = this.#modifiedTimes.get(fileObject.path)
|
|
55
|
-
|
|
56
|
-
if(lastModified > lastCached) {
|
|
57
|
-
this.#cleanup(fileObject)
|
|
58
|
-
} else {
|
|
59
|
-
if(!(this.#dataCache.has(fileObject.path)))
|
|
60
|
-
this.#cleanup(fileObject)
|
|
61
|
-
else {
|
|
62
|
-
return this.#dataCache.get(fileObject.path)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const data = await File.loadDataFile(fileObject)
|
|
68
|
-
|
|
69
|
-
this.#modifiedTimes.set(fileObject.path, lastModified)
|
|
70
|
-
this.#dataCache.set(fileObject.path, data)
|
|
71
|
-
|
|
72
|
-
return data
|
|
73
|
-
}
|
|
74
|
-
}
|