number-flow 0.2.1 → 0.2.2
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 +0 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +77 -76
- package/dist/styles.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,6 @@ import { type PartitionedParts } from './formatter';
|
|
|
2
2
|
import { ServerSafeHTMLElement } from './ssr';
|
|
3
3
|
export { SlottedTag, slottedStyles, supportsAnimationComposition, supportsLinear } from './styles';
|
|
4
4
|
export * from './formatter';
|
|
5
|
-
export declare const defaultXTimingLinearDuration = 900;
|
|
6
|
-
export declare const defaultXTimingLinearPoints: number[];
|
|
7
|
-
export declare const defaultXTimingFallbackDuration = 900;
|
|
8
|
-
export declare const defaultXTimingFallbackPoints: number[];
|
|
9
5
|
export declare const defaultFadeTiming: EffectTiming;
|
|
10
6
|
export declare const defaultXTiming: EffectTiming;
|
|
11
7
|
export declare const defaultYTiming: EffectTiming;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var St=Object.defineProperty;var et=n=>{throw TypeError(n)};var kt=(n,i,t)=>i in n?St(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>kt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},Ct=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},vt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function $t(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Rt(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",b=!1,T=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(b=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(T=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(b||T?l:s).push({type:m,value:p.value,key:c(m)})}const x=[];for(let p=e.length-1;p>=0;p--)x.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:x,fraction:a,post:l,formatted:d}}const jt=V.BROWSER?HTMLElement:class{},Tt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.15em)",E="var(--number-flow-mask-width, 0.5em)",G=`${E} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",Et={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=Tt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;function Ut(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function Mt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt=900,ut=[0,.0050235113985758065,.018768235438646315,.0394665067267097,.06561435806809059,.09593671402266707,.12935688367555642,.16496984329827014,.2020188582086,.2398750451603972,.2780195227408494,.316027838175776,.35355639522427323,.3903306400002338,.42613479005042487,.4608029172568362,.494211217479539,.5262713196397582,.5569245044497536,.5861367184830215,.6138942829733466,.6402002088371546,.6650710401106178,.688534157441182,.7106254816148533,.7313875244620506,.7508677409782638,.7691171422207626,.7861891335875677,.8021385475282429,.8170208436473976,.830891452602792,.8438052432253264,.8558160949464902,.8669765599529741,.8773376015362415,.8869483969005642,.8958561942662493,.9041062154819053,.9117415965639958,.9188033596342844,.9253304106443357,.9313595580771787,.9369255485137984,.9420611155589194,.9467970391476751,.9511622127120402,.9551837160819846,.9588868923388109,.9622954271337615,.9654314292396703,.9683155113223428,.9709668701061009,.9734033652684989,.9756415965361696,.9776969785701735,.9795838133278193,.9813153596710892,.9829039000616127,.9843608042404175,.985696589839041,.986920979908387,.9880429573842098,.989070816534304,.990012211453356,.9908742016877166,.9916632950848158,.9923854879711473,.9930463027692117,.9936508231680027,.994203726963899,.9947093166895601,.9951715481478591,.9955940569663103,.9959801832850321,.9963329946882337,.9966553074856583,.9969497064465007,.9972185630841328,.9974640525856172,.9976881694755444,.9978927420992383,.9980794460059083,.998249816307907,.9984052590879293,.998547061921768,.9986764035801687,.9987943629693811,.9989019273662413,1],mt=900,gt=[.32,.72,0,1],yt={duration:500,easing:"ease-out"},tt=ct?{duration:pt,easing:`linear(${ut.join(",")})`}:{duration:mt,easing:`cubic-bezier(${gt.join(",")})`},wt=tt;let q;var U,_,S,k,C;class At extends jt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",wt);u(this,"fadeTiming",yt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,_);r(this,S);r(this,k);r(this,C)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,_).update(s),o(this,S).update(e),o(this,k).update(a),o(this,C).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,_,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,_).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,k,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,k).el),h(this,C,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,_).willUpdate(t),o(this,S).willUpdate(t),o(this,k).willUpdate(t),o(this,C).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,_).didUpdate(t),o(this,S).didUpdate(t),o(this,k).didUpdate(t),o(this,C).didUpdate(t)}}U=new WeakMap,_=new WeakMap,S=new WeakMap,k=new WeakMap,C=new WeakMap;class bt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new _t(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Bt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${vt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";$t(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var v,M,A,B,L,N;class lt extends bt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,v);r(this,M);r(this,A);r(this,B);r(this,L);r(this,N);h(this,v,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,v).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,v)),s.forEach(e=>{e instanceof _t&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,b,T;(c=o(this,B))==null||c.cancel(),(d=o(this,N))==null||d.cancel(),(b=o(this,L))==null||b.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,v).getBoundingClientRect();this.children.forEach(x=>x.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,N,(T=o(this,v))==null?void 0:T.animate({transform:Ut(1e3,x=>`scaleX(${1/at(l,1,x)})`)},this.flow.xTiming)),h(this,L,this.el.animate(Mt(1e3,x=>({"--_number-flow-scale-x":at(l,1,x)})),this.flow.xTiming)))}}v=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,L=new WeakMap,N=new WeakMap;var P,X;class rt extends bt{constructor(){super(...arguments);r(this,P);r(this,X)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,P,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,X))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,X,this.el.animate({transform:[`translateX(${o(this,P)-e}px)`,"none"]},this.flow.xTiming))}}P=new WeakMap,X=new WeakMap;var R,W,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,W);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,W,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,W))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,W=new WeakMap,j=new WeakMap;class xt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,H,O,D,F;class _t extends xt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,H);r(this,O);r(this,D);r(this,F)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,H,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,O,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&Ct(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,b;(d=o(this,D))==null||d.cancel(),o(this,$)!==this.value&&((b=o(this,F))==null||b.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,O)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,H)}px))`;h(this,D,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,F,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,H=new WeakMap,O=new WeakMap,D=new WeakMap,F=new WeakMap;var w,z,I,Y;class Bt extends xt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,z);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,z,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,z)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,z=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=At;exports.SlottedTag=ft;exports.defaultFadeTiming=yt;exports.defaultXTiming=tt;exports.defaultXTimingFallbackDuration=mt;exports.defaultXTimingFallbackPoints=gt;exports.defaultXTimingLinearDuration=pt;exports.defaultXTimingLinearPoints=ut;exports.defaultYTiming=wt;exports.partitionParts=Rt;exports.slottedStyles=Et;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
|
|
1
|
+
"use strict";var wt=Object.defineProperty;var et=n=>{throw TypeError(n)};var xt=(n,i,t)=>i in n?wt(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>xt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},_t=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},bt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function St(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Ct(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",x=!1,E=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(x=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(E=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(x||E?l:s).push({type:m,value:p.value,key:c(m)})}const _=[];for(let p=e.length-1;p>=0;p--)_.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:_,fraction:a,post:l,formatted:d}}const vt=V.BROWSER?HTMLElement:class{},kt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",T="var(--number-flow-mask-width, 0.5em)",G=`${T} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",$t={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=kt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${T};margin-right:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${T};margin-left:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;function Rt(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function jt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt={duration:500,easing:"ease-out",endDelay:400,fill:"forwards"},tt=ct?{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)"}:{duration:900,easing:"cubic-bezier(.32,.72,0,1)"},ut=tt;let q;var U,b,S,C,v;class Et extends vt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",ut);u(this,"fadeTiming",pt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,b);r(this,S);r(this,C);r(this,v)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,b).update(s),o(this,S).update(e),o(this,C).update(a),o(this,v).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,b,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,b).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,C,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el),h(this,v,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,v).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).willUpdate(t),o(this,S).willUpdate(t),o(this,C).willUpdate(t),o(this,v).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).didUpdate(t),o(this,S).didUpdate(t),o(this,C).didUpdate(t),o(this,v).didUpdate(t)}}U=new WeakMap,b=new WeakMap,S=new WeakMap,C=new WeakMap,v=new WeakMap;class mt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new yt(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Tt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${bt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";St(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var k,M,A,B,N,L;class lt extends mt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,k);r(this,M);r(this,A);r(this,B);r(this,N);r(this,L);h(this,k,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,k).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,k)),s.forEach(e=>{e instanceof yt&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,x,E;(c=o(this,B))==null||c.cancel(),(d=o(this,L))==null||d.cancel(),(x=o(this,N))==null||x.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,k).getBoundingClientRect();this.children.forEach(_=>_.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,L,(E=o(this,k))==null?void 0:E.animate({transform:Rt(1e3,_=>`scaleX(${1/at(l,1,_)})`)},this.flow.xTiming)),h(this,N,this.el.animate(jt(1e3,_=>({"--_number-flow-scale-x":at(l,1,_)})),this.flow.xTiming)))}}k=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,N=new WeakMap,L=new WeakMap;var W,P;class rt extends mt{constructor(){super(...arguments);r(this,W);r(this,P)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,W,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,P))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,P,this.el.animate({transform:[`translateX(${o(this,W)-e}px)`,"none"]},this.flow.xTiming))}}W=new WeakMap,P=new WeakMap;var R,H,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,H);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,H,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,H))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,H=new WeakMap,j=new WeakMap;class gt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,O,X,z,D;class yt extends gt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,O);r(this,X);r(this,z);r(this,D)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,O,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,X,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&_t(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,x;(d=o(this,z))==null||d.cancel(),o(this,$)!==this.value&&((x=o(this,D))==null||x.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,X)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,O)}px))`;h(this,z,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,D,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,O=new WeakMap,X=new WeakMap,z=new WeakMap,D=new WeakMap;var w,F,I,Y;class Tt extends gt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,F);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,F,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,F)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,F=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=ft;exports.defaultFadeTiming=pt;exports.defaultXTiming=tt;exports.defaultYTiming=ut;exports.partitionParts=Ct;exports.slottedStyles=$t;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
|
package/dist/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ function wt(n, i, { reverse: t = !1 } = {}) {
|
|
|
20
20
|
for (let e = t ? s - 1 : 0; t ? e >= 0 : e < s; t ? e-- : e++)
|
|
21
21
|
i(n[e], e);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function Et(n, i) {
|
|
24
24
|
const t = i.formatToParts(n), s = [], e = [], a = [], l = [], f = {}, c = (p) => (f[p] || (f[p] = 0), `${p}:${f[p]++}`);
|
|
25
25
|
let d = "", x = !1, U = !1;
|
|
26
26
|
for (const p of t) {
|
|
@@ -49,17 +49,17 @@ if (rt)
|
|
|
49
49
|
});
|
|
50
50
|
} catch {
|
|
51
51
|
}
|
|
52
|
-
const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.
|
|
52
|
+
const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", E = "var(--number-flow-mask-width, 0.5em)", Z = `${E} * 1/var(--_number-flow-scale-x)`, it = `calc(${Z})`, st = `linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`, K = "#000 0, transparent 71%", Ct = "span", Tt = {
|
|
53
53
|
fontKerning: "none",
|
|
54
54
|
display: "inline-block",
|
|
55
55
|
lineHeight: ct,
|
|
56
56
|
padding: `${g} 0`
|
|
57
|
-
}, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${
|
|
58
|
-
function
|
|
57
|
+
}, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${Ct}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${Z}) 100%,100% calc(100% - ${g} * 2),${it} ${g},${it} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to right,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to left,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-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;}`;
|
|
58
|
+
function kt(n, i, t = 60) {
|
|
59
59
|
const s = Math.trunc(n / 1e3 * t);
|
|
60
60
|
return Array.from({ length: s }, (e, a) => i(a / (s - 1)));
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function vt(n, i, t = 60) {
|
|
63
63
|
if (rt)
|
|
64
64
|
return [i(0), i(1)];
|
|
65
65
|
const s = Math.max(Math.trunc(n / 1e3 * t), 0), e = Array.from({ length: s }, (a, l) => ({
|
|
@@ -71,29 +71,34 @@ function $t(n, i, t = 60) {
|
|
|
71
71
|
offset: 0
|
|
72
72
|
}), e;
|
|
73
73
|
}
|
|
74
|
-
const ot = (n, i, t) => n + (i - n) * t,
|
|
75
|
-
duration:
|
|
76
|
-
easing:
|
|
74
|
+
const ot = (n, i, t) => n + (i - n) * t, $t = {
|
|
75
|
+
duration: 500,
|
|
76
|
+
easing: "ease-out",
|
|
77
|
+
endDelay: 400,
|
|
78
|
+
fill: "forwards"
|
|
79
|
+
}, ht = bt ? {
|
|
80
|
+
duration: 900,
|
|
81
|
+
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)"
|
|
77
82
|
} : {
|
|
78
|
-
duration:
|
|
83
|
+
duration: 900,
|
|
79
84
|
// Spring-like cubic-bezier stolen from Vaul: https://vaul.emilkowal.ski/
|
|
80
|
-
easing:
|
|
81
|
-
},
|
|
85
|
+
easing: "cubic-bezier(.32,.72,0,1)"
|
|
86
|
+
}, St = ht;
|
|
82
87
|
let G;
|
|
83
|
-
var T, b,
|
|
84
|
-
class
|
|
88
|
+
var T, b, C, k, v;
|
|
89
|
+
class Mt extends xt {
|
|
85
90
|
constructor() {
|
|
86
91
|
super(...arguments);
|
|
87
92
|
u(this, "xTiming", ht);
|
|
88
|
-
u(this, "yTiming",
|
|
89
|
-
u(this, "fadeTiming",
|
|
93
|
+
u(this, "yTiming", St);
|
|
94
|
+
u(this, "fadeTiming", $t);
|
|
90
95
|
u(this, "root", !1);
|
|
91
96
|
u(this, "manual", !1);
|
|
92
97
|
r(this, T, !1);
|
|
93
98
|
r(this, b);
|
|
94
|
-
r(this, k);
|
|
95
99
|
r(this, C);
|
|
96
|
-
r(this,
|
|
100
|
+
r(this, k);
|
|
101
|
+
r(this, v);
|
|
97
102
|
}
|
|
98
103
|
static define() {
|
|
99
104
|
Y && customElements.define("number-flow", this);
|
|
@@ -103,7 +108,7 @@ class Lt extends xt {
|
|
|
103
108
|
return;
|
|
104
109
|
const { pre: s, integer: e, fraction: a, post: l } = t;
|
|
105
110
|
if (o(this, T))
|
|
106
|
-
this.manual || this.willUpdate(), o(this, b).update(s), o(this,
|
|
111
|
+
this.manual || this.willUpdate(), o(this, b).update(s), o(this, C).update(e), o(this, k).update(a), o(this, v).update(l), this.manual || this.didUpdate();
|
|
107
112
|
else {
|
|
108
113
|
if (this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
109
114
|
G || (G = new CSSStyleSheet(), G.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [G];
|
|
@@ -116,35 +121,35 @@ class Lt extends xt {
|
|
|
116
121
|
inert: !0,
|
|
117
122
|
ariaHidden: "true",
|
|
118
123
|
justify: "right"
|
|
119
|
-
})), this.shadowRoot.appendChild(o(this, b).el), h(this,
|
|
124
|
+
})), this.shadowRoot.appendChild(o(this, b).el), h(this, C, new at(this, e, {
|
|
120
125
|
// part: 'integer',
|
|
121
126
|
inert: !0,
|
|
122
127
|
ariaHidden: "true",
|
|
123
128
|
justify: "right"
|
|
124
|
-
})), this.shadowRoot.appendChild(o(this,
|
|
129
|
+
})), this.shadowRoot.appendChild(o(this, C).el), h(this, k, new at(this, a, {
|
|
125
130
|
// part: 'fraction',
|
|
126
131
|
inert: !0,
|
|
127
132
|
ariaHidden: "true",
|
|
128
133
|
justify: "left"
|
|
129
|
-
})), this.shadowRoot.appendChild(o(this,
|
|
134
|
+
})), this.shadowRoot.appendChild(o(this, k).el), h(this, v, new lt(this, l, {
|
|
130
135
|
// part: 'post',
|
|
131
136
|
inert: !0,
|
|
132
137
|
ariaHidden: "true",
|
|
133
138
|
justify: "left"
|
|
134
|
-
})), this.shadowRoot.appendChild(o(this,
|
|
139
|
+
})), this.shadowRoot.appendChild(o(this, v).el);
|
|
135
140
|
}
|
|
136
141
|
h(this, T, !0);
|
|
137
142
|
}
|
|
138
143
|
willUpdate() {
|
|
139
144
|
const t = this.root ? this.getBoundingClientRect() : new DOMRect();
|
|
140
|
-
o(this, b).willUpdate(t), o(this,
|
|
145
|
+
o(this, b).willUpdate(t), o(this, C).willUpdate(t), o(this, k).willUpdate(t), o(this, v).willUpdate(t);
|
|
141
146
|
}
|
|
142
147
|
didUpdate() {
|
|
143
148
|
const t = this.root ? this.getBoundingClientRect() : new DOMRect();
|
|
144
|
-
o(this, b).didUpdate(t), o(this,
|
|
149
|
+
o(this, b).didUpdate(t), o(this, C).didUpdate(t), o(this, k).didUpdate(t), o(this, v).didUpdate(t);
|
|
145
150
|
}
|
|
146
151
|
}
|
|
147
|
-
T = new WeakMap(), b = new WeakMap(),
|
|
152
|
+
T = new WeakMap(), b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), v = new WeakMap();
|
|
148
153
|
class dt {
|
|
149
154
|
constructor(i, t, { justify: s, className: e, ...a }, l) {
|
|
150
155
|
u(this, "flow");
|
|
@@ -166,7 +171,7 @@ class dt {
|
|
|
166
171
|
const e = i.type === "integer" || i.type === "fraction" ? new pt(this, i.type, t ? 0 : i.value, {
|
|
167
172
|
...s,
|
|
168
173
|
onRemove: this.onCharRemove(i.key)
|
|
169
|
-
}) : new
|
|
174
|
+
}) : new jt(this, i.type, i.value, {
|
|
170
175
|
...s,
|
|
171
176
|
onRemove: this.onCharRemove(i.key)
|
|
172
177
|
});
|
|
@@ -198,7 +203,7 @@ class dt {
|
|
|
198
203
|
});
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
|
-
var
|
|
206
|
+
var $, M, A, N, B, L;
|
|
202
207
|
class at extends dt {
|
|
203
208
|
constructor(t, s, { className: e, ...a }) {
|
|
204
209
|
let l;
|
|
@@ -210,53 +215,53 @@ class at extends dt {
|
|
|
210
215
|
className: "section__inner"
|
|
211
216
|
}, f)
|
|
212
217
|
]);
|
|
213
|
-
r(this,
|
|
218
|
+
r(this, $);
|
|
214
219
|
r(this, M);
|
|
215
220
|
r(this, A);
|
|
216
221
|
r(this, N);
|
|
217
222
|
r(this, B);
|
|
218
223
|
r(this, L);
|
|
219
|
-
h(this,
|
|
224
|
+
h(this, $, l);
|
|
220
225
|
}
|
|
221
226
|
willUpdate(t) {
|
|
222
227
|
const s = this.el.getBoundingClientRect();
|
|
223
228
|
h(this, M, s.width), h(this, A, s[this.justify] - t[this.justify]);
|
|
224
|
-
const e = o(this,
|
|
229
|
+
const e = o(this, $).getBoundingClientRect();
|
|
225
230
|
this.children.forEach((a) => a.willUpdate(e));
|
|
226
231
|
}
|
|
227
232
|
update(t) {
|
|
228
233
|
const s = /* @__PURE__ */ new Map();
|
|
229
234
|
this.children.forEach((e, a) => {
|
|
230
235
|
t.find((l) => l.key === a) || s.set(a, e), this.unpop(e);
|
|
231
|
-
}), this.addNewAndUpdateExisting(t, o(this,
|
|
236
|
+
}), this.addNewAndUpdateExisting(t, o(this, $)), s.forEach((e) => {
|
|
232
237
|
e instanceof pt && e.update(0);
|
|
233
238
|
}), this.pop(s);
|
|
234
239
|
}
|
|
235
240
|
didUpdate(t) {
|
|
236
241
|
var c, d, x, U;
|
|
237
242
|
(c = o(this, N)) == null || c.cancel(), (d = o(this, L)) == null || d.cancel(), (x = o(this, B)) == null || x.cancel();
|
|
238
|
-
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this,
|
|
243
|
+
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this, $).getBoundingClientRect();
|
|
239
244
|
this.children.forEach((_) => _.didUpdate(f)), h(this, N, this.el.animate({
|
|
240
245
|
transform: [`translateX(${a}px) scaleX(${l})`, "none"]
|
|
241
|
-
}, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this,
|
|
246
|
+
}, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this, $)) == null ? void 0 : U.animate({
|
|
242
247
|
// 1/x isn't linear so we need to do sampling:
|
|
243
|
-
transform:
|
|
244
|
-
}, this.flow.xTiming)), h(this, B, this.el.animate(
|
|
248
|
+
transform: kt(1e3, (_) => `scaleX(${1 / ot(l, 1, _)})`)
|
|
249
|
+
}, this.flow.xTiming)), h(this, B, this.el.animate(vt(1e3, (_) => ({
|
|
245
250
|
"--_number-flow-scale-x": ot(l, 1, _)
|
|
246
251
|
})), this.flow.xTiming)));
|
|
247
252
|
}
|
|
248
253
|
}
|
|
249
|
-
|
|
250
|
-
var
|
|
254
|
+
$ = new WeakMap(), M = new WeakMap(), A = new WeakMap(), N = new WeakMap(), B = new WeakMap(), L = new WeakMap();
|
|
255
|
+
var H, P;
|
|
251
256
|
class lt extends dt {
|
|
252
257
|
constructor() {
|
|
253
258
|
super(...arguments);
|
|
254
|
-
r(this, P);
|
|
255
259
|
r(this, H);
|
|
260
|
+
r(this, P);
|
|
256
261
|
}
|
|
257
262
|
willUpdate(t) {
|
|
258
263
|
const s = this.el.getBoundingClientRect();
|
|
259
|
-
h(this,
|
|
264
|
+
h(this, H, s[this.justify] - t[this.justify]), this.children.forEach((e) => e.willUpdate(s));
|
|
260
265
|
}
|
|
261
266
|
update(t) {
|
|
262
267
|
const s = /* @__PURE__ */ new Map();
|
|
@@ -266,25 +271,25 @@ class lt extends dt {
|
|
|
266
271
|
}
|
|
267
272
|
didUpdate(t) {
|
|
268
273
|
var a;
|
|
269
|
-
(a = o(this,
|
|
274
|
+
(a = o(this, P)) == null || a.cancel();
|
|
270
275
|
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify];
|
|
271
|
-
this.children.forEach((l) => l.didUpdate(s)), h(this,
|
|
272
|
-
transform: [`translateX(${o(this,
|
|
276
|
+
this.children.forEach((l) => l.didUpdate(s)), h(this, P, this.el.animate({
|
|
277
|
+
transform: [`translateX(${o(this, H) - e}px)`, "none"]
|
|
273
278
|
}, this.flow.xTiming));
|
|
274
279
|
}
|
|
275
280
|
}
|
|
276
|
-
|
|
277
|
-
var j,
|
|
281
|
+
H = new WeakMap(), P = new WeakMap();
|
|
282
|
+
var j, W, R;
|
|
278
283
|
class J {
|
|
279
284
|
constructor(i, t, { onRemove: s, animateIn: e = !1 } = {}) {
|
|
280
285
|
u(this, "flow");
|
|
281
286
|
u(this, "el");
|
|
282
287
|
r(this, j, !0);
|
|
283
|
-
r(this,
|
|
288
|
+
r(this, W);
|
|
284
289
|
r(this, R);
|
|
285
290
|
this.flow = i, this.el = t, e && this.el.animate({
|
|
286
291
|
opacity: ["0", "1"]
|
|
287
|
-
}, i.fadeTiming), h(this,
|
|
292
|
+
}, i.fadeTiming), h(this, W, s);
|
|
288
293
|
}
|
|
289
294
|
get present() {
|
|
290
295
|
return o(this, j);
|
|
@@ -298,11 +303,11 @@ class J {
|
|
|
298
303
|
opacity: [t, i ? "1" : "0"]
|
|
299
304
|
}, this.flow.fadeTiming)), i || (o(this, R).onfinish = () => {
|
|
300
305
|
var e;
|
|
301
|
-
this.el.remove(), (e = o(this,
|
|
306
|
+
this.el.remove(), (e = o(this, W)) == null || e.call(this);
|
|
302
307
|
}), h(this, j, i);
|
|
303
308
|
}
|
|
304
309
|
}
|
|
305
|
-
j = new WeakMap(),
|
|
310
|
+
j = new WeakMap(), W = new WeakMap(), R = new WeakMap();
|
|
306
311
|
class ft extends J {
|
|
307
312
|
constructor(t, s, e, a) {
|
|
308
313
|
super(t.flow, e, a);
|
|
@@ -312,7 +317,7 @@ class ft extends J {
|
|
|
312
317
|
this.section = t, this.value = s, this.el = e;
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
|
-
var S,
|
|
320
|
+
var S, X, z, D, O;
|
|
316
321
|
class pt extends ft {
|
|
317
322
|
constructor(t, s, e, a) {
|
|
318
323
|
super(t, e, y("span", {
|
|
@@ -322,17 +327,17 @@ class pt extends ft {
|
|
|
322
327
|
}), a);
|
|
323
328
|
r(this, S);
|
|
324
329
|
// Relative to parent:
|
|
325
|
-
r(this,
|
|
326
|
-
r(this, D);
|
|
330
|
+
r(this, X);
|
|
327
331
|
r(this, z);
|
|
332
|
+
r(this, D);
|
|
328
333
|
r(this, O);
|
|
329
334
|
}
|
|
330
335
|
willUpdate(t) {
|
|
331
336
|
h(this, S, this.value);
|
|
332
337
|
const s = this.el.getBoundingClientRect();
|
|
333
|
-
h(this,
|
|
338
|
+
h(this, X, s.y - t.y);
|
|
334
339
|
const e = s[this.section.justify] - t[this.section.justify], a = s.width / 2;
|
|
335
|
-
h(this,
|
|
340
|
+
h(this, z, this.section.justify === "left" ? e + a : e - a);
|
|
336
341
|
}
|
|
337
342
|
update(t) {
|
|
338
343
|
this.value = t, o(this, S) !== t && gt(this.el, [
|
|
@@ -347,9 +352,9 @@ class pt extends ft {
|
|
|
347
352
|
}
|
|
348
353
|
didUpdate(t) {
|
|
349
354
|
var d, x;
|
|
350
|
-
(d = o(this,
|
|
351
|
-
const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this,
|
|
352
|
-
h(this,
|
|
355
|
+
(d = o(this, D)) == null || d.cancel(), o(this, S) !== this.value && ((x = o(this, O)) == null || x.cancel());
|
|
356
|
+
const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this, z) - l}px)`, c = `translateY(calc((100% + ${g}) * ${this.value - o(this, S)} + ${o(this, X)}px))`;
|
|
357
|
+
h(this, D, this.el.animate({
|
|
353
358
|
transform: [et ? f : `${f} ${c}`, "none"]
|
|
354
359
|
}, {
|
|
355
360
|
...this.flow.xTiming,
|
|
@@ -363,9 +368,9 @@ class pt extends ft {
|
|
|
363
368
|
}));
|
|
364
369
|
}
|
|
365
370
|
}
|
|
366
|
-
S = new WeakMap(),
|
|
367
|
-
var w,
|
|
368
|
-
class
|
|
371
|
+
S = new WeakMap(), X = new WeakMap(), z = new WeakMap(), D = new WeakMap(), O = new WeakMap();
|
|
372
|
+
var w, I, F, V;
|
|
373
|
+
class jt extends ft {
|
|
369
374
|
constructor(t, s, e, a) {
|
|
370
375
|
const l = y("span", {
|
|
371
376
|
className: "symbol__value",
|
|
@@ -376,20 +381,20 @@ class Tt extends ft {
|
|
|
376
381
|
}, [l]), a);
|
|
377
382
|
u(this, "type");
|
|
378
383
|
r(this, w, /* @__PURE__ */ new Map());
|
|
379
|
-
r(this,
|
|
380
|
-
r(this,
|
|
384
|
+
r(this, I);
|
|
385
|
+
r(this, F, (t) => () => {
|
|
381
386
|
o(this, w).delete(t);
|
|
382
387
|
});
|
|
383
388
|
r(this, V);
|
|
384
389
|
this.type = s, o(this, w).set(e, new J(this.flow, l, {
|
|
385
|
-
onRemove: o(this,
|
|
390
|
+
onRemove: o(this, F).call(this, e)
|
|
386
391
|
}));
|
|
387
392
|
}
|
|
388
393
|
willUpdate(t) {
|
|
389
394
|
if (this.type === "decimal")
|
|
390
395
|
return;
|
|
391
396
|
const s = this.el.getBoundingClientRect();
|
|
392
|
-
h(this,
|
|
397
|
+
h(this, I, s[this.section.justify] - t[this.section.justify]);
|
|
393
398
|
}
|
|
394
399
|
update(t) {
|
|
395
400
|
if (this.value !== t) {
|
|
@@ -404,7 +409,7 @@ class Tt extends ft {
|
|
|
404
409
|
});
|
|
405
410
|
this.el.appendChild(e), o(this, w).set(t, new J(this.flow, e, {
|
|
406
411
|
animateIn: !0,
|
|
407
|
-
onRemove: o(this,
|
|
412
|
+
onRemove: o(this, F).call(this, t)
|
|
408
413
|
}));
|
|
409
414
|
}
|
|
410
415
|
}
|
|
@@ -417,23 +422,19 @@ class Tt extends ft {
|
|
|
417
422
|
(a = o(this, V)) == null || a.cancel();
|
|
418
423
|
const e = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
|
|
419
424
|
h(this, V, this.el.animate({
|
|
420
|
-
transform: [`translateX(${o(this,
|
|
425
|
+
transform: [`translateX(${o(this, I) - e}px)`, "none"]
|
|
421
426
|
}, this.flow.xTiming));
|
|
422
427
|
}
|
|
423
428
|
}
|
|
424
|
-
w = new WeakMap(),
|
|
429
|
+
w = new WeakMap(), I = new WeakMap(), F = new WeakMap(), V = new WeakMap();
|
|
425
430
|
export {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
431
|
+
Mt as NumberFlowLite,
|
|
432
|
+
Ct as SlottedTag,
|
|
433
|
+
$t as defaultFadeTiming,
|
|
429
434
|
ht as defaultXTiming,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
St as defaultXTimingLinearPoints,
|
|
434
|
-
Et as defaultYTiming,
|
|
435
|
-
Nt as partitionParts,
|
|
436
|
-
Bt as slottedStyles,
|
|
435
|
+
St as defaultYTiming,
|
|
436
|
+
Et as partitionParts,
|
|
437
|
+
Tt as slottedStyles,
|
|
437
438
|
et as supportsAnimationComposition,
|
|
438
439
|
bt as supportsLinear
|
|
439
440
|
};
|
package/dist/styles.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ export declare const supportsLinear: boolean;
|
|
|
2
2
|
export declare const supportsAtProperty: boolean;
|
|
3
3
|
export declare const supportsAnimationComposition: boolean;
|
|
4
4
|
export declare const charHeight = "var(--number-flow-char-height, 1em)";
|
|
5
|
-
export declare const maskHeight = "var(--number-flow-mask-height, 0.
|
|
5
|
+
export declare const maskHeight = "var(--number-flow-mask-height, 0.25em)";
|
|
6
6
|
export declare const SlottedTag = "span";
|
|
7
7
|
export declare const slottedStyles: {
|
|
8
8
|
readonly fontKerning: "none";
|
|
9
9
|
readonly display: "inline-block";
|
|
10
10
|
readonly lineHeight: "var(--number-flow-char-height, 1em)";
|
|
11
|
-
readonly padding: "var(--number-flow-mask-height, 0.
|
|
11
|
+
readonly padding: "var(--number-flow-mask-height, 0.25em) 0";
|
|
12
12
|
};
|
|
13
13
|
declare const styles: string;
|
|
14
14
|
export default styles;
|
package/package.json
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.2",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Maxwell Barvian",
|
|
9
9
|
"email": "max@barvian.me",
|
|
10
10
|
"url": "https://barvian.me"
|
|
11
11
|
},
|
|
12
|
-
"description": "A
|
|
12
|
+
"description": "A component to transition and format numbers.",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"homepage": "https://number-flow.barvian.me/",
|
|
15
15
|
"repository": {
|