@prose-reader/enhancer-pdf 1.307.0 → 1.309.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 CHANGED
@@ -81,20 +81,37 @@ var E = (e, t) => typeof e == "boolean" ? {
81
81
  n !== e && (n = e, i(n));
82
82
  };
83
83
  return i(n), r;
84
- }, A = k(), j = ({ records: e, ...t }) => {
84
+ }, A = k().namespace("@prose-reader/streamer", !1, { color: "#ffae42" }), j = (e) => {
85
+ let t = {};
86
+ for (let n of e) {
87
+ let e = n.split("/"), r = t;
88
+ for (let t = 0; t < e.length; t++) {
89
+ let n = e[t];
90
+ n !== void 0 && (r[n] || (r[n] = {}), r = r[n]);
91
+ }
92
+ }
93
+ let n = (e, t = "") => Object.keys(e).sort().map((r, i, a) => {
94
+ let o = i === a.length - 1, s = t + (o ? "└── " : "├── "), c = t + (o ? " " : "│ "), l = e[r];
95
+ return l && Object.keys(l).length > 0 ? `${s}${r}/\n${n(l, c)}` : `${s}${r}`;
96
+ }).join("\n");
97
+ return n(t);
98
+ }, M = ({ records: e, ...t }) => {
85
99
  let n = /* @__PURE__ */ new Map();
86
100
  for (let t of e) n.has(t.uri) || n.set(t.uri, t);
87
- return {
101
+ let r = {
88
102
  ...t,
89
103
  records: e,
90
104
  recordsByUri: n
91
105
  };
92
- };
93
- A.namespace("@prose-reader/streamer", !1, { color: "#ffae42" });
94
- var M = (e) => ({
106
+ if (A.log("Generated archive", r), process.env.NODE_ENV === "development" && A.isEnabled()) {
107
+ let t = j(e.map((e) => e.uri));
108
+ A.groupCollapsed(...A.getGroupArgs("Archive folder structure")), A.log(`\n${t}`), A.groupEnd();
109
+ }
110
+ return r;
111
+ }, N = (e) => ({
95
112
  blob: e,
96
113
  arrayBuffer: () => e().then((e) => e.arrayBuffer())
97
- }), N = /* @__PURE__ */ b(((e) => {
114
+ }), P = /* @__PURE__ */ b(((e) => {
98
115
  (function(e) {
99
116
  e.parser = function(e, t) {
100
117
  return new n(e, t);
@@ -920,12 +937,12 @@ var M = (e) => ({
920
937
  }) : String.fromCodePoint = n;
921
938
  })();
922
939
  })(e === void 0 ? e.sax = {} : e);
923
- })), P = (/* @__PURE__ */ b(((e) => {
940
+ })), F = (/* @__PURE__ */ b(((e) => {
924
941
  var t = e && e.__importDefault || function(e) {
925
942
  return e && e.__esModule ? e : { default: e };
926
943
  };
927
944
  Object.defineProperty(e, "__esModule", { value: !0 }), e.XmlDocument = e.XmlElement = e.XmlCommentNode = e.XmlCDataNode = e.XmlTextNode = void 0;
928
- var n = t(N()), r = class {
945
+ var n = t(P()), r = class {
929
946
  constructor(e) {
930
947
  this.text = e, this.type = "text";
931
948
  }
@@ -1106,45 +1123,45 @@ var M = (e) => ({
1106
1123
  let n = e;
1107
1124
  return t?.trimmed && e.length > 25 && (n = n.substring(0, 25).trim() + "…"), t?.preserveWhitespace || (n = n.trim()), n;
1108
1125
  }
1109
- })))(), F = "com.apple.ibooks.display-options.xml", I = "ComicInfo.xml";
1126
+ })))(), I = "com.apple.ibooks.display-options.xml", L = "ComicInfo.xml";
1110
1127
  new Set(["Pages", "ComicInfo"]), new Set([
1111
1128
  8,
1112
1129
  12,
1113
1130
  13,
1114
1131
  14
1115
- ]), I.toLowerCase(), F.toLowerCase(), I.toLowerCase();
1116
- var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e instanceof P.XmlElement ? L(e) : "").join("").trim() : "", R = (e, { basePath: t, baseUrl: n }) => {
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 }) => {
1117
1134
  let r = {
1118
1135
  contents: [],
1119
1136
  path: "",
1120
1137
  href: "",
1121
1138
  title: ""
1122
1139
  }, i = e.childNamed("span") || e.childNamed("a");
1123
- r.title = (i?.attr.title || i?.val.trim() || L(i)) ?? "";
1140
+ r.title = (i?.attr.title || i?.val.trim() || R(i)) ?? "";
1124
1141
  let a = i?.name;
1125
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));
1126
1143
  let o = e.childNamed("ol");
1127
1144
  if (o) {
1128
1145
  let e = o.childrenNamed("li");
1129
- e && e.length > 0 && (r.contents = e.map((e) => R(e, {
1146
+ e && e.length > 0 && (r.contents = e.map((e) => z(e, {
1130
1147
  basePath: t,
1131
1148
  baseUrl: n
1132
1149
  })));
1133
1150
  }
1134
1151
  return r;
1135
- }, z = (e, { opfBasePath: t, baseUrl: n, prefix: r }) => {
1152
+ }, B = (e, { opfBasePath: t, baseUrl: n, prefix: r }) => {
1136
1153
  let i = e?.childNamed(`${r}content`)?.attr.src || "", a = {
1137
1154
  title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
1138
1155
  path: C(t, i),
1139
1156
  href: C(n, t, i),
1140
1157
  contents: []
1141
1158
  }, o = e.childrenNamed(`${r}navPoint`);
1142
- return o && o.length > 0 && (a.contents = o.map((e) => z(e, {
1159
+ return o && o.length > 0 && (a.contents = o.map((e) => B(e, {
1143
1160
  opfBasePath: t,
1144
1161
  baseUrl: n,
1145
1162
  prefix: r
1146
1163
  }))), a;
1147
- }, B = Symbol("pdfjs"), V = (e) => "_symbol" in e && e._symbol === B, H = async (e, t) => {
1164
+ }, V = Symbol("pdfjs"), H = (e) => "_symbol" in e && e._symbol === V, U = async (e, t) => {
1148
1165
  let n = await c.getDocument(await e.arrayBuffer()).promise, r = Array.from({ length: n.numPages }), i = r.map((e, t) => ({
1149
1166
  id: `page-${t}`,
1150
1167
  resourcePath: `${t}.pdf`
@@ -1162,7 +1179,7 @@ var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e
1162
1179
  </package>
1163
1180
  `;
1164
1181
  return {
1165
- ...j({
1182
+ ...M({
1166
1183
  filename: t,
1167
1184
  encodingFormat: "application/pdf",
1168
1185
  records: [{
@@ -1170,29 +1187,29 @@ var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e
1170
1187
  basename: "content.opf",
1171
1188
  uri: "content.opf",
1172
1189
  size: 0,
1173
- ...M(async () => new Blob([a]))
1190
+ ...N(async () => new Blob([a]))
1174
1191
  }, ...r.map((e, t) => ({
1175
1192
  dir: !1,
1176
1193
  basename: `${t}.pdf`,
1177
1194
  uri: `${t}.pdf`,
1178
1195
  size: 0,
1179
- ...M(async () => {
1196
+ ...N(async () => {
1180
1197
  throw Error("Unable to get blob from pdf");
1181
1198
  })
1182
1199
  }))],
1183
1200
  close: () => n.cleanup()
1184
1201
  }),
1185
1202
  proxyDocument: n,
1186
- _symbol: B
1203
+ _symbol: V
1187
1204
  };
1188
- }, U = "html{touch-action:none}body{width:100%;height:100%;margin:0;padding:0;overflow:hidden}", W = (e, t, n) => {
1205
+ }, W = "html{touch-action:none}body{width:100%;height:100%;margin:0;padding:0;overflow:hidden}", G = (e, t, n) => {
1189
1206
  if (!e) return;
1190
1207
  let { height: r, width: i } = n.pageSize;
1191
1208
  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");
1192
- }, G = (e, t, n) => {
1209
+ }, K = (e, t, n) => {
1193
1210
  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;
1194
1211
  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`);
1195
- }, K = ":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}", q = class extends d {
1212
+ }, q = ":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}", J = class extends d {
1196
1213
  pdfViewerStyle;
1197
1214
  pageProxy;
1198
1215
  renderTask;
@@ -1230,7 +1247,7 @@ var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e
1230
1247
  return !t || !r ? e : a(t).pipe(y(this.context.bridgeEvent.viewportFree$), s(() => {
1231
1248
  this.attach();
1232
1249
  }), _, o(() => {
1233
- f(t, "pdfjs-viewer-style", this.pdfViewerStyle), f(t, "enhancer-pdf-style", U), g(t, "pdf-scale-scale", K);
1250
+ f(t, "pdfjs-viewer-style", this.pdfViewerStyle), f(t, "enhancer-pdf-style", W), g(t, "pdf-scale-scale", q);
1234
1251
  let r = t.contentDocument?.body;
1235
1252
  return !r || !this.pageProxy ? e : (p(r, "class", "textLayer"), this.textLayer = new u({
1236
1253
  container: r,
@@ -1244,10 +1261,10 @@ var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e
1244
1261
  let r = this.getFrameElement(), i = this.getCanvas();
1245
1262
  if (!r || !i) return a(void 0);
1246
1263
  let { height: s, width: c } = this.viewport.pageSize;
1247
- W(this.documentContainer, e, this.viewport);
1264
+ G(this.documentContainer, e, this.viewport);
1248
1265
  let u = i.getContext("2d"), d = window.devicePixelRatio || 1;
1249
1266
  if (!this.pageProxy || !u) return a(void 0);
1250
- this.renderTask &&= (this.renderTask.cancel(), void 0), G(this.pageProxy, i, this.viewport);
1267
+ this.renderTask &&= (this.renderTask.cancel(), void 0), K(this.pageProxy, i, this.viewport);
1251
1268
  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 : [
1252
1269
  d,
1253
1270
  0,
@@ -1282,15 +1299,15 @@ var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e
1282
1299
  getDocumentFrame() {
1283
1300
  return this.getFrameElement();
1284
1301
  }
1285
- }, J = (e) => (t) => e({
1302
+ }, Y = (e) => (t) => e({
1286
1303
  ...t,
1287
1304
  getRenderer(e) {
1288
1305
  let n = t.getRenderer?.(e);
1289
- return !n && e.href.endsWith(".pdf") ? (e) => new q(t.pdf.pdfjsViewerInlineCss, e) : n;
1306
+ return !n && e.href.endsWith(".pdf") ? (e) => new J(t.pdf.pdfjsViewerInlineCss, e) : n;
1290
1307
  },
1291
1308
  getResource: (e) => t.pdf.getArchiveForItem(e).pipe(i((t) => {
1292
1309
  if (!t) return a(void 0);
1293
- if (!V(t)) return console.warn("You provided an invalid pdf archive"), a(void 0);
1310
+ if (!H(t)) return console.warn("You provided an invalid pdf archive"), a(void 0);
1294
1311
  let i = t.records.findIndex((t) => e.href.endsWith(t.uri)) - 1;
1295
1312
  return n(t.proxyDocument.getPage(i + 1)).pipe(r((e) => ({
1296
1313
  custom: !0,
@@ -1299,6 +1316,6 @@ var L = (e) => e ? e.children.map((e) => e instanceof P.XmlTextNode ? e.text : e
1299
1316
  }))
1300
1317
  });
1301
1318
  //#endregion
1302
- export { H as createArchiveFromPdf, V as isPdfJsArchive, J as pdfEnhancer };
1319
+ export { U as createArchiveFromPdf, H as isPdfJsArchive, Y as pdfEnhancer };
1303
1320
 
1304
1321
  //# sourceMappingURL=index.js.map