webc.com 0.1.22 → 0.1.24
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/README.md +59 -1
- package/index.js +1 -4
- package/package.json +1 -1
- package/styl/reset.styl +273 -0
package/README.md
CHANGED
|
@@ -12,7 +12,65 @@
|
|
|
12
12
|
|
|
13
13
|
点击组件右上角的『在线调试』可以调试无打包的组件。
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
### 1. CDN 直接引用 (无需打包)
|
|
18
|
+
|
|
19
|
+
对于无需打包、直接在浏览器中引用的使用场景,你可以通过 CDN 直接引用 JS 与 CSS 文件。
|
|
20
|
+
|
|
21
|
+
以 `Scroll` 组件(虚拟滚动条)为例:
|
|
22
|
+
|
|
23
|
+
#### 使用 jsdelivr:
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<link href="//cdn.jsdelivr.net/npm/webc.site@0.1.23/Scroll.css" rel="stylesheet" />
|
|
27
|
+
<script type="module">
|
|
28
|
+
import "//cdn.jsdelivr.net/npm/webc.site@0.1.23/Scroll.js";
|
|
29
|
+
</script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### 使用 淘宝镜像 npmmirror(对中国大陆线路友好):
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<link href="//registry.npmmirror.com/webc.site/0.1.23/files/Scroll.css" rel="stylesheet" />
|
|
36
|
+
<script type="module">
|
|
37
|
+
import "//registry.npmmirror.com/webc.site/0.1.23/files/Scroll.js";
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### 2. 按需添加至本地项目 (用于构建打包)
|
|
44
|
+
|
|
45
|
+
项目支持类似于 [shadcn](https://ui.shadcn.com) 的按需添加组件机制。如果你使用构建工具,可在你的项目中直接运行以下命令将组件下载并添加至本地:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
bunx webc.add <组件名>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
例如添加 `Scroll` 组件(虚拟滚动条):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
bunx webc.add Scroll
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**命令行实现机制:**
|
|
58
|
+
|
|
59
|
+
- 运行该命令时,它会向 npm 注册表查询并解析 `webc.com` 对应的包源。
|
|
60
|
+
- 自动下载包源文件并提取对应的组件源码,将其按需编译并输出到本地项目中对应的 `lib/组件名` 目录下,且会把组件相关的 Stylus 自动编译成 CSS 放入公共样式中。
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 3. 配合 `vite-plugin-svg-var` 优化 SVG 资源
|
|
65
|
+
|
|
66
|
+
为了优化打包体积并大幅减少网络请求,建议在 Vite 构建器中配合使用 [vite-plugin-svg-var](https://www.npmjs.com/package/vite-plugin-svg-var) 插件。
|
|
67
|
+
|
|
68
|
+
#### 插件的用途与核心特性:
|
|
69
|
+
|
|
70
|
+
- **智能去重**:自动对 `public/svg` 下的所有 SVG 内容进行 MD5 哈希计算。即使不同路径或文件名对应同一个 SVG 内容,也只会在 CSS 中生成单一变量,所有引用都将映射到该变量,避免冗余打包。
|
|
71
|
+
- **UTF-8 安全编码**:将 SVG 直接转换为更轻量、体积更小的 UTF-8 编码 `data:image/svg+xml` URL 写入 CSS 变量,比传统的 Base64 编码方式体积更小、压缩率更高。
|
|
72
|
+
- **自动注入与替换**:在构建或运行开发服务器时,它会自动在项目入口 JS(如匹配 `/page/entry/**/*.js`)中注入虚拟的 CSS 变量样式,并将 CSS/Stylus/Svelte 中原本引用的 `url("/svg/xxx.svg")` 自动替换为 CSS 变量形式(如 `var(--xxxSvg)`)。这意味着所有 SVG 将被直接内联合并在 CSS 中,页面加载时无需发起任何多余的 SVG 图片 HTTP 请求。
|
|
73
|
+
- **开发阶段热更新 (HMR)**:自动监听 `public/svg` 文件夹,当新增、删除或修改 SVG 文件时,插件会自动重新扫描并生成 CSS 变量,且触发模块热重载,方便高效调试。
|
|
16
74
|
|
|
17
75
|
## 初衷
|
|
18
76
|
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"webc.com","version":"0.1.
|
|
1
|
+
{"name":"webc.com","version":"0.1.24","description":"","keywords":[],"homepage":"https://webc-zh.github.io","license":"MulanPSL-2.0","author":"i18n.site@gmail.com","repository":{"type":"git","url":"git+https://github.com/webc-zh/webc-zh.github.io.git"},"bin":{"webc-i":"./cli.js"},"files":["./*"],"type":"module","exports":{"./*":"./*"},"scripts":{},"dependencies":{"@3-/read":"^0.1.4","ansis":"^4.3.0","stylus":"^0.64.0","tar":"^7.5.15","yargs":"^18.0.0"},"devDependencies":{}}
|
package/styl/reset.styl
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Please read: https://github.com/unocss/unocss/blob/main/packages-presets/reset/tailwind-compat.md
|
|
3
|
+
*/
|
|
4
|
+
/*
|
|
5
|
+
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
|
|
6
|
+
2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
|
|
7
|
+
2. [UnoCSS]: allow to override the default border color with css var `--un-default-border-color`
|
|
8
|
+
*/
|
|
9
|
+
*, ::before, ::after
|
|
10
|
+
border-color var(--un-default-border-color, #e5e7eb) /* 2 */
|
|
11
|
+
border-style solid /* 2 */
|
|
12
|
+
border-width 0 /* 2 */
|
|
13
|
+
box-sizing border-box /* 1 */
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
1. Use a consistent sensible line-height in all browsers.
|
|
17
|
+
2. Prevent adjustments of font size after orientation changes in iOS.
|
|
18
|
+
3. Use a more readable tab size.
|
|
19
|
+
4. Use the user's configured `sans` font-family by default.
|
|
20
|
+
5. Use the user's configured `sans` font-feature-settings by default.
|
|
21
|
+
6. Use the user's configured `sans` font-variation-settings by default.
|
|
22
|
+
7. Disable tap highlights on iOS.
|
|
23
|
+
*/
|
|
24
|
+
html, :host
|
|
25
|
+
font-family ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji' /* 4 */
|
|
26
|
+
font-feature-settings normal /* 5 */
|
|
27
|
+
font-variation-settings normal /* 6 */
|
|
28
|
+
line-height 1.5 /* 1 */
|
|
29
|
+
tab-size 4 /* 3 */
|
|
30
|
+
-moz-tab-size 4 /* 3 */
|
|
31
|
+
-webkit-tap-highlight-color transparent /* 7 */
|
|
32
|
+
-webkit-text-size-adjust 100% /* 2 */
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
1. Remove the margin in all browsers.
|
|
36
|
+
2. Inherit line-height from `html` so users can set them as a class directly on the `html` element.
|
|
37
|
+
*/
|
|
38
|
+
body
|
|
39
|
+
line-height inherit /* 2 */
|
|
40
|
+
margin 0 /* 1 */
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
1. Add the correct height in Firefox.
|
|
44
|
+
2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
|
|
45
|
+
3. Ensure horizontal rules are visible by default.
|
|
46
|
+
*/
|
|
47
|
+
hr
|
|
48
|
+
border-top-width 1px /* 3 */
|
|
49
|
+
color inherit /* 2 */
|
|
50
|
+
height 0 /* 1 */
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
Add the correct text decoration in Chrome, Edge, and Safari.
|
|
54
|
+
*/
|
|
55
|
+
abbr:where([title])
|
|
56
|
+
text-decoration underline dotted
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
Remove the default font size and weight for headings.
|
|
60
|
+
*/
|
|
61
|
+
h1, h2, h3, h4, h5, h6
|
|
62
|
+
font-size inherit
|
|
63
|
+
font-weight inherit
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
Reset links to optimize for opt-in styling instead of opt-out.
|
|
67
|
+
*/
|
|
68
|
+
a
|
|
69
|
+
color inherit
|
|
70
|
+
text-decoration inherit
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
Add the correct font weight in Edge and Safari.
|
|
74
|
+
*/
|
|
75
|
+
b, strong
|
|
76
|
+
font-weight bolder
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
1. Use the user's configured `mono` font-family by default.
|
|
80
|
+
2. Use the user's configured `mono` font-feature-settings by default.
|
|
81
|
+
3. Use the user's configured `mono` font-variation-settings by default.
|
|
82
|
+
4. Correct the odd `em` font sizing in all browsers.
|
|
83
|
+
*/
|
|
84
|
+
code, kbd, samp, pre
|
|
85
|
+
font-family ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace /* 1 */
|
|
86
|
+
font-feature-settings normal /* 2 */
|
|
87
|
+
font-size 1em /* 4 */
|
|
88
|
+
font-variation-settings normal /* 3 */
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
Add the correct font size in all browsers.
|
|
92
|
+
*/
|
|
93
|
+
small
|
|
94
|
+
font-size 80%
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
Prevent `sub` and `sup` elements from affecting the line height in all browsers.
|
|
98
|
+
*/
|
|
99
|
+
sub, sup
|
|
100
|
+
font-size 75%
|
|
101
|
+
line-height 0
|
|
102
|
+
position relative
|
|
103
|
+
vertical-align baseline
|
|
104
|
+
|
|
105
|
+
sub
|
|
106
|
+
bottom -0.25em
|
|
107
|
+
|
|
108
|
+
sup
|
|
109
|
+
top -0.5em
|
|
110
|
+
|
|
111
|
+
/*
|
|
112
|
+
1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
|
|
113
|
+
2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
|
|
114
|
+
3. Remove gaps between table borders by default.
|
|
115
|
+
*/
|
|
116
|
+
table
|
|
117
|
+
border-collapse collapse /* 3 */
|
|
118
|
+
border-color inherit /* 2 */
|
|
119
|
+
text-indent 0 /* 1 */
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
1. Change the font styles in all browsers.
|
|
123
|
+
2. Remove the margin in Firefox and Safari.
|
|
124
|
+
3. Remove default padding in all browsers.
|
|
125
|
+
*/
|
|
126
|
+
button, input, optgroup, select, textarea
|
|
127
|
+
color inherit /* 1 */
|
|
128
|
+
font-family inherit /* 1 */
|
|
129
|
+
font-feature-settings inherit /* 1 */
|
|
130
|
+
font-size 100% /* 1 */
|
|
131
|
+
font-variation-settings inherit /* 1 */
|
|
132
|
+
font-weight inherit /* 1 */
|
|
133
|
+
line-height inherit /* 1 */
|
|
134
|
+
margin 0 /* 2 */
|
|
135
|
+
padding 0 /* 3 */
|
|
136
|
+
|
|
137
|
+
/*
|
|
138
|
+
Remove the inheritance of text transform in Edge and Firefox.
|
|
139
|
+
*/
|
|
140
|
+
button, select
|
|
141
|
+
text-transform none
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
1. Correct the inability to style clickable types in iOS and Safari.
|
|
145
|
+
2. Remove default button styles.
|
|
146
|
+
*/
|
|
147
|
+
button, [type='button'], [type='reset'], [type='submit']
|
|
148
|
+
/* Will affect the button style of most component libraries, so disable it */
|
|
149
|
+
/* https://github.com/unocss/unocss/issues/2127 */
|
|
150
|
+
/* background-color: transparent; !* 2 *! */
|
|
151
|
+
background-image none /* 2 */
|
|
152
|
+
-webkit-appearance button /* 1 */
|
|
153
|
+
|
|
154
|
+
/*
|
|
155
|
+
Use the modern Firefox focus style for all focusable elements.
|
|
156
|
+
*/
|
|
157
|
+
:-moz-focusring
|
|
158
|
+
outline auto
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)
|
|
162
|
+
*/
|
|
163
|
+
:-moz-ui-invalid
|
|
164
|
+
box-shadow none
|
|
165
|
+
|
|
166
|
+
/*
|
|
167
|
+
Add the correct vertical alignment in Chrome and Firefox.
|
|
168
|
+
*/
|
|
169
|
+
progress
|
|
170
|
+
vertical-align baseline
|
|
171
|
+
|
|
172
|
+
/*
|
|
173
|
+
Correct the cursor style of increment and decrement buttons in Safari.
|
|
174
|
+
*/
|
|
175
|
+
::-webkit-inner-spin-button, ::-webkit-outer-spin-button
|
|
176
|
+
height auto
|
|
177
|
+
|
|
178
|
+
/*
|
|
179
|
+
1. Correct the odd appearance in Chrome and Safari.
|
|
180
|
+
2. Correct the outline style in Safari.
|
|
181
|
+
*/
|
|
182
|
+
[type='search']
|
|
183
|
+
outline-offset -2px /* 2 */
|
|
184
|
+
-webkit-appearance textfield /* 1 */
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
Remove the inner padding in Chrome and Safari on macOS.
|
|
188
|
+
*/
|
|
189
|
+
::-webkit-search-decoration
|
|
190
|
+
-webkit-appearance none
|
|
191
|
+
|
|
192
|
+
/*
|
|
193
|
+
1. Correct the inability to style clickable types in iOS and Safari.
|
|
194
|
+
2. Change font properties to `inherit` in Safari.
|
|
195
|
+
*/
|
|
196
|
+
::-webkit-file-upload-button
|
|
197
|
+
font inherit /* 2 */
|
|
198
|
+
-webkit-appearance button /* 1 */
|
|
199
|
+
|
|
200
|
+
/*
|
|
201
|
+
Add the correct display in Chrome and Safari.
|
|
202
|
+
*/
|
|
203
|
+
summary
|
|
204
|
+
display list-item
|
|
205
|
+
|
|
206
|
+
/*
|
|
207
|
+
Removes the default spacing for appropriate elements.
|
|
208
|
+
*/
|
|
209
|
+
blockquote, dl, dd, h1, h2, h3, h4, h5, h6, hr, figure, p, pre
|
|
210
|
+
margin 0
|
|
211
|
+
|
|
212
|
+
fieldset
|
|
213
|
+
margin 0
|
|
214
|
+
padding 0
|
|
215
|
+
|
|
216
|
+
legend
|
|
217
|
+
padding 0
|
|
218
|
+
|
|
219
|
+
ol, ul, menu
|
|
220
|
+
list-style none
|
|
221
|
+
margin 0
|
|
222
|
+
padding 0
|
|
223
|
+
|
|
224
|
+
dialog
|
|
225
|
+
padding 0
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
Prevent resizing textareas horizontally by default.
|
|
229
|
+
*/
|
|
230
|
+
textarea
|
|
231
|
+
resize vertical
|
|
232
|
+
|
|
233
|
+
/*
|
|
234
|
+
1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)
|
|
235
|
+
2. Set the default placeholder color to the user's configured gray 400 color.
|
|
236
|
+
*/
|
|
237
|
+
input::placeholder, textarea::placeholder
|
|
238
|
+
color #9ca3af /* 2 */
|
|
239
|
+
opacity 1 /* 1 */
|
|
240
|
+
|
|
241
|
+
/*
|
|
242
|
+
Set the default cursor for buttons.
|
|
243
|
+
*/
|
|
244
|
+
button, [role='button']
|
|
245
|
+
cursor pointer
|
|
246
|
+
|
|
247
|
+
/*
|
|
248
|
+
Make sure disabled buttons don't get the pointer cursor.
|
|
249
|
+
*/
|
|
250
|
+
:disabled
|
|
251
|
+
cursor default
|
|
252
|
+
|
|
253
|
+
/*
|
|
254
|
+
1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
|
|
255
|
+
2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
|
|
256
|
+
This can trigger a poorly considered lint error in some tools but is included by design.
|
|
257
|
+
*/
|
|
258
|
+
img, svg, video, canvas, audio, iframe, embed, object
|
|
259
|
+
display block /* 1 */
|
|
260
|
+
vertical-align middle /* 2 */
|
|
261
|
+
|
|
262
|
+
/*
|
|
263
|
+
Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)
|
|
264
|
+
*/
|
|
265
|
+
img, video
|
|
266
|
+
height auto
|
|
267
|
+
max-width 100%
|
|
268
|
+
|
|
269
|
+
/*
|
|
270
|
+
Make elements with the HTML hidden attribute stay hidden by default.
|
|
271
|
+
*/
|
|
272
|
+
[hidden]:where(:not([hidden='until-found']))
|
|
273
|
+
display none
|