pxt-core 8.4.7 → 8.4.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/built/cli.js CHANGED
@@ -1848,10 +1848,20 @@ function buildReactAppAsync(app, parsed, opts) {
1848
1848
  .then(() => rimrafAsync(`${appRoot}/public/docs`, {}))
1849
1849
  .then(() => rimrafAsync(`${appRoot}/public/static`, {}))
1850
1850
  .then(() => {
1851
- // read pxtarget.json, save into 'pxtTargetBundle' global variable
1852
- let cfg = readLocalPxTarget();
1853
- nodeutil.writeFileSync(`${appRoot}/public/blb/target.js`, "// eslint-disable-next-line \n" + targetJsPrefix + JSON.stringify(cfg));
1854
- nodeutil.cp("node_modules/pxt-core/built/pxtlib.js", `${appRoot}/public/blb`);
1851
+ if (!opts.expandedPxtTarget) {
1852
+ // read pxtarget.json, save into 'pxtTargetBundle' global variable
1853
+ let cfg = readLocalPxTarget();
1854
+ nodeutil.writeFileSync(`${appRoot}/public/blb/target.js`, "// eslint-disable-next-line \n" + targetJsPrefix + JSON.stringify(cfg));
1855
+ }
1856
+ else {
1857
+ nodeutil.cp("built/target.js", `${appRoot}/public/blb`);
1858
+ }
1859
+ if (opts.usePxtEmbed) {
1860
+ nodeutil.cp("node_modules/pxt-core/built/web/pxtembed.js", `${appRoot}/public/blb/web`);
1861
+ }
1862
+ else {
1863
+ nodeutil.cp("node_modules/pxt-core/built/pxtlib.js", `${appRoot}/public/blb`);
1864
+ }
1855
1865
  nodeutil.cp("built/web/semantic.css", `${appRoot}/public/blb`);
1856
1866
  nodeutil.cp("node_modules/pxt-core/built/web/icons.css", `${appRoot}/public/blb`);
1857
1867
  nodeutil.cp(`node_modules/pxt-core/built/web/react-common-${app}.css`, `${appRoot}/public/blb`);
@@ -1879,7 +1889,11 @@ function buildAuthcodeAsync(parsed) {
1879
1889
  return buildReactAppAsync("authcode", parsed, { copyAssets: false });
1880
1890
  }
1881
1891
  function buildMultiplayerAsync(parsed) {
1882
- return buildReactAppAsync("multiplayer", parsed, { copyAssets: false });
1892
+ return buildReactAppAsync("multiplayer", parsed, {
1893
+ copyAssets: false,
1894
+ usePxtEmbed: true,
1895
+ expandedPxtTarget: true
1896
+ });
1883
1897
  }
1884
1898
  function updateDefaultProjects(cfg) {
1885
1899
  let defaultProjects = [
package/built/pxt.js CHANGED
@@ -114202,12 +114202,14 @@ var ts;
114202
114202
  }
114203
114203
  pxtc.computeUsedParts = computeUsedParts;
114204
114204
  function buildSimJsInfo(compileResult) {
114205
+ var _a;
114205
114206
  return {
114206
114207
  js: compileResult.outfiles[pxtc.BINARY_JS],
114207
114208
  targetVersion: pxt.appTarget.versions.target,
114208
114209
  fnArgs: compileResult.usedArguments,
114209
114210
  parts: pxtc.computeUsedParts(compileResult, "ignorebuiltin"),
114210
114211
  usedBuiltinParts: pxtc.computeUsedParts(compileResult, "onlybuiltin"),
114212
+ breakpoints: (_a = compileResult.breakpoints) === null || _a === void 0 ? void 0 : _a.map(bp => bp.id),
114211
114213
  };
114212
114214
  }
114213
114215
  pxtc.buildSimJsInfo = buildSimJsInfo;
@@ -152867,6 +152869,27 @@ var pxsim;
152867
152869
  return output;
152868
152870
  }
152869
152871
  U.delay = delay;
152872
+ // Returns a function, that, as long as it continues to be invoked, will only
152873
+ // trigger every N milliseconds. If `immediate` is passed, trigger the
152874
+ // function on the leading edge, instead of the trailing.
152875
+ function throttle(func, wait, immediate) {
152876
+ let timeout;
152877
+ return function () {
152878
+ let context = this;
152879
+ let args = arguments;
152880
+ let later = function () {
152881
+ timeout = null;
152882
+ if (!immediate)
152883
+ func.apply(context, args);
152884
+ };
152885
+ let callNow = immediate && !timeout;
152886
+ if (!timeout)
152887
+ timeout = setTimeout(later, wait);
152888
+ if (callNow)
152889
+ func.apply(context, args);
152890
+ };
152891
+ }
152892
+ U.throttle = throttle;
152870
152893
  function promiseMapAll(values, mapper) {
152871
152894
  return Promise.all(values.map(v => mapper(v)));
152872
152895
  }
@@ -154538,11 +154561,12 @@ var pxsim;
154538
154561
  return frames;
154539
154562
  }
154540
154563
  getSimUrl() {
154541
- const simUrl = this.options.simUrl || (window.pxtConfig || {}).simUrl || `${location.origin}/sim/simulator.html`;
154564
+ var _a, _b;
154565
+ const simUrl = this.options.simUrl || ((_a = window.pxtConfig) === null || _a === void 0 ? void 0 : _a.simUrl) || ((_b = pxt.webConfig) === null || _b === void 0 ? void 0 : _b.simUrl) || `${location.origin}/sim/simulator.html`;
154542
154566
  try {
154543
154567
  return new URL(simUrl);
154544
154568
  }
154545
- catch (_a) {
154569
+ catch (_c) {
154546
154570
  // Failed to parse set url; try based off origin in case path defined as relative (e.g. /simulator.html)
154547
154571
  return new URL(simUrl, location.origin);
154548
154572
  }
@@ -154911,14 +154935,15 @@ var pxsim;
154911
154935
  }
154912
154936
  // ensure _currentRuntime is ready
154913
154937
  startFrame(frame) {
154914
- var _a, _b;
154938
+ var _a, _b, _c;
154915
154939
  if (!this._currentRuntime || !frame.contentWindow)
154916
154940
  return false;
154917
154941
  const msg = JSON.parse(JSON.stringify(this._currentRuntime));
154918
154942
  msg.frameCounter = ++this.frameCounter;
154943
+ const mpRole = ((_a = this._runOptions) === null || _a === void 0 ? void 0 : _a.mpRole) || ((_c = (_b = /[\&\?]mp=(server|client)/i.exec(window.location.href)) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.toLowerCase());
154919
154944
  msg.options = {
154920
154945
  theme: this.themes[this.nextFrameId++ % this.themes.length],
154921
- mpRole: (_b = (_a = /[\&\?]mp=(server|client)/i.exec(window.location.href)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.toLowerCase()
154946
+ mpRole
154922
154947
  };
154923
154948
  msg.id = `${msg.options.theme}-${this.nextId()}`;
154924
154949
  frame.dataset['runid'] = this.runId;
@@ -160797,10 +160822,20 @@ function buildReactAppAsync(app, parsed, opts) {
160797
160822
  .then(() => rimrafAsync(`${appRoot}/public/docs`, {}))
160798
160823
  .then(() => rimrafAsync(`${appRoot}/public/static`, {}))
160799
160824
  .then(() => {
160800
- // read pxtarget.json, save into 'pxtTargetBundle' global variable
160801
- let cfg = readLocalPxTarget();
160802
- nodeutil.writeFileSync(`${appRoot}/public/blb/target.js`, "// eslint-disable-next-line \n" + targetJsPrefix + JSON.stringify(cfg));
160803
- nodeutil.cp("node_modules/pxt-core/built/pxtlib.js", `${appRoot}/public/blb`);
160825
+ if (!opts.expandedPxtTarget) {
160826
+ // read pxtarget.json, save into 'pxtTargetBundle' global variable
160827
+ let cfg = readLocalPxTarget();
160828
+ nodeutil.writeFileSync(`${appRoot}/public/blb/target.js`, "// eslint-disable-next-line \n" + targetJsPrefix + JSON.stringify(cfg));
160829
+ }
160830
+ else {
160831
+ nodeutil.cp("built/target.js", `${appRoot}/public/blb`);
160832
+ }
160833
+ if (opts.usePxtEmbed) {
160834
+ nodeutil.cp("node_modules/pxt-core/built/web/pxtembed.js", `${appRoot}/public/blb/web`);
160835
+ }
160836
+ else {
160837
+ nodeutil.cp("node_modules/pxt-core/built/pxtlib.js", `${appRoot}/public/blb`);
160838
+ }
160804
160839
  nodeutil.cp("built/web/semantic.css", `${appRoot}/public/blb`);
160805
160840
  nodeutil.cp("node_modules/pxt-core/built/web/icons.css", `${appRoot}/public/blb`);
160806
160841
  nodeutil.cp(`node_modules/pxt-core/built/web/react-common-${app}.css`, `${appRoot}/public/blb`);
@@ -160828,7 +160863,11 @@ function buildAuthcodeAsync(parsed) {
160828
160863
  return buildReactAppAsync("authcode", parsed, { copyAssets: false });
160829
160864
  }
160830
160865
  function buildMultiplayerAsync(parsed) {
160831
- return buildReactAppAsync("multiplayer", parsed, { copyAssets: false });
160866
+ return buildReactAppAsync("multiplayer", parsed, {
160867
+ copyAssets: false,
160868
+ usePxtEmbed: true,
160869
+ expandedPxtTarget: true
160870
+ });
160832
160871
  }
160833
160872
  function updateDefaultProjects(cfg) {
160834
160873
  let defaultProjects = [
package/built/pxtlib.js CHANGED
@@ -16516,12 +16516,14 @@ var ts;
16516
16516
  }
16517
16517
  pxtc.computeUsedParts = computeUsedParts;
16518
16518
  function buildSimJsInfo(compileResult) {
16519
+ var _a;
16519
16520
  return {
16520
16521
  js: compileResult.outfiles[pxtc.BINARY_JS],
16521
16522
  targetVersion: pxt.appTarget.versions.target,
16522
16523
  fnArgs: compileResult.usedArguments,
16523
16524
  parts: pxtc.computeUsedParts(compileResult, "ignorebuiltin"),
16524
16525
  usedBuiltinParts: pxtc.computeUsedParts(compileResult, "onlybuiltin"),
16526
+ breakpoints: (_a = compileResult.breakpoints) === null || _a === void 0 ? void 0 : _a.map(bp => bp.id),
16525
16527
  };
16526
16528
  }
16527
16529
  pxtc.buildSimJsInfo = buildSimJsInfo;
@@ -100,13 +100,18 @@ declare namespace pxt.runner {
100
100
  hideSimButtons?: boolean;
101
101
  autofocus?: boolean;
102
102
  additionalQueryParameters?: string;
103
+ debug?: boolean;
104
+ mpRole?: "server" | "client";
103
105
  }
104
106
  let mainPkg: pxt.MainPackage;
107
+ function initHost(): void;
105
108
  function initFooter(footer: HTMLElement, shareId?: string): void;
106
109
  function showError(msg: string): void;
107
110
  function generateHexFileAsync(options: SimulateOptions): Promise<string>;
108
111
  function generateVMFileAsync(options: SimulateOptions): Promise<any>;
109
112
  function simulateAsync(container: HTMLElement, simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo>;
113
+ function currentDriver(): pxsim.SimulatorDriver;
114
+ function postSimMessage(msg: pxsim.SimulatorMessage): void;
110
115
  function buildSimJsInfo(simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo>;
111
116
  enum LanguageMode {
112
117
  Blocks = 0,
@@ -1609,10 +1609,12 @@ var pxt;
1609
1609
  targetBranch: versions ? versions.targetCrowdinBranch : "",
1610
1610
  force: force,
1611
1611
  })
1612
- .then(() => {
1613
- runner.mainPkg = new pxt.MainPackage(new Host());
1614
- });
1612
+ .then(() => initHost());
1613
+ }
1614
+ function initHost() {
1615
+ runner.mainPkg = new pxt.MainPackage(new Host());
1615
1616
  }
1617
+ runner.initHost = initHost;
1616
1618
  function initFooter(footer, shareId) {
1617
1619
  if (!footer)
1618
1620
  return;
@@ -1728,6 +1730,7 @@ var pxt;
1728
1730
  });
1729
1731
  }
1730
1732
  runner.generateVMFileAsync = generateVMFileAsync;
1733
+ let simDriver;
1731
1734
  async function simulateAsync(container, simOptions) {
1732
1735
  var _a, _b;
1733
1736
  const builtSimJS = simOptions.builtJsInfo || await buildSimJsInfo(simOptions);
@@ -1740,7 +1743,7 @@ var pxt;
1740
1743
  options.onSimulatorCommand = msg => {
1741
1744
  if (msg.command === "restart") {
1742
1745
  runOptions.storedState = getStoredState(simOptions.id);
1743
- driver.run(js, runOptions);
1746
+ simDriver.run(js, runOptions);
1744
1747
  }
1745
1748
  if (msg.command == "setstate") {
1746
1749
  if (msg.stateKey && msg.stateValue) {
@@ -1749,10 +1752,11 @@ var pxt;
1749
1752
  }
1750
1753
  };
1751
1754
  options.messageSimulators = (_b = (_a = pxt.appTarget) === null || _a === void 0 ? void 0 : _a.simulator) === null || _b === void 0 ? void 0 : _b.messageSimulators;
1752
- let driver = new pxsim.SimulatorDriver(container, options);
1755
+ simDriver = new pxsim.SimulatorDriver(container, options);
1753
1756
  let board = pxt.appTarget.simulator.boardDefinition;
1754
1757
  let storedState = getStoredState(simOptions.id);
1755
1758
  let runOptions = {
1759
+ debug: simOptions.debug,
1756
1760
  boardDefinition: board,
1757
1761
  parts: parts,
1758
1762
  builtinParts: usedBuiltinParts,
@@ -1766,15 +1770,27 @@ var pxt;
1766
1770
  hideSimButtons: simOptions.hideSimButtons,
1767
1771
  autofocus: simOptions.autofocus,
1768
1772
  queryParameters: simOptions.additionalQueryParameters,
1773
+ mpRole: simOptions.mpRole,
1769
1774
  };
1770
1775
  if (pxt.appTarget.simulator && !simOptions.fullScreen)
1771
1776
  runOptions.aspectRatio = parts.length && pxt.appTarget.simulator.partsAspectRatio
1772
1777
  ? pxt.appTarget.simulator.partsAspectRatio
1773
1778
  : pxt.appTarget.simulator.aspectRatio;
1774
- driver.run(js, runOptions);
1779
+ if (builtSimJS.breakpoints && simOptions.debug) {
1780
+ simDriver.setBreakpoints(builtSimJS.breakpoints);
1781
+ }
1782
+ simDriver.run(js, runOptions);
1775
1783
  return builtSimJS;
1776
1784
  }
1777
1785
  runner.simulateAsync = simulateAsync;
1786
+ function currentDriver() {
1787
+ return simDriver;
1788
+ }
1789
+ runner.currentDriver = currentDriver;
1790
+ function postSimMessage(msg) {
1791
+ simDriver === null || simDriver === void 0 ? void 0 : simDriver.postMessage(msg);
1792
+ }
1793
+ runner.postSimMessage = postSimMessage;
1778
1794
  async function buildSimJsInfo(simOptions) {
1779
1795
  var _a;
1780
1796
  await loadPackageAsync(simOptions.id, simOptions.code, simOptions.dependencies);
@@ -1782,6 +1798,8 @@ var pxt;
1782
1798
  const currentTargetVersion = pxt.appTarget.versions.target;
1783
1799
  let compileResult = await compileAsync(false, opts => {
1784
1800
  var _a;
1801
+ if (simOptions.debug)
1802
+ opts.breakpoints = true;
1785
1803
  if (simOptions.assets) {
1786
1804
  const parsedAssets = JSON.parse(simOptions.assets);
1787
1805
  for (const key of Object.keys(parsedAssets)) {
package/built/pxtsim.d.ts CHANGED
@@ -986,6 +986,7 @@ declare namespace pxsim {
986
986
  function nextTick(f: () => void): void;
987
987
  function delay<T>(duration: number, value: T): Promise<T>;
988
988
  function delay(duration: number): Promise<void>;
989
+ function throttle(func: (...args: any[]) => any, wait: number, immediate?: boolean): any;
989
990
  function promiseMapAll<T, V>(values: T[], mapper: (obj: T) => Promise<V>): Promise<V[]>;
990
991
  function promiseMapAllSeries<T, V>(values: T[], mapper: (obj: T) => Promise<V>): Promise<V[]>;
991
992
  function promisePoolAsync<T, V>(maxConcurrent: number, inputValues: T[], handler: (input: T) => Promise<V>): Promise<V[]>;
@@ -1280,6 +1281,7 @@ declare namespace pxsim {
1280
1281
  hideSimButtons?: boolean;
1281
1282
  autofocus?: boolean;
1282
1283
  queryParameters?: string;
1284
+ mpRole?: "server" | "client";
1283
1285
  }
1284
1286
  interface HwDebugger {
1285
1287
  postMessage: (msg: pxsim.SimulatorMessage) => void;
package/built/pxtsim.js CHANGED
@@ -4523,6 +4523,27 @@ var pxsim;
4523
4523
  return output;
4524
4524
  }
4525
4525
  U.delay = delay;
4526
+ // Returns a function, that, as long as it continues to be invoked, will only
4527
+ // trigger every N milliseconds. If `immediate` is passed, trigger the
4528
+ // function on the leading edge, instead of the trailing.
4529
+ function throttle(func, wait, immediate) {
4530
+ let timeout;
4531
+ return function () {
4532
+ let context = this;
4533
+ let args = arguments;
4534
+ let later = function () {
4535
+ timeout = null;
4536
+ if (!immediate)
4537
+ func.apply(context, args);
4538
+ };
4539
+ let callNow = immediate && !timeout;
4540
+ if (!timeout)
4541
+ timeout = setTimeout(later, wait);
4542
+ if (callNow)
4543
+ func.apply(context, args);
4544
+ };
4545
+ }
4546
+ U.throttle = throttle;
4526
4547
  function promiseMapAll(values, mapper) {
4527
4548
  return Promise.all(values.map(v => mapper(v)));
4528
4549
  }
@@ -6194,11 +6215,12 @@ var pxsim;
6194
6215
  return frames;
6195
6216
  }
6196
6217
  getSimUrl() {
6197
- const simUrl = this.options.simUrl || (window.pxtConfig || {}).simUrl || `${location.origin}/sim/simulator.html`;
6218
+ var _a, _b;
6219
+ const simUrl = this.options.simUrl || ((_a = window.pxtConfig) === null || _a === void 0 ? void 0 : _a.simUrl) || ((_b = pxt.webConfig) === null || _b === void 0 ? void 0 : _b.simUrl) || `${location.origin}/sim/simulator.html`;
6198
6220
  try {
6199
6221
  return new URL(simUrl);
6200
6222
  }
6201
- catch (_a) {
6223
+ catch (_c) {
6202
6224
  // Failed to parse set url; try based off origin in case path defined as relative (e.g. /simulator.html)
6203
6225
  return new URL(simUrl, location.origin);
6204
6226
  }
@@ -6567,14 +6589,15 @@ var pxsim;
6567
6589
  }
6568
6590
  // ensure _currentRuntime is ready
6569
6591
  startFrame(frame) {
6570
- var _a, _b;
6592
+ var _a, _b, _c;
6571
6593
  if (!this._currentRuntime || !frame.contentWindow)
6572
6594
  return false;
6573
6595
  const msg = JSON.parse(JSON.stringify(this._currentRuntime));
6574
6596
  msg.frameCounter = ++this.frameCounter;
6597
+ const mpRole = ((_a = this._runOptions) === null || _a === void 0 ? void 0 : _a.mpRole) || ((_c = (_b = /[\&\?]mp=(server|client)/i.exec(window.location.href)) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.toLowerCase());
6575
6598
  msg.options = {
6576
6599
  theme: this.themes[this.nextFrameId++ % this.themes.length],
6577
- mpRole: (_b = (_a = /[\&\?]mp=(server|client)/i.exec(window.location.href)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.toLowerCase()
6600
+ mpRole
6578
6601
  };
6579
6602
  msg.id = `${msg.options.theme}-${this.nextId()}`;
6580
6603
  frame.dataset['runid'] = this.runId;