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

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 (49) hide show
  1. package/README.md +34 -122
  2. package/lib/index.cjs +13 -821
  3. package/lib/index.d.ts +0 -3
  4. package/lib/index.js +15 -786
  5. package/lib/plugin.d.ts +17 -109
  6. package/package.json +5 -15
  7. package/lib/less-adapter.cjs +0 -216
  8. package/lib/less-adapter.js +0 -181
  9. package/lib/less-compat-structures.cjs +0 -378
  10. package/lib/less-compat-structures.d.ts +0 -108
  11. package/lib/less-compat-structures.js +0 -374
  12. package/lib/nodes/at-rule.d.ts +0 -2
  13. package/lib/nodes/attribute-selector.d.ts +0 -2
  14. package/lib/nodes/call.d.ts +0 -2
  15. package/lib/nodes/color.d.ts +0 -2
  16. package/lib/nodes/combinator.d.ts +0 -2
  17. package/lib/nodes/comment.d.ts +0 -2
  18. package/lib/nodes/condition.d.ts +0 -2
  19. package/lib/nodes/declaration.d.ts +0 -2
  20. package/lib/nodes/dimension.d.ts +0 -2
  21. package/lib/nodes/expression.d.ts +0 -2
  22. package/lib/nodes/extend.d.ts +0 -2
  23. package/lib/nodes/import.d.ts +0 -2
  24. package/lib/nodes/index.d.ts +0 -45
  25. package/lib/nodes/keyword.d.ts +0 -2
  26. package/lib/nodes/list.d.ts +0 -3
  27. package/lib/nodes/mixin.d.ts +0 -2
  28. package/lib/nodes/negative.d.ts +0 -2
  29. package/lib/nodes/operation.d.ts +0 -2
  30. package/lib/nodes/paren.d.ts +0 -2
  31. package/lib/nodes/quoted.d.ts +0 -2
  32. package/lib/nodes/reference.d.ts +0 -2
  33. package/lib/nodes/ruleset.d.ts +0 -2
  34. package/lib/nodes/selector.d.ts +0 -3
  35. package/lib/nodes/sequence.d.ts +0 -2
  36. package/lib/nodes/url.d.ts +0 -2
  37. package/lib/nodes/var-declaration.d.ts +0 -2
  38. package/lib/plugin-utils.d.ts +0 -20
  39. package/lib/transform/adapter.d.ts +0 -31
  40. package/lib/transform/from-less.d.ts +0 -30
  41. package/lib/transform/index.cjs +0 -13
  42. package/lib/transform/index.d.ts +0 -7
  43. package/lib/transform/index.js +0 -3
  44. package/lib/transform/less-adapter.d.ts +0 -29
  45. package/lib/transform/to-less.d.ts +0 -17
  46. package/lib/transform/type-map.d.ts +0 -27
  47. package/lib/transform.cjs +0 -1045
  48. package/lib/transform.js +0 -1015
  49. package/lib/types.d.ts +0 -158
@@ -1,378 +0,0 @@
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;
@@ -1,108 +0,0 @@
1
- /**
2
- * Minimal Less.js-compatible structures for plugin compatibility
3
- * These are standalone implementations that don't require the actual Less.js library
4
- */
5
- export declare class LessVisitor {
6
- visitor?: any;
7
- private processingNodes;
8
- constructor(visitor?: any);
9
- /**
10
- * Visit a node - handles both modern and legacy Less.js node types
11
- * Supports Less.js v2 "Directive" nodes (mapped to AtRule)
12
- *
13
- * In Less.js v2, at-rules were called "Directive" instead of "AtRule".
14
- * For compatibility, we route AtRule nodes to visitDirective() if that method exists,
15
- * allowing v2 plugins to work with modern AtRule nodes.
16
- */
17
- visit(node: any, visitArgs?: any): any;
18
- /**
19
- * Visit array of nodes
20
- */
21
- visitArray(nodes: any[], visitArgs?: any): any[];
22
- /**
23
- * Visit Directive node (Less.js v2 compatibility)
24
- * Maps to AtRule for modern Less.js compatibility
25
- */
26
- visitDirective(node: any, visitArgs?: any): any;
27
- /**
28
- * Visit Rule node (Less.js v2 compatibility)
29
- * Maps to Declaration for modern Less.js compatibility
30
- */
31
- visitRule(node: any, visitArgs?: any): any;
32
- }
33
- /**
34
- * Less.js PluginManager (minimal implementation)
35
- * Plugins use this to register visitors, pre/post processors, etc.
36
- */
37
- export declare class LessPluginManager {
38
- less: any;
39
- newFactory?: boolean | undefined;
40
- visitors: any[];
41
- preProcessors: any[];
42
- postProcessors: any[];
43
- constructor(less: any, newFactory?: boolean | undefined);
44
- /**
45
- * Add a visitor to the manager
46
- */
47
- addVisitor(visitor: any): void;
48
- /**
49
- * Remove a visitor
50
- */
51
- removeVisitor(visitor: any): void;
52
- /**
53
- * Add a pre-processor (runs before parsing)
54
- */
55
- addPreProcessor(preProcessor: any): void;
56
- /**
57
- * Add a post-processor (runs after compilation)
58
- */
59
- addPostProcessor(postProcessor: any): void;
60
- /**
61
- * Get all visitors
62
- */
63
- getVisitors(): any[];
64
- /**
65
- * Get all pre-processors
66
- */
67
- getPreProcessors(): any[];
68
- /**
69
- * Get all post-processors
70
- */
71
- getPostProcessors(): any[];
72
- /**
73
- * Register a plugin (Less.js-compatible API)
74
- * Some plugins use this method instead of install()
75
- */
76
- registerPlugin(plugin: any, _options?: any): void;
77
- }
78
- /**
79
- * Less.js tree constructors (minimal implementations)
80
- * Plugins may access these via functionRegistry.Call, etc.
81
- */
82
- export declare const LessTreeConstructors: Record<string, any>;
83
- /**
84
- * Create a Less.js-compatible mock object
85
- * This provides the minimal structure that plugins expect
86
- */
87
- export declare function createLessMock(functionRegistry: any): {
88
- visitors: {
89
- Visitor: typeof LessVisitor;
90
- };
91
- functions: {
92
- functionRegistry: any;
93
- };
94
- tree: Record<string, any>;
95
- PluginLoader: {
96
- new (): {};
97
- };
98
- dimension(value: number, unit?: string): any;
99
- value(values: any[]): any[];
100
- declaration(name: string, value: any): any;
101
- ruleset(selector: any, rules: any[]): any;
102
- detachedruleset(rulesetLike: any): any;
103
- atrule(name: string, value: any): {
104
- type: string;
105
- name: string;
106
- value: any;
107
- };
108
- };