@prose-reader/enhancer-pdf 1.318.0 → 1.319.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/dist/index.js +40 -91
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +8 -8
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6,52 +6,33 @@ import { DocumentRenderer as d, injectCSSToFrame as f, setAttributeIfChanged as
|
|
|
6
6
|
var b = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), x = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
7
7
|
if (typeof require < "u") return require.apply(this, arguments);
|
|
8
8
|
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
9
|
-
})
|
|
10
|
-
function S(e) {
|
|
11
|
-
let t = [];
|
|
12
|
-
if (e.length === 0) return "";
|
|
13
|
-
if (typeof e[0] != "string") throw TypeError(`Url must be a string. Received ${e[0]}`);
|
|
14
|
-
e[0].match(/^[^/:]+:\/*$/) && e.length > 1 && (e[0] = e.shift() + e[0]), e[0].match(/^file:\/\/\//) ? e[0] = e[0].replace(/^([^/:]+):\/*/, "$1:///") : e[0] = e[0].replace(/^([^/:]+):\/*/, "$1://");
|
|
15
|
-
for (let n = 0; n < e.length; n++) {
|
|
16
|
-
let r = e[n];
|
|
17
|
-
if (typeof r != "string") throw TypeError(`Url must be a string. Received ${r}`);
|
|
18
|
-
r !== "" && (n > 0 && (r = r.replace(/^[/]+/, "")), r = n < e.length - 1 ? r.replace(/[/]+$/, "") : r.replace(/[/]+$/, "/"), t.push(r));
|
|
19
|
-
}
|
|
20
|
-
let n = t.join("/");
|
|
21
|
-
n = n.replace(/\/(\?|&|#[^!])/g, "$1");
|
|
22
|
-
let r = n.split("?");
|
|
23
|
-
return n = r.shift() + (r.length > 0 ? "?" : "") + r.join("&"), n;
|
|
24
|
-
}
|
|
25
|
-
function C(...e) {
|
|
26
|
-
return S(Array.from(Array.isArray(e[0]) ? e[0] : e));
|
|
27
|
-
}
|
|
28
|
-
var w = () => {
|
|
9
|
+
}), S = () => {
|
|
29
10
|
if (!(typeof window > "u")) return window;
|
|
30
11
|
};
|
|
31
|
-
function
|
|
32
|
-
let e =
|
|
12
|
+
function C() {
|
|
13
|
+
let e = S()?.__PROSE_READER_DEBUG;
|
|
33
14
|
return e === !0 || e === "true";
|
|
34
15
|
}
|
|
35
|
-
var
|
|
16
|
+
var w = (e, t) => typeof e == "boolean" ? {
|
|
36
17
|
enabled: e,
|
|
37
18
|
options: t
|
|
38
19
|
} : {
|
|
39
20
|
enabled: e?.enabled,
|
|
40
21
|
options: e ?? t
|
|
41
|
-
},
|
|
22
|
+
}, T = (e) => e.at(-1)?.color, E = (e) => {
|
|
42
23
|
if (!e.length) return;
|
|
43
24
|
if (!e.some((e) => e.color)) return [e.map((e) => e.label).join(" ")];
|
|
44
25
|
let t = "", n = [];
|
|
45
26
|
for (let r of e) t += `%c${t ? ` ${r.label}` : r.label}`, n.push(r.color ? `color: ${r.color}` : "");
|
|
46
27
|
return [t, ...n];
|
|
47
|
-
},
|
|
28
|
+
}, D = (e = [], t = C()) => {
|
|
48
29
|
let n = t, r = {
|
|
49
30
|
enable: (e) => {
|
|
50
31
|
a(e);
|
|
51
32
|
},
|
|
52
33
|
namespace: (t, r, i) => {
|
|
53
|
-
let a =
|
|
54
|
-
return
|
|
34
|
+
let a = w(r, i), o = a.options?.color ?? T(e);
|
|
35
|
+
return D([...e, {
|
|
55
36
|
label: `[${t}]`,
|
|
56
37
|
color: o
|
|
57
38
|
}], a.enabled ?? n);
|
|
@@ -63,7 +44,7 @@ var E = (e, t) => typeof e == "boolean" ? {
|
|
|
63
44
|
groupCollapsed: () => {},
|
|
64
45
|
groupEnd: () => {},
|
|
65
46
|
getGroupArgs: (t) => {
|
|
66
|
-
let n =
|
|
47
|
+
let n = E(e);
|
|
67
48
|
if (!n) return [t];
|
|
68
49
|
let [r, ...i] = n;
|
|
69
50
|
return [`${r} ${t}`, ...i];
|
|
@@ -75,13 +56,13 @@ var E = (e, t) => typeof e == "boolean" ? {
|
|
|
75
56
|
r.debug = () => {}, r.info = () => {}, r.log = () => {}, r.groupCollapsed = () => {}, r.groupEnd = () => {}, r.warn = () => {}, r.error = () => {};
|
|
76
57
|
return;
|
|
77
58
|
}
|
|
78
|
-
let n =
|
|
59
|
+
let n = E(e) ?? [];
|
|
79
60
|
r.debug = Function.prototype.bind.call(console.debug, console, ...n), r.info = Function.prototype.bind.call(console.info, console, ...n), r.log = Function.prototype.bind.call(console.log, console, ...n), r.groupCollapsed = Function.prototype.bind.call(console.groupCollapsed, console), r.groupEnd = Function.prototype.bind.call(console.groupEnd, console), r.warn = Function.prototype.bind.call(console.warn, console, ...n), r.error = Function.prototype.bind.call(console.error, console, ...n);
|
|
80
61
|
}, a = (e) => {
|
|
81
62
|
n !== e && (n = e, i(n));
|
|
82
63
|
};
|
|
83
64
|
return i(n), r;
|
|
84
|
-
},
|
|
65
|
+
}, O = D().namespace("@prose-reader/streamer", !1, { color: "#ffae42" }), k = (e) => {
|
|
85
66
|
let t = {};
|
|
86
67
|
for (let n of e) {
|
|
87
68
|
let e = n.split("/"), r = t;
|
|
@@ -95,7 +76,7 @@ var E = (e, t) => typeof e == "boolean" ? {
|
|
|
95
76
|
return l && Object.keys(l).length > 0 ? `${s}${r}/\n${n(l, c)}` : `${s}${r}`;
|
|
96
77
|
}).join("\n");
|
|
97
78
|
return n(t);
|
|
98
|
-
},
|
|
79
|
+
}, A = ({ records: e, ...t }) => {
|
|
99
80
|
let n = /* @__PURE__ */ new Map();
|
|
100
81
|
for (let t of e) n.has(t.uri) || n.set(t.uri, t);
|
|
101
82
|
let r = {
|
|
@@ -103,15 +84,15 @@ var E = (e, t) => typeof e == "boolean" ? {
|
|
|
103
84
|
records: e,
|
|
104
85
|
recordsByUri: n
|
|
105
86
|
};
|
|
106
|
-
if (
|
|
107
|
-
let t =
|
|
108
|
-
|
|
87
|
+
if (O.log("Generated archive", r), process.env.NODE_ENV === "development" && O.isEnabled()) {
|
|
88
|
+
let t = k(e.map((e) => e.uri));
|
|
89
|
+
O.groupCollapsed(...O.getGroupArgs("Archive folder structure")), O.log(`\n${t}`), O.groupEnd();
|
|
109
90
|
}
|
|
110
91
|
return r;
|
|
111
|
-
},
|
|
92
|
+
}, j = (e) => ({
|
|
112
93
|
blob: e,
|
|
113
94
|
arrayBuffer: () => e().then((e) => e.arrayBuffer())
|
|
114
|
-
}),
|
|
95
|
+
}), M = /* @__PURE__ */ b(((e) => {
|
|
115
96
|
(function(e) {
|
|
116
97
|
e.parser = function(e, t) {
|
|
117
98
|
return new n(e, t);
|
|
@@ -937,12 +918,13 @@ var E = (e, t) => typeof e == "boolean" ? {
|
|
|
937
918
|
}) : String.fromCodePoint = n;
|
|
938
919
|
})();
|
|
939
920
|
})(e === void 0 ? e.sax = {} : e);
|
|
940
|
-
}))
|
|
921
|
+
}));
|
|
922
|
+
(/* @__PURE__ */ b(((e) => {
|
|
941
923
|
var t = e && e.__importDefault || function(e) {
|
|
942
924
|
return e && e.__esModule ? e : { default: e };
|
|
943
925
|
};
|
|
944
926
|
Object.defineProperty(e, "__esModule", { value: !0 }), e.XmlDocument = e.XmlElement = e.XmlCommentNode = e.XmlCDataNode = e.XmlTextNode = void 0;
|
|
945
|
-
var n = t(
|
|
927
|
+
var n = t(M()), r = class {
|
|
946
928
|
constructor(e) {
|
|
947
929
|
this.text = e, this.type = "text";
|
|
948
930
|
}
|
|
@@ -1123,45 +1105,12 @@ var E = (e, t) => typeof e == "boolean" ? {
|
|
|
1123
1105
|
let n = e;
|
|
1124
1106
|
return t?.trimmed && e.length > 25 && (n = n.substring(0, 25).trim() + "…"), t?.preserveWhitespace || (n = n.trim()), n;
|
|
1125
1107
|
}
|
|
1126
|
-
})))()
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
]), L.toLowerCase(), I.toLowerCase(), L.toLowerCase();
|
|
1133
|
-
var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e instanceof F.XmlElement ? R(e) : "").join("").trim() : "", z = (e, { basePath: t, baseUrl: n }) => {
|
|
1134
|
-
let r = {
|
|
1135
|
-
contents: [],
|
|
1136
|
-
path: "",
|
|
1137
|
-
href: "",
|
|
1138
|
-
title: ""
|
|
1139
|
-
}, i = e.childNamed("span") || e.childNamed("a");
|
|
1140
|
-
r.title = (i?.attr.title || i?.val.trim() || R(i)) ?? "";
|
|
1141
|
-
let a = i?.name;
|
|
1142
|
-
a !== "a" && (i = e.descendantWithPath(`${a}.a`), i && (a = i.name.toLowerCase())), a === "a" && i?.attr.href && (r.path = C(t, i.attr.href), r.href = C(n, t, i.attr.href));
|
|
1143
|
-
let o = e.childNamed("ol");
|
|
1144
|
-
if (o) {
|
|
1145
|
-
let e = o.childrenNamed("li");
|
|
1146
|
-
e && e.length > 0 && (r.contents = e.map((e) => z(e, {
|
|
1147
|
-
basePath: t,
|
|
1148
|
-
baseUrl: n
|
|
1149
|
-
})));
|
|
1150
|
-
}
|
|
1151
|
-
return r;
|
|
1152
|
-
}, B = (e, { opfBasePath: t, baseUrl: n, prefix: r }) => {
|
|
1153
|
-
let i = e?.childNamed(`${r}content`)?.attr.src || "", a = {
|
|
1154
|
-
title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
|
|
1155
|
-
path: C(t, i),
|
|
1156
|
-
href: C(n, t, i),
|
|
1157
|
-
contents: []
|
|
1158
|
-
}, o = e.childrenNamed(`${r}navPoint`);
|
|
1159
|
-
return o && o.length > 0 && (a.contents = o.map((e) => B(e, {
|
|
1160
|
-
opfBasePath: t,
|
|
1161
|
-
baseUrl: n,
|
|
1162
|
-
prefix: r
|
|
1163
|
-
}))), a;
|
|
1164
|
-
}, V = Symbol("pdfjs"), H = (e) => "_symbol" in e && e._symbol === V, U = async (e, t) => {
|
|
1108
|
+
})))();
|
|
1109
|
+
var N = "com.apple.ibooks.display-options.xml", P = "ComicInfo.xml";
|
|
1110
|
+
P.toLowerCase(), N.toLowerCase(), P.toLowerCase();
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/createArchiveFromPdf.ts
|
|
1113
|
+
var F = Symbol("pdfjs"), I = (e) => "_symbol" in e && e._symbol === F, L = async (e, t) => {
|
|
1165
1114
|
let n = await c.getDocument(await e.arrayBuffer()).promise, r = Array.from({ length: n.numPages }), i = r.map((e, t) => ({
|
|
1166
1115
|
id: `page-${t}`,
|
|
1167
1116
|
resourcePath: `${t}.pdf`
|
|
@@ -1179,7 +1128,7 @@ var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e
|
|
|
1179
1128
|
</package>
|
|
1180
1129
|
`;
|
|
1181
1130
|
return {
|
|
1182
|
-
...
|
|
1131
|
+
...A({
|
|
1183
1132
|
filename: t,
|
|
1184
1133
|
encodingFormat: "application/pdf",
|
|
1185
1134
|
records: [{
|
|
@@ -1187,29 +1136,29 @@ var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e
|
|
|
1187
1136
|
basename: "content.opf",
|
|
1188
1137
|
uri: "content.opf",
|
|
1189
1138
|
size: 0,
|
|
1190
|
-
...
|
|
1139
|
+
...j(async () => new Blob([a]))
|
|
1191
1140
|
}, ...r.map((e, t) => ({
|
|
1192
1141
|
dir: !1,
|
|
1193
1142
|
basename: `${t}.pdf`,
|
|
1194
1143
|
uri: `${t}.pdf`,
|
|
1195
1144
|
size: 0,
|
|
1196
|
-
...
|
|
1145
|
+
...j(async () => {
|
|
1197
1146
|
throw Error("Unable to get blob from pdf");
|
|
1198
1147
|
})
|
|
1199
1148
|
}))],
|
|
1200
1149
|
close: () => n.cleanup()
|
|
1201
1150
|
}),
|
|
1202
1151
|
proxyDocument: n,
|
|
1203
|
-
_symbol:
|
|
1152
|
+
_symbol: F
|
|
1204
1153
|
};
|
|
1205
|
-
},
|
|
1154
|
+
}, R = "html{touch-action:none}body{width:100%;height:100%;margin:0;padding:0;overflow:hidden}", z = (e, t, n) => {
|
|
1206
1155
|
if (!e) return;
|
|
1207
1156
|
let { height: r, width: i } = n.pageSize;
|
|
1208
1157
|
h(e.style, "width", `${i}px`), h(e.style, "height", `${r}px`), t === "right" ? h(e.style, "justify-content", "flex-start") : t === "left" ? h(e.style, "justify-content", "flex-end") : h(e.style, "justify-content", "center");
|
|
1209
|
-
},
|
|
1158
|
+
}, B = (e, t, n) => {
|
|
1210
1159
|
let r = window.devicePixelRatio || 1, { height: i, width: a } = n.pageSize, { width: o, height: s } = e.getViewport({ scale: 1 }), c = Math.max(a / o, i / s), l = e.getViewport({ scale: c }), u = l.width / l.height, d = a / i, f = u > d ? a : i * u, p = u > d ? a / u : i;
|
|
1211
1160
|
m(t, "width", Math.floor(l.width * r)), m(t, "height", Math.floor(l.height * r)), h(t.style, "width", `${Math.floor(f)}px`), h(t.style, "height", `${Math.floor(p)}px`);
|
|
1212
|
-
},
|
|
1161
|
+
}, V = ":root {\n --scale-factor: 1;\n --user-unit: 1;\n --total-scale-factor: calc(var(--scale-factor) * var(--user-unit));\n --scale-round-x: 1px;\n --scale-round-y: 1px;\n}", H = class extends d {
|
|
1213
1162
|
pdfViewerStyle;
|
|
1214
1163
|
pageProxy;
|
|
1215
1164
|
renderTask;
|
|
@@ -1247,7 +1196,7 @@ var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e
|
|
|
1247
1196
|
return !t || !r ? e : a(t).pipe(y(this.context.bridgeEvent.viewportFree$), s(() => {
|
|
1248
1197
|
this.attach();
|
|
1249
1198
|
}), _, o(() => {
|
|
1250
|
-
f(t, "pdfjs-viewer-style", this.pdfViewerStyle), f(t, "enhancer-pdf-style",
|
|
1199
|
+
f(t, "pdfjs-viewer-style", this.pdfViewerStyle), f(t, "enhancer-pdf-style", R), g(t, "pdf-scale-scale", V);
|
|
1251
1200
|
let r = t.contentDocument?.body;
|
|
1252
1201
|
return !r || !this.pageProxy ? e : (p(r, "class", "textLayer"), this.textLayer = new u({
|
|
1253
1202
|
container: r,
|
|
@@ -1261,10 +1210,10 @@ var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e
|
|
|
1261
1210
|
let r = this.getFrameElement(), i = this.getCanvas();
|
|
1262
1211
|
if (!r || !i) return a(void 0);
|
|
1263
1212
|
let { height: s, width: c } = this.viewport.pageSize;
|
|
1264
|
-
|
|
1213
|
+
z(this.documentContainer, e, this.viewport);
|
|
1265
1214
|
let u = i.getContext("2d"), d = window.devicePixelRatio || 1;
|
|
1266
1215
|
if (!this.pageProxy || !u) return a(void 0);
|
|
1267
|
-
this.renderTask &&= (this.renderTask.cancel(), void 0),
|
|
1216
|
+
this.renderTask &&= (this.renderTask.cancel(), void 0), B(this.pageProxy, i, this.viewport);
|
|
1268
1217
|
let { width: f, height: p } = this.pageProxy.getViewport({ scale: 1 }), m = Math.max(c / f, s / p), g = this.pageProxy.getViewport({ scale: m }), _ = d === 1 ? null : [
|
|
1269
1218
|
d,
|
|
1270
1219
|
0,
|
|
@@ -1299,15 +1248,15 @@ var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e
|
|
|
1299
1248
|
getDocumentFrame() {
|
|
1300
1249
|
return this.getFrameElement();
|
|
1301
1250
|
}
|
|
1302
|
-
},
|
|
1251
|
+
}, U = (e) => (t) => e({
|
|
1303
1252
|
...t,
|
|
1304
1253
|
getRenderer(e) {
|
|
1305
1254
|
let n = t.getRenderer?.(e);
|
|
1306
|
-
return !n && e.href.endsWith(".pdf") ? (e) => new
|
|
1255
|
+
return !n && e.href.endsWith(".pdf") ? (e) => new H(t.pdf.pdfjsViewerInlineCss, e) : n;
|
|
1307
1256
|
},
|
|
1308
1257
|
getResource: (e) => t.pdf.getArchiveForItem(e).pipe(i((t) => {
|
|
1309
1258
|
if (!t) return a(void 0);
|
|
1310
|
-
if (!
|
|
1259
|
+
if (!I(t)) return console.warn("You provided an invalid pdf archive"), a(void 0);
|
|
1311
1260
|
let i = t.records.findIndex((t) => e.href.endsWith(t.uri)) - 1;
|
|
1312
1261
|
return n(t.proxyDocument.getPage(i + 1)).pipe(r((e) => ({
|
|
1313
1262
|
custom: !0,
|
|
@@ -1316,6 +1265,6 @@ var R = (e) => e ? e.children.map((e) => e instanceof F.XmlTextNode ? e.text : e
|
|
|
1316
1265
|
}))
|
|
1317
1266
|
});
|
|
1318
1267
|
//#endregion
|
|
1319
|
-
export {
|
|
1268
|
+
export { L as createArchiveFromPdf, I as isPdfJsArchive, U as pdfEnhancer };
|
|
1320
1269
|
|
|
1321
1270
|
//# sourceMappingURL=index.js.map
|