@nopon-web/styles 0.0.51 → 0.2.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
@@ -1,3 +1,4 @@
1
+ // bem
1
2
  $namespace: "s" !default;
2
3
  $common-separator: "-" !default;
3
4
  $element-separator: "__" !default;
@@ -5,3 +6,7 @@ $modifier-separator: "--" !default;
5
6
  $state-prefix: "is" !default;
6
7
  $theme-prefix: "theme" !default;
7
8
  $theme-name: "" !default;
9
+
10
+ // vars
11
+ $var-css-registered: true !default; // 是否已经注册 CSS Variables
12
+ $var-runtime-mode: value !default; // var运行时模式, value = 编译期计算, css = 运行时 calc + var
package/_variables.scss CHANGED
@@ -1,9 +1,98 @@
1
- // 🔤 尺寸基准值,控制设计稿与真实页面的缩放比例
2
- $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;
1
+ @use 'sass:map';
2
+
3
+ @use "./helper/expression" as expr;
4
+
5
+ // Size System
6
+ // --size-root : 设计基准(px)
7
+ // --size-unit : 等效 1px 抽象单位
8
+ // 设计参考: https://tailwindcss.com/docs/font-size
9
+ // 参考标准: https://developer.mozilla.org/en-US/docs/Web/CSS/font-size#values
10
+ // ============================================
11
+ //
12
+ // rem 模式:
13
+ // 基于 root font-size(等价 Flexible)
14
+ //
15
+ // vw 模式:
16
+ // 基于视口宽度比例
17
+ // 需通过 JS 动态设置 size-root = 当前视口宽度(px)
18
+ //
19
+ // ============================================
20
+ $size: () !default;
21
+ $size: map.deep-merge(
22
+ (
23
+ root: 16, // 尺寸基准(16 = 1rem 基准)
24
+ mode: 1rem, // Flexible 模式: 1rem; Viewport 模式: 100vw;
25
+ unit: expr.math(1, "/", expr.ref(size, root), "*", expr.ref(size, mode))
26
+ ),
27
+ $size
28
+ );
29
+
30
+ $text-base: expr.math(16, "*", expr.ref(size, unit)) !default; // 字号基准(md 等级)
31
+ $text: () !default; // 字号比例阶梯(基于 md = 1)
32
+ $text: map.deep-merge(
33
+ (
34
+ 6xs: expr.math(expr.ref(text-base), "*", 0.125),
35
+ 5xs: expr.math(expr.ref(text-base), "*", 0.25),
36
+ 4xs: expr.math(expr.ref(text-base), "*", 0.375),
37
+ 3xs: expr.math(expr.ref(text-base), "*", 0.5),
38
+ 2xs: expr.math(expr.ref(text-base), "*", 0.625),
39
+ xs: expr.math(expr.ref(text-base), "*", 0.75),
40
+ sm: expr.math(expr.ref(text-base), "*", 0.875),
41
+ md: expr.math(expr.ref(text-base), "*", 1),
42
+ lg: expr.math(expr.ref(text-base), "*", 1.125),
43
+ xl: expr.math(expr.ref(text-base), "*", 1.25),
44
+ 2xl: expr.math(expr.ref(text-base), "*", 1.5),
45
+ 3xl: expr.math(expr.ref(text-base), "*", 1.875),
46
+ 4xl: expr.math(expr.ref(text-base), "*", 2.25),
47
+ 5xl: expr.math(expr.ref(text-base), "*", 3),
48
+ 6xl: expr.math(expr.ref(text-base), "*", 3.75),
49
+ 7xl: expr.math(expr.ref(text-base), "*", 4.5),
50
+ 8xl: expr.math(expr.ref(text-base), "*", 6),
51
+ 9xl: expr.math(expr.ref(text-base), "*", 8)
52
+ ),
53
+ $text
54
+ );
55
+
56
+ // ============================================
57
+ // Color
58
+ // 设计参考: https://tailwindcss.com/docs/colors
59
+ // ============================================
60
+ // 命名: $<name>-<scale>
61
+ // scale: 50(浅) → 950(深),500 为主色
62
+ // 可映射为 CSS 变量支持主题切换
63
+ // ============================================
64
+ $color: () !default;
65
+ $color: map.deep-merge(
66
+ (
67
+ theme: (
68
+ 50: #ede6ff,
69
+ 500: #6e64c8,
70
+ ),
71
+ base: (
72
+ 50: #fff,
73
+ 250: #f5f6f7,
74
+ 500: #eee,
75
+ inverse: (
76
+ 50: #777777,
77
+ 250: #333333,
78
+ 500: #000000,
79
+ ),
80
+ ),
81
+ danger: (
82
+ 500: #ff7b7b,
83
+ ),
84
+ text: (
85
+ 500: expr.ref(color, base, inverse, 500),
86
+ inverse: (
87
+ 500: expr.ref(color, base, 50)
88
+ )
89
+ ),
90
+ icon: (
91
+ 500: expr.ref(color, base, inverse, 50)
92
+ )
93
+ ),
94
+ $color
95
+ );
7
96
 
8
97
  // 层级
9
98
  $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
- --progress-segment-point-bg-active: linear-gradient(0deg, var(--theme-color-500), var(--theme-color-500)); // 节点背景
31
+ --progress-segment-point-bg-active: linear-gradient(0deg, var(--color-theme-500), var(--color-theme-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
- --progress-bar-inner-bg: linear-gradient(0deg, var(--theme-color-500), var(--theme-color-500)); // 内背景
38
+ --progress-bar-inner-bg: linear-gradient(0deg, var(--color-theme-500), var(--color-theme-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
  }
@@ -27,7 +27,7 @@
27
27
  }
28
28
 
29
29
  &_thumb {
30
- background-color: var(--theme-color);
30
+ background-color: var(--color-theme);
31
31
  }
32
32
  }
33
33
  }
@@ -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 {