bookcover-core 0.12.0 → 0.13.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/font_sizes.d.ts.map +1 -1
- package/dist/font_sizes.js +4 -40
- package/dist/font_sizes.js.map +1 -1
- package/package.json +1 -1
package/dist/font_sizes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font_sizes.d.ts","sourceRoot":"","sources":["../src/font_sizes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAE1D,MAAM,WAAW,SAAS;IACtB,cAAc,EAAC,MAAM,EAAE,CAAA;IACvB,UAAU,EAAC,MAAM,CAAA;IACjB,WAAW,EAAC,MAAM,CAAA;IAClB,YAAY,EAAC,MAAM,CAAA;CACtB;
|
|
1
|
+
{"version":3,"file":"font_sizes.d.ts","sourceRoot":"","sources":["../src/font_sizes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAE1D,MAAM,WAAW,SAAS;IACtB,cAAc,EAAC,MAAM,EAAE,CAAA;IACvB,UAAU,EAAC,MAAM,CAAA;IACjB,WAAW,EAAC,MAAM,CAAA;IAClB,YAAY,EAAC,MAAM,CAAA;CACtB;AAwBD,sEAAsE;AACtE,wBAAgB,oBAAoB,CAChC,MAAM,EAAC,WAAW,EAClB,IAAI,EAAC,mBAAmB,GAC1B,SAAS,CAsCV"}
|
package/dist/font_sizes.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
import { clamp } from './utils.js';
|
|
3
3
|
// Average character width as a fraction of font size (proportional fonts)
|
|
4
4
|
const CHAR_WIDTH_RATIO = 0.55;
|
|
5
|
-
// Assumed side margin as fraction of panel width
|
|
6
|
-
const MARGIN_RATIO = 0.12;
|
|
7
5
|
// Minimum spine width in mm before text is suppressed
|
|
8
6
|
const MIN_SPINE_MM = 5;
|
|
9
7
|
/**
|
|
@@ -22,47 +20,13 @@ function fit_size(text, available_mm, max_lines, min_mm, max_mm) {
|
|
|
22
20
|
}
|
|
23
21
|
/** Calculate all font sizes from text content and panel dimensions */
|
|
24
22
|
export function calculate_font_sizes(schema, dims) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const height_mm = dims.cover_face_height.toNumber();
|
|
29
|
-
const subtitle_mm = height_mm * 0.045;
|
|
30
|
-
const subtitle_clean = (schema.subtitle ?? '')
|
|
23
|
+
// Subtitle lines come from the user's own break only — the UI field takes up to 2 lines.
|
|
24
|
+
// An unbroken line that is too wide is scaled down by shrink-to-width in the template.
|
|
25
|
+
const subtitle_lines = (schema.subtitle ?? '')
|
|
31
26
|
.split('\n')
|
|
32
27
|
.map((p) => p.trim().replace(/ +/g, ' '))
|
|
33
28
|
.filter((p) => p.length > 0)
|
|
34
|
-
.slice(0, 2)
|
|
35
|
-
.join('\n');
|
|
36
|
-
// Compute balanced subtitle lines: if no user \n, split at the point that minimises
|
|
37
|
-
// the difference in line lengths; otherwise respect the user's explicit break
|
|
38
|
-
let subtitle_lines = [];
|
|
39
|
-
if (subtitle_clean) {
|
|
40
|
-
const chars_per_line = available_mm / (subtitle_mm * CHAR_WIDTH_RATIO);
|
|
41
|
-
if (subtitle_clean.includes('\n')) {
|
|
42
|
-
subtitle_lines = subtitle_clean.split('\n');
|
|
43
|
-
}
|
|
44
|
-
else if (subtitle_clean.length <= chars_per_line || !subtitle_clean.includes(' ')) {
|
|
45
|
-
// Fits on one line or is a single word — no split needed
|
|
46
|
-
subtitle_lines = [subtitle_clean];
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
// Balance: try every word split, pick the one with most equal line lengths.
|
|
50
|
-
// No chars_per_line guard — shrink-to-width in Typst handles any overflow.
|
|
51
|
-
const words = subtitle_clean.split(' ');
|
|
52
|
-
let best_i = Math.ceil(words.length / 2);
|
|
53
|
-
let best_diff = Infinity;
|
|
54
|
-
for (let i = 1; i < words.length; i++) {
|
|
55
|
-
const l1 = words.slice(0, i).join(' ');
|
|
56
|
-
const l2 = words.slice(i).join(' ');
|
|
57
|
-
const diff = Math.abs(l1.length - l2.length);
|
|
58
|
-
if (diff < best_diff) {
|
|
59
|
-
best_diff = diff;
|
|
60
|
-
best_i = i;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
subtitle_lines = [words.slice(0, best_i).join(' '), words.slice(best_i).join(' ')];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
29
|
+
.slice(0, 2);
|
|
66
30
|
// Back blurb: fixed size (content length varies too much)
|
|
67
31
|
const back_blurb = 3.5;
|
|
68
32
|
// Spine: join non-empty title texts for a single-line spine label
|
package/dist/font_sizes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font_sizes.js","sourceRoot":"","sources":["../src/font_sizes.ts"],"names":[],"mappings":"AACA,gEAAgE;AAEhE,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAWhC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAE7B,
|
|
1
|
+
{"version":3,"file":"font_sizes.js","sourceRoot":"","sources":["../src/font_sizes.ts"],"names":[],"mappings":"AACA,gEAAgE;AAEhE,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAWhC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAE7B,sDAAsD;AACtD,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB;;;GAGG;AACH,SAAS,QAAQ,CAAC,IAAW,EAAE,YAAmB,EAAE,SAAgB,EAAE,MAAa,EAAE,MAAa;IAC9F,KAAK,IAAI,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,MAAM,E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