moey-ui 0.1.0 → 0.3.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/CHANGELOG.md +33 -3
- package/README.md +6 -4
- package/dist/ai-rules.md +6 -6
- package/dist/llms-full.txt +194 -60
- package/dist/moey.css +138 -59
- package/dist/moey.js +214 -67
- package/dist/moey.min.css +1 -1
- package/dist/moey.min.js +163 -53
- package/package.json +4 -3
- package/src/css/adapt.css +17 -5
- package/src/css/app.css +2 -3
- package/src/css/card.css +5 -2
- package/src/css/chat.css +1 -2
- package/src/css/datatable.css +4 -2
- package/src/css/dialog.css +14 -11
- package/src/css/form-layout.css +1 -2
- package/src/css/gallery.css +57 -15
- package/src/css/helpers.css +9 -0
- package/src/css/keyboard.css +2 -1
- package/src/css/list-group.css +4 -1
- package/src/css/palette.css +4 -3
- package/src/css/player.css +2 -3
- package/src/css/reboot.css +3 -3
- package/src/css/stretched-link.css +3 -2
- package/src/css/tabbar.css +5 -3
- package/src/css/table.css +1 -0
- package/src/css/tokens.css +3 -0
- package/src/js/moey.js +213 -66
package/dist/moey.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Moey v0.
|
|
1
|
+
/*! Moey v0.3.0 | MIT License */
|
|
2
2
|
/* ==========================================================================
|
|
3
3
|
moey.js — Moey's behaviors. Include it once; everything works on its own.
|
|
4
4
|
One listener on the document, so it also works for content added later.
|
|
@@ -26,6 +26,26 @@
|
|
|
26
26
|
setTimeout(finish, ms + 50); // safety net if transitionend never fires
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/* ---- Smooth in-page links ----------------------------------------------------
|
|
30
|
+
A link to a spot on the same page glides there (unless the visitor turned motion off).
|
|
31
|
+
Only that jump is smooth: html.mo-smooth-scroll is on just while it happens, so scripts
|
|
32
|
+
that scroll the page (scrollTo, scrollIntoView) still land at once. */
|
|
33
|
+
doc.addEventListener('click', (e) => {
|
|
34
|
+
const a = e.target.closest?.('a[href*="#"]');
|
|
35
|
+
if (!a || e.defaultPrevented || e.button || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || reducedMotion()) return;
|
|
36
|
+
if ((a.target && a.target !== '_self') || a.hasAttribute('download') || !a.hash || a.origin !== location.origin ||
|
|
37
|
+
a.pathname !== location.pathname || a.search !== location.search) return;
|
|
38
|
+
const html = doc.documentElement;
|
|
39
|
+
html.classList.add('mo-smooth-scroll');
|
|
40
|
+
let timer = 0;
|
|
41
|
+
const off = () => { clearTimeout(timer); removeEventListener('scrollend', off); html.classList.remove('mo-smooth-scroll'); };
|
|
42
|
+
setTimeout(() => { // after the click: did someone else take it over?
|
|
43
|
+
if (e.defaultPrevented) return off();
|
|
44
|
+
addEventListener('scrollend', off, { once: true });
|
|
45
|
+
timer = setTimeout(off, 1500); // no scroll (already there) or no scrollend: tidy up anyway
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
29
49
|
/* ---- Close ------------------------------------------------------------------
|
|
30
50
|
Automatic: a .btn-close closes the alert or dialog it's in. No attribute needed.
|
|
31
51
|
<div class="alert">… <button class="btn-close" aria-label="Close"></button></div>
|
|
@@ -315,7 +335,7 @@
|
|
|
315
335
|
const PHONE = matchMedia('(width < 576px)');
|
|
316
336
|
const sheetState = new WeakMap(); // dialog -> { snaps: [visible px…], index }
|
|
317
337
|
const isSheet = (d) => d.matches('dialog.sheet') ||
|
|
318
|
-
(PHONE.matches && d.matches('dialog.dialog:not(.dialog-center, .dialog-fullscreen)'));
|
|
338
|
+
(PHONE.matches && d.matches('dialog.dialog:not(.dialog-center, .dialog-fullscreen, .dialog-fullscreen-phone)'));
|
|
319
339
|
const canDrag = (d) => d.open && d.dataset.moeyDrag !== 'false' && isSheet(d);
|
|
320
340
|
|
|
321
341
|
function snapPoints(d) {
|
|
@@ -655,9 +675,9 @@
|
|
|
655
675
|
setupMenu(menu, trigger);
|
|
656
676
|
if (isOpen(menu) || !emit(menu, 'open', { trigger })) return;
|
|
657
677
|
menuState.set(menu, { trigger, point });
|
|
658
|
-
|
|
659
|
-
// Phones: a bottom sheet (submenus stay pop-ups inside it)
|
|
678
|
+
// Phones: a bottom sheet (submenus stay pop-ups inside it). Decided before it shows, so it slides up from the start
|
|
660
679
|
const asSheet = !isSubmenu(menu) && adaptAs(menu, trigger, menu.getAttribute('aria-label') || (trigger && (trigger.getAttribute('aria-label') || trigger.textContent.replace(/\s+/g, ' ').trim())));
|
|
680
|
+
try { menu.showPopover({ source: trigger }); } catch { menu.showPopover(); }
|
|
661
681
|
if (!asSheet) { menu.classList.remove('is-sheet'); placeMenu(menu); }
|
|
662
682
|
trigger?.setAttribute('aria-expanded', 'true');
|
|
663
683
|
const list = items(menu);
|
|
@@ -1489,6 +1509,13 @@
|
|
|
1489
1509
|
} else copy.type = 'button';
|
|
1490
1510
|
copy.innerHTML = `<span class="menu-item-label">${link.innerHTML}</span>`;
|
|
1491
1511
|
copy.querySelectorAll('[id]').forEach((n) => n.removeAttribute('id'));
|
|
1512
|
+
// A leading icon becomes the menu item's own icon (menu spacing + muted color), not part of the label
|
|
1513
|
+
const lab = copy.firstElementChild;
|
|
1514
|
+
const lead = [...lab.childNodes].find((n) => n.nodeType !== 3 || n.textContent.trim());
|
|
1515
|
+
if (lead && lead.nodeType === 1 && lead.matches('.mi, svg')) {
|
|
1516
|
+
copy.prepend(lead);
|
|
1517
|
+
lab.innerHTML = lab.innerHTML.trim();
|
|
1518
|
+
}
|
|
1492
1519
|
if (link.matches(':disabled, .disabled, [aria-disabled="true"]')) copy.setAttribute('aria-disabled', 'true');
|
|
1493
1520
|
if (copy.tagName === 'BUTTON' || st.tabs) copy.addEventListener('click', (e) => { e.preventDefault(); link.click(); requestAnimationFrame(() => navFit(st)); });
|
|
1494
1521
|
menu.append(copy);
|
|
@@ -2869,6 +2896,7 @@
|
|
|
2869
2896
|
const st = selState.get(sel);
|
|
2870
2897
|
if (sel.disabled || st.menu.matches(':popover-open')) return;
|
|
2871
2898
|
selBuildMenu(sel);
|
|
2899
|
+
adaptAs(st.menu, st.btn, sheetTitle(sel)); // before it shows: a phone sheet slides up from the start
|
|
2872
2900
|
st.menu.showPopover();
|
|
2873
2901
|
st.btn.setAttribute('aria-expanded', 'true');
|
|
2874
2902
|
st.search = st.menu.querySelector('.select-search input');
|
|
@@ -2877,7 +2905,6 @@
|
|
|
2877
2905
|
st.search.setAttribute('aria-controls', st.menu.id);
|
|
2878
2906
|
st.search.setAttribute('aria-expanded', 'true');
|
|
2879
2907
|
}
|
|
2880
|
-
adaptAs(st.menu, st.btn, sheetTitle(sel));
|
|
2881
2908
|
selPlace(sel);
|
|
2882
2909
|
const current = selItems(st).find((i) => i.getAttribute('aria-selected') === 'true' && i.getAttribute('aria-disabled') !== 'true') || selEnabled(st)[0];
|
|
2883
2910
|
selSetActive(sel, current);
|
|
@@ -4311,6 +4338,16 @@
|
|
|
4311
4338
|
new ResizeObserver(() => { st.winDirty = true; again(); }).observe(scroll);
|
|
4312
4339
|
}
|
|
4313
4340
|
dtHead(st);
|
|
4341
|
+
// Real sizes for the sticky parts: group headers stick right under the header row, and with
|
|
4342
|
+
// checkboxes the fixed name column starts right after the checkbox column (no gap, no overlap)
|
|
4343
|
+
const measure = () => {
|
|
4344
|
+
const head = table.tHead, first = head?.rows[0]?.cells[0];
|
|
4345
|
+
if (!head || !head.offsetParent) return;
|
|
4346
|
+
root.style.setProperty('--mo-datatable-head', `${head.getBoundingClientRect().height}px`);
|
|
4347
|
+
if (first) root.style.setProperty('--mo-datatable-first', `${first.getBoundingClientRect().width}px`);
|
|
4348
|
+
};
|
|
4349
|
+
new ResizeObserver(measure).observe(table.tHead);
|
|
4350
|
+
new ResizeObserver(measure).observe(table);
|
|
4314
4351
|
dtFillFilters(st);
|
|
4315
4352
|
dtStates.set(root, st);
|
|
4316
4353
|
st.url || st.fetcher ? dtLoad(st) : dtRender(st);
|
|
@@ -5533,8 +5570,8 @@
|
|
|
5533
5570
|
st.mode = 'days';
|
|
5534
5571
|
st.picking = false;
|
|
5535
5572
|
st.hover = null;
|
|
5573
|
+
adaptAs(st.pop, st.btn, sheetTitle(st.range ? st.host : st.inputs[0])); // before it shows: a phone sheet slides up from the start
|
|
5536
5574
|
st.pop.showPopover();
|
|
5537
|
-
adaptAs(st.pop, st.btn, sheetTitle(st.range ? st.host : st.inputs[0]));
|
|
5538
5575
|
st.btn.setAttribute('aria-expanded', 'true');
|
|
5539
5576
|
// Two months: when the end date is in the next month, show both
|
|
5540
5577
|
dpRender(st, { focus: true });
|
|
@@ -7929,11 +7966,13 @@
|
|
|
7929
7966
|
const sortHorizontal = (list) => { const its = sortItems(list); if (its.length < 2) return false; const a = its[0].getBoundingClientRect(), b = its[1].getBoundingClientRect(); return Math.abs(a.top - b.top) < a.height / 2; };
|
|
7930
7967
|
let sortFlipUntil = 0; // while items slide to their new places, their positions aren't final yet
|
|
7931
7968
|
function sortFlip(lists, change) {
|
|
7932
|
-
|
|
7969
|
+
const relayout = () => lists.forEach((l) => msStates.has(l) && msLayout(msStates.get(l))); // masonry places its items itself
|
|
7970
|
+
if (reducedMotion()) { change(); relayout(); return; }
|
|
7933
7971
|
sortFlipUntil = performance.now() + 170;
|
|
7934
7972
|
const els = lists.flatMap((l) => sortItems(l)).filter((x) => !x.classList.contains('is-sorting'));
|
|
7935
7973
|
const before = new Map(els.map((x) => [x, x.getBoundingClientRect()]));
|
|
7936
7974
|
change();
|
|
7975
|
+
relayout();
|
|
7937
7976
|
els.forEach((x) => { const a = before.get(x), b = x.getBoundingClientRect(); if (a.left !== b.left || a.top !== b.top) x.animate([{ translate: `${a.left - b.left}px ${a.top - b.top}px` }, { translate: '0 0' }], { duration: 160, easing: 'cubic-bezier(.2,0,0,1)' }); });
|
|
7938
7977
|
}
|
|
7939
7978
|
function sortGroup(list) { const g = list.dataset.moeySortable; return g && g !== '' && g !== 'true' ? [...doc.querySelectorAll(`[data-moey-sortable="${CSS.escape(g)}"]`)] : [list]; }
|
|
@@ -8212,8 +8251,9 @@
|
|
|
8212
8251
|
if (st.field.disabled || st.menu.matches(':popover-open')) return;
|
|
8213
8252
|
tpRender(st);
|
|
8214
8253
|
menuState.set(st.menu, { trigger: st.wrap });
|
|
8254
|
+
const asSheet = adaptAs(st.menu, st.field, sheetTitle(st.input) || 'Time'); // before it shows: a phone sheet slides up from the start
|
|
8215
8255
|
st.menu.showPopover();
|
|
8216
|
-
if (!
|
|
8256
|
+
if (!asSheet) placeMenu(st.menu);
|
|
8217
8257
|
st.field.setAttribute('aria-expanded', 'true');
|
|
8218
8258
|
tpActive(st, st.active);
|
|
8219
8259
|
}
|
|
@@ -8984,46 +9024,107 @@
|
|
|
8984
9024
|
.observe(doc.body, { childList: true, subtree: true });
|
|
8985
9025
|
};
|
|
8986
9026
|
|
|
8987
|
-
/* ----
|
|
8988
|
-
.
|
|
8989
|
-
|
|
8990
|
-
(grid-cols-2 md:grid-cols-4) or automatic (--mo-
|
|
8991
|
-
.
|
|
8992
|
-
|
|
9027
|
+
/* ---- Griddy -------------------------------------------------------------------------------
|
|
9028
|
+
.griddy[data-moey-griddy]: items of different heights packed into columns with no gaps, in
|
|
9029
|
+
reading order (keyboard and screen readers follow the page). Columns: the grid utilities
|
|
9030
|
+
(grid-cols-2 md:grid-cols-4) or automatic (--mo-griddy-min). Items may span columns (span-2);
|
|
9031
|
+
.griddy-dense back-fills holes; .griddy-glide makes items already on the page slide to their
|
|
9032
|
+
new place when the layout changes. Where the browser has CSS masonry, it's used as is.
|
|
9033
|
+
From code: Moey.griddy(el) → { layout() }. The old names (.masonry, .masonry-dense,
|
|
9034
|
+
data-moey-masonry, Moey.masonry) still work. */
|
|
8993
9035
|
const msStates = new WeakMap();
|
|
8994
9036
|
const MS_NATIVE = CSS.supports?.('grid-template-rows', 'masonry');
|
|
9037
|
+
const GRIDDY = '[data-moey-griddy], [data-moey-masonry]';
|
|
9038
|
+
// The real layout size: a transform (an entrance animation, scale) or zoom doesn't change it,
|
|
9039
|
+
// and fractions of a pixel are kept (offsetHeight would round them, which shows at 125% / 150%)
|
|
9040
|
+
const msHeight = (it) => {
|
|
9041
|
+
const c = getComputedStyle(it), px = (v) => parseFloat(v) || 0;
|
|
9042
|
+
const box = c.boxSizing === 'border-box' ? 0 : px(c.paddingTop) + px(c.paddingBottom) + px(c.borderTopWidth) + px(c.borderBottomWidth);
|
|
9043
|
+
return px(c.height) + box + px(c.marginTop) + px(c.marginBottom);
|
|
9044
|
+
};
|
|
9045
|
+
// How many columns an item takes: span-2, span-3, grid-column: span N, or 1 / -1 (all)
|
|
9046
|
+
const msSpan = (it, n) => {
|
|
9047
|
+
const c = getComputedStyle(it), m = /span\s+(\d+)/.exec(`${c.gridColumnStart} ${c.gridColumnEnd}`);
|
|
9048
|
+
if (m) return Math.min(n, +m[1]);
|
|
9049
|
+
return c.gridColumnEnd === '-1' ? n : 1;
|
|
9050
|
+
};
|
|
9051
|
+
// Items are placed with exact positions: each goes to the column that is shortest so far (reading
|
|
9052
|
+
// order stays roughly left to right, as in CSS masonry). Wide items sit where their columns are
|
|
9053
|
+
// lowest; with .griddy-dense later items fill the holes this leaves. Columns and gaps come from
|
|
9054
|
+
// the grid's own CSS (grid-cols-*, gap-*), so it reads like any grid.
|
|
9055
|
+
// Gliding (.griddy-glide): an item placed for the first time (new, or shown again) goes straight
|
|
9056
|
+
// to its spot, with its transition off for that one placement, so nothing flies in from a corner.
|
|
8995
9057
|
function msLayout(st) {
|
|
8996
9058
|
const { el } = st;
|
|
8997
9059
|
if (MS_NATIVE) return;
|
|
8998
|
-
el.classList.
|
|
8999
|
-
const
|
|
9000
|
-
|
|
9001
|
-
|
|
9002
|
-
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
|
|
9060
|
+
if (!el.classList.contains('is-ready')) el.classList.add('is-ready');
|
|
9061
|
+
const cs = getComputedStyle(el);
|
|
9062
|
+
const tracks = (cs.gridTemplateColumns.match(/[\d.]+px/g) || []).map(parseFloat);
|
|
9063
|
+
const n = Math.max(1, tracks.length), colGap = parseFloat(cs.columnGap) || 0, rowGap = parseFloat(cs.rowGap) || 0;
|
|
9064
|
+
if (!tracks.length) tracks.push(el.clientWidth);
|
|
9065
|
+
const xs = tracks.map((_, i) => tracks.slice(0, i).reduce((a, b) => a + b, 0) + colGap * i);
|
|
9066
|
+
const dense = /dense/.test(cs.gridAutoFlow);
|
|
9067
|
+
const padStart = parseFloat(cs.paddingInlineStart) || 0, padTop = parseFloat(cs.paddingTop) || 0;
|
|
9068
|
+
const all = [...el.children], items = all.filter((it) => !it.hidden && getComputedStyle(it).display !== 'none');
|
|
9069
|
+
all.forEach((it) => { if (!items.includes(it)) st.placed.delete(it); }); // hidden: placed afresh when shown again
|
|
9070
|
+
const fresh = items.filter((it) => !st.placed.has(it));
|
|
9071
|
+
fresh.forEach((it) => { st.placed.add(it); it.style.transition = 'none'; });
|
|
9072
|
+
// 1) widths first, 2) then read every height (one layout pass), 3) then place
|
|
9073
|
+
const spans = items.map((it) => {
|
|
9074
|
+
const k = msSpan(it, n);
|
|
9075
|
+
it.style.width = `${tracks.slice(0, k).reduce((a, b) => a + b, 0) + colGap * (k - 1)}px`;
|
|
9076
|
+
return k;
|
|
9007
9077
|
});
|
|
9078
|
+
const heights = items.map(msHeight);
|
|
9079
|
+
const cols = Array(n).fill(0), holes = []; // holes (dense): { c, top, limit } in one column
|
|
9080
|
+
items.forEach((it, i) => {
|
|
9081
|
+
const k = spans[i], h = heights[i];
|
|
9082
|
+
let c = -1, y = 0;
|
|
9083
|
+
if (dense && k === 1) {
|
|
9084
|
+
const hole = holes.filter((o) => o.top + h <= o.limit + .5).sort((a, b) => a.top - b.top || a.c - b.c)[0];
|
|
9085
|
+
if (hole) { c = hole.c; y = hole.top; hole.top += h + rowGap; if (hole.top >= hole.limit) holes.splice(holes.indexOf(hole), 1); }
|
|
9086
|
+
}
|
|
9087
|
+
if (c < 0) {
|
|
9088
|
+
let best = Infinity;
|
|
9089
|
+
for (let j = 0; j + k <= n; j++) { const top = Math.max(...cols.slice(j, j + k)); if (top < best - .5) { best = top; c = j; } }
|
|
9090
|
+
y = best;
|
|
9091
|
+
for (let j = c; j < c + k; j++) { if (dense && cols[j] < y - .5) holes.push({ c: j, top: cols[j], limit: y - rowGap }); cols[j] = y + h + rowGap; }
|
|
9092
|
+
}
|
|
9093
|
+
// (an item placed on grid lines, like 1 / -1, is measured from the content edge; others from the padding edge)
|
|
9094
|
+
it.style.insetInlineStart = `${xs[c] + (/^\d/.test(getComputedStyle(it).gridColumnStart) ? 0 : padStart)}px`;
|
|
9095
|
+
it.style.top = `${y + padTop}px`;
|
|
9096
|
+
});
|
|
9097
|
+
const content = items.length ? Math.max(...cols) - rowGap : 0;
|
|
9098
|
+
const extra = cs.boxSizing === 'border-box' ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) + (parseFloat(cs.borderTopWidth) || 0) + (parseFloat(cs.borderBottomWidth) || 0) : 0;
|
|
9099
|
+
el.style.height = `${Math.max(0, content) + extra}px`;
|
|
9100
|
+
if (fresh.length) { void el.offsetWidth; fresh.forEach((it) => { it.style.transition = ''; }); } // placed: gliding back on
|
|
9008
9101
|
}
|
|
9009
|
-
function
|
|
9102
|
+
function setupGriddy(el) {
|
|
9010
9103
|
if (msStates.has(el)) return msStates.get(el).api;
|
|
9011
|
-
el.classList.add('
|
|
9012
|
-
const st = { el, raf: 0 };
|
|
9104
|
+
el.classList.add('griddy');
|
|
9105
|
+
const st = { el, raf: 0, placed: new WeakSet() };
|
|
9013
9106
|
const again = () => { if (!st.raf) st.raf = requestAnimationFrame(() => { st.raf = 0; msLayout(st); }); };
|
|
9014
9107
|
st.ro = new ResizeObserver(again);
|
|
9015
9108
|
const watch = (it) => { st.ro.observe(it); it.querySelectorAll('img').forEach((img) => { if (!img.complete) img.addEventListener('load', again, { once: true }); }); };
|
|
9016
9109
|
st.ro.observe(el);
|
|
9017
9110
|
[...el.children].forEach(watch);
|
|
9018
|
-
|
|
9019
|
-
new
|
|
9020
|
-
|
|
9111
|
+
doc.fonts?.ready.then(again);
|
|
9112
|
+
// new items, items moved, items shown or hidden (filters), and class changes on the grid or an
|
|
9113
|
+
// item (columns, gap, span-2): place them now, before they're painted
|
|
9114
|
+
new MutationObserver((muts) => {
|
|
9115
|
+
let redo = false;
|
|
9116
|
+
muts.forEach((m) => {
|
|
9117
|
+
m.addedNodes.forEach((n) => { if (n.nodeType === 1 && n.parentElement === el) watch(n); });
|
|
9118
|
+
if (m.type === 'childList' || m.attributeName === 'hidden' || m.target === el || m.target.parentElement === el) redo = true;
|
|
9119
|
+
});
|
|
9120
|
+
if (redo) msLayout(st);
|
|
9121
|
+
}).observe(el, { childList: true, attributes: true, subtree: true, attributeFilter: ['hidden', 'class'] });
|
|
9021
9122
|
st.api = { el, layout: () => msLayout(st) };
|
|
9022
9123
|
msStates.set(el, st);
|
|
9023
9124
|
msLayout(st);
|
|
9024
9125
|
return st.api;
|
|
9025
9126
|
}
|
|
9026
|
-
const
|
|
9127
|
+
const griddy = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupGriddy(el) : null; };
|
|
9027
9128
|
|
|
9028
9129
|
/* ---- Filter & sort -------------------------------------------------------------------------
|
|
9029
9130
|
A set of buttons or chips with data-moey-filters="#gallery" filters the items of #gallery:
|
|
@@ -9102,62 +9203,80 @@
|
|
|
9102
9203
|
|
|
9103
9204
|
/* ---- Infinite scroll -----------------------------------------------------------------------
|
|
9104
9205
|
data-moey-infinite on a list or grid: near its end, moey:load fires (detail.waitUntil(promise),
|
|
9105
|
-
detail.done() when there's nothing more)
|
|
9106
|
-
data-moey-infinite-auto loads (3) it waits for a "Load more" button, so
|
|
9107
|
-
the footer
|
|
9206
|
+
detail.done() when there's nothing more): append the next items there. After
|
|
9207
|
+
data-moey-infinite-auto loads (3; "all" = never stop) it waits for a "Load more" button, so
|
|
9208
|
+
people can still reach the footer. data-moey-infinite="button": always the button.
|
|
9209
|
+
data-moey-infinite="once": the button the first time, then automatic (with the same limit).
|
|
9210
|
+
The button stays in place while loading, with a spinner and "Loading…" inside it.
|
|
9211
|
+
Status and the end are announced. */
|
|
9108
9212
|
const ifStates = new WeakMap();
|
|
9109
9213
|
function setupInfinite(box) {
|
|
9110
9214
|
if (ifStates.has(box)) return ifStates.get(box).api;
|
|
9111
|
-
const
|
|
9215
|
+
const mode = box.dataset.moeyInfinite;
|
|
9216
|
+
const autoN = () => { const v = box.dataset.moeyInfiniteAuto; return v === 'all' ? Infinity : Math.max(0, +(v ?? 3) || 0); };
|
|
9217
|
+
const st = { box, loads: 0, busy: false, ended: false, viaButton: false, auto: mode === 'button' || mode === 'once' ? 0 : autoN() };
|
|
9112
9218
|
const status = Object.assign(doc.createElement('div'), { className: 'infinite-status' });
|
|
9113
9219
|
status.setAttribute('role', 'status');
|
|
9114
|
-
status.innerHTML = '<span class="spinner spinner-sm" hidden></span><span class="infinite-text"></span><button type="button" class="btn btn-sm infinite-more" hidden
|
|
9220
|
+
status.innerHTML = '<span class="spinner spinner-sm" hidden></span><span class="infinite-text"></span><button type="button" class="btn btn-sm infinite-more" hidden></button>';
|
|
9115
9221
|
box.after(status);
|
|
9116
9222
|
const sentinel = Object.assign(doc.createElement('div'), { className: 'infinite-sentinel' });
|
|
9117
9223
|
sentinel.setAttribute('aria-hidden', 'true');
|
|
9118
9224
|
status.after(sentinel);
|
|
9119
9225
|
const text = status.querySelector('.infinite-text'), spin = status.querySelector('.spinner'), more = status.querySelector('.infinite-more');
|
|
9226
|
+
const label = box.dataset.moeyInfiniteMore || 'Load more';
|
|
9120
9227
|
const sync = () => {
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9228
|
+
const inButton = st.busy && st.viaButton; // a click on the button: it shows the loading itself, in place
|
|
9229
|
+
spin.hidden = !st.busy || inButton;
|
|
9230
|
+
more.hidden = !inButton && (st.busy || st.ended || st.loads < st.auto);
|
|
9231
|
+
more.disabled = inButton;
|
|
9232
|
+
more.toggleAttribute('aria-busy', inButton);
|
|
9233
|
+
more.innerHTML = inButton ? '<span class="spinner spinner-sm" aria-hidden="true"></span>Loading…' : '';
|
|
9234
|
+
if (!inButton) more.textContent = label;
|
|
9235
|
+
text.textContent = st.ended ? (box.dataset.moeyInfiniteEnd || "That's everything") : st.busy && !inButton ? 'Loading…' : '';
|
|
9124
9236
|
};
|
|
9125
|
-
const load = () => {
|
|
9237
|
+
const load = (viaButton = false) => {
|
|
9126
9238
|
if (st.busy || st.ended) return;
|
|
9127
|
-
st.busy = true; sync();
|
|
9239
|
+
st.busy = true; st.viaButton = viaButton; sync();
|
|
9128
9240
|
const count = flItems(box).length;
|
|
9129
9241
|
const waits = [];
|
|
9130
9242
|
let ended = false;
|
|
9131
9243
|
emit(box, 'load', { page: st.loads + 1, waitUntil: (p) => waits.push(Promise.resolve(p)), done: () => { ended = true; } });
|
|
9132
9244
|
(waits.length ? Promise.allSettled(waits) : Promise.resolve()).then(() => {
|
|
9133
|
-
|
|
9245
|
+
const hadFocus = viaButton && doc.activeElement === more;
|
|
9246
|
+
st.loads++; st.busy = false; st.viaButton = false; st.ended = ended;
|
|
9134
9247
|
const added = flItems(box).length - count;
|
|
9135
9248
|
if (!ended && added <= 0 && !waits.length) st.ended = true; // nothing came: stop
|
|
9136
9249
|
sync();
|
|
9137
9250
|
if (added > 0 && !st.ended) text.textContent = `${added} more loaded`;
|
|
9138
9251
|
if (flStates.has(box)) flApply(flStates.get(box));
|
|
9139
9252
|
else if (msStates.has(box)) msLayout(msStates.get(box));
|
|
9253
|
+
// the button went away (automatic from now on, or the end): keep the keyboard where the new items are
|
|
9254
|
+
if (hadFocus && more.hidden) { const first = flItems(box)[count]; if (first) { if (!first.matches('a, button, [tabindex]')) first.tabIndex = -1; first.focus({ preventScroll: true }); } }
|
|
9140
9255
|
// still near the end (a tall screen): keep going
|
|
9141
9256
|
if (!st.ended && st.loads < st.auto) requestAnimationFrame(() => { const r = sentinel.getBoundingClientRect(); if (r.top < innerHeight + 400) load(); });
|
|
9142
9257
|
});
|
|
9143
9258
|
};
|
|
9144
|
-
more.addEventListener('click', () => {
|
|
9259
|
+
more.addEventListener('click', () => {
|
|
9260
|
+
if (mode !== 'button') st.auto = st.loads + autoN(); // automatic again, this click counting as the first (the same limit as before)
|
|
9261
|
+
load(true);
|
|
9262
|
+
});
|
|
9145
9263
|
new IntersectionObserver((es) => { if (es.some((x) => x.isIntersecting) && st.loads < st.auto) load(); }, { rootMargin: '0px 0px 400px 0px' }).observe(sentinel);
|
|
9146
9264
|
sync();
|
|
9147
|
-
st.api = { el: box, load, reset: () => { st.loads = 0; st.ended = false; sync(); } };
|
|
9265
|
+
st.api = { el: box, load: () => load(), reset: () => { st.loads = 0; st.ended = false; st.auto = mode === 'button' || mode === 'once' ? 0 : autoN(); sync(); } };
|
|
9148
9266
|
ifStates.set(box, st);
|
|
9149
9267
|
return st.api;
|
|
9150
9268
|
}
|
|
9151
9269
|
const infinite = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupInfinite(el) : null; };
|
|
9152
9270
|
|
|
9153
9271
|
/* ---- Lightbox ------------------------------------------------------------------------------
|
|
9154
|
-
A full-screen viewer for pictures, video, audio,
|
|
9272
|
+
A full-screen viewer for pictures, video, audio, embedded players (any video site), maps, PDFs and any
|
|
9155
9273
|
HTML — phone first: the picture follows your finger between items, swipe down closes, pinch
|
|
9156
9274
|
or double-tap zooms, one tap hides the controls. Desktop: arrows, thumbnails, wheel / double-
|
|
9157
9275
|
click zoom, keys (← → Home End, + − 0, F fullscreen, Space slideshow, Esc).
|
|
9158
9276
|
Items: links inside [data-moey-lightbox] (or a link with it, or data-moey-lightbox="name" to
|
|
9159
|
-
group links anywhere). href = the big version; data-type="image|video|audio|
|
|
9160
|
-
|
|
9277
|
+
group links anywhere). href = the big version; data-type="image|video|audio|embed|iframe|
|
|
9278
|
+
inline" (else guessed from the file type: embed = a video player's embed address, as given);
|
|
9279
|
+
data-caption, data-poster, data-thumb.
|
|
9161
9280
|
Parts, on the gallery (data-moey-lightbox-*) or in options: thumbs="auto|always|never",
|
|
9162
9281
|
counter, caption, zoom, loop, download, share, fullscreen, slideshow (ms) — "false" turns a
|
|
9163
9282
|
part off. Moey.lightbox.open(items | link, options) → .close() .next() .prev() .go(i).
|
|
@@ -9166,8 +9285,6 @@
|
|
|
9166
9285
|
function lbType(src, el) {
|
|
9167
9286
|
const t = el?.dataset.type;
|
|
9168
9287
|
if (t) return t;
|
|
9169
|
-
if (/youtu\.?be/.test(src)) return 'youtube';
|
|
9170
|
-
if (/vimeo\.com/.test(src)) return 'vimeo';
|
|
9171
9288
|
if (src.startsWith('#')) return 'inline';
|
|
9172
9289
|
const ext = (src.split(/[?#]/)[0].split('.').pop() || '').toLowerCase();
|
|
9173
9290
|
return LB_TYPES[ext] || (el?.querySelector('img') ? 'image' : 'iframe');
|
|
@@ -9258,8 +9375,8 @@
|
|
|
9258
9375
|
if (!active) return `<div class="lightbox-media lightbox-placeholder">${it.thumb ? `<img src="${esc(it.thumb)}" alt="">` : ''}</div>`;
|
|
9259
9376
|
if (it.type === 'video') return `<video class="lightbox-media" src="${esc(it.src)}" controls playsinline preload="metadata"${it.poster ? ` poster="${esc(it.poster)}"` : ''}></video>`;
|
|
9260
9377
|
if (it.type === 'audio') return `<figure class="lightbox-media lightbox-audio">${it.poster ? `<img src="${esc(it.poster)}" alt="">` : `<span class="lightbox-audio-icon">${lbIcon('music')}</span>`}<audio src="${esc(it.src)}" controls preload="metadata"></audio></figure>`;
|
|
9261
|
-
|
|
9262
|
-
if (it.type === '
|
|
9378
|
+
// a video player's embed address (any video site): loaded exactly as given, in a 16:9 frame
|
|
9379
|
+
if (it.type === 'embed') return `<div class="lightbox-media lightbox-frame"><iframe src="${esc(it.src)}" title="${esc(it.caption || 'Video')}" allow="autoplay; encrypted-media; picture-in-picture; fullscreen" allowfullscreen></iframe></div>`;
|
|
9263
9380
|
if (it.type === 'inline') { const t = doc.querySelector(it.src); return `<div class="lightbox-media lightbox-html">${t ? (t.tagName === 'TEMPLATE' ? t.innerHTML : t.innerHTML) : ''}</div>`; }
|
|
9264
9381
|
return `<div class="lightbox-media lightbox-frame lightbox-frame-page"><iframe src="${esc(it.src)}" title="${esc(it.caption || 'Content')}" loading="lazy"></iframe></div>`;
|
|
9265
9382
|
}
|
|
@@ -9286,7 +9403,7 @@
|
|
|
9286
9403
|
cap.textContent = it.caption || '';
|
|
9287
9404
|
cap.hidden = !o.caption || !it.caption;
|
|
9288
9405
|
const dl = box.querySelector('[data-lb="download"]');
|
|
9289
|
-
dl.hidden = !o.download || it.type === '
|
|
9406
|
+
dl.hidden = !o.download || it.type === 'embed' || it.type === 'inline';
|
|
9290
9407
|
dl.href = it.src;
|
|
9291
9408
|
box.querySelector('[data-lb="share"]').hidden = !o.share;
|
|
9292
9409
|
box.querySelector('[data-lb="zoom"]').hidden = !o.zoom || it.type !== 'image';
|
|
@@ -9450,7 +9567,7 @@
|
|
|
9450
9567
|
b.dataset.i = k;
|
|
9451
9568
|
b.setAttribute('aria-label', `${x.caption || `Item ${k + 1}`}`);
|
|
9452
9569
|
if (x.thumb) b.append(Object.assign(doc.createElement('img'), { src: x.thumb, alt: '' }));
|
|
9453
|
-
else b.innerHTML = lbIcon({ video: 'play', audio: 'music',
|
|
9570
|
+
else b.innerHTML = lbIcon({ video: 'play', audio: 'music', embed: 'play' }[x.type] || 'file');
|
|
9454
9571
|
return b;
|
|
9455
9572
|
}) : []));
|
|
9456
9573
|
box.classList.remove('is-bare');
|
|
@@ -9496,13 +9613,49 @@
|
|
|
9496
9613
|
get index() { return lb.i; },
|
|
9497
9614
|
});
|
|
9498
9615
|
|
|
9616
|
+
/* ---- Entering items ------------------------------------------------------------------------
|
|
9617
|
+
data-moey-enter on a list or grid: children added later (infinite scroll, "load more", a post
|
|
9618
|
+
added by any script) get .is-entering and --mo-enter-index for one entrance animation, one
|
|
9619
|
+
after another (CSS: gallery.css). The value picks the effect: (empty) fade up · fade · rise ·
|
|
9620
|
+
drop · zoom · pop · slide · flip · blur · none. data-moey-enter-first: the items already there
|
|
9621
|
+
when the page loads arrive too. Items that only move (sorting, dragging) don't animate.
|
|
9622
|
+
Moey.enter(list, items?) plays it again (on all its items, or the ones given). */
|
|
9623
|
+
const enterSeen = new WeakSet();
|
|
9624
|
+
const ENTER_SKIP = '.filter-empty, .infinite-status, template, script, style';
|
|
9625
|
+
function enterPlay(box, nodes) {
|
|
9626
|
+
if (reducedMotion()) return;
|
|
9627
|
+
let i = 0;
|
|
9628
|
+
nodes.forEach((n) => {
|
|
9629
|
+
if (n.nodeType !== 1 || n.parentElement !== box || n.hidden || n.matches(ENTER_SKIP)) return;
|
|
9630
|
+
n.classList.remove('is-entering');
|
|
9631
|
+
void n.offsetWidth; // (restart, when it's playing already)
|
|
9632
|
+
n.style.setProperty('--mo-enter-index', i++);
|
|
9633
|
+
n.classList.add('is-entering');
|
|
9634
|
+
clearTimeout(n.moeyEnterT);
|
|
9635
|
+
const done = (e) => { if (e && e.target !== n) return; clearTimeout(n.moeyEnterT); n.removeEventListener('animationend', done); n.classList.remove('is-entering'); n.style.removeProperty('--mo-enter-index'); };
|
|
9636
|
+
n.addEventListener('animationend', done);
|
|
9637
|
+
n.moeyEnterT = setTimeout(done, 3000); // no animation (your own CSS): tidy up anyway
|
|
9638
|
+
});
|
|
9639
|
+
}
|
|
9640
|
+
function setupEnter(box) {
|
|
9641
|
+
if (enterSeen.has(box)) return;
|
|
9642
|
+
enterSeen.add(box);
|
|
9643
|
+
new MutationObserver((muts) => {
|
|
9644
|
+
const moved = new Set(muts.flatMap((m) => [...m.removedNodes]));
|
|
9645
|
+
enterPlay(box, muts.flatMap((m) => [...m.addedNodes]).filter((n) => !moved.has(n)));
|
|
9646
|
+
}).observe(box, { childList: true });
|
|
9647
|
+
if (box.hasAttribute('data-moey-enter-first')) enterPlay(box, [...box.children]);
|
|
9648
|
+
}
|
|
9649
|
+
const enter = (box, items) => { box = typeof box === 'string' ? doc.querySelector(box) : box; if (!box) return; setupEnter(box); enterPlay(box, items ? [...items] : [...box.children]); };
|
|
9650
|
+
|
|
9499
9651
|
const initGallery = () => {
|
|
9500
9652
|
const scan = (root) => {
|
|
9501
|
-
root.querySelectorAll?.(
|
|
9653
|
+
root.querySelectorAll?.(GRIDDY).forEach(setupGriddy);
|
|
9502
9654
|
root.querySelectorAll?.('[data-moey-infinite]').forEach(setupInfinite);
|
|
9655
|
+
root.querySelectorAll?.('[data-moey-enter]').forEach(setupEnter);
|
|
9503
9656
|
};
|
|
9504
9657
|
scan(doc);
|
|
9505
|
-
new MutationObserver((muts) => { for (const m of muts) for (const n of m.addedNodes) if (n.nodeType === 1) { if (n.matches('[data-moey-
|
|
9658
|
+
new MutationObserver((muts) => { for (const m of muts) for (const n of m.addedNodes) if (n.nodeType === 1) { if (n.matches(GRIDDY)) setupGriddy(n); if (n.matches('[data-moey-infinite]')) setupInfinite(n); if (n.matches('[data-moey-enter]')) setupEnter(n); scan(n); } })
|
|
9506
9659
|
.observe(doc.body, { childList: true, subtree: true });
|
|
9507
9660
|
};
|
|
9508
9661
|
|
|
@@ -9634,18 +9787,12 @@
|
|
|
9634
9787
|
const player = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupPlayer(el) : null; };
|
|
9635
9788
|
|
|
9636
9789
|
/* ---- Embeds ---------------------------------------------------------------------------------
|
|
9637
|
-
<a class="embed" href="https
|
|
9638
|
-
light cover with a play button; the real player (
|
|
9639
|
-
|
|
9640
|
-
the other site until the visitor chooses.
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
const yt = href.match(/(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([\w-]{6,})/);
|
|
9644
|
-
if (yt) return `https://www.youtube-nocookie.com/embed/${yt[1]}?autoplay=1&rel=0`;
|
|
9645
|
-
const vm = href.match(/vimeo\.com\/(?:video\/)?(\d+)/);
|
|
9646
|
-
if (vm) return `https://player.vimeo.com/video/${vm[1]}?autoplay=1&dnt=1`;
|
|
9647
|
-
return href;
|
|
9648
|
-
}
|
|
9790
|
+
<a class="embed" href="https://…the page to watch it on" data-src="https://…the embed address"
|
|
9791
|
+
data-moey-embed>…a cover…</a>: a light cover with a play button; the real player (any video
|
|
9792
|
+
site, a map, a calendar, any page) loads only when it's clicked, from data-src (else href),
|
|
9793
|
+
exactly as given. Faster pages, and nothing from the other site until the visitor chooses.
|
|
9794
|
+
.embed-4x3 · .embed-1x1 · .embed-9x16 shapes. */
|
|
9795
|
+
const embedSrc = (a) => a.dataset.src || a.getAttribute('href') || '';
|
|
9649
9796
|
doc.addEventListener('click', (e) => {
|
|
9650
9797
|
const a = e.target.closest?.('[data-moey-embed]');
|
|
9651
9798
|
if (!a || a.classList.contains('is-loaded') || e.metaKey || e.ctrlKey || e.shiftKey) return;
|
|
@@ -9669,5 +9816,5 @@
|
|
|
9669
9816
|
if (doc.readyState === 'loading') doc.addEventListener('DOMContentLoaded', initLate); else initLate();
|
|
9670
9817
|
|
|
9671
9818
|
// Public API
|
|
9672
|
-
window.Moey = Object.freeze({ version: '0.
|
|
9819
|
+
window.Moey = Object.freeze({ version: '0.3.0', dismiss, open, close, openMenu, closeMenu, tooltip: showTip, toast, tab: (t) => selectTab(t, { focus: false }), paginate, popover, sortTable, palette, collapse, toggle, tags, chips, dropzone, tree, notify, datatable, select, spy, carousel, datepicker, combobox, countdown, confirm: askConfirm, alert: askAlert, prompt: askPrompt, strength, clean, chart, kanban, split, calendar, swipe, refresh, sortable, timepicker, chat, shortcuts, tour, marquee, griddy, masonry: griddy, enter, filter, infinite, lightbox, player });
|
|
9673
9820
|
})();
|