Skip to content

Commit 1c6e084

Browse files
committed
Enable ts strict mode, refactor tag dialog
1 parent cad70e3 commit 1c6e084

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+351
-365
lines changed

_includes/script-theme.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
savedTheme = THEME_AUTO
1212
localStorage.setItem(KEY_THEME, savedTheme)
1313
}
14-
const bodyE = document.getElementsByTagName("body")[0];
14+
const bodyE = document.body;
1515
// 默认是没有.dark的,在确定是暗黑模式时加上.dark
1616
// 默认是没有theme-color的,在这里根据主题加上
1717
if (savedTheme === THEME_DARK

_posts/original/2021-08-03-为博客添加站内搜索和暗黑模式.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const KEY_THEME = "theme"
101101
// 读取保存的用户主题设置
102102
const savedTheme = localStorage.getItem(KEY_THEME)
103103
console.log("saved theme = " + savedTheme)
104-
const bodyE = document.querySelector("body")
104+
const bodyE = document.body
105105
// 根据用户设置显示对应主题
106106
if (savedTheme == THEME_DARK) {
107107
bodyE.classList.add("dark")

npm/dist/blog-404-v2.0.0.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/dist/blog-index-v2.0.0.js

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/dist/blog-index-v2.0.0.js.LICENSE.txt

-19
This file was deleted.

npm/dist/blog-post-v2.0.0.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/dist/blog-runtime-v2.0.0.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/dist/blog-scaffold-v2.0.0.js

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/src/base/ResizeHeightObserver.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import { consoleDebug } from "../util/log"
22

33
export class ResizeHeightObserver {
44
callback: (width: number) => void
5-
lastTimeout: NodeJS.Timeout = null
5+
lastTimeout: NodeJS.Timeout | null = null
66
lastHeight = -1
77
resizeObserver = new ResizeObserver((entries) => {
88
const entry = entries.pop()
9-
if (entry.contentRect.height == this.lastHeight) {
9+
if (entry!!.contentRect.height == this.lastHeight) {
1010
// 高度没有变化
1111
return
1212
}
13-
this.lastHeight = entry.contentRect.height
13+
this.lastHeight = entry!!.contentRect.height
1414
if (this.lastTimeout != null) {
1515
clearTimeout(this.lastTimeout)
1616
}
1717
this.lastTimeout = setTimeout(() => {
18-
consoleDebug("ResizeHeightObserver height changed after delay " + entry.contentRect.height)
19-
this.callback(entry.contentRect.height)
18+
consoleDebug("ResizeHeightObserver height changed after delay " + entry!!.contentRect.height)
19+
this.callback(entry!!.contentRect.height)
2020
}, 200)
2121
})
2222
constructor(e: HTMLElement, callback: (height: number) => void) {

npm/src/base/ResizeWidthObserver.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ import { consoleDebug } from "../util/log"
22

33
export class ResizeWidthObserver {
44
callback: (width: number) => void
5-
lastTimeout: NodeJS.Timeout = null
5+
lastTimeout: NodeJS.Timeout | null = null
66
lastWidth = -1
77
resizeObserver = new ResizeObserver((entries) => {
88
const entry = entries.pop()
9-
if (entry.contentRect.width == this.lastWidth) {
9+
if (entry!!.contentRect.width == this.lastWidth) {
1010
// 宽度没有变化
1111
return
1212
}
13-
if (entry.contentRect.width == 0) {
13+
if (entry!!.contentRect.width == 0) {
1414
// 宽度变为0是什么情况🙄
1515
return
1616
}
17-
this.lastWidth = entry.contentRect.width
17+
this.lastWidth = entry!!.contentRect.width
1818
if (this.lastTimeout != null) {
1919
clearTimeout(this.lastTimeout)
2020
}
2121
this.lastTimeout = setTimeout(() => {
22-
consoleDebug("ResizeWidthObserver width changed after delay " + entry.contentRect.width)
23-
this.callback(entry.contentRect.width)
22+
consoleDebug("ResizeWidthObserver width changed after delay " + entry!!.contentRect.width)
23+
this.callback(entry!!.contentRect.width)
2424
}, 200)
2525
})
2626
constructor(e: HTMLElement, callback: (width: number) => void) {

npm/src/base/ScrollLoader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { consoleDebug } from "../util/log"
33
export class ScrollLoader {
44
timeMsIgnore: number
55
shouldLoad: () => void
6-
lastLoadTime: number
6+
lastLoadTime: number = 0
77
constructor(shouldLoad: () => void, timeMsIgnore: number = 50) {
88
this.shouldLoad = shouldLoad
99
this.timeMsIgnore = timeMsIgnore

npm/src/component/animation/HeightAnimationContainer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class HeightAnimationContainer {
1010
containerE: HTMLElement
1111
contentE: HTMLElement
1212
lastHeight: number
13-
resizeWidthObserver: ResizeWidthObserver
13+
resizeWidthObserver: ResizeWidthObserver | null = null
1414

1515
constructor(animationContainerE: HTMLElement) {
1616
this.containerE = animationContainerE

npm/src/component/animation/ImageLoadAnimator.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { getElementAttribute } from "../../util/tools"
77
*/
88
export class ImageLoadAnimator {
99
imgE: HTMLImageElement
10-
id: string
11-
widthResizeObserver: ResizeWidthObserver
10+
id: string | null
11+
widthResizeObserver: ResizeWidthObserver | null = null
1212

1313
/**
1414
* 为图片加载添加高度变化动画
1515
* @param imgE 目标图片元素
1616
* @param ratio 图片宽高比
1717
* @param monitorResize 是否监听宽度变化,动画调整高度,false会在加载完成后设置高度为auto,之后不会再有动画
1818
*/
19-
constructor(imgE: HTMLImageElement, ratio: number = -1, monitorResize: boolean = false, animationEndCallback: () => void = null) {
19+
constructor(imgE: HTMLImageElement, ratio: number = -1, monitorResize: boolean = false, animationEndCallback: (() => void) | null = null) {
2020
this.imgE = imgE
2121
this.id = getElementAttribute(imgE, "alt")
2222

@@ -66,7 +66,7 @@ export class ImageLoadAnimator {
6666
})
6767
}
6868

69-
private animationDone(monitorResize: boolean, imgE: HTMLImageElement, animationEndCallback: () => void) {
69+
private animationDone(monitorResize: boolean, imgE: HTMLImageElement, animationEndCallback: (() => void) | null) {
7070
if (!monitorResize) {
7171
imgE.classList.remove("height-animation")
7272
imgE.style.height = "auto"

npm/src/component/contentCard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export function initContentCard(startAnimation: boolean) {
88

99
export function startContentCardAnimation() {
1010
const cardE = document.querySelector(".content-card.fade-in-animation")
11-
cardE.classList.add("fade-in-animation--start")
11+
cardE?.classList.add("fade-in-animation--start")
1212
}

0 commit comments

Comments
 (0)