number-flow 0.3.8 → 0.3.10

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