pxt-core 8.4.8 → 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;
@@ -154559,11 +154561,12 @@ var pxsim;
154559
154561
  return frames;
154560
154562
  }
154561
154563
  getSimUrl() {
154562
- 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`;
154563
154566
  try {
154564
154567
  return new URL(simUrl);
154565
154568
  }
154566
- catch (_a) {
154569
+ catch (_c) {
154567
154570
  // Failed to parse set url; try based off origin in case path defined as relative (e.g. /simulator.html)
154568
154571
  return new URL(simUrl, location.origin);
154569
154572
  }
@@ -154932,14 +154935,15 @@ var pxsim;
154932
154935
  }
154933
154936
  // ensure _currentRuntime is ready
154934
154937
  startFrame(frame) {
154935
- var _a, _b;
154938
+ var _a, _b, _c;
154936
154939
  if (!this._currentRuntime || !frame.contentWindow)
154937
154940
  return false;
154938
154941
  const msg = JSON.parse(JSON.stringify(this._currentRuntime));
154939
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());
154940
154944
  msg.options = {
154941
154945
  theme: this.themes[this.nextFrameId++ % this.themes.length],
154942
- 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
154943
154947
  };
154944
154948
  msg.id = `${msg.options.theme}-${this.nextId()}`;
154945
154949
  frame.dataset['runid'] = this.runId;
@@ -160818,10 +160822,20 @@ function buildReactAppAsync(app, parsed, opts) {
160818
160822
  .then(() => rimrafAsync(`${appRoot}/public/docs`, {}))
160819
160823
  .then(() => rimrafAsync(`${appRoot}/public/static`, {}))
160820
160824
  .then(() => {
160821
- // read pxtarget.json, save into 'pxtTargetBundle' global variable
160822
- let cfg = readLocalPxTarget();
160823
- nodeutil.writeFileSync(`${appRoot}/public/blb/target.js`, "// eslint-disable-next-line \n" + targetJsPrefix + JSON.stringify(cfg));
160824
- 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
+ }
160825
160839
  nodeutil.cp("built/web/semantic.css", `${appRoot}/public/blb`);
160826
160840
  nodeutil.cp("node_modules/pxt-core/built/web/icons.css", `${appRoot}/public/blb`);
160827
160841
  nodeutil.cp(`node_modules/pxt-core/built/web/react-common-${app}.css`, `${appRoot}/public/blb`);
@@ -160849,7 +160863,11 @@ function buildAuthcodeAsync(parsed) {
160849
160863
  return buildReactAppAsync("authcode", parsed, { copyAssets: false });
160850
160864
  }
160851
160865
  function buildMultiplayerAsync(parsed) {
160852
- return buildReactAppAsync("multiplayer", parsed, { copyAssets: false });
160866
+ return buildReactAppAsync("multiplayer", parsed, {
160867
+ copyAssets: false,
160868
+ usePxtEmbed: true,
160869
+ expandedPxtTarget: true
160870
+ });
160853
160871
  }
160854
160872
  function updateDefaultProjects(cfg) {
160855
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
@@ -1281,6 +1281,7 @@ declare namespace pxsim {
1281
1281
  hideSimButtons?: boolean;
1282
1282
  autofocus?: boolean;
1283
1283
  queryParameters?: string;
1284
+ mpRole?: "server" | "client";
1284
1285
  }
1285
1286
  interface HwDebugger {
1286
1287
  postMessage: (msg: pxsim.SimulatorMessage) => void;
package/built/pxtsim.js CHANGED
@@ -6215,11 +6215,12 @@ var pxsim;
6215
6215
  return frames;
6216
6216
  }
6217
6217
  getSimUrl() {
6218
- 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`;
6219
6220
  try {
6220
6221
  return new URL(simUrl);
6221
6222
  }
6222
- catch (_a) {
6223
+ catch (_c) {
6223
6224
  // Failed to parse set url; try based off origin in case path defined as relative (e.g. /simulator.html)
6224
6225
  return new URL(simUrl, location.origin);
6225
6226
  }
@@ -6588,14 +6589,15 @@ var pxsim;
6588
6589
  }
6589
6590
  // ensure _currentRuntime is ready
6590
6591
  startFrame(frame) {
6591
- var _a, _b;
6592
+ var _a, _b, _c;
6592
6593
  if (!this._currentRuntime || !frame.contentWindow)
6593
6594
  return false;
6594
6595
  const msg = JSON.parse(JSON.stringify(this._currentRuntime));
6595
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());
6596
6598
  msg.options = {
6597
6599
  theme: this.themes[this.nextFrameId++ % this.themes.length],
6598
- 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
6599
6601
  };
6600
6602
  msg.id = `${msg.options.theme}-${this.nextId()}`;
6601
6603
  frame.dataset['runid'] = this.runId;