mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 13:08:28 +00:00
add basic embed package
This commit is contained in:
parent
d752d0eb5e
commit
b01865f0f5
27
packages/embed/README.md
Normal file
27
packages/embed/README.md
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# @strudel.cycles/embed
|
||||||
|
|
||||||
|
This package contains a embeddable web component for the Strudel REPL.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Either install with `npm i @strudel.cycles/embed` or just use a cdn to import the script:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="https://unpkg.com/@strudel.cycles/embed@latest">
|
||||||
|
<strudel-repl>
|
||||||
|
<!--
|
||||||
|
"a4 [a3 c3] a3 c3".color('#F9D649')
|
||||||
|
.sub("<7 12 5 12>".slow(2))
|
||||||
|
.off(1/4,x=>x.add(7).color("#FFFFFF #0C3AA1 #C63928"))
|
||||||
|
.off(1/8,x=>x.add(12).color('#215CB6'))
|
||||||
|
.slow(2)
|
||||||
|
.legato(sine.range(0.3, 2).slow(28))
|
||||||
|
.wave("sawtooth square".fast(2))
|
||||||
|
.filter('lowpass', cosine.range(500,4000).slow(16))
|
||||||
|
.out()
|
||||||
|
.pianoroll({minMidi:20,maxMidi:120,background:'#202124'})
|
||||||
|
-->
|
||||||
|
</strudel-repl>
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that the Code is placed inside HTML comments to prevent the browser from treating it as HTML.
|
||||||
17
packages/embed/embed.js
Normal file
17
packages/embed/embed.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
class Strudel extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
connectedCallback() {
|
||||||
|
setTimeout(() => {
|
||||||
|
const code = (this.innerHTML + '').replace('<!--', '').replace('-->', '').trim();
|
||||||
|
const iframe = document.createElement('iframe');
|
||||||
|
const src = `https://strudel.tidalcycles.org/#${encodeURIComponent(btoa(code))}`;
|
||||||
|
iframe.setAttribute('src', src);
|
||||||
|
iframe.setAttribute('width', '600');
|
||||||
|
iframe.setAttribute('height', '400');
|
||||||
|
this.appendChild(iframe);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
customElements.define('strudel-repl', Strudel);
|
||||||
16
packages/embed/example.html
Normal file
16
packages/embed/example.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<script src="./embed.js"></script>
|
||||||
|
|
||||||
|
<strudel-repl>
|
||||||
|
<!--
|
||||||
|
"a4 [a3 c3] a3 c3".color('#F9D649')
|
||||||
|
.sub("<7 12 5 12>".slow(2))
|
||||||
|
.off(1/4,x=>x.add(7).color("#FFFFFF #0C3AA1 #C63928"))
|
||||||
|
.off(1/8,x=>x.add(12).color('#215CB6'))
|
||||||
|
.slow(2)
|
||||||
|
.legato(sine.range(0.3, 2).slow(28))
|
||||||
|
.wave("sawtooth square".fast(2))
|
||||||
|
.filter('lowpass', cosine.range(500,4000).slow(16))
|
||||||
|
.out()
|
||||||
|
.pianoroll({minMidi:20,maxMidi:120,background:'#202124'})
|
||||||
|
-->
|
||||||
|
</strudel-repl>
|
||||||
25
packages/embed/package.json
Normal file
25
packages/embed/package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "@strudel.cycles/embed",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Embeddable Web Component to load a Strudel REPL into an iframe",
|
||||||
|
"main": "embed.js",
|
||||||
|
"type": "module",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/tidalcycles/strudel.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"tidalcycles",
|
||||||
|
"strudel",
|
||||||
|
"pattern",
|
||||||
|
"livecoding",
|
||||||
|
"algorave"
|
||||||
|
],
|
||||||
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user