@nopon-web/styles 0.0.2 → 0.0.3

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 ADDED
@@ -0,0 +1,5 @@
1
+ $namespace: 's' !default;
2
+ $state-prefix: 'is' !default;
3
+ $common-separator: '-' !default;
4
+ $element-separator: '__' !default;
5
+ $modifier-separator: '--' !default;
package/_function.scss CHANGED
@@ -1,5 +1,21 @@
1
1
  @use 'sass:string';
2
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
+ }
3
19
 
4
20
  @function get-image($image) {
5
21
  // 已经是合法CSS值的情况
@@ -12,7 +28,7 @@
12
28
  }
13
29
 
14
30
  // 空值或none
15
- @if $image == none or $image == null {
31
+ @if $image ==none or $image ==null {
16
32
  @return none;
17
33
  }
18
34
 
package/_mixin.scss CHANGED
@@ -1,7 +1,62 @@
1
- @use './_variables' as var;
2
- @use './_function' as func;
3
1
  @use 'sass:map';
4
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
+ $__bem-context: null;
13
+
14
+ @mixin b($block) {
15
+ $B: $namespace + $common-separator + $block;
16
+
17
+ .#{$B} {
18
+ $__bem-context: 'block' !global;
19
+ @content;
20
+ $__bem-context: null !global;
21
+ }
22
+ }
23
+
24
+ @mixin e($element) {
25
+ @if $__bem-context != 'block' {
26
+ @error 'e() can only be used inside b()';
27
+ }
28
+
29
+ @each $E in $element {
30
+ &#{$element-separator + $E} {
31
+ $__bem-context: 'element' !global;
32
+ @content;
33
+ $__bem-context: 'block' !global;
34
+ }
35
+ }
36
+ }
37
+
38
+ @mixin m($modifier) {
39
+ @if $__bem-context != 'block' and $__bem-context != 'element' {
40
+ @error 'm() can only be used inside b() or e()';
41
+ }
42
+
43
+ @each $M in $modifier {
44
+ &#{$modifier-separator + $M} {
45
+ @content;
46
+ }
47
+ }
48
+ }
49
+
50
+ @mixin when($state) {
51
+ $state-selector: $state-prefix + $common-separator + $state;
52
+
53
+ @at-root {
54
+ #{if(&, '&.#{$state-selector}', '.#{$state-selector}')} {
55
+ @content;
56
+ }
57
+ }
58
+ }
59
+
5
60
  @mixin absolute-center($x: true, $y: true) {
6
61
  position: absolute;
7
62
 
@@ -56,6 +111,30 @@
56
111
  #{$size} -#{$size} #{$blur} #{$color}, -#{$size} -#{$size} #{$blur} #{$color};
57
112
  }
58
113
 
114
+ @mixin text-shadow($size: 14px, $color: #000, $offset-x: 2px, $offset-y: 2px) {
115
+ position: relative;
116
+ z-index: 0;
117
+ font-size: 0;
118
+ line-height: 1;
119
+
120
+ > * {
121
+ font-size: $size;
122
+ }
123
+
124
+ &::before {
125
+ content: attr(data-text);
126
+ position: absolute;
127
+ top: 50%;
128
+ left: 50%;
129
+ z-index: -1;
130
+ color: $color;
131
+ font-size: $size;
132
+ white-space: nowrap;
133
+ // 偏移量
134
+ transform: translate(calc(-50% + #{$offset-x}), calc(-50% + #{$offset-y}));
135
+ }
136
+ }
137
+
59
138
  /// 通用列表布局封装
60
139
  /// 支持 grid / flex 两种布局
61
140
  /// @param $options - 可选配置
@@ -133,7 +212,7 @@
133
212
  display: $display;
134
213
 
135
214
  // flex 布局
136
- @if $display == flex {
215
+ @if $display ==flex {
137
216
  margin: 0 calc(var(--gap) / -2);
138
217
 
139
218
  // 换行
@@ -143,7 +222,7 @@
143
222
  }
144
223
 
145
224
  // grid 布局(默认)
146
- @if $display == grid {
225
+ @if $display ==grid {
147
226
  gap: var(--gap);
148
227
 
149
228
  // 换行
@@ -155,9 +234,15 @@
155
234
  }
156
235
  }
157
236
 
158
- @if $wrap == false {
237
+ @if $wrap ==false {
159
238
  overflow-x: scroll;
160
239
  }
240
+
241
+ .#{$block}-#{$element}--item:only-child {
242
+ grid-column: 1 / calc(var(--col) + 1);
243
+ width: calc(100% / var(--col));
244
+ margin: 0 auto;
245
+ }
161
246
  }
162
247
 
163
248
  // --- 列表项 ---
@@ -165,7 +250,7 @@
165
250
  position: relative;
166
251
  font-size: 0;
167
252
 
168
- @if $display == flex {
253
+ @if $display ==flex {
169
254
  flex-shrink: 0;
170
255
  width: calc(100% / var(--col));
171
256
  padding: calc(var(--gap) / 2);
@@ -0,0 +1,19 @@
1
+ @use '../mixin' as *;
2
+
3
+ @include b('image') {
4
+ --aspect-ratio: 1;
5
+
6
+ > img {
7
+ width: 100%;
8
+ height: 100%;
9
+ }
10
+
11
+ @include when('ratio') {
12
+ position: relative;
13
+ aspect-ratio: var(--aspect-ratio);
14
+
15
+ > img {
16
+ object-fit: cover;
17
+ }
18
+ }
19
+ }
@@ -1,16 +1,15 @@
1
1
  @use '../mixin' as mixin;
2
2
 
3
3
  .picture {
4
+ position: relative;
5
+ --frame-width: 0.02rem;
6
+
4
7
  > img {
5
8
  width: 100%;
6
9
  height: 100%;
7
10
  object-fit: contain;
8
11
  }
9
12
 
10
- &:has(.picture-content, .picture-frame) {
11
- position: relative;
12
- }
13
-
14
13
  // 图片内容
15
14
  .picture-content {
16
15
  &--center {
@@ -28,13 +27,9 @@
28
27
  width: 100%;
29
28
  height: 100%;
30
29
  @include mixin.absolute-center(true, true);
31
- z-index: 0;
32
- }
33
-
34
- &:has(.picture-frame) {
35
- --frame-width: 0.02rem;
30
+ z-index: 1;
36
31
 
37
- > img {
32
+ + img {
38
33
  position: relative;
39
34
  width: calc(100% - var(--frame-width) * 2);
40
35
  height: calc(100% - var(--frame-width) * 2);
@@ -42,6 +42,7 @@
42
42
  }
43
43
 
44
44
  .text {
45
+ text-align: center;
45
46
  vertical-align: middle;
46
47
  }
47
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nopon-web/styles",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"