0.0.161 • Published 3 years ago

soid-ui-util v0.0.161

Weekly downloads
221
License
ISC
Repository
-
Last release
3 years ago

TOC

soid-ui-util

Description

utils for ui render

  • Color 颜色值管理
  • Grid
  • Shadow
  • Operate
  • ColorGradientUtils
  • Size
  • Number

Install

This project uses node and npm.Go check them out if you don`t have them locally installed.

npm install soid-ui-util

Usage

1.Color

颜色值管理

ColorManager 中的方法:

方法说明
fromRgba通过 RGBA 形式的颜色值构建 ColorManager 实例
fromHex通过十六进制形式的颜色值构建 ColorManager 实例
rgba获取 RGBA 格式的颜色值
filter转换颜色值

使用示例

// 导入 ColorManager
import { ColorManager } from 'soid-ui-util';

// 构建 ColorManager
const color = ColorManager.fromHex('#FFB6C1');
const color = ColorManager.fromRgba({red:225,green:182,blue:193,alpha:1});

// 获取 RGBA 颜色值
const rgbaColor = color.rgba;

// 转换颜色值
const filterColor = color.filter;

Grid Service

Use grid service to manage grid info.

Get Dropped GridInfo

After set grid rect / grid row info / grid column info / drop rect, base grid row / column info set dropped info , get dropped grid info

const gridService = ComponentGridManager.getInstance();
const droppedInfo = gridService
  .setWindowSize(1024, 768)
  .setGridRect({
    x: 0,
    y: 0,
    width: 500,
    height: 400
  })
  .setGridRowInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ])
  .setGridColumnInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ])
  .setDroppedInfo({
    id: 'test',
    x: 10,
    y: 10,
    width: {
      value: 20,
      unit: '%'
    },
    height: {
      value: 200,
      unit: 'px'
    },
    gridArea: {
      rowStart: 1,
      columnStart: 1,
      rowEnd: 2,
      columnEnd: 2
    }
  });

if (droppedInfo.needUpdateGridChildren) {
  const childrenGridInfo = gridService.getModifiedChildrenGirdInfo();
}

Update Child Grid Info

update child width / height / margin

const gridService = ComponentGridManager.getInstance();
const isNeedUpdateGridChildren = gridService.updateChildInfoAndGetParentGridChildrenUpdateStatus(
  {
    id: 'test',
    x: 10,
    y: 10,
    width: {
      value: 20,
      unit: '%'
    },
    height: {
      value: 200,
      unit: 'px'
    },
    gridArea: {
      rowStart: 1,
      columnStart: 1,
      rowEnd: 2,
      columnEnd: 2
    }
  }
);

if (isNeedUpdateGridChildren) {
  const childrenGridInfo = gridService.getModifiedChildrenGirdInfo();
}

Delete Child Grid Info

delete child grid

const gridService = ComponentGridManager.getInstance();
const isNeedUpdateGridChildren = gridService.deleteChildByIdAndGetParentGridChildrenUpdateStatus(
  'test'
);

if (isNeedUpdateGridChildren) {
  const childrenGridInfo = gridService.getModifiedChildrenGirdInfo();
}

Update Children Gird Info

After change grid gap \ grid padding \ children info, you can update children grid info.

const gridService = ComponentGridManager.getInstance();
gridService.setGridGap({ value: 10, unit: 'px' }, { value: 10, unit: 'px' });

const childrenGridInfo = gridService.getModifiedChildrenGirdInfo();

Adjust Children Grid Info

After change grid row / column info , you can adjust children grid info.

const gridService = ComponentGridManager.getInstance();
gridService
  .setWindowSize(1024, 768)
  .setGridRect({
    x: 0,
    y: 0,
    width: 500,
    height: 400
  })
  .setGridCount(2, 2)
  .setChildrenGridInfo([
    {
      id: '1234',
      gridArea: [1, 1, 2, 2],
      marginLeft: {
        value: 200,
        unit: 'px'
      },
      marginTop: {
        value: 200,
        unit: 'px'
      },
      width: {
        value: 20,
        unit: '%'
      },
      height: {
        value: 200,
        unit: 'px'
      }
    }
  ])
  .setGridRowInfo([
    {
      value: 20,
      unit: '%'
    }
  ])
  .setParentGridColumnInfo([
    {
      value: 20,
      unit: '%'
    }
  ])
  .adjustChildrenGridInfo();

Get Grid Lines

If you want draw grid lines, you can get grid lines coordinates(eg: { fromX: 0; fromY: 0; toX: 100; toY: 0 }) to draw grid line

const gridService = ComponentGridManager.getInstance();
gridService
  .setWindowSize(1024, 768)
  .setGridRect({
    x: 0,
    y: 0,
    width: 500,
    height: 400
  })
  .setGridRowInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ])
  .setParentGridColumnInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ]);
const gridLineList = gridService.getGridLines();
// draw line in angular eg:
<svg>
  <g>
    <line *ngFor="let line of gridLineList"
          [attr.x1]="line.fromX"
          [attr.x2]="line.toX"
          [attr.y1]="line.fromY"
          [attr.y2]="line.toY"
          [attr.stroke]="'#178df7'"
          [attr.stroke-width]="1"
          [attr.stroke-dasharray]="'4, 1'"></line>
  </g>
</svg>

Get Grid Gap Area And Lines

If you want draw grid gap area and lines, you can get grid gap area rects and lines coordinates(eg: { fromX: 0; fromY: 0; toX: 100; toY: 0 })

const gridService = ComponentGridManager.getInstance();
gridService
  .setWindowSize(1024, 768)
  .setGridRect({
    x: 0,
    y: 0,
    width: 500,
    height: 400
  })
  .setGridRowInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ])
  .setGridColumnInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ]);
const gridGapLines = gridService.getGridGapAreaAndLines(5).lines;
const gridGapArea = gridService.getGridGapAreaAndLines(5).area;
// draw area and line in angular eg:
<line *ngFor="let line of gridGapLines"
          [attr.x1]="line.fromX"
          [attr.x2]="line.toX"
          [attr.y1]="line.fromY"
          [attr.y2]="line.toY"
          [attr.stroke]="'purple'"
          [attr.stroke-width]="0.5"
          [attr.stroke-dasharray]="'3, 2'"></line>

<rect *ngFor="let gapRect of gridGapArea"
          [attr.x]="gapRect.x"
          [attr.y]="gapRect.y"
          [attr.width]="gapRect.width"
          [attr.height]="gapRect.height"
          [attr.fill]="'purple'"
          fill-opacity="0.4"></rect>

Get Grid Padding Area And Lines

If you want draw grid gap area and lines, you can get grid gap area rects and lines coordinates(eg: { fromX: 0; fromY: 0; toX: 100; toY: 0 })

const gridService = ComponentGridManager.getInstance();
gridService
  .setWindowSize(1024, 768)
  .setGridRect({
    x: 0,
    y: 0,
    width: 500,
    height: 400
  })
  .setGridRowInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ])
  .setGridColumnInfo([
    {
      value: 20,
      unit: '%'
    },
    {
      value: 150,
      unit: 'px'
    }
  ])
  .setGridPaddingInfo({
    left: {
      value: 20,
      unit: '%'
    },
    right: {
      value: 20,
      unit: '%'
    },
    top: {
      value: 20,
      unit: '%'
    },
    bottom: {
      value: 20,
      unit: '%'
    }
  });
const gridPaddingLines = gridService.getGridPaddingAreaAndLines(5).lines;
const gridPaddingArea = gridService.getGridPaddingAreaAndLines(5).area;
// draw area and line in angular eg:
<line *ngFor="let line of gridPaddingLines"
          [attr.x1]="line.fromX"
          [attr.x2]="line.toX"
          [attr.y1]="line.fromY"
          [attr.y2]="line.toY"
          [attr.stroke]="'green'"
          [attr.stroke-width]="0.5"
          [attr.stroke-dasharray]="'3, 2'"></line>

<rect *ngFor="let paddingRect of gridPaddingArea"
          [attr.x]="paddingRect.x"
          [attr.y]="paddingRect.y"
          [attr.width]="paddingRect.width"
          [attr.height]="paddingRect.height"
          [attr.fill]="'green'"
          fill-opacity="0.4"></rect>

Assist Line And Align Line

const moveX = 100;
const moveY = 100;
const gridService = ComponentGridManager.getInstance();
gridService.startMovingChildById('testing');
gridService.movingChild({
  x: moveX,
  y: moveY
});

const alignAndAssistLineInfo = gridService.getAlignAndAssistLineInfo();
const { alignLines } = alignAndAssistLineInfo;
const { assistLines } = alignAndAssistLineInfo;
const { assistSigns } = alignAndAssistLineInfo;
const { offset } = alignAndAssistLineInfo;
// draw area and line in angular eg:
<line *ngFor="let line of alignLines"
            [attr.x1]="line.fromX"
            [attr.x2]="line.toX"
            [attr.y1]="line.fromY"
            [attr.y2]="line.toY"
            [attr.stroke]="'red'"
            [attr.stroke-width]="1"
            [attr.stroke-dasharray]="'3, 2'"></line>

<line *ngFor="let line of assistLines"
            [attr.x1]="line.fromX"
            [attr.x2]="line.toX"
            [attr.y1]="line.fromY"
            [attr.y2]="line.toY"
            [attr.stroke]="'white'"
            [attr.stroke-width]="1"
            [attr.stroke-dasharray]="'3, 2'"></line>

<text *ngFor="let sign of assistSigns"
            text-anchor="middle"
            [attr.stroke]="'white'"
            [attr.x]="sign.x"
            [attr.y]="sign.y"
            [attr.font-size]="10">{{sign.sign}}</text>

Operator Service

Use operator service to manage you handle

const operatorService = OperatorService.getInstance();
operatorService.minDistance = 10;
operatorService
  .setPageContainerRectList([
    {
      x: 0,
      y: 0,
      width: 100,
      height: 100
    }
  ])
  .setParentRect({
    x: 50,
    y: 50,
    width: 100,
    height: 100
  })
  .setOperatorSize(50, 20);
const operatorRect = operatorService.getOperatorRect();
0.0.161

3 years ago

0.0.160

3 years ago

0.0.159

3 years ago

0.0.158

3 years ago

0.0.157

3 years ago

0.0.156

3 years ago

0.0.155

3 years ago

0.0.154

3 years ago

0.0.153

3 years ago

0.0.152

3 years ago

0.0.151

3 years ago

0.0.150

3 years ago

0.0.149

3 years ago

0.0.148

3 years ago

0.0.146

3 years ago

0.0.145

3 years ago

0.0.144

3 years ago

0.0.142

3 years ago

0.0.143

3 years ago

0.0.141

3 years ago

0.0.140

3 years ago

0.0.139

3 years ago

0.0.138

3 years ago

0.0.137

3 years ago

0.0.136

3 years ago

0.0.135

3 years ago

0.0.134

3 years ago

0.0.128

3 years ago

0.0.129

3 years ago

0.0.131

3 years ago

0.0.130

3 years ago

0.0.133

3 years ago

0.0.132

3 years ago

0.0.127

3 years ago

0.0.126

3 years ago

0.0.125

3 years ago

0.0.124

3 years ago

0.0.123

3 years ago

0.0.122

3 years ago

0.0.121

3 years ago

0.0.120

3 years ago

0.0.117

3 years ago

0.0.119

3 years ago

0.0.118

3 years ago

0.0.116

3 years ago

0.0.115

3 years ago

0.0.114

3 years ago

0.0.113

3 years ago

0.0.112

3 years ago

0.0.106

3 years ago

0.0.109

3 years ago

0.0.108

3 years ago

0.0.107

3 years ago

0.0.111

3 years ago

0.0.110

3 years ago

0.0.105

3 years ago

0.0.104

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago

0.0.100

3 years ago

0.0.99

3 years ago

0.0.98

3 years ago

0.0.95

3 years ago

0.0.96

3 years ago

0.0.97

3 years ago

0.0.94

3 years ago

0.0.93

3 years ago

0.0.92

3 years ago

0.0.90

3 years ago

0.0.91

3 years ago

0.0.88

3 years ago

0.0.89

3 years ago

0.0.87

3 years ago

0.0.86

3 years ago

0.0.85

3 years ago

0.0.84

3 years ago

0.0.83

3 years ago

0.0.82

3 years ago

0.0.81

3 years ago

0.0.80

3 years ago

0.0.79

3 years ago

0.0.78

3 years ago

0.0.77

3 years ago

0.0.76

3 years ago

0.0.75

3 years ago

0.0.74

3 years ago

0.0.73

3 years ago

0.0.72

3 years ago

0.0.71

3 years ago

0.0.70

3 years ago

0.0.69

3 years ago

0.0.67

3 years ago

0.0.68

3 years ago

0.0.64

3 years ago

0.0.65

3 years ago

0.0.66

3 years ago

0.0.62

3 years ago

0.0.63

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.59

3 years ago

0.0.57

3 years ago

0.0.58

3 years ago

0.0.56

3 years ago

0.0.55

3 years ago

0.0.54

3 years ago

0.0.53

3 years ago

0.0.52

3 years ago

0.0.51

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.48

4 years ago

0.0.43

4 years ago

0.0.44

4 years ago

0.0.45

4 years ago

0.0.46

4 years ago

0.0.47

4 years ago

0.0.40

4 years ago

0.0.41

4 years ago

0.0.42

4 years ago

0.0.37

4 years ago

0.0.38

4 years ago

0.0.39

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.1

4 years ago