number-flow 0.5.1 → 0.5.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.
@@ -0,0 +1,10 @@
1
+ "use strict";const m=require("esm-env"),c=(n,t,e)=>{const i=document.createElement(n),[s,r]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),r==null||r.forEach(a=>i.appendChild(a)),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,D=(n,t)=>{m.BROWSER&&customElements.get(n)!==t&&customElements.define(n,t)};function H(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 F=String.raw,P=String.raw,X=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",A="--_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:A,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)",x=`calc(${h} / 2)`,C="var(--number-flow-mask-width, 0.5em)",d=`calc(${C} / var(--scale-x))`,u="#000 0, transparent 71%",j=P`: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 * ${C});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:not(:has(.digit.is-spinning)){-webkit-mask-image:none}.number__inner{padding:${x} ${C};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 > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${A})}.digit__num,.number .section::after{padding:${x} 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(${w}))}`,Y=m.BROWSER?HTMLElement:class{},q=P`: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:${x} 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`:`symbol ${n.type}`}">${n.value}</span>`,g=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+G(i),"")}</span>`,Z=n=>F`<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
+ >`,L=z&&X&&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:r,value:a}=t;if(this.created){const l=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(l.value,a):this.trend,this.computedAnimated=L&&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(r),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(j)),this.shadowRoot.adoptedStyleSheets=[y];else{const l=document.createElement("style");l.textContent=j,this.shadowRoot.appendChild(l)}this._pre=new T(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 T(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}}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,...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=c("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=c("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({[v]:[`${e}px`,"0px"],[R]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class N{constructor(t,e,{justify:i,className:s,...r},a){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",{...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 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.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]=`${B(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",r=s?"prepend":"append";if(H(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 N{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 U&&i.update(0)}),this.pop(e)}}class T extends N{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 E{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({[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,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({[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 E{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,r){var p,f;const a=(((f=(p=t.flow.digits)==null?void 0:p[s])==null?void 0:f.max)??9)+1,o=Array.from({length:a}).map((et,b)=>{const $=c("span",{className:"digit__num"},[document.createTextNode(String(b))]);return b!==i&&$.setAttribute("inert",""),$.style.setProperty("--n",String(b)),$}),l=c("span",{part:`digit ${e}-digit`,className:"digit"},o);l.style.setProperty("--current",String(i)),l.style.setProperty("--length",String(a)),super(t,i,l,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){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,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.getDelta();o&&(this.el.classList.add("is-spinning"),this.el.animate({[A]:[-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 r=(i=s.getDelta)==null?void 0:i.call(s,this.value,this._prevValue,this);if(r!=null)return r}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 r=c("span",{className:"symbol__value",textContent:i});super(t,i,c("span",{part:`symbol ${e}`,className:"symbol"},[r]),s),this.type=e,this._children=new Map,this._onChildRemove=a=>()=>{this._children.delete(a)},this._children.set(i,new E(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,this._children.has(t)){const i=this._children.get(t);i.present=!0}else{const i=c("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),this._children.set(t,new E(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"),r=i.find(o=>!s.find(l=>l.pos===o.pos&&l.value===o.value)),a=s.find(o=>!i.find(l=>o.pos===l.pos&&o.value===l.value));S.set(e,Q(r==null?void 0:r.pos,a==null?void 0:a.pos))},getDelta(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=L;exports.continuous=tt;exports.define=D;exports.prefersReducedMotion=_;exports.renderInnerHTML=Z;
@@ -13,7 +13,7 @@ function B(n, t, { reverse: e = !1 } = {}) {
13
13
  for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
14
14
  t(n[s], s);
15
15
  }
16
- const D = String.raw, T = String.raw, H = m && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), X = 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", F = (() => {
16
+ const D = String.raw, M = String.raw, H = m && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), X = m && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), $ = m && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, _ = "--_number-flow-d-opacity", k = "--_number-flow-d-width", w = "--_number-flow-dx", A = "--_number-flow-d", F = (() => {
17
17
  try {
18
18
  return CSS.registerProperty({
19
19
  name: _,
@@ -26,12 +26,12 @@ const D = String.raw, T = String.raw, H = m && typeof CSS < "u" && CSS.supports
26
26
  inherits: !0,
27
27
  initialValue: "0px"
28
28
  }), CSS.registerProperty({
29
- name: E,
29
+ name: k,
30
30
  syntax: "<number>",
31
31
  inherits: !1,
32
32
  initialValue: "0"
33
33
  }), CSS.registerProperty({
34
- name: k,
34
+ name: A,
35
35
  syntax: "<number>",
36
36
  inherits: !0,
37
37
  initialValue: "0"
@@ -39,8 +39,8 @@ const D = String.raw, T = String.raw, H = m && typeof CSS < "u" && CSS.supports
39
39
  } catch {
40
40
  return !1;
41
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(${_}))}`, O = 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` : `symbol ${n.type}`}">${n.value}</span>`, g = (n, t) => `<span part="${t}">${n.reduce((e, i) => e + I(i), "")}</span>`, et = (n) => (
42
+ })(), R = "var(--number-flow-char-height, 1em)", h = "var(--number-flow-mask-height, 0.25em)", x = `calc(${h} / 2)`, C = "var(--number-flow-mask-width, 0.5em)", d = `calc(${C} / var(--scale-x))`, u = "#000 0, transparent 71%", U = M`: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(${k}) / var(--width));transform:translateX(var(${w})) scaleX(var(--scale-x));margin:0 calc(-1 * ${C});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:not(:has(.digit.is-spinning)){-webkit-mask-image:none}.number__inner{padding:${x} ${C};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 > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${A})}.digit__num,.number .section::after{padding:${x} 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(${_}))}`, O = m ? HTMLElement : class {
43
+ }, z = M`: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:${x} 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` : `symbol ${n.type}`}">${n.value}</span>`, g = (n, t) => `<span part="${t}">${n.reduce((e, i) => e + I(i), "")}</span>`, et = (n) => (
44
44
  // shadowroot="open" non-standard attribute for old Chrome:
45
45
  D`<template shadowroot="open" shadowrootmode="open"
46
46
  ><style>
@@ -74,22 +74,22 @@ class G extends O {
74
74
  const { pre: e, integer: i, fraction: s, post: a, value: r } = t;
75
75
  if (this.created) {
76
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
77
+ this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(l.value, r) : this.trend, this.computedAnimated = Y && this._animated && (!this.respectMotionPreference || !($ != null && $.matches)) && // https://github.com/barvian/number-flow/issues/9
78
78
  W(this), (o = this.plugins) == null || o.forEach((p) => {
79
79
  var f;
80
80
  return (f = p.onUpdate) == null ? void 0 : f.call(p, t, l, this);
81
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
82
  } else {
83
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];
84
+ y || (y = new CSSStyleSheet(), y.replaceSync(U)), this.shadowRoot.adoptedStyleSheets = [y];
85
85
  else {
86
86
  const l = document.createElement("style");
87
- l.textContent = j, this.shadowRoot.appendChild(l);
87
+ l.textContent = U, this.shadowRoot.appendChild(l);
88
88
  }
89
- this._pre = new L(this, e, {
89
+ this._pre = new T(this, e, {
90
90
  justify: "right",
91
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, {
92
+ }), this.shadowRoot.appendChild(this._pre.el), this._num = new Z(this, i, s), this.shadowRoot.appendChild(this._num.el), this._post = new T(this, a, {
93
93
  justify: "left",
94
94
  part: "right"
95
95
  }), this.shadowRoot.appendChild(this._post.el);
@@ -125,10 +125,10 @@ G.defaultProps = {
125
125
  };
126
126
  class Z {
127
127
  constructor(t, e, i, { className: s, ...a } = {}) {
128
- this.flow = t, this._integer = new A(t, e, {
128
+ this.flow = t, this._integer = new j(t, e, {
129
129
  justify: "right",
130
130
  part: "integer"
131
- }), this._fraction = new A(t, i, {
131
+ }), this._fraction = new j(t, i, {
132
132
  justify: "left",
133
133
  part: "fraction"
134
134
  }), this._inner = c("span", {
@@ -151,14 +151,14 @@ class Z {
151
151
  const e = this._prevLeft - t.left, i = this.el.offsetWidth, s = this._prevWidth - i;
152
152
  this.el.style.setProperty("--width", String(i)), this.el.animate({
153
153
  [w]: [`${e}px`, "0px"],
154
- [E]: [s, 0]
154
+ [k]: [s, 0]
155
155
  }, {
156
156
  ...this.flow.transformTiming,
157
157
  composite: "accumulate"
158
158
  });
159
159
  }
160
160
  }
161
- class M {
161
+ class P {
162
162
  constructor(t, e, { justify: i, className: s, ...a }, r) {
163
163
  this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (l) => () => {
164
164
  this.children.delete(l);
@@ -170,7 +170,7 @@ class M {
170
170
  }, r ? r(o) : o);
171
171
  }
172
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, {
173
+ const s = t.type === "integer" || t.type === "fraction" ? new L(this, t.type, e ? 0 : t.value, t.pos, {
174
174
  ...i,
175
175
  onRemove: this.onCharRemove(t.key)
176
176
  }) : new q(this, t.type, t.value, {
@@ -180,13 +180,13 @@ class M {
180
180
  return this.children.set(t.key, s), s;
181
181
  }
182
182
  unpop(t) {
183
- t.el.classList.remove("section__exiting"), t.el.style.top = "", t.el.style[this.justify] = "";
183
+ t.el.removeAttribute("inert"), t.el.style.top = "", t.el.style[this.justify] = "";
184
184
  }
185
185
  pop(t) {
186
186
  t.forEach((e) => {
187
187
  e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${V(e.el, this.justify)}px`;
188
188
  }), t.forEach((e) => {
189
- e.el.classList.add("section__exiting"), e.present = !1;
189
+ e.el.setAttribute("inert", ""), e.present = !1;
190
190
  });
191
191
  }
192
192
  addNewAndUpdateExisting(t) {
@@ -222,17 +222,17 @@ class M {
222
222
  });
223
223
  }
224
224
  }
225
- class A extends M {
225
+ class j extends P {
226
226
  update(t) {
227
227
  const e = /* @__PURE__ */ new Map();
228
228
  this.children.forEach((i, s) => {
229
229
  t.find((a) => a.key === s) || e.set(s, i), this.unpop(i);
230
230
  }), this.addNewAndUpdateExisting(t), e.forEach((i) => {
231
- i instanceof N && i.update(0);
231
+ i instanceof L && i.update(0);
232
232
  }), this.pop(e);
233
233
  }
234
234
  }
235
- class L extends M {
235
+ class T extends P {
236
236
  update(t) {
237
237
  const e = /* @__PURE__ */ new Map();
238
238
  this.children.forEach((i, s) => {
@@ -240,7 +240,7 @@ class L extends M {
240
240
  }), this.pop(e), this.addNewAndUpdateExisting(t);
241
241
  }
242
242
  }
243
- class C {
243
+ class E {
244
244
  constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
245
245
  this.flow = t, this.el = e, this._present = !0, this._remove = () => {
246
246
  var a;
@@ -257,7 +257,7 @@ class C {
257
257
  }
258
258
  set present(t) {
259
259
  if (this._present !== t) {
260
- if (this._present = t, !this.flow.computedAnimated) {
260
+ if (this._present = t, t ? this.el.removeAttribute("inert") : this.el.setAttribute("inert", ""), !this.flow.computedAnimated) {
261
261
  t || this._remove();
262
262
  return;
263
263
  }
@@ -272,17 +272,19 @@ class C {
272
272
  }
273
273
  }
274
274
  }
275
- class P extends C {
275
+ class N extends E {
276
276
  constructor(t, e, i, s) {
277
277
  super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
278
278
  }
279
279
  }
280
- class N extends P {
280
+ class L extends N {
281
281
  constructor(t, e, i, s, a) {
282
282
  var p, f;
283
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;
284
+ const b = c("span", { className: "digit__num" }, [
285
+ document.createTextNode(String(v))
286
+ ]);
287
+ return v !== i && b.setAttribute("inert", ""), b.style.setProperty("--n", String(v)), b;
286
288
  }), l = c("span", {
287
289
  part: `digit ${e}-digit`,
288
290
  className: "digit"
@@ -298,8 +300,7 @@ class N extends P {
298
300
  this._prevCenter = this.section.justify === "left" ? i + s : i - s;
299
301
  }
300
302
  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
+ this.el.style.setProperty("--current", String(t)), this._numbers.forEach((e, i) => i === t ? e.removeAttribute("inert") : e.setAttribute("inert", "")), this.value = t;
303
304
  }
304
305
  didUpdate(t) {
305
306
  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;
@@ -311,7 +312,7 @@ class N extends P {
311
312
  });
312
313
  const o = this.getDelta();
313
314
  o && (this.el.classList.add("is-spinning"), this.el.animate({
314
- [k]: [-o, 0]
315
+ [A]: [-o, 0]
315
316
  }, {
316
317
  ...this.flow.spinTiming ?? this.flow.transformTiming,
317
318
  composite: "accumulate"
@@ -329,7 +330,7 @@ class N extends P {
329
330
  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
  }
331
332
  }
332
- class q extends P {
333
+ class q extends N {
333
334
  constructor(t, e, i, s) {
334
335
  const a = c("span", {
335
336
  className: "symbol__value",
@@ -340,7 +341,7 @@ class q extends P {
340
341
  className: "symbol"
341
342
  }, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (r) => () => {
342
343
  this._children.delete(r);
343
- }, this._children.set(i, new C(this.flow, a, {
344
+ }, this._children.set(i, new E(this.flow, a, {
344
345
  onRemove: this._onChildRemove(i)
345
346
  }));
346
347
  }
@@ -353,15 +354,15 @@ class q extends P {
353
354
  update(t) {
354
355
  if (this.value !== t) {
355
356
  const e = this._children.get(this.value);
356
- if (e.present = !1, e.el.classList.add("symbol__exiting"), this._children.has(t)) {
357
+ if (e.present = !1, this._children.has(t)) {
357
358
  const i = this._children.get(t);
358
- i.present = !0, i.el.classList.remove("symbol__exiting");
359
+ i.present = !0;
359
360
  } else {
360
361
  const i = c("span", {
361
362
  className: "symbol__value",
362
363
  textContent: t
363
364
  });
364
- this.el.appendChild(i), this._children.set(t, new C(this.flow, i, {
365
+ this.el.appendChild(i), this._children.set(t, new E(this.flow, i, {
365
366
  animateIn: !0,
366
367
  onRemove: this._onChildRemove(t)
367
368
  }));
@@ -378,25 +379,25 @@ class q extends P {
378
379
  }, { ...this.flow.transformTiming, composite: "accumulate" });
379
380
  }
380
381
  }
381
- const J = (n, t) => n == null ? t : t == null ? n : Math.max(n, t), $ = /* @__PURE__ */ new WeakMap(), it = {
382
+ const J = (n, t) => n == null ? t : t == null ? n : Math.max(n, t), S = /* @__PURE__ */ new WeakMap(), it = {
382
383
  onUpdate(n, t, e) {
383
- if ($.set(e, void 0), !e.computedTrend)
384
+ if (S.set(e, void 0), !e.computedTrend)
384
385
  return;
385
386
  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
+ S.set(e, J(a == null ? void 0 : a.pos, r == null ? void 0 : r.pos));
387
388
  },
388
389
  getDelta(n, t, e) {
389
- const i = n - t, s = $.get(e.flow);
390
+ const i = n - t, s = S.get(e.flow);
390
391
  if (!i && s != null && s >= e.pos)
391
392
  return e.length * e.flow.computedTrend;
392
393
  }
393
394
  };
394
395
  export {
395
- N as D,
396
+ L as D,
396
397
  G as N,
397
398
  Y as a,
398
399
  it as c,
399
400
  tt as d,
400
- b as p,
401
+ $ as p,
401
402
  et as r
402
403
  };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./continuous-NkaCOHfo.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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./continuous-DyFEzKlu.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,4 +1,4 @@
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-DjSsg6E6.mjs";
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-dVP5sYQl.mjs";
2
2
  function d(n, h, u, l) {
3
3
  const r = h.formatToParts(n);
4
4
  u && r.unshift({ type: "prefix", value: u }), l && r.push({ type: "suffix", value: l });
package/dist/plugins.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./continuous-NkaCOHfo.js");exports.continuous=o.continuous;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./continuous-DyFEzKlu.js");exports.continuous=o.continuous;
package/dist/plugins.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as n } from "./continuous-DjSsg6E6.mjs";
1
+ import { c as n } from "./continuous-dVP5sYQl.mjs";
2
2
  export {
3
3
  n as continuous
4
4
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.5.1",
6
+ "version": "0.5.2",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",
@@ -1,10 +0,0 @@
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,D=(n,t)=>{m.BROWSER&&customElements.get(n)!==t&&customElements.define(n,t)};function H(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 F=String.raw,T=String.raw,X=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)",S=`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:${S} ${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:${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(${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:${S} 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`:`symbol ${n.type}`}">${n.value}</span>`,g=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+G(i),"")}</span>`,Z=n=>F`<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&&X&&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(H(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.getDelta();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}))}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 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),$=new WeakMap,tt={onUpdate(n,t,e){if($.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));$.set(e,Q(a==null?void 0:a.pos,r==null?void 0:r.pos))},getDelta(n,t,e){const i=n-t,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=D;exports.prefersReducedMotion=_;exports.renderInnerHTML=Z;