@sw7d/paper-renderer 0.6.0 → 0.6.1
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 +125 -51
- package/package.json +1 -1
package/dist/paper-renderer.js
CHANGED
|
@@ -3806,12 +3806,44 @@ function Lr(e, t = {}) {
|
|
|
3806
3806
|
"ol",
|
|
3807
3807
|
"ul",
|
|
3808
3808
|
"div"
|
|
3809
|
-
])
|
|
3809
|
+
]), m = new Set([
|
|
3810
|
+
"script",
|
|
3811
|
+
"style",
|
|
3812
|
+
"meta",
|
|
3813
|
+
"link",
|
|
3814
|
+
"title",
|
|
3815
|
+
"head",
|
|
3816
|
+
"base",
|
|
3817
|
+
"noscript"
|
|
3818
|
+
]), h = [], g = () => {
|
|
3819
|
+
if (h.length === 0) return;
|
|
3820
|
+
let e = l.createElement("div");
|
|
3821
|
+
for (let t of h) e.appendChild(t.cloneNode(!0));
|
|
3822
|
+
h = [];
|
|
3823
|
+
let t = Rr(e, a, "", i, f, c);
|
|
3824
|
+
if (t.length === 0 || t.every((e) => e.type === "enter")) return;
|
|
3825
|
+
let n = Le(t, i, d), r = n.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3826
|
+
u.push({
|
|
3827
|
+
lines: n,
|
|
3828
|
+
y: 0,
|
|
3829
|
+
height: r,
|
|
3830
|
+
justification: Br(t, "", c)
|
|
3831
|
+
});
|
|
3832
|
+
};
|
|
3810
3833
|
for (let e = 0; e < l.body.childNodes.length; e++) {
|
|
3811
3834
|
let t = l.body.childNodes[e];
|
|
3835
|
+
if (t.nodeType === Node.TEXT_NODE) {
|
|
3836
|
+
(t.textContent || "").replace(/\u00A0/g, " ").trim() && h.push(t);
|
|
3837
|
+
continue;
|
|
3838
|
+
}
|
|
3812
3839
|
if (t.nodeType !== Node.ELEMENT_NODE) continue;
|
|
3813
3840
|
let n = t, r = n.tagName.toLowerCase();
|
|
3814
|
-
if (r
|
|
3841
|
+
if (m.has(r)) continue;
|
|
3842
|
+
if (!p.has(r) && r !== "table" && r !== "figure") {
|
|
3843
|
+
h.push(n);
|
|
3844
|
+
continue;
|
|
3845
|
+
}
|
|
3846
|
+
if (g(), r === "table") {
|
|
3815
3847
|
let e = Xr(n, i, d), t = e.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3816
3848
|
u.push({
|
|
3817
3849
|
lines: e,
|
|
@@ -3834,75 +3866,117 @@ function Lr(e, t = {}) {
|
|
|
3834
3866
|
}
|
|
3835
3867
|
if (!p.has(r)) continue;
|
|
3836
3868
|
if (r === "div") {
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3869
|
+
let e = n.getAttribute("style") || "", t = new Set([
|
|
3870
|
+
"p",
|
|
3871
|
+
"div",
|
|
3872
|
+
"table",
|
|
3873
|
+
"figure",
|
|
3874
|
+
"ol",
|
|
3875
|
+
"ul",
|
|
3876
|
+
"h1",
|
|
3877
|
+
"h2",
|
|
3878
|
+
"h3",
|
|
3879
|
+
"h4",
|
|
3880
|
+
"h5",
|
|
3881
|
+
"h6",
|
|
3882
|
+
"blockquote"
|
|
3883
|
+
]), r = [], o = () => {
|
|
3884
|
+
if (r.length === 0) return;
|
|
3885
|
+
let t = l.createElement("div");
|
|
3886
|
+
for (let e of r) t.appendChild(e.cloneNode(!0));
|
|
3887
|
+
r = [];
|
|
3888
|
+
let n = Rr(t, a, e, i, f, c);
|
|
3889
|
+
if (n.length === 0 || n.every((e) => e.type === "enter")) return;
|
|
3890
|
+
let o = Le(n, i, d), s = o.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3891
|
+
u.push({
|
|
3892
|
+
lines: o,
|
|
3893
|
+
y: 0,
|
|
3894
|
+
height: s,
|
|
3895
|
+
justification: Br(n, e, c)
|
|
3896
|
+
});
|
|
3897
|
+
};
|
|
3898
|
+
for (let e of Array.from(n.childNodes)) {
|
|
3899
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
3900
|
+
(e.textContent || "").replace(/\u00A0/g, " ").trim() && r.push(e);
|
|
3901
|
+
continue;
|
|
3902
|
+
}
|
|
3903
|
+
if (e.nodeType !== Node.ELEMENT_NODE) continue;
|
|
3904
|
+
let n = e, s = n.tagName.toLowerCase();
|
|
3905
|
+
if (!m.has(s)) {
|
|
3906
|
+
if (!t.has(s)) {
|
|
3907
|
+
r.push(n);
|
|
3908
|
+
continue;
|
|
3909
|
+
}
|
|
3910
|
+
if (o(), s === "p") {
|
|
3911
|
+
let e = n.getAttribute("style") || "", t = Rr(n, a, e, i, f, c);
|
|
3912
|
+
if (t.length === 0) continue;
|
|
3913
|
+
let r = Ur(e, a), o = Le(t, i, d, r), s = o.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3914
|
+
u.push({
|
|
3915
|
+
lines: o,
|
|
3916
|
+
y: 0,
|
|
3917
|
+
height: s,
|
|
3918
|
+
justification: Br(t, e, c),
|
|
3919
|
+
...r > 0 ? { firstLineIndent: r } : {}
|
|
3920
|
+
});
|
|
3921
|
+
} else if (s === "table" || s === "figure") {
|
|
3922
|
+
let e = s === "table" ? n : n.querySelector("table");
|
|
3923
|
+
if (!e) {
|
|
3924
|
+
let e = Rr(n, a, n.getAttribute("style") || "", i, f, c);
|
|
3925
|
+
if (e.length === 0 || e.every((e) => e.type === "enter")) continue;
|
|
3926
|
+
let t = Le(e, i, d), r = t.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3927
|
+
u.push({
|
|
3928
|
+
lines: t,
|
|
3929
|
+
y: 0,
|
|
3930
|
+
height: r
|
|
3931
|
+
});
|
|
3932
|
+
continue;
|
|
3933
|
+
}
|
|
3934
|
+
let t = Xr(e, i, d), r = t.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3856
3935
|
u.push({
|
|
3857
|
-
lines:
|
|
3936
|
+
lines: t,
|
|
3858
3937
|
y: 0,
|
|
3859
3938
|
height: r
|
|
3860
3939
|
});
|
|
3861
|
-
|
|
3940
|
+
} else {
|
|
3941
|
+
let e = n.getAttribute("style") || "", t = Rr(n, a, e, i, f, c);
|
|
3942
|
+
if (t.length === 0 || t.every((e) => e.type === "enter")) continue;
|
|
3943
|
+
let r = Ur(e, a), o = Le(t, i, d, r), s = o.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3944
|
+
u.push({
|
|
3945
|
+
lines: o,
|
|
3946
|
+
y: 0,
|
|
3947
|
+
height: s,
|
|
3948
|
+
justification: Br(t, e, c),
|
|
3949
|
+
...r > 0 ? { firstLineIndent: r } : {}
|
|
3950
|
+
});
|
|
3862
3951
|
}
|
|
3863
|
-
let r = Xr(e, i, d), o = r.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3864
|
-
u.push({
|
|
3865
|
-
lines: r,
|
|
3866
|
-
y: 0,
|
|
3867
|
-
height: o
|
|
3868
|
-
});
|
|
3869
|
-
} else {
|
|
3870
|
-
let e = t.getAttribute("style") || "", n = Rr(t, a, e, i, f, c);
|
|
3871
|
-
if (n.length === 0 || n.every((e) => e.type === "enter")) continue;
|
|
3872
|
-
let r = Ur(e, a), o = Le(n, i, d, r), s = o.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3873
|
-
u.push({
|
|
3874
|
-
lines: o,
|
|
3875
|
-
y: 0,
|
|
3876
|
-
height: s,
|
|
3877
|
-
justification: Br(n, e, c),
|
|
3878
|
-
...r > 0 ? { firstLineIndent: r } : {}
|
|
3879
|
-
});
|
|
3880
3952
|
}
|
|
3881
3953
|
}
|
|
3954
|
+
o();
|
|
3882
3955
|
continue;
|
|
3883
3956
|
}
|
|
3884
|
-
let o = n, s = o.getAttribute("style") || "",
|
|
3885
|
-
if (
|
|
3886
|
-
let
|
|
3957
|
+
let o = n, s = o.getAttribute("style") || "", _ = Rr(o, a, s, i, f, c);
|
|
3958
|
+
if (_.length === 0) continue;
|
|
3959
|
+
let v = Ur(s, a), y = Le(_, i, d, v), b = y.reduce((e, t) => e + t.lineHeight, 0) + 4;
|
|
3887
3960
|
u.push({
|
|
3888
|
-
lines:
|
|
3961
|
+
lines: y,
|
|
3889
3962
|
y: 0,
|
|
3890
|
-
height:
|
|
3891
|
-
justification: Br(
|
|
3892
|
-
...
|
|
3963
|
+
height: b,
|
|
3964
|
+
justification: Br(_, s, c),
|
|
3965
|
+
...v > 0 ? { firstLineIndent: v } : {}
|
|
3893
3966
|
});
|
|
3894
3967
|
}
|
|
3895
|
-
|
|
3968
|
+
g();
|
|
3969
|
+
let _ = U(u), v = `topic-html-${++Pr}`;
|
|
3896
3970
|
return [{
|
|
3897
3971
|
id: `q-html-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
3898
3972
|
type: "question",
|
|
3899
3973
|
paragraphs: u,
|
|
3900
|
-
height:
|
|
3974
|
+
height: _,
|
|
3901
3975
|
protectContent: s,
|
|
3902
3976
|
metadata: {
|
|
3903
3977
|
questionNo: n,
|
|
3904
3978
|
score: r,
|
|
3905
|
-
topicId:
|
|
3979
|
+
topicId: v,
|
|
3906
3980
|
originalContentWidth: i,
|
|
3907
3981
|
label: n ? `第${n}题` : "导入题目"
|
|
3908
3982
|
}
|
|
@@ -3994,7 +4068,7 @@ function Rr(e, t, n, r, i, a = !1) {
|
|
|
3994
4068
|
isEmpty: n,
|
|
3995
4069
|
blankType: t,
|
|
3996
4070
|
showUnderline: t === "tiankong",
|
|
3997
|
-
correctAnswer: e || void 0
|
|
4071
|
+
correctAnswer: e.trim() || void 0
|
|
3998
4072
|
});
|
|
3999
4073
|
continue;
|
|
4000
4074
|
}
|