widgies 0.1.0
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 +105 -0
- package/dist/affirmation.d.ts +1 -0
- package/dist/affirmation.js +129 -0
- package/dist/affirmation.min.js +129 -0
- package/dist/ambient.d.ts +1 -0
- package/dist/ambient.js +191 -0
- package/dist/ambient.min.js +191 -0
- package/dist/calculator.d.ts +1 -0
- package/dist/calculator.js +97 -0
- package/dist/calculator.min.js +97 -0
- package/dist/chunk-3F3FJ7VN.js +82 -0
- package/dist/chunk-BP7C5X5K.min.js +82 -0
- package/dist/core/BaseWidget.d.ts +15 -0
- package/dist/core/theme.d.ts +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/qr-code.d.ts +1 -0
- package/dist/qr-code.js +125 -0
- package/dist/qr-code.min.js +125 -0
- package/dist/qrcode-5PUKNF3Z.js +3 -0
- package/dist/qrcode-DXXPLUCT.min.js +3 -0
- package/dist/random-number.d.ts +1 -0
- package/dist/random-number.js +109 -0
- package/dist/random-number.min.js +109 -0
- package/dist/timer.d.ts +1 -0
- package/dist/timer.js +153 -0
- package/dist/timer.min.js +153 -0
- package/dist/widgets/affirmation.d.ts +21 -0
- package/dist/widgets/ambient.d.ts +34 -0
- package/dist/widgets/calculator.d.ts +18 -0
- package/dist/widgets/qr-code.d.ts +22 -0
- package/dist/widgets/random-number.d.ts +17 -0
- package/dist/widgets/timer.d.ts +30 -0
- package/dist/widgies.js +882 -0
- package/dist/widgies.min.js +882 -0
- package/package.json +83 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
import{a as o}from"./chunk-BP7C5X5K.min.js";var n=class extends o{constructor(){super(...arguments);this.audioContext=null;this.oscillators=[];this.gainNodes=[];this.gainNode=null;this.isPlaying=!1;this.currentSound="rain";this.playButton=null;this.soundSelect=null;this.volumeSlider=null;this.sounds={rain:{name:"Rain",icon:"\u{1F327}\uFE0F"},ocean:{name:"Ocean Waves",icon:"\u{1F30A}"},forest:{name:"Forest",icon:"\u{1F332}"},river:{name:"River",icon:"\u{1F3DE}\uFE0F"},campfire:{name:"Crackling Campfire",icon:"\u{1F525}"}}}render(){this.shadow.innerHTML="";let t=this.createStyleSheet();t&&this.shadow.appendChild(t);let e=this.getAttribute("sound")||"rain";e in this.sounds&&(this.currentSound=e);let i=document.createElement("div");i.innerHTML=`
|
2
|
+
<div class="ambient" role="application" aria-label="Ambient sound player">
|
3
|
+
<div class="sound-display">
|
4
|
+
<span class="sound-icon">${this.sounds[this.currentSound].icon}</span>
|
5
|
+
<span class="sound-name">${this.sounds[this.currentSound].name}</span>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<div class="controls">
|
9
|
+
<select class="sound-select" aria-label="Choose ambient sound">
|
10
|
+
${Object.entries(this.sounds).map(([a,s])=>`<option value="${a}" ${a===this.currentSound?"selected":""}>${s.icon} ${s.name}</option>`).join("")}
|
11
|
+
</select>
|
12
|
+
|
13
|
+
<button class="play-btn" aria-label="Play or pause ambient sound">
|
14
|
+
<span class="play-icon">\u25B6</span>
|
15
|
+
<span class="pause-icon" style="display: none">\u23F8</span>
|
16
|
+
</button>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="volume-control">
|
20
|
+
<label>
|
21
|
+
<span class="volume-label">\u{1F50A} Volume</span>
|
22
|
+
<input type="range" class="volume-slider" min="0" max="100" value="50" aria-label="Volume control">
|
23
|
+
</label>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div class="status" aria-live="polite" aria-label="Player status">
|
27
|
+
Ready to play
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
`,this.shadow.appendChild(i),this.playButton=this.shadow.querySelector(".play-btn"),this.soundSelect=this.shadow.querySelector(".sound-select"),this.volumeSlider=this.shadow.querySelector(".volume-slider")}attachEventListeners(){this.playButton?.addEventListener("click",()=>{this.togglePlayback()}),this.soundSelect?.addEventListener("change",()=>{this.changeSound(this.soundSelect.value)}),this.volumeSlider?.addEventListener("input",()=>{this.updateVolume()}),this.addEventListener("keydown",t=>{t.key===" "&&(t.preventDefault(),this.togglePlayback())})}async initAudioContext(){this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),this.audioContext.state==="suspended"&&await this.audioContext.resume(),this.gainNode||(this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination))}createWhiteNoise(){if(!this.audioContext)throw new Error("AudioContext not initialized");let t=this.audioContext.sampleRate*2,e=this.audioContext.createBuffer(1,t,this.audioContext.sampleRate),i=e.getChannelData(0);for(let s=0;s<t;s++)i[s]=Math.random()*2-1;let a=this.audioContext.createBufferSource();return a.buffer=e,a.loop=!0,a}createRainSound(){let t=this.createWhiteNoise(),e=this.audioContext.createBiquadFilter();return e.type="lowpass",e.frequency.value=1e3,t.connect(e),e.connect(this.gainNode),t}createOceanSound(){let t=this.createWhiteNoise(),e=this.audioContext.createBiquadFilter();e.type="lowpass",e.frequency.value=400;let i=this.audioContext.createOscillator(),a=this.audioContext.createGain();return i.frequency.value=.1,a.gain.value=200,i.connect(a),a.connect(e.frequency),t.connect(e),e.connect(this.gainNode),i.start(),t}createForestSound(){let t=this.createWhiteNoise(),e=this.audioContext.createBiquadFilter();return e.type="bandpass",e.frequency.value=800,e.Q.value=.5,t.connect(e),e.connect(this.gainNode),t}createCampfireSound(){let t=this.createWhiteNoise(),e=this.audioContext.createBiquadFilter();return e.type="lowpass",e.frequency.value=300,t.connect(e),e.connect(this.gainNode),t}async togglePlayback(){try{await this.initAudioContext(),this.isPlaying?this.stopSound():await this.playSound()}catch{this.updateStatus("Audio not available")}}async playSound(){if(!this.audioContext||!this.gainNode)return;let t=this.sounds[this.currentSound],e=parseInt(this.volumeSlider?.value||"50")/100;this.gainNode.gain.setValueAtTime(e*.3,this.audioContext.currentTime);let i;switch(this.currentSound){case"rain":i=this.createRainSound();break;case"ocean":i=this.createOceanSound();break;case"forest":i=this.createForestSound();break;case"campfire":i=this.createCampfireSound();break;case"river":i=this.createForestSound();break;default:i=this.createRainSound()}i.start(),this.oscillators=[i],this.isPlaying=!0,this.updatePlayButton(),this.updateStatus(`Playing ${t.name}`),this.dispatchEvent(new CustomEvent("ambient-started",{detail:{sound:this.currentSound,volume:e},bubbles:!0}))}stopSound(){this.oscillators.forEach(t=>{this.audioContext&&t.stop&&t.stop(this.audioContext.currentTime+.1)}),this.gainNode&&this.audioContext&&this.gainNode.gain.linearRampToValueAtTime(0,this.audioContext.currentTime+.1),this.oscillators=[],this.gainNodes=[],this.isPlaying=!1,this.updatePlayButton(),this.updateStatus("Stopped"),this.dispatchEvent(new CustomEvent("ambient-stopped",{detail:{sound:this.currentSound},bubbles:!0}))}changeSound(t){let e=this.isPlaying;this.isPlaying&&this.stopSound(),this.currentSound=t,this.updateSoundDisplay(),e&&setTimeout(()=>this.playSound(),200),this.dispatchEvent(new CustomEvent("ambient-changed",{detail:{sound:this.currentSound},bubbles:!0}))}updateVolume(){if(!this.volumeSlider||!this.isPlaying||!this.gainNode||!this.audioContext)return;let t=parseInt(this.volumeSlider.value)/100;this.gainNode.gain.linearRampToValueAtTime(t*.3,this.audioContext.currentTime+.1)}updatePlayButton(){let t=this.shadow.querySelector(".play-icon"),e=this.shadow.querySelector(".pause-icon");t&&e&&(this.isPlaying?(t.style.display="none",e.style.display="inline"):(t.style.display="inline",e.style.display="none"))}updateSoundDisplay(){let t=this.shadow.querySelector(".sound-icon"),e=this.shadow.querySelector(".sound-name"),i=this.sounds[this.currentSound];t&&(t.textContent=i.icon),e&&(e.textContent=i.name)}updateStatus(t){let e=this.shadow.querySelector(".status");e&&(e.textContent=t)}static get observedAttributes(){return["sound"]}attributeChangedCallback(t,e,i){t==="sound"&&i&&i in this.sounds&&(this.changeSound(i),this.soundSelect&&(this.soundSelect.value=i))}disconnectedCallback(){super.disconnectedCallback(),this.isPlaying&&this.stopSound(),this.audioContext&&this.audioContext.close()}getStyles(){return`
|
31
|
+
${this.getBaseStyles()}
|
32
|
+
|
33
|
+
.ambient {
|
34
|
+
width: 300px;
|
35
|
+
text-align: center;
|
36
|
+
}
|
37
|
+
|
38
|
+
.sound-display {
|
39
|
+
display: flex;
|
40
|
+
align-items: center;
|
41
|
+
justify-content: center;
|
42
|
+
gap: 0.75rem;
|
43
|
+
margin-bottom: 1.5rem;
|
44
|
+
padding: 1rem;
|
45
|
+
background: linear-gradient(135deg,
|
46
|
+
var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 10%,
|
47
|
+
transparent 50%);
|
48
|
+
border-radius: var(--widgies-radius, 0.5rem);
|
49
|
+
border: 1px solid color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 30%, transparent);
|
50
|
+
}
|
51
|
+
|
52
|
+
.sound-icon {
|
53
|
+
font-size: 2rem;
|
54
|
+
}
|
55
|
+
|
56
|
+
.sound-name {
|
57
|
+
font-size: 1.2rem;
|
58
|
+
font-weight: 600;
|
59
|
+
color: var(--widgies-accent, var(--widgies-accent-light, #6c4cff));
|
60
|
+
}
|
61
|
+
|
62
|
+
.controls {
|
63
|
+
display: flex;
|
64
|
+
gap: 1rem;
|
65
|
+
margin-bottom: 1.5rem;
|
66
|
+
align-items: center;
|
67
|
+
}
|
68
|
+
|
69
|
+
.sound-select {
|
70
|
+
flex: 1;
|
71
|
+
padding: 0.75rem;
|
72
|
+
border: 1px solid color-mix(in srgb, var(--widgies-text, var(--widgies-text-light, #1a1a1a)) 30%, transparent);
|
73
|
+
border-radius: var(--widgies-radius, 0.5rem);
|
74
|
+
background: var(--widgies-surface, var(--widgies-surface-light, #ffffffe6));
|
75
|
+
color: var(--widgies-text, var(--widgies-text-light, #1a1a1a));
|
76
|
+
font: inherit;
|
77
|
+
}
|
78
|
+
|
79
|
+
.sound-select:focus {
|
80
|
+
outline: 2px solid var(--widgies-accent, var(--widgies-accent-light, #6c4cff));
|
81
|
+
outline-offset: 1px;
|
82
|
+
}
|
83
|
+
|
84
|
+
.play-btn {
|
85
|
+
width: 60px;
|
86
|
+
height: 60px;
|
87
|
+
border-radius: 50%;
|
88
|
+
font-size: 1.5rem;
|
89
|
+
display: flex;
|
90
|
+
align-items: center;
|
91
|
+
justify-content: center;
|
92
|
+
padding: 0;
|
93
|
+
box-shadow: 0 4px 12px color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 25%, transparent);
|
94
|
+
}
|
95
|
+
|
96
|
+
.volume-control {
|
97
|
+
margin-bottom: 1rem;
|
98
|
+
}
|
99
|
+
|
100
|
+
.volume-control label {
|
101
|
+
display: flex;
|
102
|
+
flex-direction: column;
|
103
|
+
gap: 0.5rem;
|
104
|
+
align-items: center;
|
105
|
+
}
|
106
|
+
|
107
|
+
.volume-label {
|
108
|
+
font-size: 0.9rem;
|
109
|
+
font-weight: 500;
|
110
|
+
}
|
111
|
+
|
112
|
+
.volume-slider {
|
113
|
+
width: 100%;
|
114
|
+
height: 8px;
|
115
|
+
border-radius: 4px;
|
116
|
+
background: color-mix(in srgb, var(--widgies-text, var(--widgies-text-light, #1a1a1a)) 20%, transparent);
|
117
|
+
outline: none;
|
118
|
+
-webkit-appearance: none;
|
119
|
+
}
|
120
|
+
|
121
|
+
.volume-slider::-webkit-slider-thumb {
|
122
|
+
-webkit-appearance: none;
|
123
|
+
width: 20px;
|
124
|
+
height: 20px;
|
125
|
+
border-radius: 50%;
|
126
|
+
background: var(--widgies-accent, var(--widgies-accent-light, #6c4cff));
|
127
|
+
cursor: pointer;
|
128
|
+
box-shadow: 0 2px 6px color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 40%, transparent);
|
129
|
+
}
|
130
|
+
|
131
|
+
.volume-slider::-moz-range-thumb {
|
132
|
+
width: 20px;
|
133
|
+
height: 20px;
|
134
|
+
border-radius: 50%;
|
135
|
+
background: var(--widgies-accent, var(--widgies-accent-light, #6c4cff));
|
136
|
+
cursor: pointer;
|
137
|
+
border: none;
|
138
|
+
box-shadow: 0 2px 6px color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 40%, transparent);
|
139
|
+
}
|
140
|
+
|
141
|
+
.status {
|
142
|
+
font-size: 0.9rem;
|
143
|
+
color: color-mix(in srgb, var(--widgies-text, var(--widgies-text-light, #1a1a1a)) 70%, transparent);
|
144
|
+
font-style: italic;
|
145
|
+
}
|
146
|
+
|
147
|
+
@media (prefers-color-scheme: dark) {
|
148
|
+
.sound-display {
|
149
|
+
background: linear-gradient(135deg,
|
150
|
+
var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 10%,
|
151
|
+
transparent 50%);
|
152
|
+
border-color: color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 30%, transparent);
|
153
|
+
}
|
154
|
+
|
155
|
+
.sound-name {
|
156
|
+
color: var(--widgies-accent, var(--widgies-accent-dark, #a88bff));
|
157
|
+
}
|
158
|
+
|
159
|
+
.sound-select {
|
160
|
+
background: var(--widgies-surface, var(--widgies-surface-dark, #181824e6));
|
161
|
+
color: var(--widgies-text, var(--widgies-text-dark, #f5f5ff));
|
162
|
+
border-color: color-mix(in srgb, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)) 30%, transparent);
|
163
|
+
}
|
164
|
+
|
165
|
+
.sound-select:focus {
|
166
|
+
outline-color: var(--widgies-accent, var(--widgies-accent-dark, #a88bff));
|
167
|
+
}
|
168
|
+
|
169
|
+
.play-btn {
|
170
|
+
box-shadow: 0 4px 12px color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 25%, transparent);
|
171
|
+
}
|
172
|
+
|
173
|
+
.volume-slider {
|
174
|
+
background: color-mix(in srgb, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)) 20%, transparent);
|
175
|
+
}
|
176
|
+
|
177
|
+
.volume-slider::-webkit-slider-thumb {
|
178
|
+
background: var(--widgies-accent, var(--widgies-accent-dark, #a88bff));
|
179
|
+
box-shadow: 0 2px 6px color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 40%, transparent);
|
180
|
+
}
|
181
|
+
|
182
|
+
.volume-slider::-moz-range-thumb {
|
183
|
+
background: var(--widgies-accent, var(--widgies-accent-dark, #a88bff));
|
184
|
+
box-shadow: 0 2px 6px color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 40%, transparent);
|
185
|
+
}
|
186
|
+
|
187
|
+
.status {
|
188
|
+
color: color-mix(in srgb, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)) 70%, transparent);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
`}};function r(){customElements.get("widgies-ambient")||customElements.define("widgies-ambient",n)}r();export{n as AmbientWidget,r as register};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { CalculatorWidget, register } from './widgets/calculator.js';
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import{a as i}from"./chunk-3F3FJ7VN.js";var e=class extends i{constructor(){super(...arguments);this.display=null;this.currentValue="0";this.previousValue="";this.operator="";this.waitingForOperand=!1}render(){this.shadow.innerHTML="";let t=this.createStyleSheet();t&&this.shadow.appendChild(t);let a=document.createElement("div");a.innerHTML=`
|
2
|
+
<div class="calculator">
|
3
|
+
<div class="display" role="textbox" aria-live="polite" aria-label="Calculator display">${this.currentValue}</div>
|
4
|
+
<div class="buttons">
|
5
|
+
<button class="btn clear" data-action="clear">C</button>
|
6
|
+
<button class="btn operator" data-action="operator" data-operator="/">\xF7</button>
|
7
|
+
<button class="btn operator" data-action="operator" data-operator="*">\xD7</button>
|
8
|
+
<button class="btn operator" data-action="operator" data-operator="-">\u2212</button>
|
9
|
+
|
10
|
+
<button class="btn number" data-action="input" data-number="7">7</button>
|
11
|
+
<button class="btn number" data-action="input" data-number="8">8</button>
|
12
|
+
<button class="btn number" data-action="input" data-number="9">9</button>
|
13
|
+
<button class="btn operator" data-action="operator" data-operator="+">+</button>
|
14
|
+
|
15
|
+
<button class="btn number" data-action="input" data-number="4">4</button>
|
16
|
+
<button class="btn number" data-action="input" data-number="5">5</button>
|
17
|
+
<button class="btn number" data-action="input" data-number="6">6</button>
|
18
|
+
<button class="btn equals" data-action="calculate" rowspan="2">=</button>
|
19
|
+
|
20
|
+
<button class="btn number" data-action="input" data-number="1">1</button>
|
21
|
+
<button class="btn number" data-action="input" data-number="2">2</button>
|
22
|
+
<button class="btn number" data-action="input" data-number="3">3</button>
|
23
|
+
|
24
|
+
<button class="btn number zero" data-action="input" data-number="0">0</button>
|
25
|
+
<button class="btn number" data-action="input" data-number=".">.</button>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
`,this.shadow.appendChild(a),this.display=this.shadow.querySelector(".display")}attachEventListeners(){this.shadow.addEventListener("click",t=>{let a=t.target;if(!a.matches("button"))return;let r=a.dataset.action,n=a.dataset.number,o=a.dataset.operator;switch(r){case"input":this.inputNumber(n);break;case"operator":this.inputOperator(o);break;case"calculate":this.calculate();break;case"clear":this.clear();break}})}inputNumber(t){this.waitingForOperand?(this.currentValue=t,this.waitingForOperand=!1):this.currentValue=this.currentValue==="0"?t:this.currentValue+t,this.updateDisplay()}inputOperator(t){let a=parseFloat(this.currentValue);if(this.previousValue==="")this.previousValue=this.currentValue;else if(this.operator){let r=this.performCalculation();this.currentValue=String(r),this.previousValue=this.currentValue,this.updateDisplay()}this.waitingForOperand=!0,this.operator=t}calculate(){if(this.previousValue!==""&&this.operator){let t=this.performCalculation();this.currentValue=String(t),this.previousValue="",this.operator="",this.waitingForOperand=!0,this.updateDisplay()}}performCalculation(){let t=parseFloat(this.previousValue),a=parseFloat(this.currentValue);switch(this.operator){case"+":return t+a;case"-":return t-a;case"*":return t*a;case"/":return a!==0?t/a:0;default:return a}}clear(){this.currentValue="0",this.previousValue="",this.operator="",this.waitingForOperand=!1,this.updateDisplay()}updateDisplay(){this.display&&(this.display.textContent=this.currentValue)}getStyles(){return`
|
29
|
+
${this.getBaseStyles()}
|
30
|
+
|
31
|
+
.calculator {
|
32
|
+
width: 240px;
|
33
|
+
}
|
34
|
+
|
35
|
+
.display {
|
36
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-light, #ffffffe6)) 70%, var(--widgies-text, var(--widgies-text-light, #1a1a1a)));
|
37
|
+
color: var(--widgies-text, var(--widgies-text-light, #1a1a1a));
|
38
|
+
padding: 1rem;
|
39
|
+
margin-bottom: 0.5rem;
|
40
|
+
border-radius: var(--widgies-radius, 0.5rem);
|
41
|
+
text-align: right;
|
42
|
+
font-size: 1.5rem;
|
43
|
+
font-weight: bold;
|
44
|
+
min-height: 1.5rem;
|
45
|
+
overflow: hidden;
|
46
|
+
}
|
47
|
+
|
48
|
+
.buttons {
|
49
|
+
display: grid;
|
50
|
+
grid-template-columns: repeat(4, 1fr);
|
51
|
+
gap: 0.5rem;
|
52
|
+
}
|
53
|
+
|
54
|
+
.btn {
|
55
|
+
height: 3rem;
|
56
|
+
font-size: 1.1rem;
|
57
|
+
font-weight: bold;
|
58
|
+
}
|
59
|
+
|
60
|
+
.btn.zero {
|
61
|
+
grid-column: span 2;
|
62
|
+
}
|
63
|
+
|
64
|
+
.btn.operator {
|
65
|
+
background: color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 80%, black);
|
66
|
+
}
|
67
|
+
|
68
|
+
.btn.equals {
|
69
|
+
background: var(--widgies-accent, var(--widgies-accent-light, #6c4cff));
|
70
|
+
grid-row: span 2;
|
71
|
+
}
|
72
|
+
|
73
|
+
.btn.number {
|
74
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-light, #ffffffe6)) 90%, var(--widgies-text, var(--widgies-text-light, #1a1a1a)));
|
75
|
+
color: var(--widgies-text, var(--widgies-text-light, #1a1a1a));
|
76
|
+
}
|
77
|
+
|
78
|
+
@media (prefers-color-scheme: dark) {
|
79
|
+
.display {
|
80
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-dark, #181824e6)) 70%, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)));
|
81
|
+
color: var(--widgies-text, var(--widgies-text-dark, #f5f5ff));
|
82
|
+
}
|
83
|
+
|
84
|
+
.btn.operator {
|
85
|
+
background: color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 80%, white);
|
86
|
+
}
|
87
|
+
|
88
|
+
.btn.equals {
|
89
|
+
background: var(--widgies-accent, var(--widgies-accent-dark, #a88bff));
|
90
|
+
}
|
91
|
+
|
92
|
+
.btn.number {
|
93
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-dark, #181824e6)) 90%, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)));
|
94
|
+
color: var(--widgies-text, var(--widgies-text-dark, #f5f5ff));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
`}};function s(){customElements.get("widgies-calculator")||customElements.define("widgies-calculator",e)}s();export{e as CalculatorWidget,s as register};
|
@@ -0,0 +1,97 @@
|
|
1
|
+
import{a as i}from"./chunk-BP7C5X5K.min.js";var e=class extends i{constructor(){super(...arguments);this.display=null;this.currentValue="0";this.previousValue="";this.operator="";this.waitingForOperand=!1}render(){this.shadow.innerHTML="";let t=this.createStyleSheet();t&&this.shadow.appendChild(t);let a=document.createElement("div");a.innerHTML=`
|
2
|
+
<div class="calculator">
|
3
|
+
<div class="display" role="textbox" aria-live="polite" aria-label="Calculator display">${this.currentValue}</div>
|
4
|
+
<div class="buttons">
|
5
|
+
<button class="btn clear" data-action="clear">C</button>
|
6
|
+
<button class="btn operator" data-action="operator" data-operator="/">\xF7</button>
|
7
|
+
<button class="btn operator" data-action="operator" data-operator="*">\xD7</button>
|
8
|
+
<button class="btn operator" data-action="operator" data-operator="-">\u2212</button>
|
9
|
+
|
10
|
+
<button class="btn number" data-action="input" data-number="7">7</button>
|
11
|
+
<button class="btn number" data-action="input" data-number="8">8</button>
|
12
|
+
<button class="btn number" data-action="input" data-number="9">9</button>
|
13
|
+
<button class="btn operator" data-action="operator" data-operator="+">+</button>
|
14
|
+
|
15
|
+
<button class="btn number" data-action="input" data-number="4">4</button>
|
16
|
+
<button class="btn number" data-action="input" data-number="5">5</button>
|
17
|
+
<button class="btn number" data-action="input" data-number="6">6</button>
|
18
|
+
<button class="btn equals" data-action="calculate" rowspan="2">=</button>
|
19
|
+
|
20
|
+
<button class="btn number" data-action="input" data-number="1">1</button>
|
21
|
+
<button class="btn number" data-action="input" data-number="2">2</button>
|
22
|
+
<button class="btn number" data-action="input" data-number="3">3</button>
|
23
|
+
|
24
|
+
<button class="btn number zero" data-action="input" data-number="0">0</button>
|
25
|
+
<button class="btn number" data-action="input" data-number=".">.</button>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
`,this.shadow.appendChild(a),this.display=this.shadow.querySelector(".display")}attachEventListeners(){this.shadow.addEventListener("click",t=>{let a=t.target;if(!a.matches("button"))return;let r=a.dataset.action,n=a.dataset.number,o=a.dataset.operator;switch(r){case"input":this.inputNumber(n);break;case"operator":this.inputOperator(o);break;case"calculate":this.calculate();break;case"clear":this.clear();break}})}inputNumber(t){this.waitingForOperand?(this.currentValue=t,this.waitingForOperand=!1):this.currentValue=this.currentValue==="0"?t:this.currentValue+t,this.updateDisplay()}inputOperator(t){let a=parseFloat(this.currentValue);if(this.previousValue==="")this.previousValue=this.currentValue;else if(this.operator){let r=this.performCalculation();this.currentValue=String(r),this.previousValue=this.currentValue,this.updateDisplay()}this.waitingForOperand=!0,this.operator=t}calculate(){if(this.previousValue!==""&&this.operator){let t=this.performCalculation();this.currentValue=String(t),this.previousValue="",this.operator="",this.waitingForOperand=!0,this.updateDisplay()}}performCalculation(){let t=parseFloat(this.previousValue),a=parseFloat(this.currentValue);switch(this.operator){case"+":return t+a;case"-":return t-a;case"*":return t*a;case"/":return a!==0?t/a:0;default:return a}}clear(){this.currentValue="0",this.previousValue="",this.operator="",this.waitingForOperand=!1,this.updateDisplay()}updateDisplay(){this.display&&(this.display.textContent=this.currentValue)}getStyles(){return`
|
29
|
+
${this.getBaseStyles()}
|
30
|
+
|
31
|
+
.calculator {
|
32
|
+
width: 240px;
|
33
|
+
}
|
34
|
+
|
35
|
+
.display {
|
36
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-light, #ffffffe6)) 70%, var(--widgies-text, var(--widgies-text-light, #1a1a1a)));
|
37
|
+
color: var(--widgies-text, var(--widgies-text-light, #1a1a1a));
|
38
|
+
padding: 1rem;
|
39
|
+
margin-bottom: 0.5rem;
|
40
|
+
border-radius: var(--widgies-radius, 0.5rem);
|
41
|
+
text-align: right;
|
42
|
+
font-size: 1.5rem;
|
43
|
+
font-weight: bold;
|
44
|
+
min-height: 1.5rem;
|
45
|
+
overflow: hidden;
|
46
|
+
}
|
47
|
+
|
48
|
+
.buttons {
|
49
|
+
display: grid;
|
50
|
+
grid-template-columns: repeat(4, 1fr);
|
51
|
+
gap: 0.5rem;
|
52
|
+
}
|
53
|
+
|
54
|
+
.btn {
|
55
|
+
height: 3rem;
|
56
|
+
font-size: 1.1rem;
|
57
|
+
font-weight: bold;
|
58
|
+
}
|
59
|
+
|
60
|
+
.btn.zero {
|
61
|
+
grid-column: span 2;
|
62
|
+
}
|
63
|
+
|
64
|
+
.btn.operator {
|
65
|
+
background: color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-light, #6c4cff)) 80%, black);
|
66
|
+
}
|
67
|
+
|
68
|
+
.btn.equals {
|
69
|
+
background: var(--widgies-accent, var(--widgies-accent-light, #6c4cff));
|
70
|
+
grid-row: span 2;
|
71
|
+
}
|
72
|
+
|
73
|
+
.btn.number {
|
74
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-light, #ffffffe6)) 90%, var(--widgies-text, var(--widgies-text-light, #1a1a1a)));
|
75
|
+
color: var(--widgies-text, var(--widgies-text-light, #1a1a1a));
|
76
|
+
}
|
77
|
+
|
78
|
+
@media (prefers-color-scheme: dark) {
|
79
|
+
.display {
|
80
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-dark, #181824e6)) 70%, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)));
|
81
|
+
color: var(--widgies-text, var(--widgies-text-dark, #f5f5ff));
|
82
|
+
}
|
83
|
+
|
84
|
+
.btn.operator {
|
85
|
+
background: color-mix(in srgb, var(--widgies-accent, var(--widgies-accent-dark, #a88bff)) 80%, white);
|
86
|
+
}
|
87
|
+
|
88
|
+
.btn.equals {
|
89
|
+
background: var(--widgies-accent, var(--widgies-accent-dark, #a88bff));
|
90
|
+
}
|
91
|
+
|
92
|
+
.btn.number {
|
93
|
+
background: color-mix(in srgb, var(--widgies-surface, var(--widgies-surface-dark, #181824e6)) 90%, var(--widgies-text, var(--widgies-text-dark, #f5f5ff)));
|
94
|
+
color: var(--widgies-text, var(--widgies-text-dark, #f5f5ff));
|
95
|
+
}
|
96
|
+
}
|
97
|
+
`}};function s(){customElements.get("widgies-calculator")||customElements.define("widgies-calculator",e)}s();export{e as CalculatorWidget,s as register};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
var r=class extends HTMLElement{constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.attachEventListeners(),this.handleAccessibility()}disconnectedCallback(){this.cleanup()}attachEventListeners(){}cleanup(){}handleAccessibility(){this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.addEventListener("keydown",e=>{(e.key==="Enter"||e.key===" ")&&this.handleActivation(e)})}handleActivation(e){}getStyles(){return this.getBaseStyles()}getBaseStyles(){return`
|
2
|
+
:host {
|
3
|
+
${this.getThemeVariables()}
|
4
|
+
display: inline-block;
|
5
|
+
font: var(--widgies-font);
|
6
|
+
border-radius: var(--widgies-radius);
|
7
|
+
background: var(--widgies-surface);
|
8
|
+
color: var(--widgies-text);
|
9
|
+
border: 1px solid color-mix(in srgb, var(--widgies-text) 20%, transparent);
|
10
|
+
padding: 1rem;
|
11
|
+
box-sizing: border-box;
|
12
|
+
overflow: hidden;
|
13
|
+
}
|
14
|
+
|
15
|
+
:host > * {
|
16
|
+
display: flex;
|
17
|
+
flex-direction: column;
|
18
|
+
align-items: center;
|
19
|
+
justify-content: center;
|
20
|
+
width: 100%;
|
21
|
+
height: 100%;
|
22
|
+
box-sizing: border-box;
|
23
|
+
}
|
24
|
+
|
25
|
+
:host(:focus-visible) {
|
26
|
+
outline: 3px solid var(--widgies-accent);
|
27
|
+
outline-offset: 2px;
|
28
|
+
}
|
29
|
+
|
30
|
+
button {
|
31
|
+
background: var(--widgies-accent);
|
32
|
+
color: white;
|
33
|
+
border: none;
|
34
|
+
border-radius: var(--widgies-radius);
|
35
|
+
padding: 0.5rem 1rem;
|
36
|
+
font: inherit;
|
37
|
+
cursor: pointer;
|
38
|
+
transition: background-color 0.2s ease;
|
39
|
+
}
|
40
|
+
|
41
|
+
button:hover {
|
42
|
+
background: color-mix(in srgb, var(--widgies-accent) 80%, black);
|
43
|
+
}
|
44
|
+
|
45
|
+
button:focus-visible {
|
46
|
+
outline: 2px solid var(--widgies-accent);
|
47
|
+
outline-offset: 2px;
|
48
|
+
}
|
49
|
+
|
50
|
+
button:disabled {
|
51
|
+
opacity: 0.5;
|
52
|
+
cursor: not-allowed;
|
53
|
+
}
|
54
|
+
|
55
|
+
@media (prefers-color-scheme: dark) {
|
56
|
+
:host {
|
57
|
+
--widgies-surface: var(--widgies-surface-dark);
|
58
|
+
--widgies-text: var(--widgies-text-dark);
|
59
|
+
--widgies-accent: var(--widgies-accent-dark);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
@media (prefers-reduced-motion: reduce) {
|
64
|
+
*, *::before, *::after {
|
65
|
+
animation-duration: 0.01ms !important;
|
66
|
+
animation-iteration-count: 1 !important;
|
67
|
+
transition-duration: 0.01ms !important;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
`}getThemeVariables(){return`
|
71
|
+
--widgies-font: 16px/1.4 Inter, sans-serif;
|
72
|
+
--widgies-radius: 0.5rem;
|
73
|
+
--widgies-surface-light: #ffffffe6;
|
74
|
+
--widgies-text-light: #1a1a1a;
|
75
|
+
--widgies-accent-light: #6c4cff;
|
76
|
+
--widgies-surface-dark: #181824e6;
|
77
|
+
--widgies-text-dark: #f5f5ff;
|
78
|
+
--widgies-accent-dark: #a88bff;
|
79
|
+
--widgies-surface: var(--widgies-surface-light);
|
80
|
+
--widgies-text: var(--widgies-text-light);
|
81
|
+
--widgies-accent: var(--widgies-accent-light);
|
82
|
+
`}createStyleSheet(){let e=this.getStyles();if("adoptedStyleSheets"in this.shadow)try{let i=new CSSStyleSheet;return i.replaceSync(e),this.shadow.adoptedStyleSheets=[i],null}catch{}let t=document.createElement("style");return t.setAttribute("type","text/css"),t.innerHTML=e,t}};export{r as a};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
var r=class extends HTMLElement{constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.attachEventListeners(),this.handleAccessibility()}disconnectedCallback(){this.cleanup()}attachEventListeners(){}cleanup(){}handleAccessibility(){this.hasAttribute("tabindex")||this.setAttribute("tabindex","0"),this.addEventListener("keydown",e=>{(e.key==="Enter"||e.key===" ")&&this.handleActivation(e)})}handleActivation(e){}getStyles(){return this.getBaseStyles()}getBaseStyles(){return`
|
2
|
+
:host {
|
3
|
+
${this.getThemeVariables()}
|
4
|
+
display: inline-block;
|
5
|
+
font: var(--widgies-font);
|
6
|
+
border-radius: var(--widgies-radius);
|
7
|
+
background: var(--widgies-surface);
|
8
|
+
color: var(--widgies-text);
|
9
|
+
border: 1px solid color-mix(in srgb, var(--widgies-text) 20%, transparent);
|
10
|
+
padding: 1rem;
|
11
|
+
box-sizing: border-box;
|
12
|
+
overflow: hidden;
|
13
|
+
}
|
14
|
+
|
15
|
+
:host > * {
|
16
|
+
display: flex;
|
17
|
+
flex-direction: column;
|
18
|
+
align-items: center;
|
19
|
+
justify-content: center;
|
20
|
+
width: 100%;
|
21
|
+
height: 100%;
|
22
|
+
box-sizing: border-box;
|
23
|
+
}
|
24
|
+
|
25
|
+
:host(:focus-visible) {
|
26
|
+
outline: 3px solid var(--widgies-accent);
|
27
|
+
outline-offset: 2px;
|
28
|
+
}
|
29
|
+
|
30
|
+
button {
|
31
|
+
background: var(--widgies-accent);
|
32
|
+
color: white;
|
33
|
+
border: none;
|
34
|
+
border-radius: var(--widgies-radius);
|
35
|
+
padding: 0.5rem 1rem;
|
36
|
+
font: inherit;
|
37
|
+
cursor: pointer;
|
38
|
+
transition: background-color 0.2s ease;
|
39
|
+
}
|
40
|
+
|
41
|
+
button:hover {
|
42
|
+
background: color-mix(in srgb, var(--widgies-accent) 80%, black);
|
43
|
+
}
|
44
|
+
|
45
|
+
button:focus-visible {
|
46
|
+
outline: 2px solid var(--widgies-accent);
|
47
|
+
outline-offset: 2px;
|
48
|
+
}
|
49
|
+
|
50
|
+
button:disabled {
|
51
|
+
opacity: 0.5;
|
52
|
+
cursor: not-allowed;
|
53
|
+
}
|
54
|
+
|
55
|
+
@media (prefers-color-scheme: dark) {
|
56
|
+
:host {
|
57
|
+
--widgies-surface: var(--widgies-surface-dark);
|
58
|
+
--widgies-text: var(--widgies-text-dark);
|
59
|
+
--widgies-accent: var(--widgies-accent-dark);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
@media (prefers-reduced-motion: reduce) {
|
64
|
+
*, *::before, *::after {
|
65
|
+
animation-duration: 0.01ms !important;
|
66
|
+
animation-iteration-count: 1 !important;
|
67
|
+
transition-duration: 0.01ms !important;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
`}getThemeVariables(){return`
|
71
|
+
--widgies-font: 16px/1.4 Inter, sans-serif;
|
72
|
+
--widgies-radius: 0.5rem;
|
73
|
+
--widgies-surface-light: #ffffffe6;
|
74
|
+
--widgies-text-light: #1a1a1a;
|
75
|
+
--widgies-accent-light: #6c4cff;
|
76
|
+
--widgies-surface-dark: #181824e6;
|
77
|
+
--widgies-text-dark: #f5f5ff;
|
78
|
+
--widgies-accent-dark: #a88bff;
|
79
|
+
--widgies-surface: var(--widgies-surface-light);
|
80
|
+
--widgies-text: var(--widgies-text-light);
|
81
|
+
--widgies-accent: var(--widgies-accent-light);
|
82
|
+
`}createStyleSheet(){let e=this.getStyles();if("adoptedStyleSheets"in this.shadow)try{let i=new CSSStyleSheet;return i.replaceSync(e),this.shadow.adoptedStyleSheets=[i],null}catch{}let t=document.createElement("style");return t.setAttribute("type","text/css"),t.innerHTML=e,t}};export{r as a};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export declare abstract class BaseWidget extends HTMLElement {
|
2
|
+
protected shadow: ShadowRoot;
|
3
|
+
constructor();
|
4
|
+
connectedCallback(): void;
|
5
|
+
disconnectedCallback(): void;
|
6
|
+
protected abstract render(): void;
|
7
|
+
protected attachEventListeners(): void;
|
8
|
+
protected cleanup(): void;
|
9
|
+
protected handleAccessibility(): void;
|
10
|
+
protected handleActivation(event: KeyboardEvent): void;
|
11
|
+
protected getStyles(): string;
|
12
|
+
protected getBaseStyles(): string;
|
13
|
+
private getThemeVariables;
|
14
|
+
protected createStyleSheet(): HTMLStyleElement | null;
|
15
|
+
}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
export declare const themeVariables = "\n /* Light theme (default) */\n --widgies-font: 16px/1.4 Inter, sans-serif;\n --widgies-radius: 0.5rem;\n --widgies-surface-light: #ffffffe6;\n --widgies-text-light: #1a1a1a;\n --widgies-accent-light: #6c4cff;\n\n /* Dark theme */\n --widgies-surface-dark: #181824e6;\n --widgies-text-dark: #f5f5ff;\n --widgies-accent-dark: #a88bff;\n\n /* Auto-switching variables */\n --widgies-surface: var(--widgies-surface-light);\n --widgies-text: var(--widgies-text-light);\n --widgies-accent: var(--widgies-accent-light);\n";
|
2
|
+
export declare const baseWidgetStyles = "\n :host {\n display: inline-block;\n font: var(--widgies-font);\n border-radius: var(--widgies-radius);\n background: var(--widgies-surface);\n color: var(--widgies-text);\n border: 1px solid color-mix(in srgb, var(--widgies-text) 20%, transparent);\n padding: 1rem;\n box-sizing: border-box;\n overflow: hidden;\n }\n\n :host > * {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n }\n\n :host(:focus-visible) {\n outline: 3px solid var(--widgies-accent);\n outline-offset: 2px;\n }\n\n button {\n background: var(--widgies-accent);\n color: white;\n border: none;\n border-radius: var(--widgies-radius);\n padding: 0.5rem 1rem;\n font: inherit;\n cursor: pointer;\n transition: background-color 0.2s ease;\n }\n\n button:hover {\n background: color-mix(in srgb, var(--widgies-accent) 80%, black);\n }\n\n button:focus-visible {\n outline: 2px solid var(--widgies-accent);\n outline-offset: 2px;\n }\n\n button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n\n @media (prefers-color-scheme: dark) {\n :host {\n --widgies-surface: var(--widgies-surface-dark);\n --widgies-text: var(--widgies-text-dark);\n --widgies-accent: var(--widgies-accent-dark);\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n *, *::before, *::after {\n animation-duration: 0.01ms !important;\n animation-iteration-count: 1 !important;\n transition-duration: 0.01ms !important;\n }\n }\n";
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
export { BaseWidget } from './core/BaseWidget.js';
|
2
|
+
export { CalculatorWidget } from './widgets/calculator.js';
|
3
|
+
export { RandomNumberWidget } from './widgets/random-number.js';
|
4
|
+
export { TimerWidget } from './widgets/timer.js';
|
5
|
+
export { AffirmationWidget } from './widgets/affirmation.js';
|
6
|
+
export { AmbientWidget } from './widgets/ambient.js';
|
7
|
+
export { QRCodeWidget } from './widgets/qr-code.js';
|
8
|
+
export declare function registerAllWidgets(): void;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { QRCodeWidget, register } from './widgets/qr-code.js';
|