<light-pen>
A lightweight codepen-like editor. <light-pen> is ~15kb in size. Compared to ~90kb from CodeMirror and ~160kb from CodeSandbox. LightPen purposely is small and lightweight and is not intended to replace these tools. But rather
fill a gap for users who don’t need as much power.
Examples
Default Usage
<light-pen>
component running inside of a <light-pen> component!!
API Reference
Imports
<!-- Auto registers as <light-pen> -->
<script type="module" src="https://cdn.jsdelivr.net/npm/light-pen/exports/components/light-pen/light-pen-register.js"></script>
<script type="module">
// Auto registers as <light-pen>
import "https://cdn.jsdelivr.net/npm/light-pen/exports/components/light-pen/light-pen-register.js"
// Manual Register
import LightPen from "https://cdn.jsdelivr.net/npm/light-pen/exports/components/light-pen/light-pen.js"
LightPen.define()
// => Registers as <light-pen>
</script>
// Auto registers as <light-pen>
import "light-pen/exports/components/light-pen/light-pen-register.js"
// Manual Register
import LightPen "light-pen/exports/components/light-pen/light-pen.js"
LightPen.define()
// => Registers as <light-pen>
Slots
| Name | Description |
|---|---|
html
|
HTML to insert |
css
|
CSS to insert |
js
|
JavaScript to insert |
title
|
The title to appear at the top of the editor |
Attributes
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
[Attribute + Property]
resizePosition
|
-
|
|
number
|
50
|
[Attribute + Property]
openLanguages
|
Languages to have open on initial render Comma separated list of elements to open on initial render “html,css,js” to open all. |
|
string
|
""
|
[Attribute + Property]
console
|
Not implemented. |
|
"enabled" | "disabled"
|
"disabled"
|
[Attribute]
sandbox-settings
[Property] sandboxSettings
|
-
|
|
string
|
"allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-scripts"
|
[Attribute]
preserve-whitespace
[Property] preserveWhitespace
|
Passed down to the editors. |
|
boolean
|
false
|
Functions
| Name | Description | Parameters |
|---|---|---|
updateCachedWidth()
|
Sets an initial width so we dont need to keep computing getBoundingClientRect |
-
|
handleResize()
|
-
|
entries: ResizeObserverEntry[]
|
updateIframeContent()
|
-
|
-
|
handleResizerKeydown()
|
-
|
event: KeyboardEvent
|
updateResizePosition()
|
-
|
resizePosition
|
resetValues()
|
-
|
-
|
renderConsole()
|
-
|
-
|
handleDrag()
|
-
|
event: PointerEvent
|
Parts
| Name | Description |
|---|---|
base
|
The base wrapper |
sandbox
|
The wrapper around the editor and the iframe |
sandbox-header
|
The wrapper around the header area |
disclosure
|
Maps to any |
disclosure-${language}
|
deprecated in favor of |
disclosure-summary
|
re-exported summary from all |
disclosure-content
|
re-exported content from all |
base:disclosure-content-base
|
re-exported content-base from all |
sandbox-disclosure-summary
|
re-exported summary from all |
sandbox-disclosure
|
the |
sandbox-disclosure-${language}
|
the specific |
sandbox-disclosure-summary
|
re-exported summary part from light-disclosure |
sandbox-disclosure-${language}-summary
|
re-exported summary part from |
sandbox-disclosure-content
|
re-exported content part from light-disclosure |
sandbox-disclosure-${language}-content
|
re-exported content part from light-disclosure for the specific |
sandbox-disclosure-content-base
|
re-exported content-base part from light-disclosure |
sandbox-disclosure-${language}-content-base
|
re-exported content-base part from light-disclosure for the specific |