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.6
to
1.0.0-rc.7
+4
-4
package.json
{
"name": "@leafer/layout",
"version": "1.0.0-rc.6",
"version": "1.0.0-rc.7",
"description": "@leafer/layout",

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

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

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

import { ILeaf, ILeafLayout, ILayoutLocationType, ILayoutBoundsType, IBoundsData, IMatrixData } from '@leafer/interface'
import { BoundsHelper } from '@leafer/math'
import { ILeaf, ILeafLayout, ILocationType, IBoundsType, IBoundsData, IMatrixData, ILayoutBoundsData, ILayoutData, IPointData } from '@leafer/interface'
import { Bounds, BoundsHelper, Matrix, MatrixHelper } from '@leafer/math'
import { Platform } from '@leafer/platform'
const { toOuterOf } = BoundsHelper
const { toOuterOf, getPoints } = BoundsHelper

@@ -26,4 +26,4 @@ export class LeafLayout implements ILeafLayout {

public localStrokeBounds: IBoundsData
public localRenderBounds: IBoundsData
public localStrokeBounds?: IBoundsData
public localRenderBounds?: IBoundsData

@@ -37,2 +37,5 @@ // world temp

public resized: boolean
public waitAutoLayout: boolean
// matrix changed

@@ -70,7 +73,15 @@ public matrixChanged: boolean

// temp local
public get a() { return 1 }
public get b() { return 0 }
public get c() { return 0 }
public get d() { return 1 }
public get e() { return this.leaf.__.x }
public get f() { return this.leaf.__.y }
constructor(leaf: ILeaf) {
this.leaf = leaf
this.renderBounds = this.strokeBounds = this.boxBounds = { x: 0, y: 0, width: 0, height: 0 }
this.localRenderBounds = this.localStrokeBounds = leaf.__local
if (leaf.__local) this.localRenderBounds = this.localStrokeBounds = leaf.__local
this.boxChange()

@@ -80,8 +91,7 @@ this.matrixChange()

public checkUpdate(force?: boolean): void {
public update(): void {
const { leafer } = this.leaf
if (leafer) {
if (leafer.ready) {
if ((Platform.realtimeLayout || force) && leafer.watcher.changed) leafer.layouter.layout()
if (leafer.watcher.changed) leafer.layouter.layout()
} else {

@@ -92,3 +102,3 @@ leafer.start()

let root = this.leaf
while (root.parent) { root = root.parent }
while (root.parent && !root.parent.leafer) { root = root.parent }
Platform.layout(root)

@@ -98,57 +108,139 @@ }

public getTransform(locationType: ILayoutLocationType): IMatrixData {
this.checkUpdate()
return locationType === 'world' ? this.leaf.__world : this.leaf.__local
public getTransform(relative: ILocationType | ILeaf = 'world'): IMatrixData {
this.update()
switch (relative) {
case 'world':
return this.leaf.__world
case 'local':
return this.leaf.__localMatrix
case 'inner':
return MatrixHelper.defaultMatrix
default:
return new Matrix(this.leaf.__world).divideParent(relative.__world)
}
}
public getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData {
public getBounds(type?: IBoundsType, relative: ILocationType | ILeaf = 'world'): IBoundsData {
this.update()
switch (relative) {
case 'world':
return this.getWorldBounds(type)
case 'local':
return this.getLocalBounds(type)
case 'inner':
return this.getInnerBounds(type)
default:
return new Bounds(this.getInnerBounds(type)).toOuterOf(this.getTransform(relative))
}
}
this.checkUpdate()
public getInnerBounds(type: IBoundsType = 'box'): IBoundsData {
switch (type) {
case 'render':
return this.renderBounds
case 'content':
if (this.contentBounds) return this.contentBounds
case 'margin':
case 'box':
return this.boxBounds
case 'stroke':
return this.strokeBounds
}
}
if (locationType === 'world') {
public getLocalBounds(type: IBoundsType = 'box'): IBoundsData {
switch (type) {
case 'render':
if (this.localRenderBounds) return this.localRenderBounds
case 'stroke':
if (this.localStrokeBounds) return this.localStrokeBounds
case 'margin':
case 'content':
case 'box':
return this.leaf.__localBounds
}
}
switch (type) {
case 'render':
return this.leaf.__world
case 'content':
if (this.contentBounds) return this.getWorldContentBounds()
case 'margin':
case 'box':
return this.getWorldBoxBounds()
case 'margin':
case 'stroke':
return this.getWorldStrokeBounds()
}
public getWorldBounds(type: IBoundsType = 'box'): IBoundsData {
switch (type) {
case 'render':
return this.leaf.__world
case 'content':
if (this.contentBounds) return this.getWorldContentBounds()
case 'margin':
case 'box':
return this.getWorldBoxBounds()
case 'margin':
case 'stroke':
return this.getWorldStrokeBounds()
}
}
} else if (locationType === 'inner') {
public getLayoutBounds(type?: IBoundsType, relative: ILocationType | ILeaf = 'world', unscale?: boolean): ILayoutBoundsData {
const { leaf } = this
let point: IPointData, layout: ILayoutData
let bounds: IBoundsData = this.getInnerBounds(type)
switch (type) {
case 'render':
return this.renderBounds
case 'content':
if (this.contentBounds) return this.contentBounds
case 'margin':
case 'box':
return this.boxBounds
case 'stroke':
return this.strokeBounds
}
switch (relative) {
case 'world':
point = leaf.getWorldPoint(bounds)
layout = leaf.__world
break
case 'local':
point = leaf.getLocalPointByInner(bounds)
layout = leaf.__ as ILayoutData
break
case 'inner':
point = bounds
layout = MatrixHelper.defaultWorld
break
default:
point = leaf.getWorldPoint(bounds, relative)
layout = leaf.__world
}
} else {
let { scaleX, scaleY, rotation, skewX, skewY } = layout
let { width, height } = bounds
switch (type) {
case 'render':
return this.localRenderBounds
case 'margin':
case 'content':
case 'box':
return this.leaf.__local
case 'stroke':
return this.localStrokeBounds
}
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
}
return { x: point.x, y: point.y, scaleX, scaleY, rotation, skewX, skewY, width, height }
}
public getLayoutPoints(type?: IBoundsType, relative: ILocationType | ILeaf = 'world'): IPointData[] {
const { leaf } = this
const points = getPoints(this.getInnerBounds(type))
let relativeLeaf: ILeaf
switch (relative) {
case 'world':
relativeLeaf = null
break
case 'local':
relativeLeaf = leaf.parent
break
case 'inner':
break
default:
relativeLeaf = relative
}
if (relativeLeaf !== undefined) points.forEach(point => leaf.innerToWorld(point, null, false, relativeLeaf))
return points
}
protected getWorldContentBounds(): IBoundsData {

@@ -177,3 +269,3 @@ this._worldContentBounds || (this._worldContentBounds = {} as IBoundsData)

this.strokeBounds = this.boxBounds
this.localStrokeBounds = this.leaf.__local
this.localStrokeBounds = this.leaf.__localBounds
if (same) this.spreadRenderCancel()

@@ -180,0 +272,0 @@ }

@@ -1,2 +0,2 @@

import { ILeafLayout, ILeaf, IBoundsData, ILayoutLocationType, IMatrixData, ILayoutBoundsType } from '@leafer/interface';
import { ILeafLayout, ILeaf, IBoundsData, ILocationType, IMatrixData, IBoundsType, ILayoutBoundsData, IPointData } from '@leafer/interface';

@@ -11,7 +11,9 @@ declare class LeafLayout implements ILeafLayout {

contentBounds: IBoundsData;
localStrokeBounds: IBoundsData;
localRenderBounds: IBoundsData;
localStrokeBounds?: IBoundsData;
localRenderBounds?: IBoundsData;
protected _worldContentBounds: IBoundsData;
protected _worldBoxBounds: IBoundsData;
protected _worldStrokeBounds: IBoundsData;
resized: boolean;
waitAutoLayout: boolean;
matrixChanged: boolean;

@@ -36,6 +38,17 @@ scaleChanged: boolean;

renderShapeSpread: number;
get a(): number;
get b(): number;
get c(): number;
get d(): number;
get e(): number;
get f(): number;
constructor(leaf: ILeaf);
checkUpdate(force?: boolean): void;
getTransform(locationType: ILayoutLocationType): IMatrixData;
getBounds(type: ILayoutBoundsType, locationType: ILayoutLocationType): IBoundsData;
update(): void;
getTransform(relative?: ILocationType | ILeaf): IMatrixData;
getBounds(type?: IBoundsType, relative?: ILocationType | ILeaf): IBoundsData;
getInnerBounds(type?: IBoundsType): IBoundsData;
getLocalBounds(type?: IBoundsType): IBoundsData;
getWorldBounds(type?: IBoundsType): IBoundsData;
getLayoutBounds(type?: IBoundsType, relative?: ILocationType | ILeaf, unscale?: boolean): ILayoutBoundsData;
getLayoutPoints(type?: IBoundsType, relative?: ILocationType | ILeaf): IPointData[];
protected getWorldContentBounds(): IBoundsData;

@@ -42,0 +55,0 @@ protected getWorldBoxBounds(): IBoundsData;