@leafer-in/flow 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ import { IBoundsData, IBox, IUI, IPointData, IAxisAlign } from '@leafer-ui/interface'
2
+
3
+ import { PointHelper } from '@leafer-ui/draw'
4
+
5
+ import { IFlowDrawData, IFlowWrapDrawData } from '@leafer-in/interface'
6
+
7
+
8
+ const { move } = PointHelper
9
+
10
+ export function layout(box: IBox, data: IFlowWrapDrawData, rowYAlign?: IAxisAlign, reverse?: boolean): void {
11
+ const { list } = data, reverseWrap = box.__.flowWrap === 'reverse'
12
+ let row: IFlowDrawData, { x, y } = data
13
+
14
+ for (let i = 0, len = list.length; i < len; i++) {
15
+ row = list[reverseWrap ? len - 1 - i : i]
16
+ layoutX(box, row, x, y, rowYAlign, reverse)
17
+ y += row.height + data.gap
18
+ }
19
+ }
20
+
21
+ export function layoutX(box: IBox, row: IFlowDrawData, fromX: number, fromY: number, rowYAlign: IAxisAlign, reverse?: boolean): void {
22
+ const { children } = box
23
+ let child: IUI, local: IBoundsData, { x, start } = row, y = fromY
24
+ x += fromX
25
+
26
+ for (let j = 0, end = row.count; j < end; j++) {
27
+ child = children[reverse ? start - j : start + j]
28
+
29
+ if (child.__.inFlow && child.__.visible !== 0) {
30
+ local = child.__flowBounds
31
+ if (rowYAlign !== 'from') y = fromY + (row.height - local.height) / (rowYAlign === 'center' ? 2 : 1)
32
+
33
+ move(child as IPointData, x - local.x, y - local.y)
34
+ x += local.width + row.gap
35
+ } else {
36
+ end++
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,28 @@
1
+ import { IAxisAlign, IBox, IFlowAlign } from '@leafer-ui/interface'
2
+
3
+ import { IFlowDrawData, IFlowWrapDrawData } from '@leafer-in/interface'
4
+
5
+ import { alignContent, alignToInnerYMap } from '../common/align'
6
+
7
+
8
+ export function align(box: IBox, data: IFlowWrapDrawData, contentAlign: IFlowAlign, rowYAlign: IAxisAlign): void {
9
+ alignContent(box, data, contentAlign)
10
+
11
+ const { list } = data
12
+ if (list.length > 1) {
13
+
14
+ if (!rowYAlign) rowYAlign = alignToInnerYMap[contentAlign]
15
+
16
+ if (rowYAlign !== 'from') {
17
+ let row: IFlowDrawData
18
+
19
+ for (let i = 0, len = list.length; i < len; i++) {
20
+ row = list[i]
21
+ row.y = data.height - row.height
22
+ if (rowYAlign === 'center') row.y /= 2
23
+ }
24
+
25
+ }
26
+ }
27
+ }
28
+
@@ -0,0 +1,59 @@
1
+ import { IBoundsData, IBox, IUI, IAutoSize } from '@leafer-ui/interface'
2
+ import { MathHelper } from '@leafer-ui/draw'
3
+
4
+ import { IFlowDrawData } from '@leafer-in/interface'
5
+
6
+
7
+ const { within } = MathHelper
8
+
9
+ export function growY(box: IBox, row: IFlowDrawData, height: number, reverse: boolean): void {
10
+ let child: IUI, grow: IAutoSize, remainSpace: number, remainTotalSpace = 0, list: IUI[] = row.hasRangeSize && [], { grow: totalGrow, start } = row
11
+ const growSize = row.height < height ? (height - row.height) / totalGrow : 0, { children } = box
12
+
13
+ if (growSize) row.height = height
14
+
15
+ for (let j = 0, end = row.count; j < end; j++) {
16
+ child = children[reverse ? start - j : start + j]
17
+
18
+ if (child.__.inFlow && child.__.visible !== 0) {
19
+
20
+ if (grow = child.__heightGrow) {
21
+ remainSpace = resizeHeight(child, child.__flowBounds, growSize * grow)
22
+
23
+ if (remainSpace) {
24
+ remainTotalSpace += remainSpace
25
+ totalGrow -= grow
26
+ } else if (list) {
27
+ child.__.heightRange ? list.unshift(child) : list.push(child)
28
+ }
29
+ }
30
+
31
+ } else {
32
+ end++
33
+ }
34
+ }
35
+
36
+ if (remainTotalSpace) assignRemainSpace(list, remainTotalSpace, totalGrow)
37
+ }
38
+
39
+
40
+ function assignRemainSpace(list: IUI[], totalSpace: number, countGrow: number): void {
41
+ let grow: IAutoSize, space: number, local: IBoundsData, remain: number
42
+ list.forEach(child => {
43
+ grow = child.__heightGrow
44
+ space = totalSpace / countGrow * grow
45
+ remain = resizeHeight(child, local = child.__flowBounds, local.height + space)
46
+ totalSpace -= space - remain
47
+ countGrow -= grow
48
+ })
49
+ }
50
+
51
+
52
+ export function resizeHeight(child: IUI, local: IBoundsData, size: number): number {
53
+ const { heightRange, lockRatio } = child.__
54
+ const realSize = heightRange ? within(size, heightRange) : size
55
+ const scale = realSize / local.height
56
+ child.scaleResize(lockRatio ? scale : 1, scale)
57
+ local.height = realSize
58
+ return size - realSize
59
+ }
@@ -0,0 +1,38 @@
1
+ import { IBoundsData, IBox, IUI, IPointData, IAxisAlign } from '@leafer-ui/interface'
2
+ import { PointHelper } from '@leafer-ui/draw'
3
+
4
+ import { IFlowDrawData, IFlowWrapDrawData } from '@leafer-in/interface'
5
+
6
+
7
+ const { move } = PointHelper
8
+
9
+ export function layout(box: IBox, data: IFlowWrapDrawData, rowXAlign: IAxisAlign, reverse?: boolean): void {
10
+ const { list } = data, reverseWrap = box.__.flowWrap === 'reverse'
11
+ let row: IFlowDrawData, { x, y } = data
12
+
13
+ for (let i = 0, len = list.length; i < len; i++) {
14
+ row = list[reverseWrap ? len - 1 - i : i]
15
+ layoutY(box, row, x, y, rowXAlign, reverse)
16
+ x += row.width + data.gap
17
+ }
18
+ }
19
+
20
+ export function layoutY(box: IBox, row: IFlowDrawData, fromX: number, fromY: number, rowXAlign: IAxisAlign, reverse?: boolean): void {
21
+ const { children } = box
22
+ let child: IUI, local: IBoundsData, { y, start } = row, x = fromX
23
+ y += fromY
24
+
25
+ for (let j = 0, end = row.count; j < end; j++) {
26
+ child = children[reverse ? start - j : start + j]
27
+
28
+ if (child.__.inFlow && child.__.visible !== 0) {
29
+ local = child.__flowBounds
30
+ if (rowXAlign !== 'from') x = fromX + (row.width - local.width) / (rowXAlign === 'center' ? 2 : 1)
31
+
32
+ move(child as IPointData, x - local.x, y - local.y)
33
+ y += local.height + row.gap
34
+ } else {
35
+ end++
36
+ }
37
+ }
38
+ }