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