@docusaurus/plugin-css-cascade-layers 3.7.0-canary-6319
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 +7 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +44 -0
- package/lib/layers.d.ts +10 -0
- package/lib/layers.js +24 -0
- package/lib/options.d.ts +11 -0
- package/lib/options.js +47 -0
- package/lib/postCssPlugin.d.ts +11 -0
- package/lib/postCssPlugin.js +41 -0
- package/package.json +30 -0
- package/src/index.ts +68 -0
- package/src/layers.ts +27 -0
- package/src/options.ts +87 -0
- package/src/postCssPlugin.ts +45 -0
- package/src/types.d.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
8
|
+
import type { PluginOptions, Options } from './options';
|
|
9
|
+
export default function pluginCssCascadeLayers(context: LoadContext, options: PluginOptions): Plugin | null;
|
|
10
|
+
export { validateOptions } from './options';
|
|
11
|
+
export type { PluginOptions, Options };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateOptions = void 0;
|
|
10
|
+
exports.default = pluginCssCascadeLayers;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const postCssPlugin_1 = require("./postCssPlugin");
|
|
14
|
+
const layers_1 = require("./layers");
|
|
15
|
+
const PluginName = 'docusaurus-plugin-css-cascade-layers';
|
|
16
|
+
const LayersDeclarationModule = 'layers.css';
|
|
17
|
+
function getLayersDeclarationPath(context, options) {
|
|
18
|
+
const { generatedFilesDir } = context;
|
|
19
|
+
const pluginId = options.id;
|
|
20
|
+
if (pluginId !== 'default') {
|
|
21
|
+
// Since it's only possible to declare a single layer order
|
|
22
|
+
// using this plugin twice doesn't really make sense
|
|
23
|
+
throw new Error('The CSS Cascade Layers plugin does not support multiple instances.');
|
|
24
|
+
}
|
|
25
|
+
return path_1.default.join(generatedFilesDir, PluginName, pluginId, LayersDeclarationModule);
|
|
26
|
+
}
|
|
27
|
+
function pluginCssCascadeLayers(context, options) {
|
|
28
|
+
const layersDeclarationPath = getLayersDeclarationPath(context, options);
|
|
29
|
+
return {
|
|
30
|
+
name: PluginName,
|
|
31
|
+
getClientModules() {
|
|
32
|
+
return [layersDeclarationPath];
|
|
33
|
+
},
|
|
34
|
+
async contentLoaded({ actions }) {
|
|
35
|
+
await actions.createData(LayersDeclarationModule, (0, layers_1.generateLayersDeclaration)(Object.keys(options.layers)));
|
|
36
|
+
},
|
|
37
|
+
configurePostCss(postCssOptions) {
|
|
38
|
+
postCssOptions.plugins.push((0, postCssPlugin_1.PostCssPluginWrapInLayer)(options));
|
|
39
|
+
return postCssOptions;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var options_1 = require("./options");
|
|
44
|
+
Object.defineProperty(exports, "validateOptions", { enumerable: true, get: function () { return options_1.validateOptions; } });
|
package/lib/layers.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export type LayerEntry = [string, (filePath: string) => boolean];
|
|
8
|
+
export declare function isValidLayerName(layer: string): boolean;
|
|
9
|
+
export declare function generateLayersDeclaration(layers: string[]): string;
|
|
10
|
+
export declare function findLayer(filePath: string, layers: LayerEntry[]): string | undefined;
|
package/lib/layers.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isValidLayerName = isValidLayerName;
|
|
10
|
+
exports.generateLayersDeclaration = generateLayersDeclaration;
|
|
11
|
+
exports.findLayer = findLayer;
|
|
12
|
+
function isValidLayerName(layer) {
|
|
13
|
+
// TODO improve validation rule to match spec, not high priority
|
|
14
|
+
return !layer.includes(',') && !layer.includes(' ');
|
|
15
|
+
}
|
|
16
|
+
function generateLayersDeclaration(layers) {
|
|
17
|
+
return `@layer ${layers.join(', ')};`;
|
|
18
|
+
}
|
|
19
|
+
function findLayer(filePath, layers) {
|
|
20
|
+
// Using find() => layers order matter
|
|
21
|
+
// The first layer that matches is used in priority even if others match too
|
|
22
|
+
const layerEntry = layers.find((layer) => layer[1](filePath));
|
|
23
|
+
return layerEntry?.[0]; // return layer name
|
|
24
|
+
}
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OptionValidationContext } from '@docusaurus/types';
|
|
2
|
+
export type PluginOptions = {
|
|
3
|
+
id: string;
|
|
4
|
+
layers: Record<string, (filePath: string) => boolean>;
|
|
5
|
+
};
|
|
6
|
+
export type Options = {
|
|
7
|
+
layers?: PluginOptions['layers'];
|
|
8
|
+
};
|
|
9
|
+
export declare const DEFAULT_LAYERS: PluginOptions['layers'];
|
|
10
|
+
export declare const DEFAULT_OPTIONS: Partial<PluginOptions>;
|
|
11
|
+
export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
|
package/lib/options.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_OPTIONS = exports.DEFAULT_LAYERS = void 0;
|
|
4
|
+
exports.validateOptions = validateOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/
|
|
11
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
|
+
const layers_1 = require("./layers");
|
|
13
|
+
// Not ideal to compute layers using "filePath.includes()"
|
|
14
|
+
// But this is mostly temporary until we add first-class layers everywhere
|
|
15
|
+
function layerFor(...params) {
|
|
16
|
+
return (filePath) => params.some((p) => filePath.includes(p));
|
|
17
|
+
}
|
|
18
|
+
// Object order matters, it defines the layer order
|
|
19
|
+
exports.DEFAULT_LAYERS = {
|
|
20
|
+
'docusaurus.infima': layerFor('node_modules/infima/dist'),
|
|
21
|
+
'docusaurus.theme-common': layerFor('packages/docusaurus-theme-common/lib', 'node_modules/@docusaurus/theme-common/lib'),
|
|
22
|
+
'docusaurus.theme-classic': layerFor('packages/docusaurus-theme-classic/lib', 'node_modules/@docusaurus/theme-classic/lib'),
|
|
23
|
+
'docusaurus.core': layerFor('packages/docusaurus/lib', 'node_modules/@docusaurus/core/lib'),
|
|
24
|
+
'docusaurus.plugin-debug': layerFor('packages/docusaurus-plugin-debug/lib', 'node_modules/@docusaurus/plugin-debug/lib'),
|
|
25
|
+
'docusaurus.theme-mermaid': layerFor('packages/docusaurus-theme-mermaid/lib', 'node_modules/@docusaurus/theme-mermaid/lib'),
|
|
26
|
+
'docusaurus.theme-live-codeblock': layerFor('packages/docusaurus-theme-live-codeblock/lib', 'node_modules/@docusaurus/theme-live-codeblock/lib'),
|
|
27
|
+
'docusaurus.theme-search-algolia.docsearch': layerFor('node_modules/@docsearch/css/dist'),
|
|
28
|
+
'docusaurus.theme-search-algolia': layerFor('packages/docusaurus-theme-search-algolia/lib', 'node_modules/@docusaurus/theme-search-algolia/lib'),
|
|
29
|
+
// docusaurus.website layer ? (declare it, even if empty?)
|
|
30
|
+
};
|
|
31
|
+
exports.DEFAULT_OPTIONS = {
|
|
32
|
+
id: 'default',
|
|
33
|
+
layers: exports.DEFAULT_LAYERS,
|
|
34
|
+
};
|
|
35
|
+
const pluginOptionsSchema = utils_validation_1.Joi.object({
|
|
36
|
+
layers: utils_validation_1.Joi.object()
|
|
37
|
+
.pattern(utils_validation_1.Joi.custom((val, helpers) => {
|
|
38
|
+
if (!(0, layers_1.isValidLayerName)(val)) {
|
|
39
|
+
return helpers.error('any.invalid');
|
|
40
|
+
}
|
|
41
|
+
return val;
|
|
42
|
+
}), utils_validation_1.Joi.function().arity(1).required())
|
|
43
|
+
.default(exports.DEFAULT_LAYERS),
|
|
44
|
+
});
|
|
45
|
+
function validateOptions({ validate, options, }) {
|
|
46
|
+
return validate(pluginOptionsSchema, options);
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginCreator } from 'postcss';
|
|
8
|
+
import type { PluginOptions } from './options';
|
|
9
|
+
export declare const PostCssPluginWrapInLayer: PluginCreator<{
|
|
10
|
+
layers: PluginOptions['layers'];
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PostCssPluginWrapInLayer = void 0;
|
|
10
|
+
const layers_1 = require("./layers");
|
|
11
|
+
function wrapCssRootInLayer(root, layer) {
|
|
12
|
+
const rootBefore = root.clone();
|
|
13
|
+
root.removeAll();
|
|
14
|
+
root.append({
|
|
15
|
+
type: 'atrule',
|
|
16
|
+
name: 'layer',
|
|
17
|
+
params: layer,
|
|
18
|
+
nodes: rootBefore.nodes,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const PostCssPluginWrapInLayer = (options) => {
|
|
22
|
+
if (!options) {
|
|
23
|
+
throw new Error('PostCssPluginWrapInLayer options are mandatory');
|
|
24
|
+
}
|
|
25
|
+
const layers = Object.entries(options.layers);
|
|
26
|
+
return {
|
|
27
|
+
postcssPlugin: 'postcss-wrap-in-layer',
|
|
28
|
+
Once(root) {
|
|
29
|
+
const filePath = root.source?.input.file;
|
|
30
|
+
if (!filePath) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const layer = (0, layers_1.findLayer)(filePath, layers);
|
|
34
|
+
if (layer) {
|
|
35
|
+
wrapCssRootInLayer(root, layer);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.PostCssPluginWrapInLayer = PostCssPluginWrapInLayer;
|
|
41
|
+
exports.PostCssPluginWrapInLayer.postcss = true;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@docusaurus/plugin-css-cascade-layers",
|
|
3
|
+
"version": "3.7.0-canary-6319",
|
|
4
|
+
"description": "CSS Cascade Layer plugin for Docusaurus.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc --build",
|
|
9
|
+
"watch": "tsc --build --watch"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/facebook/docusaurus.git",
|
|
17
|
+
"directory": "packages/docusaurus-plugin-css-cascade-layers"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@docusaurus/core": "3.7.0-canary-6319",
|
|
22
|
+
"@docusaurus/types": "3.7.0-canary-6319",
|
|
23
|
+
"@docusaurus/utils-validation": "3.7.0-canary-6319",
|
|
24
|
+
"tslib": "^2.6.0"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.0"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "9722ff10706018e5c5d95c7860fce53f9cd1a235"
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import {PostCssPluginWrapInLayer} from './postCssPlugin';
|
|
10
|
+
import {generateLayersDeclaration} from './layers';
|
|
11
|
+
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
12
|
+
import type {PluginOptions, Options} from './options';
|
|
13
|
+
|
|
14
|
+
const PluginName = 'docusaurus-plugin-css-cascade-layers';
|
|
15
|
+
|
|
16
|
+
const LayersDeclarationModule = 'layers.css';
|
|
17
|
+
|
|
18
|
+
function getLayersDeclarationPath(
|
|
19
|
+
context: LoadContext,
|
|
20
|
+
options: PluginOptions,
|
|
21
|
+
) {
|
|
22
|
+
const {generatedFilesDir} = context;
|
|
23
|
+
const pluginId = options.id;
|
|
24
|
+
if (pluginId !== 'default') {
|
|
25
|
+
// Since it's only possible to declare a single layer order
|
|
26
|
+
// using this plugin twice doesn't really make sense
|
|
27
|
+
throw new Error(
|
|
28
|
+
'The CSS Cascade Layers plugin does not support multiple instances.',
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return path.join(
|
|
32
|
+
generatedFilesDir,
|
|
33
|
+
PluginName,
|
|
34
|
+
pluginId,
|
|
35
|
+
LayersDeclarationModule,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default function pluginCssCascadeLayers(
|
|
40
|
+
context: LoadContext,
|
|
41
|
+
options: PluginOptions,
|
|
42
|
+
): Plugin | null {
|
|
43
|
+
const layersDeclarationPath = getLayersDeclarationPath(context, options);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
name: PluginName,
|
|
47
|
+
|
|
48
|
+
getClientModules() {
|
|
49
|
+
return [layersDeclarationPath];
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
async contentLoaded({actions}) {
|
|
53
|
+
await actions.createData(
|
|
54
|
+
LayersDeclarationModule,
|
|
55
|
+
generateLayersDeclaration(Object.keys(options.layers)),
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
configurePostCss(postCssOptions) {
|
|
60
|
+
postCssOptions.plugins.push(PostCssPluginWrapInLayer(options));
|
|
61
|
+
return postCssOptions;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export {validateOptions} from './options';
|
|
67
|
+
|
|
68
|
+
export type {PluginOptions, Options};
|
package/src/layers.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type LayerEntry = [string, (filePath: string) => boolean];
|
|
9
|
+
|
|
10
|
+
export function isValidLayerName(layer: string): boolean {
|
|
11
|
+
// TODO improve validation rule to match spec, not high priority
|
|
12
|
+
return !layer.includes(',') && !layer.includes(' ');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function generateLayersDeclaration(layers: string[]): string {
|
|
16
|
+
return `@layer ${layers.join(', ')};`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function findLayer(
|
|
20
|
+
filePath: string,
|
|
21
|
+
layers: LayerEntry[],
|
|
22
|
+
): string | undefined {
|
|
23
|
+
// Using find() => layers order matter
|
|
24
|
+
// The first layer that matches is used in priority even if others match too
|
|
25
|
+
const layerEntry = layers.find((layer) => layer[1](filePath));
|
|
26
|
+
return layerEntry?.[0]; // return layer name
|
|
27
|
+
}
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import {Joi} from '@docusaurus/utils-validation';
|
|
8
|
+
import {isValidLayerName} from './layers';
|
|
9
|
+
import type {OptionValidationContext} from '@docusaurus/types';
|
|
10
|
+
|
|
11
|
+
export type PluginOptions = {
|
|
12
|
+
id: string; // plugin id
|
|
13
|
+
layers: Record<string, (filePath: string) => boolean>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type Options = {
|
|
17
|
+
layers?: PluginOptions['layers'];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Not ideal to compute layers using "filePath.includes()"
|
|
21
|
+
// But this is mostly temporary until we add first-class layers everywhere
|
|
22
|
+
function layerFor(...params: string[]) {
|
|
23
|
+
return (filePath: string) => params.some((p) => filePath.includes(p));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Object order matters, it defines the layer order
|
|
27
|
+
export const DEFAULT_LAYERS: PluginOptions['layers'] = {
|
|
28
|
+
'docusaurus.infima': layerFor('node_modules/infima/dist'),
|
|
29
|
+
'docusaurus.theme-common': layerFor(
|
|
30
|
+
'packages/docusaurus-theme-common/lib',
|
|
31
|
+
'node_modules/@docusaurus/theme-common/lib',
|
|
32
|
+
),
|
|
33
|
+
'docusaurus.theme-classic': layerFor(
|
|
34
|
+
'packages/docusaurus-theme-classic/lib',
|
|
35
|
+
'node_modules/@docusaurus/theme-classic/lib',
|
|
36
|
+
),
|
|
37
|
+
'docusaurus.core': layerFor(
|
|
38
|
+
'packages/docusaurus/lib',
|
|
39
|
+
'node_modules/@docusaurus/core/lib',
|
|
40
|
+
),
|
|
41
|
+
'docusaurus.plugin-debug': layerFor(
|
|
42
|
+
'packages/docusaurus-plugin-debug/lib',
|
|
43
|
+
'node_modules/@docusaurus/plugin-debug/lib',
|
|
44
|
+
),
|
|
45
|
+
'docusaurus.theme-mermaid': layerFor(
|
|
46
|
+
'packages/docusaurus-theme-mermaid/lib',
|
|
47
|
+
'node_modules/@docusaurus/theme-mermaid/lib',
|
|
48
|
+
),
|
|
49
|
+
'docusaurus.theme-live-codeblock': layerFor(
|
|
50
|
+
'packages/docusaurus-theme-live-codeblock/lib',
|
|
51
|
+
'node_modules/@docusaurus/theme-live-codeblock/lib',
|
|
52
|
+
),
|
|
53
|
+
'docusaurus.theme-search-algolia.docsearch': layerFor(
|
|
54
|
+
'node_modules/@docsearch/css/dist',
|
|
55
|
+
),
|
|
56
|
+
'docusaurus.theme-search-algolia': layerFor(
|
|
57
|
+
'packages/docusaurus-theme-search-algolia/lib',
|
|
58
|
+
'node_modules/@docusaurus/theme-search-algolia/lib',
|
|
59
|
+
),
|
|
60
|
+
// docusaurus.website layer ? (declare it, even if empty?)
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const DEFAULT_OPTIONS: Partial<PluginOptions> = {
|
|
64
|
+
id: 'default',
|
|
65
|
+
layers: DEFAULT_LAYERS,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const pluginOptionsSchema = Joi.object<PluginOptions>({
|
|
69
|
+
layers: Joi.object()
|
|
70
|
+
.pattern(
|
|
71
|
+
Joi.custom((val, helpers) => {
|
|
72
|
+
if (!isValidLayerName(val)) {
|
|
73
|
+
return helpers.error('any.invalid');
|
|
74
|
+
}
|
|
75
|
+
return val;
|
|
76
|
+
}),
|
|
77
|
+
Joi.function().arity(1).required(),
|
|
78
|
+
)
|
|
79
|
+
.default(DEFAULT_LAYERS),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export function validateOptions({
|
|
83
|
+
validate,
|
|
84
|
+
options,
|
|
85
|
+
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
|
|
86
|
+
return validate(pluginOptionsSchema, options);
|
|
87
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {findLayer} from './layers';
|
|
9
|
+
import type {Root, PluginCreator} from 'postcss';
|
|
10
|
+
import type {PluginOptions} from './options';
|
|
11
|
+
|
|
12
|
+
function wrapCssRootInLayer(root: Root, layer: string): void {
|
|
13
|
+
const rootBefore = root.clone();
|
|
14
|
+
root.removeAll();
|
|
15
|
+
root.append({
|
|
16
|
+
type: 'atrule',
|
|
17
|
+
name: 'layer',
|
|
18
|
+
params: layer,
|
|
19
|
+
nodes: rootBefore.nodes,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const PostCssPluginWrapInLayer: PluginCreator<{
|
|
24
|
+
layers: PluginOptions['layers'];
|
|
25
|
+
}> = (options) => {
|
|
26
|
+
if (!options) {
|
|
27
|
+
throw new Error('PostCssPluginWrapInLayer options are mandatory');
|
|
28
|
+
}
|
|
29
|
+
const layers = Object.entries(options.layers);
|
|
30
|
+
return {
|
|
31
|
+
postcssPlugin: 'postcss-wrap-in-layer',
|
|
32
|
+
Once(root) {
|
|
33
|
+
const filePath = root.source?.input.file;
|
|
34
|
+
if (!filePath) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const layer = findLayer(filePath, layers);
|
|
38
|
+
if (layer) {
|
|
39
|
+
wrapCssRootInLayer(root, layer);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
PostCssPluginWrapInLayer.postcss = true;
|
package/src/types.d.ts
ADDED