number-flow 0.5.9 → 0.5.11

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