@acanthis-dec/core 1.0.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 ConstasJ
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @acanthis-dec/core
2
+
3
+ [中文文档](./README.zh-CN.md) | [Workspace README](../../README.md)
4
+
5
+ Core shared package for Acanthis. It contains platform-independent content helpers, descrambling utilities, and normalized novel/chapter type definitions used by adapters, storage, and the API server.
6
+
7
+ ## Installation
8
+
9
+ Workspace usage:
10
+
11
+ ```powershell
12
+ pnpm install --frozen-lockfile
13
+ pnpm --filter=@acanthis-dec/core run check-types
14
+ pnpm --filter=@acanthis-dec/core run build
15
+ ```
16
+
17
+ Import from workspace source or the published ESM package:
18
+
19
+ ```ts
20
+ import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
27
+
28
+ const html = joinChapterHtml("Chapter 1", "<p>Hello</p>");
29
+
30
+ const mapping = buildDescrambleMapping(4, 1234, {
31
+ multiplier: 9301,
32
+ increment: 49297,
33
+ modulus: 233280,
34
+ });
35
+
36
+ const restored = restoreByMapping(["b", "a", "d", "c"], mapping);
37
+ ```
38
+
39
+ ## API
40
+
41
+ - `joinChapterHtml(title, bodyHtml)` prepends an optional heading to chapter body HTML.
42
+ - `buildDescrambleMapping(length, seed, lcg, offset?)` builds an index mapping from linear-congruential parameters.
43
+ - `restoreByMapping(items, mapping)` restores an item array by target index mapping.
44
+ - `ContentNode` describes paragraph, image, and raw HTML content nodes.
45
+ - `DescrambleCoefficients` and `LcgConfig` describe descrambling parameters.
46
+ - `Novel`, `NovelInfo`, `NovelSearchResult`, `NovelStatus`, `Volume`, `Chapter`, and `ChapterContent` describe normalized reading metadata and content.
@@ -0,0 +1,46 @@
1
+ # @acanthis-dec/core
2
+
3
+ [English README](./README.md) | [工作区 README](../../README.zh-CN.md)
4
+
5
+ Acanthis 的核心共享包。它包含平台无关的内容辅助方法、还原工具,以及供适配器、存储和 API server 复用的统一小说/章节类型定义。
6
+
7
+ ## 安装
8
+
9
+ 工作区内使用:
10
+
11
+ ```powershell
12
+ pnpm install --frozen-lockfile
13
+ pnpm --filter=@acanthis-dec/core run check-types
14
+ pnpm --filter=@acanthis-dec/core run build
15
+ ```
16
+
17
+ 从 workspace 源码或发布后的 ESM 包导入:
18
+
19
+ ```ts
20
+ import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
21
+ ```
22
+
23
+ ## 用法
24
+
25
+ ```ts
26
+ import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
27
+
28
+ const html = joinChapterHtml("Chapter 1", "<p>Hello</p>");
29
+
30
+ const mapping = buildDescrambleMapping(4, 1234, {
31
+ multiplier: 9301,
32
+ increment: 49297,
33
+ modulus: 233280,
34
+ });
35
+
36
+ const restored = restoreByMapping(["b", "a", "d", "c"], mapping);
37
+ ```
38
+
39
+ ## API
40
+
41
+ - `joinChapterHtml(title, bodyHtml)` 为章节正文追加可选标题。
42
+ - `buildDescrambleMapping(length, seed, lcg, offset?)` 根据线性同余参数生成索引映射。
43
+ - `restoreByMapping(items, mapping)` 根据目标索引映射还原数组。
44
+ - `ContentNode` 描述段落、图片和原始 HTML 内容节点。
45
+ - `DescrambleCoefficients` 与 `LcgConfig` 描述还原参数。
46
+ - `Novel`、`NovelInfo`、`NovelSearchResult`、`NovelStatus`、`Volume`、`Chapter`、`ChapterContent` 描述统一阅读元数据与内容。
@@ -0,0 +1,67 @@
1
+ //#region src/content.d.ts
2
+ type ContentNode = {
3
+ type: "paragraph";
4
+ html: string;
5
+ } | {
6
+ type: "image";
7
+ src: string;
8
+ alt?: string;
9
+ } | {
10
+ type: "rawHtml";
11
+ html: string;
12
+ };
13
+ declare function joinChapterHtml(title: string | undefined, bodyHtml: string): string;
14
+ //#endregion
15
+ //#region src/descramble.d.ts
16
+ type LcgConfig = {
17
+ multiplier: number;
18
+ increment: number;
19
+ modulus: number;
20
+ };
21
+ interface DescrambleCoefficients extends LcgConfig {
22
+ seedMultiplier: number;
23
+ seedOffset: number;
24
+ }
25
+ declare function buildDescrambleMapping(length: number, seed: number, lcg: LcgConfig, offset?: number): number[];
26
+ declare function restoreByMapping<T>(items: T[], mapping: number[]): T[];
27
+ //#endregion
28
+ //#region src/types.d.ts
29
+ interface NovelSearchResult {
30
+ id: string;
31
+ platform: string;
32
+ title: string;
33
+ coverUrl?: string;
34
+ }
35
+ interface NovelInfo extends NovelSearchResult {
36
+ author: string;
37
+ summary: string;
38
+ status: NovelStatus;
39
+ genres: string[];
40
+ }
41
+ interface Novel extends NovelInfo {
42
+ volumes: Volume[];
43
+ }
44
+ type Volume = {
45
+ id: string;
46
+ platform?: string | null | undefined;
47
+ title: string;
48
+ coverUrl?: string | null | undefined;
49
+ novelId?: string | null | undefined;
50
+ chapters: Chapter[];
51
+ };
52
+ type Chapter = {
53
+ id: string;
54
+ platform?: string | null | undefined;
55
+ title: string;
56
+ novelId?: string | null | undefined;
57
+ volumeId?: string | null | undefined;
58
+ contentHash?: string | null | undefined;
59
+ };
60
+ type ChapterContent = {
61
+ title?: string;
62
+ html: string;
63
+ };
64
+ type NovelStatus = "ongoing" | "completed" | "unknown";
65
+ //#endregion
66
+ export { type Chapter, type ChapterContent, type ContentNode, type DescrambleCoefficients, type LcgConfig, type Novel, type NovelInfo, type NovelSearchResult, type NovelStatus, type Volume, buildDescrambleMapping, joinChapterHtml, restoreByMapping };
67
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,37 @@
1
+ //#region src/content.ts
2
+ function joinChapterHtml(title, bodyHtml) {
3
+ return `${title ? `<h2>${title}</h2>` : ""}${bodyHtml}`;
4
+ }
5
+ //#endregion
6
+ //#region src/descramble.ts
7
+ function shuffleWithSeed(array, seed, config) {
8
+ const { multiplier, increment, modulus } = config;
9
+ let currentSeed = seed;
10
+ const result = [...array];
11
+ const len = result.length;
12
+ for (let i = len - 1; i > 0; i--) {
13
+ currentSeed = (currentSeed * multiplier + increment) % modulus;
14
+ const j = Math.floor(currentSeed / modulus * (i + 1));
15
+ const temp = result[i] ?? 0;
16
+ result[i] = result[j] ?? 0;
17
+ result[j] = temp;
18
+ }
19
+ return result;
20
+ }
21
+ function buildDescrambleMapping(length, seed, lcg, offset) {
22
+ if (offset === void 0) offset = 0;
23
+ const shuffledIndices = shuffleWithSeed(Array.from({ length: length - offset }, (_, i) => i + offset), seed, lcg);
24
+ return Array.from({ length: offset }, (_, i) => i).concat(shuffledIndices);
25
+ }
26
+ function restoreByMapping(items, mapping) {
27
+ const restored = new Array(items.length);
28
+ for (let i = 0; i < items.length; i++) {
29
+ const targetIndex = mapping[i] ?? i;
30
+ restored[targetIndex] = items[i];
31
+ }
32
+ return restored;
33
+ }
34
+ //#endregion
35
+ export { buildDescrambleMapping, joinChapterHtml, restoreByMapping };
36
+
37
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@acanthis-dec/core",
3
+ "version": "1.0.0",
4
+ "description": "The core package of Acanthis project, including some platform-independent utils and type definitions.",
5
+ "author": "ConstasJ <constasj@qq.com>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "types": "./dist/index.d.mts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "package.json",
17
+ "README.md",
18
+ "README.zh-CN.md"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/ConstasJ/Acanthis.git"
23
+ },
24
+ "homepage": "https://github.com/ConstasJ/Acanthis#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/ConstasJ/Acanthis/issues"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "25.9.2",
30
+ "tsdown": "0.22.2",
31
+ "tsx": "4.22.4",
32
+ "typescript": "6.0.3",
33
+ "@acanthis-dec/config-tsdown": "1.0.0",
34
+ "@acanthis-dec/config-typescript": "1.0.0"
35
+ },
36
+ "scripts": {
37
+ "build": "tsdown",
38
+ "check-types": "tsc --noEmit"
39
+ }
40
+ }