@waline/client 2.15.8 → 3.0.0-alpha.2

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.
Files changed (139) hide show
  1. package/dist/comment.cjs +1 -1
  2. package/dist/comment.cjs.map +1 -1
  3. package/dist/comment.d.cts +2 -1
  4. package/dist/comment.d.mts +2 -1
  5. package/dist/comment.d.ts +2 -1
  6. package/dist/comment.js +1 -1
  7. package/dist/comment.js.map +1 -1
  8. package/dist/comment.mjs +1 -1
  9. package/dist/comment.mjs.map +1 -1
  10. package/dist/component.mjs +8 -1
  11. package/dist/component.mjs.map +1 -1
  12. package/dist/pageview.cjs +1 -1
  13. package/dist/pageview.cjs.map +1 -1
  14. package/dist/pageview.d.cts +2 -1
  15. package/dist/pageview.d.mts +2 -1
  16. package/dist/pageview.d.ts +2 -1
  17. package/dist/pageview.js +1 -1
  18. package/dist/pageview.js.map +1 -1
  19. package/dist/pageview.mjs +1 -1
  20. package/dist/pageview.mjs.map +1 -1
  21. package/dist/shim.cjs +8 -1
  22. package/dist/shim.cjs.map +1 -1
  23. package/dist/shim.d.cts +7 -82
  24. package/dist/shim.d.mts +7 -82
  25. package/dist/shim.mjs +8 -1
  26. package/dist/shim.mjs.map +1 -1
  27. package/dist/waline.cjs +53 -1
  28. package/dist/waline.cjs.map +1 -1
  29. package/dist/waline.css +1 -1
  30. package/dist/waline.css.map +1 -1
  31. package/dist/waline.d.cts +7 -82
  32. package/dist/waline.d.mts +7 -82
  33. package/dist/waline.d.ts +7 -82
  34. package/dist/waline.js +53 -1
  35. package/dist/waline.js.map +1 -1
  36. package/dist/waline.mjs +53 -1
  37. package/dist/waline.mjs.map +1 -1
  38. package/package.json +20 -53
  39. package/dist/api.cjs +0 -2
  40. package/dist/api.cjs.map +0 -1
  41. package/dist/api.d.cts +0 -445
  42. package/dist/api.d.mts +0 -445
  43. package/dist/api.d.ts +0 -445
  44. package/dist/api.mjs +0 -2
  45. package/dist/api.mjs.map +0 -1
  46. package/dist/legacy.umd.d.ts +0 -628
  47. package/dist/legacy.umd.js +0 -2
  48. package/dist/legacy.umd.js.map +0 -1
  49. package/src/api/articleCounter.ts +0 -82
  50. package/src/api/comment.ts +0 -258
  51. package/src/api/commentCount.ts +0 -33
  52. package/src/api/index.ts +0 -7
  53. package/src/api/login.ts +0 -96
  54. package/src/api/pageview.ts +0 -54
  55. package/src/api/recentComment.ts +0 -42
  56. package/src/api/user.ts +0 -44
  57. package/src/api/utils.ts +0 -46
  58. package/src/comment.ts +0 -69
  59. package/src/compact/convert.ts +0 -80
  60. package/src/compact/dropped.ts +0 -35
  61. package/src/compact/index.ts +0 -4
  62. package/src/compact/logger.ts +0 -5
  63. package/src/compact/v1.ts +0 -103
  64. package/src/compact/valine.ts +0 -132
  65. package/src/components/ArticleReaction.vue +0 -159
  66. package/src/components/CommentBox.vue +0 -807
  67. package/src/components/CommentCard.vue +0 -271
  68. package/src/components/Icons.ts +0 -181
  69. package/src/components/ImageWall.vue +0 -169
  70. package/src/components/WalineComment.vue +0 -353
  71. package/src/composables/index.ts +0 -6
  72. package/src/composables/inputs.ts +0 -17
  73. package/src/composables/like.ts +0 -13
  74. package/src/composables/reaction.ts +0 -15
  75. package/src/composables/recaptchaV3.ts +0 -19
  76. package/src/composables/turnstile.ts +0 -50
  77. package/src/composables/userInfo.ts +0 -16
  78. package/src/config/default.ts +0 -93
  79. package/src/config/highlighter.ts +0 -74
  80. package/src/config/i18n/en.ts +0 -53
  81. package/src/config/i18n/generate.ts +0 -58
  82. package/src/config/i18n/index.ts +0 -30
  83. package/src/config/i18n/jp.ts +0 -53
  84. package/src/config/i18n/pt-BR.ts +0 -53
  85. package/src/config/i18n/ru.ts +0 -53
  86. package/src/config/i18n/vi-VN.ts +0 -53
  87. package/src/config/i18n/zh-CN.ts +0 -53
  88. package/src/config/i18n/zh-TW.ts +0 -53
  89. package/src/config/index.ts +0 -3
  90. package/src/entries/api.ts +0 -1
  91. package/src/entries/comment.ts +0 -2
  92. package/src/entries/components.ts +0 -2
  93. package/src/entries/full.ts +0 -7
  94. package/src/entries/init.ts +0 -4
  95. package/src/entries/legacy.ts +0 -31
  96. package/src/entries/pageview.ts +0 -2
  97. package/src/init.ts +0 -112
  98. package/src/pageview.ts +0 -116
  99. package/src/shims-vue.d.ts +0 -6
  100. package/src/styles/base.scss +0 -67
  101. package/src/styles/card.scss +0 -258
  102. package/src/styles/config.scss +0 -52
  103. package/src/styles/emoji.scss +0 -137
  104. package/src/styles/gif.scss +0 -73
  105. package/src/styles/helpers/_svg.scss +0 -51
  106. package/src/styles/highlight.scss +0 -138
  107. package/src/styles/index.scss +0 -12
  108. package/src/styles/layout.scss +0 -105
  109. package/src/styles/meta.scss +0 -82
  110. package/src/styles/normalize.scss +0 -117
  111. package/src/styles/panel.scss +0 -286
  112. package/src/styles/reaction.scss +0 -103
  113. package/src/styles/recent.scss +0 -3
  114. package/src/styles/user-list.scss +0 -159
  115. package/src/typings/base.ts +0 -123
  116. package/src/typings/comment.ts +0 -94
  117. package/src/typings/index.ts +0 -5
  118. package/src/typings/locale.ts +0 -73
  119. package/src/typings/options.ts +0 -44
  120. package/src/typings/waline.ts +0 -251
  121. package/src/utils/config.ts +0 -122
  122. package/src/utils/darkmode.ts +0 -11
  123. package/src/utils/date.ts +0 -71
  124. package/src/utils/email.ts +0 -8
  125. package/src/utils/emoji.ts +0 -73
  126. package/src/utils/error.ts +0 -3
  127. package/src/utils/getRoot.ts +0 -8
  128. package/src/utils/image.ts +0 -10
  129. package/src/utils/index.ts +0 -13
  130. package/src/utils/markdown.ts +0 -41
  131. package/src/utils/markedMathExtension.ts +0 -54
  132. package/src/utils/path.ts +0 -15
  133. package/src/utils/query.ts +0 -2
  134. package/src/utils/userAgent.ts +0 -31
  135. package/src/utils/wordCount.ts +0 -31
  136. package/src/version.ts +0 -3
  137. package/src/widgets/index.ts +0 -2
  138. package/src/widgets/recentComments.ts +0 -93
  139. package/src/widgets/userList.ts +0 -136
@@ -1,94 +0,0 @@
1
- export interface WalineCommentData {
2
- /**
3
- * User Nickname
4
- */
5
- nick: string;
6
-
7
- /**
8
- * User email
9
- */
10
- mail: string;
11
-
12
- /**
13
- * User link
14
- */
15
- link?: string;
16
-
17
- /**
18
- * Content of comment
19
- */
20
- comment: string;
21
-
22
- /**
23
- * User Agent
24
- */
25
- ua: string;
26
-
27
- /**
28
- * Parent comment id
29
- */
30
-
31
- pid?: string;
32
-
33
- /**
34
- * Root comment id
35
- */
36
- rid?: string;
37
-
38
- /**
39
- * User id being at
40
- */
41
- at?: string;
42
-
43
- /**
44
- * Comment link
45
- */
46
- url: string;
47
-
48
- /**
49
- * Recaptcha Token
50
- */
51
- recaptchaV3?: string;
52
-
53
- /**
54
- * Turnstile Token
55
- */
56
- turnstile?: string;
57
- }
58
-
59
- export type WalineCommentStatus = 'approved' | 'waiting' | 'spam';
60
-
61
- export interface WalineComment extends Exclude<WalineCommentData, 'ua'> {
62
- /**
63
- * User avatar
64
- */
65
- avatar: string;
66
-
67
- /**
68
- * User type
69
- */
70
- type?: 'administrator' | 'guest' | `verify:${string}`;
71
-
72
- objectId: string;
73
-
74
- /**
75
- * Time ISOString when the comment is created
76
- */
77
- createdAt: string;
78
-
79
- insertedAt: string;
80
- updatedAt: string;
81
- children: WalineComment[];
82
- sticky?: boolean;
83
- browser?: string;
84
- os?: string;
85
- level?: number;
86
- addr?: string;
87
- label?: string;
88
- // TODO: Rename it to `userId` in next major version
89
- // eslint-disable-next-line @typescript-eslint/naming-convention
90
- user_id?: string | number;
91
- status?: WalineCommentStatus;
92
- like?: number;
93
- orig?: string;
94
- }
@@ -1,5 +0,0 @@
1
- export * from './base';
2
- export * from './comment';
3
- export * from './locale';
4
- export * from './waline';
5
- export * from './options';
@@ -1,73 +0,0 @@
1
- export interface WalineDateLocale {
2
- seconds: string;
3
- minutes: string;
4
- hours: string;
5
- days: string;
6
- now: string;
7
- }
8
-
9
- export type WalineLevelLocale = Record<`level${number}`, string>;
10
-
11
- export interface WalineReactionLocale {
12
- reactionTitle: string;
13
- reaction0: string;
14
- reaction1: string;
15
- reaction2: string;
16
- reaction3: string;
17
- reaction4: string;
18
- reaction5: string;
19
- reaction6: string;
20
- reaction7: string;
21
- reaction8: string;
22
- }
23
-
24
- export interface WalineLocale
25
- extends WalineDateLocale,
26
- WalineLevelLocale,
27
- WalineReactionLocale {
28
- nick: string;
29
- mail: string;
30
- link: string;
31
- optional: string;
32
- placeholder: string;
33
- sofa: string;
34
- submit: string;
35
- comment: string;
36
- refresh: string;
37
- more: string;
38
- uploading: string;
39
- login: string;
40
- admin: string;
41
- sticky: string;
42
- word: string;
43
- anonymous: string;
44
- gif: string;
45
- gifSearchPlaceholder: string;
46
-
47
- // manage
48
- approved: string;
49
- waiting: string;
50
- spam: string;
51
- unsticky: string;
52
-
53
- // sorting
54
- oldest: string;
55
- latest: string;
56
- hottest: string;
57
-
58
- // hint
59
- nickError: string;
60
- mailError: string;
61
- wordHint: string;
62
-
63
- // i18n
64
- like: string;
65
- cancelLike: string;
66
- reply: string;
67
- cancelReply: string;
68
- preview: string;
69
- emoji: string;
70
- uploadImage: string;
71
- profile: string;
72
- logout: string;
73
- }
@@ -1,44 +0,0 @@
1
- import { type WalineProps } from './waline.js';
2
-
3
- export interface WalineInitOptions extends Omit<WalineProps, 'path'> {
4
- /**
5
- * Waline 的初始化挂载器。必须是一个**有效的** CSS 选择器 或 HTML 元素
6
- *
7
- * The DOM element to be mounted on initialization. It must be a **valid** CSS selector string or HTML Element.
8
- */
9
- el?: string | HTMLElement | null;
10
-
11
- /**
12
- * 评论数统计
13
- *
14
- * Comment number support
15
- *
16
- * @default false
17
- */
18
- comment?: string | boolean;
19
-
20
- /**
21
- * 页面访问量统计
22
- *
23
- * Pageview number support
24
- *
25
- * @default false
26
- */
27
- pageview?: string | boolean;
28
-
29
- /**
30
- * 当前 _文章页_ 路径,用于区分不同的 _文章页_ ,以保证正确读取该 _文章页_ 下的评论列表
31
- *
32
- * 你可以将其设置为 `window.location.pathname`
33
- *
34
- * Article path id. Used to distinguish different _article pages_ to ensure loading the correct comment list under the _article page_.
35
- *
36
- * You can set it to `window.location.pathname`
37
- *
38
- * @default window.location.pathname
39
- */
40
- path?: string;
41
- }
42
-
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- export type WalineAbort = (reason?: any) => void;
@@ -1,251 +0,0 @@
1
- import {
2
- type WalineCommentSorting,
3
- type WalineHighlighter,
4
- type WalineEmojiInfo,
5
- type WalineEmojiPresets,
6
- type WalineImageUploader,
7
- type WalineLoginStatus,
8
- type WalineMeta,
9
- type WalineTeXRenderer,
10
- type WalineSearchOptions,
11
- } from './base.js';
12
- import { type WalineLocale } from './locale.js';
13
-
14
- export interface WalineProps {
15
- /**
16
- * Waline 的服务端地址
17
- *
18
- * Waline server address url
19
- */
20
- serverURL: string;
21
-
22
- /**
23
- * 当前 _文章页_ 路径,用于区分不同的 _文章页_ ,以保证正确读取该 _文章页_ 下的评论列表
24
- *
25
- * 你可以将其设置为 `window.location.pathname`
26
- *
27
- * Article path id. Used to distinguish different _article pages_ to ensure loading the correct comment list under the _article page_.
28
- *
29
- * You can set it to `window.location.pathname`
30
- */
31
- path: string;
32
-
33
- /**
34
- * 评论者相关属性
35
- *
36
- * `Meta` 可选值: `'nick'`, `'mail'`, `'link'`
37
- *
38
- * Reviewer attributes.
39
- *
40
- * Optional values for `Meta`: `'nick'`, `'mail'`, `'link'`
41
- *
42
- * @default ['nick', 'mail', 'link']
43
- */
44
- meta?: WalineMeta[];
45
-
46
- /**
47
- * 设置**必填项**,默认昵称为匿名
48
- *
49
- * Set required fields, default anonymous with nickname
50
- *
51
- * @default []
52
- */
53
- requiredMeta?: WalineMeta[];
54
-
55
- /**
56
- * 评论字数限制。填入单个数字时为最大字数限制
57
- *
58
- * @more 设置为 `0` 时无限制
59
- *
60
- * Comment word s limit. When a single number is filled in, it 's the maximum number of comment words.
61
- *
62
- * @more No limit when set to `0`.
63
- *
64
- * @default 0
65
- */
66
- wordLimit?: number | [number, number];
67
-
68
- /**
69
- * 评论列表分页,每页条数
70
- *
71
- * number of pages per page
72
- *
73
- * @default 10
74
- */
75
- pageSize?: number;
76
-
77
- /**
78
- * Waline 显示语言
79
- *
80
- * 可选值:
81
- *
82
- * - `'zh'`
83
- * - `'zh-cn'`
84
- * - `'zh-CN'`
85
- * - `'zh-tw'`
86
- * - `'zh-TW'`
87
- * - `'en'`
88
- * - `'en-US'`
89
- * - `'en-us'`
90
- * - `'jp'`
91
- * - `'jp-jp'`
92
- * - `'jp-JP'`
93
- * - `'pt-br'`
94
- * - `'pt-BR'`
95
- * - `'ru'`
96
- * - `'ru-ru'`
97
- * - `'ru-RU'`
98
- *
99
- * Display language for waline
100
- *
101
- * Optional value:
102
- *
103
- * - `'zh'`
104
- * - `'zh-cn'`
105
- * - `'zh-CN'`
106
- * - `'zh-tw'`
107
- * - `'zh-TW'`
108
- * - `'en'`
109
- * - `'en-US'`
110
- * - `'en-us'`
111
- * - `'jp'`
112
- * - `'jp-jp'`
113
- * - `'jp-JP'`
114
- * - `'pt-br'`
115
- * - `'pt-BR'`
116
- * - `'ru'`
117
- * - `'ru-ru'`
118
- * - `'ru-RU'`
119
- *
120
- * @default navigator.language
121
- */
122
- lang?: string;
123
-
124
- /**
125
- * 自定义 waline 语言显示
126
- *
127
- * @see [自定义语言](https://waline.js.org/client/i18n.html)
128
- *
129
- * Custom display language in waline
130
- *
131
- * @see [I18n](https://waline.js.org/en/client/i18n.html)
132
- */
133
- locale?: Partial<WalineLocale>;
134
-
135
- /**
136
- * 评论列表排序方式
137
- *
138
- * Sorting method for comment list
139
- *
140
- * @default 'latest'
141
- */
142
- commentSorting?: WalineCommentSorting;
143
-
144
- /**
145
- * 是否启用暗黑模式适配
146
- *
147
- * @more 设置 `'auto'` 会根据设备暗黑模式自适应。填入 CSS 选择器会在对应选择器生效时启用夜间模式。
148
- *
149
- * Whether to enable darkmode support
150
- *
151
- * @more Setting `'auto'` will display darkmode due to device settings. Filling in CSS selector will enable darkmode only when the selector match waline ancestor nodes.
152
- */
153
- dark?: string | boolean;
154
-
155
- /**
156
- * 设置表情包
157
- *
158
- * Set Emojis
159
- *
160
- * @default ['//unpkg.com/@waline/emojis@1.1.0/weibo']
161
- */
162
- emoji?: (WalineEmojiInfo | WalineEmojiPresets)[] | boolean;
163
-
164
- /**
165
- * 设置搜索功能
166
- *
167
- * Customize Search feature
168
- *
169
- * @default true
170
- */
171
- search?: WalineSearchOptions | boolean;
172
-
173
- /**
174
- * 代码高亮
175
- *
176
- * Code highlighting
177
- *
178
- * @default true
179
- */
180
-
181
- highlighter?: WalineHighlighter | boolean;
182
-
183
- /**
184
- * 自定义图片上传方法,方便更好的存储图片
185
- *
186
- * 方法执行时会将图片对象传入。
187
- *
188
- * Custom image upload callback to manage picture by yourself.
189
- *
190
- * We will pass a picture file object when execute it.
191
- *
192
- * @default true
193
- */
194
-
195
- imageUploader?: WalineImageUploader | boolean;
196
-
197
- /**
198
- * 自定义数学公式处理方法,用于预览。
199
- *
200
- * Custom math formula parse callback for preview.
201
- *
202
- * @default true
203
- */
204
- texRenderer?: WalineTeXRenderer | boolean;
205
-
206
- /**
207
- *
208
- * 登录模式状态,可选值:
209
- *
210
- * - `'enable'`: 启用登录 (默认)
211
- * - `'disable'`: 禁用登录,用户只能填写信息评论
212
- * - `'force'`: 强制登录,用户必须注册并登录才可发布评论
213
- *
214
- * Login mode status, optional values:
215
- *
216
- * - `'enable'`: enable login (default)
217
- * - `'disable'`: Login is disabled, users should fill in information to comment
218
- * - `'force'`: Forced login, users must login to comment
219
- *
220
- * @default 'enable'
221
- */
222
- login?: WalineLoginStatus;
223
-
224
- /**
225
- * 是否在页脚展示版权信息
226
- *
227
- * 为了支持 Waline,我们强烈建议你开启它
228
- *
229
- * Whether show copyright in footer
230
- *
231
- * We strongly recommended you to keep it on to support waline
232
- *
233
- * @default true
234
- */
235
- copyright?: boolean;
236
-
237
- /**
238
- * recaptcha v3 client key
239
- */
240
- recaptchaV3Key?: string;
241
-
242
- /**
243
- * turnstile client key
244
- */
245
- turnstileKey?: string;
246
-
247
- /**
248
- * reaction
249
- */
250
- reaction?: string[] | boolean;
251
- }
@@ -1,122 +0,0 @@
1
- import { decodePath, isLinkHttp, removeEndingSplash } from './path.js';
2
- import {
3
- DEFAULT_EMOJI,
4
- DEFAULT_LANG,
5
- DEFAULT_LOCALES,
6
- DEFAULT_REACTION,
7
- defaultUploadImage,
8
- defaultHighlighter,
9
- defaultTeXRenderer,
10
- getDefaultSearchOptions,
11
- getMeta,
12
- } from '../config/index.js';
13
- import {
14
- type WalineEmojiInfo,
15
- type WalineEmojiMaps,
16
- type WalineLocale,
17
- type WalineProps,
18
- } from '../typings/index.js';
19
-
20
- export interface WalineEmojiConfig {
21
- tabs: Pick<WalineEmojiInfo, 'name' | 'icon' | 'items'>[];
22
- map: WalineEmojiMaps;
23
- }
24
-
25
- export interface WalineConfig
26
- extends Required<
27
- Omit<
28
- WalineProps,
29
- | 'emoji'
30
- | 'imageUploader'
31
- | 'highlighter'
32
- | 'texRenderer'
33
- | 'wordLimit'
34
- | 'reaction'
35
- | 'search'
36
- >
37
- > {
38
- locale: WalineLocale;
39
- wordLimit: [number, number] | false;
40
- reaction: string[];
41
- emoji: Exclude<WalineProps['emoji'], boolean | undefined>;
42
- highlighter: Exclude<WalineProps['highlighter'], true | undefined>;
43
- imageUploader: Exclude<WalineProps['imageUploader'], true | undefined>;
44
- texRenderer: Exclude<WalineProps['texRenderer'], true | undefined>;
45
- search: Exclude<WalineProps['search'], true | undefined>;
46
- }
47
-
48
- export const getServerURL = (serverURL: string): string => {
49
- const result = removeEndingSplash(serverURL);
50
-
51
- return isLinkHttp(result) ? result : `https://${result}`;
52
- };
53
-
54
- const getWordLimit = (
55
- wordLimit: WalineProps['wordLimit'],
56
- ): [number, number] | false =>
57
- Array.isArray(wordLimit) ? wordLimit : wordLimit ? [0, wordLimit] : false;
58
-
59
- const fallback = <T = unknown>(
60
- value: T | boolean | undefined,
61
- fallback: T,
62
- ): T | false =>
63
- typeof value === 'function' ? value : value === false ? false : fallback;
64
-
65
- export const getConfig = ({
66
- serverURL,
67
-
68
- path = location.pathname,
69
- lang = typeof navigator === 'undefined' ? 'en-US' : navigator.language,
70
- locale,
71
- emoji = DEFAULT_EMOJI,
72
- meta = ['nick', 'mail', 'link'],
73
- requiredMeta = [],
74
- dark = false,
75
- pageSize = 10,
76
- wordLimit,
77
- imageUploader,
78
- highlighter,
79
- texRenderer,
80
- copyright = true,
81
- login = 'enable',
82
- search,
83
- reaction,
84
- recaptchaV3Key = '',
85
- turnstileKey = '',
86
- commentSorting = 'latest',
87
- ...more
88
- }: WalineProps): WalineConfig => ({
89
- serverURL: getServerURL(serverURL),
90
- path: decodePath(path),
91
- locale: {
92
- ...(DEFAULT_LOCALES[lang] || DEFAULT_LOCALES[DEFAULT_LANG]),
93
- ...(typeof locale === 'object' ? locale : {}),
94
- } as WalineLocale,
95
- wordLimit: getWordLimit(wordLimit),
96
- meta: getMeta(meta),
97
- requiredMeta: getMeta(requiredMeta),
98
- imageUploader: fallback(imageUploader, defaultUploadImage),
99
- highlighter: fallback(highlighter, defaultHighlighter),
100
- texRenderer: fallback(texRenderer, defaultTeXRenderer),
101
- lang: Object.keys(DEFAULT_LOCALES).includes(lang) ? lang : 'en-US',
102
- dark,
103
- emoji: typeof emoji === 'boolean' ? (emoji ? DEFAULT_EMOJI : []) : emoji,
104
- pageSize,
105
- login,
106
- copyright,
107
- search:
108
- search === false
109
- ? false
110
- : typeof search === 'object'
111
- ? search
112
- : getDefaultSearchOptions(lang),
113
- recaptchaV3Key,
114
- turnstileKey,
115
- reaction: Array.isArray(reaction)
116
- ? reaction
117
- : reaction === true
118
- ? DEFAULT_REACTION
119
- : [],
120
- commentSorting,
121
- ...more,
122
- });
@@ -1,11 +0,0 @@
1
- const style = `{--waline-white:#000;--waline-light-grey:#666;--waline-dark-grey:#999;--waline-color:#888;--waline-bgcolor:#1e1e1e;--waline-bgcolor-light:#272727;--waline-bgcolor-hover: #444;--waline-border-color:#333;--waline-disable-bgcolor:#444;--waline-disable-color:#272727;--waline-bq-color:#272727;--waline-info-bgcolor:#272727;--waline-info-color:#666}`;
2
-
3
- export const getDarkStyle = (selector?: string | boolean): string => {
4
- if (typeof selector === 'string') {
5
- return selector === 'auto'
6
- ? `@media(prefers-color-scheme:dark){body${style}}`
7
- : `${selector}${style}`;
8
- }
9
-
10
- return selector === true ? `:root${style}` : '';
11
- };
package/src/utils/date.ts DELETED
@@ -1,71 +0,0 @@
1
- import { WalineDateLocale } from '../typings';
2
-
3
- const padWithZeros = (vNumber: number, width: number): string => {
4
- let numAsString = vNumber.toString();
5
-
6
- while (numAsString.length < width) {
7
- numAsString = '0' + numAsString;
8
- }
9
-
10
- return numAsString;
11
- };
12
-
13
- export const dateFormat = (date: Date): string => {
14
- const vDay = padWithZeros(date.getDate(), 2);
15
- const vMonth = padWithZeros(date.getMonth() + 1, 2);
16
- const vYear = padWithZeros(date.getFullYear(), 2);
17
-
18
- return `${vYear}-${vMonth}-${vDay}`;
19
- };
20
-
21
- export const getTimeAgo = (
22
- date: Date | string,
23
- now: Date,
24
- locale: WalineDateLocale,
25
- ): string => {
26
- if (!date) return '';
27
-
28
- const time =
29
- typeof date === 'string'
30
- ? new Date(date.indexOf(' ') !== -1 ? date.replace(/-/g, '/') : date)
31
- : date;
32
-
33
- const timePassed = now.getTime() - time.getTime();
34
-
35
- const days = Math.floor(timePassed / (24 * 3600 * 1000));
36
-
37
- if (days === 0) {
38
- // 计算相差小时数
39
-
40
- // 计算天数后剩余的毫秒数
41
- const leave1 = timePassed % (24 * 3600 * 1000);
42
- const hours = Math.floor(leave1 / (3600 * 1000));
43
-
44
- if (hours === 0) {
45
- //计算相差分钟数
46
-
47
- // 计算小时数后剩余的毫秒数
48
- const leave2 = leave1 % (3600 * 1000);
49
- const minutes = Math.floor(leave2 / (60 * 1000));
50
-
51
- // 计算相差秒数
52
- if (minutes === 0) {
53
- // 计算分钟数后剩余的毫秒数
54
- const leave3 = leave2 % (60 * 1000);
55
- const seconds = Math.round(leave3 / 1000);
56
-
57
- return `${seconds} ${locale.seconds}`;
58
- }
59
-
60
- return `${minutes} ${locale.minutes}`;
61
- }
62
-
63
- return `${hours} ${locale.hours}`;
64
- }
65
-
66
- if (days < 0) return locale.now;
67
-
68
- if (days < 8) return `${days} ${locale.days}`;
69
-
70
- return dateFormat(time);
71
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * @ref https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
3
- */
4
- const EMAIL_REG_EXP =
5
- /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
6
-
7
- export const isValidEmail = (email: string): boolean =>
8
- EMAIL_REG_EXP.test(email);