@khanacademy/perseus 27.0.0 → 27.0.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/es/index.js CHANGED
@@ -25035,6 +25035,7 @@ class Explanation extends React.Component {
25035
25035
  this.state = {
25036
25036
  expanded: false
25037
25037
  };
25038
+ this._mounted = false;
25038
25039
  this.change = (...args) => {
25039
25040
  return change.apply(this, args);
25040
25041
  };
@@ -25059,10 +25060,16 @@ class Explanation extends React.Component {
25059
25060
  message: null
25060
25061
  };
25061
25062
  }
25063
+ componentDidMount() {
25064
+ this._mounted = true;
25065
+ }
25066
+ componentWillUnmount() {
25067
+ this._mounted = false;
25068
+ }
25062
25069
  render() {
25063
25070
  const promptText = this.state.expanded ? this.props.hidePrompt : this.props.showPrompt;
25064
25071
  const caretIcon = this.state.expanded ? caretUp : caretDown;
25065
- const allowTransition = mediaQueryIsMatched("(prefers-reduced-motion: no-preference)");
25072
+ const allowTransition = this._mounted && mediaQueryIsMatched("(prefers-reduced-motion: no-preference)");
25066
25073
 
25067
25074
  // Special styling is needed to fit the button in a block of text without throwing off the line spacing.
25068
25075
  // While the button is not normally included in a block of text, it needs to be able to accommodate such a case.
@@ -35902,6 +35909,10 @@ const styles$f = StyleSheet.create({
35902
35909
  });
35903
35910
 
35904
35911
  function shouldReduceMotion() {
35912
+ // We cannot use matchMedia during SSR.
35913
+ if (typeof window.matchMedia !== "function") {
35914
+ return true;
35915
+ }
35905
35916
  const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
35906
35917
  return !mediaQuery || mediaQuery.matches;
35907
35918
  }
@@ -35911,6 +35922,13 @@ class Marker extends React.Component {
35911
35922
  super(...args);
35912
35923
  // The marker icon element.
35913
35924
  this._icon = void 0;
35925
+ this._mounted = false;
35926
+ }
35927
+ componentDidMount() {
35928
+ this._mounted = true;
35929
+ }
35930
+ componentWillUnmount() {
35931
+ this._mounted = false;
35914
35932
  }
35915
35933
  renderIcon() {
35916
35934
  const {
@@ -35952,7 +35970,7 @@ class Marker extends React.Component {
35952
35970
  size: 8
35953
35971
  });
35954
35972
  } else if (showPulsate) {
35955
- iconStyles = [styles$e.markerPulsateBase, shouldReduceMotion() ? showPulsate && styles$e.markerUnfilledPulsateOnce : showPulsate && styles$e.markerUnfilledPulsateInfinite];
35973
+ iconStyles = [styles$e.markerPulsateBase, this._mounted && shouldReduceMotion() ? showPulsate && styles$e.markerUnfilledPulsateOnce : showPulsate && styles$e.markerUnfilledPulsateInfinite];
35956
35974
  }
35957
35975
  return /*#__PURE__*/React.createElement(View, {
35958
35976
  style: [styles$e.markerIcon, iconStyles],
@@ -36314,6 +36332,7 @@ class LabelImage extends React.Component {
36314
36332
  super(props);
36315
36333
  // The rendered markers on the question image for labeling.
36316
36334
  this._markers = void 0;
36335
+ this._mounted = false;
36317
36336
  this._markers = [];
36318
36337
  this.state = {
36319
36338
  activeMarkerIndex: -1,
@@ -36321,6 +36340,12 @@ class LabelImage extends React.Component {
36321
36340
  hideAnswers: false
36322
36341
  };
36323
36342
  }
36343
+ componentDidMount() {
36344
+ this._mounted = true;
36345
+ }
36346
+ componentWillUnmount() {
36347
+ this._mounted = false;
36348
+ }
36324
36349
  simpleValidate(rubric) {
36325
36350
  return LabelImage.validate(this.getUserInput(), rubric);
36326
36351
  }
@@ -36457,13 +36482,14 @@ class LabelImage extends React.Component {
36457
36482
  markersInteracted
36458
36483
  } = this.state;
36459
36484
 
36485
+ // Determine whether page is rendered in a narrow browser window.
36486
+ const isNarrowPage = this._mounted && window.matchMedia(mediaQueries.xsOrSmaller.replace("@media ", "")).matches;
36487
+
36488
+ // Determine whether the image is wider than it is tall.
36489
+ const isWideImage = this.props.imageWidth / 2 > this.props.imageHeight;
36490
+
36460
36491
  // Render all markers for widget.
36461
36492
  return markers.map((marker, index) => {
36462
- // Determine whether page is rendered in a narrow browser window.
36463
- const isNarrowPage = window.matchMedia(mediaQueries.xsOrSmaller.replace("@media ", "")).matches;
36464
-
36465
- // Determine whether the image is wider than it is tall.
36466
- const isWideImage = this.props.imageWidth / 2 > this.props.imageHeight;
36467
36493
  let side;
36468
36494
  let markerPosition;
36469
36495
  // Position popup closest to the center, preferring it renders
@@ -44089,7 +44115,7 @@ const init = function init(options) {
44089
44115
 
44090
44116
  // This file is processed by a Rollup plugin (replace) to inject the production
44091
44117
  const libName = "@khanacademy/perseus";
44092
- const libVersion = "27.0.0";
44118
+ const libVersion = "27.0.1";
44093
44119
  addLibraryVersionToPerseusDebug(libName, libVersion);
44094
44120
 
44095
44121
  const apiVersion = {