@vinicunca/unocss-preset 1.0.0 → 1.1.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.
@@ -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.BBu6rF-8.cjs');
4
+ const index = require('../shared/unocss-preset.6ezA0EE_.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.kBN4Axkk.mjs';
2
+ import { l as layerMeta } from '../shared/unocss-preset.DZKZMqtg.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.BBu6rF-8.cjs');
4
+ const index = require('./shared/unocss-preset.6ezA0EE_.cjs');
5
5
  require('@vinicunca/perkakas');
6
6
 
7
7
 
package/dist/index.d.cts CHANGED
@@ -69,6 +69,35 @@ interface UnoPresetScrollbarOption {
69
69
  noCompatible?: boolean;
70
70
  }
71
71
 
72
+ interface KeepOption {
73
+ /**
74
+ * keep prefix for your alias.
75
+ *
76
+ * @default '+'
77
+ */
78
+ prefix: string;
79
+ /**
80
+ * Decedide whether to put it in `blocklist`.
81
+ *
82
+ * @default true
83
+ */
84
+ block: boolean;
85
+ }
86
+ interface TransformerAliasOptions {
87
+ /**
88
+ * Prefix for your alias.
89
+ *
90
+ * @default "*"
91
+ */
92
+ prefix?: string;
93
+ /**
94
+ * Prefix for your alias and keep the original class.
95
+ *
96
+ * @default '+'
97
+ */
98
+ keep?: string | KeepOption;
99
+ }
100
+
72
101
  interface AnimationOptions {
73
102
  /**
74
103
  * The unit of time options
@@ -234,7 +263,7 @@ interface PresetVinicuncaOptions {
234
263
  /**
235
264
  * Enable magicss preset
236
265
  *
237
- * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss)
266
+ * @about [Magic Animate](https://github.com/miniMAC/magic)
238
267
  * @default false
239
268
  */
240
269
  magicCss?: boolean;
@@ -265,6 +294,10 @@ interface PresetVinicuncaOptions {
265
294
  * @default true
266
295
  */
267
296
  variantGroup?: boolean | TransformerVariantGroupOptions;
297
+ /**
298
+ * Enable transform alias transformer and the options of it
299
+ */
300
+ alias?: boolean | TransformerAliasOptions;
268
301
  }
269
302
  interface FluidOptions {
270
303
  /**
package/dist/index.d.mts CHANGED
@@ -69,6 +69,35 @@ interface UnoPresetScrollbarOption {
69
69
  noCompatible?: boolean;
70
70
  }
71
71
 
72
+ interface KeepOption {
73
+ /**
74
+ * keep prefix for your alias.
75
+ *
76
+ * @default '+'
77
+ */
78
+ prefix: string;
79
+ /**
80
+ * Decedide whether to put it in `blocklist`.
81
+ *
82
+ * @default true
83
+ */
84
+ block: boolean;
85
+ }
86
+ interface TransformerAliasOptions {
87
+ /**
88
+ * Prefix for your alias.
89
+ *
90
+ * @default "*"
91
+ */
92
+ prefix?: string;
93
+ /**
94
+ * Prefix for your alias and keep the original class.
95
+ *
96
+ * @default '+'
97
+ */
98
+ keep?: string | KeepOption;
99
+ }
100
+
72
101
  interface AnimationOptions {
73
102
  /**
74
103
  * The unit of time options
@@ -234,7 +263,7 @@ interface PresetVinicuncaOptions {
234
263
  /**
235
264
  * Enable magicss preset
236
265
  *
237
- * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss)
266
+ * @about [Magic Animate](https://github.com/miniMAC/magic)
238
267
  * @default false
239
268
  */
240
269
  magicCss?: boolean;
@@ -265,6 +294,10 @@ interface PresetVinicuncaOptions {
265
294
  * @default true
266
295
  */
267
296
  variantGroup?: boolean | TransformerVariantGroupOptions;
297
+ /**
298
+ * Enable transform alias transformer and the options of it
299
+ */
300
+ alias?: boolean | TransformerAliasOptions;
268
301
  }
269
302
  interface FluidOptions {
270
303
  /**
package/dist/index.d.ts CHANGED
@@ -69,6 +69,35 @@ interface UnoPresetScrollbarOption {
69
69
  noCompatible?: boolean;
70
70
  }
71
71
 
72
+ interface KeepOption {
73
+ /**
74
+ * keep prefix for your alias.
75
+ *
76
+ * @default '+'
77
+ */
78
+ prefix: string;
79
+ /**
80
+ * Decedide whether to put it in `blocklist`.
81
+ *
82
+ * @default true
83
+ */
84
+ block: boolean;
85
+ }
86
+ interface TransformerAliasOptions {
87
+ /**
88
+ * Prefix for your alias.
89
+ *
90
+ * @default "*"
91
+ */
92
+ prefix?: string;
93
+ /**
94
+ * Prefix for your alias and keep the original class.
95
+ *
96
+ * @default '+'
97
+ */
98
+ keep?: string | KeepOption;
99
+ }
100
+
72
101
  interface AnimationOptions {
73
102
  /**
74
103
  * The unit of time options
@@ -234,7 +263,7 @@ interface PresetVinicuncaOptions {
234
263
  /**
235
264
  * Enable magicss preset
236
265
  *
237
- * @about [unocss-preset-magicss](https://github.com/unpreset/unocss-preset-magicss)
266
+ * @about [Magic Animate](https://github.com/miniMAC/magic)
238
267
  * @default false
239
268
  */
240
269
  magicCss?: boolean;
@@ -265,6 +294,10 @@ interface PresetVinicuncaOptions {
265
294
  * @default true
266
295
  */
267
296
  variantGroup?: boolean | TransformerVariantGroupOptions;
297
+ /**
298
+ * Enable transform alias transformer and the options of it
299
+ */
300
+ alias?: boolean | TransformerAliasOptions;
268
301
  }
269
302
  interface FluidOptions {
270
303
  /**
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.kBN4Axkk.mjs';
2
+ export { a as defineConfig, d as defineVinicuncaConfig, p as presetVinicunca } from './shared/unocss-preset.DZKZMqtg.mjs';
3
3
  import '@vinicunca/perkakas';
@@ -431,16 +431,11 @@ function getPreflights(options) {
431
431
  ].filter(Boolean);
432
432
  }
433
433
 
434
- const PRESET_NAME = "vinicunca";
435
- const layerMeta = {
436
- layer: PRESET_NAME
437
- };
438
-
439
434
  const customShortcuts = [
440
435
  ["flex-center", "flex justify-center items-center"],
441
436
  ["flex-x-center", "flex justify-center"],
442
437
  ["flex-y-center", "flex items-center"],
443
- ["flex-col", "flex flex-col"],
438
+ ["flex-vertical", "flex flex-col"],
444
439
  ["flex-col-center", "flex-center flex-col"]
445
440
  ];
446
441
  const defaultShortcuts = normalizeShortcut(customShortcuts);
@@ -457,10 +452,17 @@ function normalizeShortcut(shortcut) {
457
452
  for (const short of defaultShortcuts) {
458
453
  short[2] = Object.assign(
459
454
  short[2] || {},
460
- layerMeta
455
+ {
456
+ layer: "shortcuts"
457
+ }
461
458
  );
462
459
  }
463
460
 
461
+ const PRESET_NAME = "vinicunca";
462
+ const layerMeta = {
463
+ layer: PRESET_NAME
464
+ };
465
+
464
466
  const RE_ANIMATION = /^([a-z-]+)\s+([0-9.]+m?s?|[*+])?\s?([a-z-]+(?:\([^)]+\))?|[*+])?\s*([a-z0-9-]+|[*+])?$/i;
465
467
  function resolveAnimation(extendAnimation) {
466
468
  const animation = {};
@@ -572,7 +574,8 @@ async function resolveOptions(options) {
572
574
  };
573
575
  const transformerMap = {
574
576
  directives: import('unocss').then((mod) => mod.transformerDirectives),
575
- 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)
576
579
  };
577
580
  for (const [key, preset] of Object.entries(presetMap)) {
578
581
  const option = optionsWithDefault[key];
@@ -641,7 +644,7 @@ const presetVinicunca = core.definePreset(
641
644
  return {
642
645
  name: `unocss-preset-${PRESET_NAME}`,
643
646
  layers: {
644
- [PRESET_NAME]: 2
647
+ [PRESET_NAME]: 10
645
648
  },
646
649
  theme,
647
650
  shortcuts: [
@@ -429,16 +429,11 @@ function getPreflights(options) {
429
429
  ].filter(Boolean);
430
430
  }
431
431
 
432
- const PRESET_NAME = "vinicunca";
433
- const layerMeta = {
434
- layer: PRESET_NAME
435
- };
436
-
437
432
  const customShortcuts = [
438
433
  ["flex-center", "flex justify-center items-center"],
439
434
  ["flex-x-center", "flex justify-center"],
440
435
  ["flex-y-center", "flex items-center"],
441
- ["flex-col", "flex flex-col"],
436
+ ["flex-vertical", "flex flex-col"],
442
437
  ["flex-col-center", "flex-center flex-col"]
443
438
  ];
444
439
  const defaultShortcuts = normalizeShortcut(customShortcuts);
@@ -455,10 +450,17 @@ function normalizeShortcut(shortcut) {
455
450
  for (const short of defaultShortcuts) {
456
451
  short[2] = Object.assign(
457
452
  short[2] || {},
458
- layerMeta
453
+ {
454
+ layer: "shortcuts"
455
+ }
459
456
  );
460
457
  }
461
458
 
459
+ const PRESET_NAME = "vinicunca";
460
+ const layerMeta = {
461
+ layer: PRESET_NAME
462
+ };
463
+
462
464
  const RE_ANIMATION = /^([a-z-]+)\s+([0-9.]+m?s?|[*+])?\s?([a-z-]+(?:\([^)]+\))?|[*+])?\s*([a-z0-9-]+|[*+])?$/i;
463
465
  function resolveAnimation(extendAnimation) {
464
466
  const animation = {};
@@ -570,7 +572,8 @@ async function resolveOptions(options) {
570
572
  };
571
573
  const transformerMap = {
572
574
  directives: import('unocss').then((mod) => mod.transformerDirectives),
573
- 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)
574
577
  };
575
578
  for (const [key, preset] of Object.entries(presetMap)) {
576
579
  const option = optionsWithDefault[key];
@@ -639,7 +642,7 @@ const presetVinicunca = definePreset(
639
642
  return {
640
643
  name: `unocss-preset-${PRESET_NAME}`,
641
644
  layers: {
642
- [PRESET_NAME]: 2
645
+ [PRESET_NAME]: 10
643
646
  },
644
647
  theme,
645
648
  shortcuts: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vinicunca/unocss-preset",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
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.2"
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.2",
53
+ "@unocss/preset-icons": "^0.65.2",
54
+ "@unocss/preset-mini": "^0.65.2",
55
+ "@unocss/preset-typography": "^0.65.2",
56
+ "@unocss/preset-uno": "^0.65.2",
57
+ "@unocss/preset-web-fonts": "^0.65.2",
58
+ "@unocss/transformer-directives": "^0.65.2",
59
+ "@unocss/transformer-variant-group": "^0.65.2",
60
60
  "postcss": "^8.4.49",
61
61
  "postcss-js": "^4.0.1"
62
62
  },