number-flow 0.5.6 → 0.5.7
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/group.js +1 -1
- package/dist/group.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{lite-hpz6xQDp.js → lite-B8p0lZvR.js} +5 -5
- package/dist/{lite-D1QTSlER.mjs → lite-CzDvSY_4.mjs} +57 -50
- package/dist/lite.js +1 -1
- package/dist/lite.mjs +1 -1
- package/package.json +1 -1
package/dist/group.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("./lite-
|
|
1
|
+
"use strict";const n=require("./lite-B8p0lZvR.js"),t=require("./index.js");class i extends n.ServerSafeHTMLElement{constructor(){super(...arguments),this._flows=new Set,this._addDescendant=e=>{e.batched=!0,this._flows.add(e)},this._removeDescendant=e=>{e.batched=!1,this._flows.delete(e)},this._onDescendantConnected=e=>{this._addDescendant(e.target)},this._updating=!1,this._onDescendantUpdate=()=>{this._updating||(this._updating=!0,this._flows.forEach(e=>{e.created&&(e.willUpdate(),queueMicrotask(()=>{e.connected&&e.didUpdate()}))}),queueMicrotask(()=>{this._updating=!1}))}}connectedCallback(){this.querySelectorAll("number-flow").forEach(e=>{this._addDescendant(e)}),this.addEventListener(t.CONNECT_EVENT,this._onDescendantConnected),this.addEventListener(t.UPDATE_EVENT,this._onDescendantUpdate),this._mutationObserver??(this._mutationObserver=new MutationObserver(e=>{e.forEach(r=>{r.removedNodes.forEach(s=>{s instanceof t.default&&this._removeDescendant(s)})})})),this._mutationObserver.observe(this,{childList:!0,subtree:!0})}disconnectedCallback(){var e;this.removeEventListener(t.CONNECT_EVENT,this._onDescendantConnected),this.removeEventListener(t.UPDATE_EVENT,this._onDescendantUpdate),(e=this._mutationObserver)==null||e.disconnect()}}n.define("number-flow-group",i);module.exports=i;
|
package/dist/group.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-B8p0lZvR.js"),l=require("./plugins.js"),n="number-flow-connect",s="number-flow-update",f=(r,{locales:t,format:o,numberPrefix:a,numberSuffix:u}={})=>{const c=e.formatToData(r,new Intl.NumberFormat(t,o),a,u);return e.renderInnerHTML(c)};class i extends e.NumberFlowLite{constructor(){super(...arguments),this.connected=!1}connectedCallback(){this.connected=!0,this.dispatchEvent(new Event(n,{bubbles:!0}))}disconnectedCallback(){this.connected=!1}get value(){return this._value}update(t){(!this._formatter||this._prevFormat!==this.format||this._prevLocales!==this.locales)&&(this._formatter=new Intl.NumberFormat(this.locales,this.format),this._prevFormat=this.format,this._prevLocales=this.locales),t!=null&&(this._value=t),this.dispatchEvent(new Event(s,{bubbles:!0})),this.data=e.formatToData(this._value,this._formatter,this.numberPrefix,this.numberSuffix)}}e.define("number-flow",i);exports.Digit=e.Digit;exports.canAnimate=e.canAnimate;exports.define=e.define;exports.formatToData=e.formatToData;exports.prefersReducedMotion=e.prefersReducedMotion;exports.continuous=l.continuous;exports.CONNECT_EVENT=n;exports.UPDATE_EVENT=s;exports.default=i;exports.renderInnerHTML=f;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as i, N as u, f as r, r as c } from "./lite-
|
|
2
|
-
import { D as _, c as v, p as E } from "./lite-
|
|
1
|
+
import { d as i, N as u, f as r, r as c } from "./lite-CzDvSY_4.mjs";
|
|
2
|
+
import { D as _, c as v, p as E } from "./lite-CzDvSY_4.mjs";
|
|
3
3
|
import { continuous as N } from "./plugins.mjs";
|
|
4
4
|
const l = "number-flow-connect", m = "number-flow-update", d = (t, { locales: e, format: s, numberPrefix: n, numberSuffix: a } = {}) => {
|
|
5
5
|
const o = r(t, new Intl.NumberFormat(e, s), n, a);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";const _=require("esm-env");require("./plugins.js");const u=(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},I=(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},X=n=>n.offsetWidth>0&&n.offsetHeight>0,z=(n,t)=>{_.BROWSER&&customElements.get(n)!==t&&customElements.define(n,t)};function q(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)}function Y(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const a=[],r=[],o=[],c=[],d={},p=h=>`${h}:${d[h]=(d[h]??-1)+1}`;let
|
|
1
|
+
"use strict";const _=require("esm-env");require("./plugins.js");const u=(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},I=(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},X=n=>n.offsetWidth>0&&n.offsetHeight>0,z=(n,t)=>{_.BROWSER&&customElements.get(n)!==t&&customElements.define(n,t)};function q(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)}function Y(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const a=[],r=[],o=[],c=[],d={},p=h=>`${h}:${d[h]=(d[h]??-1)+1}`;let x="",g=!1,y=!1;for(const h of s){x+=h.value;const l=h.type==="minusSign"||h.type==="plusSign"?"sign":h.type;l==="integer"?(g=!0,r.push(...h.value.split("").map(R=>({type:l,value:parseInt(R)})))):l==="group"?r.push({type:l,value:h.value}):l==="decimal"?(y=!0,o.push({type:l,value:h.value,key:p(l)})):l==="fraction"?o.push(...h.value.split("").map(R=>({type:l,value:parseInt(R),key:p(l),pos:-1-d[l]}))):(g||y?c:a).push({type:l,value:h.value,key:p(l)})}const P=[];for(let h=r.length-1;h>=0;h--){const l=r[h];P.unshift(l.type==="integer"?{...l,key:p(l.type),pos:d[l.type]}:{...l,key:p(l.type)})}return{pre:a,integer:P,fraction:o,post:c,valueAsString:x,value:typeof n=="string"?parseFloat(n):n}}const G=String.raw,V=String.raw,K=_.BROWSER&&(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0})(),Z=_.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),$=_.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,S="--_number-flow-d-opacity",U="--_number-flow-d-width",E="--_number-flow-dx",j="--_number-flow-d",J=(()=>{try{return CSS.registerProperty({name:S,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:E,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:U,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:j,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),T="var(--number-flow-char-height, 1em)",f="var(--number-flow-mask-height, 0.25em)",C=`calc(${f} / 2)`,A="var(--number-flow-mask-width, 0.5em)",m=`calc(${A} / var(--scale-x))`,v="#000 0, transparent 71%",L=V`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${T} !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(${U}) / var(--width));transform:translateX(var(${E})) scaleX(var(--scale-x));margin:0 calc(-1 * ${A});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),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% - ${f} * 2),calc(100% - ${m} * 2) 100%,${m} ${f},${m} ${f},${m} ${f},${m} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${C} ${A};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${E})))}: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 > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${j})}.digit__num,.number .section::after{padding:${C} 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[inert]{position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num[inert]{display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol > [inert]{left:0}.section--justify-right .symbol > [inert]{right:0}.animate-presence{opacity:calc(1 + var(${S}))}`,B=_.BROWSER?HTMLElement:class{},Q=V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${T} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${C} 0}.symbol{white-space:pre}`,tt=n=>`<span class="${n.type==="integer"||n.type==="fraction"?"digit":"symbol"}" part="${n.type==="integer"||n.type==="fraction"?`digit ${n.type}-digit`:`symbol ${n.type}`}">${n.value}</span>`,w=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+tt(i),"")}</span>`,et=n=>G`<template shadowroot="open" shadowrootmode="open"
|
|
2
2
|
><style>
|
|
3
3
|
${Q}</style
|
|
4
4
|
><span role="img" aria-label="${n.valueAsString}"
|
|
5
|
-
>${
|
|
6
|
-
>${
|
|
7
|
-
>${
|
|
5
|
+
>${w(n.pre,"left")}<span part="number" class="number"
|
|
6
|
+
>${w(n.integer,"integer")}${w(n.fraction,"fraction")}</span
|
|
7
|
+
>${w(n.post,"right")}</span
|
|
8
8
|
></template
|
|
9
9
|
><span
|
|
10
10
|
style="font-kerning: none; display: inline-block; line-height: ${T} !important; padding: ${f} 0;"
|
|
11
11
|
>${n.valueAsString}</span
|
|
12
|
-
>`,D=Z&&K&&J;let b;class H extends B{constructor(){super(),this.created=!1,this.batched=!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 c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,r):this.trend,this.computedAnimated=D&&this._animated&&(!this.respectMotionPreference||!(
|
|
12
|
+
>`,D=Z&&K&&J;let b;class H extends B{constructor(){super(),this.created=!1,this.batched=!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 c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,r):this.trend,this.computedAnimated=D&&this._animated&&(!this.respectMotionPreference||!($!=null&&$.matches))&&X(this),(o=this.plugins)==null||o.forEach(d=>{var p;return(p=d.onUpdate)==null?void 0:p.call(d,t,c,this)}),this.batched||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:s}),this._post.update(a),this.batched||this.didUpdate()}else{this._data=t,this.attachShadow({mode:"open"});try{this._internals??(this._internals=this.attachInternals()),this._internals.role="img"}catch{}if(typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)b||(b=new CSSStyleSheet,b.replaceSync(L)),this.shadowRoot.adoptedStyleSheets=[b];else{const c=document.createElement("style");c.textContent=L,this.shadowRoot.appendChild(c)}this._pre=new N(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new it(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new N(this,a,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el),this.created=!0}try{this._internals.ariaLabel=t.valueAsString}catch{}}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}}H.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 it{constructor(t,e,i,{className:s,...a}={}){this.flow=t,this._integer=new W(t,e,{justify:"right",part:"integer"}),this._fraction=new W(t,i,{justify:"left",part:"fraction"}),this._inner=u("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=u("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({[E]:[`${e}px`,"0px"],[U]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class O{constructor(t,e,{justify:i,className:s,...a},r){this.flow=t,this.children=new Map,this.onCharRemove=c=>()=>{this.children.delete(c)},this.justify=i;const o=e.map(c=>this.addChar(c).el);this.el=u("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 M(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new st(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}unpop(t){t.el.removeAttribute("inert"),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]=`${I(e.el,this.justify)}px`}),t.forEach(e=>{e.el.setAttribute("inert",""),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,s=this.justify==="left",a=s?"prepend":"append";if(q(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 W extends O{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 M&&i.update(0)}),this.pop(e)}}class N extends O{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 k{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({[S]:[-.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,t?this.el.removeAttribute("inert"):this.el.setAttribute("inert",""),!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[S]: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 k{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class M extends F{constructor(t,e,i,s,a){var d,p;const r=(((p=(d=t.flow.digits)==null?void 0:d[s])==null?void 0:p.max)??9)+1,o=Array.from({length:r}).map((x,g)=>{const y=u("span",{className:"digit__num"},[document.createTextNode(String(g))]);return g!==i&&y.setAttribute("inert",""),y.style.setProperty("--n",String(g)),y}),c=u("span",{part:`digit ${e}-digit`,className:"digit"},o);c.style.setProperty("--current",String(i)),c.style.setProperty("--length",String(r)),super(t,i,c,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){this.el.style.setProperty("--current",String(t)),this._numbers.forEach((e,i)=>i===t?e.removeAttribute("inert"):e.setAttribute("inert","")),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.getDelta();o&&(this.el.classList.add("is-spinning"),this.el.animate({[j]:[-o,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}getDelta(){var i;if(this.flow.plugins)for(const s of this.flow.plugins){const a=(i=s.getDelta)==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 st extends F{constructor(t,e,i,s){const a=u("span",{className:"symbol__value",textContent:i});super(t,i,u("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 k(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);e&&(e.present=!1);const i=this._children.get(t);if(i)i.present=!0;else{const s=u("span",{className:"symbol__value",textContent:t});this.el.appendChild(s),this._children.set(t,new k(this.flow,s,{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.Digit=M;exports.NumberFlowLite=H;exports.ServerSafeHTMLElement=B;exports.canAnimate=D;exports.define=z;exports.formatToData=Y;exports.prefersReducedMotion=$;exports.renderInnerHTML=et;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BROWSER as _ } from "esm-env";
|
|
2
2
|
import "./plugins.mjs";
|
|
3
|
-
const
|
|
3
|
+
const m = (n, t, e) => {
|
|
4
4
|
const i = document.createElement(n), [s, a] = Array.isArray(t) ? [void 0, t] : [t, e];
|
|
5
|
-
return s && Object.assign(i, s), a == null || a.forEach((
|
|
5
|
+
return s && Object.assign(i, s), a == null || a.forEach((r) => i.appendChild(r)), i;
|
|
6
6
|
}, F = (n, t) => {
|
|
7
7
|
var e;
|
|
8
8
|
return t === "left" ? n.offsetLeft : (((e = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
|
|
@@ -17,14 +17,14 @@ function X(n, t, { reverse: e = !1 } = {}) {
|
|
|
17
17
|
function nt(n, t, e, i) {
|
|
18
18
|
const s = t.formatToParts(n);
|
|
19
19
|
e && s.unshift({ type: "prefix", value: e }), i && s.push({ type: "suffix", value: i });
|
|
20
|
-
const a = [],
|
|
21
|
-
let
|
|
20
|
+
const a = [], r = [], o = [], c = [], d = {}, p = (h) => `${h}:${d[h] = (d[h] ?? -1) + 1}`;
|
|
21
|
+
let x = "", g = !1, y = !1;
|
|
22
22
|
for (const h of s) {
|
|
23
|
-
|
|
23
|
+
x += h.value;
|
|
24
24
|
const l = h.type === "minusSign" || h.type === "plusSign" ? "sign" : h.type;
|
|
25
|
-
l === "integer" ? (g = !0,
|
|
25
|
+
l === "integer" ? (g = !0, r.push(...h.value.split("").map((C) => ({ type: l, value: parseInt(C) })))) : l === "group" ? r.push({ type: l, value: h.value }) : l === "decimal" ? (y = !0, o.push({ type: l, value: h.value, key: p(l) })) : l === "fraction" ? o.push(...h.value.split("").map((C) => ({
|
|
26
26
|
type: l,
|
|
27
|
-
value: parseInt(
|
|
27
|
+
value: parseInt(C),
|
|
28
28
|
key: p(l),
|
|
29
29
|
pos: -1 - d[l]
|
|
30
30
|
}))) : (g || y ? c : a).push({
|
|
@@ -34,8 +34,8 @@ function nt(n, t, e, i) {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
const T = [];
|
|
37
|
-
for (let h =
|
|
38
|
-
const l =
|
|
37
|
+
for (let h = r.length - 1; h >= 0; h--) {
|
|
38
|
+
const l = r[h];
|
|
39
39
|
T.unshift(l.type === "integer" ? {
|
|
40
40
|
...l,
|
|
41
41
|
key: p(l.type),
|
|
@@ -48,13 +48,20 @@ function nt(n, t, e, i) {
|
|
|
48
48
|
return {
|
|
49
49
|
pre: a,
|
|
50
50
|
integer: T,
|
|
51
|
-
fraction:
|
|
51
|
+
fraction: o,
|
|
52
52
|
post: c,
|
|
53
|
-
valueAsString:
|
|
53
|
+
valueAsString: x,
|
|
54
54
|
value: typeof n == "string" ? parseFloat(n) : n
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
const I = String.raw, V = String.raw, O = _ &&
|
|
57
|
+
const I = String.raw, V = String.raw, O = _ && (() => {
|
|
58
|
+
try {
|
|
59
|
+
document.createElement("div").animate({ opacity: 0 }, { easing: "linear(0, 1)" });
|
|
60
|
+
} catch {
|
|
61
|
+
return !1;
|
|
62
|
+
}
|
|
63
|
+
return !0;
|
|
64
|
+
})(), z = _ && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), A = _ && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, $ = "--_number-flow-d-opacity", U = "--_number-flow-d-width", S = "--_number-flow-dx", j = "--_number-flow-d", Y = (() => {
|
|
58
65
|
try {
|
|
59
66
|
return CSS.registerProperty({
|
|
60
67
|
name: $,
|
|
@@ -80,7 +87,7 @@ const I = String.raw, V = String.raw, O = _ && typeof CSS < "u" && CSS.supports
|
|
|
80
87
|
} catch {
|
|
81
88
|
return !1;
|
|
82
89
|
}
|
|
83
|
-
})(), P = "var(--number-flow-char-height, 1em)", f = "var(--number-flow-mask-height, 0.25em)", k = `calc(${f} / 2)`, E = "var(--number-flow-mask-width, 0.5em)",
|
|
90
|
+
})(), P = "var(--number-flow-char-height, 1em)", f = "var(--number-flow-mask-height, 0.25em)", k = `calc(${f} / 2)`, E = "var(--number-flow-mask-width, 0.5em)", u = `calc(${E} / var(--scale-x))`, w = "#000 0, transparent 71%", M = V`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${P} !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(${U}) / var(--width));transform:translateX(var(${S})) scaleX(var(--scale-x));margin:0 calc(-1 * ${E});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${u},#000 calc(100% - ${u}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),transparent 100% ),radial-gradient(at bottom right,${w}),radial-gradient(at bottom left,${w}),radial-gradient(at top left,${w}),radial-gradient(at top right,${w});-webkit-mask-size:100% calc(100% - ${f} * 2),calc(100% - ${u} * 2) 100%,${u} ${f},${u} ${f},${u} ${f},${u} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${k} ${E};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${S})))}: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 > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${j})}.digit__num,.number .section::after{padding:${k} 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[inert]{position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num[inert]{display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol > [inert]{left:0}.section--justify-right .symbol > [inert]{right:0}.animate-presence{opacity:calc(1 + var(${$}))}`, G = _ ? HTMLElement : class {
|
|
84
91
|
}, 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:${k} 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` : `symbol ${n.type}`}">${n.value}</span>`, v = (n, t) => `<span part="${t}">${n.reduce((e, i) => e + Z(i), "")}</span>`, at = (n) => (
|
|
85
92
|
// shadowroot="open" non-standard attribute for old Chrome:
|
|
86
93
|
I`<template shadowroot="open" shadowrootmode="open"
|
|
@@ -114,14 +121,14 @@ class J extends G {
|
|
|
114
121
|
* @internal
|
|
115
122
|
*/
|
|
116
123
|
set data(t) {
|
|
117
|
-
var
|
|
124
|
+
var o;
|
|
118
125
|
if (t == null)
|
|
119
126
|
return;
|
|
120
|
-
const { pre: e, integer: i, fraction: s, post: a, value:
|
|
127
|
+
const { pre: e, integer: i, fraction: s, post: a, value: r } = t;
|
|
121
128
|
if (this.created) {
|
|
122
129
|
const c = this._data;
|
|
123
|
-
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(c.value,
|
|
124
|
-
H(this), (
|
|
130
|
+
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(c.value, r) : this.trend, this.computedAnimated = q && this._animated && (!this.respectMotionPreference || !(A != null && A.matches)) && // https://github.com/barvian/number-flow/issues/9
|
|
131
|
+
H(this), (o = this.plugins) == null || o.forEach((d) => {
|
|
125
132
|
var p;
|
|
126
133
|
return (p = d.onUpdate) == null ? void 0 : p.call(d, t, c, this);
|
|
127
134
|
}), this.batched || this.willUpdate(), this._pre.update(e), this._num.update({ integer: i, fraction: s }), this._post.update(a), this.batched || this.didUpdate();
|
|
@@ -191,9 +198,9 @@ class Q {
|
|
|
191
198
|
}), this._fraction = new L(t, i, {
|
|
192
199
|
justify: "left",
|
|
193
200
|
part: "fraction"
|
|
194
|
-
}), this._inner =
|
|
201
|
+
}), this._inner = m("span", {
|
|
195
202
|
className: "number__inner"
|
|
196
|
-
}, [this._integer.el, this._fraction.el]), this.el =
|
|
203
|
+
}, [this._integer.el, this._fraction.el]), this.el = m("span", {
|
|
197
204
|
...a,
|
|
198
205
|
part: "number",
|
|
199
206
|
className: `number ${s ?? ""}`
|
|
@@ -219,15 +226,15 @@ class Q {
|
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
class W {
|
|
222
|
-
constructor(t, e, { justify: i, className: s, ...a },
|
|
229
|
+
constructor(t, e, { justify: i, className: s, ...a }, r) {
|
|
223
230
|
this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (c) => () => {
|
|
224
231
|
this.children.delete(c);
|
|
225
232
|
}, this.justify = i;
|
|
226
|
-
const
|
|
227
|
-
this.el =
|
|
233
|
+
const o = e.map((c) => this.addChar(c).el);
|
|
234
|
+
this.el = m("span", {
|
|
228
235
|
...a,
|
|
229
236
|
className: `section section--justify-${i} ${s ?? ""}`
|
|
230
|
-
},
|
|
237
|
+
}, r ? r(o) : o);
|
|
231
238
|
}
|
|
232
239
|
addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
|
|
233
240
|
const s = t.type === "integer" || t.type === "fraction" ? new D(this, t.type, e ? 0 : t.value, t.pos, {
|
|
@@ -251,19 +258,19 @@ class W {
|
|
|
251
258
|
}
|
|
252
259
|
addNewAndUpdateExisting(t) {
|
|
253
260
|
const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", a = s ? "prepend" : "append";
|
|
254
|
-
if (X(t, (
|
|
255
|
-
let
|
|
256
|
-
this.children.has(
|
|
261
|
+
if (X(t, (r) => {
|
|
262
|
+
let o;
|
|
263
|
+
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);
|
|
257
264
|
}, { reverse: s }), this.flow.computedAnimated) {
|
|
258
|
-
const
|
|
259
|
-
e.forEach((
|
|
260
|
-
|
|
265
|
+
const r = this.el.getBoundingClientRect();
|
|
266
|
+
e.forEach((o) => {
|
|
267
|
+
o.willUpdate(r);
|
|
261
268
|
});
|
|
262
269
|
}
|
|
263
|
-
e.forEach((
|
|
264
|
-
|
|
265
|
-
}), i.forEach((
|
|
266
|
-
|
|
270
|
+
e.forEach((r, o) => {
|
|
271
|
+
r.update(o.value);
|
|
272
|
+
}), i.forEach((r, o) => {
|
|
273
|
+
r.update(o.value);
|
|
267
274
|
});
|
|
268
275
|
}
|
|
269
276
|
willUpdate() {
|
|
@@ -340,18 +347,18 @@ class B extends R {
|
|
|
340
347
|
class D extends B {
|
|
341
348
|
constructor(t, e, i, s, a) {
|
|
342
349
|
var d, p;
|
|
343
|
-
const
|
|
344
|
-
const y =
|
|
350
|
+
const r = (((p = (d = t.flow.digits) == null ? void 0 : d[s]) == null ? void 0 : p.max) ?? 9) + 1, o = Array.from({ length: r }).map((x, g) => {
|
|
351
|
+
const y = m("span", { className: "digit__num" }, [
|
|
345
352
|
document.createTextNode(String(g))
|
|
346
353
|
]);
|
|
347
354
|
return g !== i && y.setAttribute("inert", ""), y.style.setProperty("--n", String(g)), y;
|
|
348
|
-
}), c =
|
|
355
|
+
}), c = m("span", {
|
|
349
356
|
part: `digit ${e}-digit`,
|
|
350
357
|
className: "digit"
|
|
351
|
-
},
|
|
352
|
-
c.style.setProperty("--current", String(i)), c.style.setProperty("--length", String(
|
|
358
|
+
}, o);
|
|
359
|
+
c.style.setProperty("--current", String(i)), c.style.setProperty("--length", String(r)), super(t, i, c, a), this.pos = s, this._onAnimationsFinish = () => {
|
|
353
360
|
this.el.classList.remove("is-spinning");
|
|
354
|
-
}, this._numbers =
|
|
361
|
+
}, this._numbers = o, this.length = r;
|
|
355
362
|
}
|
|
356
363
|
willUpdate(t) {
|
|
357
364
|
const e = this.el.getBoundingClientRect();
|
|
@@ -363,16 +370,16 @@ class D extends B {
|
|
|
363
370
|
this.el.style.setProperty("--current", String(t)), this._numbers.forEach((e, i) => i === t ? e.removeAttribute("inert") : e.setAttribute("inert", "")), this.value = t;
|
|
364
371
|
}
|
|
365
372
|
didUpdate(t) {
|
|
366
|
-
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,
|
|
367
|
-
|
|
368
|
-
transform: [`translateX(${
|
|
373
|
+
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;
|
|
374
|
+
r && this.el.animate({
|
|
375
|
+
transform: [`translateX(${r}px)`, "none"]
|
|
369
376
|
}, {
|
|
370
377
|
...this.flow.transformTiming,
|
|
371
378
|
composite: "accumulate"
|
|
372
379
|
});
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
[j]: [-
|
|
380
|
+
const o = this.getDelta();
|
|
381
|
+
o && (this.el.classList.add("is-spinning"), this.el.animate({
|
|
382
|
+
[j]: [-o, 0]
|
|
376
383
|
}, {
|
|
377
384
|
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
378
385
|
composite: "accumulate"
|
|
@@ -392,15 +399,15 @@ class D extends B {
|
|
|
392
399
|
}
|
|
393
400
|
class tt extends B {
|
|
394
401
|
constructor(t, e, i, s) {
|
|
395
|
-
const a =
|
|
402
|
+
const a = m("span", {
|
|
396
403
|
className: "symbol__value",
|
|
397
404
|
textContent: i
|
|
398
405
|
});
|
|
399
|
-
super(t, i,
|
|
406
|
+
super(t, i, m("span", {
|
|
400
407
|
part: `symbol ${e}`,
|
|
401
408
|
className: "symbol"
|
|
402
|
-
}, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (
|
|
403
|
-
this._children.delete(
|
|
409
|
+
}, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (r) => () => {
|
|
410
|
+
this._children.delete(r);
|
|
404
411
|
}, this._children.set(i, new R(this.flow, a, {
|
|
405
412
|
onRemove: this._onChildRemove(i)
|
|
406
413
|
}));
|
|
@@ -419,7 +426,7 @@ class tt extends B {
|
|
|
419
426
|
if (i)
|
|
420
427
|
i.present = !0;
|
|
421
428
|
else {
|
|
422
|
-
const s =
|
|
429
|
+
const s = m("span", {
|
|
423
430
|
className: "symbol__value",
|
|
424
431
|
textContent: t
|
|
425
432
|
});
|
package/dist/lite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-B8p0lZvR.js"),t=require("./plugins.js");exports.Digit=e.Digit;exports.canAnimate=e.canAnimate;exports.default=e.NumberFlowLite;exports.define=e.define;exports.formatToData=e.formatToData;exports.prefersReducedMotion=e.prefersReducedMotion;exports.renderInnerHTML=e.renderInnerHTML;exports.continuous=t.continuous;
|
package/dist/lite.mjs
CHANGED