yourjs-box 1.7.0 → 1.9.0

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
@@ -7,6 +7,8 @@ Worker or the page itself. TypeScript works too.
7
7
  **[Live demo](https://westc.github.io/yourjs-box/)** ·
8
8
  [Examples](https://westc.github.io/yourjs-box/examples/)
9
9
 
10
+ ![YourJS Box running code one block at a time, expanding an object, showing a table and an error](demo.gif)
11
+
10
12
  ## Usage
11
13
 
12
14
  Add the script wherever you want the console to appear and put the code that
@@ -33,6 +35,9 @@ script is also available from unpkg at
33
35
  A comment line that ends with `\\` is a header. Headers split the code into
34
36
  blocks which are run one at a time each time the run button is clicked (or
35
37
  <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Enter</kbd> is pressed in the editor).
38
+ <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>Enter</kbd> (or **Run all
39
+ blocks** in the **&#8943;** menu) runs all of the remaining blocks, one after
40
+ another and in order with any hidden blocks.
36
41
 
37
42
  Hovering over code that already ran shows a "Copy to editor" button which
38
43
  copies that code into the editor so that it can be run again, as is or modified.
@@ -41,8 +46,8 @@ If the editor already has code in it you are asked before it is replaced.
41
46
  ### Toolbar
42
47
 
43
48
  - The **&#8943;** button opens a menu (see below).
44
- - **Clear** removes everything from the console. Code can also call
45
- `console.clear()`.
49
+ - **Clear** (or <kbd>Ctrl</kbd>+<kbd>L</kbd>) removes everything from the
50
+ console. Code can also call `console.clear()`.
46
51
  - The **layout** button switches between showing the editor beside or below
47
52
  the console.
48
53
  - **Full screen** shows the console using the whole screen. If the browser
@@ -60,6 +65,7 @@ If the editor already has code in it you are asked before it is replaced.
60
65
  code that hasn't been run yet comes back. Hidden blocks aren't in the
61
66
  history.
62
67
  - The **&#8943;** menu has:
68
+ - **Run all blocks**, which runs all of the remaining blocks.
63
69
  - **Text size**, which is remembered for every console on the same site.
64
70
  - **Open**, which loads a JavaScript (or TypeScript) file as the code that the console starts
65
71
  with (its hidden blocks are hidden and Reset goes back to it).
@@ -76,7 +82,7 @@ If the editor already has code in it you are asked before it is replaced.
76
82
  - **Reset**, which clears the console and puts the original code back into
77
83
  the editor. In worker mode this also stops any code that is still running
78
84
  (eg. an infinite loop) by starting a new worker.
79
- - **About JS Box**
85
+ - **About YourJS Box**
80
86
 
81
87
  ### Right-Clicking Values
82
88
 
@@ -106,6 +112,7 @@ objects and arrays) for a menu with:
106
112
  | `data-runner` | `"worker"` (default) runs the code in a Web Worker. `"window"` runs it directly in the page. See below. |
107
113
  | `data-divider-orient` | `"vertical"` puts the editor beside the output and `"horizontal"` puts it below. If not specified the editor is beside the output unless the console is narrower than 600px. |
108
114
  | `data-hide-prefix` | Any block whose header starts with this prefix is hidden. See below. |
115
+ | `data-loading` | `"lazy"` (default) waits to load the console until it is about to be scrolled into view (or, if it is hidden, shown). `"eager"` loads it right away. See "Loading" below. |
109
116
  | `data-theme` | `"light"` or `"dark"`. Defaults to following the system's color scheme like the browser's dev tools. |
110
117
 
111
118
  ### Results
@@ -216,7 +223,7 @@ npm install vue@3.5.43 ace-builds@1.44.0 prismjs@1.30.0 prism-themes@1.9.0 acorn
216
223
  npm install @babel/standalone@7.29.9
217
224
  ```
218
225
 
219
- The About window lists the versions that each version of JS Box uses.
226
+ The About window lists the versions that each version of YourJS Box uses.
220
227
 
221
228
  ### Console Functions
222
229
 
@@ -225,14 +232,43 @@ The About window lists the versions that each version of JS Box uses.
225
232
  `timeLog()`, `timeEnd()`, `trace()`, `group()`, `groupCollapsed()`,
226
233
  `groupEnd()` and `clear()` are all shown in the console.
227
234
 
235
+ Like the browser's console, the first argument can use format specifiers:
236
+ `%s` (string), `%d` or `%i` (integer), `%f` (number), `%o` and `%O` (a value
237
+ that can be expanded), `%c` (CSS styles for the text after it) and `%%` (a
238
+ percent sign). For example:
239
+
240
+ ```js
241
+ console.log('%cHello%c, %s!', 'color: white; background: #1a73e8; padding: 2px 6px; border-radius: 4px', '', 'world');
242
+ ```
243
+
244
+ Like the browser, `%c` only allows CSS for things like colors, fonts, borders,
245
+ margins and padding, and never anything that loads a URL.
246
+
247
+ A message that is the same as the one logged right before it is shown once with
248
+ a count instead of being repeated. Messages that include objects are always
249
+ shown again since the objects may have changed.
250
+
251
+ ### Loading
252
+
253
+ Like `<img loading="lazy">`, a console isn't loaded until it is about to be
254
+ scrolled into view, so a page with many consoles (eg. a long tutorial) only
255
+ loads the ones that are read. A console that is hidden (eg. in a closed tab)
256
+ loads once it is shown. Its space in the page is kept while it waits, so
257
+ nothing moves around when it loads.
258
+
259
+ Until a console loads none of its code runs, including hidden blocks, and in
260
+ window mode the page's `console` functions aren't captured yet. Add
261
+ `data-loading="eager"` to load a console right away (eg. if its hidden blocks
262
+ set up something that the page needs).
263
+
228
264
  ### Hidden Code
229
265
 
230
266
  If `data-hide-prefix="HIDE"` is specified then a block with a header like
231
267
  `// HIDE: Setup \\` will not be shown in the editor. Instead it runs
232
- automatically as soon as all of the code that came before it has run. It shows
233
- up in the output as a collapsed block labelled with whatever came after the
234
- prefix (and optional colon), or "Hidden code" if nothing did. Clicking the
235
- label shows or hides the code.
268
+ automatically (once the console loads) as soon as all of the code that came
269
+ before it has run. It shows up in the output as a collapsed block labelled
270
+ with whatever came after the prefix (and optional colon), or "Hidden code" if
271
+ nothing did. Clicking the label shows or hides the code.
236
272
 
237
273
  ### JavaScript API
238
274
 
@@ -267,7 +303,7 @@ functions). The options are:
267
303
  | `placement` | Where the console goes: `"fill"` (default) replaces the target's contents, `"append"` and `"prepend"` add it inside of the target, `"replace"` replaces the target itself and `"before"` and `"after"` add it next to the target. |
268
304
  | `height` | The CSS height of the console (a number is treated as pixels). Defaults to `"100%"` so the console fills its container. It is never less than 150px. |
269
305
  | `code` | The code that the console starts with. |
270
- | `runner`, `blockType`, `language`, `showResults`, `hidePrefix`, `dividerOrient`, `theme`, `importsUrl`, `librariesUrl` | The same as the `data-*` attributes above. |
306
+ | `runner`, `blockType`, `language`, `showResults`, `hidePrefix`, `dividerOrient`, `theme`, `importsUrl`, `librariesUrl`, `loading` | The same as the `data-*` attributes above. |
271
307
 
272
308
  `YourJSBox.version` is the version of JS Box that was loaded.
273
309
 
@@ -309,6 +345,10 @@ Install the development dependencies by running `npm install`.
309
345
  Pages doesn't always deploy when they are pushed together), publishes to npm
310
346
  and, once npm lists the new version, purges jsDelivr's cache. Add
311
347
  `--dry-run` to see what it would do or `--skip-tests` to skip the tests.
348
+ - `npm run record-demo` records `demo.gif` (shown at the top of this README)
349
+ from the built files. It needs [ffmpeg](https://ffmpeg.org/).
350
+ - `npm run og-image` makes `og-image.png` (the picture shown when the landing
351
+ page is shared) from the built files.
312
352
  - `npm run purge-cdn` purges jsDelivr's cache so that URLs like
313
353
  `yourjs-box@1` point to the latest version right away.
314
354
  - In VS Code, **Terminal &rarr; Run Task&hellip;** has tasks for all of these
@@ -316,10 +356,34 @@ Install the development dependencies by running `npm install`.
316
356
  - `npm start` builds and then rebuilds whenever one of the files in `src/`
317
357
  changes (without serving anything).
318
358
 
319
- The kitchen sink example (`examples/kitchen-sink.html`) has several consoles
320
- which cover every feature. Add `?build=standard` or `?build=min` to its URL to
321
- test `dist/yourjs-box.js` or `dist/yourjs-box.min.js` instead of
322
- `dist/yourjs-box.full.js`.
359
+ The kitchen sink example (`examples/kitchen-sink.html`) has a sidebar for
360
+ choosing an example and every option, including which build is loaded
361
+ (`dist/yourjs-box.full.js`, `dist/yourjs-box.js` or `dist/yourjs-box.min.js`).
362
+ The options are kept in the URL so the page can be reloaded or shared as is.
363
+
364
+ ## Roadmap
365
+
366
+ Ideas for future versions, roughly from easiest to hardest:
367
+
368
+ - **`data-autorun`:** run every visible block when the page loads.
369
+ - **Autocomplete:** turn on Ace's keyword and snippet completion in the editor.
370
+ - **`data-remember`:** save the editor's code and history in the browser so
371
+ that they are still there after a reload.
372
+ - **Copy output:** copy everything in the console as text from the **&#8943;**
373
+ menu.
374
+ - **Clickable error locations:** clicking `snippet-2.js:3:7` in an error
375
+ highlights that line in the code that ran.
376
+ - **More JavaScript API:** `box.run()`, `box.runAll()`, `box.reset()`,
377
+ `box.setCode()` and events (eg. `box.on('log', ...)`) so that a page can
378
+ control the console.
379
+ - **Output filter:** search the output and show only errors, warnings or logs.
380
+ - **Exercises:** hidden blocks that check the code above them and show which
381
+ checks passed (eg. "`sum(2, 3)` should be `5`").
382
+ - **`@timeout`:** an annotation in a block's header that runs the block
383
+ automatically once nothing has been logged for the given number of seconds.
384
+ - **Long output:** keep the console fast when thousands of messages are logged.
385
+ - **Accessibility:** announce new output to screen readers and make every value
386
+ and menu reachable with the keyboard.
323
387
 
324
388
  ## License
325
389