diff --git a/packages/griffith-utils/src/__tests__/math.spec.ts b/packages/griffith-utils/src/__tests__/math.spec.ts deleted file mode 100644 index 3e5a78e2..00000000 --- a/packages/griffith-utils/src/__tests__/math.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {getGCD, reduce} from '../math' - -describe('getGCD', () => { - it('should get greatest common divisor', () => { - expect(getGCD(1, 2)).toBe(1) - expect(getGCD(2, 4)).toBe(2) - expect(getGCD(18, 27)).toBe(9) - expect(getGCD(28, 21)).toBe(7) - }) - - it('should always get positive number', () => { - expect(getGCD(18, -27)).toBe(9) - expect(getGCD(-28, 21)).toBe(7) - }) - - it('should return the other one if either param is zero', () => { - expect(getGCD(12345, 0)).toBe(12345) - expect(getGCD(0, 100)).toBe(100) - expect(getGCD(0, 0)).toBe(0) - }) - - it('should throw if either param is not a interger', () => { - expect(() => getGCD(1, 1.234)).toThrow() - expect(() => getGCD(1, Infinity)).toThrow() - expect(() => getGCD(1, NaN)).toThrow() - - expect(() => getGCD(1, 'foo')).toThrow() - expect(() => getGCD(1, {})).toThrow() - - expect(() => getGCD(1, null)).toThrow() - expect(() => getGCD(1, undefined)).toThrow() - }) -}) - -describe('reduce', () => { - it('should reduce two numbers', () => { - expect(reduce(1, 2)).toEqual([1, 2]) - expect(reduce(2, 4)).toEqual([1, 2]) - expect(reduce(18, 27)).toEqual([2, 3]) - expect(reduce(28, 21)).toEqual([4, 3]) - }) - - it('should reduce negetive numbers correctly', () => { - expect(reduce(-2, -4)).toEqual([-1, -2]) - expect(reduce(-18, 27)).toEqual([-2, 3]) - expect(reduce(28, -21)).toEqual([4, -3]) - }) - - it('should thorw if either param is zero', () => { - expect(() => reduce(12345, 0)).toThrow() - expect(() => reduce(0, 100)).toThrow() - expect(() => reduce(0, 0)).toThrow() - }) - - it('should throw if either param is not interger', () => { - expect(() => reduce(1, 1.234)).toThrow() - expect(() => reduce(1, Infinity)).toThrow() - expect(() => reduce(1, NaN)).toThrow() - - expect(() => reduce(1, 'foo')).toThrow() - expect(() => reduce(1, {})).toThrow() - - expect(() => reduce(1, null)).toThrow() - expect(() => reduce(1, undefined)).toThrow() - }) -}) diff --git a/packages/griffith-utils/src/index.ts b/packages/griffith-utils/src/index.ts index 4874aab2..f1b9befd 100644 --- a/packages/griffith-utils/src/index.ts +++ b/packages/griffith-utils/src/index.ts @@ -2,5 +2,4 @@ export {default as logger} from './logger' export {default as ua} from './ua' export {default as isMSESupported} from './isMSESupported' export {default as isHlsNativeSupported} from './isHlsNativeSupported' -export {getGCD, reduce} from './math' export {default as sequence} from './sequence' diff --git a/packages/griffith-utils/src/math.ts b/packages/griffith-utils/src/math.ts deleted file mode 100644 index 652bd1f1..00000000 --- a/packages/griffith-utils/src/math.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 获得最大公约数 - */ -export function getGCD(a: number, b: number): number { - if (!Number.isInteger(a) || !Number.isInteger(b)) { - throw new Error('params must be interger number') - } - if (a === 0) { - return Math.abs(b) - } - if (b === 0) { - return Math.abs(a) - } - return getGCD(b, a % b) -} - -/** - * 约分 - */ -export function reduce(a: number, b: number) { - if (a === 0 || b === 0) { - throw new Error('params must not be zero') - } - const gcd = getGCD(a, b) - return [a / gcd, b / gcd] -} diff --git a/packages/griffith/src/contexts/PositionProvider.tsx b/packages/griffith/src/contexts/PositionProvider.tsx index c072e133..56a29118 100644 --- a/packages/griffith/src/contexts/PositionProvider.tsx +++ b/packages/griffith/src/contexts/PositionProvider.tsx @@ -1,6 +1,5 @@ import React, {useRef, useEffect, useState, useMemo} from 'react' import {css} from 'aphrodite/no-important' -import {reduce} from 'griffith-utils' import useHandler from '../hooks/useHandler' import usePrevious from '../hooks/usePrevious' import listenResize from '../utils/listenResize' @@ -34,8 +33,7 @@ const PositionProvider: React.FC = ({children}) => { if (!videoWidth || !videoHeight) { return } - const [width, height] = reduce(videoWidth, videoHeight) - setHelperImageSrc(createHolderImageSrc(width, height)) + setHelperImageSrc(createHolderImageSrc(videoWidth, videoHeight)) }) const updateIsFullWidth = useHandler(() => {