@jesscss/plugin-less-compat 2.0.0-alpha.5 → 2.0.0-alpha.7

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.
Files changed (114) hide show
  1. package/README.md +3 -2
  2. package/lib/index.cjs +844 -0
  3. package/lib/index.d.ts +2 -0
  4. package/lib/index.js +800 -9
  5. package/lib/less-adapter.cjs +216 -0
  6. package/lib/less-adapter.js +181 -0
  7. package/lib/less-compat-structures.cjs +378 -0
  8. package/lib/less-compat-structures.d.ts +2 -2
  9. package/lib/less-compat-structures.js +367 -512
  10. package/lib/nodes/at-rule.d.ts +2 -6
  11. package/lib/nodes/attribute-selector.d.ts +2 -6
  12. package/lib/nodes/call.d.ts +2 -6
  13. package/lib/nodes/color.d.ts +1 -5
  14. package/lib/nodes/combinator.d.ts +1 -5
  15. package/lib/nodes/comment.d.ts +1 -5
  16. package/lib/nodes/condition.d.ts +2 -6
  17. package/lib/nodes/declaration.d.ts +2 -6
  18. package/lib/nodes/dimension.d.ts +1 -5
  19. package/lib/nodes/expression.d.ts +2 -6
  20. package/lib/nodes/extend.d.ts +1 -5
  21. package/lib/nodes/import.d.ts +2 -6
  22. package/lib/nodes/keyword.d.ts +1 -5
  23. package/lib/nodes/list.d.ts +2 -5
  24. package/lib/nodes/mixin.d.ts +2 -6
  25. package/lib/nodes/negative.d.ts +2 -6
  26. package/lib/nodes/operation.d.ts +2 -6
  27. package/lib/nodes/paren.d.ts +2 -6
  28. package/lib/nodes/quoted.d.ts +1 -5
  29. package/lib/nodes/reference.d.ts +1 -8
  30. package/lib/nodes/ruleset.d.ts +2 -6
  31. package/lib/nodes/selector.d.ts +2 -7
  32. package/lib/nodes/sequence.d.ts +2 -9
  33. package/lib/nodes/url.d.ts +1 -5
  34. package/lib/nodes/var-declaration.d.ts +2 -6
  35. package/lib/plugin.d.ts +44 -16
  36. package/lib/transform/adapter.d.ts +31 -0
  37. package/lib/transform/index.cjs +13 -0
  38. package/lib/transform/index.d.ts +1 -1
  39. package/lib/transform/index.js +3 -8
  40. package/lib/transform/less-adapter.d.ts +29 -0
  41. package/lib/transform.cjs +1045 -0
  42. package/lib/transform.js +1015 -0
  43. package/lib/types.d.ts +153 -28
  44. package/package.json +13 -12
  45. package/lib/index.js.map +0 -1
  46. package/lib/less-compat-structures.js.map +0 -1
  47. package/lib/nodes/at-rule.js +0 -72
  48. package/lib/nodes/at-rule.js.map +0 -1
  49. package/lib/nodes/attribute-selector.js +0 -54
  50. package/lib/nodes/attribute-selector.js.map +0 -1
  51. package/lib/nodes/call.js +0 -83
  52. package/lib/nodes/call.js.map +0 -1
  53. package/lib/nodes/color.js +0 -57
  54. package/lib/nodes/color.js.map +0 -1
  55. package/lib/nodes/combinator.js +0 -34
  56. package/lib/nodes/combinator.js.map +0 -1
  57. package/lib/nodes/comment.js +0 -41
  58. package/lib/nodes/comment.js.map +0 -1
  59. package/lib/nodes/condition.js +0 -60
  60. package/lib/nodes/condition.js.map +0 -1
  61. package/lib/nodes/declaration.js +0 -81
  62. package/lib/nodes/declaration.js.map +0 -1
  63. package/lib/nodes/dimension.js +0 -47
  64. package/lib/nodes/dimension.js.map +0 -1
  65. package/lib/nodes/expression.js +0 -44
  66. package/lib/nodes/expression.js.map +0 -1
  67. package/lib/nodes/extend.js +0 -57
  68. package/lib/nodes/extend.js.map +0 -1
  69. package/lib/nodes/import.js +0 -63
  70. package/lib/nodes/import.js.map +0 -1
  71. package/lib/nodes/index.js +0 -308
  72. package/lib/nodes/index.js.map +0 -1
  73. package/lib/nodes/keyword.js +0 -36
  74. package/lib/nodes/keyword.js.map +0 -1
  75. package/lib/nodes/list.js +0 -150
  76. package/lib/nodes/list.js.map +0 -1
  77. package/lib/nodes/mixin.js +0 -62
  78. package/lib/nodes/mixin.js.map +0 -1
  79. package/lib/nodes/negative.js +0 -42
  80. package/lib/nodes/negative.js.map +0 -1
  81. package/lib/nodes/operation.js +0 -63
  82. package/lib/nodes/operation.js.map +0 -1
  83. package/lib/nodes/paren.js +0 -42
  84. package/lib/nodes/paren.js.map +0 -1
  85. package/lib/nodes/quoted.js +0 -57
  86. package/lib/nodes/quoted.js.map +0 -1
  87. package/lib/nodes/reference.js +0 -80
  88. package/lib/nodes/reference.js.map +0 -1
  89. package/lib/nodes/ruleset.js +0 -108
  90. package/lib/nodes/ruleset.js.map +0 -1
  91. package/lib/nodes/selector.js +0 -226
  92. package/lib/nodes/selector.js.map +0 -1
  93. package/lib/nodes/sequence.js +0 -75
  94. package/lib/nodes/sequence.js.map +0 -1
  95. package/lib/nodes/url.js +0 -42
  96. package/lib/nodes/url.js.map +0 -1
  97. package/lib/nodes/var-declaration.js +0 -60
  98. package/lib/nodes/var-declaration.js.map +0 -1
  99. package/lib/plugin-utils.js +0 -100
  100. package/lib/plugin-utils.js.map +0 -1
  101. package/lib/plugin.js +0 -1027
  102. package/lib/plugin.js.map +0 -1
  103. package/lib/transform/from-less.js +0 -170
  104. package/lib/transform/from-less.js.map +0 -1
  105. package/lib/transform/index.js.map +0 -1
  106. package/lib/transform/proxy.d.ts +0 -32
  107. package/lib/transform/proxy.js +0 -138
  108. package/lib/transform/proxy.js.map +0 -1
  109. package/lib/transform/to-less.js +0 -128
  110. package/lib/transform/to-less.js.map +0 -1
  111. package/lib/transform/type-map.js +0 -105
  112. package/lib/transform/type-map.js.map +0 -1
  113. package/lib/types.js +0 -5
  114. package/lib/types.js.map +0 -1
@@ -0,0 +1,378 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_less_adapter = require("./less-adapter.cjs");
3
+ //#region src/less-compat-structures.ts
4
+ /**
5
+ * Minimal Less.js-compatible structures for plugin compatibility
6
+ * These are standalone implementations that don't require the actual Less.js library
7
+ */
8
+ /**
9
+ * Less.js Visitor base class (minimal implementation)
10
+ * Plugins expect this structure to exist
11
+ */
12
+ var LessVisitor = class {
13
+ processingNodes = /* @__PURE__ */ new WeakSet();
14
+ constructor(visitor) {
15
+ this.visitor = visitor;
16
+ }
17
+ /**
18
+ * Visit a node - handles both modern and legacy Less.js node types
19
+ * Supports Less.js v2 "Directive" nodes (mapped to AtRule)
20
+ *
21
+ * In Less.js v2, at-rules were called "Directive" instead of "AtRule".
22
+ * For compatibility, we route AtRule nodes to visitDirective() if that method exists,
23
+ * allowing v2 plugins to work with modern AtRule nodes.
24
+ */
25
+ visit(node, visitArgs) {
26
+ if (!node) return node;
27
+ if (typeof node !== "object") return node;
28
+ if (!this.visitor) return node;
29
+ if (this.processingNodes.has(node)) return node;
30
+ this.processingNodes.add(node);
31
+ const args = visitArgs || { visitDeeper: true };
32
+ if (args.visitDeeper === void 0) args.visitDeeper = true;
33
+ const nodeType = node.type;
34
+ if (!nodeType || typeof nodeType !== "string") {
35
+ if (typeof this.visitor.visit === "function") {
36
+ const result = this.visitor.visit(node, args);
37
+ if (args.visitDeeper && node && node.accept) node.accept(this);
38
+ return result;
39
+ }
40
+ return node;
41
+ }
42
+ const visitMethodName = `visit${nodeType}`;
43
+ let result = node;
44
+ let visitMethod;
45
+ if (typeof this.visitor[visitMethodName] === "function") visitMethod = this.visitor[visitMethodName];
46
+ else if (nodeType === "Directive" || nodeType === "AtRule") {
47
+ if (typeof this.visitor.visitDirective === "function") visitMethod = this.visitor.visitDirective;
48
+ else if (typeof this.visitor.visitAtRule === "function") visitMethod = this.visitor.visitAtRule;
49
+ } else if (nodeType === "Rule") {
50
+ if (typeof this.visitor.visitRule === "function") visitMethod = this.visitor.visitRule;
51
+ else if (typeof this.visitor.visitDeclaration === "function") visitMethod = this.visitor.visitDeclaration;
52
+ } else if (nodeType === "Reference") {
53
+ if (typeof this.visitor.visitVariable === "function") visitMethod = this.visitor.visitVariable;
54
+ else if (typeof this.visitor.visitReference === "function") visitMethod = this.visitor.visitReference;
55
+ }
56
+ if (visitMethod) {
57
+ result = visitMethod.call(this.visitor, node, args);
58
+ if (this.visitor.isReplacing && result !== void 0) node = result;
59
+ } else if (typeof this.visitor.visit === "function") {
60
+ result = this.visitor.visit(node, args);
61
+ if (this.visitor.isReplacing && result !== void 0) node = result;
62
+ }
63
+ if (args.visitDeeper && node && node.accept) {
64
+ if (node instanceof require_less_adapter.LessAdapterBase) node.accept(this);
65
+ }
66
+ return result;
67
+ }
68
+ /**
69
+ * Visit array of nodes
70
+ */
71
+ visitArray(nodes, visitArgs) {
72
+ if (!nodes) return nodes;
73
+ return nodes.map((node) => this.visit(node, visitArgs));
74
+ }
75
+ /**
76
+ * Visit Directive node (Less.js v2 compatibility)
77
+ * Maps to AtRule for modern Less.js compatibility
78
+ */
79
+ visitDirective(node, visitArgs) {
80
+ if (node && node.type === "Directive") {
81
+ if (this.visitor && typeof this.visitor.visitDirective === "function") return this.visitor.visitDirective(node, visitArgs);
82
+ if (this.visitor && typeof this.visitor.visitAtRule === "function") return this.visitor.visitAtRule(node, visitArgs);
83
+ }
84
+ return this.visit(node, visitArgs);
85
+ }
86
+ /**
87
+ * Visit Rule node (Less.js v2 compatibility)
88
+ * Maps to Declaration for modern Less.js compatibility
89
+ */
90
+ visitRule(node, visitArgs) {
91
+ if (node && (node.type === "Rule" || node.type === "Declaration")) {
92
+ if (this.visitor && typeof this.visitor.visitRule === "function") return this.visitor.visitRule(node, visitArgs);
93
+ if (this.visitor && typeof this.visitor.visitDeclaration === "function") return this.visitor.visitDeclaration(node, visitArgs);
94
+ }
95
+ return this.visit(node, visitArgs);
96
+ }
97
+ };
98
+ /**
99
+ * Less.js PluginManager (minimal implementation)
100
+ * Plugins use this to register visitors, pre/post processors, etc.
101
+ */
102
+ var LessPluginManager = class {
103
+ visitors = [];
104
+ preProcessors = [];
105
+ postProcessors = [];
106
+ constructor(less, newFactory) {
107
+ this.less = less;
108
+ this.newFactory = newFactory;
109
+ }
110
+ /**
111
+ * Add a visitor to the manager
112
+ */
113
+ addVisitor(visitor) {
114
+ this.visitors.push(visitor);
115
+ }
116
+ /**
117
+ * Remove a visitor
118
+ */
119
+ removeVisitor(visitor) {
120
+ const index = this.visitors.indexOf(visitor);
121
+ if (index > -1) this.visitors.splice(index, 1);
122
+ }
123
+ /**
124
+ * Add a pre-processor (runs before parsing)
125
+ */
126
+ addPreProcessor(preProcessor) {
127
+ this.preProcessors.push(preProcessor);
128
+ }
129
+ /**
130
+ * Add a post-processor (runs after compilation)
131
+ */
132
+ addPostProcessor(postProcessor) {
133
+ this.postProcessors.push(postProcessor);
134
+ }
135
+ /**
136
+ * Get all visitors
137
+ */
138
+ getVisitors() {
139
+ return this.visitors;
140
+ }
141
+ /**
142
+ * Get all pre-processors
143
+ */
144
+ getPreProcessors() {
145
+ return this.preProcessors;
146
+ }
147
+ /**
148
+ * Get all post-processors
149
+ */
150
+ getPostProcessors() {
151
+ return this.postProcessors;
152
+ }
153
+ /**
154
+ * Register a plugin (Less.js-compatible API)
155
+ * Some plugins use this method instead of install()
156
+ */
157
+ registerPlugin(plugin, _options) {
158
+ if (!plugin) return;
159
+ if (typeof plugin.install === "function") plugin.install(this.less, this, this.less.functions.functionRegistry);
160
+ if ((typeof plugin.visit === "function" || typeof plugin.visitRuleset === "function") && !this.visitors.includes(plugin)) this.addVisitor(plugin);
161
+ }
162
+ };
163
+ /**
164
+ * Less.js tree constructors (minimal implementations)
165
+ * Plugins may access these via functionRegistry.Call, etc.
166
+ */
167
+ const LessTreeConstructors = {
168
+ Anonymous: function(value, index, fileInfo) {
169
+ return {
170
+ type: "Anonymous",
171
+ value,
172
+ index: index || 0,
173
+ fileInfo: fileInfo || {},
174
+ accept: function(visitor) {
175
+ return visitor.visit(this);
176
+ },
177
+ toCSS: function() {
178
+ return String(value);
179
+ }
180
+ };
181
+ },
182
+ Quoted: function(quote, value, escaped, index, fileInfo) {
183
+ return {
184
+ type: "Quoted",
185
+ quote,
186
+ value,
187
+ escaped: !!escaped,
188
+ index: index || 0,
189
+ fileInfo: fileInfo || {},
190
+ accept: function(visitor) {
191
+ return visitor.visit(this);
192
+ },
193
+ toCSS: function() {
194
+ return `${quote}${String(value)}${quote}`;
195
+ }
196
+ };
197
+ },
198
+ DetachedRuleset: function(ruleset) {
199
+ return {
200
+ type: "DetachedRuleset",
201
+ ruleset,
202
+ accept: function(visitor) {
203
+ return visitor.visit(this);
204
+ }
205
+ };
206
+ },
207
+ Call: function(name, args, index, fileInfo) {
208
+ return {
209
+ type: "Call",
210
+ name,
211
+ args: args || [],
212
+ index: index || 0,
213
+ fileInfo: fileInfo || {},
214
+ value: null,
215
+ accept: function(visitor) {
216
+ return visitor.visit(this);
217
+ }
218
+ };
219
+ },
220
+ Variable: function(name, index, fileInfo) {
221
+ return {
222
+ type: "Variable",
223
+ name,
224
+ index: index || 0,
225
+ fileInfo: fileInfo || {},
226
+ value: null,
227
+ accept: function(visitor) {
228
+ return visitor.visit(this);
229
+ }
230
+ };
231
+ },
232
+ VariableCall: function(name, index, fileInfo) {
233
+ return {
234
+ type: "VariableCall",
235
+ name,
236
+ index: index || 0,
237
+ fileInfo: fileInfo || {},
238
+ value: null,
239
+ accept: function(visitor) {
240
+ return visitor.visit(this);
241
+ }
242
+ };
243
+ },
244
+ Ruleset: function(selectors, rules, strictImports, visibilityInfo, fileInfo) {
245
+ return {
246
+ type: "Ruleset",
247
+ selectors: selectors || [],
248
+ rules: rules || [],
249
+ strictImports,
250
+ visibilityInfo,
251
+ fileInfo: fileInfo || {},
252
+ accept: function(visitor) {
253
+ return visitor.visit(this);
254
+ }
255
+ };
256
+ },
257
+ Declaration: function(name, value, index, fileInfo, variable, important) {
258
+ return {
259
+ type: "Declaration",
260
+ name,
261
+ value,
262
+ index: index || 0,
263
+ fileInfo: fileInfo || {},
264
+ variable: variable || false,
265
+ important: important || "",
266
+ accept: function(visitor) {
267
+ return visitor.visit(this);
268
+ }
269
+ };
270
+ },
271
+ Dimension: function(value, unit) {
272
+ return {
273
+ type: "Dimension",
274
+ value,
275
+ unit: unit || "",
276
+ accept: function(visitor) {
277
+ return visitor.visit(this);
278
+ }
279
+ };
280
+ },
281
+ Color: function(rgb, alpha) {
282
+ let rgbArray;
283
+ if (typeof rgb === "string") {
284
+ const hex = rgb.replace(/^#/, "");
285
+ rgbArray = (hex.length >= 6 ? hex.match(/.{2}/g) ?? [] : hex.split("").map((c) => c + c)).slice(0, 3).map((c) => parseInt(c, 16));
286
+ } else rgbArray = rgb || [
287
+ 0,
288
+ 0,
289
+ 0
290
+ ];
291
+ return {
292
+ type: "Color",
293
+ rgb: rgbArray,
294
+ alpha: alpha !== void 0 ? alpha : 1,
295
+ accept: function(visitor) {
296
+ return visitor.visit(this);
297
+ }
298
+ };
299
+ },
300
+ Directive: function(name, value, rules, index, fileInfo) {
301
+ return {
302
+ type: "Directive",
303
+ name: name || "",
304
+ value: value || null,
305
+ rules: rules || [],
306
+ index: index || 0,
307
+ fileInfo: fileInfo || {},
308
+ isCharset: function() {
309
+ return this.name === "@charset" || this.name === "charset";
310
+ },
311
+ isRulesetLike: function() {
312
+ return this.rules && this.rules.length > 0;
313
+ },
314
+ accept: function(visitor) {
315
+ if (visitor.visitDirective) return visitor.visitDirective(this);
316
+ if (visitor.visitAtRule) return visitor.visitAtRule(this);
317
+ return visitor.visit(this);
318
+ }
319
+ };
320
+ },
321
+ Rule: function(name, value, important, merge, index, fileInfo, inline, variable) {
322
+ return {
323
+ type: "Rule",
324
+ name: name || "",
325
+ value: value || null,
326
+ important: important || "",
327
+ merge: merge || false,
328
+ index: index || 0,
329
+ fileInfo: fileInfo || {},
330
+ inline: inline || false,
331
+ variable: variable !== void 0 ? variable : name && name.charAt && name.charAt(0) === "@",
332
+ accept: function(visitor) {
333
+ if (visitor.visitRule) return visitor.visitRule(this);
334
+ if (visitor.visitDeclaration) return visitor.visitDeclaration(this);
335
+ return visitor.visit(this);
336
+ }
337
+ };
338
+ }
339
+ };
340
+ /**
341
+ * Create a Less.js-compatible mock object
342
+ * This provides the minimal structure that plugins expect
343
+ */
344
+ function createLessMock(functionRegistry) {
345
+ return {
346
+ visitors: { Visitor: LessVisitor },
347
+ functions: { functionRegistry },
348
+ tree: LessTreeConstructors,
349
+ PluginLoader: class {},
350
+ dimension(value, unit) {
351
+ return LessTreeConstructors.Dimension(value, unit);
352
+ },
353
+ value(values) {
354
+ return values;
355
+ },
356
+ declaration(name, value) {
357
+ return LessTreeConstructors.Declaration(name, value);
358
+ },
359
+ ruleset(selector, rules) {
360
+ return LessTreeConstructors.Ruleset([selector], rules);
361
+ },
362
+ detachedruleset(rulesetLike) {
363
+ return LessTreeConstructors.DetachedRuleset(rulesetLike);
364
+ },
365
+ atrule(name, value) {
366
+ return {
367
+ type: "AtRule",
368
+ name,
369
+ value
370
+ };
371
+ }
372
+ };
373
+ }
374
+ //#endregion
375
+ exports.LessPluginManager = LessPluginManager;
376
+ exports.LessTreeConstructors = LessTreeConstructors;
377
+ exports.LessVisitor = LessVisitor;
378
+ exports.createLessMock = createLessMock;
@@ -3,9 +3,9 @@
3
3
  * These are standalone implementations that don't require the actual Less.js library
4
4
  */
5
5
  export declare class LessVisitor {
6
- visitor?: any | undefined;
6
+ visitor?: any;
7
7
  private processingNodes;
8
- constructor(visitor?: any | undefined);
8
+ constructor(visitor?: any);
9
9
  /**
10
10
  * Visit a node - handles both modern and legacy Less.js node types
11
11
  * Supports Less.js v2 "Directive" nodes (mapped to AtRule)