snail.view 1.0.9 → 1.0.11

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.
@@ -1,5 +1,10 @@
1
1
  import { IScope, IVersionManager } from 'snail.core';
2
2
 
3
+ /**
4
+ * CSS 样式相关属性
5
+ * 1、支持class样式和style样式
6
+ * 2、针对常用style样式做结构封装,值仅封装常用的,若不满足则自己写样式控制
7
+ */
3
8
  /**
4
9
  * CSS管理器
5
10
  */
@@ -20,10 +25,9 @@ interface ICSSManager {
20
25
  /**
21
26
  * 构建样式
22
27
  * @param options 样式配置
23
- * @param isFlex 是否是flex布局
24
28
  * @returns 计算出来的组件样式信息
25
29
  */
26
- buildStyle(options: AllStyle | undefined, isFlex?: boolean): Partial<CSSStyleDeclaration>;
30
+ buildStyle(options: AllStyle): Record<string, string>;
27
31
  }
28
32
  /**
29
33
  * css 样式
@@ -50,52 +54,76 @@ type CSSDescriptor = {
50
54
  * - 高度、宽度、对齐、边框、内边距等合集
51
55
  * - 对齐方式、、、
52
56
  */
53
- type AllStyle = AlignStyle & FlexStyle & HeightStyle & WidthStyle & MarginStyle & BorderStyle & PaddingStyle & TransitionStyle;
57
+ type AllStyle = BaseStyle & FlexBoxStyle & WidthStyle & HeightStyle & MarginStyle & BorderStyle & PaddingStyle & TransitionStyle;
54
58
  /**
55
- * 组件对齐样式
56
- * - flex布局时约束 align-items和 justify-content
57
- * - 非flex布局时约束 text-align和 vertical-align
59
+ * 基础样式:对齐方式、颜色属性
58
60
  */
59
- type AlignStyle = {
61
+ type BaseStyle = {
62
+ /**
63
+ * 文本颜色
64
+ */
65
+ color?: string;
60
66
  /**
61
- * 对齐方式
67
+ * 背景颜色
68
+ */
69
+ backgroundColor?: string;
70
+ /**
71
+ * 文本对齐方式
62
72
  * - left: 左对齐
63
73
  * - center: 居中对齐
64
74
  * - right: 右对齐
65
75
  */
66
- align?: "left" | "center" | "right";
76
+ textAlign?: "left" | "center" | "right";
67
77
  /**
68
78
  * 垂直对齐方式
69
79
  * - top: 顶部对齐
70
80
  * - middle: 居中对齐
71
81
  * - bottom: 底部对齐
72
82
  */
73
- valign?: "top" | "middle" | "bottom";
83
+ verticalAlign?: "top" | "middle" | "bottom";
74
84
  };
75
85
  /**
76
- * 主轴弹性样式
86
+ * 弹性盒子样式
87
+ * - Flex Container
88
+ * - Flex Item
77
89
  */
78
- type FlexStyle = {
90
+ type FlexBoxStyle = {
91
+ /**
92
+ * 项目主轴方向对齐方式
93
+ * - 取值较多,先列举常用的
94
+ */
95
+ justifyContent?: "start" | "center" | "end" | "space-between" | "space-around" | "space-evenly" | "stretch";
96
+ /**
97
+ * 项目交叉轴方向对齐方式
98
+ * - 取值较多,先列举常用的
99
+ */
100
+ alignItems?: "start" | "center" | "end";
79
101
  /**
80
102
  * 弹性置
81
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex
82
103
  */
83
104
  flex?: string;
84
105
  /**
85
106
  * 主轴初始大小
86
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex-basis
87
107
  */
88
108
  flexBasis?: string;
89
109
  /**
90
110
  * 主轴放大系数
91
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex-grow
92
111
  */
93
- flexGrow?: number | "inherit" | "initial" | "revert" | "unset";
112
+ flexGrow?: number;
94
113
  /**
95
114
  * 主轴收缩规则
96
- * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/flex-shrink
97
115
  */
98
- flexShrink?: number | "inherit" | "initial" | "unset";
116
+ flexShrink?: number;
117
+ /**
118
+ * 项目的排列顺序。数值越小,排列越靠前
119
+ */
120
+ order?: number;
121
+ /**
122
+ * 项目在交叉轴方向的对齐方式
123
+ * - 自定义,独立与容器指定的 alignItems
124
+ * - 取值较多,先列举常用的
125
+ */
126
+ alignSelf?: "start" | "center" | "end";
99
127
  };
100
128
  /**
101
129
  * 宽度样式
@@ -470,4 +498,4 @@ type ElementSize = {
470
498
  declare function useObserver(): IObserver & IScope;
471
499
 
472
500
  export { configLink, css, link, linkMap, useAnimation, useLink, useObserver };
473
- export type { AlignStyle, AllStyle, BorderStyle, CSS, CSSDescriptor, ElementSize, FlexStyle, HeightStyle, IAnimationManager, ICSSManager, ILinkManager, IObserver, LinkElement, LinkFile, LinkOptions, MarginStyle, PaddingStyle, TransitionEffectOptions, TransitionStyle, WidthStyle };
501
+ export type { AllStyle, BaseStyle, BorderStyle, CSS, CSSDescriptor, ElementSize, FlexBoxStyle, HeightStyle, IAnimationManager, ICSSManager, ILinkManager, IObserver, LinkElement, LinkFile, LinkOptions, MarginStyle, PaddingStyle, TransitionEffectOptions, TransitionStyle, WidthStyle };
@@ -7,85 +7,6 @@ function getAnimationScope(manager, el) {
7
7
  return useKeyScope(el, false).scope;
8
8
  }
9
9
 
10
- function buildAlign(style, align, isFlex) {
11
- if (isFlex == true) {
12
- const map = {
13
- "left": "start",
14
- "center": "center",
15
- "right": "end",
16
- "top": "start",
17
- "middle": "center",
18
- "bottom": "end"
19
- };
20
- const aV = map[align.align],
21
- vaV = map[align.valign];
22
- aV && (style.justifyContent = aV);
23
- vaV && (style.alignItems = vaV);
24
- } else {
25
- align.align && (style.textAlign = align.align);
26
- align.valign && (style.verticalAlign = align.valign);
27
- }
28
- }
29
- function buildFlex(style, flex) {
30
- if (flex) {
31
- flex.flex && (style.flex = flex.flex);
32
- flex.flexBasis && (style.flexBasis = flex.flexBasis);
33
- flex.flexGrow && (style.flexGrow = String(flex.flexGrow));
34
- flex.flexShrink && (style.flexShrink = String(flex.flexShrink));
35
- }
36
- }
37
- function buildWidth(style, width) {
38
- if (width) {
39
- width.width && (style.width = width.width);
40
- width.minWidth && (style.minWidth = width.minWidth);
41
- width.maxWidth && (style.maxWidth = width.maxWidth);
42
- }
43
- }
44
- function buildHeight(style, height) {
45
- if (height) {
46
- height.height && (style.height = height.height);
47
- height.minHeight && (style.minHeight = height.minHeight);
48
- height.maxHeight && (style.maxHeight = height.maxHeight);
49
- }
50
- }
51
- function buildMargin(style, margin) {
52
- if (margin) {
53
- margin.margin && (style.margin = margin.margin);
54
- margin.marginTop && (style.marginTop = margin.marginTop);
55
- margin.marginRight && (style.marginRight = margin.marginRight);
56
- margin.marginBottom && (style.marginBottom = margin.marginBottom);
57
- margin.marginLeft && (style.marginLeft = margin.marginLeft);
58
- }
59
- }
60
- function buildBorder(style, border) {
61
- if (border) {
62
- border.borderRadius && (style.borderRadius = border.borderRadius);
63
- border.border && (style.border = border.border);
64
- border.borderTop && (style.borderTop = border.borderTop);
65
- border.borderRight && (style.borderRight = border.borderRight);
66
- border.borderBottom && (style.borderBottom = border.borderBottom);
67
- border.borderLeft && (style.borderLeft = border.borderLeft);
68
- }
69
- }
70
- function buildPadding(style, padding) {
71
- if (padding) {
72
- padding.padding && (style.padding = padding.padding);
73
- padding.paddingTop && (style.paddingTop = padding.paddingTop);
74
- padding.paddingRight && (style.paddingRight = padding.paddingRight);
75
- padding.paddingBottom && (style.paddingBottom = padding.paddingBottom);
76
- padding.paddingLeft && (style.paddingLeft = padding.paddingLeft);
77
- }
78
- }
79
- function buildTransition(style, transition) {
80
- if (transition) {
81
- transition.transition && (style.transition = transition.transition);
82
- transition.transitionProperty && (style.transitionProperty = transition.transitionProperty);
83
- transition.transitionDuration && (style.transitionDuration = transition.transitionDuration);
84
- transition.transitionDelay && (style.transitionDelay = transition.transitionDelay);
85
- transition.transitionTimingFunction && (style.transitionTimingFunction = transition.transitionTimingFunction);
86
- }
87
- }
88
-
89
10
  function useCSS() {
90
11
  function parse(css2) {
91
12
  if (isStringNotEmpty(css2) == true) {
@@ -110,17 +31,55 @@ function useCSS() {
110
31
  css2 && isArrayNotEmpty(css2.class) && css2.class.forEach(name => type == "add" ? el.classList.add(name) : el.classList.remove(name));
111
32
  css2 && css2.style && Object.keys(css2.style).forEach(key => type == "add" ? el.style.setProperty(key, css2.style[key]) : el.style.removeProperty(key));
112
33
  }
113
- function buildStyle(options, isFlex) {
34
+ function buildStyle(options) {
114
35
  const style = Object.create(null);
115
- if (options) {
116
- buildAlign(style, options, isFlex);
117
- isFlex && buildFlex(style, options);
118
- buildWidth(style, options);
119
- buildHeight(style, options);
120
- buildMargin(style, options);
121
- buildBorder(style, options);
122
- buildPadding(style, options);
123
- buildTransition(style, options);
36
+ if (!!!options) {
37
+ return style;
38
+ }
39
+ {
40
+ options.color && (style.color = options.color);
41
+ options.backgroundColor && (style.backgroundColor = options.backgroundColor);
42
+ options.textAlign && (style.textAlign = options.textAlign);
43
+ options.verticalAlign && (style.verticalAlign = options.verticalAlign);
44
+ options.justifyContent && (style.justifyContent = options.justifyContent);
45
+ options.alignItems && (style.alignItems = options.alignItems);
46
+ options.flex && (style.flex = options.flex);
47
+ options.flexBasis && (style.flexBasis = options.flexBasis);
48
+ options.flexGrow > 0 && (style.flexGrow = String(options.flexGrow));
49
+ options.flexShrink > 0 && (style.flexShrink = String(options.flexShrink));
50
+ options.order > 0 && (style.order = String(options.order));
51
+ options.alignSelf && (style.alignSelf = options.alignSelf);
52
+ }
53
+ {
54
+ options.width && (style.width = options.width);
55
+ options.minWidth && (style.minWidth = options.minWidth);
56
+ options.maxWidth && (style.maxWidth = options.maxWidth);
57
+ options.height && (style.height = options.height);
58
+ options.minHeight && (style.minHeight = options.minHeight);
59
+ options.maxHeight && (style.maxHeight = options.maxHeight);
60
+ options.margin && (style.margin = options.margin);
61
+ options.marginTop && (style.marginTop = options.marginTop);
62
+ options.marginRight && (style.marginRight = options.marginRight);
63
+ options.marginBottom && (style.marginBottom = options.marginBottom);
64
+ options.marginLeft && (style.marginLeft = options.marginLeft);
65
+ options.borderRadius && (style.borderRadius = options.borderRadius);
66
+ options.border && (style.border = options.border);
67
+ options.borderTop && (style.borderTop = options.borderTop);
68
+ options.borderRight && (style.borderRight = options.borderRight);
69
+ options.borderBottom && (style.borderBottom = options.borderBottom);
70
+ options.borderLeft && (style.borderLeft = options.borderLeft);
71
+ options.padding && (style.padding = options.padding);
72
+ options.paddingTop && (style.paddingTop = options.paddingTop);
73
+ options.paddingRight && (style.paddingRight = options.paddingRight);
74
+ options.paddingBottom && (style.paddingBottom = options.paddingBottom);
75
+ options.paddingLeft && (style.paddingLeft = options.paddingLeft);
76
+ }
77
+ {
78
+ options.transition && (style.transition = options.transition);
79
+ options.transitionProperty && (style.transitionProperty = options.transitionProperty);
80
+ options.transitionDuration && (style.transitionDuration = options.transitionDuration);
81
+ options.transitionDelay && (style.transitionDelay = options.transitionDelay);
82
+ options.transitionTimingFunction && (style.transitionTimingFunction = options.transitionTimingFunction);
124
83
  }
125
84
  return style;
126
85
  }
@@ -11,85 +11,6 @@
11
11
  return snail_core.useKeyScope(el, false).scope;
12
12
  }
13
13
 
14
- function buildAlign(style, align, isFlex) {
15
- if (isFlex == true) {
16
- const map = {
17
- "left": "start",
18
- "center": "center",
19
- "right": "end",
20
- "top": "start",
21
- "middle": "center",
22
- "bottom": "end"
23
- };
24
- const aV = map[align.align],
25
- vaV = map[align.valign];
26
- aV && (style.justifyContent = aV);
27
- vaV && (style.alignItems = vaV);
28
- } else {
29
- align.align && (style.textAlign = align.align);
30
- align.valign && (style.verticalAlign = align.valign);
31
- }
32
- }
33
- function buildFlex(style, flex) {
34
- if (flex) {
35
- flex.flex && (style.flex = flex.flex);
36
- flex.flexBasis && (style.flexBasis = flex.flexBasis);
37
- flex.flexGrow && (style.flexGrow = String(flex.flexGrow));
38
- flex.flexShrink && (style.flexShrink = String(flex.flexShrink));
39
- }
40
- }
41
- function buildWidth(style, width) {
42
- if (width) {
43
- width.width && (style.width = width.width);
44
- width.minWidth && (style.minWidth = width.minWidth);
45
- width.maxWidth && (style.maxWidth = width.maxWidth);
46
- }
47
- }
48
- function buildHeight(style, height) {
49
- if (height) {
50
- height.height && (style.height = height.height);
51
- height.minHeight && (style.minHeight = height.minHeight);
52
- height.maxHeight && (style.maxHeight = height.maxHeight);
53
- }
54
- }
55
- function buildMargin(style, margin) {
56
- if (margin) {
57
- margin.margin && (style.margin = margin.margin);
58
- margin.marginTop && (style.marginTop = margin.marginTop);
59
- margin.marginRight && (style.marginRight = margin.marginRight);
60
- margin.marginBottom && (style.marginBottom = margin.marginBottom);
61
- margin.marginLeft && (style.marginLeft = margin.marginLeft);
62
- }
63
- }
64
- function buildBorder(style, border) {
65
- if (border) {
66
- border.borderRadius && (style.borderRadius = border.borderRadius);
67
- border.border && (style.border = border.border);
68
- border.borderTop && (style.borderTop = border.borderTop);
69
- border.borderRight && (style.borderRight = border.borderRight);
70
- border.borderBottom && (style.borderBottom = border.borderBottom);
71
- border.borderLeft && (style.borderLeft = border.borderLeft);
72
- }
73
- }
74
- function buildPadding(style, padding) {
75
- if (padding) {
76
- padding.padding && (style.padding = padding.padding);
77
- padding.paddingTop && (style.paddingTop = padding.paddingTop);
78
- padding.paddingRight && (style.paddingRight = padding.paddingRight);
79
- padding.paddingBottom && (style.paddingBottom = padding.paddingBottom);
80
- padding.paddingLeft && (style.paddingLeft = padding.paddingLeft);
81
- }
82
- }
83
- function buildTransition(style, transition) {
84
- if (transition) {
85
- transition.transition && (style.transition = transition.transition);
86
- transition.transitionProperty && (style.transitionProperty = transition.transitionProperty);
87
- transition.transitionDuration && (style.transitionDuration = transition.transitionDuration);
88
- transition.transitionDelay && (style.transitionDelay = transition.transitionDelay);
89
- transition.transitionTimingFunction && (style.transitionTimingFunction = transition.transitionTimingFunction);
90
- }
91
- }
92
-
93
14
  function useCSS() {
94
15
  function parse(css2) {
95
16
  if (snail_core.isStringNotEmpty(css2) == true) {
@@ -114,17 +35,55 @@
114
35
  css2 && snail_core.isArrayNotEmpty(css2.class) && css2.class.forEach(name => type == "add" ? el.classList.add(name) : el.classList.remove(name));
115
36
  css2 && css2.style && Object.keys(css2.style).forEach(key => type == "add" ? el.style.setProperty(key, css2.style[key]) : el.style.removeProperty(key));
116
37
  }
117
- function buildStyle(options, isFlex) {
38
+ function buildStyle(options) {
118
39
  const style = Object.create(null);
119
- if (options) {
120
- buildAlign(style, options, isFlex);
121
- isFlex && buildFlex(style, options);
122
- buildWidth(style, options);
123
- buildHeight(style, options);
124
- buildMargin(style, options);
125
- buildBorder(style, options);
126
- buildPadding(style, options);
127
- buildTransition(style, options);
40
+ if (!!!options) {
41
+ return style;
42
+ }
43
+ {
44
+ options.color && (style.color = options.color);
45
+ options.backgroundColor && (style.backgroundColor = options.backgroundColor);
46
+ options.textAlign && (style.textAlign = options.textAlign);
47
+ options.verticalAlign && (style.verticalAlign = options.verticalAlign);
48
+ options.justifyContent && (style.justifyContent = options.justifyContent);
49
+ options.alignItems && (style.alignItems = options.alignItems);
50
+ options.flex && (style.flex = options.flex);
51
+ options.flexBasis && (style.flexBasis = options.flexBasis);
52
+ options.flexGrow > 0 && (style.flexGrow = String(options.flexGrow));
53
+ options.flexShrink > 0 && (style.flexShrink = String(options.flexShrink));
54
+ options.order > 0 && (style.order = String(options.order));
55
+ options.alignSelf && (style.alignSelf = options.alignSelf);
56
+ }
57
+ {
58
+ options.width && (style.width = options.width);
59
+ options.minWidth && (style.minWidth = options.minWidth);
60
+ options.maxWidth && (style.maxWidth = options.maxWidth);
61
+ options.height && (style.height = options.height);
62
+ options.minHeight && (style.minHeight = options.minHeight);
63
+ options.maxHeight && (style.maxHeight = options.maxHeight);
64
+ options.margin && (style.margin = options.margin);
65
+ options.marginTop && (style.marginTop = options.marginTop);
66
+ options.marginRight && (style.marginRight = options.marginRight);
67
+ options.marginBottom && (style.marginBottom = options.marginBottom);
68
+ options.marginLeft && (style.marginLeft = options.marginLeft);
69
+ options.borderRadius && (style.borderRadius = options.borderRadius);
70
+ options.border && (style.border = options.border);
71
+ options.borderTop && (style.borderTop = options.borderTop);
72
+ options.borderRight && (style.borderRight = options.borderRight);
73
+ options.borderBottom && (style.borderBottom = options.borderBottom);
74
+ options.borderLeft && (style.borderLeft = options.borderLeft);
75
+ options.padding && (style.padding = options.padding);
76
+ options.paddingTop && (style.paddingTop = options.paddingTop);
77
+ options.paddingRight && (style.paddingRight = options.paddingRight);
78
+ options.paddingBottom && (style.paddingBottom = options.paddingBottom);
79
+ options.paddingLeft && (style.paddingLeft = options.paddingLeft);
80
+ }
81
+ {
82
+ options.transition && (style.transition = options.transition);
83
+ options.transitionProperty && (style.transitionProperty = options.transitionProperty);
84
+ options.transitionDuration && (style.transitionDuration = options.transitionDuration);
85
+ options.transitionDelay && (style.transitionDelay = options.transitionDelay);
86
+ options.transitionTimingFunction && (style.transitionTimingFunction = options.transitionTimingFunction);
128
87
  }
129
88
  return style;
130
89
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "对视图界面做的一些封装。如样式计算助手方法,常用样式less混入、变量等;dom相关助手类",
4
4
  "author": "snail_dev@163.com",
5
5
  "license": "MIT",
6
- "version": "1.0.9",
6
+ "version": "1.0.11",
7
7
  "type": "module",
8
8
  "main": "dist/snail.view.js",
9
9
  "module": "dist/snail.view.js",