@sw7d/paper-renderer 0.1.8 → 0.1.9
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/paper-renderer.js
CHANGED
|
@@ -299,17 +299,8 @@ var te = class {
|
|
|
299
299
|
t = Math.max(t, n);
|
|
300
300
|
}
|
|
301
301
|
return 20 + Math.min(t, n - 20);
|
|
302
|
-
}), i = e.options.map((e) => e.paragraphs.reduce((e, t) => e + (t.height || 26), 0)), a =
|
|
303
|
-
|
|
304
|
-
let e = r[t], l = i[t];
|
|
305
|
-
if (a > 0) {
|
|
306
|
-
let i = t - c, l = n - r.slice(c, t).reduce((e, t) => e + t, 0) - e, u = i > 0 ? Math.max(8, l / i) : 8;
|
|
307
|
-
a + e + u > n && (a = 0, o += s, s = 0, c = t);
|
|
308
|
-
}
|
|
309
|
-
let u = t - c + 1, d = r.slice(c, t + 1).reduce((e, t) => e + t, 0), f = u > 1 ? Math.max(8, (n - d) / u) : 16;
|
|
310
|
-
a += e + f, s = Math.max(s, l);
|
|
311
|
-
}
|
|
312
|
-
return o + s;
|
|
302
|
+
}), i = e.options.map((e) => e.paragraphs.reduce((e, t) => e + (t.height || 26), 0)), a = e.options.length;
|
|
303
|
+
return Math.max(...r) * a <= n ? Math.max(...i) : i.reduce((e, t) => e + t, 0);
|
|
313
304
|
}
|
|
314
305
|
measureParagraph(e) {
|
|
315
306
|
let t = 0;
|
|
@@ -503,21 +494,28 @@ function ge() {
|
|
|
503
494
|
//#endregion
|
|
504
495
|
//#region src/engine/svg/optionsRenderer.ts
|
|
505
496
|
function H(e, t, n, r, i) {
|
|
506
|
-
let a = t - 20, o = ` <g class="swed-option" transform="translate(0, ${n})">\n`, s = e.map((e) => _e(e, 20, a)), c = e.map((e) => e.paragraphs.reduce((e, t) => e + (t.height || 26), 0)), l =
|
|
507
|
-
|
|
508
|
-
let
|
|
509
|
-
|
|
510
|
-
let
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
o += "
|
|
519
|
-
|
|
520
|
-
|
|
497
|
+
let a = t - 20, o = ` <g class="swed-option" transform="translate(0, ${n})">\n`, s = e.map((e) => _e(e, 20, a)), c = e.map((e) => e.paragraphs.reduce((e, t) => e + (t.height || 26), 0)), l = e.length, u = Math.max(...s);
|
|
498
|
+
if (l > 0 && u * l <= t) {
|
|
499
|
+
let n = t / l, a = n - 20;
|
|
500
|
+
for (let t = 0; t < l; t++) {
|
|
501
|
+
let s = n * t;
|
|
502
|
+
o += ` <g class="swed-option-item" transform="translate(${s}, 0)">\n`;
|
|
503
|
+
let c = e[t].paragraphs[0]?.lines[0]?.baseline || r * 1.56;
|
|
504
|
+
o += ` <text class="swed-text" xml:space="preserve" font-size="${r}" font-weight="normal" font-family="Times New Roman" font-style="normal" fill="#000000" fill-opacity="1" y="${c.toFixed(3)}">${V(e[t].label)}.</text>\n`, o += " <g>\n";
|
|
505
|
+
let l = 0;
|
|
506
|
+
for (let n of e[t].paragraphs) o += xe(n, a, l, !1, "", r, i, 20), l += n.height || 26;
|
|
507
|
+
o += " </g>\n", o += " </g>\n";
|
|
508
|
+
}
|
|
509
|
+
return o += " </g>\n", o;
|
|
510
|
+
}
|
|
511
|
+
let d = 0;
|
|
512
|
+
for (let t = 0; t < l; t++) {
|
|
513
|
+
o += ` <g class="swed-option-item" transform="translate(0, ${d})">\n`;
|
|
514
|
+
let n = e[t].paragraphs[0]?.lines[0]?.baseline || r * 1.56;
|
|
515
|
+
o += ` <text class="swed-text" xml:space="preserve" font-size="${r}" font-weight="normal" font-family="Times New Roman" font-style="normal" fill="#000000" fill-opacity="1" y="${n.toFixed(3)}">${V(e[t].label)}.</text>\n`, o += " <g>\n";
|
|
516
|
+
let s = 0;
|
|
517
|
+
for (let n of e[t].paragraphs) o += xe(n, a, s, !1, "", r, i, 20), s += n.height || 26;
|
|
518
|
+
o += " </g>\n", o += " </g>\n", d += c[t];
|
|
521
519
|
}
|
|
522
520
|
return o += " </g>\n", o;
|
|
523
521
|
}
|
|
@@ -532,17 +530,8 @@ function _e(e, t, n) {
|
|
|
532
530
|
}
|
|
533
531
|
function U(e, t) {
|
|
534
532
|
if (e.length === 0) return 0;
|
|
535
|
-
let n = e.map((e) => _e(e, 20, t)), r = e.map((e) => e.paragraphs.reduce((e, t) => e + (t.height || 26), 0)), i =
|
|
536
|
-
|
|
537
|
-
let e = n[c], l = r[c];
|
|
538
|
-
if (i > 0) {
|
|
539
|
-
let r = c - s, l = t - n.slice(s, c).reduce((e, t) => e + t, 0) - e, u = r > 0 ? Math.max(8, l / r) : 8;
|
|
540
|
-
i + e + u > t && (i = 0, a += o, o = 0, s = c);
|
|
541
|
-
}
|
|
542
|
-
let u = c - s + 1, d = n.slice(s, c + 1).reduce((e, t) => e + t, 0), f = u > 1 ? Math.max(8, (t - d) / u) : 16;
|
|
543
|
-
i += e + f, o = Math.max(o, l);
|
|
544
|
-
}
|
|
545
|
-
return a + o;
|
|
533
|
+
let n = e.map((e) => _e(e, 20, t)), r = e.map((e) => e.paragraphs.reduce((e, t) => e + (t.height || 26), 0)), i = e.length;
|
|
534
|
+
return Math.max(...n) * i <= t ? Math.max(...r) : r.reduce((e, t) => e + t, 0);
|
|
546
535
|
}
|
|
547
536
|
//#endregion
|
|
548
537
|
//#region src/engine/svg/questionRenderer.ts
|
|
@@ -42,8 +42,11 @@ export declare class PaperLayout {
|
|
|
42
42
|
*/
|
|
43
43
|
measureBlock(block: ContentBlock): number;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* 测量选项区域总高度
|
|
46
|
+
*
|
|
47
|
+
* 与 calcOptionsHeight 使用相同的布局策略,确保布局预留高度 = 实际渲染高度:
|
|
48
|
+
* - 一行等分排列 → 返回最高选项高度
|
|
49
|
+
* - 每个选项单独一行 → 返回高度之和
|
|
47
50
|
*/
|
|
48
51
|
private measureOptionsHeight;
|
|
49
52
|
measureParagraph(p: {
|
|
@@ -7,10 +7,10 @@ import type { OptionItem, RenderMode } from '../../types/paper';
|
|
|
7
7
|
/**
|
|
8
8
|
* 渲染选择题选项区域 (g.option)
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* 布局策略:
|
|
11
11
|
* - 计算每个选项内容宽度
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
12
|
+
* - 如果所有选项能在一行等分放下 → 一行等分排列(slotWidth = stemWidth / n)
|
|
13
|
+
* - 否则 → 每个选项单独一行(垂直排列)
|
|
14
14
|
*/
|
|
15
15
|
export declare function renderOptions(options: OptionItem[], stemWidth: number, startY: number, fontSize: number, renderMode: RenderMode): string;
|
|
16
16
|
/**
|
|
@@ -19,5 +19,9 @@ export declare function renderOptions(options: OptionItem[], stemWidth: number,
|
|
|
19
19
|
export declare function calcOptionItemWidth(opt: OptionItem, labelWidth: number, maxContentWidth: number): number;
|
|
20
20
|
/**
|
|
21
21
|
* 计算选项区域总高度
|
|
22
|
+
*
|
|
23
|
+
* 与 renderOptions 布局策略保持一致:
|
|
24
|
+
* - 一行等分排列 → 返回最高选项高度
|
|
25
|
+
* - 每个选项单独一行 → 返回高度之和
|
|
22
26
|
*/
|
|
23
27
|
export declare function calcOptionsHeight(options: OptionItem[], stemWidth: number): number;
|