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