diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2026-01-09 22:06:40 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-09 22:06:40 +0900 |
| commit | 41592eafb363e3c62ab2d3e5f41b38d7d083d3fb (patch) | |
| tree | 8f69243a5482ad4161eb28b69769684a221aa05c /packages/frontend/src/utility | |
| parent | fix(frontend): popupのemit型が正しく利用できるように修正 (#16... (diff) | |
| download | misskey-41592eafb363e3c62ab2d3e5f41b38d7d083d3fb.tar.gz misskey-41592eafb363e3c62ab2d3e5f41b38d7d083d3fb.tar.bz2 misskey-41592eafb363e3c62ab2d3e5f41b38d7d083d3fb.zip | |
refactor: make noImplicitAny true (#17083)
* wip
* Update emojis.emoji.vue
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update manager.ts
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* wip
* Update analytics.ts
Diffstat (limited to 'packages/frontend/src/utility')
| -rw-r--r-- | packages/frontend/src/utility/admin-lookup.ts | 8 | ||||
| -rw-r--r-- | packages/frontend/src/utility/autocomplete.ts | 2 | ||||
| -rw-r--r-- | packages/frontend/src/utility/chart-vline.ts | 2 | ||||
| -rw-r--r-- | packages/frontend/src/utility/collect-page-vars.ts | 73 | ||||
| -rw-r--r-- | packages/frontend/src/utility/deep-equal.ts | 2 | ||||
| -rw-r--r-- | packages/frontend/src/utility/element-contains.ts (renamed from packages/frontend/src/utility/contains.ts) | 5 | ||||
| -rw-r--r-- | packages/frontend/src/utility/form.ts | 36 | ||||
| -rw-r--r-- | packages/frontend/src/utility/get-embed-code.ts | 13 | ||||
| -rw-r--r-- | packages/frontend/src/utility/get-user-environment.ts | 2 | ||||
| -rw-r--r-- | packages/frontend/src/utility/snowfall-effect.ts | 22 |
10 files changed, 45 insertions, 120 deletions
diff --git a/packages/frontend/src/utility/admin-lookup.ts b/packages/frontend/src/utility/admin-lookup.ts index f393fd4ae1..74485a11d7 100644 --- a/packages/frontend/src/utility/admin-lookup.ts +++ b/packages/frontend/src/utility/admin-lookup.ts @@ -14,7 +14,7 @@ export async function lookupUser() { }); if (canceled || result == null) return; - const show = (user) => { + const show = (user: Misskey.entities.UserDetailed) => { os.pageWindow(`/admin/user/${user.id}`); }; @@ -71,12 +71,8 @@ export async function lookupFile() { }); if (canceled) return; - const show = (file) => { - os.pageWindow(`/admin/file/${file.id}`); - }; - misskeyApi('admin/drive/show-file', q.startsWith('http://') || q.startsWith('https://') ? { url: q.trim() } : { fileId: q.trim() }).then(file => { - show(file); + os.pageWindow(`/admin/file/${file.id}`); }).catch(err => { if (err.code === 'NO_SUCH_FILE') { os.alert({ diff --git a/packages/frontend/src/utility/autocomplete.ts b/packages/frontend/src/utility/autocomplete.ts index c0b1865617..4eb1e29d07 100644 --- a/packages/frontend/src/utility/autocomplete.ts +++ b/packages/frontend/src/utility/autocomplete.ts @@ -194,7 +194,7 @@ export class Autocomplete { this.currentType = type; //#region サジェストを表示すべき位置を計算 - const caretPosition = getCaretCoordinates(this.textarea, this.textarea.selectionStart); + const caretPosition = getCaretCoordinates(this.textarea, this.textarea.selectionStart ?? 0); const rect = this.textarea.getBoundingClientRect(); diff --git a/packages/frontend/src/utility/chart-vline.ts b/packages/frontend/src/utility/chart-vline.ts index 2fe4bdb83b..1097c66d0e 100644 --- a/packages/frontend/src/utility/chart-vline.ts +++ b/packages/frontend/src/utility/chart-vline.ts @@ -11,7 +11,7 @@ export const chartVLine = (vLineColor: string) => ({ const tooltip = chart.tooltip as any; if (tooltip?._active?.length) { const ctx = chart.ctx; - const xs = tooltip._active.map(a => a.element.x); + const xs = tooltip._active.map((a: any) => a.element.x) as number[]; const x = xs.reduce((a, b) => a + b, 0) / xs.length; const topY = chart.scales.y.top; const bottomY = chart.scales.y.bottom; diff --git a/packages/frontend/src/utility/collect-page-vars.ts b/packages/frontend/src/utility/collect-page-vars.ts deleted file mode 100644 index 5096c0669e..0000000000 --- a/packages/frontend/src/utility/collect-page-vars.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SPDX-FileCopyrightText: syuilo and misskey-project - * SPDX-License-Identifier: AGPL-3.0-only - */ - -interface StringPageVar { - name: string, - type: 'string', - value: string -} - -interface NumberPageVar { - name: string, - type: 'number', - value: number -} - -interface BooleanPageVar { - name: string, - type: 'boolean', - value: boolean -} - -type PageVar = StringPageVar | NumberPageVar | BooleanPageVar; - -export function collectPageVars(content): PageVar[] { - const pageVars: PageVar[] = []; - const collect = (xs: any[]): void => { - for (const x of xs) { - if (x.type === 'textInput') { - pageVars.push({ - name: x.name, - type: 'string', - value: x.default || '', - }); - } else if (x.type === 'textareaInput') { - pageVars.push({ - name: x.name, - type: 'string', - value: x.default || '', - }); - } else if (x.type === 'numberInput') { - pageVars.push({ - name: x.name, - type: 'number', - value: x.default || 0, - }); - } else if (x.type === 'switch') { - pageVars.push({ - name: x.name, - type: 'boolean', - value: x.default || false, - }); - } else if (x.type === 'counter') { - pageVars.push({ - name: x.name, - type: 'number', - value: 0, - }); - } else if (x.type === 'radioButton') { - pageVars.push({ - name: x.name, - type: 'string', - value: x.default || '', - }); - } else if (x.children) { - collect(x.children); - } - } - }; - collect(content); - return pageVars; -} diff --git a/packages/frontend/src/utility/deep-equal.ts b/packages/frontend/src/utility/deep-equal.ts index 2859641dc7..ac2c2e68da 100644 --- a/packages/frontend/src/utility/deep-equal.ts +++ b/packages/frontend/src/utility/deep-equal.ts @@ -31,7 +31,7 @@ export function deepEqual(a: JsonLike, b: JsonLike): boolean { if (aks.length !== bks.length) return false; for (let i = 0; i < aks.length; i++) { const k = aks[i]; - if (!deepEqual(a[k], (b as { [key: string]: JsonLike })[k])) return false; + if (!deepEqual((a as { [key: string]: JsonLike })[k], (b as { [key: string]: JsonLike })[k])) return false; } return true; } diff --git a/packages/frontend/src/utility/contains.ts b/packages/frontend/src/utility/element-contains.ts index 6137c06e85..8389d49278 100644 --- a/packages/frontend/src/utility/contains.ts +++ b/packages/frontend/src/utility/element-contains.ts @@ -3,7 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -export default (parent, child, checkSame = true) => { +export function elementContains(parent: Element | null, child: Element | null, checkSame = true) { + if (parent === null || child === null) return false; if (checkSame && parent === child) return true; let node = child.parentNode; while (node) { @@ -11,4 +12,4 @@ export default (parent, child, checkSame = true) => { node = node.parentNode; } return false; -}; +} diff --git a/packages/frontend/src/utility/form.ts b/packages/frontend/src/utility/form.ts index fe89333285..a86ae1d1c4 100644 --- a/packages/frontend/src/utility/form.ts +++ b/packages/frontend/src/utility/form.ts @@ -84,7 +84,7 @@ export interface ArrayFormItem extends FormItemBase { export interface ButtonFormItem extends FormItemBase { type: 'button'; content?: string; - action: (ev: MouseEvent, v: any) => void; + action: (ev: PointerEvent, v: any) => void; } export interface DriveFileFormItem extends FormItemBase { @@ -126,23 +126,23 @@ type NonNullableIfRequired<T, Item extends FormItem> = type GetItemType<Item extends FormItem> = Item extends StringFormItem ? NonNullableIfRequired<InferDefault<Item, string>, Item> - : Item extends NumberFormItem - ? NonNullableIfRequired<InferDefault<Item, number>, Item> - : Item extends BooleanFormItem - ? boolean - : Item extends RadioFormItem - ? GetRadioItemType<Item> - : Item extends RangeFormItem - ? NonNullableIfRequired<InferDefault<Item, number>, Item> - : Item extends EnumFormItem - ? GetEnumItemType<Item> - : Item extends ArrayFormItem - ? NonNullableIfRequired<InferDefault<Item, unknown[]>, Item> - : Item extends ObjectFormItem - ? NonNullableIfRequired<InferDefault<Item, Record<string, unknown>>, Item> - : Item extends DriveFileFormItem - ? Misskey.entities.DriveFile | undefined - : never; + : Item extends NumberFormItem + ? NonNullableIfRequired<InferDefault<Item, number>, Item> + : Item extends BooleanFormItem + ? boolean + : Item extends RadioFormItem + ? GetRadioItemType<Item> + : Item extends RangeFormItem + ? NonNullableIfRequired<InferDefault<Item, number>, Item> + : Item extends EnumFormItem + ? GetEnumItemType<Item> + : Item extends ArrayFormItem + ? NonNullableIfRequired<InferDefault<Item, unknown[]>, Item> + : Item extends ObjectFormItem + ? NonNullableIfRequired<InferDefault<Item, Record<string, unknown>>, Item> + : Item extends DriveFileFormItem + ? Misskey.entities.DriveFile | undefined + : never; export type GetFormResultType<F extends Form> = { [P in keyof F]: GetItemType<F[P]>; diff --git a/packages/frontend/src/utility/get-embed-code.ts b/packages/frontend/src/utility/get-embed-code.ts index 5ccd46cfe2..5817d7ece8 100644 --- a/packages/frontend/src/utility/get-embed-code.ts +++ b/packages/frontend/src/utility/get-embed-code.ts @@ -3,10 +3,10 @@ * SPDX-License-Identifier: AGPL-3.0-only */ import { defineAsyncComponent } from 'vue'; -import { genId } from '@/utility/id.js'; import { url } from '@@/js/config.js'; import { defaultEmbedParams, embedRouteWithScrollbar } from '@@/js/embed-page.js'; import type { EmbedParams, EmbeddableEntity } from '@@/js/embed-page.js'; +import { genId } from '@/utility/id.js'; import * as os from '@/os.js'; import { copyToClipboard } from '@/utility/copy-to-clipboard.js'; @@ -21,19 +21,20 @@ export function normalizeEmbedParams(params: EmbedParams): Record<string, string // paramsのvalueをすべてstringに変換。undefinedやnullはプロパティごと消す const normalizedParams: Record<string, string> = {}; for (const key in params) { + const k = key as keyof EmbedParams; // デフォルトの値と同じならparamsに含めない - if (params[key] == null || params[key] === defaultEmbedParams[key]) { + if (params[k] == null || params[k] === defaultEmbedParams[k]) { continue; } - switch (typeof params[key]) { + switch (typeof params[k]) { case 'number': - normalizedParams[key] = params[key].toString(); + normalizedParams[k] = params[k].toString(); break; case 'boolean': - normalizedParams[key] = params[key] ? 'true' : 'false'; + normalizedParams[k] = params[k] ? 'true' : 'false'; break; default: - normalizedParams[key] = params[key]; + normalizedParams[k] = params[k]; break; } } diff --git a/packages/frontend/src/utility/get-user-environment.ts b/packages/frontend/src/utility/get-user-environment.ts index 3b8d43fb2c..ebae0492b1 100644 --- a/packages/frontend/src/utility/get-user-environment.ts +++ b/packages/frontend/src/utility/get-user-environment.ts @@ -39,7 +39,7 @@ export async function getUserEnvironment(): Promise<UserEnvironment> { } } - const browserData = uaData.fullVersionList.find((item) => !/^\s*not.+a.+brand\s*$/i.test(item.brand)); + const browserData = uaData.fullVersionList.find((item: any) => !/^\s*not.+a.+brand\s*$/i.test(item.brand)); return { os: `${uaData.platform} ${osVersion}`, browser: browserData ? `${browserData.brand} v${browserData.version}` : 'Unknown', diff --git a/packages/frontend/src/utility/snowfall-effect.ts b/packages/frontend/src/utility/snowfall-effect.ts index cefa720ebf..aa86db6bd1 100644 --- a/packages/frontend/src/utility/snowfall-effect.ts +++ b/packages/frontend/src/utility/snowfall-effect.ts @@ -21,7 +21,7 @@ export class SnowfallEffect { }>; private uniforms: Record<string, { type: string; - value: number[] | Float32Array; + value: number | number[] | Float32Array; location: WebGLUniformLocation; }>; private texture: WebGLTexture; @@ -44,9 +44,9 @@ export class SnowfallEffect { start: number; previous: number; } = { - start: 0, - previous: 0, - }; + start: 0, + previous: 0, + }; private raf = 0; private density: number = 1 / 90; @@ -90,7 +90,7 @@ export class SnowfallEffect { mat2: 'uniformMatrix2fv', mat3: 'uniformMatrix3fv', mat4: 'uniformMatrix4fv', - }; + } as const; private CAMERA = { fov: 60, @@ -167,7 +167,7 @@ export class SnowfallEffect { return { ...this.WIND }; } - private initShader(type, source): WebGLShader { + private initShader(type: number, source: string): WebGLShader { const { gl } = this; const shader = gl.createShader(type); if (shader == null) throw new Error('Failed to create shader'); @@ -224,7 +224,7 @@ export class SnowfallEffect { } } - private setBuffer(name: string, value?) { + private setBuffer(name: string, value?: number[] | undefined) { const { gl, buffers } = this; const buffer = buffers[name]; @@ -253,18 +253,18 @@ export class SnowfallEffect { } } - private setUniform(name: string, value?) { + private setUniform(name: string, value?: number | number[] | Float32Array<ArrayBufferLike> | undefined) { const { gl, uniforms } = this; const uniform = uniforms[name]; - const setter = this.UNIFORM_SETTERS[uniform.type]; + const setter = this.UNIFORM_SETTERS[uniform.type as keyof typeof this.UNIFORM_SETTERS]; const isMatrix = /^mat[2-4]$/i.test(uniform.type); uniform.value = value ?? uniform.value; if (isMatrix) { - gl[setter](uniform.location, false, uniform.value); + (gl as any)[setter](uniform.location, false, uniform.value); } else { - gl[setter](uniform.location, uniform.value); + (gl as any)[setter](uniform.location, uniform.value); } } |