number-flow 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,10 +2,6 @@ import { type PartitionedParts } from './formatter';
2
2
  import { ServerSafeHTMLElement } from './ssr';
3
3
  export { SlottedTag, slottedStyles, supportsAnimationComposition, supportsLinear } from './styles';
4
4
  export * from './formatter';
5
- export declare const defaultXTimingLinearDuration = 900;
6
- export declare const defaultXTimingLinearPoints: number[];
7
- export declare const defaultXTimingFallbackDuration = 900;
8
- export declare const defaultXTimingFallbackPoints: number[];
9
5
  export declare const defaultFadeTiming: EffectTiming;
10
6
  export declare const defaultXTiming: EffectTiming;
11
7
  export declare const defaultYTiming: EffectTiming;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var St=Object.defineProperty;var et=n=>{throw TypeError(n)};var kt=(n,i,t)=>i in n?St(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>kt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},Ct=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},vt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function $t(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Rt(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",b=!1,T=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(b=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(T=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(b||T?l:s).push({type:m,value:p.value,key:c(m)})}const x=[];for(let p=e.length-1;p>=0;p--)x.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:x,fraction:a,post:l,formatted:d}}const jt=V.BROWSER?HTMLElement:class{},Tt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.15em)",E="var(--number-flow-mask-width, 0.5em)",G=`${E} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",Et={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=Tt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;function Ut(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function Mt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt=900,ut=[0,.0050235113985758065,.018768235438646315,.0394665067267097,.06561435806809059,.09593671402266707,.12935688367555642,.16496984329827014,.2020188582086,.2398750451603972,.2780195227408494,.316027838175776,.35355639522427323,.3903306400002338,.42613479005042487,.4608029172568362,.494211217479539,.5262713196397582,.5569245044497536,.5861367184830215,.6138942829733466,.6402002088371546,.6650710401106178,.688534157441182,.7106254816148533,.7313875244620506,.7508677409782638,.7691171422207626,.7861891335875677,.8021385475282429,.8170208436473976,.830891452602792,.8438052432253264,.8558160949464902,.8669765599529741,.8773376015362415,.8869483969005642,.8958561942662493,.9041062154819053,.9117415965639958,.9188033596342844,.9253304106443357,.9313595580771787,.9369255485137984,.9420611155589194,.9467970391476751,.9511622127120402,.9551837160819846,.9588868923388109,.9622954271337615,.9654314292396703,.9683155113223428,.9709668701061009,.9734033652684989,.9756415965361696,.9776969785701735,.9795838133278193,.9813153596710892,.9829039000616127,.9843608042404175,.985696589839041,.986920979908387,.9880429573842098,.989070816534304,.990012211453356,.9908742016877166,.9916632950848158,.9923854879711473,.9930463027692117,.9936508231680027,.994203726963899,.9947093166895601,.9951715481478591,.9955940569663103,.9959801832850321,.9963329946882337,.9966553074856583,.9969497064465007,.9972185630841328,.9974640525856172,.9976881694755444,.9978927420992383,.9980794460059083,.998249816307907,.9984052590879293,.998547061921768,.9986764035801687,.9987943629693811,.9989019273662413,1],mt=900,gt=[.32,.72,0,1],yt={duration:500,easing:"ease-out"},tt=ct?{duration:pt,easing:`linear(${ut.join(",")})`}:{duration:mt,easing:`cubic-bezier(${gt.join(",")})`},wt=tt;let q;var U,_,S,k,C;class At extends jt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",wt);u(this,"fadeTiming",yt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,_);r(this,S);r(this,k);r(this,C)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,_).update(s),o(this,S).update(e),o(this,k).update(a),o(this,C).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,_,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,_).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,k,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,k).el),h(this,C,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,_).willUpdate(t),o(this,S).willUpdate(t),o(this,k).willUpdate(t),o(this,C).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,_).didUpdate(t),o(this,S).didUpdate(t),o(this,k).didUpdate(t),o(this,C).didUpdate(t)}}U=new WeakMap,_=new WeakMap,S=new WeakMap,k=new WeakMap,C=new WeakMap;class bt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("​")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new _t(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Bt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${vt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";$t(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var v,M,A,B,L,N;class lt extends bt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,v);r(this,M);r(this,A);r(this,B);r(this,L);r(this,N);h(this,v,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,v).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,v)),s.forEach(e=>{e instanceof _t&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,b,T;(c=o(this,B))==null||c.cancel(),(d=o(this,N))==null||d.cancel(),(b=o(this,L))==null||b.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,v).getBoundingClientRect();this.children.forEach(x=>x.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,N,(T=o(this,v))==null?void 0:T.animate({transform:Ut(1e3,x=>`scaleX(${1/at(l,1,x)})`)},this.flow.xTiming)),h(this,L,this.el.animate(Mt(1e3,x=>({"--_number-flow-scale-x":at(l,1,x)})),this.flow.xTiming)))}}v=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,L=new WeakMap,N=new WeakMap;var P,X;class rt extends bt{constructor(){super(...arguments);r(this,P);r(this,X)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,P,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,X))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,X,this.el.animate({transform:[`translateX(${o(this,P)-e}px)`,"none"]},this.flow.xTiming))}}P=new WeakMap,X=new WeakMap;var R,W,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,W);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,W,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,W))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,W=new WeakMap,j=new WeakMap;class xt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,H,O,D,F;class _t extends xt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,H);r(this,O);r(this,D);r(this,F)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,H,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,O,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&Ct(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,b;(d=o(this,D))==null||d.cancel(),o(this,$)!==this.value&&((b=o(this,F))==null||b.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,O)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,H)}px))`;h(this,D,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,F,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,H=new WeakMap,O=new WeakMap,D=new WeakMap,F=new WeakMap;var w,z,I,Y;class Bt extends xt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,z);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,z,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,z)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,z=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=At;exports.SlottedTag=ft;exports.defaultFadeTiming=yt;exports.defaultXTiming=tt;exports.defaultXTimingFallbackDuration=mt;exports.defaultXTimingFallbackPoints=gt;exports.defaultXTimingLinearDuration=pt;exports.defaultXTimingLinearPoints=ut;exports.defaultYTiming=wt;exports.partitionParts=Rt;exports.slottedStyles=Et;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
1
+ "use strict";var wt=Object.defineProperty;var et=n=>{throw TypeError(n)};var xt=(n,i,t)=>i in n?wt(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>xt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},_t=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},bt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function St(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Ct(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",x=!1,E=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(x=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(E=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(x||E?l:s).push({type:m,value:p.value,key:c(m)})}const _=[];for(let p=e.length-1;p>=0;p--)_.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:_,fraction:a,post:l,formatted:d}}const vt=V.BROWSER?HTMLElement:class{},kt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",T="var(--number-flow-mask-width, 0.5em)",G=`${T} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",$t={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=kt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${T};margin-right:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${T};margin-left:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;function Rt(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function jt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt={duration:500,easing:"ease-out"},tt=ct?{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)"}:{duration:900,easing:"cubic-bezier(.32,.72,0,1)"},ut=tt;let q;var U,b,S,C,v;class Et extends vt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",ut);u(this,"fadeTiming",pt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,b);r(this,S);r(this,C);r(this,v)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,b).update(s),o(this,S).update(e),o(this,C).update(a),o(this,v).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,b,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,b).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,C,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el),h(this,v,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,v).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).willUpdate(t),o(this,S).willUpdate(t),o(this,C).willUpdate(t),o(this,v).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).didUpdate(t),o(this,S).didUpdate(t),o(this,C).didUpdate(t),o(this,v).didUpdate(t)}}U=new WeakMap,b=new WeakMap,S=new WeakMap,C=new WeakMap,v=new WeakMap;class mt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("​")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new yt(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Tt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${bt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";St(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var k,M,A,B,N,L;class lt extends mt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,k);r(this,M);r(this,A);r(this,B);r(this,N);r(this,L);h(this,k,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,k).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,k)),s.forEach(e=>{e instanceof yt&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,x,E;(c=o(this,B))==null||c.cancel(),(d=o(this,L))==null||d.cancel(),(x=o(this,N))==null||x.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,k).getBoundingClientRect();this.children.forEach(_=>_.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,L,(E=o(this,k))==null?void 0:E.animate({transform:Rt(1e3,_=>`scaleX(${1/at(l,1,_)})`)},this.flow.xTiming)),h(this,N,this.el.animate(jt(1e3,_=>({"--_number-flow-scale-x":at(l,1,_)})),this.flow.xTiming)))}}k=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,N=new WeakMap,L=new WeakMap;var W,P;class rt extends mt{constructor(){super(...arguments);r(this,W);r(this,P)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,W,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,P))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,P,this.el.animate({transform:[`translateX(${o(this,W)-e}px)`,"none"]},this.flow.xTiming))}}W=new WeakMap,P=new WeakMap;var R,H,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,H);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,H,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,H))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,H=new WeakMap,j=new WeakMap;class gt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,O,X,z,D;class yt extends gt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,O);r(this,X);r(this,z);r(this,D)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,O,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,X,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&_t(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,x;(d=o(this,z))==null||d.cancel(),o(this,$)!==this.value&&((x=o(this,D))==null||x.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,X)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,O)}px))`;h(this,z,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,D,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,O=new WeakMap,X=new WeakMap,z=new WeakMap,D=new WeakMap;var w,F,I,Y;class Tt extends gt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,F);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,F,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,F)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,F=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=ft;exports.defaultFadeTiming=pt;exports.defaultXTiming=tt;exports.defaultYTiming=ut;exports.partitionParts=Ct;exports.slottedStyles=$t;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ function wt(n, i, { reverse: t = !1 } = {}) {
20
20
  for (let e = t ? s - 1 : 0; t ? e >= 0 : e < s; t ? e-- : e++)
21
21
  i(n[e], e);
22
22
  }
23
- function Nt(n, i) {
23
+ function Et(n, i) {
24
24
  const t = i.formatToParts(n), s = [], e = [], a = [], l = [], f = {}, c = (p) => (f[p] || (f[p] = 0), `${p}:${f[p]++}`);
25
25
  let d = "", x = !1, U = !1;
26
26
  for (const p of t) {
@@ -49,17 +49,17 @@ if (rt)
49
49
  });
50
50
  } catch {
51
51
  }
52
- const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.15em)", E = "var(--number-flow-mask-width, 0.5em)", Z = `${E} * 1/var(--_number-flow-scale-x)`, it = `calc(${Z})`, st = `linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`, K = "#000 0, transparent 71%", kt = "span", Bt = {
52
+ const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", E = "var(--number-flow-mask-width, 0.5em)", Z = `${E} * 1/var(--_number-flow-scale-x)`, it = `calc(${Z})`, st = `linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`, K = "#000 0, transparent 71%", Ct = "span", Tt = {
53
53
  fontKerning: "none",
54
54
  display: "inline-block",
55
55
  lineHeight: ct,
56
56
  padding: `${g} 0`
57
- }, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${kt}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${Z}) 100%,100% calc(100% - ${g} * 2),${it} ${g},${it} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to right,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to left,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;
58
- function Ct(n, i, t = 60) {
57
+ }, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${Ct}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${Z}) 100%,100% calc(100% - ${g} * 2),${it} ${g},${it} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to right,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to left,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;
58
+ function kt(n, i, t = 60) {
59
59
  const s = Math.trunc(n / 1e3 * t);
60
60
  return Array.from({ length: s }, (e, a) => i(a / (s - 1)));
61
61
  }
62
- function $t(n, i, t = 60) {
62
+ function vt(n, i, t = 60) {
63
63
  if (rt)
64
64
  return [i(0), i(1)];
65
65
  const s = Math.max(Math.trunc(n / 1e3 * t), 0), e = Array.from({ length: s }, (a, l) => ({
@@ -71,29 +71,29 @@ function $t(n, i, t = 60) {
71
71
  offset: 0
72
72
  }), e;
73
73
  }
74
- const ot = (n, i, t) => n + (i - n) * t, vt = 900, St = [0, 0.0050235113985758065, 0.018768235438646315, 0.0394665067267097, 0.06561435806809059, 0.09593671402266707, 0.12935688367555642, 0.16496984329827014, 0.2020188582086, 0.2398750451603972, 0.2780195227408494, 0.316027838175776, 0.35355639522427323, 0.3903306400002338, 0.42613479005042487, 0.4608029172568362, 0.494211217479539, 0.5262713196397582, 0.5569245044497536, 0.5861367184830215, 0.6138942829733466, 0.6402002088371546, 0.6650710401106178, 0.688534157441182, 0.7106254816148533, 0.7313875244620506, 0.7508677409782638, 0.7691171422207626, 0.7861891335875677, 0.8021385475282429, 0.8170208436473976, 0.830891452602792, 0.8438052432253264, 0.8558160949464902, 0.8669765599529741, 0.8773376015362415, 0.8869483969005642, 0.8958561942662493, 0.9041062154819053, 0.9117415965639958, 0.9188033596342844, 0.9253304106443357, 0.9313595580771787, 0.9369255485137984, 0.9420611155589194, 0.9467970391476751, 0.9511622127120402, 0.9551837160819846, 0.9588868923388109, 0.9622954271337615, 0.9654314292396703, 0.9683155113223428, 0.9709668701061009, 0.9734033652684989, 0.9756415965361696, 0.9776969785701735, 0.9795838133278193, 0.9813153596710892, 0.9829039000616127, 0.9843608042404175, 0.985696589839041, 0.986920979908387, 0.9880429573842098, 0.989070816534304, 0.990012211453356, 0.9908742016877166, 0.9916632950848158, 0.9923854879711473, 0.9930463027692117, 0.9936508231680027, 0.994203726963899, 0.9947093166895601, 0.9951715481478591, 0.9955940569663103, 0.9959801832850321, 0.9963329946882337, 0.9966553074856583, 0.9969497064465007, 0.9972185630841328, 0.9974640525856172, 0.9976881694755444, 0.9978927420992383, 0.9980794460059083, 0.998249816307907, 0.9984052590879293, 0.998547061921768, 0.9986764035801687, 0.9987943629693811, 0.9989019273662413, 1], jt = 900, Rt = [0.32, 0.72, 0, 1], Ut = { duration: 500, easing: "ease-out" }, ht = bt ? {
75
- duration: vt,
76
- easing: `linear(${St.join(",")})`
74
+ const ot = (n, i, t) => n + (i - n) * t, $t = { duration: 500, easing: "ease-out" }, ht = bt ? {
75
+ duration: 900,
76
+ 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)"
77
77
  } : {
78
- duration: jt,
78
+ duration: 900,
79
79
  // Spring-like cubic-bezier stolen from Vaul: https://vaul.emilkowal.ski/
80
- easing: `cubic-bezier(${Rt.join(",")})`
81
- }, Et = ht;
80
+ easing: "cubic-bezier(.32,.72,0,1)"
81
+ }, St = ht;
82
82
  let G;
83
- var T, b, k, C, $;
84
- class Lt extends xt {
83
+ var T, b, C, k, v;
84
+ class Mt extends xt {
85
85
  constructor() {
86
86
  super(...arguments);
87
87
  u(this, "xTiming", ht);
88
- u(this, "yTiming", Et);
89
- u(this, "fadeTiming", Ut);
88
+ u(this, "yTiming", St);
89
+ u(this, "fadeTiming", $t);
90
90
  u(this, "root", !1);
91
91
  u(this, "manual", !1);
92
92
  r(this, T, !1);
93
93
  r(this, b);
94
- r(this, k);
95
94
  r(this, C);
96
- r(this, $);
95
+ r(this, k);
96
+ r(this, v);
97
97
  }
98
98
  static define() {
99
99
  Y && customElements.define("number-flow", this);
@@ -103,7 +103,7 @@ class Lt extends xt {
103
103
  return;
104
104
  const { pre: s, integer: e, fraction: a, post: l } = t;
105
105
  if (o(this, T))
106
- this.manual || this.willUpdate(), o(this, b).update(s), o(this, k).update(e), o(this, C).update(a), o(this, $).update(l), this.manual || this.didUpdate();
106
+ this.manual || this.willUpdate(), o(this, b).update(s), o(this, C).update(e), o(this, k).update(a), o(this, v).update(l), this.manual || this.didUpdate();
107
107
  else {
108
108
  if (this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
109
109
  G || (G = new CSSStyleSheet(), G.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [G];
@@ -116,35 +116,35 @@ class Lt extends xt {
116
116
  inert: !0,
117
117
  ariaHidden: "true",
118
118
  justify: "right"
119
- })), this.shadowRoot.appendChild(o(this, b).el), h(this, k, new at(this, e, {
119
+ })), this.shadowRoot.appendChild(o(this, b).el), h(this, C, new at(this, e, {
120
120
  // part: 'integer',
121
121
  inert: !0,
122
122
  ariaHidden: "true",
123
123
  justify: "right"
124
- })), this.shadowRoot.appendChild(o(this, k).el), h(this, C, new at(this, a, {
124
+ })), this.shadowRoot.appendChild(o(this, C).el), h(this, k, new at(this, a, {
125
125
  // part: 'fraction',
126
126
  inert: !0,
127
127
  ariaHidden: "true",
128
128
  justify: "left"
129
- })), this.shadowRoot.appendChild(o(this, C).el), h(this, $, new lt(this, l, {
129
+ })), this.shadowRoot.appendChild(o(this, k).el), h(this, v, new lt(this, l, {
130
130
  // part: 'post',
131
131
  inert: !0,
132
132
  ariaHidden: "true",
133
133
  justify: "left"
134
- })), this.shadowRoot.appendChild(o(this, $).el);
134
+ })), this.shadowRoot.appendChild(o(this, v).el);
135
135
  }
136
136
  h(this, T, !0);
137
137
  }
138
138
  willUpdate() {
139
139
  const t = this.root ? this.getBoundingClientRect() : new DOMRect();
140
- o(this, b).willUpdate(t), o(this, k).willUpdate(t), o(this, C).willUpdate(t), o(this, $).willUpdate(t);
140
+ o(this, b).willUpdate(t), o(this, C).willUpdate(t), o(this, k).willUpdate(t), o(this, v).willUpdate(t);
141
141
  }
142
142
  didUpdate() {
143
143
  const t = this.root ? this.getBoundingClientRect() : new DOMRect();
144
- o(this, b).didUpdate(t), o(this, k).didUpdate(t), o(this, C).didUpdate(t), o(this, $).didUpdate(t);
144
+ o(this, b).didUpdate(t), o(this, C).didUpdate(t), o(this, k).didUpdate(t), o(this, v).didUpdate(t);
145
145
  }
146
146
  }
147
- T = new WeakMap(), b = new WeakMap(), k = new WeakMap(), C = new WeakMap(), $ = new WeakMap();
147
+ T = new WeakMap(), b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), v = new WeakMap();
148
148
  class dt {
149
149
  constructor(i, t, { justify: s, className: e, ...a }, l) {
150
150
  u(this, "flow");
@@ -166,7 +166,7 @@ class dt {
166
166
  const e = i.type === "integer" || i.type === "fraction" ? new pt(this, i.type, t ? 0 : i.value, {
167
167
  ...s,
168
168
  onRemove: this.onCharRemove(i.key)
169
- }) : new Tt(this, i.type, i.value, {
169
+ }) : new jt(this, i.type, i.value, {
170
170
  ...s,
171
171
  onRemove: this.onCharRemove(i.key)
172
172
  });
@@ -198,7 +198,7 @@ class dt {
198
198
  });
199
199
  }
200
200
  }
201
- var v, M, A, N, B, L;
201
+ var $, M, A, N, B, L;
202
202
  class at extends dt {
203
203
  constructor(t, s, { className: e, ...a }) {
204
204
  let l;
@@ -210,53 +210,53 @@ class at extends dt {
210
210
  className: "section__inner"
211
211
  }, f)
212
212
  ]);
213
- r(this, v);
213
+ r(this, $);
214
214
  r(this, M);
215
215
  r(this, A);
216
216
  r(this, N);
217
217
  r(this, B);
218
218
  r(this, L);
219
- h(this, v, l);
219
+ h(this, $, l);
220
220
  }
221
221
  willUpdate(t) {
222
222
  const s = this.el.getBoundingClientRect();
223
223
  h(this, M, s.width), h(this, A, s[this.justify] - t[this.justify]);
224
- const e = o(this, v).getBoundingClientRect();
224
+ const e = o(this, $).getBoundingClientRect();
225
225
  this.children.forEach((a) => a.willUpdate(e));
226
226
  }
227
227
  update(t) {
228
228
  const s = /* @__PURE__ */ new Map();
229
229
  this.children.forEach((e, a) => {
230
230
  t.find((l) => l.key === a) || s.set(a, e), this.unpop(e);
231
- }), this.addNewAndUpdateExisting(t, o(this, v)), s.forEach((e) => {
231
+ }), this.addNewAndUpdateExisting(t, o(this, $)), s.forEach((e) => {
232
232
  e instanceof pt && e.update(0);
233
233
  }), this.pop(s);
234
234
  }
235
235
  didUpdate(t) {
236
236
  var c, d, x, U;
237
237
  (c = o(this, N)) == null || c.cancel(), (d = o(this, L)) == null || d.cancel(), (x = o(this, B)) == null || x.cancel();
238
- const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this, v).getBoundingClientRect();
238
+ const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this, $).getBoundingClientRect();
239
239
  this.children.forEach((_) => _.didUpdate(f)), h(this, N, this.el.animate({
240
240
  transform: [`translateX(${a}px) scaleX(${l})`, "none"]
241
- }, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this, v)) == null ? void 0 : U.animate({
241
+ }, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this, $)) == null ? void 0 : U.animate({
242
242
  // 1/x isn't linear so we need to do sampling:
243
- transform: Ct(1e3, (_) => `scaleX(${1 / ot(l, 1, _)})`)
244
- }, this.flow.xTiming)), h(this, B, this.el.animate($t(1e3, (_) => ({
243
+ transform: kt(1e3, (_) => `scaleX(${1 / ot(l, 1, _)})`)
244
+ }, this.flow.xTiming)), h(this, B, this.el.animate(vt(1e3, (_) => ({
245
245
  "--_number-flow-scale-x": ot(l, 1, _)
246
246
  })), this.flow.xTiming)));
247
247
  }
248
248
  }
249
- v = new WeakMap(), M = new WeakMap(), A = new WeakMap(), N = new WeakMap(), B = new WeakMap(), L = new WeakMap();
250
- var P, H;
249
+ $ = new WeakMap(), M = new WeakMap(), A = new WeakMap(), N = new WeakMap(), B = new WeakMap(), L = new WeakMap();
250
+ var H, P;
251
251
  class lt extends dt {
252
252
  constructor() {
253
253
  super(...arguments);
254
- r(this, P);
255
254
  r(this, H);
255
+ r(this, P);
256
256
  }
257
257
  willUpdate(t) {
258
258
  const s = this.el.getBoundingClientRect();
259
- h(this, P, s[this.justify] - t[this.justify]), this.children.forEach((e) => e.willUpdate(s));
259
+ h(this, H, s[this.justify] - t[this.justify]), this.children.forEach((e) => e.willUpdate(s));
260
260
  }
261
261
  update(t) {
262
262
  const s = /* @__PURE__ */ new Map();
@@ -266,25 +266,25 @@ class lt extends dt {
266
266
  }
267
267
  didUpdate(t) {
268
268
  var a;
269
- (a = o(this, H)) == null || a.cancel();
269
+ (a = o(this, P)) == null || a.cancel();
270
270
  const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify];
271
- this.children.forEach((l) => l.didUpdate(s)), h(this, H, this.el.animate({
272
- transform: [`translateX(${o(this, P) - e}px)`, "none"]
271
+ this.children.forEach((l) => l.didUpdate(s)), h(this, P, this.el.animate({
272
+ transform: [`translateX(${o(this, H) - e}px)`, "none"]
273
273
  }, this.flow.xTiming));
274
274
  }
275
275
  }
276
- P = new WeakMap(), H = new WeakMap();
277
- var j, X, R;
276
+ H = new WeakMap(), P = new WeakMap();
277
+ var j, W, R;
278
278
  class J {
279
279
  constructor(i, t, { onRemove: s, animateIn: e = !1 } = {}) {
280
280
  u(this, "flow");
281
281
  u(this, "el");
282
282
  r(this, j, !0);
283
- r(this, X);
283
+ r(this, W);
284
284
  r(this, R);
285
285
  this.flow = i, this.el = t, e && this.el.animate({
286
286
  opacity: ["0", "1"]
287
- }, i.fadeTiming), h(this, X, s);
287
+ }, i.fadeTiming), h(this, W, s);
288
288
  }
289
289
  get present() {
290
290
  return o(this, j);
@@ -298,11 +298,11 @@ class J {
298
298
  opacity: [t, i ? "1" : "0"]
299
299
  }, this.flow.fadeTiming)), i || (o(this, R).onfinish = () => {
300
300
  var e;
301
- this.el.remove(), (e = o(this, X)) == null || e.call(this);
301
+ this.el.remove(), (e = o(this, W)) == null || e.call(this);
302
302
  }), h(this, j, i);
303
303
  }
304
304
  }
305
- j = new WeakMap(), X = new WeakMap(), R = new WeakMap();
305
+ j = new WeakMap(), W = new WeakMap(), R = new WeakMap();
306
306
  class ft extends J {
307
307
  constructor(t, s, e, a) {
308
308
  super(t.flow, e, a);
@@ -312,7 +312,7 @@ class ft extends J {
312
312
  this.section = t, this.value = s, this.el = e;
313
313
  }
314
314
  }
315
- var S, W, D, z, O;
315
+ var S, X, z, O, D;
316
316
  class pt extends ft {
317
317
  constructor(t, s, e, a) {
318
318
  super(t, e, y("span", {
@@ -322,17 +322,17 @@ class pt extends ft {
322
322
  }), a);
323
323
  r(this, S);
324
324
  // Relative to parent:
325
- r(this, W);
326
- r(this, D);
325
+ r(this, X);
327
326
  r(this, z);
328
327
  r(this, O);
328
+ r(this, D);
329
329
  }
330
330
  willUpdate(t) {
331
331
  h(this, S, this.value);
332
332
  const s = this.el.getBoundingClientRect();
333
- h(this, W, s.y - t.y);
333
+ h(this, X, s.y - t.y);
334
334
  const e = s[this.section.justify] - t[this.section.justify], a = s.width / 2;
335
- h(this, D, this.section.justify === "left" ? e + a : e - a);
335
+ h(this, z, this.section.justify === "left" ? e + a : e - a);
336
336
  }
337
337
  update(t) {
338
338
  this.value = t, o(this, S) !== t && gt(this.el, [
@@ -347,15 +347,15 @@ class pt extends ft {
347
347
  }
348
348
  didUpdate(t) {
349
349
  var d, x;
350
- (d = o(this, z)) == null || d.cancel(), o(this, S) !== this.value && ((x = o(this, O)) == null || x.cancel());
351
- const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this, D) - l}px)`, c = `translateY(calc((100% + ${g}) * ${this.value - o(this, S)} + ${o(this, W)}px))`;
352
- h(this, z, this.el.animate({
350
+ (d = o(this, O)) == null || d.cancel(), o(this, S) !== this.value && ((x = o(this, D)) == null || x.cancel());
351
+ const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this, z) - l}px)`, c = `translateY(calc((100% + ${g}) * ${this.value - o(this, S)} + ${o(this, X)}px))`;
352
+ h(this, O, this.el.animate({
353
353
  transform: [et ? f : `${f} ${c}`, "none"]
354
354
  }, {
355
355
  ...this.flow.xTiming,
356
356
  composite: "accumulate"
357
357
  // in case there's an in-flight y animation
358
- })), et && o(this, S) !== this.value && h(this, O, this.el.animate({
358
+ })), et && o(this, S) !== this.value && h(this, D, this.el.animate({
359
359
  transform: [c, "none"]
360
360
  }, {
361
361
  ...this.flow.yTiming,
@@ -363,9 +363,9 @@ class pt extends ft {
363
363
  }));
364
364
  }
365
365
  }
366
- S = new WeakMap(), W = new WeakMap(), D = new WeakMap(), z = new WeakMap(), O = new WeakMap();
367
- var w, F, I, V;
368
- class Tt extends ft {
366
+ S = new WeakMap(), X = new WeakMap(), z = new WeakMap(), O = new WeakMap(), D = new WeakMap();
367
+ var w, I, F, V;
368
+ class jt extends ft {
369
369
  constructor(t, s, e, a) {
370
370
  const l = y("span", {
371
371
  className: "symbol__value",
@@ -376,20 +376,20 @@ class Tt extends ft {
376
376
  }, [l]), a);
377
377
  u(this, "type");
378
378
  r(this, w, /* @__PURE__ */ new Map());
379
- r(this, F);
380
- r(this, I, (t) => () => {
379
+ r(this, I);
380
+ r(this, F, (t) => () => {
381
381
  o(this, w).delete(t);
382
382
  });
383
383
  r(this, V);
384
384
  this.type = s, o(this, w).set(e, new J(this.flow, l, {
385
- onRemove: o(this, I).call(this, e)
385
+ onRemove: o(this, F).call(this, e)
386
386
  }));
387
387
  }
388
388
  willUpdate(t) {
389
389
  if (this.type === "decimal")
390
390
  return;
391
391
  const s = this.el.getBoundingClientRect();
392
- h(this, F, s[this.section.justify] - t[this.section.justify]);
392
+ h(this, I, s[this.section.justify] - t[this.section.justify]);
393
393
  }
394
394
  update(t) {
395
395
  if (this.value !== t) {
@@ -404,7 +404,7 @@ class Tt extends ft {
404
404
  });
405
405
  this.el.appendChild(e), o(this, w).set(t, new J(this.flow, e, {
406
406
  animateIn: !0,
407
- onRemove: o(this, I).call(this, t)
407
+ onRemove: o(this, F).call(this, t)
408
408
  }));
409
409
  }
410
410
  }
@@ -417,23 +417,19 @@ class Tt extends ft {
417
417
  (a = o(this, V)) == null || a.cancel();
418
418
  const e = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
419
419
  h(this, V, this.el.animate({
420
- transform: [`translateX(${o(this, F) - e}px)`, "none"]
420
+ transform: [`translateX(${o(this, I) - e}px)`, "none"]
421
421
  }, this.flow.xTiming));
422
422
  }
423
423
  }
424
- w = new WeakMap(), F = new WeakMap(), I = new WeakMap(), V = new WeakMap();
424
+ w = new WeakMap(), I = new WeakMap(), F = new WeakMap(), V = new WeakMap();
425
425
  export {
426
- Lt as NumberFlowLite,
427
- kt as SlottedTag,
428
- Ut as defaultFadeTiming,
426
+ Mt as NumberFlowLite,
427
+ Ct as SlottedTag,
428
+ $t as defaultFadeTiming,
429
429
  ht as defaultXTiming,
430
- jt as defaultXTimingFallbackDuration,
431
- Rt as defaultXTimingFallbackPoints,
432
- vt as defaultXTimingLinearDuration,
433
- St as defaultXTimingLinearPoints,
434
- Et as defaultYTiming,
435
- Nt as partitionParts,
436
- Bt as slottedStyles,
430
+ St as defaultYTiming,
431
+ Et as partitionParts,
432
+ Tt as slottedStyles,
437
433
  et as supportsAnimationComposition,
438
434
  bt as supportsLinear
439
435
  };
package/dist/styles.d.ts CHANGED
@@ -2,13 +2,13 @@ export declare const supportsLinear: boolean;
2
2
  export declare const supportsAtProperty: boolean;
3
3
  export declare const supportsAnimationComposition: boolean;
4
4
  export declare const charHeight = "var(--number-flow-char-height, 1em)";
5
- export declare const maskHeight = "var(--number-flow-mask-height, 0.15em)";
5
+ export declare const maskHeight = "var(--number-flow-mask-height, 0.25em)";
6
6
  export declare const SlottedTag = "span";
7
7
  export declare const slottedStyles: {
8
8
  readonly fontKerning: "none";
9
9
  readonly display: "inline-block";
10
10
  readonly lineHeight: "var(--number-flow-char-height, 1em)";
11
- readonly padding: "var(--number-flow-mask-height, 0.15em) 0";
11
+ readonly padding: "var(--number-flow-mask-height, 0.25em) 0";
12
12
  };
13
13
  declare const styles: string;
14
14
  export default styles;
package/package.json CHANGED
@@ -3,13 +3,13 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.1",
6
+ "version": "0.2.3",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",
10
10
  "url": "https://barvian.me"
11
11
  },
12
- "description": "A lightweight component to transition and format numbers.",
12
+ "description": "A component to transition and format numbers.",
13
13
  "license": "MIT",
14
14
  "homepage": "https://number-flow.barvian.me/",
15
15
  "repository": {