epub-codec 0.0.0 → 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 +21 -0
- package/README.md +184 -0
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +2308 -0
- package/dist/codec.d.ts +2308 -0
- package/dist/codec.js +25 -0
- package/dist/diagnostics-Ee4kG7mw.d.cts +60 -0
- package/dist/diagnostics-Ee4kG7mw.d.ts +60 -0
- package/dist/diagnostics.cjs +96 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +85 -0
- package/dist/format.cjs +9 -0
- package/dist/format.d.cts +6 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +6 -0
- package/dist/image/dimensions.cjs +82 -0
- package/dist/image/dimensions.d.cts +11 -0
- package/dist/image/dimensions.d.ts +11 -0
- package/dist/image/dimensions.js +79 -0
- package/dist/index.cjs +105 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/nav/nav3.cjs +19 -0
- package/dist/nav/nav3.d.cts +4 -0
- package/dist/nav/nav3.d.ts +4 -0
- package/dist/nav/nav3.js +18 -0
- package/dist/nav/ncx.cjs +17 -0
- package/dist/nav/ncx.d.cts +4 -0
- package/dist/nav/ncx.d.ts +4 -0
- package/dist/nav/ncx.js +16 -0
- package/dist/nav/reconcile.cjs +8 -0
- package/dist/nav/reconcile.d.cts +4 -0
- package/dist/nav/reconcile.d.ts +4 -0
- package/dist/nav/reconcile.js +7 -0
- package/dist/nav/write.cjs +39 -0
- package/dist/nav/write.d.cts +10 -0
- package/dist/nav/write.d.ts +10 -0
- package/dist/nav/write.js +37 -0
- package/dist/ocf/container.cjs +20 -0
- package/dist/ocf/container.d.cts +4 -0
- package/dist/ocf/container.d.ts +4 -0
- package/dist/ocf/container.js +19 -0
- package/dist/ocf/write.cjs +13 -0
- package/dist/ocf/write.d.cts +4 -0
- package/dist/ocf/write.d.ts +4 -0
- package/dist/ocf/write.js +12 -0
- package/dist/opf/metadata.cjs +51 -0
- package/dist/opf/metadata.d.cts +7 -0
- package/dist/opf/metadata.d.ts +7 -0
- package/dist/opf/metadata.js +50 -0
- package/dist/opf/parse.cjs +47 -0
- package/dist/opf/parse.d.cts +6 -0
- package/dist/opf/parse.d.ts +6 -0
- package/dist/opf/parse.js +46 -0
- package/dist/opf/types.cjs +0 -0
- package/dist/opf/types.d.cts +20 -0
- package/dist/opf/types.d.ts +20 -0
- package/dist/opf/types.js +0 -0
- package/dist/opf/write.cjs +55 -0
- package/dist/opf/write.d.cts +12 -0
- package/dist/opf/write.d.ts +12 -0
- package/dist/opf/write.js +54 -0
- package/dist/path.cjs +22 -0
- package/dist/path.d.cts +5 -0
- package/dist/path.d.ts +5 -0
- package/dist/path.js +20 -0
- package/dist/read.cjs +166 -0
- package/dist/read.d.cts +10 -0
- package/dist/read.d.ts +10 -0
- package/dist/read.js +164 -0
- package/dist/util/base64.cjs +51 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +49 -0
- package/dist/write.cjs +136 -0
- package/dist/write.d.cts +10 -0
- package/dist/write.d.ts +10 -0
- package/dist/write.js +134 -0
- package/dist/xhtml/context.cjs +0 -0
- package/dist/xhtml/context.d.cts +20 -0
- package/dist/xhtml/context.d.ts +20 -0
- package/dist/xhtml/context.js +0 -0
- package/dist/xhtml/footnote.cjs +32 -0
- package/dist/xhtml/footnote.d.cts +7 -0
- package/dist/xhtml/footnote.d.ts +7 -0
- package/dist/xhtml/footnote.js +29 -0
- package/dist/xhtml/inline.cjs +128 -0
- package/dist/xhtml/inline.d.cts +11 -0
- package/dist/xhtml/inline.d.ts +11 -0
- package/dist/xhtml/inline.js +127 -0
- package/dist/xhtml/list-id.cjs +22 -0
- package/dist/xhtml/list-id.d.cts +13 -0
- package/dist/xhtml/list-id.d.ts +13 -0
- package/dist/xhtml/list-id.js +20 -0
- package/dist/xhtml/read.cjs +423 -0
- package/dist/xhtml/read.d.cts +20 -0
- package/dist/xhtml/read.d.ts +20 -0
- package/dist/xhtml/read.js +422 -0
- package/dist/xhtml/style-constants.cjs +13 -0
- package/dist/xhtml/style-constants.d.cts +8 -0
- package/dist/xhtml/style-constants.d.ts +8 -0
- package/dist/xhtml/style-constants.js +8 -0
- package/dist/xhtml/write.cjs +183 -0
- package/dist/xhtml/write.d.cts +12 -0
- package/dist/xhtml/write.d.ts +12 -0
- package/dist/xhtml/write.js +182 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +20 -0
- package/dist/xml/entities.d.cts +5 -0
- package/dist/xml/entities.d.ts +5 -0
- package/dist/xml/entities.js +18 -0
- package/dist/xml/node.cjs +67 -0
- package/dist/xml/node.d.cts +83 -0
- package/dist/xml/node.d.ts +83 -0
- package/dist/xml/node.js +58 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/xml/query.cjs +44 -0
- package/dist/xml/query.d.cts +11 -0
- package/dist/xml/query.d.ts +11 -0
- package/dist/xml/query.js +37 -0
- package/dist/zip.cjs +19 -0
- package/dist/zip.d.cts +9 -0
- package/dist/zip.d.ts +9 -0
- package/dist/zip.js +17 -0
- package/package.json +95 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/xml/parse.ts
|
|
3
|
+
const PARSER = new (require("fast-xml-parser")).XMLParser({
|
|
4
|
+
preserveOrder: true,
|
|
5
|
+
attributeNamePrefix: "@_",
|
|
6
|
+
ignoreAttributes: false,
|
|
7
|
+
textNodeName: "#text",
|
|
8
|
+
cdataPropName: "__cdata",
|
|
9
|
+
commentPropName: "__comment",
|
|
10
|
+
processEntities: false,
|
|
11
|
+
parseTagValue: false,
|
|
12
|
+
trimValues: false
|
|
13
|
+
});
|
|
14
|
+
function parseXml(xml) {
|
|
15
|
+
return parseNodes(PARSER.parse(xml));
|
|
16
|
+
}
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function isUnknownArray(value) {
|
|
21
|
+
return Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function asString(value) {
|
|
24
|
+
if (typeof value !== "string") throw new Error(`expected string while parsing XML, got ${typeof value}`);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function parseNodes(raw) {
|
|
28
|
+
if (!isUnknownArray(raw)) throw new Error("fast-xml-parser output was not an ordered array");
|
|
29
|
+
return raw.map(parseNode);
|
|
30
|
+
}
|
|
31
|
+
function parseNode(raw) {
|
|
32
|
+
if (!isRecord(raw)) throw new Error("fast-xml-parser node was not an object");
|
|
33
|
+
let tagKey;
|
|
34
|
+
for (const key of Object.keys(raw)) if (key !== ":@") {
|
|
35
|
+
if (tagKey !== void 0) throw new Error("XML node had multiple tag keys");
|
|
36
|
+
tagKey = key;
|
|
37
|
+
}
|
|
38
|
+
if (tagKey === void 0) throw new Error("XML node had no tag key");
|
|
39
|
+
const attributes = parseAttributes(raw[":@"]);
|
|
40
|
+
if (tagKey === "#text") return {
|
|
41
|
+
type: "text",
|
|
42
|
+
value: asString(raw["#text"])
|
|
43
|
+
};
|
|
44
|
+
if (tagKey === "__comment") return {
|
|
45
|
+
type: "comment",
|
|
46
|
+
value: scalarText(raw.__comment)
|
|
47
|
+
};
|
|
48
|
+
if (tagKey === "__cdata") return {
|
|
49
|
+
type: "cdata",
|
|
50
|
+
value: scalarText(raw.__cdata)
|
|
51
|
+
};
|
|
52
|
+
if (tagKey === "?xml") return {
|
|
53
|
+
type: "declaration",
|
|
54
|
+
attributes
|
|
55
|
+
};
|
|
56
|
+
if (tagKey.startsWith("?")) return {
|
|
57
|
+
type: "pi",
|
|
58
|
+
target: tagKey.slice(1),
|
|
59
|
+
content: scalarText(raw[tagKey])
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
type: "element",
|
|
63
|
+
tag: tagKey,
|
|
64
|
+
attributes,
|
|
65
|
+
children: parseNodes(raw[tagKey])
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function parseAttributes(raw) {
|
|
69
|
+
if (raw === void 0) return [];
|
|
70
|
+
if (!isRecord(raw)) throw new Error("XML attributes were not an object");
|
|
71
|
+
const attrs = [];
|
|
72
|
+
for (const key of Object.keys(raw)) {
|
|
73
|
+
if (!key.startsWith("@_")) throw new Error(`unexpected attribute key without @_ prefix: ${key}`);
|
|
74
|
+
attrs.push({
|
|
75
|
+
name: key.slice(2),
|
|
76
|
+
value: asString(raw[key])
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return attrs;
|
|
80
|
+
}
|
|
81
|
+
function scalarText(raw) {
|
|
82
|
+
if (!isUnknownArray(raw) || raw.length === 0) throw new Error("expected a scalar-text wrapper array");
|
|
83
|
+
const first = raw[0];
|
|
84
|
+
if (!isRecord(first)) throw new Error("scalar-text wrapper was not an object");
|
|
85
|
+
return asString(first["#text"]);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.parseXml = parseXml;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
|
+
//#region src/xml/parse.ts
|
|
3
|
+
const PARSER = new XMLParser({
|
|
4
|
+
preserveOrder: true,
|
|
5
|
+
attributeNamePrefix: "@_",
|
|
6
|
+
ignoreAttributes: false,
|
|
7
|
+
textNodeName: "#text",
|
|
8
|
+
cdataPropName: "__cdata",
|
|
9
|
+
commentPropName: "__comment",
|
|
10
|
+
processEntities: false,
|
|
11
|
+
parseTagValue: false,
|
|
12
|
+
trimValues: false
|
|
13
|
+
});
|
|
14
|
+
function parseXml(xml) {
|
|
15
|
+
return parseNodes(PARSER.parse(xml));
|
|
16
|
+
}
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function isUnknownArray(value) {
|
|
21
|
+
return Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function asString(value) {
|
|
24
|
+
if (typeof value !== "string") throw new Error(`expected string while parsing XML, got ${typeof value}`);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function parseNodes(raw) {
|
|
28
|
+
if (!isUnknownArray(raw)) throw new Error("fast-xml-parser output was not an ordered array");
|
|
29
|
+
return raw.map(parseNode);
|
|
30
|
+
}
|
|
31
|
+
function parseNode(raw) {
|
|
32
|
+
if (!isRecord(raw)) throw new Error("fast-xml-parser node was not an object");
|
|
33
|
+
let tagKey;
|
|
34
|
+
for (const key of Object.keys(raw)) if (key !== ":@") {
|
|
35
|
+
if (tagKey !== void 0) throw new Error("XML node had multiple tag keys");
|
|
36
|
+
tagKey = key;
|
|
37
|
+
}
|
|
38
|
+
if (tagKey === void 0) throw new Error("XML node had no tag key");
|
|
39
|
+
const attributes = parseAttributes(raw[":@"]);
|
|
40
|
+
if (tagKey === "#text") return {
|
|
41
|
+
type: "text",
|
|
42
|
+
value: asString(raw["#text"])
|
|
43
|
+
};
|
|
44
|
+
if (tagKey === "__comment") return {
|
|
45
|
+
type: "comment",
|
|
46
|
+
value: scalarText(raw.__comment)
|
|
47
|
+
};
|
|
48
|
+
if (tagKey === "__cdata") return {
|
|
49
|
+
type: "cdata",
|
|
50
|
+
value: scalarText(raw.__cdata)
|
|
51
|
+
};
|
|
52
|
+
if (tagKey === "?xml") return {
|
|
53
|
+
type: "declaration",
|
|
54
|
+
attributes
|
|
55
|
+
};
|
|
56
|
+
if (tagKey.startsWith("?")) return {
|
|
57
|
+
type: "pi",
|
|
58
|
+
target: tagKey.slice(1),
|
|
59
|
+
content: scalarText(raw[tagKey])
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
type: "element",
|
|
63
|
+
tag: tagKey,
|
|
64
|
+
attributes,
|
|
65
|
+
children: parseNodes(raw[tagKey])
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function parseAttributes(raw) {
|
|
69
|
+
if (raw === void 0) return [];
|
|
70
|
+
if (!isRecord(raw)) throw new Error("XML attributes were not an object");
|
|
71
|
+
const attrs = [];
|
|
72
|
+
for (const key of Object.keys(raw)) {
|
|
73
|
+
if (!key.startsWith("@_")) throw new Error(`unexpected attribute key without @_ prefix: ${key}`);
|
|
74
|
+
attrs.push({
|
|
75
|
+
name: key.slice(2),
|
|
76
|
+
value: asString(raw[key])
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return attrs;
|
|
80
|
+
}
|
|
81
|
+
function scalarText(raw) {
|
|
82
|
+
if (!isUnknownArray(raw) || raw.length === 0) throw new Error("expected a scalar-text wrapper array");
|
|
83
|
+
const first = raw[0];
|
|
84
|
+
if (!isRecord(first)) throw new Error("scalar-text wrapper was not an object");
|
|
85
|
+
return asString(first["#text"]);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { parseXml };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/xml/query.ts
|
|
3
|
+
function rootElement(nodes) {
|
|
4
|
+
for (const node of nodes) if (node.type === "element") return node;
|
|
5
|
+
}
|
|
6
|
+
function findChildElement(nodes, tag) {
|
|
7
|
+
for (const node of nodes) if (node.type === "element" && node.tag === tag) return node;
|
|
8
|
+
}
|
|
9
|
+
function childrenWithTag(element, tag) {
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
function* walk(nodes) {
|
|
15
|
+
for (const node of nodes) {
|
|
16
|
+
yield node;
|
|
17
|
+
if (node.type === "element") yield* walk(node.children);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function elementsWithTag(nodes, tag) {
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
function findElement(nodes, predicate) {
|
|
26
|
+
for (const node of walk(nodes)) if (node.type === "element" && predicate(node)) return node;
|
|
27
|
+
}
|
|
28
|
+
function attrValue(element, name) {
|
|
29
|
+
return element.attributes.find((attribute) => attribute.name === name)?.value;
|
|
30
|
+
}
|
|
31
|
+
function textContent(nodes) {
|
|
32
|
+
let out = "";
|
|
33
|
+
for (const node of nodes) if (node.type === "text") out += node.value;
|
|
34
|
+
else if (node.type === "element") out += textContent(node.children);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.attrValue = attrValue;
|
|
39
|
+
exports.childrenWithTag = childrenWithTag;
|
|
40
|
+
exports.elementsWithTag = elementsWithTag;
|
|
41
|
+
exports.findChildElement = findChildElement;
|
|
42
|
+
exports.findElement = findElement;
|
|
43
|
+
exports.rootElement = rootElement;
|
|
44
|
+
exports.textContent = textContent;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { XmlElement, XmlNode } from "./node.cjs";
|
|
2
|
+
//#region src/xml/query.d.ts
|
|
3
|
+
declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
|
|
4
|
+
declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
|
|
5
|
+
declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
|
|
6
|
+
declare function elementsWithTag(nodes: readonly XmlNode[], tag: string): XmlElement[];
|
|
7
|
+
declare function findElement(nodes: readonly XmlNode[], predicate: (element: XmlElement) => boolean): XmlElement | undefined;
|
|
8
|
+
declare function attrValue(element: XmlElement, name: string): string | undefined;
|
|
9
|
+
declare function textContent(nodes: readonly XmlNode[]): string;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { attrValue, childrenWithTag, elementsWithTag, findChildElement, findElement, rootElement, textContent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { XmlElement, XmlNode } from "./node.js";
|
|
2
|
+
//#region src/xml/query.d.ts
|
|
3
|
+
declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
|
|
4
|
+
declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
|
|
5
|
+
declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
|
|
6
|
+
declare function elementsWithTag(nodes: readonly XmlNode[], tag: string): XmlElement[];
|
|
7
|
+
declare function findElement(nodes: readonly XmlNode[], predicate: (element: XmlElement) => boolean): XmlElement | undefined;
|
|
8
|
+
declare function attrValue(element: XmlElement, name: string): string | undefined;
|
|
9
|
+
declare function textContent(nodes: readonly XmlNode[]): string;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { attrValue, childrenWithTag, elementsWithTag, findChildElement, findElement, rootElement, textContent };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/xml/query.ts
|
|
2
|
+
function rootElement(nodes) {
|
|
3
|
+
for (const node of nodes) if (node.type === "element") return node;
|
|
4
|
+
}
|
|
5
|
+
function findChildElement(nodes, tag) {
|
|
6
|
+
for (const node of nodes) if (node.type === "element" && node.tag === tag) return node;
|
|
7
|
+
}
|
|
8
|
+
function childrenWithTag(element, tag) {
|
|
9
|
+
const out = [];
|
|
10
|
+
for (const child of element.children) if (child.type === "element" && child.tag === tag) out.push(child);
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
function* walk(nodes) {
|
|
14
|
+
for (const node of nodes) {
|
|
15
|
+
yield node;
|
|
16
|
+
if (node.type === "element") yield* walk(node.children);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function elementsWithTag(nodes, tag) {
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const node of walk(nodes)) if (node.type === "element" && node.tag === tag) out.push(node);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
function findElement(nodes, predicate) {
|
|
25
|
+
for (const node of walk(nodes)) if (node.type === "element" && predicate(node)) return node;
|
|
26
|
+
}
|
|
27
|
+
function attrValue(element, name) {
|
|
28
|
+
return element.attributes.find((attribute) => attribute.name === name)?.value;
|
|
29
|
+
}
|
|
30
|
+
function textContent(nodes) {
|
|
31
|
+
let out = "";
|
|
32
|
+
for (const node of nodes) if (node.type === "text") out += node.value;
|
|
33
|
+
else if (node.type === "element") out += textContent(node.children);
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { attrValue, childrenWithTag, elementsWithTag, findChildElement, findElement, rootElement, textContent };
|
package/dist/zip.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let fflate = require("fflate");
|
|
3
|
+
//#region src/zip.ts
|
|
4
|
+
function unzipPackage(bytes) {
|
|
5
|
+
return (0, fflate.unzipSync)(bytes);
|
|
6
|
+
}
|
|
7
|
+
const FIXED_ENTRY_MTIME = new Date(Date.UTC(1980, 0, 1, 0, 0, 0));
|
|
8
|
+
function zipPackage(entries) {
|
|
9
|
+
const data = {};
|
|
10
|
+
for (const [path, entry] of entries) if (entry.stored === true) data[path] = [entry.bytes, {
|
|
11
|
+
level: 0,
|
|
12
|
+
mtime: FIXED_ENTRY_MTIME
|
|
13
|
+
}];
|
|
14
|
+
else data[path] = [entry.bytes, { mtime: FIXED_ENTRY_MTIME }];
|
|
15
|
+
return (0, fflate.zipSync)(data);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.unzipPackage = unzipPackage;
|
|
19
|
+
exports.zipPackage = zipPackage;
|
package/dist/zip.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/zip.d.ts
|
|
2
|
+
interface ZipEntry {
|
|
3
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
4
|
+
readonly stored?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function unzipPackage(bytes: Uint8Array<ArrayBuffer>): Record<string, Uint8Array<ArrayBuffer>>;
|
|
7
|
+
declare function zipPackage(entries: readonly (readonly [string, ZipEntry])[]): Uint8Array<ArrayBuffer>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ZipEntry, unzipPackage, zipPackage };
|
package/dist/zip.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/zip.d.ts
|
|
2
|
+
interface ZipEntry {
|
|
3
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
4
|
+
readonly stored?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function unzipPackage(bytes: Uint8Array<ArrayBuffer>): Record<string, Uint8Array<ArrayBuffer>>;
|
|
7
|
+
declare function zipPackage(entries: readonly (readonly [string, ZipEntry])[]): Uint8Array<ArrayBuffer>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ZipEntry, unzipPackage, zipPackage };
|
package/dist/zip.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { unzipSync, zipSync } from "fflate";
|
|
2
|
+
//#region src/zip.ts
|
|
3
|
+
function unzipPackage(bytes) {
|
|
4
|
+
return unzipSync(bytes);
|
|
5
|
+
}
|
|
6
|
+
const FIXED_ENTRY_MTIME = new Date(Date.UTC(1980, 0, 1, 0, 0, 0));
|
|
7
|
+
function zipPackage(entries) {
|
|
8
|
+
const data = {};
|
|
9
|
+
for (const [path, entry] of entries) if (entry.stored === true) data[path] = [entry.bytes, {
|
|
10
|
+
level: 0,
|
|
11
|
+
mtime: FIXED_ENTRY_MTIME
|
|
12
|
+
}];
|
|
13
|
+
else data[path] = [entry.bytes, { mtime: FIXED_ENTRY_MTIME }];
|
|
14
|
+
return zipSync(data);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { unzipPackage, zipPackage };
|
package/package.json
CHANGED
|
@@ -1,5 +1,98 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epub-codec",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "EPUB 2/3 reading and deterministic EPUB 3 writing against the shared document-schema.js content pivot.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ExaDev/documents.js.git",
|
|
9
|
+
"directory": "packages/epub-codec"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/ExaDev/documents.js/tree/main/packages/epub-codec",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ExaDev/documents.js/issues"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": {
|
|
18
|
+
"import": "./dist/index.d.ts",
|
|
19
|
+
"require": "./dist/index.d.cts"
|
|
20
|
+
},
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./*": {
|
|
25
|
+
"types": {
|
|
26
|
+
"import": "./dist/*.d.ts",
|
|
27
|
+
"require": "./dist/*.d.cts"
|
|
28
|
+
},
|
|
29
|
+
"import": "./dist/*.js",
|
|
30
|
+
"require": "./dist/*.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true,
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "turbo run _build",
|
|
50
|
+
"_build": "tsdown",
|
|
51
|
+
"prepublishOnly": "pnpm run lint && pnpm run typecheck && tsdown && publint && attw --pack",
|
|
52
|
+
"lint": "turbo run _lint",
|
|
53
|
+
"_lint": "eslint . --fix --cache --max-warnings 0",
|
|
54
|
+
"lint:check": "eslint . --max-warnings 0",
|
|
55
|
+
"typecheck": "turbo run _typecheck _typecheck:attw",
|
|
56
|
+
"_typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.node.json",
|
|
57
|
+
"_typecheck:attw": "attw --pack",
|
|
58
|
+
"test": "turbo run _test",
|
|
59
|
+
"_test": "vitest run --project unit",
|
|
60
|
+
"test:watch": "vitest --project unit",
|
|
61
|
+
"test:workers": "turbo run _test:workers",
|
|
62
|
+
"_test:workers": "vitest run --config vitest.workers.config.ts",
|
|
63
|
+
"test:smoke": "turbo run _test:smoke",
|
|
64
|
+
"_test:smoke": "vitest run --project smoke",
|
|
65
|
+
"prepare": "husky"
|
|
66
|
+
},
|
|
67
|
+
"keywords": [
|
|
68
|
+
"epub",
|
|
69
|
+
"epub2",
|
|
70
|
+
"epub3",
|
|
71
|
+
"codec",
|
|
72
|
+
"zod",
|
|
73
|
+
"ebook"
|
|
74
|
+
],
|
|
75
|
+
"license": "MIT",
|
|
76
|
+
"packageManager": "pnpm@11.6.0",
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"document-schema.js": "^5.4.0",
|
|
79
|
+
"fast-xml-parser": "^5.10.1",
|
|
80
|
+
"fflate": "^0.8.3",
|
|
81
|
+
"zod": "^4.4.3"
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
85
|
+
"@cloudflare/vitest-pool-workers": "^0.20.1",
|
|
86
|
+
"@types/node": "^26.1.2",
|
|
87
|
+
"eslint": "^10.8.0",
|
|
88
|
+
"husky": "^9.1.7",
|
|
89
|
+
"publint": "^0.3.21",
|
|
90
|
+
"tsdown": "^0.22.13",
|
|
91
|
+
"turbo": "^2.10.8",
|
|
92
|
+
"typescript": "^6.0.3",
|
|
93
|
+
"vitest": "^4.1.10"
|
|
94
|
+
},
|
|
95
|
+
"lint-staged": {
|
|
96
|
+
"*.ts": "eslint --fix"
|
|
97
|
+
}
|
|
5
98
|
}
|