pxt-core 8.6.47 → 8.6.48

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/pxt.js CHANGED
@@ -102740,15 +102740,19 @@ var pxt;
102740
102740
  }
102741
102741
  BrowserUtils.loadCanvasAsync = loadCanvasAsync;
102742
102742
  function scaleImageData(img, scale) {
102743
- const cvs = document.createElement("canvas");
102744
- cvs.width = img.width * scale;
102745
- cvs.height = img.height * scale;
102746
- const ctx = cvs.getContext("2d");
102743
+ const inputCanvas = document.createElement("canvas");
102744
+ const outputCanvas = document.createElement("canvas");
102745
+ inputCanvas.width = img.width;
102746
+ inputCanvas.height = img.height;
102747
+ outputCanvas.width = img.width * scale;
102748
+ outputCanvas.height = img.height * scale;
102749
+ const ctx = inputCanvas.getContext("2d");
102750
+ const outCtx = outputCanvas.getContext("2d");
102747
102751
  ctx.putImageData(img, 0, 0);
102748
- ctx.imageSmoothingEnabled = false;
102749
- ctx.scale(scale, scale);
102750
- ctx.drawImage(cvs, 0, 0);
102751
- return ctx.getImageData(0, 0, img.width * scale, img.height * scale);
102752
+ outCtx.imageSmoothingEnabled = false;
102753
+ outCtx.scale(scale, scale);
102754
+ outCtx.drawImage(inputCanvas, 0, 0);
102755
+ return outCtx.getImageData(0, 0, img.width * scale, img.height * scale);
102752
102756
  }
102753
102757
  BrowserUtils.scaleImageData = scaleImageData;
102754
102758
  function imageDataToPNG(img, scale = 1) {
@@ -120557,6 +120561,19 @@ var pxt;
120557
120561
  return pxt.U.delay(500);
120558
120562
  });
120559
120563
  }
120564
+ async forgetAsync() {
120565
+ var _a;
120566
+ if (!((_a = this.dev) === null || _a === void 0 ? void 0 : _a.forget))
120567
+ return false;
120568
+ try {
120569
+ await this.dev.forget();
120570
+ return true;
120571
+ // connection changed listener will handle disconnecting when access is revoked.
120572
+ }
120573
+ catch (e) {
120574
+ return false;
120575
+ }
120576
+ }
120560
120577
  reconnectAsync() {
120561
120578
  this.log("reconnect");
120562
120579
  this.setConnecting(true);
@@ -120787,6 +120804,7 @@ var pxt;
120787
120804
  return [];
120788
120805
  }
120789
120806
  }
120807
+ usb.tryGetDevicesAsync = tryGetDevicesAsync;
120790
120808
  let _hid;
120791
120809
  function mkWebUSBHIDPacketIOAsync() {
120792
120810
  pxt.debug(`packetio: mk webusb io`);
@@ -120796,6 +120814,16 @@ var pxt;
120796
120814
  return Promise.resolve(_hid);
120797
120815
  }
120798
120816
  usb.mkWebUSBHIDPacketIOAsync = mkWebUSBHIDPacketIOAsync;
120817
+ // returns true if device has been successfully forgotten, false otherwise.
120818
+ async function forgetDeviceAsync() {
120819
+ pxt.debug(`packetio: forget webusb io`);
120820
+ if (!_hid) {
120821
+ // No device to forget
120822
+ return false;
120823
+ }
120824
+ return _hid.forgetAsync();
120825
+ }
120826
+ usb.forgetDeviceAsync = forgetDeviceAsync;
120799
120827
  usb.isEnabled = false;
120800
120828
  function setEnabled(v) {
120801
120829
  if (!isAvailable())
@@ -148740,7 +148768,8 @@ var pxt;
148740
148768
  }
148741
148769
  function emitMultiLnStrLitExp(s) {
148742
148770
  if (ts.isNoSubstitutionTemplateLiteral(s)) {
148743
- return asExpRes(`"""\n${py.indent1(s.text.trim())}\n"""`);
148771
+ // manually perform indent1(), trimming existing indentation for multiline strings.
148772
+ return asExpRes(`"""\n${s.text.trim().split('\n').map(x => `${py.INDENT}${x.trim()}`).join('\n')}\n${py.INDENT}"""`);
148744
148773
  }
148745
148774
  let [tag, tagSup] = emitExp(s.tag);
148746
148775
  let [temp, tempSup] = emitExp(s.template);
@@ -158993,9 +159022,11 @@ var pxsim;
158993
159022
  return this.view;
158994
159023
  }
158995
159024
  screenshotAsync(width) {
158996
- const svg = this.view.cloneNode(true);
158997
- svg.setAttribute('width', this.view.viewBox.baseVal.width + "");
158998
- svg.setAttribute('height', this.view.viewBox.baseVal.height + "");
159025
+ // only clone the svg node with class="sim" so that screenshot doesn't include external parts
159026
+ const simEl = this.view.querySelector(".sim");
159027
+ const svg = simEl.cloneNode(true);
159028
+ svg.setAttribute('width', svg.viewBox.baseVal.width + "");
159029
+ svg.setAttribute('height', svg.viewBox.baseVal.height + "");
158999
159030
  const xml = new XMLSerializer().serializeToString(svg);
159000
159031
  const data = "data:image/svg+xml,"
159001
159032
  + encodeURIComponent(xml.replace(/\s+/g, ' ').replace(/"/g, "'"));
package/built/pxtlib.d.ts CHANGED
@@ -919,6 +919,7 @@ declare namespace pxt.commands {
919
919
  jsx: any;
920
920
  helpUrl: string;
921
921
  };
922
+ let showUsbDeviceForgottenDialog: (confirmAsync: (options: any) => Promise<number>) => Promise<void>;
922
923
  let showUploadInstructionsAsync: (fn: string, url: string, confirmAsync: (options: any) => Promise<number>, saveOnly?: boolean, redeploy?: () => Promise<void>) => Promise<void>;
923
924
  let showProgramTooLargeErrorAsync: (variants: string[], confirmAsync: (options: any) => Promise<number>, saveOnly?: boolean) => Promise<RecompileOptions>;
924
925
  let saveProjectAsync: (project: pxt.cpp.HexFile) => Promise<void>;
@@ -3403,9 +3404,12 @@ declare namespace pxt.usb {
3403
3404
  isochronousTransferIn(endpointNumber: number, packetLengths: number[]): Promise<USBIsochronousInTransferResult>;
3404
3405
  isochronousTransferOut(endpointNumber: number, data: BufferSource, packetLengths: number[]): Promise<USBIsochronousOutTransferResult>;
3405
3406
  reset(): Promise<void>;
3407
+ forget?(): Promise<void>;
3406
3408
  }
3407
3409
  function pairAsync(): Promise<boolean>;
3410
+ function tryGetDevicesAsync(): Promise<USBDevice[]>;
3408
3411
  function mkWebUSBHIDPacketIOAsync(): Promise<pxt.packetio.PacketIO>;
3412
+ function forgetDeviceAsync(): Promise<boolean>;
3409
3413
  let isEnabled: boolean;
3410
3414
  function setEnabled(v: boolean): void;
3411
3415
  function checkAvailableAsync(): Promise<void>;
package/built/pxtlib.js CHANGED
@@ -5054,15 +5054,19 @@ var pxt;
5054
5054
  }
5055
5055
  BrowserUtils.loadCanvasAsync = loadCanvasAsync;
5056
5056
  function scaleImageData(img, scale) {
5057
- const cvs = document.createElement("canvas");
5058
- cvs.width = img.width * scale;
5059
- cvs.height = img.height * scale;
5060
- const ctx = cvs.getContext("2d");
5057
+ const inputCanvas = document.createElement("canvas");
5058
+ const outputCanvas = document.createElement("canvas");
5059
+ inputCanvas.width = img.width;
5060
+ inputCanvas.height = img.height;
5061
+ outputCanvas.width = img.width * scale;
5062
+ outputCanvas.height = img.height * scale;
5063
+ const ctx = inputCanvas.getContext("2d");
5064
+ const outCtx = outputCanvas.getContext("2d");
5061
5065
  ctx.putImageData(img, 0, 0);
5062
- ctx.imageSmoothingEnabled = false;
5063
- ctx.scale(scale, scale);
5064
- ctx.drawImage(cvs, 0, 0);
5065
- return ctx.getImageData(0, 0, img.width * scale, img.height * scale);
5066
+ outCtx.imageSmoothingEnabled = false;
5067
+ outCtx.scale(scale, scale);
5068
+ outCtx.drawImage(inputCanvas, 0, 0);
5069
+ return outCtx.getImageData(0, 0, img.width * scale, img.height * scale);
5066
5070
  }
5067
5071
  BrowserUtils.scaleImageData = scaleImageData;
5068
5072
  function imageDataToPNG(img, scale = 1) {
@@ -22871,6 +22875,19 @@ var pxt;
22871
22875
  return pxt.U.delay(500);
22872
22876
  });
22873
22877
  }
22878
+ async forgetAsync() {
22879
+ var _a;
22880
+ if (!((_a = this.dev) === null || _a === void 0 ? void 0 : _a.forget))
22881
+ return false;
22882
+ try {
22883
+ await this.dev.forget();
22884
+ return true;
22885
+ // connection changed listener will handle disconnecting when access is revoked.
22886
+ }
22887
+ catch (e) {
22888
+ return false;
22889
+ }
22890
+ }
22874
22891
  reconnectAsync() {
22875
22892
  this.log("reconnect");
22876
22893
  this.setConnecting(true);
@@ -23101,6 +23118,7 @@ var pxt;
23101
23118
  return [];
23102
23119
  }
23103
23120
  }
23121
+ usb.tryGetDevicesAsync = tryGetDevicesAsync;
23104
23122
  let _hid;
23105
23123
  function mkWebUSBHIDPacketIOAsync() {
23106
23124
  pxt.debug(`packetio: mk webusb io`);
@@ -23110,6 +23128,16 @@ var pxt;
23110
23128
  return Promise.resolve(_hid);
23111
23129
  }
23112
23130
  usb.mkWebUSBHIDPacketIOAsync = mkWebUSBHIDPacketIOAsync;
23131
+ // returns true if device has been successfully forgotten, false otherwise.
23132
+ async function forgetDeviceAsync() {
23133
+ pxt.debug(`packetio: forget webusb io`);
23134
+ if (!_hid) {
23135
+ // No device to forget
23136
+ return false;
23137
+ }
23138
+ return _hid.forgetAsync();
23139
+ }
23140
+ usb.forgetDeviceAsync = forgetDeviceAsync;
23113
23141
  usb.isEnabled = false;
23114
23142
  function setEnabled(v) {
23115
23143
  if (!isAvailable())
package/built/pxtpy.js CHANGED
@@ -6209,7 +6209,8 @@ var pxt;
6209
6209
  }
6210
6210
  function emitMultiLnStrLitExp(s) {
6211
6211
  if (ts.isNoSubstitutionTemplateLiteral(s)) {
6212
- return asExpRes(`"""\n${py.indent1(s.text.trim())}\n"""`);
6212
+ // manually perform indent1(), trimming existing indentation for multiline strings.
6213
+ return asExpRes(`"""\n${s.text.trim().split('\n').map(x => `${py.INDENT}${x.trim()}`).join('\n')}\n${py.INDENT}"""`);
6213
6214
  }
6214
6215
  let [tag, tagSup] = emitExp(s.tag);
6215
6216
  let [temp, tempSup] = emitExp(s.template);
package/built/pxtsim.js CHANGED
@@ -9782,9 +9782,11 @@ var pxsim;
9782
9782
  return this.view;
9783
9783
  }
9784
9784
  screenshotAsync(width) {
9785
- const svg = this.view.cloneNode(true);
9786
- svg.setAttribute('width', this.view.viewBox.baseVal.width + "");
9787
- svg.setAttribute('height', this.view.viewBox.baseVal.height + "");
9785
+ // only clone the svg node with class="sim" so that screenshot doesn't include external parts
9786
+ const simEl = this.view.querySelector(".sim");
9787
+ const svg = simEl.cloneNode(true);
9788
+ svg.setAttribute('width', svg.viewBox.baseVal.width + "");
9789
+ svg.setAttribute('height', svg.viewBox.baseVal.height + "");
9788
9790
  const xml = new XMLSerializer().serializeToString(svg);
9789
9791
  const data = "data:image/svg+xml,"
9790
9792
  + encodeURIComponent(xml.replace(/\s+/g, ' ').replace(/"/g, "'"));