Skip to content

Commit

Permalink
Merge branch 'main' into vite-hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Apr 25, 2024
2 parents 6156459 + 47eafba commit 1fb731e
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 154 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "0.59.4",
"private": true,
"packageManager": "pnpm@9.0.2",
"packageManager": "pnpm@9.0.6",
"scripts": {
"postinstall": "esno scripts/prepare.ts",
"taze": "taze minor -wIr && pnpm -r --parallel run update-post",
Expand Down Expand Up @@ -66,6 +66,7 @@
"@unocss/postcss": "workspace:*",
"@unocss/preset-attributify": "workspace:*",
"@unocss/preset-icons": "workspace:*",
"@unocss/preset-legacy-compat": "workspace:*",
"@unocss/preset-mini": "workspace:*",
"@unocss/preset-tagify": "workspace:*",
"@unocss/preset-typography": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/preset-legacy-compat/src/comma-color.ts
@@ -1,10 +1,10 @@
export function toCommaStyleColorFunction(str: string) {
return str.replace(/(rgb|hsl)a?\(([^)]+)\)/g, (_, fn: string, v: string) => {
return str.replace(/((?:rgb|hsl)a?)\(([^)]+)\)/g, (_, fn: string, v: string) => {
const [rgb, alpha] = v.split(/\//g).map(i => i.trim())
if (alpha && !fn.endsWith('a'))
fn += 'a'

const parts = rgb.split(/(?!,)\s+/).map(i => i.trim())
const parts = rgb.split(/,?\s+/).map(i => i.trim())
if (alpha)
parts.push(alpha)

Expand Down
2 changes: 1 addition & 1 deletion packages/shared-integration/src/defaults.ts
Expand Up @@ -16,7 +16,7 @@ export const defaultIdeMatchInclude: RegExp[] = [
// String literals
/(['"`])[^\1]*?\1/g,
// HTML tags
/<[^\/](?:"[^"]*"|'[^"]*'|[^>])+>/g,
/<[^\/?<>0-9$_!](?:"[^"]*"|'[^"]*'|[^>])+>/g,
// CSS directives
/(@apply|--uno|--at-apply)[^;]*?;/g,
]
Expand Down
319 changes: 169 additions & 150 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions test/pos.test.ts
Expand Up @@ -416,6 +416,17 @@ let transition = 'ease-in-out duration-300'
],
]
`)

// #3733, match php <? stuck
expect(await match(uno, `<?php
Route::get('/some-route', [SomeController::class, 'someMethod']);
Route::get('/some-route', [SomeController::class, 'someMethod']);
Route::get('/some-route', [SomeController::class, 'someMethod']);
`, '', {
includeRegex: defaultIdeMatchInclude,
excludeRegex: defaultIdeMatchExclude,
}))
.toMatchInlineSnapshot(`[]`)
})
})

Expand Down
32 changes: 32 additions & 0 deletions test/preset-legacy-compat.test.ts
@@ -0,0 +1,32 @@
import { createGenerator } from '@unocss/core'
import presetLegacyCompat, { type LegacyCompatOptions } from '@unocss/preset-legacy-compat'
import presetUno from '@unocss/preset-uno'
import { describe, expect, it } from 'vitest'

function generateUno(options: LegacyCompatOptions = {}) {
return createGenerator({
presets: [
presetUno(),
presetLegacyCompat(options),
],
})
}

describe('preset-legacy-compat', () => {
it('with commaStyleColorFunction', async () => {
const uno = generateUno({
commaStyleColorFunction: true,
})

const { css } = await uno.generate([
'bg-[rgba(255,255,255,0.1)]',
'text-red',
].join(' '), { preflights: false })

await expect(css).toMatchInlineSnapshot(`
"/* layer: default */
.bg-\\[rgba\\(255\\,255\\,255\\,0\\.1\\)\\]{--un-bg-opacity:0.1;background-color:rgba(255, 255, 255, var(--un-bg-opacity));}
.text-red{--un-text-opacity:1;color:rgba(248, 113, 113, var(--un-text-opacity));}"
`)
})
})
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -25,6 +25,7 @@
"@unocss/preset-mini/variants": ["./packages/preset-mini/src/variants.ts"],
"@unocss/preset-rem-to-px": ["./packages/preset-rem-to-px/src/index.ts"],
"@unocss/preset-tagify": ["./packages/preset-tagify/src/index.ts"],
"@unocss/preset-legacy-compat": ["./packages/preset-legacy-compat/src/index.ts"],
"@unocss/preset-typography": ["./packages/preset-typography/src/index.ts"],
"@unocss/preset-uno": ["./packages/preset-uno/src/index.ts"],
"@unocss/preset-web-fonts": ["./packages/preset-web-fonts/src/index.ts"],
Expand Down

0 comments on commit 1fb731e

Please sign in to comment.