UNPKG

ixfx

Version:

Bundle of ixfx libraries

1 lines 6.54 kB
import{n as e}from"./chunk-BKBlUVio.js";import{C as t,M as n,p as r,v as i}from"./src-CrVWx2VD.js";const a=(e,t=Math.random)=>{let n=[],r=0;for(let t=0;t<e.length;t++)r+=e[t],n[t]=r;if(r!==1)throw Error(`Weightings should add up to 1. Got: ${r}`);return()=>{let e=t();for(let t=0;t<n.length;t++)if(e<=n[t])return t;throw Error(`Bug: weightedIndex could not select index`)}};function o(e,t=Math.random){return Math.floor(t()*e.length)}function s(e,t={}){if(e===void 0)throw Error(`Param 'array' is undefined`);if(!Array.isArray(e))throw Error(`Param 'array' is not an array`);let n=t.mutate??!1,r=t.source??Math.random;if(e.length===0)return n?void 0:{value:void 0,remainder:[]};let i=o(e,r);if(n){let t=e[i];return e.splice(i,1),t}else{let t=[...e];return t.splice(i,1),{value:e[i],remainder:t}}}function c(e,t=Math.random){return n(r(e,`array`)),e[Math.floor(t()*e.length)]}function l(e,t,n=Math.random){if(e.length!==t.length)throw Error(`Lengths of 'array' and 'weightings' should be the same.`);let r=a(t,n);return()=>e[r()]}function u(e,t=Math.random){let n=[...e];for(let e=n.length-1;e>0;e--){let r=Math.floor(t()*(e+1));[n[e],n[r]]=[n[r],n[e]]}return n}const d=(e,r,i,a)=>{let o=a??Math.random,s=e=>typeof e==`function`?e():e,c=s(e);return n(t(c,`percentage`,`p`)),o()<=c?s(i):s(r)},f=e=>{let t=m(e);return()=>t()*2-1},p=e=>f(e)(),m=(e=1)=>{let r=typeof e==`number`?{max:e}:e,i=r.max??1,a=r.min??0,o=r.source??Math.random;if(n(t(a,``,`min`),t(i,``,`max`)),!r.min&&i<0&&(a=i,i=0),a>i)throw Error(`Min is greater than max. Min: ${a.toString()} max: ${i.toString()}`);return()=>o()*(i-a)+a},h=(e=1)=>m(e)();function g(e={}){let t=v(e);return()=>t().value}const _={8:[7,5,4,3],16:[15,13,12,10]};function v(e={}){let t=e.seed??181;if(t<=0)throw TypeError(`Param 'seed' must be a positive non-zero integer. Got: '${t}'`);let n=(e.output??`integer`)===`float`,r=e.width??Math.floor(Math.log2(t))+1,i=e.taps??_[r];if(!i||i.length===0)throw TypeError(`Param 'taps' empty or undefined for width: '${r}'`);let a=t&(1<<r)-1;return()=>{let e=0;for(let t of i)e^=a>>t&1;a=(a<<1|e)&(1<<r)-1;let t=a;return n&&(r===8&&(t=(t-1)/256),r===16&&(t=(t-1)/65536)),{value:t,stringValue:a.toString(2).padStart(r,`0`)}}}function y(e=123456789){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}const b=(e=Math.random)=>{let t=0;for(;t===0;)t=e();return t},x=(e=1)=>S(e)(),S=(e=1)=>{let t=()=>{let n=b(),r=b(),i=Math.sqrt(-2*Math.log(n))*Math.cos(2*Math.PI*r);return i=i/10+.5,i>1||i<0?i=t():(i**=+e,i*=1,i+=0),i};return t},C=(e={})=>{let t=e.source??Math.random,n=Math.trunc(t()*46656),r=Math.trunc(t()*46656);return`000${n.toString(36)}`.slice(-3)+`000${r.toString(36)}`.slice(-3)};function*w(e,t=0){if(n(i(e,``,`amount`),i(t,``,`offset`)),e===0)return;let r=0;do yield e<0?-r+t:r+t;while(r++<Math.abs(e)-1)}const T=e=>{if(e===void 0)throw TypeError(`maxOrOptions is undefined`);let r=typeof e==`number`?{max:e}:e,i=Math.floor(r.max??100),a=Math.floor(r.min??0);!r.min&&i<0&&(i=1,a=r.max??0);let o=r.source??Math.random;if(a>i)throw Error(`Min value is greater than max (min: ${a.toString()} max: ${i.toString()})`);if(n(t(a,``,`min`),t(i,``,`max`)),i===a)throw Error(`Max and min values cannot be the same (${i.toString()})`);let s=Math.abs(i-a);return()=>Math.floor(o()*s)+a},E=e=>T(e)();function*D(e){let t=typeof e==`number`?{max:e}:e,r=t.min??0,a=t.max??100,o=t.source??Math.random,s=t.loop??!1;if(n(i(r,``,`min`),i(a,``,`max`)),r>a)throw Error(`Min value is greater than max. Min: ${r.toString()} Max: ${a.toString()}`);let c=[...w(a-r,r)],l=u(c),d=0;for(;;){if(d===l.length)if(s)l=u(c,o);else return;yield l[d++]}}function O(e){e===void 0&&(e=Math.random()*4294967295);let t=Array(624);t[0]=e>>>0;let n=1812433253;for(let e=1;e<624;e++){let r=t[e-1]^t[e-1]>>>30;t[e]=((n&4294901760)*r>>>0)+((n&65535)*r>>>0)+e>>>0}let r=624,i=()=>{let e;if(r>=624){for(let n=0;n<227;n++)e=(t[n]&2147483648|t[n+1]&2147483647)>>>0,t[n]=(t[n+397]^e>>>1^(e&1?2567483615:0))>>>0;for(let n=227;n<623;n++)e=(t[n]&2147483648|t[n+1]&2147483647)>>>0,t[n]=(t[n-227]^e>>>1^(e&1?2567483615:0))>>>0;e=(t[623]&2147483648|t[0]&2147483647)>>>0,t[623]=(t[396]^e>>>1^(e&1?2567483615:0))>>>0,r=0}return e=t[r++],e=(e^e>>>11)>>>0,e=(e^e<<7&2636928640)>>>0,e=(e^e<<15&4022730752)>>>0,e=(e^e>>>18)>>>0,e};return{integer:(e,t=0)=>{if(e<1)throw Error(`Upper bound must be greater than or equal to 1`);if(e>4294967296)throw Error(`Upper bound must not be greater than 4294967296`);if(e===1)return 0;let n=e-t,r=(1<<Math.ceil(Math.log2(n)))-1;for(;;){let e=i()&r;if(e<n)return t+e}},float:()=>i()/4294967296}}const k=(e=5)=>{let t=typeof e==`number`?{length:e}:e,n=t.source??Math.random,r=t.length??5,i=``;for(;i.length<r;)i+=n().toString(36).slice(2);return i.substring(0,r)},A=e=>{let t=typeof e==`number`?{max:e}:e,n=(t.min??0)*60*1e3,r=(t.max??5)*60*1e3;return T({...t,max:r,min:n})},j=e=>A(e)(),M=e=>{let t=typeof e==`number`?{max:e}:e,n=(t.min??0)*1e3,r=(t.max??5)*1e3;return()=>E({...t,max:r,min:n})},N=e=>M(e)();function P(e,t=0,n=1){return e<t?t:e>n?n:e}const F=e=>{let t=e.source??Math.random;if(e.easingFunction===void 0)throw Error(`Param 'easingFunction' is undefined`);let n=e.max??1,r=e.min??0;if(n===r)throw Error(`Param 'max' is the same as 'min'`);if(n<r)throw Error(`Param 'max' should be greater than 'min'`);return()=>{let i=P(e.easingFunction(t()));return Math.floor(i*(n-r))+r}},I=e=>F(e)(),L=e=>R(e)(),R=e=>{let t=e.source??Math.random;if(e.easing!==void 0)throw Error(`Param 'easingName' unavailable. Use @ixfx/modulation.weighted instead.`);if(e.easingFunction===void 0)throw Error(`Param 'easingFunction' is undefined`);return()=>e.easingFunction(t())};var z=e({bipolar:()=>p,bipolarSource:()=>f,calculateNonZero:()=>b,chance:()=>d,float:()=>h,floatSource:()=>m,gaussian:()=>x,gaussianSource:()=>S,integer:()=>E,integerSource:()=>T,integerUniqueGen:()=>D,lfsrCompute:()=>v,lfsrSource:()=>g,mersenneTwister:()=>O,minutesMs:()=>j,minutesMsSource:()=>A,mulberrySource:()=>y,randomElement:()=>c,randomElementWeightedSource:()=>l,randomIndex:()=>o,randomPluck:()=>s,secondsMs:()=>N,secondsMsSource:()=>M,shortGuid:()=>C,shuffle:()=>u,string:()=>k,weighted:()=>L,weightedIndex:()=>a,weightedInteger:()=>I,weightedIntegerSource:()=>F,weightedSource:()=>R});export{s as A,f as C,c as D,d as E,a as M,l as O,p as S,m as T,S as _,F as a,v as b,N as c,O as d,E as f,x as g,C as h,I as i,u as j,o as k,M as l,D as m,L as n,j as o,T as p,R as r,A as s,z as t,k as u,b as v,h as w,g as x,y};