@studiometa/playground-preview 0.3.4
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 +120 -0
- package/dist/element.d.ts +1 -0
- package/dist/element.js +1177 -0
- package/dist/element.js.map +7 -0
- package/dist/icons.d.ts +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1182 -0
- package/dist/index.js.map +7 -0
- package/dist/playground-preview.d.ts +26 -0
- package/dist/styles.d.ts +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/zip.d.ts +5 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @studiometa/playground-preview
|
|
2
|
+
|
|
3
|
+
A lightweight web component to embed [`@studiometa/playground`](https://github.com/studiometa/playground) previews anywhere — framework-agnostic, zero configuration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @studiometa/playground-preview
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Auto-registration
|
|
14
|
+
|
|
15
|
+
Import the package to automatically register the `<playground-preview>` custom element:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import '@studiometa/playground-preview';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Manual registration
|
|
22
|
+
|
|
23
|
+
Import the class and register it yourself with a custom tag name:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { PlaygroundPreview } from '@studiometa/playground-preview/element';
|
|
27
|
+
|
|
28
|
+
customElements.define('my-playground', PlaygroundPreview);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Short content via attributes
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<playground-preview
|
|
35
|
+
html="<h1>Hello</h1>"
|
|
36
|
+
script="console.log('hi')"
|
|
37
|
+
css="h1 { color: red }"></playground-preview>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Long content via `<script>` children
|
|
41
|
+
|
|
42
|
+
For longer code snippets, use `<script>` elements with custom `type` attributes. The browser won't execute them, and the component reads their `textContent`:
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<playground-preview height="80vh" theme="dark">
|
|
46
|
+
<script type="playground/html">
|
|
47
|
+
<div class="flex items-center gap-4">
|
|
48
|
+
<h1>Hello World</h1>
|
|
49
|
+
<p>Some longer content here...</p>
|
|
50
|
+
</div>
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<script type="playground/script">
|
|
54
|
+
import { Base, createApp } from '@studiometa/js-toolkit';
|
|
55
|
+
|
|
56
|
+
class App extends Base {
|
|
57
|
+
static config = { name: 'App' };
|
|
58
|
+
mounted() { console.log('mounted!'); }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default createApp(App);
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<script type="playground/css">
|
|
65
|
+
@import "tailwindcss";
|
|
66
|
+
h1 { @apply text-4xl font-bold; }
|
|
67
|
+
</script>
|
|
68
|
+
</playground-preview>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
When both attributes and `<script>` children are provided for the same language, children take precedence.
|
|
72
|
+
|
|
73
|
+
## Attributes
|
|
74
|
+
|
|
75
|
+
| Attribute | Type | Default | Description |
|
|
76
|
+
| ------------- | --------- | ----------------------------------------- | -------------------------------------------------------- |
|
|
77
|
+
| `html` | `string` | `""` | HTML content |
|
|
78
|
+
| `script` | `string` | `""` | JavaScript content |
|
|
79
|
+
| `css` | `string` | `""` | CSS content |
|
|
80
|
+
| `base-url` | `string` | `https://studiometa-playground.pages.dev` | Playground instance URL |
|
|
81
|
+
| `height` | `string` | `60vh` | Container height |
|
|
82
|
+
| `zoom` | `number` | `0.9` | Initial iframe scale |
|
|
83
|
+
| `theme` | `string` | `auto` | `dark`, `light`, or `auto` (uses `prefers-color-scheme`) |
|
|
84
|
+
| `no-controls` | `boolean` | `false` | Hide zoom/reload/open controls |
|
|
85
|
+
| `header` | `string` | — | Passed through to the playground URL |
|
|
86
|
+
|
|
87
|
+
## Controls
|
|
88
|
+
|
|
89
|
+
When `no-controls` is not set, the component displays a toolbar with:
|
|
90
|
+
|
|
91
|
+
- **Zoom in / out / reset** — adjust the iframe scale
|
|
92
|
+
- **Reload** — re-creates the iframe
|
|
93
|
+
- **Open in new window** — opens the full playground with editors enabled
|
|
94
|
+
|
|
95
|
+
## Theming
|
|
96
|
+
|
|
97
|
+
The component uses Shadow DOM for style encapsulation. You can customize its appearance via CSS custom properties:
|
|
98
|
+
|
|
99
|
+
```css
|
|
100
|
+
playground-preview {
|
|
101
|
+
--pg-bg: #f4f4f5;
|
|
102
|
+
--pg-bg-dark: #27272a;
|
|
103
|
+
--pg-controls-bg: rgba(0, 0, 0, 0.55);
|
|
104
|
+
--pg-controls-bg-hover: rgba(0, 0, 0, 0.75);
|
|
105
|
+
--pg-controls-color: #fff;
|
|
106
|
+
--pg-border-color: #e4e4e7;
|
|
107
|
+
--pg-border-color-dark: #3f3f46;
|
|
108
|
+
--pg-border-radius: 8px;
|
|
109
|
+
--pg-loader-color: #a1a1aa;
|
|
110
|
+
--pg-transition-duration: 200ms;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Lazy loading
|
|
115
|
+
|
|
116
|
+
The iframe is only created when the component scrolls into the viewport (using `IntersectionObserver` with a `100px` root margin). A spinner is displayed while the iframe loads.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PlaygroundPreview } from './playground-preview.js';
|