diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c4e1ec..8dc8227 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -157,14 +157,6 @@ packages: resolution: {integrity: sha512-pvFiLP2BeOKA/ZOS6jxx4XhKzdVLHDhGlFEaZ2flWWYf2xOqVniqpk38I04DFRyz+L0ASggl7SkItTc+ZLju4w==} dev: true - /@babel/code-frame@7.22.13: - resolution: {integrity: sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/highlight': 7.22.13 - chalk: 2.4.2 - dev: true - /@babel/code-frame@7.23.4: resolution: {integrity: sha512-r1IONyb6Ia+jYR2vvIDhdWdlTGhqbBoFqLTQidzZ4kepUFH15ejXvFHxCVbtl7BOXIudsIubf4E81xeA3h3IXA==} engines: {node: '>=6.9.0'} @@ -183,12 +175,12 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@ampproject/remapping': 2.2.1 - '@babel/code-frame': 7.22.13 + '@babel/code-frame': 7.23.4 '@babel/generator': 7.22.15 '@babel/helper-compilation-targets': 7.22.15 '@babel/helper-module-transforms': 7.22.15(@babel/core@7.22.15) '@babel/helpers': 7.22.15 - '@babel/parser': 7.22.16 + '@babel/parser': 7.23.4 '@babel/template': 7.22.15 '@babel/traverse': 7.22.15 '@babel/types': 7.23.4 @@ -270,8 +262,8 @@ packages: dependencies: '@babel/core': 7.23.3 '@babel/helper-annotate-as-pure': 7.22.5 - '@babel/helper-environment-visitor': 7.22.20 - '@babel/helper-function-name': 7.23.0 + '@babel/helper-environment-visitor': 7.22.5 + '@babel/helper-function-name': 7.22.5 '@babel/helper-member-expression-to-functions': 7.23.0 '@babel/helper-optimise-call-expression': 7.22.5 '@babel/helper-replace-supers': 7.22.20(@babel/core@7.23.3) @@ -435,16 +427,6 @@ packages: - supports-color dev: true - /@babel/highlight@7.22.13: - resolution: {integrity: sha512-C/BaXcnnvBCmHTpz/VGZ8jgtE2aYlW4hxDhseJAWZb7gqGM/qtCK6iZUb0TyKFf7BOUsBH7Q7fkRsDRhg1XklQ==} - engines: {node: '>=6.9.0'} - requiresBuild: true - dependencies: - '@babel/helper-validator-identifier': 7.22.20 - chalk: 2.4.2 - js-tokens: 4.0.0 - dev: true - /@babel/highlight@7.23.4: resolution: {integrity: sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==} engines: {node: '>=6.9.0'} @@ -455,14 +437,6 @@ packages: js-tokens: 4.0.0 dev: true - /@babel/parser@7.22.16: - resolution: {integrity: sha512-+gPfKv8UWeKKeJTUxe59+OobVcrYHETCsORl61EmSkmgymguYk/X5bp7GuUIXaFsc6y++v8ZxPsLSSuujqDphA==} - engines: {node: '>=6.0.0'} - hasBin: true - dependencies: - '@babel/types': 7.23.4 - dev: true - /@babel/parser@7.23.4: resolution: {integrity: sha512-vf3Xna6UEprW+7t6EtOmFpHNAuxw3xqPZghy+brsnusscJRW5BMUzzHZc5ICjULee81WeUV2jjakG09MDglJXQ==} engines: {node: '>=6.0.0'} @@ -538,8 +512,8 @@ packages: resolution: {integrity: sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==} engines: {node: '>=6.9.0'} dependencies: - '@babel/code-frame': 7.22.13 - '@babel/parser': 7.22.16 + '@babel/code-frame': 7.23.4 + '@babel/parser': 7.23.4 '@babel/types': 7.23.4 dev: true @@ -547,13 +521,13 @@ packages: resolution: {integrity: sha512-DdHPwvJY0sEeN4xJU5uRLmZjgMMDIvMPniLuYzUVXj/GGzysPl0/fwt44JBkyUIzGJPV8QgHMcQdQ34XFuKTYQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/code-frame': 7.22.13 + '@babel/code-frame': 7.23.4 '@babel/generator': 7.22.15 '@babel/helper-environment-visitor': 7.22.5 '@babel/helper-function-name': 7.22.5 '@babel/helper-hoist-variables': 7.22.5 '@babel/helper-split-export-declaration': 7.22.6 - '@babel/parser': 7.22.16 + '@babel/parser': 7.23.4 '@babel/types': 7.23.4 debug: 4.3.4 globals: 11.12.0 @@ -1263,8 +1237,8 @@ packages: resolution: {integrity: sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==} dev: true - /@iconify/utils@2.1.11: - resolution: {integrity: sha512-M/w3PkN8zQYXi8N6qK/KhnYMfEbbb6Sk8RZVn8g+Pmmu5ybw177RpsaGwpziyHeUsu4etrexYSWq3rwnIqzYCg==} + /@iconify/utils@2.1.12: + resolution: {integrity: sha512-7vf3Uk6H7TKX4QMs2gbg5KR1X9J0NJzKSRNWhMZ+PWN92l0t6Q3tj2ZxLDG07rC3ppWBtTtA4FPmkQphuEmdsg==} dependencies: '@antfu/install-pkg': 0.1.1 '@antfu/utils': 0.7.6 @@ -2070,7 +2044,7 @@ packages: /@unocss/preset-icons@0.57.7: resolution: {integrity: sha512-s3AelKCS9CL1ArP1GanYv0XxxPrcFi+XOuQoQCwCRHDo2CiBEq3fLLMIhaUCFEWGtIy7o7wLeL5BRjMvJ2QnMg==} dependencies: - '@iconify/utils': 2.1.11 + '@iconify/utils': 2.1.12 '@unocss/core': 0.57.7 ofetch: 1.3.3 transitivePeerDependencies: @@ -3830,7 +3804,7 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: dir-glob: 3.0.1 - fast-glob: 3.3.1 + fast-glob: 3.3.2 ignore: 5.2.4 merge2: 1.4.1 slash: 4.0.0 @@ -5234,7 +5208,7 @@ packages: rollup: ^3.25 typescript: ^4.5 || ^5.0 dependencies: - magic-string: 0.30.3 + magic-string: 0.30.5 rollup: 3.29.0 typescript: 5.2.2 optionalDependencies: diff --git a/src/index.ts b/src/index.ts index 41637c1..6b2ed92 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ export const presetBlock = definePreset((_options: PresetBlockOptions = {}) => { } const regexes = [ - /^((p|m|rounded|rd|space|inset)(-?[xyrltb])?|pa|ma|top|bottom|left|right|w|h|min-w|min-h)-?((\.\d+)|(\d+)(\.\d+)?)(rem|px)$/, + /^((p|m|rounded|rd|space|inset)(-?[xyrltb])?|pa|ma|top|bottom|left|right|w|h|min-w|min-h|lh|leading)-?((\.\d+)|(\d+)(\.\d+)?)(rem|px)$/, /^text-(size-)?[0-9]$/, /\w+--((\.\d+)|(\d+)(\.\d+)?)/, ] diff --git a/tests/index.test.ts b/tests/index.test.ts index 5f96c31..f1c4066 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,5 +1,6 @@ -import { createGenerator } from 'unocss' +import { createGenerator } from '@unocss/core' import { describe, expect, it } from 'vitest' +import { presetUno } from 'unocss' import { presetBlock } from '../src' function cartesian(arr: T[][]): T[][] { @@ -17,13 +18,39 @@ function cartesian(arr: T[][]): T[][] { ) } +function createBlockMatcher(uno: ReturnType) { + const blocked = new Set() + const matchBlocked = async (raw: string) => { + if (blocked.has(raw)) + return + if (uno.isBlocked(raw)) { + blocked.add(raw) + return + } + let current = raw + for (const p of uno.config.preprocess) + current = p(raw)! + const applied = await uno.matchVariants(raw, current) + if (applied && uno.isBlocked(applied[1])) + blocked.add(raw) + } + return async (raw: string, matches: string[]) => { + const extracts = Array.from(await uno.applyExtractors(raw)) + await Promise.all(extracts.map(matchBlocked)) + return matches.every(m => blocked.has(m)) + } +} + describe('presetBlock', () => { const uno = createGenerator({ - presets: [presetBlock({ - ignores: [ - 'w-4px', - ], - })], + presets: [ + presetUno(), + presetBlock({ + ignores: [ + 'w-4px', + ], + }), + ], blocklist: [ /block-\d+/, ], @@ -60,4 +87,10 @@ describe('presetBlock', () => { it('base blocklist', () => { expect(uno.isBlocked('block-1')).toBe(true) }) + + it('match variants', async () => { + const matchBlocked = createBlockMatcher(uno) + const rs = await matchBlocked('!w-100px w-30 p-10 lh-40px', ['!w-100px', 'lh-40px']) + expect(rs).toBe(true) + }) })