@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/theme.scss CHANGED
@@ -1,157 +1,17 @@
1
- @use "sass:map";
2
- @use "./_variables" as var;
3
-
4
- // -----------------------------
5
- // 🎨 颜色设计变量命名规范
6
- // -----------------------------
7
- // 设计参考: https://tailwindcss.com/docs/colors
8
- // 采用设计系统分级(Design Token)风格,使用结构化命名,方便主题维护与自动生成 CSS 变量。
9
- // 命名格式: $<color-name>-<scale>
10
- //
11
- // - color-name: 颜色语义标识或色调(如 primary、success、gray)
12
- // - scale: 数值越小表示颜色越浅(如 50 接近白色,900 接近黑色)
13
- //
14
- // 🌟 建议使用分级: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950
15
- // - 500 为主色基准值(推荐 UI 主色)
16
- // - 其他等级用于 hover、disabled、背景、边框等场景
17
- //
18
- // 🔄 可统一生成 CSS Variables,用于 :root 或主题切换
19
- // e.g. $primary-500 → --primary-500
20
-
21
- // 主题色
22
- $theme-color-50: #ede6ff;
23
- $theme-color-500: #6e64c8;
24
-
25
- // 基础色(背景/字体)
26
- $color-base-50: #fff;
27
- $color-base-250: #f5f6f7;
28
- $color-base-500: #eee;
29
- $color-base-inverse-50: #777777;
30
- $color-base-inverse-250: #333333;
31
- $color-base-inverse-500: #000000;
32
-
33
- // 警告色
34
- $color-danger-500: #ff7b7b;
35
-
36
- // -----------------------------
37
- // 🔤 字体设计变量命名规范
38
- // -----------------------------
39
- // 设计参考: https://tailwindcss.com/docs/font-size
40
- // 参考标准: https://developer.mozilla.org/en-US/docs/Web/CSS/font-size#values
41
- // xx-small、x-small、small、medium、large、x-large、xx-large、xxx-large(基于用户默认字体大小(medium)的绝对大小关键字)
42
-
43
- $text-small-map: (
44
- // 14px
45
- 0: 0.875,
46
- // 12px
47
- 1: 0.75,
48
- // 10px
49
- 2: 0.625,
50
- // 8px
51
- 3: 0.5,
52
- // 6px
53
- 4: 0.375,
54
- // 4px
55
- 5: 0.25,
56
- // 2px
57
- 6: 0.125
58
- );
59
-
60
- $text-large-map: (
61
- // 18px
62
- 0: 1.125,
63
- // 20px
64
- 1: 1.25,
65
- // 24px
66
- 2: 1.5,
67
- // 30px
68
- 3: 1.875,
69
- 4: 2.25,
70
- 5: 3,
71
- 6: 3.75,
72
- 7: 4.5,
73
- 8: 6,
74
- 9: 8
75
- );
76
-
77
- // 获取字体大小比例
78
- @function text-get-ratio($scale, $step) {
79
- $ratio: 1; // 默认值
80
-
81
- @if $scale == small and map.has-key($text-small-map, $step) {
82
- $ratio: map.get($text-small-map, $step);
83
- } @else if $scale == large and map.has-key($text-large-map, $step) {
84
- $ratio: map.get($text-large-map, $step);
85
- } @else {
86
- @warn "text-get-ratio(): 无效的 scale 或 step,返回基础值";
87
- }
88
-
89
- @return $ratio;
90
- }
91
-
92
- // 主题变量
93
- @mixin vars {
94
- // 🌈 主题色
95
- --theme-color-50: #{$theme-color-50};
96
- --theme-color-500: #{$theme-color-500};
97
-
98
- // 🎨 基础颜色
99
- --color-base-50: #{$color-base-50};
100
- --color-base-250: #{$color-base-250};
101
- --color-base-500: #{$color-base-500};
102
- --color-base-inverse-50: #{$color-base-inverse-50};
103
- --color-base-inverse-250: #{$color-base-inverse-250};
104
- --color-base-inverse-500: #{$color-base-inverse-500};
105
- --color-danger-500: #{$color-danger-500};
106
-
107
- // 🔤 尺寸基准值,控制设计稿与真实页面的缩放比例
108
- --size-root: #{var.$size-root};
109
-
110
- // 🔤 最小单位:等效于 1px:
111
- // - 当使用 rem 方案:1px = calc(1 / var(--size-root) * 1rem)
112
- // - 当使用 vw 方案:1px = calc(1 / var(--size-root) * 100vw)
113
- --size-unit: calc(1 / var(--size-root) * 1rem);
114
-
115
- // 🔠 字体尺寸(根据 --size-root 等比缩放)
116
- --text-6xs: calc(var(--text-base) * #{text-get-ratio(small, 6)});
117
- --text-5xs: calc(var(--text-base) * #{text-get-ratio(small, 5)});
118
- --text-4xs: calc(var(--text-base) * #{text-get-ratio(small, 4)});
119
- --text-3xs: calc(var(--text-base) * #{text-get-ratio(small, 3)});
120
- --text-2xs: calc(var(--text-base) * #{text-get-ratio(small, 2)});
121
- --text-xs: calc(var(--text-base) * #{text-get-ratio(small, 1)});
122
- --text-sm: calc(var(--text-base) * #{text-get-ratio(small, 0)});
123
- --text-base: calc(16 * var(--size-unit));
124
- --text-lg: calc(var(--text-base) * #{text-get-ratio(large, 0)});
125
- --text-xl: calc(var(--text-base) * #{text-get-ratio(large, 1)});
126
- --text-2xl: calc(var(--text-base) * #{text-get-ratio(large, 2)});
127
- --text-3xl: calc(var(--text-base) * #{text-get-ratio(large, 3)});
128
- --text-4xl: calc(var(--text-base) * #{text-get-ratio(large, 4)});
129
- --text-5xl: calc(var(--text-base) * #{text-get-ratio(large, 5)});
130
- --text-6xl: calc(var(--text-base) * #{text-get-ratio(large, 6)});
131
- --text-7xl: calc(var(--text-base) * #{text-get-ratio(large, 7)});
132
- --text-8xl: calc(var(--text-base) * #{text-get-ratio(large, 8)});
133
- --text-9xl: calc(var(--text-base) * #{text-get-ratio(large, 9)});
134
-
135
- // 🧱 层级控制
136
- --z-index-base: #{var.$z-index-base};
137
-
138
- // 🎯 语义色扩展(从基础色继承)
139
- --color-text-500: var(--color-base-inverse-500);
140
- --color-text-inverse-500: var(--color-base-50);
141
- --color-icon-500: var(--color-base-inverse-500);
142
- --color-border-500: var(--color-base-500);
143
- --color-bg-500: var(--color-base-250);
144
-
145
- // 🌙 暗色模式变量切换(通过类名控制)
146
- &.dark {
147
- --color-base-inverse-50: #{$color-base-50};
148
- --color-base-inverse-250: #{$color-base-250};
149
- --color-base-inverse-500: #{$color-base-500};
150
-
151
- --color-base-50: #{$color-base-inverse-500};
152
- --color-base-250: #{$color-base-inverse-250};
153
- --color-base-500: #{$color-base-inverse-50};
154
- }
155
-
156
- font-size: calc(var(--size-root) * 1px);
1
+ @use "./function/index" as fn;
2
+ @use "./mixin/index" as mx;
3
+
4
+ @mixin vars() {
5
+ font-size: calc(#{fn.var-get(size, root)} * 1px);
6
+ @include mx.var-register();
7
+
8
+ &.dark {
9
+ --color-base-50: #{fn.var-get-value(color, base, inverse, 500)};
10
+ --color-base-250: #{fn.var-get-value(color, base, inverse, 250)};
11
+ --color-base-500: #{fn.var-get-value(color, base, inverse, 50)};
12
+
13
+ --color-base-inverse-50: #{fn.var-get-value(color, base, 50)};
14
+ --color-base-inverse-250: #{fn.var-get-value(color, base, 250)};
15
+ --color-base-inverse-500: #{fn.var-get-value(color, base, 500)};
16
+ }
157
17
  }
package/_function.scss DELETED
@@ -1,64 +0,0 @@
1
- @use "sass:string";
2
- @use "./_variables" as var;
3
- @use "_config" as config;
4
-
5
- // bem("block", "element", "modifier") => "s_block__element--modifier"
6
- @function bem($block, $element: "", $modifier: "") {
7
- $name: config.$namespace + config.$common-separator + $block;
8
-
9
- @if $element != "" {
10
- $name: $name + config.$element-separator + $element;
11
- }
12
-
13
- @if $modifier != "" {
14
- $name: $name + config.$modifier-separator + $modifier;
15
- }
16
-
17
- @return $name;
18
- }
19
-
20
- @function when($state) {
21
- $state-selector: config.$state-prefix + config.$common-separator + $state;
22
-
23
- @return ".#{$state-selector}";
24
- }
25
-
26
- @function join-class($parts...) {
27
- $result: "";
28
-
29
- @each $part in $parts {
30
- @if $part != null and $part != "" {
31
- @if $result == "" {
32
- $result: $part;
33
- } @else {
34
- $result: $result + config.$common-separator + $part;
35
- }
36
- }
37
- }
38
-
39
- @return $result;
40
- }
41
-
42
- // 最小尺寸单位转换
43
- @function u($value) {
44
- @return calc(#{$value} * var(--size-unit));
45
- }
46
-
47
- @function get-image($image) {
48
- // 已经是合法CSS值的情况
49
- @if string.index($image, "url(") or
50
- string.index($image, "gradient(") or
51
- string.index($image, "var(") or
52
- string.index($image, "data:")
53
- {
54
- @return $image;
55
- }
56
-
57
- // 空值或none
58
- @if $image ==none or $image ==null {
59
- @return none;
60
- }
61
-
62
- // 默认处理为路径
63
- @return url($image);
64
- }
package/_mixin.scss DELETED
@@ -1,193 +0,0 @@
1
- @use "sass:map";
2
-
3
- @use "_config" as *;
4
- @use "_variables" as var;
5
- @use "_function" as func;
6
-
7
- @forward "_config";
8
- @forward "_variables";
9
- @forward "_function";
10
-
11
- // BEM
12
- $B: null;
13
- $__bem-context: null;
14
-
15
- @mixin b($block) {
16
- $B: $namespace + $common-separator + $block !global;
17
-
18
- .#{$B} {
19
- $__bem-context: "block" !global;
20
- @content;
21
- $__bem-context: null !global;
22
- }
23
- }
24
-
25
- @mixin e($element) {
26
- @if $__bem-context != "block" {
27
- @error "e() can only be used inside b()";
28
- }
29
-
30
- @each $E in $element {
31
- .#{$B + $element-separator + $E} {
32
- $__bem-context: "element" !global;
33
- @content;
34
- $__bem-context: "block" !global;
35
- }
36
- }
37
- }
38
-
39
- @mixin m($modifier) {
40
- @if $__bem-context != "block" and $__bem-context != "element" {
41
- @error "m() can only be used inside b() or e()";
42
- }
43
-
44
- @each $M in $modifier {
45
- &#{$modifier-separator + $M} {
46
- @content;
47
- }
48
- }
49
- }
50
-
51
- @mixin t($names: null) {
52
- @if $__bem-context != "block" {
53
- @error "t() can only be used inside b()";
54
- }
55
-
56
- // 解析 themes 列表
57
- $themes: ();
58
- @if $names == null {
59
- @if $theme-name == null or $theme-name == "" {
60
- @error "$theme-name must be set globally or passed to @include t().";
61
- }
62
- $themes: ($theme-name);
63
- } @else {
64
- $themes: $names;
65
- }
66
-
67
- // 逐个生成 theme 选择器
68
- @each $theme in $themes {
69
- @if $theme == null or $theme == "" {
70
- @error "Invalid theme name in @include t().";
71
- }
72
-
73
- $T: $theme-prefix + $common-separator + $theme;
74
-
75
- &.#{$B + $modifier-separator + $T} {
76
- @content;
77
- }
78
- }
79
- }
80
-
81
- @mixin when($state) {
82
- $state-selector: $state-prefix + $common-separator + $state;
83
-
84
- @at-root {
85
- @if & {
86
- &.#{$state-selector} {
87
- @content;
88
- }
89
- } @else {
90
- .#{$state-selector} {
91
- @content;
92
- }
93
- }
94
- }
95
- }
96
-
97
- @mixin absolute-center($x: true, $y: true) {
98
- $x-value: 0;
99
- $y-value: 0;
100
-
101
- position: absolute;
102
-
103
- @if $x {
104
- left: 50%;
105
- $x-value: -50%;
106
- }
107
-
108
- @if $y {
109
- top: 50%;
110
- $y-value: -50%;
111
- }
112
-
113
- transform: translate(#{$x-value}, #{$y-value});
114
- }
115
-
116
- @mixin set-z-index($number) {
117
- z-index: calc(var(--z-index-base, var.$z-index-base) + $number);
118
- }
119
-
120
- // 背景
121
- @mixin bg($w, $h, $image) {
122
- width: $w;
123
- height: $h;
124
- background-size: 100% 100%;
125
- background-repeat: no-repeat;
126
- background-position: center;
127
- background-image: func.get-image($image);
128
- }
129
-
130
- @mixin bg-text($image) {
131
- background-clip: text;
132
- -webkit-background-clip: text;
133
- color: transparent;
134
- -webkit-text-fill-color: transparent;
135
- background-image: func.get-image($image);
136
- }
137
-
138
- @mixin frame-border($frame) {
139
- $image: map.get($frame, image);
140
- $inset: map.get($frame, inset);
141
- $slice: map.get($frame, slice);
142
- $fill: map.get($frame, fill);
143
- $repeat: map.get($frame, repeat, stretch);
144
-
145
- @if not $image or not $inset or not $slice {
146
- @error "frame-border: image / inset / slice are required";
147
- }
148
-
149
- @if $fill {
150
- border-image-slice: #{$slice} fill;
151
- } @else {
152
- border-image-slice: #{$slice};
153
- }
154
-
155
- box-sizing: border-box;
156
- border-style: solid;
157
- border-width: $inset;
158
- border-image-source: func.get-image($image);
159
- border-image-repeat: $repeat;
160
- }
161
-
162
- @mixin text-stroke($size, $color: #000, $blur: 0) {
163
- text-shadow:
164
- #{$size} #{$size} #{$blur} #{$color},
165
- -#{$size} #{$size} #{$blur} #{$color},
166
- #{$size} -#{$size} #{$blur} #{$color},
167
- -#{$size} -#{$size} #{$blur} #{$color};
168
- }
169
-
170
- @mixin text-shadow($size, $color: #000, $offset-x: func.u(2), $offset-y: #{u(2)}) {
171
- position: relative;
172
- z-index: 0;
173
- font-size: 0;
174
- line-height: 1;
175
- font-size: #{func.u(10)};
176
-
177
- > * {
178
- font-size: $size;
179
- }
180
-
181
- &::before {
182
- content: attr(data-text);
183
- position: absolute;
184
- top: 50%;
185
- left: 50%;
186
- z-index: -1;
187
- color: $color;
188
- font-size: $size;
189
- white-space: nowrap;
190
- // 偏移量
191
- transform: translate(calc(-50% + #{$offset-x}), calc(-50% + #{$offset-y}));
192
- }
193
- }
package/atomic.scss DELETED
@@ -1,60 +0,0 @@
1
- // flex
2
- .flex {
3
- display: flex;
4
- }
5
- .flex-1 {
6
- flex: 1 1 0%;
7
- }
8
- .flex-auto {
9
- flex: 1 1 auto;
10
- }
11
- .flex-initial {
12
- flex: 0 1 auto;
13
- }
14
- .flex-none {
15
- flex: none;
16
- }
17
- .justify-normal {
18
- justify-content: normal;
19
- }
20
- .justify-start {
21
- justify-content: flex-start;
22
- }
23
- .justify-end {
24
- justify-content: flex-end;
25
- }
26
- .justify-center {
27
- justify-content: center;
28
- }
29
- .justify-between {
30
- justify-content: space-between;
31
- }
32
- .justify-around {
33
- justify-content: space-around;
34
- }
35
- .justify-evenly {
36
- justify-content: space-evenly;
37
- }
38
- .justify-stretch {
39
- justify-content: stretch;
40
- }
41
- .items-start {
42
- align-items: flex-start;
43
- }
44
- .items-end {
45
- align-items: flex-end;
46
- }
47
- .items-center {
48
- align-items: center;
49
- }
50
- .items-baseline {
51
- align-items: baseline;
52
- }
53
- .items-stretch {
54
- align-items: stretch;
55
- }
56
- .text-overflow {
57
- white-space: nowrap;
58
- overflow: hidden;
59
- text-overflow: ellipsis;
60
- }