npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@webwriter/code

v3.0.3

Published

Write and run code as a code cell. Supports several languages (HTML, JavaScript/TypeScript, Python, Java, WebAssembly).

Downloads

42

Readme

Code (@webwriter/[email protected])

License: MIT | Version: 3.0.2

The Code Widget enables interactive code exercises directly in the browser. Users can effortlessly write, execute, and explore code in multiple programming languages, including:

  • JavaScript or TypeScript
  • HTML
  • Python (powered by Pyodide)
  • Java (powered by TeaVM)
  • WebAssembly Text Format (WAT)

Features

  • Intuitive Editor: Based on CodeMirror, offering syntax highlighting and optional autocompletion for a smoother coding experience.
  • Line Locking: Allows instructors to lock specific lines, creating read-only templates to guide students effectively.
  • Rich Output Display: Outputs appear neatly below each code cell, with JavaScript execution featuring a fully interactive console inspector.
  • 100% Client-Side Execution: Everything executes locally within the browser, ensuring complete offline capability and no reliance on servers.

Development

To set up the development environment, clone the repository and execute the following commands:

npm install
npm run dev # runs @webwriter/build dev

Finally, import the code directory into WebWriter to begin.

Snippets

Snippets are examples and templates using the package's widgets.

| Name | Import Path | | :--: | :---------: | | HTML | @webwriter/code/snippets/HTML.html |

CodeHTML (<webwriter-code-html>)

Code widget for HTML with live preview functionality.

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-html.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-html.js"></script>
<webwriter-code-html></webwriter-code-html>

Or use with a bundler (e.g. Vite):

npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-html.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-html.js"></script>
<webwriter-code-html></webwriter-code-html>

Fields

| Name (Attribute Name) | Type | Description | Default | Reflects | | :-------------------: | :--: | :---------: | :-----: | :------: | | code (code) | String | The source code content displayed in the editor. | - | ✓ | | visible (visible) | boolean | Whether the code editor is visible to the user. | true | ✓ | | autoRun (autoRun) | boolean | Whether to automatically run the code when the component is first loaded. | false | ✓ | | runnable (runnable) | boolean | Whether the code execution is allowed and the run button is enabled. | true | ✓ | | autocomplete (autocomplete) | boolean | Whether autocompletion is enabled in the code editor. | false | ✓ | | lockedLines (lockedLines) | number[] | Array of line numbers that should be locked from editing. | [] | ✓ | | showExecutionTime (showExecutionTime) | boolean | Whether to display the execution time in the controls. | false | ✓ | | executionTime (executionTime) | number | The execution time in milliseconds of the last code run. | 0 | ✓ | | showExecutionCount (showExecutionCount) | boolean | Whether to display the execution count in the run button. | false | ✓ | | executionCount (executionCount) | number | The number of times the code has been executed. | 0 | ✓ | | results (results) | any | The results from the last code execution. | [] | ✓ | | diagnostics (diagnostics) | Diagnostic[] | Compilation or runtime errors from the last code execution. | [] | ✓ |

Fields including properties and attributes define the current state of the widget and offer customization options.

Editing config

| Name | Value | | :--: | :---------: |

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public methods, slots, events, custom CSS properties, or CSS parts.

CodeJavaScript (<webwriter-code-javascript>)

Code widget for JavaScript with execution capabilities.

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-javascript.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-javascript.js"></script>
<webwriter-code-javascript></webwriter-code-javascript>

Or use with a bundler (e.g. Vite):

npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-javascript.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-javascript.js"></script>
<webwriter-code-javascript></webwriter-code-javascript>

Fields

| Name (Attribute Name) | Type | Description | Default | Reflects | | :-------------------: | :--: | :---------: | :-----: | :------: | | code (code) | String | The source code content displayed in the editor. | - | ✓ | | visible (visible) | boolean | Whether the code editor is visible to the user. | true | ✓ | | autoRun (autoRun) | boolean | Whether to automatically run the code when the component is first loaded. | false | ✓ | | runnable (runnable) | boolean | Whether the code execution is allowed and the run button is enabled. | true | ✓ | | autocomplete (autocomplete) | boolean | Whether autocompletion is enabled in the code editor. | false | ✓ | | lockedLines (lockedLines) | number[] | Array of line numbers that should be locked from editing. | [] | ✓ | | showExecutionTime (showExecutionTime) | boolean | Whether to display the execution time in the controls. | false | ✓ | | executionTime (executionTime) | number | The execution time in milliseconds of the last code run. | 0 | ✓ | | showExecutionCount (showExecutionCount) | boolean | Whether to display the execution count in the run button. | false | ✓ | | executionCount (executionCount) | number | The number of times the code has been executed. | 0 | ✓ | | results (results) | any | The results from the last code execution. | [] | ✓ | | diagnostics (diagnostics) | Diagnostic[] | Compilation or runtime errors from the last code execution. | [] | ✓ |

Fields including properties and attributes define the current state of the widget and offer customization options.

Editing config

| Name | Value | | :--: | :---------: |

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public methods, slots, events, custom CSS properties, or CSS parts.

CodeJava (<webwriter-code-java>)

Code widget for Java with compilation and execution capabilities using TeaVM (Java 21).

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-java.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-java.js"></script>
<webwriter-code-java></webwriter-code-java>

Or use with a bundler (e.g. Vite):

npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-java.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-java.js"></script>
<webwriter-code-java></webwriter-code-java>

Fields

| Name (Attribute Name) | Type | Description | Default | Reflects | | :-------------------: | :--: | :---------: | :-----: | :------: | | code (code) | String | The source code content displayed in the editor. | - | ✓ | | visible (visible) | boolean | Whether the code editor is visible to the user. | true | ✓ | | autoRun (autoRun) | boolean | Whether to automatically run the code when the component is first loaded. | false | ✓ | | runnable (runnable) | boolean | Whether the code execution is allowed and the run button is enabled. | true | ✓ | | autocomplete (autocomplete) | boolean | Whether autocompletion is enabled in the code editor. | false | ✓ | | lockedLines (lockedLines) | number[] | Array of line numbers that should be locked from editing. | [] | ✓ | | showExecutionTime (showExecutionTime) | boolean | Whether to display the execution time in the controls. | false | ✓ | | executionTime (executionTime) | number | The execution time in milliseconds of the last code run. | 0 | ✓ | | showExecutionCount (showExecutionCount) | boolean | Whether to display the execution count in the run button. | false | ✓ | | executionCount (executionCount) | number | The number of times the code has been executed. | 0 | ✓ | | results (results) | any | The results from the last code execution. | [] | ✓ | | diagnostics (diagnostics) | Diagnostic[] | Compilation or runtime errors from the last code execution. | [] | ✓ |

Fields including properties and attributes define the current state of the widget and offer customization options.

Editing config

| Name | Value | | :--: | :---------: |

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public methods, slots, events, custom CSS properties, or CSS parts.

CodeTypeScript (<webwriter-code-typescript>)

Code widget for TypeScript with compilation and execution capabilities.

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-typescript.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-typescript.js"></script>
<webwriter-code-typescript></webwriter-code-typescript>

Or use with a bundler (e.g. Vite):

npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-typescript.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-typescript.js"></script>
<webwriter-code-typescript></webwriter-code-typescript>

Fields

| Name (Attribute Name) | Type | Description | Default | Reflects | | :-------------------: | :--: | :---------: | :-----: | :------: | | code (code) | String | The source code content displayed in the editor. | - | ✓ | | visible (visible) | boolean | Whether the code editor is visible to the user. | true | ✓ | | autoRun (autoRun) | boolean | Whether to automatically run the code when the component is first loaded. | false | ✓ | | runnable (runnable) | boolean | Whether the code execution is allowed and the run button is enabled. | true | ✓ | | autocomplete (autocomplete) | boolean | Whether autocompletion is enabled in the code editor. | false | ✓ | | lockedLines (lockedLines) | number[] | Array of line numbers that should be locked from editing. | [] | ✓ | | showExecutionTime (showExecutionTime) | boolean | Whether to display the execution time in the controls. | false | ✓ | | executionTime (executionTime) | number | The execution time in milliseconds of the last code run. | 0 | ✓ | | showExecutionCount (showExecutionCount) | boolean | Whether to display the execution count in the run button. | false | ✓ | | executionCount (executionCount) | number | The number of times the code has been executed. | 0 | ✓ | | results (results) | any | The results from the last code execution. | [] | ✓ | | diagnostics (diagnostics) | Diagnostic[] | Compilation or runtime errors from the last code execution. | [] | ✓ |

Fields including properties and attributes define the current state of the widget and offer customization options.

Editing config

| Name | Value | | :--: | :---------: |

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public methods, slots, events, custom CSS properties, or CSS parts.

CodePython (<webwriter-code-python>)

Code widget for Python with execution capabilities using Pyodide.

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-python.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-python.js"></script>
<webwriter-code-python></webwriter-code-python>

Or use with a bundler (e.g. Vite):

npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-python.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-python.js"></script>
<webwriter-code-python></webwriter-code-python>

Fields

| Name (Attribute Name) | Type | Description | Default | Reflects | | :-------------------: | :--: | :---------: | :-----: | :------: | | code (code) | String | The source code content displayed in the editor. | - | ✓ | | visible (visible) | boolean | Whether the code editor is visible to the user. | true | ✓ | | autoRun (autoRun) | boolean | Whether to automatically run the code when the component is first loaded. | false | ✓ | | runnable (runnable) | boolean | Whether the code execution is allowed and the run button is enabled. | true | ✓ | | autocomplete (autocomplete) | boolean | Whether autocompletion is enabled in the code editor. | false | ✓ | | lockedLines (lockedLines) | number[] | Array of line numbers that should be locked from editing. | [] | ✓ | | showExecutionTime (showExecutionTime) | boolean | Whether to display the execution time in the controls. | false | ✓ | | executionTime (executionTime) | number | The execution time in milliseconds of the last code run. | 0 | ✓ | | showExecutionCount (showExecutionCount) | boolean | Whether to display the execution count in the run button. | false | ✓ | | executionCount (executionCount) | number | The number of times the code has been executed. | 0 | ✓ | | results (results) | any | The results from the last code execution. | [] | ✓ | | diagnostics (diagnostics) | Diagnostic[] | Compilation or runtime errors from the last code execution. | [] | ✓ |

Fields including properties and attributes define the current state of the widget and offer customization options.

Editing config

| Name | Value | | :--: | :---------: |

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public methods, slots, events, custom CSS properties, or CSS parts.

CodeWebAssembly (<webwriter-code-webassembly>)

Code widget for WebAssembly with compilation and execution capabilities.

Usage

Use with a CDN (e.g. jsdelivr):

<link href="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-webassembly.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/@webwriter/code/widgets/webwriter-code-webassembly.js"></script>
<webwriter-code-webassembly></webwriter-code-webassembly>

Or use with a bundler (e.g. Vite):

npm install @webwriter/code
<link href="@webwriter/code/widgets/webwriter-code-webassembly.css" rel="stylesheet">
<script type="module" src="@webwriter/code/widgets/webwriter-code-webassembly.js"></script>
<webwriter-code-webassembly></webwriter-code-webassembly>

Fields

| Name (Attribute Name) | Type | Description | Default | Reflects | | :-------------------: | :--: | :---------: | :-----: | :------: | | code (code) | String | The source code content displayed in the editor. | - | ✓ | | visible (visible) | boolean | Whether the code editor is visible to the user. | true | ✓ | | autoRun (autoRun) | boolean | Whether to automatically run the code when the component is first loaded. | false | ✓ | | runnable (runnable) | boolean | Whether the code execution is allowed and the run button is enabled. | true | ✓ | | autocomplete (autocomplete) | boolean | Whether autocompletion is enabled in the code editor. | false | ✓ | | lockedLines (lockedLines) | number[] | Array of line numbers that should be locked from editing. | [] | ✓ | | showExecutionTime (showExecutionTime) | boolean | Whether to display the execution time in the controls. | false | ✓ | | executionTime (executionTime) | number | The execution time in milliseconds of the last code run. | 0 | ✓ | | showExecutionCount (showExecutionCount) | boolean | Whether to display the execution count in the run button. | false | ✓ | | executionCount (executionCount) | number | The number of times the code has been executed. | 0 | ✓ | | results (results) | any | The results from the last code execution. | [] | ✓ | | diagnostics (diagnostics) | Diagnostic[] | Compilation or runtime errors from the last code execution. | [] | ✓ |

Fields including properties and attributes define the current state of the widget and offer customization options.

Editing config

| Name | Value | | :--: | :---------: |

The editing config defines how explorable authoring tools such as WebWriter treat the widget.

No public methods, slots, events, custom CSS properties, or CSS parts.


Generated with @webwriter/[email protected]