@vinicunca/unocss-preset 1.0.1 → 1.1.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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const utils = require('@unocss/preset-mini/utils');
4
- const index = require('../shared/unocss-preset.D8jPio-z.cjs');
4
+ const index = require('../shared/unocss-preset.D0RjZcM6.cjs');
5
5
  require('@unocss/core');
6
6
  require('@vinicunca/perkakas');
7
7
 
@@ -1,5 +1,5 @@
1
1
  import { h } from '@unocss/preset-mini/utils';
2
- import { l as layerMeta } from '../shared/unocss-preset.4cul6C3a.mjs';
2
+ import { l as layerMeta } from '../shared/unocss-preset.BsBSSEP8.mjs';
3
3
  import '@unocss/core';
4
4
  import '@vinicunca/perkakas';
5
5
 
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ const core = require('@unocss/core');
4
+ const perkakas = require('@vinicunca/perkakas');
5
+
6
+ function transformerAlias(options) {
7
+ return {
8
+ name: "unocss-transformer-alias",
9
+ enforce: "pre",
10
+ async transform(code, _, { uno }) {
11
+ await transformAlias({ code, uno, options });
12
+ }
13
+ };
14
+ }
15
+ async function transformAlias({
16
+ code,
17
+ uno,
18
+ options = {}
19
+ }) {
20
+ let {
21
+ prefix = "*",
22
+ keep = "+"
23
+ } = options;
24
+ if (perkakas.isString(keep)) {
25
+ keep = { prefix: keep, block: true };
26
+ }
27
+ const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep.prefix)})([\\w-:]+)`, "g");
28
+ const map = /* @__PURE__ */ new Map();
29
+ for (const item of Array.from(code.original.matchAll(extraRE))) {
30
+ let result = map.get(item[0]);
31
+ if (result === false) {
32
+ continue;
33
+ } else if (!result) {
34
+ const res = await expandShortcut({ input: item[2], uno });
35
+ if (res) {
36
+ result = res[0].join(" ");
37
+ map.set(item[0], result);
38
+ } else {
39
+ map.set(item[0], false);
40
+ continue;
41
+ }
42
+ }
43
+ if (item[1] === keep.prefix) {
44
+ result = `${item[2]} ${result}`;
45
+ if (keep.block) {
46
+ uno.config.blocklist = [.../* @__PURE__ */ new Set([...uno.config.blocklist, item[2]])];
47
+ }
48
+ }
49
+ code.overwrite(item.index, item.index + item[0].length, result);
50
+ }
51
+ }
52
+ async function expandShortcut({ input, uno, depth = 5 }) {
53
+ if (depth <= 0) {
54
+ return;
55
+ }
56
+ let result;
57
+ for (const shortcut of uno.config.shortcuts) {
58
+ if (core.isStaticShortcut(shortcut)) {
59
+ if (shortcut[0] === input) {
60
+ result = shortcut[1];
61
+ }
62
+ } else {
63
+ const match = input.match(shortcut[0]);
64
+ if (match != null) {
65
+ result = shortcut[1](match, {});
66
+ }
67
+ }
68
+ }
69
+ if (perkakas.isString(result)) {
70
+ result = core.expandVariantGroup(result.trim()).split(/\s+/g);
71
+ }
72
+ if (!result) {
73
+ return;
74
+ }
75
+ return [
76
+ (await Promise.all(
77
+ result.filter((s) => s !== input).map(
78
+ async (res) => (perkakas.isString(res) ? (await expandShortcut({ input: res, uno, depth: depth - 1 }))?.[0] : void 0) || [res]
79
+ )
80
+ )).flat(1).filter(Boolean)
81
+ ];
82
+ }
83
+ function escapeRegExp(str) {
84
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
85
+ }
86
+
87
+ exports.expandShortcut = expandShortcut;
88
+ exports.transformAlias = transformAlias;
89
+ exports.transformerAlias = transformerAlias;
@@ -0,0 +1,85 @@
1
+ import { isStaticShortcut, expandVariantGroup } from '@unocss/core';
2
+ import { isString } from '@vinicunca/perkakas';
3
+
4
+ function transformerAlias(options) {
5
+ return {
6
+ name: "unocss-transformer-alias",
7
+ enforce: "pre",
8
+ async transform(code, _, { uno }) {
9
+ await transformAlias({ code, uno, options });
10
+ }
11
+ };
12
+ }
13
+ async function transformAlias({
14
+ code,
15
+ uno,
16
+ options = {}
17
+ }) {
18
+ let {
19
+ prefix = "*",
20
+ keep = "+"
21
+ } = options;
22
+ if (isString(keep)) {
23
+ keep = { prefix: keep, block: true };
24
+ }
25
+ const extraRE = new RegExp(`(${escapeRegExp(prefix)}|${escapeRegExp(keep.prefix)})([\\w-:]+)`, "g");
26
+ const map = /* @__PURE__ */ new Map();
27
+ for (const item of Array.from(code.original.matchAll(extraRE))) {
28
+ let result = map.get(item[0]);
29
+ if (result === false) {
30
+ continue;
31
+ } else if (!result) {
32
+ const res = await expandShortcut({ input: item[2], uno });
33
+ if (res) {
34
+ result = res[0].join(" ");
35
+ map.set(item[0], result);
36
+ } else {
37
+ map.set(item[0], false);
38
+ continue;
39
+ }
40
+ }
41
+ if (item[1] === keep.prefix) {
42
+ result = `${item[2]} ${result}`;
43
+ if (keep.block) {
44
+ uno.config.blocklist = [.../* @__PURE__ */ new Set([...uno.config.blocklist, item[2]])];
45
+ }
46
+ }
47
+ code.overwrite(item.index, item.index + item[0].length, result);
48
+ }
49
+ }
50
+ async function expandShortcut({ input, uno, depth = 5 }) {
51
+ if (depth <= 0) {
52
+ return;
53
+ }
54
+ let result;
55
+ for (const shortcut of uno.config.shortcuts) {
56
+ if (isStaticShortcut(shortcut)) {
57
+ if (shortcut[0] === input) {
58
+ result = shortcut[1];
59
+ }
60
+ } else {
61
+ const match = input.match(shortcut[0]);
62
+ if (match != null) {
63
+ result = shortcut[1](match, {});
64
+ }
65
+ }
66
+ }
67
+ if (isString(result)) {
68
+ result = expandVariantGroup(result.trim()).split(/\s+/g);
69
+ }
70
+ if (!result) {
71
+ return;
72
+ }
73
+ return [
74
+ (await Promise.all(
75
+ result.filter((s) => s !== input).map(
76
+ async (res) => (isString(res) ? (await expandShortcut({ input: res, uno, depth: depth - 1 }))?.[0] : void 0) || [res]
77
+ )
78
+ )).flat(1).filter(Boolean)
79
+ ];
80
+ }
81
+ function escapeRegExp(str) {
82
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
83
+ }
84
+
85
+ export { expandShortcut, transformAlias, transformerAlias };
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  require('@unocss/core');
4
- const index = require('./shared/unocss-preset.D8jPio-z.cjs');
4
+ const index = require('./shared/unocss-preset.D0RjZcM6.cjs');
5
5
  require('@vinicunca/perkakas');
6
6
 
7
7
 
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import { CSSObject, PresetFactoryAwaitable, UserConfig } from '@unocss/core';
2
- import { Theme } from '@unocss/preset-mini';
1
+ import * as _unocss_core from '@unocss/core';
2
+ import { CSSObject, UserConfig } from '@unocss/core';
3
3
  import { IconsOptions } from '@unocss/preset-icons';
4
+ import { Theme } from '@unocss/preset-mini';
4
5
  import { TypographyOptions } from '@unocss/preset-typography';
5
6
  import { PresetUnoOptions } from '@unocss/preset-uno';
6
7
  import { WebFontsOptions } from '@unocss/preset-web-fonts';
@@ -69,6 +70,35 @@ interface UnoPresetScrollbarOption {
69
70
  noCompatible?: boolean;
70
71
  }
71
72
 
73
+ interface KeepOption {
74
+ /**
75
+ * keep prefix for your alias.
76
+ *
77
+ * @default '+'
78
+ */
79
+ prefix: string;
80
+ /**
81
+ * Decedide whether to put it in `blocklist`.
82
+ *
83
+ * @default true
84
+ */
85
+ block: boolean;
86
+ }
87
+ interface TransformerAliasOptions {
88
+ /**
89
+ * Prefix for your alias.
90
+ *
91
+ * @default "*"
92
+ */
93
+ prefix?: string;
94
+ /**
95
+ * Prefix for your alias and keep the original class.
96
+ *
97
+ * @default '+'
98
+ */
99
+ keep?: string | KeepOption;
100
+ }
101
+
72
102
  interface AnimationOptions {
73
103
  /**
74
104
  * The unit of time options
@@ -234,7 +264,7 @@ interface PresetVinicuncaOptions {
234
264
  /**
235
265
  * Enable magicss preset
236
266
  *
237
- * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss)
267
+ * @about [Magic Animate](https://github.com/miniMAC/magic)
238
268
  * @default false
239
269
  */
240
270
  magicCss?: boolean;
@@ -265,6 +295,10 @@ interface PresetVinicuncaOptions {
265
295
  * @default true
266
296
  */
267
297
  variantGroup?: boolean | TransformerVariantGroupOptions;
298
+ /**
299
+ * Enable transform alias transformer and the options of it
300
+ */
301
+ alias?: boolean | TransformerAliasOptions;
268
302
  }
269
303
  interface FluidOptions {
270
304
  /**
@@ -312,7 +346,7 @@ type DeepPartial<T> = {
312
346
  [P in keyof T]: DeepPartial<T[P]>;
313
347
  };
314
348
 
315
- declare const presetVinicunca: PresetFactoryAwaitable<Theme, PresetVinicuncaOptions>;
349
+ declare const presetVinicunca: _unocss_core.PresetFactoryAwaitable<VinicuncaTheme, PresetVinicuncaOptions>;
316
350
  declare function defineVinicuncaConfig<T extends object = VinicuncaTheme>(options?: PresetVinicuncaOptions, config?: UserConfig<T>): UserConfig<T>;
317
351
  declare function defineConfig<T extends object = VinicuncaTheme>(config: UserConfig<T>): UserConfig<T>;
318
352
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { CSSObject, PresetFactoryAwaitable, UserConfig } from '@unocss/core';
2
- import { Theme } from '@unocss/preset-mini';
1
+ import * as _unocss_core from '@unocss/core';
2
+ import { CSSObject, UserConfig } from '@unocss/core';
3
3
  import { IconsOptions } from '@unocss/preset-icons';
4
+ import { Theme } from '@unocss/preset-mini';
4
5
  import { TypographyOptions } from '@unocss/preset-typography';
5
6
  import { PresetUnoOptions } from '@unocss/preset-uno';
6
7
  import { WebFontsOptions } from '@unocss/preset-web-fonts';
@@ -69,6 +70,35 @@ interface UnoPresetScrollbarOption {
69
70
  noCompatible?: boolean;
70
71
  }
71
72
 
73
+ interface KeepOption {
74
+ /**
75
+ * keep prefix for your alias.
76
+ *
77
+ * @default '+'
78
+ */
79
+ prefix: string;
80
+ /**
81
+ * Decedide whether to put it in `blocklist`.
82
+ *
83
+ * @default true
84
+ */
85
+ block: boolean;
86
+ }
87
+ interface TransformerAliasOptions {
88
+ /**
89
+ * Prefix for your alias.
90
+ *
91
+ * @default "*"
92
+ */
93
+ prefix?: string;
94
+ /**
95
+ * Prefix for your alias and keep the original class.
96
+ *
97
+ * @default '+'
98
+ */
99
+ keep?: string | KeepOption;
100
+ }
101
+
72
102
  interface AnimationOptions {
73
103
  /**
74
104
  * The unit of time options
@@ -234,7 +264,7 @@ interface PresetVinicuncaOptions {
234
264
  /**
235
265
  * Enable magicss preset
236
266
  *
237
- * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss)
267
+ * @about [Magic Animate](https://github.com/miniMAC/magic)
238
268
  * @default false
239
269
  */
240
270
  magicCss?: boolean;
@@ -265,6 +295,10 @@ interface PresetVinicuncaOptions {
265
295
  * @default true
266
296
  */
267
297
  variantGroup?: boolean | TransformerVariantGroupOptions;
298
+ /**
299
+ * Enable transform alias transformer and the options of it
300
+ */
301
+ alias?: boolean | TransformerAliasOptions;
268
302
  }
269
303
  interface FluidOptions {
270
304
  /**
@@ -312,7 +346,7 @@ type DeepPartial<T> = {
312
346
  [P in keyof T]: DeepPartial<T[P]>;
313
347
  };
314
348
 
315
- declare const presetVinicunca: PresetFactoryAwaitable<Theme, PresetVinicuncaOptions>;
349
+ declare const presetVinicunca: _unocss_core.PresetFactoryAwaitable<VinicuncaTheme, PresetVinicuncaOptions>;
316
350
  declare function defineVinicuncaConfig<T extends object = VinicuncaTheme>(options?: PresetVinicuncaOptions, config?: UserConfig<T>): UserConfig<T>;
317
351
  declare function defineConfig<T extends object = VinicuncaTheme>(config: UserConfig<T>): UserConfig<T>;
318
352
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { CSSObject, PresetFactoryAwaitable, UserConfig } from '@unocss/core';
2
- import { Theme } from '@unocss/preset-mini';
1
+ import * as _unocss_core from '@unocss/core';
2
+ import { CSSObject, UserConfig } from '@unocss/core';
3
3
  import { IconsOptions } from '@unocss/preset-icons';
4
+ import { Theme } from '@unocss/preset-mini';
4
5
  import { TypographyOptions } from '@unocss/preset-typography';
5
6
  import { PresetUnoOptions } from '@unocss/preset-uno';
6
7
  import { WebFontsOptions } from '@unocss/preset-web-fonts';
@@ -69,6 +70,35 @@ interface UnoPresetScrollbarOption {
69
70
  noCompatible?: boolean;
70
71
  }
71
72
 
73
+ interface KeepOption {
74
+ /**
75
+ * keep prefix for your alias.
76
+ *
77
+ * @default '+'
78
+ */
79
+ prefix: string;
80
+ /**
81
+ * Decedide whether to put it in `blocklist`.
82
+ *
83
+ * @default true
84
+ */
85
+ block: boolean;
86
+ }
87
+ interface TransformerAliasOptions {
88
+ /**
89
+ * Prefix for your alias.
90
+ *
91
+ * @default "*"
92
+ */
93
+ prefix?: string;
94
+ /**
95
+ * Prefix for your alias and keep the original class.
96
+ *
97
+ * @default '+'
98
+ */
99
+ keep?: string | KeepOption;
100
+ }
101
+
72
102
  interface AnimationOptions {
73
103
  /**
74
104
  * The unit of time options
@@ -234,7 +264,7 @@ interface PresetVinicuncaOptions {
234
264
  /**
235
265
  * Enable magicss preset
236
266
  *
237
- * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss)
267
+ * @about [Magic Animate](https://github.com/miniMAC/magic)
238
268
  * @default false
239
269
  */
240
270
  magicCss?: boolean;
@@ -265,6 +295,10 @@ interface PresetVinicuncaOptions {
265
295
  * @default true
266
296
  */
267
297
  variantGroup?: boolean | TransformerVariantGroupOptions;
298
+ /**
299
+ * Enable transform alias transformer and the options of it
300
+ */
301
+ alias?: boolean | TransformerAliasOptions;
268
302
  }
269
303
  interface FluidOptions {
270
304
  /**
@@ -312,7 +346,7 @@ type DeepPartial<T> = {
312
346
  [P in keyof T]: DeepPartial<T[P]>;
313
347
  };
314
348
 
315
- declare const presetVinicunca: PresetFactoryAwaitable<Theme, PresetVinicuncaOptions>;
349
+ declare const presetVinicunca: _unocss_core.PresetFactoryAwaitable<VinicuncaTheme, PresetVinicuncaOptions>;
316
350
  declare function defineVinicuncaConfig<T extends object = VinicuncaTheme>(options?: PresetVinicuncaOptions, config?: UserConfig<T>): UserConfig<T>;
317
351
  declare function defineConfig<T extends object = VinicuncaTheme>(config: UserConfig<T>): UserConfig<T>;
318
352
 
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import '@unocss/core';
2
- export { a as defineConfig, d as defineVinicuncaConfig, p as presetVinicunca } from './shared/unocss-preset.4cul6C3a.mjs';
2
+ export { a as defineConfig, d as defineVinicuncaConfig, p as presetVinicunca } from './shared/unocss-preset.BsBSSEP8.mjs';
3
3
  import '@vinicunca/perkakas';
@@ -572,7 +572,8 @@ async function resolveOptions(options) {
572
572
  };
573
573
  const transformerMap = {
574
574
  directives: import('unocss').then((mod) => mod.transformerDirectives),
575
- variantGroup: import('unocss').then((mod) => mod.transformerVariantGroup)
575
+ variantGroup: import('unocss').then((mod) => mod.transformerVariantGroup),
576
+ alias: import('../chunks/transformer-alias.mjs').then((mod) => mod.transformerAlias)
576
577
  };
577
578
  for (const [key, preset] of Object.entries(presetMap)) {
578
579
  const option = optionsWithDefault[key];
@@ -630,8 +631,8 @@ function resolveExtend(extend) {
630
631
  }
631
632
 
632
633
  const presetVinicunca = definePreset(
633
- async (options = {}) => {
634
- const resolvedOptions = await resolveOptions(options);
634
+ async (options) => {
635
+ const resolvedOptions = await resolveOptions(options ?? {});
635
636
  const {
636
637
  enableDefaultShortcuts,
637
638
  unColor,
@@ -574,7 +574,8 @@ async function resolveOptions(options) {
574
574
  };
575
575
  const transformerMap = {
576
576
  directives: import('unocss').then((mod) => mod.transformerDirectives),
577
- variantGroup: import('unocss').then((mod) => mod.transformerVariantGroup)
577
+ variantGroup: import('unocss').then((mod) => mod.transformerVariantGroup),
578
+ alias: import('../chunks/transformer-alias.cjs').then((mod) => mod.transformerAlias)
578
579
  };
579
580
  for (const [key, preset] of Object.entries(presetMap)) {
580
581
  const option = optionsWithDefault[key];
@@ -632,8 +633,8 @@ function resolveExtend(extend) {
632
633
  }
633
634
 
634
635
  const presetVinicunca = core.definePreset(
635
- async (options = {}) => {
636
- const resolvedOptions = await resolveOptions(options);
636
+ async (options) => {
637
+ const resolvedOptions = await resolveOptions(options ?? {});
637
638
  const {
638
639
  enableDefaultShortcuts,
639
640
  unColor,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinicunca/unocss-preset",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.1.1",
5
5
  "description": "Opinionated UnoCSS preset",
6
6
  "author": "praburangki<https://github.com/praburangki>",
7
7
  "license": "MIT",
@@ -42,21 +42,21 @@
42
42
  "dist"
43
43
  ],
44
44
  "peerDependencies": {
45
- "@vinicunca/perkakas": "^1.1.0",
46
- "unocss": "^0.65.1"
45
+ "@vinicunca/perkakas": "^1.2.0",
46
+ "unocss": "^0.65.3"
47
47
  },
48
48
  "publishConfig": {
49
49
  "registry": "https://registry.npmjs.org/"
50
50
  },
51
51
  "dependencies": {
52
- "@unocss/core": "^0.65.1",
53
- "@unocss/preset-icons": "^0.65.1",
54
- "@unocss/preset-mini": "^0.65.1",
55
- "@unocss/preset-typography": "^0.65.1",
56
- "@unocss/preset-uno": "^0.65.1",
57
- "@unocss/preset-web-fonts": "^0.65.1",
58
- "@unocss/transformer-directives": "^0.65.1",
59
- "@unocss/transformer-variant-group": "^0.65.1",
52
+ "@unocss/core": "^0.65.3",
53
+ "@unocss/preset-icons": "^0.65.3",
54
+ "@unocss/preset-mini": "^0.65.3",
55
+ "@unocss/preset-typography": "^0.65.3",
56
+ "@unocss/preset-uno": "^0.65.3",
57
+ "@unocss/preset-web-fonts": "^0.65.3",
58
+ "@unocss/transformer-directives": "^0.65.3",
59
+ "@unocss/transformer-variant-group": "^0.65.3",
60
60
  "postcss": "^8.4.49",
61
61
  "postcss-js": "^4.0.1"
62
62
  },