Skip to content

Commit 2d417a7

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 212d692 + 91a74c3 commit 2d417a7

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

blog/2022-10-29-IntersectionObserver用法.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ authors: oxygen
1212

1313
<!--truncate-->
1414

15-
# IntersectionObserver 介绍
16-
1715
W3C 在 [2017-09-14](https://www.w3.org/standards/history/intersection-observer) 正式发布了`IntersectionObserver` API 草案,其功能上提供了检测目标元素在祖先元素或 [viewport](https://developer.mozilla.org/zh-CN/docs/Glossary/Viewport) 内可视情况变化的方式,这种观测是异步的,保证了开发上的便捷和性能上的高效。
1816

1917
## IntersectionObserver类型定义
@@ -169,7 +167,9 @@ interface IntersectionObserverEntry {
169167

170168
:::
171169

172-
## 元素是否可见的判断
170+
## IntersectionObserver用例
171+
172+
### 判断元素是否可见
173173

174174
通过`IntersectionObserver`我们可以判断元素是否可见的两种情况:
175175

@@ -197,11 +197,9 @@ interface IntersectionObserverEntry {
197197
></iframe>
198198
199199

200+
### Image Lazyload
200201

201202

202-
# IntersectionObserver用例
203-
204-
## Image Lazyload
205203

206204
<iframe src="https://codesandbox.io/embed/hopeful-poincare-uuhiob?fontsize=14&hidenavigation=1&theme=dark"
207205
width="100%"
@@ -213,7 +211,9 @@ interface IntersectionObserverEntry {
213211
></iframe>
214212
215213

216-
## Sticky Header BoxShadow
214+
### Sticky Header BoxShadow
215+
216+
217217

218218
<iframe src="https://codesandbox.io/embed/angry-taussig-e07ysx?fontsize=14&hidenavigation=1&theme=dark"
219219
width="100%"
@@ -224,7 +224,10 @@ interface IntersectionObserverEntry {
224224
loading="lazy"
225225
></iframe>
226226
227-
## Infinite Scroll
227+
228+
### Infinite Scroll
229+
230+
228231

229232
<iframe src="https://codesandbox.io/embed/intelligent-albattani-yrujgn?fontsize=14&hidenavigation=1&theme=dark"
230233
width="100%"

blog/2024-04-01-TS全局类型定义.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TypeScript 全局类型定义或者覆盖在日常开发中经常使用,本文
88

99
<!--truncate-->
1010

11-
# 使用declare global命名空间
11+
## 使用declare global命名空间
1212

1313
在包含在 TypeScript 类型检测文件目录内的任意位置新建`xxx.d.ts`文件,并使用`declare global`全局命名空间语法来定义覆盖类型,例如:
1414

@@ -66,7 +66,7 @@ export {}
6666

6767
:::
6868

69-
# 使用declare module命名空间
69+
## 使用declare module命名空间
7070

7171
如果要对一个第三方的包覆盖其类型定义,可以使用`import <module>``declare module`语法,例如覆盖`axios`的类型定义。
7272

@@ -103,9 +103,7 @@ declare module 'axios' {
103103
}
104104
```
105105

106-
107-
108-
# 使用全局模块类型声明
106+
## 使用全局模块类型声明
109107

110108
在包含在 TypeScript 类型检测文件目录内的任意位置新建`xxx.d.ts`文件,内部可以随意定义任何类型,但是不能包含任何`export``import`语句,例如:
111109

blog/2024-04-28-shadcnui.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Shadcn ui 是最近比较火的一个 React 组件库,官方介绍其并非组
1010

1111
<!--truncate-->
1212

13-
# 使用
13+
## 使用
1414

15-
## 初始化
15+
### 初始化
1616

17-
shadcn ui 依赖于 tailwindcss,来实现,所以使用 shadcn ui 的组件需要安装和配置 tailwindcss,这里就不细说了。
17+
shadcn ui 依赖于 tailwindcss,所以使用 shadcn ui 的组件需要安装和配置 tailwindcss,这里就不细说了。
1818

1919
tailwindcss 安装完就可以使用 shadcn ui 提供的 cli 工具来初始化一些配置了:
2020

@@ -26,9 +26,8 @@ npx shadcn-ui@latest init
2626

2727
![image-20240428212404577](./../public/images/image-20240428212404577.png)
2828

29-
执行这一步主要会生成一个`components.json`的配置文件,后续添加的时候需要读取这个配置文件的内容。
30-
3129
```json
30+
// components.json
3231
{
3332
"$schema": "https://ui.shadcn.com/schema.json",
3433
// 组件样式
@@ -53,7 +52,7 @@ npx shadcn-ui@latest init
5352
}
5453
```
5554

56-
## 添加组件
55+
### 添加组件
5756

5857
使用 cli 命令添加 shadcn ui 具有的组件,比如添加一个`button`组件
5958

@@ -65,17 +64,17 @@ npx shadcn-ui@latest add button
6564

6665
![shadcn-code](./../public/images/shadcn-code.png)
6766

68-
## 更新组件
67+
### 更新组件
6968

7069
shadcn 的 cli 还有一个`diff`命令用于显示组件更新,执行`diff button`可以看到其会在终端显示远端和本地存在不同的代码行,通过蓝绿色区分开,说实话,这功能感觉比较鸡肋。
7170

7271
![image-20240428214650945](./../public/images/image-20240428214650945.png)
7372

74-
## monorepo
73+
## monorepo 支持
7574

7675
shadcn ui提供的三个 cli 命令都支持通过`--cwd`来指定项目的根目录,也算是支持`monorepo`吧。
7776

78-
# cli解析
77+
## cli解析
7978

8079
shadcn 的 cli 代码基于 pnpm workspace 的结构,虽然是 monorepo 项目,但 workspace 下只有一个 cli 项目,代码目录结构还是很简洁清晰的。
8180

@@ -122,7 +121,7 @@ async function main() {
122121
main()
123122
```
124123

125-
## init
124+
### init
126125

127126
`init`方法如下,正如`init`命令定义的描述那样`initialize your project and install dependencies`,其主要工作其实就两步:
128127

@@ -179,7 +178,7 @@ export const init = new Command()
179178
})
180179
```
181180

182-
### promptForConfig
181+
#### promptForConfig
183182

184183
`promptForConfig`方法源码如下,其主要工作就是三步:
185184

@@ -254,7 +253,7 @@ export async function getRegistryBaseColors() {
254253
}
255254
```
256255

257-
### fetchRegistry
256+
#### fetchRegistry
258257

259258
`promptForConfig`内部使用的`fetchRegistry`方法,默认从`https://ui.shadcn.com`域名拉取配置,这个域名也就是shadcn ui 官方文档的域名地址。`https://ui.shadcn.com/registry/styles/index.json`获取一份主题配置,对应`components.json``style`
260259

@@ -280,7 +279,7 @@ async function fetchRegistry(paths: string[]) {
280279
}
281280
```
282281

283-
### resolveConfigPaths
282+
#### resolveConfigPaths
284283

285284
`resolveConfigPaths`内部使用`tsconfig-paths``createMatchPath`方法来对`tconfig.json`中定义的`paths`字段进行解析,可以得到一个绝对路径。
286285

@@ -390,7 +389,7 @@ export declare function createMatchPath(absoluteBaseUrl: string, paths: {
390389

391390
所以上面的`resolveImport`方法对`@/components``@/lib/utils`这样的相对路径,解析可以得到其绝对路径如`D:\code\tsconfig-path-test\src\components`
392391

393-
### runInit
392+
#### runInit
394393

395394
`runInit`方法负责生成`components``utils`等目录,以及替换`tailwind.config.ts`配置,并安装 shadcn ui 需要的第三方组件库依赖`tailwindcss-animate``class-variance-authority``clsx`等。
396395

@@ -479,7 +478,7 @@ export async function runInit(cwd: string, config: Config) {
479478
}
480479
```
481480

482-
### getPackageManager
481+
#### getPackageManager
483482

484483
`getPackageManager`方法获取项目使用的依赖管理工具,这个方法非常实用,万能!
485484

@@ -518,7 +517,7 @@ export async function getPackageManager(
518517
}
519518
```
520519

521-
## add
520+
### add
522521

523522
`add`命令的实现也比较简单,其主要实现部分的源码如下,可拆解为以下四步:
524523

@@ -614,7 +613,7 @@ const add = new Command()
614613
})
615614
```
616615

617-
### getRegistryIndex
616+
#### getRegistryIndex
618617

619618
`getRegistryIndex`会默认从远端地址——https://ui.shadcn.com/registry/index.json加载一个组件`json`,这个`json`包含了 shadcn ui 所有支持的组件信息。
620619

@@ -665,7 +664,7 @@ export const registryItemSchema = z.object({
665664
export const registryIndexSchema = z.array(registryItemSchema)
666665
```
667666

668-
### resolveTree
667+
#### resolveTree
669668

670669
在获取到远端注册的所有 shadcn ui 内部组件的信息后,`resolveTree`会对用户选择添加的组件进行依赖解析,得到所有需要添加到项目内部的组件信息。
671670

@@ -708,7 +707,7 @@ export async function resolveTree(
708707
}
709708
```
710709

711-
### fetchTree
710+
#### fetchTree
712711

713712
在获取所有要添加的组件后,使用`fetchTree`从远端加载其源码。
714713

@@ -753,7 +752,7 @@ export async function fetchTree(
753752
}
754753
```
755754

756-
### transform
755+
#### transform
757756

758757
在得到组件源码以后,从`components.json`中解析配置项`aliases.components`,得到项目存放组件的目录路径,然后使用`transform`方法对组件源码进行解析,并最终生成组件文件。
759758

@@ -826,7 +825,7 @@ export async function transform(opts: TransformOpts) {
826825
}
827826
```
828827

829-
## diff
828+
### diff
830829

831830
`diff`命令内部主要使用了[`diff`](https://github.com/kpdecker/jsdiff)对项目的组件代码和远端组件代码进行对比,然后输出到 shell 内,具体实现就不细说了,比较简单。
832831

@@ -961,40 +960,40 @@ async function buildStyles(registry: Registry) {
961960
}
962961
```
963962

964-
# shadcn 用到的一些 nodejs 工具
963+
## shadcn 用到的一些 nodejs 工具
965964

966-
## commander
965+
### commander
967966

968967
注册 nodejs cli 命令以及 cli 参数,以及获取 cli 输入,执行操作等。
969968

970-
## prompts
969+
### prompts
971970

972971
cli 输入交互
973972

974-
## zod
973+
### zod
975974

976975
`zod` 是一个用于 TypeScript 和 JavaScript 的数据验证库。它允许开发者定义一个模式(schema),这个模式描述了数据应该如何结构化,以及每个字段的类型是什么。可以在 node 和 web 环境下使用。
977976

978-
## cosmiconfig
977+
### cosmiconfig
979978

980979
查找或读取`json``yml`等配置文件
981980

982-
## tsconfig-paths
981+
### tsconfig-paths
983982

984983
解析`tsconfig.json`中定义的`paths`的模块路径。
985984

986-
## chalk
985+
### chalk
987986

988987
cli 打印颜色文字
989988

990-
## ora
989+
### ora
991990

992991
cli loading 交互效果
993992

994-
## node-fetch
993+
### node-fetch
995994

996995
nodejs 中使用 fetch
997996

998-
## tsx
997+
### tsx
999998

1000999
支持直接在 node 命令行中执行 typescript 文件。

docs/css/和文本有关的CSS属性.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ white-space: nowrap;
2727

2828
<iframe width="100%" height="390" src="https://interactive-examples.mdn.mozilla.net/pages/css/text-overflow.html" loading="lazy"></iframe>
2929

30+
## text-wrap
31+
32+
设置文本是否换行显示,以及换行的样式。设置`balance`和`pretty`会让文本显示更为优雅。
33+
34+
<iframe height="400" src="https://interactive-examples.mdn.mozilla.net/pages/css/text-wrap.html" title="MDN Web Docs Interactive Example" allow="clipboard-write" loading="lazy" data-readystate="complete"></iframe>
35+
3036
## white-space
3137

3238
`white-space`属性用来处理文本中的空白。通常用于处理一段文本是否进行换行。
@@ -63,19 +69,9 @@ white-space: nowrap;
6369

6470
### pre-line
6571

66-
连续的空白符会被**合并****在遇到换行符或者[`br`](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/br)元素**,或者需要为了填充「行框盒子([line boxes](https://www.w3.org/TR/CSS2/visuren.html#inline-formatting))」时才会换行。
67-
68-
`white-space:pre-line`这个属性很强大,尤其是在处理换行文本的时候,说到这里,又得说起不同换行符的处理情况:
69-
70-
| 系统 | 常见 | 换行符 |
71-
| ------- | ----------- | --------------- |
72-
| Unix | Linux服务器 | `\n` |
73-
| Windows | | `\r\n` |
74-
| HTML | | `<br/>`或`<br>` |
72+
**在遇到换行符或者[`br`](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/br)元素**,或者需要为了填充「行框盒子([line boxes](https://www.w3.org/TR/CSS2/visuren.html#inline-formatting))」时才会换行。
7573

76-
`\n`或者`\r\n`,如果放在字符串里然后再放到 HTML 的标签中,HTML只会将它们都处理成空格。你可能会想到将`\n`或者 `\r\n`转换成`<br>`来期望 HTML 生成换行的效果,不幸的是,如果转成`<br>`,`<br>`会被直接保留下来显示出来!
77-
78-
这时候最简单的处理方式就是使用`white-space:pre-line`,就可让 HTML 遇到换行符或者`<br>`自动换行了。
74+
`white-space:pre-line`这个属性在自动处理换行的情况很强大,当文本中包含`\n`、`\r\n`、以及`<br/>`或`<br>`时会自动换行。
7975

8076
### break-spaces
8177

@@ -222,6 +218,12 @@ CJK 文本不进行换行,非 CJK 文本表现同`word-break:normal`
222218

223219
`text-decoration-thickness`设置线的粗细,可以使用 CSS 里的长度值`<length>`,百分比值,当设置百分比值的时候,相对于当前元素字体的`1em`(`1em`也就是`1`倍字体大小)。
224220

221+
## text-underline-offset
222+
223+
设置文本下划线距离文本的偏移量。
224+
225+
<iframe height="360" width="100%" src="https://interactive-examples.mdn.mozilla.net/pages/css/text-underline-offset.html" title="MDN Web Docs Interactive Example" allow="clipboard-write" loading="lazy" data-readystate="complete"></iframe>
226+
225227
## line-clamp
226228

227229
`line-clamp`是 CSS3 规范定义的属性,用来指定块级元素内部显示的文本行数,超出指定行数的内容会被浏览器处理折叠,既不渲染也不纳入父元素文本内容的计算(某些情况例如富文本编辑需要计算编辑内容)。

0 commit comments

Comments
 (0)