@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,353 +0,0 @@
1
- <template>
2
- <div data-waline>
3
- <Reaction />
4
-
5
- <CommentBox v-if="!reply" @log="refresh" @submit="onSubmit" />
6
-
7
- <div class="wl-meta-head">
8
- <div class="wl-count">
9
- <span v-if="count" class="wl-num" v-text="count" />
10
- {{ i18n.comment }}
11
- </div>
12
-
13
- <ul class="wl-sort">
14
- <li
15
- v-for="item in sortingMethods"
16
- :key="item"
17
- :class="[item === commentSortingRef ? 'active' : '']"
18
- @click="onSortByChange(item)"
19
- >
20
- {{ i18n[item] }}
21
- </li>
22
- </ul>
23
- </div>
24
-
25
- <div class="wl-cards">
26
- <CommentCard
27
- v-for="comment in data"
28
- :key="comment.objectId"
29
- :root-id="comment.objectId"
30
- :comment="comment"
31
- :reply="reply"
32
- :edit="edit"
33
- @log="refresh"
34
- @reply="onReply"
35
- @edit="onEdit"
36
- @submit="onSubmit"
37
- @status="onStatusChange"
38
- @delete="onDelete"
39
- @sticky="onSticky"
40
- @like="onLike"
41
- />
42
- </div>
43
-
44
- <div v-if="status === 'error'" class="wl-operation">
45
- <button
46
- type="button"
47
- class="wl-btn"
48
- @click="refresh"
49
- v-text="i18n.refresh"
50
- />
51
- </div>
52
-
53
- <template v-else>
54
- <div v-if="status === 'loading'" class="wl-loading">
55
- <LoadingIcon :size="30" />
56
- </div>
57
-
58
- <div v-else-if="!data.length" class="wl-empty" v-text="i18n.sofa" />
59
-
60
- <!-- Load more button -->
61
- <div v-else-if="page < totalPages" class="wl-operation">
62
- <button
63
- type="button"
64
- class="wl-btn"
65
- @click="loadMore"
66
- v-text="i18n.more"
67
- />
68
- </div>
69
- </template>
70
-
71
- <!-- Copyright Information -->
72
- <div v-if="config.copyright" class="wl-power">
73
- Powered by
74
- <a
75
- href="https://github.com/walinejs/waline"
76
- target="_blank"
77
- rel="noopener noreferrer"
78
- >
79
- Waline
80
- </a>
81
- v{{ version }}
82
- </div>
83
- </div>
84
- </template>
85
-
86
- <script setup lang="ts">
87
- /* eslint-disable vue/define-props-declaration */
88
- /* eslint-disable vue/no-unused-properties */
89
- /* eslint-disable vue/require-prop-comment */
90
- /* eslint-disable vue/require-prop-types */
91
- import { useStyleTag } from '@vueuse/core';
92
- import { computed, onMounted, onUnmounted, provide, ref, watch } from 'vue';
93
-
94
- import Reaction from './ArticleReaction.vue';
95
- import CommentBox from './CommentBox.vue';
96
- import CommentCard from './CommentCard.vue';
97
- import { LoadingIcon } from './Icons.js';
98
- import { deleteComment, getComment, updateComment } from '../api/index.js';
99
- import { useUserInfo, useLikeStorage } from '../composables/index.js';
100
- import {
101
- type WalineComment,
102
- type WalineCommentSorting,
103
- type WalineCommentStatus,
104
- type WalineProps,
105
- } from '../typings/index.js';
106
- import { getConfig, getDarkStyle } from '../utils/index.js';
107
- import { version } from '../version.js';
108
-
109
- type SortKey = 'insertedAt_desc' | 'insertedAt_asc' | 'like_desc';
110
-
111
- const props = defineProps([
112
- 'serverURL',
113
- 'path',
114
- 'meta',
115
- 'requiredMeta',
116
- 'dark',
117
- 'commentSorting',
118
- 'lang',
119
- 'locale',
120
- 'pageSize',
121
- 'wordLimit',
122
- 'emoji',
123
- 'login',
124
- 'highlighter',
125
- 'texRenderer',
126
- 'imageUploader',
127
- 'search',
128
- 'copyright',
129
- 'recaptchaV3Key',
130
- 'turnstileKey',
131
- 'reaction',
132
- ]);
133
-
134
- const sortKeyMap: Record<WalineCommentSorting, SortKey> = {
135
- latest: 'insertedAt_desc',
136
- oldest: 'insertedAt_asc',
137
- hottest: 'like_desc',
138
- };
139
- const sortingMethods = Object.keys(sortKeyMap) as WalineCommentSorting[];
140
-
141
- const userInfo = useUserInfo();
142
- const likeStorage = useLikeStorage();
143
-
144
- const status = ref<'loading' | 'success' | 'error'>('loading');
145
-
146
- const count = ref(0);
147
- const page = ref(1);
148
- const totalPages = ref(0);
149
-
150
- const config = computed(() => getConfig(props as WalineProps));
151
-
152
- // eslint-disable-next-line vue/no-ref-object-destructure
153
- const commentSortingRef = ref(config.value.commentSorting);
154
-
155
- const data = ref<WalineComment[]>([]);
156
- const reply = ref<WalineComment | null>(null);
157
- const edit = ref<WalineComment | null>(null);
158
-
159
- const darkmodeStyle = computed(() => getDarkStyle(config.value.dark));
160
-
161
- const i18n = computed(() => config.value.locale);
162
-
163
- useStyleTag(darkmodeStyle, { id: 'waline-darkmode' });
164
-
165
- let abort: () => void;
166
-
167
- const getCommentData = (pageNumber: number): void => {
168
- const { serverURL, path, pageSize } = config.value;
169
- const controller = new AbortController();
170
-
171
- status.value = 'loading';
172
-
173
- abort?.();
174
-
175
- getComment({
176
- serverURL,
177
- lang: config.value.lang,
178
- path,
179
- pageSize,
180
- sortBy: sortKeyMap[commentSortingRef.value],
181
- page: pageNumber,
182
- signal: controller.signal,
183
- token: userInfo.value?.token,
184
- })
185
- .then((resp) => {
186
- status.value = 'success';
187
- count.value = resp.count;
188
- data.value.push(...resp.data);
189
- page.value = pageNumber;
190
- totalPages.value = resp.totalPages;
191
- })
192
- .catch((err: Error) => {
193
- if (err.name !== 'AbortError') {
194
- console.error(err.message);
195
- status.value = 'error';
196
- }
197
- });
198
-
199
- abort = controller.abort.bind(controller);
200
- };
201
-
202
- const loadMore = (): void => getCommentData(page.value + 1);
203
-
204
- const refresh = (): void => {
205
- count.value = 0;
206
- data.value = [];
207
- getCommentData(1);
208
- };
209
-
210
- const onSortByChange = (item: WalineCommentSorting): void => {
211
- if (commentSortingRef.value !== item) {
212
- commentSortingRef.value = item;
213
- refresh();
214
- }
215
- };
216
-
217
- const onReply = (comment: WalineComment | null): void => {
218
- reply.value = comment;
219
- };
220
-
221
- const onEdit = (comment: WalineComment | null): void => {
222
- edit.value = comment;
223
- };
224
-
225
- const onSubmit = (comment: WalineComment): void => {
226
- if (edit.value) {
227
- edit.value.comment = comment.comment;
228
- edit.value.orig = comment.orig;
229
- } else if (comment.rid) {
230
- const repliedComment = data.value.find(
231
- ({ objectId }) => objectId === comment.rid,
232
- );
233
-
234
- if (!repliedComment) return;
235
-
236
- if (!Array.isArray(repliedComment.children)) repliedComment.children = [];
237
-
238
- repliedComment.children.push(comment);
239
- } else {
240
- data.value.unshift(comment);
241
- count.value += 1;
242
- }
243
- };
244
-
245
- const onStatusChange = async ({
246
- comment,
247
- status,
248
- }: {
249
- comment: WalineComment;
250
- status: WalineCommentStatus;
251
- }): Promise<void> => {
252
- if (comment.status === status) return;
253
-
254
- const { serverURL, lang } = config.value;
255
-
256
- await updateComment({
257
- serverURL,
258
- lang,
259
- token: userInfo.value?.token,
260
- objectId: comment.objectId,
261
- comment: { status },
262
- });
263
-
264
- comment.status = status;
265
- };
266
-
267
- const onSticky = async (comment: WalineComment): Promise<void> => {
268
- if (comment.rid) return;
269
-
270
- const { serverURL, lang } = config.value;
271
-
272
- await updateComment({
273
- serverURL,
274
- lang,
275
- token: userInfo.value?.token,
276
- objectId: comment.objectId,
277
- comment: { sticky: comment.sticky ? 0 : 1 },
278
- });
279
-
280
- comment.sticky = !comment.sticky;
281
- };
282
-
283
- const onDelete = async ({ objectId }: WalineComment): Promise<void> => {
284
- if (!confirm('Are you sure you want to delete this comment?')) return;
285
-
286
- const { serverURL, lang } = config.value;
287
-
288
- await deleteComment({
289
- serverURL,
290
- lang,
291
- token: userInfo.value?.token,
292
- objectId,
293
- });
294
-
295
- // delete comment from data
296
- data.value.some((item, index) => {
297
- if (item.objectId === objectId) {
298
- data.value = data.value.filter((_item, i) => i !== index);
299
-
300
- return true;
301
- }
302
-
303
- return item.children.some((child, childIndex) => {
304
- if (child.objectId === objectId) {
305
- data.value[index].children = item.children.filter(
306
- (_item, i) => i !== childIndex,
307
- );
308
-
309
- return true;
310
- }
311
-
312
- return false;
313
- });
314
- });
315
- };
316
-
317
- const onLike = async (comment: WalineComment): Promise<void> => {
318
- const { serverURL, lang } = config.value;
319
- const { objectId } = comment;
320
- const hasLiked = likeStorage.value.includes(objectId);
321
-
322
- await updateComment({
323
- serverURL,
324
- lang,
325
- objectId,
326
- token: userInfo.value?.token,
327
- comment: { like: !hasLiked },
328
- });
329
-
330
- if (hasLiked)
331
- likeStorage.value = likeStorage.value.filter((id) => id !== objectId);
332
- else {
333
- likeStorage.value = [...likeStorage.value, objectId];
334
-
335
- if (likeStorage.value.length > 50)
336
- likeStorage.value = likeStorage.value.slice(-50);
337
- }
338
-
339
- comment.like = (comment.like || 0) + (hasLiked ? -1 : 1);
340
- };
341
-
342
- provide('config', config);
343
-
344
- onMounted(() => {
345
- watch(
346
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
347
- () => [props.serverURL, props.path],
348
- () => refresh(),
349
- { immediate: true },
350
- );
351
- });
352
- onUnmounted(() => abort?.());
353
- </script>
@@ -1,6 +0,0 @@
1
- export * from './inputs';
2
- export * from './like';
3
- export * from './reaction';
4
- export * from './recaptchaV3';
5
- export * from './turnstile';
6
- export * from './userInfo';
@@ -1,17 +0,0 @@
1
- import { type RemovableRef, useStorage } from '@vueuse/core';
2
-
3
- export interface UserMeta {
4
- nick: string;
5
- mail: string;
6
- link: string;
7
- }
8
-
9
- export const useUserMeta = (): RemovableRef<UserMeta> =>
10
- useStorage<UserMeta>('WALINE_USER_META', {
11
- nick: '',
12
- mail: '',
13
- link: '',
14
- });
15
-
16
- export const useEditor = (): RemovableRef<string> =>
17
- useStorage<string>('WALINE_COMMENT_BOX_EDITOR', '');
@@ -1,13 +0,0 @@
1
- import { useStorage } from '@vueuse/core';
2
- import { type Ref } from 'vue';
3
-
4
- const LIKE_KEY = 'WALINE_LIKE';
5
-
6
- export type LikeID = number | string;
7
-
8
- export type LikeRef = Ref<LikeID[]>;
9
-
10
- let likeStorage: LikeRef | null = null;
11
-
12
- export const useLikeStorage = (): LikeRef =>
13
- likeStorage || (likeStorage = useStorage<LikeID[]>(LIKE_KEY, []));
@@ -1,15 +0,0 @@
1
- import { useStorage } from '@vueuse/core';
2
- import { type Ref } from 'vue';
3
-
4
- const REACTION_KEY = 'WALINE_REACTION';
5
-
6
- export interface WalineReactionStore {
7
- [VOTE_IDENTIFIER: string]: number | undefined;
8
- }
9
-
10
- export type VoteRef = Ref<WalineReactionStore>;
11
-
12
- let reactionStorage: VoteRef | null = null;
13
-
14
- export const useReactionStorage = (): VoteRef =>
15
- (reactionStorage ??= useStorage<WalineReactionStore>(REACTION_KEY, {}));
@@ -1,19 +0,0 @@
1
- import { type ReCaptchaInstance, load } from 'recaptcha-v3';
2
-
3
- const recaptchaStore: Record<string, Promise<ReCaptchaInstance>> = {};
4
-
5
- interface ReCaptcha {
6
- execute: (action: string) => Promise<string>;
7
- }
8
-
9
- export const useReCaptcha = (key: string): ReCaptcha => {
10
- const init = (recaptchaStore[key] ??= load(key, {
11
- useRecaptchaNet: true,
12
- autoHideBadge: true,
13
- }));
14
-
15
- return {
16
- execute: (action: string) =>
17
- init.then((instance) => instance.execute(action)),
18
- };
19
- };
@@ -1,50 +0,0 @@
1
- import { useScriptTag } from '@vueuse/core';
2
-
3
- interface TurnstileOptions {
4
- sitekey: string;
5
- action?: string;
6
- size?: 'normal' | 'compact';
7
- callback?: (token: string) => void;
8
- }
9
- interface TurnstileInstance {
10
- ready: (fn: () => void) => void;
11
- excute: (className: string, options?: TurnstileOptions) => void;
12
- render: (className: string, options?: TurnstileOptions) => void;
13
- }
14
-
15
- declare global {
16
- interface Window {
17
- turnstile?: TurnstileInstance;
18
- }
19
- }
20
-
21
- interface Turnstile {
22
- execute: (action: string) => Promise<string>;
23
- }
24
-
25
- export const useTurnstile = (key: string): Turnstile => {
26
- const execute = async (action: string): Promise<string> => {
27
- const { load } = useScriptTag(
28
- 'https://challenges.cloudflare.com/turnstile/v0/api.js',
29
- undefined,
30
- { async: false },
31
- );
32
-
33
- await load();
34
-
35
- const turnstile = window?.turnstile;
36
-
37
- return new Promise((resolve) => {
38
- turnstile?.ready(() => {
39
- turnstile?.render('.wl-captcha-container', {
40
- sitekey: key,
41
- action,
42
- size: 'compact',
43
- callback: resolve,
44
- });
45
- });
46
- });
47
- };
48
-
49
- return { execute };
50
- };
@@ -1,16 +0,0 @@
1
- import { useStorage } from '@vueuse/core';
2
- import { type Ref } from 'vue';
3
-
4
- import { type UserInfo } from '../api/index.js';
5
-
6
- export const USER_KEY = 'WALINE_USER';
7
-
8
- export type UserInfoRef = Ref<UserInfo | Record<string, never>>;
9
-
10
- let userInfoStorage: UserInfoRef | null = null;
11
-
12
- export const useUserInfo = (): UserInfoRef =>
13
- (userInfoStorage ??= useStorage<UserInfo | Record<string, never>>(
14
- USER_KEY,
15
- {},
16
- ));
@@ -1,93 +0,0 @@
1
- import { type IGif } from '@giphy/js-types';
2
-
3
- import {
4
- type WalineEmojiPresets,
5
- type WalineMeta,
6
- type WalineSearchOptions,
7
- type WalineSearchResult,
8
- } from '../typings/index.js';
9
-
10
- const AVAILABLE_META: WalineMeta[] = ['nick', 'mail', 'link'];
11
-
12
- export const getMeta = (meta: WalineMeta[]): WalineMeta[] =>
13
- meta.filter((item) => AVAILABLE_META.includes(item));
14
-
15
- export const DEFAULT_EMOJI: WalineEmojiPresets[] = [
16
- '//unpkg.com/@waline/emojis@1.1.0/weibo',
17
- ];
18
-
19
- export const DEFAULT_LANG = 'en-US';
20
-
21
- export const DEFAULT_REACTION = [
22
- '//unpkg.com/@waline/emojis/tieba/tieba_agree.png',
23
- '//unpkg.com/@waline/emojis/tieba/tieba_look_down.png',
24
- '//unpkg.com/@waline/emojis/tieba/tieba_sunglasses.png',
25
- '//unpkg.com/@waline/emojis/tieba/tieba_pick_nose.png',
26
- '//unpkg.com/@waline/emojis/tieba/tieba_awkward.png',
27
- '//unpkg.com/@waline/emojis/tieba/tieba_sleep.png',
28
- ];
29
-
30
- export const defaultUploadImage = (file: File): Promise<string> =>
31
- new Promise((resolve, reject) => {
32
- if (file.size > 128 * 1000)
33
- return reject(new Error('File too large! File size limit 128KB'));
34
-
35
- const reader = new FileReader();
36
-
37
- reader.readAsDataURL(file);
38
- reader.onload = (): void => resolve(reader.result?.toString() || '');
39
- reader.onerror = reject;
40
- });
41
-
42
- export const defaultTeXRenderer = (blockMode: boolean): string =>
43
- blockMode === true
44
- ? '<p class="wl-tex">TeX is not available in preview</p>'
45
- : '<span class="wl-tex">TeX is not available in preview</span>';
46
-
47
- export const getDefaultSearchOptions = (lang: string): WalineSearchOptions => {
48
- interface GifResult {
49
- data: IGif[];
50
- meta: {
51
- msg: string;
52
- // eslint-disable-next-line @typescript-eslint/naming-convention
53
- response_id: string;
54
- status: number;
55
- };
56
- pagination: {
57
- count: number;
58
- // eslint-disable-next-line @typescript-eslint/naming-convention
59
- total_count: number;
60
- offset: number;
61
- };
62
- }
63
-
64
- const fetchGiphy = async (
65
- url: string,
66
- params: Record<string, string> = {},
67
- ): Promise<WalineSearchResult> =>
68
- fetch(
69
- `https://api.giphy.com/v1/gifs/${url}?${new URLSearchParams({
70
- lang,
71
- limit: '20',
72
- rating: 'g',
73
- // eslint-disable-next-line @typescript-eslint/naming-convention
74
- api_key: '6CIMLkNMMOhRcXPoMCPkFy4Ybk2XUiMp',
75
- ...params,
76
- }).toString()}`,
77
- )
78
- .then((resp) => <Promise<GifResult>>resp.json())
79
- .then(({ data }) =>
80
- data.map((gif) => ({
81
- title: gif.title,
82
- src: gif.images.downsized_medium.url,
83
- })),
84
- );
85
-
86
- return {
87
- search: (word: string): Promise<WalineSearchResult> =>
88
- fetchGiphy('search', { q: word, offset: '0' }),
89
- default: (): Promise<WalineSearchResult> => fetchGiphy('trending', {}),
90
- more: (word: string, offset = 0): Promise<WalineSearchResult> =>
91
- fetchGiphy('search', { q: word, offset: offset.toString() }),
92
- };
93
- };
@@ -1,74 +0,0 @@
1
- /**
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) egoist <0x142857@gmail.com> (https://egoistian.com)
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in
14
- * all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- * THE SOFTWARE.
23
- *
24
- */
25
-
26
- const WORD_REGEXP =
27
- /[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/;
28
- const LEFT_ANGLE_REGEXP = /</;
29
- const LINE_COMMENT_REGEXP = /(?:^|\s)\/\/(.+?)$/gm;
30
- const BLOCK_COMMENT_REGEXP = /\/\*([\S\s]*?)\*\//gm;
31
- const REGEXP = new RegExp(
32
- `(${WORD_REGEXP.source}|${LEFT_ANGLE_REGEXP.source})|((?:${LINE_COMMENT_REGEXP.source})|(?:${BLOCK_COMMENT_REGEXP.source}))`,
33
- 'gmi',
34
- );
35
-
36
- const COLORS = [
37
- '23AC69',
38
- '91C132',
39
- 'F19726',
40
- 'E8552D',
41
- '1AAB8E',
42
- 'E1147F',
43
- '2980C1',
44
- '1BA1E6',
45
- '9FA0A0',
46
- 'F19726',
47
- 'E30B20',
48
- 'E30B20',
49
- 'A3338B',
50
- ];
51
- const cache: Record<string, string> = {};
52
-
53
- export const defaultHighlighter = (input: string): string => {
54
- let index = 0;
55
-
56
- return input.replace(REGEXP, (_match, word: string, comment: string) => {
57
- if (comment) return `<span style="color: slategray">${comment}</span>`;
58
- if (word === '<') return '&lt;';
59
-
60
- let color: string;
61
-
62
- if (cache[word]) color = cache[word];
63
- else {
64
- color = COLORS[index];
65
- cache[word] = color;
66
- }
67
-
68
- const out = `<span style="color: #${color}">${word}</span>`;
69
-
70
- index = ++index % COLORS.length;
71
-
72
- return out;
73
- });
74
- };