@framv/slides 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mens Reversa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # SLIDES\n\nPart of the Framv framework.\n
@@ -0,0 +1,287 @@
1
+ // src/slide.ts
2
+ var STYLES = `
3
+ :host {
4
+ display: flex;
5
+ position: absolute;
6
+ inset: 0;
7
+ align-items: center;
8
+ justify-content: center;
9
+ flex-direction: column;
10
+ opacity: 0;
11
+ transition: opacity 0.4s ease, transform 0.4s ease;
12
+ transform: translateX(30px);
13
+ pointer-events: none;
14
+ }
15
+ :host([active]) {
16
+ opacity: 1;
17
+ transform: translateX(0);
18
+ pointer-events: auto;
19
+ }
20
+ :host([transition="fade"]) {
21
+ transition: opacity 0.5s ease;
22
+ transform: none;
23
+ }
24
+ :host([transition="slide-up"]) {
25
+ transform: translateY(40px);
26
+ }
27
+ :host([transition="slide-up"][active]) {
28
+ transform: translateY(0);
29
+ }
30
+ :host([transition="zoom"]) {
31
+ transform: scale(0.9);
32
+ }
33
+ :host([transition="zoom"][active]) {
34
+ transform: scale(1);
35
+ }
36
+ `;
37
+ var FramvSlideElement = class extends HTMLElement {
38
+ static observedAttributes = ["background", "active", "transition"];
39
+ connectedCallback() {
40
+ if (!this.shadowRoot) {
41
+ this.attachShadow({ mode: "open" }).innerHTML = `<style>${STYLES}</style><slot></slot>`;
42
+ }
43
+ this._applyBackground();
44
+ }
45
+ attributeChangedCallback(name) {
46
+ if (name === "background") this._applyBackground();
47
+ }
48
+ set active(val) {
49
+ if (val) this.setAttribute("active", "");
50
+ else this.removeAttribute("active");
51
+ }
52
+ get active() {
53
+ return this.hasAttribute("active");
54
+ }
55
+ _applyBackground() {
56
+ const bg = this.getAttribute("background");
57
+ if (bg) this.style.background = bg;
58
+ }
59
+ };
60
+ if (!customElements.get("framv-slide")) {
61
+ customElements.define("framv-slide", FramvSlideElement);
62
+ }
63
+
64
+ // src/element.ts
65
+ var STYLES2 = `
66
+ :host {
67
+ display: block;
68
+ position: relative;
69
+ background: #000;
70
+ overflow: hidden;
71
+ font-family: system-ui, sans-serif;
72
+ }
73
+ .framv-slides-stage {
74
+ position: relative;
75
+ width: 100%;
76
+ height: 100%;
77
+ }
78
+ .framv-slides-controls {
79
+ position: absolute; bottom: 0; left: 0; right: 0;
80
+ display: flex; align-items: center; gap: 12px;
81
+ padding: 12px 20px;
82
+ background: linear-gradient(transparent, rgba(0,0,0,0.6));
83
+ color: #fff; font: 13px system-ui;
84
+ opacity: 0; transition: opacity 0.3s;
85
+ z-index: 20;
86
+ }
87
+ :host(:hover) .framv-slides-controls,
88
+ :host([controls]) .framv-slides-controls { opacity: 1; }
89
+ .framv-slides-controls button {
90
+ background: rgba(255,255,255,0.15); border: none;
91
+ color: #fff; cursor: pointer;
92
+ padding: 8px 14px; font: inherit; border-radius: 6px;
93
+ transition: background 0.2s;
94
+ }
95
+ .framv-slides-controls button:hover { background: rgba(255,255,255,0.3); }
96
+ .framv-slides-controls button:disabled { opacity: 0.3; cursor: default; }
97
+ .framv-counter {
98
+ margin: 0 auto; opacity: 0.7; font-variant-numeric: tabular-nums;
99
+ }
100
+ .framv-progress {
101
+ position: absolute; bottom: 0; left: 0;
102
+ height: 3px; background: #ff79c6;
103
+ transition: width 0.3s ease;
104
+ z-index: 21;
105
+ }
106
+ .framv-fullscreen-badge {
107
+ position: absolute; top: 12px; right: 12px;
108
+ background: rgba(0,0,0,0.5); color: #fff;
109
+ padding: 4px 12px; border-radius: 4px;
110
+ font: 11px system-ui; opacity: 0; transition: opacity 0.3s;
111
+ z-index: 15;
112
+ }
113
+ :host(:hover) .framv-fullscreen-badge { opacity: 1; }
114
+ .framv-exporting-overlay {
115
+ position: absolute; inset: 0;
116
+ background: rgba(0,0,0,0.8); display: flex;
117
+ align-items: center; justify-content: center;
118
+ color: #fff; font: 14px system-ui; z-index: 30;
119
+ gap: 8px;
120
+ }
121
+ `;
122
+ var FramvSlidesElement = class extends HTMLElement {
123
+ static observedAttributes = ["transition"];
124
+ _currentIndex = 0;
125
+ _slides = [];
126
+ _stage;
127
+ _controls;
128
+ _counter;
129
+ _progress;
130
+ _prevBtn;
131
+ _nextBtn;
132
+ _fullscreenBtn;
133
+ _exportBtn;
134
+ _autoplayTimer = null;
135
+ _exporting = false;
136
+ get currentIndex() {
137
+ return this._currentIndex;
138
+ }
139
+ get slideCount() {
140
+ return this._slides.length;
141
+ }
142
+ get transition() {
143
+ return this.getAttribute("transition") ?? "slide";
144
+ }
145
+ connectedCallback() {
146
+ const w = this.getAttribute("width") ?? "1920";
147
+ const h = this.getAttribute("height") ?? "1080";
148
+ this.style.aspectRatio = `${w} / ${h}`;
149
+ this.style.maxWidth = "100%";
150
+ this.innerHTML = `
151
+ <style>${STYLES2}</style>
152
+ <div class="framv-fullscreen-badge">framv slides \xB7 ${w}x${h}</div>
153
+ <div class="framv-slides-stage"></div>
154
+ <div class="framv-progress"></div>
155
+ <div class="framv-slides-controls">
156
+ <button class="btn-prev">\u25C0 Prev</button>
157
+ <button class="btn-next">Next \u25B6</button>
158
+ <span class="framv-counter">1 / 1</span>
159
+ <button class="btn-fullscreen">\u26F6 Fullscreen</button>
160
+ <button class="btn-export" style="border:1px solid #ff79c6;color:#ff79c6">\u2B07 Export PDF</button>
161
+ </div>
162
+ `;
163
+ this._stage = this.querySelector(".framv-slides-stage");
164
+ this._controls = this.querySelector(".framv-slides-controls");
165
+ this._counter = this.querySelector(".framv-counter");
166
+ this._progress = this.querySelector(".framv-progress");
167
+ this._prevBtn = this.querySelector(".btn-prev");
168
+ this._nextBtn = this.querySelector(".btn-next");
169
+ this._fullscreenBtn = this.querySelector(".btn-fullscreen");
170
+ this._exportBtn = this.querySelector(".btn-export");
171
+ this._slides = Array.from(this.querySelectorAll("framv-slide"));
172
+ this._slides.forEach((slide, i) => {
173
+ slide.setAttribute("transition", slide.getAttribute("transition") ?? this.transition);
174
+ this._stage.appendChild(slide);
175
+ });
176
+ this._showSlide(0);
177
+ this._prevBtn.addEventListener("click", () => this.prev());
178
+ this._nextBtn.addEventListener("click", () => this.next());
179
+ this._fullscreenBtn.addEventListener("click", () => this._toggleFullscreen());
180
+ this._exportBtn.addEventListener("click", () => this._export());
181
+ this.addEventListener("keydown", (e) => {
182
+ if (e.key === "ArrowRight" || e.key === " ") {
183
+ e.preventDefault();
184
+ this.next();
185
+ }
186
+ if (e.key === "ArrowLeft") {
187
+ e.preventDefault();
188
+ this.prev();
189
+ }
190
+ if (e.key === "f" || e.key === "F") {
191
+ e.preventDefault();
192
+ this._toggleFullscreen();
193
+ }
194
+ });
195
+ this.addEventListener("click", (e) => {
196
+ const target = e.target;
197
+ if (target.closest("button, .framv-slides-controls")) return;
198
+ this.next();
199
+ });
200
+ if (this.hasAttribute("autoplay")) {
201
+ const interval = parseInt(this.getAttribute("interval") ?? "5000");
202
+ this._autoplayTimer = setInterval(() => this.next(), interval);
203
+ }
204
+ this._updateCounter();
205
+ }
206
+ disconnectedCallback() {
207
+ if (this._autoplayTimer) clearInterval(this._autoplayTimer);
208
+ }
209
+ attributeChangedCallback(name) {
210
+ if (name === "transition" && this._slides.length > 0) {
211
+ this._slides.forEach((s) => {
212
+ if (!s.hasAttribute("transition")) s.setAttribute("transition", this.transition);
213
+ });
214
+ }
215
+ }
216
+ next() {
217
+ if (this._currentIndex < this._slides.length - 1) {
218
+ this._showSlide(this._currentIndex + 1);
219
+ } else if (this.hasAttribute("loop")) {
220
+ this._showSlide(0);
221
+ }
222
+ }
223
+ prev() {
224
+ if (this._currentIndex > 0) {
225
+ this._showSlide(this._currentIndex - 1);
226
+ } else if (this.hasAttribute("loop")) {
227
+ this._showSlide(this._slides.length - 1);
228
+ }
229
+ }
230
+ goTo(index) {
231
+ if (index >= 0 && index < this._slides.length) {
232
+ this._showSlide(index);
233
+ }
234
+ }
235
+ _showSlide(index) {
236
+ if (this._slides.length === 0) return;
237
+ this._slides.forEach((s) => s.active = false);
238
+ this._currentIndex = index;
239
+ this._slides[index].active = true;
240
+ this._updateCounter();
241
+ }
242
+ _updateCounter() {
243
+ if (this._counter) this._counter.textContent = `${this._currentIndex + 1} / ${this._slides.length}`;
244
+ if (this._progress) this._progress.style.width = `${(this._currentIndex + 1) / this._slides.length * 100}%`;
245
+ if (this._prevBtn) this._prevBtn.disabled = this._currentIndex === 0 && !this.hasAttribute("loop");
246
+ if (this._nextBtn) this._nextBtn.disabled = this._currentIndex === this._slides.length - 1 && !this.hasAttribute("loop");
247
+ }
248
+ _toggleFullscreen() {
249
+ if (document.fullscreenElement) {
250
+ document.exitFullscreen();
251
+ } else {
252
+ this.requestFullscreen();
253
+ }
254
+ }
255
+ async _export() {
256
+ if (this._exporting) return;
257
+ this._exporting = true;
258
+ const w = parseInt(this.getAttribute("width") ?? "1920");
259
+ const h = parseInt(this.getAttribute("height") ?? "1080");
260
+ const overlay = document.createElement("div");
261
+ overlay.className = "framv-exporting-overlay";
262
+ this.appendChild(overlay);
263
+ try {
264
+ const { jsPDF } = await import("jspdf");
265
+ const pdf = new jsPDF({ orientation: "l", unit: "px", format: [w, h] });
266
+ for (let i = 0; i < this._slides.length; i++) {
267
+ if (i > 0) pdf.addPage();
268
+ const slide = this._slides[i];
269
+ overlay.textContent = `Exporting slide ${i + 1}/${this._slides.length}...`;
270
+ await pdf.html(slide, { x: 0, y: 0, width: w, windowWidth: w });
271
+ }
272
+ pdf.save("framv-presentation.pdf");
273
+ } catch (err) {
274
+ console.error("Export failed:", err);
275
+ } finally {
276
+ overlay.remove();
277
+ this._exporting = false;
278
+ }
279
+ }
280
+ };
281
+ if (!customElements.get("framv-slides")) {
282
+ customElements.define("framv-slides", FramvSlidesElement);
283
+ }
284
+ export {
285
+ FramvSlideElement,
286
+ FramvSlidesElement
287
+ };