Skip to content

Commit 6704ec0

Browse files
committed
fix: handle negative
1 parent d30ba3b commit 6704ec0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface DynamicPixelOptions {
2828
}
2929

3030
const UNIT = 'px'
31-
const UNIT_REGEXP = new RegExp(`"[^"]+"|'[^']+'|url\\([^\\)]+\\)|(\\d*\\.?\\d+)${UNIT}`, 'g')
31+
const UNIT_REGEXP = new RegExp(`"[^"]+"|'[^']+'|url\\([^\\)]+\\)|(\\-?\\d*\\.?\\d+)${UNIT}`, 'g')
3232

3333
const DEFAULT_IDEAL_VIEWPORT_WIDTH = 1920
3434
const DEFAULT_CURRENT_VIEWPORT_WIDTH = 100

test/index.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,19 @@ describe('should all pass 😄', () => {
9595
const result = await postcss([dynamicPixel()]).process(``)
9696
expect(result.css).toEqual('')
9797
})
98+
99+
it('minus postion', async () => {
100+
const result = await postcss([dynamicPixel()]).process(`.simple-class { postion: absolute; top: -50px;}`)
101+
expect(result.css).toEqual('.simple-class { postion: absolute; top: calc( -50 * (clamp(768px, 100vw, 2560px) / 1920) );}')
102+
})
103+
104+
it('minus box-shadow', async () => {
105+
const result = await postcss([dynamicPixel()]).process(`.simple-class {box-shadow: 60px -16px teal;}`)
106+
expect(result.css).toEqual('.simple-class {box-shadow: calc( 60 * (clamp(768px, 100vw, 2560px) / 1920) ) calc( -16 * (clamp(768px, 100vw, 2560px) / 1920) ) teal;}')
107+
})
108+
109+
it('minus with calc', async () => {
110+
const result = await postcss([dynamicPixel()]).process(`.simple-class { font-size: calc( 16 - 1px ); }`)
111+
expect(result.css).toEqual('.simple-class { font-size: calc( 16 - calc( 1 * (clamp(768px, 100vw, 2560px) / 1920) ) ); }')
112+
})
98113
})

0 commit comments

Comments
 (0)