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

@leafer/layout

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer/layout - npm Package Compare versions

Comparing version
1.0.0-rc.9
to
1.0.0-rc.10
+5
-5
package.json
{
"name": "@leafer/layout",
"version": "1.0.0-rc.9",
"version": "1.0.0-rc.10",
"description": "@leafer/layout",

@@ -18,3 +18,3 @@ "author": "Chao (Leafer) Wan",

},
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/layout",
"homepage": "https://github.com/leaferjs/leafer/tree/main/packages/display-module/layout",
"bugs": "https://github.com/leaferjs/leafer/issues",

@@ -26,8 +26,8 @@ "keywords": [

"dependencies": {
"@leafer/math": "1.0.0-rc.9",
"@leafer/platform": "1.0.0-rc.9"
"@leafer/math": "1.0.0-rc.10",
"@leafer/platform": "1.0.0-rc.10"
},
"devDependencies": {
"@leafer/interface": "1.0.0-rc.9"
"@leafer/interface": "1.0.0-rc.10"
}
}

@@ -1,7 +0,8 @@

import { ILeaf, ILeafLayout, ILocationType, IBoundsType, IBoundsData, IMatrixData, ILayoutBoundsData, ILayoutData, IPointData } from '@leafer/interface'
import { Bounds, BoundsHelper, Matrix, MatrixHelper } from '@leafer/math'
import { ILeaf, ILeafLayout, ILocationType, IBoundsType, IBoundsData, IMatrixData, ILayoutBoundsData, IPointData } from '@leafer/interface'
import { Bounds, BoundsHelper, Matrix, MatrixHelper, PointHelper } from '@leafer/math'
import { Platform } from '@leafer/platform'
const { toOuterOf, getPoints } = BoundsHelper
const tempMatrix = new Matrix()
const { toOuterOf, getPoints, copy } = BoundsHelper

@@ -14,8 +15,11 @@ export class LeafLayout implements ILeafLayout {

// local
// inner
public boxBounds: IBoundsData
public strokeBounds: IBoundsData
public renderBounds: IBoundsData
public get strokeBounds(): IBoundsData { return this._strokeBounds || this.boxBounds }
public get renderBounds(): IBoundsData { return this._renderBounds || this.boxBounds }
public _strokeBounds: IBoundsData
public _renderBounds: IBoundsData
// auto layout

@@ -27,5 +31,8 @@ public marginBounds: IBoundsData

public localStrokeBounds?: IBoundsData
public localRenderBounds?: IBoundsData
public get localStrokeBounds(): IBoundsData { return this._localStrokeBounds || this }
public get localRenderBounds(): IBoundsData { return this._localRenderBounds || this }
protected _localStrokeBounds?: IBoundsData
protected _localRenderBounds?: IBoundsData
// world temp

@@ -80,2 +87,6 @@ protected _worldContentBounds: IBoundsData

public get f() { return this.leaf.__.y }
public get x() { return this.e + this.boxBounds.x }
public get y() { return this.f + this.boxBounds.y }
public get width() { return this.boxBounds.width }
public get height() { return this.boxBounds.height }

@@ -85,4 +96,4 @@

this.leaf = leaf
this.renderBounds = this.strokeBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
if (leaf.__local) this.localRenderBounds = this.localStrokeBounds = leaf.__local
this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
if (this.leaf.__local) this._localRenderBounds = this._localStrokeBounds = this.leaf.__local
this.boxChange()

@@ -92,2 +103,8 @@ this.matrixChange()

public createLocal(): void {
const local = this.leaf.__local = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, x: 0, y: 0, width: 0, height: 0 }
if (!this._localStrokeBounds) this._localStrokeBounds = local
if (!this._localRenderBounds) this._localRenderBounds = local
}
public update(): void {

@@ -153,9 +170,9 @@ const { leafer } = this.leaf

case 'render':
if (this.localRenderBounds) return this.localRenderBounds
return this.localRenderBounds
case 'stroke':
if (this.localStrokeBounds) return this.localStrokeBounds
return this.localStrokeBounds
case 'margin':
case 'content':
case 'box':
return this.leaf.__localBounds
return this.leaf.__localBoxBounds
}

@@ -181,4 +198,3 @@ }

const { leaf } = this
let point: IPointData, layout: ILayoutData
let bounds: IBoundsData = this.getInnerBounds(type)
let point: IPointData, matrix: IMatrixData, bounds: IBoundsData = this.getInnerBounds(type)

@@ -188,39 +204,34 @@ switch (relative) {

point = leaf.getWorldPoint(bounds)
layout = leaf.__world
matrix = leaf.__world
break
case 'local':
point = leaf.getLocalPointByInner(bounds)
layout = leaf.__ as ILayoutData
matrix = leaf.__localMatrix
break
case 'inner':
point = bounds
layout = MatrixHelper.defaultWorld
matrix = MatrixHelper.defaultMatrix
break
default:
point = leaf.getWorldPoint(bounds, relative)
layout = leaf.__world
matrix = tempMatrix.set(leaf.__world).divideParent(relative.__world)
}
let { scaleX, scaleY, rotation, skewX, skewY } = layout
let { width, height } = bounds
const layoutBounds = MatrixHelper.getLayout(matrix) as ILayoutBoundsData
copy(layoutBounds, bounds)
PointHelper.copy(layoutBounds, point)
if (typeof relative === 'object') {
const r = relative.__world
scaleX /= r.scaleX
scaleY /= r.scaleY
rotation -= r.rotation
skewX -= r.skewX
skewY -= r.skewY
}
if (unscale) {
const uScaleX = scaleX < 0 ? -scaleX : scaleX
const uScaleY = scaleY < 0 ? -scaleY : scaleY
scaleX /= uScaleX
scaleY /= uScaleY
width *= uScaleX
height *= uScaleY
const { scaleX, scaleY } = layoutBounds
const uScaleX = Math.abs(scaleX)
const uScaleY = Math.abs(scaleY)
if (uScaleX !== 1 || uScaleY !== 1) {
layoutBounds.scaleX /= uScaleX
layoutBounds.scaleY /= uScaleY
layoutBounds.width *= uScaleX
layoutBounds.height *= uScaleY
}
}
return { x: point.x, y: point.y, scaleX, scaleY, rotation, skewX, skewY, width, height }
return layoutBounds
}

@@ -270,9 +281,9 @@

const same = this.renderBounds === this.strokeBounds
this.strokeBounds = this.boxBounds
this.localStrokeBounds = this.leaf.__localBounds
this._strokeBounds = this.boxBounds
this._localStrokeBounds = this.leaf.__localBoxBounds
if (same) this.spreadRenderCancel()
}
public spreadRenderCancel(): void {
this.renderBounds = this.strokeBounds
this.localRenderBounds = this.localStrokeBounds
this._renderBounds = this._strokeBounds
this._localRenderBounds = this._localStrokeBounds
}

@@ -282,4 +293,4 @@

const { x, y, width, height } = this.strokeBounds
this.strokeBounds = { x, y, width, height }
this.localStrokeBounds = { x, y, width, height }
this._strokeBounds = { x, y, width, height }
this._localStrokeBounds = { x, y, width, height }
if (!this.renderSpread) this.spreadRenderCancel()

@@ -289,4 +300,4 @@ }

const { x, y, width, height } = this.renderBounds
this.renderBounds = { x, y, width, height }
this.localRenderBounds = { x, y, width, height }
this._renderBounds = { x, y, width, height }
this._localRenderBounds = { x, y, width, height }
}

@@ -338,2 +349,3 @@

this.matrixChange()
if (!this.leaf.__local) this.createLocal()
}

@@ -340,0 +352,0 @@

@@ -7,8 +7,12 @@ import { ILeafLayout, ILeaf, IBoundsData, ILocationType, IMatrixData, IBoundsType, ILayoutBoundsData, IPointData } from '@leafer/interface';

boxBounds: IBoundsData;
strokeBounds: IBoundsData;
renderBounds: IBoundsData;
get strokeBounds(): IBoundsData;
get renderBounds(): IBoundsData;
_strokeBounds: IBoundsData;
_renderBounds: IBoundsData;
marginBounds: IBoundsData;
contentBounds: IBoundsData;
localStrokeBounds?: IBoundsData;
localRenderBounds?: IBoundsData;
get localStrokeBounds(): IBoundsData;
get localRenderBounds(): IBoundsData;
protected _localStrokeBounds?: IBoundsData;
protected _localRenderBounds?: IBoundsData;
protected _worldContentBounds: IBoundsData;

@@ -44,3 +48,8 @@ protected _worldBoxBounds: IBoundsData;

get f(): number;
get x(): number;
get y(): number;
get width(): number;
get height(): number;
constructor(leaf: ILeaf);
createLocal(): void;
update(): void;

@@ -47,0 +56,0 @@ getTransform(relative?: ILocationType | ILeaf): IMatrixData;