number-flow 0.3.0 → 0.3.2

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Maxwell Barvian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -12,12 +12,13 @@ type SymbolPart = {
12
12
  type: Exclude<NumberPartType, 'integer' | 'fraction'>;
13
13
  value: string;
14
14
  };
15
- export type NumberPart = DigitPart | SymbolPart;
16
15
  export type NumberPartKey = string;
17
16
  type KeyedPart = {
18
17
  key: NumberPartKey;
19
18
  };
20
- export type KeyedDigitPart = DigitPart & KeyedPart;
19
+ export type KeyedDigitPart = DigitPart & KeyedPart & {
20
+ place: number;
21
+ };
21
22
  export type KeyedSymbolPart = SymbolPart & KeyedPart;
22
23
  export type KeyedNumberPart = KeyedDigitPart | KeyedSymbolPart;
23
24
  export type Format = Omit<Intl.NumberFormatOptions, 'notation'> & {
package/dist/index.d.ts CHANGED
@@ -21,8 +21,10 @@ export declare class NumberFlowLite extends ServerSafeHTMLElement {
21
21
  manual: boolean;
22
22
  respectMotionPreference: boolean;
23
23
  trend: RawTrend;
24
- getComputedTrend(): Trend | undefined;
25
- set parts(newVal: PartitionedParts | undefined);
24
+ continuous: boolean;
25
+ get startingPlace(): number | null | undefined;
26
+ get computedTrend(): Trend | undefined;
27
+ set parts(parts: PartitionedParts | undefined);
26
28
  willUpdate(): void;
27
29
  didUpdate(): void;
28
30
  get animated(): boolean;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("esm-env");function n(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,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?a!==t||!s:!t.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(a,e):s?s.value=e:t.set(a,e),e}const g=(a,t,e)=>{const i=document.createElement(a),[s,o]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),o==null||o.forEach(r=>i.appendChild(r)),i},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};function gt(a,t,{reverse:e=!1}={}){const i=a.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(a[s],s)}function wt(a,t){const e=t.formatToParts(a),i=[],s=[],o=[],r=[],l={},f=c=>(l[c]||(l[c]=0),`${c}:${l[c]++}`);let $="",tt=!1,et=!1;for(const c of e){$+=c.value;const d=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;d==="integer"?(tt=!0,s.push(...c.value.split("").map(K=>({type:d,value:parseInt(K)})))):d==="group"?s.push({type:d,value:c.value}):d==="decimal"?(et=!0,o.push({type:d,value:c.value,key:f(d)})):d==="fraction"?o.push(...c.value.split("").map(K=>({type:d,value:parseInt(K),key:f(d)}))):(tt||et?r:i).push({type:d,value:c.value,key:f(d)})}const it=[];for(let c=s.length-1;c>=0;c--)it.unshift({...s[c],key:f(s[c].type)});return{pre:i,integer:it,fraction:o,post:r,formatted:$,value:typeof a=="string"?parseFloat(a):a}}const yt=G.BROWSER?HTMLElement:class{},_t=String.raw,vt=G.BROWSER&&typeof CSS<"u"&&CSS.supports("line-height","mod(1,1)"),T=G.BROWSER?matchMedia("(prefers-reduced-motion: reduce)"):null,z="--_number-flow-d-opacity",J="--_number-flow-d-width",I="--_number-flow-dx",Q="--_number-flow-d",bt=(()=>{try{return CSS.registerProperty({name:z,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:I,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:J,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:Q,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),ot="var(--number-flow-char-height, 1em)",m="var(--number-flow-mask-height, 0.25em)",N=`calc(${m} / 2)`,Y="var(--number-flow-mask-width, 0.5em)",y=`calc(${Y} / var(--scale-x))`,P="#000 0, transparent 71%",rt="span",St=({willChange:a})=>({fontKerning:"none",display:"inline-block",lineHeight:ot,padding:`${m} 0`,willChange:a?"transform":void 0}),st=_t`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ot} !important;isolation:isolate;}::slotted(${rt}){position:absolute;left:0;top:0;color:transparent !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(${J}) / var(--width));transform:translateX(var(${I})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Y});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${y},#000 calc(100% - ${y}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${P}),radial-gradient(at bottom left,${P}),radial-gradient(at top left,${P}),radial-gradient(at top right,${P});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${y} * 2) 100%,${y} ${m},${y} ${m},${y} ${m},${y} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${Y};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${I})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${N};padding-top:${N};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${N} 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(${Q});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${N} 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:${N} 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}));}`;var j,L,_,v,b,S,W,x,A,E,k,O,F,D,C,B,M,R,u,H,q,w,V,X;const lt=vt&&bt;var p;(function(a){a[a.UP=1]="UP",a[a.DOWN=-1]="DOWN",a[a.NONE=0]="NONE"})(p||(p={}));const ht=(a,t)=>{if(t!=null)return a>t?p.UP:a<t?p.DOWN:p.NONE},ct={duration:450,easing:"ease-out"},ft={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)"};let U;class Et extends yt{constructor(){super(...arguments),this.transformTiming=ft,this.opacityTiming=ct,j.set(this,!0),this.manual=!1,this.respectMotionPreference=!0,L.set(this,!1),_.set(this,void 0),v.set(this,void 0),b.set(this,void 0),this.trend=!0,S.set(this,void 0),W.set(this,void 0),x.set(this,void 0)}static define(){G.BROWSER&&customElements.define("number-flow",this)}getComputedTrend(){return n(this,S,"f")}set parts(t){if(t==null)return;const{pre:e,integer:i,fraction:s,post:o,value:r}=t;if(n(this,L,"f")){const l=n(this,W,"f");h(this,W,r,"f"),this.trend===!0?h(this,S,ht(r,l),"f"):this.trend==="increasing"?h(this,S,p.UP,"f"):this.trend==="decreasing"?h(this,S,p.DOWN,"f"):h(this,S,p.NONE,"f"),this.manual||this.willUpdate(),n(this,_,"f").update(e),n(this,v,"f").update({integer:i,fraction:s}),n(this,b,"f").update(o),this.manual||this.didUpdate()}else{if(h(this,W,r,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)U||(U=new CSSStyleSheet,U.replaceSync(st)),this.shadowRoot.adoptedStyleSheets=[U];else{const l=document.createElement("style");l.textContent=st,this.shadowRoot.appendChild(l)}this.shadowRoot.appendChild(g("slot")),h(this,_,new at(this,e,{inert:!0,ariaHidden:"true",justify:"right"}),"f"),this.shadowRoot.appendChild(n(this,_,"f").el),h(this,v,new kt(this,i,s,{inert:!0,ariaHidden:"true"}),"f"),this.shadowRoot.appendChild(n(this,v,"f").el),h(this,b,new at(this,o,{inert:!0,ariaHidden:"true",justify:"left"}),"f"),this.shadowRoot.appendChild(n(this,b,"f").el)}h(this,L,!0,"f")}willUpdate(){this.animated&&(n(this,_,"f").willUpdate(),n(this,v,"f").willUpdate(),n(this,b,"f").willUpdate())}didUpdate(){if(!this.animated)return;n(this,x,"f")?n(this,x,"f").abort():this.dispatchEvent(new Event("animationsstart")),n(this,_,"f").didUpdate(),n(this,v,"f").didUpdate(),n(this,b,"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,x,void 0,"f"))}),h(this,x,t,"f")}get animated(){return lt&&n(this,j,"f")&&(!this.respectMotionPreference||!(T!=null&&T.matches))}set animated(t){var e;this.animated!==t&&(h(this,j,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}}j=new WeakMap,L=new WeakMap,_=new WeakMap,v=new WeakMap,b=new WeakMap,S=new WeakMap,W=new WeakMap,x=new WeakMap;class kt{constructor(t,e,i,{className:s,...o}={}){this.flow=t,A.set(this,void 0),E.set(this,void 0),k.set(this,void 0),O.set(this,void 0),F.set(this,void 0),h(this,E,new nt(t,e,{justify:"right"}),"f"),h(this,k,new nt(t,i,{justify:"left"}),"f"),h(this,A,g("span",{className:"number__inner"},[n(this,E,"f").el,n(this,k,"f").el]),"f"),this.el=g("span",{...o,className:`number ${s??""}`},[n(this,A,"f")])}willUpdate(){h(this,O,this.el.offsetWidth,"f"),h(this,F,this.el.getBoundingClientRect().left,"f"),n(this,E,"f").willUpdate(),n(this,k,"f").willUpdate()}update({integer:t,fraction:e}){n(this,E,"f").update(t),n(this,k,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();n(this,E,"f").didUpdate(),n(this,k,"f").didUpdate();const e=n(this,F,"f")-t.left,i=this.el.offsetWidth,s=n(this,O,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[I]:[`${e}px`,"0px"],[J]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}A=new WeakMap,E=new WeakMap,k=new WeakMap,O=new WeakMap,F=new WeakMap;class dt{constructor(t,e,{justify:i,className:s,...o},r){this.flow=t,this.children=new Map,this.onCharRemove=f=>()=>{this.children.delete(f)},D.set(this,void 0),this.justify=i;const l=e.map(f=>this.addChar(f).el);this.el=g("span",{...o,className:`section section--justify-${i} ${s??""}`},r?r(l):l)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new ut(this,t.type,e?0:t.value,{...i,onRemove:this.onCharRemove(t.key)}):new xt(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}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,s=this.justify==="left",o=s?"prepend":"append";if(gt(t,r=>{let l;this.children.has(r.key)?(l=this.children.get(r.key),i.set(r,l),this.unpop(l),l.present=!0):(l=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,l)),this.el[o](l.el)},{reverse:s}),this.flow.animated){const r=this.el.getBoundingClientRect();e.forEach(l=>{l.willUpdate(r)})}e.forEach((r,l)=>{r.update(l.value)}),i.forEach((r,l)=>{r.update(l.value)})}willUpdate(){const t=this.el.getBoundingClientRect();h(this,D,t[this.justify],"f"),this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=n(this,D,"f")-e;this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}D=new WeakMap;class nt extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof ut&&i.update(0)}),this.pop(e)}}class at extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class Z{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,C.set(this,!0),B.set(this,void 0),M.set(this,()=>{var o;this.el.remove(),(o=n(this,B,"f"))==null||o.call(this)}),this.el.classList.add("animate-presence"),this.flow.animated&&s&&this.el.animate({[z]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),h(this,B,i,"f")}get present(){return n(this,C,"f")}set present(t){if(n(this,C,"f")!==t){if(h(this,C,t,"f"),!this.flow.animated){t||n(this,M,"f").call(this);return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[z]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",n(this,M,"f")):this.flow.addEventListener("animationsfinish",n(this,M,"f"),{once:!0})}}}C=new WeakMap,B=new WeakMap,M=new WeakMap;class pt extends Z{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class ut extends pt{constructor(t,e,i,s){const o=Array.from({length:10}).map((l,f)=>{const $=g("span",{className:`digit__num${f===i?" is-current":""}`},[document.createTextNode(String(f))]);return $.style.setProperty("--n",String(f)),$}),r=g("span",{className:"digit"},o);r.style.setProperty("--current",String(i)),super(t,i,r,s),R.set(this,void 0),u.set(this,void 0),H.set(this,void 0),q.set(this,()=>{this.el.classList.remove("is-spinning")}),h(this,R,o,"f")}get trend(){const t=this.flow.getComputedTrend();return t===p.NONE?ht(this.value,n(this,u,"f")):t}willUpdate(t){const e=this.el.getBoundingClientRect();h(this,u,this.value,"f");const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;h(this,H,this.section.justify==="left"?i+s:i-s,"f")}update(t){var e,i;(e=n(this,R,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=n(this,R,"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],s=e.width/2,o=this.section.justify==="left"?i+s:i-s;if(this.el.animate({transform:[`translateX(${n(this,H,"f")-o}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"}),this.value===n(this,u,"f"))return;const r=this.trend;let l=this.value-n(this,u,"f");r===p.DOWN&&this.value>n(this,u,"f")&&(l=this.value-10-n(this,u,"f")),r===p.UP&&this.value<n(this,u,"f")&&(l=10-n(this,u,"f")+this.value),this.el.classList.add("is-spinning"),this.el.animate({[Q]:[-l,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",n(this,q,"f"),{once:!0})}}R=new WeakMap,u=new WeakMap,H=new WeakMap,q=new WeakMap;class xt extends pt{constructor(t,e,i,s){const o=g("span",{className:"symbol__value",textContent:i});super(t,i,g("span",{className:"symbol"},[o]),s),this.type=e,w.set(this,new Map),V.set(this,void 0),X.set(this,r=>()=>{n(this,w,"f").delete(r)}),n(this,w,"f").set(i,new Z(this.flow,o,{onRemove:n(this,X,"f").call(this,i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();h(this,V,e[this.section.justify]-t[this.section.justify],"f")}update(t){if(this.value!==t){const e=n(this,w,"f").get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),n(this,w,"f").has(t)){const i=n(this,w,"f").get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=g("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),n(this,w,"f").set(t,new Z(this.flow,i,{animateIn:!0,onRemove:n(this,X,"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(${n(this,V,"f")-i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}w=new WeakMap,V=new WeakMap,X=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=rt;exports.canAnimate=lt;exports.defaultOpacityTiming=ct;exports.defaultTransformTiming=ft;exports.partitionParts=wt;exports.prefersReducedMotion=T;exports.slottedStyles=St;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("esm-env");function n(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,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?a!==t||!s:!t.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(a,e):s?s.value=e:t.set(a,e),e}const w=(a,t,e)=>{const i=document.createElement(a),[s,r]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),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};function gt(a,t,{reverse:e=!1}={}){const i=a.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(a[s],s)}function wt(a,t){const e=t.formatToParts(a),i=[],s=[],r=[],l=[],o={},p=c=>{const f=o[c]==null?o[c]=0:++o[c];return`${c}:${f}`};let u="",m=!1,W=!1;for(const c of e){u+=c.value;const f=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;f==="integer"?(m=!0,s.push(...c.value.split("").map(J=>({type:f,value:parseInt(J)})))):f==="group"?s.push({type:f,value:c.value}):f==="decimal"?(W=!0,r.push({type:f,value:c.value,key:p(f)})):f==="fraction"?r.push(...c.value.split("").map(J=>({type:f,value:parseInt(J),key:p(f),place:-1-o[f]}))):(m||W?l:i).push({type:f,value:c.value,key:p(f)})}const d=[];for(let c=s.length-1;c>=0;c--){const f=s[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 yt=T.BROWSER?HTMLElement:class{},vt=String.raw,_t=T.BROWSER&&typeof CSS<"u"&&CSS.supports("animation-timing-function","linear(1,2)"),bt=T.BROWSER&&typeof CSS<"u"&&CSS.supports("line-height","mod(1,1)"),F=T.BROWSER?matchMedia("(prefers-reduced-motion: reduce)"):null,q="--_number-flow-d-opacity",it="--_number-flow-d-width",Z="--_number-flow-dx",st="--_number-flow-d",St=(()=>{try{return CSS.registerProperty({name:q,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:Z,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:it,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:st,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),rt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",C=`calc(${g} / 2)`,Q="var(--number-flow-mask-width, 0.5em)",S=`calc(${Q} / var(--scale-x))`,A="#000 0, transparent 71%",lt="span",kt=({willChange:a})=>({fontKerning:"none",display:"inline-block",lineHeight:rt,padding:`${g} 0`,willChange:a?"transform":void 0}),nt=vt`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${rt} !important;isolation:isolate;}::slotted(${lt}){position:absolute;left:0;top:0;color:transparent !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(${it}) / var(--width));transform:translateX(var(${Z})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Q});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,${A}),radial-gradient(at bottom left,${A}),radial-gradient(at top left,${A}),radial-gradient(at top right,${A});-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 ${Q};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${Z})));}.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(${st});}: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}));}`,xt=(a,t)=>a!=null&&t==null?a:a==null&&t!=null?t:a!=null&&t!=null?Math.max(a,t):null;var B,D,k,x,E,y,R,P,N,H,$,M,V,X,z,U,I,L,j,v,G,tt,_,K,Y;const ht=bt&&_t&&St;var b;(function(a){a[a.UP=1]="UP",a[a.DOWN=-1]="DOWN",a[a.NONE=0]="NONE"})(b||(b={}));const ct={duration:450,easing:"ease-out"},ft={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)"};let O;class Et extends yt{constructor(){super(...arguments),this.transformTiming=ft,this.opacityTiming=ct,B.set(this,!0),this.manual=!1,this.respectMotionPreference=!0,D.set(this,!1),k.set(this,void 0),x.set(this,void 0),E.set(this,void 0),this.trend=!0,y.set(this,void 0),this.continuous=!1,R.set(this,void 0),P.set(this,void 0),N.set(this,void 0)}static define(){T.BROWSER&&customElements.define("number-flow",this)}get startingPlace(){return n(this,R,"f")}get computedTrend(){return n(this,y,"f")}set parts(t){if(t==null)return;const{pre:e,integer:i,fraction:s,post:r,value:l}=t;if(n(this,D,"f")){const o=n(this,P,"f");if(h(this,P,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,R,void 0,"f"),n(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)),W=u.find(d=>!p.find(c=>d.place===c.place&&d.value===c.value));h(this,R,xt(m==null?void 0:m.place,W==null?void 0:W.place),"f")}this.manual||this.willUpdate(),n(this,k,"f").update(e),n(this,x,"f").update({integer:i,fraction:s}),n(this,E,"f").update(r),this.manual||this.didUpdate()}else{if(h(this,P,t,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)O||(O=new CSSStyleSheet,O.replaceSync(nt)),this.shadowRoot.adoptedStyleSheets=[O];else{const o=document.createElement("style");o.textContent=nt,this.shadowRoot.appendChild(o)}this.shadowRoot.appendChild(w("slot")),h(this,k,new ot(this,e,{inert:!0,ariaHidden:"true",justify:"right"}),"f"),this.shadowRoot.appendChild(n(this,k,"f").el),h(this,x,new $t(this,i,s,{inert:!0,ariaHidden:"true"}),"f"),this.shadowRoot.appendChild(n(this,x,"f").el),h(this,E,new ot(this,r,{inert:!0,ariaHidden:"true",justify:"left"}),"f"),this.shadowRoot.appendChild(n(this,E,"f").el)}h(this,D,!0,"f")}willUpdate(){this.animated&&(n(this,k,"f").willUpdate(),n(this,x,"f").willUpdate(),n(this,E,"f").willUpdate())}didUpdate(){if(!this.animated)return;n(this,N,"f")?n(this,N,"f").abort():this.dispatchEvent(new Event("animationsstart")),n(this,k,"f").didUpdate(),n(this,x,"f").didUpdate(),n(this,E,"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,N,void 0,"f"))}),h(this,N,t,"f")}get animated(){return ht&&n(this,B,"f")&&(!this.respectMotionPreference||!(F!=null&&F.matches))}set animated(t){var e;this.animated!==t&&(h(this,B,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}}B=new WeakMap,D=new WeakMap,k=new WeakMap,x=new WeakMap,E=new WeakMap,y=new WeakMap,R=new WeakMap,P=new WeakMap,N=new WeakMap;class $t{constructor(t,e,i,{className:s,...r}={}){this.flow=t,H.set(this,void 0),$.set(this,void 0),M.set(this,void 0),V.set(this,void 0),X.set(this,void 0),h(this,$,new at(t,e,{justify:"right"}),"f"),h(this,M,new at(t,i,{justify:"left"}),"f"),h(this,H,w("span",{className:"number__inner"},[n(this,$,"f").el,n(this,M,"f").el]),"f"),this.el=w("span",{...r,className:`number ${s??""}`},[n(this,H,"f")])}willUpdate(){h(this,V,this.el.offsetWidth,"f"),h(this,X,this.el.getBoundingClientRect().left,"f"),n(this,$,"f").willUpdate(),n(this,M,"f").willUpdate()}update({integer:t,fraction:e}){n(this,$,"f").update(t),n(this,M,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();n(this,$,"f").didUpdate(),n(this,M,"f").didUpdate();const e=n(this,X,"f")-t.left,i=this.el.offsetWidth,s=n(this,V,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[Z]:[`${e}px`,"0px"],[it]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}H=new WeakMap,$=new WeakMap,M=new WeakMap,V=new WeakMap,X=new WeakMap;class dt{constructor(t,e,{justify:i,className:s,...r},l){this.flow=t,this.children=new Map,this.onCharRemove=p=>()=>{this.children.delete(p)},z.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} ${s??""}`},l?l(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new ut(this,t.type,e?0:t.value,t.place,{...i,onRemove:this.onCharRemove(t.key)}):new Mt(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}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,s=this.justify==="left",r=s?"prepend":"append";if(gt(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:s}),this.flow.animated){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,z,t[this.justify],"f"),this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=n(this,z,"f")-e;this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}z=new WeakMap;class at extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(r=>r.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof ut&&i.update(0)}),this.pop(e)}}class ot extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(r=>r.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class et{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,U.set(this,!0),I.set(this,void 0),L.set(this,()=>{var r;this.el.remove(),(r=n(this,I,"f"))==null||r.call(this)}),this.el.classList.add("animate-presence"),this.flow.animated&&s&&this.el.animate({[q]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),h(this,I,i,"f")}get present(){return n(this,U,"f")}set present(t){if(n(this,U,"f")!==t){if(h(this,U,t,"f"),!this.flow.animated){t||n(this,L,"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",n(this,L,"f")):this.flow.addEventListener("animationsfinish",n(this,L,"f"),{once:!0})}}}U=new WeakMap,I=new WeakMap,L=new WeakMap;class pt extends et{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class ut extends pt{constructor(t,e,i,s,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=s,j.set(this,void 0),v.set(this,void 0),G.set(this,void 0),tt.set(this,()=>{this.el.classList.remove("is-spinning")}),h(this,j,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],s=e.width/2;h(this,G,this.section.justify==="left"?i+s:i-s,"f")}update(t){var e,i;(e=n(this,j,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=n(this,j,"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],s=e.width/2,r=this.section.justify==="left"?i+s:i-s;this.el.animate({transform:[`translateX(${n(this,G,"f")-r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const l=this.diff;l&&(this.el.classList.add("is-spinning"),this.el.animate({[st]:[-l,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",n(this,tt,"f"),{once:!0}))}get diff(){let t=this.flow.computedTrend;const e=this.value-n(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>n(this,v,"f")?this.value-10-n(this,v,"f"):t===b.UP&&this.value<n(this,v,"f")?10-n(this,v,"f")+this.value:e)}}j=new WeakMap,v=new WeakMap,G=new WeakMap,tt=new WeakMap;class Mt extends pt{constructor(t,e,i,s){const r=w("span",{className:"symbol__value",textContent:i});super(t,i,w("span",{className:"symbol"},[r]),s),this.type=e,_.set(this,new Map),K.set(this,void 0),Y.set(this,l=>()=>{n(this,_,"f").delete(l)}),n(this,_,"f").set(i,new et(this.flow,r,{onRemove:n(this,Y,"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=n(this,_,"f").get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),n(this,_,"f").has(t)){const i=n(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),n(this,_,"f").set(t,new et(this.flow,i,{animateIn:!0,onRemove:n(this,Y,"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(${n(this,K,"f")-i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}_=new WeakMap,K=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=lt;exports.canAnimate=ht;exports.defaultOpacityTiming=ct;exports.defaultTransformTiming=ft;exports.partitionParts=wt;exports.prefersReducedMotion=F;exports.slottedStyles=kt;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { BROWSER as I } from "esm-env";
1
+ import { BROWSER as T } from "esm-env";
2
2
  function n(a, t, e, i) {
3
3
  if (e === "a" && !i) throw new TypeError("Private accessor was defined without a getter");
4
4
  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");
@@ -10,9 +10,9 @@ function h(a, t, e, i, s) {
10
10
  if (typeof t == "function" ? a !== t || !s : !t.has(a)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return i === "a" ? s.call(a, e) : s ? s.value = e : t.set(a, e), e;
12
12
  }
13
- const g = (a, t, e) => {
14
- const i = document.createElement(a), [s, o] = Array.isArray(t) ? [void 0, t] : [t, e];
15
- return s && Object.assign(i, s), o == null || o.forEach((r) => i.appendChild(r)), i;
13
+ const w = (a, t, e) => {
14
+ const i = document.createElement(a), [s, r] = Array.isArray(t) ? [void 0, t] : [t, e];
15
+ return s && Object.assign(i, s), r == null || r.forEach((l) => i.appendChild(l)), i;
16
16
  }, ft = (a, t) => {
17
17
  var e;
18
18
  return t === "left" ? a.offsetLeft : (((e = a.offsetParent instanceof HTMLElement ? a.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - a.offsetWidth - a.offsetLeft;
@@ -22,50 +22,67 @@ function dt(a, t, { reverse: e = !1 } = {}) {
22
22
  for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
23
23
  t(a[s], s);
24
24
  }
25
- function kt(a, t) {
26
- const e = t.formatToParts(a), i = [], s = [], o = [], r = [], l = {}, f = (c) => (l[c] || (l[c] = 0), `${c}:${l[c]++}`);
27
- let E = "", tt = !1, et = !1;
25
+ function Et(a, t) {
26
+ const e = t.formatToParts(a), i = [], s = [], r = [], l = [], o = {}, p = (c) => {
27
+ const f = o[c] == null ? o[c] = 0 : ++o[c];
28
+ return `${c}:${f}`;
29
+ };
30
+ let u = "", m = !1, N = !1;
28
31
  for (const c of e) {
29
- E += c.value;
30
- const d = c.type === "minusSign" || c.type === "plusSign" ? "sign" : c.type;
31
- d === "integer" ? (tt = !0, s.push(...c.value.split("").map((G) => ({ type: d, value: parseInt(G) })))) : d === "group" ? s.push({ type: d, value: c.value }) : d === "decimal" ? (et = !0, o.push({ type: d, value: c.value, key: f(d) })) : d === "fraction" ? o.push(...c.value.split("").map((G) => ({ type: d, value: parseInt(G), key: f(d) }))) : (tt || et ? r : i).push({
32
- type: d,
32
+ u += c.value;
33
+ const f = c.type === "minusSign" || c.type === "plusSign" ? "sign" : c.type;
34
+ f === "integer" ? (m = !0, s.push(...c.value.split("").map((q) => ({ type: f, value: parseInt(q) })))) : f === "group" ? s.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((q) => ({
35
+ type: f,
36
+ value: parseInt(q),
37
+ key: p(f),
38
+ place: -1 - o[f]
39
+ }))) : (m || N ? l : i).push({
40
+ type: f,
33
41
  value: c.value,
34
- key: f(d)
42
+ key: p(f)
43
+ });
44
+ }
45
+ const d = [];
46
+ for (let c = s.length - 1; c >= 0; c--) {
47
+ const f = s[c];
48
+ d.unshift(f.type === "integer" ? {
49
+ ...f,
50
+ key: p(f.type),
51
+ place: o[f.type]
52
+ } : {
53
+ ...f,
54
+ key: p(f.type)
35
55
  });
36
56
  }
37
- const it = [];
38
- for (let c = s.length - 1; c >= 0; c--)
39
- it.unshift({ ...s[c], key: f(s[c].type) });
40
57
  return {
41
58
  pre: i,
42
- integer: it,
43
- fraction: o,
44
- post: r,
45
- formatted: E,
59
+ integer: d,
60
+ fraction: r,
61
+ post: l,
62
+ formatted: u,
46
63
  value: typeof a == "string" ? parseFloat(a) : a
47
64
  };
48
65
  }
49
- const pt = I ? HTMLElement : class {
50
- }, ut = String.raw, mt = I && typeof CSS < "u" && CSS.supports("line-height", "mod(1,1)"), K = I ? matchMedia("(prefers-reduced-motion: reduce)") : null, X = "--_number-flow-d-opacity", J = "--_number-flow-d-width", z = "--_number-flow-dx", Q = "--_number-flow-d", gt = (() => {
66
+ const pt = T ? HTMLElement : class {
67
+ }, ut = String.raw, mt = T && typeof CSS < "u" && CSS.supports("animation-timing-function", "linear(1,2)"), gt = T && typeof CSS < "u" && CSS.supports("line-height", "mod(1,1)"), J = T ? matchMedia("(prefers-reduced-motion: reduce)") : null, Y = "--_number-flow-d-opacity", it = "--_number-flow-d-width", Z = "--_number-flow-dx", st = "--_number-flow-d", wt = (() => {
51
68
  try {
52
69
  return CSS.registerProperty({
53
- name: X,
70
+ name: Y,
54
71
  syntax: "<number>",
55
72
  inherits: !1,
56
73
  initialValue: "0"
57
74
  }), CSS.registerProperty({
58
- name: z,
75
+ name: Z,
59
76
  syntax: "<length>",
60
77
  inherits: !0,
61
78
  initialValue: "0px"
62
79
  }), CSS.registerProperty({
63
- name: J,
80
+ name: it,
64
81
  syntax: "<number>",
65
82
  inherits: !1,
66
83
  initialValue: "0"
67
84
  }), CSS.registerProperty({
68
- name: Q,
85
+ name: st,
69
86
  syntax: "<number>",
70
87
  inherits: !0,
71
88
  initialValue: "0"
@@ -73,137 +90,141 @@ const pt = I ? HTMLElement : class {
73
90
  } catch {
74
91
  return !1;
75
92
  }
76
- })(), ot = "var(--number-flow-char-height, 1em)", m = "var(--number-flow-mask-height, 0.25em)", N = `calc(${m} / 2)`, Y = "var(--number-flow-mask-width, 0.5em)", y = `calc(${Y} / var(--scale-x))`, P = "#000 0, transparent 71%", wt = "span", $t = ({ willChange: a }) => ({
93
+ })(), rt = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", C = `calc(${g} / 2)`, Q = "var(--number-flow-mask-width, 0.5em)", S = `calc(${Q} / var(--scale-x))`, A = "#000 0, transparent 71%", yt = "span", Mt = ({ willChange: a }) => ({
77
94
  fontKerning: "none",
78
95
  display: "inline-block",
79
- lineHeight: ot,
80
- padding: `${m} 0`,
96
+ lineHeight: rt,
97
+ padding: `${g} 0`,
81
98
  willChange: a ? "transform" : void 0
82
- }), st = ut`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ot} !important;isolation:isolate;}::slotted(${wt}){position:absolute;left:0;top:0;color:transparent !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(${J}) / var(--width));transform:translateX(var(${z})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Y});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${y},#000 calc(100% - ${y}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${P}),radial-gradient(at bottom left,${P}),radial-gradient(at top left,${P}),radial-gradient(at top right,${P});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${y} * 2) 100%,${y} ${m},${y} ${m},${y} ${m},${y} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${Y};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${z})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${N};padding-top:${N};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${N} 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(${Q});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${N} 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:${N} 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(${X}));}`;
83
- var R, L, _, v, b, S, C, $, T, x, k, A, D, F, W, O, M, U, u, B, Z, w, H, V;
84
- const yt = mt && gt;
85
- var p;
99
+ }), nt = ut`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${rt} !important;isolation:isolate;}::slotted(${yt}){position:absolute;left:0;top:0;color:transparent !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(${it}) / var(--width));transform:translateX(var(${Z})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Q});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,${A}),radial-gradient(at bottom left,${A}),radial-gradient(at top left,${A}),radial-gradient(at top right,${A});-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 ${Q};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${Z})));}.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(${st});}: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(${Y}));}`, vt = (a, t) => a != null && t == null ? a : a == null && t != null ? t : a != null && t != null ? Math.max(a, t) : null;
100
+ var D, O, x, k, $, y, P, U, W, B, E, M, H, V, X, L, z, j, R, v, I, tt, _, G, K;
101
+ const _t = gt && mt && wt;
102
+ var b;
86
103
  (function(a) {
87
104
  a[a.UP = 1] = "UP", a[a.DOWN = -1] = "DOWN", a[a.NONE = 0] = "NONE";
88
- })(p || (p = {}));
89
- const rt = (a, t) => {
90
- if (t != null)
91
- return a > t ? p.UP : a < t ? p.DOWN : p.NONE;
92
- }, _t = { duration: 450, easing: "ease-out" }, vt = {
105
+ })(b || (b = {}));
106
+ const bt = { duration: 450, easing: "ease-out" }, St = {
93
107
  duration: 900,
94
108
  // Make sure to keep this minified:
95
109
  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)"
96
110
  };
97
- let j;
98
- class Et extends pt {
111
+ let F;
112
+ class Nt extends pt {
99
113
  constructor() {
100
- super(...arguments), this.transformTiming = vt, this.opacityTiming = _t, R.set(this, !0), this.manual = !1, this.respectMotionPreference = !0, L.set(this, !1), _.set(this, void 0), v.set(this, void 0), b.set(this, void 0), this.trend = !0, S.set(this, void 0), C.set(this, void 0), $.set(this, void 0);
114
+ super(...arguments), this.transformTiming = St, this.opacityTiming = bt, D.set(this, !0), this.manual = !1, this.respectMotionPreference = !0, O.set(this, !1), x.set(this, void 0), k.set(this, void 0), $.set(this, void 0), this.trend = !0, y.set(this, void 0), this.continuous = !1, P.set(this, void 0), U.set(this, void 0), W.set(this, void 0);
101
115
  }
102
116
  static define() {
103
- I && customElements.define("number-flow", this);
117
+ T && customElements.define("number-flow", this);
118
+ }
119
+ get startingPlace() {
120
+ return n(this, P, "f");
104
121
  }
105
- getComputedTrend() {
106
- return n(this, S, "f");
122
+ get computedTrend() {
123
+ return n(this, y, "f");
107
124
  }
108
125
  set parts(t) {
109
126
  if (t == null)
110
127
  return;
111
- const { pre: e, integer: i, fraction: s, post: o, value: r } = t;
112
- if (n(this, L, "f")) {
113
- const l = n(this, C, "f");
114
- h(this, C, r, "f"), this.trend === !0 ? h(this, S, rt(r, l), "f") : this.trend === "increasing" ? h(this, S, p.UP, "f") : this.trend === "decreasing" ? h(this, S, p.DOWN, "f") : h(this, S, p.NONE, "f"), this.manual || this.willUpdate(), n(this, _, "f").update(e), n(this, v, "f").update({ integer: i, fraction: s }), n(this, b, "f").update(o), this.manual || this.didUpdate();
128
+ const { pre: e, integer: i, fraction: s, post: r, value: l } = t;
129
+ if (n(this, O, "f")) {
130
+ const o = n(this, U, "f");
131
+ if (h(this, U, 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, P, void 0, "f"), n(this, y, "f") !== b.NONE && this.continuous) {
132
+ 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));
133
+ h(this, P, vt(m == null ? void 0 : m.place, N == null ? void 0 : N.place), "f");
134
+ }
135
+ this.manual || this.willUpdate(), n(this, x, "f").update(e), n(this, k, "f").update({ integer: i, fraction: s }), n(this, $, "f").update(r), this.manual || this.didUpdate();
115
136
  } else {
116
- if (h(this, C, r, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
117
- j || (j = new CSSStyleSheet(), j.replaceSync(st)), this.shadowRoot.adoptedStyleSheets = [j];
137
+ if (h(this, U, t, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
138
+ F || (F = new CSSStyleSheet(), F.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [F];
118
139
  else {
119
- const l = document.createElement("style");
120
- l.textContent = st, this.shadowRoot.appendChild(l);
140
+ const o = document.createElement("style");
141
+ o.textContent = nt, this.shadowRoot.appendChild(o);
121
142
  }
122
- this.shadowRoot.appendChild(g("slot")), h(this, _, new at(this, e, {
143
+ this.shadowRoot.appendChild(w("slot")), h(this, x, new ot(this, e, {
123
144
  inert: !0,
124
145
  ariaHidden: "true",
125
146
  justify: "right"
126
- }), "f"), this.shadowRoot.appendChild(n(this, _, "f").el), h(this, v, new bt(this, i, s, {
147
+ }), "f"), this.shadowRoot.appendChild(n(this, x, "f").el), h(this, k, new xt(this, i, s, {
127
148
  inert: !0,
128
149
  ariaHidden: "true"
129
- }), "f"), this.shadowRoot.appendChild(n(this, v, "f").el), h(this, b, new at(this, o, {
150
+ }), "f"), this.shadowRoot.appendChild(n(this, k, "f").el), h(this, $, new ot(this, r, {
130
151
  inert: !0,
131
152
  ariaHidden: "true",
132
153
  justify: "left"
133
- }), "f"), this.shadowRoot.appendChild(n(this, b, "f").el);
154
+ }), "f"), this.shadowRoot.appendChild(n(this, $, "f").el);
134
155
  }
135
- h(this, L, !0, "f");
156
+ h(this, O, !0, "f");
136
157
  }
137
158
  willUpdate() {
138
- this.animated && (n(this, _, "f").willUpdate(), n(this, v, "f").willUpdate(), n(this, b, "f").willUpdate());
159
+ this.animated && (n(this, x, "f").willUpdate(), n(this, k, "f").willUpdate(), n(this, $, "f").willUpdate());
139
160
  }
140
161
  didUpdate() {
141
162
  if (!this.animated)
142
163
  return;
143
- n(this, $, "f") ? n(this, $, "f").abort() : this.dispatchEvent(new Event("animationsstart")), n(this, _, "f").didUpdate(), n(this, v, "f").didUpdate(), n(this, b, "f").didUpdate();
164
+ n(this, W, "f") ? n(this, W, "f").abort() : this.dispatchEvent(new Event("animationsstart")), n(this, x, "f").didUpdate(), n(this, k, "f").didUpdate(), n(this, $, "f").didUpdate();
144
165
  const t = new AbortController();
145
166
  Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
146
- t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, $, void 0, "f"));
147
- }), h(this, $, t, "f");
167
+ t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, W, void 0, "f"));
168
+ }), h(this, W, t, "f");
148
169
  }
149
170
  get animated() {
150
- return yt && n(this, R, "f") && (!this.respectMotionPreference || !(K != null && K.matches));
171
+ return _t && n(this, D, "f") && (!this.respectMotionPreference || !(J != null && J.matches));
151
172
  }
152
173
  set animated(t) {
153
174
  var e;
154
- this.animated !== t && (h(this, R, t, "f"), (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
175
+ this.animated !== t && (h(this, D, t, "f"), (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
155
176
  }
156
177
  }
157
- R = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap();
158
- class bt {
159
- constructor(t, e, i, { className: s, ...o } = {}) {
160
- this.flow = t, T.set(this, void 0), x.set(this, void 0), k.set(this, void 0), A.set(this, void 0), D.set(this, void 0), h(this, x, new nt(t, e, {
178
+ D = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap();
179
+ class xt {
180
+ constructor(t, e, i, { className: s, ...r } = {}) {
181
+ this.flow = t, B.set(this, void 0), E.set(this, void 0), M.set(this, void 0), H.set(this, void 0), V.set(this, void 0), h(this, E, new at(t, e, {
161
182
  justify: "right"
162
- }), "f"), h(this, k, new nt(t, i, {
183
+ }), "f"), h(this, M, new at(t, i, {
163
184
  justify: "left"
164
- }), "f"), h(this, T, g("span", {
185
+ }), "f"), h(this, B, w("span", {
165
186
  className: "number__inner"
166
- }, [n(this, x, "f").el, n(this, k, "f").el]), "f"), this.el = g("span", {
167
- ...o,
187
+ }, [n(this, E, "f").el, n(this, M, "f").el]), "f"), this.el = w("span", {
188
+ ...r,
168
189
  className: `number ${s ?? ""}`
169
- }, [n(this, T, "f")]);
190
+ }, [n(this, B, "f")]);
170
191
  }
171
192
  willUpdate() {
172
- h(this, A, this.el.offsetWidth, "f"), h(this, D, this.el.getBoundingClientRect().left, "f"), n(this, x, "f").willUpdate(), n(this, k, "f").willUpdate();
193
+ h(this, H, this.el.offsetWidth, "f"), h(this, V, this.el.getBoundingClientRect().left, "f"), n(this, E, "f").willUpdate(), n(this, M, "f").willUpdate();
173
194
  }
174
195
  update({ integer: t, fraction: e }) {
175
- n(this, x, "f").update(t), n(this, k, "f").update(e);
196
+ n(this, E, "f").update(t), n(this, M, "f").update(e);
176
197
  }
177
198
  didUpdate() {
178
199
  const t = this.el.getBoundingClientRect();
179
- n(this, x, "f").didUpdate(), n(this, k, "f").didUpdate();
180
- const e = n(this, D, "f") - t.left, i = this.el.offsetWidth, s = n(this, A, "f") - i;
200
+ n(this, E, "f").didUpdate(), n(this, M, "f").didUpdate();
201
+ const e = n(this, V, "f") - t.left, i = this.el.offsetWidth, s = n(this, H, "f") - i;
181
202
  this.el.style.setProperty("--width", String(i)), this.el.animate({
182
- [z]: [`${e}px`, "0px"],
183
- [J]: [s, 0]
203
+ [Z]: [`${e}px`, "0px"],
204
+ [it]: [s, 0]
184
205
  }, {
185
206
  ...this.flow.transformTiming,
186
207
  composite: "accumulate"
187
208
  });
188
209
  }
189
210
  }
190
- T = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap();
211
+ B = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap();
191
212
  class lt {
192
- constructor(t, e, { justify: i, className: s, ...o }, r) {
193
- this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (f) => () => {
194
- this.children.delete(f);
195
- }, F.set(this, void 0), this.justify = i;
196
- const l = e.map((f) => this.addChar(f).el);
197
- this.el = g("span", {
198
- ...o,
213
+ constructor(t, e, { justify: i, className: s, ...r }, l) {
214
+ this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (p) => () => {
215
+ this.children.delete(p);
216
+ }, X.set(this, void 0), this.justify = i;
217
+ const o = e.map((p) => this.addChar(p).el);
218
+ this.el = w("span", {
219
+ ...r,
199
220
  className: `section section--justify-${i} ${s ?? ""}`
200
- }, r ? r(l) : l);
221
+ }, l ? l(o) : o);
201
222
  }
202
223
  addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
203
- const s = t.type === "integer" || t.type === "fraction" ? new ct(this, t.type, e ? 0 : t.value, {
224
+ const s = t.type === "integer" || t.type === "fraction" ? new ct(this, t.type, e ? 0 : t.value, t.place, {
204
225
  ...i,
205
226
  onRemove: this.onCharRemove(t.key)
206
- }) : new St(this, t.type, t.value, {
227
+ }) : new kt(this, t.type, t.value, {
207
228
  ...i,
208
229
  onRemove: this.onCharRemove(t.key)
209
230
  });
@@ -220,30 +241,30 @@ class lt {
220
241
  });
221
242
  }
222
243
  addNewAndUpdateExisting(t) {
223
- const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", o = s ? "prepend" : "append";
224
- if (dt(t, (r) => {
225
- let l;
226
- this.children.has(r.key) ? (l = this.children.get(r.key), i.set(r, l), this.unpop(l), l.present = !0) : (l = this.addChar(r, { startDigitsAtZero: !0, animateIn: !0 }), e.set(r, l)), this.el[o](l.el);
244
+ const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", r = s ? "prepend" : "append";
245
+ if (dt(t, (l) => {
246
+ let o;
247
+ 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);
227
248
  }, { reverse: s }), this.flow.animated) {
228
- const r = this.el.getBoundingClientRect();
229
- e.forEach((l) => {
230
- l.willUpdate(r);
249
+ const l = this.el.getBoundingClientRect();
250
+ e.forEach((o) => {
251
+ o.willUpdate(l);
231
252
  });
232
253
  }
233
- e.forEach((r, l) => {
234
- r.update(l.value);
235
- }), i.forEach((r, l) => {
236
- r.update(l.value);
254
+ e.forEach((l, o) => {
255
+ l.update(o.value);
256
+ }), i.forEach((l, o) => {
257
+ l.update(o.value);
237
258
  });
238
259
  }
239
260
  willUpdate() {
240
261
  const t = this.el.getBoundingClientRect();
241
- h(this, F, t[this.justify], "f"), this.children.forEach((e) => e.willUpdate(t));
262
+ h(this, X, t[this.justify], "f"), this.children.forEach((e) => e.willUpdate(t));
242
263
  }
243
264
  didUpdate() {
244
265
  const t = this.el.getBoundingClientRect();
245
266
  this.children.forEach((s) => s.didUpdate(t));
246
- const e = t[this.justify], i = n(this, F, "f") - e;
267
+ const e = t[this.justify], i = n(this, X, "f") - e;
247
268
  this.el.animate({
248
269
  transform: [`translateX(${i}px)`, "none"]
249
270
  }, {
@@ -252,143 +273,142 @@ class lt {
252
273
  });
253
274
  }
254
275
  }
255
- F = /* @__PURE__ */ new WeakMap();
256
- class nt extends lt {
276
+ X = /* @__PURE__ */ new WeakMap();
277
+ class at extends lt {
257
278
  update(t) {
258
279
  const e = /* @__PURE__ */ new Map();
259
280
  this.children.forEach((i, s) => {
260
- t.find((o) => o.key === s) || e.set(s, i), this.unpop(i);
281
+ t.find((r) => r.key === s) || e.set(s, i), this.unpop(i);
261
282
  }), this.addNewAndUpdateExisting(t), e.forEach((i) => {
262
283
  i instanceof ct && i.update(0);
263
284
  }), this.pop(e);
264
285
  }
265
286
  }
266
- class at extends lt {
287
+ class ot extends lt {
267
288
  update(t) {
268
289
  const e = /* @__PURE__ */ new Map();
269
290
  this.children.forEach((i, s) => {
270
- t.find((o) => o.key === s) || e.set(s, i);
291
+ t.find((r) => r.key === s) || e.set(s, i);
271
292
  }), this.pop(e), this.addNewAndUpdateExisting(t);
272
293
  }
273
294
  }
274
- class q {
295
+ class et {
275
296
  constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
276
- this.flow = t, this.el = e, W.set(this, !0), O.set(this, void 0), M.set(this, () => {
277
- var o;
278
- this.el.remove(), (o = n(this, O, "f")) == null || o.call(this);
297
+ this.flow = t, this.el = e, L.set(this, !0), z.set(this, void 0), j.set(this, () => {
298
+ var r;
299
+ this.el.remove(), (r = n(this, z, "f")) == null || r.call(this);
279
300
  }), this.el.classList.add("animate-presence"), this.flow.animated && s && this.el.animate({
280
- [X]: [-0.9999, 0]
301
+ [Y]: [-0.9999, 0]
281
302
  }, {
282
303
  ...this.flow.opacityTiming,
283
304
  composite: "accumulate"
284
- }), h(this, O, i, "f");
305
+ }), h(this, z, i, "f");
285
306
  }
286
307
  get present() {
287
- return n(this, W, "f");
308
+ return n(this, L, "f");
288
309
  }
289
310
  set present(t) {
290
- if (n(this, W, "f") !== t) {
291
- if (h(this, W, t, "f"), !this.flow.animated) {
292
- t || n(this, M, "f").call(this);
311
+ if (n(this, L, "f") !== t) {
312
+ if (h(this, L, t, "f"), !this.flow.animated) {
313
+ t || n(this, j, "f").call(this);
293
314
  return;
294
315
  }
295
316
  this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
296
- [X]: t ? [-0.9999, 0] : [0.999, 0]
317
+ [Y]: t ? [-0.9999, 0] : [0.999, 0]
297
318
  }, {
298
319
  ...this.flow.opacityTiming,
299
320
  composite: "accumulate"
300
- }), t ? this.flow.removeEventListener("animationsfinish", n(this, M, "f")) : this.flow.addEventListener("animationsfinish", n(this, M, "f"), {
321
+ }), t ? this.flow.removeEventListener("animationsfinish", n(this, j, "f")) : this.flow.addEventListener("animationsfinish", n(this, j, "f"), {
301
322
  once: !0
302
323
  });
303
324
  }
304
325
  }
305
326
  }
306
- W = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap();
307
- class ht extends q {
327
+ L = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap();
328
+ class ht extends et {
308
329
  constructor(t, e, i, s) {
309
330
  super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
310
331
  }
311
332
  }
312
333
  class ct extends ht {
313
- constructor(t, e, i, s) {
314
- const o = Array.from({ length: 10 }).map((l, f) => {
315
- const E = g("span", { className: `digit__num${f === i ? " is-current" : ""}` }, [document.createTextNode(String(f))]);
316
- return E.style.setProperty("--n", String(f)), E;
317
- }), r = g("span", {
334
+ constructor(t, e, i, s, r) {
335
+ const l = Array.from({ length: 10 }).map((p, u) => {
336
+ const m = w("span", { className: `digit__num${u === i ? " is-current" : ""}` }, [document.createTextNode(String(u))]);
337
+ return m.style.setProperty("--n", String(u)), m;
338
+ }), o = w("span", {
318
339
  className: "digit"
319
- }, o);
320
- r.style.setProperty("--current", String(i)), super(t, i, r, s), U.set(this, void 0), u.set(this, void 0), B.set(this, void 0), Z.set(this, () => {
340
+ }, l);
341
+ o.style.setProperty("--current", String(i)), super(t, i, o, r), this.place = s, R.set(this, void 0), v.set(this, void 0), I.set(this, void 0), tt.set(this, () => {
321
342
  this.el.classList.remove("is-spinning");
322
- }), h(this, U, o, "f");
323
- }
324
- get trend() {
325
- const t = this.flow.getComputedTrend();
326
- return t === p.NONE ? rt(this.value, n(this, u, "f")) : t;
343
+ }), h(this, R, l, "f");
327
344
  }
328
345
  willUpdate(t) {
329
346
  const e = this.el.getBoundingClientRect();
330
- h(this, u, this.value, "f");
347
+ h(this, v, this.value, "f");
331
348
  const i = e[this.section.justify] - t[this.section.justify], s = e.width / 2;
332
- h(this, B, this.section.justify === "left" ? i + s : i - s, "f");
349
+ h(this, I, this.section.justify === "left" ? i + s : i - s, "f");
333
350
  }
334
351
  update(t) {
335
352
  var e, i;
336
- (e = n(this, U, "f")[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = n(this, U, "f")[t]) == null || i.classList.add("is-current"), this.value = t;
353
+ (e = n(this, R, "f")[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = n(this, R, "f")[t]) == null || i.classList.add("is-current"), this.value = t;
337
354
  }
338
355
  didUpdate(t) {
339
- const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, o = this.section.justify === "left" ? i + s : i - s;
340
- if (this.el.animate({
341
- transform: [`translateX(${n(this, B, "f") - o}px)`, "none"]
356
+ const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, r = this.section.justify === "left" ? i + s : i - s;
357
+ this.el.animate({
358
+ transform: [`translateX(${n(this, I, "f") - r}px)`, "none"]
342
359
  }, {
343
360
  ...this.flow.transformTiming,
344
361
  composite: "accumulate"
345
- }), this.value === n(this, u, "f"))
346
- return;
347
- const r = this.trend;
348
- let l = this.value - n(this, u, "f");
349
- r === p.DOWN && this.value > n(this, u, "f") && (l = this.value - 10 - n(this, u, "f")), r === p.UP && this.value < n(this, u, "f") && (l = 10 - n(this, u, "f") + this.value), this.el.classList.add("is-spinning"), this.el.animate({
350
- [Q]: [-l, 0]
362
+ });
363
+ const l = this.diff;
364
+ l && (this.el.classList.add("is-spinning"), this.el.animate({
365
+ [st]: [-l, 0]
351
366
  }, {
352
367
  ...this.flow.spinTiming ?? this.flow.transformTiming,
353
368
  composite: "accumulate"
354
- }), this.flow.addEventListener("animationsfinish", n(this, Z, "f"), { once: !0 });
369
+ }), this.flow.addEventListener("animationsfinish", n(this, tt, "f"), { once: !0 }));
370
+ }
371
+ get diff() {
372
+ let t = this.flow.computedTrend;
373
+ const e = this.value - n(this, v, "f");
374
+ return !e && this.flow.startingPlace != null && this.flow.startingPlace >= this.place ? 10 * t : (t || (t = Math.sign(e)), t === b.DOWN && this.value > n(this, v, "f") ? this.value - 10 - n(this, v, "f") : t === b.UP && this.value < n(this, v, "f") ? 10 - n(this, v, "f") + this.value : e);
355
375
  }
356
376
  }
357
- U = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap();
358
- class St extends ht {
377
+ R = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), tt = /* @__PURE__ */ new WeakMap();
378
+ class kt extends ht {
359
379
  constructor(t, e, i, s) {
360
- const o = g("span", {
380
+ const r = w("span", {
361
381
  className: "symbol__value",
362
382
  textContent: i
363
383
  });
364
- super(t, i, g("span", {
384
+ super(t, i, w("span", {
365
385
  className: "symbol"
366
- }, [o]), s), this.type = e, w.set(this, /* @__PURE__ */ new Map()), H.set(this, void 0), V.set(this, (r) => () => {
367
- n(this, w, "f").delete(r);
368
- }), n(this, w, "f").set(i, new q(this.flow, o, {
369
- onRemove: n(this, V, "f").call(this, i)
386
+ }, [r]), s), this.type = e, _.set(this, /* @__PURE__ */ new Map()), G.set(this, void 0), K.set(this, (l) => () => {
387
+ n(this, _, "f").delete(l);
388
+ }), n(this, _, "f").set(i, new et(this.flow, r, {
389
+ onRemove: n(this, K, "f").call(this, i)
370
390
  }));
371
391
  }
372
392
  willUpdate(t) {
373
393
  if (this.type === "decimal")
374
394
  return;
375
395
  const e = this.el.getBoundingClientRect();
376
- h(this, H, e[this.section.justify] - t[this.section.justify], "f");
396
+ h(this, G, e[this.section.justify] - t[this.section.justify], "f");
377
397
  }
378
398
  update(t) {
379
399
  if (this.value !== t) {
380
- const e = n(this, w, "f").get(this.value);
381
- if (e.present = !1, e.el.classList.add("symbol__exiting"), n(this, w, "f").has(t)) {
382
- const i = n(this, w, "f").get(t);
400
+ const e = n(this, _, "f").get(this.value);
401
+ if (e.present = !1, e.el.classList.add("symbol__exiting"), n(this, _, "f").has(t)) {
402
+ const i = n(this, _, "f").get(t);
383
403
  i.present = !0, i.el.classList.remove("symbol__exiting");
384
404
  } else {
385
- const i = g("span", {
405
+ const i = w("span", {
386
406
  className: "symbol__value",
387
407
  textContent: t
388
408
  });
389
- this.el.appendChild(i), n(this, w, "f").set(t, new q(this.flow, i, {
409
+ this.el.appendChild(i), n(this, _, "f").set(t, new et(this.flow, i, {
390
410
  animateIn: !0,
391
- onRemove: n(this, V, "f").call(this, t)
411
+ onRemove: n(this, K, "f").call(this, t)
392
412
  }));
393
413
  }
394
414
  }
@@ -399,18 +419,18 @@ class St extends ht {
399
419
  return;
400
420
  const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
401
421
  this.el.animate({
402
- transform: [`translateX(${n(this, H, "f") - i}px)`, "none"]
422
+ transform: [`translateX(${n(this, G, "f") - i}px)`, "none"]
403
423
  }, { ...this.flow.transformTiming, composite: "accumulate" });
404
424
  }
405
425
  }
406
- w = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap();
426
+ _ = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap();
407
427
  export {
408
- Et as NumberFlowLite,
409
- wt as SlottedTag,
410
- yt as canAnimate,
411
- _t as defaultOpacityTiming,
412
- vt as defaultTransformTiming,
413
- kt as partitionParts,
414
- K as prefersReducedMotion,
415
- $t as slottedStyles
428
+ Nt as NumberFlowLite,
429
+ yt as SlottedTag,
430
+ _t as canAnimate,
431
+ bt as defaultOpacityTiming,
432
+ St as defaultTransformTiming,
433
+ Et as partitionParts,
434
+ J as prefersReducedMotion,
435
+ Mt as slottedStyles
416
436
  };
package/dist/styles.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const supportsLinear: boolean;
1
2
  export declare const supportsMod: boolean;
2
3
  export declare const prefersReducedMotion: MediaQueryList | null;
3
4
  export declare const opacityDeltaVar = "--_number-flow-d-opacity";
@@ -0,0 +1 @@
1
+ export declare const max: (n1?: number, n2?: number) => number | null;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.0",
6
+ "version": "0.3.2",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",