@mathscan/math-exercise-engine 1.2.4 → 1.2.5

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
@@ -11916,7 +11916,7 @@ function getEventCoordinates(event) {
11916
11916
  }
11917
11917
  return null;
11918
11918
  }
11919
- const CSS = /* @__PURE__ */ Object.freeze({
11919
+ const CSS$1 = /* @__PURE__ */ Object.freeze({
11920
11920
  Translate: {
11921
11921
  toString(transform) {
11922
11922
  if (!transform) {
@@ -11946,7 +11946,7 @@ const CSS = /* @__PURE__ */ Object.freeze({
11946
11946
  if (!transform) {
11947
11947
  return;
11948
11948
  }
11949
- return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(" ");
11949
+ return [CSS$1.Translate.toString(transform), CSS$1.Scale.toString(transform)].join(" ");
11950
11950
  }
11951
11951
  },
11952
11952
  Transition: {
@@ -15065,7 +15065,7 @@ const PositionedOverlay = /* @__PURE__ */ forwardRef((_ref, ref) => {
15065
15065
  height: rect.height,
15066
15066
  top: rect.top,
15067
15067
  left: rect.left,
15068
- transform: CSS.Transform.toString(scaleAdjustedTransform),
15068
+ transform: CSS$1.Transform.toString(scaleAdjustedTransform),
15069
15069
  transformOrigin: adjustScale2 && activatorEvent ? getRelativeTransformOrigin(activatorEvent, rect) : void 0,
15070
15070
  transition: typeof transition === "function" ? transition(activatorEvent) : transition,
15071
15071
  ...style
@@ -15126,9 +15126,9 @@ const defaultKeyframeResolver = (_ref2) => {
15126
15126
  }
15127
15127
  } = _ref2;
15128
15128
  return [{
15129
- transform: CSS.Transform.toString(initial)
15129
+ transform: CSS$1.Transform.toString(initial)
15130
15130
  }, {
15131
- transform: CSS.Transform.toString(final)
15131
+ transform: CSS$1.Transform.toString(final)
15132
15132
  }];
15133
15133
  };
15134
15134
  const defaultDropAnimationConfiguration = {
@@ -15561,7 +15561,7 @@ const Draggable = ({
15561
15561
  disabled
15562
15562
  });
15563
15563
  const style = {
15564
- transform: CSS.Translate.toString(transform),
15564
+ transform: CSS$1.Translate.toString(transform),
15565
15565
  cursor: disabled ? "default" : "grab",
15566
15566
  touchAction: "none"
15567
15567
  };
@@ -17921,7 +17921,7 @@ const CHART_TYPE_COMPONENTS = {
17921
17921
  const Chart = (props) => {
17922
17922
  const ChartComponent = CHART_TYPE_COMPONENTS[props.item.chartType];
17923
17923
  if (!ChartComponent) {
17924
- return /* @__PURE__ */ jsx("div", { className: "chart chart--unsupported", children: /* @__PURE__ */ jsx("span", { style: { color: "var(--exercise-incorrect, #ef4444)", fontSize: "0.85rem" }, children: `Chart type "${props.item.chartType}" is not yet supported.` }) });
17924
+ return /* @__PURE__ */ jsx("div", { className: "chart chart--unsupported", children: /* @__PURE__ */ jsx("span", { style: { color: "var(--exercise-error, #ef4444)", fontSize: "0.85rem" }, children: `Chart type "${props.item.chartType}" is not yet supported.` }) });
17925
17925
  }
17926
17926
  return /* @__PURE__ */ jsx(ChartComponent, { ...props });
17927
17927
  };
@@ -20841,6 +20841,15 @@ const TOOL_ASPECT_RATIO = {
20841
20841
  "set-square": SET_SQUARE_ASPECT_RATIO
20842
20842
  };
20843
20843
  const FLIP_BTN_EXTRA = 44;
20844
+ function warnOnInvalidThemeColors(theme) {
20845
+ if (process.env.NODE_ENV === "production" || !theme) return;
20846
+ if (typeof CSS === "undefined" || typeof CSS.supports !== "function") return;
20847
+ for (const [key2, value] of Object.entries(theme)) {
20848
+ if (value && !CSS.supports("color", value)) {
20849
+ console.warn(`[ExerciseRenderer] theme.${key2} is not a valid CSS color: "${value}"`);
20850
+ }
20851
+ }
20852
+ }
20844
20853
  function buildInitialValues(json) {
20845
20854
  const initial = {};
20846
20855
  for (const [id, widget] of Object.entries(json.widgets)) {
@@ -20913,7 +20922,8 @@ const ExerciseRenderer = forwardRef(({
20913
20922
  showSubmitButton = false,
20914
20923
  className = "",
20915
20924
  soundEnabled = true,
20916
- sounds
20925
+ sounds,
20926
+ theme
20917
20927
  }, ref) => {
20918
20928
  const initialValuesSignature = useMemo(() => buildInitialValuesSignature(json), [json]);
20919
20929
  const [values, setValues] = useState(() => buildInitialValues(json));
@@ -20927,6 +20937,15 @@ const ExerciseRenderer = forwardRef(({
20927
20937
  const rootRef = useRef(null);
20928
20938
  const [resetKey, setResetKey] = useState(0);
20929
20939
  const [revealed, setRevealed] = useState(false);
20940
+ const themeStyle = useMemo(() => {
20941
+ const style = {};
20942
+ if (theme?.correct) style["--exercise-correct"] = theme.correct;
20943
+ if (theme?.incorrect) style["--exercise-incorrect"] = theme.incorrect;
20944
+ return Object.keys(style).length > 0 ? style : void 0;
20945
+ }, [theme?.correct, theme?.incorrect]);
20946
+ useEffect(() => {
20947
+ warnOnInvalidThemeColors({ correct: theme?.correct, incorrect: theme?.incorrect });
20948
+ }, [theme?.correct, theme?.incorrect]);
20930
20949
  const playSound = useSoundPlayer(soundEnabled, sounds);
20931
20950
  const externallyLocked = useExerciseLocked();
20932
20951
  useLayoutEffect(() => {
@@ -21183,7 +21202,7 @@ const ExerciseRenderer = forwardRef(({
21183
21202
  if (setSquareWidget) add2("set-square-1", "set-square", Math.round(getSize(setSquareWidget) * 160));
21184
21203
  return { tools: list, toolsMinHeight: maxH };
21185
21204
  }, [rulerWidget, protractorWidget, setSquareWidget]);
21186
- return /* @__PURE__ */ jsx(SoundPlayerProvider, { play: playSound, children: /* @__PURE__ */ jsx(ExerciseLockProvider, { locked, children: /* @__PURE__ */ jsx(ExerciseDndProvider, { droppedSources, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: `math-exercise-renderer ${revealed ? "revealed" : ""} ${locked ? "locked" : ""} ${className}`, children: [
21205
+ return /* @__PURE__ */ jsx(SoundPlayerProvider, { play: playSound, children: /* @__PURE__ */ jsx(ExerciseLockProvider, { locked, children: /* @__PURE__ */ jsx(ExerciseDndProvider, { droppedSources, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: `math-exercise-renderer ${revealed ? "revealed" : ""} ${locked ? "locked" : ""} ${className}`, style: themeStyle, children: [
21187
21206
  /* @__PURE__ */ jsxs(
21188
21207
  "div",
21189
21208
  {