@algorisys/tinyfly 0.128.0 → 0.129.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 +12 -4
- package/bin/tinyfly.mjs +47 -1
- package/docs/editor-guide.md +1 -1
- package/docs/examples.md +1 -1
- package/docs/getting-started.md +1 -1
- package/docs/gsap-compat.md +1 -1
- package/docs/llm-guide.md +3 -0
- package/docs/maps.md +2 -2
- package/docs/math.md +1 -1
- package/docs/presenting.md +258 -0
- package/docs/teaching.md +1 -1
- package/lib/addons/characters.js +512 -511
- package/lib/addons/present.js +586 -0
- package/lib/browser/tinyfly.iife.js +65 -15
- package/lib/browser/tinyfly.js +6950 -6446
- package/lib/browser/tinyfly.umd.js +65 -15
- package/lib/types/browser/index.d.ts +4 -0
- package/lib/types/present/deck-labels.d.ts +46 -0
- package/lib/types/present/deck-state.d.ts +128 -0
- package/lib/types/present/deck-styles.d.ts +16 -0
- package/lib/types/present/deck.d.ts +104 -0
- package/lib/types/present/index.d.ts +20 -0
- package/lib/types/present/inline-deck.d.ts +30 -0
- package/lib/types/present/presenter-view.d.ts +29 -0
- package/llms-full.txt +277 -10
- package/llms.txt +35 -34
- package/package.json +5 -1
- package/skills/tinyfly/SKILL.md +3 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
function de(o, t) {
|
|
2
|
+
const e = o && o.length > 0 ? o.slice() : [0];
|
|
3
|
+
for (; e.length <= t; ) e.push(e[e.length - 1]);
|
|
4
|
+
return e;
|
|
5
|
+
}
|
|
6
|
+
class he {
|
|
7
|
+
slides;
|
|
8
|
+
/** The current slide, 0-based */
|
|
9
|
+
index = 0;
|
|
10
|
+
fragmentSteps;
|
|
11
|
+
constructor(t) {
|
|
12
|
+
if (t.length === 0) throw new Error("A deck needs at least one slide");
|
|
13
|
+
this.fragmentSteps = t.map((e) => Math.max(0, e.fragmentSteps ?? 0)), this.slides = t.map((e, n) => {
|
|
14
|
+
const l = de(e.marks, this.fragmentSteps[n]);
|
|
15
|
+
return {
|
|
16
|
+
id: e.id,
|
|
17
|
+
title: e.title ?? e.id,
|
|
18
|
+
notes: e.notes ?? "",
|
|
19
|
+
marks: l,
|
|
20
|
+
steps: l.length - 1,
|
|
21
|
+
step: 0,
|
|
22
|
+
time: l[0],
|
|
23
|
+
target: l[0],
|
|
24
|
+
timers: (e.timers ?? []).map((d) => ({ ...d, state: "idle", startedAt: 0, endedAt: 0 }))
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
get slide() {
|
|
29
|
+
return this.slides[this.index];
|
|
30
|
+
}
|
|
31
|
+
/** True while the current slide's scene clock is still playing to its target. */
|
|
32
|
+
get playing() {
|
|
33
|
+
return this.slide.time < this.slide.target - 1;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Give a slide its marks once its scene is built (scenes are built when first
|
|
37
|
+
* needed). The slide keeps its step, clamped to the new count.
|
|
38
|
+
*/
|
|
39
|
+
setMarks(t, e) {
|
|
40
|
+
const n = this.slides[t];
|
|
41
|
+
n.marks = de(e, this.fragmentSteps[t]), n.steps = n.marks.length - 1, n.step = Math.min(n.step, n.steps), n.time = n.target = n.marks[n.step];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Show slide `index` at `step` (`'last'` for its final step). With `play`, the
|
|
45
|
+
* scene plays into that step from the one before; otherwise it is shown as it
|
|
46
|
+
* ends. Timers on the slide left and the slide shown go back to idle.
|
|
47
|
+
*/
|
|
48
|
+
goTo(t, e = 0, n = {}) {
|
|
49
|
+
const l = Math.max(0, Math.min(this.slides.length - 1, Math.trunc(t) || 0));
|
|
50
|
+
this.resetTimers(this.slide), this.index = l;
|
|
51
|
+
const d = this.slide;
|
|
52
|
+
this.resetTimers(d);
|
|
53
|
+
const k = e === "last" ? d.steps : Math.max(0, Math.min(d.steps, Math.trunc(e) || 0));
|
|
54
|
+
d.step = k, d.target = d.marks[k], d.time = n.play ? k > 0 ? d.marks[k - 1] : 0 : d.target;
|
|
55
|
+
}
|
|
56
|
+
/** The clicker's forward button. */
|
|
57
|
+
next(t) {
|
|
58
|
+
const e = this.slide;
|
|
59
|
+
if (this.playing)
|
|
60
|
+
return e.time = e.target, "snap";
|
|
61
|
+
const n = this.stepTimer();
|
|
62
|
+
return n && n.state === "idle" ? (this.startTimer(n, t), "timer-start") : n && n.state === "running" ? (this.finishTimer(n, t), "timer-end") : e.step < e.steps ? (e.step++, e.target = e.marks[e.step], "step") : this.index < this.slides.length - 1 ? (this.goTo(this.index + 1, 0, { play: !0 }), "slide") : "end";
|
|
63
|
+
}
|
|
64
|
+
/** Back one step, shown as it ends; from a slide's first step, to the end of the slide before. */
|
|
65
|
+
prev() {
|
|
66
|
+
const t = this.slide;
|
|
67
|
+
if (t.step > 0) this.goTo(this.index, t.step - 1);
|
|
68
|
+
else if (this.index > 0) this.goTo(this.index - 1, "last");
|
|
69
|
+
else return !1;
|
|
70
|
+
return !0;
|
|
71
|
+
}
|
|
72
|
+
/** Play the current step again. */
|
|
73
|
+
replay() {
|
|
74
|
+
this.goTo(this.index, this.slide.step, { play: !0 });
|
|
75
|
+
}
|
|
76
|
+
/** The countdown that belongs to the current step, if any. */
|
|
77
|
+
stepTimer() {
|
|
78
|
+
const t = this.slide;
|
|
79
|
+
return t.timers.find((e) => e.step === t.step);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Start a countdown, or end it when it is running: the current step's, or
|
|
83
|
+
* `timer` (one of the current slide's, on a step already reached). False when
|
|
84
|
+
* there is none to toggle.
|
|
85
|
+
*/
|
|
86
|
+
toggleTimer(t, e = this.stepTimer()) {
|
|
87
|
+
return !e || !this.slide.timers.includes(e) || e.step > this.slide.step ? !1 : (e.state === "running" ? this.finishTimer(e, t) : this.startTimer(e, t), !0);
|
|
88
|
+
}
|
|
89
|
+
/** Move the scene clock on by `dt` ms and finish countdowns that have run out. */
|
|
90
|
+
advance(t, e) {
|
|
91
|
+
const n = this.slide;
|
|
92
|
+
n.time < n.target && (n.time = Math.min(n.target, n.time + Math.max(0, t)));
|
|
93
|
+
for (const l of n.timers)
|
|
94
|
+
l.state === "running" && e - l.startedAt >= l.seconds * 1e3 && (l.state = "done", l.endedAt = l.startedAt + l.seconds * 1e3);
|
|
95
|
+
}
|
|
96
|
+
/** The current slide's countdown as a scene sees it: the last one that is running or done. */
|
|
97
|
+
timerFrame(t) {
|
|
98
|
+
let e = null;
|
|
99
|
+
for (const n of this.slide.timers)
|
|
100
|
+
n.state !== "idle" && (e = {
|
|
101
|
+
state: n.state,
|
|
102
|
+
elapsed: t - n.startedAt,
|
|
103
|
+
seconds: n.seconds,
|
|
104
|
+
sinceEnd: n.state === "done" ? t - n.endedAt : 0
|
|
105
|
+
});
|
|
106
|
+
return e;
|
|
107
|
+
}
|
|
108
|
+
/** Seconds left on a countdown, never below 0. */
|
|
109
|
+
secondsLeft(t, e) {
|
|
110
|
+
return t.state === "idle" ? t.seconds : t.state === "done" ? 0 : Math.max(0, Math.min(t.seconds, t.seconds - (e - t.startedAt) / 1e3));
|
|
111
|
+
}
|
|
112
|
+
/** What the next press will do. */
|
|
113
|
+
hint() {
|
|
114
|
+
const t = this.slide, e = this.stepTimer();
|
|
115
|
+
if (e && e.state === "idle") return { kind: "timer-start", seconds: e.seconds };
|
|
116
|
+
if (e && e.state === "running") return { kind: "timer-end" };
|
|
117
|
+
if (t.step < t.steps) return { kind: "step", step: t.step + 1 };
|
|
118
|
+
const n = this.slides[this.index + 1];
|
|
119
|
+
return n ? { kind: "slide", title: n.title } : { kind: "end" };
|
|
120
|
+
}
|
|
121
|
+
startTimer(t, e) {
|
|
122
|
+
t.state = "running", t.startedAt = e, t.endedAt = 0;
|
|
123
|
+
}
|
|
124
|
+
finishTimer(t, e) {
|
|
125
|
+
t.state = "done", t.endedAt = e;
|
|
126
|
+
}
|
|
127
|
+
resetTimers(t) {
|
|
128
|
+
for (const e of t.timers)
|
|
129
|
+
e.state = "idle", e.startedAt = 0, e.endedAt = 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const me = {
|
|
133
|
+
timerStart: "▶ Start {seconds}s timer",
|
|
134
|
+
timerDone: "✓ Time’s up",
|
|
135
|
+
goTo: "Go to {slide}",
|
|
136
|
+
helpTitle: "Keys",
|
|
137
|
+
helpNext: "Next step (also a click)",
|
|
138
|
+
helpPrev: "Back (also a right click)",
|
|
139
|
+
helpGoTo: "Go to a slide",
|
|
140
|
+
helpEnds: "First and last slide",
|
|
141
|
+
helpBlank: "Black or white screen",
|
|
142
|
+
helpFullscreen: "Full screen",
|
|
143
|
+
helpReplay: "Play this step again",
|
|
144
|
+
helpTimer: "Start or end the countdown",
|
|
145
|
+
helpPresenter: "Presenter window",
|
|
146
|
+
helpHelp: "This list",
|
|
147
|
+
presenterTitle: "Presenter · {title}",
|
|
148
|
+
popupBlocked: "Allow pop-ups for this page to open the presenter window.",
|
|
149
|
+
slideOf: "Slide {index} of {total}",
|
|
150
|
+
clicks: "{step}/{steps} clicks",
|
|
151
|
+
timeLeft: "{left} left of {slot}",
|
|
152
|
+
overTime: "over time",
|
|
153
|
+
prev: "◀ Prev",
|
|
154
|
+
next: "Next ▶",
|
|
155
|
+
resetClock: "Reset clock",
|
|
156
|
+
hintTimerStart: "Next: start the {seconds}s timer",
|
|
157
|
+
hintTimerEnd: "Timer running (Next ends it)",
|
|
158
|
+
hintStep: "Next: click {step} on this slide",
|
|
159
|
+
hintSlide: "Next slide: {title}",
|
|
160
|
+
hintEnd: "End of deck"
|
|
161
|
+
};
|
|
162
|
+
function w(o, t) {
|
|
163
|
+
return o.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e);
|
|
164
|
+
}
|
|
165
|
+
const ge = `
|
|
166
|
+
html.tf-deck-page, html.tf-deck-page body { margin: 0; height: 100%; background: #000; overflow: hidden; }
|
|
167
|
+
.tf-deck { position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: hidden; background: var(--tf-deck-bg, #fff); }
|
|
168
|
+
.tf-deck.tf-idle { cursor: none; }
|
|
169
|
+
.tf-deck [data-slide] { position: absolute; inset: 0; opacity: 0; visibility: hidden; background: var(--tf-deck-bg, #fff); transition: opacity .55s ease, visibility 0s linear .55s; }
|
|
170
|
+
.tf-deck [data-slide].tf-current { opacity: 1; visibility: visible; z-index: 2; transition: opacity .55s ease, visibility 0s; }
|
|
171
|
+
.tf-deck canvas[data-scene] { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
|
|
172
|
+
.tf-deck [data-notes] { display: none; }
|
|
173
|
+
.tf-deck [data-step] { opacity: 0; transform: translateY(26px); transition: opacity .5s ease, transform .6s cubic-bezier(.2,.9,.25,1.15); }
|
|
174
|
+
.tf-deck [data-step][data-reveal="pop"] { transform: scale(.6); }
|
|
175
|
+
.tf-deck [data-step][data-reveal="fade"], .tf-deck [data-step][data-reveal="none"] { transform: none; }
|
|
176
|
+
.tf-deck [data-step][data-reveal="none"] { transition: none; }
|
|
177
|
+
.tf-deck [data-step].tf-on { opacity: 1; transform: none; }
|
|
178
|
+
.tf-deck [data-timer] { position: relative; overflow: hidden; min-width: 240px; height: 64px; padding: 0 28px; border: 0; border-radius: 32px; background: var(--tf-deck-accent, #f0812f); color: #fff; font: 700 26px/1 var(--tf-deck-font, inherit); cursor: pointer; }
|
|
179
|
+
.tf-deck [data-timer] i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(255,255,255,.28); }
|
|
180
|
+
.tf-deck [data-timer] span, .tf-deck [data-timer] b { position: relative; }
|
|
181
|
+
.tf-deck [data-timer][data-state="running"] { background: var(--tf-deck-panel, #0e2841); cursor: default; }
|
|
182
|
+
.tf-deck [data-timer][data-state="running"] b { font-size: 40px; font-variant-numeric: tabular-nums; }
|
|
183
|
+
.tf-deck [data-timer][data-state="done"] { background: var(--tf-deck-done, #2e9e48); }
|
|
184
|
+
.tf-deck-progress { position: absolute; left: 0; bottom: 0; height: 8px; width: 0; z-index: 50; background: var(--tf-deck-accent, #f0812f); transition: width .5s ease; }
|
|
185
|
+
.tf-deck-blank { position: absolute; inset: 0; z-index: 90; background: #000; opacity: 0; pointer-events: none; transition: opacity .3s; }
|
|
186
|
+
.tf-deck-blank.tf-white { background: #fff; }
|
|
187
|
+
.tf-deck-blank.tf-on { opacity: 1; }
|
|
188
|
+
.tf-deck-goto { position: absolute; right: 50px; top: 40px; z-index: 95; display: none; padding: 10px 30px; border-radius: 18px; background: var(--tf-deck-panel, #0e2841); color: #fff; font: 800 54px/1.2 var(--tf-deck-font, inherit); }
|
|
189
|
+
.tf-deck-goto.tf-on { display: block; }
|
|
190
|
+
.tf-deck-help { position: absolute; inset: 0; z-index: 99; display: none; box-sizing: border-box; padding: 100px 180px; background: var(--tf-deck-panel, #0e2841); color: #fff; font: 400 30px/1.3 var(--tf-deck-font, inherit); opacity: .96; }
|
|
191
|
+
.tf-deck-help.tf-on { display: block; }
|
|
192
|
+
.tf-deck-help h2 { margin: 0 0 36px; font-size: 52px; }
|
|
193
|
+
.tf-deck-help table { border-collapse: collapse; }
|
|
194
|
+
.tf-deck-help td { padding: 9px 40px 9px 0; vertical-align: top; }
|
|
195
|
+
.tf-deck-help kbd { display: inline-block; margin-right: 6px; padding: 2px 14px; border-radius: 8px; background: #fff; color: #0e2841; font: 700 24px/1.4 var(--tf-deck-font, inherit); }
|
|
196
|
+
`, ke = `
|
|
197
|
+
body { margin: 0; height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background: #0e2841; color: #fff; font-family: "Segoe UI", Inter, Arial, sans-serif; }
|
|
198
|
+
header { display: flex; gap: 40px; align-items: baseline; padding: 22px 34px; background: #071937; }
|
|
199
|
+
#timer { font-size: 64px; font-weight: 800; font-variant-numeric: tabular-nums; }
|
|
200
|
+
#timer.warn { color: #f0812f; }
|
|
201
|
+
#timer.over { color: #ff5a52; }
|
|
202
|
+
#left { font-size: 26px; opacity: .85; }
|
|
203
|
+
#clock { margin-left: auto; font-size: 30px; opacity: .7; }
|
|
204
|
+
main { padding: 28px 34px; overflow: auto; }
|
|
205
|
+
#where { font-size: 22px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #f0812f; }
|
|
206
|
+
#title { margin: 6px 0 18px; font-size: 44px; font-weight: 800; }
|
|
207
|
+
#steps span { display: inline-block; width: 18px; height: 18px; margin-right: 8px; border-radius: 50%; background: #33507a; }
|
|
208
|
+
#steps span.on { background: #f0812f; }
|
|
209
|
+
#notes { max-width: 1100px; font-size: 30px; line-height: 1.45; white-space: pre-line; }
|
|
210
|
+
footer { display: flex; gap: 30px; align-items: center; padding: 18px 34px; background: #071937; font-size: 24px; }
|
|
211
|
+
#next { opacity: .85; }
|
|
212
|
+
button { padding: 10px 22px; border: 0; border-radius: 10px; font: inherit; font-size: 22px; cursor: pointer; }
|
|
213
|
+
`, xe = (o) => Math.min(300 * 1e3, o / 6);
|
|
214
|
+
function J(o) {
|
|
215
|
+
const t = Math.max(0, Math.round(o / 1e3));
|
|
216
|
+
return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`;
|
|
217
|
+
}
|
|
218
|
+
function C(o) {
|
|
219
|
+
return o.replace(/[&<>"]/g, (t) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[t]);
|
|
220
|
+
}
|
|
221
|
+
function ve(o) {
|
|
222
|
+
const { state: t, labels: e } = o;
|
|
223
|
+
let n = null, l = 0, d;
|
|
224
|
+
const k = () => n !== null && !n.closed, m = (r) => n.document.getElementById(r);
|
|
225
|
+
function v() {
|
|
226
|
+
if (!k()) {
|
|
227
|
+
clearInterval(d);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const r = Date.now() - l, g = m("timer");
|
|
231
|
+
if (g.textContent = J(r), o.slotMinutes) {
|
|
232
|
+
const a = o.slotMinutes * 60 * 1e3;
|
|
233
|
+
g.className = r > a ? "over" : r > a - xe(a) ? "warn" : "", m("left").textContent = r > a ? e.overTime : w(e.timeLeft, { left: J(a - r), slot: J(a) });
|
|
234
|
+
}
|
|
235
|
+
m("clock").textContent = (/* @__PURE__ */ new Date()).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
236
|
+
}
|
|
237
|
+
function y() {
|
|
238
|
+
const r = t.hint();
|
|
239
|
+
return r.kind === "timer-start" ? w(e.hintTimerStart, { seconds: r.seconds }) : r.kind === "timer-end" ? e.hintTimerEnd : r.kind === "step" ? w(e.hintStep, { step: r.step }) : r.kind === "slide" ? w(e.hintSlide, { title: r.title }) : e.hintEnd;
|
|
240
|
+
}
|
|
241
|
+
function c() {
|
|
242
|
+
if (!k()) return;
|
|
243
|
+
const r = t.slide;
|
|
244
|
+
m("where").textContent = w(e.slideOf, { index: t.index + 1, total: t.slides.length }), m("title").textContent = r.title;
|
|
245
|
+
const g = Array.from({ length: r.steps }, (a, T) => `<span class="${T < r.step ? "on" : ""}"></span>`).join("");
|
|
246
|
+
m("steps").innerHTML = r.steps ? `${g} <small>${C(w(e.clicks, { step: r.step, steps: r.steps }))}</small>` : "", m("notes").textContent = r.notes, m("next").textContent = y(), v();
|
|
247
|
+
}
|
|
248
|
+
function p() {
|
|
249
|
+
if (k()) {
|
|
250
|
+
n.focus();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (n = window.open("", "tinyfly-presenter", "width=1200,height=760"), !n) {
|
|
254
|
+
window.alert(e.popupBlocked);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const r = n.document;
|
|
258
|
+
r.open(), r.write(
|
|
259
|
+
`<!doctype html><meta charset="utf-8"><title>${C(w(e.presenterTitle, { title: o.title }))}</title><style>${ke}</style><header><div id="timer">0:00</div><div id="left"></div><div id="clock"></div></header><main><div id="where"></div><div id="title"></div><div id="steps"></div><p id="notes"></p></main><footer><button id="prev">${C(e.prev)}</button><button id="nextb">${C(e.next)}</button><button id="reset">${C(e.resetClock)}</button><div id="next"></div></footer>`
|
|
260
|
+
), r.close(), l = Date.now(), m("prev").onclick = o.onPrev, m("nextb").onclick = o.onNext, m("reset").onclick = () => {
|
|
261
|
+
l = Date.now(), v();
|
|
262
|
+
}, r.addEventListener("keydown", o.onKey), clearInterval(d), d = setInterval(v, 500), c();
|
|
263
|
+
}
|
|
264
|
+
function h() {
|
|
265
|
+
clearInterval(d), k() && n.close(), n = null;
|
|
266
|
+
}
|
|
267
|
+
return { open: p, update: c, close: h };
|
|
268
|
+
}
|
|
269
|
+
const be = ["ArrowRight", "ArrowDown", "PageDown", " ", "Enter", "n", "N"], ye = ["ArrowLeft", "ArrowUp", "PageUp", "Backspace"], we = "a, button, input, select, textarea, label, [data-timer]", Te = 2e3, Ee = 2500, Se = 100;
|
|
270
|
+
function Q(o) {
|
|
271
|
+
return o ? Math.max(0, Number(o.dataset.step) || 0) : 0;
|
|
272
|
+
}
|
|
273
|
+
function Le(o) {
|
|
274
|
+
if (o.querySelector("style[data-tinyfly-deck]")) return;
|
|
275
|
+
const t = o.createElement("style");
|
|
276
|
+
t.setAttribute("data-tinyfly-deck", ""), t.textContent = ge, o.head.appendChild(t);
|
|
277
|
+
}
|
|
278
|
+
function $e(o, t) {
|
|
279
|
+
const e = [
|
|
280
|
+
[["→", "Space", "N"], t.helpNext],
|
|
281
|
+
[["←", "Backspace"], t.helpPrev],
|
|
282
|
+
[["1…9", "Enter"], t.helpGoTo],
|
|
283
|
+
[["Home", "End"], t.helpEnds],
|
|
284
|
+
[["B", "W"], t.helpBlank],
|
|
285
|
+
[["F"], t.helpFullscreen],
|
|
286
|
+
[["R"], t.helpReplay],
|
|
287
|
+
[["T"], t.helpTimer],
|
|
288
|
+
[["P"], t.helpPresenter],
|
|
289
|
+
[["?"], t.helpHelp]
|
|
290
|
+
], n = o.ownerDocument, l = n.createElement("h2");
|
|
291
|
+
l.textContent = t.helpTitle;
|
|
292
|
+
const d = n.createElement("table");
|
|
293
|
+
for (const [k, m] of e) {
|
|
294
|
+
const v = d.insertRow(), y = v.insertCell();
|
|
295
|
+
for (const c of k) {
|
|
296
|
+
const p = n.createElement("kbd");
|
|
297
|
+
p.textContent = c, y.appendChild(p);
|
|
298
|
+
}
|
|
299
|
+
v.insertCell().textContent = m;
|
|
300
|
+
}
|
|
301
|
+
o.replaceChildren(l, d);
|
|
302
|
+
}
|
|
303
|
+
function Re(o, t = {}) {
|
|
304
|
+
const e = typeof o == "string" ? document.querySelector(o) : o;
|
|
305
|
+
if (!e) throw new Error(`createDeck: no element matches ${String(o)}`);
|
|
306
|
+
const n = e, l = n.ownerDocument, d = l.defaultView, k = t.width ?? 1920, m = t.height ?? 1080, v = { ...me, ...t.labels }, y = t.scenes ?? {}, c = t.hash !== !1, p = t.fit !== !1 && n.parentElement === l.body;
|
|
307
|
+
Le(l), n.classList.add("tf-deck"), n.style.width = `${k}px`, n.style.height = `${m}px`, p && l.documentElement.classList.add("tf-deck-page");
|
|
308
|
+
const h = [...n.querySelectorAll("[data-slide]")];
|
|
309
|
+
if (h.length === 0) throw new Error("createDeck: the deck has no [data-slide] elements");
|
|
310
|
+
const r = [], g = h.map((i) => {
|
|
311
|
+
const s = [...i.querySelectorAll("[data-step]")], f = [...i.querySelectorAll("[data-timer]")];
|
|
312
|
+
return r.push({ el: i, fragments: s, timerButtons: f, canvas: i.querySelector("canvas[data-scene]"), ctx: null, scene: null, built: !1 }), {
|
|
313
|
+
id: i.dataset.slide || "",
|
|
314
|
+
title: i.dataset.title,
|
|
315
|
+
notes: [...i.querySelectorAll("[data-notes]")].map((u) => (u.textContent || "").trim()).join(`
|
|
316
|
+
|
|
317
|
+
`),
|
|
318
|
+
fragmentSteps: s.reduce((u, x) => Math.max(u, Q(x)), 0),
|
|
319
|
+
timers: f.map((u) => ({
|
|
320
|
+
step: Q(u.closest("[data-step]")),
|
|
321
|
+
seconds: Number(u.dataset.timer) > 0 ? Number(u.dataset.timer) : 30
|
|
322
|
+
}))
|
|
323
|
+
};
|
|
324
|
+
}), a = new he(g), T = (i) => {
|
|
325
|
+
const s = l.createElement("div");
|
|
326
|
+
return s.className = i, n.appendChild(s), s;
|
|
327
|
+
}, ne = T("tf-deck-progress"), L = T("tf-deck-blank"), H = T("tf-deck-goto"), A = T("tf-deck-help");
|
|
328
|
+
$e(A, v);
|
|
329
|
+
let $ = -1, N = !1;
|
|
330
|
+
function D(i) {
|
|
331
|
+
const s = r[i];
|
|
332
|
+
if (!s || s.built) return;
|
|
333
|
+
s.built = !0;
|
|
334
|
+
const f = a.slides[i].id, u = y[f];
|
|
335
|
+
if (!u) return;
|
|
336
|
+
try {
|
|
337
|
+
s.scene = u({ width: k, height: m, el: s.el });
|
|
338
|
+
} catch (b) {
|
|
339
|
+
console.error(`tinyfly deck: the scene for slide "${f}" failed to build`, b);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const x = s.scene;
|
|
343
|
+
x.draw && (s.canvas || (s.canvas = l.createElement("canvas"), s.canvas.setAttribute("data-scene", ""), s.el.appendChild(s.canvas)), s.canvas.width = k, s.canvas.height = m, s.ctx = s.canvas.getContext("2d")), a.setMarks(i, x.marks);
|
|
344
|
+
}
|
|
345
|
+
function fe(i, s, f) {
|
|
346
|
+
i.dataset.state = s.state;
|
|
347
|
+
const u = i.closest("[data-step]");
|
|
348
|
+
if (u && (u.dataset.timerState = s.state), s.state === "running") {
|
|
349
|
+
const x = a.secondsLeft(s, f), b = (100 * (1 - x / s.seconds)).toFixed(1);
|
|
350
|
+
i.innerHTML = `<i style="width:${b}%"></i><b>${Math.ceil(x) || 1}</b>`;
|
|
351
|
+
} else {
|
|
352
|
+
const x = l.createElement("span");
|
|
353
|
+
x.textContent = s.state === "done" ? v.timerDone : w(v.timerStart, { seconds: s.seconds }), i.replaceChildren(x);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function K(i, s) {
|
|
357
|
+
r[i].timerButtons.forEach((f, u) => fe(f, a.slides[i].timers[u], s));
|
|
358
|
+
}
|
|
359
|
+
function E(i = d.performance.now()) {
|
|
360
|
+
const s = a.index, f = a.slide;
|
|
361
|
+
$ !== s && ($ >= 0 && (r[$].el.classList.remove("tf-current"), K($, i)), r[s].el.classList.add("tf-current"), $ = s, r[s + 1] && !r[s + 1].built && d.setTimeout(() => !N && D(s + 1), 50));
|
|
362
|
+
for (const x of r[s].fragments) {
|
|
363
|
+
const b = Q(x);
|
|
364
|
+
x.classList.toggle("tf-on", f.step >= b), x.classList.toggle("tf-now", f.step === b);
|
|
365
|
+
}
|
|
366
|
+
r[s].el.dataset.currentStep = String(f.step), K(s, i);
|
|
367
|
+
const u = a.slides.length - 1;
|
|
368
|
+
if (ne.style.width = `${u > 0 ? s / u * 100 : 100}%`, c)
|
|
369
|
+
try {
|
|
370
|
+
d.history.replaceState(null, "", `#${s + 1}${f.step ? `.${f.step}` : ""}`);
|
|
371
|
+
} catch {
|
|
372
|
+
}
|
|
373
|
+
B.update(), t.onChange?.(le);
|
|
374
|
+
}
|
|
375
|
+
function S(i, s, f) {
|
|
376
|
+
const u = Math.max(0, Math.min(a.slides.length - 1, i));
|
|
377
|
+
D(u), a.goTo(u, s, { play: f }), E();
|
|
378
|
+
}
|
|
379
|
+
function z() {
|
|
380
|
+
a.slide.step >= a.slide.steps && D(a.index + 1), a.next(d.performance.now()), E();
|
|
381
|
+
}
|
|
382
|
+
function P() {
|
|
383
|
+
a.slide.step === 0 && D(a.index - 1), a.prev() && E();
|
|
384
|
+
}
|
|
385
|
+
function O(i) {
|
|
386
|
+
a.toggleTimer(d.performance.now(), i ?? a.stepTimer()) && E();
|
|
387
|
+
}
|
|
388
|
+
function q(i = "black") {
|
|
389
|
+
const s = i === "white", f = !(L.classList.contains("tf-on") && L.classList.contains("tf-white") === s);
|
|
390
|
+
L.classList.toggle("tf-white", s), L.classList.toggle("tf-on", f);
|
|
391
|
+
}
|
|
392
|
+
function pe() {
|
|
393
|
+
l.fullscreenElement ? l.exitFullscreen() : l.documentElement.requestFullscreen?.().catch(() => {
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
let R = "", j;
|
|
397
|
+
function _(i) {
|
|
398
|
+
R = i, H.classList.toggle("tf-on", i !== ""), H.textContent = w(v.goTo, { slide: i }), clearTimeout(j), i && (j = setTimeout(() => _(""), Ee));
|
|
399
|
+
}
|
|
400
|
+
function U(i) {
|
|
401
|
+
if (i.ctrlKey || i.metaKey || i.altKey) return;
|
|
402
|
+
const s = i.key;
|
|
403
|
+
if (/^[0-9]$/.test(s)) _(R + s);
|
|
404
|
+
else if (s === "Enter" && R)
|
|
405
|
+
S(parseInt(R, 10) - 1, 0, !0), _("");
|
|
406
|
+
else if (be.includes(s)) z();
|
|
407
|
+
else if (ye.includes(s)) P();
|
|
408
|
+
else if (s === "Home") S(0, 0, !0);
|
|
409
|
+
else if (s === "End") S(a.slides.length - 1, "last", !1);
|
|
410
|
+
else if (s === "b" || s === "B" || s === ".") q("black");
|
|
411
|
+
else if (s === "w" || s === "W" || s === ",") q("white");
|
|
412
|
+
else if (s === "f" || s === "F" || s === "F5") pe();
|
|
413
|
+
else if (s === "r" || s === "R")
|
|
414
|
+
a.replay(), E();
|
|
415
|
+
else if (s === "t" || s === "T") O();
|
|
416
|
+
else if (s === "p" || s === "P") B.open();
|
|
417
|
+
else if (s === "?" || s === "h" || s === "H") A.classList.toggle("tf-on");
|
|
418
|
+
else if (s === "Escape")
|
|
419
|
+
A.classList.remove("tf-on"), L.classList.remove("tf-on"), _("");
|
|
420
|
+
else return;
|
|
421
|
+
i.preventDefault();
|
|
422
|
+
}
|
|
423
|
+
function se(i) {
|
|
424
|
+
const s = i.target, f = s?.closest("[data-timer]");
|
|
425
|
+
if (f) {
|
|
426
|
+
const u = r[a.index].timerButtons.indexOf(f);
|
|
427
|
+
u >= 0 && O(a.slide.timers[u]);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
s?.closest(we) || z();
|
|
431
|
+
}
|
|
432
|
+
function ie(i) {
|
|
433
|
+
i.preventDefault(), P();
|
|
434
|
+
}
|
|
435
|
+
let W;
|
|
436
|
+
function re() {
|
|
437
|
+
n.classList.remove("tf-idle"), clearTimeout(W), W = setTimeout(() => n.classList.add("tf-idle"), Te);
|
|
438
|
+
}
|
|
439
|
+
function G() {
|
|
440
|
+
const i = n.parentElement, s = p || !i ? d.innerWidth : i.clientWidth, f = p || !i ? d.innerHeight : i.clientHeight;
|
|
441
|
+
if (!(s > 0 && f > 0)) return;
|
|
442
|
+
const u = Math.min(s / k, f / m), x = (s - k * u) / 2, b = (f - m * u) / 2;
|
|
443
|
+
n.style.transform = `translate(${x}px, ${b}px) scale(${u})`;
|
|
444
|
+
}
|
|
445
|
+
let V = null;
|
|
446
|
+
function oe(i) {
|
|
447
|
+
const s = V === null ? 0 : Math.min(Se, i - V);
|
|
448
|
+
V = i;
|
|
449
|
+
const f = a.slide, u = f.timers.filter((M) => M.state === "running").length;
|
|
450
|
+
a.advance(s, i), f.timers.filter((M) => M.state === "running").length !== u ? E(i) : u > 0 && K(a.index, i);
|
|
451
|
+
const b = r[a.index], F = b.scene;
|
|
452
|
+
if (!F) return;
|
|
453
|
+
const ce = { time: f.time, clock: i, step: f.step, timer: a.timerFrame(i), width: k, height: m };
|
|
454
|
+
try {
|
|
455
|
+
F.update?.(ce), F.draw && b.ctx && (b.ctx.clearRect(0, 0, k, m), F.draw(b.ctx, ce));
|
|
456
|
+
} catch (M) {
|
|
457
|
+
console.error(`tinyfly deck: the scene for slide "${f.id}" failed and was stopped`, M), b.scene = null;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
let Y = 0;
|
|
461
|
+
function ae(i) {
|
|
462
|
+
N || (oe(i), Y = d.requestAnimationFrame(ae));
|
|
463
|
+
}
|
|
464
|
+
function ue() {
|
|
465
|
+
if (!N) {
|
|
466
|
+
N = !0, d.cancelAnimationFrame(Y), clearTimeout(j), clearTimeout(W), d.removeEventListener("keydown", U), d.removeEventListener("resize", G), d.removeEventListener("mousemove", re), n.removeEventListener("click", se), n.removeEventListener("contextmenu", ie), B.close();
|
|
467
|
+
for (const i of [ne, L, H, A]) i.remove();
|
|
468
|
+
p && l.documentElement.classList.remove("tf-deck-page");
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const le = {
|
|
472
|
+
state: a,
|
|
473
|
+
element: n,
|
|
474
|
+
next: z,
|
|
475
|
+
prev: P,
|
|
476
|
+
goTo: (i, s = 0) => S(i - 1, s, !0),
|
|
477
|
+
seek(i, s = 0, f) {
|
|
478
|
+
S(i - 1, s, !1), f !== void 0 && (a.slide.time = a.slide.target = f);
|
|
479
|
+
},
|
|
480
|
+
replay() {
|
|
481
|
+
a.replay(), E();
|
|
482
|
+
},
|
|
483
|
+
toggleTimer: () => O(),
|
|
484
|
+
blank: q,
|
|
485
|
+
openPresenter: () => B.open(),
|
|
486
|
+
render: oe,
|
|
487
|
+
destroy: ue
|
|
488
|
+
}, B = ve({
|
|
489
|
+
state: a,
|
|
490
|
+
labels: v,
|
|
491
|
+
title: t.title ?? l.title,
|
|
492
|
+
slotMinutes: t.slotMinutes,
|
|
493
|
+
onNext: z,
|
|
494
|
+
onPrev: P,
|
|
495
|
+
onKey: U
|
|
496
|
+
});
|
|
497
|
+
t.keyboard !== !1 && d.addEventListener("keydown", U), n.addEventListener("click", se), n.addEventListener("contextmenu", ie), d.addEventListener("mousemove", re), t.fit !== !1 && (d.addEventListener("resize", G), G());
|
|
498
|
+
const X = c ? /^#(\d+)(?:\.(\d+))?/.exec(d.location.hash) : null;
|
|
499
|
+
return X ? S(Number(X[1]) - 1, Number(X[2] || 0), !1) : S(0, 0, !0), t.autoStart !== !1 && (Y = d.requestAnimationFrame(ae)), le;
|
|
500
|
+
}
|
|
501
|
+
const Me = {
|
|
502
|
+
png: "image/png",
|
|
503
|
+
jpg: "image/jpeg",
|
|
504
|
+
jpeg: "image/jpeg",
|
|
505
|
+
gif: "image/gif",
|
|
506
|
+
webp: "image/webp",
|
|
507
|
+
avif: "image/avif",
|
|
508
|
+
svg: "image/svg+xml",
|
|
509
|
+
ico: "image/x-icon",
|
|
510
|
+
woff: "font/woff",
|
|
511
|
+
woff2: "font/woff2",
|
|
512
|
+
ttf: "font/ttf",
|
|
513
|
+
otf: "font/otf",
|
|
514
|
+
mp3: "audio/mpeg",
|
|
515
|
+
wav: "audio/wav",
|
|
516
|
+
ogg: "audio/ogg",
|
|
517
|
+
mp4: "video/mp4",
|
|
518
|
+
webm: "video/webm"
|
|
519
|
+
}, Ce = /<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi, Ae = /(<style\b[^>]*>)([\s\S]*?)(<\/style\s*>)/gi, Ne = /<link\b[^>]*>/gi, De = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)"'\s]+))\s*\)/gi;
|
|
520
|
+
function Z(o, t) {
|
|
521
|
+
const e = new RegExp(`(?:^|\\s)${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i").exec(o);
|
|
522
|
+
return e ? e[1] ?? e[2] ?? e[3] : void 0;
|
|
523
|
+
}
|
|
524
|
+
const I = (o) => /^(https?:)?\/\//i.test(o), ee = (o) => o === "" || /^(data:|blob:|about:|javascript:|mailto:|tel:|#)/i.test(o);
|
|
525
|
+
function te(o, t) {
|
|
526
|
+
const e = decodeURIComponent(t.replace(/[?#].*$/, "")), n = [];
|
|
527
|
+
for (const l of `${e.startsWith("/") ? "" : `${o}/`}${e}`.split("/"))
|
|
528
|
+
l === "" || l === "." || (l === ".." && n.length > 0 && n[n.length - 1] !== ".." ? n.pop() : n.push(l));
|
|
529
|
+
return n.join("/");
|
|
530
|
+
}
|
|
531
|
+
const ze = (o) => o.includes("/") ? o.slice(0, o.lastIndexOf("/")) : "", Pe = (o) => (/\.([a-z0-9]+)$/i.exec(o)?.[1] ?? "").toLowerCase();
|
|
532
|
+
function _e(o, t) {
|
|
533
|
+
const e = { html: "", inlined: [], missing: [], remote: [], unsupported: [] }, n = (c, p) => {
|
|
534
|
+
c.includes(p) || c.push(p);
|
|
535
|
+
};
|
|
536
|
+
function l(c, p) {
|
|
537
|
+
if (ee(c)) return c;
|
|
538
|
+
if (I(c))
|
|
539
|
+
return n(e.remote, c), c;
|
|
540
|
+
const h = te(p, c), r = Me[Pe(h)], g = r ? t.readBase64(h) : null;
|
|
541
|
+
return r ? g === null && n(e.missing, h) : n(e.unsupported, `${h} (unknown file type)`), !r || g === null ? c : (n(e.inlined, h), `data:${r};base64,${g}`);
|
|
542
|
+
}
|
|
543
|
+
function d(c, p) {
|
|
544
|
+
return /@import\b/i.test(c) && n(e.unsupported, "@import in a stylesheet"), c.replace(De, (h, r, g, a) => `url("${l(r ?? g ?? a, p)}")`);
|
|
545
|
+
}
|
|
546
|
+
function k(c, p) {
|
|
547
|
+
const h = Z(p, "src");
|
|
548
|
+
if (h === void 0 || ee(h)) return c;
|
|
549
|
+
if (I(h))
|
|
550
|
+
return n(e.remote, h), c;
|
|
551
|
+
const r = te("", h), g = t.readText(r);
|
|
552
|
+
if (g === null)
|
|
553
|
+
return n(e.missing, r), c;
|
|
554
|
+
/\btype\s*=\s*["']?module/i.test(p) && /^\s*(import|export)\b[^;]*\bfrom\b|^\s*import\s*["']/m.test(g) && n(e.unsupported, `${r} (a module that imports other files; bundle it first)`), n(e.inlined, r);
|
|
555
|
+
const a = p.replace(/\s*\bsrc\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i, ""), T = g.replace(/<\/script/gi, "<\\/script").replace(/<!--/g, "<\\!--");
|
|
556
|
+
return `<script${a}>/* ${r} */
|
|
557
|
+
${T}
|
|
558
|
+
<\/script>`;
|
|
559
|
+
}
|
|
560
|
+
function m(c) {
|
|
561
|
+
const p = Z(c, "href"), h = (Z(c, "rel") ?? "").toLowerCase();
|
|
562
|
+
if (p === void 0 || ee(p)) return c;
|
|
563
|
+
if (h.split(/\s+/).includes("stylesheet")) {
|
|
564
|
+
if (I(p))
|
|
565
|
+
return n(e.remote, p), c;
|
|
566
|
+
const r = te("", p), g = t.readText(r);
|
|
567
|
+
return g === null ? (n(e.missing, r), c) : (n(e.inlined, r), `<style>/* ${r} */
|
|
568
|
+
${d(g, ze(r)).replace(/<\/style/gi, "<\\/style")}
|
|
569
|
+
</style>`);
|
|
570
|
+
}
|
|
571
|
+
return /icon/.test(h) ? c.replace(p, l(p, "")) : (I(p) && /^(preload|modulepreload|prefetch|preconnect|dns-prefetch)$/.test(h) && n(e.remote, p), c);
|
|
572
|
+
}
|
|
573
|
+
function v(c) {
|
|
574
|
+
return /\ssrcset\s*=/i.test(c) && n(e.unsupported, "srcset (use one src)"), c.replace(Ne, m).replace(Ae, (p, h, r, g) => `${h}${d(r, "")}${g}`).replace(/(\s(?:src|poster)\s*=\s*)(?:"([^"]*)"|'([^']*)')/gi, (p, h, r, g) => `${h}"${l(r ?? g, "")}"`).replace(/(\sstyle\s*=\s*)"([^"]*)"/gi, (p, h, r) => `${h}"${d(r, "").replace(/"/g, "'")}"`);
|
|
575
|
+
}
|
|
576
|
+
let y = 0;
|
|
577
|
+
for (const c of o.matchAll(Ce))
|
|
578
|
+
e.html += v(o.slice(y, c.index)), e.html += k(c[0], c[1]), y = c.index + c[0].length;
|
|
579
|
+
return e.html += v(o.slice(y)), e;
|
|
580
|
+
}
|
|
581
|
+
export {
|
|
582
|
+
me as DEFAULT_DECK_LABELS,
|
|
583
|
+
he as DeckState,
|
|
584
|
+
Re as createDeck,
|
|
585
|
+
_e as inlineDeck
|
|
586
|
+
};
|