number-flow 0.3.6 → 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';
@@ -32,11 +32,12 @@ export declare class NumberFlowLite extends ServerSafeHTMLElement implements Pro
32
32
  continuous: boolean;
33
33
  get animated(): boolean;
34
34
  set animated(val: boolean);
35
+ get created(): boolean;
35
36
  get computedTrend(): Trend | undefined;
36
37
  get startingPlace(): number | null | undefined;
37
38
  get computedAnimated(): boolean;
38
39
  manual: boolean;
39
- set parts(parts: PartitionedParts | undefined);
40
+ set data(data: Data | undefined);
40
41
  willUpdate(): void;
41
42
  didUpdate(): void;
42
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 F=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(!(!F||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={},p=c=>{const f=o[c]==null?o[c]=0:++o[c];return`${c}:${f}`};let u="",m=!1,P=!1;for(const c of e){u+=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:p(f)})):f==="fraction"?r.push(...c.value.split("").map(Q=>({type:f,value:parseInt(Q),key:p(f),place:-1-o[f]}))):(m||P?l:i).push({type:f,value:c.value,key:p(f)})}const d=[];for(let c=n.length-1;c>=0;c--){const f=n[c];d.unshift(f.type==="integer"?{...f,key:p(f.type),place:o[f.type]}:{...f,key:p(f.type)})}return{pre:i,integer:d,fraction:r,post:l,formatted:u,value:typeof a=="string"?parseFloat(a):a}}const _t=String.raw,bt=F&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),St=F&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),B=F&&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))`,D="#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,${D}),radial-gradient(at bottom left,${D}),radial-gradient(at top left,${D}),radial-gradient(at top right,${D});-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=F?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,H,k,$,x,y,U,L,R,W,V,M,E,X,z,I,j,G,T,A,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 O;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),H.set(this,!1),k.set(this,void 0),$.set(this,void 0),x.set(this,void 0),y.set(this,void 0),U.set(this,void 0),L.set(this,s(this,N,"f")),R.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 computedTrend(){return s(this,y,"f")}get startingPlace(){return s(this,U,"f")}get computedAnimated(){return s(this,L,"f")}set parts(t){if(t==null)return;const{pre:e,integer:i,fraction:n,post:r,value:l}=t;if(s(this,H,"f")){const o=s(this,R,"f");if(h(this,R,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,U,void 0,"f"),s(this,y,"f")!==b.NONE&&this.continuous){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)),P=u.find(d=>!p.find(c=>d.place===c.place&&d.value===c.value));h(this,U,Mt(m==null?void 0:m.place,P==null?void 0:P.place),"f")}h(this,L,ct&&s(this,N,"f")&&(!this.respectMotionPreference||!(B!=null&&B.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,R,t,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)O||(O=new CSSStyleSheet,O.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[O];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,H,!0,"f")}willUpdate(){s(this,k,"f").willUpdate(),s(this,$,"f").willUpdate(),s(this,x,"f").willUpdate()}didUpdate(){if(!s(this,L,"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,H=new WeakMap,k=new WeakMap,$=new WeakMap,x=new WeakMap,y=new WeakMap,U=new WeakMap,L=new WeakMap,R=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=p=>()=>{this.children.delete(p)},I.set(this,void 0),this.justify=i;const o=e.map(p=>this.addChar(p).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 ut(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 ut&&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,j.set(this,!0),G.set(this,void 0),T.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,j,"f")}set present(t){if(s(this,j,"f")!==t){if(h(this,j,t,"f"),!this.flow.computedAnimated){t||s(this,T,"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,T,"f")):this.flow.addEventListener("animationsfinish",s(this,T,"f"),{once:!0})}}}j=new WeakMap,G=new WeakMap,T=new WeakMap;class pt extends st{constructor(t,e,i,n){super(t.flow,i,n),this.section=t,this.value=e,this.el=i}}class ut extends pt{constructor(t,e,i,n,r){const l=Array.from({length:10}).map((p,u)=>{const m=w("span",{className:`digit__num${u===i?" is-current":""}`},[document.createTextNode(String(u))]);return m.style.setProperty("--n",String(u)),m}),o=w("span",{className:"digit"},l);o.style.setProperty("--current",String(i)),super(t,i,o,r),this.place=n,A.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,A,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,A,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=s(this,A,"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)}}A=new WeakMap,v=new WeakMap,Y=new WeakMap,it=new WeakMap;class Pt extends pt{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=B;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 F = 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 (!(!F || 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 = F && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), yt = F && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), Q = F && 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,84 +90,87 @@ const gt = String.raw, wt = F && 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))`, D = "#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,${D}),radial-gradient(at bottom left,${D}),radial-gradient(at top left,${D}),radial-gradient(at top right,${D});-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 = F ? 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, B, k, x, $, y, U, L, R, W, H, E, M, V, X, z, j, I, T, A, _, 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 O;
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), B.set(this, !1), k.set(this, void 0), x.set(this, void 0), $.set(this, void 0), y.set(this, void 0), U.set(this, void 0), L.set(this, s(this, P, "f")), R.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()));
112
+ }
113
+ get created() {
114
+ return s(this, L, "f");
113
115
  }
114
116
  get computedTrend() {
115
- return s(this, y, "f");
117
+ return s(this, v, "f");
116
118
  }
117
119
  get startingPlace() {
118
- return s(this, U, "f");
120
+ return s(this, R, "f");
119
121
  }
120
122
  get computedAnimated() {
121
- return s(this, L, "f");
123
+ return s(this, j, "f");
122
124
  }
123
- set parts(t) {
125
+ set data(t) {
124
126
  if (t == null)
125
127
  return;
126
- const { pre: e, integer: i, fraction: n, post: r, value: l } = t;
127
- if (s(this, B, "f")) {
128
- const o = s(this, R, "f");
129
- if (h(this, R, 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, U, void 0, "f"), s(this, y, "f") !== b.NONE && this.continuous) {
130
- 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));
131
- h(this, U, 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");
132
134
  }
133
- h(this, L, St && s(this, P, "f") && (!this.respectMotionPreference || !(Q != null && Q.matches)) && // https://github.com/barvian/number-flow/issues/9
134
- 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();
135
137
  } else {
136
- if (h(this, R, t, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
137
- O || (O = new CSSStyleSheet(), O.replaceSync(ot)), this.shadowRoot.adoptedStyleSheets = [O];
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];
138
140
  else {
139
141
  const o = document.createElement("style");
140
- o.textContent = ot, this.shadowRoot.appendChild(o);
142
+ o.textContent = lt, this.shadowRoot.appendChild(o);
141
143
  }
142
- 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, {
143
145
  inert: !0,
144
146
  ariaHidden: "true",
145
147
  justify: "right"
146
- }), "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, {
147
149
  inert: !0,
148
150
  ariaHidden: "true"
149
- }), "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, {
150
152
  inert: !0,
151
153
  ariaHidden: "true",
152
154
  justify: "left"
153
- }), "f"), this.shadowRoot.appendChild(s(this, $, "f").el);
155
+ }), "f"), this.shadowRoot.appendChild(s(this, E, "f").el);
154
156
  }
155
- h(this, B, !0, "f");
157
+ h(this, L, !0, "f");
156
158
  }
157
159
  willUpdate() {
158
- 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();
159
161
  }
160
162
  didUpdate() {
161
- if (!s(this, L, "f"))
163
+ if (!s(this, j, "f"))
162
164
  return;
163
- 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();
164
166
  const t = new AbortController();
165
167
  Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
166
- t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, W, void 0, "f"));
167
- }), 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");
168
170
  }
169
171
  }
170
- P = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap();
171
- 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 = {
172
174
  transformTiming: {
173
175
  duration: 900,
174
176
  // Make sure to keep this minified:
@@ -181,55 +183,55 @@ kt.defaultProps = {
181
183
  continuous: !1,
182
184
  respectMotionPreference: !0
183
185
  };
184
- class xt {
185
- constructor(t, e, i, { className: n, ...r } = {}) {
186
- 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, {
187
189
  justify: "right"
188
- }), "f"), h(this, M, new rt(t, i, {
190
+ }), "f"), h(this, N, new ht(t, i, {
189
191
  justify: "left"
190
- }), "f"), h(this, H, w("span", {
192
+ }), "f"), h(this, V, w("span", {
191
193
  className: "number__inner"
192
- }, [s(this, E, "f").el, s(this, M, "f").el]), "f"), this.el = w("span", {
193
- ...r,
194
+ }, [s(this, M, "f").el, s(this, N, "f").el]), "f"), this.el = w("span", {
195
+ ...l,
194
196
  className: `number ${n ?? ""}`
195
- }, [s(this, H, "f")]);
197
+ }, [s(this, V, "f")]);
196
198
  }
197
199
  willUpdate() {
198
- 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();
199
201
  }
200
202
  update({ integer: t, fraction: e }) {
201
- 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);
202
204
  }
203
205
  didUpdate() {
204
206
  const t = this.el.getBoundingClientRect();
205
- s(this, E, "f").didUpdate(), s(this, M, "f").didUpdate();
206
- 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;
207
209
  this.el.style.setProperty("--width", String(i)), this.el.animate({
208
- [q]: [`${e}px`, "0px"],
209
- [nt]: [n, 0]
210
+ [J]: [`${e}px`, "0px"],
211
+ [at]: [n, 0]
210
212
  }, {
211
213
  ...this.flow.transformTiming,
212
214
  composite: "accumulate"
213
215
  });
214
216
  }
215
217
  }
216
- H = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap();
217
- class ct {
218
- constructor(t, e, { justify: i, className: n, ...r }, l) {
219
- this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (p) => () => {
220
- this.children.delete(p);
221
- }, z.set(this, void 0), this.justify = i;
222
- 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);
223
225
  this.el = w("span", {
224
- ...r,
226
+ ...l,
225
227
  className: `section section--justify-${i} ${n ?? ""}`
226
- }, l ? l(o) : o);
228
+ }, r ? r(o) : o);
227
229
  }
228
230
  addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
229
- 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, {
230
232
  ...i,
231
233
  onRemove: this.onCharRemove(t.key)
232
- }) : new $t(this, t.type, t.value, {
234
+ }) : new Mt(this, t.type, t.value, {
233
235
  ...i,
234
236
  onRemove: this.onCharRemove(t.key)
235
237
  });
@@ -240,37 +242,37 @@ class ct {
240
242
  }
241
243
  pop(t) {
242
244
  t.forEach((e) => {
243
- e.el.style[this.justify] = `${pt(e.el, this.justify)}px`;
245
+ e.el.style[this.justify] = `${mt(e.el, this.justify)}px`;
244
246
  }), t.forEach((e) => {
245
247
  e.el.classList.add("section__exiting"), e.present = !1;
246
248
  });
247
249
  }
248
250
  addNewAndUpdateExisting(t) {
249
- const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), n = this.justify === "left", r = n ? "prepend" : "append";
250
- 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) => {
251
253
  let o;
252
- 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);
253
255
  }, { reverse: n }), this.flow.computedAnimated) {
254
- const l = this.el.getBoundingClientRect();
256
+ const r = this.el.getBoundingClientRect();
255
257
  e.forEach((o) => {
256
- o.willUpdate(l);
258
+ o.willUpdate(r);
257
259
  });
258
260
  }
259
- e.forEach((l, o) => {
260
- l.update(o.value);
261
- }), i.forEach((l, o) => {
262
- l.update(o.value);
261
+ e.forEach((r, o) => {
262
+ r.update(o.value);
263
+ }), i.forEach((r, o) => {
264
+ r.update(o.value);
263
265
  });
264
266
  }
265
267
  willUpdate() {
266
268
  const t = this.el.getBoundingClientRect();
267
- 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));
268
270
  }
269
271
  didUpdate() {
270
272
  const t = this.el.getBoundingClientRect();
271
273
  this.children.forEach((n) => n.didUpdate(t));
272
- const e = t[this.justify], i = s(this, z, "f") - e;
273
- this.el.animate({
274
+ const e = t[this.justify], i = s(this, I, "f") - e;
275
+ i && this.children.size && this.el.animate({
274
276
  transform: [`translateX(${i}px)`, "none"]
275
277
  }, {
276
278
  ...this.flow.transformTiming,
@@ -278,142 +280,142 @@ class ct {
278
280
  });
279
281
  }
280
282
  }
281
- z = /* @__PURE__ */ new WeakMap();
282
- class rt extends ct {
283
+ I = /* @__PURE__ */ new WeakMap();
284
+ class ht extends dt {
283
285
  update(t) {
284
286
  const e = /* @__PURE__ */ new Map();
285
287
  this.children.forEach((i, n) => {
286
- 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);
287
289
  }), this.addNewAndUpdateExisting(t), e.forEach((i) => {
288
- i instanceof dt && i.update(0);
290
+ i instanceof ut && i.update(0);
289
291
  }), this.pop(e);
290
292
  }
291
293
  }
292
- class lt extends ct {
294
+ class ct extends dt {
293
295
  update(t) {
294
296
  const e = /* @__PURE__ */ new Map();
295
297
  this.children.forEach((i, n) => {
296
- t.find((r) => r.key === n) || e.set(n, i);
298
+ t.find((l) => l.key === n) || e.set(n, i);
297
299
  }), this.pop(e), this.addNewAndUpdateExisting(t);
298
300
  }
299
301
  }
300
- class st {
302
+ class nt {
301
303
  constructor(t, e, { onRemove: i, animateIn: n = !1 } = {}) {
302
- this.flow = t, this.el = e, j.set(this, !0), I.set(this, void 0), T.set(this, () => {
303
- var r;
304
- 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);
305
307
  }), this.el.classList.add("animate-presence"), this.flow.computedAnimated && n && this.el.animate({
306
- [Z]: [-0.9999, 0]
308
+ [q]: [-0.9999, 0]
307
309
  }, {
308
310
  ...this.flow.opacityTiming,
309
311
  composite: "accumulate"
310
- }), h(this, I, i, "f");
312
+ }), h(this, G, i, "f");
311
313
  }
312
314
  get present() {
313
- return s(this, j, "f");
315
+ return s(this, A, "f");
314
316
  }
315
317
  set present(t) {
316
- if (s(this, j, "f") !== t) {
317
- if (h(this, j, t, "f"), !this.flow.computedAnimated) {
318
- t || s(this, T, "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);
319
321
  return;
320
322
  }
321
323
  this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
322
- [Z]: t ? [-0.9999, 0] : [0.999, 0]
324
+ [q]: t ? [-0.9999, 0] : [0.999, 0]
323
325
  }, {
324
326
  ...this.flow.opacityTiming,
325
327
  composite: "accumulate"
326
- }), t ? this.flow.removeEventListener("animationsfinish", s(this, T, "f")) : this.flow.addEventListener("animationsfinish", s(this, T, "f"), {
328
+ }), t ? this.flow.removeEventListener("animationsfinish", s(this, F, "f")) : this.flow.addEventListener("animationsfinish", s(this, F, "f"), {
327
329
  once: !0
328
330
  });
329
331
  }
330
332
  }
331
333
  }
332
- j = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap();
333
- class ft extends st {
334
+ A = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap();
335
+ class pt extends nt {
334
336
  constructor(t, e, i, n) {
335
337
  super(t.flow, i, n), this.section = t, this.value = e, this.el = i;
336
338
  }
337
339
  }
338
- class dt extends ft {
339
- constructor(t, e, i, n, r) {
340
- const l = Array.from({ length: 10 }).map((p, u) => {
341
- const m = w("span", { className: `digit__num${u === i ? " is-current" : ""}` }, [document.createTextNode(String(u))]);
342
- 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;
343
345
  }), o = w("span", {
344
346
  className: "digit"
345
- }, l);
346
- o.style.setProperty("--current", String(i)), super(t, i, o, r), this.place = n, A.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, () => {
347
349
  this.el.classList.remove("is-spinning");
348
- }), h(this, A, l, "f");
350
+ }), h(this, D, r, "f");
349
351
  }
350
352
  willUpdate(t) {
351
353
  const e = this.el.getBoundingClientRect();
352
354
  h(this, _, this.value, "f");
353
355
  const i = e[this.section.justify] - t[this.section.justify], n = e.width / 2;
354
- 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");
355
357
  }
356
358
  update(t) {
357
359
  var e, i;
358
- (e = s(this, A, "f")[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = s(this, A, "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;
359
361
  }
360
362
  didUpdate(t) {
361
- 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;
362
- this.el.animate({
363
- 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"]
364
366
  }, {
365
367
  ...this.flow.transformTiming,
366
368
  composite: "accumulate"
367
369
  });
368
- const l = this.diff;
369
- l && (this.el.classList.add("is-spinning"), this.el.animate({
370
- [at]: [-l, 0]
370
+ const o = this.diff;
371
+ o && (this.el.classList.add("is-spinning"), this.el.animate({
372
+ [ot]: [-o, 0]
371
373
  }, {
372
374
  ...this.flow.spinTiming ?? this.flow.transformTiming,
373
375
  composite: "accumulate"
374
- }), this.flow.addEventListener("animationsfinish", s(this, it, "f"), { once: !0 }));
376
+ }), this.flow.addEventListener("animationsfinish", s(this, st, "f"), { once: !0 }));
375
377
  }
376
378
  get diff() {
377
379
  let t = this.flow.computedTrend;
378
380
  const e = this.value - s(this, _, "f");
379
- 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);
380
382
  }
381
383
  }
382
- A = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), it = /* @__PURE__ */ new WeakMap();
383
- 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 {
384
386
  constructor(t, e, i, n) {
385
- const r = w("span", {
387
+ const l = w("span", {
386
388
  className: "symbol__value",
387
389
  textContent: i
388
390
  });
389
391
  super(t, i, w("span", {
390
392
  className: "symbol"
391
- }, [r]), n), this.type = e, v.set(this, /* @__PURE__ */ new Map()), Y.set(this, void 0), K.set(this, (l) => () => {
392
- s(this, v, "f").delete(l);
393
- }), s(this, v, "f").set(i, new st(this.flow, r, {
394
- 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)
395
397
  }));
396
398
  }
397
399
  willUpdate(t) {
398
400
  if (this.type === "decimal")
399
401
  return;
400
402
  const e = this.el.getBoundingClientRect();
401
- 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");
402
404
  }
403
405
  update(t) {
404
406
  if (this.value !== t) {
405
- const e = s(this, v, "f").get(this.value);
406
- if (e.present = !1, e.el.classList.add("symbol__exiting"), s(this, v, "f").has(t)) {
407
- 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);
408
410
  i.present = !0, i.el.classList.remove("symbol__exiting");
409
411
  } else {
410
412
  const i = w("span", {
411
413
  className: "symbol__value",
412
414
  textContent: t
413
415
  });
414
- 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, {
415
417
  animateIn: !0,
416
- onRemove: s(this, K, "f").call(this, t)
418
+ onRemove: s(this, Z, "f").call(this, t)
417
419
  }));
418
420
  }
419
421
  }
@@ -422,18 +424,18 @@ class $t extends ft {
422
424
  didUpdate(t) {
423
425
  if (this.type === "decimal")
424
426
  return;
425
- const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
426
- this.el.animate({
427
- 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"]
428
430
  }, { ...this.flow.transformTiming, composite: "accumulate" });
429
431
  }
430
432
  }
431
- 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();
432
434
  export {
433
- kt as NumberFlowLite,
434
- St as canAnimate,
435
- Et as define,
436
- Mt as partitionParts,
437
- Q as prefersReducedMotion,
438
- 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
439
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.6",
6
+ "version": "0.3.8",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",