@gesslar/sassy 0.21.0 → 0.21.3

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 CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@gesslar/sassy",
3
- "version": "0.21.0",
3
+ "version": "0.21.3",
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
- "main": "src/cli.js",
9
+ "main": "src/index.js",
10
10
  "bin": "src/cli.js",
11
+ "exports": {
12
+ ".": "./src/index.js",
13
+ "./cli": "./src/cli.js"
14
+ },
11
15
  "files": [
12
16
  "src/",
13
17
  "UNLICENSE.txt"
@@ -43,6 +47,7 @@
43
47
  ],
44
48
  "dependencies": {
45
49
  "@gesslar/colours": "^0.0.1",
50
+ "@gesslar/toolkit": "^0.0.3",
46
51
  "chokidar": "^4.0.3",
47
52
  "color-support": "^1.1.3",
48
53
  "commander": "^14.0.1",
@@ -52,13 +57,13 @@
52
57
  "yaml": "^2.8.1"
53
58
  },
54
59
  "devDependencies": {
55
- "@stylistic/eslint-plugin": "^5.3.1",
60
+ "@stylistic/eslint-plugin": "^5.4.0",
56
61
  "@types/vscode": "^1.104.0",
57
62
  "@typescript-eslint/eslint-plugin": "^8.44.0",
58
63
  "@typescript-eslint/parser": "^8.44.0",
59
64
  "esbuild": "^0.25.10",
60
- "eslint": "^9.35.0",
61
- "eslint-plugin-jsdoc": "^59.0.1",
65
+ "eslint": "^9.36.0",
66
+ "eslint-plugin-jsdoc": "^60.1.0",
62
67
  "typescript": "^5.9.2"
63
68
  }
64
69
  }
@@ -1,10 +1,9 @@
1
1
  import {EventEmitter} from "node:events"
2
2
  import process from "node:process"
3
3
 
4
+ import {Sass, Term} from "@gesslar/toolkit"
4
5
  import Command from "./Command.js"
5
- import Sass from "./Sass.js"
6
6
  import Session from "./Session.js"
7
- import Term from "./Term.js"
8
7
  import Theme from "./Theme.js"
9
8
 
10
9
  /**
package/src/Colour.js CHANGED
@@ -13,10 +13,8 @@ import {
13
13
  parse
14
14
  } from "culori"
15
15
 
16
- import Sass from "./Sass.js"
16
+ import {Util, Sass} from "@gesslar/toolkit"
17
17
  import ThemeToken from "./ThemeToken.js"
18
- import Util from "./Util.js"
19
-
20
18
  // Cache for parsed colours to improve performance
21
19
  const _colourCache = new Map()
22
20
 
package/src/Command.js CHANGED
@@ -1,6 +1,4 @@
1
- import Sass from "./Sass.js"
2
- import FileObject from "./FileObject.js"
3
- import DirectoryObject from "./DirectoryObject.js"
1
+ import {Sass, FileObject, DirectoryObject, Cache} from "@gesslar/toolkit"
4
2
 
5
3
  /**
6
4
  * Base class for command-line interface commands.
package/src/Compiler.js CHANGED
@@ -11,14 +11,9 @@
11
11
  * Supports extension points for custom phases and output formats.
12
12
  */
13
13
 
14
- import Sass from "./Sass.js"
15
- import Data from "./Data.js"
14
+ import {Sass, Data, File, FileObject, Term, Util} from "@gesslar/toolkit"
16
15
  import Evaluator from "./Evaluator.js"
17
- import File from "./File.js"
18
- import FileObject from "./FileObject.js"
19
- import Term from "./Term.js"
20
16
  import Theme from "./Theme.js"
21
- import Util from "./Util.js"
22
17
 
23
18
  /**
24
19
  * Main compiler class for processing theme source files.
package/src/Evaluator.js CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  import {parse} from "culori"
15
15
 
16
- import Sass from "./Sass.js"
16
+ import {Sass} from "@gesslar/toolkit"
17
17
  import Colour from "./Colour.js"
18
18
  import ThemePool from "./ThemePool.js"
19
19
  import ThemeToken from "./ThemeToken.js"
@@ -56,6 +56,37 @@ export default class Evaluator {
56
56
  */
57
57
  static func = /(?<captured>(?<func>\w+)\((?<args>[^()]+)\))/
58
58
 
59
+ /**
60
+ * Extracts a variable name from a string containing variable syntax.
61
+ * Supports $(var), $var, and ${var} patterns.
62
+ *
63
+ * @param {string} [str] - String that may contain a variable reference
64
+ * @returns {string|null} The variable name or null if none found
65
+ */
66
+ static extractVariableName(str="") {
67
+ const {none, parens, braces} = Evaluator.sub.exec(str)?.groups ?? {}
68
+
69
+ return none || parens || braces || null
70
+ }
71
+
72
+ /**
73
+ * Extracts function name and arguments from a string containing function syntax.
74
+ * Supports functionName(args) patterns.
75
+ *
76
+ * @param {string} [str] - String that may contain a function call
77
+ * @returns {{func:string, args:string}|null} Object with {func, args} or null if none found
78
+ */
79
+ static extractFunctionCall(str="") {
80
+ const match = Evaluator.func.exec(str)
81
+
82
+ if(!match?.groups)
83
+ return null
84
+
85
+ const {func, args} = match.groups
86
+
87
+ return {func, args}
88
+ }
89
+
59
90
  #pool = new ThemePool()
60
91
  get pool() {
61
92
  return this.#pool
@@ -81,6 +112,18 @@ export default class Evaluator {
81
112
  * - No return value. Evident by the absence of a return statement.
82
113
  *
83
114
  * @param {Array<{flatPath:string,value:unknown}>} decomposed - Variable entries to resolve.
115
+ * @example
116
+ * // Example decomposed input with variables and theme references
117
+ * const evaluator = new Evaluator();
118
+ * const decomposed = [
119
+ * { flatPath: 'vars.primary', value: '#3366cc' },
120
+ * { flatPath: 'theme.colors.background', value: '$(vars.primary)' },
121
+ * { flatPath: 'theme.colors.accent', value: 'lighten($(vars.primary), 20)' }
122
+ * ];
123
+ * evaluator.evaluate(decomposed);
124
+ * // After evaluation, values are resolved:
125
+ * // decomposed[1].value === '#3366cc'
126
+ * // decomposed[2].value === '#5588dd' (lightened color)
84
127
  */
85
128
  evaluate(decomposed) {
86
129
  let it = 0
@@ -229,8 +272,8 @@ export default class Evaluator {
229
272
  * @returns {ThemeToken|null} The resolved token or null.
230
273
  */
231
274
  #resolveVariable(value) {
232
- const {captured,none,parens,braces} = Evaluator.sub.exec(value).groups
233
- const work = none ?? parens ?? braces
275
+ const {captured} = Evaluator.sub.exec(value).groups
276
+ const work = Evaluator.extractVariableName(value)
234
277
  const existing = this.#pool.findToken(work)
235
278
 
236
279
  if(!existing)
@@ -253,7 +296,13 @@ export default class Evaluator {
253
296
  * @returns {ThemeToken|null} The resolved token or null.
254
297
  */
255
298
  #resolveFunction(value) {
256
- const {captured,func,args} = Evaluator.func.exec(value).groups
299
+ const {captured} = Evaluator.func.exec(value).groups
300
+ const result = Evaluator.extractFunctionCall(value)
301
+
302
+ if(!result)
303
+ return null
304
+
305
+ const {func, args} = result
257
306
  const split = args?.split(",").map(a => a.trim()) ?? []
258
307
 
259
308
  // Look up source tokens for arguments to preserve color space