pxt-core 12.2.17 → 12.2.18

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.
@@ -184,5 +184,6 @@ declare namespace pxt.docs {
184
184
  export function buildTOC(summaryMD: string): pxt.TOCMenuEntry[];
185
185
  export function visitTOC(toc: TOCMenuEntry[], fn: (e: TOCMenuEntry) => void): void;
186
186
  export function augmentDocs(baseMd: string, childMd: string): string;
187
+ export function hydrateYouTubeEmbeds(content: HTMLElement, tickEvent: boolean): void;
187
188
  export {};
188
189
  }
@@ -862,7 +862,8 @@ var pxt;
862
862
  const text = token.text || "";
863
863
  if (href.startsWith("youtube:")) {
864
864
  const videoId = href.split(":").pop();
865
- return `<div class="tutorial-video-embed"><iframe class="yt-embed" src="https://www.youtube.com/embed/${videoId}" title="${text}" frameborder="0" allowFullScreen allow="autoplay; picture-in-picture"></iframe></div>`;
865
+ // This data-youtube attribute is handled in hydrateYoutubeEmbeds
866
+ return `<div class="tutorial-video-embed" data-youtube="${encodeURIComponent(videoId)}" title="${text}"></div>`;
866
867
  }
867
868
  else {
868
869
  let out = `<img class="ui image" src="${href}" alt="${text}"`;
@@ -1547,6 +1548,32 @@ My links
1547
1548
  test(templ0, inp0, outp0);
1548
1549
  test(templ0, inp1, outp1);
1549
1550
  }
1551
+ function hydrateYouTubeEmbeds(content, tickEvent) {
1552
+ var _a, _b;
1553
+ for (const videoContainer of content.querySelectorAll(".tutorial-video-embed[data-youtube]")) {
1554
+ const videoId = decodeURIComponent(videoContainer.getAttribute("data-youtube"));
1555
+ const iframe = document.createElement("iframe");
1556
+ iframe.className = "yt-embed";
1557
+ const rawUrl = `https://www.youtube.com/embed/${videoId}`;
1558
+ let lang = (_b = (_a = pxt.appTarget.appTheme) === null || _a === void 0 ? void 0 : _a.defaultLocale) !== null && _b !== void 0 ? _b : "en";
1559
+ let url = new URL(rawUrl);
1560
+ if (tickEvent) {
1561
+ pxt.tickEvent("video.loaded", {
1562
+ player: "youtube",
1563
+ url: rawUrl
1564
+ });
1565
+ }
1566
+ url.searchParams.append("hl", lang);
1567
+ iframe.setAttribute("src", url.toString());
1568
+ iframe.setAttribute("title", videoContainer.getAttribute("title") || "");
1569
+ iframe.setAttribute("frameborder", "0");
1570
+ iframe.setAttribute("allowFullScreen", "true");
1571
+ iframe.setAttribute("allow", "autoplay; picture-in-picture");
1572
+ videoContainer.textContent = "";
1573
+ videoContainer.appendChild(iframe);
1574
+ }
1575
+ }
1576
+ docs.hydrateYouTubeEmbeds = hydrateYouTubeEmbeds;
1550
1577
  })(docs = pxt.docs || (pxt.docs = {}));
1551
1578
  })(pxt || (pxt = {}));
1552
1579
  /// <reference path="../pxtlib/docsrender.ts"/>
package/built/cli.js CHANGED
@@ -36,11 +36,11 @@ pxt.docs.requireDOMSanitizer = () => {
36
36
  const sanitizeHtml = require("sanitize-html");
37
37
  const defaults = sanitizeHtml.defaults || {};
38
38
  const baseAllowedAttrs = defaults.allowedAttributes || {};
39
- const mergeClassAttribute = (tag) => {
39
+ const mergeClassAttribute = (tag, ...otherAttributes) => {
40
40
  const existing = baseAllowedAttrs[tag] || [];
41
- return Array.from(new Set([...existing, "class"]));
41
+ return Array.from(new Set([...existing, "class", ...otherAttributes]));
42
42
  };
43
- const options = Object.assign(Object.assign({}, defaults), { allowedAttributes: Object.assign(Object.assign({}, baseAllowedAttrs), { code: mergeClassAttribute("code"), pre: mergeClassAttribute("pre") }) });
43
+ const options = Object.assign(Object.assign({}, defaults), { allowedAttributes: Object.assign(Object.assign({}, baseAllowedAttrs), { code: mergeClassAttribute("code"), pre: mergeClassAttribute("pre"), div: mergeClassAttribute("div", "data-youtube", "title") }) });
44
44
  return (html) => sanitizeHtml(html, options);
45
45
  };
46
46
  let forceCloudBuild = process.env["KS_FORCE_CLOUD"] !== "no";
package/built/pxt.js CHANGED
@@ -107072,7 +107072,8 @@ var pxt;
107072
107072
  const text = token.text || "";
107073
107073
  if (href.startsWith("youtube:")) {
107074
107074
  const videoId = href.split(":").pop();
107075
- return `<div class="tutorial-video-embed"><iframe class="yt-embed" src="https://www.youtube.com/embed/${videoId}" title="${text}" frameborder="0" allowFullScreen allow="autoplay; picture-in-picture"></iframe></div>`;
107075
+ // This data-youtube attribute is handled in hydrateYoutubeEmbeds
107076
+ return `<div class="tutorial-video-embed" data-youtube="${encodeURIComponent(videoId)}" title="${text}"></div>`;
107076
107077
  }
107077
107078
  else {
107078
107079
  let out = `<img class="ui image" src="${href}" alt="${text}"`;
@@ -107757,6 +107758,32 @@ My links
107757
107758
  test(templ0, inp0, outp0);
107758
107759
  test(templ0, inp1, outp1);
107759
107760
  }
107761
+ function hydrateYouTubeEmbeds(content, tickEvent) {
107762
+ var _a, _b;
107763
+ for (const videoContainer of content.querySelectorAll(".tutorial-video-embed[data-youtube]")) {
107764
+ const videoId = decodeURIComponent(videoContainer.getAttribute("data-youtube"));
107765
+ const iframe = document.createElement("iframe");
107766
+ iframe.className = "yt-embed";
107767
+ const rawUrl = `https://www.youtube.com/embed/${videoId}`;
107768
+ let lang = (_b = (_a = pxt.appTarget.appTheme) === null || _a === void 0 ? void 0 : _a.defaultLocale) !== null && _b !== void 0 ? _b : "en";
107769
+ let url = new URL(rawUrl);
107770
+ if (tickEvent) {
107771
+ pxt.tickEvent("video.loaded", {
107772
+ player: "youtube",
107773
+ url: rawUrl
107774
+ });
107775
+ }
107776
+ url.searchParams.append("hl", lang);
107777
+ iframe.setAttribute("src", url.toString());
107778
+ iframe.setAttribute("title", videoContainer.getAttribute("title") || "");
107779
+ iframe.setAttribute("frameborder", "0");
107780
+ iframe.setAttribute("allowFullScreen", "true");
107781
+ iframe.setAttribute("allow", "autoplay; picture-in-picture");
107782
+ videoContainer.textContent = "";
107783
+ videoContainer.appendChild(iframe);
107784
+ }
107785
+ }
107786
+ docs.hydrateYouTubeEmbeds = hydrateYouTubeEmbeds;
107760
107787
  })(docs = pxt.docs || (pxt.docs = {}));
107761
107788
  })(pxt || (pxt = {}));
107762
107789
  var pxt;
@@ -162752,11 +162779,11 @@ pxt.docs.requireDOMSanitizer = () => {
162752
162779
  const sanitizeHtml = require("sanitize-html");
162753
162780
  const defaults = sanitizeHtml.defaults || {};
162754
162781
  const baseAllowedAttrs = defaults.allowedAttributes || {};
162755
- const mergeClassAttribute = (tag) => {
162782
+ const mergeClassAttribute = (tag, ...otherAttributes) => {
162756
162783
  const existing = baseAllowedAttrs[tag] || [];
162757
- return Array.from(new Set([...existing, "class"]));
162784
+ return Array.from(new Set([...existing, "class", ...otherAttributes]));
162758
162785
  };
162759
- const options = Object.assign(Object.assign({}, defaults), { allowedAttributes: Object.assign(Object.assign({}, baseAllowedAttrs), { code: mergeClassAttribute("code"), pre: mergeClassAttribute("pre") }) });
162786
+ const options = Object.assign(Object.assign({}, defaults), { allowedAttributes: Object.assign(Object.assign({}, baseAllowedAttrs), { code: mergeClassAttribute("code"), pre: mergeClassAttribute("pre"), div: mergeClassAttribute("div", "data-youtube", "title") }) });
162760
162787
  return (html) => sanitizeHtml(html, options);
162761
162788
  };
162762
162789
  let forceCloudBuild = process.env["KS_FORCE_CLOUD"] !== "no";
package/built/pxtlib.d.ts CHANGED
@@ -1303,6 +1303,7 @@ declare namespace pxt.docs {
1303
1303
  export function buildTOC(summaryMD: string): pxt.TOCMenuEntry[];
1304
1304
  export function visitTOC(toc: TOCMenuEntry[], fn: (e: TOCMenuEntry) => void): void;
1305
1305
  export function augmentDocs(baseMd: string, childMd: string): string;
1306
+ export function hydrateYouTubeEmbeds(content: HTMLElement, tickEvent: boolean): void;
1306
1307
  export {};
1307
1308
  }
1308
1309
  declare namespace pxt.dom {
package/built/pxtlib.js CHANGED
@@ -9351,7 +9351,8 @@ var pxt;
9351
9351
  const text = token.text || "";
9352
9352
  if (href.startsWith("youtube:")) {
9353
9353
  const videoId = href.split(":").pop();
9354
- return `<div class="tutorial-video-embed"><iframe class="yt-embed" src="https://www.youtube.com/embed/${videoId}" title="${text}" frameborder="0" allowFullScreen allow="autoplay; picture-in-picture"></iframe></div>`;
9354
+ // This data-youtube attribute is handled in hydrateYoutubeEmbeds
9355
+ return `<div class="tutorial-video-embed" data-youtube="${encodeURIComponent(videoId)}" title="${text}"></div>`;
9355
9356
  }
9356
9357
  else {
9357
9358
  let out = `<img class="ui image" src="${href}" alt="${text}"`;
@@ -10036,6 +10037,32 @@ My links
10036
10037
  test(templ0, inp0, outp0);
10037
10038
  test(templ0, inp1, outp1);
10038
10039
  }
10040
+ function hydrateYouTubeEmbeds(content, tickEvent) {
10041
+ var _a, _b;
10042
+ for (const videoContainer of content.querySelectorAll(".tutorial-video-embed[data-youtube]")) {
10043
+ const videoId = decodeURIComponent(videoContainer.getAttribute("data-youtube"));
10044
+ const iframe = document.createElement("iframe");
10045
+ iframe.className = "yt-embed";
10046
+ const rawUrl = `https://www.youtube.com/embed/${videoId}`;
10047
+ let lang = (_b = (_a = pxt.appTarget.appTheme) === null || _a === void 0 ? void 0 : _a.defaultLocale) !== null && _b !== void 0 ? _b : "en";
10048
+ let url = new URL(rawUrl);
10049
+ if (tickEvent) {
10050
+ pxt.tickEvent("video.loaded", {
10051
+ player: "youtube",
10052
+ url: rawUrl
10053
+ });
10054
+ }
10055
+ url.searchParams.append("hl", lang);
10056
+ iframe.setAttribute("src", url.toString());
10057
+ iframe.setAttribute("title", videoContainer.getAttribute("title") || "");
10058
+ iframe.setAttribute("frameborder", "0");
10059
+ iframe.setAttribute("allowFullScreen", "true");
10060
+ iframe.setAttribute("allow", "autoplay; picture-in-picture");
10061
+ videoContainer.textContent = "";
10062
+ videoContainer.appendChild(iframe);
10063
+ }
10064
+ }
10065
+ docs.hydrateYouTubeEmbeds = hydrateYouTubeEmbeds;
10039
10066
  })(docs = pxt.docs || (pxt.docs = {}));
10040
10067
  })(pxt || (pxt = {}));
10041
10068
  var pxt;