bookcover-core 0.22.0 → 0.22.2
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/defaults.d.ts +1 -1
- package/dist/defaults.js +1 -1
- package/dist/form_schema.js +1 -1
- package/dist/index.js +15 -3
- package/package.json +3 -3
package/dist/defaults.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const SCHEMA_VERSION = 1;
|
|
|
7
7
|
* the bundled pattern/vector/icon data. Hosts that re-render a frozen record later should
|
|
8
8
|
* record this at freeze time (alongside the typst version their wrapper reports) so a drifted
|
|
9
9
|
* reprint is detectable instead of silent. */
|
|
10
|
-
export declare const RENDER_VERSION =
|
|
10
|
+
export declare const RENDER_VERSION = 6;
|
|
11
11
|
/** What an omitted CoverSchema field resolves to at render time. Derived fields are absent by
|
|
12
12
|
* design — see the note at the top of this file. */
|
|
13
13
|
export declare const SCHEMA_DEFAULTS: {
|
package/dist/defaults.js
CHANGED
|
@@ -19,7 +19,7 @@ export const SCHEMA_VERSION = 1;
|
|
|
19
19
|
* the bundled pattern/vector/icon data. Hosts that re-render a frozen record later should
|
|
20
20
|
* record this at freeze time (alongside the typst version their wrapper reports) so a drifted
|
|
21
21
|
* reprint is detectable instead of silent. */
|
|
22
|
-
export const RENDER_VERSION =
|
|
22
|
+
export const RENDER_VERSION = 6;
|
|
23
23
|
/** What an omitted CoverSchema field resolves to at render time. Derived fields are absent by
|
|
24
24
|
* design — see the note at the top of this file. */
|
|
25
25
|
export const SCHEMA_DEFAULTS = {
|
package/dist/form_schema.js
CHANGED
|
@@ -34,7 +34,7 @@ function build_blurb(doc) {
|
|
|
34
34
|
doc: (node, ctx) => (node.content ?? []).map(child => {
|
|
35
35
|
const rendered = ctx.node(child);
|
|
36
36
|
return text_dir(pm_text(child)) === 'rtl'
|
|
37
|
-
? `#[#set text(dir: rtl)\n${rendered}\n]
|
|
37
|
+
? `#[#set text(dir: rtl)\n${rendered}\n];` : rendered;
|
|
38
38
|
}).join('\n\n'),
|
|
39
39
|
} });
|
|
40
40
|
return typst.trim() ? typst : undefined;
|
package/dist/index.js
CHANGED
|
@@ -41,23 +41,35 @@ export { resolve_dimensions } from './dimensions.js';
|
|
|
41
41
|
export { calculate_crop_regions, calculate_pixel_crop_regions, split_svg, split_png, split_pdf } from './split.js';
|
|
42
42
|
export { resolve_icon } from './icon_cache.js';
|
|
43
43
|
export { frame_image, frame_asset_path } from './frame.js';
|
|
44
|
+
// The string literal inside each #raw(…) that pm-to-typst emits for inline code and code
|
|
45
|
+
// blocks (escape_typst leaves no other bare `#` in blurb markup)
|
|
46
|
+
const RAW_STRING_REGEX = /#raw\((?:block: true, )?("(?:[^"\\]|\\.)*")\)/g;
|
|
44
47
|
/**
|
|
45
48
|
* Wrap each CJK sentence segment of the blurb markup in a #text(font:) span putting that
|
|
46
49
|
* sentence's regional family first, so a blurb mixing e.g. Japanese and Chinese sentences
|
|
47
50
|
* renders each language with its own glyph shapes (per-glyph font fallback alone can't tell
|
|
48
51
|
* shared Han characters apart). Safe on Typst markup: the wrapped ranges contain only CJK
|
|
49
|
-
* characters, which are never Typst syntax
|
|
52
|
+
* characters, which are never Typst syntax, and each span ends with `;` so whatever follows
|
|
53
|
+
* it — `(`, `[` or `.ident`, all of which would otherwise continue the expression — stays
|
|
54
|
+
* markup. Typst consumes that `;` without printing it. CJK inside a #raw string literal is
|
|
55
|
+
* left alone, since a span there would be literal text (and its quotes would end the string).
|
|
50
56
|
*/
|
|
51
57
|
function wrap_blurb_cjk(markup, han_variant, style, chain) {
|
|
52
58
|
const segments = cjk_segments(markup, han_variant);
|
|
53
59
|
if (segments.length === 0) {
|
|
54
60
|
return markup;
|
|
55
61
|
}
|
|
62
|
+
// A CJK run can't contain a `"`, so each segment lies wholly inside or outside a literal
|
|
63
|
+
const raw_strings = [...markup.matchAll(RAW_STRING_REGEX)].map(match => {
|
|
64
|
+
const start = match.index + match[0].indexOf('"');
|
|
65
|
+
return { start, end: start + match[1].length };
|
|
66
|
+
});
|
|
56
67
|
let out = '';
|
|
57
68
|
let pos = 0;
|
|
58
69
|
for (const segment of segments) {
|
|
59
70
|
const family = cjk_family(segment.region, style);
|
|
60
|
-
|
|
71
|
+
const in_raw = raw_strings.some(r => segment.start >= r.start && segment.end <= r.end);
|
|
72
|
+
if (!family || in_raw) {
|
|
61
73
|
continue;
|
|
62
74
|
}
|
|
63
75
|
// The chosen font stays first (it rarely covers CJK, and wins when it does), then
|
|
@@ -65,7 +77,7 @@ function wrap_blurb_cjk(markup, han_variant, style, chain) {
|
|
|
65
77
|
const fonts = [chain[0], family, ...chain.slice(1).filter(f => f !== family)];
|
|
66
78
|
const font_list = fonts.map(f => `"${escape_typst_str(f)}"`).join(', ');
|
|
67
79
|
out += markup.slice(pos, segment.start);
|
|
68
|
-
out += `#text(font: (${font_list},))[${markup.slice(segment.start, segment.end)}]
|
|
80
|
+
out += `#text(font: (${font_list},))[${markup.slice(segment.start, segment.end)}];`;
|
|
69
81
|
pos = segment.end;
|
|
70
82
|
}
|
|
71
83
|
return out + markup.slice(pos);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bookcover-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"license": "MIT-0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"big.js": "^7.0.1",
|
|
42
42
|
"bwip-js": "^4.9.0",
|
|
43
43
|
"chroma-js": "^3.2.0",
|
|
44
|
-
"pm-to-typst": "^0.1.
|
|
44
|
+
"pm-to-typst": "^0.1.2",
|
|
45
45
|
"printing-services": "^1.5.1",
|
|
46
|
-
"typst-fonts": "^0.1.
|
|
46
|
+
"typst-fonts": "^0.1.4",
|
|
47
47
|
"typst-utils": "^0.2.0",
|
|
48
48
|
"zod": "^4.3.6"
|
|
49
49
|
},
|