@jesscss/plugin-less-compat 2.0.0-alpha.6 → 2.0.0-alpha.8
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/README.md +40 -137
- package/lib/index.cjs +844 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +800 -10
- package/lib/less-adapter.cjs +216 -0
- package/lib/less-adapter.js +181 -0
- package/lib/less-compat-structures.cjs +378 -0
- package/lib/less-compat-structures.d.ts +2 -2
- package/lib/less-compat-structures.js +367 -512
- package/lib/nodes/at-rule.d.ts +2 -2
- package/lib/nodes/attribute-selector.d.ts +2 -2
- package/lib/nodes/call.d.ts +2 -2
- package/lib/nodes/color.d.ts +2 -1
- package/lib/nodes/combinator.d.ts +2 -1
- package/lib/nodes/comment.d.ts +2 -1
- package/lib/nodes/condition.d.ts +2 -2
- package/lib/nodes/declaration.d.ts +2 -2
- package/lib/nodes/dimension.d.ts +2 -1
- package/lib/nodes/expression.d.ts +2 -2
- package/lib/nodes/extend.d.ts +2 -1
- package/lib/nodes/import.d.ts +2 -2
- package/lib/nodes/keyword.d.ts +2 -1
- package/lib/nodes/list.d.ts +3 -2
- package/lib/nodes/mixin.d.ts +2 -2
- package/lib/nodes/negative.d.ts +2 -2
- package/lib/nodes/operation.d.ts +2 -2
- package/lib/nodes/paren.d.ts +2 -2
- package/lib/nodes/quoted.d.ts +2 -1
- package/lib/nodes/reference.d.ts +2 -1
- package/lib/nodes/ruleset.d.ts +2 -2
- package/lib/nodes/selector.d.ts +2 -2
- package/lib/nodes/sequence.d.ts +2 -2
- package/lib/nodes/url.d.ts +2 -1
- package/lib/nodes/var-declaration.d.ts +2 -2
- package/lib/plugin.d.ts +44 -16
- package/lib/transform/adapter.d.ts +9 -11
- package/lib/transform/index.cjs +13 -0
- package/lib/transform/index.d.ts +1 -1
- package/lib/transform/index.js +3 -8
- package/lib/transform/less-adapter.d.ts +29 -0
- package/lib/transform.cjs +1045 -0
- package/lib/transform.js +1015 -0
- package/lib/types.d.ts +153 -28
- package/package.json +6 -9
- package/lib/index.js.map +0 -1
- package/lib/less-compat-structures.js.map +0 -1
- package/lib/nodes/at-rule.js +0 -21
- package/lib/nodes/at-rule.js.map +0 -1
- package/lib/nodes/attribute-selector.js +0 -18
- package/lib/nodes/attribute-selector.js.map +0 -1
- package/lib/nodes/call.js +0 -27
- package/lib/nodes/call.js.map +0 -1
- package/lib/nodes/color.js +0 -23
- package/lib/nodes/color.js.map +0 -1
- package/lib/nodes/combinator.js +0 -7
- package/lib/nodes/combinator.js.map +0 -1
- package/lib/nodes/comment.js +0 -9
- package/lib/nodes/comment.js.map +0 -1
- package/lib/nodes/condition.js +0 -19
- package/lib/nodes/condition.js.map +0 -1
- package/lib/nodes/declaration.js +0 -38
- package/lib/nodes/declaration.js.map +0 -1
- package/lib/nodes/dimension.js +0 -9
- package/lib/nodes/dimension.js.map +0 -1
- package/lib/nodes/expression.js +0 -16
- package/lib/nodes/expression.js.map +0 -1
- package/lib/nodes/extend.js +0 -18
- package/lib/nodes/extend.js.map +0 -1
- package/lib/nodes/import.js +0 -22
- package/lib/nodes/import.js.map +0 -1
- package/lib/nodes/index.js +0 -308
- package/lib/nodes/index.js.map +0 -1
- package/lib/nodes/keyword.js +0 -8
- package/lib/nodes/keyword.js.map +0 -1
- package/lib/nodes/list.js +0 -61
- package/lib/nodes/list.js.map +0 -1
- package/lib/nodes/mixin.js +0 -22
- package/lib/nodes/mixin.js.map +0 -1
- package/lib/nodes/negative.js +0 -13
- package/lib/nodes/negative.js.map +0 -1
- package/lib/nodes/operation.js +0 -22
- package/lib/nodes/operation.js.map +0 -1
- package/lib/nodes/paren.js +0 -13
- package/lib/nodes/paren.js.map +0 -1
- package/lib/nodes/quoted.js +0 -23
- package/lib/nodes/quoted.js.map +0 -1
- package/lib/nodes/reference.js +0 -44
- package/lib/nodes/reference.js.map +0 -1
- package/lib/nodes/ruleset.js +0 -67
- package/lib/nodes/ruleset.js.map +0 -1
- package/lib/nodes/selector.js +0 -158
- package/lib/nodes/selector.js.map +0 -1
- package/lib/nodes/sequence.js +0 -56
- package/lib/nodes/sequence.js.map +0 -1
- package/lib/nodes/url.js +0 -13
- package/lib/nodes/url.js.map +0 -1
- package/lib/nodes/var-declaration.js +0 -21
- package/lib/nodes/var-declaration.js.map +0 -1
- package/lib/plugin-utils.js +0 -100
- package/lib/plugin-utils.js.map +0 -1
- package/lib/plugin.js +0 -1026
- package/lib/plugin.js.map +0 -1
- package/lib/transform/adapter.js +0 -111
- package/lib/transform/adapter.js.map +0 -1
- package/lib/transform/from-less.js +0 -170
- package/lib/transform/from-less.js.map +0 -1
- package/lib/transform/index.js.map +0 -1
- package/lib/transform/proxy.d.ts +0 -32
- package/lib/transform/proxy.js +0 -138
- package/lib/transform/proxy.js.map +0 -1
- package/lib/transform/to-less.js +0 -130
- package/lib/transform/to-less.js.map +0 -1
- package/lib/transform/type-map.js +0 -105
- package/lib/transform/type-map.js.map +0 -1
- package/lib/types.js +0 -5
- package/lib/types.js.map +0 -1
|
@@ -1,519 +1,374 @@
|
|
|
1
|
+
import { t as LessAdapterBase } from "./less-adapter.js";
|
|
2
|
+
//#region src/less-compat-structures.ts
|
|
1
3
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
* Minimal Less.js-compatible structures for plugin compatibility
|
|
5
|
+
* These are standalone implementations that don't require the actual Less.js library
|
|
6
|
+
*/
|
|
5
7
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (visitMethod) {
|
|
96
|
-
result = visitMethod.call(this.visitor, node, args);
|
|
97
|
-
// If visitor is replacing and returned a new node, use it
|
|
98
|
-
if (this.visitor.isReplacing && result !== undefined) {
|
|
99
|
-
node = result;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (typeof this.visitor.visit === 'function') {
|
|
103
|
-
// Fallback to generic visit method
|
|
104
|
-
result = this.visitor.visit(node, args);
|
|
105
|
-
if (this.visitor.isReplacing && result !== undefined) {
|
|
106
|
-
node = result;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// Less.js pattern: after calling visit method, traverse children if visitDeeper is true
|
|
110
|
-
// This matches Less.js Visitor.visit() behavior
|
|
111
|
-
// CRITICAL: Only call accept() on Less proxies, NOT on Jess nodes
|
|
112
|
-
// Jess nodes' accept() calls visitor.visit() which would cause infinite recursion
|
|
113
|
-
// Less proxies' accept() methods only traverse children, they don't call visitor.visit()
|
|
114
|
-
if (args.visitDeeper && node && node.accept) {
|
|
115
|
-
const isProxy = isLessProxy(node);
|
|
116
|
-
// Only call accept() if this is a Less proxy
|
|
117
|
-
// Less proxies have accept() that traverses children without calling visit()
|
|
118
|
-
if (isProxy) {
|
|
119
|
-
node.accept(this);
|
|
120
|
-
}
|
|
121
|
-
// If it's not a Less proxy (it's a Jess node), we should NOT call accept()
|
|
122
|
-
// because Jess's accept() calls visitor.visit() which would recurse
|
|
123
|
-
// Instead, the plugin visitor's visit() method handles Jess node traversal
|
|
124
|
-
}
|
|
125
|
-
// Note: We keep the node in processingNodes for the entire visitor lifetime
|
|
126
|
-
// to prevent re-processing. The WeakSet will be garbage collected when done.
|
|
127
|
-
return result;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Visit array of nodes
|
|
131
|
-
*/
|
|
132
|
-
visitArray(nodes, visitArgs) {
|
|
133
|
-
if (!nodes) {
|
|
134
|
-
return nodes;
|
|
135
|
-
}
|
|
136
|
-
return nodes.map(node => this.visit(node, visitArgs));
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Visit Directive node (Less.js v2 compatibility)
|
|
140
|
-
* Maps to AtRule for modern Less.js compatibility
|
|
141
|
-
*/
|
|
142
|
-
visitDirective(node, visitArgs) {
|
|
143
|
-
// Convert Directive to AtRule-compatible format
|
|
144
|
-
// Less.js v2 used "Directive", modern versions use "AtRule"
|
|
145
|
-
if (node && node.type === 'Directive') {
|
|
146
|
-
// Try visitDirective first (v2 plugins)
|
|
147
|
-
if (this.visitor && typeof this.visitor.visitDirective === 'function') {
|
|
148
|
-
return this.visitor.visitDirective(node, visitArgs);
|
|
149
|
-
}
|
|
150
|
-
// Fallback to visitAtRule (modern plugins)
|
|
151
|
-
if (this.visitor && typeof this.visitor.visitAtRule === 'function') {
|
|
152
|
-
return this.visitor.visitAtRule(node, visitArgs);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// Default to regular visit
|
|
156
|
-
return this.visit(node, visitArgs);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Visit Rule node (Less.js v2 compatibility)
|
|
160
|
-
* Maps to Declaration for modern Less.js compatibility
|
|
161
|
-
*/
|
|
162
|
-
visitRule(node, visitArgs) {
|
|
163
|
-
// Convert Rule to Declaration-compatible format
|
|
164
|
-
// Less.js v2 used "Rule", modern versions use "Declaration"
|
|
165
|
-
if (node && (node.type === 'Rule' || node.type === 'Declaration')) {
|
|
166
|
-
// Try visitRule first (v2 plugins)
|
|
167
|
-
if (this.visitor && typeof this.visitor.visitRule === 'function') {
|
|
168
|
-
return this.visitor.visitRule(node, visitArgs);
|
|
169
|
-
}
|
|
170
|
-
// Fallback to visitDeclaration (modern plugins)
|
|
171
|
-
if (this.visitor && typeof this.visitor.visitDeclaration === 'function') {
|
|
172
|
-
return this.visitor.visitDeclaration(node, visitArgs);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// Default to regular visit
|
|
176
|
-
return this.visit(node, visitArgs);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
8
|
+
* Less.js Visitor base class (minimal implementation)
|
|
9
|
+
* Plugins expect this structure to exist
|
|
10
|
+
*/
|
|
11
|
+
var LessVisitor = class {
|
|
12
|
+
processingNodes = /* @__PURE__ */ new WeakSet();
|
|
13
|
+
constructor(visitor) {
|
|
14
|
+
this.visitor = visitor;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Visit a node - handles both modern and legacy Less.js node types
|
|
18
|
+
* Supports Less.js v2 "Directive" nodes (mapped to AtRule)
|
|
19
|
+
*
|
|
20
|
+
* In Less.js v2, at-rules were called "Directive" instead of "AtRule".
|
|
21
|
+
* For compatibility, we route AtRule nodes to visitDirective() if that method exists,
|
|
22
|
+
* allowing v2 plugins to work with modern AtRule nodes.
|
|
23
|
+
*/
|
|
24
|
+
visit(node, visitArgs) {
|
|
25
|
+
if (!node) return node;
|
|
26
|
+
if (typeof node !== "object") return node;
|
|
27
|
+
if (!this.visitor) return node;
|
|
28
|
+
if (this.processingNodes.has(node)) return node;
|
|
29
|
+
this.processingNodes.add(node);
|
|
30
|
+
const args = visitArgs || { visitDeeper: true };
|
|
31
|
+
if (args.visitDeeper === void 0) args.visitDeeper = true;
|
|
32
|
+
const nodeType = node.type;
|
|
33
|
+
if (!nodeType || typeof nodeType !== "string") {
|
|
34
|
+
if (typeof this.visitor.visit === "function") {
|
|
35
|
+
const result = this.visitor.visit(node, args);
|
|
36
|
+
if (args.visitDeeper && node && node.accept) node.accept(this);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
return node;
|
|
40
|
+
}
|
|
41
|
+
const visitMethodName = `visit${nodeType}`;
|
|
42
|
+
let result = node;
|
|
43
|
+
let visitMethod;
|
|
44
|
+
if (typeof this.visitor[visitMethodName] === "function") visitMethod = this.visitor[visitMethodName];
|
|
45
|
+
else if (nodeType === "Directive" || nodeType === "AtRule") {
|
|
46
|
+
if (typeof this.visitor.visitDirective === "function") visitMethod = this.visitor.visitDirective;
|
|
47
|
+
else if (typeof this.visitor.visitAtRule === "function") visitMethod = this.visitor.visitAtRule;
|
|
48
|
+
} else if (nodeType === "Rule") {
|
|
49
|
+
if (typeof this.visitor.visitRule === "function") visitMethod = this.visitor.visitRule;
|
|
50
|
+
else if (typeof this.visitor.visitDeclaration === "function") visitMethod = this.visitor.visitDeclaration;
|
|
51
|
+
} else if (nodeType === "Reference") {
|
|
52
|
+
if (typeof this.visitor.visitVariable === "function") visitMethod = this.visitor.visitVariable;
|
|
53
|
+
else if (typeof this.visitor.visitReference === "function") visitMethod = this.visitor.visitReference;
|
|
54
|
+
}
|
|
55
|
+
if (visitMethod) {
|
|
56
|
+
result = visitMethod.call(this.visitor, node, args);
|
|
57
|
+
if (this.visitor.isReplacing && result !== void 0) node = result;
|
|
58
|
+
} else if (typeof this.visitor.visit === "function") {
|
|
59
|
+
result = this.visitor.visit(node, args);
|
|
60
|
+
if (this.visitor.isReplacing && result !== void 0) node = result;
|
|
61
|
+
}
|
|
62
|
+
if (args.visitDeeper && node && node.accept) {
|
|
63
|
+
if (node instanceof LessAdapterBase) node.accept(this);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Visit array of nodes
|
|
69
|
+
*/
|
|
70
|
+
visitArray(nodes, visitArgs) {
|
|
71
|
+
if (!nodes) return nodes;
|
|
72
|
+
return nodes.map((node) => this.visit(node, visitArgs));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Visit Directive node (Less.js v2 compatibility)
|
|
76
|
+
* Maps to AtRule for modern Less.js compatibility
|
|
77
|
+
*/
|
|
78
|
+
visitDirective(node, visitArgs) {
|
|
79
|
+
if (node && node.type === "Directive") {
|
|
80
|
+
if (this.visitor && typeof this.visitor.visitDirective === "function") return this.visitor.visitDirective(node, visitArgs);
|
|
81
|
+
if (this.visitor && typeof this.visitor.visitAtRule === "function") return this.visitor.visitAtRule(node, visitArgs);
|
|
82
|
+
}
|
|
83
|
+
return this.visit(node, visitArgs);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Visit Rule node (Less.js v2 compatibility)
|
|
87
|
+
* Maps to Declaration for modern Less.js compatibility
|
|
88
|
+
*/
|
|
89
|
+
visitRule(node, visitArgs) {
|
|
90
|
+
if (node && (node.type === "Rule" || node.type === "Declaration")) {
|
|
91
|
+
if (this.visitor && typeof this.visitor.visitRule === "function") return this.visitor.visitRule(node, visitArgs);
|
|
92
|
+
if (this.visitor && typeof this.visitor.visitDeclaration === "function") return this.visitor.visitDeclaration(node, visitArgs);
|
|
93
|
+
}
|
|
94
|
+
return this.visit(node, visitArgs);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
179
97
|
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (!plugin) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
// If plugin has install method, call it first
|
|
248
|
-
// The install method may add the visitor itself via addVisitor()
|
|
249
|
-
if (typeof plugin.install === 'function') {
|
|
250
|
-
plugin.install(this.less, this, this.less.functions.functionRegistry);
|
|
251
|
-
}
|
|
252
|
-
// If plugin is a visitor and not already added, add it
|
|
253
|
-
// Check if it's already in the visitors array to avoid duplicates
|
|
254
|
-
const isVisitor = typeof plugin.visit === 'function' || typeof plugin.visitRuleset === 'function';
|
|
255
|
-
if (isVisitor && !this.visitors.includes(plugin)) {
|
|
256
|
-
this.addVisitor(plugin);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
98
|
+
* Less.js PluginManager (minimal implementation)
|
|
99
|
+
* Plugins use this to register visitors, pre/post processors, etc.
|
|
100
|
+
*/
|
|
101
|
+
var LessPluginManager = class {
|
|
102
|
+
visitors = [];
|
|
103
|
+
preProcessors = [];
|
|
104
|
+
postProcessors = [];
|
|
105
|
+
constructor(less, newFactory) {
|
|
106
|
+
this.less = less;
|
|
107
|
+
this.newFactory = newFactory;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Add a visitor to the manager
|
|
111
|
+
*/
|
|
112
|
+
addVisitor(visitor) {
|
|
113
|
+
this.visitors.push(visitor);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Remove a visitor
|
|
117
|
+
*/
|
|
118
|
+
removeVisitor(visitor) {
|
|
119
|
+
const index = this.visitors.indexOf(visitor);
|
|
120
|
+
if (index > -1) this.visitors.splice(index, 1);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Add a pre-processor (runs before parsing)
|
|
124
|
+
*/
|
|
125
|
+
addPreProcessor(preProcessor) {
|
|
126
|
+
this.preProcessors.push(preProcessor);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Add a post-processor (runs after compilation)
|
|
130
|
+
*/
|
|
131
|
+
addPostProcessor(postProcessor) {
|
|
132
|
+
this.postProcessors.push(postProcessor);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get all visitors
|
|
136
|
+
*/
|
|
137
|
+
getVisitors() {
|
|
138
|
+
return this.visitors;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get all pre-processors
|
|
142
|
+
*/
|
|
143
|
+
getPreProcessors() {
|
|
144
|
+
return this.preProcessors;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get all post-processors
|
|
148
|
+
*/
|
|
149
|
+
getPostProcessors() {
|
|
150
|
+
return this.postProcessors;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Register a plugin (Less.js-compatible API)
|
|
154
|
+
* Some plugins use this method instead of install()
|
|
155
|
+
*/
|
|
156
|
+
registerPlugin(plugin, _options) {
|
|
157
|
+
if (!plugin) return;
|
|
158
|
+
if (typeof plugin.install === "function") plugin.install(this.less, this, this.less.functions.functionRegistry);
|
|
159
|
+
if ((typeof plugin.visit === "function" || typeof plugin.visitRuleset === "function") && !this.visitors.includes(plugin)) this.addVisitor(plugin);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
260
162
|
/**
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
isRulesetLike: function () {
|
|
437
|
-
return this.rules && this.rules.length > 0;
|
|
438
|
-
},
|
|
439
|
-
accept: function (visitor) {
|
|
440
|
-
// Map visitDirective to visitAtRule for compatibility
|
|
441
|
-
if (visitor.visitDirective) {
|
|
442
|
-
return visitor.visitDirective(this);
|
|
443
|
-
}
|
|
444
|
-
// Fallback to visitAtRule or generic visit
|
|
445
|
-
if (visitor.visitAtRule) {
|
|
446
|
-
return visitor.visitAtRule(this);
|
|
447
|
-
}
|
|
448
|
-
return visitor.visit(this);
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
},
|
|
452
|
-
/**
|
|
453
|
-
* Rule node constructor (Less.js v2 compatibility)
|
|
454
|
-
* In Less.js v2, declarations were called "Rule" instead of "Declaration"
|
|
455
|
-
* This creates a Declaration-compatible node for backward compatibility
|
|
456
|
-
*/
|
|
457
|
-
Rule: function (name, value, important, merge, index, fileInfo, inline, variable) {
|
|
458
|
-
return {
|
|
459
|
-
type: 'Rule', // Keep type as 'Rule' for v2 compatibility
|
|
460
|
-
name: name || '',
|
|
461
|
-
value: value || null,
|
|
462
|
-
important: important || '',
|
|
463
|
-
merge: merge || false,
|
|
464
|
-
index: index || 0,
|
|
465
|
-
fileInfo: fileInfo || {},
|
|
466
|
-
inline: inline || false,
|
|
467
|
-
variable: variable !== undefined ? variable : (name && name.charAt && name.charAt(0) === '@'),
|
|
468
|
-
accept: function (visitor) {
|
|
469
|
-
// Map visitRule to visitDeclaration for compatibility
|
|
470
|
-
if (visitor.visitRule) {
|
|
471
|
-
return visitor.visitRule(this);
|
|
472
|
-
}
|
|
473
|
-
// Fallback to visitDeclaration or generic visit
|
|
474
|
-
if (visitor.visitDeclaration) {
|
|
475
|
-
return visitor.visitDeclaration(this);
|
|
476
|
-
}
|
|
477
|
-
return visitor.visit(this);
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
}
|
|
163
|
+
* Less.js tree constructors (minimal implementations)
|
|
164
|
+
* Plugins may access these via functionRegistry.Call, etc.
|
|
165
|
+
*/
|
|
166
|
+
const LessTreeConstructors = {
|
|
167
|
+
Anonymous: function(value, index, fileInfo) {
|
|
168
|
+
return {
|
|
169
|
+
type: "Anonymous",
|
|
170
|
+
value,
|
|
171
|
+
index: index || 0,
|
|
172
|
+
fileInfo: fileInfo || {},
|
|
173
|
+
accept: function(visitor) {
|
|
174
|
+
return visitor.visit(this);
|
|
175
|
+
},
|
|
176
|
+
toCSS: function() {
|
|
177
|
+
return String(value);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
Quoted: function(quote, value, escaped, index, fileInfo) {
|
|
182
|
+
return {
|
|
183
|
+
type: "Quoted",
|
|
184
|
+
quote,
|
|
185
|
+
value,
|
|
186
|
+
escaped: !!escaped,
|
|
187
|
+
index: index || 0,
|
|
188
|
+
fileInfo: fileInfo || {},
|
|
189
|
+
accept: function(visitor) {
|
|
190
|
+
return visitor.visit(this);
|
|
191
|
+
},
|
|
192
|
+
toCSS: function() {
|
|
193
|
+
return `${quote}${String(value)}${quote}`;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
DetachedRuleset: function(ruleset) {
|
|
198
|
+
return {
|
|
199
|
+
type: "DetachedRuleset",
|
|
200
|
+
ruleset,
|
|
201
|
+
accept: function(visitor) {
|
|
202
|
+
return visitor.visit(this);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
Call: function(name, args, index, fileInfo) {
|
|
207
|
+
return {
|
|
208
|
+
type: "Call",
|
|
209
|
+
name,
|
|
210
|
+
args: args || [],
|
|
211
|
+
index: index || 0,
|
|
212
|
+
fileInfo: fileInfo || {},
|
|
213
|
+
value: null,
|
|
214
|
+
accept: function(visitor) {
|
|
215
|
+
return visitor.visit(this);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
Variable: function(name, index, fileInfo) {
|
|
220
|
+
return {
|
|
221
|
+
type: "Variable",
|
|
222
|
+
name,
|
|
223
|
+
index: index || 0,
|
|
224
|
+
fileInfo: fileInfo || {},
|
|
225
|
+
value: null,
|
|
226
|
+
accept: function(visitor) {
|
|
227
|
+
return visitor.visit(this);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
VariableCall: function(name, index, fileInfo) {
|
|
232
|
+
return {
|
|
233
|
+
type: "VariableCall",
|
|
234
|
+
name,
|
|
235
|
+
index: index || 0,
|
|
236
|
+
fileInfo: fileInfo || {},
|
|
237
|
+
value: null,
|
|
238
|
+
accept: function(visitor) {
|
|
239
|
+
return visitor.visit(this);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
Ruleset: function(selectors, rules, strictImports, visibilityInfo, fileInfo) {
|
|
244
|
+
return {
|
|
245
|
+
type: "Ruleset",
|
|
246
|
+
selectors: selectors || [],
|
|
247
|
+
rules: rules || [],
|
|
248
|
+
strictImports,
|
|
249
|
+
visibilityInfo,
|
|
250
|
+
fileInfo: fileInfo || {},
|
|
251
|
+
accept: function(visitor) {
|
|
252
|
+
return visitor.visit(this);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
Declaration: function(name, value, index, fileInfo, variable, important) {
|
|
257
|
+
return {
|
|
258
|
+
type: "Declaration",
|
|
259
|
+
name,
|
|
260
|
+
value,
|
|
261
|
+
index: index || 0,
|
|
262
|
+
fileInfo: fileInfo || {},
|
|
263
|
+
variable: variable || false,
|
|
264
|
+
important: important || "",
|
|
265
|
+
accept: function(visitor) {
|
|
266
|
+
return visitor.visit(this);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
Dimension: function(value, unit) {
|
|
271
|
+
return {
|
|
272
|
+
type: "Dimension",
|
|
273
|
+
value,
|
|
274
|
+
unit: unit || "",
|
|
275
|
+
accept: function(visitor) {
|
|
276
|
+
return visitor.visit(this);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
Color: function(rgb, alpha) {
|
|
281
|
+
let rgbArray;
|
|
282
|
+
if (typeof rgb === "string") {
|
|
283
|
+
const hex = rgb.replace(/^#/, "");
|
|
284
|
+
rgbArray = (hex.length >= 6 ? hex.match(/.{2}/g) ?? [] : hex.split("").map((c) => c + c)).slice(0, 3).map((c) => parseInt(c, 16));
|
|
285
|
+
} else rgbArray = rgb || [
|
|
286
|
+
0,
|
|
287
|
+
0,
|
|
288
|
+
0
|
|
289
|
+
];
|
|
290
|
+
return {
|
|
291
|
+
type: "Color",
|
|
292
|
+
rgb: rgbArray,
|
|
293
|
+
alpha: alpha !== void 0 ? alpha : 1,
|
|
294
|
+
accept: function(visitor) {
|
|
295
|
+
return visitor.visit(this);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
},
|
|
299
|
+
Directive: function(name, value, rules, index, fileInfo) {
|
|
300
|
+
return {
|
|
301
|
+
type: "Directive",
|
|
302
|
+
name: name || "",
|
|
303
|
+
value: value || null,
|
|
304
|
+
rules: rules || [],
|
|
305
|
+
index: index || 0,
|
|
306
|
+
fileInfo: fileInfo || {},
|
|
307
|
+
isCharset: function() {
|
|
308
|
+
return this.name === "@charset" || this.name === "charset";
|
|
309
|
+
},
|
|
310
|
+
isRulesetLike: function() {
|
|
311
|
+
return this.rules && this.rules.length > 0;
|
|
312
|
+
},
|
|
313
|
+
accept: function(visitor) {
|
|
314
|
+
if (visitor.visitDirective) return visitor.visitDirective(this);
|
|
315
|
+
if (visitor.visitAtRule) return visitor.visitAtRule(this);
|
|
316
|
+
return visitor.visit(this);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
Rule: function(name, value, important, merge, index, fileInfo, inline, variable) {
|
|
321
|
+
return {
|
|
322
|
+
type: "Rule",
|
|
323
|
+
name: name || "",
|
|
324
|
+
value: value || null,
|
|
325
|
+
important: important || "",
|
|
326
|
+
merge: merge || false,
|
|
327
|
+
index: index || 0,
|
|
328
|
+
fileInfo: fileInfo || {},
|
|
329
|
+
inline: inline || false,
|
|
330
|
+
variable: variable !== void 0 ? variable : name && name.charAt && name.charAt(0) === "@",
|
|
331
|
+
accept: function(visitor) {
|
|
332
|
+
if (visitor.visitRule) return visitor.visitRule(this);
|
|
333
|
+
if (visitor.visitDeclaration) return visitor.visitDeclaration(this);
|
|
334
|
+
return visitor.visit(this);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
481
338
|
};
|
|
482
339
|
/**
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
return { type: 'AtRule', name, value };
|
|
516
|
-
}
|
|
517
|
-
};
|
|
340
|
+
* Create a Less.js-compatible mock object
|
|
341
|
+
* This provides the minimal structure that plugins expect
|
|
342
|
+
*/
|
|
343
|
+
function createLessMock(functionRegistry) {
|
|
344
|
+
return {
|
|
345
|
+
visitors: { Visitor: LessVisitor },
|
|
346
|
+
functions: { functionRegistry },
|
|
347
|
+
tree: LessTreeConstructors,
|
|
348
|
+
PluginLoader: class {},
|
|
349
|
+
dimension(value, unit) {
|
|
350
|
+
return LessTreeConstructors.Dimension(value, unit);
|
|
351
|
+
},
|
|
352
|
+
value(values) {
|
|
353
|
+
return values;
|
|
354
|
+
},
|
|
355
|
+
declaration(name, value) {
|
|
356
|
+
return LessTreeConstructors.Declaration(name, value);
|
|
357
|
+
},
|
|
358
|
+
ruleset(selector, rules) {
|
|
359
|
+
return LessTreeConstructors.Ruleset([selector], rules);
|
|
360
|
+
},
|
|
361
|
+
detachedruleset(rulesetLike) {
|
|
362
|
+
return LessTreeConstructors.DetachedRuleset(rulesetLike);
|
|
363
|
+
},
|
|
364
|
+
atrule(name, value) {
|
|
365
|
+
return {
|
|
366
|
+
type: "AtRule",
|
|
367
|
+
name,
|
|
368
|
+
value
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
};
|
|
518
372
|
}
|
|
519
|
-
//#
|
|
373
|
+
//#endregion
|
|
374
|
+
export { LessPluginManager, LessTreeConstructors, LessVisitor, createLessMock };
|