@acanthis-dec/core 1.1.0 → 1.3.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/README.md CHANGED
@@ -17,13 +17,21 @@ pnpm --filter=@acanthis-dec/core run build
17
17
  Import from workspace source or the published ESM package:
18
18
 
19
19
  ```ts
20
- import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
20
+ import {
21
+ buildDescrambleMapping,
22
+ joinChapterHtml,
23
+ restoreByMapping,
24
+ } from "@acanthis-dec/core";
21
25
  ```
22
26
 
23
27
  ## Usage
24
28
 
25
29
  ```ts
26
- import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
30
+ import {
31
+ buildDescrambleMapping,
32
+ joinChapterHtml,
33
+ restoreByMapping,
34
+ } from "@acanthis-dec/core";
27
35
 
28
36
  const html = joinChapterHtml("Chapter 1", "<p>Hello</p>");
29
37
 
package/README.zh-CN.md CHANGED
@@ -17,13 +17,21 @@ pnpm --filter=@acanthis-dec/core run build
17
17
  从 workspace 源码或发布后的 ESM 包导入:
18
18
 
19
19
  ```ts
20
- import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
20
+ import {
21
+ buildDescrambleMapping,
22
+ joinChapterHtml,
23
+ restoreByMapping,
24
+ } from "@acanthis-dec/core";
21
25
  ```
22
26
 
23
27
  ## 用法
24
28
 
25
29
  ```ts
26
- import { buildDescrambleMapping, joinChapterHtml, restoreByMapping } from "@acanthis-dec/core";
30
+ import {
31
+ buildDescrambleMapping,
32
+ joinChapterHtml,
33
+ restoreByMapping,
34
+ } from "@acanthis-dec/core";
27
35
 
28
36
  const html = joinChapterHtml("Chapter 1", "<p>Hello</p>");
29
37
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/content.d.ts
2
1
  type ContentNode = {
3
2
  type: "paragraph";
4
3
  html: string;
@@ -10,9 +9,7 @@ type ContentNode = {
10
9
  type: "rawHtml";
11
10
  html: string;
12
11
  };
13
- declare function joinChapterHtml(title: string | undefined, bodyHtml: string): string;
14
- //#endregion
15
- //#region src/descramble.d.ts
12
+ export declare function joinChapterHtml(title: string | undefined, bodyHtml: string): string;
16
13
  type LcgConfig = {
17
14
  multiplier: number;
18
15
  increment: number;
@@ -22,10 +19,8 @@ interface DescrambleCoefficients extends LcgConfig {
22
19
  seedMultiplier: number;
23
20
  seedOffset: number;
24
21
  }
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
22
+ export declare function buildDescrambleMapping(length: number, seed: number, lcg: LcgConfig, offset?: number): number[];
23
+ export declare function restoreByMapping<T>(items: T[], mapping: number[]): T[];
29
24
  interface NovelSearchResult {
30
25
  id: string;
31
26
  platform: string;
@@ -62,9 +57,105 @@ type ChapterContent = {
62
57
  html: string;
63
58
  };
64
59
  type NovelStatus = "ongoing" | "completed" | "unknown";
65
- //#endregion
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 };
70
- //# sourceMappingURL=index.d.mts.map
60
+ type SourceCapability = "search" | "novels" | "illustrations" | "explore";
61
+ interface NovelSourceDescriptor {
62
+ id: string;
63
+ name: string;
64
+ capabilities: SourceCapability[];
65
+ }
66
+ interface BookshelfItem {
67
+ platform: string;
68
+ novelId: string;
69
+ title: string;
70
+ author: string;
71
+ coverUrl: string;
72
+ addedAt: number;
73
+ updatedAt: number;
74
+ deletedAt: number | null;
75
+ }
76
+ interface ReadingProgress {
77
+ platform: string;
78
+ novelId: string;
79
+ novelTitle: string;
80
+ coverUrl: string;
81
+ volumeId: string;
82
+ volumeTitle: string;
83
+ chapterId: string;
84
+ chapterTitle: string;
85
+ paragraphIndex: number;
86
+ totalParagraphs: number;
87
+ deviceLabel: string;
88
+ updatedAt: number;
89
+ }
90
+ interface ExploreFilterOption {
91
+ value: string;
92
+ label: string;
93
+ }
94
+ interface ExploreFilterGroup {
95
+ key: string;
96
+ label: string;
97
+ defaultValue: string;
98
+ options: ExploreFilterOption[];
99
+ }
100
+ interface ExploreChannelOption {
101
+ id: string;
102
+ label: string;
103
+ requiresChallenge?: boolean;
104
+ }
105
+ interface ExploreRankingOption {
106
+ id: string;
107
+ label: string;
108
+ supportsAll: boolean;
109
+ supportsFull: boolean;
110
+ }
111
+ interface ExploreSchema {
112
+ platform: string;
113
+ supportsHome: boolean;
114
+ channels: ExploreChannelOption[];
115
+ rankings: ExploreRankingOption[];
116
+ catalogRequiresChallenge?: boolean;
117
+ catalogFilters: ExploreFilterGroup[];
118
+ }
119
+ interface ExploreNovelItem {
120
+ id: string;
121
+ platform: string;
122
+ title: string;
123
+ coverUrl?: string;
124
+ author?: string;
125
+ summary?: string;
126
+ status?: NovelStatus;
127
+ category?: string;
128
+ genres?: string[];
129
+ latestChapter?: string;
130
+ latestChapterId?: string;
131
+ wordCount?: string;
132
+ updatedAt?: string;
133
+ rank?: number;
134
+ }
135
+ type ExploreSectionLayout = "featured" | "grid" | "rank" | "updates";
136
+ interface ExploreSectionMoreTarget {
137
+ type: "ranking" | "catalog" | "channel";
138
+ params: Record<string, string>;
139
+ }
140
+ interface ExploreSection {
141
+ id: string;
142
+ title: string;
143
+ layout: ExploreSectionLayout;
144
+ items: ExploreNovelItem[];
145
+ more?: ExploreSectionMoreTarget;
146
+ }
147
+ interface ExploreHomeData {
148
+ platform: string;
149
+ channel: string;
150
+ title: string;
151
+ sections: ExploreSection[];
152
+ }
153
+ interface ExplorePage {
154
+ platform: string;
155
+ items: ExploreNovelItem[];
156
+ page: number;
157
+ totalPages?: number;
158
+ hasNextPage: boolean;
159
+ }
160
+ export declare function runTimeout<T>(callback: () => T | Promise<T>, delayTime: number): Promise<T>;
161
+ export type { BookshelfItem, Chapter, ChapterContent, ContentNode, DescrambleCoefficients, ExploreChannelOption, ExploreFilterGroup, ExploreFilterOption, ExploreHomeData, ExploreNovelItem, ExplorePage, ExploreRankingOption, ExploreSchema, ExploreSection, ExploreSectionLayout, ExploreSectionMoreTarget, LcgConfig, Novel, NovelInfo, NovelSearchResult, NovelSourceDescriptor, NovelStatus, ReadingProgress, SourceCapability, Volume };
package/dist/index.mjs CHANGED
@@ -1,9 +1,8 @@
1
- //#region src/content.ts
1
+ // src/content.ts
2
2
  function joinChapterHtml(title, bodyHtml) {
3
3
  return `${title ? `<h2>${title}</h2>` : ""}${bodyHtml}`;
4
4
  }
5
- //#endregion
6
- //#region src/descramble.ts
5
+ // src/descramble.ts
7
6
  function shuffleWithSeed(array, seed, config) {
8
7
  const { multiplier, increment, modulus } = config;
9
8
  let currentSeed = seed;
@@ -31,14 +30,12 @@ function restoreByMapping(items, mapping) {
31
30
  }
32
31
  return restored;
33
32
  }
34
- //#endregion
35
- //#region src/utils.ts
33
+ // src/utils.ts
36
34
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
37
35
  async function runTimeout(callback, delayTime) {
38
36
  await sleep(delayTime);
39
37
  return await callback();
40
38
  }
41
- //#endregion
42
39
  export { buildDescrambleMapping, joinChapterHtml, restoreByMapping, runTimeout };
43
40
 
44
41
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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"}
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.1.0",
3
+ "version": "1.3.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",
@@ -26,12 +26,12 @@
26
26
  "url": "https://github.com/ConstasJ/Acanthis/issues"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/node": "25.9.2",
30
- "tsdown": "0.22.2",
31
- "tsx": "4.22.4",
32
- "typescript": "6.0.3",
33
29
  "@acanthis-dec/config-tsdown": "1.0.0",
34
- "@acanthis-dec/config-typescript": "1.0.0"
30
+ "@acanthis-dec/config-typescript": "1.0.0",
31
+ "@types/node": "26.6.6",
32
+ "tsdown": "0.23.7",
33
+ "tsx": "4.23.15",
34
+ "typescript": "7.0.2"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsdown",