@jesscss/plugin-less-compat 2.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +139 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/less-compat-structures.d.ts +108 -0
- package/lib/less-compat-structures.js +519 -0
- package/lib/less-compat-structures.js.map +1 -0
- package/lib/nodes/at-rule.d.ts +6 -0
- package/lib/nodes/at-rule.js +72 -0
- package/lib/nodes/at-rule.js.map +1 -0
- package/lib/nodes/attribute-selector.d.ts +6 -0
- package/lib/nodes/attribute-selector.js +54 -0
- package/lib/nodes/attribute-selector.js.map +1 -0
- package/lib/nodes/call.d.ts +6 -0
- package/lib/nodes/call.js +83 -0
- package/lib/nodes/call.js.map +1 -0
- package/lib/nodes/color.d.ts +6 -0
- package/lib/nodes/color.js +57 -0
- package/lib/nodes/color.js.map +1 -0
- package/lib/nodes/combinator.d.ts +6 -0
- package/lib/nodes/combinator.js +34 -0
- package/lib/nodes/combinator.js.map +1 -0
- package/lib/nodes/comment.d.ts +6 -0
- package/lib/nodes/comment.js +41 -0
- package/lib/nodes/comment.js.map +1 -0
- package/lib/nodes/condition.d.ts +6 -0
- package/lib/nodes/condition.js +60 -0
- package/lib/nodes/condition.js.map +1 -0
- package/lib/nodes/declaration.d.ts +6 -0
- package/lib/nodes/declaration.js +81 -0
- package/lib/nodes/declaration.js.map +1 -0
- package/lib/nodes/dimension.d.ts +6 -0
- package/lib/nodes/dimension.js +47 -0
- package/lib/nodes/dimension.js.map +1 -0
- package/lib/nodes/expression.d.ts +6 -0
- package/lib/nodes/expression.js +44 -0
- package/lib/nodes/expression.js.map +1 -0
- package/lib/nodes/extend.d.ts +6 -0
- package/lib/nodes/extend.js +57 -0
- package/lib/nodes/extend.js.map +1 -0
- package/lib/nodes/import.d.ts +6 -0
- package/lib/nodes/import.js +63 -0
- package/lib/nodes/import.js.map +1 -0
- package/lib/nodes/index.d.ts +45 -0
- package/lib/nodes/index.js +308 -0
- package/lib/nodes/index.js.map +1 -0
- package/lib/nodes/keyword.d.ts +6 -0
- package/lib/nodes/keyword.js +36 -0
- package/lib/nodes/keyword.js.map +1 -0
- package/lib/nodes/list.d.ts +6 -0
- package/lib/nodes/list.js +150 -0
- package/lib/nodes/list.js.map +1 -0
- package/lib/nodes/mixin.d.ts +6 -0
- package/lib/nodes/mixin.js +62 -0
- package/lib/nodes/mixin.js.map +1 -0
- package/lib/nodes/negative.d.ts +6 -0
- package/lib/nodes/negative.js +42 -0
- package/lib/nodes/negative.js.map +1 -0
- package/lib/nodes/operation.d.ts +6 -0
- package/lib/nodes/operation.js +63 -0
- package/lib/nodes/operation.js.map +1 -0
- package/lib/nodes/paren.d.ts +6 -0
- package/lib/nodes/paren.js +42 -0
- package/lib/nodes/paren.js.map +1 -0
- package/lib/nodes/quoted.d.ts +6 -0
- package/lib/nodes/quoted.js +57 -0
- package/lib/nodes/quoted.js.map +1 -0
- package/lib/nodes/reference.d.ts +9 -0
- package/lib/nodes/reference.js +80 -0
- package/lib/nodes/reference.js.map +1 -0
- package/lib/nodes/ruleset.d.ts +6 -0
- package/lib/nodes/ruleset.js +108 -0
- package/lib/nodes/ruleset.js.map +1 -0
- package/lib/nodes/selector.d.ts +8 -0
- package/lib/nodes/selector.js +226 -0
- package/lib/nodes/selector.js.map +1 -0
- package/lib/nodes/sequence.d.ts +9 -0
- package/lib/nodes/sequence.js +75 -0
- package/lib/nodes/sequence.js.map +1 -0
- package/lib/nodes/url.d.ts +6 -0
- package/lib/nodes/url.js +42 -0
- package/lib/nodes/url.js.map +1 -0
- package/lib/nodes/var-declaration.d.ts +6 -0
- package/lib/nodes/var-declaration.js +60 -0
- package/lib/nodes/var-declaration.js.map +1 -0
- package/lib/plugin-utils.d.ts +20 -0
- package/lib/plugin-utils.js +100 -0
- package/lib/plugin-utils.js.map +1 -0
- package/lib/plugin.d.ts +92 -0
- package/lib/plugin.js +1027 -0
- package/lib/plugin.js.map +1 -0
- package/lib/transform/from-less.d.ts +30 -0
- package/lib/transform/from-less.js +170 -0
- package/lib/transform/from-less.js.map +1 -0
- package/lib/transform/index.d.ts +7 -0
- package/lib/transform/index.js +8 -0
- package/lib/transform/index.js.map +1 -0
- package/lib/transform/proxy.d.ts +32 -0
- package/lib/transform/proxy.js +138 -0
- package/lib/transform/proxy.js.map +1 -0
- package/lib/transform/to-less.d.ts +17 -0
- package/lib/transform/to-less.js +128 -0
- package/lib/transform/to-less.js.map +1 -0
- package/lib/transform/type-map.d.ts +27 -0
- package/lib/transform/type-map.js +105 -0
- package/lib/transform/type-map.js.map +1 -0
- package/lib/types.d.ts +33 -0
- package/lib/types.js +5 -0
- package/lib/types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with Less.js plugins in Jess
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Detect if a plugin is a Less.js plugin
|
|
6
|
+
*/
|
|
7
|
+
export function isLessPlugin(plugin) {
|
|
8
|
+
if (!plugin) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
// Less plugins typically have an install method
|
|
12
|
+
if (typeof plugin.install === 'function') {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
// Some Less plugins are constructor functions that create instances with install
|
|
16
|
+
// Check if the constructor's prototype has install (like autoprefix)
|
|
17
|
+
if (typeof plugin === 'function') {
|
|
18
|
+
// Check if the function itself has install (some plugins are like this)
|
|
19
|
+
if (typeof plugin.install === 'function') {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
// Check if the constructor's prototype has install
|
|
23
|
+
if (plugin.prototype && typeof plugin.prototype.install === 'function') {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// Try calling as a constructor
|
|
27
|
+
try {
|
|
28
|
+
const instance = new plugin({});
|
|
29
|
+
if (instance && typeof instance.install === 'function') {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// Try calling as a function
|
|
35
|
+
try {
|
|
36
|
+
const instance = plugin({});
|
|
37
|
+
if (instance && typeof instance.install === 'function') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
// Even if it returns undefined, if it's a function it might be a Less plugin
|
|
41
|
+
// Less.js will handle it by checking for install on the plugin object itself
|
|
42
|
+
// So we should treat functions as potential Less plugins
|
|
43
|
+
return true; // Assume function might be a Less plugin
|
|
44
|
+
}
|
|
45
|
+
catch (e2) {
|
|
46
|
+
// Not a Less plugin
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Detect if a plugin is a Jess plugin
|
|
54
|
+
*/
|
|
55
|
+
export function isJessPlugin(plugin) {
|
|
56
|
+
if (!plugin) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// Jess plugins implement PluginInterface
|
|
60
|
+
// They have a name property and implement AbstractPlugin or match PluginInterface
|
|
61
|
+
if (typeof plugin === 'object' && 'name' in plugin && typeof plugin.name === 'string') {
|
|
62
|
+
// Could be a Jess plugin
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
// Plugin factory functions that return PluginInterface
|
|
66
|
+
if (typeof plugin === 'function') {
|
|
67
|
+
try {
|
|
68
|
+
const instance = plugin({});
|
|
69
|
+
if (instance && typeof instance === 'object' && 'name' in instance && typeof instance.name === 'string') {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
// Not a Jess plugin factory
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Filter and separate Less plugins from Jess plugins
|
|
81
|
+
* This allows mixed plugin arrays to be handled correctly
|
|
82
|
+
*/
|
|
83
|
+
export function filterPlugins(plugins) {
|
|
84
|
+
const lessPlugins = [];
|
|
85
|
+
const jessPlugins = [];
|
|
86
|
+
for (const plugin of plugins) {
|
|
87
|
+
if (isLessPlugin(plugin)) {
|
|
88
|
+
lessPlugins.push(plugin);
|
|
89
|
+
}
|
|
90
|
+
else if (isJessPlugin(plugin)) {
|
|
91
|
+
jessPlugins.push(plugin);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Unknown type - assume it's a Less plugin and try to handle it
|
|
95
|
+
lessPlugins.push(plugin);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { lessPlugins, jessPlugins };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=plugin-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-utils.js","sourceRoot":"","sources":["../src/plugin-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAW;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC;IACf,CAAC;IAED,gDAAgD;IAChD,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iFAAiF;IACjF,qEAAqE;IACrE,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,wEAAwE;QACxE,IAAI,OAAQ,MAAc,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,mDAAmD;QACnD,IAAI,MAAM,CAAC,SAAS,IAAI,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YACvE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,+BAA+B;QAC/B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,IAAI,M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O,CAAC,EAAE,CAAC;YACX,4BAA4B;QAC9B,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAc;IAC1C,MAAM,WAAW,GAAU,EAAE,CAAC;IAC9B,MAAM,WAAW,GAAsB,EAAE,CAAC;IAE1C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAChC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,gEAAgE;YAChE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACtC,CAAC"}
|
package/lib/plugin.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AbstractPlugin, type Plugin, type Visitor } from '@jesscss/core';
|
|
2
|
+
import type { LessVisitor } from './types.js';
|
|
3
|
+
import { NodeModulesPlugin } from '@jesscss/plugin-node-modules';
|
|
4
|
+
export interface LessCompatPluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Less.js plugins - these will have their install() method called to extract visitors.
|
|
7
|
+
* Can be mixed with Jess plugins - Less plugins will be handled by this compat layer,
|
|
8
|
+
* Jess plugins will be passed through.
|
|
9
|
+
*/
|
|
10
|
+
plugins?: any[];
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Less.js Visitor API - Less.js visitor implementations (advanced - use plugins instead).
|
|
13
|
+
* This is for compatibility with Less.js visitor patterns. Prefer using Jess's native Visitor interface.
|
|
14
|
+
*/
|
|
15
|
+
visitors?: LessVisitor[];
|
|
16
|
+
/** Enable conversion caching (default: true) */
|
|
17
|
+
cache?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Plugin registry for @plugin directive support.
|
|
20
|
+
* Maps plugin names/paths to plugin instances or factory functions.
|
|
21
|
+
* Used when processing @plugin directives in the source.
|
|
22
|
+
*/
|
|
23
|
+
pluginRegistry?: Record<string, any>;
|
|
24
|
+
/**
|
|
25
|
+
* Enable auto-loading of plugins by name (Less.js 4.x CLI behavior).
|
|
26
|
+
* When true (default), @plugin directives will attempt to require/import
|
|
27
|
+
* plugins by their npm package name (e.g., "less-plugin-autoprefix").
|
|
28
|
+
* Set to false to disable and only use pluginRegistry.
|
|
29
|
+
*/
|
|
30
|
+
autoLoadPlugins?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Reference to the node-modules plugin for npm package resolution.
|
|
33
|
+
* If provided, will be used to resolve npm packages.
|
|
34
|
+
* If not provided, will try to use require() directly.
|
|
35
|
+
*/
|
|
36
|
+
nodeModulesPlugin?: NodeModulesPlugin;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Plugin that enables Less.js compatibility by transforming
|
|
40
|
+
* Jess nodes to Less-compatible format for visitor processing.
|
|
41
|
+
*/
|
|
42
|
+
export declare class LessCompatPlugin extends AbstractPlugin {
|
|
43
|
+
opts: LessCompatPluginOptions;
|
|
44
|
+
name: string;
|
|
45
|
+
private _cachedVisitor;
|
|
46
|
+
private _lessPluginManager?;
|
|
47
|
+
private _currentFilePath?;
|
|
48
|
+
private _jessFunctionRegistry?;
|
|
49
|
+
constructor(opts?: LessCompatPluginOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Return the visitor as a preEval visitor so it runs before evaluation.
|
|
52
|
+
* This ensures @plugin directives are processed early, allowing their visitors
|
|
53
|
+
* to run on subsequent nodes during the preEval phase.
|
|
54
|
+
*
|
|
55
|
+
* Less plugins can register visitors via:
|
|
56
|
+
* - addVisitor() - these will run during preEval (default)
|
|
57
|
+
* - addPreProcessor() - these will run during preEval
|
|
58
|
+
* - addPostProcessor() - these will run during postEval (after evaluation)
|
|
59
|
+
*/
|
|
60
|
+
get preEvalVisitor(): Visitor | Visitor[] | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Return postEval visitors from Less plugins that registered via addPostProcessor.
|
|
63
|
+
* These visitors will run after node.eval() completes.
|
|
64
|
+
*/
|
|
65
|
+
get postEvalVisitor(): undefined;
|
|
66
|
+
runPostProcessors(css: string, extra?: Record<string, any>): string;
|
|
67
|
+
setCurrentFilePath(filePath: string): void;
|
|
68
|
+
setContext(context: any): void;
|
|
69
|
+
/**
|
|
70
|
+
* Filter and separate Less plugins from Jess plugins
|
|
71
|
+
* This allows mixed plugin arrays to be handled correctly
|
|
72
|
+
*
|
|
73
|
+
* @deprecated Use filterPlugins from './plugin-utils.js' instead
|
|
74
|
+
*/
|
|
75
|
+
static filterLessPlugins(plugins: any[]): {
|
|
76
|
+
lessPlugins: any[];
|
|
77
|
+
jessPlugins: import("@jesscss/core").PluginInterface[];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Return a visitor that wraps Less visitors
|
|
81
|
+
*
|
|
82
|
+
* This visitor intercepts each node, converts it to Less format,
|
|
83
|
+
* runs the Less visitors, and converts back if modified.
|
|
84
|
+
*/
|
|
85
|
+
get visitor(): Visitor | Visitor[] | undefined;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a Less.js compatibility plugin
|
|
89
|
+
*/
|
|
90
|
+
declare const lessCompatPlugin: Plugin;
|
|
91
|
+
export default lessCompatPlugin;
|
|
92
|
+
export { lessCompatPlugin };
|