Skip to content

Commit 0f8cc42

Browse files
committed
refactor
1 parent f290750 commit 0f8cc42

12 files changed

+440
-301
lines changed

index.html

+53-9
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919

2020
<section class="container">
2121
<div class="controls">
22+
<!-- Wave Type Selector -->
2223
<div class="tab-nav">
2324
<ul class="tab-list">
2425
<li>
25-
<button class="wave-type tab active" data-type="wave">
26+
<button
27+
class="wave-type tab active"
28+
data-type="wave"
29+
x-data="curveSelector"
30+
@click="updateCurve"
31+
>
2632
<svg width="16" height="16" viewBox="0 0 16 16">
2733
<path
2834
d="M0 8C2 8 2 4 4 4S6 12 8 12s2-4 4-4 2 4 4 4"
@@ -34,7 +40,12 @@
3440
</button>
3541
</li>
3642
<li>
37-
<button class="wave-type tab" data-type="step">
43+
<button
44+
class="wave-type tab"
45+
data-type="step"
46+
x-data="curveSelector"
47+
@click="updateCurve"
48+
>
3849
<svg width="16" height="16" viewBox="0 0 16 16">
3950
<path
4051
d="M0 8H4V4H8V8H12V4H16"
@@ -46,7 +57,12 @@
4657
</button>
4758
</li>
4859
<li>
49-
<button class="wave-type tab" data-type="peak">
60+
<button
61+
class="wave-type tab"
62+
data-type="peak"
63+
x-data="curveSelector"
64+
@click="updateCurve"
65+
>
5066
<svg width="16" height="16" viewBox="0 0 16 16">
5167
<path
5268
d="M0 8L4 4L8 12L12 4L16 8"
@@ -60,10 +76,16 @@
6076
</ul>
6177
</div>
6278

79+
<!-- Direction Selector -->
6380
<div class="tab-nav">
6481
<ul class="tab-list">
6582
<li>
66-
<button class="direction-btn tab active" data-direction="up">
83+
<button
84+
class="direction-btn tab active"
85+
data-direction="up"
86+
x-data="directionSelector"
87+
@click="updateDirection"
88+
>
6789
<svg
6890
xmlns="http://www.w3.org/2000/svg"
6991
width="20"
@@ -80,7 +102,12 @@
80102
</button>
81103
</li>
82104
<li>
83-
<button class="direction-btn tab" data-direction="down">
105+
<button
106+
class="direction-btn tab"
107+
data-direction="down"
108+
x-data="directionSelector"
109+
@click="updateDirection"
110+
>
84111
<svg
85112
xmlns="http://www.w3.org/2000/svg"
86113
width="20"
@@ -99,6 +126,7 @@
99126
</ul>
100127
</div>
101128

129+
<!-- Complexity Slider -->
102130
<div class="slider-container">
103131
<svg
104132
class="complexity-icon"
@@ -121,6 +149,8 @@
121149
min="2"
122150
max="50"
123151
value="10"
152+
x-data="complexitySlider"
153+
@input="updateValue"
124154
/>
125155

126156
<svg
@@ -138,7 +168,13 @@
138168
</svg>
139169
</div>
140170

141-
<button id="btn-randomize" aria-label="Randomize waves">
171+
<!-- Randomize Button -->
172+
<button
173+
id="btn-randomize"
174+
aria-label="Randomize waves"
175+
x-data="waveActions"
176+
@click="randomize"
177+
>
142178
<svg
143179
xmlns="http://www.w3.org/2000/svg"
144180
width="16"
@@ -158,15 +194,23 @@
158194
</button>
159195
</div>
160196

197+
<!-- Wave Preview -->
161198
<div id="preview">
162199
<svg id="wave-preview" viewBox="0 0 500 200"></svg>
163200
</div>
164201

165-
<div class="button-group">
166-
<button id="btn-download" data-appearance="secondary">
202+
<!-- Action Buttons -->
203+
<div class="button-group" x-data="waveActions">
204+
<button
205+
id="btn-download"
206+
data-appearance="secondary"
207+
@click="downloadSVG"
208+
>
167209
Download
168210
</button>
169-
<button id="btn-create" data-appearance="primary">Create</button>
211+
<button id="btn-create" data-appearance="primary" @click="createPattern">
212+
Create
213+
</button>
170214
</div>
171215
</section>
172216

src/style.css src/assets/style.css

File renamed without changes.

src/common/actions.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Alpine from 'alpinejs';
2+
import type { WaveStore } from './store';
3+
import type { PluginUIEvent } from './types';
4+
5+
const sendMessage = (message: PluginUIEvent) => {
6+
parent.postMessage(message, '*');
7+
};
8+
9+
export const downloadSVG = () => {
10+
const svg = (Alpine.store('wave') as WaveStore).svg;
11+
if (!svg) return;
12+
13+
const svgClone = svg.cloneNode(true) as SVGElement;
14+
svgClone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
15+
16+
const serializer = new XMLSerializer();
17+
let source = serializer.serializeToString(svgClone);
18+
source = `<?xml version="1.0" standalone="no"?>\r\n${source}`;
19+
20+
const blob = new Blob([source], { type: 'image/svg+xml;charset=utf-8' });
21+
const url = URL.createObjectURL(blob);
22+
23+
const timestamp = new Date().toISOString().replace(/[:]/g, '-').slice(0, -5);
24+
const filename = `Waves-${timestamp}.svg`;
25+
26+
const link = document.createElement('a');
27+
link.href = url;
28+
link.download = filename;
29+
document.body.appendChild(link);
30+
link.click();
31+
32+
document.body.removeChild(link);
33+
URL.revokeObjectURL(url);
34+
};
35+
36+
export const createPattern = () => {
37+
const svg = (Alpine.store('wave') as WaveStore).svg;
38+
if (!svg) return;
39+
40+
const data = svg.outerHTML;
41+
sendMessage({
42+
type: 'create-pattern',
43+
content: {
44+
data,
45+
name: 'New Wave',
46+
},
47+
});
48+
};

0 commit comments

Comments
 (0)