@mathwiz/ui-components 0.1.8 → 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,13 +16012,14 @@ 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],
16022
+ children: null,
16019
16023
  displayMode: !1,
16020
16024
  fontSize: "1em",
16021
16025
  color: "#333333"
@@ -16029,7 +16033,150 @@ const loadKaTeXCSS = () => {
16029
16033
  className: "content-block",
16030
16034
  key: r
16031
16035
  }, renderContentBlock(t))
16032
- ), 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 = ({
16033
16180
  scene: e,
16034
16181
  position: t = "header",
16035
16182
  size: r = "medium",
@@ -16062,13 +16209,13 @@ const loadKaTeXCSS = () => {
16062
16209
  }[r]), h;
16063
16210
  };
16064
16211
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: l(), children: a[e] });
16065
- }, Question = ({ question: e, problemType: t }) => {
16066
- const r = {
16212
+ }, Question = ({ question: e }) => {
16213
+ const t = {
16067
16214
  padding: "20px",
16068
16215
  lineHeight: "1.6",
16069
16216
  fontSize: "16px"
16070
16217
  };
16071
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: r, children: renderContentBlocks(e) });
16218
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: t, children: renderContentBlocks(e) });
16072
16219
  }, AnswerInput = ({
16073
16220
  problemType: e,
16074
16221
  options: t,
@@ -16173,7 +16320,7 @@ const loadKaTeXCSS = () => {
16173
16320
  };
16174
16321
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: r, children: [
16175
16322
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: s, children: t }),
16176
- /* @__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)) })
16177
16324
  ] });
16178
16325
  }, ReviewContent = ({
16179
16326
  reviewContent: e,
@@ -16210,8 +16357,12 @@ const loadKaTeXCSS = () => {
16210
16357
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: s, children: [
16211
16358
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: n, children: "复习内容" }),
16212
16359
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: o, children: [
16213
- e.reviewTemplate && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: a, children: e.reviewTemplate.replace(/{correctAnswer}/g, r.join(", ")).replace(/{userAnswer}/g, t.join(", ")) }),
16214
- 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)) })
16215
16366
  ] })
16216
16367
  ] });
16217
16368
  }, LoadingState = ({ type: e = "skeleton" }) => {
@@ -16287,30 +16438,31 @@ const loadKaTeXCSS = () => {
16287
16438
  onNext: t,
16288
16439
  onRetry: r,
16289
16440
  onAnswerChange: s,
16290
- onHintToggle: n
16441
+ onHintToggle: n,
16442
+ value: o
16291
16443
  }) => {
16292
- const { problemData: o, scene: a, submissionResult: l, config: h } = useMathCardContext();
16293
- if (!o)
16444
+ const { problemData: a, scene: l, submissionResult: h, config: c } = useMathCardContext();
16445
+ if (!a)
16294
16446
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorState, { error: "No problem data provided" });
16295
- const c = () => {
16447
+ const u = () => {
16296
16448
  e && e();
16297
- }, u = () => {
16298
- t && t(o.problemId);
16299
16449
  }, d = () => {
16300
- r && r(o.problemId);
16301
- }, f = (g) => {
16302
- s && s(g, o.problemType);
16303
- }, p = {
16304
- 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",
16305
16457
  borderRadius: "8px",
16306
16458
  boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
16307
16459
  fontFamily: "'Arial', sans-serif",
16308
16460
  fontSize: "14px",
16309
16461
  overflow: "hidden",
16310
- color: h?.theme === "dark" ? "#ffffff" : "#333333",
16462
+ color: c?.theme === "dark" ? "#ffffff" : "#333333",
16311
16463
  width: "100%",
16312
16464
  maxWidth: "800px"
16313
- }, m = {
16465
+ }, g = {
16314
16466
  padding: "20px",
16315
16467
  borderTop: "1px solid #e0e0e0",
16316
16468
  display: "flex",
@@ -16319,64 +16471,65 @@ const loadKaTeXCSS = () => {
16319
16471
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
16320
16472
  "div",
16321
16473
  {
16322
- style: p,
16474
+ style: m,
16323
16475
  "data-testid": "math-card",
16324
- "data-theme": h?.theme,
16476
+ "data-theme": c?.theme,
16325
16477
  children: [
16326
- h?.showBanner !== !1 && /* @__PURE__ */ jsxRuntimeExports.jsx(
16478
+ c?.showBanner !== !1 && /* @__PURE__ */ jsxRuntimeExports.jsx(
16327
16479
  Banner,
16328
16480
  {
16329
- scene: a,
16330
- position: h?.bannerPosition,
16331
- size: h?.bannerSize,
16332
- color: h?.bannerCustomStyle?.color,
16333
- 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
16334
16486
  }
16335
16487
  ),
16336
16488
  /* @__PURE__ */ jsxRuntimeExports.jsx(
16337
16489
  Question,
16338
16490
  {
16339
- question: o.question,
16340
- problemType: o.problemType
16491
+ question: a.question,
16492
+ problemType: a.problemType
16341
16493
  }
16342
16494
  ),
16343
- a === "question" && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
16495
+ l === "question" && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
16344
16496
  /* @__PURE__ */ jsxRuntimeExports.jsx(
16345
16497
  AnswerInput,
16346
16498
  {
16347
- problemType: o.problemType,
16348
- options: o.answer.options,
16349
- onChange: f,
16350
- placeholder: h?.inputPlaceholder
16499
+ problemType: a.problemType,
16500
+ options: a.answer.options,
16501
+ value: o,
16502
+ onChange: p,
16503
+ placeholder: c?.inputPlaceholder
16351
16504
  }
16352
16505
  ),
16353
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: m, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
16506
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: g, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
16354
16507
  SubmitButton,
16355
16508
  {
16356
- onClick: c,
16509
+ onClick: u,
16357
16510
  disabled: !e,
16358
- children: h?.submitButtonText || "提交答案"
16511
+ children: c?.submitButtonText || "提交答案"
16359
16512
  }
16360
16513
  ) })
16361
16514
  ] }),
16362
- a === "solve" && o.explanation && /* @__PURE__ */ jsxRuntimeExports.jsx(
16515
+ l === "solve" && a.explanation && /* @__PURE__ */ jsxRuntimeExports.jsx(
16363
16516
  Explanation,
16364
16517
  {
16365
- steps: o.explanation,
16518
+ steps: a.explanation,
16366
16519
  title: "官方解析"
16367
16520
  }
16368
16521
  ),
16369
- a === "review" && l && o.reviewContent && /* @__PURE__ */ jsxRuntimeExports.jsx(
16522
+ l === "review" && h && a.reviewContent && /* @__PURE__ */ jsxRuntimeExports.jsx(
16370
16523
  ReviewContent,
16371
16524
  {
16372
- reviewContent: o.reviewContent,
16373
- userAnswer: l.userAnswer,
16374
- correctAnswer: o.answer.correctAnswer
16525
+ reviewContent: a.reviewContent,
16526
+ userAnswer: h.userAnswer,
16527
+ correctAnswer: a.answer.correctAnswer
16375
16528
  }
16376
16529
  ),
16377
- (a === "solve" || a === "review") && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: m, children: [
16378
- t && /* @__PURE__ */ jsxRuntimeExports.jsx(SubmitButton, { onClick: u, children: h?.nextButtonText || "下一题" }),
16379
- 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 || "重新作答" })
16380
16533
  ] })
16381
16534
  ]
16382
16535
  }
@@ -16394,7 +16547,8 @@ const loadKaTeXCSS = () => {
16394
16547
  onRetry: c,
16395
16548
  onErrorRetry: u,
16396
16549
  onAnswerChange: d,
16397
- onHintToggle: f
16550
+ onHintToggle: f,
16551
+ value: p
16398
16552
  }) => {
16399
16553
  if (s)
16400
16554
  return /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingState, { type: "skeleton" });
@@ -16408,20 +16562,22 @@ const loadKaTeXCSS = () => {
16408
16562
  );
16409
16563
  if (!e)
16410
16564
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorState, { error: "No problem data provided" });
16411
- const p = {
16565
+ const m = {
16412
16566
  problemData: e,
16413
16567
  scene: t,
16414
16568
  submissionResult: r,
16415
- config: o
16569
+ config: o,
16570
+ value: p
16416
16571
  };
16417
- 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(
16418
16573
  DefaultLayout,
16419
16574
  {
16420
16575
  onSubmit: l,
16421
16576
  onNext: h,
16422
16577
  onRetry: c,
16423
16578
  onAnswerChange: d,
16424
- onHintToggle: f
16579
+ onHintToggle: f,
16580
+ value: p
16425
16581
  }
16426
16582
  ) });
16427
16583
  };
@@ -68655,11 +68811,11 @@ JXG$2.useBlackWhiteOptions;
68655
68811
  JXG$2.useStandardOptions;
68656
68812
  JXG$2.warn;
68657
68813
  JXG$2.isBrowser ? window.JXG = JXG$2 : JXG$2.isWebWorker() && (self.JXG = JXG$2);
68658
- const JXG$1 = JXG$2.JSXGraph, { OBJECT_TYPE_POINT } = JXG$1, GraphContainer = (e) => {
68814
+ const JXG$1 = JXG$2.JSXGraph, GraphContainer = (e) => {
68659
68815
  const t = useRef(null), [r, s] = useState(null), [n, o] = useState({}), a = useCallback((h, c) => {
68660
- e.onShapeChange && e.onShapeChange(h, c);
68816
+ e.onShapeChange;
68661
68817
  }, [e.onShapeChange]), l = useCallback((h) => {
68662
- e.onSelectionChange && e.onSelectionChange(h);
68818
+ e.onSelectionChange && e.onSelectionChange(h ? [h] : []);
68663
68819
  }, [e.onSelectionChange]);
68664
68820
  return useEffect(() => {
68665
68821
  if (t.current) {
@@ -68672,7 +68828,6 @@ const JXG$1 = JXG$2.JSXGraph, { OBJECT_TYPE_POINT } = JXG$1, GraphContainer = (e
68672
68828
  grid: e.showGrid ?? !0,
68673
68829
  showNavigation: !1,
68674
68830
  pan: { enabled: e.mode === "edit" },
68675
- zoom: { enabled: !1 },
68676
68831
  keepaspectratio: !0,
68677
68832
  showCopyright: !1
68678
68833
  });
@@ -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),