pyret-embed 0.1.6 → 0.1.8

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/README.md CHANGED
@@ -25,6 +25,28 @@ editor.embed.html work from your source.
25
25
  ```
26
26
  See examples/ for more examples!
27
27
 
28
+ ## Choosing the compiler backend
29
+
30
+ The embedded editor can run on either the stock Pyret-hosted compiler or the
31
+ TypeScript port of the compiler (`pyret-lang/src/ts-compiler`) — the same
32
+ opt-in as code.pyret.org's `?compiler=ts` flag. Pass `compiler: 'ts'` in the
33
+ config form of the API and the flag is appended to the embed URL for you:
34
+
35
+ ```
36
+ const embed = await makeEmbedConfig({
37
+ container,
38
+ src: "/dist/build/web/editor.embed.html",
39
+ compiler: "ts", // default: "pyret" (the stock compiler)
40
+ options: { footerStyle: "hide" },
41
+ });
42
+ ```
43
+
44
+ For self-hosted builds the ts artifacts (`cpo-main-ts.jarr.js`,
45
+ `ts-compiler.js`) are only present if you build with `npm run build:ts`
46
+ (which runs the regular build plus code.pyret.org's `make web-ts`); the
47
+ default `npm run build` produces the stock-only bundle and the default
48
+ behavior is unchanged.
49
+
28
50
  ## API
29
51
 
30
52
  ```
@@ -902,6 +902,27 @@ body.hideFooter .replContainer {
902
902
  padding-bottom: 0rem;
903
903
  }
904
904
 
905
+ /* Unobtrusive compiler-flavor indicator, pinned to the REPL's corner just
906
+ above the footer padding. Hidden unless the page resolved to the ts
907
+ flavor (editor.html adds .ts-mode to <html> in the same branch that
908
+ swaps PYRET), so the stock editor shows nothing new. */
909
+ #compilerFlavorBadge {
910
+ display: none;
911
+ position: absolute;
912
+ right: 8px;
913
+ bottom: calc(2.5rem + 4px);
914
+ font-size: 11px;
915
+ color: #999;
916
+ z-index: 1;
917
+ user-select: none;
918
+ }
919
+ html.ts-mode #compilerFlavorBadge {
920
+ display: block;
921
+ }
922
+ body.hideFooter #compilerFlavorBadge {
923
+ bottom: 4px;
924
+ }
925
+
905
926
  body.hideHeader .replContainer {
906
927
  padding-top: 0px;
907
928
  }
@@ -3,8 +3,40 @@
3
3
  <head>
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
5
  <title>code.pyret.org</title>
6
- <link crossorigin="anonymous" rel="preload" href="./js/cpo-main.jarr.js" as="script">
7
- <script>window.PYRET = "./js/cpo-main.jarr.js"; window.PYRET_GZIPPED = "" === "true"; window.APP_NAME = "code.pyret.org"; window.APP_DOMAIN = "code.pyret.org";</script>
6
+
7
+ <script>
8
+ window.PYRET = "./js/cpo-main.jarr.gz.js"; window.PYRET_GZIPPED = "true" === "true"; window.APP_NAME = "code.pyret.org"; window.APP_DOMAIN = "code.pyret.org";
9
+ // Opt-in TypeScript-compiler flavor: chosen by ?compiler=ts (or the
10
+ // server-side CPO_COMPILER env default). Swaps in the cpo-main-ts jarr
11
+ // and loads the TS compiler bundle; default behavior is unchanged.
12
+ //
13
+ // The ts asset URLs are never configured -- they are derived from PYRET's
14
+ // directory plus canonical names, a contract every host satisfies by
15
+ // publishing the three files side by side (deploys upload them together;
16
+ // static/webview builds copy them together). Both ts assets are gzip bytes
17
+ // at rest everywhere. No PYRET means no ts flavor: ?compiler=ts silently
18
+ // serves the stock compiler.
19
+ window.CPO_COMPILER = "pyret" || "pyret";
20
+ (function() {
21
+ var dir = window.PYRET ? window.PYRET.slice(0, window.PYRET.lastIndexOf("/") + 1) : "";
22
+ window.PYRET_TS = window.PYRET ? dir + "cpo-main-ts.jarr.gz.js" : "";
23
+ window.PYRET_TS_COMPILER = window.PYRET ? dir + "ts-compiler.gz.js" : "";
24
+ var m = /[?&]compiler=([^&]*)/.exec(window.location.search);
25
+ if(m) { window.CPO_COMPILER = decodeURIComponent(m[1]); }
26
+ if(window.CPO_COMPILER === "ts" && window.PYRET_TS) {
27
+ window.PYRET = window.PYRET_TS;
28
+ // Lets pure CSS show ts-only chrome (the "(ts mode)" badge in the
29
+ // REPL corner) without another script running at DOM-ready.
30
+ document.documentElement.classList.add("ts-mode");
31
+ // In gzipped mode the host may serve assets without an executable MIME
32
+ // type (nosniff), which refuses a <script src> load outright --
33
+ // beforePyret.js fetches the compiler bundle alongside the jarr instead.
34
+ if(!window.PYRET_GZIPPED) {
35
+ document.write('<script src="' + window.PYRET_TS_COMPILER + '"><\/script>');
36
+ }
37
+ }
38
+ })();
39
+ </script>
8
40
  <link rel="stylesheet" href="./css/reset.css" />
9
41
  <link rel="stylesheet" href="./css/smoothness-jquery-ui.css" />
10
42
  <link rel="stylesheet" href="./css/fira-mono.css" />
@@ -362,6 +394,7 @@
362
394
  </div>
363
395
  <div id="REPL" class="replContainer" role="region" aria-label="Interactions">
364
396
  <div id="handle" class="ui-resizable-handle ui-resizable-w"></div>
397
+ <div id="compilerFlavorBadge" title="This session uses the TypeScript version of Pyret. Visit /settings/clear-ts to turn it off.">(ts mode)</div>
365
398
  </div>
366
399
  <div id="help-keys">
367
400
  <p><b>Press <kbd>Esc</kbd> to close this help window</b></p>
@@ -4,7 +4,39 @@
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
5
  <title>{{APP_NAME}}</title>
6
6
  {{^PYRET_GZIPPED}}<link crossorigin="anonymous" rel="preload" href="{{&PYRET}}" as="script">{{/PYRET_GZIPPED}}
7
- <script>window.PYRET = "{{&PYRET}}"; window.PYRET_GZIPPED = "{{ PYRET_GZIPPED }}" === "true"; window.APP_NAME = "{{APP_NAME}}"; window.APP_DOMAIN = "{{APP_DOMAIN}}";</script>
7
+ <script>
8
+ window.PYRET = "{{&PYRET}}"; window.PYRET_GZIPPED = "{{ PYRET_GZIPPED }}" === "true"; window.APP_NAME = "{{APP_NAME}}"; window.APP_DOMAIN = "{{APP_DOMAIN}}";
9
+ // Opt-in TypeScript-compiler flavor: chosen by ?compiler=ts (or the
10
+ // server-side CPO_COMPILER env default). Swaps in the cpo-main-ts jarr
11
+ // and loads the TS compiler bundle; default behavior is unchanged.
12
+ //
13
+ // The ts asset URLs are never configured -- they are derived from PYRET's
14
+ // directory plus canonical names, a contract every host satisfies by
15
+ // publishing the three files side by side (deploys upload them together;
16
+ // static/webview builds copy them together). Both ts assets are gzip bytes
17
+ // at rest everywhere. No PYRET means no ts flavor: ?compiler=ts silently
18
+ // serves the stock compiler.
19
+ window.CPO_COMPILER = "{{&CPO_COMPILER}}" || "pyret";
20
+ (function() {
21
+ var dir = window.PYRET ? window.PYRET.slice(0, window.PYRET.lastIndexOf("/") + 1) : "";
22
+ window.PYRET_TS = window.PYRET ? dir + "cpo-main-ts.jarr.gz.js" : "";
23
+ window.PYRET_TS_COMPILER = window.PYRET ? dir + "ts-compiler.gz.js" : "";
24
+ var m = /[?&]compiler=([^&]*)/.exec(window.location.search);
25
+ if(m) { window.CPO_COMPILER = decodeURIComponent(m[1]); }
26
+ if(window.CPO_COMPILER === "ts" && window.PYRET_TS) {
27
+ window.PYRET = window.PYRET_TS;
28
+ // Lets pure CSS show ts-only chrome (the "(ts mode)" badge in the
29
+ // REPL corner) without another script running at DOM-ready.
30
+ document.documentElement.classList.add("ts-mode");
31
+ // In gzipped mode the host may serve assets without an executable MIME
32
+ // type (nosniff), which refuses a <script src> load outright --
33
+ // beforePyret.js fetches the compiler bundle alongside the jarr instead.
34
+ if(!window.PYRET_GZIPPED) {
35
+ document.write('<script src="' + window.PYRET_TS_COMPILER + '"><\/script>');
36
+ }
37
+ }
38
+ })();
39
+ </script>
8
40
  <link rel="stylesheet" href="{{ &BASE_URL }}/css/reset.css" />
9
41
  <link rel="stylesheet" href="{{ &BASE_URL }}/css/smoothness-jquery-ui.css" />
10
42
  <link rel="stylesheet" href="{{ &BASE_URL }}/css/fira-mono.css" />
@@ -362,6 +394,7 @@
362
394
  </div>
363
395
  <div id="REPL" class="replContainer" role="region" aria-label="Interactions">
364
396
  <div id="handle" class="ui-resizable-handle ui-resizable-w"></div>
397
+ <div id="compilerFlavorBadge" title="This session uses the TypeScript version of Pyret. Visit /settings/clear-ts to turn it off.">(ts mode)</div>
365
398
  </div>
366
399
  <div id="help-keys">
367
400
  <p><b>Press <kbd>Esc</kbd> to close this help window</b></p>