postext-epub 0.42.0 → 0.43.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/worker/serve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/worker/serve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAqD7E,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAC1E,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IACrG,KAAK,IAAI,IAAI,CAAC;CACf;AAED;wDACwD;AACxD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CA8C5D"}
|
package/dist/worker/serve.js
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
// The worker side of `createEpubWorker`: answers render requests on a
|
|
2
2
|
// message port (the worker's global scope, or a MessagePort in tests).
|
|
3
|
+
import { evictFontFamilies } from 'postext';
|
|
3
4
|
import { renderToEpub } from '../index.js';
|
|
5
|
+
/** The faces already in this worker's set, by family, weight, slant and
|
|
6
|
+
* range: a book written again does not add them twice. */
|
|
7
|
+
const registered = new Set();
|
|
8
|
+
/**
|
|
9
|
+
* Give the worker's own `FontFaceSet` the book's faces before its pages
|
|
10
|
+
* are written.
|
|
11
|
+
*
|
|
12
|
+
* A worker has none of the page's fonts, and the pages' markup measures
|
|
13
|
+
* text again as it writes it: the words of a design text go in a box
|
|
14
|
+
* each, at the width the measurer gives them (`wordBoxesHtml`), and the
|
|
15
|
+
* pieces of a word are joined at theirs (`wordSegmentsOf`). Without the
|
|
16
|
+
* faces every one of those is measured in the worker's fallback, which
|
|
17
|
+
* pulls the words of a contents heading apart and runs its leader over
|
|
18
|
+
* them. The bytes are already here to be embedded, so the set takes them
|
|
19
|
+
* from the same files.
|
|
20
|
+
*
|
|
21
|
+
* Widths measured before the faces landed were measured in the fallback:
|
|
22
|
+
* `evictFontFamilies` drops them, with pretext's glyph cache. A face the
|
|
23
|
+
* set will not take is skipped and the writer falls back on its own
|
|
24
|
+
* (`measuresOwnFace`).
|
|
25
|
+
*/
|
|
26
|
+
async function registerWorkerFonts(fonts) {
|
|
27
|
+
const set = globalThis.fonts;
|
|
28
|
+
if (!set || typeof FontFace === 'undefined' || !fonts || fonts.length === 0)
|
|
29
|
+
return;
|
|
30
|
+
const loaded = await Promise.all(fonts.map(async (f) => {
|
|
31
|
+
const key = `${f.family}\u0000${f.weight}\u0000${f.style}\u0000${f.unicodeRange ?? ''}`;
|
|
32
|
+
if (registered.has(key))
|
|
33
|
+
return null;
|
|
34
|
+
try {
|
|
35
|
+
const face = new FontFace(f.family, f.bytes, {
|
|
36
|
+
weight: String(f.weight),
|
|
37
|
+
style: f.style,
|
|
38
|
+
...(f.unicodeRange !== undefined ? { unicodeRange: f.unicodeRange } : {}),
|
|
39
|
+
});
|
|
40
|
+
await face.load();
|
|
41
|
+
return { key, face, family: f.family };
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.warn('[postext-epub/worker] failed to register font', f.family, err);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
const added = new Set();
|
|
49
|
+
for (const entry of loaded) {
|
|
50
|
+
if (!entry || registered.has(entry.key))
|
|
51
|
+
continue;
|
|
52
|
+
set.add(entry.face);
|
|
53
|
+
registered.add(entry.key);
|
|
54
|
+
added.add(entry.family);
|
|
55
|
+
}
|
|
56
|
+
if (added.size > 0)
|
|
57
|
+
evictFontFamilies(added);
|
|
58
|
+
}
|
|
4
59
|
/** Write the books asked for on `port`, one `renderToEpub` per request,
|
|
5
60
|
* with progress and warnings posted as they happen. */
|
|
6
61
|
export function serveEpubRequests(port) {
|
|
@@ -14,6 +69,8 @@ export function serveEpubRequests(port) {
|
|
|
14
69
|
running.set(msg.id, controller);
|
|
15
70
|
const bytesById = new Map(msg.resourceBytes);
|
|
16
71
|
try {
|
|
72
|
+
// The faces first: the pages are measured as they are written.
|
|
73
|
+
await registerWorkerFonts(msg.settings.fonts);
|
|
17
74
|
const bytes = await renderToEpub(msg.docs, {
|
|
18
75
|
...msg.settings,
|
|
19
76
|
resourceBytes: (fileId) => bytesById.get(fileId),
|
package/dist/worker/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/worker/serve.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,uEAAuE;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/worker/serve.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,uEAAuE;AAEvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C;2DAC2D;AAC3D,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;AAErC;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,UAAU,mBAAmB,CAAC,KAA0C;IAC3E,MAAM,GAAG,GAAI,UAAsC,CAAC,KAAK,CAAC;IAC1D,IAAI,CAAC,GAAG,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACpF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC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,MAAM,EAAE;oBAAE,UAAU,CAAC,KAAK,EAAE,CAAC;gBAC9D,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postext-epub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Browser-native EPUB 3 writer for Postext documents: fixed-layout (pre-paginated) books that reproduce every printed page with real text, and reflowable books in semantic XHTML styled from the same configuration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"./package.json": "./package.json"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"postext": "^1.
|
|
45
|
+
"postext": "^1.57.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"fflate": "^0.8.3"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@postext/typescript-config": "0.0.0",
|
|
52
52
|
"@types/node": "^26.5.0",
|
|
53
53
|
"eslint": "^9.39.4",
|
|
54
|
-
"postext": "1.
|
|
54
|
+
"postext": "1.57.0",
|
|
55
55
|
"typescript": "^6.0.3",
|
|
56
56
|
"typescript-eslint": "^8.70.0",
|
|
57
57
|
"vitest": "^5.0.0"
|