@storyteller-platform/epub 0.8.2 → 1.0.1
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 +4236 -1017
- package/dist/adapters/interface.d.ts +20 -1
- package/dist/adapters/memory.d.ts +2 -2
- package/dist/adapters/memory.js +16 -30
- package/dist/adapters/tmpfs.browser.d.ts +11 -0
- package/dist/adapters/tmpfs.browser.js +9 -0
- package/dist/adapters/tmpfs.d.ts +2 -2
- package/dist/adapters/tmpfs.js +22 -35
- package/dist/files.browser.d.ts +2 -0
- package/dist/files.browser.js +7 -0
- package/dist/files.node.d.ts +2 -0
- package/dist/files.node.js +10 -0
- package/dist/index.d.ts +44 -122
- package/dist/index.js +380 -654
- package/dist/jsx-dev-runtime.d.ts +9 -0
- package/dist/jsx-dev-runtime.js +9 -0
- package/dist/jsx-runtime.d.ts +42 -0
- package/dist/jsx-runtime.js +69 -0
- package/dist/upgrade.d.ts +26 -17
- package/dist/upgrade.js +118 -159
- package/dist/xml.d.ts +104 -0
- package/dist/xml.js +251 -0
- package/dist/zip.browser.d.ts +2 -0
- package/dist/zip.browser.js +33 -0
- package/dist/zip.node.d.ts +9 -0
- package/dist/zip.node.js +246 -0
- package/package.json +92 -10
- package/dist/epubcheck.d.ts +0 -21
- package/dist/epubcheck.js +0 -34
- package/dist/zip.d.ts +0 -2
- package/dist/zip.js +0 -137
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development-mode entry point used by the JSX transform.
|
|
3
|
+
*
|
|
4
|
+
* Transforms compiling in development mode import `jsxDEV` from
|
|
5
|
+
* `<jsxImportSource>/jsx-dev-runtime` rather than from `<jsxImportSource>/jsx-runtime`,
|
|
6
|
+
* so the subpath has to resolve. There is no separate development behaviour
|
|
7
|
+
* here: XML has no key reconciliation to warn about.
|
|
8
|
+
*/
|
|
9
|
+
export { Fragment, jsx, jsxDEV, jsxs } from "./jsx-runtime.ts";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development-mode entry point used by the JSX transform.
|
|
3
|
+
*
|
|
4
|
+
* Transforms compiling in development mode import `jsxDEV` from
|
|
5
|
+
* `<jsxImportSource>/jsx-dev-runtime` rather than from `<jsxImportSource>/jsx-runtime`,
|
|
6
|
+
* so the subpath has to resolve. There is no separate development behaviour
|
|
7
|
+
* here: XML has no key reconciliation to warn about.
|
|
8
|
+
*/
|
|
9
|
+
export { Fragment, jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JSX runtime that builds XML DOM nodes.
|
|
3
|
+
*
|
|
4
|
+
* Enable it per project with `jsx: "react-jsx"` and
|
|
5
|
+
* `jsxImportSource: "@storyteller-platform/epub"`.
|
|
6
|
+
*
|
|
7
|
+
* Everything is built through {@link x}, so namespaces behave exactly as they do
|
|
8
|
+
* when calling `x()` directly: a `dc:` prefix resolves to the Dublin Core
|
|
9
|
+
* namespace, and an `xmlns` attribute binds the namespace it declares instead of
|
|
10
|
+
* being emitted as an extra attribute.
|
|
11
|
+
*/
|
|
12
|
+
import { type Element as DomElement, type Node } from "@xmldom/xmldom";
|
|
13
|
+
/** Anything a JSX expression may place in a child position. */
|
|
14
|
+
export type JsxChild = Node | string | number | boolean | null | undefined | JsxChild[];
|
|
15
|
+
/** Anything a JSX attribute may evaluate to. */
|
|
16
|
+
export type JsxAttr = string | number | boolean | null | undefined;
|
|
17
|
+
type JsxProps = {
|
|
18
|
+
children?: JsxChild | undefined;
|
|
19
|
+
key?: unknown;
|
|
20
|
+
} & Record<string, JsxAttr>;
|
|
21
|
+
/**
|
|
22
|
+
* Groups children without contributing an element.
|
|
23
|
+
*
|
|
24
|
+
* The result is a plain array of children, which {@link flatten} splices into
|
|
25
|
+
* the parent.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Fragment(props: {
|
|
28
|
+
children?: JsxChild | undefined;
|
|
29
|
+
}): Array<Node | string>;
|
|
30
|
+
export declare function jsx(type: string | typeof Fragment, props?: JsxProps | null, _key?: unknown): DomElement;
|
|
31
|
+
export declare function jsxs(type: string | typeof Fragment, props?: JsxProps | null, _key?: unknown): DomElement;
|
|
32
|
+
export declare function jsxDEV(type: string | typeof Fragment, props?: JsxProps | null, _key?: unknown): DomElement;
|
|
33
|
+
export declare namespace JSX {
|
|
34
|
+
type Element = DomElement;
|
|
35
|
+
interface ElementChildrenAttribute {
|
|
36
|
+
children: JsxChild;
|
|
37
|
+
}
|
|
38
|
+
interface IntrinsicElements {
|
|
39
|
+
[name: string]: Record<string, JsxChild>;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JSX runtime that builds XML DOM nodes.
|
|
3
|
+
*
|
|
4
|
+
* Enable it per project with `jsx: "react-jsx"` and
|
|
5
|
+
* `jsxImportSource: "@storyteller-platform/epub"`.
|
|
6
|
+
*
|
|
7
|
+
* Everything is built through {@link x}, so namespaces behave exactly as they do
|
|
8
|
+
* when calling `x()` directly: a `dc:` prefix resolves to the Dublin Core
|
|
9
|
+
* namespace, and an `xmlns` attribute binds the namespace it declares instead of
|
|
10
|
+
* being emitted as an extra attribute.
|
|
11
|
+
*/
|
|
12
|
+
import { x } from "./xml.js";
|
|
13
|
+
/**
|
|
14
|
+
* Groups children without contributing an element.
|
|
15
|
+
*
|
|
16
|
+
* The result is a plain array of children, which {@link flatten} splices into
|
|
17
|
+
* the parent.
|
|
18
|
+
*/
|
|
19
|
+
export function Fragment(props) {
|
|
20
|
+
return flatten(props.children);
|
|
21
|
+
}
|
|
22
|
+
function flatten(child) {
|
|
23
|
+
if (child === null || child === undefined || typeof child === "boolean") {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(child)) {
|
|
27
|
+
return child.flatMap((c) => flatten(c));
|
|
28
|
+
}
|
|
29
|
+
if (typeof child === "number") {
|
|
30
|
+
return [String(child)];
|
|
31
|
+
}
|
|
32
|
+
return [child];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Attribute values follow XML, not HTML: `null`, `undefined` and `false` leave
|
|
36
|
+
* the attribute off entirely, `true` writes an empty value, and numbers are
|
|
37
|
+
* stringified.
|
|
38
|
+
*/
|
|
39
|
+
function attributeValue(value) {
|
|
40
|
+
// Only `true` reaches here; `false` is dropped by the caller.
|
|
41
|
+
if (typeof value === "boolean")
|
|
42
|
+
return "";
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
function isFragment(type) {
|
|
46
|
+
return type === Fragment;
|
|
47
|
+
}
|
|
48
|
+
function build(type, props) {
|
|
49
|
+
const { children, key: _key, ...attributes } = props ?? {};
|
|
50
|
+
if (isFragment(type)) {
|
|
51
|
+
return Fragment({ children });
|
|
52
|
+
}
|
|
53
|
+
const attrs = {};
|
|
54
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
55
|
+
if (value === null || value === undefined || value === false)
|
|
56
|
+
continue;
|
|
57
|
+
attrs[name] = attributeValue(value);
|
|
58
|
+
}
|
|
59
|
+
return x(type, attrs, ...flatten(children));
|
|
60
|
+
}
|
|
61
|
+
export function jsx(type, props, _key) {
|
|
62
|
+
return build(type, props);
|
|
63
|
+
}
|
|
64
|
+
export function jsxs(type, props, _key) {
|
|
65
|
+
return build(type, props);
|
|
66
|
+
}
|
|
67
|
+
export function jsxDEV(type, props, _key) {
|
|
68
|
+
return build(type, props);
|
|
69
|
+
}
|
package/dist/upgrade.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsxImportSource @storyteller-platform/epub */
|
|
2
|
+
import { type Document, type Element } from "@xmldom/xmldom";
|
|
3
|
+
import { type Epub, type NavigationItem } from "./index.tsx";
|
|
2
4
|
export interface Landmark {
|
|
3
5
|
href: string;
|
|
4
6
|
title: string;
|
|
@@ -14,23 +16,30 @@ export interface Epub2UpgradeOptions {
|
|
|
14
16
|
*/
|
|
15
17
|
removeNcx?: boolean;
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
28
|
-
export declare function
|
|
29
|
-
export declare function
|
|
19
|
+
/**
|
|
20
|
+
* Replace an outdated document type declaration with `<!DOCTYPE html>`.
|
|
21
|
+
*
|
|
22
|
+
* EPUB 3 XHTML content documents must conform to the HTML5 conformance
|
|
23
|
+
* criteria, which require `<!DOCTYPE html>`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeDoctype(doc: Document): void;
|
|
26
|
+
export declare function upgradeIdentifiers(pkg: Element): void;
|
|
27
|
+
export declare function upgradeTitle(pkg: Element): void;
|
|
28
|
+
export declare function upgradeLanguages(pkg: Element): void;
|
|
29
|
+
export declare function upgradeAuthors(pkg: Element): void;
|
|
30
|
+
export declare function upgradeDate(pkg: Element): void;
|
|
31
|
+
export declare function upgradeMeta(pkg: Element): void;
|
|
32
|
+
export declare function upgradeCover(pkg: Element): void;
|
|
33
|
+
export declare function removeInvalidDcAttrs(pkg: Element): void;
|
|
34
|
+
export declare function setLastModified(pkg: Element): void;
|
|
35
|
+
export declare function upgradePackageMetadata(pkg: Element): void;
|
|
36
|
+
export declare function extractGuideLandmarks(pkg: Element): Landmark[];
|
|
37
|
+
export declare function removeGuide(pkg: Element): void;
|
|
38
|
+
export declare function removeSpineTocRef(pkg: Element): void;
|
|
30
39
|
export declare function collectManifestProperties(epub: Epub): Promise<void>;
|
|
31
|
-
export declare function fixFontMimeTypes(pkg:
|
|
32
|
-
export declare function buildTocOl(entries: NavigationItem[]):
|
|
40
|
+
export declare function fixFontMimeTypes(pkg: Element): void;
|
|
41
|
+
export declare function buildTocOl(entries: NavigationItem[]): Element;
|
|
33
42
|
export declare function buildNavDocument(epub: Epub, tocEntries: NavigationItem[], landmarks: Landmark[]): Promise<string>;
|
|
34
|
-
export declare function setPackageVersion(pkg:
|
|
43
|
+
export declare function setPackageVersion(pkg: Element, version: string): void;
|
|
35
44
|
export declare function chooseNavHref(epub: Epub): Promise<string>;
|
|
36
45
|
export declare function removeNcx(epub: Epub): Promise<void>;
|