Skip to content

Commit

Permalink
feat: init book abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Feb 27, 2023
1 parent 94c33e9 commit defe8da
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './epub';

export * from './error';

export * from './theme';
9 changes: 9 additions & 0 deletions packages/core/src/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Theme {
name: string;

pages: string[];

styles: string[];

images: string[];
}
1 change: 1 addition & 0 deletions packages/epubook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@epubook/core": "workspace:*",
"@epubook/theme-default": "workspace:*",
"breadc": "^0.8.8"
},
"devDependencies": {
Expand Down
63 changes: 63 additions & 0 deletions packages/epubook/src/epubook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { type Author, type Theme, Epub } from '@epubook/core';

import { loadTheme } from './theme';

export interface EpubookOption {
title: string;

language: string;

author: Author[];

theme: string;
}

export class Epubook {
private container: Epub;

private option: EpubookOption;

private theme!: Theme;

private constructor(option: Partial<EpubookOption>) {
this.option = {
title: '',
language: 'zh-CN',
author: [{ name: 'unknown' }],
theme: '@epubook/theme-default',
...option
};

this.container = new Epub(this.option);
}

public static async create(option: Partial<EpubookOption>) {
const epubook = new Epubook(option);
return await epubook.loadTheme();
}

private async loadTheme() {
await loadTheme(this.option.theme);
return this;
}

public epub() {
return this.container;
}

public setCover() {
return this;
}

public addPage() {
return this;
}

public setToc() {
return this;
}

public setSpine() {
return this;
}
}
1 change: 1 addition & 0 deletions packages/epubook/src/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export async function loadTheme(pkg: string) {}
3 changes: 2 additions & 1 deletion packages/theme-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"pages": [],
"styles": [
"styles/main.css"
]
],
"images": []
}
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
"skipLibCheck": true,
"skipDefaultLibCheck": true
},
"exclude": ["node_modules"]
"paths": {
"@epubook/core": ["./packages/core/src/index.ts"],
"epubook": ["./packages/epubook/src/index.ts"]
},
"exclude": [
"**/dist/**",
"**/node_modules/**"
]
}

0 comments on commit defe8da

Please sign in to comment.