Skip to content

Commit

Permalink
Remove conversion handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Dec 20, 2024
1 parent 3132134 commit fe691a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
16 changes: 0 additions & 16 deletions src/js/css-calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@ export const resolveDimension = (token, opt = {}) => {
pixelValue = dimension[unit];
} else if (typeof dimension.callback === 'function') {
pixelValue = dimension.callback(unit);
} else if (/^(?:ch|lh)$/.test(unit) &&
Object.hasOwnProperty.call(dimension, 'em')) {
const { em } = dimension;
if (unit === 'lh') {
pixelValue = em * 1.2;
} else {
pixelValue = em / 2;
}
} else if (/^(?:rch|rlh)$/.test(unit) &&
Object.hasOwnProperty.call(dimension, 'rem')) {
const { rem } = dimension;
if (unit === 'rlh') {
pixelValue = rem * 1.2;
} else {
pixelValue = rem / 2;
}
}
if (Number.isFinite(pixelValue)) {
res = `${relativeValue * pixelValue}px`;
Expand Down
22 changes: 10 additions & 12 deletions test/css-calc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('resolve dimension', () => {
assert.strictEqual(res, '1200px', 'result');
});

it('should get value', () => {
it('should get null', () => {
const token = [
'dimension-token',
'100ch',
Expand All @@ -165,7 +165,7 @@ describe('resolve dimension', () => {
vw: 10.26
}
});
assert.strictEqual(res, '600px', 'result');
assert.strictEqual(res, null, 'result');
});

it('should get null', () => {
Expand All @@ -191,7 +191,7 @@ describe('resolve dimension', () => {
assert.strictEqual(res, null, 'result');
});

it('should get value', () => {
it('should get null', () => {
const token = [
'dimension-token',
'100lh',
Expand All @@ -204,18 +204,17 @@ describe('resolve dimension', () => {
unit: 'lh'
}
];
let res = func(token, {
const res = func(token, {
dimension: {
em: 12,
rem: 16,
vw: 10.26
}
});
res = `${parseFloat(parseFloat(res).toPrecision(6))}px`;
assert.strictEqual(res, '1440px', 'result');
assert.strictEqual(res, null, 'result');
});

it('should get value', () => {
it('should get null', () => {
const token = [
'dimension-token',
'10rch',
Expand All @@ -235,7 +234,7 @@ describe('resolve dimension', () => {
vw: 10.26
}
});
assert.strictEqual(res, '80px', 'result');
assert.strictEqual(res, null, 'result');
});

it('should get null', () => {
Expand All @@ -261,7 +260,7 @@ describe('resolve dimension', () => {
assert.strictEqual(res, null, 'result');
});

it('should get value', () => {
it('should get null', () => {
const token = [
'dimension-token',
'100rlh',
Expand All @@ -274,15 +273,14 @@ describe('resolve dimension', () => {
unit: 'rlh'
}
];
let res = func(token, {
const res = func(token, {
dimension: {
em: 12,
rem: 16,
vw: 10.26
}
});
res = `${parseFloat(parseFloat(res).toPrecision(6))}px`;
assert.strictEqual(res, '1920px', 'result');
assert.strictEqual(res, null, 'result');
});

it('should get null', () => {
Expand Down

0 comments on commit fe691a0

Please sign in to comment.