@mathwiz/ui-components 0.1.9 → 0.1.10

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/index.mjs CHANGED
@@ -15956,11 +15956,9 @@ var renderToString = function(t, r) {
15956
15956
  return renderError(o, t, s);
15957
15957
  }
15958
15958
  };
15959
- const loadKaTeXCSS = () => {
15960
- typeof window < "u" && Promise.resolve({ }).catch((e) => {
15961
- console.warn("KaTeX CSS loading failed in Storybook environment:", e);
15962
- });
15963
- }, EquationRender = React__default.memo(
15959
+ const loadKaTeXCSS = () => typeof window < "u" ? Promise.resolve({ }).catch((e) => {
15960
+ console.warn("KaTeX CSS loading failed in Storybook environment:", e);
15961
+ }) : Promise.resolve(), EquationRender = React__default.memo(
15964
15962
  ({
15965
15963
  parts: e = [],
15966
15964
  children: t = null,
@@ -15969,36 +15967,41 @@ const loadKaTeXCSS = () => {
15969
15967
  displayMode: n = !1,
15970
15968
  className: o = ""
15971
15969
  }) => {
15972
- if (useEffect(() => {
15973
- loadKaTeXCSS();
15974
- }, []), e.length === 0)
15975
- return null;
15976
- const a = useMemo(() => e.map((u, d) => {
15970
+ const [a, l] = useState(!1);
15971
+ useEffect(() => {
15972
+ loadKaTeXCSS().then(() => {
15973
+ l(!0);
15974
+ });
15975
+ }, []);
15976
+ const h = useMemo(() => e.length === 0 ? [] : a ? e.map((f, p) => {
15977
15977
  try {
15978
- return renderToString(u, {
15978
+ return renderToString(f, {
15979
15979
  displayMode: n,
15980
15980
  throwOnError: !1,
15981
15981
  errorColor: "#ff0000"
15982
15982
  });
15983
- } catch (f) {
15984
- return console.error(`KaTeX rendering error in part ${d}:`, f), '<span style="color: red;">KaTeX Error</span>';
15983
+ } catch (m) {
15984
+ return console.error(`KaTeX rendering error in part ${p}:`, m), '<span style="color: red;">KaTeX Error</span>';
15985
15985
  }
15986
- }), [e, n]), l = n ? "div" : "span", h = React__default.Children.toArray(t), c = [];
15987
- return a.forEach((u, d) => {
15988
- c.push(
15986
+ }) : e.map((f) => f), [e, n, a]);
15987
+ if (e.length === 0)
15988
+ return null;
15989
+ const c = n ? "div" : "span", u = React__default.Children.toArray(t), d = [];
15990
+ return h.forEach((f, p) => {
15991
+ d.push(
15989
15992
  /* @__PURE__ */ jsxRuntimeExports.jsx(
15990
15993
  "span",
15991
15994
  {
15992
- dangerouslySetInnerHTML: { __html: u },
15995
+ dangerouslySetInnerHTML: { __html: f },
15993
15996
  style: { display: "inline-block" }
15994
15997
  },
15995
- `part-${d}`
15998
+ `part-${p}`
15996
15999
  )
15997
- ), d < h.length && d < e.length - 1 && c.push(
15998
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style: { display: "inline-block" }, children: h[d] }, `slot-${d}`)
16000
+ ), p < u.length && p < e.length - 1 && d.push(
16001
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style: { display: "inline-block" }, children: u[p] }, `slot-${p}`)
15999
16002
  );
16000
16003
  }), /* @__PURE__ */ jsxRuntimeExports.jsx(
16001
- l,
16004
+ c,
16002
16005
  {
16003
16006
  className: `equation-render ${o}`.trim(),
16004
16007
  style: {
@@ -16009,11 +16012,11 @@ const loadKaTeXCSS = () => {
16009
16012
  gap: "0.3em",
16010
16013
  ...n ? { justifyContent: "center", margin: "1em 0" } : {}
16011
16014
  },
16012
- children: c
16015
+ children: d
16013
16016
  }
16014
16017
  );
16015
16018
  }
16016
- ), renderContentBlock = (e) => e.type === "formula" ? React__default.createElement(EquationRender, {
16019
+ ), parseTemplate = (e, t, r) => e.replace(/{correctAnswer}/g, t.join(", ")).replace(/{userAnswer}/g, r.join(", ")), renderContentBlock = (e) => e.type === "formula" ? React__default.createElement(EquationRender, {
16017
16020
  key: e.content,
16018
16021
  parts: [e.content],
16019
16022
  children: null,
@@ -16030,7 +16033,150 @@ const loadKaTeXCSS = () => {
16030
16033
  className: "content-block",
16031
16034
  key: r
16032
16035
  }, renderContentBlock(t))
16033
- ), Banner = ({
16036
+ ), parseTemplateWithFormulas = (e) => {
16037
+ const t = [];
16038
+ let r = 0;
16039
+ const s = /\$\$?[^$]+\$\$?/g;
16040
+ let n;
16041
+ for (; (n = s.exec(e)) !== null; ) {
16042
+ const o = n.index, a = n.index + n[0].length;
16043
+ if (o > r) {
16044
+ const c = e.substring(r, o);
16045
+ c.trim() && t.push({
16046
+ type: "text",
16047
+ content: c
16048
+ });
16049
+ }
16050
+ const h = n[0].replace(/^\$\$?/, "").replace(/\$\$?$/, "");
16051
+ t.push({
16052
+ type: "formula",
16053
+ content: h
16054
+ }), r = a;
16055
+ }
16056
+ if (r < e.length) {
16057
+ const o = e.substring(r);
16058
+ o.trim() && t.push({
16059
+ type: "text",
16060
+ content: o
16061
+ });
16062
+ }
16063
+ return t;
16064
+ }, renderTemplateWithFormulas = (e, t, r) => {
16065
+ const s = parseTemplate(e, t, r), n = parseTemplateWithFormulas(s);
16066
+ return renderContentBlocks(n);
16067
+ }, renderExplanationStep = (e) => {
16068
+ const { type: t, content: r, style: s = {} } = e, n = {
16069
+ marginBottom: "8px",
16070
+ lineHeight: "1.6",
16071
+ ...s
16072
+ };
16073
+ switch (t) {
16074
+ case "instruction":
16075
+ return React__default.createElement("div", {
16076
+ key: e.id,
16077
+ style: {
16078
+ ...n,
16079
+ fontWeight: "bold",
16080
+ color: "#4a6cf7"
16081
+ }
16082
+ }, r);
16083
+ case "formula":
16084
+ const o = r.includes("\\\\") || r.includes("\\downarrow") || r.includes("\\quad");
16085
+ return React__default.createElement(EquationRender, {
16086
+ key: e.id,
16087
+ parts: [r],
16088
+ children: null,
16089
+ displayMode: o,
16090
+ fontSize: "1.1em",
16091
+ color: "#333333"
16092
+ });
16093
+ case "conclusion":
16094
+ return React__default.createElement("div", {
16095
+ key: e.id,
16096
+ style: {
16097
+ ...n,
16098
+ fontWeight: "bold",
16099
+ color: "#22c55e",
16100
+ borderLeft: "3px solid #22c55e",
16101
+ paddingLeft: "12px"
16102
+ }
16103
+ }, r);
16104
+ case "image":
16105
+ return React__default.createElement("div", {
16106
+ key: e.id,
16107
+ style: n
16108
+ }, React__default.createElement("img", {
16109
+ src: r,
16110
+ alt: "解题步骤",
16111
+ style: {
16112
+ maxWidth: "100%",
16113
+ height: "auto",
16114
+ borderRadius: "4px"
16115
+ }
16116
+ }));
16117
+ case "table":
16118
+ return React__default.createElement("div", {
16119
+ key: e.id,
16120
+ style: n
16121
+ }, React__default.createElement("div", {
16122
+ style: {
16123
+ border: "1px solid #e0e0e0",
16124
+ borderRadius: "4px",
16125
+ padding: "8px",
16126
+ backgroundColor: "#f8f9fa"
16127
+ }
16128
+ }, r));
16129
+ default:
16130
+ return React__default.createElement("div", {
16131
+ key: e.id,
16132
+ style: n
16133
+ }, r);
16134
+ }
16135
+ }, renderReviewStep = (e, t, r) => {
16136
+ const { type: s, content: n, style: o = {} } = e, a = {
16137
+ marginBottom: "8px",
16138
+ lineHeight: "1.6",
16139
+ ...o
16140
+ };
16141
+ switch (s) {
16142
+ case "instruction":
16143
+ return React__default.createElement("div", {
16144
+ key: e.id,
16145
+ style: {
16146
+ ...a,
16147
+ fontWeight: "bold",
16148
+ color: "#4ade80"
16149
+ }
16150
+ }, n);
16151
+ case "formula":
16152
+ const l = n.includes("\\\\") || n.includes("\\downarrow") || n.includes("\\quad");
16153
+ return React__default.createElement(EquationRender, {
16154
+ key: e.id,
16155
+ parts: [n],
16156
+ children: null,
16157
+ displayMode: l,
16158
+ fontSize: "1.1em",
16159
+ color: "#333333"
16160
+ });
16161
+ case "conclusion":
16162
+ const h = parseTemplate(n, r, t);
16163
+ return React__default.createElement("div", {
16164
+ key: e.id,
16165
+ style: {
16166
+ ...a,
16167
+ fontWeight: "bold",
16168
+ color: "#4ade80",
16169
+ borderLeft: "3px solid #4ade80",
16170
+ paddingLeft: "12px"
16171
+ }
16172
+ }, h);
16173
+ default:
16174
+ return React__default.createElement("div", {
16175
+ key: e.id,
16176
+ style: a
16177
+ }, n);
16178
+ }
16179
+ }, renderExplanationSteps = (e) => e.map(renderExplanationStep), renderReviewSteps = (e, t, r) => e.map((s) => renderReviewStep(s, t, r)), Banner = ({
16034
16180
  scene: e,
16035
16181
  position: t = "header",
16036
16182
  size: r = "medium",
@@ -16174,7 +16320,7 @@ const loadKaTeXCSS = () => {
16174
16320
  };
16175
16321
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: r, children: [
16176
16322
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: s, children: t }),
16177
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: n, children: e.map((a) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: o, children: a.content }, a.id)) })
16323
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: n, children: renderExplanationSteps(e).map((a, l) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: o, children: a }, e[l].id)) })
16178
16324
  ] });
16179
16325
  }, ReviewContent = ({
16180
16326
  reviewContent: e,
@@ -16211,8 +16357,12 @@ const loadKaTeXCSS = () => {
16211
16357
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: s, children: [
16212
16358
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: n, children: "复习内容" }),
16213
16359
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: o, children: [
16214
- e.reviewTemplate && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: a, children: e.reviewTemplate.replace(/{correctAnswer}/g, r.join(", ")).replace(/{userAnswer}/g, t.join(", ")) }),
16215
- e.reviewExplanation && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: l, children: e.reviewExplanation.map((c) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: h, children: c.content }, c.id)) })
16360
+ e.reviewTemplate && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: a, children: renderTemplateWithFormulas(
16361
+ e.reviewTemplate,
16362
+ r,
16363
+ t
16364
+ ) }),
16365
+ e.reviewExplanation && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: l, children: renderReviewSteps(e.reviewExplanation, t, r).map((c, u) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: h, children: c }, e.reviewExplanation[u].id)) })
16216
16366
  ] })
16217
16367
  ] });
16218
16368
  }, LoadingState = ({ type: e = "skeleton" }) => {
@@ -16288,30 +16438,31 @@ const loadKaTeXCSS = () => {
16288
16438
  onNext: t,
16289
16439
  onRetry: r,
16290
16440
  onAnswerChange: s,
16291
- onHintToggle: n
16441
+ onHintToggle: n,
16442
+ value: o
16292
16443
  }) => {
16293
- const { problemData: o, scene: a, submissionResult: l, config: h } = useMathCardContext();
16294
- if (!o)
16444
+ const { problemData: a, scene: l, submissionResult: h, config: c } = useMathCardContext();
16445
+ if (!a)
16295
16446
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorState, { error: "No problem data provided" });
16296
- const c = () => {
16447
+ const u = () => {
16297
16448
  e && e();
16298
- }, u = () => {
16299
- t && t(o.problemId);
16300
16449
  }, d = () => {
16301
- r && r(o.problemId);
16302
- }, f = (g) => {
16303
- s && s(g, o.problemType);
16304
- }, p = {
16305
- background: h?.theme === "dark" ? "#1a1a1a" : "#ffffff",
16450
+ t && t(a.problemId);
16451
+ }, f = () => {
16452
+ r && r(a.problemId);
16453
+ }, p = (b) => {
16454
+ s && s(b, a.problemType);
16455
+ }, m = {
16456
+ background: c?.theme === "dark" ? "#1a1a1a" : "#ffffff",
16306
16457
  borderRadius: "8px",
16307
16458
  boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
16308
16459
  fontFamily: "'Arial', sans-serif",
16309
16460
  fontSize: "14px",
16310
16461
  overflow: "hidden",
16311
- color: h?.theme === "dark" ? "#ffffff" : "#333333",
16462
+ color: c?.theme === "dark" ? "#ffffff" : "#333333",
16312
16463
  width: "100%",
16313
16464
  maxWidth: "800px"
16314
- }, m = {
16465
+ }, g = {
16315
16466
  padding: "20px",
16316
16467
  borderTop: "1px solid #e0e0e0",
16317
16468
  display: "flex",
@@ -16320,64 +16471,65 @@ const loadKaTeXCSS = () => {
16320
16471
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
16321
16472
  "div",
16322
16473
  {
16323
- style: p,
16474
+ style: m,
16324
16475
  "data-testid": "math-card",
16325
- "data-theme": h?.theme,
16476
+ "data-theme": c?.theme,
16326
16477
  children: [
16327
- h?.showBanner !== !1 && /* @__PURE__ */ jsxRuntimeExports.jsx(
16478
+ c?.showBanner !== !1 && /* @__PURE__ */ jsxRuntimeExports.jsx(
16328
16479
  Banner,
16329
16480
  {
16330
- scene: a,
16331
- position: h?.bannerPosition,
16332
- size: h?.bannerSize,
16333
- color: h?.bannerCustomStyle?.color,
16334
- bgColor: h?.bannerCustomStyle?.bgColor
16481
+ scene: l,
16482
+ position: c?.bannerPosition,
16483
+ size: c?.bannerSize,
16484
+ color: c?.bannerCustomStyle?.color,
16485
+ bgColor: c?.bannerCustomStyle?.bgColor
16335
16486
  }
16336
16487
  ),
16337
16488
  /* @__PURE__ */ jsxRuntimeExports.jsx(
16338
16489
  Question,
16339
16490
  {
16340
- question: o.question,
16341
- problemType: o.problemType
16491
+ question: a.question,
16492
+ problemType: a.problemType
16342
16493
  }
16343
16494
  ),
16344
- a === "question" && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
16495
+ l === "question" && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
16345
16496
  /* @__PURE__ */ jsxRuntimeExports.jsx(
16346
16497
  AnswerInput,
16347
16498
  {
16348
- problemType: o.problemType,
16349
- options: o.answer.options,
16350
- onChange: f,
16351
- placeholder: h?.inputPlaceholder
16499
+ problemType: a.problemType,
16500
+ options: a.answer.options,
16501
+ value: o,
16502
+ onChange: p,
16503
+ placeholder: c?.inputPlaceholder
16352
16504
  }
16353
16505
  ),
16354
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: m, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
16506
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: g, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
16355
16507
  SubmitButton,
16356
16508
  {
16357
- onClick: c,
16509
+ onClick: u,
16358
16510
  disabled: !e,
16359
- children: h?.submitButtonText || "提交答案"
16511
+ children: c?.submitButtonText || "提交答案"
16360
16512
  }
16361
16513
  ) })
16362
16514
  ] }),
16363
- a === "solve" && o.explanation && /* @__PURE__ */ jsxRuntimeExports.jsx(
16515
+ l === "solve" && a.explanation && /* @__PURE__ */ jsxRuntimeExports.jsx(
16364
16516
  Explanation,
16365
16517
  {
16366
- steps: o.explanation,
16518
+ steps: a.explanation,
16367
16519
  title: "官方解析"
16368
16520
  }
16369
16521
  ),
16370
- a === "review" && l && o.reviewContent && /* @__PURE__ */ jsxRuntimeExports.jsx(
16522
+ l === "review" && h && a.reviewContent && /* @__PURE__ */ jsxRuntimeExports.jsx(
16371
16523
  ReviewContent,
16372
16524
  {
16373
- reviewContent: o.reviewContent,
16374
- userAnswer: l.userAnswer,
16375
- correctAnswer: o.answer.correctAnswer
16525
+ reviewContent: a.reviewContent,
16526
+ userAnswer: h.userAnswer,
16527
+ correctAnswer: a.answer.correctAnswer
16376
16528
  }
16377
16529
  ),
16378
- (a === "solve" || a === "review") && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: m, children: [
16379
- t && /* @__PURE__ */ jsxRuntimeExports.jsx(SubmitButton, { onClick: u, children: h?.nextButtonText || "下一题" }),
16380
- r && /* @__PURE__ */ jsxRuntimeExports.jsx(SubmitButton, { onClick: d, children: h?.retryButtonText || "重新作答" })
16530
+ (l === "solve" || l === "review") && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: g, children: [
16531
+ t && /* @__PURE__ */ jsxRuntimeExports.jsx(SubmitButton, { onClick: d, children: c?.nextButtonText || "下一题" }),
16532
+ r && /* @__PURE__ */ jsxRuntimeExports.jsx(SubmitButton, { onClick: f, children: c?.retryButtonText || "重新作答" })
16381
16533
  ] })
16382
16534
  ]
16383
16535
  }
@@ -16395,7 +16547,8 @@ const loadKaTeXCSS = () => {
16395
16547
  onRetry: c,
16396
16548
  onErrorRetry: u,
16397
16549
  onAnswerChange: d,
16398
- onHintToggle: f
16550
+ onHintToggle: f,
16551
+ value: p
16399
16552
  }) => {
16400
16553
  if (s)
16401
16554
  return /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingState, { type: "skeleton" });
@@ -16409,20 +16562,22 @@ const loadKaTeXCSS = () => {
16409
16562
  );
16410
16563
  if (!e)
16411
16564
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorState, { error: "No problem data provided" });
16412
- const p = {
16565
+ const m = {
16413
16566
  problemData: e,
16414
16567
  scene: t,
16415
16568
  submissionResult: r,
16416
- config: o
16569
+ config: o,
16570
+ value: p
16417
16571
  };
16418
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MathCardContext.Provider, { value: p, children: a || /* @__PURE__ */ jsxRuntimeExports.jsx(
16572
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MathCardContext.Provider, { value: m, children: a || /* @__PURE__ */ jsxRuntimeExports.jsx(
16419
16573
  DefaultLayout,
16420
16574
  {
16421
16575
  onSubmit: l,
16422
16576
  onNext: h,
16423
16577
  onRetry: c,
16424
16578
  onAnswerChange: d,
16425
- onHintToggle: f
16579
+ onHintToggle: f,
16580
+ value: p
16426
16581
  }
16427
16582
  ) });
16428
16583
  };
@@ -69610,6 +69765,7 @@ const MathGraph = (e) => {
69610
69765
  submissionResult: f[x],
69611
69766
  loading: c,
69612
69767
  error: u ? I(u) : void 0,
69768
+ value: p[x],
69613
69769
  onAnswerChange: E,
69614
69770
  onSubmit: P,
69615
69771
  onNext: () => $(s),