yourjs-box 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Christopher West
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # yourjs-box
2
+
3
+ Embed an interactive JavaScript console on any web page with one script tag.
4
+ Step-by-step code blocks, DevTools-style output, and code that runs in a Web
5
+ Worker or the page itself.
6
+
7
+ **[Live demo](https://westc.github.io/yourjs-box/)** ·
8
+ [Examples](https://westc.github.io/yourjs-box/examples/)
9
+
10
+ ## Usage
11
+
12
+ Add the script wherever you want the console to appear and put the code that
13
+ should be loaded into the console inside of the script tag:
14
+
15
+ ```html
16
+ <div style="height: 400px;">
17
+ <script src="https://cdn.jsdelivr.net/npm/yourjs-box@1/dist/yourjs-box.min.js">
18
+ // Say hello \\
19
+ console.log('Hello world!');
20
+
21
+ // Show a table \\
22
+ console.table([{name: 'John', age: 42}, {name: 'Jane', age: 37}]);
23
+ </script>
24
+ </div>
25
+ ```
26
+
27
+ The console fills its container. The script is also available from unpkg at
28
+ `https://unpkg.com/yourjs-box@1/dist/yourjs-box.min.js`.
29
+
30
+ ### Code Blocks
31
+
32
+ A comment line that ends with `\\` is a header. Headers split the code into
33
+ blocks which are run one at a time each time the run button is clicked (or
34
+ <kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Enter</kbd> is pressed in the editor).
35
+
36
+ Hovering over code that already ran shows a "Copy to editor" button which
37
+ copies that code into the editor so that it can be run again, as is or modified.
38
+ If the editor already has code in it you are asked before it is replaced.
39
+
40
+ ### Toolbar
41
+
42
+ - **Clear** removes everything from the console. Code can also call
43
+ `console.clear()`.
44
+ - **Reset** clears the console and puts the original code back into the editor.
45
+ In worker mode this also stops any code that is still running (eg. an
46
+ infinite loop) by starting a new worker.
47
+ - The layout button switches between showing the editor below or beside the
48
+ console.
49
+ - **Run** runs the next block of code.
50
+
51
+ ### Attributes
52
+
53
+ | Attribute | Description |
54
+ | --- | --- |
55
+ | `data-runner` | `"worker"` (default) runs the code in a Web Worker. `"window"` runs it directly in the page. See below. |
56
+ | `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. |
57
+ | `data-hide-prefix` | Any block whose header starts with this prefix is hidden. See below. |
58
+ | `data-theme` | `"light"` or `"dark"`. Defaults to following the system's color scheme like the browser's dev tools. |
59
+
60
+ ### Hidden Code
61
+
62
+ If `data-hide-prefix="HIDE"` is specified then a block with a header like
63
+ `// HIDE: Setup \\` will not be shown in the editor. Instead it runs
64
+ automatically as soon as all of the code that came before it has run. It shows
65
+ up in the output as a collapsed block labelled with whatever came after the
66
+ prefix (and optional colon), or "Hidden code" if nothing did. Clicking the
67
+ label shows or hides the code.
68
+
69
+ ### Where Code Runs
70
+
71
+ The console's interface is always in an IFRAME so that its styles and the
72
+ page's styles can't affect each other. The code itself runs in one of two
73
+ places:
74
+
75
+ - **Web Worker** (`data-runner="worker"`, the default): The code can't access
76
+ the page. There is no `document` or DOM, but everything else (timers,
77
+ `fetch()`, promises, etc.) works. Reset stops code that never finishes.
78
+ - **Window** (`data-runner="window"`): The code runs directly in the page, so
79
+ it can use the page's globals, functions and DOM. Only use this with code you
80
+ trust. Since it replaces the page's `console` functions, the console also
81
+ shows anything else the page logs, just like the browser's console. Reset
82
+ can't undo what the code already did to the page (eg. variables it defined).
83
+
84
+ In both modes, top-level declarations (`let`, `const`, `class`, etc.) are shared
85
+ between blocks.
86
+
87
+ ## Development
88
+
89
+ Install the development dependencies by running `npm install`.
90
+
91
+ - `npm run dev` builds, rebuilds whenever one of the files in `src/` changes
92
+ and serves the examples at http://localhost:3000/examples/ with the browser
93
+ reloading automatically after each rebuild.
94
+ - `npm run build` builds the files in `dist/` once.
95
+ - `npm start` builds and then rebuilds whenever one of the files in `src/`
96
+ changes (without serving anything).
97
+
98
+ The kitchen sink example (`examples/kitchen-sink.html`) has several consoles
99
+ which cover every feature. Add `?build=standard` or `?build=min` to its URL to
100
+ test `dist/yourjs-box.js` or `dist/yourjs-box.min.js` instead of
101
+ `dist/yourjs-box.full.js`.
102
+
103
+ ## Roadmap
104
+
105
+ - Open button - Load a JS file from the filesystem.
106
+ - Save button - Save the current inputs as a JS file that can be opened later.
107
+ - Add `@timeout` annotation to the special comments that will allow you to input the amount of seconds to wait since the last call to a console logging function before automatically running the next comment segmented block.
108
+ - Allow for TypeScript
109
+ - Allow for CoffeeScript
110
+ - Allow code to run in main window.
111
+
112
+ ## License
113
+
114
+ Released under the [MIT License](LICENSE). You're free to use, modify and
115
+ distribute it, including in commercial projects, as long as the copyright and
116
+ license notice is kept.
117
+
118
+ Copyright (c) 2023-present Christopher West