number-flow 0.3.7 → 0.3.8

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.
@@ -1,4 +1,4 @@
1
- type NumberPartType = Exclude<Intl.NumberFormatPartTypes, 'minusSign' | 'plusSign'> | 'sign';
1
+ export type NumberPartType = Exclude<Intl.NumberFormatPartTypes, 'minusSign' | 'plusSign'> | 'sign' | 'prefix' | 'suffix';
2
2
  type IntegerPart = {
3
3
  type: NumberPartType & 'integer';
4
4
  value: number;
@@ -25,13 +25,13 @@ export type Format = Omit<Intl.NumberFormatOptions, 'notation'> & {
25
25
  notation?: Exclude<Intl.NumberFormatOptions['notation'], 'scientific' | 'engineering'>;
26
26
  };
27
27
  export type Value = Exclude<Parameters<typeof Intl.NumberFormat.prototype.formatToParts>[0], bigint>;
28
- export declare function partitionParts(value: Value, formatter: Intl.NumberFormat): {
28
+ export declare function formatToData(value: Value, formatter: Intl.NumberFormat, prefix?: string, suffix?: string): {
29
29
  pre: KeyedNumberPart[];
30
30
  integer: KeyedNumberPart[];
31
31
  fraction: KeyedNumberPart[];
32
32
  post: KeyedNumberPart[];
33
- formatted: string;
33
+ valueAsString: string;
34
34
  value: number;
35
35
  };
36
- export type PartitionedParts = ReturnType<typeof partitionParts>;
36
+ export type Data = ReturnType<typeof formatToData>;
37
37
  export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type PartitionedParts } from './formatter';
1
+ import { type Data } from './formatter';
2
2
  import { ServerSafeHTMLElement } from './ssr';
3
3
  export { define } from './util/dom';
4
4
  export { prefersReducedMotion } from './styles';
@@ -37,7 +37,7 @@ export declare class NumberFlowLite extends ServerSafeHTMLElement implements Pro
37
37
  get startingPlace(): number | null | undefined;
38
38
  get computedAnimated(): boolean;
39
39
  manual: boolean;
40
- set parts(parts: PartitionedParts | undefined);
40
+ set data(data: Data | undefined);
41
41
  willUpdate(): void;
42
42
  didUpdate(): void;
43
43
  }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(a,t,e,i){if(e==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?a!==t||!i:!t.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?i:e==="a"?i.call(a):i?i.value:t.get(a)}function h(a,t,e,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?a!==t||!n:!t.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(a,e):n?n.value=e:t.set(a,e),e}const D=typeof window<"u",w=(a,t,e)=>{const i=document.createElement(a),[n,r]=Array.isArray(t)?[void 0,t]:[t,e];return n&&Object.assign(i,n),r==null||r.forEach(l=>i.appendChild(l)),i},mt=(a,t)=>{var e;return t==="left"?a.offsetLeft:(((e=a.offsetParent instanceof HTMLElement?a.offsetParent:null)==null?void 0:e.offsetWidth)??0)-a.offsetWidth-a.offsetLeft},gt=a=>a.offsetWidth>0&&a.offsetHeight>0,wt=(a,t)=>{if(!(!D||customElements.get(a)===t))return customElements.define(a,t)};function yt(a,t,{reverse:e=!1}={}){const i=a.length;for(let n=e?i-1:0;e?n>=0:n<i;e?n--:n++)t(a[n],n)}function vt(a,t){const e=t.formatToParts(a),i=[],n=[],r=[],l=[],o={},u=c=>{const f=o[c]==null?o[c]=0:++o[c];return`${c}:${f}`};let p="",m=!1,P=!1;for(const c of e){p+=c.value;const f=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;f==="integer"?(m=!0,n.push(...c.value.split("").map(Q=>({type:f,value:parseInt(Q)})))):f==="group"?n.push({type:f,value:c.value}):f==="decimal"?(P=!0,r.push({type:f,value:c.value,key:u(f)})):f==="fraction"?r.push(...c.value.split("").map(Q=>({type:f,value:parseInt(Q),key:u(f),place:-1-o[f]}))):(m||P?l:i).push({type:f,value:c.value,key:u(f)})}const d=[];for(let c=n.length-1;c>=0;c--){const f=n[c];d.unshift(f.type==="integer"?{...f,key:u(f.type),place:o[f.type]}:{...f,key:u(f.type)})}return{pre:i,integer:d,fraction:r,post:l,formatted:p,value:typeof a=="string"?parseFloat(a):a}}const _t=String.raw,bt=D&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),St=D&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),H=D&&matchMedia?matchMedia("(prefers-reduced-motion: reduce)"):null,q="--_number-flow-d-opacity",nt="--_number-flow-d-width",J="--_number-flow-dx",at="--_number-flow-d",kt=(()=>{try{return CSS.registerProperty({name:q,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:J,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:nt,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:at,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),ht="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",C=`calc(${g} / 2)`,tt="var(--number-flow-mask-width, 0.5em)",S=`calc(${tt} / var(--scale-x))`,O="#000 0, transparent 71%",et="span",ot=_t`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ht} !important;isolation:isolate;}::slotted(${et}){position:absolute;left:0;top:0;color:transparent !important;will-change:unset !important;z-index:-5;}:host > .number,:host > .section{pointer-events:none;user-select:none;}.number,.number__inner{display:inline-flex;align-items:baseline;transform-origin:left top;}:host([data-will-change]) .number,:host([data-will-change]) .number__inner{will-change:transform;}.number{--scale-x:calc(1 + var(${nt}) / var(--width));transform:translateX(var(${J})) scaleX(var(--scale-x));margin:0 calc(-1 * ${tt});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${S},#000 calc(100% - ${S}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent 100% ),radial-gradient(at bottom right,${O}),radial-gradient(at bottom left,${O}),radial-gradient(at top left,${O}),radial-gradient(at top right,${O});-webkit-mask-size:100% calc(100% - ${g} * 2),calc(100% - ${S} * 2) 100%,${S} ${g},${S} ${g},${S} ${g},${S} ${g};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${tt};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${J})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${C};padding-top:${C};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${C} 0;}:host([data-will-change]) .section{will-change:transform;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:block;position:relative;--c:var(--current) + var(${at});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${C} 0;--offset-raw:mod(10 + var(--n) - mod(var(--c),10),10);--offset:calc(var(--offset-raw) - 10 * round(down,var(--offset-raw) / 5,1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y));}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y));}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none;}.symbol{display:inline-flex;align-items:baseline;position:relative;isolation:isolate;padding:${C} 0;}:host([data-will-change]) .symbol{will-change:transform;}.symbol__value{display:block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${q}));}`,$t=D?HTMLElement:class{},xt=({formatted:a,willChange:t})=>`<${et} style="font-kerning: none; display: inline-block; line-height: ${ht}; padding: ${g} 0;${t?"will-change: transform":""}">${a}</${et}>`,Mt=(a,t)=>a!=null&&t==null?a:a==null&&t!=null?t:a!=null&&t!=null?Math.max(a,t):null;var N,U,k,$,x,y,L,R,j,W,V,M,E,X,z,I,T,G,A,F,v,Y,it,_,K,Z;const ct=St&&bt&&kt;var b;(function(a){a[a.UP=1]="UP",a[a.DOWN=-1]="DOWN",a[a.NONE=0]="NONE"})(b||(b={}));let B;class ft extends $t{constructor(){super(...arguments),this.transformTiming=this.constructor.defaultProps.transformTiming,this.spinTiming=this.constructor.defaultProps.spinTiming,this.opacityTiming=this.constructor.defaultProps.opacityTiming,this.respectMotionPreference=this.constructor.defaultProps.respectMotionPreference,this.trend=this.constructor.defaultProps.trend,this.continuous=this.constructor.defaultProps.continuous,N.set(this,this.constructor.defaultProps.animated),U.set(this,!1),k.set(this,void 0),$.set(this,void 0),x.set(this,void 0),y.set(this,void 0),L.set(this,void 0),R.set(this,s(this,N,"f")),j.set(this,void 0),this.manual=!1,W.set(this,void 0)}get animated(){return s(this,N,"f")}set animated(t){var e;this.animated!==t&&(h(this,N,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}get created(){return s(this,U,"f")}get computedTrend(){return s(this,y,"f")}get startingPlace(){return s(this,L,"f")}get computedAnimated(){return s(this,R,"f")}set parts(t){if(t==null)return;const{pre:e,integer:i,fraction:n,post:r,value:l}=t;if(s(this,U,"f")){const o=s(this,j,"f");if(h(this,j,t,"f"),this.trend===!0?h(this,y,Math.sign(l-o.value),"f"):this.trend==="increasing"?h(this,y,b.UP,"f"):this.trend==="decreasing"?h(this,y,b.DOWN,"f"):h(this,y,b.NONE,"f"),h(this,L,void 0,"f"),s(this,y,"f")!==b.NONE&&this.continuous){const u=o.integer.concat(o.fraction).filter(d=>d.type==="integer"||d.type==="fraction"),p=t.integer.concat(t.fraction).filter(d=>d.type==="integer"||d.type==="fraction"),m=u.find(d=>!p.find(c=>c.place===d.place&&c.value===d.value)),P=p.find(d=>!u.find(c=>d.place===c.place&&d.value===c.value));h(this,L,Mt(m==null?void 0:m.place,P==null?void 0:P.place),"f")}h(this,R,ct&&s(this,N,"f")&&(!this.respectMotionPreference||!(H!=null&&H.matches))&&gt(this),"f"),this.manual||this.willUpdate(),s(this,k,"f").update(e),s(this,$,"f").update({integer:i,fraction:n}),s(this,x,"f").update(r),this.manual||this.didUpdate()}else{if(h(this,j,t,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)B||(B=new CSSStyleSheet,B.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[B];else{const o=document.createElement("style");o.textContent=ot,this.shadowRoot.appendChild(o)}this.shadowRoot.appendChild(w("slot")),h(this,k,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"}),"f"),this.shadowRoot.appendChild(s(this,k,"f").el),h(this,$,new Et(this,i,n,{inert:!0,ariaHidden:"true"}),"f"),this.shadowRoot.appendChild(s(this,$,"f").el),h(this,x,new lt(this,r,{inert:!0,ariaHidden:"true",justify:"left"}),"f"),this.shadowRoot.appendChild(s(this,x,"f").el)}h(this,U,!0,"f")}willUpdate(){s(this,k,"f").willUpdate(),s(this,$,"f").willUpdate(),s(this,x,"f").willUpdate()}didUpdate(){if(!s(this,R,"f"))return;s(this,W,"f")?s(this,W,"f").abort():this.dispatchEvent(new Event("animationsstart")),s(this,k,"f").didUpdate(),s(this,$,"f").didUpdate(),s(this,x,"f").didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),h(this,W,void 0,"f"))}),h(this,W,t,"f")}}N=new WeakMap,U=new WeakMap,k=new WeakMap,$=new WeakMap,x=new WeakMap,y=new WeakMap,L=new WeakMap,R=new WeakMap,j=new WeakMap,W=new WeakMap;ft.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:!0,continuous:!1,respectMotionPreference:!0};class Et{constructor(t,e,i,{className:n,...r}={}){this.flow=t,V.set(this,void 0),M.set(this,void 0),E.set(this,void 0),X.set(this,void 0),z.set(this,void 0),h(this,M,new rt(t,e,{justify:"right"}),"f"),h(this,E,new rt(t,i,{justify:"left"}),"f"),h(this,V,w("span",{className:"number__inner"},[s(this,M,"f").el,s(this,E,"f").el]),"f"),this.el=w("span",{...r,className:`number ${n??""}`},[s(this,V,"f")])}willUpdate(){h(this,X,this.el.offsetWidth,"f"),h(this,z,this.el.getBoundingClientRect().left,"f"),s(this,M,"f").willUpdate(),s(this,E,"f").willUpdate()}update({integer:t,fraction:e}){s(this,M,"f").update(t),s(this,E,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();s(this,M,"f").didUpdate(),s(this,E,"f").didUpdate();const e=s(this,z,"f")-t.left,i=this.el.offsetWidth,n=s(this,X,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[J]:[`${e}px`,"0px"],[nt]:[n,0]},{...this.flow.transformTiming,composite:"accumulate"})}}V=new WeakMap,M=new WeakMap,E=new WeakMap,X=new WeakMap,z=new WeakMap;class dt{constructor(t,e,{justify:i,className:n,...r},l){this.flow=t,this.children=new Map,this.onCharRemove=u=>()=>{this.children.delete(u)},I.set(this,void 0),this.justify=i;const o=e.map(u=>this.addChar(u).el);this.el=w("span",{...r,className:`section section--justify-${i} ${n??""}`},l?l(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const n=t.type==="integer"||t.type==="fraction"?new pt(this,t.type,e?0:t.value,t.place,{...i,onRemove:this.onCharRemove(t.key)}):new Pt(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,n),n}unpop(t){t.el.classList.remove("section__exiting"),t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style[this.justify]=`${mt(e.el,this.justify)}px`}),t.forEach(e=>{e.el.classList.add("section__exiting"),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,n=this.justify==="left",r=n?"prepend":"append";if(yt(t,l=>{let o;this.children.has(l.key)?(o=this.children.get(l.key),i.set(l,o),this.unpop(o),o.present=!0):(o=this.addChar(l,{startDigitsAtZero:!0,animateIn:!0}),e.set(l,o)),this.el[r](o.el)},{reverse:n}),this.flow.computedAnimated){const l=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(l)})}e.forEach((l,o)=>{l.update(o.value)}),i.forEach((l,o)=>{l.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();h(this,I,t[this.justify],"f"),this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(n=>n.didUpdate(t));const e=t[this.justify],i=s(this,I,"f")-e;this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}I=new WeakMap;class rt extends dt{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(r=>r.key===n)||e.set(n,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof pt&&i.update(0)}),this.pop(e)}}class lt extends dt{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(r=>r.key===n)||e.set(n,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class st{constructor(t,e,{onRemove:i,animateIn:n=!1}={}){this.flow=t,this.el=e,T.set(this,!0),G.set(this,void 0),A.set(this,()=>{var r;this.el.remove(),(r=s(this,G,"f"))==null||r.call(this)}),this.el.classList.add("animate-presence"),this.flow.computedAnimated&&n&&this.el.animate({[q]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),h(this,G,i,"f")}get present(){return s(this,T,"f")}set present(t){if(s(this,T,"f")!==t){if(h(this,T,t,"f"),!this.flow.computedAnimated){t||s(this,A,"f").call(this);return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[q]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",s(this,A,"f")):this.flow.addEventListener("animationsfinish",s(this,A,"f"),{once:!0})}}}T=new WeakMap,G=new WeakMap,A=new WeakMap;class ut extends st{constructor(t,e,i,n){super(t.flow,i,n),this.section=t,this.value=e,this.el=i}}class pt extends ut{constructor(t,e,i,n,r){const l=Array.from({length:10}).map((u,p)=>{const m=w("span",{className:`digit__num${p===i?" is-current":""}`},[document.createTextNode(String(p))]);return m.style.setProperty("--n",String(p)),m}),o=w("span",{className:"digit"},l);o.style.setProperty("--current",String(i)),super(t,i,o,r),this.place=n,F.set(this,void 0),v.set(this,void 0),Y.set(this,void 0),it.set(this,()=>{this.el.classList.remove("is-spinning")}),h(this,F,l,"f")}willUpdate(t){const e=this.el.getBoundingClientRect();h(this,v,this.value,"f");const i=e[this.section.justify]-t[this.section.justify],n=e.width/2;h(this,Y,this.section.justify==="left"?i+n:i-n,"f")}update(t){var e,i;(e=s(this,F,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=s(this,F,"f")[t])==null||i.classList.add("is-current"),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],n=e.width/2,r=this.section.justify==="left"?i+n:i-n;this.el.animate({transform:[`translateX(${s(this,Y,"f")-r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const l=this.diff;l&&(this.el.classList.add("is-spinning"),this.el.animate({[at]:[-l,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",s(this,it,"f"),{once:!0}))}get diff(){let t=this.flow.computedTrend;const e=this.value-s(this,v,"f");return!e&&this.flow.startingPlace!=null&&this.flow.startingPlace>=this.place?10*t:(t||(t=Math.sign(e)),t===b.DOWN&&this.value>s(this,v,"f")?this.value-10-s(this,v,"f"):t===b.UP&&this.value<s(this,v,"f")?10-s(this,v,"f")+this.value:e)}}F=new WeakMap,v=new WeakMap,Y=new WeakMap,it=new WeakMap;class Pt extends ut{constructor(t,e,i,n){const r=w("span",{className:"symbol__value",textContent:i});super(t,i,w("span",{className:"symbol"},[r]),n),this.type=e,_.set(this,new Map),K.set(this,void 0),Z.set(this,l=>()=>{s(this,_,"f").delete(l)}),s(this,_,"f").set(i,new st(this.flow,r,{onRemove:s(this,Z,"f").call(this,i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();h(this,K,e[this.section.justify]-t[this.section.justify],"f")}update(t){if(this.value!==t){const e=s(this,_,"f").get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),s(this,_,"f").has(t)){const i=s(this,_,"f").get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=w("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),s(this,_,"f").set(t,new st(this.flow,i,{animateIn:!0,onRemove:s(this,Z,"f").call(this,t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];this.el.animate({transform:[`translateX(${s(this,K,"f")-i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}_=new WeakMap,K=new WeakMap,Z=new WeakMap;exports.NumberFlowLite=ft;exports.canAnimate=ct;exports.define=wt;exports.partitionParts=vt;exports.prefersReducedMotion=H;exports.render=xt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(a,t,e,i){if(e==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?a!==t||!i:!t.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?i:e==="a"?i.call(a):i?i.value:t.get(a)}function h(a,t,e,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?a!==t||!n:!t.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(a,e):n?n.value=e:t.set(a,e),e}const O=typeof window<"u",w=(a,t,e)=>{const i=document.createElement(a),[n,l]=Array.isArray(t)?[void 0,t]:[t,e];return n&&Object.assign(i,n),l==null||l.forEach(r=>i.appendChild(r)),i},wt=(a,t)=>{var e;return t==="left"?a.offsetLeft:(((e=a.offsetParent instanceof HTMLElement?a.offsetParent:null)==null?void 0:e.offsetWidth)??0)-a.offsetWidth-a.offsetLeft},yt=a=>a.offsetWidth>0&&a.offsetHeight>0,vt=(a,t)=>{if(!(!O||customElements.get(a)===t))return customElements.define(a,t)};function _t(a,t,{reverse:e=!1}={}){const i=a.length;for(let n=e?i-1:0;e?n>=0:n<i;e?n--:n++)t(a[n],n)}function bt(a,t,e,i){const n=t.formatToParts(a);e&&n.unshift({type:"prefix",value:e}),i&&n.push({type:"suffix",value:i});const l=[],r=[],o=[],m=[],u={},p=f=>`${f}:${u[f]=(u[f]??-1)+1}`;let P="",d=!1,y=!1;for(const f of n){P+=f.value;const c=f.type==="minusSign"||f.type==="plusSign"?"sign":f.type;c==="integer"?(d=!0,r.push(...f.value.split("").map(tt=>({type:c,value:parseInt(tt)})))):c==="group"?r.push({type:c,value:f.value}):c==="decimal"?(y=!0,o.push({type:c,value:f.value,key:p(c)})):c==="fraction"?o.push(...f.value.split("").map(tt=>({type:c,value:parseInt(tt),key:p(c),place:-1-u[c]}))):(d||y?m:l).push({type:c,value:f.value,key:p(c)})}const rt=[];for(let f=r.length-1;f>=0;f--){const c=r[f];rt.unshift(c.type==="integer"?{...c,key:p(c.type),place:u[c.type]}:{...c,key:p(c.type)})}return{pre:l,integer:rt,fraction:o,post:m,valueAsString:P,value:typeof a=="string"?parseFloat(a):a}}const St=String.raw,xt=O&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),kt=O&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),V=O&&matchMedia?matchMedia("(prefers-reduced-motion: reduce)"):null,J="--_number-flow-d-opacity",at="--_number-flow-d-width",Q="--_number-flow-dx",ot="--_number-flow-d",$t=(()=>{try{return CSS.registerProperty({name:J,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:Q,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:at,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:ot,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),ft="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",U=`calc(${g} / 2)`,et="var(--number-flow-mask-width, 0.5em)",x=`calc(${et} / var(--scale-x))`,B="#000 0, transparent 71%",it="span",lt=St`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ft} !important;isolation:isolate;}::slotted(${it}){position:absolute;left:0;top:0;color:transparent !important;will-change:unset !important;z-index:-5;}:host > .number,:host > .section{pointer-events:none;user-select:none;}.number,.number__inner{display:inline-flex;align-items:baseline;transform-origin:left top;}:host([data-will-change]) .number,:host([data-will-change]) .number__inner{will-change:transform;}.number{--scale-x:calc(1 + var(${at}) / var(--width));transform:translateX(var(${Q})) scaleX(var(--scale-x));margin:0 calc(-1 * ${et});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${x},#000 calc(100% - ${x}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent 100% ),radial-gradient(at bottom right,${B}),radial-gradient(at bottom left,${B}),radial-gradient(at top left,${B}),radial-gradient(at top right,${B});-webkit-mask-size:100% calc(100% - ${g} * 2),calc(100% - ${x} * 2) 100%,${x} ${g},${x} ${g},${x} ${g},${x} ${g};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${et};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${Q})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${U};padding-top:${U};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${U} 0;}:host([data-will-change]) .section{will-change:transform;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:block;position:relative;--c:var(--current) + var(${ot});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${U} 0;--offset-raw:mod(10 + var(--n) - mod(var(--c),10),10);--offset:calc(var(--offset-raw) - 10 * round(down,var(--offset-raw) / 5,1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y));}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y));}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none;}.symbol{display:inline-flex;align-items:baseline;position:relative;isolation:isolate;padding:${U} 0;}:host([data-will-change]) .symbol{will-change:transform;}.symbol__value{display:block;mix-blend-mode:plus-lighter;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${J}));}`,Mt=O?HTMLElement:class{},Et=({valueAsString:a,willChange:t})=>`<${it} style="font-kerning: none; display: inline-block; line-height: ${ft}; padding: ${g} 0;${t?"will-change: transform":""}">${a}</${it}>`,Nt=(a,t)=>a!=null&&t==null?a:a==null&&t!=null?t:a!=null&&t!=null?Math.max(a,t):null;var W,L,k,$,M,v,R,T,j,C,X,E,N,z,I,G,A,Y,F,D,_,K,st,b,Z,q;const dt=kt&&xt&&$t;var S;(function(a){a[a.UP=1]="UP",a[a.DOWN=-1]="DOWN",a[a.NONE=0]="NONE"})(S||(S={}));let H;class pt extends Mt{constructor(){super(...arguments),this.transformTiming=this.constructor.defaultProps.transformTiming,this.spinTiming=this.constructor.defaultProps.spinTiming,this.opacityTiming=this.constructor.defaultProps.opacityTiming,this.respectMotionPreference=this.constructor.defaultProps.respectMotionPreference,this.trend=this.constructor.defaultProps.trend,this.continuous=this.constructor.defaultProps.continuous,W.set(this,this.constructor.defaultProps.animated),L.set(this,!1),k.set(this,void 0),$.set(this,void 0),M.set(this,void 0),v.set(this,void 0),R.set(this,void 0),T.set(this,s(this,W,"f")),j.set(this,void 0),this.manual=!1,C.set(this,void 0)}get animated(){return s(this,W,"f")}set animated(t){var e;this.animated!==t&&(h(this,W,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}get created(){return s(this,L,"f")}get computedTrend(){return s(this,v,"f")}get startingPlace(){return s(this,R,"f")}get computedAnimated(){return s(this,T,"f")}set data(t){if(t==null)return;const{pre:e,integer:i,fraction:n,post:l,value:r}=t;if(s(this,L,"f")){const o=s(this,j,"f");if(h(this,j,t,"f"),this.trend===!0?h(this,v,Math.sign(r-o.value),"f"):this.trend==="increasing"?h(this,v,S.UP,"f"):this.trend==="decreasing"?h(this,v,S.DOWN,"f"):h(this,v,S.NONE,"f"),h(this,R,void 0,"f"),s(this,v,"f")!==S.NONE&&this.continuous){const m=o.integer.concat(o.fraction).filter(d=>d.type==="integer"||d.type==="fraction"),u=t.integer.concat(t.fraction).filter(d=>d.type==="integer"||d.type==="fraction"),p=m.find(d=>!u.find(y=>y.place===d.place&&y.value===d.value)),P=u.find(d=>!m.find(y=>d.place===y.place&&d.value===y.value));h(this,R,Nt(p==null?void 0:p.place,P==null?void 0:P.place),"f")}h(this,T,dt&&s(this,W,"f")&&(!this.respectMotionPreference||!(V!=null&&V.matches))&&yt(this),"f"),this.manual||this.willUpdate(),s(this,k,"f").update(e),s(this,$,"f").update({integer:i,fraction:n}),s(this,M,"f").update(l),this.manual||this.didUpdate()}else{if(h(this,j,t,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)H||(H=new CSSStyleSheet,H.replaceSync(lt)),this.shadowRoot.adoptedStyleSheets=[H];else{const o=document.createElement("style");o.textContent=lt,this.shadowRoot.appendChild(o)}this.shadowRoot.appendChild(w("slot")),h(this,k,new ct(this,e,{inert:!0,ariaHidden:"true",justify:"right"}),"f"),this.shadowRoot.appendChild(s(this,k,"f").el),h(this,$,new Pt(this,i,n,{inert:!0,ariaHidden:"true"}),"f"),this.shadowRoot.appendChild(s(this,$,"f").el),h(this,M,new ct(this,l,{inert:!0,ariaHidden:"true",justify:"left"}),"f"),this.shadowRoot.appendChild(s(this,M,"f").el)}h(this,L,!0,"f")}willUpdate(){s(this,k,"f").willUpdate(),s(this,$,"f").willUpdate(),s(this,M,"f").willUpdate()}didUpdate(){if(!s(this,T,"f"))return;s(this,C,"f")?s(this,C,"f").abort():this.dispatchEvent(new Event("animationsstart")),s(this,k,"f").didUpdate(),s(this,$,"f").didUpdate(),s(this,M,"f").didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),h(this,C,void 0,"f"))}),h(this,C,t,"f")}}W=new WeakMap,L=new WeakMap,k=new WeakMap,$=new WeakMap,M=new WeakMap,v=new WeakMap,R=new WeakMap,T=new WeakMap,j=new WeakMap,C=new WeakMap;pt.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:!0,continuous:!1,respectMotionPreference:!0};class Pt{constructor(t,e,i,{className:n,...l}={}){this.flow=t,X.set(this,void 0),E.set(this,void 0),N.set(this,void 0),z.set(this,void 0),I.set(this,void 0),h(this,E,new ht(t,e,{justify:"right"}),"f"),h(this,N,new ht(t,i,{justify:"left"}),"f"),h(this,X,w("span",{className:"number__inner"},[s(this,E,"f").el,s(this,N,"f").el]),"f"),this.el=w("span",{...l,className:`number ${n??""}`},[s(this,X,"f")])}willUpdate(){h(this,z,this.el.offsetWidth,"f"),h(this,I,this.el.getBoundingClientRect().left,"f"),s(this,E,"f").willUpdate(),s(this,N,"f").willUpdate()}update({integer:t,fraction:e}){s(this,E,"f").update(t),s(this,N,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();s(this,E,"f").didUpdate(),s(this,N,"f").didUpdate();const e=s(this,I,"f")-t.left,i=this.el.offsetWidth,n=s(this,z,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[Q]:[`${e}px`,"0px"],[at]:[n,0]},{...this.flow.transformTiming,composite:"accumulate"})}}X=new WeakMap,E=new WeakMap,N=new WeakMap,z=new WeakMap,I=new WeakMap;class ut{constructor(t,e,{justify:i,className:n,...l},r){this.flow=t,this.children=new Map,this.onCharRemove=m=>()=>{this.children.delete(m)},G.set(this,void 0),this.justify=i;const o=e.map(m=>this.addChar(m).el);this.el=w("span",{...l,className:`section section--justify-${i} ${n??""}`},r?r(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const n=t.type==="integer"||t.type==="fraction"?new gt(this,t.type,e?0:t.value,t.place,{...i,onRemove:this.onCharRemove(t.key)}):new Wt(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,n),n}unpop(t){t.el.classList.remove("section__exiting"),t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style[this.justify]=`${wt(e.el,this.justify)}px`}),t.forEach(e=>{e.el.classList.add("section__exiting"),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,n=this.justify==="left",l=n?"prepend":"append";if(_t(t,r=>{let o;this.children.has(r.key)?(o=this.children.get(r.key),i.set(r,o),this.unpop(o),o.present=!0):(o=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,o)),this.el[l](o.el)},{reverse:n}),this.flow.computedAnimated){const r=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(r)})}e.forEach((r,o)=>{r.update(o.value)}),i.forEach((r,o)=>{r.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();h(this,G,t[this.justify],"f"),this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(n=>n.didUpdate(t));const e=t[this.justify],i=s(this,G,"f")-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}G=new WeakMap;class ht extends ut{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(l=>l.key===n)||e.set(n,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof gt&&i.update(0)}),this.pop(e)}}class ct extends ut{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(l=>l.key===n)||e.set(n,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class nt{constructor(t,e,{onRemove:i,animateIn:n=!1}={}){this.flow=t,this.el=e,A.set(this,!0),Y.set(this,void 0),F.set(this,()=>{var l;this.el.remove(),(l=s(this,Y,"f"))==null||l.call(this)}),this.el.classList.add("animate-presence"),this.flow.computedAnimated&&n&&this.el.animate({[J]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),h(this,Y,i,"f")}get present(){return s(this,A,"f")}set present(t){if(s(this,A,"f")!==t){if(h(this,A,t,"f"),!this.flow.computedAnimated){t||s(this,F,"f").call(this);return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[J]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",s(this,F,"f")):this.flow.addEventListener("animationsfinish",s(this,F,"f"),{once:!0})}}}A=new WeakMap,Y=new WeakMap,F=new WeakMap;class mt extends nt{constructor(t,e,i,n){super(t.flow,i,n),this.section=t,this.value=e,this.el=i}}class gt extends mt{constructor(t,e,i,n,l){const r=Array.from({length:10}).map((m,u)=>{const p=w("span",{className:`digit__num${u===i?" is-current":""}`},[document.createTextNode(String(u))]);return p.style.setProperty("--n",String(u)),p}),o=w("span",{className:"digit"},r);o.style.setProperty("--current",String(i)),super(t,i,o,l),this.place=n,D.set(this,void 0),_.set(this,void 0),K.set(this,void 0),st.set(this,()=>{this.el.classList.remove("is-spinning")}),h(this,D,r,"f")}willUpdate(t){const e=this.el.getBoundingClientRect();h(this,_,this.value,"f");const i=e[this.section.justify]-t[this.section.justify],n=e.width/2;h(this,K,this.section.justify==="left"?i+n:i-n,"f")}update(t){var e,i;(e=s(this,D,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=s(this,D,"f")[t])==null||i.classList.add("is-current"),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],n=e.width/2,l=this.section.justify==="left"?i+n:i-n,r=s(this,K,"f")-l;r&&this.el.animate({transform:[`translateX(${r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const o=this.diff;o&&(this.el.classList.add("is-spinning"),this.el.animate({[ot]:[-o,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",s(this,st,"f"),{once:!0}))}get diff(){let t=this.flow.computedTrend;const e=this.value-s(this,_,"f");return!e&&this.flow.startingPlace!=null&&this.flow.startingPlace>=this.place?10*t:(t||(t=Math.sign(e)),t===S.DOWN&&this.value>s(this,_,"f")?this.value-10-s(this,_,"f"):t===S.UP&&this.value<s(this,_,"f")?10-s(this,_,"f")+this.value:e)}}D=new WeakMap,_=new WeakMap,K=new WeakMap,st=new WeakMap;class Wt extends mt{constructor(t,e,i,n){const l=w("span",{className:"symbol__value",textContent:i});super(t,i,w("span",{className:"symbol"},[l]),n),this.type=e,b.set(this,new Map),Z.set(this,void 0),q.set(this,r=>()=>{s(this,b,"f").delete(r)}),s(this,b,"f").set(i,new nt(this.flow,l,{onRemove:s(this,q,"f").call(this,i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();h(this,Z,e[this.section.justify]-t[this.section.justify],"f")}update(t){if(this.value!==t){const e=s(this,b,"f").get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),s(this,b,"f").has(t)){const i=s(this,b,"f").get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=w("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),s(this,b,"f").set(t,new nt(this.flow,i,{animateIn:!0,onRemove:s(this,q,"f").call(this,t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],n=s(this,Z,"f")-i;n&&this.el.animate({transform:[`translateX(${n}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}b=new WeakMap,Z=new WeakMap,q=new WeakMap;exports.NumberFlowLite=pt;exports.canAnimate=dt;exports.define=vt;exports.formatToData=bt;exports.prefersReducedMotion=V;exports.render=Et;
package/dist/index.mjs CHANGED
@@ -9,81 +9,80 @@ function h(a, t, e, i, n) {
9
9
  if (typeof t == "function" ? a !== t || !n : !t.has(a)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return i === "a" ? n.call(a, e) : n ? n.value = e : t.set(a, e), e;
11
11
  }
12
- const D = typeof window < "u", w = (a, t, e) => {
13
- const i = document.createElement(a), [n, r] = Array.isArray(t) ? [void 0, t] : [t, e];
14
- return n && Object.assign(i, n), r == null || r.forEach((l) => i.appendChild(l)), i;
15
- }, pt = (a, t) => {
12
+ const O = typeof window < "u", w = (a, t, e) => {
13
+ const i = document.createElement(a), [n, l] = Array.isArray(t) ? [void 0, t] : [t, e];
14
+ return n && Object.assign(i, n), l == null || l.forEach((r) => i.appendChild(r)), i;
15
+ }, mt = (a, t) => {
16
16
  var e;
17
17
  return t === "left" ? a.offsetLeft : (((e = a.offsetParent instanceof HTMLElement ? a.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - a.offsetWidth - a.offsetLeft;
18
- }, ut = (a) => a.offsetWidth > 0 && a.offsetHeight > 0, Et = (a, t) => {
19
- if (!(!D || customElements.get(a) === t))
18
+ }, gt = (a) => a.offsetWidth > 0 && a.offsetHeight > 0, Nt = (a, t) => {
19
+ if (!(!O || customElements.get(a) === t))
20
20
  return customElements.define(a, t);
21
21
  };
22
- function mt(a, t, { reverse: e = !1 } = {}) {
22
+ function wt(a, t, { reverse: e = !1 } = {}) {
23
23
  const i = a.length;
24
24
  for (let n = e ? i - 1 : 0; e ? n >= 0 : n < i; e ? n-- : n++)
25
25
  t(a[n], n);
26
26
  }
27
- function Mt(a, t) {
28
- const e = t.formatToParts(a), i = [], n = [], r = [], l = [], o = {}, p = (c) => {
29
- const f = o[c] == null ? o[c] = 0 : ++o[c];
30
- return `${c}:${f}`;
31
- };
32
- let u = "", m = !1, N = !1;
33
- for (const c of e) {
34
- u += c.value;
35
- const f = c.type === "minusSign" || c.type === "plusSign" ? "sign" : c.type;
36
- f === "integer" ? (m = !0, n.push(...c.value.split("").map((J) => ({ type: f, value: parseInt(J) })))) : f === "group" ? n.push({ type: f, value: c.value }) : f === "decimal" ? (N = !0, r.push({ type: f, value: c.value, key: p(f) })) : f === "fraction" ? r.push(...c.value.split("").map((J) => ({
37
- type: f,
38
- value: parseInt(J),
39
- key: p(f),
40
- place: -1 - o[f]
41
- }))) : (m || N ? l : i).push({
42
- type: f,
43
- value: c.value,
44
- key: p(f)
27
+ function Pt(a, t, e, i) {
28
+ const n = t.formatToParts(a);
29
+ e && n.unshift({ type: "prefix", value: e }), i && n.push({ type: "suffix", value: i });
30
+ const l = [], r = [], o = [], m = [], u = {}, p = (f) => `${f}:${u[f] = (u[f] ?? -1) + 1}`;
31
+ let P = "", d = !1, y = !1;
32
+ for (const f of n) {
33
+ P += f.value;
34
+ const c = f.type === "minusSign" || f.type === "plusSign" ? "sign" : f.type;
35
+ c === "integer" ? (d = !0, r.push(...f.value.split("").map((Q) => ({ type: c, value: parseInt(Q) })))) : c === "group" ? r.push({ type: c, value: f.value }) : c === "decimal" ? (y = !0, o.push({ type: c, value: f.value, key: p(c) })) : c === "fraction" ? o.push(...f.value.split("").map((Q) => ({
36
+ type: c,
37
+ value: parseInt(Q),
38
+ key: p(c),
39
+ place: -1 - u[c]
40
+ }))) : (d || y ? m : l).push({
41
+ type: c,
42
+ value: f.value,
43
+ key: p(c)
45
44
  });
46
45
  }
47
- const d = [];
48
- for (let c = n.length - 1; c >= 0; c--) {
49
- const f = n[c];
50
- d.unshift(f.type === "integer" ? {
51
- ...f,
52
- key: p(f.type),
53
- place: o[f.type]
46
+ const rt = [];
47
+ for (let f = r.length - 1; f >= 0; f--) {
48
+ const c = r[f];
49
+ rt.unshift(c.type === "integer" ? {
50
+ ...c,
51
+ key: p(c.type),
52
+ place: u[c.type]
54
53
  } : {
55
- ...f,
56
- key: p(f.type)
54
+ ...c,
55
+ key: p(c.type)
57
56
  });
58
57
  }
59
58
  return {
60
- pre: i,
61
- integer: d,
62
- fraction: r,
63
- post: l,
64
- formatted: u,
59
+ pre: l,
60
+ integer: rt,
61
+ fraction: o,
62
+ post: m,
63
+ valueAsString: P,
65
64
  value: typeof a == "string" ? parseFloat(a) : a
66
65
  };
67
66
  }
68
- const gt = String.raw, wt = D && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), yt = D && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), Q = D && matchMedia ? matchMedia("(prefers-reduced-motion: reduce)") : null, Z = "--_number-flow-d-opacity", nt = "--_number-flow-d-width", q = "--_number-flow-dx", at = "--_number-flow-d", _t = (() => {
67
+ const yt = String.raw, vt = O && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), _t = O && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), tt = O && matchMedia ? matchMedia("(prefers-reduced-motion: reduce)") : null, q = "--_number-flow-d-opacity", at = "--_number-flow-d-width", J = "--_number-flow-dx", ot = "--_number-flow-d", bt = (() => {
69
68
  try {
70
69
  return CSS.registerProperty({
71
- name: Z,
70
+ name: q,
72
71
  syntax: "<number>",
73
72
  inherits: !1,
74
73
  initialValue: "0"
75
74
  }), CSS.registerProperty({
76
- name: q,
75
+ name: J,
77
76
  syntax: "<length>",
78
77
  inherits: !0,
79
78
  initialValue: "0px"
80
79
  }), CSS.registerProperty({
81
- name: nt,
80
+ name: at,
82
81
  syntax: "<number>",
83
82
  inherits: !1,
84
83
  initialValue: "0"
85
84
  }), CSS.registerProperty({
86
- name: at,
85
+ name: ot,
87
86
  syntax: "<number>",
88
87
  inherits: !0,
89
88
  initialValue: "0"
@@ -91,87 +90,87 @@ const gt = String.raw, wt = D && typeof CSS < "u" && CSS.supports && CSS.support
91
90
  } catch {
92
91
  return !1;
93
92
  }
94
- })(), ht = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", C = `calc(${g} / 2)`, tt = "var(--number-flow-mask-width, 0.5em)", S = `calc(${tt} / var(--scale-x))`, O = "#000 0, transparent 71%", et = "span", ot = gt`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ht} !important;isolation:isolate;}::slotted(${et}){position:absolute;left:0;top:0;color:transparent !important;will-change:unset !important;z-index:-5;}:host > .number,:host > .section{pointer-events:none;user-select:none;}.number,.number__inner{display:inline-flex;align-items:baseline;transform-origin:left top;}:host([data-will-change]) .number,:host([data-will-change]) .number__inner{will-change:transform;}.number{--scale-x:calc(1 + var(${nt}) / var(--width));transform:translateX(var(${q})) scaleX(var(--scale-x));margin:0 calc(-1 * ${tt});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${S},#000 calc(100% - ${S}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent 100% ),radial-gradient(at bottom right,${O}),radial-gradient(at bottom left,${O}),radial-gradient(at top left,${O}),radial-gradient(at top right,${O});-webkit-mask-size:100% calc(100% - ${g} * 2),calc(100% - ${S} * 2) 100%,${S} ${g},${S} ${g},${S} ${g},${S} ${g};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${tt};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${q})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${C};padding-top:${C};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${C} 0;}:host([data-will-change]) .section{will-change:transform;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:block;position:relative;--c:var(--current) + var(${at});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${C} 0;--offset-raw:mod(10 + var(--n) - mod(var(--c),10),10);--offset:calc(var(--offset-raw) - 10 * round(down,var(--offset-raw) / 5,1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y));}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y));}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none;}.symbol{display:inline-flex;align-items:baseline;position:relative;isolation:isolate;padding:${C} 0;}:host([data-will-change]) .symbol{will-change:transform;}.symbol__value{display:block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${Z}));}`, vt = D ? HTMLElement : class {
95
- }, Nt = ({ formatted: a, willChange: t }) => `<${et} style="font-kerning: none; display: inline-block; line-height: ${ht}; padding: ${g} 0;${t ? "will-change: transform" : ""}">${a}</${et}>`, bt = (a, t) => a != null && t == null ? a : a == null && t != null ? t : a != null && t != null ? Math.max(a, t) : null;
96
- var P, U, k, x, $, y, L, R, j, W, H, E, M, V, X, z, T, I, A, F, _, G, it, v, Y, K;
97
- const St = yt && wt && _t;
98
- var b;
93
+ })(), ft = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", U = `calc(${g} / 2)`, et = "var(--number-flow-mask-width, 0.5em)", x = `calc(${et} / var(--scale-x))`, B = "#000 0, transparent 71%", it = "span", lt = yt`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ft} !important;isolation:isolate;}::slotted(${it}){position:absolute;left:0;top:0;color:transparent !important;will-change:unset !important;z-index:-5;}:host > .number,:host > .section{pointer-events:none;user-select:none;}.number,.number__inner{display:inline-flex;align-items:baseline;transform-origin:left top;}:host([data-will-change]) .number,:host([data-will-change]) .number__inner{will-change:transform;}.number{--scale-x:calc(1 + var(${at}) / var(--width));transform:translateX(var(${J})) scaleX(var(--scale-x));margin:0 calc(-1 * ${et});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${x},#000 calc(100% - ${x}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent 100% ),radial-gradient(at bottom right,${B}),radial-gradient(at bottom left,${B}),radial-gradient(at top left,${B}),radial-gradient(at top right,${B});-webkit-mask-size:100% calc(100% - ${g} * 2),calc(100% - ${x} * 2) 100%,${x} ${g},${x} ${g},${x} ${g},${x} ${g};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${et};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${J})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${U};padding-top:${U};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${U} 0;}:host([data-will-change]) .section{will-change:transform;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:block;position:relative;--c:var(--current) + var(${ot});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${U} 0;--offset-raw:mod(10 + var(--n) - mod(var(--c),10),10);--offset:calc(var(--offset-raw) - 10 * round(down,var(--offset-raw) / 5,1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y));}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y));}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none;}.symbol{display:inline-flex;align-items:baseline;position:relative;isolation:isolate;padding:${U} 0;}:host([data-will-change]) .symbol{will-change:transform;}.symbol__value{display:block;mix-blend-mode:plus-lighter;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${q}));}`, St = O ? HTMLElement : class {
94
+ }, Wt = ({ valueAsString: a, willChange: t }) => `<${it} style="font-kerning: none; display: inline-block; line-height: ${ft}; padding: ${g} 0;${t ? "will-change: transform" : ""}">${a}</${it}>`, xt = (a, t) => a != null && t == null ? a : a == null && t != null ? t : a != null && t != null ? Math.max(a, t) : null;
95
+ var W, L, k, $, E, v, R, j, T, C, V, M, N, X, z, I, A, G, F, D, _, Y, st, b, K, Z;
96
+ const kt = _t && vt && bt;
97
+ var S;
99
98
  (function(a) {
100
99
  a[a.UP = 1] = "UP", a[a.DOWN = -1] = "DOWN", a[a.NONE = 0] = "NONE";
101
- })(b || (b = {}));
102
- let B;
103
- class kt extends vt {
100
+ })(S || (S = {}));
101
+ let H;
102
+ class $t extends St {
104
103
  constructor() {
105
- super(...arguments), this.transformTiming = this.constructor.defaultProps.transformTiming, this.spinTiming = this.constructor.defaultProps.spinTiming, this.opacityTiming = this.constructor.defaultProps.opacityTiming, this.respectMotionPreference = this.constructor.defaultProps.respectMotionPreference, this.trend = this.constructor.defaultProps.trend, this.continuous = this.constructor.defaultProps.continuous, P.set(this, this.constructor.defaultProps.animated), U.set(this, !1), k.set(this, void 0), x.set(this, void 0), $.set(this, void 0), y.set(this, void 0), L.set(this, void 0), R.set(this, s(this, P, "f")), j.set(this, void 0), this.manual = !1, W.set(this, void 0);
104
+ super(...arguments), this.transformTiming = this.constructor.defaultProps.transformTiming, this.spinTiming = this.constructor.defaultProps.spinTiming, this.opacityTiming = this.constructor.defaultProps.opacityTiming, this.respectMotionPreference = this.constructor.defaultProps.respectMotionPreference, this.trend = this.constructor.defaultProps.trend, this.continuous = this.constructor.defaultProps.continuous, W.set(this, this.constructor.defaultProps.animated), L.set(this, !1), k.set(this, void 0), $.set(this, void 0), E.set(this, void 0), v.set(this, void 0), R.set(this, void 0), j.set(this, s(this, W, "f")), T.set(this, void 0), this.manual = !1, C.set(this, void 0);
106
105
  }
107
106
  get animated() {
108
- return s(this, P, "f");
107
+ return s(this, W, "f");
109
108
  }
110
109
  set animated(t) {
111
110
  var e;
112
- this.animated !== t && (h(this, P, t, "f"), (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
111
+ this.animated !== t && (h(this, W, t, "f"), (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
113
112
  }
114
113
  get created() {
115
- return s(this, U, "f");
114
+ return s(this, L, "f");
116
115
  }
117
116
  get computedTrend() {
118
- return s(this, y, "f");
117
+ return s(this, v, "f");
119
118
  }
120
119
  get startingPlace() {
121
- return s(this, L, "f");
120
+ return s(this, R, "f");
122
121
  }
123
122
  get computedAnimated() {
124
- return s(this, R, "f");
123
+ return s(this, j, "f");
125
124
  }
126
- set parts(t) {
125
+ set data(t) {
127
126
  if (t == null)
128
127
  return;
129
- const { pre: e, integer: i, fraction: n, post: r, value: l } = t;
130
- if (s(this, U, "f")) {
131
- const o = s(this, j, "f");
132
- if (h(this, j, t, "f"), this.trend === !0 ? h(this, y, Math.sign(l - o.value), "f") : this.trend === "increasing" ? h(this, y, b.UP, "f") : this.trend === "decreasing" ? h(this, y, b.DOWN, "f") : h(this, y, b.NONE, "f"), h(this, L, void 0, "f"), s(this, y, "f") !== b.NONE && this.continuous) {
133
- const p = o.integer.concat(o.fraction).filter((d) => d.type === "integer" || d.type === "fraction"), u = t.integer.concat(t.fraction).filter((d) => d.type === "integer" || d.type === "fraction"), m = p.find((d) => !u.find((c) => c.place === d.place && c.value === d.value)), N = u.find((d) => !p.find((c) => d.place === c.place && d.value === c.value));
134
- h(this, L, bt(m == null ? void 0 : m.place, N == null ? void 0 : N.place), "f");
128
+ const { pre: e, integer: i, fraction: n, post: l, value: r } = t;
129
+ if (s(this, L, "f")) {
130
+ const o = s(this, T, "f");
131
+ if (h(this, T, t, "f"), this.trend === !0 ? h(this, v, Math.sign(r - o.value), "f") : this.trend === "increasing" ? h(this, v, S.UP, "f") : this.trend === "decreasing" ? h(this, v, S.DOWN, "f") : h(this, v, S.NONE, "f"), h(this, R, void 0, "f"), s(this, v, "f") !== S.NONE && this.continuous) {
132
+ const m = o.integer.concat(o.fraction).filter((d) => d.type === "integer" || d.type === "fraction"), u = t.integer.concat(t.fraction).filter((d) => d.type === "integer" || d.type === "fraction"), p = m.find((d) => !u.find((y) => y.place === d.place && y.value === d.value)), P = u.find((d) => !m.find((y) => d.place === y.place && d.value === y.value));
133
+ h(this, R, xt(p == null ? void 0 : p.place, P == null ? void 0 : P.place), "f");
135
134
  }
136
- h(this, R, St && s(this, P, "f") && (!this.respectMotionPreference || !(Q != null && Q.matches)) && // https://github.com/barvian/number-flow/issues/9
137
- ut(this), "f"), this.manual || this.willUpdate(), s(this, k, "f").update(e), s(this, x, "f").update({ integer: i, fraction: n }), s(this, $, "f").update(r), this.manual || this.didUpdate();
135
+ h(this, j, kt && s(this, W, "f") && (!this.respectMotionPreference || !(tt != null && tt.matches)) && // https://github.com/barvian/number-flow/issues/9
136
+ gt(this), "f"), this.manual || this.willUpdate(), s(this, k, "f").update(e), s(this, $, "f").update({ integer: i, fraction: n }), s(this, E, "f").update(l), this.manual || this.didUpdate();
138
137
  } else {
139
- if (h(this, j, t, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
140
- B || (B = new CSSStyleSheet(), B.replaceSync(ot)), this.shadowRoot.adoptedStyleSheets = [B];
138
+ if (h(this, T, t, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
139
+ H || (H = new CSSStyleSheet(), H.replaceSync(lt)), this.shadowRoot.adoptedStyleSheets = [H];
141
140
  else {
142
141
  const o = document.createElement("style");
143
- o.textContent = ot, this.shadowRoot.appendChild(o);
142
+ o.textContent = lt, this.shadowRoot.appendChild(o);
144
143
  }
145
- this.shadowRoot.appendChild(w("slot")), h(this, k, new lt(this, e, {
144
+ this.shadowRoot.appendChild(w("slot")), h(this, k, new ct(this, e, {
146
145
  inert: !0,
147
146
  ariaHidden: "true",
148
147
  justify: "right"
149
- }), "f"), this.shadowRoot.appendChild(s(this, k, "f").el), h(this, x, new xt(this, i, n, {
148
+ }), "f"), this.shadowRoot.appendChild(s(this, k, "f").el), h(this, $, new Et(this, i, n, {
150
149
  inert: !0,
151
150
  ariaHidden: "true"
152
- }), "f"), this.shadowRoot.appendChild(s(this, x, "f").el), h(this, $, new lt(this, r, {
151
+ }), "f"), this.shadowRoot.appendChild(s(this, $, "f").el), h(this, E, new ct(this, l, {
153
152
  inert: !0,
154
153
  ariaHidden: "true",
155
154
  justify: "left"
156
- }), "f"), this.shadowRoot.appendChild(s(this, $, "f").el);
155
+ }), "f"), this.shadowRoot.appendChild(s(this, E, "f").el);
157
156
  }
158
- h(this, U, !0, "f");
157
+ h(this, L, !0, "f");
159
158
  }
160
159
  willUpdate() {
161
- s(this, k, "f").willUpdate(), s(this, x, "f").willUpdate(), s(this, $, "f").willUpdate();
160
+ s(this, k, "f").willUpdate(), s(this, $, "f").willUpdate(), s(this, E, "f").willUpdate();
162
161
  }
163
162
  didUpdate() {
164
- if (!s(this, R, "f"))
163
+ if (!s(this, j, "f"))
165
164
  return;
166
- s(this, W, "f") ? s(this, W, "f").abort() : this.dispatchEvent(new Event("animationsstart")), s(this, k, "f").didUpdate(), s(this, x, "f").didUpdate(), s(this, $, "f").didUpdate();
165
+ s(this, C, "f") ? s(this, C, "f").abort() : this.dispatchEvent(new Event("animationsstart")), s(this, k, "f").didUpdate(), s(this, $, "f").didUpdate(), s(this, E, "f").didUpdate();
167
166
  const t = new AbortController();
168
167
  Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
169
- t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, W, void 0, "f"));
170
- }), h(this, W, t, "f");
168
+ t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, C, void 0, "f"));
169
+ }), h(this, C, t, "f");
171
170
  }
172
171
  }
173
- P = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap();
174
- kt.defaultProps = {
172
+ W = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap();
173
+ $t.defaultProps = {
175
174
  transformTiming: {
176
175
  duration: 900,
177
176
  // Make sure to keep this minified:
@@ -184,55 +183,55 @@ kt.defaultProps = {
184
183
  continuous: !1,
185
184
  respectMotionPreference: !0
186
185
  };
187
- class xt {
188
- constructor(t, e, i, { className: n, ...r } = {}) {
189
- this.flow = t, H.set(this, void 0), E.set(this, void 0), M.set(this, void 0), V.set(this, void 0), X.set(this, void 0), h(this, E, new rt(t, e, {
186
+ class Et {
187
+ constructor(t, e, i, { className: n, ...l } = {}) {
188
+ this.flow = t, V.set(this, void 0), M.set(this, void 0), N.set(this, void 0), X.set(this, void 0), z.set(this, void 0), h(this, M, new ht(t, e, {
190
189
  justify: "right"
191
- }), "f"), h(this, M, new rt(t, i, {
190
+ }), "f"), h(this, N, new ht(t, i, {
192
191
  justify: "left"
193
- }), "f"), h(this, H, w("span", {
192
+ }), "f"), h(this, V, w("span", {
194
193
  className: "number__inner"
195
- }, [s(this, E, "f").el, s(this, M, "f").el]), "f"), this.el = w("span", {
196
- ...r,
194
+ }, [s(this, M, "f").el, s(this, N, "f").el]), "f"), this.el = w("span", {
195
+ ...l,
197
196
  className: `number ${n ?? ""}`
198
- }, [s(this, H, "f")]);
197
+ }, [s(this, V, "f")]);
199
198
  }
200
199
  willUpdate() {
201
- h(this, V, this.el.offsetWidth, "f"), h(this, X, this.el.getBoundingClientRect().left, "f"), s(this, E, "f").willUpdate(), s(this, M, "f").willUpdate();
200
+ h(this, X, this.el.offsetWidth, "f"), h(this, z, this.el.getBoundingClientRect().left, "f"), s(this, M, "f").willUpdate(), s(this, N, "f").willUpdate();
202
201
  }
203
202
  update({ integer: t, fraction: e }) {
204
- s(this, E, "f").update(t), s(this, M, "f").update(e);
203
+ s(this, M, "f").update(t), s(this, N, "f").update(e);
205
204
  }
206
205
  didUpdate() {
207
206
  const t = this.el.getBoundingClientRect();
208
- s(this, E, "f").didUpdate(), s(this, M, "f").didUpdate();
209
- const e = s(this, X, "f") - t.left, i = this.el.offsetWidth, n = s(this, V, "f") - i;
207
+ s(this, M, "f").didUpdate(), s(this, N, "f").didUpdate();
208
+ const e = s(this, z, "f") - t.left, i = this.el.offsetWidth, n = s(this, X, "f") - i;
210
209
  this.el.style.setProperty("--width", String(i)), this.el.animate({
211
- [q]: [`${e}px`, "0px"],
212
- [nt]: [n, 0]
210
+ [J]: [`${e}px`, "0px"],
211
+ [at]: [n, 0]
213
212
  }, {
214
213
  ...this.flow.transformTiming,
215
214
  composite: "accumulate"
216
215
  });
217
216
  }
218
217
  }
219
- H = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap();
220
- class ct {
221
- constructor(t, e, { justify: i, className: n, ...r }, l) {
222
- this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (p) => () => {
223
- this.children.delete(p);
224
- }, z.set(this, void 0), this.justify = i;
225
- const o = e.map((p) => this.addChar(p).el);
218
+ V = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap();
219
+ class dt {
220
+ constructor(t, e, { justify: i, className: n, ...l }, r) {
221
+ this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (m) => () => {
222
+ this.children.delete(m);
223
+ }, I.set(this, void 0), this.justify = i;
224
+ const o = e.map((m) => this.addChar(m).el);
226
225
  this.el = w("span", {
227
- ...r,
226
+ ...l,
228
227
  className: `section section--justify-${i} ${n ?? ""}`
229
- }, l ? l(o) : o);
228
+ }, r ? r(o) : o);
230
229
  }
231
230
  addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
232
- const n = t.type === "integer" || t.type === "fraction" ? new dt(this, t.type, e ? 0 : t.value, t.place, {
231
+ const n = t.type === "integer" || t.type === "fraction" ? new ut(this, t.type, e ? 0 : t.value, t.place, {
233
232
  ...i,
234
233
  onRemove: this.onCharRemove(t.key)
235
- }) : new $t(this, t.type, t.value, {
234
+ }) : new Mt(this, t.type, t.value, {
236
235
  ...i,
237
236
  onRemove: this.onCharRemove(t.key)
238
237
  });
@@ -243,37 +242,37 @@ class ct {
243
242
  }
244
243
  pop(t) {
245
244
  t.forEach((e) => {
246
- e.el.style[this.justify] = `${pt(e.el, this.justify)}px`;
245
+ e.el.style[this.justify] = `${mt(e.el, this.justify)}px`;
247
246
  }), t.forEach((e) => {
248
247
  e.el.classList.add("section__exiting"), e.present = !1;
249
248
  });
250
249
  }
251
250
  addNewAndUpdateExisting(t) {
252
- const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), n = this.justify === "left", r = n ? "prepend" : "append";
253
- if (mt(t, (l) => {
251
+ const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), n = this.justify === "left", l = n ? "prepend" : "append";
252
+ if (wt(t, (r) => {
254
253
  let o;
255
- this.children.has(l.key) ? (o = this.children.get(l.key), i.set(l, o), this.unpop(o), o.present = !0) : (o = this.addChar(l, { startDigitsAtZero: !0, animateIn: !0 }), e.set(l, o)), this.el[r](o.el);
254
+ this.children.has(r.key) ? (o = this.children.get(r.key), i.set(r, o), this.unpop(o), o.present = !0) : (o = this.addChar(r, { startDigitsAtZero: !0, animateIn: !0 }), e.set(r, o)), this.el[l](o.el);
256
255
  }, { reverse: n }), this.flow.computedAnimated) {
257
- const l = this.el.getBoundingClientRect();
256
+ const r = this.el.getBoundingClientRect();
258
257
  e.forEach((o) => {
259
- o.willUpdate(l);
258
+ o.willUpdate(r);
260
259
  });
261
260
  }
262
- e.forEach((l, o) => {
263
- l.update(o.value);
264
- }), i.forEach((l, o) => {
265
- l.update(o.value);
261
+ e.forEach((r, o) => {
262
+ r.update(o.value);
263
+ }), i.forEach((r, o) => {
264
+ r.update(o.value);
266
265
  });
267
266
  }
268
267
  willUpdate() {
269
268
  const t = this.el.getBoundingClientRect();
270
- h(this, z, t[this.justify], "f"), this.children.forEach((e) => e.willUpdate(t));
269
+ h(this, I, t[this.justify], "f"), this.children.forEach((e) => e.willUpdate(t));
271
270
  }
272
271
  didUpdate() {
273
272
  const t = this.el.getBoundingClientRect();
274
273
  this.children.forEach((n) => n.didUpdate(t));
275
- const e = t[this.justify], i = s(this, z, "f") - e;
276
- this.el.animate({
274
+ const e = t[this.justify], i = s(this, I, "f") - e;
275
+ i && this.children.size && this.el.animate({
277
276
  transform: [`translateX(${i}px)`, "none"]
278
277
  }, {
279
278
  ...this.flow.transformTiming,
@@ -281,142 +280,142 @@ class ct {
281
280
  });
282
281
  }
283
282
  }
284
- z = /* @__PURE__ */ new WeakMap();
285
- class rt extends ct {
283
+ I = /* @__PURE__ */ new WeakMap();
284
+ class ht extends dt {
286
285
  update(t) {
287
286
  const e = /* @__PURE__ */ new Map();
288
287
  this.children.forEach((i, n) => {
289
- t.find((r) => r.key === n) || e.set(n, i), this.unpop(i);
288
+ t.find((l) => l.key === n) || e.set(n, i), this.unpop(i);
290
289
  }), this.addNewAndUpdateExisting(t), e.forEach((i) => {
291
- i instanceof dt && i.update(0);
290
+ i instanceof ut && i.update(0);
292
291
  }), this.pop(e);
293
292
  }
294
293
  }
295
- class lt extends ct {
294
+ class ct extends dt {
296
295
  update(t) {
297
296
  const e = /* @__PURE__ */ new Map();
298
297
  this.children.forEach((i, n) => {
299
- t.find((r) => r.key === n) || e.set(n, i);
298
+ t.find((l) => l.key === n) || e.set(n, i);
300
299
  }), this.pop(e), this.addNewAndUpdateExisting(t);
301
300
  }
302
301
  }
303
- class st {
302
+ class nt {
304
303
  constructor(t, e, { onRemove: i, animateIn: n = !1 } = {}) {
305
- this.flow = t, this.el = e, T.set(this, !0), I.set(this, void 0), A.set(this, () => {
306
- var r;
307
- this.el.remove(), (r = s(this, I, "f")) == null || r.call(this);
304
+ this.flow = t, this.el = e, A.set(this, !0), G.set(this, void 0), F.set(this, () => {
305
+ var l;
306
+ this.el.remove(), (l = s(this, G, "f")) == null || l.call(this);
308
307
  }), this.el.classList.add("animate-presence"), this.flow.computedAnimated && n && this.el.animate({
309
- [Z]: [-0.9999, 0]
308
+ [q]: [-0.9999, 0]
310
309
  }, {
311
310
  ...this.flow.opacityTiming,
312
311
  composite: "accumulate"
313
- }), h(this, I, i, "f");
312
+ }), h(this, G, i, "f");
314
313
  }
315
314
  get present() {
316
- return s(this, T, "f");
315
+ return s(this, A, "f");
317
316
  }
318
317
  set present(t) {
319
- if (s(this, T, "f") !== t) {
320
- if (h(this, T, t, "f"), !this.flow.computedAnimated) {
321
- t || s(this, A, "f").call(this);
318
+ if (s(this, A, "f") !== t) {
319
+ if (h(this, A, t, "f"), !this.flow.computedAnimated) {
320
+ t || s(this, F, "f").call(this);
322
321
  return;
323
322
  }
324
323
  this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
325
- [Z]: t ? [-0.9999, 0] : [0.999, 0]
324
+ [q]: t ? [-0.9999, 0] : [0.999, 0]
326
325
  }, {
327
326
  ...this.flow.opacityTiming,
328
327
  composite: "accumulate"
329
- }), t ? this.flow.removeEventListener("animationsfinish", s(this, A, "f")) : this.flow.addEventListener("animationsfinish", s(this, A, "f"), {
328
+ }), t ? this.flow.removeEventListener("animationsfinish", s(this, F, "f")) : this.flow.addEventListener("animationsfinish", s(this, F, "f"), {
330
329
  once: !0
331
330
  });
332
331
  }
333
332
  }
334
333
  }
335
- T = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap();
336
- class ft extends st {
334
+ A = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap();
335
+ class pt extends nt {
337
336
  constructor(t, e, i, n) {
338
337
  super(t.flow, i, n), this.section = t, this.value = e, this.el = i;
339
338
  }
340
339
  }
341
- class dt extends ft {
342
- constructor(t, e, i, n, r) {
343
- const l = Array.from({ length: 10 }).map((p, u) => {
344
- const m = w("span", { className: `digit__num${u === i ? " is-current" : ""}` }, [document.createTextNode(String(u))]);
345
- return m.style.setProperty("--n", String(u)), m;
340
+ class ut extends pt {
341
+ constructor(t, e, i, n, l) {
342
+ const r = Array.from({ length: 10 }).map((m, u) => {
343
+ const p = w("span", { className: `digit__num${u === i ? " is-current" : ""}` }, [document.createTextNode(String(u))]);
344
+ return p.style.setProperty("--n", String(u)), p;
346
345
  }), o = w("span", {
347
346
  className: "digit"
348
- }, l);
349
- o.style.setProperty("--current", String(i)), super(t, i, o, r), this.place = n, F.set(this, void 0), _.set(this, void 0), G.set(this, void 0), it.set(this, () => {
347
+ }, r);
348
+ o.style.setProperty("--current", String(i)), super(t, i, o, l), this.place = n, D.set(this, void 0), _.set(this, void 0), Y.set(this, void 0), st.set(this, () => {
350
349
  this.el.classList.remove("is-spinning");
351
- }), h(this, F, l, "f");
350
+ }), h(this, D, r, "f");
352
351
  }
353
352
  willUpdate(t) {
354
353
  const e = this.el.getBoundingClientRect();
355
354
  h(this, _, this.value, "f");
356
355
  const i = e[this.section.justify] - t[this.section.justify], n = e.width / 2;
357
- h(this, G, this.section.justify === "left" ? i + n : i - n, "f");
356
+ h(this, Y, this.section.justify === "left" ? i + n : i - n, "f");
358
357
  }
359
358
  update(t) {
360
359
  var e, i;
361
- (e = s(this, F, "f")[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = s(this, F, "f")[t]) == null || i.classList.add("is-current"), this.value = t;
360
+ (e = s(this, D, "f")[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = s(this, D, "f")[t]) == null || i.classList.add("is-current"), this.value = t;
362
361
  }
363
362
  didUpdate(t) {
364
- const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], n = e.width / 2, r = this.section.justify === "left" ? i + n : i - n;
365
- this.el.animate({
366
- transform: [`translateX(${s(this, G, "f") - r}px)`, "none"]
363
+ const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], n = e.width / 2, l = this.section.justify === "left" ? i + n : i - n, r = s(this, Y, "f") - l;
364
+ r && this.el.animate({
365
+ transform: [`translateX(${r}px)`, "none"]
367
366
  }, {
368
367
  ...this.flow.transformTiming,
369
368
  composite: "accumulate"
370
369
  });
371
- const l = this.diff;
372
- l && (this.el.classList.add("is-spinning"), this.el.animate({
373
- [at]: [-l, 0]
370
+ const o = this.diff;
371
+ o && (this.el.classList.add("is-spinning"), this.el.animate({
372
+ [ot]: [-o, 0]
374
373
  }, {
375
374
  ...this.flow.spinTiming ?? this.flow.transformTiming,
376
375
  composite: "accumulate"
377
- }), this.flow.addEventListener("animationsfinish", s(this, it, "f"), { once: !0 }));
376
+ }), this.flow.addEventListener("animationsfinish", s(this, st, "f"), { once: !0 }));
378
377
  }
379
378
  get diff() {
380
379
  let t = this.flow.computedTrend;
381
380
  const e = this.value - s(this, _, "f");
382
- return !e && this.flow.startingPlace != null && this.flow.startingPlace >= this.place ? 10 * t : (t || (t = Math.sign(e)), t === b.DOWN && this.value > s(this, _, "f") ? this.value - 10 - s(this, _, "f") : t === b.UP && this.value < s(this, _, "f") ? 10 - s(this, _, "f") + this.value : e);
381
+ return !e && this.flow.startingPlace != null && this.flow.startingPlace >= this.place ? 10 * t : (t || (t = Math.sign(e)), t === S.DOWN && this.value > s(this, _, "f") ? this.value - 10 - s(this, _, "f") : t === S.UP && this.value < s(this, _, "f") ? 10 - s(this, _, "f") + this.value : e);
383
382
  }
384
383
  }
385
- F = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), it = /* @__PURE__ */ new WeakMap();
386
- class $t extends ft {
384
+ D = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), Y = /* @__PURE__ */ new WeakMap(), st = /* @__PURE__ */ new WeakMap();
385
+ class Mt extends pt {
387
386
  constructor(t, e, i, n) {
388
- const r = w("span", {
387
+ const l = w("span", {
389
388
  className: "symbol__value",
390
389
  textContent: i
391
390
  });
392
391
  super(t, i, w("span", {
393
392
  className: "symbol"
394
- }, [r]), n), this.type = e, v.set(this, /* @__PURE__ */ new Map()), Y.set(this, void 0), K.set(this, (l) => () => {
395
- s(this, v, "f").delete(l);
396
- }), s(this, v, "f").set(i, new st(this.flow, r, {
397
- onRemove: s(this, K, "f").call(this, i)
393
+ }, [l]), n), this.type = e, b.set(this, /* @__PURE__ */ new Map()), K.set(this, void 0), Z.set(this, (r) => () => {
394
+ s(this, b, "f").delete(r);
395
+ }), s(this, b, "f").set(i, new nt(this.flow, l, {
396
+ onRemove: s(this, Z, "f").call(this, i)
398
397
  }));
399
398
  }
400
399
  willUpdate(t) {
401
400
  if (this.type === "decimal")
402
401
  return;
403
402
  const e = this.el.getBoundingClientRect();
404
- h(this, Y, e[this.section.justify] - t[this.section.justify], "f");
403
+ h(this, K, e[this.section.justify] - t[this.section.justify], "f");
405
404
  }
406
405
  update(t) {
407
406
  if (this.value !== t) {
408
- const e = s(this, v, "f").get(this.value);
409
- if (e.present = !1, e.el.classList.add("symbol__exiting"), s(this, v, "f").has(t)) {
410
- const i = s(this, v, "f").get(t);
407
+ const e = s(this, b, "f").get(this.value);
408
+ if (e.present = !1, e.el.classList.add("symbol__exiting"), s(this, b, "f").has(t)) {
409
+ const i = s(this, b, "f").get(t);
411
410
  i.present = !0, i.el.classList.remove("symbol__exiting");
412
411
  } else {
413
412
  const i = w("span", {
414
413
  className: "symbol__value",
415
414
  textContent: t
416
415
  });
417
- this.el.appendChild(i), s(this, v, "f").set(t, new st(this.flow, i, {
416
+ this.el.appendChild(i), s(this, b, "f").set(t, new nt(this.flow, i, {
418
417
  animateIn: !0,
419
- onRemove: s(this, K, "f").call(this, t)
418
+ onRemove: s(this, Z, "f").call(this, t)
420
419
  }));
421
420
  }
422
421
  }
@@ -425,18 +424,18 @@ class $t extends ft {
425
424
  didUpdate(t) {
426
425
  if (this.type === "decimal")
427
426
  return;
428
- const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
429
- this.el.animate({
430
- transform: [`translateX(${s(this, Y, "f") - i}px)`, "none"]
427
+ const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify], n = s(this, K, "f") - i;
428
+ n && this.el.animate({
429
+ transform: [`translateX(${n}px)`, "none"]
431
430
  }, { ...this.flow.transformTiming, composite: "accumulate" });
432
431
  }
433
432
  }
434
- v = /* @__PURE__ */ new WeakMap(), Y = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap();
433
+ b = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap();
435
434
  export {
436
- kt as NumberFlowLite,
437
- St as canAnimate,
438
- Et as define,
439
- Mt as partitionParts,
440
- Q as prefersReducedMotion,
441
- Nt as render
435
+ $t as NumberFlowLite,
436
+ kt as canAnimate,
437
+ Nt as define,
438
+ Pt as formatToData,
439
+ tt as prefersReducedMotion,
440
+ Wt as render
442
441
  };
package/dist/ssr.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import type { PartitionedParts } from './formatter';
1
+ import type { Data } from './formatter';
2
2
  export declare const ServerSafeHTMLElement: {
3
3
  new (): HTMLElement;
4
4
  prototype: HTMLElement;
5
5
  };
6
- export type RenderProps = {
7
- formatted: PartitionedParts['formatted'];
6
+ export type RenderProps = Pick<Data, 'valueAsString'> & {
8
7
  willChange?: boolean;
9
8
  };
10
- export declare const render: ({ formatted, willChange }: RenderProps) => string;
9
+ export declare const render: ({ valueAsString, willChange }: RenderProps) => string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.7",
6
+ "version": "0.3.8",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",