You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@leafer/math

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer/math - npm Package Compare versions

Comparing version
1.8.0
to
1.9.0
+3
-2
package.json
{
"name": "@leafer/math",
"version": "1.8.0",
"version": "1.9.0",
"description": "@leafer/math",

@@ -25,4 +25,5 @@ "author": "Chao (Leafer) Wan",

"devDependencies": {
"@leafer/interface": "1.8.0"
"@leafer/interface": "1.9.0",
"@leafer/data": "1.9.0"
}
}
+3
-1
import { IAround, IPointData, IBoundsData, IUnitPointData } from '@leafer/interface'
import { isString } from '@leafer/data'
import { Direction9 } from './Direction'

@@ -55,3 +57,3 @@

function get(around: IAround): IUnitPointData {
return typeof around === 'string' ? directionData[Direction9[around]] : around
return isString(around) ? directionData[Direction9[around]] : around
}
import { IAutoBounds, IAutoBoundsData, IBounds, ISizeData } from '@leafer/interface'
import { isObject } from '@leafer/data'
import { Bounds } from './Bounds'

@@ -16,3 +18,3 @@

constructor(top?: number | IAutoBoundsData, right?: number, bottom?: number, left?: number, width?: number, height?: number) {
typeof top === 'object' ? this.copy(top) : this.set(top, right, bottom, left, width, height)
isObject(top) ? this.copy(top) : this.set(top, right, bottom, left, width, height)
}

@@ -19,0 +21,0 @@

import { IBounds, IBoundsData, IMatrixData, IPointData, IBoundsDataFn, IObject, IMatrix, IRadiusPointData, IMatrixWithLayoutData, IFourNumber, ISide, IAlign } from '@leafer/interface'
import { isObject } from '@leafer/data'
import { BoundsHelper as B } from './BoundsHelper'

@@ -22,3 +24,3 @@

public set(x?: number | IBoundsData, y?: number, width?: number, height?: number): IBounds {
typeof x === 'object' ? B.copy(this, x) : B.set(this, x, y, width, height)
isObject(x) ? B.copy(this, x) : B.set(this, x, y, width, height)
return this

@@ -25,0 +27,0 @@ }

import { IPointData, IBoundsData, IMatrixData, IFourNumber, IBoundsDataFn, IObject, IMatrix, IOffsetBoundsData, IRadiusPointData, IMatrixWithScaleData, ISide, IAlign, ISizeData } from '@leafer/interface'
import { isArray, isString } from '@leafer/data'
import { Matrix } from './Matrix'

@@ -40,3 +42,3 @@ import { MatrixHelper as M } from './MatrixHelper'

const { x, y, width, height } = bounds
if (spread instanceof Array) {
if (isArray(spread)) {
const four = fourNumber(spread)

@@ -187,3 +189,3 @@ isShrink

to || (to = put as unknown as IPointData)
if (typeof putScale === 'string') putScale = B.getFitScale(t, put, putScale === 'cover')
if (isString(putScale)) putScale = B.getFitScale(t, put, putScale === 'cover')
tempBounds.width = changeSize ? put.width *= putScale : put.width * putScale

@@ -269,3 +271,3 @@ tempBounds.height = changeSize ? put.height *= putScale : put.height * putScale

for (let i = 0, len = list.length; i < len; i++) {
bounds = boundsDataFn ? boundsDataFn(list[i]) : list[i] as IBoundsData
bounds = boundsDataFn ? boundsDataFn(list[i], i) : list[i] as IBoundsData
if (bounds && (bounds.width || bounds.height)) {

@@ -272,0 +274,0 @@ if (first) {

import { IPointData, IBoundsData, IMatrixData, IRangeSize, IScaleData, ISizeData, IOptionSizeData } from '@leafer/interface'
import { isArray, isObject, isNumber, isUndefined } from '@leafer/data'

@@ -8,5 +9,5 @@ const { round, pow, PI } = Math

within(value: number, min: number | IRangeSize, max?: number): number {
if (typeof min === 'object') max = min.max, min = min.min
if (min !== undefined && value < min) value = min
if (max !== undefined && value > max) value = max
if (isObject(min)) max = min.max, min = min.min
if (!isUndefined(min) && value < min) value = min
if (!isUndefined(max) && value > max) value = max
return value

@@ -17,6 +18,6 @@ },

let data: number[]
if (num instanceof Array) {
if (isArray(num)) {
switch (num.length) {
case 4:
data = maxValue === undefined ? num : [...num]
data = isUndefined(maxValue) ? num : [...num]
break

@@ -62,3 +63,3 @@ case 2:

float(num: number, maxLength?: number): number {
const a = maxLength !== undefined ? pow(10, maxLength) : 1000000000000 // default
const a = !isUndefined(maxLength) ? pow(10, maxLength) : 1000000000000 // default
num = round(num * a) / a

@@ -71,3 +72,3 @@ return num === -0 ? 0 : num

if (size) {
const scaleX = (typeof size === 'number' ? size : size.width || 0) / originSize.width, scaleY = (typeof size === 'number' ? size : size.height || 0) / originSize.height
const scaleX = (isNumber(size) ? size : size.width || 0) / originSize.width, scaleY = (isNumber(size) ? size : size.height || 0) / originSize.height
scaleData.scaleX = scaleX || scaleY || 1

@@ -80,3 +81,3 @@ scaleData.scaleY = scaleY || scaleX || 1

assignScale(scaleData: IScaleData, scale: number | IPointData): void {
if (typeof scale === 'number') {
if (isNumber(scale)) {
scaleData.scaleX = scaleData.scaleY = scale

@@ -83,0 +84,0 @@ } else {

import { IMatrix, IMatrixData, IPointData, ILayoutData, IMatrixWithScaleData } from '@leafer/interface'
import { isObject } from '@leafer/data'
import { MatrixHelper as M } from './MatrixHelper'

@@ -22,3 +24,3 @@

public set(a?: number | IMatrixData, b?: number, c?: number, d?: number, e?: number, f?: number): IMatrix {
typeof a === 'object' ? M.copy(this, a) : M.set(this, a, b, c, d, e, f)
isObject(a) ? M.copy(this, a) : M.set(this, a, b, c, d, e, f)
return this

@@ -25,0 +27,0 @@ }

import { IMatrixData, IPointData, ILayoutData, IMatrixWithLayoutData, IMatrixWithOptionScaleData, IScaleData, IMatrixWithScaleData, IScrollPointData } from '@leafer/interface'
import { isUndefined } from '@leafer/data'
import { MathHelper, OneRadian, PI_2, getBoundsData, getMatrixData } from './MathHelper'

@@ -143,3 +145,3 @@

if (abcdChanged === undefined) abcdChanged = t.a !== 1 || t.b || t.c || t.d !== 1
if (isUndefined(abcdChanged)) abcdChanged = t.a !== 1 || t.b || t.c || t.d !== 1

@@ -252,3 +254,3 @@ if (abcdChanged) {

if (bcChanged === undefined) bcChanged = layout.rotation || layout.skewX || layout.skewY
if (isUndefined(bcChanged)) bcChanged = layout.rotation || layout.skewX || layout.skewY

@@ -255,0 +257,0 @@ if (bcChanged) {

import { IPoint, IPointData, IMatrixData } from '@leafer/interface'
import { isObject } from '@leafer/data'
import { PointHelper as P } from './PointHelper'

@@ -14,3 +16,3 @@

public set(x?: number | IPointData, y?: number): IPoint {
typeof x === 'object' ? P.copy(this, x) : P.set(this, x, y)
isObject(x) ? P.copy(this, x) : P.set(this, x, y)
return this

@@ -17,0 +19,0 @@ }

import { IPointData, IMatrixData, IRadiusPointData, IMatrixWithScaleData } from '@leafer/interface'
import { isObject, isUndefined } from '@leafer/data'
import { OneRadian, getPointData } from './MathHelper'
import { MatrixHelper as M } from './MatrixHelper'

@@ -25,3 +26,3 @@

t.radiusX = x
t.radiusY = y === undefined ? x : y
t.radiusY = isUndefined(y) ? x : y
},

@@ -45,3 +46,3 @@

move(t: IPointData, x: number | IPointData, y?: number): void {
if (typeof x === 'object') t.x += x.x, t.y += x.y
if (isObject(x)) t.x += x.x, t.y += x.y
else t.x += x, t.y += y

@@ -147,3 +148,3 @@ },

getRadianFrom(fromX: number, fromY: number, originX: number, originY: number, toX: number, toY: number, toOriginX?: number, toOriginY?: number): number {
if (toOriginX === undefined) toOriginX = originX, toOriginY = originY
if (isUndefined(toOriginX)) toOriginX = originX, toOriginY = originY
const a = fromX - originX

@@ -171,3 +172,3 @@ const b = fromY - originY

let points = originPoints as number[]
if (typeof originPoints[0] === 'object') points = [], (originPoints as IPointData[]).forEach(p => points.push(p.x, p.y))
if (isObject(originPoints[0])) points = [], (originPoints as IPointData[]).forEach(p => points.push(p.x, p.y))
return points

@@ -174,0 +175,0 @@ },