@unocss/transformer-variant-group 0.26.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
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
@@ -0,0 +1,36 @@
1
+ # @unocss/transformer-variant-group
2
+
3
+ Enables the [variant group feature of Windi CSS](https://windicss.org/features/variant-groups.html) for UnoCSS.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -D @unocss/transformer-variant-group
9
+ ```
10
+
11
+ ```ts
12
+ import Unocss from 'unocss/vite'
13
+ import transformerVariantGroup from '@unocss/transformer-variant-group'
14
+
15
+ Unocss({
16
+ transformers: [
17
+ transformerVariantGroup(),
18
+ ]
19
+ })
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```html
25
+ <div class="hover:(bg-gray-400 font-medium) font-(light mono)"/>
26
+ ```
27
+
28
+ Will be transformed to:
29
+
30
+ ```html
31
+ <div class="hover:bg-gray-400 hover-font-medium font-light font-mono"/>
32
+ ```
33
+
34
+ ## License
35
+
36
+ MIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
package/dist/index.cjs ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const core = require('@unocss/core');
6
+ const MagicString = require('magic-string');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
9
+
10
+ const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
11
+
12
+ function transformerVariantGroup() {
13
+ return {
14
+ name: "variant-group",
15
+ enforce: "pre",
16
+ async transform(code) {
17
+ return transformVariantGroups(code);
18
+ }
19
+ };
20
+ }
21
+ function transformVariantGroups(code, sourcemap = true) {
22
+ const s = new MagicString__default(code);
23
+ let hasReplaced = false;
24
+ let match;
25
+ core.regexClassGroup.lastIndex = 0;
26
+ while (match = core.regexClassGroup.exec(code)) {
27
+ hasReplaced = true;
28
+ const start = match.index;
29
+ const end = start + match[0].length;
30
+ const [, pre, sep, body] = match;
31
+ const replacement = body.split(/\s/g).map((i) => i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
32
+ s.overwrite(start, end, replacement);
33
+ }
34
+ if (!hasReplaced)
35
+ return null;
36
+ return {
37
+ code: s.toString(),
38
+ map: sourcemap ? s.generateMap({ hires: true }) : void 0
39
+ };
40
+ }
41
+
42
+ exports["default"] = transformerVariantGroup;
43
+ exports.transformVariantGroups = transformVariantGroups;
@@ -0,0 +1,10 @@
1
+ import * as magic_string from 'magic-string';
2
+ import { SourceCodeTransformer } from '@unocss/core';
3
+
4
+ declare function transformerVariantGroup(): SourceCodeTransformer;
5
+ declare function transformVariantGroups(code: string, sourcemap?: boolean): {
6
+ code: string;
7
+ map: magic_string.SourceMap | undefined;
8
+ } | null;
9
+
10
+ export { transformerVariantGroup as default, transformVariantGroups };
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ import { regexClassGroup } from '@unocss/core';
2
+ import MagicString from 'magic-string';
3
+
4
+ function transformerVariantGroup() {
5
+ return {
6
+ name: "variant-group",
7
+ enforce: "pre",
8
+ async transform(code) {
9
+ return transformVariantGroups(code);
10
+ }
11
+ };
12
+ }
13
+ function transformVariantGroups(code, sourcemap = true) {
14
+ const s = new MagicString(code);
15
+ let hasReplaced = false;
16
+ let match;
17
+ regexClassGroup.lastIndex = 0;
18
+ while (match = regexClassGroup.exec(code)) {
19
+ hasReplaced = true;
20
+ const start = match.index;
21
+ const end = start + match[0].length;
22
+ const [, pre, sep, body] = match;
23
+ const replacement = body.split(/\s/g).map((i) => i.replace(/^(!?)(.*)/, `$1${pre}${sep}$2`)).join(" ");
24
+ s.overwrite(start, end, replacement);
25
+ }
26
+ if (!hasReplaced)
27
+ return null;
28
+ return {
29
+ code: s.toString(),
30
+ map: sourcemap ? s.generateMap({ hires: true }) : void 0
31
+ };
32
+ }
33
+
34
+ export { transformerVariantGroup as default, transformVariantGroups };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@unocss/transformer-variant-group",
3
+ "version": "0.26.0",
4
+ "description": "Variant group transformer for UnoCSS",
5
+ "keywords": [
6
+ "unocss",
7
+ "unocss-transformer"
8
+ ],
9
+ "homepage": "https://github.com/unocss/unocss/tree/main/packages/transformer-variant-group#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/unocss/unocss/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/unocss/unocss.git",
16
+ "directory": "packages/transformer-variant-group"
17
+ },
18
+ "funding": "https://github.com/sponsors/antfu",
19
+ "license": "MIT",
20
+ "author": "Anthony Fu <anthonyfu117@hotmail.com>",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "require": "./dist/index.cjs",
25
+ "import": "./dist/index.mjs"
26
+ }
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "peerDependencies": {
35
+ "@unocss/core": "0.26.0"
36
+ },
37
+ "devDependencies": {
38
+ "@unocss/core": "0.26.0"
39
+ },
40
+ "dependencies": {
41
+ "magic-string": "^0.25.7"
42
+ },
43
+ "scripts": {
44
+ "build": "unbuild",
45
+ "stub": "unbuild --stub"
46
+ }
47
+ }