@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 +133 -119
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +132 -119
- package/dist/index.js.map +1 -1
- package/dist/strings.js +4 -0
- package/dist/util/graphie.d.ts +23 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8692,6 +8692,11 @@ function polar(r, th) {
|
|
|
8692
8692
|
class Graphie$1 {
|
|
8693
8693
|
#bounds;
|
|
8694
8694
|
#drawingTransform;
|
|
8695
|
+
|
|
8696
|
+
// The primary drawing layer
|
|
8697
|
+
|
|
8698
|
+
// The layer that all visuals with mouse handlers are drawn into
|
|
8699
|
+
|
|
8695
8700
|
isMobile = false;
|
|
8696
8701
|
// Set up some reasonable defaults
|
|
8697
8702
|
currentStyle = {
|
|
@@ -9537,13 +9542,125 @@ class Graphie$1 {
|
|
|
9537
9542
|
return processed;
|
|
9538
9543
|
}
|
|
9539
9544
|
|
|
9540
|
-
//
|
|
9541
|
-
|
|
9542
|
-
|
|
9545
|
+
// Graphie puts text spans on top of the SVG, which looks good, but gets
|
|
9546
|
+
// in the way of mouse events. This adds another SVG element on top
|
|
9547
|
+
// of everything else where we can add invisible shapes with mouse
|
|
9548
|
+
// handlers wherever we want.
|
|
9549
|
+
addMouseLayer(options) {
|
|
9550
|
+
const localOptions = {
|
|
9551
|
+
allowScratchpad: false,
|
|
9552
|
+
setDrawingAreaAvailable: function () {},
|
|
9553
|
+
...options
|
|
9554
|
+
};
|
|
9555
|
+
const mouselayerZIndex = 2;
|
|
9556
|
+
this.mouselayer = Raphael$1(this.el, this.xpixels, this.ypixels);
|
|
9557
|
+
$__default["default"](this.mouselayer.canvas).css("z-index", mouselayerZIndex);
|
|
9558
|
+
if (localOptions.onClick || localOptions.onMouseDown || localOptions.onMouseMove || localOptions.onMouseOver || localOptions.onMouseOut) {
|
|
9559
|
+
const canvasClickTarget = this.mouselayer.rect(0, 0, this.xpixels, this.ypixels).attr({
|
|
9560
|
+
fill: "#000",
|
|
9561
|
+
opacity: 0
|
|
9562
|
+
});
|
|
9563
|
+
let isClickingCanvas = false;
|
|
9564
|
+
$__default["default"](this.mouselayer.canvas).on("vmousedown", e => {
|
|
9565
|
+
if (e.target === canvasClickTarget[0]) {
|
|
9566
|
+
if (localOptions.onMouseDown) {
|
|
9567
|
+
localOptions.onMouseDown(this.getMouseCoord(e));
|
|
9568
|
+
}
|
|
9569
|
+
isClickingCanvas = true;
|
|
9570
|
+
if (localOptions.onMouseMove) {
|
|
9571
|
+
const handler = localOptions.onMouseMove;
|
|
9572
|
+
$__default["default"](document).bind("vmousemove.mouseLayer", e => {
|
|
9573
|
+
if (isClickingCanvas) {
|
|
9574
|
+
e.preventDefault();
|
|
9575
|
+
handler(this.getMouseCoord(e));
|
|
9576
|
+
}
|
|
9577
|
+
});
|
|
9578
|
+
}
|
|
9579
|
+
$__default["default"](document).bind("vmouseup.mouseLayer", e => {
|
|
9580
|
+
$__default["default"](document).unbind(".mouseLayer");
|
|
9581
|
+
|
|
9582
|
+
// Only register clicks that started on the canvas,
|
|
9583
|
+
// and not on another mouseLayer target
|
|
9584
|
+
if (isClickingCanvas && localOptions.onClick) {
|
|
9585
|
+
localOptions.onClick(this.getMouseCoord(e));
|
|
9586
|
+
}
|
|
9587
|
+
isClickingCanvas = false;
|
|
9588
|
+
});
|
|
9589
|
+
}
|
|
9590
|
+
});
|
|
9591
|
+
if (localOptions.onMouseOver) {
|
|
9592
|
+
const handler = localOptions.onMouseOver;
|
|
9593
|
+
$__default["default"](this.mouselayer.canvas).on("vmouseover", e => {
|
|
9594
|
+
handler(this.getMouseCoord(e));
|
|
9595
|
+
});
|
|
9596
|
+
}
|
|
9597
|
+
if (localOptions.onMouseOut) {
|
|
9598
|
+
const handler = localOptions.onMouseOut;
|
|
9599
|
+
$__default["default"](this.mouselayer.canvas).on("vmouseout", e => {
|
|
9600
|
+
handler(this.getMouseCoord(e));
|
|
9601
|
+
});
|
|
9602
|
+
}
|
|
9603
|
+
}
|
|
9604
|
+
if (!localOptions.allowScratchpad) {
|
|
9605
|
+
localOptions.setDrawingAreaAvailable?.(false);
|
|
9606
|
+
}
|
|
9607
|
+
|
|
9608
|
+
// Add mouse and visible wrapper layers for DOM-node-wrapped movables
|
|
9609
|
+
this._mouselayerWrapper = document.createElement("div");
|
|
9610
|
+
$__default["default"](this._mouselayerWrapper).css({
|
|
9611
|
+
position: "absolute",
|
|
9612
|
+
left: 0,
|
|
9613
|
+
top: 0,
|
|
9614
|
+
zIndex: mouselayerZIndex
|
|
9615
|
+
});
|
|
9616
|
+
this._visiblelayerWrapper = document.createElement("div");
|
|
9617
|
+
$__default["default"](this._visiblelayerWrapper).css({
|
|
9618
|
+
position: "absolute",
|
|
9619
|
+
left: 0,
|
|
9620
|
+
top: 0
|
|
9621
|
+
});
|
|
9622
|
+
const el = this.el;
|
|
9623
|
+
el.appendChild(this._visiblelayerWrapper);
|
|
9624
|
+
el.appendChild(this._mouselayerWrapper);
|
|
9625
|
+
|
|
9626
|
+
// Add functions for adding to wrappers
|
|
9627
|
+
this.addToMouseLayerWrapper = el => {
|
|
9628
|
+
this._mouselayerWrapper?.appendChild(el);
|
|
9629
|
+
};
|
|
9630
|
+
this.addToVisibleLayerWrapper = el => {
|
|
9631
|
+
this._visiblelayerWrapper?.appendChild(el);
|
|
9632
|
+
};
|
|
9633
|
+
}
|
|
9634
|
+
addToMouseLayerWrapper(el) {
|
|
9635
|
+
throw new Error("addToMouseLayerWrapper is not ready. Call addMouseLayer() first.");
|
|
9636
|
+
}
|
|
9637
|
+
addToVisibleLayerWrapper(el) {
|
|
9638
|
+
throw new Error("addToVisibleLayerWrapper is not ready. Call addMouseLayer() first.");
|
|
9639
|
+
}
|
|
9640
|
+
/**
|
|
9641
|
+
* Get mouse coordinates in pixels
|
|
9642
|
+
*/
|
|
9643
|
+
getMousePx(event) {
|
|
9644
|
+
const offset = $__default["default"](this.el).offset();
|
|
9645
|
+
const mouseX =
|
|
9646
|
+
// @ts-expect-error - TS18048 - 'event.pageX' is possibly 'undefined'.
|
|
9647
|
+
event.pageX -
|
|
9648
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
9649
|
+
offset.left;
|
|
9650
|
+
const mouseY =
|
|
9651
|
+
// @ts-expect-error - TS18048 - 'event.pageY' is possibly 'undefined'.
|
|
9652
|
+
event.pageY -
|
|
9653
|
+
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
9654
|
+
offset.top;
|
|
9655
|
+
return [mouseX, mouseY];
|
|
9543
9656
|
}
|
|
9544
9657
|
|
|
9545
|
-
|
|
9546
|
-
|
|
9658
|
+
/**
|
|
9659
|
+
* Get mouse coordinates in graph coordinates
|
|
9660
|
+
*/
|
|
9661
|
+
getMouseCoord(event) {
|
|
9662
|
+
return this.unscalePoint(this.getMousePx(event));
|
|
9663
|
+
}
|
|
9547
9664
|
}
|
|
9548
9665
|
const labelDirections = {
|
|
9549
9666
|
center: [-0.5, -0.5],
|
|
@@ -10644,114 +10761,6 @@ const InteractiveUtils = {
|
|
|
10644
10761
|
}
|
|
10645
10762
|
};
|
|
10646
10763
|
___default["default"].extend(GraphUtils.Graphie.prototype, {
|
|
10647
|
-
// graphie puts text spans on top of the SVG, which looks good, but gets
|
|
10648
|
-
// in the way of mouse events. This adds another SVG element on top
|
|
10649
|
-
// of everything else where we can add invisible shapes with mouse
|
|
10650
|
-
// handlers wherever we want.
|
|
10651
|
-
addMouseLayer: function (options) {
|
|
10652
|
-
const graph = this;
|
|
10653
|
-
options = ___default["default"].extend({
|
|
10654
|
-
allowScratchpad: false,
|
|
10655
|
-
setDrawingAreaAvailable: function () {}
|
|
10656
|
-
}, options);
|
|
10657
|
-
const mouselayerZIndex = 2;
|
|
10658
|
-
graph.mouselayer = Raphael$1(graph.raphael.canvas.parentNode, graph.xpixels, graph.ypixels);
|
|
10659
|
-
$__default["default"](graph.mouselayer.canvas).css("z-index", mouselayerZIndex);
|
|
10660
|
-
if (options.onClick || options.onMouseDown || options.onMouseMove || options.onMouseOver || options.onMouseOut) {
|
|
10661
|
-
const canvasClickTarget = graph.mouselayer.rect(0, 0, graph.xpixels, graph.ypixels).attr({
|
|
10662
|
-
fill: "#000",
|
|
10663
|
-
opacity: 0
|
|
10664
|
-
});
|
|
10665
|
-
let isClickingCanvas = false;
|
|
10666
|
-
$__default["default"](graph.mouselayer.canvas).on("vmousedown", function (e) {
|
|
10667
|
-
if (e.target === canvasClickTarget[0]) {
|
|
10668
|
-
if (options.onMouseDown) {
|
|
10669
|
-
options.onMouseDown(graph.getMouseCoord(e));
|
|
10670
|
-
}
|
|
10671
|
-
isClickingCanvas = true;
|
|
10672
|
-
if (options.onMouseMove) {
|
|
10673
|
-
const handler = options.onMouseMove;
|
|
10674
|
-
$__default["default"](document).bind("vmousemove.mouseLayer", function (e) {
|
|
10675
|
-
if (isClickingCanvas) {
|
|
10676
|
-
e.preventDefault();
|
|
10677
|
-
handler(graph.getMouseCoord(e));
|
|
10678
|
-
}
|
|
10679
|
-
});
|
|
10680
|
-
}
|
|
10681
|
-
$__default["default"](document).bind("vmouseup.mouseLayer", function (e) {
|
|
10682
|
-
$__default["default"](document).unbind(".mouseLayer");
|
|
10683
|
-
|
|
10684
|
-
// Only register clicks that started on the canvas,
|
|
10685
|
-
// and not on another mouseLayer target
|
|
10686
|
-
if (isClickingCanvas && options.onClick) {
|
|
10687
|
-
options.onClick(graph.getMouseCoord(e));
|
|
10688
|
-
}
|
|
10689
|
-
isClickingCanvas = false;
|
|
10690
|
-
});
|
|
10691
|
-
}
|
|
10692
|
-
});
|
|
10693
|
-
if (options.onMouseOver) {
|
|
10694
|
-
const handler = options.onMouseOver;
|
|
10695
|
-
$__default["default"](graph.mouselayer.canvas).on("vmouseover", function (e) {
|
|
10696
|
-
handler(graph.getMouseCoord(e));
|
|
10697
|
-
});
|
|
10698
|
-
}
|
|
10699
|
-
if (options.onMouseOut) {
|
|
10700
|
-
const handler = options.onMouseOut;
|
|
10701
|
-
$__default["default"](graph.mouselayer.canvas).on("vmouseout", function (e) {
|
|
10702
|
-
handler(graph.getMouseCoord(e));
|
|
10703
|
-
});
|
|
10704
|
-
}
|
|
10705
|
-
}
|
|
10706
|
-
if (!options.allowScratchpad) {
|
|
10707
|
-
options.setDrawingAreaAvailable?.(false);
|
|
10708
|
-
}
|
|
10709
|
-
|
|
10710
|
-
// Add mouse and visible wrapper layers for DOM-node-wrapped movables
|
|
10711
|
-
graph._mouselayerWrapper = document.createElement("div");
|
|
10712
|
-
$__default["default"](graph._mouselayerWrapper).css({
|
|
10713
|
-
position: "absolute",
|
|
10714
|
-
left: 0,
|
|
10715
|
-
top: 0,
|
|
10716
|
-
zIndex: mouselayerZIndex
|
|
10717
|
-
});
|
|
10718
|
-
graph._visiblelayerWrapper = document.createElement("div");
|
|
10719
|
-
$__default["default"](graph._visiblelayerWrapper).css({
|
|
10720
|
-
position: "absolute",
|
|
10721
|
-
left: 0,
|
|
10722
|
-
top: 0
|
|
10723
|
-
});
|
|
10724
|
-
const el = graph.raphael.canvas.parentNode;
|
|
10725
|
-
el.appendChild(graph._visiblelayerWrapper);
|
|
10726
|
-
el.appendChild(graph._mouselayerWrapper);
|
|
10727
|
-
|
|
10728
|
-
// Add functions for adding to wrappers
|
|
10729
|
-
graph.addToMouseLayerWrapper = function (el) {
|
|
10730
|
-
this._mouselayerWrapper.appendChild(el);
|
|
10731
|
-
};
|
|
10732
|
-
graph.addToVisibleLayerWrapper = function (el) {
|
|
10733
|
-
this._visiblelayerWrapper.appendChild(el);
|
|
10734
|
-
};
|
|
10735
|
-
},
|
|
10736
|
-
/**
|
|
10737
|
-
* Get mouse coordinates in pixels
|
|
10738
|
-
*/
|
|
10739
|
-
getMousePx: function (event) {
|
|
10740
|
-
const graphie = this;
|
|
10741
|
-
const mouseX =
|
|
10742
|
-
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
10743
|
-
event.pageX - $__default["default"](graphie.raphael.canvas.parentNode).offset().left;
|
|
10744
|
-
const mouseY =
|
|
10745
|
-
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
|
|
10746
|
-
event.pageY - $__default["default"](graphie.raphael.canvas.parentNode).offset().top;
|
|
10747
|
-
return [mouseX, mouseY];
|
|
10748
|
-
},
|
|
10749
|
-
/**
|
|
10750
|
-
* Get mouse coordinates in graph coordinates
|
|
10751
|
-
*/
|
|
10752
|
-
getMouseCoord: function (event) {
|
|
10753
|
-
return this.unscalePoint(this.getMousePx(event));
|
|
10754
|
-
},
|
|
10755
10764
|
/**
|
|
10756
10765
|
* Unlike all other Graphie-related code, the following three functions use
|
|
10757
10766
|
* a lot of scaled coordinates (so that labels appear the same size
|
|
@@ -23343,14 +23352,16 @@ const Choice = function (props) {
|
|
|
23343
23352
|
close
|
|
23344
23353
|
} = _ref2;
|
|
23345
23354
|
return /*#__PURE__*/React__namespace.createElement(wonderBlocksPopover.PopoverContent, {
|
|
23346
|
-
title: "Cross out",
|
|
23347
|
-
content: "Cross out option",
|
|
23355
|
+
title: i18n__namespace._("Cross out"),
|
|
23356
|
+
content: i18n__namespace._("Cross out option"),
|
|
23348
23357
|
closeButtonVisible: true,
|
|
23349
23358
|
actions: /*#__PURE__*/React__namespace.createElement(wonderBlocksCore.View, null, /*#__PURE__*/React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
23350
23359
|
size: Spacing__default["default"].medium_16
|
|
23351
23360
|
}), /*#__PURE__*/React__namespace.createElement(Button__default["default"], {
|
|
23352
23361
|
kind: "primary",
|
|
23353
|
-
"aria-label":
|
|
23362
|
+
"aria-label": i18n__namespace._("Cross out Choice %(letter)s", {
|
|
23363
|
+
letter: getChoiceLetter(pos)
|
|
23364
|
+
}),
|
|
23354
23365
|
disabled: apiOptions.readOnly || reviewMode,
|
|
23355
23366
|
onClick: () => {
|
|
23356
23367
|
if (!crossedOut) {
|
|
@@ -23369,7 +23380,7 @@ const Choice = function (props) {
|
|
|
23369
23380
|
}
|
|
23370
23381
|
close();
|
|
23371
23382
|
}
|
|
23372
|
-
}, crossedOut ? "Bring back" : "Cross out"))
|
|
23383
|
+
}, crossedOut ? i18n__namespace._("Bring back") : i18n__namespace._("Cross out")))
|
|
23373
23384
|
});
|
|
23374
23385
|
}
|
|
23375
23386
|
}, _ref3 => {
|
|
@@ -23378,7 +23389,9 @@ const Choice = function (props) {
|
|
|
23378
23389
|
} = _ref3;
|
|
23379
23390
|
return /*#__PURE__*/React__namespace.createElement(Clickable__default["default"], {
|
|
23380
23391
|
onClick: open,
|
|
23381
|
-
"aria-label": `Open menu for Choice
|
|
23392
|
+
"aria-label": i18n__namespace._(`Open menu for Choice %(letter)s`, {
|
|
23393
|
+
letter: getChoiceLetter(pos)
|
|
23394
|
+
}),
|
|
23382
23395
|
style: {
|
|
23383
23396
|
alignSelf: "center",
|
|
23384
23397
|
padding: "5px",
|
|
@@ -41709,7 +41722,7 @@ const init = function (options) {
|
|
|
41709
41722
|
|
|
41710
41723
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
41711
41724
|
const libName = "@khanacademy/perseus";
|
|
41712
|
-
const libVersion = "19.1.
|
|
41725
|
+
const libVersion = "19.1.9";
|
|
41713
41726
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
41714
41727
|
|
|
41715
41728
|
const apiVersion = {
|