pxt-core 8.0.1 → 8.0.2

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
@@ -151712,6 +151712,7 @@ var pxsim;
151712
151712
  }
151713
151713
  kill() {
151714
151714
  super.kill();
151715
+ pxsim.codal.music.__stopSoundExpressions();
151715
151716
  pxsim.AudioContextManager.stopAll();
151716
151717
  }
151717
151718
  }
@@ -155368,6 +155369,10 @@ var pxsim;
155368
155369
  const soundPromise = new Promise((resolve, reject) => {
155369
155370
  soundQueue.push({
155370
155371
  notes,
155372
+ onStarted: () => {
155373
+ if (!waitTillDone)
155374
+ cb();
155375
+ },
155371
155376
  onFinished: resolve,
155372
155377
  onCancelled: resolve
155373
155378
  });
@@ -155375,10 +155380,9 @@ var pxsim;
155375
155380
  if (!playing) {
155376
155381
  playNextSoundAsync();
155377
155382
  }
155378
- if (!waitTillDone)
155379
- cb();
155380
- else
155383
+ if (waitTillDone) {
155381
155384
  soundPromise.then(cb);
155385
+ }
155382
155386
  }
155383
155387
  music.__playSoundExpression = __playSoundExpression;
155384
155388
  async function playNextSoundAsync() {
@@ -155387,6 +155391,7 @@ var pxsim;
155387
155391
  const sound = soundQueue.shift();
155388
155392
  let currentToken = cancellationToken;
155389
155393
  try {
155394
+ sound.onStarted();
155390
155395
  await playSoundExpressionAsync(sound.notes, () => currentToken.cancelled);
155391
155396
  if (currentToken.cancelled) {
155392
155397
  sound.onCancelled();
@@ -6997,7 +6997,7 @@ var pxt;
6997
6997
  const xmlString = serializeNode(sg)
6998
6998
  .replace(/^\s*<svg[^>]+>/i, '')
6999
6999
  .replace(/<\/svg>\s*$/i, ''); // strip out svg tag
7000
- const svgXml = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="${XLINK_NAMESPACE}" width="${renderWidth}" height="${renderHeight}" viewBox="${x} ${y} ${width} ${height}" class="pxt-renderer">${xmlString}</svg>`;
7000
+ const svgXml = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="${XLINK_NAMESPACE}" width="${renderWidth}" height="${renderHeight}" viewBox="${x} ${y} ${width} ${height}" class="pxt-renderer classic-theme">${xmlString}</svg>`;
7001
7001
  const xsg = new DOMParser().parseFromString(svgXml, "image/svg+xml");
7002
7002
  const cssLink = xsg.createElementNS("http://www.w3.org/1999/xhtml", "style");
7003
7003
  const isRtl = pxt.Util.isUserLanguageRtl();
@@ -7011,7 +7011,7 @@ var pxt;
7011
7011
  .filter((el) => /\.blocklySvg/.test(el.innerText))[0];
7012
7012
  // Custom CSS injected directly into the DOM by Blockly
7013
7013
  customCss.unshift(((_a = document.getElementById(`blockly-common-style`)) === null || _a === void 0 ? void 0 : _a.innerText) || "");
7014
- customCss.unshift(((_b = document.getElementById(`blockly-renderer-style-pxt`)) === null || _b === void 0 ? void 0 : _b.innerText) || "");
7014
+ customCss.unshift(((_b = document.getElementById(`blockly-renderer-style-pxt-classic`)) === null || _b === void 0 ? void 0 : _b.innerText) || "");
7015
7015
  // CSS may contain <, > which need to be stored in CDATA section
7016
7016
  const cssString = (blocklySvg ? blocklySvg.innerText : "") + '\n\n' + customCss.map(el => el + '\n\n');
7017
7017
  cssLink.appendChild(xsg.createCDATASection(cssString));
@@ -14088,6 +14088,7 @@ var pxtblockly;
14088
14088
  .at((FieldCustomMelody.COLOR_BLOCK_WIDTH + FieldCustomMelody.COLOR_BLOCK_SPACING) * i + FieldCustomMelody.COLOR_BLOCK_X, FieldCustomMelody.COLOR_BLOCK_Y)
14089
14089
  .size(FieldCustomMelody.COLOR_BLOCK_WIDTH, FieldCustomMelody.COLOR_BLOCK_HEIGHT)
14090
14090
  .stroke("#898989", 1)
14091
+ .fill(getPlaceholderColor(pxtmelody.noteToRow(notes[i])))
14091
14092
  .corners(3, 2);
14092
14093
  pxt.BrowserUtils.addClass(cb.el, className);
14093
14094
  this.fieldGroup_.appendChild(cb.el);
@@ -14516,6 +14517,24 @@ var pxtblockly;
14516
14517
  props.switchColor = "#ffffff";
14517
14518
  return props;
14518
14519
  }
14520
+ /**
14521
+ * This gets the placeholder color which is embedded in the rendered svg. These are overridden
14522
+ * by the css class we set on each rect from pxtmelody.getColorClass and will only be seen
14523
+ * if the svg is taken without the corresponding css (e.g. in a blockly snapshot)
14524
+ */
14525
+ function getPlaceholderColor(row) {
14526
+ switch (row) {
14527
+ case 0: return "#A80000"; // Middle C
14528
+ case 1: return "#D83B01"; // Middle D
14529
+ case 2: return "#FFB900"; // Middle E
14530
+ case 3: return "#107C10"; // Middle F
14531
+ case 4: return "#008272"; // Middle G
14532
+ case 5: return "#0078D7"; // Middle A
14533
+ case 6: return "#5C2D91"; // Middle B
14534
+ case 7: return "#B4009E"; // Tenor C
14535
+ }
14536
+ return "#DCDCDC";
14537
+ }
14519
14538
  })(pxtblockly || (pxtblockly = {}));
14520
14539
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
14521
14540
  var pxtblockly;
@@ -3435,7 +3435,7 @@ var pxt;
3435
3435
  const xmlString = serializeNode(sg)
3436
3436
  .replace(/^\s*<svg[^>]+>/i, '')
3437
3437
  .replace(/<\/svg>\s*$/i, ''); // strip out svg tag
3438
- const svgXml = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="${XLINK_NAMESPACE}" width="${renderWidth}" height="${renderHeight}" viewBox="${x} ${y} ${width} ${height}" class="pxt-renderer">${xmlString}</svg>`;
3438
+ const svgXml = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="${XLINK_NAMESPACE}" width="${renderWidth}" height="${renderHeight}" viewBox="${x} ${y} ${width} ${height}" class="pxt-renderer classic-theme">${xmlString}</svg>`;
3439
3439
  const xsg = new DOMParser().parseFromString(svgXml, "image/svg+xml");
3440
3440
  const cssLink = xsg.createElementNS("http://www.w3.org/1999/xhtml", "style");
3441
3441
  const isRtl = pxt.Util.isUserLanguageRtl();
@@ -3449,7 +3449,7 @@ var pxt;
3449
3449
  .filter((el) => /\.blocklySvg/.test(el.innerText))[0];
3450
3450
  // Custom CSS injected directly into the DOM by Blockly
3451
3451
  customCss.unshift(((_a = document.getElementById(`blockly-common-style`)) === null || _a === void 0 ? void 0 : _a.innerText) || "");
3452
- customCss.unshift(((_b = document.getElementById(`blockly-renderer-style-pxt`)) === null || _b === void 0 ? void 0 : _b.innerText) || "");
3452
+ customCss.unshift(((_b = document.getElementById(`blockly-renderer-style-pxt-classic`)) === null || _b === void 0 ? void 0 : _b.innerText) || "");
3453
3453
  // CSS may contain <, > which need to be stored in CDATA section
3454
3454
  const cssString = (blocklySvg ? blocklySvg.innerText : "") + '\n\n' + customCss.map(el => el + '\n\n');
3455
3455
  cssLink.appendChild(xsg.createCDATASection(cssString));
@@ -10526,6 +10526,7 @@ var pxtblockly;
10526
10526
  .at((FieldCustomMelody.COLOR_BLOCK_WIDTH + FieldCustomMelody.COLOR_BLOCK_SPACING) * i + FieldCustomMelody.COLOR_BLOCK_X, FieldCustomMelody.COLOR_BLOCK_Y)
10527
10527
  .size(FieldCustomMelody.COLOR_BLOCK_WIDTH, FieldCustomMelody.COLOR_BLOCK_HEIGHT)
10528
10528
  .stroke("#898989", 1)
10529
+ .fill(getPlaceholderColor(pxtmelody.noteToRow(notes[i])))
10529
10530
  .corners(3, 2);
10530
10531
  pxt.BrowserUtils.addClass(cb.el, className);
10531
10532
  this.fieldGroup_.appendChild(cb.el);
@@ -10954,6 +10955,24 @@ var pxtblockly;
10954
10955
  props.switchColor = "#ffffff";
10955
10956
  return props;
10956
10957
  }
10958
+ /**
10959
+ * This gets the placeholder color which is embedded in the rendered svg. These are overridden
10960
+ * by the css class we set on each rect from pxtmelody.getColorClass and will only be seen
10961
+ * if the svg is taken without the corresponding css (e.g. in a blockly snapshot)
10962
+ */
10963
+ function getPlaceholderColor(row) {
10964
+ switch (row) {
10965
+ case 0: return "#A80000"; // Middle C
10966
+ case 1: return "#D83B01"; // Middle D
10967
+ case 2: return "#FFB900"; // Middle E
10968
+ case 3: return "#107C10"; // Middle F
10969
+ case 4: return "#008272"; // Middle G
10970
+ case 5: return "#0078D7"; // Middle A
10971
+ case 6: return "#5C2D91"; // Middle B
10972
+ case 7: return "#B4009E"; // Tenor C
10973
+ }
10974
+ return "#DCDCDC";
10975
+ }
10957
10976
  })(pxtblockly || (pxtblockly = {}));
10958
10977
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
10959
10978
  var pxtblockly;
package/built/pxtsim.js CHANGED
@@ -4835,6 +4835,7 @@ var pxsim;
4835
4835
  }
4836
4836
  kill() {
4837
4837
  super.kill();
4838
+ pxsim.codal.music.__stopSoundExpressions();
4838
4839
  pxsim.AudioContextManager.stopAll();
4839
4840
  }
4840
4841
  }
@@ -8491,6 +8492,10 @@ var pxsim;
8491
8492
  const soundPromise = new Promise((resolve, reject) => {
8492
8493
  soundQueue.push({
8493
8494
  notes,
8495
+ onStarted: () => {
8496
+ if (!waitTillDone)
8497
+ cb();
8498
+ },
8494
8499
  onFinished: resolve,
8495
8500
  onCancelled: resolve
8496
8501
  });
@@ -8498,10 +8503,9 @@ var pxsim;
8498
8503
  if (!playing) {
8499
8504
  playNextSoundAsync();
8500
8505
  }
8501
- if (!waitTillDone)
8502
- cb();
8503
- else
8506
+ if (waitTillDone) {
8504
8507
  soundPromise.then(cb);
8508
+ }
8505
8509
  }
8506
8510
  music.__playSoundExpression = __playSoundExpression;
8507
8511
  async function playNextSoundAsync() {
@@ -8510,6 +8514,7 @@ var pxsim;
8510
8514
  const sound = soundQueue.shift();
8511
8515
  let currentToken = cancellationToken;
8512
8516
  try {
8517
+ sound.onStarted();
8513
8518
  await playSoundExpressionAsync(sound.notes, () => currentToken.cancelled);
8514
8519
  if (currentToken.cancelled) {
8515
8520
  sound.onCancelled();