Skip to content

Commit

Permalink
修剪代码导入,缩小产物体积
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-xmh committed Jun 23, 2023
1 parent aad6742 commit 4391599
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 1,558 deletions.
144 changes: 72 additions & 72 deletions dist/index.js

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
],
"description": "类 Apple Music 歌词页面插件|近乎完美的 Apple Music 歌词体验",
"preview": "preview.svg",
"version": "2.1.0",
"commit": "3bb850ecec38ed64d39d33dafa20d33c084d46f6",
"version": "2.1.1",
"commit": "aad6742427dd7f9b9a7d651ecadba84358967236",
"type": "extension",
"noDevReload": true,
"ncm3-compatible": true,
"incompatible": [
"RefinedNowPlaying"
],
"betterncm_version": ">=1.0.0",
"injects": {
"Main": [
Expand Down
1,235 changes: 1 addition & 1,234 deletions dist/worker_script.js

Large diffs are not rendered by default.

91 changes: 0 additions & 91 deletions dist/worker_script.js.LEGAL.txt
Original file line number Diff line number Diff line change
@@ -1,91 +0,0 @@
Bundled license information:

react/cjs/react.production.min.js:
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

scheduler/cjs/scheduler.production.min.js:
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

react-dom/cjs/react-dom.production.min.js:
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

react-is/cjs/react-is.production.min.js:
/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

react/cjs/react-jsx-runtime.production.min.js:
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

pangu/dist/browser/pangu.min.js:
/*!
* pangu.js
* --------
* @version: 4.0.7
* @homepage: https://github.com/vinta/pangu.js
* @license: MIT
* @author: Vinta Chen <[email protected]> (https://github.com/vinta)
*/

punycode/punycode.js:
/*! https://mths.be/punycode v1.4.1 by @mathias */

jszip/dist/jszip.min.js:
/*!

JSZip v3.10.1 - A JavaScript class for generating and reading zip files
<http://stuartk.com/jszip>

(c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/main/LICENSE.markdown.

JSZip uses the library pako released under the MIT license :
https://github.com/nodeca/pako/blob/main/LICENSE
*/

prismjs/components/prism-core.js:
/**
* Prism: Lightweight, robust, elegant syntax highlighting
*
* @license MIT <https://opensource.org/licenses/MIT>
* @author Lea Verou <https://lea.verou.me>
* @namespace
* @public
*/
5 changes: 1 addition & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
],
"description": "类 Apple Music 歌词页面插件|近乎完美的 Apple Music 歌词体验",
"preview": "preview.svg",
"version": "2.0.3",
"version": "2.1.1",
"commit": "!SET_BY_BUILD_SCRIPT!",
"type": "extension",
"noDevReload": true,
"ncm3-compatible": true,
"incompatible": [
"RefinedNowPlaying"
],
"betterncm_version": ">=1.0.0",
"injects": {
"Main": [
Expand Down
4 changes: 3 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { log, warn } from "../utils/logger";
import { isNCMV3, genRandomString, normalizePath } from "../utils";
import { isNCMV3 } from "../utils";
import type { LyricLine } from "../core/lyric-types";
import { parseLyric as parseTTMLLyric } from "../core/ttml-lyric-parser";
import { songInfoPayload } from "../utils/page-injector/v3";
import { genRandomString } from "../utils/gen-random-string";
import { normalizePath } from "../utils/path";
let cachedFunctionMap: Map<string, Function> = new Map();

export enum PlayState {
Expand Down
4 changes: 2 additions & 2 deletions src/components/lyric-background/pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {
Sprite,
Texture,
} from "pixi.js";
import colorDitheringFragment from "./color-dithering.frag"
import colorDitheringFragment from "./color-dithering.frag";

class TimedContainer extends Container {
public time: number = 0;
}

class ColorDitheringFilter extends Filter {
constructor() {
super(undefined, colorDitheringFragment)
super(undefined, colorDitheringFragment);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/config/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import { GLOBAL_EVENTS } from "../utils/global-events";
import { log, warn } from "../utils/logger";
import { debounce, normalizePath } from "../utils";
import { setConfigFromMain } from "../worker";
import { IS_WORKER } from "../utils/is-worker";
import { normalizePath } from "../utils/path";
import { debounce } from "../utils/debounce";

export interface Config {
[key: string]: string | undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
initInjectorV2,
initInjectorV3,
} from "./utils/page-injector";
import { isNCMV3, normalizePath } from "./utils";
import { isNCMV3 } from "./utils";
import { normalizePath } from "./utils/path";

export let cssContent = "";

Expand Down
12 changes: 12 additions & 0 deletions src/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function debounce<T extends Function>(callback: T, waitTime: number): T {
let timer = 0;
return function debounceClosure() {
const self = this;
// rome-ignore lint/style/noArguments: 防抖函数
const args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(callback.bind(self, args), waitTime);
} as unknown as T;
}
8 changes: 8 additions & 0 deletions src/utils/gen-random-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function genRandomString(length: number) {
const words = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
const result: string[] = [];
for (let i = 0; i < length; i++) {
result.push(words.charAt(Math.floor(Math.random() * words.length)));
}
return result.join("");
}
144 changes: 0 additions & 144 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@ import semverLt from "semver/functions/lt";
import { appStore } from "./page-injector/v3";
import { IS_WORKER } from "./is-worker";

export function debounce<T extends Function>(callback: T, waitTime: number): T {
let timer = 0;
return function debounceClosure() {
const self = this;
// rome-ignore lint/style/noArguments: 防抖函数
const args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(callback.bind(self, args), waitTime);
} as unknown as T;
}

let IS_NCMV3: boolean;
export function isNCMV3() {
if (typeof IS_NCMV3 === "undefined") {
Expand All @@ -37,137 +24,6 @@ export function isNCMV3() {
return IS_NCMV3;
}

/* eslint-disable max-depth, max-statements, complexity, max-lines-per-function */
const SLASH = 47;
const DOT = 46;

const assertPath = (path: string) => {
const t = typeof path;
if (t !== "string") {
throw new TypeError(`Expected a string, got a ${t}`);
}
};

// this function is directly from node source
const posixNormalize = (path: string, allowAboveRoot: boolean) => {
let res = "";
let lastSegmentLength = 0;
let lastSlash = -1;
let dots = 0;
let code: number | undefined;

for (let i = 0; i <= path.length; ++i) {
if (i < path.length) {
code = path.charCodeAt(i);
} else if (code === SLASH) {
break;
} else {
code = SLASH;
}
if (code === SLASH) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
if (
res.length < 2 ||
lastSegmentLength !== 2 ||
res.charCodeAt(res.length - 1) !== DOT ||
res.charCodeAt(res.length - 2) !== DOT
) {
if (res.length > 2) {
const lastSlashIndex = res.lastIndexOf("/");
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = "";
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
}
lastSlash = i;
dots = 0;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = "";
lastSegmentLength = 0;
lastSlash = i;
dots = 0;
continue;
}
}
if (allowAboveRoot) {
if (res.length > 0) {
res += "/..";
} else {
res = "..";
}
lastSegmentLength = 2;
}
} else {
if (res.length > 0) {
res += `/${path.slice(lastSlash + 1, i)}`;
} else {
res = path.slice(lastSlash + 1, i);
}
lastSegmentLength = i - lastSlash - 1;
}
lastSlash = i;
dots = 0;
} else if (code === DOT && dots !== -1) {
++dots;
} else {
dots = -1;
}
}

return res;
};

const decode = (s: string) => {
try {
return decodeURIComponent(s);
} catch {
return s;
}
};

export const normalizePath = (p: string) => {
assertPath(p);

let path = p.replaceAll("\\", "/");
if (path.length === 0) {
return ".";
}

const isAbsolute = path.charCodeAt(0) === SLASH;
const trailingSeparator = path.charCodeAt(path.length - 1) === SLASH;

path = decode(path);
path = posixNormalize(path, !isAbsolute);

if (path.length === 0 && !isAbsolute) {
path = ".";
}
if (path.length > 0 && trailingSeparator) {
path += "/";
}
if (isAbsolute) {
return `/${path}`;
}

return path;
};

export function genRandomString(length: number) {
const words = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
const result: string[] = [];
for (let i = 0; i < length; i++) {
result.push(words.charAt(Math.floor(Math.random() * words.length)));
}
return result.join("");
}

// 猜测歌词的阅读时间,大概根据中日英文简单计算,返回单位毫秒的阅读时间
export function guessTextReadDuration(text: string): number {
const wordRegexp = /^([A-Za-z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff\-]+)$/;
Expand Down
Loading

0 comments on commit 4391599

Please sign in to comment.