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