Skip to content

Commit

Permalink
fix: biome error
Browse files Browse the repository at this point in the history
  • Loading branch information
xpadev-net committed Apr 30, 2024
1 parent b51c14a commit caf419b
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 152 deletions.
14 changes: 7 additions & 7 deletions src/comments/BaseComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class BaseComment implements IComment {
this.image = cache.image;
window.setTimeout(
() => {
delete this.image;
this.image = undefined;
},
this.comment.long * 10 + config.cacheAge,
);
Expand Down Expand Up @@ -317,7 +317,7 @@ class BaseComment implements IComment {
this.image = image;
window.setTimeout(
() => {
delete this.image;
this.image = undefined;
},
this.comment.long * 10 + config.cacheAge,
);
Expand Down Expand Up @@ -352,11 +352,11 @@ class BaseComment implements IComment {
}

protected getCacheKey() {
return (
JSON.stringify(this.comment.content) +
`@@${this.pluginName}@@` +
[...this.comment.mail].sort((a, b) => a.localeCompare(b)).join(",")
);
return `${JSON.stringify(this.comment.content)}@@${this.pluginName}@@${[
...this.comment.mail,
]
.sort((a, b) => a.localeCompare(b))
.join(",")}`;
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/comments/FlashComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FlashComment extends BaseComment {
}
this.comment = this.getCommentSize(comment);
this.cacheKey = this.getCacheKey();
delete this.image;
this.image = undefined;
}

override convertComment(comment: FormattedComment): FormattedCommentWithSize {
Expand Down Expand Up @@ -169,9 +169,9 @@ class FlashComment extends BaseComment {

override measureText(comment: MeasureTextInput): MeasureTextResult {
//ref: https://github.com/Saccubus/Saccubus1/blob/master/vhook/src/comment/com_surface.c
const configLineHeight = getConfig(config.lineHeight, true),
configFontSize = getConfig(config.fontSize, true)[comment.size],
configStageSize = getConfig(config.commentStageSize, true);
const configLineHeight = getConfig(config.lineHeight, true);
const configFontSize = getConfig(config.fontSize, true)[comment.size];
const configStageSize = getConfig(config.commentStageSize, true);
const defaultFontSize = configFontSize.default;
comment.lineHeight ??= configLineHeight[comment.size].default;
const widthLimit = configStageSize[comment.full ? "fullWidth" : "width"];
Expand Down Expand Up @@ -263,10 +263,10 @@ class FlashComment extends BaseComment {
}

private _measureContent(comment: MeasureTextInput) {
const widthArr: number[] = [],
spacedWidthArr: number[] = [];
let currentWidth = 0,
spacedWidth = 0;
const widthArr: number[] = [];
const spacedWidthArr: number[] = [];
let currentWidth = 0;
let spacedWidth = 0;
for (const item of comment.content) {
if (item.type === "spacer") {
spacedWidth +=
Expand Down Expand Up @@ -303,9 +303,9 @@ class FlashComment extends BaseComment {
spacedWidthArr.push(spacedWidth);
item.width = widths;
}
const leadLine = (function () {
let max = 0,
index = -1;
const leadLine = (() => {
let max = 0;
let index = -1;
spacedWidthArr.forEach((val, i) => {
if (max < val) {
max = val;
Expand Down Expand Up @@ -342,7 +342,7 @@ class FlashComment extends BaseComment {
this.comment.resizedY ? "resized" : "default"
]) *
this.comment.scale;
this.renderer.setStrokeStyle(`rgba(255,255,0,0.25)`);
this.renderer.setStrokeStyle("rgba(255,255,0,0.25)");
this.renderer.strokeRect(
posX,
posY + linePosY * this._globalScale,
Expand Down Expand Up @@ -371,10 +371,10 @@ class FlashComment extends BaseComment {
this.comment.fontSize *
this.comment.lineHeight *
config.flashCommentYOffset[this.comment.size][offsetKey];
let lastFont = this.comment.font,
leftOffset = 0,
lineCount = 0,
isLastButton = false;
let lastFont = this.comment.font;
let leftOffset = 0;
let lineCount = 0;
let isLastButton = false;
for (const item of this.comment.content) {
if (item.type === "spacer") {
leftOffset += item.count * item.charWidth * this.comment.fontSize;
Expand Down
8 changes: 4 additions & 4 deletions src/comments/HTML5Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HTML5Comment extends BaseComment {
};
this.comment = this.getCommentSize(comment);
this.cacheKey = this.getCacheKey();
delete this.image;
this.image = undefined;
}

override convertComment(comment: FormattedComment): FormattedCommentWithSize {
Expand Down Expand Up @@ -129,9 +129,9 @@ class HTML5Comment extends BaseComment {

override measureText(comment: MeasureTextInput): MeasureTextResult {
const scale = getConfig(config.commentScale, false);
const configFontSize = getConfig(config.fontSize, false),
lineHeight = getLineHeight(comment.size, false),
charSize = getCharSize(comment.size, false);
const configFontSize = getConfig(config.fontSize, false);
const lineHeight = getLineHeight(comment.size, false);
const charSize = getCharSize(comment.size, false);
if (!comment.lineHeight) comment.lineHeight = lineHeight;
if (!comment.charSize) comment.charSize = charSize;
comment.fontSize = comment.charSize * 0.8;
Expand Down
24 changes: 17 additions & 7 deletions src/definition/initConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ import { isFlashComment } from "@/utils/comment";
* コンフィグを初期化する
*/
const initConfig = () => {
const platform: Platform = (function (ua) {
if (RegExp(/windows nt 6\.[12]/i).exec(ua)) return "win7";
else if (RegExp(/windows nt (6\.3|10\.\d+)|win32/i).exec(ua))
const platform: Platform = ((ua) => {
if (RegExp(/windows nt 6\.[12]/i).exec(ua)) {
return "win7";
}
if (RegExp(/windows nt (6\.3|10\.\d+)|win32/i).exec(ua)) {
return "win8_1";
else if (RegExp(/windows nt/i).exec(ua)) return "win";
else if (RegExp(/mac os x 10(.|_)(9|10)/i).exec(ua)) return "mac10_9";
else if (RegExp(/mac os x 10(.|_)\d{2}|darwin/i).exec(ua))
}
if (RegExp(/windows nt/i).exec(ua)) {
return "win";
}
if (RegExp(/mac os x 10(.|_)(9|10)/i).exec(ua)) {
return "mac10_9";
}
if (RegExp(/mac os x 10(.|_)\d{2}|darwin/i).exec(ua)) {
return "mac10_11";
else if (RegExp(/mac os x/i).exec(ua)) return "mac";
}
if (RegExp(/mac os x/i).exec(ua)) {
return "mac";
}
return "other";
})(typeof navigator !== "undefined" ? navigator.userAgent : process.platform);
const defaultConfig: BaseConfig = {
Expand Down
14 changes: 7 additions & 7 deletions src/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const processCommentDisableScript = (vpos: number, lastVpos: number) => {
if (handlerCounts.commentDisable < 1 && handlerCounts.commentEnable < 1)
return;
for (const range of nicoScripts.ban) {
const vposInRange = range.start < vpos && vpos < range.end,
lastVposInRange = range.start < lastVpos && lastVpos < range.end;
const vposInRange = range.start < vpos && vpos < range.end;
const lastVposInRange = range.start < lastVpos && lastVpos < range.end;
if (vposInRange && !lastVposInRange) {
executeEvents("commentDisable", {
type: "commentDisable",
Expand All @@ -104,8 +104,8 @@ const processCommentDisableScript = (vpos: number, lastVpos: number) => {
const processSeekDisableScript = (vpos: number, lastVpos: number) => {
if (handlerCounts.seekDisable < 1 && handlerCounts.seekEnable < 1) return;
for (const range of nicoScripts.seekDisable) {
const vposInRange = range.start < vpos && vpos < range.end,
lastVposInRange = range.start < lastVpos && lastVpos < range.end;
const vposInRange = range.start < vpos && vpos < range.end;
const lastVposInRange = range.start < lastVpos && lastVpos < range.end;
if (vposInRange && !lastVposInRange) {
executeEvents("seekDisable", {
type: "seekDisable",
Expand All @@ -130,9 +130,9 @@ const processSeekDisableScript = (vpos: number, lastVpos: number) => {
const processJumpScript = (vpos: number, lastVpos: number) => {
if (handlerCounts.jump < 1) return;
for (const range of nicoScripts.jump) {
const vposInRange = range.start < vpos && (!range.end || vpos < range.end),
lastVposInRange =
range.start < lastVpos && (!range.end || lastVpos < range.end);
const vposInRange = range.start < vpos && (!range.end || vpos < range.end);
const lastVposInRange =
range.start < lastVpos && (!range.end || lastVpos < range.end);
if (vposInRange && !lastVposInRange) {
executeEvents("jump", {
type: "jump",
Expand Down
4 changes: 2 additions & 2 deletions src/input/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const LegacyParser: InputParser = {
* @returns 変換後のデータ
*/
const fromLegacy = (data: RawApiResponse[]): FormattedComment[] => {
const data_: FormattedComment[] = [],
userList: string[] = [];
const data_: FormattedComment[] = [];
const userList: string[] = [];
for (const _val of data) {
const val = safeParse(ZApiChat, _val.chat);
if (!val.success) continue;
Expand Down
9 changes: 5 additions & 4 deletions src/input/legacyOwner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InputParser } from "@/@types";
import { type FormattedComment } from "@/@types";
import type { FormattedComment } from "@/@types";
import { InvalidFormatError } from "@/errors";
import typeGuard from "@/typeGuard";

Expand All @@ -17,15 +17,16 @@ export const LegacyOwnerParser: InputParser = {
* @returns 変換後のデータ
*/
const fromLegacyOwner = (data: string): FormattedComment[] => {
const data_: FormattedComment[] = [],
comments = data.split("\n");
const data_: FormattedComment[] = [];
const comments = data.split("\n");
for (let i = 0, n = comments.length; i < n; i++) {
const value = comments[i];
if (!value) continue;
const commentData = value.split(":");
if (commentData.length < 3) {
continue;
} else if (commentData.length > 3) {
}
if (commentData.length > 3) {
for (let j = 3, n = commentData.length; j < n; j++) {
commentData[2] += `:${commentData[j]}`;
}
Expand Down
14 changes: 8 additions & 6 deletions src/input/owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ const time2vpos = (input: string): number => {
) {
return (
(Number(time[1]) * 60 + Number(time[2])) * 100 +
Number(time[3]) / Math.pow(10, time[3].length - 2)
Number(time[3]) / 10 ** (time[3].length - 2)
);
} else if (time[4] !== undefined && time[5] !== undefined) {
}
if (time[4] !== undefined && time[5] !== undefined) {
return (Number(time[4]) * 60 + Number(time[5])) * 100;
} else if (time[6] !== undefined && time[7] !== undefined) {
}
if (time[6] !== undefined && time[7] !== undefined) {
return (
Number(time[6]) * 100 +
Number(time[7]) / Math.pow(10, time[7].length - 2)
Number(time[6]) * 100 + Number(time[7]) / 10 ** (time[7].length - 2)
);
} else if (time[8] !== undefined) {
}
if (time[8] !== undefined) {
return Number(time[8]) * 100;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/input/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const V1Parser: InputParser = {
* @returns 変換後のデータ
*/
const fromV1 = (data: V1Thread[]): FormattedComment[] => {
const data_: FormattedComment[] = [],
userList: string[] = [];
const data_: FormattedComment[] = [];
const userList: string[] = [];
for (const item of data) {
const val = item.comments,
forkName = item.fork;
const val = item.comments;
const forkName = item.fork;
for (const value of val) {
const tmpParam: FormattedComment = {
id: value.no,
Expand Down
4 changes: 2 additions & 2 deletions src/input/xml2js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const Xml2jsParser: InputParser = {
};

const fromXml2js = (data: Xml2jsPacket): FormattedComment[] => {
const data_: FormattedComment[] = [],
userList: string[] = [];
const data_: FormattedComment[] = [];
const userList: string[] = [];
let index = data.packet.chat.length;
for (const item of data.packet.chat) {
const tmpParam: FormattedComment = {
Expand Down
4 changes: 2 additions & 2 deletions src/input/xmlDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const XmlDocumentParser: InputParser = {
* @returns 変換後のデータ
*/
const parseXMLDocument = (data: XMLDocument): FormattedComment[] => {
const data_: FormattedComment[] = [],
userList: string[] = [];
const data_: FormattedComment[] = [];
const userList: string[] = [];
let index = Array.from(data.documentElement.children).length;
for (const item of Array.from(data.documentElement.children)) {
if (item.nodeName !== "chat") continue;
Expand Down
32 changes: 17 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type {
CommentEventHandlerMap,
FormattedComment,
IComment,
InputFormat,
IPluginList,
IRenderer,
InputFormat,
Options,
Position,
Timeline,
Expand Down Expand Up @@ -76,7 +76,7 @@ class NiconiComments {
* @param initOptions 初期化オプション
*/
constructor(
renderer: IRenderer | HTMLCanvasElement,
_renderer: IRenderer | HTMLCanvasElement,
data: InputFormat,
initOptions: Options = {},
) {
Expand All @@ -89,6 +89,7 @@ class NiconiComments {
setIsDebug(options.debug);
resetImageCache();
resetNicoScripts();
let renderer = _renderer;
if (renderer instanceof HTMLCanvasElement) {
renderer = new CanvasRenderer(renderer, options.video);
} else if (options.video) {
Expand Down Expand Up @@ -149,10 +150,11 @@ class NiconiComments {

/**
* 事前に当たり判定を考慮してコメントの描画場所を決定する
* @param rawData コメントデータ
* @param _rawData コメントデータ
* @returns コメントのインスタンス配列
*/
private preRendering(rawData: FormattedComment[]) {
private preRendering(_rawData: FormattedComment[]) {
let rawData = _rawData;
const preRenderingStart = performance.now();
if (options.keepCA) {
rawData = changeCALayer(rawData);
Expand Down Expand Up @@ -192,7 +194,7 @@ class NiconiComments {
* @param end 終了インデックス
* @param lazy 遅延処理を行うか
*/
private getCommentPos(data: IComment[], end: number, lazy: boolean = false) {
private getCommentPos(data: IComment[], end: number, lazy = false) {
const getCommentPosStart = performance.now();
if (this.processedCommentIndex + 1 >= end) return;
for (const comment of data.slice(this.processedCommentIndex, end)) {
Expand Down Expand Up @@ -225,8 +227,8 @@ class NiconiComments {
for (const vpos of Object.keys(this.timeline)) {
const item = this.timeline[Number(vpos)];
if (!item) continue;
const owner: IComment[] = [],
user: IComment[] = [];
const owner: IComment[] = [];
const user: IComment[] = [];
for (const comment of item) {
if (comment?.owner) {
owner.push(comment);
Expand Down Expand Up @@ -296,11 +298,11 @@ class NiconiComments {
this.timeline[this.lastVposInt]?.filter((item) => item.loc === "naka")
?.length === 0
) {
const current = timelineRange.filter((item) => item.loc !== "naka"),
last =
this.timeline[this.lastVposInt]?.filter(
(item) => item.loc !== "naka",
) ?? [];
const current = timelineRange.filter((item) => item.loc !== "naka");
const last =
this.timeline[this.lastVposInt]?.filter(
(item) => item.loc !== "naka",
) ?? [];
if (arrayEqual(current, last)) return false;
}
this.renderer.clearRect(0, 0, config.canvasWidth, config.canvasHeight);
Expand All @@ -311,7 +313,7 @@ class NiconiComments {
plugin.instance.draw?.(vpos);
this.renderer.drawImage(plugin.canvas, 0, 0);
} catch (e) {
console.error(`Failed to draw comments`, e);
console.error("Failed to draw comments", e);
}
}
this._drawCollision(vposInt);
Expand Down Expand Up @@ -367,8 +369,8 @@ class NiconiComments {
private _drawCollision(vpos: number) {
if (this.showCollision) {
this.renderer.save();
const leftCollision = this.collision.left[vpos],
rightCollision = this.collision.right[vpos];
const leftCollision = this.collision.left[vpos];
const rightCollision = this.collision.right[vpos];
this.renderer.setFillStyle("red");
if (leftCollision) {
for (const comment of leftCollision) {
Expand Down
Loading

0 comments on commit caf419b

Please sign in to comment.