@khanacademy/perseus 19.1.8 → 19.1.9

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
@@ -8685,7 +8685,12 @@ class Graphie$1 {
8685
8685
  writable: true,
8686
8686
  value: void 0
8687
8687
  });
8688
+ // The primary drawing layer
8688
8689
  this.raphael = void 0;
8690
+ // The layer that all visuals with mouse handlers are drawn into
8691
+ this.mouselayer = void 0;
8692
+ this._mouselayerWrapper = void 0;
8693
+ this._visiblelayerWrapper = void 0;
8689
8694
  this.isMobile = false;
8690
8695
  // Set up some reasonable defaults
8691
8696
  this.currentStyle = {
@@ -9526,13 +9531,126 @@ class Graphie$1 {
9526
9531
  return processed;
9527
9532
  }
9528
9533
 
9529
- // This is a stub that's overridden in interactive.ts
9530
- getMouseCoord(event) {
9531
- throw new Error("getMouseCoord is a stub, and is not implemented");
9534
+ // Graphie puts text spans on top of the SVG, which looks good, but gets
9535
+ // in the way of mouse events. This adds another SVG element on top
9536
+ // of everything else where we can add invisible shapes with mouse
9537
+ // handlers wherever we want.
9538
+ addMouseLayer(options) {
9539
+ const localOptions = _extends({
9540
+ allowScratchpad: false,
9541
+ setDrawingAreaAvailable: function () {}
9542
+ }, options);
9543
+ const mouselayerZIndex = 2;
9544
+ this.mouselayer = Raphael$1(this.el, this.xpixels, this.ypixels);
9545
+ $(this.mouselayer.canvas).css("z-index", mouselayerZIndex);
9546
+ if (localOptions.onClick || localOptions.onMouseDown || localOptions.onMouseMove || localOptions.onMouseOver || localOptions.onMouseOut) {
9547
+ const canvasClickTarget = this.mouselayer.rect(0, 0, this.xpixels, this.ypixels).attr({
9548
+ fill: "#000",
9549
+ opacity: 0
9550
+ });
9551
+ let isClickingCanvas = false;
9552
+ $(this.mouselayer.canvas).on("vmousedown", e => {
9553
+ if (e.target === canvasClickTarget[0]) {
9554
+ if (localOptions.onMouseDown) {
9555
+ localOptions.onMouseDown(this.getMouseCoord(e));
9556
+ }
9557
+ isClickingCanvas = true;
9558
+ if (localOptions.onMouseMove) {
9559
+ const handler = localOptions.onMouseMove;
9560
+ $(document).bind("vmousemove.mouseLayer", e => {
9561
+ if (isClickingCanvas) {
9562
+ e.preventDefault();
9563
+ handler(this.getMouseCoord(e));
9564
+ }
9565
+ });
9566
+ }
9567
+ $(document).bind("vmouseup.mouseLayer", e => {
9568
+ $(document).unbind(".mouseLayer");
9569
+
9570
+ // Only register clicks that started on the canvas,
9571
+ // and not on another mouseLayer target
9572
+ if (isClickingCanvas && localOptions.onClick) {
9573
+ localOptions.onClick(this.getMouseCoord(e));
9574
+ }
9575
+ isClickingCanvas = false;
9576
+ });
9577
+ }
9578
+ });
9579
+ if (localOptions.onMouseOver) {
9580
+ const handler = localOptions.onMouseOver;
9581
+ $(this.mouselayer.canvas).on("vmouseover", e => {
9582
+ handler(this.getMouseCoord(e));
9583
+ });
9584
+ }
9585
+ if (localOptions.onMouseOut) {
9586
+ const handler = localOptions.onMouseOut;
9587
+ $(this.mouselayer.canvas).on("vmouseout", e => {
9588
+ handler(this.getMouseCoord(e));
9589
+ });
9590
+ }
9591
+ }
9592
+ if (!localOptions.allowScratchpad) {
9593
+ localOptions.setDrawingAreaAvailable == null || localOptions.setDrawingAreaAvailable(false);
9594
+ }
9595
+
9596
+ // Add mouse and visible wrapper layers for DOM-node-wrapped movables
9597
+ this._mouselayerWrapper = document.createElement("div");
9598
+ $(this._mouselayerWrapper).css({
9599
+ position: "absolute",
9600
+ left: 0,
9601
+ top: 0,
9602
+ zIndex: mouselayerZIndex
9603
+ });
9604
+ this._visiblelayerWrapper = document.createElement("div");
9605
+ $(this._visiblelayerWrapper).css({
9606
+ position: "absolute",
9607
+ left: 0,
9608
+ top: 0
9609
+ });
9610
+ const el = this.el;
9611
+ el.appendChild(this._visiblelayerWrapper);
9612
+ el.appendChild(this._mouselayerWrapper);
9613
+
9614
+ // Add functions for adding to wrappers
9615
+ this.addToMouseLayerWrapper = el => {
9616
+ var _this$_mouselayerWrap;
9617
+ (_this$_mouselayerWrap = this._mouselayerWrapper) == null || _this$_mouselayerWrap.appendChild(el);
9618
+ };
9619
+ this.addToVisibleLayerWrapper = el => {
9620
+ var _this$_visiblelayerWr;
9621
+ (_this$_visiblelayerWr = this._visiblelayerWrapper) == null || _this$_visiblelayerWr.appendChild(el);
9622
+ };
9623
+ }
9624
+ addToMouseLayerWrapper(el) {
9625
+ throw new Error("addToMouseLayerWrapper is not ready. Call addMouseLayer() first.");
9626
+ }
9627
+ addToVisibleLayerWrapper(el) {
9628
+ throw new Error("addToVisibleLayerWrapper is not ready. Call addMouseLayer() first.");
9629
+ }
9630
+ /**
9631
+ * Get mouse coordinates in pixels
9632
+ */
9633
+ getMousePx(event) {
9634
+ const offset = $(this.el).offset();
9635
+ const mouseX =
9636
+ // @ts-expect-error - TS18048 - 'event.pageX' is possibly 'undefined'.
9637
+ event.pageX -
9638
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
9639
+ offset.left;
9640
+ const mouseY =
9641
+ // @ts-expect-error - TS18048 - 'event.pageY' is possibly 'undefined'.
9642
+ event.pageY -
9643
+ // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
9644
+ offset.top;
9645
+ return [mouseX, mouseY];
9532
9646
  }
9533
9647
 
9534
- // This is a stub that's overridden in interactive.ts
9535
- addMouseLayer(options) {}
9648
+ /**
9649
+ * Get mouse coordinates in graph coordinates
9650
+ */
9651
+ getMouseCoord(event) {
9652
+ return this.unscalePoint(this.getMousePx(event));
9653
+ }
9536
9654
  }
9537
9655
  const labelDirections = {
9538
9656
  center: [-0.5, -0.5],
@@ -10632,114 +10750,6 @@ const InteractiveUtils = {
10632
10750
  }
10633
10751
  };
10634
10752
  _.extend(GraphUtils.Graphie.prototype, {
10635
- // graphie puts text spans on top of the SVG, which looks good, but gets
10636
- // in the way of mouse events. This adds another SVG element on top
10637
- // of everything else where we can add invisible shapes with mouse
10638
- // handlers wherever we want.
10639
- addMouseLayer: function (options) {
10640
- const graph = this;
10641
- options = _.extend({
10642
- allowScratchpad: false,
10643
- setDrawingAreaAvailable: function () {}
10644
- }, options);
10645
- const mouselayerZIndex = 2;
10646
- graph.mouselayer = Raphael$1(graph.raphael.canvas.parentNode, graph.xpixels, graph.ypixels);
10647
- $(graph.mouselayer.canvas).css("z-index", mouselayerZIndex);
10648
- if (options.onClick || options.onMouseDown || options.onMouseMove || options.onMouseOver || options.onMouseOut) {
10649
- const canvasClickTarget = graph.mouselayer.rect(0, 0, graph.xpixels, graph.ypixels).attr({
10650
- fill: "#000",
10651
- opacity: 0
10652
- });
10653
- let isClickingCanvas = false;
10654
- $(graph.mouselayer.canvas).on("vmousedown", function (e) {
10655
- if (e.target === canvasClickTarget[0]) {
10656
- if (options.onMouseDown) {
10657
- options.onMouseDown(graph.getMouseCoord(e));
10658
- }
10659
- isClickingCanvas = true;
10660
- if (options.onMouseMove) {
10661
- const handler = options.onMouseMove;
10662
- $(document).bind("vmousemove.mouseLayer", function (e) {
10663
- if (isClickingCanvas) {
10664
- e.preventDefault();
10665
- handler(graph.getMouseCoord(e));
10666
- }
10667
- });
10668
- }
10669
- $(document).bind("vmouseup.mouseLayer", function (e) {
10670
- $(document).unbind(".mouseLayer");
10671
-
10672
- // Only register clicks that started on the canvas,
10673
- // and not on another mouseLayer target
10674
- if (isClickingCanvas && options.onClick) {
10675
- options.onClick(graph.getMouseCoord(e));
10676
- }
10677
- isClickingCanvas = false;
10678
- });
10679
- }
10680
- });
10681
- if (options.onMouseOver) {
10682
- const handler = options.onMouseOver;
10683
- $(graph.mouselayer.canvas).on("vmouseover", function (e) {
10684
- handler(graph.getMouseCoord(e));
10685
- });
10686
- }
10687
- if (options.onMouseOut) {
10688
- const handler = options.onMouseOut;
10689
- $(graph.mouselayer.canvas).on("vmouseout", function (e) {
10690
- handler(graph.getMouseCoord(e));
10691
- });
10692
- }
10693
- }
10694
- if (!options.allowScratchpad) {
10695
- options.setDrawingAreaAvailable == null || options.setDrawingAreaAvailable(false);
10696
- }
10697
-
10698
- // Add mouse and visible wrapper layers for DOM-node-wrapped movables
10699
- graph._mouselayerWrapper = document.createElement("div");
10700
- $(graph._mouselayerWrapper).css({
10701
- position: "absolute",
10702
- left: 0,
10703
- top: 0,
10704
- zIndex: mouselayerZIndex
10705
- });
10706
- graph._visiblelayerWrapper = document.createElement("div");
10707
- $(graph._visiblelayerWrapper).css({
10708
- position: "absolute",
10709
- left: 0,
10710
- top: 0
10711
- });
10712
- const el = graph.raphael.canvas.parentNode;
10713
- el.appendChild(graph._visiblelayerWrapper);
10714
- el.appendChild(graph._mouselayerWrapper);
10715
-
10716
- // Add functions for adding to wrappers
10717
- graph.addToMouseLayerWrapper = function (el) {
10718
- this._mouselayerWrapper.appendChild(el);
10719
- };
10720
- graph.addToVisibleLayerWrapper = function (el) {
10721
- this._visiblelayerWrapper.appendChild(el);
10722
- };
10723
- },
10724
- /**
10725
- * Get mouse coordinates in pixels
10726
- */
10727
- getMousePx: function (event) {
10728
- const graphie = this;
10729
- const mouseX =
10730
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
10731
- event.pageX - $(graphie.raphael.canvas.parentNode).offset().left;
10732
- const mouseY =
10733
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'.
10734
- event.pageY - $(graphie.raphael.canvas.parentNode).offset().top;
10735
- return [mouseX, mouseY];
10736
- },
10737
- /**
10738
- * Get mouse coordinates in graph coordinates
10739
- */
10740
- getMouseCoord: function (event) {
10741
- return this.unscalePoint(this.getMousePx(event));
10742
- },
10743
10753
  /**
10744
10754
  * Unlike all other Graphie-related code, the following three functions use
10745
10755
  * a lot of scaled coordinates (so that labels appear the same size
@@ -23226,14 +23236,16 @@ const Choice = function Choice(props) {
23226
23236
  content: ({
23227
23237
  close
23228
23238
  }) => /*#__PURE__*/React.createElement(PopoverContent, {
23229
- title: "Cross out",
23230
- content: "Cross out option",
23239
+ title: i18n._("Cross out"),
23240
+ content: i18n._("Cross out option"),
23231
23241
  closeButtonVisible: true,
23232
23242
  actions: /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(Strut, {
23233
23243
  size: Spacing.medium_16
23234
23244
  }), /*#__PURE__*/React.createElement(Button, {
23235
23245
  kind: "primary",
23236
- "aria-label": `Cross out Choice ${getChoiceLetter(pos)}`,
23246
+ "aria-label": i18n._("Cross out Choice %(letter)s", {
23247
+ letter: getChoiceLetter(pos)
23248
+ }),
23237
23249
  disabled: apiOptions.readOnly || reviewMode,
23238
23250
  onClick: () => {
23239
23251
  if (!crossedOut) {
@@ -23252,13 +23264,15 @@ const Choice = function Choice(props) {
23252
23264
  }
23253
23265
  close();
23254
23266
  }
23255
- }, crossedOut ? "Bring back" : "Cross out"))
23267
+ }, crossedOut ? i18n._("Bring back") : i18n._("Cross out")))
23256
23268
  })
23257
23269
  }, ({
23258
23270
  open
23259
23271
  }) => /*#__PURE__*/React.createElement(Clickable, {
23260
23272
  onClick: open,
23261
- "aria-label": `Open menu for Choice ${getChoiceLetter(pos)}`,
23273
+ "aria-label": i18n._(`Open menu for Choice %(letter)s`, {
23274
+ letter: getChoiceLetter(pos)
23275
+ }),
23262
23276
  style: {
23263
23277
  alignSelf: "center",
23264
23278
  padding: "5px",
@@ -41554,7 +41568,7 @@ const init = function init(options) {
41554
41568
 
41555
41569
  // This file is processed by a Rollup plugin (replace) to inject the production
41556
41570
  const libName = "@khanacademy/perseus";
41557
- const libVersion = "19.1.8";
41571
+ const libVersion = "19.1.9";
41558
41572
  addLibraryVersionToPerseusDebug(libName, libVersion);
41559
41573
 
41560
41574
  const apiVersion = {