moey-ui 0.1.0 → 0.2.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.min.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! Moey v0.1.0 | MIT License */
2
- /*! Moey v0.1.0 | MIT License */
1
+ /*! Moey v0.2.0 | MIT License */
2
+ /*! Moey v0.2.0 | MIT License */
3
3
 
4
4
  (()=>{
5
5
  'use strict';
@@ -18,6 +18,21 @@ const onEnd=(e)=>{if(e.target===el)finish();};
18
18
  el.addEventListener('transitionend',onEnd);
19
19
  setTimeout(finish,ms+50);
20
20
  }
21
+ doc.addEventListener('click',(e)=>{
22
+ const a=e.target.closest?.('a[href*="#"]');
23
+ if(!a||e.defaultPrevented||e.button||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||reducedMotion())return;
24
+ if((a.target&&a.target!=='_self')||a.hasAttribute('download')||!a.hash||a.origin!==location.origin||
25
+ a.pathname!==location.pathname||a.search!==location.search)return;
26
+ const html=doc.documentElement;
27
+ html.classList.add('mo-smooth-scroll');
28
+ let timer=0;
29
+ const off=()=>{clearTimeout(timer);removeEventListener('scrollend',off);html.classList.remove('mo-smooth-scroll');};
30
+ setTimeout(()=>{
31
+ if(e.defaultPrevented)return off();
32
+ addEventListener('scrollend',off,{once:true});
33
+ timer=setTimeout(off,1500);
34
+ });
35
+ });
21
36
  const DIALOG='dialog.dialog, dialog.drawer, dialog.sheet, dialog.palette';
22
37
  const CLOSABLE=`.alert, .toast, ${DIALOG}, .menu[popover], .popover`;
23
38
  function dismiss(el){
@@ -234,7 +249,7 @@ if(e.newState==='open')closedOnce.delete(e.target);else onDialogClosed(e.target)
234
249
  const PHONE=matchMedia('(width < 576px)');
235
250
  const sheetState=new WeakMap();
236
251
  const isSheet=(d)=>d.matches('dialog.sheet')||
237
- (PHONE.matches&&d.matches('dialog.dialog:not(.dialog-center, .dialog-fullscreen)'));
252
+ (PHONE.matches&&d.matches('dialog.dialog:not(.dialog-center, .dialog-fullscreen, .dialog-fullscreen-phone)'));
238
253
  const canDrag=(d)=>d.open&&d.dataset.moeyDrag!=='false'&&isSheet(d);
239
254
  function snapPoints(d){
240
255
  const full=d.offsetHeight,vh=innerHeight;
@@ -6939,11 +6954,13 @@ const sortName=(it)=>(it.querySelector('.sort-label, .list-group-title, .kanban-
6939
6954
  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;};
6940
6955
  let sortFlipUntil=0;
6941
6956
  function sortFlip(lists,change){
6942
- if(reducedMotion()){change();return;}
6957
+ const relayout=()=>lists.forEach((l)=>msStates.has(l)&&msLayout(msStates.get(l)));
6958
+ if(reducedMotion()){change();relayout();return;}
6943
6959
  sortFlipUntil=performance.now()+170;
6944
6960
  const els=lists.flatMap((l)=>sortItems(l)).filter((x)=>!x.classList.contains('is-sorting'));
6945
6961
  const before=new Map(els.map((x)=>[x,x.getBoundingClientRect()]));
6946
6962
  change();
6963
+ relayout();
6947
6964
  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)'});});
6948
6965
  }
6949
6966
  function sortGroup(list){const g=list.dataset.moeySortable;return g&&g!==''&&g!=='true'?[...doc.querySelectorAll(`[data-moey-sortable="${CSS.escape(g)}"]`)]:[list];}
@@ -7925,19 +7942,54 @@ new MutationObserver((muts)=>{for(const m of muts)for(const n of m.addedNodes)if
7925
7942
  };
7926
7943
  const msStates=new WeakMap();
7927
7944
  const MS_NATIVE=CSS.supports?.('grid-template-rows','masonry');
7945
+ const msHeight=(it)=>{
7946
+ const c=getComputedStyle(it),px=(v)=>parseFloat(v)||0;
7947
+ const box=c.boxSizing==='border-box'?0:px(c.paddingTop)+px(c.paddingBottom)+px(c.borderTopWidth)+px(c.borderBottomWidth);
7948
+ return px(c.height)+box+px(c.marginTop)+px(c.marginBottom);
7949
+ };
7950
+ const msSpan=(it,n)=>{
7951
+ const c=getComputedStyle(it),m=/span\s+(\d+)/.exec(`${c.gridColumnStart} ${c.gridColumnEnd}`);
7952
+ if(m)return Math.min(n,+m[1]);
7953
+ return c.gridColumnEnd==='-1'?n:1;
7954
+ };
7928
7955
  function msLayout(st){
7929
7956
  const{el}=st;
7930
7957
  if(MS_NATIVE)return;
7931
- el.classList.remove('is-ready');
7932
- const gap=parseFloat(getComputedStyle(el).rowGap)||0;
7933
7958
  el.classList.add('is-ready');
7934
- el.style.setProperty('--mo-masonry-gap-y',`${gap}px`);
7935
- [...el.children].forEach((it)=>{
7936
- if(it.hidden||getComputedStyle(it).display==='none')return;
7937
- it.style.gridRowEnd='auto';
7938
- const h=it.getBoundingClientRect().height;
7939
- it.style.gridRowEnd=`span ${Math.max(1,Math.ceil(h+gap))}`;
7959
+ const cs=getComputedStyle(el);
7960
+ const tracks=(cs.gridTemplateColumns.match(/[\d.]+px/g)||[]).map(parseFloat);
7961
+ const n=Math.max(1,tracks.length),colGap=parseFloat(cs.columnGap)||0,rowGap=parseFloat(cs.rowGap)||0;
7962
+ if(!tracks.length)tracks.push(el.clientWidth);
7963
+ const xs=tracks.map((_,i)=>tracks.slice(0,i).reduce((a,b)=>a+b,0)+colGap*i);
7964
+ const dense=/dense/.test(cs.gridAutoFlow);
7965
+ const padStart=parseFloat(cs.paddingInlineStart)||0,padTop=parseFloat(cs.paddingTop)||0;
7966
+ const items=[...el.children].filter((it)=>!it.hidden&&getComputedStyle(it).display!=='none');
7967
+ const spans=items.map((it)=>{
7968
+ const k=msSpan(it,n);
7969
+ it.style.width=`${tracks.slice(0,k).reduce((a,b)=>a+b,0)+colGap*(k-1)}px`;
7970
+ return k;
7971
+ });
7972
+ const heights=items.map(msHeight);
7973
+ const cols=Array(n).fill(0),holes=[];
7974
+ items.forEach((it,i)=>{
7975
+ const k=spans[i],h=heights[i];
7976
+ let c=-1,y=0;
7977
+ if(dense&&k===1){
7978
+ const hole=holes.filter((o)=>o.top+h<=o.limit+.5).sort((a,b)=>a.top-b.top||a.c-b.c)[0];
7979
+ if(hole){c=hole.c;y=hole.top;hole.top+=h+rowGap;if(hole.top>=hole.limit)holes.splice(holes.indexOf(hole),1);}
7980
+ }
7981
+ if(c<0){
7982
+ let best=Infinity;
7983
+ 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;}}
7984
+ y=best;
7985
+ 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;}
7986
+ }
7987
+ it.style.insetInlineStart=`${xs[c]+(/^\d/.test(getComputedStyle(it).gridColumnStart)?0:padStart)}px`;
7988
+ it.style.top=`${y+padTop}px`;
7940
7989
  });
7990
+ const content=items.length?Math.max(...cols)-rowGap:0;
7991
+ const extra=cs.boxSizing==='border-box'?(parseFloat(cs.paddingTop)||0)+(parseFloat(cs.paddingBottom)||0)+(parseFloat(cs.borderTopWidth)||0)+(parseFloat(cs.borderBottomWidth)||0):0;
7992
+ el.style.height=`${Math.max(0,content)+extra}px`;
7941
7993
  }
7942
7994
  function setupMasonry(el){
7943
7995
  if(msStates.has(el))return msStates.get(el).api;
@@ -7948,7 +8000,7 @@ st.ro=new ResizeObserver(again);
7948
8000
  const watch=(it)=>{st.ro.observe(it);it.querySelectorAll('img').forEach((img)=>{if(!img.complete)img.addEventListener('load',again,{once:true});});};
7949
8001
  st.ro.observe(el);
7950
8002
  [...el.children].forEach(watch);
7951
- new MutationObserver((muts)=>{muts.forEach((m)=>m.addedNodes.forEach((n)=>{if(n.nodeType===1&&n.parentElement===el)watch(n);}));again();})
8003
+ new MutationObserver((muts)=>{muts.forEach((m)=>m.addedNodes.forEach((n)=>{if(n.nodeType===1&&n.parentElement===el)watch(n);}));msLayout(st);})
7952
8004
  .observe(el,{childList:true,attributes:true,subtree:true,attributeFilter:['hidden']});
7953
8005
  st.api={el,layout:()=>msLayout(st)};
7954
8006
  msStates.set(el,st);
@@ -8390,13 +8442,32 @@ if(a)a.click();
8390
8442
  close:()=>lbClose(),next:()=>lbGo(lb.i+1,1),prev:()=>lbGo(lb.i-1,-1),go:(i)=>lbGo(i),
8391
8443
  get index(){return lb.i;},
8392
8444
  });
8445
+ const enterSeen=new WeakSet();
8446
+ function setupEnter(box){
8447
+ if(enterSeen.has(box))return;
8448
+ enterSeen.add(box);
8449
+ new MutationObserver((muts)=>{
8450
+ const moved=new Set(muts.flatMap((m)=>[...m.removedNodes]));
8451
+ let i=0;
8452
+ muts.forEach((m)=>m.addedNodes.forEach((n)=>{
8453
+ if(n.nodeType!==1||n.parentElement!==box||moved.has(n)||n.matches('.filter-empty, .infinite-status, template, script'))return;
8454
+ n.style.setProperty('--mo-enter-index',i++);
8455
+ n.classList.add('is-entering');
8456
+ let t=0;
8457
+ 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');};
8458
+ n.addEventListener('animationend',done);
8459
+ t=setTimeout(done,2000);
8460
+ }));
8461
+ }).observe(box,{childList:true});
8462
+ }
8393
8463
  const initGallery=()=>{
8394
8464
  const scan=(root)=>{
8395
8465
  root.querySelectorAll?.('[data-moey-masonry]').forEach(setupMasonry);
8396
8466
  root.querySelectorAll?.('[data-moey-infinite]').forEach(setupInfinite);
8467
+ root.querySelectorAll?.('[data-moey-enter]').forEach(setupEnter);
8397
8468
  };
8398
8469
  scan(doc);
8399
- 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);scan(n);}})
8470
+ 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);}})
8400
8471
  .observe(doc.body,{childList:true,subtree:true});
8401
8472
  };
8402
8473
  const plStates=new WeakMap();
@@ -8539,5 +8610,5 @@ new MutationObserver((muts)=>{for(const m of muts)for(const n of m.addedNodes)if
8539
8610
  };
8540
8611
  const initLate=()=>{initSelects();initDatatables();initDatepickers();initComboboxes();initOtp();initCopy();initPasswords();initDirty();initFloating();initTimepickers();initCharts();initKanbans();initSplits();initCalendars();initTabbars();initSwipes();initRefresh();initSortables();initChats();initShortcuts();initMarquees();initGallery();initPlayers();};
8541
8612
  if(doc.readyState==='loading')doc.addEventListener('DOMContentLoaded',initLate);else initLate();
8542
- window.Moey=Object.freeze({version:'0.1.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});
8613
+ 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});
8543
8614
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moey-ui",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A clean, mobile-first front-end framework for admin dashboards, productivity apps and websites — one stylesheet, one script, no dependencies.",
5
5
  "keywords": [
6
6
  "css",
@@ -49,6 +49,7 @@
49
49
  "build": "node build.mjs",
50
50
  "build:icons": "node icons/build.mjs",
51
51
  "build:all": "node build.mjs && node icons/build.mjs",
52
- "deploy:icons": "node icons/build.mjs && node icons/deploy.mjs && npx wrangler pages deploy icons/site-dist --project-name moey-icons --branch main --commit-dirty=true"
52
+ "deploy:icons": "node icons/build.mjs && node icons/deploy.mjs && npx wrangler pages deploy icons/site-dist --project-name moey-icons --branch main --commit-dirty=true",
53
+ "build:live": "node build.mjs && node build-live.mjs"
53
54
  }
54
55
  }
package/src/css/card.css CHANGED
@@ -163,17 +163,19 @@
163
163
  <div class="stat-value">$48,210</div>
164
164
  <div class="stat-trend theme-green"><i class="mi mi-trending-up"></i> 12.4% <span>vs last month</span></div>
165
165
  </div></div> */
166
- .stat { display: grid; gap: .25rem; align-content: start; }
166
+ .stat { display: grid; gap: .25rem; align-content: start; min-width: 0; }
167
167
  .stat-label {
168
168
  display: flex;
169
+ flex-wrap: wrap; /* a narrow tile (two on a small phone): the icon moves under the label */
169
170
  align-items: center;
170
171
  gap: .5rem;
172
+ min-width: 0;
171
173
  font-size: var(--mo-font-size-sm);
172
174
  font-weight: var(--mo-font-weight-medium);
173
175
  color: var(--mo-fg-3);
174
176
  }
175
177
  .stat-value {
176
- font-size: 1.75rem;
178
+ font-size: clamp(1.125rem, 7vw, 1.75rem); /* a little smaller on small phones, so $48,210 fits two to a row at 280px */
177
179
  font-weight: var(--mo-font-weight-semibold);
178
180
  line-height: 1.2;
179
181
  letter-spacing: -.025em;
@@ -196,6 +198,7 @@
196
198
  place-items: center;
197
199
  width: 2.25rem;
198
200
  height: 2.25rem;
201
+ flex: none;
199
202
  margin-inline-start: auto;
200
203
  font-size: 1.125rem;
201
204
  color: var(--mo-theme-fg-emphasis);
@@ -14,7 +14,9 @@
14
14
 
15
15
  moey.js: opens with data-moey-open, closes on .btn-close / data-moey-dismiss /
16
16
  outside click / Esc (data-moey-static keeps it open).
17
- On phones a .dialog becomes a bottom sheet (.dialog-center keeps it centered).
17
+ On phones a .dialog becomes a bottom sheet (.dialog-center keeps it centered,
18
+ .dialog-fullscreen-phone makes it cover the screen there instead).
19
+ A page can set --mo-dialog-bg / --mo-dialog-fg (on :root, say) to color every dialog, drawer and sheet.
18
20
  ========================================================================== */
19
21
 
20
22
  /* Lock page scrolling while a modal is open */
@@ -24,13 +26,12 @@ html:has(:is(.dialog, .drawer, .sheet)[open]:modal) { overflow: hidden; }
24
26
  :is(.dialog, .drawer, .sheet) {
25
27
  --mo-dialog-padding: 1.5rem;
26
28
  --mo-dialog-footer-padding: .875rem; /* space above & below the footer buttons */
27
- --mo-dialog-bg: var(--mo-bg-raised);
28
29
  --mo-dialog-duration: .22s;
29
30
  max-width: none;
30
31
  max-height: none;
31
32
  padding: 0;
32
- color: var(--mo-fg-body);
33
- background: var(--mo-dialog-bg);
33
+ color: var(--mo-dialog-fg, var(--mo-fg-body)); /* --mo-dialog-bg / -fg: set them on the page to recolor them all */
34
+ background: var(--mo-dialog-bg, var(--mo-bg-raised));
34
35
  border: 0;
35
36
  box-shadow: var(--mo-shadow-overlay);
36
37
  }
@@ -115,9 +116,10 @@ html:has(:is(.dialog, .drawer, .sheet)[open]:modal) { overflow: hidden; }
115
116
  /* Fullscreen: covers the whole screen (content clears the notch / home bar) */
116
117
  .dialog-fullscreen { inset-inline: 0 auto; width: 100vw; max-width: none; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
117
118
 
118
- /* Phones: dialogs become bottom sheets (unless .dialog-center / .dialog-fullscreen) */
119
+ /* Phones: dialogs become bottom sheets (unless .dialog-center / .dialog-fullscreen / .dialog-fullscreen-phone) */
119
120
  @media (width < 576px) {
120
- .dialog:not(.dialog-center, .dialog-fullscreen) {
121
+ .dialog-fullscreen-phone { inset-inline: 0 auto; width: 100vw; max-width: none; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
122
+ .dialog:not(.dialog-center, .dialog-fullscreen, .dialog-fullscreen-phone) {
121
123
  inset-inline: 0 auto;
122
124
  width: 100vw;
123
125
  max-width: none;
@@ -279,9 +281,9 @@ html:has(:is(.dialog, .drawer, .sheet)[open]:modal) { overflow: hidden; }
279
281
  @keyframes mo-sheet-bump { 50% { translate: 0 -.5rem; } }
280
282
 
281
283
  @media (width < 576px) {
282
- .dialog:not(.dialog-center, .dialog-fullscreen):not([open]) { scale: 1; translate: 0 100%; }
284
+ .dialog:not(.dialog-center, .dialog-fullscreen, .dialog-fullscreen-phone):not([open]) { scale: 1; translate: 0 100%; }
283
285
  @starting-style {
284
- .dialog:not(.dialog-center, .dialog-fullscreen)[open] { scale: 1; translate: 0 100%; }
286
+ .dialog:not(.dialog-center, .dialog-fullscreen, .dialog-fullscreen-phone)[open] { scale: 1; translate: 0 100%; }
285
287
  }
286
288
  }
287
289
 
@@ -12,15 +12,28 @@
12
12
  }
13
13
  /* the grid-cols-* utilities set --mo-columns (phone first: grid-cols-2 md:grid-cols-4) */
14
14
  .masonry[class*="grid-cols-"] { grid-template-columns: repeat(var(--mo-columns, 3), minmax(0, 1fr)); }
15
- .masonry.is-ready { grid-auto-rows: 1px; row-gap: 0 !important; } /* (beats a gap-* utility: the gap is measured first and built into each span) */
15
+ /* moey.js gives each item its exact place (is-ready): the grid only supplies the columns and gaps */
16
+ .masonry.is-ready { position: relative; }
17
+ .masonry.is-ready > * { position: absolute; box-sizing: border-box; }
16
18
  .masonry > * { min-width: 0; margin: 0; }
17
19
  .masonry > .span-2 { grid-column: span 2; }
18
20
  .masonry > .span-3 { grid-column: span 3; }
19
21
  .masonry-dense { grid-auto-flow: row dense; }
20
22
  @supports (grid-template-rows: masonry) {
21
23
  .masonry { grid-template-rows: masonry; }
22
- .masonry.is-ready { grid-auto-rows: auto; row-gap: revert-layer; }
23
24
  }
25
+
26
+ /* New items glide in: data-moey-enter on any list or grid (masonry, infinite scroll, a feed).
27
+ Items added later get .is-entering and --mo-enter-index (0, 1, 2… in each batch, for a stagger).
28
+ data-moey-enter="fade" fades only; "zoom" grows from 96%. Your own: style [data-moey-enter] > .is-entering. */
29
+ @media (prefers-reduced-motion: no-preference) {
30
+ [data-moey-enter] > .is-entering { animation: mo-enter-up .45s var(--mo-ease) both; animation-delay: calc(min(var(--mo-enter-index, 0), 10) * 60ms); }
31
+ [data-moey-enter="fade"] > .is-entering { animation-name: mo-enter-fade; }
32
+ [data-moey-enter="zoom"] > .is-entering { animation-name: mo-enter-zoom; }
33
+ }
34
+ @keyframes mo-enter-up { from { opacity: 0; translate: 0 1rem; } }
35
+ @keyframes mo-enter-fade { from { opacity: 0; } }
36
+ @keyframes mo-enter-zoom { from { opacity: 0; scale: .96; } }
24
37
  /* Picture tiles */
25
38
  .masonry img,
26
39
  .gallery-tile img { display: block; width: 100%; height: auto; border-radius: var(--mo-radius-card); }
@@ -27,7 +27,8 @@ html.mo-keyboard .sheet-inset:modal { max-height: calc(var(--mo-vv-h) - var(--_t
27
27
  html.mo-keyboard .dialog:modal:not(.sheet) { max-height: calc(var(--mo-vv-h) - 1rem); }
28
28
  html.mo-keyboard .dialog-fullscreen:modal { height: var(--mo-vv-h); max-height: var(--mo-vv-h); padding-bottom: 0; }
29
29
  @media (width < 576px) {
30
- html.mo-keyboard .dialog:modal:not(.dialog-center, .dialog-fullscreen) { max-height: calc(var(--mo-vv-h) - 2.5rem); padding-bottom: 0; }
30
+ html.mo-keyboard .dialog-fullscreen-phone:modal { height: var(--mo-vv-h); max-height: var(--mo-vv-h); padding-bottom: 0; }
31
+ html.mo-keyboard .dialog:modal:not(.dialog-center, .dialog-fullscreen, .dialog-fullscreen-phone) { max-height: calc(var(--mo-vv-h) - 2.5rem); padding-bottom: 0; }
31
32
  }
32
33
 
33
34
  /* Drawers: as tall as what's visible */
@@ -16,9 +16,9 @@ html {
16
16
  /* Mobile first: nothing may push the page wider than the screen */
17
17
  body { overflow-wrap: break-word; }
18
18
  img, svg, video, canvas, iframe { max-width: 100%; }
19
- @media (prefers-reduced-motion: no-preference) {
20
- html { scroll-behavior: smooth; }
21
- }
19
+ /* Smooth scrolling only for in-page links (moey.js turns it on for that one jump), so scripts that
20
+ move the page (scrollTo, scrollIntoView, "jump to post") land at once, exactly where they aimed */
21
+ html.mo-smooth-scroll { scroll-behavior: smooth; }
22
22
 
23
23
  body {
24
24
  margin: 0;
package/src/js/moey.js CHANGED
@@ -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) {
@@ -7929,11 +7949,13 @@
7929
7949
  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
7950
  let sortFlipUntil = 0; // while items slide to their new places, their positions aren't final yet
7931
7951
  function sortFlip(lists, change) {
7932
- if (reducedMotion()) { change(); return; }
7952
+ const relayout = () => lists.forEach((l) => msStates.has(l) && msLayout(msStates.get(l))); // masonry places its items itself
7953
+ if (reducedMotion()) { change(); relayout(); return; }
7933
7954
  sortFlipUntil = performance.now() + 170;
7934
7955
  const els = lists.flatMap((l) => sortItems(l)).filter((x) => !x.classList.contains('is-sorting'));
7935
7956
  const before = new Map(els.map((x) => [x, x.getBoundingClientRect()]));
7936
7957
  change();
7958
+ relayout();
7937
7959
  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
7960
  }
7939
7961
  function sortGroup(list) { const g = list.dataset.moeySortable; return g && g !== '' && g !== 'true' ? [...doc.querySelectorAll(`[data-moey-sortable="${CSS.escape(g)}"]`)] : [list]; }
@@ -8992,19 +9014,62 @@
8992
9014
  From code: Moey.masonry(el) → { layout() }. */
8993
9015
  const msStates = new WeakMap();
8994
9016
  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
9018
+ const msHeight = (it) => {
9019
+ const c = getComputedStyle(it), px = (v) => parseFloat(v) || 0;
9020
+ const box = c.boxSizing === 'border-box' ? 0 : px(c.paddingTop) + px(c.paddingBottom) + px(c.borderTopWidth) + px(c.borderBottomWidth);
9021
+ return px(c.height) + box + px(c.marginTop) + px(c.marginBottom);
9022
+ };
9023
+ // How many columns an item takes: span-2, span-3, grid-column: span N, or 1 / -1 (all)
9024
+ const msSpan = (it, n) => {
9025
+ const c = getComputedStyle(it), m = /span\s+(\d+)/.exec(`${c.gridColumnStart} ${c.gridColumnEnd}`);
9026
+ if (m) return Math.min(n, +m[1]);
9027
+ return c.gridColumnEnd === '-1' ? n : 1;
9028
+ };
9029
+ // Items are placed with exact positions: each goes to the column that is shortest so far (reading
9030
+ // 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
9032
+ // the grid's own CSS (grid-cols-*, gap-*), so it reads like any grid.
8995
9033
  function msLayout(st) {
8996
9034
  const { el } = st;
8997
9035
  if (MS_NATIVE) return;
8998
- el.classList.remove('is-ready'); // read the real row gap first
8999
- const gap = parseFloat(getComputedStyle(el).rowGap) || 0;
9000
9036
  el.classList.add('is-ready');
9001
- el.style.setProperty('--mo-masonry-gap-y', `${gap}px`);
9002
- [...el.children].forEach((it) => {
9003
- if (it.hidden || getComputedStyle(it).display === 'none') return;
9004
- it.style.gridRowEnd = 'auto';
9005
- const h = it.getBoundingClientRect().height;
9006
- it.style.gridRowEnd = `span ${Math.max(1, Math.ceil(h + gap))}`; // 1px rows
9037
+ const cs = getComputedStyle(el);
9038
+ const tracks = (cs.gridTemplateColumns.match(/[\d.]+px/g) || []).map(parseFloat);
9039
+ const n = Math.max(1, tracks.length), colGap = parseFloat(cs.columnGap) || 0, rowGap = parseFloat(cs.rowGap) || 0;
9040
+ if (!tracks.length) tracks.push(el.clientWidth);
9041
+ const xs = tracks.map((_, i) => tracks.slice(0, i).reduce((a, b) => a + b, 0) + colGap * i);
9042
+ const dense = /dense/.test(cs.gridAutoFlow);
9043
+ const padStart = parseFloat(cs.paddingInlineStart) || 0, padTop = parseFloat(cs.paddingTop) || 0;
9044
+ const items = [...el.children].filter((it) => !it.hidden && getComputedStyle(it).display !== 'none');
9045
+ // 1) widths first, 2) then read every height (one layout pass), 3) then place
9046
+ const spans = items.map((it) => {
9047
+ const k = msSpan(it, n);
9048
+ it.style.width = `${tracks.slice(0, k).reduce((a, b) => a + b, 0) + colGap * (k - 1)}px`;
9049
+ return k;
9007
9050
  });
9051
+ const heights = items.map(msHeight);
9052
+ const cols = Array(n).fill(0), holes = []; // holes (dense): { c, top, limit } in one column
9053
+ items.forEach((it, i) => {
9054
+ const k = spans[i], h = heights[i];
9055
+ let c = -1, y = 0;
9056
+ if (dense && k === 1) {
9057
+ const hole = holes.filter((o) => o.top + h <= o.limit + .5).sort((a, b) => a.top - b.top || a.c - b.c)[0];
9058
+ if (hole) { c = hole.c; y = hole.top; hole.top += h + rowGap; if (hole.top >= hole.limit) holes.splice(holes.indexOf(hole), 1); }
9059
+ }
9060
+ if (c < 0) {
9061
+ let best = Infinity;
9062
+ 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; } }
9063
+ y = best;
9064
+ 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; }
9065
+ }
9066
+ // (an item placed on grid lines, like 1 / -1, is measured from the content edge; others from the padding edge)
9067
+ it.style.insetInlineStart = `${xs[c] + (/^\d/.test(getComputedStyle(it).gridColumnStart) ? 0 : padStart)}px`;
9068
+ it.style.top = `${y + padTop}px`;
9069
+ });
9070
+ const content = items.length ? Math.max(...cols) - rowGap : 0;
9071
+ const extra = cs.boxSizing === 'border-box' ? (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0) + (parseFloat(cs.borderTopWidth) || 0) + (parseFloat(cs.borderBottomWidth) || 0) : 0;
9072
+ el.style.height = `${Math.max(0, content) + extra}px`;
9008
9073
  }
9009
9074
  function setupMasonry(el) {
9010
9075
  if (msStates.has(el)) return msStates.get(el).api;
@@ -9015,8 +9080,8 @@
9015
9080
  const watch = (it) => { st.ro.observe(it); it.querySelectorAll('img').forEach((img) => { if (!img.complete) img.addEventListener('load', again, { once: true }); }); };
9016
9081
  st.ro.observe(el);
9017
9082
  [...el.children].forEach(watch);
9018
- // new items, and items shown or hidden (filters): lay out again (not on class changes — layout makes those)
9019
- new MutationObserver((muts) => { muts.forEach((m) => m.addedNodes.forEach((n) => { if (n.nodeType === 1 && n.parentElement === el) watch(n); })); again(); })
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); })
9020
9085
  .observe(el, { childList: true, attributes: true, subtree: true, attributeFilter: ['hidden'] });
9021
9086
  st.api = { el, layout: () => msLayout(st) };
9022
9087
  msStates.set(el, st);
@@ -9496,13 +9561,37 @@
9496
9561
  get index() { return lb.i; },
9497
9562
  });
9498
9563
 
9564
+ /* ---- 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. */
9568
+ const enterSeen = new WeakSet();
9569
+ function setupEnter(box) {
9570
+ if (enterSeen.has(box)) return;
9571
+ enterSeen.add(box);
9572
+ new MutationObserver((muts) => {
9573
+ 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
+ }));
9584
+ }).observe(box, { childList: true });
9585
+ }
9586
+
9499
9587
  const initGallery = () => {
9500
9588
  const scan = (root) => {
9501
9589
  root.querySelectorAll?.('[data-moey-masonry]').forEach(setupMasonry);
9502
9590
  root.querySelectorAll?.('[data-moey-infinite]').forEach(setupInfinite);
9591
+ root.querySelectorAll?.('[data-moey-enter]').forEach(setupEnter);
9503
9592
  };
9504
9593
  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-masonry]')) setupMasonry(n); if (n.matches('[data-moey-infinite]')) setupInfinite(n); scan(n); } })
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); } })
9506
9595
  .observe(doc.body, { childList: true, subtree: true });
9507
9596
  };
9508
9597