number-flow 0.5.11 → 0.5.12

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/lite.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("esm-env"),f=require("./ssr-Dh5VMUdt.js"),T=require("./plugins.js"),u=(n,t,e)=>{const i=document.createElement(n),[s,o]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),o==null||o.forEach(r=>i.appendChild(r)),i},S=(n,t)=>{var e;return t==="left"?n.offsetLeft:(((e=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:e.offsetWidth)??0)-n.offsetWidth-n.offsetLeft},M=n=>n.offsetWidth>0&&n.offsetHeight>0,L=(n,t)=>{j.BROWSER&&!customElements.get(n)&&customElements.define(n,t)};function P(n,t,{reverse:e=!1}={}){const i=n.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(n[s],s)}function N(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const o=[],r=[],a=[],d=[],c={},p=l=>`${l}:${c[l]=(c[l]??-1)+1}`;let m="",g=!1,_=!1;for(const l of s){m+=l.value;const h=l.type==="minusSign"||l.type==="plusSign"?"sign":l.type;h==="integer"?(g=!0,r.push(...l.value.split("").map(y=>({type:h,value:parseInt(y)})))):h==="group"?r.push({type:h,value:l.value}):h==="decimal"?(_=!0,a.push({type:h,value:l.value,key:p(h)})):h==="fraction"?a.push(...l.value.split("").map(y=>({type:h,value:parseInt(y),key:p(h),pos:-1-c[h]}))):(g||_?d:o).push({type:h,value:l.value,key:p(h)})}const b=[];for(let l=r.length-1;l>=0;l--){const h=r[l];b.unshift(h.type==="integer"?{...h,key:p(h.type),pos:c[h.type]}:{...h,key:p(h.type)})}return{pre:o,integer:b,fraction:a,post:d,valueAsString:m,value:typeof n=="string"?parseFloat(n):n}}const R=f.supportsMod&&f.supportsLinear&&f.supportsAtProperty;class C extends f.ServerSafeHTMLElement{constructor(){super(),this.created=!1,this.batched=!1;const{animated:t,...e}=this.constructor.defaultProps;this._animated=this.computedAnimated=t,Object.assign(this,e)}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}set data(t){var a,d;if(t==null)return;const{pre:e,integer:i,fraction:s,post:o,value:r}=t;if(this.created){const c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,r):this.trend,this.computedAnimated=R&&this._animated&&(!this.respectMotionPreference||!((a=f.prefersReducedMotion)!=null&&a.matches))&&M(this),(d=this.plugins)==null||d.forEach(p=>{var m;return(m=p.onUpdate)==null?void 0:m.call(p,t,c,this)}),this.batched||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:s}),this._post.update(o),this.batched||this.didUpdate()}else{this._data=t,this.attachShadow({mode:"open"});try{this._internals??(this._internals=this.attachInternals()),this._internals.role="img"}catch{}const c=document.createElement("style");this.nonce&&(c.nonce=this.nonce),c.textContent=f.styles$1,this.shadowRoot.appendChild(c),this._pre=new E(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new $(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new E(this,o,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el),this.created=!0}try{this._internals.ariaLabel=t.valueAsString}catch{}}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this.computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}C.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:(n,t)=>Math.sign(t-n),respectMotionPreference:!0,plugins:void 0,digits:void 0};class ${constructor(t,e,i,{className:s,...o}={}){this.flow=t,this._integer=new A(t,e,{justify:"right",part:"integer"}),this._fraction=new A(t,i,{justify:"left",part:"fraction"}),this._inner=u("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=u("span",{...o,part:"number",className:`number ${s??""}`},[this._inner])}willUpdate(){this._prevWidth=this.el.offsetWidth,this._prevLeft=this.el.getBoundingClientRect().left,this._integer.willUpdate(),this._fraction.willUpdate()}update({integer:t,fraction:e}){this._integer.update(t),this._fraction.update(e)}didUpdate(){const t=this.el.getBoundingClientRect();this._integer.didUpdate(),this._fraction.didUpdate();const e=this._prevLeft-t.left,i=this.el.offsetWidth,s=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[f.dxVar]:[`${e}px`,"0px"],[f.widthDeltaVar]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class U{constructor(t,e,{justify:i,className:s,...o},r){this.flow=t,this.children=new Map,this.onCharRemove=d=>()=>{this.children.delete(d)},this.justify=i;const a=e.map(d=>this.addChar(d).el);this.el=u("span",{...o,className:`section section--justify-${i} ${s??""}`},r?r(a):a)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new w(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new V(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}unpop(t){t.el.removeAttribute("inert"),t.el.style.top="",t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style.top=`${e.el.offsetTop}px`,e.el.style[this.justify]=`${S(e.el,this.justify)}px`}),t.forEach(e=>{e.el.setAttribute("inert",""),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,s=this.justify==="left",o=s?"prepend":"append";if(P(t,r=>{let a;this.children.has(r.key)?(a=this.children.get(r.key),i.set(r,a),this.unpop(a),a.present=!0):(a=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,a)),this.el[o](a.el)},{reverse:s}),this.flow.computedAnimated){const r=this.el.getBoundingClientRect();e.forEach(a=>{a.willUpdate(r)})}e.forEach((r,a)=>{r.update(a.value)}),i.forEach((r,a)=>{r.update(a.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class A extends U{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof w&&i.update(0)}),this.pop(e)}}class E extends U{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class v{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var o;this.el.remove(),(o=this._onRemove)==null||o.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&s&&this.el.animate({[f.opacityDeltaVar]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),this._onRemove=i}get present(){return this._present}set present(t){if(this._present!==t){if(this._present=t,t?this.el.removeAttribute("inert"):this.el.setAttribute("inert",""),!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[f.opacityDeltaVar]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",this._remove):this.flow.addEventListener("animationsfinish",this._remove,{once:!0})}}}class x extends v{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class w extends x{constructor(t,e,i,s,o){var c,p;const r=(((p=(c=t.flow.digits)==null?void 0:c[s])==null?void 0:p.max)??9)+1,a=Array.from({length:r}).map((m,g)=>{const _=u("span",{className:"digit__num"},[document.createTextNode(String(g))]);return g!==i&&_.setAttribute("inert",""),_.style.setProperty("--n",String(g)),_}),d=u("span",{part:`digit ${e}-digit`,className:"digit"},a);d.style.setProperty("--current",String(i)),d.style.setProperty("--length",String(r)),super(t,i,d,o),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=a,this.length=r}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){this.el.style.setProperty("--current",String(t)),this._numbers.forEach((e,i)=>i===t?e.removeAttribute("inert"):e.setAttribute("inert","")),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],s=e.width/2,o=this.section.justify==="left"?i+s:i-s,r=this._prevCenter-o;r&&this.el.animate({transform:[`translateX(${r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const a=this.getDelta();a&&(this.el.classList.add("is-spinning"),this.el.animate({[f.deltaVar]:[-a,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}getDelta(){var i;if(this.flow.plugins)for(const s of this.flow.plugins){const o=(i=s.getDelta)==null?void 0:i.call(s,this.value,this._prevValue,this);if(o!=null)return o}const t=this.value-this._prevValue,e=this.flow.computedTrend||Math.sign(t);return e<0&&this.value>this._prevValue?this.value-this.length-this._prevValue:e>0&&this.value<this._prevValue?this.length-this._prevValue+this.value:t}}class V extends x{constructor(t,e,i,s){const o=u("span",{className:"symbol__value",textContent:i});super(t,i,u("span",{part:`symbol ${e}`,className:"symbol"},[o]),s),this.type=e,this._children=new Map,this._onChildRemove=r=>()=>{this._children.delete(r)},this._children.set(i,new v(this.flow,o,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);e&&(e.present=!1);const i=this._children.get(t);if(i)i.present=!0;else{const s=u("span",{className:"symbol__value",textContent:t});this.el.appendChild(s),this._children.set(t,new v(this.flow,s,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],s=this._prevOffset-i;s&&this.el.animate({transform:[`translateX(${s}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}exports.prefersReducedMotion=f.prefersReducedMotion;exports.renderInnerHTML=f.renderInnerHTML;exports.continuous=T.continuous;exports.Digit=w;exports.canAnimate=R;exports.default=C;exports.define=L;exports.formatToData=N;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("esm-env"),f=require("./ssr-Dh5VMUdt.js"),T=require("./plugins.js"),u=(n,t,e)=>{const i=document.createElement(n),[s,o]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),o==null||o.forEach(r=>i.appendChild(r)),i},S=(n,t)=>{var e;return t==="left"?n.offsetLeft:(((e=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:e.offsetWidth)??0)-n.offsetWidth-n.offsetLeft},M=n=>n.offsetWidth>0&&n.offsetHeight>0,L=(n,t)=>{j.BROWSER&&!customElements.get(n)&&customElements.define(n,t)};function P(n,t,{reverse:e=!1}={}){const i=n.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(n[s],s)}function N(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const o=[],r=[],a=[],d=[],c={},p=l=>`${l}:${c[l]=(c[l]??-1)+1}`;let m="",g=!1,_=!1;for(const l of s){m+=l.value;const h=l.type==="minusSign"||l.type==="plusSign"?"sign":l.type;h==="integer"?(g=!0,r.push(...l.value.split("").map(y=>({type:h,value:parseInt(y)})))):h==="group"?r.push({type:h,value:l.value}):h==="decimal"?(_=!0,a.push({type:h,value:l.value,key:p(h)})):h==="fraction"?a.push(...l.value.split("").map(y=>({type:h,value:parseInt(y),key:p(h),pos:-1-c[h]}))):(g||_?d:o).push({type:h,value:l.value,key:p(h)})}const b=[];for(let l=r.length-1;l>=0;l--){const h=r[l];b.unshift(h.type==="integer"?{...h,key:p(h.type),pos:c[h.type]}:{...h,key:p(h.type)})}return{pre:o,integer:b,fraction:a,post:d,valueAsString:m,value:typeof n=="string"?parseFloat(n):n}}const R=f.supportsMod&&f.supportsLinear&&f.supportsAtProperty;class C extends f.ServerSafeHTMLElement{constructor(){super(),this.created=!1,this.batched=!1;const{animated:t,...e}=this.constructor.defaultProps;this._animated=this.computedAnimated=t,Object.assign(this,e)}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}set data(t){var a,d;if(t==null)return;const{pre:e,integer:i,fraction:s,post:o,value:r}=t;if(this.created){const c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,r):this.trend,this.computedAnimated=R&&this._animated&&(!this.respectMotionPreference||!((a=f.prefersReducedMotion)!=null&&a.matches))&&M(this)&&this.ownerDocument.visibilityState==="visible",(d=this.plugins)==null||d.forEach(p=>{var m;return(m=p.onUpdate)==null?void 0:m.call(p,t,c,this)}),this.batched||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:s}),this._post.update(o),this.batched||this.didUpdate()}else{this._data=t,this.attachShadow({mode:"open"});try{this._internals??(this._internals=this.attachInternals()),this._internals.role="img"}catch{}const c=document.createElement("style");this.nonce&&(c.nonce=this.nonce),c.textContent=f.styles$1,this.shadowRoot.appendChild(c),this._pre=new E(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new $(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new E(this,o,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el),this.created=!0}try{this._internals.ariaLabel=t.valueAsString}catch{}}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this.computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}C.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:(n,t)=>Math.sign(t-n),respectMotionPreference:!0,plugins:void 0,digits:void 0};class ${constructor(t,e,i,{className:s,...o}={}){this.flow=t,this._integer=new A(t,e,{justify:"right",part:"integer"}),this._fraction=new A(t,i,{justify:"left",part:"fraction"}),this._inner=u("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=u("span",{...o,part:"number",className:`number ${s??""}`},[this._inner])}willUpdate(){this._prevWidth=this.el.offsetWidth,this._prevLeft=this.el.getBoundingClientRect().left,this._integer.willUpdate(),this._fraction.willUpdate()}update({integer:t,fraction:e}){this._integer.update(t),this._fraction.update(e)}didUpdate(){const t=this.el.getBoundingClientRect();this._integer.didUpdate(),this._fraction.didUpdate();const e=this._prevLeft-t.left,i=this.el.offsetWidth,s=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[f.dxVar]:[`${e}px`,"0px"],[f.widthDeltaVar]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class U{constructor(t,e,{justify:i,className:s,...o},r){this.flow=t,this.children=new Map,this.onCharRemove=d=>()=>{this.children.delete(d)},this.justify=i;const a=e.map(d=>this.addChar(d).el);this.el=u("span",{...o,className:`section section--justify-${i} ${s??""}`},r?r(a):a)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new w(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new D(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}unpop(t){t.el.removeAttribute("inert"),t.el.style.top="",t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style.top=`${e.el.offsetTop}px`,e.el.style[this.justify]=`${S(e.el,this.justify)}px`}),t.forEach(e=>{e.el.setAttribute("inert",""),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,s=this.justify==="left",o=s?"prepend":"append";if(P(t,r=>{let a;this.children.has(r.key)?(a=this.children.get(r.key),i.set(r,a),this.unpop(a),a.present=!0):(a=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,a)),this.el[o](a.el)},{reverse:s}),this.flow.computedAnimated){const r=this.el.getBoundingClientRect();e.forEach(a=>{a.willUpdate(r)})}e.forEach((r,a)=>{r.update(a.value)}),i.forEach((r,a)=>{r.update(a.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class A extends U{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof w&&i.update(0)}),this.pop(e)}}class E extends U{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class v{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var o;this.el.remove(),(o=this._onRemove)==null||o.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&s&&this.el.animate({[f.opacityDeltaVar]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),this._onRemove=i}get present(){return this._present}set present(t){if(this._present!==t){if(this._present=t,t?this.el.removeAttribute("inert"):this.el.setAttribute("inert",""),!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[f.opacityDeltaVar]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",this._remove):this.flow.addEventListener("animationsfinish",this._remove,{once:!0})}}}class x extends v{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class w extends x{constructor(t,e,i,s,o){var c,p;const r=(((p=(c=t.flow.digits)==null?void 0:c[s])==null?void 0:p.max)??9)+1,a=Array.from({length:r}).map((m,g)=>{const _=u("span",{className:"digit__num"},[document.createTextNode(String(g))]);return g!==i&&_.setAttribute("inert",""),_.style.setProperty("--n",String(g)),_}),d=u("span",{part:`digit ${e}-digit`,className:"digit"},a);d.style.setProperty("--current",String(i)),d.style.setProperty("--length",String(r)),super(t,i,d,o),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=a,this.length=r}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){this.el.style.setProperty("--current",String(t)),this._numbers.forEach((e,i)=>i===t?e.removeAttribute("inert"):e.setAttribute("inert","")),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],s=e.width/2,o=this.section.justify==="left"?i+s:i-s,r=this._prevCenter-o;r&&this.el.animate({transform:[`translateX(${r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const a=this.getDelta();a&&(this.el.classList.add("is-spinning"),this.el.animate({[f.deltaVar]:[-a,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}getDelta(){var i;if(this.flow.plugins)for(const s of this.flow.plugins){const o=(i=s.getDelta)==null?void 0:i.call(s,this.value,this._prevValue,this);if(o!=null)return o}const t=this.value-this._prevValue,e=this.flow.computedTrend||Math.sign(t);return e<0&&this.value>this._prevValue?this.value-this.length-this._prevValue:e>0&&this.value<this._prevValue?this.length-this._prevValue+this.value:t}}class D extends x{constructor(t,e,i,s){const o=u("span",{className:"symbol__value",textContent:i});super(t,i,u("span",{part:`symbol ${e}`,className:"symbol"},[o]),s),this.type=e,this._children=new Map,this._onChildRemove=r=>()=>{this._children.delete(r)},this._children.set(i,new v(this.flow,o,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);e&&(e.present=!1);const i=this._children.get(t);if(i)i.present=!0;else{const s=u("span",{className:"symbol__value",textContent:t});this.el.appendChild(s),this._children.set(t,new v(this.flow,s,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],s=this._prevOffset-i;s&&this.el.animate({transform:[`translateX(${s}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}exports.prefersReducedMotion=f.prefersReducedMotion;exports.renderInnerHTML=f.renderInnerHTML;exports.continuous=T.continuous;exports.Digit=w;exports.canAnimate=R;exports.default=C;exports.define=L;exports.formatToData=N;
package/dist/lite.mjs CHANGED
@@ -81,7 +81,8 @@ class D extends T {
81
81
  if (this.created) {
82
82
  const c = this._data;
83
83
  this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(c.value, a) : this.trend, this.computedAnimated = B && this._animated && (!this.respectMotionPreference || !((r = P) != null && r.matches)) && // https://github.com/barvian/number-flow/issues/9
84
- W(this), (d = this.plugins) == null || d.forEach((f) => {
84
+ W(this) && // https://github.com/barvian/number-flow/issues/165
85
+ this.ownerDocument.visibilityState === "visible", (d = this.plugins) == null || d.forEach((f) => {
85
86
  var u;
86
87
  return (u = f.onUpdate) == null ? void 0 : u.call(f, t, c, this);
87
88
  }), this.batched || this.willUpdate(), this._pre.update(e), this._num.update({ integer: i, fraction: s }), this._post.update(o), this.batched || this.didUpdate();
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.5.11",
6
+ "version": "0.5.12",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",