number-flow 0.3.9 → 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 +16 -1
- package/dist/index.js +7 -7
- package/dist/index.mjs +202 -221
- package/dist/styles.d.ts +0 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,12 @@ export interface Props {
|
|
|
22
22
|
continuous: boolean;
|
|
23
23
|
}
|
|
24
24
|
export declare class NumberFlowLite extends ServerSafeHTMLElement implements Props {
|
|
25
|
-
|
|
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,10 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
2
|
><style>
|
|
3
|
-
${
|
|
4
|
-
>${
|
|
5
|
-
>${
|
|
6
|
-
>${
|
|
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
7
|
><span
|
|
8
|
-
style="font-kerning: none; display: inline-block; line-height: ${
|
|
8
|
+
style="font-kerning: none; display: inline-block; line-height: ${N} !important; padding: ${f} 0;"
|
|
9
9
|
>${s.valueAsString}</span
|
|
10
|
-
>`,Ct=(s,t)=>s!=null&&t==null?s:s==null&&t!=null?t:s!=null&&t!=null?Math.max(s,t):null;var P,R,k,E,M,y,L,T,U,C,I,x,W,z,G,Y,j,q,A,F,v,K,st,_,Z,J;const pt=Et&&kt&&Mt;var b;(function(s){s[s.UP=1]="UP",s[s.DOWN=-1]="DOWN",s[s.NONE=0]="NONE"})(b||(b={}));let V;class ut extends xt{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,P.set(this,this.constructor.defaultProps.animated),R.set(this,!1),k.set(this,void 0),E.set(this,void 0),M.set(this,void 0),y.set(this,void 0),L.set(this,void 0),T.set(this,n(this,P,"f")),U.set(this,void 0),this.manual=!1,C.set(this,void 0)}get animated(){return n(this,P,"f")}set animated(t){var e;this.animated!==t&&(c(this,P,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}get created(){return n(this,R,"f")}get computedTrend(){return n(this,y,"f")}get startingPlace(){return n(this,L,"f")}get computedAnimated(){return n(this,T,"f")}set data(t){if(t==null)return;const{pre:e,integer:i,fraction:a,post:l,value:r}=t;if(n(this,R,"f")){const o=n(this,U,"f");if(c(this,U,t,"f"),this.trend===!0?c(this,y,Math.sign(r-o.value),"f"):this.trend==="increasing"?c(this,y,b.UP,"f"):this.trend==="decreasing"?c(this,y,b.DOWN,"f"):c(this,y,b.NONE,"f"),c(this,L,void 0,"f"),n(this,y,"f")!==b.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(w=>w.place===d.place&&w.value===d.value)),N=u.find(d=>!m.find(w=>d.place===w.place&&d.value===w.value));c(this,L,Ct(p==null?void 0:p.place,N==null?void 0:N.place),"f")}c(this,T,pt&&n(this,P,"f")&&(!this.respectMotionPreference||!(H!=null&&H.matches))&&vt(this),"f"),this.manual||this.willUpdate(),n(this,k,"f").update(e),n(this,E,"f").update({integer:i,fraction:a}),n(this,M,"f").update(l),this.manual||this.didUpdate()}else{if(c(this,U,t,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)V||(V=new CSSStyleSheet,V.replaceSync(ct)),this.shadowRoot.adoptedStyleSheets=[V];else{const o=document.createElement("style");o.textContent=ct,this.shadowRoot.appendChild(o)}c(this,k,new ft(this,e,{justify:"right",part:"left"}),"f"),this.shadowRoot.appendChild(n(this,k,"f").el),c(this,E,new Rt(this,i,a),"f"),this.shadowRoot.appendChild(n(this,E,"f").el),c(this,M,new ft(this,l,{justify:"left",part:"right"}),"f"),this.shadowRoot.appendChild(n(this,M,"f").el)}c(this,R,!0,"f")}willUpdate(){n(this,k,"f").willUpdate(),n(this,E,"f").willUpdate(),n(this,M,"f").willUpdate()}didUpdate(){if(!n(this,T,"f"))return;n(this,C,"f")?n(this,C,"f").abort():this.dispatchEvent(new Event("animationsstart")),n(this,k,"f").didUpdate(),n(this,E,"f").didUpdate(),n(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")),c(this,C,void 0,"f"))}),c(this,C,t,"f")}}P=new WeakMap,R=new WeakMap,k=new WeakMap,E=new WeakMap,M=new WeakMap,y=new WeakMap,L=new WeakMap,T=new WeakMap,U=new WeakMap,C=new WeakMap;ut.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 Rt{constructor(t,e,i,{className:a,...l}={}){this.flow=t,I.set(this,void 0),x.set(this,void 0),W.set(this,void 0),z.set(this,void 0),G.set(this,void 0),c(this,x,new ht(t,e,{justify:"right",part:"integer"}),"f"),c(this,W,new ht(t,i,{justify:"left",part:"fraction"}),"f"),c(this,I,S("span",{className:"number__inner"},[n(this,x,"f").el,n(this,W,"f").el]),"f"),this.el=S("span",{...l,part:"number",className:`number ${a??""}`},[n(this,I,"f")])}willUpdate(){c(this,z,this.el.offsetWidth,"f"),c(this,G,this.el.getBoundingClientRect().left,"f"),n(this,x,"f").willUpdate(),n(this,W,"f").willUpdate()}update({integer:t,fraction:e}){n(this,x,"f").update(t),n(this,W,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();n(this,x,"f").didUpdate(),n(this,W,"f").didUpdate();const e=n(this,G,"f")-t.left,i=this.el.offsetWidth,a=n(this,z,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[tt]:[`${e}px`,"0px"],[at]:[a,0]},{...this.flow.transformTiming,composite:"accumulate"})}}I=new WeakMap,x=new WeakMap,W=new WeakMap,z=new WeakMap,G=new WeakMap;class mt{constructor(t,e,{justify:i,className:a,...l},r){this.flow=t,this.children=new Map,this.onCharRemove=m=>()=>{this.children.delete(m)},Y.set(this,void 0),this.justify=i;const o=e.map(m=>this.addChar(m).el);this.el=S("span",{...l,className:`section section--justify-${i} ${a??""}`},r?r(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const a=t.type==="integer"||t.type==="fraction"?new wt(this,t.type,e?0:t.value,t.place,{...i,onRemove:this.onCharRemove(t.key)}):new Lt(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,a),a}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]=`${yt(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,a=this.justify==="left",l=a?"prepend":"append";if(bt(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:a}),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();c(this,Y,t[this.justify],"f"),this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(a=>a.didUpdate(t));const e=t[this.justify],i=n(this,Y,"f")-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}Y=new WeakMap;class ht extends mt{update(t){const e=new Map;this.children.forEach((i,a)=>{t.find(l=>l.key===a)||e.set(a,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof wt&&i.update(0)}),this.pop(e)}}class ft extends mt{update(t){const e=new Map;this.children.forEach((i,a)=>{t.find(l=>l.key===a)||e.set(a,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class nt{constructor(t,e,{onRemove:i,animateIn:a=!1}={}){this.flow=t,this.el=e,j.set(this,!0),q.set(this,void 0),A.set(this,()=>{var l;this.el.remove(),(l=n(this,q,"f"))==null||l.call(this)}),this.el.classList.add("animate-presence"),this.flow.computedAnimated&&a&&this.el.animate({[Q]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),c(this,q,i,"f")}get present(){return n(this,j,"f")}set present(t){if(n(this,j,"f")!==t){if(c(this,j,t,"f"),!this.flow.computedAnimated){t||n(this,A,"f").call(this);return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[Q]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",n(this,A,"f")):this.flow.addEventListener("animationsfinish",n(this,A,"f"),{once:!0})}}}j=new WeakMap,q=new WeakMap,A=new WeakMap;class gt extends nt{constructor(t,e,i,a){super(t.flow,i,a),this.section=t,this.value=e,this.el=i}}class wt extends gt{constructor(t,e,i,a,l){const r=Array.from({length:10}).map((m,u)=>{const p=S("span",{className:`digit__num${u===i?" is-current":""}`},[document.createTextNode(String(u))]);return p.style.setProperty("--n",String(u)),p}),o=S("span",{part:`digit ${e}-digit`,className:"digit"},r);o.style.setProperty("--current",String(i)),super(t,i,o,l),this.place=a,F.set(this,void 0),v.set(this,void 0),K.set(this,void 0),st.set(this,()=>{this.el.classList.remove("is-spinning")}),c(this,F,r,"f")}willUpdate(t){const e=this.el.getBoundingClientRect();c(this,v,this.value,"f");const i=e[this.section.justify]-t[this.section.justify],a=e.width/2;c(this,K,this.section.justify==="left"?i+a:i-a,"f")}update(t){var e,i;(e=n(this,F,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=n(this,F,"f")[t])==null||i.classList.add("is-current"),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],a=e.width/2,l=this.section.justify==="left"?i+a:i-a,r=n(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",n(this,st,"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)}}F=new WeakMap,v=new WeakMap,K=new WeakMap,st=new WeakMap;class Lt extends gt{constructor(t,e,i,a){const l=S("span",{className:"symbol__value",textContent:i});super(t,i,S("span",{part:e,className:"symbol"},[l]),a),this.type=e,_.set(this,new Map),Z.set(this,void 0),J.set(this,r=>()=>{n(this,_,"f").delete(r)}),n(this,_,"f").set(i,new nt(this.flow,l,{onRemove:n(this,J,"f").call(this,i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();c(this,Z,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=S("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),n(this,_,"f").set(t,new nt(this.flow,i,{animateIn:!0,onRemove:n(this,J,"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],a=n(this,Z,"f")-i;a&&this.el.animate({transform:[`translateX(${a}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}_=new WeakMap,Z=new WeakMap,J=new WeakMap;exports.NumberFlowLite=ut;exports.canAnimate=pt;exports.define=_t;exports.formatToData=St;exports.prefersReducedMotion=H;exports.renderInnerHTML=Pt;
|
|
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,89 +1,78 @@
|
|
|
1
|
-
import { BROWSER as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
function h(s, t, e, i, a) {
|
|
8
|
-
if (i === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (i === "a" && !a) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof t == "function" ? s !== t || !a : !t.has(s)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return i === "a" ? a.call(s, e) : a ? a.value = e : t.set(s, e), e;
|
|
12
|
-
}
|
|
13
|
-
const S = (s, t, e) => {
|
|
14
|
-
const i = document.createElement(s), [a, l] = Array.isArray(t) ? [void 0, t] : [t, e];
|
|
15
|
-
return a && Object.assign(i, a), l == null || l.forEach((r) => i.appendChild(r)), i;
|
|
16
|
-
}, gt = (s, 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) => {
|
|
17
6
|
var e;
|
|
18
7
|
return t === "left" ? s.offsetLeft : (((e = s.offsetParent instanceof HTMLElement ? s.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - s.offsetWidth - s.offsetLeft;
|
|
19
|
-
},
|
|
20
|
-
if (!(!
|
|
8
|
+
}, H = (s) => s.offsetWidth > 0 && s.offsetHeight > 0, nt = (s, t) => {
|
|
9
|
+
if (!(!v || customElements.get(s) === t))
|
|
21
10
|
return customElements.define(s, t);
|
|
22
11
|
};
|
|
23
|
-
function
|
|
12
|
+
function X(s, t, { reverse: e = !1 } = {}) {
|
|
24
13
|
const i = s.length;
|
|
25
|
-
for (let
|
|
26
|
-
t(s[
|
|
14
|
+
for (let n = e ? i - 1 : 0; e ? n >= 0 : n < i; e ? n-- : n++)
|
|
15
|
+
t(s[n], n);
|
|
27
16
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
e &&
|
|
31
|
-
const
|
|
32
|
-
let
|
|
33
|
-
for (const
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
type:
|
|
38
|
-
value: parseInt(
|
|
39
|
-
key:
|
|
40
|
-
place: -1 -
|
|
41
|
-
}))) : (
|
|
42
|
-
type:
|
|
43
|
-
value:
|
|
44
|
-
key:
|
|
17
|
+
function at(s, t, e, i) {
|
|
18
|
+
const n = t.formatToParts(s);
|
|
19
|
+
e && n.unshift({ type: "prefix", value: e }), i && n.push({ type: "suffix", value: i });
|
|
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)
|
|
45
34
|
});
|
|
46
35
|
}
|
|
47
|
-
const
|
|
48
|
-
for (let
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
...
|
|
52
|
-
key:
|
|
53
|
-
place:
|
|
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]
|
|
54
43
|
} : {
|
|
55
|
-
...
|
|
56
|
-
key:
|
|
44
|
+
...l,
|
|
45
|
+
key: d(l.type)
|
|
57
46
|
});
|
|
58
47
|
}
|
|
59
48
|
return {
|
|
60
|
-
pre:
|
|
61
|
-
integer:
|
|
62
|
-
fraction:
|
|
63
|
-
post:
|
|
64
|
-
valueAsString:
|
|
49
|
+
pre: r,
|
|
50
|
+
integer: j,
|
|
51
|
+
fraction: a,
|
|
52
|
+
post: u,
|
|
53
|
+
valueAsString: w,
|
|
65
54
|
value: typeof s == "string" ? parseFloat(s) : s
|
|
66
55
|
};
|
|
67
56
|
}
|
|
68
|
-
const
|
|
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 = (() => {
|
|
69
58
|
try {
|
|
70
59
|
return CSS.registerProperty({
|
|
71
|
-
name:
|
|
60
|
+
name: C,
|
|
72
61
|
syntax: "<number>",
|
|
73
62
|
inherits: !1,
|
|
74
63
|
initialValue: "0"
|
|
75
64
|
}), CSS.registerProperty({
|
|
76
|
-
name:
|
|
65
|
+
name: E,
|
|
77
66
|
syntax: "<length>",
|
|
78
67
|
inherits: !0,
|
|
79
68
|
initialValue: "0px"
|
|
80
69
|
}), CSS.registerProperty({
|
|
81
|
-
name:
|
|
70
|
+
name: A,
|
|
82
71
|
syntax: "<number>",
|
|
83
72
|
inherits: !1,
|
|
84
73
|
initialValue: "0"
|
|
85
74
|
}), CSS.registerProperty({
|
|
86
|
-
name:
|
|
75
|
+
name: T,
|
|
87
76
|
syntax: "<number>",
|
|
88
77
|
inherits: !0,
|
|
89
78
|
initialValue: "0"
|
|
@@ -91,94 +80,91 @@ const vt = String.raw, dt = String.raw, _t = D && typeof CSS < "u" && CSS.suppor
|
|
|
91
80
|
} catch {
|
|
92
81
|
return !1;
|
|
93
82
|
}
|
|
94
|
-
})(),
|
|
95
|
-
},
|
|
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) => (
|
|
96
85
|
// shadowroot="open" non-standard attribute for old Chrome:
|
|
97
|
-
|
|
86
|
+
I`<template shadowroot="open" shadowrootmode="open"
|
|
98
87
|
><style>
|
|
99
|
-
${
|
|
100
|
-
>${
|
|
101
|
-
>${
|
|
102
|
-
>${
|
|
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
|
|
103
92
|
><span
|
|
104
|
-
style="font-kerning: none; display: inline-block; line-height: ${
|
|
93
|
+
style="font-kerning: none; display: inline-block; line-height: ${N} !important; padding: ${f} 0;"
|
|
105
94
|
>${s.valueAsString}</span
|
|
106
95
|
>`
|
|
107
|
-
),
|
|
108
|
-
var
|
|
109
|
-
const Mt = bt && _t && St;
|
|
110
|
-
var b;
|
|
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;
|
|
111
98
|
(function(s) {
|
|
112
99
|
s[s.UP = 1] = "UP", s[s.DOWN = -1] = "DOWN", s[s.NONE = 0] = "NONE";
|
|
113
|
-
})(
|
|
114
|
-
let
|
|
115
|
-
class
|
|
100
|
+
})(g || (g = {}));
|
|
101
|
+
let S;
|
|
102
|
+
class tt extends K {
|
|
116
103
|
constructor() {
|
|
117
|
-
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,
|
|
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;
|
|
118
105
|
}
|
|
119
106
|
get animated() {
|
|
120
|
-
return
|
|
107
|
+
return this._animated;
|
|
121
108
|
}
|
|
122
109
|
set animated(t) {
|
|
123
110
|
var e;
|
|
124
|
-
this.animated !== t && (
|
|
111
|
+
this.animated !== t && (this._animated = t, (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
|
|
125
112
|
}
|
|
126
113
|
get created() {
|
|
127
|
-
return
|
|
114
|
+
return this._created;
|
|
128
115
|
}
|
|
129
116
|
get computedTrend() {
|
|
130
|
-
return
|
|
117
|
+
return this._computedTrend;
|
|
131
118
|
}
|
|
132
119
|
get startingPlace() {
|
|
133
|
-
return
|
|
120
|
+
return this._startingPlace;
|
|
134
121
|
}
|
|
135
122
|
get computedAnimated() {
|
|
136
|
-
return
|
|
123
|
+
return this._computedAnimated;
|
|
137
124
|
}
|
|
138
125
|
set data(t) {
|
|
139
126
|
if (t == null)
|
|
140
127
|
return;
|
|
141
|
-
const { pre: e, integer: i, fraction:
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
145
|
-
const
|
|
146
|
-
|
|
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);
|
|
147
134
|
}
|
|
148
|
-
|
|
149
|
-
|
|
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();
|
|
150
137
|
} else {
|
|
151
|
-
if (
|
|
152
|
-
|
|
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];
|
|
153
140
|
else {
|
|
154
|
-
const
|
|
155
|
-
|
|
141
|
+
const a = document.createElement("style");
|
|
142
|
+
a.textContent = L, this.shadowRoot.appendChild(a);
|
|
156
143
|
}
|
|
157
|
-
|
|
144
|
+
this._pre = new W(this, e, {
|
|
158
145
|
justify: "right",
|
|
159
146
|
part: "left"
|
|
160
|
-
}),
|
|
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, {
|
|
161
148
|
justify: "left",
|
|
162
149
|
part: "right"
|
|
163
|
-
}),
|
|
150
|
+
}), this.shadowRoot.appendChild(this._post.el);
|
|
164
151
|
}
|
|
165
|
-
|
|
152
|
+
this._created = !0;
|
|
166
153
|
}
|
|
167
154
|
willUpdate() {
|
|
168
|
-
|
|
155
|
+
this._pre.willUpdate(), this._num.willUpdate(), this._post.willUpdate();
|
|
169
156
|
}
|
|
170
157
|
didUpdate() {
|
|
171
|
-
if (!
|
|
158
|
+
if (!this._computedAnimated)
|
|
172
159
|
return;
|
|
173
|
-
|
|
160
|
+
this._abortAnimationsFinish ? this._abortAnimationsFinish.abort() : this.dispatchEvent(new Event("animationsstart")), this._pre.didUpdate(), this._num.didUpdate(), this._post.didUpdate();
|
|
174
161
|
const t = new AbortController();
|
|
175
162
|
Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
|
|
176
|
-
t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")),
|
|
177
|
-
}),
|
|
163
|
+
t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), this._abortAnimationsFinish = void 0);
|
|
164
|
+
}), this._abortAnimationsFinish = t;
|
|
178
165
|
}
|
|
179
166
|
}
|
|
180
|
-
|
|
181
|
-
Nt.defaultProps = {
|
|
167
|
+
tt.defaultProps = {
|
|
182
168
|
transformTiming: {
|
|
183
169
|
duration: 900,
|
|
184
170
|
// Make sure to keep this minified:
|
|
@@ -191,98 +177,97 @@ Nt.defaultProps = {
|
|
|
191
177
|
continuous: !1,
|
|
192
178
|
respectMotionPreference: !0
|
|
193
179
|
};
|
|
194
|
-
class
|
|
195
|
-
constructor(t, e, i, { className:
|
|
196
|
-
this.flow = t,
|
|
180
|
+
class et {
|
|
181
|
+
constructor(t, e, i, { className: n, ...r } = {}) {
|
|
182
|
+
this.flow = t, this._integer = new M(t, e, {
|
|
197
183
|
justify: "right",
|
|
198
184
|
part: "integer"
|
|
199
|
-
}),
|
|
185
|
+
}), this._fraction = new M(t, i, {
|
|
200
186
|
justify: "left",
|
|
201
187
|
part: "fraction"
|
|
202
|
-
}),
|
|
188
|
+
}), this._inner = y("span", {
|
|
203
189
|
className: "number__inner"
|
|
204
|
-
}, [
|
|
205
|
-
...
|
|
190
|
+
}, [this._integer.el, this._fraction.el]), this.el = y("span", {
|
|
191
|
+
...r,
|
|
206
192
|
part: "number",
|
|
207
|
-
className: `number ${
|
|
208
|
-
}, [
|
|
193
|
+
className: `number ${n ?? ""}`
|
|
194
|
+
}, [this._inner]);
|
|
209
195
|
}
|
|
210
196
|
willUpdate() {
|
|
211
|
-
|
|
197
|
+
this._prevWidth = this.el.offsetWidth, this._prevLeft = this.el.getBoundingClientRect().left, this._integer.willUpdate(), this._fraction.willUpdate();
|
|
212
198
|
}
|
|
213
199
|
update({ integer: t, fraction: e }) {
|
|
214
|
-
|
|
200
|
+
this._integer.update(t), this._fraction.update(e);
|
|
215
201
|
}
|
|
216
202
|
didUpdate() {
|
|
217
203
|
const t = this.el.getBoundingClientRect();
|
|
218
|
-
|
|
219
|
-
const e =
|
|
204
|
+
this._integer.didUpdate(), this._fraction.didUpdate();
|
|
205
|
+
const e = this._prevLeft - t.left, i = this.el.offsetWidth, n = this._prevWidth - i;
|
|
220
206
|
this.el.style.setProperty("--width", String(i)), this.el.animate({
|
|
221
|
-
[
|
|
222
|
-
[
|
|
207
|
+
[E]: [`${e}px`, "0px"],
|
|
208
|
+
[A]: [n, 0]
|
|
223
209
|
}, {
|
|
224
210
|
...this.flow.transformTiming,
|
|
225
211
|
composite: "accumulate"
|
|
226
212
|
});
|
|
227
213
|
}
|
|
228
214
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}, r ? r(o) : o);
|
|
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,
|
|
223
|
+
className: `section section--justify-${i} ${n ?? ""}`
|
|
224
|
+
}, o ? o(a) : a);
|
|
240
225
|
}
|
|
241
226
|
addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
|
|
242
|
-
const
|
|
227
|
+
const n = t.type === "integer" || t.type === "fraction" ? new D(this, t.type, e ? 0 : t.value, t.place, {
|
|
243
228
|
...i,
|
|
244
229
|
onRemove: this.onCharRemove(t.key)
|
|
245
|
-
}) : new
|
|
230
|
+
}) : new it(this, t.type, t.value, {
|
|
246
231
|
...i,
|
|
247
232
|
onRemove: this.onCharRemove(t.key)
|
|
248
233
|
});
|
|
249
|
-
return this.children.set(t.key,
|
|
234
|
+
return this.children.set(t.key, n), n;
|
|
250
235
|
}
|
|
251
236
|
unpop(t) {
|
|
252
237
|
t.el.classList.remove("section__exiting"), t.el.style.top = "", t.el.style[this.justify] = "";
|
|
253
238
|
}
|
|
254
239
|
pop(t) {
|
|
255
240
|
t.forEach((e) => {
|
|
256
|
-
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${
|
|
241
|
+
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${F(e.el, this.justify)}px`;
|
|
257
242
|
}), t.forEach((e) => {
|
|
258
243
|
e.el.classList.add("section__exiting"), e.present = !1;
|
|
259
244
|
});
|
|
260
245
|
}
|
|
261
246
|
addNewAndUpdateExisting(t) {
|
|
262
|
-
const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(),
|
|
263
|
-
if (
|
|
264
|
-
let
|
|
265
|
-
this.children.has(
|
|
266
|
-
}, { reverse:
|
|
267
|
-
const
|
|
268
|
-
e.forEach((
|
|
269
|
-
|
|
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);
|
|
251
|
+
}, { reverse: n }), this.flow.computedAnimated) {
|
|
252
|
+
const o = this.el.getBoundingClientRect();
|
|
253
|
+
e.forEach((a) => {
|
|
254
|
+
a.willUpdate(o);
|
|
270
255
|
});
|
|
271
256
|
}
|
|
272
|
-
e.forEach((
|
|
273
|
-
|
|
274
|
-
}), i.forEach((
|
|
275
|
-
|
|
257
|
+
e.forEach((o, a) => {
|
|
258
|
+
o.update(a.value);
|
|
259
|
+
}), i.forEach((o, a) => {
|
|
260
|
+
o.update(a.value);
|
|
276
261
|
});
|
|
277
262
|
}
|
|
278
263
|
willUpdate() {
|
|
279
264
|
const t = this.el.getBoundingClientRect();
|
|
280
|
-
|
|
265
|
+
this._prevOffset = t[this.justify], this.children.forEach((e) => e.willUpdate(t));
|
|
281
266
|
}
|
|
282
267
|
didUpdate() {
|
|
283
268
|
const t = this.el.getBoundingClientRect();
|
|
284
|
-
this.children.forEach((
|
|
285
|
-
const e = t[this.justify], i =
|
|
269
|
+
this.children.forEach((n) => n.didUpdate(t));
|
|
270
|
+
const e = t[this.justify], i = this._prevOffset - e;
|
|
286
271
|
i && this.children.size && this.el.animate({
|
|
287
272
|
transform: [`translateX(${i}px)`, "none"]
|
|
288
273
|
}, {
|
|
@@ -291,144 +276,141 @@ class pt {
|
|
|
291
276
|
});
|
|
292
277
|
}
|
|
293
278
|
}
|
|
294
|
-
|
|
295
|
-
class ct extends pt {
|
|
279
|
+
class M extends O {
|
|
296
280
|
update(t) {
|
|
297
281
|
const e = /* @__PURE__ */ new Map();
|
|
298
|
-
this.children.forEach((i,
|
|
299
|
-
t.find((
|
|
282
|
+
this.children.forEach((i, n) => {
|
|
283
|
+
t.find((r) => r.key === n) || e.set(n, i), this.unpop(i);
|
|
300
284
|
}), this.addNewAndUpdateExisting(t), e.forEach((i) => {
|
|
301
|
-
i instanceof
|
|
285
|
+
i instanceof D && i.update(0);
|
|
302
286
|
}), this.pop(e);
|
|
303
287
|
}
|
|
304
288
|
}
|
|
305
|
-
class
|
|
289
|
+
class W extends O {
|
|
306
290
|
update(t) {
|
|
307
291
|
const e = /* @__PURE__ */ new Map();
|
|
308
|
-
this.children.forEach((i,
|
|
309
|
-
t.find((
|
|
292
|
+
this.children.forEach((i, n) => {
|
|
293
|
+
t.find((r) => r.key === n) || e.set(n, i);
|
|
310
294
|
}), this.pop(e), this.addNewAndUpdateExisting(t);
|
|
311
295
|
}
|
|
312
296
|
}
|
|
313
|
-
class
|
|
314
|
-
constructor(t, e, { onRemove: i, animateIn:
|
|
315
|
-
this.flow = t, this.el = e,
|
|
316
|
-
var
|
|
317
|
-
this.el.remove(), (
|
|
318
|
-
}
|
|
319
|
-
[
|
|
297
|
+
class U {
|
|
298
|
+
constructor(t, e, { onRemove: i, animateIn: n = !1 } = {}) {
|
|
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]
|
|
320
304
|
}, {
|
|
321
305
|
...this.flow.opacityTiming,
|
|
322
306
|
composite: "accumulate"
|
|
323
|
-
}),
|
|
307
|
+
}), this._onRemove = i;
|
|
324
308
|
}
|
|
325
309
|
get present() {
|
|
326
|
-
return
|
|
310
|
+
return this._present;
|
|
327
311
|
}
|
|
328
312
|
set present(t) {
|
|
329
|
-
if (
|
|
330
|
-
if (
|
|
331
|
-
t ||
|
|
313
|
+
if (this._present !== t) {
|
|
314
|
+
if (this._present = t, !this.flow.computedAnimated) {
|
|
315
|
+
t || this._remove();
|
|
332
316
|
return;
|
|
333
317
|
}
|
|
334
318
|
this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
|
|
335
|
-
[
|
|
319
|
+
[C]: t ? [-0.9999, 0] : [0.999, 0]
|
|
336
320
|
}, {
|
|
337
321
|
...this.flow.opacityTiming,
|
|
338
322
|
composite: "accumulate"
|
|
339
|
-
}), t ? this.flow.removeEventListener("animationsfinish",
|
|
323
|
+
}), t ? this.flow.removeEventListener("animationsfinish", this._remove) : this.flow.addEventListener("animationsfinish", this._remove, {
|
|
340
324
|
once: !0
|
|
341
325
|
});
|
|
342
326
|
}
|
|
343
327
|
}
|
|
344
328
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
super(t.flow, i, a), this.section = t, this.value = e, this.el = i;
|
|
329
|
+
class B extends U {
|
|
330
|
+
constructor(t, e, i, n) {
|
|
331
|
+
super(t.flow, i, n), this.section = t, this.value = e, this.el = i;
|
|
349
332
|
}
|
|
350
333
|
}
|
|
351
|
-
class
|
|
352
|
-
constructor(t, e, i,
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
return
|
|
356
|
-
}),
|
|
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", {
|
|
357
340
|
part: `digit ${e}-digit`,
|
|
358
341
|
className: "digit"
|
|
359
|
-
},
|
|
360
|
-
|
|
342
|
+
}, o);
|
|
343
|
+
a.style.setProperty("--current", String(i)), super(t, i, a, r), this.place = n, this._onAnimationsFinish = () => {
|
|
361
344
|
this.el.classList.remove("is-spinning");
|
|
362
|
-
}
|
|
345
|
+
}, this._numbers = o;
|
|
363
346
|
}
|
|
364
347
|
willUpdate(t) {
|
|
365
348
|
const e = this.el.getBoundingClientRect();
|
|
366
|
-
|
|
367
|
-
const i = e[this.section.justify] - t[this.section.justify],
|
|
368
|
-
|
|
349
|
+
this._prevValue = this.value;
|
|
350
|
+
const i = e[this.section.justify] - t[this.section.justify], n = e.width / 2;
|
|
351
|
+
this._prevCenter = this.section.justify === "left" ? i + n : i - n;
|
|
369
352
|
}
|
|
370
353
|
update(t) {
|
|
371
354
|
var e, i;
|
|
372
|
-
(e =
|
|
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;
|
|
373
356
|
}
|
|
374
357
|
didUpdate(t) {
|
|
375
|
-
const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify],
|
|
376
|
-
|
|
377
|
-
transform: [`translateX(${
|
|
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"]
|
|
378
361
|
}, {
|
|
379
362
|
...this.flow.transformTiming,
|
|
380
363
|
composite: "accumulate"
|
|
381
364
|
});
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
[
|
|
365
|
+
const a = this.diff;
|
|
366
|
+
a && (this.el.classList.add("is-spinning"), this.el.animate({
|
|
367
|
+
[T]: [-a, 0]
|
|
385
368
|
}, {
|
|
386
369
|
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
387
370
|
composite: "accumulate"
|
|
388
|
-
}), this.flow.addEventListener("animationsfinish",
|
|
371
|
+
}), this.flow.addEventListener("animationsfinish", this._onAnimationsFinish, { once: !0 }));
|
|
389
372
|
}
|
|
390
373
|
get diff() {
|
|
391
374
|
let t = this.flow.computedTrend;
|
|
392
|
-
const e = this.value -
|
|
393
|
-
return !e && this.flow.startingPlace != null && this.flow.startingPlace >= this.place ? 10 * t : (t || (t = Math.sign(e)), t ===
|
|
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);
|
|
394
377
|
}
|
|
395
378
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const l = S("span", {
|
|
379
|
+
class it extends B {
|
|
380
|
+
constructor(t, e, i, n) {
|
|
381
|
+
const r = y("span", {
|
|
400
382
|
className: "symbol__value",
|
|
401
383
|
textContent: i
|
|
402
384
|
});
|
|
403
|
-
super(t, i,
|
|
385
|
+
super(t, i, y("span", {
|
|
404
386
|
part: e,
|
|
405
387
|
className: "symbol"
|
|
406
|
-
}, [
|
|
407
|
-
|
|
408
|
-
}
|
|
409
|
-
onRemove:
|
|
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)
|
|
410
392
|
}));
|
|
411
393
|
}
|
|
412
394
|
willUpdate(t) {
|
|
413
395
|
if (this.type === "decimal")
|
|
414
396
|
return;
|
|
415
397
|
const e = this.el.getBoundingClientRect();
|
|
416
|
-
|
|
398
|
+
this._prevOffset = e[this.section.justify] - t[this.section.justify];
|
|
417
399
|
}
|
|
418
400
|
update(t) {
|
|
419
401
|
if (this.value !== t) {
|
|
420
|
-
const e =
|
|
421
|
-
if (e.present = !1, e.el.classList.add("symbol__exiting"),
|
|
422
|
-
const i =
|
|
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);
|
|
423
405
|
i.present = !0, i.el.classList.remove("symbol__exiting");
|
|
424
406
|
} else {
|
|
425
|
-
const i =
|
|
407
|
+
const i = y("span", {
|
|
426
408
|
className: "symbol__value",
|
|
427
409
|
textContent: t
|
|
428
410
|
});
|
|
429
|
-
this.el.appendChild(i),
|
|
411
|
+
this.el.appendChild(i), this._children.set(t, new U(this.flow, i, {
|
|
430
412
|
animateIn: !0,
|
|
431
|
-
onRemove:
|
|
413
|
+
onRemove: this._onChildRemove(t)
|
|
432
414
|
}));
|
|
433
415
|
}
|
|
434
416
|
}
|
|
@@ -437,18 +419,17 @@ class Wt extends ut {
|
|
|
437
419
|
didUpdate(t) {
|
|
438
420
|
if (this.type === "decimal")
|
|
439
421
|
return;
|
|
440
|
-
const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify],
|
|
441
|
-
|
|
442
|
-
transform: [`translateX(${
|
|
422
|
+
const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify], n = this._prevOffset - i;
|
|
423
|
+
n && this.el.animate({
|
|
424
|
+
transform: [`translateX(${n}px)`, "none"]
|
|
443
425
|
}, { ...this.flow.transformTiming, composite: "accumulate" });
|
|
444
426
|
}
|
|
445
427
|
}
|
|
446
|
-
_ = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap();
|
|
447
428
|
export {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
429
|
+
tt as NumberFlowLite,
|
|
430
|
+
Q as canAnimate,
|
|
431
|
+
nt as define,
|
|
432
|
+
at as formatToData,
|
|
433
|
+
k as prefersReducedMotion,
|
|
434
|
+
ot as renderInnerHTML
|
|
454
435
|
};
|
package/dist/styles.d.ts
CHANGED
|
@@ -9,6 +9,5 @@ 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
11
|
export declare const halfMaskHeight = "calc(var(--number-flow-mask-height, 0.25em) / 2)";
|
|
12
|
-
export declare const SlottedTag = "span";
|
|
13
12
|
declare const styles: string;
|
|
14
13
|
export default styles;
|