pxt-microbit 8.1.11 → 8.1.13

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/built/sim.js CHANGED
@@ -4069,13 +4069,14 @@ var pxsim;
4069
4069
  .sim-button-nut:hover {
4070
4070
  stroke:1px solid #704A4A;
4071
4071
  }
4072
- .sim-pin:hover {
4072
+ .sim-pin[focusable=true]:hover {
4073
4073
  stroke:#D4AF37;
4074
4074
  stroke-width:2px;
4075
4075
  }
4076
4076
 
4077
- .sim-pin-touch.touched {
4077
+ .sim-pin-touch[focusable=true].touched {
4078
4078
  stroke:darkorange !important;
4079
+ stroke-width:5px;
4079
4080
  }
4080
4081
 
4081
4082
  .sim-led-back:hover {
@@ -4170,6 +4171,7 @@ var pxsim;
4170
4171
  }
4171
4172
  .sim-label, .sim-button-label {
4172
4173
  fill: #000;
4174
+ pointer-events: none;
4173
4175
  }
4174
4176
  .sim-wireframe .sim-board {
4175
4177
  stroke-width: 2px;
@@ -4177,25 +4179,25 @@ var pxsim;
4177
4179
  *:focus {
4178
4180
  outline: none;
4179
4181
  }
4180
- *:focus .sim-button-outer,
4181
- .sim-shake:focus,
4182
- .sim-thermometer:focus {
4182
+ *:focus-visible .sim-button-outer,
4183
+ .sim-shake:focus-visible,
4184
+ .sim-thermometer:focus-visible {
4183
4185
  outline: 5px solid white;
4184
4186
  stroke: black;
4185
4187
  stroke-width: 10px;
4186
4188
  paint-order: stroke;
4187
4189
  }
4188
- .sim-button-outer.sim-button-group:focus > .sim-button {
4190
+ .sim-button-outer.sim-button-group:focus-visible > .sim-button {
4189
4191
  outline: 5px solid white;
4190
4192
  stroke: black;
4191
4193
  stroke-width: 5px;
4192
4194
  paint-order: stroke;
4193
4195
  }
4194
- .sim-light-level-button:focus,
4195
- .sim-antenna-outer:focus > .sim-antenna {
4196
+ .sim-light-level-button:focus-visible,
4197
+ .sim-antenna-outer:focus-visible > .sim-antenna {
4196
4198
  outline: 5px solid white;
4197
4199
  }
4198
- .sim-pin:focus {
4200
+ .sim-pin:focus-visible {
4199
4201
  stroke: white;
4200
4202
  stroke-width: 5px !important;
4201
4203
  }
@@ -4208,6 +4210,9 @@ var pxsim;
4208
4210
  -webkit-user-select: none;
4209
4211
  -ms-user-select: none;
4210
4212
  }
4213
+ [focusable=true] {
4214
+ cursor: pointer;
4215
+ }
4211
4216
  `;
4212
4217
  const MB_HIGHCONTRAST = `
4213
4218
  path.sim-board {
@@ -4220,11 +4225,11 @@ path.sim-board {
4220
4225
  .sim-led-back {
4221
4226
  stroke: white;
4222
4227
  }
4223
- *:focus .sim-button-outer,
4224
- .sim-pin:focus,
4225
- .sim-thermometer:focus,
4226
- .sim-shake:focus,
4227
- .sim-light-level-button:focus {
4228
+ *:focus-visible .sim-button-outer,
4229
+ .sim-pin:focus-visible,
4230
+ .sim-thermometer:focus-visible,
4231
+ .sim-shake:focus-visible,
4232
+ .sim-light-level-button:focus-visible {
4228
4233
  stroke: #10C8CD !important;
4229
4234
  }
4230
4235
  `;
@@ -4315,6 +4320,7 @@ path.sim-board {
4315
4320
  class MicrobitBoardSvg {
4316
4321
  constructor(props) {
4317
4322
  this.props = props;
4323
+ this.liveRegionInitialized = false;
4318
4324
  this.headInitialized = false;
4319
4325
  this.antennaInitialized = false;
4320
4326
  this.lightLevelInitialized = false;
@@ -4350,7 +4356,7 @@ path.sim-board {
4350
4356
  if (props && props.runtime) {
4351
4357
  this.board = this.props.runtime.board;
4352
4358
  this.board.updateSubscribers.push(() => this.updateState());
4353
- this.updateState();
4359
+ this.updateState(true);
4354
4360
  this.attachEvents();
4355
4361
  }
4356
4362
  }
@@ -4409,7 +4415,7 @@ path.sim-board {
4409
4415
  pxsim.svg.setGradientColors(this.soundLevelGradient, theme.ledOff, theme.ledOn);
4410
4416
  this.positionV2Elements();
4411
4417
  }
4412
- updateState() {
4418
+ updateState(initialCall = false) {
4413
4419
  const state = this.board;
4414
4420
  if (!state)
4415
4421
  return;
@@ -4430,6 +4436,12 @@ path.sim-board {
4430
4436
  pxsim.U.addClass(this.element, "grayscale");
4431
4437
  else
4432
4438
  pxsim.U.removeClass(this.element, "grayscale");
4439
+ if (!initialCall && !this.liveRegionInitialized) {
4440
+ // The iframe document's innerHTML is cleared after mkBoardView is called.
4441
+ // Ensure that the live region is created after this.
4442
+ pxsim.accessibility.setLiveContent("");
4443
+ this.liveRegionInitialized = true;
4444
+ }
4433
4445
  }
4434
4446
  updateButtonPairs() {
4435
4447
  const state = this.board;
@@ -4494,7 +4506,7 @@ path.sim-board {
4494
4506
  this.board.accelerometerState.shake();
4495
4507
  });
4496
4508
  pxsim.accessibility.setAria(this.shakeButton, "button", "Shake the board");
4497
- this.shakeText = pxsim.svg.child(this.g, "text", { x: 420, y: 122, class: "sim-text-small" });
4509
+ this.shakeText = pxsim.svg.child(this.g, "text", { x: 420, y: 122, class: "sim-text-small", "aria-hidden": true });
4498
4510
  this.shakeText.textContent = "SHAKE";
4499
4511
  }
4500
4512
  }
@@ -4566,7 +4578,6 @@ path.sim-board {
4566
4578
  this.pins[index].setAttribute("aria-valuemax", pin.mode & pxsim.PinFlags.Analog ? "1023" : "100");
4567
4579
  this.pins[index].setAttribute("aria-orientation", "vertical");
4568
4580
  this.pins[index].setAttribute("aria-valuenow", text ? text.textContent : v);
4569
- pxsim.accessibility.setLiveContent(text ? text.textContent : v);
4570
4581
  }
4571
4582
  }
4572
4583
  updateTemperature() {
@@ -4578,7 +4589,7 @@ path.sim-board {
4578
4589
  if (!this.thermometerInitialized) {
4579
4590
  this.thermometerInitialized = true;
4580
4591
  this.thermometer.style.visibility = "visible";
4581
- this.thermometerText = pxsim.svg.child(this.g, "text", { class: 'sim-text', x: 58, y: 130 });
4592
+ this.thermometerText = pxsim.svg.child(this.g, "text", { class: 'sim-text', x: 58, y: 130, "aria-hidden": true });
4582
4593
  if (this.props.runtime)
4583
4594
  this.props.runtime.environmentGlobals[pxsim.localization.lf("temperature")] = state.thermometerState.temperature;
4584
4595
  this.updateTheme();
@@ -4597,21 +4608,9 @@ path.sim-board {
4597
4608
  ev => { },
4598
4609
  // keydown
4599
4610
  (ev) => {
4600
- let charCode = (typeof ev.which == "number") ? ev.which : ev.keyCode;
4601
- if (charCode === 40 || charCode === 37) { // Down/Left arrow
4602
- ev.preventDefault();
4603
- state.thermometerState.temperature--;
4604
- if (state.thermometerState.temperature < -5) {
4605
- state.thermometerState.temperature = 50;
4606
- }
4607
- this.updateTemperature();
4608
- }
4609
- else if (charCode === 38 || charCode === 39) { // Up/Right arrow
4610
- ev.preventDefault();
4611
- state.thermometerState.temperature++;
4612
- if (state.thermometerState.temperature > 50) {
4613
- state.thermometerState.temperature = -5;
4614
- }
4611
+ const value = commonKeyHandler(ev, state.thermometerState.temperature, tmin, tmax);
4612
+ if (value !== undefined) {
4613
+ state.thermometerState.temperature = value;
4615
4614
  this.updateTemperature();
4616
4615
  }
4617
4616
  });
@@ -4629,7 +4628,6 @@ path.sim-board {
4629
4628
  this.thermometerText.textContent = t + "°C";
4630
4629
  this.thermometer.setAttribute("aria-valuenow", t.toString());
4631
4630
  this.thermometer.setAttribute("aria-valuetext", t + "°C");
4632
- pxsim.accessibility.setLiveContent(t + "°C");
4633
4631
  }
4634
4632
  updateSoundLevel() {
4635
4633
  let state = this.board;
@@ -4641,7 +4639,7 @@ path.sim-board {
4641
4639
  this.soundLevelInitialized = true;
4642
4640
  this.soundLevel.style.visibility = "visible";
4643
4641
  const level = state.microphoneState.getLevel();
4644
- this.soundLevelText = pxsim.svg.child(this.g, "text", { class: 'sim-text', x: 370, y: 90 });
4642
+ this.soundLevelText = pxsim.svg.child(this.g, "text", { class: 'sim-text', x: 370, y: 90, "aria-hidden": true });
4645
4643
  if (this.props.runtime)
4646
4644
  this.props.runtime.environmentGlobals[pxsim.localization.lf("sound level")] = state.microphoneState.getLevel();
4647
4645
  this.updateTheme();
@@ -4660,15 +4658,9 @@ path.sim-board {
4660
4658
  ev => { },
4661
4659
  // keydown
4662
4660
  (ev) => {
4663
- let charCode = (typeof ev.which == "number") ? ev.which : ev.keyCode;
4664
- if (charCode === 40 || charCode === 37) { // Down/Left arrow
4665
- ev.preventDefault();
4666
- state.microphoneState.setLevel(state.microphoneState.getLevel() - 1);
4667
- this.updateMicrophone();
4668
- }
4669
- else if (charCode === 38 || charCode === 39) { // Up/Right arrow
4670
- ev.preventDefault();
4671
- state.microphoneState.setLevel(state.microphoneState.getLevel() + 1);
4661
+ const value = commonKeyHandler(ev, state.microphoneState.getLevel(), tmin, tmax);
4662
+ if (value !== undefined) {
4663
+ state.microphoneState.setLevel(value);
4672
4664
  this.updateMicrophone();
4673
4665
  }
4674
4666
  });
@@ -4686,7 +4678,6 @@ path.sim-board {
4686
4678
  this.soundLevelText.textContent = t + "";
4687
4679
  this.soundLevel.setAttribute("aria-valuenow", t.toString());
4688
4680
  this.soundLevel.setAttribute("aria-valuetext", t + "");
4689
- pxsim.accessibility.setLiveContent(t + "");
4690
4681
  }
4691
4682
  updateHeading() {
4692
4683
  let xc = 258;
@@ -4714,23 +4705,9 @@ path.sim-board {
4714
4705
  ev => { },
4715
4706
  // keydown
4716
4707
  (ev) => {
4717
- let charCode = (typeof ev.which == "number") ? ev.which : ev.keyCode;
4718
- if (charCode === 40 || charCode === 37) { // Down/Left arrow
4719
- ev.preventDefault();
4720
- state.compassState.heading--;
4721
- if (state.compassState.heading < 0)
4722
- state.compassState.heading += 360;
4723
- if (state.compassState.heading >= 360)
4724
- state.compassState.heading %= 360;
4725
- this.updateHeading();
4726
- }
4727
- else if (charCode === 38 || charCode === 39) { // Up/Right arrow
4728
- ev.preventDefault();
4729
- state.compassState.heading++;
4730
- if (state.compassState.heading < 0)
4731
- state.compassState.heading += 360;
4732
- if (state.compassState.heading >= 360)
4733
- state.compassState.heading %= 360;
4708
+ const value = commonKeyHandler(ev, state.compassState.heading, 0, 359);
4709
+ if (value !== undefined) {
4710
+ state.compassState.heading = value;
4734
4711
  this.updateHeading();
4735
4712
  }
4736
4713
  });
@@ -4778,15 +4755,9 @@ path.sim-board {
4778
4755
  };
4779
4756
  const keyboardEventHandler = (ev) => {
4780
4757
  var _a;
4781
- const charCode = (typeof ev.which == "number") ? ev.which : ev.keyCode;
4782
- const rs = (_a = this.board.radioState.datagram.rssi) !== null && _a !== void 0 ? _a : -75;
4783
- if (charCode === 40 || charCode === 37) { // Down/Left arrow
4784
- ev.preventDefault();
4785
- setValue(rs - 1);
4786
- }
4787
- else if (charCode === 38 || charCode === 39) { // Up/Right arrow
4788
- ev.preventDefault();
4789
- setValue(rs + 1);
4758
+ const value = commonKeyHandler(ev, (_a = this.board.radioState.datagram.rssi) !== null && _a !== void 0 ? _a : -75, valueMin, valueMax);
4759
+ if (value !== undefined) {
4760
+ setValue(value);
4790
4761
  }
4791
4762
  };
4792
4763
  pxsim.svg.buttonEvents(this.antenna.children[0], mouseEventHandler, mouseEventHandler, mouseEventHandler, () => { });
@@ -4798,7 +4769,6 @@ path.sim-board {
4798
4769
  this.antenna.setAttribute("aria-valuemax", `${valueMax}`);
4799
4770
  this.antenna.setAttribute("aria-orientation", "horizontal");
4800
4771
  this.antenna.setAttribute("aria-valuenow", "");
4801
- pxsim.accessibility.setLiveContent("");
4802
4772
  }
4803
4773
  let now = Date.now();
4804
4774
  if (now - this.lastAntennaFlash > 200) {
@@ -4819,14 +4789,13 @@ path.sim-board {
4819
4789
  let ayb = 40;
4820
4790
  for (let i = 0; i < 4; ++i)
4821
4791
  pxsim.svg.child(this.g, "rect", { x: ANTENNA_X - 90 + i * 6, y: ayt + 28 - i * 4, width: 4, height: 2 + i * 4, fill: "#fff" });
4822
- this.rssi = pxsim.svg.child(this.g, "text", { x: ANTENNA_X - 64, y: ayb, class: "sim-text" });
4792
+ this.rssi = pxsim.svg.child(this.g, "text", { x: ANTENNA_X - 64, y: ayb, class: "sim-text", "aria-hidden": true });
4823
4793
  this.rssi.textContent = "";
4824
4794
  }
4825
4795
  const vt = v.toString();
4826
4796
  if (vt !== this.rssi.textContent) {
4827
4797
  this.rssi.textContent = v.toString();
4828
4798
  this.antenna.setAttribute("aria-valuenow", this.rssi.textContent);
4829
- pxsim.accessibility.setLiveContent(this.rssi.textContent);
4830
4799
  }
4831
4800
  }
4832
4801
  updatePins() {
@@ -4860,25 +4829,13 @@ path.sim-board {
4860
4829
  ev => { },
4861
4830
  // keydown
4862
4831
  (ev) => {
4863
- let charCode = (typeof ev.which == "number") ? ev.which : ev.keyCode;
4864
- if (charCode === 40 || charCode === 37) { // Down/Left arrow
4865
- ev.preventDefault();
4866
- this.board.lightSensorState.lightLevel--;
4867
- if (this.board.lightSensorState.lightLevel < 0) {
4868
- this.board.lightSensorState.lightLevel = 255;
4869
- }
4870
- this.applyLightLevel();
4871
- }
4872
- else if (charCode === 38 || charCode === 39) { // Up/Right arrow
4873
- ev.preventDefault();
4874
- this.board.lightSensorState.lightLevel++;
4875
- if (this.board.lightSensorState.lightLevel > 255) {
4876
- this.board.lightSensorState.lightLevel = 0;
4877
- }
4878
- this.applyLightLevel();
4832
+ const value = commonKeyHandler(ev, state.lightSensorState.lightLevel, 0, 255);
4833
+ if (value !== undefined) {
4834
+ state.lightSensorState.lightLevel = value;
4835
+ this.updateLightLevel();
4879
4836
  }
4880
4837
  });
4881
- this.lightLevelText = pxsim.svg.child(this.g, "text", { x: 85, y: LIGHT_LEVEL_BUTTON_POSITION_Y + LIGHT_LEVEL_BUTTON_RADIUS - 5, text: '', class: 'sim-text' });
4838
+ this.lightLevelText = pxsim.svg.child(this.g, "text", { x: 85, y: LIGHT_LEVEL_BUTTON_POSITION_Y + LIGHT_LEVEL_BUTTON_RADIUS - 5, text: '', class: 'sim-text', 'aria-hidden': true });
4882
4839
  if (this.props.runtime)
4883
4840
  this.props.runtime.environmentGlobals[pxsim.localization.lf("lightLevel")] = state.lightSensorState.lightLevel;
4884
4841
  this.updateTheme();
@@ -4897,7 +4854,6 @@ path.sim-board {
4897
4854
  pxsim.svg.setGradientValue(this.lightLevelGradient, Math.min(100, Math.max(0, Math.floor(lv * 100 / 255))) + '%');
4898
4855
  this.lightLevelText.textContent = lv.toString();
4899
4856
  this.lightLevelButton.setAttribute("aria-valuenow", lv.toString());
4900
- pxsim.accessibility.setLiveContent(lv.toString());
4901
4857
  }
4902
4858
  findParentElement() {
4903
4859
  let el = this.element;
@@ -4936,21 +4892,21 @@ path.sim-board {
4936
4892
  // update text
4937
4893
  if (acc.flags & pxsim.AccelerometerFlag.X) {
4938
4894
  if (!this.accTextX) {
4939
- this.accTextX = pxsim.svg.child(this.g, "text", { x: 365, y: 260, class: "sim-text" });
4895
+ this.accTextX = pxsim.svg.child(this.g, "text", { x: 365, y: 260, class: "sim-text", "aria-hidden": true });
4940
4896
  this.accTextX.textContent = "";
4941
4897
  }
4942
4898
  this.accTextX.textContent = `ax:${x}`;
4943
4899
  }
4944
4900
  if (acc.flags & pxsim.AccelerometerFlag.Y) {
4945
4901
  if (!this.accTextY) {
4946
- this.accTextY = pxsim.svg.child(this.g, "text", { x: 365, y: 285, class: "sim-text" });
4902
+ this.accTextY = pxsim.svg.child(this.g, "text", { x: 365, y: 285, class: "sim-text", "aria-hidden": true });
4947
4903
  this.accTextY.textContent = "";
4948
4904
  }
4949
4905
  this.accTextY.textContent = `ay:${-y}`;
4950
4906
  }
4951
4907
  if (acc.flags & pxsim.AccelerometerFlag.Z) {
4952
4908
  if (!this.accTextZ) {
4953
- this.accTextZ = pxsim.svg.child(this.g, "text", { x: 365, y: 310, class: "sim-text" });
4909
+ this.accTextZ = pxsim.svg.child(this.g, "text", { x: 365, y: 310, class: "sim-text", "aria-hidden": true });
4954
4910
  this.accTextZ.textContent = "";
4955
4911
  }
4956
4912
  this.accTextZ.textContent = `az:${z}`;
@@ -4968,7 +4924,9 @@ path.sim-board {
4968
4924
  "y": "0px",
4969
4925
  "width": MB_WIDTH + "px",
4970
4926
  "height": MB_HEIGHT + "px",
4971
- "fill": "rgba(0,0,0,0)"
4927
+ "fill": "rgba(0,0,0,0)",
4928
+ // Allows screen reader users to interact with board properly.
4929
+ "role": "application"
4972
4930
  });
4973
4931
  this.style = pxsim.svg.child(this.element, "style", {});
4974
4932
  this.style.textContent = MB_STYLE + (this.props.theme.highContrast ? MB_HIGHCONTRAST : "");
@@ -5095,7 +5053,7 @@ path.sim-board {
5095
5053
  this.heads.push(pxsim.svg.path(this.headParts, "sim-theme", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2"));
5096
5054
  this.heads.push(pxsim.svg.path(this.headParts, "sim-theme", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7"));
5097
5055
  this.heads.push(pxsim.svg.path(this.headParts, "sim-theme", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3"));
5098
- this.headText = pxsim.svg.child(this.g, "text", { x: 160, y: 60, class: "sim-text" });
5056
+ this.headText = pxsim.svg.child(this.g, "text", { x: 160, y: 60, class: "sim-text", "aria-hidden": true });
5099
5057
  }
5100
5058
  buildPinElements() {
5101
5059
  // https://www.microbit.co.uk/device/pins
@@ -5129,7 +5087,7 @@ path.sim-board {
5129
5087
  pin.setAttribute("fill", `url(#${gid})`);
5130
5088
  return lg;
5131
5089
  });
5132
- this.pinTexts = [67, 165, 275].map(x => pxsim.svg.child(this.g, "text", { class: "sim-text-pin", x: x, y: 345 }));
5090
+ this.pinTexts = [67, 165, 275].map(x => pxsim.svg.child(this.g, "text", { class: "sim-text-pin", x: x, y: 345, "aria-hidden": true }));
5133
5091
  pxsim.svg.path(this.g, "sim-label", "M35.7,376.4c0-2.8,2.1-5.1,5.5-5.1c3.3,0,5.5,2.4,5.5,5.1v4.7c0,2.8-2.2,5.1-5.5,5.1c-3.3,0-5.5-2.4-5.5-5.1V376.4zM43.3,376.4c0-1.3-0.8-2.3-2.2-2.3c-1.3,0-2.1,1.1-2.1,2.3v4.7c0,1.2,0.8,2.3,2.1,2.3c1.3,0,2.2-1.1,2.2-2.3V376.4z");
5134
5092
  pxsim.svg.path(this.g, "sim-label", "M136.2,374.1c2.8,0,3.4-0.8,3.4-2.5h2.9v14.3h-3.4v-9.5h-3V374.1z");
5135
5093
  pxsim.svg.path(this.g, "sim-label", "M248.6,378.5c1.7-1,3-1.7,3-3.1c0-1.1-0.7-1.6-1.6-1.6c-1,0-1.8,0.6-1.8,2.1h-3.3c0-2.6,1.8-4.6,5.1-4.6c2.6,0,4.9,1.3,4.9,4.3c0,2.4-2.3,3.9-3.8,4.7c-2,1.3-2.5,1.8-2.5,2.9h6.1v2.7h-10C244.8,381.2,246.4,379.9,248.6,378.5z");
@@ -5199,7 +5157,7 @@ path.sim-board {
5199
5157
  const title = pxsim.localization.lf("micro:bit v2 needed");
5200
5158
  this.v2Circle = pxsim.svg.child(this.g, "circle", { r: 21, title: title });
5201
5159
  pxsim.svg.fill(this.v2Circle, "white");
5202
- this.v2Text = pxsim.svg.child(this.g, "text", { class: "sim-text", title: title });
5160
+ this.v2Text = pxsim.svg.child(this.g, "text", { class: "sim-text", title: title, "aria-hidden": true });
5203
5161
  this.v2Text.textContent = "V2";
5204
5162
  pxsim.svg.fill(this.v2Text, "black");
5205
5163
  this.v2Text.style.fontWeight = "700";
@@ -5523,6 +5481,47 @@ path.sim-board {
5523
5481
  }
5524
5482
  }
5525
5483
  visuals.MicrobitBoardSvg = MicrobitBoardSvg;
5484
+ const isHandledKey = (key) => {
5485
+ return ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "PageUp", "PageDown", "Home", "End"].includes(key);
5486
+ };
5487
+ const getSliderStepValue = (min, max) => {
5488
+ const range = max - min;
5489
+ // Assumes slider values are always integers.
5490
+ return Math.max(1, Math.floor(range / 10));
5491
+ };
5492
+ const commonKeyHandler = (e, currentValue, min, max) => {
5493
+ const key = e.key;
5494
+ if (isHandledKey(key)) {
5495
+ e.preventDefault();
5496
+ }
5497
+ switch (key) {
5498
+ case "ArrowDown":
5499
+ case "ArrowLeft": {
5500
+ return Math.max(min, currentValue - 1);
5501
+ }
5502
+ case "ArrowUp":
5503
+ case "ArrowRight": {
5504
+ return Math.min(max, currentValue + 1);
5505
+ }
5506
+ case "Home": {
5507
+ return min;
5508
+ }
5509
+ case "End": {
5510
+ return max;
5511
+ }
5512
+ case "PageDown": {
5513
+ const step = getSliderStepValue(min, max);
5514
+ const value = currentValue - step;
5515
+ return Math.max(min, value);
5516
+ }
5517
+ case "PageUp": {
5518
+ const step = getSliderStepValue(min, max);
5519
+ const value = currentValue + step;
5520
+ return Math.min(max, value);
5521
+ }
5522
+ }
5523
+ return undefined;
5524
+ };
5526
5525
  })(visuals = pxsim.visuals || (pxsim.visuals = {}));
5527
5526
  })(pxsim || (pxsim = {}));
5528
5527
  var pxsim;