pxt-core 7.5.21 → 7.5.24

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
@@ -102338,6 +102338,9 @@ var pxt;
102338
102338
  }
102339
102339
  BrowserUtils.noSharedLocalStorage = noSharedLocalStorage;
102340
102340
  function useOldTutorialLayout() {
102341
+ var _a, _b;
102342
+ if ((_b = (_a = pxt.appTarget) === null || _a === void 0 ? void 0 : _a.appTheme) === null || _b === void 0 ? void 0 : _b.legacyTutorial)
102343
+ return true;
102341
102344
  try {
102342
102345
  return (/tutorialview=old/.test(window.location.href));
102343
102346
  }
@@ -114470,11 +114473,10 @@ var pxt;
114470
114473
  (function (pxt) {
114471
114474
  var assets;
114472
114475
  (function (assets) {
114476
+ assets.MAX_FREQUENCY = 5000;
114477
+ assets.MAX_VOLUME = 255;
114473
114478
  function renderSoundPath(sound, width, height) {
114474
114479
  const { startFrequency, endFrequency, startVolume, endVolume, wave, interpolation } = sound;
114475
- const scale = (start, end, percent) => {
114476
- return Math.pow(start, 1 - percent) * Math.pow(end, percent);
114477
- };
114478
114480
  // To make the graph appear consistent with the implementation, use a seeded random for the noise waveform.
114479
114481
  // The numbers are still nonsense but at least this reflects that it's deterministic.
114480
114482
  const random = new SeededRandom(startFrequency + endFrequency + 1);
@@ -114491,11 +114493,13 @@ var pxt;
114491
114493
  break;
114492
114494
  }
114493
114495
  if (wave === "noise") {
114494
- getFrequencyAt = () => random.randomRange(500, 1000);
114496
+ getFrequencyAt = () => random.randomRange(500, 5000);
114495
114497
  }
114496
- const getVolumeAt = (x) => ((endVolume - startVolume) / width) * x + startVolume;
114497
- const volumeToAmplitude = (volume) => (volume / 1023) * (height - 2) / 2;
114498
- const frequencyToWidth = (frequency) => Math.min(width, Math.max(10, (1 / scale(1, 4000, frequency / 4000)) * width / 2));
114498
+ const getVolumeAt = (x) => Math.max(Math.min(((endVolume - startVolume) / width) * x + startVolume, assets.MAX_VOLUME), 0);
114499
+ const minWaveWidth = 10;
114500
+ const maxWaveWidth = width / 2;
114501
+ const volumeToAmplitude = (volume) => (volume / assets.MAX_VOLUME) * (height - 2) / 2;
114502
+ const frequencyToWidth = (frequency) => (1 - frequency / assets.MAX_FREQUENCY) * (maxWaveWidth - minWaveWidth) + minWaveWidth;
114499
114503
  const parts = [`M ${2} ${height / 2}`];
114500
114504
  let currentX = 0;
114501
114505
  while (currentX < width) {
@@ -114512,8 +114516,8 @@ var pxt;
114512
114516
  // The numbers are still nonsense but at least this reflects that it's deterministic.
114513
114517
  const random = new SeededRandom(frequency);
114514
114518
  if (wave === "noise")
114515
- frequency = random.randomRange(500, 1000);
114516
- const amplitude = (volume / 1023) * (height - 2) / 2;
114519
+ frequency = random.randomRange(500, 5000);
114520
+ const amplitude = (volume / assets.MAX_VOLUME) * (height - 2) / 2;
114517
114521
  const waveHalfWidth = (width / (frequency * timeBase / 1000)) / 2;
114518
114522
  let numSegments = Math.ceil(width / (waveHalfWidth * 2));
114519
114523
  if (numSegments % 2 === 1)
@@ -152886,62 +152890,64 @@ var pxsim;
152886
152890
  const single = !!((_a = this._currentRuntime) === null || _a === void 0 ? void 0 : _a.single);
152887
152891
  const parentWindow = window.parent && window.parent !== window.window
152888
152892
  ? window.parent : window.opener;
152889
- if (this.options.nestedEditorSim && parentWindow) {
152893
+ if (parentWindow) {
152890
152894
  // if message comes from parent already, don't echo
152891
152895
  if (source !== parentWindow) {
152892
152896
  const parentOrigin = this.options.parentOrigin || window.location.origin;
152893
152897
  parentWindow.postMessage(msg, parentOrigin);
152894
152898
  }
152895
- // send message to other editors
152896
152899
  }
152897
- else if (depEditors) {
152898
- depEditors.forEach(w => {
152899
- if (source !== w)
152900
- // dependant editors should be in the same origin
152901
- w.postMessage(msg, window.location.origin);
152902
- });
152903
- // start second simulator
152904
- }
152905
- else if (!single) {
152906
- const messageChannel = msg.type === "messagepacket" && msg.channel;
152907
- const messageSimulator = messageChannel &&
152908
- this.options.messageSimulators &&
152909
- this.options.messageSimulators[messageChannel];
152910
- // should we start an extension editor?
152911
- if (messageSimulator) {
152912
- // find a frame already running that simulator
152913
- let messageFrame = frames.find(frame => frame.dataset[FRAME_DATA_MESSAGE_CHANNEL] === messageChannel);
152914
- // not found, spin a new one
152915
- if (!messageFrame) {
152916
- const useLocalHost = pxsim.U.isLocalHost() && /localhostmessagesims=1/i.test(window.location.href);
152917
- const url = ((useLocalHost && messageSimulator.localHostUrl) || messageSimulator.url)
152918
- .replace("$PARENT_ORIGIN$", encodeURIComponent(this.options.parentOrigin || ""));
152919
- let wrapper = this.createFrame(url);
152920
- this.container.appendChild(wrapper);
152921
- messageFrame = wrapper.firstElementChild;
152922
- messageFrame.dataset[FRAME_DATA_MESSAGE_CHANNEL] = messageChannel;
152923
- pxsim.U.addClass(wrapper, "simmsg");
152924
- pxsim.U.addClass(wrapper, "simmsg" + messageChannel);
152925
- if (messageSimulator.permanent)
152926
- messageFrame.dataset[PERMANENT] = "true";
152927
- this.startFrame(messageFrame);
152928
- frames = this.simFrames(); // refresh
152929
- }
152930
- // not running the curren run, restart
152931
- else if (messageFrame.dataset['runid'] != this.runId) {
152932
- this.startFrame(messageFrame);
152933
- }
152934
- }
152935
- else {
152936
- // start secondary frame if needed
152937
- const mkcdFrames = frames.filter(frame => !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL]);
152938
- if (mkcdFrames.length < 2) {
152939
- this.container.appendChild(this.createFrame());
152940
- frames = this.simFrames();
152941
- // there might be an old frame
152900
+ if (!this.options.nestedEditorSim && !(broadcastmsg === null || broadcastmsg === void 0 ? void 0 : broadcastmsg.toParentIFrameOnly)) {
152901
+ // send message to other editors
152902
+ if (depEditors) {
152903
+ depEditors.forEach(w => {
152904
+ if (source !== w)
152905
+ // dependant editors should be in the same origin
152906
+ w.postMessage(msg, window.location.origin);
152907
+ });
152908
+ // start second simulator
152909
+ }
152910
+ else if (!single) {
152911
+ const messageChannel = msg.type === "messagepacket" && msg.channel;
152912
+ const messageSimulator = messageChannel &&
152913
+ this.options.messageSimulators &&
152914
+ this.options.messageSimulators[messageChannel];
152915
+ // should we start an extension editor?
152916
+ if (messageSimulator) {
152917
+ // find a frame already running that simulator
152918
+ let messageFrame = frames.find(frame => frame.dataset[FRAME_DATA_MESSAGE_CHANNEL] === messageChannel);
152919
+ // not found, spin a new one
152920
+ if (!messageFrame) {
152921
+ const useLocalHost = pxsim.U.isLocalHost() && /localhostmessagesims=1/i.test(window.location.href);
152922
+ const url = ((useLocalHost && messageSimulator.localHostUrl) || messageSimulator.url)
152923
+ .replace("$PARENT_ORIGIN$", encodeURIComponent(this.options.parentOrigin || ""));
152924
+ let wrapper = this.createFrame(url);
152925
+ this.container.appendChild(wrapper);
152926
+ messageFrame = wrapper.firstElementChild;
152927
+ messageFrame.dataset[FRAME_DATA_MESSAGE_CHANNEL] = messageChannel;
152928
+ pxsim.U.addClass(wrapper, "simmsg");
152929
+ pxsim.U.addClass(wrapper, "simmsg" + messageChannel);
152930
+ if (messageSimulator.permanent)
152931
+ messageFrame.dataset[PERMANENT] = "true";
152932
+ this.startFrame(messageFrame);
152933
+ frames = this.simFrames(); // refresh
152934
+ }
152935
+ // not running the curren run, restart
152936
+ else if (messageFrame.dataset['runid'] != this.runId) {
152937
+ this.startFrame(messageFrame);
152938
+ }
152942
152939
  }
152943
- else if (mkcdFrames[1].dataset['runid'] != this.runId) {
152944
- this.startFrame(mkcdFrames[1]);
152940
+ else {
152941
+ // start secondary frame if needed
152942
+ const mkcdFrames = frames.filter(frame => !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL]);
152943
+ if (mkcdFrames.length < 2) {
152944
+ this.container.appendChild(this.createFrame());
152945
+ frames = this.simFrames();
152946
+ // there might be an old frame
152947
+ }
152948
+ else if (mkcdFrames[1].dataset['runid'] != this.runId) {
152949
+ this.startFrame(mkcdFrames[1]);
152950
+ }
152945
152951
  }
152946
152952
  }
152947
152953
  }
@@ -153221,12 +153227,14 @@ var pxsim;
153221
153227
  }
153222
153228
  // ensure _currentRuntime is ready
153223
153229
  startFrame(frame) {
153230
+ var _a, _b;
153224
153231
  if (!this._currentRuntime || !frame.contentWindow)
153225
153232
  return false;
153226
153233
  const msg = JSON.parse(JSON.stringify(this._currentRuntime));
153227
153234
  msg.frameCounter = ++this.frameCounter;
153228
153235
  msg.options = {
153229
153236
  theme: this.themes[this.nextFrameId++ % this.themes.length],
153237
+ 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()
153230
153238
  };
153231
153239
  msg.id = `${msg.options.theme}-${this.nextId()}`;
153232
153240
  frame.dataset['runid'] = this.runId;
@@ -674,7 +674,7 @@ Blockly.Field.prototype.markDirty=function(){this.isDirty_=!0;this.constants_=nu
674
674
  Blockly.Field.prototype.setValue=function(a){if(null!==a){var b=this.doClassValidation_(a);a=this.processValidation_(a,b);if(!(a instanceof Error)){if(b=this.getValidator())if(b=b.call(this,a),a=this.processValidation_(a,b),a instanceof Error)return;b=this.sourceBlock_;if(!b||!b.disposed){var c=this.getValue();c===a?this.doValueUpdate_(a):(b&&Blockly.Events.isEnabled()&&Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))(b,"field",this.name||null,c,a)),this.doValueUpdate_(a),
675
675
  this.isDirty_&&this.forceRerender())}}}};Blockly.Field.prototype.processValidation_=function(a,b){if(null===b)return this.doValueInvalid_(a),this.isDirty_&&this.forceRerender(),Error();void 0!==b&&(a=b);return a};Blockly.Field.prototype.getValue=function(){return this.value_};Blockly.Field.prototype.doClassValidation_=function(a){return null===a||void 0===a?null:a};Blockly.Field.prototype.doValueUpdate_=function(a){this.value_=a;this.isDirty_=!0};Blockly.Field.prototype.doValueInvalid_=function(a){};
676
676
  Blockly.Field.prototype.onMouseDown_=function(a){this.sourceBlock_&&this.sourceBlock_.workspace&&(a=this.sourceBlock_.workspace.getGesture(a))&&a.setStartField(this)};Blockly.Field.prototype.setTooltip=function(a){a||""===a||(a=this.sourceBlock_);var b=this.getClickTarget_();b?b.tooltip=a:this.tooltip_=a};Blockly.Field.prototype.getTooltip=function(){var a=this.getClickTarget_();return a?Blockly.Tooltip.getTooltipOfObject(a):Blockly.Tooltip.getTooltipOfObject({tooltip:this.tooltip_})};
677
- Blockly.Field.prototype.getClickTarget_=function(){if(this.clickTarget_)return this.clickTarget_;if(!this.sourceBlock_)return null;for(var a=0,b=0,c=0,d;d=this.sourceBlock_.inputList[c];c++){for(var e=0,f;f=d.fieldRow[e];e++)f instanceof Blockly.FieldLabel||a++;d.connection&&b++}return this.clickTarget_=1>=a&&this.sourceBlock_.outputConnection&&!b?this.sourceBlock_.getSvgRoot():this.getSvgRoot()};
677
+ Blockly.Field.prototype.getClickTarget_=function(){if(this.clickTarget_)return this.clickTarget_;if(!this.sourceBlock_||!this.sourceBlock_.getSvgRoot)return null;for(var a=0,b=0,c=0,d;d=this.sourceBlock_.inputList[c];c++){for(var e=0,f;f=d.fieldRow[e];e++)f instanceof Blockly.FieldLabel||a++;d.connection&&b++}return this.clickTarget_=1>=a&&this.sourceBlock_.outputConnection&&!b?this.sourceBlock_.getSvgRoot():this.getSvgRoot()};
678
678
  Blockly.Field.prototype.getTotalFields_=function(a){a=void 0===a?!1:a;for(var b=0,c=0,d;d=this.sourceBlock_.inputList[c];c++)for(var e=0,f;f=d.fieldRow[e];e++)f instanceof Blockly.FieldLabel&&a||b++;return b};Blockly.Field.prototype.getAbsoluteXY_=function(){return Blockly.utils.style.getPageOffset(this.getClickTarget_())};Blockly.Field.prototype.referencesVariables=function(){return!1};
679
679
  Blockly.Field.prototype.getParentInput=function(){for(var a=null,b=this.sourceBlock_,c=b.inputList,d=0;d<b.inputList.length;d++)for(var e=c[d],f=e.fieldRow,g=0;g<f.length;g++)if(f[g]===this){a=e;break}return a};Blockly.Field.prototype.getFlipRtl=function(){return!1};Blockly.Field.prototype.isTabNavigable=function(){return!1};Blockly.Field.prototype.onShortcut=function(a){return!1};
680
680
  Blockly.Field.prototype.setCursorSvg=function(a){a?(this.fieldGroup_.appendChild(a),this.cursorSvg_=a):this.cursorSvg_=null};Blockly.Field.prototype.setMarkerSvg=function(a){a?(this.fieldGroup_.appendChild(a),this.markerSvg_=a):this.markerSvg_=null};Blockly.Field.prototype.updateMarkers_=function(){var a=this.sourceBlock_.workspace;a.keyboardAccessibilityMode&&this.cursorSvg_&&a.getCursor().draw();a.keyboardAccessibilityMode&&this.markerSvg_&&a.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw()};Blockly.fieldRegistry={};Blockly.fieldRegistry.register=function(a,b){Blockly.registry.register(Blockly.registry.Type.FIELD,a,b)};Blockly.fieldRegistry.unregister=function(a){Blockly.registry.unregister(Blockly.registry.Type.FIELD,a)};
@@ -1084,7 +1084,7 @@ return Blockly.Functions.namesInUse(b,null,a)[c]?(Blockly.alert(Blockly.Msg.VARI
1084
1084
  Blockly.Functions.mutateCallersAndDefinition=function(a,b,c){var d=Blockly.Functions.getDefinition(a,b);d?(a=Blockly.Functions.getCallers(a,d.workspace),a.push(d),Blockly.Events.setGroup(!0),a.forEach(function(a){var b=a.mutationToDom(),e=b&&Blockly.Xml.domToText(b);a.domToMutation(c);var h=a.mutationToDom(),k=h&&Blockly.Xml.domToText(h);if(e!=k)if(Blockly.Events.fire(new Blockly.Events.BlockChange(a,"mutation",null,e,k)),a.id==d.id){var l=Blockly.Functions.getArgMap(b),m=Blockly.Functions.getArgMap(h,
1085
1085
  !0);d.getDescendants().forEach(function(a){if(Blockly.pxtBlocklyUtils.isFunctionArgumentReporter(a)){var b=a.getFieldValue("VALUE"),c=l[b];m[c]?m[c]!==b&&a.setFieldValue(m[c],"VALUE"):a.dispose()}})}else setTimeout(function(){a.bumpNeighbours()},Blockly.BUMP_DELAY)}),Blockly.Events.setGroup(!1)):console.warn("Attempted to change function "+a+", but no definition block was found on the workspace")};
1086
1086
  Blockly.Functions.createFlyout=function(a,b){var c=new Blockly.Options({scrollbars:!0,disabledPatternId:a.options.disabledPatternId,parentWorkspace:a,rtl:a.RTL,oneBasedIndex:a.options.oneBasedIndex,horizontalLayout:a.horizontalLayout,toolboxPosition:a.options.toolboxPosition,zoomOptions:a.options.zoomOptions,renderer:a.options.renderer,rendererOverrides:a.options.rendererOverrides,newFunctions:a.options.newFunctions,move:{scrollbars:!0}});c=c.horizontalLayout?new Blockly.HorizontalFlyout(c):new Blockly.VerticalFlyout(c);
1087
- var d=c.createDom("svg");goog.dom.insertSiblingAfter(d,b);c.init(a);return c};Blockly.VERSION="4.0.9";Blockly.mainWorkspace=null;Blockly.selected=null;Blockly.draggingConnections=[];Blockly.clipboardXml_=null;Blockly.clipboardSource_=null;Blockly.clipboardTypeCounts_=null;Blockly.cache3dSupported_=null;Blockly.parentContainer=null;Blockly.svgSize=function(a){Blockly.utils.deprecation.warn("Blockly.svgSize","March 2021","March 2022","workspace.getCachedParentSvgSize");return new Blockly.utils.Size(a.cachedWidth_,a.cachedHeight_)};Blockly.resizeSvgContents=function(a){a.resizeContents()};
1087
+ var d=c.createDom("svg");goog.dom.insertSiblingAfter(d,b);c.init(a);return c};Blockly.VERSION="4.0.10";Blockly.mainWorkspace=null;Blockly.selected=null;Blockly.draggingConnections=[];Blockly.clipboardXml_=null;Blockly.clipboardSource_=null;Blockly.clipboardTypeCounts_=null;Blockly.cache3dSupported_=null;Blockly.parentContainer=null;Blockly.svgSize=function(a){Blockly.utils.deprecation.warn("Blockly.svgSize","March 2021","March 2022","workspace.getCachedParentSvgSize");return new Blockly.utils.Size(a.cachedWidth_,a.cachedHeight_)};Blockly.resizeSvgContents=function(a){a.resizeContents()};
1088
1088
  Blockly.svgResize=function(a){for(;a.options.parentWorkspace;)a=a.options.parentWorkspace;var b=a.getParentSvg(),c=a.getCachedParentSvgSize(),d=b.parentNode;if(d){var e=d.offsetWidth;d=d.offsetHeight;c.width!=e&&(b.setAttribute("width",e+"px"),a.setCachedParentSvgSize(e,null));c.height!=d&&(b.setAttribute("height",d+"px"),a.setCachedParentSvgSize(null,d));a.resize()}};
1089
1089
  Blockly.onKeyDown=function(a){var b=Blockly.mainWorkspace;if(b&&!(Blockly.utils.isTargetInput(a)||b.rendered&&!b.isVisible()))Blockly.ShortcutRegistry.registry.onKeyDown(b,a)};Blockly.deleteBlock=function(a){a.workspace.isFlyout||(Blockly.Events.setGroup(!0),Blockly.hideChaff(),a.outputConnection?a.dispose(!1,!0):a.dispose(!0,!0),Blockly.Events.setGroup(!1))};Blockly.copy=function(a){if(a=a.toCopyData())Blockly.clipboardXml_=a.xml,Blockly.clipboardSource_=a.source,Blockly.clipboardTypeCounts_=a.typeCounts};
1090
1090
  Blockly.paste=function(){if(!Blockly.clipboardXml_)return!1;var a=Blockly.clipboardSource_;a.isFlyout&&(a=a.targetWorkspace);return Blockly.clipboardTypeCounts_&&a.isCapacityAvailable(Blockly.clipboardTypeCounts_)?(Blockly.Events.setGroup(!0),a.paste(Blockly.clipboardXml_),Blockly.Events.setGroup(!1),!0):!1};
@@ -15246,6 +15246,7 @@ var pxtblockly;
15246
15246
  .size(TOTAL_WIDTH, TOTAL_HEIGHT)
15247
15247
  .setClass("blocklySpriteField")
15248
15248
  .stroke("#fff", 1)
15249
+ .fill("#dedede")
15249
15250
  .corner(TOTAL_HEIGHT / 2);
15250
15251
  const clipPathId = "preview-clip-" + pxt.U.guidGen();
15251
15252
  const clip = new svg.ClipPath()
@@ -15480,8 +15481,8 @@ var pxtblockly;
15480
15481
  sound = {
15481
15482
  duration: 1000,
15482
15483
  startFrequency: 100,
15483
- endFrequency: 1800,
15484
- startVolume: 1023,
15484
+ endFrequency: 4800,
15485
+ startVolume: 100,
15485
15486
  endVolume: 0,
15486
15487
  wave: "sine",
15487
15488
  interpolation: "linear",
@@ -11684,6 +11684,7 @@ var pxtblockly;
11684
11684
  .size(TOTAL_WIDTH, TOTAL_HEIGHT)
11685
11685
  .setClass("blocklySpriteField")
11686
11686
  .stroke("#fff", 1)
11687
+ .fill("#dedede")
11687
11688
  .corner(TOTAL_HEIGHT / 2);
11688
11689
  const clipPathId = "preview-clip-" + pxt.U.guidGen();
11689
11690
  const clip = new svg.ClipPath()
@@ -11918,8 +11919,8 @@ var pxtblockly;
11918
11919
  sound = {
11919
11920
  duration: 1000,
11920
11921
  startFrequency: 100,
11921
- endFrequency: 1800,
11922
- startVolume: 1023,
11922
+ endFrequency: 4800,
11923
+ startVolume: 100,
11923
11924
  endVolume: 0,
11924
11925
  wave: "sine",
11925
11926
  interpolation: "linear",
package/built/pxtlib.d.ts CHANGED
@@ -2313,6 +2313,8 @@ declare namespace pxt.assets {
2313
2313
  endVolume: number;
2314
2314
  duration: number;
2315
2315
  }
2316
+ const MAX_FREQUENCY = 5000;
2317
+ const MAX_VOLUME = 255;
2316
2318
  function renderSoundPath(sound: pxt.assets.Sound, width: number, height: number): string;
2317
2319
  function renderWaveSnapshot(frequency: number, volume: number, wave: SoundWaveForm, width: number, height: number, timeBase: number): string;
2318
2320
  }
package/built/pxtlib.js CHANGED
@@ -4652,6 +4652,9 @@ var pxt;
4652
4652
  }
4653
4653
  BrowserUtils.noSharedLocalStorage = noSharedLocalStorage;
4654
4654
  function useOldTutorialLayout() {
4655
+ var _a, _b;
4656
+ if ((_b = (_a = pxt.appTarget) === null || _a === void 0 ? void 0 : _a.appTheme) === null || _b === void 0 ? void 0 : _b.legacyTutorial)
4657
+ return true;
4655
4658
  try {
4656
4659
  return (/tutorialview=old/.test(window.location.href));
4657
4660
  }
@@ -16784,11 +16787,10 @@ var pxt;
16784
16787
  (function (pxt) {
16785
16788
  var assets;
16786
16789
  (function (assets) {
16790
+ assets.MAX_FREQUENCY = 5000;
16791
+ assets.MAX_VOLUME = 255;
16787
16792
  function renderSoundPath(sound, width, height) {
16788
16793
  const { startFrequency, endFrequency, startVolume, endVolume, wave, interpolation } = sound;
16789
- const scale = (start, end, percent) => {
16790
- return Math.pow(start, 1 - percent) * Math.pow(end, percent);
16791
- };
16792
16794
  // To make the graph appear consistent with the implementation, use a seeded random for the noise waveform.
16793
16795
  // The numbers are still nonsense but at least this reflects that it's deterministic.
16794
16796
  const random = new SeededRandom(startFrequency + endFrequency + 1);
@@ -16805,11 +16807,13 @@ var pxt;
16805
16807
  break;
16806
16808
  }
16807
16809
  if (wave === "noise") {
16808
- getFrequencyAt = () => random.randomRange(500, 1000);
16810
+ getFrequencyAt = () => random.randomRange(500, 5000);
16809
16811
  }
16810
- const getVolumeAt = (x) => ((endVolume - startVolume) / width) * x + startVolume;
16811
- const volumeToAmplitude = (volume) => (volume / 1023) * (height - 2) / 2;
16812
- const frequencyToWidth = (frequency) => Math.min(width, Math.max(10, (1 / scale(1, 4000, frequency / 4000)) * width / 2));
16812
+ const getVolumeAt = (x) => Math.max(Math.min(((endVolume - startVolume) / width) * x + startVolume, assets.MAX_VOLUME), 0);
16813
+ const minWaveWidth = 10;
16814
+ const maxWaveWidth = width / 2;
16815
+ const volumeToAmplitude = (volume) => (volume / assets.MAX_VOLUME) * (height - 2) / 2;
16816
+ const frequencyToWidth = (frequency) => (1 - frequency / assets.MAX_FREQUENCY) * (maxWaveWidth - minWaveWidth) + minWaveWidth;
16813
16817
  const parts = [`M ${2} ${height / 2}`];
16814
16818
  let currentX = 0;
16815
16819
  while (currentX < width) {
@@ -16826,8 +16830,8 @@ var pxt;
16826
16830
  // The numbers are still nonsense but at least this reflects that it's deterministic.
16827
16831
  const random = new SeededRandom(frequency);
16828
16832
  if (wave === "noise")
16829
- frequency = random.randomRange(500, 1000);
16830
- const amplitude = (volume / 1023) * (height - 2) / 2;
16833
+ frequency = random.randomRange(500, 5000);
16834
+ const amplitude = (volume / assets.MAX_VOLUME) * (height - 2) / 2;
16831
16835
  const waveHalfWidth = (width / (frequency * timeBase / 1000)) / 2;
16832
16836
  let numSegments = Math.ceil(width / (waveHalfWidth * 2));
16833
16837
  if (numSegments % 2 === 1)
package/built/pxtsim.d.ts CHANGED
@@ -382,6 +382,7 @@ declare namespace pxsim {
382
382
  }
383
383
  interface SimulatorBroadcastMessage extends SimulatorMessage {
384
384
  broadcast: boolean;
385
+ toParentIFrameOnly?: boolean;
385
386
  }
386
387
  interface SimulatorControlMessage extends SimulatorBroadcastMessage {
387
388
  type: "messagepacket";
@@ -1219,6 +1220,7 @@ declare namespace pxsim {
1219
1220
  invalidatedClass?: string;
1220
1221
  nestedEditorSim?: boolean;
1221
1222
  parentOrigin?: string;
1223
+ mpRole?: string;
1222
1224
  messageSimulators?: pxt.Map<{
1223
1225
  url: string;
1224
1226
  localHostUrl?: string;
package/built/pxtsim.js CHANGED
@@ -6199,62 +6199,64 @@ var pxsim;
6199
6199
  const single = !!((_a = this._currentRuntime) === null || _a === void 0 ? void 0 : _a.single);
6200
6200
  const parentWindow = window.parent && window.parent !== window.window
6201
6201
  ? window.parent : window.opener;
6202
- if (this.options.nestedEditorSim && parentWindow) {
6202
+ if (parentWindow) {
6203
6203
  // if message comes from parent already, don't echo
6204
6204
  if (source !== parentWindow) {
6205
6205
  const parentOrigin = this.options.parentOrigin || window.location.origin;
6206
6206
  parentWindow.postMessage(msg, parentOrigin);
6207
6207
  }
6208
- // send message to other editors
6209
6208
  }
6210
- else if (depEditors) {
6211
- depEditors.forEach(w => {
6212
- if (source !== w)
6213
- // dependant editors should be in the same origin
6214
- w.postMessage(msg, window.location.origin);
6215
- });
6216
- // start second simulator
6217
- }
6218
- else if (!single) {
6219
- const messageChannel = msg.type === "messagepacket" && msg.channel;
6220
- const messageSimulator = messageChannel &&
6221
- this.options.messageSimulators &&
6222
- this.options.messageSimulators[messageChannel];
6223
- // should we start an extension editor?
6224
- if (messageSimulator) {
6225
- // find a frame already running that simulator
6226
- let messageFrame = frames.find(frame => frame.dataset[FRAME_DATA_MESSAGE_CHANNEL] === messageChannel);
6227
- // not found, spin a new one
6228
- if (!messageFrame) {
6229
- const useLocalHost = pxsim.U.isLocalHost() && /localhostmessagesims=1/i.test(window.location.href);
6230
- const url = ((useLocalHost && messageSimulator.localHostUrl) || messageSimulator.url)
6231
- .replace("$PARENT_ORIGIN$", encodeURIComponent(this.options.parentOrigin || ""));
6232
- let wrapper = this.createFrame(url);
6233
- this.container.appendChild(wrapper);
6234
- messageFrame = wrapper.firstElementChild;
6235
- messageFrame.dataset[FRAME_DATA_MESSAGE_CHANNEL] = messageChannel;
6236
- pxsim.U.addClass(wrapper, "simmsg");
6237
- pxsim.U.addClass(wrapper, "simmsg" + messageChannel);
6238
- if (messageSimulator.permanent)
6239
- messageFrame.dataset[PERMANENT] = "true";
6240
- this.startFrame(messageFrame);
6241
- frames = this.simFrames(); // refresh
6242
- }
6243
- // not running the curren run, restart
6244
- else if (messageFrame.dataset['runid'] != this.runId) {
6245
- this.startFrame(messageFrame);
6246
- }
6247
- }
6248
- else {
6249
- // start secondary frame if needed
6250
- const mkcdFrames = frames.filter(frame => !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL]);
6251
- if (mkcdFrames.length < 2) {
6252
- this.container.appendChild(this.createFrame());
6253
- frames = this.simFrames();
6254
- // there might be an old frame
6209
+ if (!this.options.nestedEditorSim && !(broadcastmsg === null || broadcastmsg === void 0 ? void 0 : broadcastmsg.toParentIFrameOnly)) {
6210
+ // send message to other editors
6211
+ if (depEditors) {
6212
+ depEditors.forEach(w => {
6213
+ if (source !== w)
6214
+ // dependant editors should be in the same origin
6215
+ w.postMessage(msg, window.location.origin);
6216
+ });
6217
+ // start second simulator
6218
+ }
6219
+ else if (!single) {
6220
+ const messageChannel = msg.type === "messagepacket" && msg.channel;
6221
+ const messageSimulator = messageChannel &&
6222
+ this.options.messageSimulators &&
6223
+ this.options.messageSimulators[messageChannel];
6224
+ // should we start an extension editor?
6225
+ if (messageSimulator) {
6226
+ // find a frame already running that simulator
6227
+ let messageFrame = frames.find(frame => frame.dataset[FRAME_DATA_MESSAGE_CHANNEL] === messageChannel);
6228
+ // not found, spin a new one
6229
+ if (!messageFrame) {
6230
+ const useLocalHost = pxsim.U.isLocalHost() && /localhostmessagesims=1/i.test(window.location.href);
6231
+ const url = ((useLocalHost && messageSimulator.localHostUrl) || messageSimulator.url)
6232
+ .replace("$PARENT_ORIGIN$", encodeURIComponent(this.options.parentOrigin || ""));
6233
+ let wrapper = this.createFrame(url);
6234
+ this.container.appendChild(wrapper);
6235
+ messageFrame = wrapper.firstElementChild;
6236
+ messageFrame.dataset[FRAME_DATA_MESSAGE_CHANNEL] = messageChannel;
6237
+ pxsim.U.addClass(wrapper, "simmsg");
6238
+ pxsim.U.addClass(wrapper, "simmsg" + messageChannel);
6239
+ if (messageSimulator.permanent)
6240
+ messageFrame.dataset[PERMANENT] = "true";
6241
+ this.startFrame(messageFrame);
6242
+ frames = this.simFrames(); // refresh
6243
+ }
6244
+ // not running the curren run, restart
6245
+ else if (messageFrame.dataset['runid'] != this.runId) {
6246
+ this.startFrame(messageFrame);
6247
+ }
6255
6248
  }
6256
- else if (mkcdFrames[1].dataset['runid'] != this.runId) {
6257
- this.startFrame(mkcdFrames[1]);
6249
+ else {
6250
+ // start secondary frame if needed
6251
+ const mkcdFrames = frames.filter(frame => !frame.dataset[FRAME_DATA_MESSAGE_CHANNEL]);
6252
+ if (mkcdFrames.length < 2) {
6253
+ this.container.appendChild(this.createFrame());
6254
+ frames = this.simFrames();
6255
+ // there might be an old frame
6256
+ }
6257
+ else if (mkcdFrames[1].dataset['runid'] != this.runId) {
6258
+ this.startFrame(mkcdFrames[1]);
6259
+ }
6258
6260
  }
6259
6261
  }
6260
6262
  }
@@ -6534,12 +6536,14 @@ var pxsim;
6534
6536
  }
6535
6537
  // ensure _currentRuntime is ready
6536
6538
  startFrame(frame) {
6539
+ var _a, _b;
6537
6540
  if (!this._currentRuntime || !frame.contentWindow)
6538
6541
  return false;
6539
6542
  const msg = JSON.parse(JSON.stringify(this._currentRuntime));
6540
6543
  msg.frameCounter = ++this.frameCounter;
6541
6544
  msg.options = {
6542
6545
  theme: this.themes[this.nextFrameId++ % this.themes.length],
6546
+ 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()
6543
6547
  };
6544
6548
  msg.id = `${msg.options.theme}-${this.nextId()}`;
6545
6549
  frame.dataset['runid'] = this.runId;