moey-ui 0.2.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/dist/moey.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Moey v0.2.0 | MIT License */
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.
@@ -675,9 +675,9 @@
675
675
  setupMenu(menu, trigger);
676
676
  if (isOpen(menu) || !emit(menu, 'open', { trigger })) return;
677
677
  menuState.set(menu, { trigger, point });
678
- try { menu.showPopover({ source: trigger }); } catch { menu.showPopover(); }
679
- // 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
680
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(); }
681
681
  if (!asSheet) { menu.classList.remove('is-sheet'); placeMenu(menu); }
682
682
  trigger?.setAttribute('aria-expanded', 'true');
683
683
  const list = items(menu);
@@ -1509,6 +1509,13 @@
1509
1509
  } else copy.type = 'button';
1510
1510
  copy.innerHTML = `<span class="menu-item-label">${link.innerHTML}</span>`;
1511
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
+ }
1512
1519
  if (link.matches(':disabled, .disabled, [aria-disabled="true"]')) copy.setAttribute('aria-disabled', 'true');
1513
1520
  if (copy.tagName === 'BUTTON' || st.tabs) copy.addEventListener('click', (e) => { e.preventDefault(); link.click(); requestAnimationFrame(() => navFit(st)); });
1514
1521
  menu.append(copy);
@@ -2889,6 +2896,7 @@
2889
2896
  const st = selState.get(sel);
2890
2897
  if (sel.disabled || st.menu.matches(':popover-open')) return;
2891
2898
  selBuildMenu(sel);
2899
+ adaptAs(st.menu, st.btn, sheetTitle(sel)); // before it shows: a phone sheet slides up from the start
2892
2900
  st.menu.showPopover();
2893
2901
  st.btn.setAttribute('aria-expanded', 'true');
2894
2902
  st.search = st.menu.querySelector('.select-search input');
@@ -2897,7 +2905,6 @@
2897
2905
  st.search.setAttribute('aria-controls', st.menu.id);
2898
2906
  st.search.setAttribute('aria-expanded', 'true');
2899
2907
  }
2900
- adaptAs(st.menu, st.btn, sheetTitle(sel));
2901
2908
  selPlace(sel);
2902
2909
  const current = selItems(st).find((i) => i.getAttribute('aria-selected') === 'true' && i.getAttribute('aria-disabled') !== 'true') || selEnabled(st)[0];
2903
2910
  selSetActive(sel, current);
@@ -4331,6 +4338,16 @@
4331
4338
  new ResizeObserver(() => { st.winDirty = true; again(); }).observe(scroll);
4332
4339
  }
4333
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);
4334
4351
  dtFillFilters(st);
4335
4352
  dtStates.set(root, st);
4336
4353
  st.url || st.fetcher ? dtLoad(st) : dtRender(st);
@@ -5553,8 +5570,8 @@
5553
5570
  st.mode = 'days';
5554
5571
  st.picking = false;
5555
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
5556
5574
  st.pop.showPopover();
5557
- adaptAs(st.pop, st.btn, sheetTitle(st.range ? st.host : st.inputs[0]));
5558
5575
  st.btn.setAttribute('aria-expanded', 'true');
5559
5576
  // Two months: when the end date is in the next month, show both
5560
5577
  dpRender(st, { focus: true });
@@ -8234,8 +8251,9 @@
8234
8251
  if (st.field.disabled || st.menu.matches(':popover-open')) return;
8235
8252
  tpRender(st);
8236
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
8237
8255
  st.menu.showPopover();
8238
- if (!adaptAs(st.menu, st.field, sheetTitle(st.input) || 'Time')) placeMenu(st.menu);
8256
+ if (!asSheet) placeMenu(st.menu);
8239
8257
  st.field.setAttribute('aria-expanded', 'true');
8240
8258
  tpActive(st, st.active);
8241
8259
  }
@@ -9006,15 +9024,19 @@
9006
9024
  .observe(doc.body, { childList: true, subtree: true });
9007
9025
  };
9008
9026
 
9009
- /* ---- Masonry -------------------------------------------------------------------------------
9010
- .masonry[data-moey-masonry]: items of different heights packed into columns with no gaps,
9011
- in reading order (keyboard and screen readers follow the page). Columns: the grid utilities
9012
- (grid-cols-2 md:grid-cols-4) or automatic (--mo-masonry-min). Items may span columns (span-2);
9013
- .masonry-dense back-fills holes. Where the browser has CSS masonry, it's used as is.
9014
- From code: Moey.masonry(el) → { layout() }. */
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. */
9015
9035
  const msStates = new WeakMap();
9016
9036
  const MS_NATIVE = CSS.supports?.('grid-template-rows', 'masonry');
9017
- // The real layout size: a transform (an entrance animation, scale) or zoom doesn't change it
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%)
9018
9040
  const msHeight = (it) => {
9019
9041
  const c = getComputedStyle(it), px = (v) => parseFloat(v) || 0;
9020
9042
  const box = c.boxSizing === 'border-box' ? 0 : px(c.paddingTop) + px(c.paddingBottom) + px(c.borderTopWidth) + px(c.borderBottomWidth);
@@ -9028,12 +9050,14 @@
9028
9050
  };
9029
9051
  // Items are placed with exact positions: each goes to the column that is shortest so far (reading
9030
9052
  // order stays roughly left to right, as in CSS masonry). Wide items sit where their columns are
9031
- // lowest; with .masonry-dense later items fill the holes this leaves. Columns and gaps come from
9053
+ // lowest; with .griddy-dense later items fill the holes this leaves. Columns and gaps come from
9032
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.
9033
9057
  function msLayout(st) {
9034
9058
  const { el } = st;
9035
9059
  if (MS_NATIVE) return;
9036
- el.classList.add('is-ready');
9060
+ if (!el.classList.contains('is-ready')) el.classList.add('is-ready');
9037
9061
  const cs = getComputedStyle(el);
9038
9062
  const tracks = (cs.gridTemplateColumns.match(/[\d.]+px/g) || []).map(parseFloat);
9039
9063
  const n = Math.max(1, tracks.length), colGap = parseFloat(cs.columnGap) || 0, rowGap = parseFloat(cs.rowGap) || 0;
@@ -9041,7 +9065,10 @@
9041
9065
  const xs = tracks.map((_, i) => tracks.slice(0, i).reduce((a, b) => a + b, 0) + colGap * i);
9042
9066
  const dense = /dense/.test(cs.gridAutoFlow);
9043
9067
  const padStart = parseFloat(cs.paddingInlineStart) || 0, padTop = parseFloat(cs.paddingTop) || 0;
9044
- const items = [...el.children].filter((it) => !it.hidden && getComputedStyle(it).display !== 'none');
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'; });
9045
9072
  // 1) widths first, 2) then read every height (one layout pass), 3) then place
9046
9073
  const spans = items.map((it) => {
9047
9074
  const k = msSpan(it, n);
@@ -9070,25 +9097,34 @@
9070
9097
  const content = items.length ? Math.max(...cols) - rowGap : 0;
9071
9098
  const extra = cs.boxSizing === 'border-box' ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) + (parseFloat(cs.borderTopWidth) || 0) + (parseFloat(cs.borderBottomWidth) || 0) : 0;
9072
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
9073
9101
  }
9074
- function setupMasonry(el) {
9102
+ function setupGriddy(el) {
9075
9103
  if (msStates.has(el)) return msStates.get(el).api;
9076
- el.classList.add('masonry');
9077
- const st = { el, raf: 0 };
9104
+ el.classList.add('griddy');
9105
+ const st = { el, raf: 0, placed: new WeakSet() };
9078
9106
  const again = () => { if (!st.raf) st.raf = requestAnimationFrame(() => { st.raf = 0; msLayout(st); }); };
9079
9107
  st.ro = new ResizeObserver(again);
9080
9108
  const watch = (it) => { st.ro.observe(it); it.querySelectorAll('img').forEach((img) => { if (!img.complete) img.addEventListener('load', again, { once: true }); }); };
9081
9109
  st.ro.observe(el);
9082
9110
  [...el.children].forEach(watch);
9083
- // new items, items moved, and items shown or hidden (filters): place them now, before they're painted
9084
- new MutationObserver((muts) => { muts.forEach((m) => m.addedNodes.forEach((n) => { if (n.nodeType === 1 && n.parentElement === el) watch(n); })); msLayout(st); })
9085
- .observe(el, { childList: true, attributes: true, subtree: true, attributeFilter: ['hidden'] });
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'] });
9086
9122
  st.api = { el, layout: () => msLayout(st) };
9087
9123
  msStates.set(el, st);
9088
9124
  msLayout(st);
9089
9125
  return st.api;
9090
9126
  }
9091
- const masonry = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupMasonry(el) : null; };
9127
+ const griddy = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupGriddy(el) : null; };
9092
9128
 
9093
9129
  /* ---- Filter & sort -------------------------------------------------------------------------
9094
9130
  A set of buttons or chips with data-moey-filters="#gallery" filters the items of #gallery:
@@ -9167,62 +9203,80 @@
9167
9203
 
9168
9204
  /* ---- Infinite scroll -----------------------------------------------------------------------
9169
9205
  data-moey-infinite on a list or grid: near its end, moey:load fires (detail.waitUntil(promise),
9170
- detail.done() when there's nothing more) — append the next items there. After
9171
- data-moey-infinite-auto loads (3) it waits for a "Load more" button, so people can still reach
9172
- the footer; data-moey-infinite="button" always waits. Status and the end are announced. */
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. */
9173
9212
  const ifStates = new WeakMap();
9174
9213
  function setupInfinite(box) {
9175
9214
  if (ifStates.has(box)) return ifStates.get(box).api;
9176
- const st = { box, loads: 0, busy: false, ended: false, auto: box.dataset.moeyInfinite === 'button' ? 0 : +(box.dataset.moeyInfiniteAuto ?? 3) };
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() };
9177
9218
  const status = Object.assign(doc.createElement('div'), { className: 'infinite-status' });
9178
9219
  status.setAttribute('role', 'status');
9179
- status.innerHTML = '<span class="spinner spinner-sm" hidden></span><span class="infinite-text"></span><button type="button" class="btn btn-sm infinite-more" hidden>Load more</button>';
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>';
9180
9221
  box.after(status);
9181
9222
  const sentinel = Object.assign(doc.createElement('div'), { className: 'infinite-sentinel' });
9182
9223
  sentinel.setAttribute('aria-hidden', 'true');
9183
9224
  status.after(sentinel);
9184
9225
  const text = status.querySelector('.infinite-text'), spin = status.querySelector('.spinner'), more = status.querySelector('.infinite-more');
9226
+ const label = box.dataset.moeyInfiniteMore || 'Load more';
9185
9227
  const sync = () => {
9186
- spin.hidden = !st.busy;
9187
- more.hidden = st.busy || st.ended || st.loads < st.auto;
9188
- text.textContent = st.ended ? (box.dataset.moeyInfiniteEnd || "That's everything") : st.busy ? 'Loading…' : '';
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…' : '';
9189
9236
  };
9190
- const load = () => {
9237
+ const load = (viaButton = false) => {
9191
9238
  if (st.busy || st.ended) return;
9192
- st.busy = true; sync();
9239
+ st.busy = true; st.viaButton = viaButton; sync();
9193
9240
  const count = flItems(box).length;
9194
9241
  const waits = [];
9195
9242
  let ended = false;
9196
9243
  emit(box, 'load', { page: st.loads + 1, waitUntil: (p) => waits.push(Promise.resolve(p)), done: () => { ended = true; } });
9197
9244
  (waits.length ? Promise.allSettled(waits) : Promise.resolve()).then(() => {
9198
- st.loads++; st.busy = false; st.ended = ended;
9245
+ const hadFocus = viaButton && doc.activeElement === more;
9246
+ st.loads++; st.busy = false; st.viaButton = false; st.ended = ended;
9199
9247
  const added = flItems(box).length - count;
9200
9248
  if (!ended && added <= 0 && !waits.length) st.ended = true; // nothing came: stop
9201
9249
  sync();
9202
9250
  if (added > 0 && !st.ended) text.textContent = `${added} more loaded`;
9203
9251
  if (flStates.has(box)) flApply(flStates.get(box));
9204
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 }); } }
9205
9255
  // still near the end (a tall screen): keep going
9206
9256
  if (!st.ended && st.loads < st.auto) requestAnimationFrame(() => { const r = sentinel.getBoundingClientRect(); if (r.top < innerHeight + 400) load(); });
9207
9257
  });
9208
9258
  };
9209
- more.addEventListener('click', () => { st.auto = st.loads + (+(box.dataset.moeyInfiniteAuto ?? 3) || 0); load(); });
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
+ });
9210
9263
  new IntersectionObserver((es) => { if (es.some((x) => x.isIntersecting) && st.loads < st.auto) load(); }, { rootMargin: '0px 0px 400px 0px' }).observe(sentinel);
9211
9264
  sync();
9212
- 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(); } };
9213
9266
  ifStates.set(box, st);
9214
9267
  return st.api;
9215
9268
  }
9216
9269
  const infinite = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupInfinite(el) : null; };
9217
9270
 
9218
9271
  /* ---- Lightbox ------------------------------------------------------------------------------
9219
- A full-screen viewer for pictures, video, audio, embeds (YouTube, Vimeo, maps, PDFs) and any
9272
+ A full-screen viewer for pictures, video, audio, embedded players (any video site), maps, PDFs and any
9220
9273
  HTML — phone first: the picture follows your finger between items, swipe down closes, pinch
9221
9274
  or double-tap zooms, one tap hides the controls. Desktop: arrows, thumbnails, wheel / double-
9222
9275
  click zoom, keys (← → Home End, + − 0, F fullscreen, Space slideshow, Esc).
9223
9276
  Items: links inside [data-moey-lightbox] (or a link with it, or data-moey-lightbox="name" to
9224
- group links anywhere). href = the big version; data-type="image|video|audio|youtube|vimeo|
9225
- iframe|inline" (else guessed from the address); data-caption, data-poster, data-thumb.
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.
9226
9280
  Parts, on the gallery (data-moey-lightbox-*) or in options: thumbs="auto|always|never",
9227
9281
  counter, caption, zoom, loop, download, share, fullscreen, slideshow (ms) — "false" turns a
9228
9282
  part off. Moey.lightbox.open(items | link, options) → .close() .next() .prev() .go(i).
@@ -9231,8 +9285,6 @@
9231
9285
  function lbType(src, el) {
9232
9286
  const t = el?.dataset.type;
9233
9287
  if (t) return t;
9234
- if (/youtu\.?be/.test(src)) return 'youtube';
9235
- if (/vimeo\.com/.test(src)) return 'vimeo';
9236
9288
  if (src.startsWith('#')) return 'inline';
9237
9289
  const ext = (src.split(/[?#]/)[0].split('.').pop() || '').toLowerCase();
9238
9290
  return LB_TYPES[ext] || (el?.querySelector('img') ? 'image' : 'iframe');
@@ -9323,8 +9375,8 @@
9323
9375
  if (!active) return `<div class="lightbox-media lightbox-placeholder">${it.thumb ? `<img src="${esc(it.thumb)}" alt="">` : ''}</div>`;
9324
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>`;
9325
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>`;
9326
- if (it.type === 'youtube') { const id = (it.src.match(/(?:v=|youtu\.be\/|embed\/|shorts\/)([\w-]{6,})/) || [])[1]; return `<div class="lightbox-media lightbox-frame"><iframe src="https://www.youtube-nocookie.com/embed/${esc(id || '')}?autoplay=1&rel=0" title="${esc(it.caption || 'Video')}" allow="autoplay; encrypted-media; picture-in-picture; fullscreen" allowfullscreen></iframe></div>`; }
9327
- if (it.type === 'vimeo') { const id = (it.src.match(/vimeo\.com\/(?:video\/)?(\d+)/) || [])[1]; return `<div class="lightbox-media lightbox-frame"><iframe src="https://player.vimeo.com/video/${esc(id || '')}?autoplay=1&dnt=1" title="${esc(it.caption || 'Video')}" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe></div>`; }
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>`;
9328
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>`; }
9329
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>`;
9330
9382
  }
@@ -9351,7 +9403,7 @@
9351
9403
  cap.textContent = it.caption || '';
9352
9404
  cap.hidden = !o.caption || !it.caption;
9353
9405
  const dl = box.querySelector('[data-lb="download"]');
9354
- dl.hidden = !o.download || it.type === 'youtube' || it.type === 'vimeo' || it.type === 'inline';
9406
+ dl.hidden = !o.download || it.type === 'embed' || it.type === 'inline';
9355
9407
  dl.href = it.src;
9356
9408
  box.querySelector('[data-lb="share"]').hidden = !o.share;
9357
9409
  box.querySelector('[data-lb="zoom"]').hidden = !o.zoom || it.type !== 'image';
@@ -9515,7 +9567,7 @@
9515
9567
  b.dataset.i = k;
9516
9568
  b.setAttribute('aria-label', `${x.caption || `Item ${k + 1}`}`);
9517
9569
  if (x.thumb) b.append(Object.assign(doc.createElement('img'), { src: x.thumb, alt: '' }));
9518
- else b.innerHTML = lbIcon({ video: 'play', audio: 'music', youtube: 'play', vimeo: 'play' }[x.type] || 'file');
9570
+ else b.innerHTML = lbIcon({ video: 'play', audio: 'music', embed: 'play' }[x.type] || 'file');
9519
9571
  return b;
9520
9572
  }) : []));
9521
9573
  box.classList.remove('is-bare');
@@ -9562,36 +9614,48 @@
9562
9614
  });
9563
9615
 
9564
9616
  /* ---- Entering items ------------------------------------------------------------------------
9565
- data-moey-enter on a list or grid: children added later (infinite scroll, "load more", a new
9566
- post) get .is-entering and --mo-enter-index for one entrance animation (CSS: gallery.css).
9567
- Items that only move (sorting, dragging) don't animate. */
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). */
9568
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
+ }
9569
9640
  function setupEnter(box) {
9570
9641
  if (enterSeen.has(box)) return;
9571
9642
  enterSeen.add(box);
9572
9643
  new MutationObserver((muts) => {
9573
9644
  const moved = new Set(muts.flatMap((m) => [...m.removedNodes]));
9574
- let i = 0;
9575
- muts.forEach((m) => m.addedNodes.forEach((n) => {
9576
- if (n.nodeType !== 1 || n.parentElement !== box || moved.has(n) || n.matches('.filter-empty, .infinite-status, template, script')) return;
9577
- n.style.setProperty('--mo-enter-index', i++);
9578
- n.classList.add('is-entering');
9579
- let t = 0;
9580
- const done = (e) => { if (e && e.target !== n) return; clearTimeout(t); n.removeEventListener('animationend', done); n.classList.remove('is-entering'); n.style.removeProperty('--mo-enter-index'); };
9581
- n.addEventListener('animationend', done);
9582
- t = setTimeout(done, 2000); // no animation (reduced motion, your own CSS): tidy up anyway
9583
- }));
9645
+ enterPlay(box, muts.flatMap((m) => [...m.addedNodes]).filter((n) => !moved.has(n)));
9584
9646
  }).observe(box, { childList: true });
9647
+ if (box.hasAttribute('data-moey-enter-first')) enterPlay(box, [...box.children]);
9585
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]); };
9586
9650
 
9587
9651
  const initGallery = () => {
9588
9652
  const scan = (root) => {
9589
- root.querySelectorAll?.('[data-moey-masonry]').forEach(setupMasonry);
9653
+ root.querySelectorAll?.(GRIDDY).forEach(setupGriddy);
9590
9654
  root.querySelectorAll?.('[data-moey-infinite]').forEach(setupInfinite);
9591
9655
  root.querySelectorAll?.('[data-moey-enter]').forEach(setupEnter);
9592
9656
  };
9593
9657
  scan(doc);
9594
- new MutationObserver((muts) => { for (const m of muts) for (const n of m.addedNodes) if (n.nodeType === 1) { if (n.matches('[data-moey-masonry]')) setupMasonry(n); if (n.matches('[data-moey-infinite]')) setupInfinite(n); if (n.matches('[data-moey-enter]')) setupEnter(n); scan(n); } })
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); } })
9595
9659
  .observe(doc.body, { childList: true, subtree: true });
9596
9660
  };
9597
9661
 
@@ -9723,18 +9787,12 @@
9723
9787
  const player = (el) => { el = typeof el === 'string' ? doc.querySelector(el) : el; return el ? setupPlayer(el) : null; };
9724
9788
 
9725
9789
  /* ---- Embeds ---------------------------------------------------------------------------------
9726
- <a class="embed" href="https://www.youtube.com/watch?v=…" data-moey-embed>…a cover…</a> — a
9727
- light cover with a play button; the real player (YouTube no-cookie, Vimeo, a map, any page:
9728
- data-src + data-type="iframe") loads only when it's clicked. Faster pages, and nothing from
9729
- the other site until the visitor chooses. .embed-4x3 · .embed-1x1 · .embed-9x16 shapes. */
9730
- function embedSrc(a) {
9731
- const href = a.dataset.src || a.getAttribute('href') || '';
9732
- const yt = href.match(/(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([\w-]{6,})/);
9733
- if (yt) return `https://www.youtube-nocookie.com/embed/${yt[1]}?autoplay=1&rel=0`;
9734
- const vm = href.match(/vimeo\.com\/(?:video\/)?(\d+)/);
9735
- if (vm) return `https://player.vimeo.com/video/${vm[1]}?autoplay=1&dnt=1`;
9736
- return href;
9737
- }
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') || '';
9738
9796
  doc.addEventListener('click', (e) => {
9739
9797
  const a = e.target.closest?.('[data-moey-embed]');
9740
9798
  if (!a || a.classList.contains('is-loaded') || e.metaKey || e.ctrlKey || e.shiftKey) return;
@@ -9758,5 +9816,5 @@
9758
9816
  if (doc.readyState === 'loading') doc.addEventListener('DOMContentLoaded', initLate); else initLate();
9759
9817
 
9760
9818
  // Public API
9761
- window.Moey = Object.freeze({ version: '0.2.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, masonry, filter, infinite, lightbox, player });
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 });
9762
9820
  })();