@unocss/preset-tagify 0.35.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 +22 -0
- package/README.md +77 -0
- package/dist/index.cjs +68 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.mjs +60 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-PRESENT Jeff Zou <https://github.com/zojize>
|
|
4
|
+
Copyright (c) 2022-PRESENT Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @unocss/preset-tagify
|
|
2
|
+
|
|
3
|
+
Tagify Mode for [UnoCSS](https://github.com/unocss/unocss).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D @unocss/preset-tagify
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import preseTagify from '@unocss/preset-tagify'
|
|
13
|
+
|
|
14
|
+
Unocss({
|
|
15
|
+
presets: [
|
|
16
|
+
presetTagify({ /* options */ }),
|
|
17
|
+
// ...other presets
|
|
18
|
+
],
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Tagify Mode
|
|
23
|
+
|
|
24
|
+
This preset can come in handy when you only need a single unocss rule to be apply on an element.
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<span class="text-red"> red text </span>
|
|
28
|
+
<div class="flex"> flexbox </div>
|
|
29
|
+
I'm feeling <span class="i-line-md-emoji-grin"></span> today!
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
With tagify mode, you can embed CSS styles into HTML tags:
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<text-red> red text </text-red>
|
|
36
|
+
<flex> flexbox </flex>
|
|
37
|
+
I'm feeling <i-line-md-emoji-grin> </i-line-md-emoji-grin> today!
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The HTML above works exactly as you would expect.
|
|
41
|
+
|
|
42
|
+
## With Prefix
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
presetTagify({
|
|
46
|
+
prefix: 'un-'
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<!-- this will be matched -->
|
|
52
|
+
<un-flex> </un-flex>
|
|
53
|
+
<!-- this will not be matched -->
|
|
54
|
+
<flex> </flex>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Extra Properties
|
|
58
|
+
|
|
59
|
+
You can inject extra properties to the matched rules:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
presetTagify({
|
|
63
|
+
// adds display: inline-block to matched icons
|
|
64
|
+
extraProperties: matched => matched.startsWith('i-')
|
|
65
|
+
? { display: 'inline-block' }
|
|
66
|
+
: { }
|
|
67
|
+
})
|
|
68
|
+
presetTagify({
|
|
69
|
+
// extraProperties can also be a plain object
|
|
70
|
+
extraProperties: { display: 'block' }
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT License © 2022-PRESENT [Jeff Zou](https://github.com/zojize)
|
|
77
|
+
MIT License © 2022-PRESENT [Anthony Fu](https://github.com/antfu)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const core = require('@unocss/core');
|
|
6
|
+
|
|
7
|
+
const MARKER = "__TAGIFY__";
|
|
8
|
+
const htmlTagRE = /<([\w\d-:]+)/g;
|
|
9
|
+
const extractorTagify = (options) => {
|
|
10
|
+
const {
|
|
11
|
+
prefix = ""
|
|
12
|
+
} = options;
|
|
13
|
+
return {
|
|
14
|
+
name: "tagify",
|
|
15
|
+
extract({ code }) {
|
|
16
|
+
return new Set(Array.from(code.matchAll(htmlTagRE)).filter(({ 1: match }) => match.startsWith(prefix)).map(([, matched]) => `${MARKER}${matched}`));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const variantTagify = (options) => {
|
|
22
|
+
const { extraProperties } = options;
|
|
23
|
+
const prefix = `${MARKER}${options.prefix ?? ""}`;
|
|
24
|
+
return {
|
|
25
|
+
name: "tagify",
|
|
26
|
+
match(input) {
|
|
27
|
+
if (!input.startsWith(prefix))
|
|
28
|
+
return;
|
|
29
|
+
const matcher = input.slice(prefix.length);
|
|
30
|
+
const handler = {
|
|
31
|
+
matcher,
|
|
32
|
+
selector: (i) => i.slice(MARKER.length + 1)
|
|
33
|
+
};
|
|
34
|
+
if (extraProperties) {
|
|
35
|
+
if (typeof extraProperties === "function")
|
|
36
|
+
handler.body = (entries) => [...entries, ...Object.entries(extraProperties(matcher) ?? {})];
|
|
37
|
+
else
|
|
38
|
+
handler.body = (entries) => [...entries, ...Object.entries(extraProperties)];
|
|
39
|
+
}
|
|
40
|
+
return handler;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const preset = (options = {}) => {
|
|
46
|
+
const {
|
|
47
|
+
defaultExtractor = true
|
|
48
|
+
} = options;
|
|
49
|
+
const variants = [
|
|
50
|
+
variantTagify(options)
|
|
51
|
+
];
|
|
52
|
+
const extractors = [
|
|
53
|
+
extractorTagify(options)
|
|
54
|
+
];
|
|
55
|
+
if (defaultExtractor)
|
|
56
|
+
extractors.push(core.extractorSplit);
|
|
57
|
+
return {
|
|
58
|
+
name: "@unocss/preset-tagify",
|
|
59
|
+
variants,
|
|
60
|
+
extractors
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports.MARKER = MARKER;
|
|
65
|
+
exports["default"] = preset;
|
|
66
|
+
exports.extractorTagify = extractorTagify;
|
|
67
|
+
exports.htmlTagRE = htmlTagRE;
|
|
68
|
+
exports.variantTagify = variantTagify;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Extractor, VariantObject, Preset } from '@unocss/core';
|
|
2
|
+
|
|
3
|
+
interface TagifyOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The prefix to use for the tagify variant.
|
|
6
|
+
*/
|
|
7
|
+
prefix?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Extra CSS properties to apply to matched rules
|
|
10
|
+
*/
|
|
11
|
+
extraProperties?: Record<string, string> | ((matched: string) => Partial<Record<string, string>>);
|
|
12
|
+
/**
|
|
13
|
+
* Enable default extractor
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
defaultExtractor?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare const MARKER = "__TAGIFY__";
|
|
20
|
+
declare const htmlTagRE: RegExp;
|
|
21
|
+
declare const extractorTagify: (options: TagifyOptions) => Extractor;
|
|
22
|
+
|
|
23
|
+
declare const variantTagify: (options: TagifyOptions) => VariantObject;
|
|
24
|
+
|
|
25
|
+
declare const preset: (options?: TagifyOptions) => Preset;
|
|
26
|
+
|
|
27
|
+
export { MARKER, TagifyOptions, preset as default, extractorTagify, htmlTagRE, variantTagify };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { extractorSplit } from '@unocss/core';
|
|
2
|
+
|
|
3
|
+
const MARKER = "__TAGIFY__";
|
|
4
|
+
const htmlTagRE = /<([\w\d-:]+)/g;
|
|
5
|
+
const extractorTagify = (options) => {
|
|
6
|
+
const {
|
|
7
|
+
prefix = ""
|
|
8
|
+
} = options;
|
|
9
|
+
return {
|
|
10
|
+
name: "tagify",
|
|
11
|
+
extract({ code }) {
|
|
12
|
+
return new Set(Array.from(code.matchAll(htmlTagRE)).filter(({ 1: match }) => match.startsWith(prefix)).map(([, matched]) => `${MARKER}${matched}`));
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const variantTagify = (options) => {
|
|
18
|
+
const { extraProperties } = options;
|
|
19
|
+
const prefix = `${MARKER}${options.prefix ?? ""}`;
|
|
20
|
+
return {
|
|
21
|
+
name: "tagify",
|
|
22
|
+
match(input) {
|
|
23
|
+
if (!input.startsWith(prefix))
|
|
24
|
+
return;
|
|
25
|
+
const matcher = input.slice(prefix.length);
|
|
26
|
+
const handler = {
|
|
27
|
+
matcher,
|
|
28
|
+
selector: (i) => i.slice(MARKER.length + 1)
|
|
29
|
+
};
|
|
30
|
+
if (extraProperties) {
|
|
31
|
+
if (typeof extraProperties === "function")
|
|
32
|
+
handler.body = (entries) => [...entries, ...Object.entries(extraProperties(matcher) ?? {})];
|
|
33
|
+
else
|
|
34
|
+
handler.body = (entries) => [...entries, ...Object.entries(extraProperties)];
|
|
35
|
+
}
|
|
36
|
+
return handler;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const preset = (options = {}) => {
|
|
42
|
+
const {
|
|
43
|
+
defaultExtractor = true
|
|
44
|
+
} = options;
|
|
45
|
+
const variants = [
|
|
46
|
+
variantTagify(options)
|
|
47
|
+
];
|
|
48
|
+
const extractors = [
|
|
49
|
+
extractorTagify(options)
|
|
50
|
+
];
|
|
51
|
+
if (defaultExtractor)
|
|
52
|
+
extractors.push(extractorSplit);
|
|
53
|
+
return {
|
|
54
|
+
name: "@unocss/preset-tagify",
|
|
55
|
+
variants,
|
|
56
|
+
extractors
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { MARKER, preset as default, extractorTagify, htmlTagRE, variantTagify };
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unocss/preset-tagify",
|
|
3
|
+
"version": "0.35.0",
|
|
4
|
+
"description": "Tagify preset for UnoCSS",
|
|
5
|
+
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://github.com/sponsors/antfu",
|
|
8
|
+
"homepage": "https://github.com/unocss/unocss/tree/main/packages/transformer-variant-group#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/unocss/unocss.git",
|
|
12
|
+
"directory": "packages/transformer-variant-group"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/unocss/unocss/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"unocss",
|
|
19
|
+
"unocss-preset"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@unocss/core": "0.35.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "unbuild",
|
|
40
|
+
"stub": "unbuild --stub"
|
|
41
|
+
}
|
|
42
|
+
}
|