@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.
@@ -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 === "table") {
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
- for (let e of Array.from(n.children)) {
3838
- let t = e, n = t.tagName.toLowerCase();
3839
- if (n === "p") {
3840
- let e = t.getAttribute("style") || "", n = Rr(t, a, e, i, f, c);
3841
- if (n.length === 0) continue;
3842
- let r = Ur(e, a), o = Le(n, i, d, r), s = o.reduce((e, t) => e + t.lineHeight, 0) + 4;
3843
- u.push({
3844
- lines: o,
3845
- y: 0,
3846
- height: s,
3847
- justification: Br(n, e, c),
3848
- ...r > 0 ? { firstLineIndent: r } : {}
3849
- });
3850
- } else if (n === "table" || n === "figure") {
3851
- let e = n === "table" ? t : t.querySelector("table");
3852
- if (!e) {
3853
- let e = Rr(t, a, t.getAttribute("style") || "", i, f, c);
3854
- if (e.length === 0 || e.every((e) => e.type === "enter")) continue;
3855
- let n = Le(e, i, d), r = n.reduce((e, t) => e + t.lineHeight, 0) + 4;
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: n,
3936
+ lines: t,
3858
3937
  y: 0,
3859
3938
  height: r
3860
3939
  });
3861
- continue;
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") || "", m = Rr(o, a, s, i, f, c);
3885
- if (m.length === 0) continue;
3886
- let h = Ur(s, a), g = Le(m, i, d, h), _ = g.reduce((e, t) => e + t.lineHeight, 0) + 4;
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: g,
3961
+ lines: y,
3889
3962
  y: 0,
3890
- height: _,
3891
- justification: Br(m, s, c),
3892
- ...h > 0 ? { firstLineIndent: h } : {}
3963
+ height: b,
3964
+ justification: Br(_, s, c),
3965
+ ...v > 0 ? { firstLineIndent: v } : {}
3893
3966
  });
3894
3967
  }
3895
- let m = U(u), h = `topic-html-${++Pr}`;
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: m,
3974
+ height: _,
3901
3975
  protectContent: s,
3902
3976
  metadata: {
3903
3977
  questionNo: n,
3904
3978
  score: r,
3905
- topicId: h,
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sw7d/paper-renderer",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "题卡设计器核心组件 - 纯编辑表面",
5
5
  "type": "module",
6
6
  "main": "./dist/paper-renderer.js",