motimeline 2.9.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,6 +92,41 @@ import 'motimeline/dist/moTimeline.css';
92
92
  </li>
93
93
  ```
94
94
 
95
+ ### Rendered DOM (after init)
96
+
97
+ The library injects classes and elements into your markup. Here is what a fully rendered item looks like:
98
+
99
+ ```html
100
+ <!-- Container gets mo-timeline, mo-theme, mo-twocol added -->
101
+ <ul class="mo-timeline mo-theme mo-twocol">
102
+
103
+ <!-- Left-column item: mo-item + js-mo-item added to every <li> -->
104
+ <li class="mo-item js-mo-item">
105
+ <span class="mo-arrow js-mo-arrow"></span> <!-- injected when showArrow: true -->
106
+ <span class="mo-badge js-mo-badge">1</span> <!-- injected when showBadge: true -->
107
+ <div class="mo-card">
108
+ <div class="mo-card-image">
109
+ <img class="mo-banner" src="banner.jpg" alt="">
110
+ <img class="mo-avatar" src="avatar.jpg" alt="">
111
+ </div>
112
+ <div class="mo-card-body">
113
+ <h3>Title</h3>
114
+ <p class="mo-meta">Date</p>
115
+ <p>Text…</p>
116
+ </div>
117
+ </div>
118
+ </li>
119
+
120
+ <!-- Right-column item: also gets mo-inverted + js-mo-inverted -->
121
+ <li class="mo-item js-mo-item mo-inverted js-mo-inverted">
122
+ ...
123
+ </li>
124
+
125
+ </ul>
126
+ ```
127
+
128
+ > `js-mo-*` classes are JS-only selector mirrors of their `mo-*` counterparts — use them in your own scripts to avoid coupling to styling class names.
129
+
95
130
  ---
96
131
 
97
132
  ## Options
@@ -110,6 +145,7 @@ import 'motimeline/dist/moTimeline.css';
110
145
  | `cardMarginFullWidth` | string | `'0.5rem'` | Margin of full-width themed cards. Sets `--mo-card-margin-fullwidth` on the container. |
111
146
  | `randomFullWidth` | number \| boolean | `0` | `0`/`false` = off. A number `0–1` sets the probability that each item is randomly promoted to full-width during init. `true` = 33% chance. Items can also be set manually by adding the `mo-fullwidth` class to the `<li>`. |
112
147
  | `animate` | string \| boolean | `false` | Animate items as they scroll into view using `IntersectionObserver`. `'fade'` — items fade in. `'slide'` — left-column items slide in from the left, right-column items from the right. `true` = `'fade'`. Disable for individual items by adding `mo-visible` manually. Control speed via `--mo-animate-duration`. |
148
+ | `renderCard` | function \| null | `null` | `(item, cardEl) => void`. When set, called for every item instead of the built-in HTML renderer. `cardEl` is the `.mo-card` div already placed inside the `<li>`. Populate it via `innerHTML` or DOM methods. The library still owns the `<li>`, column placement, spine, badge, arrow, `addItems()`, and scroll pagination. |
113
149
 
114
150
  ---
115
151
 
@@ -382,6 +418,9 @@ No framework option needed. Wrap the `<ul>` inside a Bootstrap `.container`:
382
418
 
383
419
  ## Changelog
384
420
 
421
+ ### v2.10.0
422
+ - New option `renderCard(item, cardEl)` — custom card renderer. When provided, the library skips its built-in card HTML and calls this function instead, passing the item data object and the `.mo-card` div already inserted into the DOM. The library continues to own column placement, spine, badge, arrow, `addItems()`, and scroll pagination. Enables full React component injection via `createRoot(cardEl).render(...)`.
423
+
385
424
  ### v2.9.0
386
425
  - New option `animate` — scroll-triggered animations via `IntersectionObserver`. `'fade'` fades items in as they enter the viewport; `'slide'` slides left-column items from the left and right-column items from the right. `true` defaults to `'fade'`. Speed controlled via `--mo-animate-duration` (default `0.5s`). Works for initial load, `addItems()`, and `insertItem()`.
387
426
 
@@ -1,6 +1,6 @@
1
1
  "use strict";var _=Object.defineProperty;var b=(a,e,t)=>e in a?_(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var p=(a,e,t)=>b(a,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});/*!
2
- * moTimeline v2.9.0
2
+ * moTimeline v2.10.0
3
3
  * Responsive two-column timeline layout library
4
4
  * https://github.com/MattOpen/moTimeline
5
5
  * MIT License
6
- */const m=new WeakMap,v={columnCount:{xs:1,sm:2,md:2,lg:2},showBadge:!1,showArrow:!1,theme:!1,showCounterStyle:"counter",cardBorderRadius:"8px",avatarSize:"50px",cardMargin:"0.5rem 1.25rem 0.5rem 0.5rem",cardMarginInverted:"0.5rem 0.5rem 0.5rem 1.25rem",cardMarginFullWidth:"0.5rem",randomFullWidth:0,animate:!1},E="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='%234f46e5'/><circle cx='12' cy='12' r='4.5' fill='white'/></svg>";function w(){const a=window.innerWidth;return a<600?"xs":a<992?"sm":a<1200?"md":"lg"}function I(a,e=100){let t;return(...r)=>{clearTimeout(t),t=setTimeout(()=>a(...r),e)}}function f(a){return a?{o:a.offsetTop,h:a.offsetHeight,gppu:a.offsetTop+a.offsetHeight}:{o:0,h:0,gppu:0}}function y(a,e){const t=[];let r=a.previousElementSibling;for(;r;)(!e||r.matches(e))&&t.push(r),r=r.previousElementSibling;return t}const c=class c{constructor(e,t={}){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("moTimeline: element not found");this.element=e,this.settings=Object.assign({},v,t),this.settings.columnCount=Object.assign({},v.columnCount,t.columnCount),this._resizeHandler=I(()=>this.refresh(),100),this._initialized=!1,this.init()}init(){const e=this.element;if(m.has(e)){this.refresh();return}const t=Object.assign({},this.settings,{lastItemIdx:0});if(m.set(e,t),c.instances.add(this),e.classList.add("mo-timeline"),t.theme&&e.classList.add("mo-theme"),e.style.setProperty("--mo-card-border-radius",t.cardBorderRadius),e.style.setProperty("--mo-avatar-size",t.avatarSize),e.style.setProperty("--mo-card-margin",t.cardMargin),e.style.setProperty("--mo-card-margin-inverted",t.cardMarginInverted),e.style.setProperty("--mo-card-margin-fullwidth",t.cardMarginFullWidth),t.animate){const r=t.animate===!0?"fade":t.animate;e.classList.add("mo-animate",`mo-animate-${r}`),this._observer=new IntersectionObserver(o=>{o.forEach(s=>{s.isIntersecting&&(s.target.classList.add("mo-visible"),this._observer.unobserve(s.target))})},{threshold:.1})}this._initialized=!0,window.addEventListener("resize",this._resizeHandler),Array.from(e.children).length>0&&this._initItems()}refresh(){c.instances.forEach(e=>{const t=e.element,r=m.get(t);r&&(r.col=r.columnCount[w()],e._setDivider(),Array.from(t.children).forEach(o=>{e._setPostPosition(o)}))})}initNewItems(){this._initItems()}addItems(e){typeof e=="string"&&(e=JSON.parse(e)),e.forEach(t=>this.element.appendChild(this._createItemElement(t))),this._initItems()}insertItem(e,t){const r=this.element,o=this._getData();if(!o)return;const s=this._createItemElement(e),i=Array.from(r.children).filter(l=>l.classList.contains("js-mo-item")),n=t==null?Math.floor(Math.random()*(i.length+1)):Math.max(0,Math.min(t,i.length));if(n>=i.length?r.appendChild(s):r.insertBefore(s,i[n]),s.id||(s.id="moT"+crypto.randomUUID()+"_"+n),s.classList.add("mo-item","js-mo-item"),e.fullWidth)s.classList.add("mo-fullwidth","js-mo-fullwidth");else if(o.randomFullWidth){const l=o.randomFullWidth===!0?.33:o.randomFullWidth;Math.random()<l&&s.classList.add("mo-fullwidth","js-mo-fullwidth")}return o.showBadge&&this._createBadge(s,n+1),o.showArrow&&this._createArrow(s),o.showBadge&&o.showCounterStyle==="counter"&&Array.from(r.querySelectorAll(".js-mo-item")).forEach((l,d)=>{const h=l.querySelector(".js-mo-badge");h&&(h.textContent=d+1)}),o.lastItemIdx=Array.from(r.children).length,m.set(r,o),this.refresh(),this._observeItems([s]),s.querySelectorAll("img").forEach(l=>{l.complete||l.addEventListener("load",this._resizeHandler,{once:!0})}),s}destroy(){window.removeEventListener("resize",this._resizeHandler),this._observer&&(this._observer.disconnect(),this._observer=null),m.delete(this.element),c.instances.delete(this),this.element.style.removeProperty("--mo-card-border-radius"),this.element.style.removeProperty("--mo-avatar-size"),this.element.style.removeProperty("--mo-card-margin"),this.element.style.removeProperty("--mo-card-margin-inverted"),this.element.style.removeProperty("--mo-card-margin-fullwidth"),this.element.classList.remove("mo-timeline","mo-theme","mo-twocol","mo-animate","mo-animate-fade","mo-animate-slide"),Array.from(this.element.children).forEach(e=>{e.classList.remove("mo-item","js-mo-item","mo-inverted","js-mo-inverted","mo-offset","mo-fullwidth","js-mo-fullwidth","mo-visible"),e.querySelectorAll(".js-mo-badge, .js-mo-arrow").forEach(t=>t.remove())})}_getData(){return m.get(this.element)}_setDivider(){const e=this._getData();e&&(e.col=e.columnCount[w()],this.element.classList.toggle("mo-twocol",e.col>1))}_initItems(){const e=this.element,t=this._getData();if(!t)return;const r=t.lastItemIdx,o=Array.from(e.children),s=o.slice(r);if(s.length!==0){if(s.forEach((i,n)=>{i.id||(i.id="moT"+crypto.randomUUID()+"_"+(n+r)),i.classList.add("mo-item","js-mo-item")}),this._setDivider(),t.randomFullWidth){const i=t.randomFullWidth===!0?.33:t.randomFullWidth;s.forEach(n=>{!n.classList.contains("mo-fullwidth")&&Math.random()<i&&n.classList.add("mo-fullwidth","js-mo-fullwidth")})}s.forEach((i,n)=>{t.showBadge&&this._createBadge(i,n+r+1),t.showArrow&&this._createArrow(i)}),t.lastItemIdx=o.length,m.set(e,t),this.refresh(),this._observeItems(s),s.forEach(i=>{i.querySelectorAll("img").forEach(n=>{n.complete||n.addEventListener("load",this._resizeHandler,{once:!0})})})}}_setPostPosition(e){if(e.classList.contains("mo-fullwidth")){e.classList.remove("mo-inverted","js-mo-inverted","mo-offset");return}const t=this._getLeftOrRight(e);t&&(e.classList.toggle("mo-inverted",t.lr>0),e.classList.toggle("js-mo-inverted",t.lr>0),e.classList.toggle("mo-offset",t.badge_offset>0))}_getLeftOrRight(e){if(!e)return null;const t=this._getData();if(!t)return null;const r=t.col,o=y(e,".js-mo-inverted")[0]||null,s=y(e,".js-mo-item:not(.js-mo-inverted)")[0]||null,i=f(s),n=f(o),l=f(e);let d=0,h=0;if(r>1){i.gppu>l.o+1&&(d=1),n.gppu>i.gppu&&(d=0);const g=e.previousElementSibling;g&&Math.abs(l.o-f(g).o)<40&&(h=1)}return{lr:d,badge_offset:h}}_createBadge(e,t){const r=this._getData(),o=document.createElement("span");if(o.className="mo-badge js-mo-badge",r.showCounterStyle==="none")o.style.opacity="0";else if(r.showCounterStyle==="image"){const s=document.createElement("img");s.className="mo-badge-icon",s.alt="",s.src=e.dataset.moIcon||E,o.appendChild(s)}else o.textContent=t;e.prepend(o)}_createItemElement(e){const t=document.createElement("li");e.icon&&(t.dataset.moIcon=e.icon);const r=document.createElement("div");if(r.className="mo-card",e.banner){const s=document.createElement("div");s.className="mo-card-image";const i=document.createElement("img");if(i.className="mo-banner",i.src=e.banner,i.alt="",s.appendChild(i),e.avatar){const n=document.createElement("img");n.className="mo-avatar",n.src=e.avatar,n.alt="",s.appendChild(n)}r.appendChild(s)}const o=document.createElement("div");if(o.className="mo-card-body",e.title){const s=document.createElement("h3");s.textContent=e.title,o.appendChild(s)}if(e.meta){const s=document.createElement("p");s.className="mo-meta",s.textContent=e.meta,o.appendChild(s)}if(e.text){const s=document.createElement("p");s.textContent=e.text,o.appendChild(s)}return r.appendChild(o),t.appendChild(r),t}_createArrow(e){const t=document.createElement("span");t.className="mo-arrow js-mo-arrow",e.prepend(t)}_observeItems(e){this._observer&&e.forEach(t=>{t.classList.contains("mo-visible")||this._observer.observe(t)})}};p(c,"instances",new Set);let u=c;exports.MoTimeline=u;exports.default=u;
6
+ */const m=new WeakMap,v={columnCount:{xs:1,sm:2,md:2,lg:2},showBadge:!1,showArrow:!1,theme:!1,showCounterStyle:"counter",cardBorderRadius:"8px",avatarSize:"50px",cardMargin:"0.5rem 1.25rem 0.5rem 0.5rem",cardMarginInverted:"0.5rem 0.5rem 0.5rem 1.25rem",cardMarginFullWidth:"0.5rem",randomFullWidth:0,animate:!1,renderCard:null},E="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='%234f46e5'/><circle cx='12' cy='12' r='4.5' fill='white'/></svg>";function w(){const a=window.innerWidth;return a<600?"xs":a<992?"sm":a<1200?"md":"lg"}function I(a,e=100){let t;return(...r)=>{clearTimeout(t),t=setTimeout(()=>a(...r),e)}}function f(a){return a?{o:a.offsetTop,h:a.offsetHeight,gppu:a.offsetTop+a.offsetHeight}:{o:0,h:0,gppu:0}}function y(a,e){const t=[];let r=a.previousElementSibling;for(;r;)(!e||r.matches(e))&&t.push(r),r=r.previousElementSibling;return t}const d=class d{constructor(e,t={}){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("moTimeline: element not found");this.element=e,this.settings=Object.assign({},v,t),this.settings.columnCount=Object.assign({},v.columnCount,t.columnCount),this._resizeHandler=I(()=>this.refresh(),100),this._initialized=!1,this.init()}init(){const e=this.element;if(m.has(e)){this.refresh();return}const t=Object.assign({},this.settings,{lastItemIdx:0});if(m.set(e,t),d.instances.add(this),e.classList.add("mo-timeline"),t.theme&&e.classList.add("mo-theme"),e.style.setProperty("--mo-card-border-radius",t.cardBorderRadius),e.style.setProperty("--mo-avatar-size",t.avatarSize),e.style.setProperty("--mo-card-margin",t.cardMargin),e.style.setProperty("--mo-card-margin-inverted",t.cardMarginInverted),e.style.setProperty("--mo-card-margin-fullwidth",t.cardMarginFullWidth),t.animate){const r=t.animate===!0?"fade":t.animate;e.classList.add("mo-animate",`mo-animate-${r}`),this._observer=new IntersectionObserver(i=>{i.forEach(s=>{s.isIntersecting&&(s.target.classList.add("mo-visible"),this._observer.unobserve(s.target))})},{threshold:.1})}this._initialized=!0,window.addEventListener("resize",this._resizeHandler),Array.from(e.children).length>0&&this._initItems()}refresh(){d.instances.forEach(e=>{const t=e.element,r=m.get(t);r&&(r.col=r.columnCount[w()],e._setDivider(),Array.from(t.children).forEach(i=>{e._setPostPosition(i)}))})}initNewItems(){this._initItems()}addItems(e){typeof e=="string"&&(e=JSON.parse(e)),e.forEach(t=>this.element.appendChild(this._createItemElement(t))),this._initItems()}insertItem(e,t){const r=this.element,i=this._getData();if(!i)return;const s=this._createItemElement(e),o=Array.from(r.children).filter(l=>l.classList.contains("js-mo-item")),n=t==null?Math.floor(Math.random()*(o.length+1)):Math.max(0,Math.min(t,o.length));if(n>=o.length?r.appendChild(s):r.insertBefore(s,o[n]),s.id||(s.id="moT"+crypto.randomUUID()+"_"+n),s.classList.add("mo-item","js-mo-item"),e.fullWidth)s.classList.add("mo-fullwidth","js-mo-fullwidth");else if(i.randomFullWidth){const l=i.randomFullWidth===!0?.33:i.randomFullWidth;Math.random()<l&&s.classList.add("mo-fullwidth","js-mo-fullwidth")}return i.showBadge&&this._createBadge(s,n+1),i.showArrow&&this._createArrow(s),i.showBadge&&i.showCounterStyle==="counter"&&Array.from(r.querySelectorAll(".js-mo-item")).forEach((l,c)=>{const h=l.querySelector(".js-mo-badge");h&&(h.textContent=c+1)}),i.lastItemIdx=Array.from(r.children).length,m.set(r,i),this.refresh(),this._observeItems([s]),s.querySelectorAll("img").forEach(l=>{l.complete||l.addEventListener("load",this._resizeHandler,{once:!0})}),s}destroy(){window.removeEventListener("resize",this._resizeHandler),this._observer&&(this._observer.disconnect(),this._observer=null),m.delete(this.element),d.instances.delete(this),this.element.style.removeProperty("--mo-card-border-radius"),this.element.style.removeProperty("--mo-avatar-size"),this.element.style.removeProperty("--mo-card-margin"),this.element.style.removeProperty("--mo-card-margin-inverted"),this.element.style.removeProperty("--mo-card-margin-fullwidth"),this.element.classList.remove("mo-timeline","mo-theme","mo-twocol","mo-animate","mo-animate-fade","mo-animate-slide"),Array.from(this.element.children).forEach(e=>{e.classList.remove("mo-item","js-mo-item","mo-inverted","js-mo-inverted","mo-offset","mo-fullwidth","js-mo-fullwidth","mo-visible"),e.querySelectorAll(".js-mo-badge, .js-mo-arrow").forEach(t=>t.remove())})}_getData(){return m.get(this.element)}_setDivider(){const e=this._getData();e&&(e.col=e.columnCount[w()],this.element.classList.toggle("mo-twocol",e.col>1))}_initItems(){const e=this.element,t=this._getData();if(!t)return;const r=t.lastItemIdx,i=Array.from(e.children),s=i.slice(r);if(s.length!==0){if(s.forEach((o,n)=>{o.id||(o.id="moT"+crypto.randomUUID()+"_"+(n+r)),o.classList.add("mo-item","js-mo-item")}),this._setDivider(),t.randomFullWidth){const o=t.randomFullWidth===!0?.33:t.randomFullWidth;s.forEach(n=>{!n.classList.contains("mo-fullwidth")&&Math.random()<o&&n.classList.add("mo-fullwidth","js-mo-fullwidth")})}s.forEach((o,n)=>{t.showBadge&&this._createBadge(o,n+r+1),t.showArrow&&this._createArrow(o)}),t.lastItemIdx=i.length,m.set(e,t),this.refresh(),this._observeItems(s),s.forEach(o=>{o.querySelectorAll("img").forEach(n=>{n.complete||n.addEventListener("load",this._resizeHandler,{once:!0})})})}}_setPostPosition(e){if(e.classList.contains("mo-fullwidth")){e.classList.remove("mo-inverted","js-mo-inverted","mo-offset");return}const t=this._getLeftOrRight(e);t&&(e.classList.toggle("mo-inverted",t.lr>0),e.classList.toggle("js-mo-inverted",t.lr>0),e.classList.toggle("mo-offset",t.badge_offset>0))}_getLeftOrRight(e){if(!e)return null;const t=this._getData();if(!t)return null;const r=t.col,i=y(e,".js-mo-inverted")[0]||null,s=y(e,".js-mo-item:not(.js-mo-inverted)")[0]||null,o=f(s),n=f(i),l=f(e);let c=0,h=0;if(r>1){o.gppu>l.o+1&&(c=1),n.gppu>o.gppu&&(c=0);const g=e.previousElementSibling;g&&Math.abs(l.o-f(g).o)<40&&(h=1)}return{lr:c,badge_offset:h}}_createBadge(e,t){const r=this._getData(),i=document.createElement("span");if(i.className="mo-badge js-mo-badge",r.showCounterStyle==="none")i.style.opacity="0";else if(r.showCounterStyle==="image"){const s=document.createElement("img");s.className="mo-badge-icon",s.alt="",s.src=e.dataset.moIcon||E,i.appendChild(s)}else i.textContent=t;e.prepend(i)}_createItemElement(e){const t=document.createElement("li");e.icon&&(t.dataset.moIcon=e.icon);const r=document.createElement("div");r.className="mo-card";const i=this._getData();if(i&&typeof i.renderCard=="function")i.renderCard(e,r);else{if(e.banner){const o=document.createElement("div");o.className="mo-card-image";const n=document.createElement("img");if(n.className="mo-banner",n.src=e.banner,n.alt="",o.appendChild(n),e.avatar){const l=document.createElement("img");l.className="mo-avatar",l.src=e.avatar,l.alt="",o.appendChild(l)}r.appendChild(o)}const s=document.createElement("div");if(s.className="mo-card-body",e.title){const o=document.createElement("h3");o.textContent=e.title,s.appendChild(o)}if(e.meta){const o=document.createElement("p");o.className="mo-meta",o.textContent=e.meta,s.appendChild(o)}if(e.text){const o=document.createElement("p");o.textContent=e.text,s.appendChild(o)}r.appendChild(s)}return t.appendChild(r),t}_createArrow(e){const t=document.createElement("span");t.className="mo-arrow js-mo-arrow",e.prepend(t)}_observeItems(e){this._observer&&e.forEach(t=>{t.classList.contains("mo-visible")||this._observer.observe(t)})}};p(d,"instances",new Set);let u=d;exports.MoTimeline=u;exports.default=u;
@@ -1,3 +1,3 @@
1
1
  /*!
2
- * moTimeline v2.9.0 — CSS
2
+ * moTimeline v2.10.0 — CSS
3
3
  */:root{--mo-line-color: #dde1e7;--mo-badge-bg: #4f46e5;--mo-badge-color: #fff;--mo-badge-size: 26px;--mo-badge-font-size: 12px;--mo-arrow-color: #dde1e7}.mo-timeline{display:block;list-style:none;margin:0;padding:0;position:relative;width:100%}.mo-timeline:after{content:"";display:table;clear:both}.mo-timeline.mo-twocol:before{background-color:var(--mo-line-color);bottom:0;content:"";left:50%;margin-left:-1.5px;position:absolute;top:0;width:3px;z-index:0}.mo-timeline>.mo-item{box-sizing:border-box;display:block;float:left;position:relative;width:50%}.mo-timeline:not(.mo-twocol)>.mo-item{float:none;width:100%}.mo-timeline>.mo-item.mo-inverted{float:right}.mo-timeline.mo-twocol>.mo-item.mo-fullwidth{clear:both;float:none;width:100%}.mo-theme>.mo-item.mo-fullwidth .mo-card{margin:var(--mo-card-margin-fullwidth, .5rem)}.mo-timeline.mo-twocol>.mo-item.mo-fullwidth .mo-badge,.mo-timeline.mo-twocol>.mo-item.mo-fullwidth .mo-arrow{display:none}.mo-badge{align-items:center;background:var(--mo-badge-bg);border-radius:50%;color:var(--mo-badge-color);display:flex;font-size:var(--mo-badge-font-size);font-weight:700;height:var(--mo-badge-size);justify-content:center;min-width:var(--mo-badge-size);overflow:hidden;position:absolute;top:18px;z-index:2}.mo-badge .mo-badge-icon{border-radius:50%;height:100%;object-fit:cover;width:100%}.mo-timeline.mo-twocol>.mo-item:not(.mo-inverted) .mo-badge{left:auto;right:calc(var(--mo-badge-size) / -2)}.mo-timeline.mo-twocol>.mo-item.mo-inverted .mo-badge{left:calc(var(--mo-badge-size) / -2);right:auto}.mo-timeline.mo-twocol>.mo-item.mo-offset .mo-badge{top:calc(18px + var(--mo-badge-size) + 10px)}.mo-timeline.mo-twocol>.mo-item.mo-offset .mo-arrow{top:calc(26px + var(--mo-badge-size) + 10px)}.mo-timeline:not(.mo-twocol)>.mo-item .mo-badge{display:none}.mo-arrow{border:8px solid transparent;display:block;height:0;position:absolute;top:26px;width:0;z-index:1}.mo-timeline.mo-twocol>.mo-item:not(.mo-inverted) .mo-arrow{border-left:8px solid var(--mo-arrow-color);border-right:none;left:auto;right:0}.mo-timeline.mo-twocol>.mo-item.mo-inverted .mo-arrow{border-right:8px solid var(--mo-arrow-color);border-left:none;left:0;right:auto}.mo-timeline:not(.mo-twocol)>.mo-item .mo-arrow{display:none}.mo-theme{--mo-arrow-color: #fff}.mo-theme>.mo-item .mo-card{background:#fff;border-radius:var(--mo-card-border-radius, 8px);box-shadow:0 2px 14px #0000001a;margin:var(--mo-card-margin, .5rem 1.25rem .5rem .5rem);position:relative}.mo-theme>.mo-item.mo-inverted .mo-card{margin:var(--mo-card-margin-inverted, .5rem .5rem .5rem 1.25rem)}.mo-theme>.mo-item .mo-banner{border-radius:var(--mo-card-border-radius, 8px) var(--mo-card-border-radius, 8px) 0 0;display:block;max-height:240px;object-fit:cover;width:100%}.mo-theme>.mo-item .mo-card-image{overflow:visible;position:relative}.mo-theme>.mo-item .mo-avatar{border:3px solid #fff;border-radius:50%;bottom:calc(var(--mo-avatar-size, 50px) * -.44);box-shadow:0 2px 8px #0000002e;height:var(--mo-avatar-size, 50px);object-fit:cover;position:absolute;right:14px;width:var(--mo-avatar-size, 50px);z-index:1}.mo-theme>.mo-item .mo-card-body{padding:1.75rem 1rem 1rem}.mo-theme>.mo-item .mo-card-body h3{font-size:1rem;font-weight:700;margin:0 0 .3rem}.mo-theme>.mo-item .mo-card-body .mo-meta{color:#9ca3af;font-size:.75rem;margin-bottom:.5rem}.mo-theme>.mo-item .mo-card-body p{color:#6b7280;font-size:.875rem;line-height:1.55;margin:0}.mo-theme.mo-twocol>.mo-item:not(.mo-inverted) .mo-arrow{border-left-color:var(--mo-arrow-color);right:12px}.mo-theme.mo-twocol>.mo-item.mo-inverted .mo-arrow{border-right-color:var(--mo-arrow-color);left:12px}.mo-theme .mo-badge{background:#fff;border:2px solid var(--mo-line-color);box-shadow:0 2px 6px #0000001a;color:#374151}.mo-timeline.mo-animate>.mo-item{transition:opacity var(--mo-animate-duration, .5s) ease,transform var(--mo-animate-duration, .5s) ease}.mo-timeline.mo-animate-fade>.mo-item{opacity:0}.mo-timeline.mo-animate-slide>.mo-item:not(.mo-inverted){opacity:0;transform:translate(-40px)}.mo-timeline.mo-animate-slide>.mo-item.mo-inverted{opacity:0;transform:translate(40px)}.mo-timeline:not(.mo-twocol).mo-animate-slide>.mo-item{transform:translate(-40px)}.mo-timeline.mo-animate>.mo-item.mo-visible{opacity:1;transform:translate(0)}
@@ -2,7 +2,7 @@ var _ = Object.defineProperty;
2
2
  var b = (a, e, t) => e in a ? _(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
3
  var g = (a, e, t) => b(a, typeof e != "symbol" ? e + "" : e, t);
4
4
  /*!
5
- * moTimeline v2.9.0
5
+ * moTimeline v2.10.0
6
6
  * Responsive two-column timeline layout library
7
7
  * https://github.com/MattOpen/moTimeline
8
8
  * MIT License
@@ -21,8 +21,10 @@ const m = /* @__PURE__ */ new WeakMap(), p = {
21
21
  cardMarginFullWidth: "0.5rem",
22
22
  randomFullWidth: 0,
23
23
  // 0 = off; 0–1 = probability per item; true = 0.33
24
- animate: !1
24
+ animate: !1,
25
25
  // false | 'fade' | 'slide'
26
+ renderCard: null
27
+ // (item, cardEl) => void — custom card renderer; skips built-in HTML
26
28
  }, E = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='%234f46e5'/><circle cx='12' cy='12' r='4.5' fill='white'/></svg>";
27
29
  function v() {
28
30
  const a = window.innerWidth;
@@ -48,7 +50,7 @@ function w(a, e) {
48
50
  (!e || r.matches(e)) && t.push(r), r = r.previousElementSibling;
49
51
  return t;
50
52
  }
51
- const c = class c {
53
+ const d = class d {
52
54
  constructor(e, t = {}) {
53
55
  if (typeof e == "string" && (e = document.querySelector(e)), !e) throw new Error("moTimeline: element not found");
54
56
  this.element = e, this.settings = Object.assign({}, p, t), this.settings.columnCount = Object.assign({}, p.columnCount, t.columnCount), this._resizeHandler = I(() => this.refresh(), 100), this._initialized = !1, this.init();
@@ -60,10 +62,10 @@ const c = class c {
60
62
  return;
61
63
  }
62
64
  const t = Object.assign({}, this.settings, { lastItemIdx: 0 });
63
- if (m.set(e, t), c.instances.add(this), e.classList.add("mo-timeline"), t.theme && e.classList.add("mo-theme"), e.style.setProperty("--mo-card-border-radius", t.cardBorderRadius), e.style.setProperty("--mo-avatar-size", t.avatarSize), e.style.setProperty("--mo-card-margin", t.cardMargin), e.style.setProperty("--mo-card-margin-inverted", t.cardMarginInverted), e.style.setProperty("--mo-card-margin-fullwidth", t.cardMarginFullWidth), t.animate) {
65
+ if (m.set(e, t), d.instances.add(this), e.classList.add("mo-timeline"), t.theme && e.classList.add("mo-theme"), e.style.setProperty("--mo-card-border-radius", t.cardBorderRadius), e.style.setProperty("--mo-avatar-size", t.avatarSize), e.style.setProperty("--mo-card-margin", t.cardMargin), e.style.setProperty("--mo-card-margin-inverted", t.cardMarginInverted), e.style.setProperty("--mo-card-margin-fullwidth", t.cardMarginFullWidth), t.animate) {
64
66
  const r = t.animate === !0 ? "fade" : t.animate;
65
- e.classList.add("mo-animate", `mo-animate-${r}`), this._observer = new IntersectionObserver((o) => {
66
- o.forEach((s) => {
67
+ e.classList.add("mo-animate", `mo-animate-${r}`), this._observer = new IntersectionObserver((i) => {
68
+ i.forEach((s) => {
67
69
  s.isIntersecting && (s.target.classList.add("mo-visible"), this._observer.unobserve(s.target));
68
70
  });
69
71
  }, { threshold: 0.1 });
@@ -71,10 +73,10 @@ const c = class c {
71
73
  this._initialized = !0, window.addEventListener("resize", this._resizeHandler), Array.from(e.children).length > 0 && this._initItems();
72
74
  }
73
75
  refresh() {
74
- c.instances.forEach((e) => {
76
+ d.instances.forEach((e) => {
75
77
  const t = e.element, r = m.get(t);
76
- r && (r.col = r.columnCount[v()], e._setDivider(), Array.from(t.children).forEach((o) => {
77
- e._setPostPosition(o);
78
+ r && (r.col = r.columnCount[v()], e._setDivider(), Array.from(t.children).forEach((i) => {
79
+ e._setPostPosition(i);
78
80
  }));
79
81
  });
80
82
  }
@@ -101,24 +103,24 @@ const c = class c {
101
103
  * @returns {HTMLElement} the inserted <li> element
102
104
  */
103
105
  insertItem(e, t) {
104
- const r = this.element, o = this._getData();
105
- if (!o) return;
106
- const s = this._createItemElement(e), i = Array.from(r.children).filter((l) => l.classList.contains("js-mo-item")), n = t == null ? Math.floor(Math.random() * (i.length + 1)) : Math.max(0, Math.min(t, i.length));
107
- if (n >= i.length ? r.appendChild(s) : r.insertBefore(s, i[n]), s.id || (s.id = "moT" + crypto.randomUUID() + "_" + n), s.classList.add("mo-item", "js-mo-item"), e.fullWidth)
106
+ const r = this.element, i = this._getData();
107
+ if (!i) return;
108
+ const s = this._createItemElement(e), o = Array.from(r.children).filter((l) => l.classList.contains("js-mo-item")), n = t == null ? Math.floor(Math.random() * (o.length + 1)) : Math.max(0, Math.min(t, o.length));
109
+ if (n >= o.length ? r.appendChild(s) : r.insertBefore(s, o[n]), s.id || (s.id = "moT" + crypto.randomUUID() + "_" + n), s.classList.add("mo-item", "js-mo-item"), e.fullWidth)
108
110
  s.classList.add("mo-fullwidth", "js-mo-fullwidth");
109
- else if (o.randomFullWidth) {
110
- const l = o.randomFullWidth === !0 ? 0.33 : o.randomFullWidth;
111
+ else if (i.randomFullWidth) {
112
+ const l = i.randomFullWidth === !0 ? 0.33 : i.randomFullWidth;
111
113
  Math.random() < l && s.classList.add("mo-fullwidth", "js-mo-fullwidth");
112
114
  }
113
- return o.showBadge && this._createBadge(s, n + 1), o.showArrow && this._createArrow(s), o.showBadge && o.showCounterStyle === "counter" && Array.from(r.querySelectorAll(".js-mo-item")).forEach((l, d) => {
115
+ return i.showBadge && this._createBadge(s, n + 1), i.showArrow && this._createArrow(s), i.showBadge && i.showCounterStyle === "counter" && Array.from(r.querySelectorAll(".js-mo-item")).forEach((l, c) => {
114
116
  const h = l.querySelector(".js-mo-badge");
115
- h && (h.textContent = d + 1);
116
- }), o.lastItemIdx = Array.from(r.children).length, m.set(r, o), this.refresh(), this._observeItems([s]), s.querySelectorAll("img").forEach((l) => {
117
+ h && (h.textContent = c + 1);
118
+ }), i.lastItemIdx = Array.from(r.children).length, m.set(r, i), this.refresh(), this._observeItems([s]), s.querySelectorAll("img").forEach((l) => {
117
119
  l.complete || l.addEventListener("load", this._resizeHandler, { once: !0 });
118
120
  }), s;
119
121
  }
120
122
  destroy() {
121
- window.removeEventListener("resize", this._resizeHandler), this._observer && (this._observer.disconnect(), this._observer = null), m.delete(this.element), c.instances.delete(this), this.element.style.removeProperty("--mo-card-border-radius"), this.element.style.removeProperty("--mo-avatar-size"), this.element.style.removeProperty("--mo-card-margin"), this.element.style.removeProperty("--mo-card-margin-inverted"), this.element.style.removeProperty("--mo-card-margin-fullwidth"), this.element.classList.remove("mo-timeline", "mo-theme", "mo-twocol", "mo-animate", "mo-animate-fade", "mo-animate-slide"), Array.from(this.element.children).forEach((e) => {
123
+ window.removeEventListener("resize", this._resizeHandler), this._observer && (this._observer.disconnect(), this._observer = null), m.delete(this.element), d.instances.delete(this), this.element.style.removeProperty("--mo-card-border-radius"), this.element.style.removeProperty("--mo-avatar-size"), this.element.style.removeProperty("--mo-card-margin"), this.element.style.removeProperty("--mo-card-margin-inverted"), this.element.style.removeProperty("--mo-card-margin-fullwidth"), this.element.classList.remove("mo-timeline", "mo-theme", "mo-twocol", "mo-animate", "mo-animate-fade", "mo-animate-slide"), Array.from(this.element.children).forEach((e) => {
122
124
  e.classList.remove("mo-item", "js-mo-item", "mo-inverted", "js-mo-inverted", "mo-offset", "mo-fullwidth", "js-mo-fullwidth", "mo-visible"), e.querySelectorAll(".js-mo-badge, .js-mo-arrow").forEach((t) => t.remove());
123
125
  });
124
126
  }
@@ -133,20 +135,20 @@ const c = class c {
133
135
  _initItems() {
134
136
  const e = this.element, t = this._getData();
135
137
  if (!t) return;
136
- const r = t.lastItemIdx, o = Array.from(e.children), s = o.slice(r);
138
+ const r = t.lastItemIdx, i = Array.from(e.children), s = i.slice(r);
137
139
  if (s.length !== 0) {
138
- if (s.forEach((i, n) => {
139
- i.id || (i.id = "moT" + crypto.randomUUID() + "_" + (n + r)), i.classList.add("mo-item", "js-mo-item");
140
+ if (s.forEach((o, n) => {
141
+ o.id || (o.id = "moT" + crypto.randomUUID() + "_" + (n + r)), o.classList.add("mo-item", "js-mo-item");
140
142
  }), this._setDivider(), t.randomFullWidth) {
141
- const i = t.randomFullWidth === !0 ? 0.33 : t.randomFullWidth;
143
+ const o = t.randomFullWidth === !0 ? 0.33 : t.randomFullWidth;
142
144
  s.forEach((n) => {
143
- !n.classList.contains("mo-fullwidth") && Math.random() < i && n.classList.add("mo-fullwidth", "js-mo-fullwidth");
145
+ !n.classList.contains("mo-fullwidth") && Math.random() < o && n.classList.add("mo-fullwidth", "js-mo-fullwidth");
144
146
  });
145
147
  }
146
- s.forEach((i, n) => {
147
- t.showBadge && this._createBadge(i, n + r + 1), t.showArrow && this._createArrow(i);
148
- }), t.lastItemIdx = o.length, m.set(e, t), this.refresh(), this._observeItems(s), s.forEach((i) => {
149
- i.querySelectorAll("img").forEach((n) => {
148
+ s.forEach((o, n) => {
149
+ t.showBadge && this._createBadge(o, n + r + 1), t.showArrow && this._createArrow(o);
150
+ }), t.lastItemIdx = i.length, m.set(e, t), this.refresh(), this._observeItems(s), s.forEach((o) => {
151
+ o.querySelectorAll("img").forEach((n) => {
150
152
  n.complete || n.addEventListener("load", this._resizeHandler, { once: !0 });
151
153
  });
152
154
  });
@@ -164,54 +166,61 @@ const c = class c {
164
166
  if (!e) return null;
165
167
  const t = this._getData();
166
168
  if (!t) return null;
167
- const r = t.col, o = w(e, ".js-mo-inverted")[0] || null, s = w(e, ".js-mo-item:not(.js-mo-inverted)")[0] || null, i = f(s), n = f(o), l = f(e);
168
- let d = 0, h = 0;
169
+ const r = t.col, i = w(e, ".js-mo-inverted")[0] || null, s = w(e, ".js-mo-item:not(.js-mo-inverted)")[0] || null, o = f(s), n = f(i), l = f(e);
170
+ let c = 0, h = 0;
169
171
  if (r > 1) {
170
- i.gppu > l.o + 1 && (d = 1), n.gppu > i.gppu && (d = 0);
172
+ o.gppu > l.o + 1 && (c = 1), n.gppu > o.gppu && (c = 0);
171
173
  const u = e.previousElementSibling;
172
174
  u && Math.abs(l.o - f(u).o) < 40 && (h = 1);
173
175
  }
174
- return { lr: d, badge_offset: h };
176
+ return { lr: c, badge_offset: h };
175
177
  }
176
178
  _createBadge(e, t) {
177
- const r = this._getData(), o = document.createElement("span");
178
- if (o.className = "mo-badge js-mo-badge", r.showCounterStyle === "none")
179
- o.style.opacity = "0";
179
+ const r = this._getData(), i = document.createElement("span");
180
+ if (i.className = "mo-badge js-mo-badge", r.showCounterStyle === "none")
181
+ i.style.opacity = "0";
180
182
  else if (r.showCounterStyle === "image") {
181
183
  const s = document.createElement("img");
182
- s.className = "mo-badge-icon", s.alt = "", s.src = e.dataset.moIcon || E, o.appendChild(s);
184
+ s.className = "mo-badge-icon", s.alt = "", s.src = e.dataset.moIcon || E, i.appendChild(s);
183
185
  } else
184
- o.textContent = t;
185
- e.prepend(o);
186
+ i.textContent = t;
187
+ e.prepend(i);
186
188
  }
187
189
  _createItemElement(e) {
188
190
  const t = document.createElement("li");
189
191
  e.icon && (t.dataset.moIcon = e.icon);
190
192
  const r = document.createElement("div");
191
- if (r.className = "mo-card", e.banner) {
192
- const s = document.createElement("div");
193
- s.className = "mo-card-image";
194
- const i = document.createElement("img");
195
- if (i.className = "mo-banner", i.src = e.banner, i.alt = "", s.appendChild(i), e.avatar) {
193
+ r.className = "mo-card";
194
+ const i = this._getData();
195
+ if (i && typeof i.renderCard == "function")
196
+ i.renderCard(e, r);
197
+ else {
198
+ if (e.banner) {
199
+ const o = document.createElement("div");
200
+ o.className = "mo-card-image";
196
201
  const n = document.createElement("img");
197
- n.className = "mo-avatar", n.src = e.avatar, n.alt = "", s.appendChild(n);
202
+ if (n.className = "mo-banner", n.src = e.banner, n.alt = "", o.appendChild(n), e.avatar) {
203
+ const l = document.createElement("img");
204
+ l.className = "mo-avatar", l.src = e.avatar, l.alt = "", o.appendChild(l);
205
+ }
206
+ r.appendChild(o);
207
+ }
208
+ const s = document.createElement("div");
209
+ if (s.className = "mo-card-body", e.title) {
210
+ const o = document.createElement("h3");
211
+ o.textContent = e.title, s.appendChild(o);
212
+ }
213
+ if (e.meta) {
214
+ const o = document.createElement("p");
215
+ o.className = "mo-meta", o.textContent = e.meta, s.appendChild(o);
216
+ }
217
+ if (e.text) {
218
+ const o = document.createElement("p");
219
+ o.textContent = e.text, s.appendChild(o);
198
220
  }
199
221
  r.appendChild(s);
200
222
  }
201
- const o = document.createElement("div");
202
- if (o.className = "mo-card-body", e.title) {
203
- const s = document.createElement("h3");
204
- s.textContent = e.title, o.appendChild(s);
205
- }
206
- if (e.meta) {
207
- const s = document.createElement("p");
208
- s.className = "mo-meta", s.textContent = e.meta, o.appendChild(s);
209
- }
210
- if (e.text) {
211
- const s = document.createElement("p");
212
- s.textContent = e.text, o.appendChild(s);
213
- }
214
- return r.appendChild(o), t.appendChild(r), t;
223
+ return t.appendChild(r), t;
215
224
  }
216
225
  _createArrow(e) {
217
226
  const t = document.createElement("span");
@@ -223,8 +232,8 @@ const c = class c {
223
232
  });
224
233
  }
225
234
  };
226
- g(c, "instances", /* @__PURE__ */ new Set());
227
- let y = c;
235
+ g(d, "instances", /* @__PURE__ */ new Set());
236
+ let y = d;
228
237
  export {
229
238
  y as MoTimeline,
230
239
  y as default
@@ -1,6 +1,6 @@
1
- (function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.MoTimeline={}))})(this,function(l){"use strict";var I=Object.defineProperty;var L=(l,a,c)=>a in l?I(l,a,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[a]=c;var b=(l,a,c)=>L(l,typeof a!="symbol"?a+"":a,c);/*!
2
- * moTimeline v2.9.0
1
+ (function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.MoTimeline={}))})(this,function(d){"use strict";var I=Object.defineProperty;var C=(d,a,c)=>a in d?I(d,a,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[a]=c;var _=(d,a,c)=>C(d,typeof a!="symbol"?a+"":a,c);/*!
2
+ * moTimeline v2.10.0
3
3
  * Responsive two-column timeline layout library
4
4
  * https://github.com/MattOpen/moTimeline
5
5
  * MIT License
6
- */const a=new WeakMap,c={columnCount:{xs:1,sm:2,md:2,lg:2},showBadge:!1,showArrow:!1,theme:!1,showCounterStyle:"counter",cardBorderRadius:"8px",avatarSize:"50px",cardMargin:"0.5rem 1.25rem 0.5rem 0.5rem",cardMarginInverted:"0.5rem 0.5rem 0.5rem 1.25rem",cardMarginFullWidth:"0.5rem",randomFullWidth:0,animate:!1},_="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='%234f46e5'/><circle cx='12' cy='12' r='4.5' fill='white'/></svg>";function v(){const m=window.innerWidth;return m<600?"xs":m<992?"sm":m<1200?"md":"lg"}function E(m,e=100){let t;return(...r)=>{clearTimeout(t),t=setTimeout(()=>m(...r),e)}}function g(m){return m?{o:m.offsetTop,h:m.offsetHeight,gppu:m.offsetTop+m.offsetHeight}:{o:0,h:0,gppu:0}}function w(m,e){const t=[];let r=m.previousElementSibling;for(;r;)(!e||r.matches(e))&&t.push(r),r=r.previousElementSibling;return t}const h=class h{constructor(e,t={}){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("moTimeline: element not found");this.element=e,this.settings=Object.assign({},c,t),this.settings.columnCount=Object.assign({},c.columnCount,t.columnCount),this._resizeHandler=E(()=>this.refresh(),100),this._initialized=!1,this.init()}init(){const e=this.element;if(a.has(e)){this.refresh();return}const t=Object.assign({},this.settings,{lastItemIdx:0});if(a.set(e,t),h.instances.add(this),e.classList.add("mo-timeline"),t.theme&&e.classList.add("mo-theme"),e.style.setProperty("--mo-card-border-radius",t.cardBorderRadius),e.style.setProperty("--mo-avatar-size",t.avatarSize),e.style.setProperty("--mo-card-margin",t.cardMargin),e.style.setProperty("--mo-card-margin-inverted",t.cardMarginInverted),e.style.setProperty("--mo-card-margin-fullwidth",t.cardMarginFullWidth),t.animate){const r=t.animate===!0?"fade":t.animate;e.classList.add("mo-animate",`mo-animate-${r}`),this._observer=new IntersectionObserver(o=>{o.forEach(s=>{s.isIntersecting&&(s.target.classList.add("mo-visible"),this._observer.unobserve(s.target))})},{threshold:.1})}this._initialized=!0,window.addEventListener("resize",this._resizeHandler),Array.from(e.children).length>0&&this._initItems()}refresh(){h.instances.forEach(e=>{const t=e.element,r=a.get(t);r&&(r.col=r.columnCount[v()],e._setDivider(),Array.from(t.children).forEach(o=>{e._setPostPosition(o)}))})}initNewItems(){this._initItems()}addItems(e){typeof e=="string"&&(e=JSON.parse(e)),e.forEach(t=>this.element.appendChild(this._createItemElement(t))),this._initItems()}insertItem(e,t){const r=this.element,o=this._getData();if(!o)return;const s=this._createItemElement(e),i=Array.from(r.children).filter(d=>d.classList.contains("js-mo-item")),n=t==null?Math.floor(Math.random()*(i.length+1)):Math.max(0,Math.min(t,i.length));if(n>=i.length?r.appendChild(s):r.insertBefore(s,i[n]),s.id||(s.id="moT"+crypto.randomUUID()+"_"+n),s.classList.add("mo-item","js-mo-item"),e.fullWidth)s.classList.add("mo-fullwidth","js-mo-fullwidth");else if(o.randomFullWidth){const d=o.randomFullWidth===!0?.33:o.randomFullWidth;Math.random()<d&&s.classList.add("mo-fullwidth","js-mo-fullwidth")}return o.showBadge&&this._createBadge(s,n+1),o.showArrow&&this._createArrow(s),o.showBadge&&o.showCounterStyle==="counter"&&Array.from(r.querySelectorAll(".js-mo-item")).forEach((d,f)=>{const u=d.querySelector(".js-mo-badge");u&&(u.textContent=f+1)}),o.lastItemIdx=Array.from(r.children).length,a.set(r,o),this.refresh(),this._observeItems([s]),s.querySelectorAll("img").forEach(d=>{d.complete||d.addEventListener("load",this._resizeHandler,{once:!0})}),s}destroy(){window.removeEventListener("resize",this._resizeHandler),this._observer&&(this._observer.disconnect(),this._observer=null),a.delete(this.element),h.instances.delete(this),this.element.style.removeProperty("--mo-card-border-radius"),this.element.style.removeProperty("--mo-avatar-size"),this.element.style.removeProperty("--mo-card-margin"),this.element.style.removeProperty("--mo-card-margin-inverted"),this.element.style.removeProperty("--mo-card-margin-fullwidth"),this.element.classList.remove("mo-timeline","mo-theme","mo-twocol","mo-animate","mo-animate-fade","mo-animate-slide"),Array.from(this.element.children).forEach(e=>{e.classList.remove("mo-item","js-mo-item","mo-inverted","js-mo-inverted","mo-offset","mo-fullwidth","js-mo-fullwidth","mo-visible"),e.querySelectorAll(".js-mo-badge, .js-mo-arrow").forEach(t=>t.remove())})}_getData(){return a.get(this.element)}_setDivider(){const e=this._getData();e&&(e.col=e.columnCount[v()],this.element.classList.toggle("mo-twocol",e.col>1))}_initItems(){const e=this.element,t=this._getData();if(!t)return;const r=t.lastItemIdx,o=Array.from(e.children),s=o.slice(r);if(s.length!==0){if(s.forEach((i,n)=>{i.id||(i.id="moT"+crypto.randomUUID()+"_"+(n+r)),i.classList.add("mo-item","js-mo-item")}),this._setDivider(),t.randomFullWidth){const i=t.randomFullWidth===!0?.33:t.randomFullWidth;s.forEach(n=>{!n.classList.contains("mo-fullwidth")&&Math.random()<i&&n.classList.add("mo-fullwidth","js-mo-fullwidth")})}s.forEach((i,n)=>{t.showBadge&&this._createBadge(i,n+r+1),t.showArrow&&this._createArrow(i)}),t.lastItemIdx=o.length,a.set(e,t),this.refresh(),this._observeItems(s),s.forEach(i=>{i.querySelectorAll("img").forEach(n=>{n.complete||n.addEventListener("load",this._resizeHandler,{once:!0})})})}}_setPostPosition(e){if(e.classList.contains("mo-fullwidth")){e.classList.remove("mo-inverted","js-mo-inverted","mo-offset");return}const t=this._getLeftOrRight(e);t&&(e.classList.toggle("mo-inverted",t.lr>0),e.classList.toggle("js-mo-inverted",t.lr>0),e.classList.toggle("mo-offset",t.badge_offset>0))}_getLeftOrRight(e){if(!e)return null;const t=this._getData();if(!t)return null;const r=t.col,o=w(e,".js-mo-inverted")[0]||null,s=w(e,".js-mo-item:not(.js-mo-inverted)")[0]||null,i=g(s),n=g(o),d=g(e);let f=0,u=0;if(r>1){i.gppu>d.o+1&&(f=1),n.gppu>i.gppu&&(f=0);const y=e.previousElementSibling;y&&Math.abs(d.o-g(y).o)<40&&(u=1)}return{lr:f,badge_offset:u}}_createBadge(e,t){const r=this._getData(),o=document.createElement("span");if(o.className="mo-badge js-mo-badge",r.showCounterStyle==="none")o.style.opacity="0";else if(r.showCounterStyle==="image"){const s=document.createElement("img");s.className="mo-badge-icon",s.alt="",s.src=e.dataset.moIcon||_,o.appendChild(s)}else o.textContent=t;e.prepend(o)}_createItemElement(e){const t=document.createElement("li");e.icon&&(t.dataset.moIcon=e.icon);const r=document.createElement("div");if(r.className="mo-card",e.banner){const s=document.createElement("div");s.className="mo-card-image";const i=document.createElement("img");if(i.className="mo-banner",i.src=e.banner,i.alt="",s.appendChild(i),e.avatar){const n=document.createElement("img");n.className="mo-avatar",n.src=e.avatar,n.alt="",s.appendChild(n)}r.appendChild(s)}const o=document.createElement("div");if(o.className="mo-card-body",e.title){const s=document.createElement("h3");s.textContent=e.title,o.appendChild(s)}if(e.meta){const s=document.createElement("p");s.className="mo-meta",s.textContent=e.meta,o.appendChild(s)}if(e.text){const s=document.createElement("p");s.textContent=e.text,o.appendChild(s)}return r.appendChild(o),t.appendChild(r),t}_createArrow(e){const t=document.createElement("span");t.className="mo-arrow js-mo-arrow",e.prepend(t)}_observeItems(e){this._observer&&e.forEach(t=>{t.classList.contains("mo-visible")||this._observer.observe(t)})}};b(h,"instances",new Set);let p=h;l.MoTimeline=p,l.default=p,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
6
+ */const a=new WeakMap,c={columnCount:{xs:1,sm:2,md:2,lg:2},showBadge:!1,showArrow:!1,theme:!1,showCounterStyle:"counter",cardBorderRadius:"8px",avatarSize:"50px",cardMargin:"0.5rem 1.25rem 0.5rem 0.5rem",cardMarginInverted:"0.5rem 0.5rem 0.5rem 1.25rem",cardMarginFullWidth:"0.5rem",randomFullWidth:0,animate:!1,renderCard:null},b="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='%234f46e5'/><circle cx='12' cy='12' r='4.5' fill='white'/></svg>";function v(){const m=window.innerWidth;return m<600?"xs":m<992?"sm":m<1200?"md":"lg"}function E(m,e=100){let t;return(...r)=>{clearTimeout(t),t=setTimeout(()=>m(...r),e)}}function g(m){return m?{o:m.offsetTop,h:m.offsetHeight,gppu:m.offsetTop+m.offsetHeight}:{o:0,h:0,gppu:0}}function w(m,e){const t=[];let r=m.previousElementSibling;for(;r;)(!e||r.matches(e))&&t.push(r),r=r.previousElementSibling;return t}const h=class h{constructor(e,t={}){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("moTimeline: element not found");this.element=e,this.settings=Object.assign({},c,t),this.settings.columnCount=Object.assign({},c.columnCount,t.columnCount),this._resizeHandler=E(()=>this.refresh(),100),this._initialized=!1,this.init()}init(){const e=this.element;if(a.has(e)){this.refresh();return}const t=Object.assign({},this.settings,{lastItemIdx:0});if(a.set(e,t),h.instances.add(this),e.classList.add("mo-timeline"),t.theme&&e.classList.add("mo-theme"),e.style.setProperty("--mo-card-border-radius",t.cardBorderRadius),e.style.setProperty("--mo-avatar-size",t.avatarSize),e.style.setProperty("--mo-card-margin",t.cardMargin),e.style.setProperty("--mo-card-margin-inverted",t.cardMarginInverted),e.style.setProperty("--mo-card-margin-fullwidth",t.cardMarginFullWidth),t.animate){const r=t.animate===!0?"fade":t.animate;e.classList.add("mo-animate",`mo-animate-${r}`),this._observer=new IntersectionObserver(i=>{i.forEach(s=>{s.isIntersecting&&(s.target.classList.add("mo-visible"),this._observer.unobserve(s.target))})},{threshold:.1})}this._initialized=!0,window.addEventListener("resize",this._resizeHandler),Array.from(e.children).length>0&&this._initItems()}refresh(){h.instances.forEach(e=>{const t=e.element,r=a.get(t);r&&(r.col=r.columnCount[v()],e._setDivider(),Array.from(t.children).forEach(i=>{e._setPostPosition(i)}))})}initNewItems(){this._initItems()}addItems(e){typeof e=="string"&&(e=JSON.parse(e)),e.forEach(t=>this.element.appendChild(this._createItemElement(t))),this._initItems()}insertItem(e,t){const r=this.element,i=this._getData();if(!i)return;const s=this._createItemElement(e),o=Array.from(r.children).filter(l=>l.classList.contains("js-mo-item")),n=t==null?Math.floor(Math.random()*(o.length+1)):Math.max(0,Math.min(t,o.length));if(n>=o.length?r.appendChild(s):r.insertBefore(s,o[n]),s.id||(s.id="moT"+crypto.randomUUID()+"_"+n),s.classList.add("mo-item","js-mo-item"),e.fullWidth)s.classList.add("mo-fullwidth","js-mo-fullwidth");else if(i.randomFullWidth){const l=i.randomFullWidth===!0?.33:i.randomFullWidth;Math.random()<l&&s.classList.add("mo-fullwidth","js-mo-fullwidth")}return i.showBadge&&this._createBadge(s,n+1),i.showArrow&&this._createArrow(s),i.showBadge&&i.showCounterStyle==="counter"&&Array.from(r.querySelectorAll(".js-mo-item")).forEach((l,f)=>{const u=l.querySelector(".js-mo-badge");u&&(u.textContent=f+1)}),i.lastItemIdx=Array.from(r.children).length,a.set(r,i),this.refresh(),this._observeItems([s]),s.querySelectorAll("img").forEach(l=>{l.complete||l.addEventListener("load",this._resizeHandler,{once:!0})}),s}destroy(){window.removeEventListener("resize",this._resizeHandler),this._observer&&(this._observer.disconnect(),this._observer=null),a.delete(this.element),h.instances.delete(this),this.element.style.removeProperty("--mo-card-border-radius"),this.element.style.removeProperty("--mo-avatar-size"),this.element.style.removeProperty("--mo-card-margin"),this.element.style.removeProperty("--mo-card-margin-inverted"),this.element.style.removeProperty("--mo-card-margin-fullwidth"),this.element.classList.remove("mo-timeline","mo-theme","mo-twocol","mo-animate","mo-animate-fade","mo-animate-slide"),Array.from(this.element.children).forEach(e=>{e.classList.remove("mo-item","js-mo-item","mo-inverted","js-mo-inverted","mo-offset","mo-fullwidth","js-mo-fullwidth","mo-visible"),e.querySelectorAll(".js-mo-badge, .js-mo-arrow").forEach(t=>t.remove())})}_getData(){return a.get(this.element)}_setDivider(){const e=this._getData();e&&(e.col=e.columnCount[v()],this.element.classList.toggle("mo-twocol",e.col>1))}_initItems(){const e=this.element,t=this._getData();if(!t)return;const r=t.lastItemIdx,i=Array.from(e.children),s=i.slice(r);if(s.length!==0){if(s.forEach((o,n)=>{o.id||(o.id="moT"+crypto.randomUUID()+"_"+(n+r)),o.classList.add("mo-item","js-mo-item")}),this._setDivider(),t.randomFullWidth){const o=t.randomFullWidth===!0?.33:t.randomFullWidth;s.forEach(n=>{!n.classList.contains("mo-fullwidth")&&Math.random()<o&&n.classList.add("mo-fullwidth","js-mo-fullwidth")})}s.forEach((o,n)=>{t.showBadge&&this._createBadge(o,n+r+1),t.showArrow&&this._createArrow(o)}),t.lastItemIdx=i.length,a.set(e,t),this.refresh(),this._observeItems(s),s.forEach(o=>{o.querySelectorAll("img").forEach(n=>{n.complete||n.addEventListener("load",this._resizeHandler,{once:!0})})})}}_setPostPosition(e){if(e.classList.contains("mo-fullwidth")){e.classList.remove("mo-inverted","js-mo-inverted","mo-offset");return}const t=this._getLeftOrRight(e);t&&(e.classList.toggle("mo-inverted",t.lr>0),e.classList.toggle("js-mo-inverted",t.lr>0),e.classList.toggle("mo-offset",t.badge_offset>0))}_getLeftOrRight(e){if(!e)return null;const t=this._getData();if(!t)return null;const r=t.col,i=w(e,".js-mo-inverted")[0]||null,s=w(e,".js-mo-item:not(.js-mo-inverted)")[0]||null,o=g(s),n=g(i),l=g(e);let f=0,u=0;if(r>1){o.gppu>l.o+1&&(f=1),n.gppu>o.gppu&&(f=0);const y=e.previousElementSibling;y&&Math.abs(l.o-g(y).o)<40&&(u=1)}return{lr:f,badge_offset:u}}_createBadge(e,t){const r=this._getData(),i=document.createElement("span");if(i.className="mo-badge js-mo-badge",r.showCounterStyle==="none")i.style.opacity="0";else if(r.showCounterStyle==="image"){const s=document.createElement("img");s.className="mo-badge-icon",s.alt="",s.src=e.dataset.moIcon||b,i.appendChild(s)}else i.textContent=t;e.prepend(i)}_createItemElement(e){const t=document.createElement("li");e.icon&&(t.dataset.moIcon=e.icon);const r=document.createElement("div");r.className="mo-card";const i=this._getData();if(i&&typeof i.renderCard=="function")i.renderCard(e,r);else{if(e.banner){const o=document.createElement("div");o.className="mo-card-image";const n=document.createElement("img");if(n.className="mo-banner",n.src=e.banner,n.alt="",o.appendChild(n),e.avatar){const l=document.createElement("img");l.className="mo-avatar",l.src=e.avatar,l.alt="",o.appendChild(l)}r.appendChild(o)}const s=document.createElement("div");if(s.className="mo-card-body",e.title){const o=document.createElement("h3");o.textContent=e.title,s.appendChild(o)}if(e.meta){const o=document.createElement("p");o.className="mo-meta",o.textContent=e.meta,s.appendChild(o)}if(e.text){const o=document.createElement("p");o.textContent=e.text,s.appendChild(o)}r.appendChild(s)}return t.appendChild(r),t}_createArrow(e){const t=document.createElement("span");t.className="mo-arrow js-mo-arrow",e.prepend(t)}_observeItems(e){this._observer&&e.forEach(t=>{t.classList.contains("mo-visible")||this._observer.observe(t)})}};_(h,"instances",new Set);let p=h;d.MoTimeline=p,d.default=p,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motimeline",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Responsive two-column timeline layout library. Plain JavaScript, no dependencies.",
5
5
  "main": "./dist/moTimeline.cjs",
6
6
  "module": "./dist/moTimeline.js",
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * moTimeline v2.9.0 — CSS
2
+ * moTimeline v2.10.0 — CSS
3
3
  */
4
4
 
5
5
  /* ── CSS custom properties (easy override) ─────────────────── */
package/src/moTimeline.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * moTimeline v2.9.0
2
+ * moTimeline v2.10.0
3
3
  * Responsive two-column timeline layout library
4
4
  * https://github.com/MattOpen/moTimeline
5
5
  * MIT License
@@ -23,6 +23,7 @@ const DEFAULTS = {
23
23
  cardMarginFullWidth: '0.5rem',
24
24
  randomFullWidth: 0, // 0 = off; 0–1 = probability per item; true = 0.33
25
25
  animate: false, // false | 'fade' | 'slide'
26
+ renderCard: null, // (item, cardEl) => void — custom card renderer; skips built-in HTML
26
27
  };
27
28
 
28
29
  const DEFAULT_BADGE_ICON = "data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='11' fill='%234f46e5'/><circle cx='12' cy='12' r='4.5' fill='white'/></svg>";
@@ -382,43 +383,49 @@ export class MoTimeline {
382
383
  const card = document.createElement('div');
383
384
  card.className = 'mo-card';
384
385
 
385
- if (item.banner) {
386
- const wrap = document.createElement('div');
387
- wrap.className = 'mo-card-image';
388
- const banner = document.createElement('img');
389
- banner.className = 'mo-banner';
390
- banner.src = item.banner;
391
- banner.alt = '';
392
- wrap.appendChild(banner);
393
- if (item.avatar) {
394
- const avatar = document.createElement('img');
395
- avatar.className = 'mo-avatar';
396
- avatar.src = item.avatar;
397
- avatar.alt = '';
398
- wrap.appendChild(avatar);
386
+ const data = this._getData();
387
+ if (data && typeof data.renderCard === 'function') {
388
+ data.renderCard(item, card);
389
+ } else {
390
+ if (item.banner) {
391
+ const wrap = document.createElement('div');
392
+ wrap.className = 'mo-card-image';
393
+ const banner = document.createElement('img');
394
+ banner.className = 'mo-banner';
395
+ banner.src = item.banner;
396
+ banner.alt = '';
397
+ wrap.appendChild(banner);
398
+ if (item.avatar) {
399
+ const avatar = document.createElement('img');
400
+ avatar.className = 'mo-avatar';
401
+ avatar.src = item.avatar;
402
+ avatar.alt = '';
403
+ wrap.appendChild(avatar);
404
+ }
405
+ card.appendChild(wrap);
399
406
  }
400
- card.appendChild(wrap);
401
- }
402
407
 
403
- const body = document.createElement('div');
404
- body.className = 'mo-card-body';
405
- if (item.title) {
406
- const h = document.createElement('h3');
407
- h.textContent = item.title;
408
- body.appendChild(h);
409
- }
410
- if (item.meta) {
411
- const m = document.createElement('p');
412
- m.className = 'mo-meta';
413
- m.textContent = item.meta;
414
- body.appendChild(m);
415
- }
416
- if (item.text) {
417
- const p = document.createElement('p');
418
- p.textContent = item.text;
419
- body.appendChild(p);
408
+ const body = document.createElement('div');
409
+ body.className = 'mo-card-body';
410
+ if (item.title) {
411
+ const h = document.createElement('h3');
412
+ h.textContent = item.title;
413
+ body.appendChild(h);
414
+ }
415
+ if (item.meta) {
416
+ const m = document.createElement('p');
417
+ m.className = 'mo-meta';
418
+ m.textContent = item.meta;
419
+ body.appendChild(m);
420
+ }
421
+ if (item.text) {
422
+ const p = document.createElement('p');
423
+ p.textContent = item.text;
424
+ body.appendChild(p);
425
+ }
426
+ card.appendChild(body);
420
427
  }
421
- card.appendChild(body);
428
+
422
429
  li.appendChild(card);
423
430
  return li;
424
431
  }