code-playpad 0.10.0 → 0.10.1

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.
Files changed (3) hide show
  1. package/README.md +58 -14
  2. package/dist/cdn.js +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,21 +3,21 @@
3
3
  [![npm](https://img.shields.io/npm/v/code-playpad)](https://www.npmjs.com/package/code-playpad) [![license](https://img.shields.io/npm/l/code-playpad)](./LICENSE)
4
4
 
5
5
  Runnable code in any web page. A CodeMirror editor that **executes what it
6
- shows** — Python, JavaScript, TypeScript and a documented subset of Java —
7
- entirely in the reader's browser. No backend, no iframe, no sign-up.
6
+ shows** — Python, JavaScript, TypeScript, a documented subset of Java, and
7
+ experimental C and C++ — entirely in the reader's browser. No backend, no iframe, no sign-up.
8
8
 
9
9
  **[Live demo →](https://code-playpad.swengr.com)**
10
10
 
11
11
  ```html
12
- <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.9.0/dist/standalone.js"></script>
12
+ <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.10.1/dist/standalone.js"></script>
13
13
 
14
14
  <code-playpad height="auto">
15
15
  print("hello from a static page")
16
16
  </code-playpad>
17
17
  ```
18
18
 
19
- **Contents** — [Languages](#languages) · [Install](#install) · [Attributes](#attributes)
20
- · [Sizing](#sizing) · [Several files](#several-files) · [Input](#input)
19
+ **Contents** — [Languages](#languages) · [Experimental C/C++](#experimental-cc)
20
+ · [Install](#install) · [Attributes](#attributes) · [Sizing](#sizing) · [Several files](#several-files) · [Input](#input)
21
21
  · [Controlling it from JavaScript](#controlling-it-from-javascript)
22
22
  · [Events and grading](#events-and-grading) · [Saving work](#saving-work)
23
23
  · [Light and dark](#light-and-dark) · [Styling](#styling) · [Framework recipes](#framework-recipes)
@@ -31,6 +31,7 @@ entirely in the reader's browser. No backend, no iframe, no sign-up.
31
31
  | `javascript` | The browser's own engine, in a Worker | nothing |
32
32
  | `typescript` | Same engine, types stripped before running | nothing from another service: a ~47 KB (gzipped) transform chunk of this package, loaded the first time a widget needs it |
33
33
  | `java` | A documented subset of Java 25, compiled and interpreted in a Worker by an engine built for this package — see [Java](#java) | nothing: the engine is a ~105 KB (gzipped) chunk of this package, loaded with the first Java widget, and its library a ~75 KB chunk loaded the first time a program uses it |
34
+ | `c`, `cpp` | Experimental: C17 and C++20, compiled by a real Clang compiler in a Worker — see [Experimental C/C++](#experimental-cc) | ~30 MB on the first C/C++ Run, then cached |
34
35
 
35
36
  ```html
36
37
  <code-playpad height="auto">print("python is the default")</code-playpad>
@@ -162,18 +163,39 @@ the evidence behind it and every known difference from the JDK, is in
162
163
  ## Experimental C/C++
163
164
 
164
165
  `language="c"` (C17) and `language="cpp"` (C++20) compile and run in a worker
165
- with a real Clang compiler, prefilled stdin and Stop. They are experimental:
166
+ with a real Clang compiler, prefilled stdin and Stop. No setup is needed:
167
+
168
+ ```html
169
+ <code-playpad language="cpp" height="auto">
170
+ #include &lt;algorithm&gt;
171
+ #include &lt;iostream&gt;
172
+ #include &lt;vector&gt;
173
+
174
+ int main() {
175
+ std::vector&lt;int&gt; v{3, 1, 2};
176
+ std::sort(v.begin(), v.end());
177
+ for (int n : v) std::cout &lt;&lt; n &lt;&lt; " ";
178
+ }
179
+ </code-playpad>
180
+ ```
181
+
182
+ Inside HTML, write `<` as `&lt;`. They are experimental:
166
183
 
167
184
  - **The compiler loads on the first C/C++ Run.** It is a separate package,
168
185
  [`@code-playpad/cpp-toolchain`](https://www.npmjs.com/package/@code-playpad/cpp-toolchain),
169
- fetched from jsDelivr and checked by SHA-256. Installing `code-playpad` does not
170
- download it. To host it yourself, call `configureCpp({ indexURL })`.
186
+ fetched from jsDelivr and checked by SHA-256. You don't install it, and
187
+ installing `code-playpad` doesn't download it. A page with a strict
188
+ Content-Security-Policy must allow the host in `connect-src`, `blob:` in
189
+ `script-src` and `worker-src`, and `'wasm-unsafe-eval'`. To host it yourself, see
190
+ [Production](#production).
191
+ - **Not everything works.** Exceptions and threads don't compile, input must be
192
+ prefilled (it can't wait for typing), and programs only get stdin, stdout and
193
+ stderr. A run stops after 120 seconds; change that with
194
+ `configureCpp({ timeoutMs })`.
171
195
  - **Lightly tested on phones.** Desktop Chromium, WebKit and Firefox pass the
172
196
  browser suite. One physical phone was checked by hand; memory on phones has
173
197
  not been measured.
174
198
 
175
- See [setup and limits](https://github.com/stancs/code-playpad/blob/main/docs/COMPILER-RUNTIMES.md).
176
-
177
199
  ## Download size
178
200
 
179
201
  What a page downloads once a reader presses Run, with the CDN build, as
@@ -245,7 +267,7 @@ actually sent.
245
267
  ### From a CDN — nothing to install
246
268
 
247
269
  ```html
248
- <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.9.0/dist/standalone.js"></script>
270
+ <script type="module" src="https://cdn.jsdelivr.net/npm/code-playpad@0.10.1/dist/standalone.js"></script>
249
271
  ```
250
272
 
251
273
  This is the `standalone` build: CodeMirror is bundled in, so a static blog post
@@ -267,7 +289,7 @@ npm install code-playpad @codemirror/state @codemirror/view @codemirror/commands
267
289
  CodeMirror is a peer dependency so you never end up with two copies of
268
290
  `@codemirror/state`. Language grammars are **optional** — install only what you
269
291
  use (`@codemirror/lang-python`, `@codemirror/lang-javascript`,
270
- `@codemirror/lang-json`, `@codemirror/lang-java`); a missing one degrades to
292
+ `@codemirror/lang-json`, `@codemirror/lang-java`, `@codemirror/lang-cpp`); a missing one degrades to
271
293
  plain text rather than throwing.
272
294
 
273
295
  ```js
@@ -854,6 +876,19 @@ self-contained ES module exporting `transform`), set before the first
854
876
  JavaScript or TypeScript widget starts its runtime. Give those files a long `Cache-Control`: one page's download then
855
877
  warms every other page on the site.
856
878
 
879
+ C and C++ load their compiler from jsDelivr unless you host it. To host it, unpack
880
+ [`@code-playpad/cpp-toolchain`](https://www.npmjs.com/package/@code-playpad/cpp-toolchain),
881
+ keep its version and notices together, and serve its `dist` folder:
882
+
883
+ ```js
884
+ import { configureCpp } from 'code-playpad';
885
+
886
+ configureCpp({ indexURL: 'https://your-site.example/cpp-toolchain/dist/' }); // before any widget runs
887
+ ```
888
+
889
+ Use the toolchain version that your `code-playpad` version pins: every file is
890
+ checked by SHA-256, so another version fails. A different origin must allow CORS.
891
+
857
892
  ## Worth knowing
858
893
 
859
894
  - **One runtime per page.** Every widget shares a single Worker per language, so
@@ -876,6 +911,15 @@ warms every other page on the site.
876
911
 
877
912
  ## Version history
878
913
 
914
+ ### 0.10.1
915
+
916
+ Documentation only: nothing changes in how the widget runs.
917
+
918
+ - **The README's opening** now mentions C and C++, in the intro, the Languages table
919
+ and the contents, and its snippets pin the current version.
920
+ - **The C/C++ section** has an example, its limits, CSP needs and self-hosting steps.
921
+ - **Removed links to private files,** which readers couldn't open.
922
+
879
923
  ### 0.10.0
880
924
 
881
925
  C and C++ now work with no setup. Nothing else changed.
@@ -1247,8 +1291,8 @@ this package.
1247
1291
  Experimental C/C++ downloads separate compiler assets with additional
1248
1292
  third-party terms; those assets are not MIT-only. Their notices ship in
1249
1293
  `dist/COMPILER-NOTICES.txt`. The pinned C/C++ rebuild passes its scoped license
1250
- inventory gate; see the [compiler license audit](docs/COMPILER-LICENSE-AUDIT.md)
1251
- and [rebuild and remaining gates](docs/CPP-REBUILD.md).
1294
+ inventory gate; see `dist/COMPILER-LICENSE-AUDIT.md`. Programs compiled here
1295
+ include parts of the C and C++ libraries, which have their own terms.
1252
1296
 
1253
1297
  The Java engine is original code under the same MIT licence. Java is a trademark
1254
1298
  of Oracle and/or its affiliates; code-playpad is not affiliated with, endorsed
package/dist/cdn.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! code-playpad 0.10.0: CDN entry, loads dist/standalone.js of this exact version */
2
- export * from "https://cdn.jsdelivr.net/npm/code-playpad@0.10.0/dist/standalone.js";
1
+ /*! code-playpad 0.10.1: CDN entry, loads dist/standalone.js of this exact version */
2
+ export * from "https://cdn.jsdelivr.net/npm/code-playpad@0.10.1/dist/standalone.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-playpad",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Embeddable browser code playground: a CodeMirror editor that runs Python, JavaScript, TypeScript, a subset of Java and experimental C/C++ in the browser. No backend. One shared worker per page, blocking input(), multi-file projects, lazy per-language loading.",
5
5
  "type": "module",
6
6
  "license": "MIT",