@acanthis-dec/core 1.0.1 → 1.1.0
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.
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +8 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -63,5 +63,8 @@ type ChapterContent = {
|
|
|
63
63
|
};
|
|
64
64
|
type NovelStatus = "ongoing" | "completed" | "unknown";
|
|
65
65
|
//#endregion
|
|
66
|
-
|
|
66
|
+
//#region src/utils.d.ts
|
|
67
|
+
declare function runTimeout<T>(callback: () => T | Promise<T>, delayTime: number): Promise<T>;
|
|
68
|
+
//#endregion
|
|
69
|
+
export { type Chapter, type ChapterContent, type ContentNode, type DescrambleCoefficients, type LcgConfig, type Novel, type NovelInfo, type NovelSearchResult, type NovelStatus, type Volume, buildDescrambleMapping, joinChapterHtml, restoreByMapping, runTimeout };
|
|
67
70
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,13 @@ function restoreByMapping(items, mapping) {
|
|
|
32
32
|
return restored;
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
|
-
|
|
35
|
+
//#region src/utils.ts
|
|
36
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
37
|
+
async function runTimeout(callback, delayTime) {
|
|
38
|
+
await sleep(delayTime);
|
|
39
|
+
return await callback();
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { buildDescrambleMapping, joinChapterHtml, restoreByMapping, runTimeout };
|
|
36
43
|
|
|
37
44
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/content.ts","../src/descramble.ts"],"sourcesContent":["export type ContentNode =\n\t| { type: \"paragraph\"; html: string }\n\t| { type: \"image\"; src: string; alt?: string }\n\t| { type: \"rawHtml\"; html: string };\n\nexport function joinChapterHtml(\n\ttitle: string | undefined,\n\tbodyHtml: string,\n): string {\n\tconst titleHtml = title ? `<h2>${title}</h2>` : \"\";\n\treturn `${titleHtml}${bodyHtml}`;\n}\n","export type LcgConfig = {\n\tmultiplier: number;\n\tincrement: number;\n\tmodulus: number;\n};\n\nexport interface DescrambleCoefficients extends LcgConfig {\n\tseedMultiplier: number;\n\tseedOffset: number;\n}\n\nexport function shuffleWithSeed(\n\tarray: number[],\n\tseed: number,\n\tconfig: LcgConfig,\n): number[] {\n\tconst { multiplier, increment, modulus } = config;\n\tlet currentSeed = seed;\n\tconst result = [...array];\n\tconst len = result.length;\n\n\tfor (let i = len - 1; i > 0; i--) {\n\t\tcurrentSeed = (currentSeed * multiplier + increment) % modulus;\n\t\tconst j = Math.floor((currentSeed / modulus) * (i + 1));\n\n\t\t// 交换\n\t\tconst temp = result[i] ?? 0;\n\t\tresult[i] = result[j] ?? 0;\n\t\tresult[j] = temp;\n\t}\n\treturn result;\n}\n\nexport function buildDescrambleMapping(\n\tlength: number,\n\tseed: number,\n\tlcg: LcgConfig,\n\toffset?: number,\n): number[] {\n\tif (offset === undefined) {\n\t\toffset = 0;\n\t}\n\tconst indices = Array.from({ length: length - offset }, (_, i) => i + offset);\n\tconst shuffledIndices = shuffleWithSeed(indices, seed, lcg);\n\tconst fullMapping = Array.from({ length: offset }, (_, i) => i).concat(\n\t\tshuffledIndices,\n\t);\n\treturn fullMapping;\n}\n\nexport function restoreByMapping<T>(items: T[], mapping: number[]): T[] {\n\tconst restored = new Array(items.length);\n\tfor (let i = 0; i < items.length; i++) {\n\t\tconst targetIndex = mapping[i] ?? i;\n\t\trestored[targetIndex] = items[i];\n\t}\n\treturn restored;\n}\n"],"mappings":";AAKA,SAAgB,gBACf,OACA,UACS;CAET,OAAO,GADW,QAAQ,OAAO,MAAM,SAAS,KAC1B;AACvB;;;ACAA,SAAgB,gBACf,OACA,MACA,QACW;CACX,MAAM,EAAE,YAAY,WAAW,YAAY;CAC3C,IAAI,cAAc;CAClB,MAAM,SAAS,CAAC,GAAG,KAAK;CACxB,MAAM,MAAM,OAAO;CAEnB,KAAK,IAAI,IAAI,MAAM,GAAG,IAAI,GAAG,KAAK;EACjC,eAAe,cAAc,aAAa,aAAa;EACvD,MAAM,IAAI,KAAK,MAAO,cAAc,WAAY,IAAI,EAAE;EAGtD,MAAM,OAAO,OAAO,MAAM;EAC1B,OAAO,KAAK,OAAO,MAAM;EACzB,OAAO,KAAK;CACb;CACA,OAAO;AACR;AAEA,SAAgB,uBACf,QACA,MACA,KACA,QACW;CACX,IAAI,WAAW,KAAA,GACd,SAAS;CAGV,MAAM,kBAAkB,gBADR,MAAM,KAAK,EAAE,QAAQ,SAAS,OAAO,IAAI,GAAG,MAAM,IAAI,MACxB,GAAG,MAAM,GAAG;CAI1D,OAHoB,MAAM,KAAK,EAAE,QAAQ,OAAO,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,OAC/D,eAEgB;AAClB;AAEA,SAAgB,iBAAoB,OAAY,SAAwB;CACvE,MAAM,WAAW,IAAI,MAAM,MAAM,MAAM;CACvC,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACtC,MAAM,cAAc,QAAQ,MAAM;EAClC,SAAS,eAAe,MAAM;CAC/B;CACA,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/content.ts","../src/descramble.ts","../src/utils.ts"],"sourcesContent":["export type ContentNode =\n\t| { type: \"paragraph\"; html: string }\n\t| { type: \"image\"; src: string; alt?: string }\n\t| { type: \"rawHtml\"; html: string };\n\nexport function joinChapterHtml(\n\ttitle: string | undefined,\n\tbodyHtml: string,\n): string {\n\tconst titleHtml = title ? `<h2>${title}</h2>` : \"\";\n\treturn `${titleHtml}${bodyHtml}`;\n}\n","export type LcgConfig = {\n\tmultiplier: number;\n\tincrement: number;\n\tmodulus: number;\n};\n\nexport interface DescrambleCoefficients extends LcgConfig {\n\tseedMultiplier: number;\n\tseedOffset: number;\n}\n\nexport function shuffleWithSeed(\n\tarray: number[],\n\tseed: number,\n\tconfig: LcgConfig,\n): number[] {\n\tconst { multiplier, increment, modulus } = config;\n\tlet currentSeed = seed;\n\tconst result = [...array];\n\tconst len = result.length;\n\n\tfor (let i = len - 1; i > 0; i--) {\n\t\tcurrentSeed = (currentSeed * multiplier + increment) % modulus;\n\t\tconst j = Math.floor((currentSeed / modulus) * (i + 1));\n\n\t\t// 交换\n\t\tconst temp = result[i] ?? 0;\n\t\tresult[i] = result[j] ?? 0;\n\t\tresult[j] = temp;\n\t}\n\treturn result;\n}\n\nexport function buildDescrambleMapping(\n\tlength: number,\n\tseed: number,\n\tlcg: LcgConfig,\n\toffset?: number,\n): number[] {\n\tif (offset === undefined) {\n\t\toffset = 0;\n\t}\n\tconst indices = Array.from({ length: length - offset }, (_, i) => i + offset);\n\tconst shuffledIndices = shuffleWithSeed(indices, seed, lcg);\n\tconst fullMapping = Array.from({ length: offset }, (_, i) => i).concat(\n\t\tshuffledIndices,\n\t);\n\treturn fullMapping;\n}\n\nexport function restoreByMapping<T>(items: T[], mapping: number[]): T[] {\n\tconst restored = new Array(items.length);\n\tfor (let i = 0; i < items.length; i++) {\n\t\tconst targetIndex = mapping[i] ?? i;\n\t\trestored[targetIndex] = items[i];\n\t}\n\treturn restored;\n}\n","const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\nexport async function runTimeout<T>(\n\tcallback: () => T | Promise<T>,\n\tdelayTime: number,\n): Promise<T> {\n\tawait sleep(delayTime);\n\treturn await callback();\n}\n"],"mappings":";AAKA,SAAgB,gBACf,OACA,UACS;CAET,OAAO,GADW,QAAQ,OAAO,MAAM,SAAS,KAC1B;AACvB;;;ACAA,SAAgB,gBACf,OACA,MACA,QACW;CACX,MAAM,EAAE,YAAY,WAAW,YAAY;CAC3C,IAAI,cAAc;CAClB,MAAM,SAAS,CAAC,GAAG,KAAK;CACxB,MAAM,MAAM,OAAO;CAEnB,KAAK,IAAI,IAAI,MAAM,GAAG,IAAI,GAAG,KAAK;EACjC,eAAe,cAAc,aAAa,aAAa;EACvD,MAAM,IAAI,KAAK,MAAO,cAAc,WAAY,IAAI,EAAE;EAGtD,MAAM,OAAO,OAAO,MAAM;EAC1B,OAAO,KAAK,OAAO,MAAM;EACzB,OAAO,KAAK;CACb;CACA,OAAO;AACR;AAEA,SAAgB,uBACf,QACA,MACA,KACA,QACW;CACX,IAAI,WAAW,KAAA,GACd,SAAS;CAGV,MAAM,kBAAkB,gBADR,MAAM,KAAK,EAAE,QAAQ,SAAS,OAAO,IAAI,GAAG,MAAM,IAAI,MACxB,GAAG,MAAM,GAAG;CAI1D,OAHoB,MAAM,KAAK,EAAE,QAAQ,OAAO,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,OAC/D,eAEgB;AAClB;AAEA,SAAgB,iBAAoB,OAAY,SAAwB;CACvE,MAAM,WAAW,IAAI,MAAM,MAAM,MAAM;CACvC,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACtC,MAAM,cAAc,QAAQ,MAAM;EAClC,SAAS,eAAe,MAAM;CAC/B;CACA,OAAO;AACR;;;ACzDA,MAAM,SAAS,OAAe,IAAI,SAAS,YAAY,WAAW,SAAS,EAAE,CAAC;AAE9E,eAAsB,WACrB,UACA,WACa;CACb,MAAM,MAAM,SAAS;CACrB,OAAO,MAAM,SAAS;AACvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acanthis-dec/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The core package of Acanthis project, including some platform-independent utils and type definitions.",
|
|
5
5
|
"author": "ConstasJ <constasj@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"build": "tsdown",
|
|
38
38
|
"check-types": "tsc --noEmit"
|
|
39
39
|
},
|
|
40
|
-
"types": "./
|
|
40
|
+
"types": "./dist/index.d.mts"
|
|
41
41
|
}
|