@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.
@@ -0,0 +1,39 @@
1
+
2
+ @use "../_config"as cfg;
3
+
4
+ // bem("block", "element", "modifier") => "s_block__element--modifier"
5
+ @function bem($block, $element: "", $modifier: "") {
6
+ $name: cfg.$namespace + cfg.$common-separator + $block;
7
+
8
+ @if $element != "" {
9
+ $name: $name + cfg.$element-separator + $element;
10
+ }
11
+
12
+ @if $modifier != "" {
13
+ $name: $name + cfg.$modifier-separator + $modifier;
14
+ }
15
+
16
+ @return $name;
17
+ }
18
+
19
+ @function when($state) {
20
+ $state-selector: cfg.$state-prefix + cfg.$common-separator + $state;
21
+
22
+ @return ".#{$state-selector}";
23
+ }
24
+
25
+ @function join-class($parts...) {
26
+ $result: "";
27
+
28
+ @each $part in $parts {
29
+ @if $part != null and $part != "" {
30
+ @if $result == "" {
31
+ $result: $part;
32
+ } @else {
33
+ $result: $result + cfg.$common-separator + $part;
34
+ }
35
+ }
36
+ }
37
+
38
+ @return $result;
39
+ }
@@ -0,0 +1,33 @@
1
+ @use "sass:string";
2
+
3
+ @use "./namespace" as *;
4
+
5
+ @forward "./_namespace";
6
+
7
+ // 尺寸最小单位
8
+ @function u($value) {
9
+ @return calc(#{$value} * var(--size-unit));
10
+ }
11
+
12
+ @function css-var-name($category, $token) {
13
+ @return "--#{$category}-#{$token}";
14
+ }
15
+
16
+ @function get-image($image) {
17
+ // 已经是合法CSS值的情况
18
+ @if string.index($image, "url(") or
19
+ string.index($image, "gradient(") or
20
+ string.index($image, "var(") or
21
+ string.index($image, "data:")
22
+ {
23
+ @return $image;
24
+ }
25
+
26
+ // 空值或none
27
+ @if $image ==none or $image ==null {
28
+ @return none;
29
+ }
30
+
31
+ // 默认处理为路径
32
+ @return url($image);
33
+ }
@@ -0,0 +1,9 @@
1
+
2
+ // atomic
3
+ @mixin generate-atomic($prefix, $property, $map) {
4
+ @each $key, $value in $map {
5
+ .#{$prefix}-#{$key} {
6
+ #{$property}: $value;
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,87 @@
1
+ @use "../_config"as cfg;
2
+
3
+ // BEM
4
+ $B: null;
5
+ $__bem-context: null;
6
+
7
+ @mixin b($block) {
8
+ $B: cfg.$namespace + cfg.$common-separator + $block !global;
9
+
10
+ .#{$B} {
11
+ $__bem-context: "block" !global;
12
+ @content;
13
+ $__bem-context: null !global;
14
+ }
15
+ }
16
+
17
+ @mixin e($element) {
18
+ @if $__bem-context != "block" {
19
+ @error "e() can only be used inside b()";
20
+ }
21
+
22
+ @each $E in $element {
23
+ .#{$B + cfg.$element-separator + $E} {
24
+ $__bem-context: "element" !global;
25
+ @content;
26
+ $__bem-context: "block" !global;
27
+ }
28
+ }
29
+ }
30
+
31
+ @mixin m($modifier) {
32
+ @if $__bem-context != "block" and $__bem-context != "element" {
33
+ @error "m() can only be used inside b() or e()";
34
+ }
35
+
36
+ @each $M in $modifier {
37
+ &#{cfg.$modifier-separator + $M} {
38
+ @content;
39
+ }
40
+ }
41
+ }
42
+
43
+ @mixin t($names: null) {
44
+ @if $__bem-context != "block" {
45
+ @error "t() can only be used inside b()";
46
+ }
47
+
48
+ // 解析 themes 列表
49
+ $themes: ();
50
+ @if $names == null {
51
+ @if cfg.$theme-name == null or cfg.$theme-name == "" {
52
+ @error "$theme-name must be set globally or passed to @include t().";
53
+ }
54
+ $themes: (cfg.$theme-name);
55
+ } @else {
56
+ $themes: $names;
57
+ }
58
+
59
+ // 逐个生成 theme 选择器
60
+ @each $theme in $themes {
61
+ @if $theme == null or $theme == "" {
62
+ @error "Invalid theme name in @include t().";
63
+ }
64
+
65
+ $T: cfg.$theme-prefix + cfg.$common-separator + $theme;
66
+
67
+ &.#{$B + cfg.$modifier-separator + $T} {
68
+ @content;
69
+ }
70
+ }
71
+ }
72
+
73
+ @mixin when($state) {
74
+ $state-selector: cfg.$state-prefix + cfg.$common-separator + $state;
75
+
76
+ @at-root {
77
+ @if & {
78
+ &.#{$state-selector} {
79
+ @content;
80
+ }
81
+ } @else {
82
+ .#{$state-selector} {
83
+ @content;
84
+ }
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,106 @@
1
+ @use "sass:map";
2
+
3
+ @use "../_config"as cfg;
4
+ @use "../_variables" as vars;
5
+ @use "../function/index" as fn;
6
+
7
+ @use "./_atomic" as *;
8
+ @use "./_namespace" as *;
9
+
10
+ @forward "../_config";
11
+ @forward "./_namespace";
12
+
13
+ @mixin absolute-center($x: true, $y: true) {
14
+ $x-value: 0;
15
+ $y-value: 0;
16
+
17
+ position: absolute;
18
+
19
+ @if $x {
20
+ left: 50%;
21
+ $x-value: -50%;
22
+ }
23
+
24
+ @if $y {
25
+ top: 50%;
26
+ $y-value: -50%;
27
+ }
28
+
29
+ transform: translate(#{$x-value}, #{$y-value});
30
+ }
31
+
32
+ @mixin set-z-index($number) {
33
+ z-index: calc(var(--z-index-base, vars.$z-index-base) + $number);
34
+ }
35
+
36
+ // 背景
37
+ @mixin bg($w, $h, $image) {
38
+ width: $w;
39
+ height: $h;
40
+ background-size: 100% 100%;
41
+ background-repeat: no-repeat;
42
+ background-position: center;
43
+ background-image: fn.get-image($image);
44
+ }
45
+
46
+ @mixin bg-text($image) {
47
+ background-clip: text;
48
+ -webkit-background-clip: text;
49
+ color: transparent;
50
+ -webkit-text-fill-color: transparent;
51
+ background-image: fn.get-image($image);
52
+ }
53
+
54
+ @mixin frame-border($frame) {
55
+ $image: map.get($frame, image);
56
+ $inset: map.get($frame, inset);
57
+ $slice: map.get($frame, slice);
58
+ $fill: map.get($frame, fill);
59
+ $repeat: map.get($frame, repeat, stretch);
60
+
61
+ @if not $image or not $inset or not $slice {
62
+ @error "frame-border: image / inset / slice are required";
63
+ }
64
+
65
+ @if $fill {
66
+ border-image-slice: #{$slice} fill;
67
+ } @else {
68
+ border-image-slice: #{$slice};
69
+ }
70
+
71
+ box-sizing: border-box;
72
+ border-style: solid;
73
+ border-width: $inset;
74
+ border-image-source: fn.get-image($image);
75
+ border-image-repeat: $repeat;
76
+ }
77
+
78
+ @mixin text-stroke($size, $color: #000, $blur: 0) {
79
+ text-shadow: #{$size} #{$size} #{$blur} #{$color}, -#{$size} #{$size} #{$blur} #{$color},
80
+ #{$size} -#{$size} #{$blur} #{$color}, -#{$size} -#{$size} #{$blur} #{$color};
81
+ }
82
+
83
+ @mixin text-shadow($size, $color: #000, $offset-x: fn.u(2), $offset-y: #{u(2)}) {
84
+ position: relative;
85
+ z-index: 0;
86
+ font-size: 0;
87
+ line-height: 1;
88
+ font-size: #{fn.u(10)};
89
+
90
+ > * {
91
+ font-size: $size;
92
+ }
93
+
94
+ &::before {
95
+ content: attr(data-text);
96
+ position: absolute;
97
+ top: 50%;
98
+ left: 50%;
99
+ z-index: -1;
100
+ color: $color;
101
+ font-size: $size;
102
+ white-space: nowrap;
103
+ // 偏移量
104
+ transform: translate(calc(-50% + #{$offset-x}), calc(-50% + #{$offset-y}));
105
+ }
106
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nopon-web/styles",
3
- "version": "0.0.51",
3
+ "version": "0.1.00",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/theme.scss CHANGED
@@ -1,28 +1,22 @@
1
1
  @use "sass:map";
2
- @use "./_variables" as var;
2
+ @use "./_config"as cfg;
3
+ @use "./_variables" as vars;
4
+ @use "./function/index" as fn;
3
5
 
4
- // -----------------------------
5
- // 🎨 颜色设计变量命名规范
6
- // -----------------------------
6
+ // ============================================
7
+ // Color Tokens(颜色设计令牌)
7
8
  // 设计参考: 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
9
+ // ============================================
10
+ // 命名: $<name>-<scale>
11
+ // scale: 50(浅) → 950(深),500 为主色
12
+ // 可映射为 CSS 变量支持主题切换
13
+ // ============================================
20
14
 
21
15
  // 主题色
22
16
  $theme-color-50: #ede6ff;
23
17
  $theme-color-500: #6e64c8;
24
18
 
25
- // 基础色(背景/字体)
19
+ // 基础色(Background / Text Base)
26
20
  $color-base-50: #fff;
27
21
  $color-base-250: #f5f6f7;
28
22
  $color-base-500: #eee;
@@ -30,128 +24,92 @@ $color-base-inverse-50: #777777;
30
24
  $color-base-inverse-250: #333333;
31
25
  $color-base-inverse-500: #000000;
32
26
 
33
- // 警告色
27
+ // 功能色(Semantic)
34
28
  $color-danger-500: #ff7b7b;
35
29
 
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;
30
+ @mixin color-vars {
31
+ --theme-color-50: #{$theme-color-50};
32
+ --theme-color-500: #{$theme-color-500};
33
+
34
+ // Base
35
+ --color-base-50: #{$color-base-50};
36
+ --color-base-250: #{$color-base-250};
37
+ --color-base-500: #{$color-base-500};
38
+ --color-base-inverse-50: #{$color-base-inverse-50};
39
+ --color-base-inverse-250: #{$color-base-inverse-250};
40
+ --color-base-inverse-500: #{$color-base-inverse-500};
41
+
42
+ // Semantic
43
+ --color-danger-500: #{$color-danger-500};
44
+
45
+ --color-text-500: var(--color-base-inverse-500);
46
+ --color-text-inverse-500: var(--color-base-50);
47
+ --color-icon-500: var(--color-base-inverse-500);
48
+ --color-border-500: var(--color-base-500);
49
+ --color-bg-500: var(--color-base-250);
50
+
51
+ // Dark Mode(结构反转
52
+ &.dark {
53
+ --color-base-inverse-50: #{$color-base-50};
54
+ --color-base-inverse-250: #{$color-base-250};
55
+ --color-base-inverse-500: #{$color-base-500};
56
+
57
+ --color-base-50: #{$color-base-inverse-500};
58
+ --color-base-250: #{$color-base-inverse-250};
59
+ --color-base-500: #{$color-base-inverse-50};
60
+ }
90
61
  }
91
62
 
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);
63
+ // ============================================
64
+ // Scale Apply
65
+ // --size-root : 设计基准(px)
66
+ // --size-unit : 等效 1px 抽象单位
67
+ // ============================================
68
+ //
69
+ // rem 模式:
70
+ // 基于 root font-size(等价 Flexible)
71
+ //
72
+ // vw 模式:
73
+ // 基于视口宽度比例
74
+ // 需通过 JS 动态设置 --size-root = 当前视口宽度(px)
75
+ //
76
+ // ============================================
77
+ @mixin size-apply() {
78
+ font-size: calc(var(--size-root) * 1px);
79
+ --size-root: #{vars.$size-root};
80
+
81
+ @if vars.$size-mode ==rem {
82
+ // Flexible
83
+ --size-unit: calc(1 / var(--size-root) * 1rem);
84
+ }
85
+
86
+ @else if vars.$size-mode ==vw {
87
+ // Viewport
88
+ --size-unit: calc(1 / var(--size-root) * 100vw);
89
+ }
157
90
  }
91
+
92
+ // ============================================
93
+ // Font Variables
94
+ // text-* = base × ratio
95
+ // ============================================
96
+ @mixin text-vars() {
97
+ #{fn.css-var-name(cfg.$theme-font-prefix, base)}: calc(#{vars.$text-base} * var(--size-unit));
98
+
99
+ @each $step, $data in vars.$text-scale {
100
+ $ratio: map.get($data, ratio);
101
+ $token: map.get($data, token);
102
+
103
+ #{fn.css-var-name(cfg.$theme-font-prefix, $token)}: calc(var(--#{cfg.$theme-font-prefix}-base) * #{$ratio});
104
+ }
105
+ }
106
+
107
+ // 主题变量
108
+ @mixin vars() {
109
+ @include size-apply();
110
+ @include text-vars();
111
+ @include color-vars();
112
+
113
+ // 层级控制
114
+ --z-index-base: #{vars.$z-index-base};
115
+ }
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
- }