@nopon-web/styles 0.0.51 → 0.1.0

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.
package/_config.scss CHANGED
@@ -3,5 +3,7 @@ $common-separator: "-" !default;
3
3
  $element-separator: "__" !default;
4
4
  $modifier-separator: "--" !default;
5
5
  $state-prefix: "is" !default;
6
+
6
7
  $theme-prefix: "theme" !default;
7
8
  $theme-name: "" !default;
9
+ $theme-font-prefix: "text" !default;
package/_variables.scss CHANGED
@@ -1,9 +1,42 @@
1
- // 🔤 尺寸基准值,控制设计稿与真实页面的缩放比例
1
+ // 尺寸模式(rem/vw)
2
+ $size-mode: rem !default;
3
+
4
+ // 尺寸基准(16 = 1rem 基准)
2
5
  $size-root: 16 !default;
3
- // 🔤 最小单位:等效于 1px:
4
- // - 当使用 rem 方案:1px = calc(1 / var(--size-root) * 1rem)
5
- // - 当使用 vw 方案:1px = calc(1 / var(--size-root) * 100vw)
6
- $size-unit: calc(1 / var(--size-root) * 1rem) !default;
6
+
7
+ // 字号基准(md 等级)
8
+ $text-base: 16 !default;
9
+
10
+ // 字号比例阶梯(基于 md = 1)
11
+ // lv < 0: small
12
+ // lv = 0: medium
13
+ // lv > 0: large
14
+ //
15
+ // 设计参考: https://tailwindcss.com/docs/font-size
16
+ // 参考标准: https://developer.mozilla.org/en-US/docs/Web/CSS/font-size#values
17
+ $text-scale: (
18
+ -7: (ratio: 0.125, token: 6xs),
19
+ -6: (ratio: 0.25, token: 5xs),
20
+ -5: (ratio: 0.375, token: 4xs),
21
+ -4: (ratio: 0.5, token: 3xs),
22
+ -3: (ratio: 0.625, token: 2xs),
23
+ -2: (ratio: 0.75, token: xs),
24
+ -1: (ratio: 0.875, token: sm),
25
+ 0: (ratio: 1, token: md),
26
+ 1: (ratio: 1.125, token: lg),
27
+ 2: (ratio: 1.25, token: xl),
28
+ 3: (ratio: 1.5, token: 2xl),
29
+ 4: (ratio: 1.875, token: 3xl),
30
+ 5: (ratio: 2.25, token: 4xl),
31
+ 6: (ratio: 3, token: 5xl),
32
+ 7: (ratio: 3.75, token: 6xl),
33
+ 8: (ratio: 4.5, token: 7xl),
34
+ 9: (ratio: 6, token: 8xl),
35
+ 10: (ratio: 8, token: 9xl)
36
+ );
37
+
38
+ // 判断是否应用了主题包, 从而确定是否注册了 theme-vars
39
+ $theme-applied: false !default;
7
40
 
8
41
  // 层级
9
- $z-index-base: 1000;
42
+ $z-index-base: 1000;
@@ -0,0 +1,35 @@
1
+ @use "../mixin/index" as mx;
2
+
3
+ $flex: (
4
+ 1: 1 1 0%,
5
+ auto: 1 1 auto,
6
+ initial: 0 1 auto,
7
+ none: none,
8
+ );
9
+
10
+ $flex-justify: (
11
+ normal: normal,
12
+ start: flex-start,
13
+ end: flex-end,
14
+ center: center,
15
+ between: space-between,
16
+ around: space-around,
17
+ evenly: space-evenly,
18
+ stretch: stretch,
19
+ );
20
+
21
+ $flex-align: (
22
+ start: flex-start,
23
+ end: flex-end,
24
+ center: center,
25
+ baseline: baseline,
26
+ stretch: stretch,
27
+ );
28
+
29
+ .flex {
30
+ display: flex;
31
+ }
32
+
33
+ @include mx.generate-atomic("flex", flex, $flex);
34
+ @include mx.generate-atomic("justify", justify-content, $flex-justify);
35
+ @include mx.generate-atomic("items", align-items, $flex-align);
@@ -0,0 +1 @@
1
+ @use "./flex";
@@ -1,4 +1,5 @@
1
- @use "../mixin" as *;
1
+ @use "../function/index" as fn;
2
+ @use "../mixin/index" as mx;
2
3
 
3
4
  @keyframes like-floating {
4
5
  from {
@@ -10,8 +11,8 @@
10
11
  }
11
12
  }
12
13
 
13
- @include b(animation) {
14
- &.#{join-class("like", "floating")} {
14
+ @include mx.b(animation) {
15
+ &.#{fn.join-class("like", "floating")} {
15
16
  animation-name: like-floating;
16
17
  animation-duration: 1s;
17
18
  animation-timing-function: ease-out;
@@ -1,32 +1,33 @@
1
- @use "../mixin" as *;
1
+ @use "../function/index" as fn;
2
+ @use "../mixin/index" as mx;
2
3
 
3
- @include b(popup) {
4
- &.#{bem(dialog)} {
4
+ @include mx.b(popup) {
5
+ &.#{fn.bem(dialog)} {
5
6
  --popup-padding: 0;
6
7
  --popup-width: var(--dialog-width, 50%);
7
8
  }
8
9
  }
9
10
 
10
- @include b(dialog) {
11
+ @include mx.b(dialog) {
11
12
  --dialog-width: 30%;
12
- --dialog-padding-header: #{u(10)};
13
- --dialog-padding-body: #{u(15)};
14
- --dialog-padding-footer: #{u(10)};
13
+ --dialog-padding-header: #{fn.u(10)};
14
+ --dialog-padding-body: #{fn.u(15)};
15
+ --dialog-padding-footer: #{fn.u(10)};
15
16
 
16
- @include e(header) {
17
+ @include mx.e(header) {
17
18
  padding: var(--dialog-padding-header);
18
19
 
19
- @include m(title) {
20
+ @include mx.m(title) {
20
21
  font-size: var(--text-lg);
21
22
  }
22
23
  }
23
24
 
24
- @include e(body) {
25
+ @include mx.e(body) {
25
26
  padding: var(--dialog-padding-body);
26
27
  overflow: hidden;
27
28
  }
28
29
 
29
- @include e(footer) {
30
+ @include mx.e(footer) {
30
31
  padding: var(--dialog-padding-footer);
31
32
  }
32
33
  }
@@ -1,4 +1,5 @@
1
- @use "../mixin" as *;
1
+ @use "../function/index" as fn;
2
+ @use "../mixin/index" as mx;
2
3
 
3
4
  /*!
4
5
  Example HTML:
@@ -17,42 +18,42 @@ Example HTML:
17
18
  </div>
18
19
  */
19
20
 
20
- @include b(join-class("frame", "box")) {
21
+ @include mx.b(fn.join-class("frame", "box")) {
21
22
  position: relative;
22
23
  box-sizing: border-box;
23
24
  font-size: 0;
24
25
 
25
- @include e(bg) {
26
+ @include mx.e(bg) {
26
27
  width: 100%;
27
28
  height: 100%;
28
- @include absolute-center(true, true);
29
+ @include mx.absolute-center(true, true);
29
30
  z-index: 0;
30
31
  pointer-events: none;
31
32
  }
32
33
 
33
- @include e(wrapper) {
34
+ @include mx.e(wrapper) {
34
35
  position: relative;
35
36
  z-index: 1;
36
37
  margin: 0 auto;
37
38
  }
38
39
 
39
- @include e(frame) {
40
+ @include mx.e(frame) {
40
41
  width: 100%;
41
42
  height: 100%;
42
- @include absolute-center(true, true);
43
+ @include mx.absolute-center(true, true);
43
44
  z-index: 2;
44
45
  pointer-events: none;
45
46
  }
46
47
 
47
- @include e(header) {
48
- @include absolute-center(true, false);
48
+ @include mx.e(header) {
49
+ @include mx.absolute-center(true, false);
49
50
  top: 0;
50
51
  z-index: 3;
51
52
  display: flex;
52
53
  justify-content: center;
53
54
  align-items: center;
54
55
 
55
- @include m(title) {
56
+ @include mx.m(title) {
56
57
  white-space: nowrap;
57
58
  }
58
59
  }
@@ -1,23 +1,23 @@
1
- // 布局网格
2
- @use "../mixin" as *;
1
+ @use "../function/index" as fn;
2
+ @use "../mixin/index" as mx;
3
3
 
4
- @include b("grid") {
4
+ @include mx.b("grid") {
5
5
  --col: 4;
6
- --gap: #{u(0)};
6
+ --gap: #{fn.u(0)};
7
7
  --display: grid;
8
8
  display: var(--display);
9
9
 
10
10
  /* ========= grid 布局 ========= */
11
- @include when("grid") {
11
+ @include mx.when("grid") {
12
12
  --display: grid;
13
13
  gap: var(--gap);
14
14
 
15
15
  // 换行
16
- @include when("wrap") {
16
+ @include mx.when("wrap") {
17
17
  grid-template-columns: repeat(var(--col), minmax(0, 1fr));
18
18
  }
19
19
 
20
- &:not(#{when("wrap")}) {
20
+ &:not(#{fn.when("wrap")}) {
21
21
  grid-auto-flow: column;
22
22
  grid-auto-columns: calc((100% - (var(--col) - 1) * var(--gap)) / var(--col));
23
23
  overflow-x: scroll;
@@ -25,14 +25,14 @@
25
25
  }
26
26
 
27
27
  /* ========= flex布局 ========= */
28
- @include when("flex") {
28
+ @include mx.when("flex") {
29
29
  --display: flex;
30
30
  gap: var(--gap);
31
31
 
32
32
  // 自动宽度
33
- &:not(#{when("auto")}) {
33
+ &:not(#{fn.when("auto")}) {
34
34
  > {
35
- @include b("cell") {
35
+ @include mx.b("cell") {
36
36
  flex-shrink: 0;
37
37
  width: calc((100% - (var(--col) - 1) * var(--gap)) / var(--col));
38
38
  }
@@ -40,19 +40,19 @@
40
40
  }
41
41
 
42
42
  // 换行
43
- @include when("wrap") {
43
+ @include mx.when("wrap") {
44
44
  flex-wrap: wrap;
45
45
  }
46
46
 
47
- &:not(#{when("wrap")}) {
47
+ &:not(#{fn.when("wrap")}) {
48
48
  overflow-x: scroll;
49
49
  }
50
50
  }
51
51
 
52
52
  /* ========= 单个 cell 居中 ========= */
53
- @include when(join-class("only", "center")) {
53
+ @include mx.when(fn.join-class("only", "center")) {
54
54
  > {
55
- @include b("cell") {
55
+ @include mx.b("cell") {
56
56
  &:only-child {
57
57
  grid-column: 1 / calc(var(--col) + 1);
58
58
  width: calc(100% / var(--col));
@@ -1,6 +1,6 @@
1
- @use "../mixin" as *;
1
+ @use "../mixin/index" as mx;
2
2
 
3
- @include b("icon") {
3
+ @include mx.b("icon") {
4
4
  display: inline-block;
5
5
  vertical-align: middle;
6
6
  color: inherit;
@@ -1,12 +1,12 @@
1
- @use "../mixin" as *;
1
+ @use "../mixin/index" as mx;
2
2
 
3
- @include b("image") {
3
+ @include mx.b("image") {
4
4
  --aspect-ratio: 1;
5
5
  position: relative;
6
6
 
7
7
  // 背景
8
- @include e("bg") {
9
- @include absolute-center(true, true);
8
+ @include mx.e("bg") {
9
+ @include mx.absolute-center(true, true);
10
10
  z-index: 0;
11
11
  width: 100%;
12
12
  height: 100%;
@@ -16,7 +16,7 @@
16
16
  }
17
17
 
18
18
  // 图片内容
19
- @include e("content") {
19
+ @include mx.e("content") {
20
20
  position: relative;
21
21
  z-index: 1;
22
22
  width: 100%;
@@ -25,23 +25,23 @@
25
25
  }
26
26
 
27
27
  // 遮罩
28
- @include e("overlay") {
29
- @include absolute-center(true, true);
28
+ @include mx.e("overlay") {
29
+ @include mx.absolute-center(true, true);
30
30
  z-index: 3;
31
31
  width: 100%;
32
32
  height: 100%;
33
33
  }
34
34
 
35
35
  // 装饰
36
- @include e("decoration") {
36
+ @include mx.e("decoration") {
37
37
  position: absolute;
38
38
  z-index: 2;
39
39
  top: 0;
40
40
  right: 0;
41
41
  }
42
42
 
43
- @include when("ratio") {
44
- @include e("content") {
43
+ @include mx.when("ratio") {
44
+ @include mx.e("content") {
45
45
  aspect-ratio: var(--aspect-ratio);
46
46
  object-fit: cover;
47
47
  }
@@ -1,12 +1,13 @@
1
- @use "../mixin" as *;
1
+ @use "../function/index" as fn;
2
+ @use "../mixin/index" as mx;
2
3
 
3
- @include b(popup) {
4
+ @include mx.b(popup) {
4
5
  --popup-width: 30%;
5
6
  --popup-height: auto;
6
7
  --popup-padding: calc(20 * var(--size-unit));
7
8
  --popup-bg: linear-gradient(0deg, var(--color-base-50), var(--color-base-50));
8
9
  --popup-z-index: 1;
9
- --popup-close-inset: #{u(4)} #{u(4)} auto auto;
10
+ --popup-close-inset: #{fn.u(4)} #{fn.u(4)} auto auto;
10
11
 
11
12
  position: fixed;
12
13
  top: 0;
@@ -14,49 +15,49 @@
14
15
  width: 100%;
15
16
  height: 100%;
16
17
  pointer-events: none;
17
- @include set-z-index(var(--popup-z-index));
18
+ @include mx.set-z-index(var(--popup-z-index));
18
19
 
19
- @include e(wrapper) {
20
- @include bg(var(--popup-width), var(--popup-height), var(--popup-bg));
20
+ @include mx.e(wrapper) {
21
+ @include mx.bg(var(--popup-width), var(--popup-height), var(--popup-bg));
21
22
  position: relative;
22
23
  padding: var(--popup-padding);
23
24
  pointer-events: auto;
24
25
  }
25
26
 
26
- @include e(close) {
27
+ @include mx.e(close) {
27
28
  position: absolute;
28
29
  inset: var(--popup-close-inset);
29
30
  z-index: 1;
30
31
  }
31
32
 
32
33
  // 默认居中
33
- &:not(#{when(ttb)}, #{when(rtl)}, #{when(btt)}, #{when(ltr)}) {
34
+ &:not(#{fn.when(ttb)}, #{fn.when(rtl)}, #{fn.when(btt)}, #{fn.when(ltr)}) {
34
35
  display: flex;
35
36
  align-items: center;
36
37
  justify-content: center;
37
38
  }
38
39
 
39
- @include when(ttb) {
40
+ @include mx.when(ttb) {
40
41
  --popup-width: 100%;
41
42
  }
42
43
 
43
- @include when(rtl) {
44
+ @include mx.when(rtl) {
44
45
  display: flex;
45
46
  justify-content: flex-end;
46
47
 
47
- @include e(wrapper) {
48
+ @include mx.e(wrapper) {
48
49
  height: 100%;
49
50
  }
50
51
  }
51
52
 
52
- @include when(btt) {
53
+ @include mx.when(btt) {
53
54
  --popup-width: 100%;
54
55
  display: flex;
55
56
  align-items: flex-end;
56
57
  }
57
58
 
58
- @include when(ltr) {
59
- @include e(wrapper) {
59
+ @include mx.when(ltr) {
60
+ @include mx.e(wrapper) {
60
61
  height: 100%;
61
62
  }
62
63
  }
@@ -1,4 +1,5 @@
1
- @use "../mixin" as *;
1
+ @use "../function/index" as fn;
2
+ @use "../mixin/index" as mx;
2
3
 
3
4
  /*!
4
5
  Example HTML:
@@ -21,48 +22,48 @@ Example HTML:
21
22
 
22
23
  */
23
24
 
24
- @include b(progress) {
25
+ @include mx.b(progress) {
25
26
  --progress-width: 100%;
26
27
  --progress-value: 0%; // 进度值
27
- --progress-segment-point-width: #{u(30)}; // 节点大小
28
+ --progress-segment-point-width: #{fn.u(30)}; // 节点大小
28
29
  --progress-segment-point-transform: translateX(50%); // 节点中心偏移
29
30
  --progress-segment-point-bg: linear-gradient(0deg, var(--color-base-500), var(--color-base-500)); // 节点背景
30
31
  --progress-segment-point-bg-active: linear-gradient(0deg, var(--theme-color-500), var(--theme-color-500)); // 节点背景
31
32
  --progress-segment-content-transform: translateX(50%); // 内容中心偏移
32
33
 
33
- --progress-bar-height: #{u(20)}; // 进度条高度
34
- --progress-bar-radius: #{u(10)}; // 进度条(内外)圆角
34
+ --progress-bar-height: #{fn.u(20)}; // 进度条高度
35
+ --progress-bar-radius: #{fn.u(10)}; // 进度条(内外)圆角
35
36
  --progress-bar-outer-bg: linear-gradient(0deg, var(--color-base-250), var(--color-base-250)); // 外背景
36
37
  --progress-bar-outer-padding: 0; // 外边距
37
38
  --progress-bar-inner-bg: linear-gradient(0deg, var(--theme-color-500), var(--theme-color-500)); // 内背景
38
39
  overflow-x: scroll;
39
40
 
40
- @include e(wrapper) {
41
+ @include mx.e(wrapper) {
41
42
  width: var(--progress-width);
42
43
  position: relative;
43
44
  min-height: var(--progress-segment-point-width);
44
45
  }
45
46
 
46
47
  // 片段
47
- @include e(segments) {
48
+ @include mx.e(segments) {
48
49
  display: flex;
49
50
  justify-content: flex-start;
50
51
  }
51
52
 
52
- @include e(segment) {
53
+ @include mx.e(segment) {
53
54
  position: relative;
54
55
  z-index: 1;
55
56
  width: var(--progress-segment-width, 0%);
56
57
 
57
- @include m(wrapper) {
58
+ @include mx.m(wrapper) {
58
59
  display: flex;
59
60
  flex-direction: column;
60
61
  align-items: flex-end;
61
62
  }
62
63
 
63
- @include m(point) {
64
+ @include mx.m(point) {
64
65
  border-radius: 100%;
65
- @include bg(
66
+ @include mx.bg(
66
67
  var(--progress-segment-point-width),
67
68
  var(--progress-segment-point-width),
68
69
  var(--progress-segment-point-bg)
@@ -70,13 +71,13 @@ Example HTML:
70
71
  transform: var(--progress-segment-point-transform);
71
72
  }
72
73
 
73
- @include m(content) {
74
+ @include mx.m(content) {
74
75
  transform: var(--progress-segment-content-transform);
75
76
  }
76
77
 
77
- @include when("active") {
78
- .#{bem("progress", "segment", "point")} {
79
- @include bg(
78
+ @include mx.when("active") {
79
+ .#{fn.bem("progress", "segment", "point")} {
80
+ @include mx.bg(
80
81
  var(--progress-segment-point-width),
81
82
  var(--progress-segment-point-width),
82
83
  var(--progress-segment-point-bg-active)
@@ -86,7 +87,7 @@ Example HTML:
86
87
  }
87
88
 
88
89
  // 进度条
89
- @include e(bar) {
90
+ @include mx.e(bar) {
90
91
  width: 100%;
91
92
  position: absolute;
92
93
  top: calc(var(--progress-segment-point-width) / 2);
@@ -94,21 +95,21 @@ Example HTML:
94
95
  z-index: 0;
95
96
  transform: translateY(-50%);
96
97
 
97
- @include m(outer) {
98
+ @include mx.m(outer) {
98
99
  width: 100%;
99
100
  padding: var(--progress-bar-outer-padding);
100
101
  border-radius: var(--progress-bar-radius);
101
- @include bg(100%, var(--progress-bar-height), var(--progress-bar-outer-bg));
102
+ @include mx.bg(100%, var(--progress-bar-height), var(--progress-bar-outer-bg));
102
103
  }
103
104
 
104
- @include m(inner) {
105
+ @include mx.m(inner) {
105
106
  height: 100%;
106
107
  border-radius: var(--progress-bar-radius);
107
- @include bg(var(--progress-value, 0%), 100%, var(--progress-bar-inner-bg));
108
+ @include mx.bg(var(--progress-value, 0%), 100%, var(--progress-bar-inner-bg));
108
109
  }
109
110
  }
110
111
 
111
- @include when(rtl) {
112
+ @include mx.when(rtl) {
112
113
  --progress-segment-point-transform: translateX(-50%);
113
114
  --progress-segment-content-transform: translateX(-50%);
114
115
  }
@@ -1,5 +1,7 @@
1
+ @use "../function/index" as fn;
2
+
1
3
  .table {
2
- --grid-padding: #{u(2)} 0;
4
+ --grid-padding: #{fn.u(2)} 0;
3
5
  --grid-width: auto;
4
6
  --bg-thead: rgba(0, 0, 0, 0.2);
5
7
  --color-border: #ffffff33;
@@ -7,7 +9,7 @@
7
9
  font-size: 0;
8
10
  border-spacing: 0;
9
11
  border-collapse: separate;
10
- border: #{u(2)} solid var(--color-border);
12
+ border: #{fn.u(2)} solid var(--color-border);
11
13
  overflow: hidden;
12
14
 
13
15
  thead {
@@ -31,7 +33,7 @@
31
33
  flex: 1 0 var(--grid-width);
32
34
  padding: var(--grid-padding);
33
35
  border: solid var(--color-border);
34
- border-width: 0 #{u(2)} #{u(2)} 0;
36
+ border-width: 0 #{fn.u(2)} #{fn.u(2)} 0;
35
37
  }
36
38
 
37
39
  .text {
@@ -1,43 +1,33 @@
1
- @use "../mixin" as *;
2
-
3
- @include b("text") {
4
- display: inline-block;
5
- line-height: 1;
6
- vertical-align: middle;
7
-
8
- @include when("ellipsis") {
9
- width: 100%;
10
- white-space: nowrap;
11
- text-overflow: ellipsis;
12
- overflow: hidden;
13
- }
14
-
15
- @include when("h1") {
16
- font-size: var(--text-3xl);
17
- }
18
-
19
- @include when("h2") {
20
- font-size: var(--text-2xl);
21
- }
22
-
23
- @include when("h3") {
24
- font-size: var(--text-xl);
25
- }
26
-
27
- @include when("h4") {
28
- font-size: var(--text-lg);
29
- }
30
-
31
- @include when("h5") {
32
- font-size: var(--text-base);
33
- }
34
-
35
- @include when("h6") {
36
- font-size: var(--text-sm);
37
- }
38
-
39
- @include when("p") {
40
- display: block;
41
- line-height: 1.5;
42
- }
43
- }
1
+ @use "sass:map";
2
+ @use "../_config"as cfg;
3
+ @use "../_variables" as vars;
4
+ @use "../function/index" as fn;
5
+ @use "../mixin/index" as mx;
6
+
7
+ @include mx.b("text") {
8
+ display: inline-block;
9
+ line-height: 1;
10
+ vertical-align: middle;
11
+
12
+ @include mx.when("ellipsis") {
13
+ width: 100%;
14
+ white-space: nowrap;
15
+ text-overflow: ellipsis;
16
+ overflow: hidden;
17
+ }
18
+
19
+ @each $step, $data in vars.$text-scale {
20
+ $ratio: map.get($data, ratio);
21
+ $token: map.get($data, token);
22
+
23
+ // 生成字体尺寸
24
+ @include mx.m($token) {
25
+ font-size: var(#{fn.css-var-name(cfg.$theme-font-prefix, $token)});
26
+ }
27
+ }
28
+
29
+ @include mx.when("p") {
30
+ display: block;
31
+ line-height: 1.5;
32
+ }
33
+ }