create-shopify-scss-autofill 0.2.1 → 0.3.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/bin/create-scss-kit.mjs
CHANGED
|
@@ -79,18 +79,7 @@ function parseArgs(argv) {
|
|
|
79
79
|
return out
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
function makeLowRangeCoefficients() {
|
|
83
|
-
const out = {}
|
|
84
|
-
for (let i = 0; i <= 50; i += 5) {
|
|
85
|
-
const key = `scale-${String(i).padStart(2, '0')}`
|
|
86
|
-
out[key] = Number((i / 100).toFixed(2))
|
|
87
|
-
}
|
|
88
|
-
return out
|
|
89
|
-
}
|
|
90
|
-
|
|
91
82
|
function makeDefaultConfig() {
|
|
92
|
-
const lowRange = makeLowRangeCoefficients()
|
|
93
|
-
|
|
94
83
|
return {
|
|
95
84
|
$schema: './tools/scss-kit/schema.json',
|
|
96
85
|
design: {
|
|
@@ -127,30 +116,82 @@ function makeDefaultConfig() {
|
|
|
127
116
|
},
|
|
128
117
|
coefficients: {
|
|
129
118
|
mobile: {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
'button-text':
|
|
140
|
-
|
|
119
|
+
h1: 0.52,
|
|
120
|
+
h2: 0.55,
|
|
121
|
+
h3: 0.55,
|
|
122
|
+
h4: 0.6,
|
|
123
|
+
h5: 0.6,
|
|
124
|
+
h6: 0.6,
|
|
125
|
+
body: 0.6,
|
|
126
|
+
small: 0.65,
|
|
127
|
+
quote: 0.55,
|
|
128
|
+
'button-text': 0.6,
|
|
129
|
+
'nav-link': 0.6,
|
|
130
|
+
'form-label': 0.6,
|
|
131
|
+
'form-input': 0.6,
|
|
132
|
+
'price-large': 0.5,
|
|
133
|
+
'price-small': 0.6,
|
|
134
|
+
badge: 0.65,
|
|
135
|
+
breadcrumb: 0.65,
|
|
136
|
+
},
|
|
137
|
+
desktop: {
|
|
138
|
+
h1: 0.58,
|
|
139
|
+
h2: 0.6,
|
|
140
|
+
h3: 0.6,
|
|
141
|
+
h4: 0.6,
|
|
142
|
+
h5: 0.65,
|
|
143
|
+
h6: 0.65,
|
|
144
|
+
body: 0.65,
|
|
145
|
+
small: 0.65,
|
|
146
|
+
quote: 0.6,
|
|
147
|
+
'button-text': 0.65,
|
|
148
|
+
'nav-link': 0.65,
|
|
149
|
+
'form-label': 0.65,
|
|
150
|
+
'form-input': 0.65,
|
|
151
|
+
'price-large': 0.55,
|
|
152
|
+
'price-small': 0.65,
|
|
153
|
+
badge: 0.7,
|
|
154
|
+
breadcrumb: 0.7,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
floors: {
|
|
158
|
+
mobile: {
|
|
159
|
+
h1: '24px',
|
|
160
|
+
h2: '20px',
|
|
161
|
+
h3: '18px',
|
|
162
|
+
h4: '16px',
|
|
163
|
+
h5: '14px',
|
|
164
|
+
h6: '14px',
|
|
165
|
+
body: '14px',
|
|
166
|
+
small: '12px',
|
|
167
|
+
quote: '14px',
|
|
168
|
+
'button-text': '14px',
|
|
169
|
+
'nav-link': '14px',
|
|
170
|
+
'form-label': '14px',
|
|
171
|
+
'form-input': '16px',
|
|
172
|
+
'price-large': '22px',
|
|
173
|
+
'price-small': '14px',
|
|
174
|
+
badge: '11px',
|
|
175
|
+
breadcrumb: '11px',
|
|
141
176
|
},
|
|
142
177
|
desktop: {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
'
|
|
150
|
-
'
|
|
151
|
-
'
|
|
152
|
-
'button-text':
|
|
153
|
-
|
|
178
|
+
h1: '28px',
|
|
179
|
+
h2: '22px',
|
|
180
|
+
h3: '18px',
|
|
181
|
+
h4: '16px',
|
|
182
|
+
h5: '14px',
|
|
183
|
+
h6: '14px',
|
|
184
|
+
body: '14px',
|
|
185
|
+
small: '12px',
|
|
186
|
+
quote: '16px',
|
|
187
|
+
'button-text': '14px',
|
|
188
|
+
'nav-link': '14px',
|
|
189
|
+
'form-label': '14px',
|
|
190
|
+
'form-input': '14px',
|
|
191
|
+
'price-large': '24px',
|
|
192
|
+
'price-small': '14px',
|
|
193
|
+
badge: '12px',
|
|
194
|
+
breadcrumb: '12px',
|
|
154
195
|
},
|
|
155
196
|
},
|
|
156
197
|
}
|
package/package.json
CHANGED
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
|
|
62
62
|
- 字体/需要下限兜底的值:使用 `r.resp(pc, mobile, desktopType[, mobileType])`
|
|
63
63
|
- 大多数间距(padding/margin/gap):使用 `r.vw(pc, mobile)`
|
|
64
|
+
- 少量间距若确实需要最小值:改用 `r.resp(...)`(不要给 `r.vw` 追加参数)
|
|
64
65
|
|
|
65
66
|
`r.vw(pc, mobile)` 的行为:
|
|
66
67
|
|
|
@@ -84,19 +85,23 @@
|
|
|
84
85
|
- 用途:用于“间距/尺寸优先流式”的场景(如 padding/margin/gap/宽高)。
|
|
85
86
|
- PC 输出:`min(vw, px)`(防止超大屏继续放大)。
|
|
86
87
|
- Mobile 输出:由自动生成器扫描 `r.vw(...)` 后,在 `@media` 中生成纯 `vw` 覆盖。
|
|
88
|
+
- 说明:`r.vw` 仅保留两个参数;若你需要最小值下限,请使用 `r.resp(...)`。
|
|
87
89
|
- 示例:`margin-top: r.vw(40px, 24px);`
|
|
88
90
|
|
|
89
91
|
### 由 `r.resp` / `r.vw` 间接使用(一般不直接写)
|
|
90
92
|
|
|
91
|
-
- `r.min_px($
|
|
93
|
+
- `r.min_px($value, $type, $range: mobile, $override-coef: null, $override-floor: null)`
|
|
92
94
|
- 用途:计算 clamp 最小值。
|
|
93
95
|
- 规则:
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
+
- 命名 type:按 `max(designPx * coef(type), floor(type))` 计算(floor 来自 `floors.mobile/desktop`)。
|
|
97
|
+
- 数字 type:可直接传系数(例如 `0.6`),此时跳过 type 表查询;可选叠加 `override-floor`。
|
|
96
98
|
|
|
97
99
|
- `r.coef($type, $range: mobile)`
|
|
98
100
|
- 用途:读取 `coefficients.mobile/desktop` 中对应 type 的系数。
|
|
99
101
|
|
|
102
|
+
- `r._floor($type, $range: mobile)`
|
|
103
|
+
- 用途:读取 `floors.mobile/desktop` 中对应 type 的绝对兜底值。
|
|
104
|
+
|
|
100
105
|
- `r.clamp_pc($pc, $min)`
|
|
101
106
|
- 用途:生成 PC clamp。
|
|
102
107
|
- 结构:`clamp($min, calc($pc * var(--px-to-vw)), $pc)`。
|
|
@@ -572,10 +572,11 @@ function toScssMap(obj) {
|
|
|
572
572
|
function generateResponsiveScss(cfg) {
|
|
573
573
|
const mobileMap = toScssMap(cfg.coefficients.mobile)
|
|
574
574
|
const desktopMap = toScssMap(cfg.coefficients.desktop)
|
|
575
|
+
const mobileFloorMap = toScssMap(cfg.floors?.mobile ?? {})
|
|
576
|
+
const desktopFloorMap = toScssMap(cfg.floors?.desktop ?? {})
|
|
575
577
|
|
|
576
578
|
return `@use "sass:map";
|
|
577
579
|
@use "sass:math";
|
|
578
|
-
@use "sass:list";
|
|
579
580
|
@use "sass:meta";
|
|
580
581
|
|
|
581
582
|
// Generated by scss-kit from ${CONFIG_NAME}
|
|
@@ -589,6 +590,10 @@ $coef-mobile: ${mobileMap};
|
|
|
589
590
|
|
|
590
591
|
$coef-desktop: ${desktopMap};
|
|
591
592
|
|
|
593
|
+
$floor-mobile: ${mobileFloorMap};
|
|
594
|
+
|
|
595
|
+
$floor-desktop: ${desktopFloorMap};
|
|
596
|
+
|
|
592
597
|
@function _to-px($value) {
|
|
593
598
|
@return if(math.is-unitless($value), $value * 1px, $value);
|
|
594
599
|
}
|
|
@@ -614,25 +619,36 @@ $coef-desktop: ${desktopMap};
|
|
|
614
619
|
@error "Unknown coef type: #{$type}";
|
|
615
620
|
}
|
|
616
621
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
622
|
+
@function _floor($type, $range: mobile) {
|
|
623
|
+
$table: if($range == desktop, $floor-desktop, $floor-mobile);
|
|
624
|
+
@if map.has-key($table, $type) {
|
|
625
|
+
@return map.get($table, $type);
|
|
626
|
+
}
|
|
627
|
+
@return null;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// 根据设计稿 px + 系数推导 clamp() 最小值:max(design * coef, floor)。
|
|
631
|
+
// $type 可传命名类型(字符串)或直接传数字系数(跳过系数表查询,不使用 floor)。
|
|
632
|
+
@function min_px($value, $type, $range: mobile, $override-coef: null, $override-floor: null) {
|
|
633
|
+
$v: _to-px($value);
|
|
620
634
|
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
$typography-types: (h1, h2, h3, body, small, button-text);
|
|
627
|
-
@if list.index($typography-types, $type) {
|
|
628
|
-
$scaled-375: $v * math.div(375, ${cfg.design.mobileWidth});
|
|
629
|
-
$floor: if($type == h1, 16px, if($type == h2, 14px, 12px));
|
|
630
|
-
@return math.min($v, math.max($scaled-375, $floor));
|
|
635
|
+
// 直接传数字系数:跳过类型表,直接以系数计算
|
|
636
|
+
@if meta.type-of($type) == number {
|
|
637
|
+
$min: $v * $type;
|
|
638
|
+
@if $override-floor != null {
|
|
639
|
+
@return math.max($min, _to-px($override-floor));
|
|
631
640
|
}
|
|
641
|
+
@return $min;
|
|
632
642
|
}
|
|
633
643
|
|
|
634
644
|
$c: if($override-coef == null, coef($type, $range), $override-coef);
|
|
635
|
-
|
|
645
|
+
$min: $v * $c;
|
|
646
|
+
|
|
647
|
+
$f: if($override-floor != null, _to-px($override-floor), _floor($type, $range));
|
|
648
|
+
@if $f {
|
|
649
|
+
@return math.max($min, $f);
|
|
650
|
+
}
|
|
651
|
+
@return $min;
|
|
636
652
|
}
|
|
637
653
|
|
|
638
654
|
// 生成桌面段 clamp:min + calc(pc * var(--px-to-vw)) + pc
|
|
@@ -662,11 +678,9 @@ $coef-desktop: ${desktopMap};
|
|
|
662
678
|
@return calc(#{$n} * var(--px-to-vw-mb));
|
|
663
679
|
}
|
|
664
680
|
|
|
665
|
-
// vw(): spacing-first helper
|
|
681
|
+
// vw(): spacing-first helper(间距优先,默认不设最小值)
|
|
666
682
|
// - PC: min(vw, px)
|
|
667
|
-
// - Mobile:
|
|
668
|
-
// - arg1: pc
|
|
669
|
-
// - arg2: mobile (used by autofill scanner for mobile overrides)
|
|
683
|
+
// - Mobile: 纯 vw(通过 autofill 覆盖生成)
|
|
670
684
|
@function vw($pc, $mobile) {
|
|
671
685
|
@if meta.type-of($pc) != number or meta.type-of($mobile) != number {
|
|
672
686
|
@error "vw() expects numeric px values for both pc and mobile";
|
|
@@ -48,6 +48,13 @@
|
|
|
48
48
|
"mobile": {"type": "object", "additionalProperties": {"type": "number"}},
|
|
49
49
|
"desktop": {"type": "object", "additionalProperties": {"type": "number"}}
|
|
50
50
|
}
|
|
51
|
+
},
|
|
52
|
+
"floors": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"properties": {
|
|
55
|
+
"mobile": {"type": "object", "additionalProperties": {"type": "string"}},
|
|
56
|
+
"desktop": {"type": "object", "additionalProperties": {"type": "string"}}
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
}
|