@dice-roller/rpg-dice-roller
Advanced tools
Comparing version 5.4.1 to 5.5.0
/** | ||
* @dice-roller/rpg-dice-roller - An advanced JS based dice roller that can roll various types of dice and modifiers, along with mathematical equations. | ||
* | ||
* @version 5.4.1 | ||
* @version 5.5.0 | ||
* @license MIT | ||
@@ -10,2 +10,2 @@ * @author GreenImp Media <info@greenimp.co.uk> (https://greenimp.co.uk) | ||
import{evaluate as t}from"mathjs";class CompareOperatorError extends TypeError{constructor(t){super(`Operator "${t}" is invalid`),TypeError.captureStackTrace&&TypeError.captureStackTrace(this,CompareOperatorError),this.name="CompareOperatorError",this.operator=t}}class DataFormatError extends Error{constructor(t){super(`Invalid data format: ${t}`),Error.captureStackTrace&&Error.captureStackTrace(this,DataFormatError),this.name="ImportError",this.data=t}}class DieActionValueError extends Error{constructor(t,e=null){super(`Die "${t}" must have more than 1 possible value to ${e||"do this action"}`),Error.captureStackTrace&&Error.captureStackTrace(this,DieActionValueError),this.name="DieActionValueError",this.action=e,this.die=t}}class NotationError extends Error{constructor(t){super(`Notation "${t}" is invalid`),Error.captureStackTrace&&Error.captureStackTrace(this,NotationError),this.name="NotationError",this.notation=t}}class RequiredArgumentError extends Error{constructor(t=null){super("Missing argument"+(t?` "${t}"`:"")),Error.captureStackTrace&&Error.captureStackTrace(this,RequiredArgumentError),this.argumentName=t}}var e=Object.freeze({__proto__:null,CompareOperatorError:CompareOperatorError,DataFormatError:DataFormatError,DieActionValueError:DieActionValueError,NotationError:NotationError,RequiredArgumentError:RequiredArgumentError});const r=e=>t(e),n=t=>("number"==typeof t||"string"==typeof t)&&(!Number.isNaN(t)&&Number.isFinite(Number(t))),i=t=>{if(!n(t))return!1;const e=Number(t);return e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER},o=9007199254740992,s=o-1,a=-1>>>0,u=a+1,l=u/2,c=l-1,h=1<<21,f=h-1;function p(t){return 0|t.next()}function d(t,e){return 0===e?t:r=>t(r)+e}function m(t){const e=0|t.next(),r=t.next()>>>0;return(e&f)*u+r+(e&h?-o:0)}function g(t){for(;;){const e=0|t.next();if(!(4194304&e)){const r=t.next()>>>0;return(e&f)*u+r+(e&h?-o:0)}if(4194304==(8388607&e)&&0==(0|t.next()))return o}}function y(t){return t.next()>>>0}function w(t){const e=t.next()&f,r=t.next()>>>0;return e*u+r}function b(t){for(;;){const e=0|t.next();if(!(e&h)){const r=t.next()>>>0;return(e&f)*u+r}if(0==(e&f)&&0==(0|t.next()))return o}}function x(t){return 0==(t+1&t)}function v(t){return x(t)?(e=t,t=>t.next()&e):function(t){const e=t+1,r=e*Math.floor(u/e);return t=>{let n=0;do{n=t.next()>>>0}while(n>=r);return n%e}}(t);var e}function E(t){const e=t+1;if(0==(0|e)){const t=(e/u|0)-1;if(x(t))return r=t,t=>{const e=t.next()&r,n=t.next()>>>0;return e*u+n}}var r;return function(t){const e=t*Math.floor(o/t);return r=>{let n=0;do{const t=r.next()&f,e=r.next()>>>0;n=t*u+e}while(n>=e);return n%t}}(e)}function S(t,e){return r=>{let n=0;do{const t=0|r.next(),e=r.next()>>>0;n=(t&f)*u+e+(t&h?-o:0)}while(n<t||n>e);return n}}function A(t,e){if(t=Math.floor(t),e=Math.floor(e),t<-o||!isFinite(t))throw new RangeError("Expected min to be at least "+-o);if(e>o||!isFinite(e))throw new RangeError(`Expected max to be at most ${o}`);const r=e-t;return r<=0||!isFinite(r)?()=>t:r===a?0===t?y:d(p,t+l):r<a?d(v(r),t):r===s?d(w,t):r<s?d(E(r),t):e-1-t===s?d(b,t):t===-o&&e===o?g:t===-o&&e===s?m:t===-s&&e===o?d(m,1):e===o?d(S(t-1,e-1),1):S(t,e)}function R(t){return 1==(1&t.next())}function M(t,e){return r=>t(r)<e}function C(t,e){return null==e?null==t?R:function(t){if(t<=0)return()=>!1;if(t>=1)return()=>!0;{const e=t*u;return e%1==0?M(p,e-l|0):M(w,Math.round(t*o))}}(t):t<=0?()=>!1:t>=e?()=>!0:M(A(0,e-1),t)}function T(t){return A(1,t)}function N(t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"){const e=t.length;if(!e)throw new Error("Expected pool not to be an empty string");const r=A(0,e-1);return(e,n)=>{let i="";for(let o=0;o<n;++o){const n=r(e);i+=t.charAt(n)}return i}}const O="0123456789abcdef",$=N(O),D=N(O.toUpperCase());function F(t,e){return t<0?Math.max(t+e,0):Math.min(t,e)}function P(t){const e=+t;return e<0?Math.ceil(e):Math.floor(e)}function I(t){return w(t)/o}function J(t){return b(t)/o}const j=Array.prototype.slice;function q(t,e,r=0){const n=e.length;if(n)for(let i=n-1>>>0;i>r;--i){const r=A(0,i)(t);if(i!==r){const t=e[i];e[i]=e[r],e[r]=t}}return e}const G=(()=>{try{if("xxx"==="x".repeat(3))return(t,e)=>t.repeat(e)}catch(t){}return(t,e)=>{let r="";for(;e>0;)1&e&&(r+=t),e>>=1,t+=t;return r}})();function V(t,e){return G("0",e-t.length)+t}const k={next:()=>Math.random()*u|0};class Random{constructor(t=k){this.engine=t}int32(){return p(this.engine)}uint32(){return y(this.engine)}uint53(){return w(this.engine)}uint53Full(){return b(this.engine)}int53(){return m(this.engine)}int53Full(){return g(this.engine)}integer(t,e){return A(t,e)(this.engine)}realZeroToOneInclusive(){return J(this.engine)}realZeroToOneExclusive(){return I(this.engine)}real(t,e,r=!1){return function(t,e,r=!1){if(!isFinite(t))throw new RangeError("Expected min to be a finite number");if(!isFinite(e))throw new RangeError("Expected max to be a finite number");return d((n=r?J:I,1==(i=e-t)?n:0===i?()=>0:t=>n(t)*i),t);var n,i}(t,e,r)(this.engine)}bool(t,e){return C(t,e)(this.engine)}pick(t,e,r){return function(t,e,r,n){const i=e.length;if(0===i)throw new RangeError("Cannot pick from an empty array");const o=null==r?0:F(P(r),i),s=void 0===n?i:F(P(n),i);if(o>=s)throw new RangeError(`Cannot pick between bounds ${o} and ${s}`);return e[A(o,s-1)(t)]}(this.engine,t,e,r)}shuffle(t){return q(this.engine,t)}sample(t,e){return function(t,e,r){if(r<0||r>e.length||!isFinite(r))throw new RangeError("Expected sampleSize to be within 0 and the length of the population");if(0===r)return[];const n=j.call(e),i=n.length;if(i===r)return q(t,n,0);const o=i-r;return q(t,n,o-1).slice(o)}(this.engine,t,e)}die(t){return T(t)(this.engine)}dice(t,e){return function(t,e){const r=T(t);return t=>{const n=[];for(let i=0;i<e;++i)n.push(r(t));return n}}(t,e)(this.engine)}uuid4(){return function(t){const e=t.next()>>>0,r=0|t.next(),n=0|t.next(),i=t.next()>>>0;return V(e.toString(16),8)+"-"+V((65535&r).toString(16),4)+"-"+V((r>>4&4095|16384).toString(16),4)+"-"+V((16383&n|32768).toString(16),4)+"-"+V((n>>4&65535).toString(16),4)+V(i.toString(16),8)}(this.engine)}string(t,e){return N(e)(this.engine,t)}hex(t,e){return function(t){return t?D:$}(e)(this.engine,t)}date(t,e){return function(t,e){const r=A(+t,+e);return t=>new Date(r(t))}(t,e)(this.engine)}}const _=(()=>{try{const t=new ArrayBuffer(4),e=new Int32Array(t);if(e[0]=l,e[0]===-l)return Int32Array}catch(t){}return Array})();let B=null;let z=128;const L={next:()=>(z>=128&&(null===B&&(B=new _(128)),crypto.getRandomValues(B),z=0),0|B[z++])};const U=(()=>{try{if(-5===Math.imul(a,5))return Math.imul}catch(t){}const t=65535;return(e,r)=>{const n=e&t,i=r&t;return n*i+((e>>>16&t)*i+n*(r>>>16&t)<<16>>>0)|0}})(),K=624,W=623,H=2567483615;class MersenneTwister19937{constructor(){this.data=new _(K),this.index=0,this.uses=0}static seed(t){return(new MersenneTwister19937).seed(t)}static seedWithArray(t){return(new MersenneTwister19937).seedWithArray(t)}static autoSeed(){return MersenneTwister19937.seedWithArray(function(t=k,e=16){const r=[];r.push(0|(new Date).getTime());for(let n=1;n<e;++n)r[n]=0|t.next();return r}())}next(){(0|this.index)>=K&&(Z(this.data),this.index=0);const t=this.data[this.index];return this.index=this.index+1|0,this.uses+=1,0|function(t){return t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^t>>>18}(t)}getUseCount(){return this.uses}discard(t){if(t<=0)return this;for(this.uses+=t,(0|this.index)>=K&&(Z(this.data),this.index=0);t+this.index>K;)t-=K-this.index,Z(this.data),this.index=0;return this.index=this.index+t|0,this}seed(t){let e=0;this.data[0]=e=0|t;for(let t=1;t<K;t=t+1|0)this.data[t]=e=U(e^e>>>30,1812433253)+t|0;return this.index=K,this.uses=0,this}seedWithArray(t){return this.seed(19650218),function(t,e){let r=1,n=0;const i=e.length;let o=0|Math.max(i,K),s=0|t[0];for(;(0|o)>0;--o)t[r]=s=(t[r]^U(s^s>>>30,1664525))+(0|e[n])+(0|n)|0,r=r+1|0,++n,(0|r)>W&&(t[0]=t[623],r=1),n>=i&&(n=0);for(o=W;(0|o)>0;--o)t[r]=s=(t[r]^U(s^s>>>30,1566083941))-r|0,r=r+1|0,(0|r)>W&&(t[0]=t[623],r=1);t[0]=l}(this.data,t),this}}function Z(t){let e=0,r=0;for(;(0|e)<227;e=e+1|0)r=t[e]&l|t[e+1|0]&c,t[e]=t[e+397|0]^r>>>1^(1&r?H:0);for(;(0|e)<W;e=e+1|0)r=t[e]&l|t[e+1|0]&c,t[e]=t[e-227|0]^r>>>1^(1&r?H:0);r=t[623]&l|t[0]&c,t[623]=t[396]^r>>>1^(1&r?H:0)}let X=null;let Q=128;const Y={next:()=>(Q>=128&&(X=new Int32Array(new Int8Array(require("crypto").randomBytes(512)).buffer),Q=0),0|X[Q++])},tt=Symbol("engine"),et=Symbol("random"),rt={browserCrypto:L,nodeCrypto:Y,MersenneTwister19937:MersenneTwister19937,nativeMath:k,min:{next:()=>0},max:{range:[],next(){return this.range[1]-this.range[0]}}};const nt=new class NumberGenerator{constructor(t=k){this.engine=t||k}get engine(){return this[tt]}set engine(t){if(t&&"function"!=typeof t.next)throw new TypeError("engine must have function `next()`");this[tt]=t||k,this[et]=new Random(this[tt])}integer(t,e){return this[tt].range=[t,e],this[et].integer(t,e)}real(t,e,r=!1){return this[tt].range=[t,e],this[et].real(t,e,r)}};var it=Object.freeze({__proto__:null,engines:rt,generator:nt});const ot=Symbol("operator"),st=Symbol("value");class ComparePoint{constructor(t,e){if(!t)throw new RequiredArgumentError("operator");if(!e&&0!==e)throw new RequiredArgumentError("value");this.operator=t,this.value=e}static isValidOperator(t){return"string"==typeof t&&/^(?:[<>!]?=|[<>]|<>)$/.test(t)}set operator(t){if(!this.constructor.isValidOperator(t))throw new CompareOperatorError(t);this[ot]=t}get operator(){return this[ot]}set value(t){if(!n(t))throw new TypeError("value must be a finite number");this[st]=Number(t)}get value(){return this[st]}isMatch(t){return((t,e,r)=>{const n=Number(t),i=Number(e);let o;if(Number.isNaN(n)||Number.isNaN(i))return!1;switch(r){case"=":case"==":o=n===i;break;case"<":o=n<i;break;case">":o=n>i;break;case"<=":o=n<=i;break;case">=":o=n>=i;break;case"!":case"!=":case"<>":o=n!==i;break;default:o=!1}return o})(t,this.value,this.operator)}toJSON(){const{operator:t,value:e}=this;return{operator:t,type:"compare-point",value:e}}toString(){return`${this.operator}${this.value}`}}class Modifier{static order=999;constructor(){this.order=this.constructor.order}get name(){return"modifier"}get notation(){return""}get maxIterations(){return 1e3}run(t,e){return t}toJSON(){const{notation:t,name:e}=this;return{name:e,notation:t,type:"modifier"}}toString(){return this.notation}}const at=Symbol("compare-point");class ComparisonModifier extends Modifier{constructor(t){super(),t&&(this.comparePoint=t)}get comparePoint(){return this[at]}set comparePoint(t){if(!(t instanceof ComparePoint))throw new TypeError("comparePoint must be instance of ComparePoint");this[at]=t}get name(){return"comparison"}get notation(){return`${this.comparePoint||""}`}isComparePoint(t){return!!this.comparePoint&&this.comparePoint.isMatch(t)}toJSON(){const{comparePoint:t}=this;return Object.assign(super.toJSON(),{comparePoint:t})}}const ut=Symbol("compound"),lt=Symbol("penetrate");class ExplodeModifier extends ComparisonModifier{static order=3;constructor(t=null,e=!1,r=!1){super(t),this[ut]=!!e,this[lt]=!!r}get compound(){return this[ut]}get name(){return"explode"}get notation(){return`!${this.compound?"!":""}${this.penetrate?"p":""}${super.notation}`}get penetrate(){return this[lt]}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"explode");const r=t;return r.rolls=t.rolls.map((t=>{const r=[t];let i=t.value;for(let t=0;t<this.maxIterations&&this.isComparePoint(i);t++){const t=r[r.length-1],n=e.rollOnce();i=n.value,t.modifiers.add("explode"),this.penetrate&&(t.modifiers.add("penetrate"),n.value-=1),r.push(n)}return this.compound&&r.length>1?(t.value=(o=r.map((t=>t.value)),Array.isArray(o)?o.reduce(((t,e)=>t+(n(e)?parseFloat(`${e}`):0)),0):0),t.modifiers=["explode","compound"],this.penetrate&&t.modifiers.add("penetrate"),t):r;var o})).flat(),r}toJSON(){const{compound:t,penetrate:e}=this;return Object.assign(super.toJSON(),{compound:t,penetrate:e})}}const ct=Symbol("text"),ht=Symbol("type");class Description{static types={MULTILINE:"multiline",INLINE:"inline"};constructor(t,e=this.constructor.types.INLINE){this.text=t,this.type=e}get text(){return this[ct]}set text(t){if("object"==typeof t)throw new TypeError("Description text is invalid");if(!t&&0!==t||""===`${t}`.trim())throw new TypeError("Description text cannot be empty");this[ct]=`${t}`.trim()}get type(){return this[ht]}set type(t){const e=Object.values(this.constructor.types);if("string"!=typeof t)throw new TypeError("Description type must be a string");if(!e.includes(t))throw new RangeError(`Description type must be one of; ${e.join(", ")}`);this[ht]=t}toJSON(){const{text:t,type:e}=this;return{text:t,type:e}}toString(){return this.type===this.constructor.types.INLINE?`# ${this.text}`:`[${this.text}]`}}const ft=Symbol("description");class HasDescription{constructor(t=null){this.description=t}get description(){return this[ft]||null}set description(t){if(t||0===t)if(t instanceof Description)this[ft]=t;else{if("string"!=typeof t)throw new TypeError("description must be of type Description, string or null. Received "+typeof t);this[ft]=new Description(t)}else this[ft]=null}toJSON(){const{description:t}=this;return{description:t}}toString(){return this.description?`${this.description}`:""}}const pt={compound:"!",explode:"!","critical-failure":"__","critical-success":"**",drop:"d",max:"v",min:"^",penetrate:"p","re-roll":"r","re-roll-once":"ro","target-failure":"_","target-success":"*",unique:"u","unique-once":"uo"},dt=(...t)=>[...t].reduce(((t,e)=>{let r;return r=e instanceof Modifier?e.name:e,t+(pt[r]||r)}),""),mt=Symbol("calculation-value"),gt=Symbol("modifiers"),yt=Symbol("initial-value"),wt=Symbol("use-in-total"),bt=Symbol("value");class RollResult{constructor(t,e=[],r=!0){if(n(t))this[yt]=Number(t),this.modifiers=e||[],this.useInTotal=r;else{if(!t||"object"!=typeof t||Array.isArray(t))throw t===1/0?new RangeError("Result value must be a finite number"):new TypeError(`Result value is invalid: ${t}`);{const i=n(t.initialValue)?t.initialValue:t.value;if(!n(i))throw new TypeError(`Result value is invalid: ${i}`);this[yt]=Number(i),n(t.value)&&Number(t.value)!==this[yt]&&(this.value=t.value),n(t.calculationValue)&&parseFloat(`${t.calculationValue}`)!==this.value&&(this.calculationValue=t.calculationValue),this.modifiers=t.modifiers||e||[],this.useInTotal="boolean"==typeof t.useInTotal?t.useInTotal:r||!1}}}get calculationValue(){return n(this[mt])?parseFloat(this[mt]):this.value}set calculationValue(t){const e=n(t);if(t===1/0)throw new RangeError("Result calculation value must be a finite number");if(t&&!e)throw new TypeError(`Result calculation value is invalid: ${t}`);this[mt]=e?parseFloat(`${t}`):null}get initialValue(){return this[yt]}get modifierFlags(){return dt(...this.modifiers)}get modifiers(){return this[gt]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[gt]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[gt]=new Set}}get useInTotal(){return!!this[wt]}set useInTotal(t){this[wt]=!!t}get value(){return n(this[bt])?this[bt]:this[yt]}set value(t){if(t===1/0)throw new RangeError("Result value must be a finite number");if(!n(t))throw new TypeError(`Result value is invalid: ${t}`);this[bt]=Number(t)}toJSON(){const{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:n,useInTotal:i,value:o}=this;return{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:[...n],type:"result",useInTotal:i,value:o}}toString(){return this.value+this.modifierFlags}}const xt=Symbol("rolls");class RollResults{constructor(t=[]){this.rolls=t}get length(){return this.rolls.length||0}get rolls(){return[...this[xt]]}set rolls(t){if(!t||!Array.isArray(t))throw new TypeError(`rolls must be an array: ${t}`);this[xt]=[],t.forEach((t=>{this.addRoll(t)}))}get value(){return this.rolls.reduce(((t,e)=>t+(e.useInTotal?e.calculationValue:0)),0)}addRoll(t){const e=t instanceof RollResult?t:new RollResult(t);this[xt].push(e)}toJSON(){const{rolls:t,value:e}=this;return{rolls:t,type:"roll-results",value:e}}toString(){return`[${this.rolls.join(", ")}]`}}const vt=Symbol("once");class ReRollModifier extends ComparisonModifier{static order=4;constructor(t=!1,e=null){super(e),this.once=!!t}get name(){return"re-roll"}get notation(){return`r${this.once?"o":""}${super.notation}`}get once(){return!!this[vt]}set once(t){this[vt]=!!t}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.map((t=>{for(let r=0;r<this.maxIterations&&this.isComparePoint(t.value);r++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("re-roll"+(this.once?"-once":"")),this.once)break}return t})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}const Et=Symbol("modifiers"),St=Symbol("qty"),At=Symbol("sides"),Rt=Symbol("min-value"),Mt=Symbol("max-value");class StandardDice extends HasDescription{constructor(t,e=1,r=null,o=1,s=null,a=null){if(super(a),!t&&0!==t)throw new RequiredArgumentError("sides");if(t===1/0)throw new RangeError("numerical sides must be finite number");if(n(t)){if(t<1||!i(t))throw new RangeError("numerical sides must be a positive finite number")}else if("string"!=typeof t)throw new TypeError("non-numerical sides must be a string");if(!n(e))throw new TypeError("qty must be a positive finite integer");if(e<1||e>999)throw new RangeError("qty must be between 1 and 999");let u=o;if(null==u)u=1;else{if(!n(u))throw new TypeError("min must a finite number");if(!i(u))throw new RangeError("min must a finite number")}if(s&&!n(s))throw new TypeError("max must a finite number");if(s&&!i(s))throw new RangeError("max must a finite number");this[St]=parseInt(`${e}`,10),this[At]=t,r&&(this.modifiers=r),this[Rt]=parseInt(u,10),this[Mt]=s?parseInt(`${s}`,10):t}get average(){return(this.min+this.max)/2}get modifiers(){return this[Et]?new Map([...this[Et]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[Et]=e,this[Et].forEach((t=>{t instanceof ExplodeModifier&&!t.comparePoint?t.comparePoint=new ComparePoint("=",this.max):t instanceof ReRollModifier&&!t.comparePoint&&(t.comparePoint=new ComparePoint("=",this.min))}))}get max(){return this[Mt]}get min(){return this[Rt]}get name(){return"standard"}get notation(){let t=`${this.qty}d${this.sides}`;return this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}get qty(){return this[St]}get sides(){return this[At]}roll(){const t=new RollResults;for(let e=0;e<this.qty;e++)t.addRoll(this.rollOnce());return(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}rollOnce(){return new RollResult(nt.integer(this.min,this.max))}toJSON(){const{average:t,max:e,min:r,modifiers:n,name:i,notation:o,qty:s,sides:a}=this;return Object.assign(super.toJSON(),{average:t,max:e,min:r,modifiers:n,name:i,notation:o,qty:s,sides:a,type:"die"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}class FudgeDice extends StandardDice{constructor(t=2,e=1,r=null,n=null){let i=t;if(i||0===i){if(1!==i&&2!==i)throw new RangeError("nonBlanks must be 1 or 2")}else i=2;super(i,e,r,-1,1,n)}get name(){return"fudge"}get nonBlanks(){return super.sides}get sides(){return`F.${this.nonBlanks}`}rollOnce(){let t=0;if(2===this.nonBlanks)t=nt.integer(1,3)-2;else if(1===this.nonBlanks){const e=nt.integer(1,6);1===e?t=-1:6===e&&(t=1)}return new RollResult(t)}}class PercentileDice extends StandardDice{constructor(t=1,e=null,r=!1,n=null){super(100,t,e,null,null,n),this.sidesAsNumber=!!r}get name(){return"percentile"}get sides(){return this.sidesAsNumber?super.sides:"%"}}var Ct=Object.freeze({__proto__:null,FudgeDice:FudgeDice,PercentileDice:PercentileDice,StandardDice:StandardDice});class CriticalFailureModifier extends ComparisonModifier{static order=10;constructor(t){super(t)}get name(){return"critical-failure"}get notation(){return`cf${super.notation}`}run(t,e){return t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-failure"),t))),t}}class CriticalSuccessModifier extends ComparisonModifier{static order=9;constructor(t){super(t)}get name(){return"critical-success"}get notation(){return`cs${super.notation}`}run(t,e){return t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-success"),t))),t}}const Tt=Symbol("calculation-value"),Nt=Symbol("is-roll-group"),Ot=Symbol("modifiers"),$t=Symbol("results"),Dt=Symbol("use-in-total");class ResultGroup{constructor(t=[],e=[],r=!1,n=!0){this.isRollGroup=r,this.modifiers=e,this.results=t,this.useInTotal=n}get calculationValue(){return n(this[Tt])?parseFloat(this[Tt]):this.value}set calculationValue(t){const e=n(t);if(t===1/0)throw new RangeError("Results calculation value must be a finite number");if(t&&!e)throw new TypeError(`Results calculation value is invalid: ${t}`);this[Tt]=e?parseFloat(`${t}`):null}get isRollGroup(){return this[Nt]}set isRollGroup(t){this[Nt]=!!t}get length(){return this.results.length||0}get modifierFlags(){return dt(...this.modifiers)}get modifiers(){return this[Ot]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[Ot]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[Ot]=new Set}}get results(){return[...this[$t]]}set results(t){if(!t||!Array.isArray(t))throw new TypeError(`results must be an array: ${t}`);this[$t]=[],t.forEach((t=>{this.addResult(t)}))}get useInTotal(){return!!this[Dt]}set useInTotal(t){this[Dt]=!!t}get value(){if(!this.results.length)return 0;const t=this.results.reduce(((t,e)=>{let r=e;return e instanceof ResultGroup?r=e.useInTotal?e.calculationValue:0:e instanceof RollResults&&(r=e.value),t+r}),"string"==typeof this.results[0]?"":0);return"string"==typeof t?r(t):t}addResult(t){let e;if(t instanceof ResultGroup||t instanceof RollResults)e=t;else{if("string"!=typeof t&&!n(t))throw new TypeError("value must be one of ResultGroup, RollResults, string, or number");e=t}this[$t].push(e)}toJSON(){const{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:n,results:i,useInTotal:o,value:s}=this;return{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:[...n],results:i,type:"result-group",useInTotal:o,value:s}}toString(){let t;return t=this.isRollGroup?`{${this.results.join(", ")}}`:this.results.join(""),this.modifierFlags&&(t=`(${t})${this.modifierFlags}`),t}}const Ft=Symbol("end"),Pt=Symbol("qty");class KeepModifier extends Modifier{static order=6;constructor(t="h",e=1){super(),this.end=t,this.qty=e}get end(){return this[Ft]}set end(t){if("h"!==t&&"l"!==t)throw new RangeError('End must be "h" or "l"');this[Ft]=t}get name(){return`keep-${this.end}`}get notation(){return`k${this.end}${this.qty}`}get qty(){return this[Pt]}set qty(t){if(t===1/0)throw new RangeError("qty must be a finite number");if(!n(t)||t<1)throw new TypeError("qty must be a positive finite integer");this[Pt]=Math.floor(t)}rangeToDrop(t){return"h"===this.end?[0,t.length-this.qty]:[this.qty,t.length]}run(t,e){let r,n;return t instanceof ResultGroup?(r=t.results,n=1===r.length&&r[0]instanceof ResultGroup?r[0].results.map(((t,e)=>t instanceof RollResults?t.rolls.map(((t,r)=>({value:t.value,index:[e,r]}))):null)).flat().filter(Boolean):[...r].map(((t,e)=>({value:t.value,index:e})))):(r=t.rolls,n=[...r].map(((t,e)=>({value:t.value,index:e})))),n=n.sort(((t,e)=>t.value-e.value)).map((t=>t.index)).slice(...this.rangeToDrop(n)),n.forEach((t=>{let e;e=Array.isArray(t)?r[0].results[t[0]].rolls[t[1]]:r[t],e.modifiers.add("drop"),e.useInTotal=!1})),t}toJSON(){const{end:t,qty:e}=this;return Object.assign(super.toJSON(),{end:t,qty:e})}}class DropModifier extends KeepModifier{static order=7;constructor(t="l",e=1){super(t,e)}get name(){return`drop-${this.end}`}get notation(){return`d${this.end}${this.qty}`}rangeToDrop(t){return"h"===this.end?[t.length-this.qty,t.length]:[0,this.qty]}}const It=Symbol("max");class MaxModifier extends Modifier{static order=2;constructor(t){super(),this.max=t}get max(){return this[It]}set max(t){if(!n(t))throw new TypeError("max must be a number");this[It]=parseFloat(`${t}`)}get name(){return"max"}get notation(){return`max${this.max}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value>this.max&&(e.value=this.max,e.modifiers.add("max")),e})),r}toJSON(){const{max:t}=this;return Object.assign(super.toJSON(),{max:t})}}const Jt=Symbol("min");class MinModifier extends Modifier{static order=1;constructor(t){super(),this.min=t}get min(){return this[Jt]}set min(t){if(!n(t))throw new TypeError("min must be a number");this[Jt]=parseFloat(`${t}`)}get name(){return"min"}get notation(){return`min${this.min}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value<this.min&&(e.value=this.min,e.modifiers.add("min")),e})),r}toJSON(){const{min:t}=this;return Object.assign(super.toJSON(),{min:t})}}const jt=Symbol("direction");class SortingModifier extends Modifier{static order=11;constructor(t="a"){super(),this.direction=t}get direction(){return this[jt]}set direction(t){if("a"!==t&&"d"!==t)throw new RangeError('Direction must be "a" (Ascending) or "d" (Descending)');this[jt]=t}get name(){return"sorting"}get notation(){return`s${this.direction}`}run(t,e){let r;return r=t instanceof ResultGroup?"results":"rolls",t[r]=t[r].sort(((t,e)=>"d"===this.direction?e.value-t.value:t.value-e.value)),t instanceof ResultGroup&&(t[r]=t[r].map((t=>t instanceof ResultGroup||t instanceof RollResults?this.run(t,e):t))),t}toJSON(){const{direction:t}=this;return Object.assign(super.toJSON(),{direction:t})}}const qt=Symbol("failure-cp");class TargetModifier extends ComparisonModifier{static order=8;constructor(t,e=null){super(t),this.failureComparePoint=e}get failureComparePoint(){return this[qt]}set failureComparePoint(t){if(t&&!(t instanceof ComparePoint))throw new TypeError("failure comparePoint must be instance of ComparePoint or null");this[qt]=t||null}get name(){return"target"}get notation(){return`${super.notation}${this.failureComparePoint?`f${this.failureComparePoint}`:""}`}get successComparePoint(){return this.comparePoint}set successComparePoint(t){super.comparePoint=t}getStateValue(t){return this.isSuccess(t)?1:this.isFailure(t)?-1:0}isFailure(t){return!!this.failureComparePoint&&this.failureComparePoint.isMatch(t)}isNeutral(t){return!this.isSuccess(t)&&!this.isFailure(t)}isSuccess(t){return this.isComparePoint(t)}run(t,e){let r;return r=t instanceof ResultGroup?t.results:t.rolls,r.forEach((t=>{this.isSuccess(t.value)?t.modifiers.add("target-success"):this.isFailure(t.value)&&t.modifiers.add("target-failure"),t.calculationValue=this.getStateValue(t.value)})),t}toJSON(){const{failureComparePoint:t,successComparePoint:e}=this,r=super.toJSON();return delete r.comparePoint,Object.assign(r,{failureComparePoint:t,successComparePoint:e})}}const Gt=Symbol("once"),Vt=(t,e,r,n=!1)=>{const i=r.map((t=>t.value)).indexOf(t.value);return n?i<e:i!==e};class UniqueModifier extends ComparisonModifier{static order=5;constructor(t=!1,e=null){super(e),this.once=!!t}get name(){return"unique"}get notation(){return`u${this.once?"o":""}${super.notation}`}get once(){return!!this[Gt]}set once(t){this[Gt]=!!t}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.forEach(((t,r,n)=>{if(0!==r)for(let i=0;i<this.maxIterations&&(!this.comparePoint||this.isComparePoint(t.value))&&Vt(t,r,n,!0);i++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("unique"+(this.once?"-once":"")),this.once)break}})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}var kt=Object.freeze({__proto__:null,ComparisonModifier:ComparisonModifier,CriticalFailureModifier:CriticalFailureModifier,CriticalSuccessModifier:CriticalSuccessModifier,DropModifier:DropModifier,ExplodeModifier:ExplodeModifier,KeepModifier:KeepModifier,MaxModifier:MaxModifier,MinModifier:MinModifier,Modifier:Modifier,ReRollModifier:ReRollModifier,SortingModifier:SortingModifier,TargetModifier:TargetModifier,UniqueModifier:UniqueModifier}),_t=Object.freeze({__proto__:null,ResultGroup:ResultGroup,RollResult:RollResult,RollResults:RollResults});const Bt=t=>{try{return!(!t||btoa(atob(t))!==t)}catch(t){return!1}},zt=t=>{try{const e=!!t&&JSON.parse(t);return!(!e||"object"!=typeof e)}catch(t){return!1}},Lt=Symbol("expressions"),Ut=Symbol("modifiers");class RollGroup extends HasDescription{constructor(t=[],e=[],r=null){super(r),this.expressions=t,this.modifiers=e}get expressions(){return[...this[Lt]||[]]}set expressions(t){if(!t)throw new RequiredArgumentError("expressions");if(!Array.isArray(t))throw new TypeError(`expressions must be an array: ${t}`);this[Lt]=[],t.forEach((e=>{if(!e||!Array.isArray(e))throw new TypeError(`Expressions must be an array of arrays: ${t}`);if(0===e.length)throw new TypeError(`Sub expressions cannot be empty: ${t}`);if(!e.every((t=>t instanceof StandardDice||"string"==typeof t||"number"==typeof t)))throw new TypeError("Sub expression items must be Dice, numbers, or strings");this[Lt].push(e)}))}get modifiers(){return this[Ut]?new Map([...this[Ut]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[Ut]=e}get notation(){let t=this.expressions.map((t=>t.reduce(((t,e)=>t+e),""))).join(", ");return t=`{${t}}`,this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}roll(){const t=new ResultGroup(this.expressions.map((t=>{const e=t.map((t=>t instanceof StandardDice?t.roll():t));return new ResultGroup(e)})));return t.isRollGroup=!0,(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}toJSON(){const{modifiers:t,notation:e,expressions:r}=this;return Object.assign(super.toJSON(),{expressions:r,modifiers:t,notation:e,type:"group"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}function Kt(t,e,r,n){var i=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(i,Kt.prototype),i.expected=e,i.found=r,i.location=n,i.name="SyntaxError",i}function Wt(t,e,r){return r=r||" ",t.length>e?t:(e-=t.length,t+(r+=r.repeat(e)).slice(0,e))}function Ht(t,e){var n,i,o,s,a={},u=(e=void 0!==e?e:{}).grammarSource,l={Main:vr},c=vr,h="{",f=",",p="}",d="d",m="d%",g="dF",y=".",w="!",b="p",x="k",v="max",E="min",S="r",A="o",R="u",M="cs",C="cf",T="s",N="a",O="f",$="!=",D="<=",F=">=",P="=",I="<>",J=">",j="<",q="(",G=")",V="abs",k="ceil",_="cos",B="exp",z="floor",L="log",U="round",K="sign",W="sin",H="sqrt",Z="tan",X="pow",Q="-",Y="**",tt="*",et="^",rt="%",nt="/",it="+",ot="/*",st="*/",at="[",ut="]",lt="//",ct="#",ht=/^[12]/,ft=/^[lh]/,pt=/^[.]/,dt=/^[1-9]/,mt=/^[0-9]/,gt=/^[^\]]/,yt=/^[\n\r\u2028\u2029]/,wt=/^[ \t\n\r]/,bt=mr("{",!1),xt=mr(",",!1),vt=mr("}",!1),Et=mr("d",!1),St=mr("d%",!1),At=mr("dF",!1),Rt=mr(".",!1),Mt=gr(["1","2"],!1,!1),Ct=mr("!",!1),Tt=mr("p",!1),Nt=gr(["l","h"],!1,!1),Ot=mr("k",!1),$t=mr("max",!1),Dt=mr("min",!1),Ft=mr("r",!1),Pt=mr("o",!1),It=mr("u",!1),Jt=mr("cs",!1),jt=mr("cf",!1),qt=mr("s",!1),Gt=mr("a",!1),Vt=mr("f",!1),kt=mr("!=",!1),_t=mr("<=",!1),Bt=mr(">=",!1),zt=mr("=",!1),Lt=mr("<>",!1),Ut=mr(">",!1),Wt=mr("<",!1),Ht=mr("(",!1),Zt=mr(")",!1),Xt=mr("abs",!1),Qt=mr("ceil",!1),Yt=mr("cos",!1),te=mr("exp",!1),ee=mr("floor",!1),re=mr("log",!1),ne=mr("round",!1),ie=mr("sign",!1),oe=mr("sin",!1),se=mr("sqrt",!1),ae=mr("tan",!1),ue=mr("pow",!1),le=mr("-",!1),ce=gr(["."],!1,!1),he=gr([["1","9"]],!1,!1),fe=gr([["0","9"]],!1,!1),pe=mr("**",!1),de=mr("*",!1),me=mr("^",!1),ge=mr("%",!1),ye=mr("/",!1),we=mr("+",!1),be=yr("comment"),xe=mr("/*",!1),ve=mr("*/",!1),Ee={type:"any"},Se=mr("[",!1),Ae=gr(["]"],!0,!1),Re=mr("]",!1),Me=mr("//",!1),Ce=mr("#",!1),Te=gr(["\n","\r","\u2028","\u2029"],!1,!1),Ne=yr("whitespace"),Oe=gr([" ","\t","\n","\r"],!1,!1),$e=yr("whitespace or comment"),De=function(t,e,r,n){return new RollGroup([t,...e.map((t=>t[3]))],Object.assign({},...r.map((t=>({[t.name]:t})))),n.find((t=>t instanceof Description)))},Fe=function(t,e,r){return t.modifiers=Object.assign({},...e.map((t=>({[t.name]:t})))),t.description=r.find((t=>t instanceof Description)),t},Pe=function(t,e){return new StandardDice(e,t||1)},Ie=function(t){return new PercentileDice(t||1)},Je=function(t,e){return new FudgeDice(e?parseInt(e[1],10):2,t||1)},je=function(t,e,r){return new ExplodeModifier(r,!!t,!!e)},qe=function(t,e){return new TargetModifier(t,e)},Ge=function(t,e){return new DropModifier(t||"l",e)},Ve=function(t,e){return new KeepModifier(t||"h",e)},ke=function(t){return new MaxModifier(t)},_e=function(t){return new MinModifier(t)},Be=function(t,e){return new ReRollModifier(!!t,e)},ze=function(t,e){return new UniqueModifier(!!t,e)},Le=function(t){return new CriticalSuccessModifier(t)},Ue=function(t){return new CriticalFailureModifier(t)},Ke=function(t){return new SortingModifier(t||"a")},We=function(t){return t},He=function(t,e){return new ComparePoint(t,e)},Ze=function(t,e,n){return r(dr())},Xe=function(t,e){return t=Array.isArray(t)?t:[t],[...t,...e.map((([,t,,e])=>[t,e])).flat(2)]},Qe=function(t,e,r){return[t,...e,r]},Ye=function(t,e){return[`${t}(`,...e,")"]},tr=function(t,e,r){return[`${t}(`,...e,",",...r,")"]},er=function(){return parseFloat(dr())},rr=function(){return parseInt(dr(),10)},nr=function(){return parseInt(dr(),10)},ir=function(){return"^"},or=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},sr=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},ar=function(t){return new Description(t.flat().join(""),Description.types.INLINE)},ur=0,lr=0,cr=[{line:1,column:1}],hr=0,fr=[],pr=0;if("startRule"in e){if(!(e.startRule in l))throw new Error("Can't start parsing from rule \""+e.startRule+'".');c=l[e.startRule]}function dr(){return t.substring(lr,ur)}function mr(t,e){return{type:"literal",text:t,ignoreCase:e}}function gr(t,e,r){return{type:"class",parts:t,inverted:e,ignoreCase:r}}function yr(t){return{type:"other",description:t}}function wr(e){var r,n=cr[e];if(n)return n;for(r=e-1;!cr[r];)r--;for(n={line:(n=cr[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return cr[e]=n,n}function br(t,e){var r=wr(t),n=wr(e);return{source:u,start:{offset:t,line:r.line,column:r.column},end:{offset:e,line:n.line,column:n.column}}}function xr(t){ur<hr||(ur>hr&&(hr=ur,fr=[]),fr.push(t))}function vr(){return Mr()}function Er(){var e,r,n,i;if(e=ur,r=function(){var e,r,n,i;e=ur,r=Rr(),r===a&&(r=null);100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&xr(Et));n!==a&&(i=Rr())!==a?(lr=e,e=Pe(r,i)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n;e=ur,r=Rr(),r===a&&(r=null);t.substr(ur,2)===m?(n=m,ur+=2):(n=a,0===pr&&xr(St));n!==a?(lr=e,e=Ie(r)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n,i,o,s;e=ur,r=Rr(),r===a&&(r=null);t.substr(ur,2)===g?(n=g,ur+=2):(n=a,0===pr&&xr(At));n!==a?(i=ur,46===t.charCodeAt(ur)?(o=y,ur++):(o=a,0===pr&&xr(Rt)),o!==a?(ht.test(t.charAt(ur))?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Mt)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a),i===a&&(i=null),lr=e,e=Je(r,i)):(ur=e,e=a);return e}())),r!==a){for(n=[],i=Sr();i!==a;)n.push(i),i=Sr();i=Jr(),lr=e,e=Fe(r,n,i)}else ur=e,e=a;return e}function Sr(){var e;return(e=function(){var e,r,n,i,o;e=ur,33===t.charCodeAt(ur)?(r=w,ur++):(r=a,0===pr&&xr(Ct));r!==a?(33===t.charCodeAt(ur)?(n=w,ur++):(n=a,0===pr&&xr(Ct)),n===a&&(n=null),112===t.charCodeAt(ur)?(i=b,ur++):(i=a,0===pr&&xr(Tt)),i===a&&(i=null),(o=Ar())===a&&(o=null),lr=e,e=je(n,i,o)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,(r=Ar())!==a?(n=function(){var e,r,n;e=ur,102===t.charCodeAt(ur)?(r=O,ur++):(r=a,0===pr&&xr(Vt));r!==a&&(n=Ar())!==a?(lr=e,e=We(n)):(ur=e,e=a);return e}(),n===a&&(n=null),lr=e,e=qe(r,n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,100===t.charCodeAt(ur)?(r=d,ur++):(r=a,0===pr&&xr(Et));r!==a?(ft.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(Nt)),n===a&&(n=null),(i=Nr())!==a?(lr=e,e=Ge(n,i)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,107===t.charCodeAt(ur)?(r=x,ur++):(r=a,0===pr&&xr(Ot));r!==a?(ft.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(Nt)),n===a&&(n=null),(i=Nr())!==a?(lr=e,e=Ve(n,i)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,114===t.charCodeAt(ur)?(r=S,ur++):(r=a,0===pr&&xr(Ft));r!==a?(111===t.charCodeAt(ur)?(n=A,ur++):(n=a,0===pr&&xr(Pt)),n===a&&(n=null),(i=Ar())===a&&(i=null),lr=e,e=Be(n,i)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,117===t.charCodeAt(ur)?(r=R,ur++):(r=a,0===pr&&xr(It));r!==a?(111===t.charCodeAt(ur)?(n=A,ur++):(n=a,0===pr&&xr(Pt)),n===a&&(n=null),(i=Ar())===a&&(i=null),lr=e,e=ze(n,i)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===M?(r=M,ur+=2):(r=a,0===pr&&xr(Jt));r!==a&&(n=Ar())!==a?(lr=e,e=Le(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===C?(r=C,ur+=2):(r=a,0===pr&&xr(jt));r!==a&&(n=Ar())!==a?(lr=e,e=Ue(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,115===t.charCodeAt(ur)?(r=T,ur++):(r=a,0===pr&&xr(qt));r!==a?(97===t.charCodeAt(ur)?(n=N,ur++):(n=a,0===pr&&xr(Gt)),n===a&&(100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&xr(Et))),n===a&&(n=null),lr=e,e=Ke(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===v?(r=v,ur+=3):(r=a,0===pr&&xr($t));r!==a&&(n=Tr())!==a?(lr=e,e=ke(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&xr(Dt));r!==a&&(n=Tr())!==a?(lr=e,e=_e(n)):(ur=e,e=a);return e}()),e}function Ar(){var e,r,n;return e=ur,r=function(){var e;t.substr(ur,2)===$?(e=$,ur+=2):(e=a,0===pr&&xr(kt));e===a&&(t.substr(ur,2)===D?(e=D,ur+=2):(e=a,0===pr&&xr(_t)),e===a&&(t.substr(ur,2)===F?(e=F,ur+=2):(e=a,0===pr&&xr(Bt)),e===a&&(61===t.charCodeAt(ur)?(e=P,ur++):(e=a,0===pr&&xr(zt)),e===a&&(t.substr(ur,2)===I?(e=I,ur+=2):(e=a,0===pr&&xr(Lt)),e===a&&(62===t.charCodeAt(ur)?(e=J,ur++):(e=a,0===pr&&xr(Ut)),e===a&&(60===t.charCodeAt(ur)?(e=j,ur++):(e=a,0===pr&&xr(Wt))))))));return e}(),r!==a&&(n=Tr())!==a?(lr=e,e=He(r,n)):(ur=e,e=a),e}function Rr(){var e,r,n,i,o,s,u,l,c,h;if((e=Nr())===a)if(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&xr(Ht)),r!==a){if(Ir(),n=ur,(i=Tr())!==a){if(o=[],s=ur,u=Ir(),(l=$r())!==a?(c=Ir(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a),s!==a)for(;s!==a;)o.push(s),s=ur,u=Ir(),(l=$r())!==a?(c=Ir(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a);else o=a;o!==a?n=i=[i,o]:(ur=n,n=a)}else ur=n,n=a;n!==a?(i=Ir(),41===t.charCodeAt(ur)?(o=G,ur++):(o=a,0===pr&&xr(Zt)),o!==a?(lr=e,e=Ze()):(ur=e,e=a)):(ur=e,e=a)}else ur=e,e=a;return e}function Mr(){var t,e,r,n,i,o,s,u;if(t=ur,(e=Cr())!==a){for(r=[],n=ur,i=Ir(),(o=$r())!==a?(s=Ir(),(u=Cr())!==a?n=i=[i,o,s,u]:(ur=n,n=a)):(ur=n,n=a);n!==a;)r.push(n),n=ur,i=Ir(),(o=$r())!==a?(s=Ir(),(u=Cr())!==a?n=i=[i,o,s,u]:(ur=n,n=a)):(ur=n,n=a);lr=t,t=Xe(e,r)}else ur=t,t=a;return t}function Cr(){var e,r,n,i;return e=function(){var e,r,n,i,o,s,u;e=ur,t.substr(ur,3)===V?(r=V,ur+=3):(r=a,0===pr&&xr(Xt));r===a&&(t.substr(ur,4)===k?(r=k,ur+=4):(r=a,0===pr&&xr(Qt)),r===a&&(t.substr(ur,3)===_?(r=_,ur+=3):(r=a,0===pr&&xr(Yt)),r===a&&(t.substr(ur,3)===B?(r=B,ur+=3):(r=a,0===pr&&xr(te)),r===a&&(t.substr(ur,5)===z?(r=z,ur+=5):(r=a,0===pr&&xr(ee)),r===a&&(t.substr(ur,3)===L?(r=L,ur+=3):(r=a,0===pr&&xr(re)),r===a&&(t.substr(ur,5)===U?(r=U,ur+=5):(r=a,0===pr&&xr(ne)),r===a&&(t.substr(ur,4)===K?(r=K,ur+=4):(r=a,0===pr&&xr(ie)),r===a&&(t.substr(ur,3)===W?(r=W,ur+=3):(r=a,0===pr&&xr(oe)),r===a&&(t.substr(ur,4)===H?(r=H,ur+=4):(r=a,0===pr&&xr(se)),r===a&&(t.substr(ur,3)===Z?(r=Z,ur+=3):(r=a,0===pr&&xr(ae))))))))))));r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&xr(Ht)),n!==a?(Ir(),(i=Mr())!==a?(Ir(),41===t.charCodeAt(ur)?(o=G,ur++):(o=a,0===pr&&xr(Zt)),o!==a?(lr=e,e=Ye(r,i)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a);e===a&&(e=ur,t.substr(ur,3)===X?(r=X,ur+=3):(r=a,0===pr&&xr(ue)),r===a&&(t.substr(ur,3)===v?(r=v,ur+=3):(r=a,0===pr&&xr($t)),r===a&&(t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&xr(Dt)))),r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&xr(Ht)),n!==a?(Ir(),(i=Mr())!==a?(Ir(),44===t.charCodeAt(ur)?(o=f,ur++):(o=a,0===pr&&xr(xt)),o!==a?(Ir(),(s=Mr())!==a?(Ir(),41===t.charCodeAt(ur)?(u=G,ur++):(u=a,0===pr&&xr(Zt)),u!==a?(lr=e,e=tr(r,i,s)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a));return e}(),e===a&&(e=Er())===a&&(e=Tr())===a&&(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&xr(Ht)),r!==a?(Ir(),(n=Mr())!==a?(Ir(),41===t.charCodeAt(ur)?(i=G,ur++):(i=a,0===pr&&xr(Zt)),i!==a?(lr=e,e=Qe(r,n,i)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a),e===a&&(e=function(){var e,r,n,i,o,s,u,l,c;if(e=ur,123===t.charCodeAt(ur)?(r=h,ur++):(r=a,0===pr&&xr(bt)),r!==a)if(Ir(),(n=Mr())!==a){for(i=[],o=ur,s=Ir(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&xr(xt)),u!==a?(l=Ir(),(c=Mr())!==a?o=s=[s,u,l,c]:(ur=o,o=a)):(ur=o,o=a);o!==a;)i.push(o),o=ur,s=Ir(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&xr(xt)),u!==a?(l=Ir(),(c=Mr())!==a?o=s=[s,u,l,c]:(ur=o,o=a)):(ur=o,o=a);if(o=Ir(),125===t.charCodeAt(ur)?(s=p,ur++):(s=a,0===pr&&xr(vt)),s!==a){for(u=[],l=Sr();l!==a;)u.push(l),l=Sr();l=Jr(),lr=e,e=De(n,i,u,l)}else ur=e,e=a}else ur=e,e=a;else ur=e,e=a;return e}())),e}function Tr(){var e,r,n,i;return e=ur,45===t.charCodeAt(ur)?ur++:0===pr&&xr(le),Or()!==a?(r=ur,pt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(ce)),n!==a&&(i=Or())!==a?r=n=[n,i]:(ur=r,r=a),r===a&&(r=null),lr=e,e=er()):(ur=e,e=a),e}function Nr(){var e,r,n,i;if(e=ur,dt.test(t.charAt(ur))?(r=t.charAt(ur),ur++):(r=a,0===pr&&xr(he)),r!==a){for(n=[],mt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(fe));i!==a;)n.push(i),mt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(fe));lr=e,e=rr()}else ur=e,e=a;return e}function Or(){var e,r,n;if(e=ur,r=[],mt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(fe)),n!==a)for(;n!==a;)r.push(n),mt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(fe));else r=a;return r!==a&&(lr=e,r=nr()),e=r}function $r(){var e,r;return e=ur,t.substr(ur,2)===Y?(r=Y,ur+=2):(r=a,0===pr&&xr(pe)),r!==a&&(lr=e,r=ir()),(e=r)===a&&(42===t.charCodeAt(ur)?(e=tt,ur++):(e=a,0===pr&&xr(de)),e===a&&(94===t.charCodeAt(ur)?(e=et,ur++):(e=a,0===pr&&xr(me)),e===a&&(37===t.charCodeAt(ur)?(e=rt,ur++):(e=a,0===pr&&xr(ge)),e===a&&(47===t.charCodeAt(ur)?(e=nt,ur++):(e=a,0===pr&&xr(ye)),e===a&&(43===t.charCodeAt(ur)?(e=it,ur++):(e=a,0===pr&&xr(we)),e===a&&(45===t.charCodeAt(ur)?(e=Q,ur++):(e=a,0===pr&&xr(le)))))))),e}function Dr(){var e;return pr++,(e=function(){var e,r,n,i,o,s;e=ur,t.substr(ur,2)===ot?(r=ot,ur+=2):(r=a,0===pr&&xr(xe));if(r!==a){for(n=[],i=ur,o=ur,pr++,t.substr(ur,2)===st?(s=st,ur+=2):(s=a,0===pr&&xr(ve)),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);i!==a;)n.push(i),i=ur,o=ur,pr++,t.substr(ur,2)===st?(s=st,ur+=2):(s=a,0===pr&&xr(ve)),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);t.substr(ur,2)===st?(i=st,ur+=2):(i=a,0===pr&&xr(ve)),i!==a?(lr=e,e=or(n)):(ur=e,e=a)}else ur=e,e=a;if(e===a)if(e=ur,91===t.charCodeAt(ur)?(r=at,ur++):(r=a,0===pr&&xr(Se)),r!==a){for(n=[],gt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(Ae));i!==a;)n.push(i),gt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(Ae));93===t.charCodeAt(ur)?(i=ut,ur++):(i=a,0===pr&&xr(Re)),i!==a?(lr=e,e=sr(n)):(ur=e,e=a)}else ur=e,e=a;return e}())===a&&(e=function(){var e,r,n,i,o,s;e=ur,t.substr(ur,2)===lt?(r=lt,ur+=2):(r=a,0===pr&&xr(Me));r===a&&(35===t.charCodeAt(ur)?(r=ct,ur++):(r=a,0===pr&&xr(Ce)));if(r!==a){for(n=[],i=ur,o=ur,pr++,s=Fr(),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);i!==a;)n.push(i),i=ur,o=ur,pr++,s=Fr(),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);lr=e,e=ar(n)}else ur=e,e=a;return e}()),pr--,e===a&&0===pr&&xr(be),e}function Fr(){var e;return yt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&xr(Te)),e}function Pr(){var e;return pr++,wt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&xr(Oe)),pr--,e===a&&0===pr&&xr(Ne),e}function Ir(){var t,e;for(t=[],e=Pr();e!==a;)t.push(e),e=Pr();return t}function Jr(){var t,e;for(pr++,t=[],(e=Pr())===a&&(e=Dr());e!==a;)t.push(e),(e=Pr())===a&&(e=Dr());return pr--,e=a,0===pr&&xr($e),t}if((n=c())!==a&&ur===t.length)return n;throw n!==a&&ur<t.length&&xr({type:"end"}),i=fr,o=hr<t.length?t.charAt(hr):null,s=hr<t.length?br(hr,hr+1):br(hr,hr),new Kt(Kt.buildMessage(i,o),i,o,s)}!function(t,e){function r(){this.constructor=t}r.prototype=e.prototype,t.prototype=new r}(Kt,Error),Kt.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var r,n=null;for(r=0;r<t.length;r++)if(t[r].source===this.location.source){n=t[r].text.split(/\r\n|\n|\r/g);break}var i=this.location.start,o=this.location.source+":"+i.line+":"+i.column;if(n){var s=this.location.end,a=Wt("",i.line.toString().length," "),u=n[i.line-1],l=(i.line===s.line?s.column:u.length+1)-i.column||1;e+="\n --\x3e "+o+"\n"+a+" |\n"+i.line+" | "+u+"\n"+a+" | "+Wt("",i.column-1," ")+Wt("",l,"^")}else e+="\n at "+o}return e},Kt.buildMessage=function(t,e){var r={literal:function(t){return'"'+i(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?o(t[0])+"-"+o(t[1]):o(t)}));return"["+(t.inverted?"^":"")+e.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function i(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function o(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function s(t){return r[t.type](t)}return"Expected "+function(t){var e,r,n=t.map(s);if(n.sort(),n.length>0){for(e=1,r=1;e<n.length;e++)n[e-1]!==n[e]&&(n[r]=n[e],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(t)+" but "+function(t){return t?'"'+i(t)+'"':"end of input"}(e)+" found."};class Parser{static parse(t){if(!t)throw new RequiredArgumentError("notation");if("string"!=typeof t)throw new TypeError("Notation must be a string");return Ht(t)}}const Zt=Object.freeze({BASE_64:1,JSON:0,OBJECT:2}),Xt=Symbol("notation"),Qt=Symbol("maxTotal"),Yt=Symbol("minTotal"),te=Symbol("expressions"),ee=Symbol("roll-method"),re=Symbol("rolls"),ne=Symbol("set-rolls"),ie=Symbol("total"),oe=t=>((t,e=0)=>parseFloat(parseFloat(`${t}`).toFixed(e||0)))(t.calculationValue,2);class DiceRoll{constructor(t){if(!t)throw new RequiredArgumentError("notation");if(this[te]=[],t instanceof Object&&!Array.isArray(t)){if(!t.notation)throw new RequiredArgumentError("notation");if("string"!=typeof t.notation)throw new NotationError(t.notation);t.rolls&&this[ne](t.rolls),this[Xt]=t.notation,this[te]=Parser.parse(this.notation),this.hasRolls()||this.roll()}else{if("string"!=typeof t)throw new NotationError(t);this[Xt]=t,this[te]=Parser.parse(this.notation),this.roll()}}get averageTotal(){return(this.maxTotal+this.minTotal)/2}get maxTotal(){if(!this.hasExpressions())return 0;if(!this[Qt]){const t=this[ee](rt.max);this[Qt]=oe(t)}return this[Qt]}get minTotal(){if(!this.hasExpressions())return 0;if(!this[Yt]){const t=this[ee](rt.min);this[Yt]=oe(t)}return this[Yt]}get notation(){return this[Xt]}get output(){let t=`${this.notation}: `;return this.hasRolls()?t+=`${this[re]} = ${this.total}`:t+="No dice rolled",t}get rolls(){return this[re]?this[re].results:[]}get total(){return!this[ie]&&this.hasRolls()&&(this[ie]=oe(this[re])),this[ie]||0}export(t=Zt.JSON){switch(t){case Zt.BASE_64:return btoa(this.export(Zt.JSON));case Zt.JSON:return JSON.stringify(this);case Zt.OBJECT:return JSON.parse(this.export(Zt.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}hasExpressions(){return this[te]&&this[te].length>0}hasRolls(){return this.hasExpressions()&&this.rolls.length>0}roll(){return this[ie]=0,this[re]=this[ee](),this.rolls}toJSON(){const{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:i,rolls:o,total:s}=this;return{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:i,rolls:o,total:s,type:"dice-roll"}}toString(){return this.output}static import(t){if(t){if(zt(t))return DiceRoll.import(JSON.parse(t));if(Bt(t))return DiceRoll.import(atob(t));if("object"==typeof t)return new DiceRoll(t);throw new DataFormatError(t)}throw new RequiredArgumentError("data")}[ee](t){let e;t&&(e=nt.engine,nt.engine=t);const r=new ResultGroup(this[te].map((t=>t instanceof StandardDice||t instanceof RollGroup?t.roll():t)).filter((t=>!!t||0===t)));return t&&(nt.engine=e),r}[ne](t){if(t instanceof ResultGroup)this[re]=t;else if(t instanceof RollResults)this[re]=new ResultGroup([t]);else{if(!Array.isArray(t))throw new TypeError("Rolls must be a valid result object, or an array");this[re]=new ResultGroup(t.map((t=>{if(t instanceof ResultGroup||t instanceof RollResults)return t;if(Array.isArray(t))return new RollResults(t);if("object"==typeof t){if(Array.isArray(t.results))return new ResultGroup(t.results,t.modifiers||[],t.isRollGroup||!1,"boolean"!=typeof t.useInTotal||t.useInTotal);if(Array.isArray(t.rolls))return new RollResults(t.rolls)}return t})))}}}const se=Symbol("log");class DiceRoller{constructor(t){this[se]=[],t&&this.import(t)}get log(){return this[se]||[]}get output(){return this.log.join("; ")}get total(){return this.log.reduce(((t,e)=>t+e.total),0)}clearLog(){this[se].length=0}export(t=Zt.JSON){switch(t){case Zt.BASE_64:return btoa(this.export(Zt.JSON));case Zt.JSON:return JSON.stringify(this);case Zt.OBJECT:return JSON.parse(this.export(Zt.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}import(t){if(t){if(zt(t))return this.import(JSON.parse(t));if(Bt(t))return this.import(atob(t));if("object"==typeof t){let e=t.log||null;if(!t.log&&Array.isArray(t)&&t.length&&(e=t),e&&Array.isArray(e))e.forEach((t=>{this[se].push(DiceRoll.import(t))}));else if(e)throw new TypeError("log must be an array");return this.log}throw new DataFormatError(t)}throw new RequiredArgumentError("data")}roll(...t){const e=t.filter(Boolean);if(0===e.length)throw new RequiredArgumentError("notations");const r=e.map((t=>{const e=new DiceRoll(t);return this[se].push(e),e}));return r.length>1?r:r[0]}toJSON(){const{log:t,output:e,total:r}=this;return{log:t,output:e,total:r,type:"dice-roller"}}toString(){return this.output}static import(t){const e=new DiceRoller;return e.import(t),e}}export{ComparePoint,Ct as Dice,DiceRoll,DiceRoller,e as Exceptions,kt as Modifiers,it as NumberGenerator,Parser,_t as Results,RollGroup,Zt as exportFormats}; | ||
import{evaluate as t}from"mathjs";class CompareOperatorError extends TypeError{constructor(t){super(`Operator "${t}" is invalid`),TypeError.captureStackTrace&&TypeError.captureStackTrace(this,CompareOperatorError),this.name="CompareOperatorError",this.operator=t}}class DataFormatError extends Error{constructor(t){super(`Invalid data format: ${t}`),Error.captureStackTrace&&Error.captureStackTrace(this,DataFormatError),this.name="ImportError",this.data=t}}class DieActionValueError extends Error{constructor(t,e=null){super(`Die "${t}" must have more than 1 possible value to ${e||"do this action"}`),Error.captureStackTrace&&Error.captureStackTrace(this,DieActionValueError),this.name="DieActionValueError",this.action=e,this.die=t}}class NotationError extends Error{constructor(t){super(`Notation "${t}" is invalid`),Error.captureStackTrace&&Error.captureStackTrace(this,NotationError),this.name="NotationError",this.notation=t}}class RequiredArgumentError extends Error{constructor(t=null){super("Missing argument"+(t?` "${t}"`:"")),Error.captureStackTrace&&Error.captureStackTrace(this,RequiredArgumentError),this.argumentName=t}}var e=Object.freeze({__proto__:null,CompareOperatorError:CompareOperatorError,DataFormatError:DataFormatError,DieActionValueError:DieActionValueError,NotationError:NotationError,RequiredArgumentError:RequiredArgumentError});const r=e=>t(e),n=t=>("number"==typeof t||"string"==typeof t)&&(!Number.isNaN(t)&&Number.isFinite(Number(t))),i=t=>{if(!n(t))return!1;const e=Number(t);return e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER},o=9007199254740992,s=o-1,a=-1>>>0,u=a+1,l=u/2,c=l-1,h=1<<21,f=h-1;function p(t){return 0|t.next()}function d(t,e){return 0===e?t:r=>t(r)+e}function m(t){const e=0|t.next(),r=t.next()>>>0;return(e&f)*u+r+(e&h?-o:0)}function g(t){for(;;){const e=0|t.next();if(!(4194304&e)){const r=t.next()>>>0;return(e&f)*u+r+(e&h?-o:0)}if(4194304==(8388607&e)&&0==(0|t.next()))return o}}function y(t){return t.next()>>>0}function w(t){const e=t.next()&f,r=t.next()>>>0;return e*u+r}function b(t){for(;;){const e=0|t.next();if(!(e&h)){const r=t.next()>>>0;return(e&f)*u+r}if(0==(e&f)&&0==(0|t.next()))return o}}function x(t){return 0==(t+1&t)}function v(t){return x(t)?(e=t,t=>t.next()&e):function(t){const e=t+1,r=e*Math.floor(u/e);return t=>{let n=0;do{n=t.next()>>>0}while(n>=r);return n%e}}(t);var e}function E(t){const e=t+1;if(0==(0|e)){const t=(e/u|0)-1;if(x(t))return r=t,t=>{const e=t.next()&r,n=t.next()>>>0;return e*u+n}}var r;return function(t){const e=t*Math.floor(o/t);return r=>{let n=0;do{const t=r.next()&f,e=r.next()>>>0;n=t*u+e}while(n>=e);return n%t}}(e)}function S(t,e){return r=>{let n=0;do{const t=0|r.next(),e=r.next()>>>0;n=(t&f)*u+e+(t&h?-o:0)}while(n<t||n>e);return n}}function A(t,e){if(t=Math.floor(t),e=Math.floor(e),t<-o||!isFinite(t))throw new RangeError("Expected min to be at least "+-o);if(e>o||!isFinite(e))throw new RangeError(`Expected max to be at most ${o}`);const r=e-t;return r<=0||!isFinite(r)?()=>t:r===a?0===t?y:d(p,t+l):r<a?d(v(r),t):r===s?d(w,t):r<s?d(E(r),t):e-1-t===s?d(b,t):t===-o&&e===o?g:t===-o&&e===s?m:t===-s&&e===o?d(m,1):e===o?d(S(t-1,e-1),1):S(t,e)}function R(t){return 1==(1&t.next())}function M(t,e){return r=>t(r)<e}function C(t,e){return null==e?null==t?R:function(t){if(t<=0)return()=>!1;if(t>=1)return()=>!0;{const e=t*u;return e%1==0?M(p,e-l|0):M(w,Math.round(t*o))}}(t):t<=0?()=>!1:t>=e?()=>!0:M(A(0,e-1),t)}function T(t){return A(1,t)}function N(t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"){const e=t.length;if(!e)throw new Error("Expected pool not to be an empty string");const r=A(0,e-1);return(e,n)=>{let i="";for(let o=0;o<n;++o){const n=r(e);i+=t.charAt(n)}return i}}const O="0123456789abcdef",$=N(O),D=N(O.toUpperCase());function F(t,e){return t<0?Math.max(t+e,0):Math.min(t,e)}function P(t){const e=+t;return e<0?Math.ceil(e):Math.floor(e)}function I(t){return w(t)/o}function j(t){return b(t)/o}const J=Array.prototype.slice;function q(t,e,r=0){const n=e.length;if(n)for(let i=n-1>>>0;i>r;--i){const r=A(0,i)(t);if(i!==r){const t=e[i];e[i]=e[r],e[r]=t}}return e}const G=(()=>{try{if("xxx"==="x".repeat(3))return(t,e)=>t.repeat(e)}catch(t){}return(t,e)=>{let r="";for(;e>0;)1&e&&(r+=t),e>>=1,t+=t;return r}})();function V(t,e){return G("0",e-t.length)+t}const k={next:()=>Math.random()*u|0};class Random{constructor(t=k){this.engine=t}int32(){return p(this.engine)}uint32(){return y(this.engine)}uint53(){return w(this.engine)}uint53Full(){return b(this.engine)}int53(){return m(this.engine)}int53Full(){return g(this.engine)}integer(t,e){return A(t,e)(this.engine)}realZeroToOneInclusive(){return j(this.engine)}realZeroToOneExclusive(){return I(this.engine)}real(t,e,r=!1){return function(t,e,r=!1){if(!isFinite(t))throw new RangeError("Expected min to be a finite number");if(!isFinite(e))throw new RangeError("Expected max to be a finite number");return d((n=r?j:I,1==(i=e-t)?n:0===i?()=>0:t=>n(t)*i),t);var n,i}(t,e,r)(this.engine)}bool(t,e){return C(t,e)(this.engine)}pick(t,e,r){return function(t,e,r,n){const i=e.length;if(0===i)throw new RangeError("Cannot pick from an empty array");const o=null==r?0:F(P(r),i),s=void 0===n?i:F(P(n),i);if(o>=s)throw new RangeError(`Cannot pick between bounds ${o} and ${s}`);return e[A(o,s-1)(t)]}(this.engine,t,e,r)}shuffle(t){return q(this.engine,t)}sample(t,e){return function(t,e,r){if(r<0||r>e.length||!isFinite(r))throw new RangeError("Expected sampleSize to be within 0 and the length of the population");if(0===r)return[];const n=J.call(e),i=n.length;if(i===r)return q(t,n,0);const o=i-r;return q(t,n,o-1).slice(o)}(this.engine,t,e)}die(t){return T(t)(this.engine)}dice(t,e){return function(t,e){const r=T(t);return t=>{const n=[];for(let i=0;i<e;++i)n.push(r(t));return n}}(t,e)(this.engine)}uuid4(){return function(t){const e=t.next()>>>0,r=0|t.next(),n=0|t.next(),i=t.next()>>>0;return V(e.toString(16),8)+"-"+V((65535&r).toString(16),4)+"-"+V((r>>4&4095|16384).toString(16),4)+"-"+V((16383&n|32768).toString(16),4)+"-"+V((n>>4&65535).toString(16),4)+V(i.toString(16),8)}(this.engine)}string(t,e){return N(e)(this.engine,t)}hex(t,e){return function(t){return t?D:$}(e)(this.engine,t)}date(t,e){return function(t,e){const r=A(+t,+e);return t=>new Date(r(t))}(t,e)(this.engine)}}const _=(()=>{try{const t=new ArrayBuffer(4),e=new Int32Array(t);if(e[0]=l,e[0]===-l)return Int32Array}catch(t){}return Array})();let B=null;let z=128;const L={next:()=>(z>=128&&(null===B&&(B=new _(128)),crypto.getRandomValues(B),z=0),0|B[z++])};const U=(()=>{try{if(-5===Math.imul(a,5))return Math.imul}catch(t){}const t=65535;return(e,r)=>{const n=e&t,i=r&t;return n*i+((e>>>16&t)*i+n*(r>>>16&t)<<16>>>0)|0}})(),K=624,W=623,H=2567483615;class MersenneTwister19937{constructor(){this.data=new _(K),this.index=0,this.uses=0}static seed(t){return(new MersenneTwister19937).seed(t)}static seedWithArray(t){return(new MersenneTwister19937).seedWithArray(t)}static autoSeed(){return MersenneTwister19937.seedWithArray(function(t=k,e=16){const r=[];r.push(0|(new Date).getTime());for(let n=1;n<e;++n)r[n]=0|t.next();return r}())}next(){(0|this.index)>=K&&(Z(this.data),this.index=0);const t=this.data[this.index];return this.index=this.index+1|0,this.uses+=1,0|function(t){return t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^t>>>18}(t)}getUseCount(){return this.uses}discard(t){if(t<=0)return this;for(this.uses+=t,(0|this.index)>=K&&(Z(this.data),this.index=0);t+this.index>K;)t-=K-this.index,Z(this.data),this.index=0;return this.index=this.index+t|0,this}seed(t){let e=0;this.data[0]=e=0|t;for(let t=1;t<K;t=t+1|0)this.data[t]=e=U(e^e>>>30,1812433253)+t|0;return this.index=K,this.uses=0,this}seedWithArray(t){return this.seed(19650218),function(t,e){let r=1,n=0;const i=e.length;let o=0|Math.max(i,K),s=0|t[0];for(;(0|o)>0;--o)t[r]=s=(t[r]^U(s^s>>>30,1664525))+(0|e[n])+(0|n)|0,r=r+1|0,++n,(0|r)>W&&(t[0]=t[623],r=1),n>=i&&(n=0);for(o=W;(0|o)>0;--o)t[r]=s=(t[r]^U(s^s>>>30,1566083941))-r|0,r=r+1|0,(0|r)>W&&(t[0]=t[623],r=1);t[0]=l}(this.data,t),this}}function Z(t){let e=0,r=0;for(;(0|e)<227;e=e+1|0)r=t[e]&l|t[e+1|0]&c,t[e]=t[e+397|0]^r>>>1^(1&r?H:0);for(;(0|e)<W;e=e+1|0)r=t[e]&l|t[e+1|0]&c,t[e]=t[e-227|0]^r>>>1^(1&r?H:0);r=t[623]&l|t[0]&c,t[623]=t[396]^r>>>1^(1&r?H:0)}let X=null;let Q=128;const Y={next:()=>(Q>=128&&(X=new Int32Array(new Int8Array(require("crypto").randomBytes(512)).buffer),Q=0),0|X[Q++])},tt=Symbol("engine"),et=Symbol("random"),rt={browserCrypto:L,nodeCrypto:Y,MersenneTwister19937:MersenneTwister19937,nativeMath:k,min:{next:()=>0},max:{range:[],next(){return this.range[1]-this.range[0]}}};const nt=new class NumberGenerator{constructor(t=k){this.engine=t||k}get engine(){return this[tt]}set engine(t){if(t&&"function"!=typeof t.next)throw new TypeError("engine must have function `next()`");this[tt]=t||k,this[et]=new Random(this[tt])}integer(t,e){return this[tt].range=[t,e],this[et].integer(t,e)}real(t,e,r=!1){return this[tt].range=[t,e],this[et].real(t,e,r)}};var it=Object.freeze({__proto__:null,engines:rt,generator:nt});const ot=Symbol("text"),st=Symbol("type");class Description{static types={MULTILINE:"multiline",INLINE:"inline"};constructor(t,e=this.constructor.types.INLINE){this.text=t,this.type=e}get text(){return this[ot]}set text(t){if("object"==typeof t)throw new TypeError("Description text is invalid");if(!t&&0!==t||""===`${t}`.trim())throw new TypeError("Description text cannot be empty");this[ot]=`${t}`.trim()}get type(){return this[st]}set type(t){const e=Object.values(this.constructor.types);if("string"!=typeof t)throw new TypeError("Description type must be a string");if(!e.includes(t))throw new RangeError(`Description type must be one of; ${e.join(", ")}`);this[st]=t}toJSON(){const{text:t,type:e}=this;return{text:t,type:e}}toString(){return this.type===this.constructor.types.INLINE?`# ${this.text}`:`[${this.text}]`}}const at=Symbol("description");class HasDescription{constructor(t=null){this.description=t}get description(){return this[at]||null}set description(t){if(t||0===t)if(t instanceof Description)this[at]=t;else{if("string"!=typeof t)throw new TypeError("description must be of type Description, string or null. Received "+typeof t);this[at]=new Description(t)}else this[at]=null}toJSON(){const{description:t}=this;return{description:t}}toString(){return this.description?`${this.description}`:""}}class Modifier{static order=999;constructor(){this.order=this.constructor.order}get name(){return"modifier"}get notation(){return""}get maxIterations(){return 1e3}defaults(t){return{}}useDefaultsIfNeeded(t){Object.entries(this.defaults(t)).forEach((([t,e])=>{void 0===this[t]&&(this[t]=e)}))}run(t,e){return this.useDefaultsIfNeeded(e),t}toJSON(){const{notation:t,name:e}=this;return{name:e,notation:t,type:"modifier"}}toString(){return this.notation}}const ut={compound:"!",explode:"!","critical-failure":"__","critical-success":"**",drop:"d",max:"v",min:"^",penetrate:"p","re-roll":"r","re-roll-once":"ro","target-failure":"_","target-success":"*",unique:"u","unique-once":"uo"},lt=(...t)=>[...t].reduce(((t,e)=>{let r;return r=e instanceof Modifier?e.name:e,t+(ut[r]||r)}),""),ct=Symbol("calculation-value"),ht=Symbol("modifiers"),ft=Symbol("initial-value"),pt=Symbol("use-in-total"),dt=Symbol("value");class RollResult{constructor(t,e=[],r=!0){if(n(t))this[ft]=Number(t),this.modifiers=e||[],this.useInTotal=r;else{if(!t||"object"!=typeof t||Array.isArray(t))throw t===1/0?new RangeError("Result value must be a finite number"):new TypeError(`Result value is invalid: ${t}`);{const i=n(t.initialValue)?t.initialValue:t.value;if(!n(i))throw new TypeError(`Result value is invalid: ${i}`);this[ft]=Number(i),n(t.value)&&Number(t.value)!==this[ft]&&(this.value=t.value),n(t.calculationValue)&&parseFloat(`${t.calculationValue}`)!==this.value&&(this.calculationValue=t.calculationValue),this.modifiers=t.modifiers||e||[],this.useInTotal="boolean"==typeof t.useInTotal?t.useInTotal:r||!1}}}get calculationValue(){return n(this[ct])?parseFloat(this[ct]):this.value}set calculationValue(t){const e=n(t);if(t===1/0)throw new RangeError("Result calculation value must be a finite number");if(t&&!e)throw new TypeError(`Result calculation value is invalid: ${t}`);this[ct]=e?parseFloat(`${t}`):null}get initialValue(){return this[ft]}get modifierFlags(){return lt(...this.modifiers)}get modifiers(){return this[ht]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[ht]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[ht]=new Set}}get useInTotal(){return!!this[pt]}set useInTotal(t){this[pt]=!!t}get value(){return n(this[dt])?this[dt]:this[ft]}set value(t){if(t===1/0)throw new RangeError("Result value must be a finite number");if(!n(t))throw new TypeError(`Result value is invalid: ${t}`);this[dt]=Number(t)}toJSON(){const{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:n,useInTotal:i,value:o}=this;return{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:[...n],type:"result",useInTotal:i,value:o}}toString(){return this.value+this.modifierFlags}}const mt=Symbol("rolls");class RollResults{constructor(t=[]){this.rolls=t}get length(){return this.rolls.length||0}get rolls(){return[...this[mt]]}set rolls(t){if(!t||!Array.isArray(t))throw new TypeError(`rolls must be an array: ${t}`);this[mt]=[],t.forEach((t=>{this.addRoll(t)}))}get value(){return this.rolls.reduce(((t,e)=>t+(e.useInTotal?e.calculationValue:0)),0)}addRoll(t){const e=t instanceof RollResult?t:new RollResult(t);this[mt].push(e)}toJSON(){const{rolls:t,value:e}=this;return{rolls:t,type:"roll-results",value:e}}toString(){return`[${this.rolls.join(", ")}]`}}const gt=Symbol("modifiers"),yt=Symbol("qty"),wt=Symbol("sides"),bt=Symbol("min-value"),xt=Symbol("max-value");class StandardDice extends HasDescription{constructor(t,e=1,r=null,o=1,s=null,a=null){if(super(a),!t&&0!==t)throw new RequiredArgumentError("sides");if(t===1/0)throw new RangeError("numerical sides must be finite number");if(n(t)){if(t<1||!i(t))throw new RangeError("numerical sides must be a positive finite number")}else if("string"!=typeof t)throw new TypeError("non-numerical sides must be a string");if(!n(e))throw new TypeError("qty must be a positive finite integer");if(e<1||e>999)throw new RangeError("qty must be between 1 and 999");let u=o;if(null==u)u=1;else{if(!n(u))throw new TypeError("min must a finite number");if(!i(u))throw new RangeError("min must a finite number")}if(s&&!n(s))throw new TypeError("max must a finite number");if(s&&!i(s))throw new RangeError("max must a finite number");this[yt]=parseInt(`${e}`,10),this[wt]=t,r&&(this.modifiers=r),this[bt]=parseInt(u,10),this[xt]=s?parseInt(`${s}`,10):t}get average(){return(this.min+this.max)/2}get modifiers(){return this[gt]?new Map([...this[gt]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[gt]=e}get max(){return this[xt]}get min(){return this[bt]}get name(){return"standard"}get notation(){let t=`${this.qty}d${this.sides}`;return this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}get qty(){return this[yt]}get sides(){return this[wt]}roll(){const t=new RollResults;for(let e=0;e<this.qty;e++)t.addRoll(this.rollOnce());return(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}rollOnce(){return new RollResult(nt.integer(this.min,this.max))}toJSON(){const{average:t,max:e,min:r,modifiers:n,name:i,notation:o,qty:s,sides:a}=this;return Object.assign(super.toJSON(),{average:t,max:e,min:r,modifiers:n,name:i,notation:o,qty:s,sides:a,type:"die"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}class FudgeDice extends StandardDice{constructor(t=2,e=1,r=null,n=null){let i=t;if(i||0===i){if(1!==i&&2!==i)throw new RangeError("nonBlanks must be 1 or 2")}else i=2;super(i,e,r,-1,1,n)}get name(){return"fudge"}get nonBlanks(){return super.sides}get sides(){return`F.${this.nonBlanks}`}rollOnce(){let t=0;if(2===this.nonBlanks)t=nt.integer(1,3)-2;else if(1===this.nonBlanks){const e=nt.integer(1,6);1===e?t=-1:6===e&&(t=1)}return new RollResult(t)}}class PercentileDice extends StandardDice{constructor(t=1,e=null,r=!1,n=null){super(100,t,e,null,null,n),this.sidesAsNumber=!!r}get name(){return"percentile"}get sides(){return this.sidesAsNumber?super.sides:"%"}}var vt=Object.freeze({__proto__:null,FudgeDice:FudgeDice,PercentileDice:PercentileDice,StandardDice:StandardDice});const Et=Symbol("operator"),St=Symbol("value");class ComparePoint{constructor(t,e){if(!t)throw new RequiredArgumentError("operator");if(!e&&0!==e)throw new RequiredArgumentError("value");this.operator=t,this.value=e}static isValidOperator(t){return"string"==typeof t&&/^(?:[<>!]?=|[<>]|<>)$/.test(t)}set operator(t){if(!this.constructor.isValidOperator(t))throw new CompareOperatorError(t);this[Et]=t}get operator(){return this[Et]}set value(t){if(!n(t))throw new TypeError("value must be a finite number");this[St]=Number(t)}get value(){return this[St]}isMatch(t){return((t,e,r)=>{const n=Number(t),i=Number(e);let o;if(Number.isNaN(n)||Number.isNaN(i))return!1;switch(r){case"=":case"==":o=n===i;break;case"<":o=n<i;break;case">":o=n>i;break;case"<=":o=n<=i;break;case">=":o=n>=i;break;case"!":case"!=":case"<>":o=n!==i;break;default:o=!1}return o})(t,this.value,this.operator)}toJSON(){const{operator:t,value:e}=this;return{operator:t,type:"compare-point",value:e}}toString(){return`${this.operator}${this.value}`}}const At=Symbol("compare-point");class ComparisonModifier extends Modifier{constructor(t){super(),t&&(this.comparePoint=t)}get comparePoint(){return this[At]}set comparePoint(t){if(!(t instanceof ComparePoint))throw new TypeError("comparePoint must be instance of ComparePoint");this[At]=t}get name(){return"comparison"}get notation(){return`${this.comparePoint||""}`}defaultComparePoint(t){return{}}defaults(t){const e=this.defaultComparePoint(t);return"object"==typeof e&&2===e.length?{comparePoint:new ComparePoint(...e)}:{}}isComparePoint(t){return!!this.comparePoint&&this.comparePoint.isMatch(t)}toJSON(){const{comparePoint:t}=this;return Object.assign(super.toJSON(),{comparePoint:t})}}class CriticalFailureModifier extends ComparisonModifier{static order=10;constructor(t){super(t)}get name(){return"critical-failure"}get notation(){return`cf${super.notation}`}defaultComparePoint(t){return["=",t.min]}run(t,e){return super.run(t,e),t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-failure"),t))),t}}class CriticalSuccessModifier extends ComparisonModifier{static order=9;constructor(t){super(t)}get name(){return"critical-success"}get notation(){return`cs${super.notation}`}defaultComparePoint(t){return["=",t.max]}run(t,e){return super.run(t,e),t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-success"),t))),t}}const Rt=Symbol("calculation-value"),Mt=Symbol("is-roll-group"),Ct=Symbol("modifiers"),Tt=Symbol("results"),Nt=Symbol("use-in-total");class ResultGroup{constructor(t=[],e=[],r=!1,n=!0){this.isRollGroup=r,this.modifiers=e,this.results=t,this.useInTotal=n}get calculationValue(){return n(this[Rt])?parseFloat(this[Rt]):this.value}set calculationValue(t){const e=n(t);if(t===1/0)throw new RangeError("Results calculation value must be a finite number");if(t&&!e)throw new TypeError(`Results calculation value is invalid: ${t}`);this[Rt]=e?parseFloat(`${t}`):null}get isRollGroup(){return this[Mt]}set isRollGroup(t){this[Mt]=!!t}get length(){return this.results.length||0}get modifierFlags(){return lt(...this.modifiers)}get modifiers(){return this[Ct]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[Ct]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[Ct]=new Set}}get results(){return[...this[Tt]]}set results(t){if(!t||!Array.isArray(t))throw new TypeError(`results must be an array: ${t}`);this[Tt]=[],t.forEach((t=>{this.addResult(t)}))}get useInTotal(){return!!this[Nt]}set useInTotal(t){this[Nt]=!!t}get value(){if(!this.results.length)return 0;const t=this.results.reduce(((t,e)=>{let r=e;return e instanceof ResultGroup?r=e.useInTotal?e.calculationValue:0:e instanceof RollResults&&(r=e.value),t+r}),"string"==typeof this.results[0]?"":0);return"string"==typeof t?r(t):t}addResult(t){let e;if(t instanceof ResultGroup||t instanceof RollResults)e=t;else{if("string"!=typeof t&&!n(t))throw new TypeError("value must be one of ResultGroup, RollResults, string, or number");e=t}this[Tt].push(e)}toJSON(){const{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:n,results:i,useInTotal:o,value:s}=this;return{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:[...n],results:i,type:"result-group",useInTotal:o,value:s}}toString(){let t;return t=this.isRollGroup?`{${this.results.join(", ")}}`:this.results.join(""),this.modifierFlags&&(t=`(${t})${this.modifierFlags}`),t}}const Ot=Symbol("end"),$t=Symbol("qty");class KeepModifier extends Modifier{static order=6;constructor(t="h",e=1){super(),this.end=t,this.qty=e}get end(){return this[Ot]}set end(t){if("h"!==t&&"l"!==t)throw new RangeError('End must be "h" or "l"');this[Ot]=t}get name(){return`keep-${this.end}`}get notation(){return`k${this.end}${this.qty}`}get qty(){return this[$t]}set qty(t){if(t===1/0)throw new RangeError("qty must be a finite number");if(!n(t)||t<1)throw new TypeError("qty must be a positive finite integer");this[$t]=Math.floor(t)}rangeToDrop(t){return"h"===this.end?[0,t.length-this.qty]:[this.qty,t.length]}run(t,e){let r,n;return t instanceof ResultGroup?(r=t.results,n=1===r.length&&r[0]instanceof ResultGroup?r[0].results.map(((t,e)=>t instanceof RollResults?t.rolls.map(((t,r)=>({value:t.value,index:[e,r]}))):null)).flat().filter(Boolean):[...r].map(((t,e)=>({value:t.value,index:e})))):(r=t.rolls,n=[...r].map(((t,e)=>({value:t.value,index:e})))),n=n.sort(((t,e)=>t.value-e.value)).map((t=>t.index)).slice(...this.rangeToDrop(n)),n.forEach((t=>{let e;e=Array.isArray(t)?r[0].results[t[0]].rolls[t[1]]:r[t],e.modifiers.add("drop"),e.useInTotal=!1})),t}toJSON(){const{end:t,qty:e}=this;return Object.assign(super.toJSON(),{end:t,qty:e})}}class DropModifier extends KeepModifier{static order=7;constructor(t="l",e=1){super(t,e)}get name(){return`drop-${this.end}`}get notation(){return`d${this.end}${this.qty}`}rangeToDrop(t){return"h"===this.end?[t.length-this.qty,t.length]:[0,this.qty]}}const Dt=Symbol("compound"),Ft=Symbol("penetrate");class ExplodeModifier extends ComparisonModifier{static order=3;constructor(t=null,e=!1,r=!1){super(t),this[Dt]=!!e,this[Ft]=!!r}get compound(){return this[Dt]}get name(){return"explode"}get notation(){return`!${this.compound?"!":""}${this.penetrate?"p":""}${super.notation}`}get penetrate(){return this[Ft]}defaultComparePoint(t){return["=",t.max]}run(t,e){if(super.run(t,e),e.min===e.max)throw new DieActionValueError(e,"explode");const r=t;return r.rolls=t.rolls.map((t=>{const r=[t];let i=t.value;for(let t=0;t<this.maxIterations&&this.isComparePoint(i);t++){const t=r[r.length-1],n=e.rollOnce();i=n.value,t.modifiers.add("explode"),this.penetrate&&(t.modifiers.add("penetrate"),n.value-=1),r.push(n)}return this.compound&&r.length>1?(t.value=(o=r.map((t=>t.value)),Array.isArray(o)?o.reduce(((t,e)=>t+(n(e)?parseFloat(`${e}`):0)),0):0),t.modifiers=["explode","compound"],this.penetrate&&t.modifiers.add("penetrate"),t):r;var o})).flat(),r}toJSON(){const{compound:t,penetrate:e}=this;return Object.assign(super.toJSON(),{compound:t,penetrate:e})}}const Pt=Symbol("max");class MaxModifier extends Modifier{static order=2;constructor(t){super(),this.max=t}get max(){return this[Pt]}set max(t){if(!n(t))throw new TypeError("max must be a number");this[Pt]=parseFloat(`${t}`)}get name(){return"max"}get notation(){return`max${this.max}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value>this.max&&(e.value=this.max,e.modifiers.add("max")),e})),r}toJSON(){const{max:t}=this;return Object.assign(super.toJSON(),{max:t})}}const It=Symbol("min");class MinModifier extends Modifier{static order=1;constructor(t){super(),this.min=t}get min(){return this[It]}set min(t){if(!n(t))throw new TypeError("min must be a number");this[It]=parseFloat(`${t}`)}get name(){return"min"}get notation(){return`min${this.min}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value<this.min&&(e.value=this.min,e.modifiers.add("min")),e})),r}toJSON(){const{min:t}=this;return Object.assign(super.toJSON(),{min:t})}}const jt=Symbol("once");class ReRollModifier extends ComparisonModifier{static order=4;constructor(t=!1,e=null){super(e),this.once=!!t}get name(){return"re-roll"}get notation(){return`r${this.once?"o":""}${super.notation}`}get once(){return!!this[jt]}set once(t){this[jt]=!!t}defaultComparePoint(t){return["=",t.min]}run(t,e){if(super.run(t,e),e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.map((t=>{for(let r=0;r<this.maxIterations&&this.isComparePoint(t.value);r++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("re-roll"+(this.once?"-once":"")),this.once)break}return t})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}const Jt=Symbol("direction");class SortingModifier extends Modifier{static order=11;constructor(t="a"){super(),this.direction=t}get direction(){return this[Jt]}set direction(t){if("a"!==t&&"d"!==t)throw new RangeError('Direction must be "a" (Ascending) or "d" (Descending)');this[Jt]=t}get name(){return"sorting"}get notation(){return`s${this.direction}`}run(t,e){let r;return r=t instanceof ResultGroup?"results":"rolls",t[r]=t[r].sort(((t,e)=>"d"===this.direction?e.value-t.value:t.value-e.value)),t instanceof ResultGroup&&(t[r]=t[r].map((t=>t instanceof ResultGroup||t instanceof RollResults?this.run(t,e):t))),t}toJSON(){const{direction:t}=this;return Object.assign(super.toJSON(),{direction:t})}}const qt=Symbol("failure-cp");class TargetModifier extends ComparisonModifier{static order=8;constructor(t,e=null){super(t),this.failureComparePoint=e}get failureComparePoint(){return this[qt]}set failureComparePoint(t){if(t&&!(t instanceof ComparePoint))throw new TypeError("failure comparePoint must be instance of ComparePoint or null");this[qt]=t||null}get name(){return"target"}get notation(){return`${super.notation}${this.failureComparePoint?`f${this.failureComparePoint}`:""}`}get successComparePoint(){return this.comparePoint}set successComparePoint(t){super.comparePoint=t}getStateValue(t){return this.isSuccess(t)?1:this.isFailure(t)?-1:0}isFailure(t){return!!this.failureComparePoint&&this.failureComparePoint.isMatch(t)}isNeutral(t){return!this.isSuccess(t)&&!this.isFailure(t)}isSuccess(t){return this.isComparePoint(t)}run(t,e){let r;return r=t instanceof ResultGroup?t.results:t.rolls,r.forEach((t=>{this.isSuccess(t.value)?t.modifiers.add("target-success"):this.isFailure(t.value)&&t.modifiers.add("target-failure"),t.calculationValue=this.getStateValue(t.value)})),t}toJSON(){const{failureComparePoint:t,successComparePoint:e}=this,r=super.toJSON();return delete r.comparePoint,Object.assign(r,{failureComparePoint:t,successComparePoint:e})}}const Gt=Symbol("once"),Vt=(t,e,r,n=!1)=>{const i=r.map((t=>t.value)).indexOf(t.value);return n?i<e:i!==e};class UniqueModifier extends ComparisonModifier{static order=5;constructor(t=!1,e=null){super(e),this.once=!!t}get name(){return"unique"}get notation(){return`u${this.once?"o":""}${super.notation}`}get once(){return!!this[Gt]}set once(t){this[Gt]=!!t}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.forEach(((t,r,n)=>{if(0!==r)for(let i=0;i<this.maxIterations&&(!this.comparePoint||this.isComparePoint(t.value))&&Vt(t,r,n,!0);i++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("unique"+(this.once?"-once":"")),this.once)break}})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}var kt=Object.freeze({__proto__:null,ComparisonModifier:ComparisonModifier,CriticalFailureModifier:CriticalFailureModifier,CriticalSuccessModifier:CriticalSuccessModifier,DropModifier:DropModifier,ExplodeModifier:ExplodeModifier,KeepModifier:KeepModifier,MaxModifier:MaxModifier,MinModifier:MinModifier,Modifier:Modifier,ReRollModifier:ReRollModifier,SortingModifier:SortingModifier,TargetModifier:TargetModifier,UniqueModifier:UniqueModifier}),_t=Object.freeze({__proto__:null,ResultGroup:ResultGroup,RollResult:RollResult,RollResults:RollResults});const Bt=t=>{try{return!(!t||btoa(atob(t))!==t)}catch(t){return!1}},zt=t=>{try{const e=!!t&&JSON.parse(t);return!(!e||"object"!=typeof e)}catch(t){return!1}},Lt=Symbol("expressions"),Ut=Symbol("modifiers");class RollGroup extends HasDescription{constructor(t=[],e=[],r=null){super(r),this.expressions=t,this.modifiers=e}get expressions(){return[...this[Lt]||[]]}set expressions(t){if(!t)throw new RequiredArgumentError("expressions");if(!Array.isArray(t))throw new TypeError(`expressions must be an array: ${t}`);this[Lt]=[],t.forEach((e=>{if(!e||!Array.isArray(e))throw new TypeError(`Expressions must be an array of arrays: ${t}`);if(0===e.length)throw new TypeError(`Sub expressions cannot be empty: ${t}`);if(!e.every((t=>t instanceof StandardDice||"string"==typeof t||"number"==typeof t)))throw new TypeError("Sub expression items must be Dice, numbers, or strings");this[Lt].push(e)}))}get modifiers(){return this[Ut]?new Map([...this[Ut]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[Ut]=e}get notation(){let t=this.expressions.map((t=>t.reduce(((t,e)=>t+e),""))).join(", ");return t=`{${t}}`,this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}roll(){const t=new ResultGroup(this.expressions.map((t=>{const e=t.map((t=>t instanceof StandardDice?t.roll():t));return new ResultGroup(e)})));return t.isRollGroup=!0,(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}toJSON(){const{modifiers:t,notation:e,expressions:r}=this;return Object.assign(super.toJSON(),{expressions:r,modifiers:t,notation:e,type:"group"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}function Kt(t,e,r,n){var i=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(i,Kt.prototype),i.expected=e,i.found=r,i.location=n,i.name="SyntaxError",i}function Wt(t,e,r){return r=r||" ",t.length>e?t:(e-=t.length,t+(r+=r.repeat(e)).slice(0,e))}function Ht(t,e){var n,i,o,s,a={},u=(e=void 0!==e?e:{}).grammarSource,l={Main:vr},c=vr,h="{",f=",",p="}",d="d",m="d%",g="dF",y=".",w="!",b="p",x="k",v="max",E="min",S="r",A="o",R="u",M="cs",C="cf",T="s",N="a",O="f",$="!=",D="<=",F=">=",P="=",I="<>",j=">",J="<",q="(",G=")",V="abs",k="ceil",_="cos",B="exp",z="floor",L="log",U="round",K="sign",W="sin",H="sqrt",Z="tan",X="pow",Q="-",Y="**",tt="*",et="^",rt="%",nt="/",it="+",ot="/*",st="*/",at="[",ut="]",lt="//",ct="#",ht=/^[12]/,ft=/^[lh]/,pt=/^[.]/,dt=/^[1-9]/,mt=/^[0-9]/,gt=/^[^\]]/,yt=/^[\n\r\u2028\u2029]/,wt=/^[ \t\n\r]/,bt=mr("{",!1),xt=mr(",",!1),vt=mr("}",!1),Et=mr("d",!1),St=mr("d%",!1),At=mr("dF",!1),Rt=mr(".",!1),Mt=gr(["1","2"],!1,!1),Ct=mr("!",!1),Tt=mr("p",!1),Nt=gr(["l","h"],!1,!1),Ot=mr("k",!1),$t=mr("max",!1),Dt=mr("min",!1),Ft=mr("r",!1),Pt=mr("o",!1),It=mr("u",!1),jt=mr("cs",!1),Jt=mr("cf",!1),qt=mr("s",!1),Gt=mr("a",!1),Vt=mr("f",!1),kt=mr("!=",!1),_t=mr("<=",!1),Bt=mr(">=",!1),zt=mr("=",!1),Lt=mr("<>",!1),Ut=mr(">",!1),Wt=mr("<",!1),Ht=mr("(",!1),Zt=mr(")",!1),Xt=mr("abs",!1),Qt=mr("ceil",!1),Yt=mr("cos",!1),te=mr("exp",!1),ee=mr("floor",!1),re=mr("log",!1),ne=mr("round",!1),ie=mr("sign",!1),oe=mr("sin",!1),se=mr("sqrt",!1),ae=mr("tan",!1),ue=mr("pow",!1),le=mr("-",!1),ce=gr(["."],!1,!1),he=gr([["1","9"]],!1,!1),fe=gr([["0","9"]],!1,!1),pe=mr("**",!1),de=mr("*",!1),me=mr("^",!1),ge=mr("%",!1),ye=mr("/",!1),we=mr("+",!1),be=yr("comment"),xe=mr("/*",!1),ve=mr("*/",!1),Ee={type:"any"},Se=mr("[",!1),Ae=gr(["]"],!0,!1),Re=mr("]",!1),Me=mr("//",!1),Ce=mr("#",!1),Te=gr(["\n","\r","\u2028","\u2029"],!1,!1),Ne=yr("whitespace"),Oe=gr([" ","\t","\n","\r"],!1,!1),$e=yr("whitespace or comment"),De=function(t,e,r,n){return new RollGroup([t,...e.map((t=>t[3]))],Object.assign({},...r.map((t=>({[t.name]:t})))),n.find((t=>t instanceof Description)))},Fe=function(t,e,r){return t.modifiers=Object.assign({},...e.map((t=>({[t.name]:t})))),t.description=r.find((t=>t instanceof Description)),t},Pe=function(t,e){return new StandardDice(e,t||1)},Ie=function(t){return new PercentileDice(t||1)},je=function(t,e){return new FudgeDice(e?parseInt(e[1],10):2,t||1)},Je=function(t,e,r){return new ExplodeModifier(r,!!t,!!e)},qe=function(t,e){return new TargetModifier(t,e)},Ge=function(t,e){return new DropModifier(t||"l",e)},Ve=function(t,e){return new KeepModifier(t||"h",e)},ke=function(t){return new MaxModifier(t)},_e=function(t){return new MinModifier(t)},Be=function(t,e){return new ReRollModifier(!!t,e)},ze=function(t,e){return new UniqueModifier(!!t,e)},Le=function(t){return new CriticalSuccessModifier(t)},Ue=function(t){return new CriticalFailureModifier(t)},Ke=function(t){return new SortingModifier(t||"a")},We=function(t){return t},He=function(t,e){return new ComparePoint(t,e)},Ze=function(t,e,n){return r(dr())},Xe=function(t,e){return t=Array.isArray(t)?t:[t],[...t,...e.map((([,t,,e])=>[t,e])).flat(2)]},Qe=function(t,e,r){return[t,...e,r]},Ye=function(t,e){return[`${t}(`,...e,")"]},tr=function(t,e,r){return[`${t}(`,...e,",",...r,")"]},er=function(){return parseFloat(dr())},rr=function(){return parseInt(dr(),10)},nr=function(){return parseInt(dr(),10)},ir=function(){return"^"},or=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},sr=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},ar=function(t){return new Description(t.flat().join(""),Description.types.INLINE)},ur=0,lr=0,cr=[{line:1,column:1}],hr=0,fr=[],pr=0;if("startRule"in e){if(!(e.startRule in l))throw new Error("Can't start parsing from rule \""+e.startRule+'".');c=l[e.startRule]}function dr(){return t.substring(lr,ur)}function mr(t,e){return{type:"literal",text:t,ignoreCase:e}}function gr(t,e,r){return{type:"class",parts:t,inverted:e,ignoreCase:r}}function yr(t){return{type:"other",description:t}}function wr(e){var r,n=cr[e];if(n)return n;for(r=e-1;!cr[r];)r--;for(n={line:(n=cr[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return cr[e]=n,n}function br(t,e,r){var n=wr(t),i=wr(e),o={source:u,start:{offset:t,line:n.line,column:n.column},end:{offset:e,line:i.line,column:i.column}};return r&&u&&"function"==typeof u.offset&&(o.start=u.offset(o.start),o.end=u.offset(o.end)),o}function xr(t){ur<hr||(ur>hr&&(hr=ur,fr=[]),fr.push(t))}function vr(){return Mr()}function Er(){var e,r,n,i;if(e=ur,r=function(){var e,r,n,i;e=ur,r=Rr(),r===a&&(r=null);100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&xr(Et));n!==a&&(i=Rr())!==a?(lr=e,e=Pe(r,i)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n;e=ur,r=Rr(),r===a&&(r=null);t.substr(ur,2)===m?(n=m,ur+=2):(n=a,0===pr&&xr(St));n!==a?(lr=e,e=Ie(r)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n,i,o,s;e=ur,r=Rr(),r===a&&(r=null);t.substr(ur,2)===g?(n=g,ur+=2):(n=a,0===pr&&xr(At));n!==a?(i=ur,46===t.charCodeAt(ur)?(o=y,ur++):(o=a,0===pr&&xr(Rt)),o!==a?(ht.test(t.charAt(ur))?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Mt)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a),i===a&&(i=null),lr=e,e=je(r,i)):(ur=e,e=a);return e}())),r!==a){for(n=[],i=Sr();i!==a;)n.push(i),i=Sr();i=jr(),lr=e,e=Fe(r,n,i)}else ur=e,e=a;return e}function Sr(){var e;return(e=function(){var e,r,n,i,o;e=ur,33===t.charCodeAt(ur)?(r=w,ur++):(r=a,0===pr&&xr(Ct));r!==a?(33===t.charCodeAt(ur)?(n=w,ur++):(n=a,0===pr&&xr(Ct)),n===a&&(n=null),112===t.charCodeAt(ur)?(i=b,ur++):(i=a,0===pr&&xr(Tt)),i===a&&(i=null),(o=Ar())===a&&(o=null),lr=e,e=Je(n,i,o)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,(r=Ar())!==a?(n=function(){var e,r,n;e=ur,102===t.charCodeAt(ur)?(r=O,ur++):(r=a,0===pr&&xr(Vt));r!==a&&(n=Ar())!==a?(lr=e,e=We(n)):(ur=e,e=a);return e}(),n===a&&(n=null),lr=e,e=qe(r,n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,100===t.charCodeAt(ur)?(r=d,ur++):(r=a,0===pr&&xr(Et));r!==a?(ft.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(Nt)),n===a&&(n=null),(i=Nr())!==a?(lr=e,e=Ge(n,i)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,107===t.charCodeAt(ur)?(r=x,ur++):(r=a,0===pr&&xr(Ot));r!==a?(ft.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(Nt)),n===a&&(n=null),(i=Nr())!==a?(lr=e,e=Ve(n,i)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,114===t.charCodeAt(ur)?(r=S,ur++):(r=a,0===pr&&xr(Ft));r!==a?(111===t.charCodeAt(ur)?(n=A,ur++):(n=a,0===pr&&xr(Pt)),n===a&&(n=null),(i=Ar())===a&&(i=null),lr=e,e=Be(n,i)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,i;e=ur,117===t.charCodeAt(ur)?(r=R,ur++):(r=a,0===pr&&xr(It));r!==a?(111===t.charCodeAt(ur)?(n=A,ur++):(n=a,0===pr&&xr(Pt)),n===a&&(n=null),(i=Ar())===a&&(i=null),lr=e,e=ze(n,i)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===M?(r=M,ur+=2):(r=a,0===pr&&xr(jt));r!==a?((n=Ar())===a&&(n=null),lr=e,e=Le(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===C?(r=C,ur+=2):(r=a,0===pr&&xr(Jt));r!==a?((n=Ar())===a&&(n=null),lr=e,e=Ue(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,115===t.charCodeAt(ur)?(r=T,ur++):(r=a,0===pr&&xr(qt));r!==a?(97===t.charCodeAt(ur)?(n=N,ur++):(n=a,0===pr&&xr(Gt)),n===a&&(100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&xr(Et))),n===a&&(n=null),lr=e,e=Ke(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===v?(r=v,ur+=3):(r=a,0===pr&&xr($t));r!==a&&(n=Tr())!==a?(lr=e,e=ke(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&xr(Dt));r!==a&&(n=Tr())!==a?(lr=e,e=_e(n)):(ur=e,e=a);return e}()),e}function Ar(){var e,r,n;return e=ur,r=function(){var e;t.substr(ur,2)===$?(e=$,ur+=2):(e=a,0===pr&&xr(kt));e===a&&(t.substr(ur,2)===D?(e=D,ur+=2):(e=a,0===pr&&xr(_t)),e===a&&(t.substr(ur,2)===F?(e=F,ur+=2):(e=a,0===pr&&xr(Bt)),e===a&&(61===t.charCodeAt(ur)?(e=P,ur++):(e=a,0===pr&&xr(zt)),e===a&&(t.substr(ur,2)===I?(e=I,ur+=2):(e=a,0===pr&&xr(Lt)),e===a&&(62===t.charCodeAt(ur)?(e=j,ur++):(e=a,0===pr&&xr(Ut)),e===a&&(60===t.charCodeAt(ur)?(e=J,ur++):(e=a,0===pr&&xr(Wt))))))));return e}(),r!==a&&(n=Tr())!==a?(lr=e,e=He(r,n)):(ur=e,e=a),e}function Rr(){var e,r,n,i,o,s,u,l,c,h;if((e=Nr())===a)if(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&xr(Ht)),r!==a){if(Ir(),n=ur,(i=Tr())!==a){if(o=[],s=ur,u=Ir(),(l=$r())!==a?(c=Ir(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a),s!==a)for(;s!==a;)o.push(s),s=ur,u=Ir(),(l=$r())!==a?(c=Ir(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a);else o=a;o!==a?n=i=[i,o]:(ur=n,n=a)}else ur=n,n=a;n!==a?(i=Ir(),41===t.charCodeAt(ur)?(o=G,ur++):(o=a,0===pr&&xr(Zt)),o!==a?(lr=e,e=Ze()):(ur=e,e=a)):(ur=e,e=a)}else ur=e,e=a;return e}function Mr(){var t,e,r,n,i,o,s,u;if(t=ur,(e=Cr())!==a){for(r=[],n=ur,i=Ir(),(o=$r())!==a?(s=Ir(),(u=Cr())!==a?n=i=[i,o,s,u]:(ur=n,n=a)):(ur=n,n=a);n!==a;)r.push(n),n=ur,i=Ir(),(o=$r())!==a?(s=Ir(),(u=Cr())!==a?n=i=[i,o,s,u]:(ur=n,n=a)):(ur=n,n=a);lr=t,t=Xe(e,r)}else ur=t,t=a;return t}function Cr(){var e,r,n,i;return e=function(){var e,r,n,i,o,s,u;e=ur,t.substr(ur,3)===V?(r=V,ur+=3):(r=a,0===pr&&xr(Xt));r===a&&(t.substr(ur,4)===k?(r=k,ur+=4):(r=a,0===pr&&xr(Qt)),r===a&&(t.substr(ur,3)===_?(r=_,ur+=3):(r=a,0===pr&&xr(Yt)),r===a&&(t.substr(ur,3)===B?(r=B,ur+=3):(r=a,0===pr&&xr(te)),r===a&&(t.substr(ur,5)===z?(r=z,ur+=5):(r=a,0===pr&&xr(ee)),r===a&&(t.substr(ur,3)===L?(r=L,ur+=3):(r=a,0===pr&&xr(re)),r===a&&(t.substr(ur,5)===U?(r=U,ur+=5):(r=a,0===pr&&xr(ne)),r===a&&(t.substr(ur,4)===K?(r=K,ur+=4):(r=a,0===pr&&xr(ie)),r===a&&(t.substr(ur,3)===W?(r=W,ur+=3):(r=a,0===pr&&xr(oe)),r===a&&(t.substr(ur,4)===H?(r=H,ur+=4):(r=a,0===pr&&xr(se)),r===a&&(t.substr(ur,3)===Z?(r=Z,ur+=3):(r=a,0===pr&&xr(ae))))))))))));r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&xr(Ht)),n!==a?(Ir(),(i=Mr())!==a?(Ir(),41===t.charCodeAt(ur)?(o=G,ur++):(o=a,0===pr&&xr(Zt)),o!==a?(lr=e,e=Ye(r,i)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a);e===a&&(e=ur,t.substr(ur,3)===X?(r=X,ur+=3):(r=a,0===pr&&xr(ue)),r===a&&(t.substr(ur,3)===v?(r=v,ur+=3):(r=a,0===pr&&xr($t)),r===a&&(t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&xr(Dt)))),r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&xr(Ht)),n!==a?(Ir(),(i=Mr())!==a?(Ir(),44===t.charCodeAt(ur)?(o=f,ur++):(o=a,0===pr&&xr(xt)),o!==a?(Ir(),(s=Mr())!==a?(Ir(),41===t.charCodeAt(ur)?(u=G,ur++):(u=a,0===pr&&xr(Zt)),u!==a?(lr=e,e=tr(r,i,s)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a));return e}(),e===a&&(e=Er())===a&&(e=Tr())===a&&(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&xr(Ht)),r!==a?(Ir(),(n=Mr())!==a?(Ir(),41===t.charCodeAt(ur)?(i=G,ur++):(i=a,0===pr&&xr(Zt)),i!==a?(lr=e,e=Qe(r,n,i)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a),e===a&&(e=function(){var e,r,n,i,o,s,u,l,c;if(e=ur,123===t.charCodeAt(ur)?(r=h,ur++):(r=a,0===pr&&xr(bt)),r!==a)if(Ir(),(n=Mr())!==a){for(i=[],o=ur,s=Ir(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&xr(xt)),u!==a?(l=Ir(),(c=Mr())!==a?o=s=[s,u,l,c]:(ur=o,o=a)):(ur=o,o=a);o!==a;)i.push(o),o=ur,s=Ir(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&xr(xt)),u!==a?(l=Ir(),(c=Mr())!==a?o=s=[s,u,l,c]:(ur=o,o=a)):(ur=o,o=a);if(o=Ir(),125===t.charCodeAt(ur)?(s=p,ur++):(s=a,0===pr&&xr(vt)),s!==a){for(u=[],l=Sr();l!==a;)u.push(l),l=Sr();l=jr(),lr=e,e=De(n,i,u,l)}else ur=e,e=a}else ur=e,e=a;else ur=e,e=a;return e}())),e}function Tr(){var e,r,n,i;return e=ur,45===t.charCodeAt(ur)?ur++:0===pr&&xr(le),Or()!==a?(r=ur,pt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(ce)),n!==a&&(i=Or())!==a?r=n=[n,i]:(ur=r,r=a),r===a&&(r=null),lr=e,e=er()):(ur=e,e=a),e}function Nr(){var e,r,n,i;if(e=ur,dt.test(t.charAt(ur))?(r=t.charAt(ur),ur++):(r=a,0===pr&&xr(he)),r!==a){for(n=[],mt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(fe));i!==a;)n.push(i),mt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(fe));lr=e,e=rr()}else ur=e,e=a;return e}function Or(){var e,r,n;if(e=ur,r=[],mt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(fe)),n!==a)for(;n!==a;)r.push(n),mt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&xr(fe));else r=a;return r!==a&&(lr=e,r=nr()),e=r}function $r(){var e,r;return e=ur,t.substr(ur,2)===Y?(r=Y,ur+=2):(r=a,0===pr&&xr(pe)),r!==a&&(lr=e,r=ir()),(e=r)===a&&(42===t.charCodeAt(ur)?(e=tt,ur++):(e=a,0===pr&&xr(de)),e===a&&(94===t.charCodeAt(ur)?(e=et,ur++):(e=a,0===pr&&xr(me)),e===a&&(37===t.charCodeAt(ur)?(e=rt,ur++):(e=a,0===pr&&xr(ge)),e===a&&(47===t.charCodeAt(ur)?(e=nt,ur++):(e=a,0===pr&&xr(ye)),e===a&&(43===t.charCodeAt(ur)?(e=it,ur++):(e=a,0===pr&&xr(we)),e===a&&(45===t.charCodeAt(ur)?(e=Q,ur++):(e=a,0===pr&&xr(le)))))))),e}function Dr(){var e;return pr++,(e=function(){var e,r,n,i,o,s;e=ur,t.substr(ur,2)===ot?(r=ot,ur+=2):(r=a,0===pr&&xr(xe));if(r!==a){for(n=[],i=ur,o=ur,pr++,t.substr(ur,2)===st?(s=st,ur+=2):(s=a,0===pr&&xr(ve)),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);i!==a;)n.push(i),i=ur,o=ur,pr++,t.substr(ur,2)===st?(s=st,ur+=2):(s=a,0===pr&&xr(ve)),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);t.substr(ur,2)===st?(i=st,ur+=2):(i=a,0===pr&&xr(ve)),i!==a?(lr=e,e=or(n)):(ur=e,e=a)}else ur=e,e=a;if(e===a)if(e=ur,91===t.charCodeAt(ur)?(r=at,ur++):(r=a,0===pr&&xr(Se)),r!==a){for(n=[],gt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(Ae));i!==a;)n.push(i),gt.test(t.charAt(ur))?(i=t.charAt(ur),ur++):(i=a,0===pr&&xr(Ae));93===t.charCodeAt(ur)?(i=ut,ur++):(i=a,0===pr&&xr(Re)),i!==a?(lr=e,e=sr(n)):(ur=e,e=a)}else ur=e,e=a;return e}())===a&&(e=function(){var e,r,n,i,o,s;e=ur,t.substr(ur,2)===lt?(r=lt,ur+=2):(r=a,0===pr&&xr(Me));r===a&&(35===t.charCodeAt(ur)?(r=ct,ur++):(r=a,0===pr&&xr(Ce)));if(r!==a){for(n=[],i=ur,o=ur,pr++,s=Fr(),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);i!==a;)n.push(i),i=ur,o=ur,pr++,s=Fr(),pr--,s===a?o=void 0:(ur=o,o=a),o!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&xr(Ee)),s!==a?i=o=[o,s]:(ur=i,i=a)):(ur=i,i=a);lr=e,e=ar(n)}else ur=e,e=a;return e}()),pr--,e===a&&0===pr&&xr(be),e}function Fr(){var e;return yt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&xr(Te)),e}function Pr(){var e;return pr++,wt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&xr(Oe)),pr--,e===a&&0===pr&&xr(Ne),e}function Ir(){var t,e;for(t=[],e=Pr();e!==a;)t.push(e),e=Pr();return t}function jr(){var t,e;for(pr++,t=[],(e=Pr())===a&&(e=Dr());e!==a;)t.push(e),(e=Pr())===a&&(e=Dr());return pr--,e=a,0===pr&&xr($e),t}if((n=c())!==a&&ur===t.length)return n;throw n!==a&&ur<t.length&&xr({type:"end"}),i=fr,o=hr<t.length?t.charAt(hr):null,s=hr<t.length?br(hr,hr+1):br(hr,hr),new Kt(Kt.buildMessage(i,o),i,o,s)}!function(t,e){function r(){this.constructor=t}r.prototype=e.prototype,t.prototype=new r}(Kt,Error),Kt.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var r,n=null;for(r=0;r<t.length;r++)if(t[r].source===this.location.source){n=t[r].text.split(/\r\n|\n|\r/g);break}var i=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(i):i,s=this.location.source+":"+o.line+":"+o.column;if(n){var a=this.location.end,u=Wt("",o.line.toString().length," "),l=n[i.line-1],c=(i.line===a.line?a.column:l.length+1)-i.column||1;e+="\n --\x3e "+s+"\n"+u+" |\n"+o.line+" | "+l+"\n"+u+" | "+Wt("",i.column-1," ")+Wt("",c,"^")}else e+="\n at "+s}return e},Kt.buildMessage=function(t,e){var r={literal:function(t){return'"'+i(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?o(t[0])+"-"+o(t[1]):o(t)}));return"["+(t.inverted?"^":"")+e.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function i(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function o(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function s(t){return r[t.type](t)}return"Expected "+function(t){var e,r,n=t.map(s);if(n.sort(),n.length>0){for(e=1,r=1;e<n.length;e++)n[e-1]!==n[e]&&(n[r]=n[e],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(t)+" but "+function(t){return t?'"'+i(t)+'"':"end of input"}(e)+" found."};class Parser{static parse(t){if(!t)throw new RequiredArgumentError("notation");if("string"!=typeof t)throw new TypeError("Notation must be a string");return Ht(t)}}const Zt=Object.freeze({BASE_64:1,JSON:0,OBJECT:2}),Xt=Symbol("notation"),Qt=Symbol("maxTotal"),Yt=Symbol("minTotal"),te=Symbol("expressions"),ee=Symbol("roll-method"),re=Symbol("rolls"),ne=Symbol("set-rolls"),ie=Symbol("total"),oe=t=>((t,e=0)=>parseFloat(parseFloat(`${t}`).toFixed(e||0)))(t.calculationValue,2);class DiceRoll{constructor(t){if(!t)throw new RequiredArgumentError("notation");if(this[te]=[],t instanceof Object&&!Array.isArray(t)){if(!t.notation)throw new RequiredArgumentError("notation");if("string"!=typeof t.notation)throw new NotationError(t.notation);t.rolls&&this[ne](t.rolls),this[Xt]=t.notation,this[te]=Parser.parse(this.notation),this.hasRolls()||this.roll()}else{if("string"!=typeof t)throw new NotationError(t);this[Xt]=t,this[te]=Parser.parse(this.notation),this.roll()}}get averageTotal(){return(this.maxTotal+this.minTotal)/2}get maxTotal(){if(!this.hasExpressions())return 0;if(!this[Qt]){const t=this[ee](rt.max);this[Qt]=oe(t)}return this[Qt]}get minTotal(){if(!this.hasExpressions())return 0;if(!this[Yt]){const t=this[ee](rt.min);this[Yt]=oe(t)}return this[Yt]}get notation(){return this[Xt]}get output(){let t=`${this.notation}: `;return this.hasRolls()?t+=`${this[re]} = ${this.total}`:t+="No dice rolled",t}get rolls(){return this[re]?this[re].results:[]}get total(){return!this[ie]&&this.hasRolls()&&(this[ie]=oe(this[re])),this[ie]||0}export(t=Zt.JSON){switch(t){case Zt.BASE_64:return btoa(this.export(Zt.JSON));case Zt.JSON:return JSON.stringify(this);case Zt.OBJECT:return JSON.parse(this.export(Zt.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}hasExpressions(){return this[te]&&this[te].length>0}hasRolls(){return this.hasExpressions()&&this.rolls.length>0}roll(){return this[ie]=0,this[re]=this[ee](),this.rolls}toJSON(){const{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:i,rolls:o,total:s}=this;return{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:i,rolls:o,total:s,type:"dice-roll"}}toString(){return this.output}static import(t){if(t){if(zt(t))return DiceRoll.import(JSON.parse(t));if(Bt(t))return DiceRoll.import(atob(t));if("object"==typeof t)return new DiceRoll(t);throw new DataFormatError(t)}throw new RequiredArgumentError("data")}[ee](t){let e;t&&(e=nt.engine,nt.engine=t);const r=new ResultGroup(this[te].map((t=>t instanceof StandardDice||t instanceof RollGroup?t.roll():t)).filter((t=>!!t||0===t)));return t&&(nt.engine=e),r}[ne](t){if(t instanceof ResultGroup)this[re]=t;else if(t instanceof RollResults)this[re]=new ResultGroup([t]);else{if(!Array.isArray(t))throw new TypeError("Rolls must be a valid result object, or an array");this[re]=new ResultGroup(t.map((t=>{if(t instanceof ResultGroup||t instanceof RollResults)return t;if(Array.isArray(t))return new RollResults(t);if("object"==typeof t){if(Array.isArray(t.results))return new ResultGroup(t.results,t.modifiers||[],t.isRollGroup||!1,"boolean"!=typeof t.useInTotal||t.useInTotal);if(Array.isArray(t.rolls))return new RollResults(t.rolls)}return t})))}}}const se=Symbol("log");class DiceRoller{constructor(t){this[se]=[],t&&this.import(t)}get log(){return this[se]||[]}get output(){return this.log.join("; ")}get total(){return this.log.reduce(((t,e)=>t+e.total),0)}clearLog(){this[se].length=0}export(t=Zt.JSON){switch(t){case Zt.BASE_64:return btoa(this.export(Zt.JSON));case Zt.JSON:return JSON.stringify(this);case Zt.OBJECT:return JSON.parse(this.export(Zt.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}import(t){if(t){if(zt(t))return this.import(JSON.parse(t));if(Bt(t))return this.import(atob(t));if("object"==typeof t){let e=t.log||null;if(!t.log&&Array.isArray(t)&&t.length&&(e=t),e&&Array.isArray(e))e.forEach((t=>{this[se].push(DiceRoll.import(t))}));else if(e)throw new TypeError("log must be an array");return this.log}throw new DataFormatError(t)}throw new RequiredArgumentError("data")}roll(...t){const e=t.filter(Boolean);if(0===e.length)throw new RequiredArgumentError("notations");const r=e.map((t=>{const e=new DiceRoll(t);return this[se].push(e),e}));return r.length>1?r:r[0]}toJSON(){const{log:t,output:e,total:r}=this;return{log:t,output:e,total:r,type:"dice-roller"}}toString(){return this.output}static import(t){const e=new DiceRoller;return e.import(t),e}}export{ComparePoint,vt as Dice,DiceRoll,DiceRoller,e as Exceptions,kt as Modifiers,it as NumberGenerator,Parser,_t as Results,RollGroup,Zt as exportFormats}; |
/** | ||
* @dice-roller/rpg-dice-roller - An advanced JS based dice roller that can roll various types of dice and modifiers, along with mathematical equations. | ||
* | ||
* @version 5.4.1 | ||
* @version 5.5.0 | ||
* @license MIT | ||
@@ -10,2 +10,2 @@ * @author GreenImp Media <info@greenimp.co.uk> (https://greenimp.co.uk) | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mathjs"),require("random-js")):"function"==typeof define&&define.amd?define(["exports","mathjs","random-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).rpgDiceRoller={},t.math,t.Random)}(this,(function(t,e,r){"use strict";class CompareOperatorError extends TypeError{constructor(t){super(`Operator "${t}" is invalid`),TypeError.captureStackTrace&&TypeError.captureStackTrace(this,CompareOperatorError),this.name="CompareOperatorError",this.operator=t}}class DataFormatError extends Error{constructor(t){super(`Invalid data format: ${t}`),Error.captureStackTrace&&Error.captureStackTrace(this,DataFormatError),this.name="ImportError",this.data=t}}class DieActionValueError extends Error{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;super(`Die "${t}" must have more than 1 possible value to ${e||"do this action"}`),Error.captureStackTrace&&Error.captureStackTrace(this,DieActionValueError),this.name="DieActionValueError",this.action=e,this.die=t}}class NotationError extends Error{constructor(t){super(`Notation "${t}" is invalid`),Error.captureStackTrace&&Error.captureStackTrace(this,NotationError),this.name="NotationError",this.notation=t}}class RequiredArgumentError extends Error{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;super("Missing argument"+(t?` "${t}"`:"")),Error.captureStackTrace&&Error.captureStackTrace(this,RequiredArgumentError),this.argumentName=t}}var n=Object.freeze({__proto__:null,CompareOperatorError:CompareOperatorError,DataFormatError:DataFormatError,DieActionValueError:DieActionValueError,NotationError:NotationError,RequiredArgumentError:RequiredArgumentError});const o=t=>e.evaluate(t),i=t=>("number"==typeof t||"string"==typeof t)&&(!Number.isNaN(t)&&Number.isFinite(Number(t))),s=t=>{if(!i(t))return!1;const e=Number(t);return e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER},a=Symbol("engine"),u=Symbol("random"),l={range:[],next(){return this.range[1]-this.range[0]}},c={next:()=>0},h={browserCrypto:r.browserCrypto,nodeCrypto:r.nodeCrypto,MersenneTwister19937:r.MersenneTwister19937,nativeMath:r.nativeMath,min:c,max:l};const f=new class NumberGenerator{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r.nativeMath;this.engine=t||r.nativeMath}get engine(){return this[a]}set engine(t){if(t&&"function"!=typeof t.next)throw new TypeError("engine must have function `next()`");this[a]=t||r.nativeMath,this[u]=new r.Random(this[a])}integer(t,e){return this[a].range=[t,e],this[u].integer(t,e)}real(t,e){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this[a].range=[t,e],this[u].real(t,e,r)}};var p=Object.freeze({__proto__:null,engines:h,generator:f});const d=Symbol("operator"),m=Symbol("value");class ComparePoint{constructor(t,e){if(!t)throw new RequiredArgumentError("operator");if(!e&&0!==e)throw new RequiredArgumentError("value");this.operator=t,this.value=e}static isValidOperator(t){return"string"==typeof t&&/^(?:[<>!]?=|[<>]|<>)$/.test(t)}set operator(t){if(!this.constructor.isValidOperator(t))throw new CompareOperatorError(t);this[d]=t}get operator(){return this[d]}set value(t){if(!i(t))throw new TypeError("value must be a finite number");this[m]=Number(t)}get value(){return this[m]}isMatch(t){return((t,e,r)=>{const n=Number(t),o=Number(e);let i;if(Number.isNaN(n)||Number.isNaN(o))return!1;switch(r){case"=":case"==":i=n===o;break;case"<":i=n<o;break;case">":i=n>o;break;case"<=":i=n<=o;break;case">=":i=n>=o;break;case"!":case"!=":case"<>":i=n!==o;break;default:i=!1}return i})(t,this.value,this.operator)}toJSON(){const{operator:t,value:e}=this;return{operator:t,type:"compare-point",value:e}}toString(){return`${this.operator}${this.value}`}}class Modifier{static order=999;constructor(){this.order=this.constructor.order}get name(){return"modifier"}get notation(){return""}get maxIterations(){return 1e3}run(t,e){return t}toJSON(){const{notation:t,name:e}=this;return{name:e,notation:t,type:"modifier"}}toString(){return this.notation}}const g=Symbol("compare-point");class ComparisonModifier extends Modifier{constructor(t){super(),t&&(this.comparePoint=t)}get comparePoint(){return this[g]}set comparePoint(t){if(!(t instanceof ComparePoint))throw new TypeError("comparePoint must be instance of ComparePoint");this[g]=t}get name(){return"comparison"}get notation(){return`${this.comparePoint||""}`}isComparePoint(t){return!!this.comparePoint&&this.comparePoint.isMatch(t)}toJSON(){const{comparePoint:t}=this;return Object.assign(super.toJSON(),{comparePoint:t})}}const y=Symbol("compound"),v=Symbol("penetrate");class ExplodeModifier extends ComparisonModifier{static order=3;constructor(){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],e=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:null),this[y]=!!t,this[v]=!!e}get compound(){return this[y]}get name(){return"explode"}get notation(){return`!${this.compound?"!":""}${this.penetrate?"p":""}${super.notation}`}get penetrate(){return this[v]}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"explode");const r=t;return r.rolls=t.rolls.map((t=>{const r=[t];let n=t.value;for(let t=0;t<this.maxIterations&&this.isComparePoint(n);t++){const t=r[r.length-1],o=e.rollOnce();n=o.value,t.modifiers.add("explode"),this.penetrate&&(t.modifiers.add("penetrate"),o.value-=1),r.push(o)}return this.compound&&r.length>1?(t.value=(o=r.map((t=>t.value)),Array.isArray(o)?o.reduce(((t,e)=>t+(i(e)?parseFloat(`${e}`):0)),0):0),t.modifiers=["explode","compound"],this.penetrate&&t.modifiers.add("penetrate"),t):r;var o})).flat(),r}toJSON(){const{compound:t,penetrate:e}=this;return Object.assign(super.toJSON(),{compound:t,penetrate:e})}}const b=Symbol("text"),w=Symbol("type");class Description{static types={MULTILINE:"multiline",INLINE:"inline"};constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.constructor.types.INLINE;this.text=t,this.type=e}get text(){return this[b]}set text(t){if("object"==typeof t)throw new TypeError("Description text is invalid");if(!t&&0!==t||""===`${t}`.trim())throw new TypeError("Description text cannot be empty");this[b]=`${t}`.trim()}get type(){return this[w]}set type(t){const e=Object.values(this.constructor.types);if("string"!=typeof t)throw new TypeError("Description type must be a string");if(!e.includes(t))throw new RangeError(`Description type must be one of; ${e.join(", ")}`);this[w]=t}toJSON(){const{text:t,type:e}=this;return{text:t,type:e}}toString(){return this.type===this.constructor.types.INLINE?`# ${this.text}`:`[${this.text}]`}}const E=Symbol("description");class HasDescription{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.description=t}get description(){return this[E]||null}set description(t){if(t||0===t)if(t instanceof Description)this[E]=t;else{if("string"!=typeof t)throw new TypeError("description must be of type Description, string or null. Received "+typeof t);this[E]=new Description(t)}else this[E]=null}toJSON(){const{description:t}=this;return{description:t}}toString(){return this.description?`${this.description}`:""}}const S={compound:"!",explode:"!","critical-failure":"__","critical-success":"**",drop:"d",max:"v",min:"^",penetrate:"p","re-roll":"r","re-roll-once":"ro","target-failure":"_","target-success":"*",unique:"u","unique-once":"uo"},R=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return[...e].reduce(((t,e)=>{let r;return r=e instanceof Modifier?e.name:e,t+(S[r]||r)}),"")},x=Symbol("calculation-value"),A=Symbol("modifiers"),M=Symbol("initial-value"),C=Symbol("use-in-total"),T=Symbol("value");class RollResult{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(i(t))this[M]=Number(t),this.modifiers=e||[],this.useInTotal=r;else{if(!t||"object"!=typeof t||Array.isArray(t))throw t===1/0?new RangeError("Result value must be a finite number"):new TypeError(`Result value is invalid: ${t}`);{const n=i(t.initialValue)?t.initialValue:t.value;if(!i(n))throw new TypeError(`Result value is invalid: ${n}`);this[M]=Number(n),i(t.value)&&Number(t.value)!==this[M]&&(this.value=t.value),i(t.calculationValue)&&parseFloat(`${t.calculationValue}`)!==this.value&&(this.calculationValue=t.calculationValue),this.modifiers=t.modifiers||e||[],this.useInTotal="boolean"==typeof t.useInTotal?t.useInTotal:r||!1}}}get calculationValue(){return i(this[x])?parseFloat(this[x]):this.value}set calculationValue(t){const e=i(t);if(t===1/0)throw new RangeError("Result calculation value must be a finite number");if(t&&!e)throw new TypeError(`Result calculation value is invalid: ${t}`);this[x]=e?parseFloat(`${t}`):null}get initialValue(){return this[M]}get modifierFlags(){return R(...this.modifiers)}get modifiers(){return this[A]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[A]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[A]=new Set}}get useInTotal(){return!!this[C]}set useInTotal(t){this[C]=!!t}get value(){return i(this[T])?this[T]:this[M]}set value(t){if(t===1/0)throw new RangeError("Result value must be a finite number");if(!i(t))throw new TypeError(`Result value is invalid: ${t}`);this[T]=Number(t)}toJSON(){const{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:n,useInTotal:o,value:i}=this;return{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:[...n],type:"result",useInTotal:o,value:i}}toString(){return this.value+this.modifierFlags}}const N=Symbol("rolls");class RollResults{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.rolls=t}get length(){return this.rolls.length||0}get rolls(){return[...this[N]]}set rolls(t){if(!t||!Array.isArray(t))throw new TypeError(`rolls must be an array: ${t}`);this[N]=[],t.forEach((t=>{this.addRoll(t)}))}get value(){return this.rolls.reduce(((t,e)=>t+(e.useInTotal?e.calculationValue:0)),0)}addRoll(t){const e=t instanceof RollResult?t:new RollResult(t);this[N].push(e)}toJSON(){const{rolls:t,value:e}=this;return{rolls:t,type:"roll-results",value:e}}toString(){return`[${this.rolls.join(", ")}]`}}const O=Symbol("once");class ReRollModifier extends ComparisonModifier{static order=4;constructor(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];super(arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),this.once=!!t}get name(){return"re-roll"}get notation(){return`r${this.once?"o":""}${super.notation}`}get once(){return!!this[O]}set once(t){this[O]=!!t}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.map((t=>{for(let r=0;r<this.maxIterations&&this.isComparePoint(t.value);r++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("re-roll"+(this.once?"-once":"")),this.once)break}return t})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}const $=Symbol("modifiers"),D=Symbol("qty"),P=Symbol("sides"),F=Symbol("min-value"),j=Symbol("max-value");class StandardDice extends HasDescription{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;if(super(arguments.length>5&&void 0!==arguments[5]?arguments[5]:null),!t&&0!==t)throw new RequiredArgumentError("sides");if(t===1/0)throw new RangeError("numerical sides must be finite number");if(i(t)){if(t<1||!s(t))throw new RangeError("numerical sides must be a positive finite number")}else if("string"!=typeof t)throw new TypeError("non-numerical sides must be a string");if(!i(e))throw new TypeError("qty must be a positive finite integer");if(e<1||e>999)throw new RangeError("qty must be between 1 and 999");let a=n;if(null==a)a=1;else{if(!i(a))throw new TypeError("min must a finite number");if(!s(a))throw new RangeError("min must a finite number")}if(o&&!i(o))throw new TypeError("max must a finite number");if(o&&!s(o))throw new RangeError("max must a finite number");this[D]=parseInt(`${e}`,10),this[P]=t,r&&(this.modifiers=r),this[F]=parseInt(a,10),this[j]=o?parseInt(`${o}`,10):t}get average(){return(this.min+this.max)/2}get modifiers(){return this[$]?new Map([...this[$]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[$]=e,this[$].forEach((t=>{t instanceof ExplodeModifier&&!t.comparePoint?t.comparePoint=new ComparePoint("=",this.max):t instanceof ReRollModifier&&!t.comparePoint&&(t.comparePoint=new ComparePoint("=",this.min))}))}get max(){return this[j]}get min(){return this[F]}get name(){return"standard"}get notation(){let t=`${this.qty}d${this.sides}`;return this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}get qty(){return this[D]}get sides(){return this[P]}roll(){const t=new RollResults;for(let e=0;e<this.qty;e++)t.addRoll(this.rollOnce());return(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}rollOnce(){return new RollResult(f.integer(this.min,this.max))}toJSON(){const{average:t,max:e,min:r,modifiers:n,name:o,notation:i,qty:s,sides:a}=this;return Object.assign(super.toJSON(),{average:t,max:e,min:r,modifiers:n,name:o,notation:i,qty:s,sides:a,type:"die"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}class FudgeDice extends StandardDice{constructor(){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2;if(n||0===n){if(1!==n&&2!==n)throw new RangeError("nonBlanks must be 1 or 2")}else n=2;super(n,t,e,-1,1,r)}get name(){return"fudge"}get nonBlanks(){return super.sides}get sides(){return`F.${this.nonBlanks}`}rollOnce(){let t=0;if(2===this.nonBlanks)t=f.integer(1,3)-2;else if(1===this.nonBlanks){const e=f.integer(1,6);1===e?t=-1:6===e&&(t=1)}return new RollResult(t)}}class PercentileDice extends StandardDice{constructor(){let t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(100,arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,null,null,arguments.length>3&&void 0!==arguments[3]?arguments[3]:null),this.sidesAsNumber=!!t}get name(){return"percentile"}get sides(){return this.sidesAsNumber?super.sides:"%"}}var J=Object.freeze({__proto__:null,FudgeDice:FudgeDice,PercentileDice:PercentileDice,StandardDice:StandardDice});class CriticalFailureModifier extends ComparisonModifier{static order=10;constructor(t){super(t)}get name(){return"critical-failure"}get notation(){return`cf${super.notation}`}run(t,e){return t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-failure"),t))),t}}class CriticalSuccessModifier extends ComparisonModifier{static order=9;constructor(t){super(t)}get name(){return"critical-success"}get notation(){return`cs${super.notation}`}run(t,e){return t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-success"),t))),t}}const I=Symbol("calculation-value"),q=Symbol("is-roll-group"),G=Symbol("modifiers"),V=Symbol("results"),_=Symbol("use-in-total");class ResultGroup{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];this.isRollGroup=r,this.modifiers=e,this.results=t,this.useInTotal=n}get calculationValue(){return i(this[I])?parseFloat(this[I]):this.value}set calculationValue(t){const e=i(t);if(t===1/0)throw new RangeError("Results calculation value must be a finite number");if(t&&!e)throw new TypeError(`Results calculation value is invalid: ${t}`);this[I]=e?parseFloat(`${t}`):null}get isRollGroup(){return this[q]}set isRollGroup(t){this[q]=!!t}get length(){return this.results.length||0}get modifierFlags(){return R(...this.modifiers)}get modifiers(){return this[G]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[G]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[G]=new Set}}get results(){return[...this[V]]}set results(t){if(!t||!Array.isArray(t))throw new TypeError(`results must be an array: ${t}`);this[V]=[],t.forEach((t=>{this.addResult(t)}))}get useInTotal(){return!!this[_]}set useInTotal(t){this[_]=!!t}get value(){if(!this.results.length)return 0;const t=this.results.reduce(((t,e)=>{let r=e;return e instanceof ResultGroup?r=e.useInTotal?e.calculationValue:0:e instanceof RollResults&&(r=e.value),t+r}),"string"==typeof this.results[0]?"":0);return"string"==typeof t?o(t):t}addResult(t){let e;if(t instanceof ResultGroup||t instanceof RollResults)e=t;else{if("string"!=typeof t&&!i(t))throw new TypeError("value must be one of ResultGroup, RollResults, string, or number");e=t}this[V].push(e)}toJSON(){const{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:n,results:o,useInTotal:i,value:s}=this;return{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:[...n],results:o,type:"result-group",useInTotal:i,value:s}}toString(){let t;return t=this.isRollGroup?`{${this.results.join(", ")}}`:this.results.join(""),this.modifierFlags&&(t=`(${t})${this.modifierFlags}`),t}}const k=Symbol("end"),B=Symbol("qty");class KeepModifier extends Modifier{static order=6;constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"h",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;super(),this.end=t,this.qty=e}get end(){return this[k]}set end(t){if("h"!==t&&"l"!==t)throw new RangeError('End must be "h" or "l"');this[k]=t}get name(){return`keep-${this.end}`}get notation(){return`k${this.end}${this.qty}`}get qty(){return this[B]}set qty(t){if(t===1/0)throw new RangeError("qty must be a finite number");if(!i(t)||t<1)throw new TypeError("qty must be a positive finite integer");this[B]=Math.floor(t)}rangeToDrop(t){return"h"===this.end?[0,t.length-this.qty]:[this.qty,t.length]}run(t,e){let r,n;return t instanceof ResultGroup?(r=t.results,n=1===r.length&&r[0]instanceof ResultGroup?r[0].results.map(((t,e)=>t instanceof RollResults?t.rolls.map(((t,r)=>({value:t.value,index:[e,r]}))):null)).flat().filter(Boolean):[...r].map(((t,e)=>({value:t.value,index:e})))):(r=t.rolls,n=[...r].map(((t,e)=>({value:t.value,index:e})))),n=n.sort(((t,e)=>t.value-e.value)).map((t=>t.index)).slice(...this.rangeToDrop(n)),n.forEach((t=>{let e;e=Array.isArray(t)?r[0].results[t[0]].rolls[t[1]]:r[t],e.modifiers.add("drop"),e.useInTotal=!1})),t}toJSON(){const{end:t,qty:e}=this;return Object.assign(super.toJSON(),{end:t,qty:e})}}class DropModifier extends KeepModifier{static order=7;constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"l",arguments.length>1&&void 0!==arguments[1]?arguments[1]:1)}get name(){return`drop-${this.end}`}get notation(){return`d${this.end}${this.qty}`}rangeToDrop(t){return"h"===this.end?[t.length-this.qty,t.length]:[0,this.qty]}}const L=Symbol("max");class MaxModifier extends Modifier{static order=2;constructor(t){super(),this.max=t}get max(){return this[L]}set max(t){if(!i(t))throw new TypeError("max must be a number");this[L]=parseFloat(`${t}`)}get name(){return"max"}get notation(){return`max${this.max}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value>this.max&&(e.value=this.max,e.modifiers.add("max")),e})),r}toJSON(){const{max:t}=this;return Object.assign(super.toJSON(),{max:t})}}const z=Symbol("min");class MinModifier extends Modifier{static order=1;constructor(t){super(),this.min=t}get min(){return this[z]}set min(t){if(!i(t))throw new TypeError("min must be a number");this[z]=parseFloat(`${t}`)}get name(){return"min"}get notation(){return`min${this.min}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value<this.min&&(e.value=this.min,e.modifiers.add("min")),e})),r}toJSON(){const{min:t}=this;return Object.assign(super.toJSON(),{min:t})}}const U=Symbol("direction");class SortingModifier extends Modifier{static order=11;constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"a";super(),this.direction=t}get direction(){return this[U]}set direction(t){if("a"!==t&&"d"!==t)throw new RangeError('Direction must be "a" (Ascending) or "d" (Descending)');this[U]=t}get name(){return"sorting"}get notation(){return`s${this.direction}`}run(t,e){let r;return r=t instanceof ResultGroup?"results":"rolls",t[r]=t[r].sort(((t,e)=>"d"===this.direction?e.value-t.value:t.value-e.value)),t instanceof ResultGroup&&(t[r]=t[r].map((t=>t instanceof ResultGroup||t instanceof RollResults?this.run(t,e):t))),t}toJSON(){const{direction:t}=this;return Object.assign(super.toJSON(),{direction:t})}}const K=Symbol("failure-cp");class TargetModifier extends ComparisonModifier{static order=8;constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;super(t),this.failureComparePoint=e}get failureComparePoint(){return this[K]}set failureComparePoint(t){if(t&&!(t instanceof ComparePoint))throw new TypeError("failure comparePoint must be instance of ComparePoint or null");this[K]=t||null}get name(){return"target"}get notation(){return`${super.notation}${this.failureComparePoint?`f${this.failureComparePoint}`:""}`}get successComparePoint(){return this.comparePoint}set successComparePoint(t){super.comparePoint=t}getStateValue(t){return this.isSuccess(t)?1:this.isFailure(t)?-1:0}isFailure(t){return!!this.failureComparePoint&&this.failureComparePoint.isMatch(t)}isNeutral(t){return!this.isSuccess(t)&&!this.isFailure(t)}isSuccess(t){return this.isComparePoint(t)}run(t,e){let r;return r=t instanceof ResultGroup?t.results:t.rolls,r.forEach((t=>{this.isSuccess(t.value)?t.modifiers.add("target-success"):this.isFailure(t.value)&&t.modifiers.add("target-failure"),t.calculationValue=this.getStateValue(t.value)})),t}toJSON(){const{failureComparePoint:t,successComparePoint:e}=this,r=super.toJSON();return delete r.comparePoint,Object.assign(r,{failureComparePoint:t,successComparePoint:e})}}const H=Symbol("once"),X=function(t,e,r){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const o=r.map((t=>t.value)).indexOf(t.value);return n?o<e:o!==e};class UniqueModifier extends ComparisonModifier{static order=5;constructor(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];super(arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),this.once=!!t}get name(){return"unique"}get notation(){return`u${this.once?"o":""}${super.notation}`}get once(){return!!this[H]}set once(t){this[H]=!!t}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.forEach(((t,r,n)=>{if(0!==r)for(let o=0;o<this.maxIterations&&(!this.comparePoint||this.isComparePoint(t.value))&&X(t,r,n,!0);o++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("unique"+(this.once?"-once":"")),this.once)break}})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}var Q=Object.freeze({__proto__:null,ComparisonModifier:ComparisonModifier,CriticalFailureModifier:CriticalFailureModifier,CriticalSuccessModifier:CriticalSuccessModifier,DropModifier:DropModifier,ExplodeModifier:ExplodeModifier,KeepModifier:KeepModifier,MaxModifier:MaxModifier,MinModifier:MinModifier,Modifier:Modifier,ReRollModifier:ReRollModifier,SortingModifier:SortingModifier,TargetModifier:TargetModifier,UniqueModifier:UniqueModifier}),W=Object.freeze({__proto__:null,ResultGroup:ResultGroup,RollResult:RollResult,RollResults:RollResults});const Y=t=>{try{return!(!t||btoa(atob(t))!==t)}catch(t){return!1}},Z=t=>{try{const e=!!t&&JSON.parse(t);return!(!e||"object"!=typeof e)}catch(t){return!1}},tt=Symbol("expressions"),et=Symbol("modifiers");class RollGroup extends HasDescription{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];super(arguments.length>2&&void 0!==arguments[2]?arguments[2]:null),this.expressions=t,this.modifiers=e}get expressions(){return[...this[tt]||[]]}set expressions(t){if(!t)throw new RequiredArgumentError("expressions");if(!Array.isArray(t))throw new TypeError(`expressions must be an array: ${t}`);this[tt]=[],t.forEach((e=>{if(!e||!Array.isArray(e))throw new TypeError(`Expressions must be an array of arrays: ${t}`);if(0===e.length)throw new TypeError(`Sub expressions cannot be empty: ${t}`);if(!e.every((t=>t instanceof StandardDice||"string"==typeof t||"number"==typeof t)))throw new TypeError("Sub expression items must be Dice, numbers, or strings");this[tt].push(e)}))}get modifiers(){return this[et]?new Map([...this[et]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[et]=e}get notation(){let t=this.expressions.map((t=>t.reduce(((t,e)=>t+e),""))).join(", ");return t=`{${t}}`,this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}roll(){const t=new ResultGroup(this.expressions.map((t=>{const e=t.map((t=>t instanceof StandardDice?t.roll():t));return new ResultGroup(e)})));return t.isRollGroup=!0,(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}toJSON(){const{modifiers:t,notation:e,expressions:r}=this;return Object.assign(super.toJSON(),{expressions:r,modifiers:t,notation:e,type:"group"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}function rt(t,e,r,n){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,rt.prototype),o.expected=e,o.found=r,o.location=n,o.name="SyntaxError",o}function nt(t,e,r){return r=r||" ",t.length>e?t:(e-=t.length,t+(r+=r.repeat(e)).slice(0,e))}function ot(t,e){var r,n,i,s,a={},u=(e=void 0!==e?e:{}).grammarSource,l={Main:Er},c=Er,h="{",f=",",p="}",d="d",m="d%",g="dF",y=".",v="!",b="p",w="k",E="max",S="min",R="r",x="o",A="u",M="cs",C="cf",T="s",N="a",O="f",$="!=",D="<=",P=">=",F="=",j="<>",J=">",I="<",q="(",G=")",V="abs",_="ceil",k="cos",B="exp",L="floor",z="log",U="round",K="sign",H="sin",X="sqrt",Q="tan",W="pow",Y="-",Z="**",tt="*",et="^",nt="%",ot="/",it="+",st="/*",at="*/",ut="[",lt="]",ct="//",ht="#",ft=/^[12]/,pt=/^[lh]/,dt=/^[.]/,mt=/^[1-9]/,gt=/^[0-9]/,yt=/^[^\]]/,vt=/^[\n\r\u2028\u2029]/,bt=/^[ \t\n\r]/,wt=mr("{",!1),Et=mr(",",!1),St=mr("}",!1),Rt=mr("d",!1),xt=mr("d%",!1),At=mr("dF",!1),Mt=mr(".",!1),Ct=gr(["1","2"],!1,!1),Tt=mr("!",!1),Nt=mr("p",!1),Ot=gr(["l","h"],!1,!1),$t=mr("k",!1),Dt=mr("max",!1),Pt=mr("min",!1),Ft=mr("r",!1),jt=mr("o",!1),Jt=mr("u",!1),It=mr("cs",!1),qt=mr("cf",!1),Gt=mr("s",!1),Vt=mr("a",!1),_t=mr("f",!1),kt=mr("!=",!1),Bt=mr("<=",!1),Lt=mr(">=",!1),zt=mr("=",!1),Ut=mr("<>",!1),Kt=mr(">",!1),Ht=mr("<",!1),Xt=mr("(",!1),Qt=mr(")",!1),Wt=mr("abs",!1),Yt=mr("ceil",!1),Zt=mr("cos",!1),te=mr("exp",!1),ee=mr("floor",!1),re=mr("log",!1),ne=mr("round",!1),oe=mr("sign",!1),ie=mr("sin",!1),se=mr("sqrt",!1),ae=mr("tan",!1),ue=mr("pow",!1),le=mr("-",!1),ce=gr(["."],!1,!1),he=gr([["1","9"]],!1,!1),fe=gr([["0","9"]],!1,!1),pe=mr("**",!1),de=mr("*",!1),me=mr("^",!1),ge=mr("%",!1),ye=mr("/",!1),ve=mr("+",!1),be=yr("comment"),we=mr("/*",!1),Ee=mr("*/",!1),Se={type:"any"},Re=mr("[",!1),xe=gr(["]"],!0,!1),Ae=mr("]",!1),Me=mr("//",!1),Ce=mr("#",!1),Te=gr(["\n","\r","\u2028","\u2029"],!1,!1),Ne=yr("whitespace"),Oe=gr([" ","\t","\n","\r"],!1,!1),$e=yr("whitespace or comment"),De=function(t,e,r,n){return new RollGroup([t,...e.map((t=>t[3]))],Object.assign({},...r.map((t=>({[t.name]:t})))),n.find((t=>t instanceof Description)))},Pe=function(t,e,r){return t.modifiers=Object.assign({},...e.map((t=>({[t.name]:t})))),t.description=r.find((t=>t instanceof Description)),t},Fe=function(t,e){return new StandardDice(e,t||1)},je=function(t){return new PercentileDice(t||1)},Je=function(t,e){return new FudgeDice(e?parseInt(e[1],10):2,t||1)},Ie=function(t,e,r){return new ExplodeModifier(r,!!t,!!e)},qe=function(t,e){return new TargetModifier(t,e)},Ge=function(t,e){return new DropModifier(t||"l",e)},Ve=function(t,e){return new KeepModifier(t||"h",e)},_e=function(t){return new MaxModifier(t)},ke=function(t){return new MinModifier(t)},Be=function(t,e){return new ReRollModifier(!!t,e)},Le=function(t,e){return new UniqueModifier(!!t,e)},ze=function(t){return new CriticalSuccessModifier(t)},Ue=function(t){return new CriticalFailureModifier(t)},Ke=function(t){return new SortingModifier(t||"a")},He=function(t){return t},Xe=function(t,e){return new ComparePoint(t,e)},Qe=function(t,e,r){return o(dr())},We=function(t,e){return t=Array.isArray(t)?t:[t],[...t,...e.map((t=>{let[,e,,r]=t;return[e,r]})).flat(2)]},Ye=function(t,e,r){return[t,...e,r]},Ze=function(t,e){return[`${t}(`,...e,")"]},tr=function(t,e,r){return[`${t}(`,...e,",",...r,")"]},er=function(){return parseFloat(dr())},rr=function(){return parseInt(dr(),10)},nr=function(){return parseInt(dr(),10)},or=function(){return"^"},ir=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},sr=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},ar=function(t){return new Description(t.flat().join(""),Description.types.INLINE)},ur=0,lr=0,cr=[{line:1,column:1}],hr=0,fr=[],pr=0;if("startRule"in e){if(!(e.startRule in l))throw new Error("Can't start parsing from rule \""+e.startRule+'".');c=l[e.startRule]}function dr(){return t.substring(lr,ur)}function mr(t,e){return{type:"literal",text:t,ignoreCase:e}}function gr(t,e,r){return{type:"class",parts:t,inverted:e,ignoreCase:r}}function yr(t){return{type:"other",description:t}}function vr(e){var r,n=cr[e];if(n)return n;for(r=e-1;!cr[r];)r--;for(n={line:(n=cr[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return cr[e]=n,n}function br(t,e){var r=vr(t),n=vr(e);return{source:u,start:{offset:t,line:r.line,column:r.column},end:{offset:e,line:n.line,column:n.column}}}function wr(t){ur<hr||(ur>hr&&(hr=ur,fr=[]),fr.push(t))}function Er(){return Mr()}function Sr(){var e,r,n,o;if(e=ur,r=function(){var e,r,n,o;e=ur,r=Ar(),r===a&&(r=null);100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&wr(Rt));n!==a&&(o=Ar())!==a?(lr=e,e=Fe(r,o)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n;e=ur,r=Ar(),r===a&&(r=null);t.substr(ur,2)===m?(n=m,ur+=2):(n=a,0===pr&&wr(xt));n!==a?(lr=e,e=je(r)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n,o,i,s;e=ur,r=Ar(),r===a&&(r=null);t.substr(ur,2)===g?(n=g,ur+=2):(n=a,0===pr&&wr(At));n!==a?(o=ur,46===t.charCodeAt(ur)?(i=y,ur++):(i=a,0===pr&&wr(Mt)),i!==a?(ft.test(t.charAt(ur))?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Ct)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a),o===a&&(o=null),lr=e,e=Je(r,o)):(ur=e,e=a);return e}())),r!==a){for(n=[],o=Rr();o!==a;)n.push(o),o=Rr();o=Jr(),lr=e,e=Pe(r,n,o)}else ur=e,e=a;return e}function Rr(){var e;return(e=function(){var e,r,n,o,i;e=ur,33===t.charCodeAt(ur)?(r=v,ur++):(r=a,0===pr&&wr(Tt));r!==a?(33===t.charCodeAt(ur)?(n=v,ur++):(n=a,0===pr&&wr(Tt)),n===a&&(n=null),112===t.charCodeAt(ur)?(o=b,ur++):(o=a,0===pr&&wr(Nt)),o===a&&(o=null),(i=xr())===a&&(i=null),lr=e,e=Ie(n,o,i)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,(r=xr())!==a?(n=function(){var e,r,n;e=ur,102===t.charCodeAt(ur)?(r=O,ur++):(r=a,0===pr&&wr(_t));r!==a&&(n=xr())!==a?(lr=e,e=He(n)):(ur=e,e=a);return e}(),n===a&&(n=null),lr=e,e=qe(r,n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,100===t.charCodeAt(ur)?(r=d,ur++):(r=a,0===pr&&wr(Rt));r!==a?(pt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(Ot)),n===a&&(n=null),(o=Nr())!==a?(lr=e,e=Ge(n,o)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,107===t.charCodeAt(ur)?(r=w,ur++):(r=a,0===pr&&wr($t));r!==a?(pt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(Ot)),n===a&&(n=null),(o=Nr())!==a?(lr=e,e=Ve(n,o)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,114===t.charCodeAt(ur)?(r=R,ur++):(r=a,0===pr&&wr(Ft));r!==a?(111===t.charCodeAt(ur)?(n=x,ur++):(n=a,0===pr&&wr(jt)),n===a&&(n=null),(o=xr())===a&&(o=null),lr=e,e=Be(n,o)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,117===t.charCodeAt(ur)?(r=A,ur++):(r=a,0===pr&&wr(Jt));r!==a?(111===t.charCodeAt(ur)?(n=x,ur++):(n=a,0===pr&&wr(jt)),n===a&&(n=null),(o=xr())===a&&(o=null),lr=e,e=Le(n,o)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===M?(r=M,ur+=2):(r=a,0===pr&&wr(It));r!==a&&(n=xr())!==a?(lr=e,e=ze(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===C?(r=C,ur+=2):(r=a,0===pr&&wr(qt));r!==a&&(n=xr())!==a?(lr=e,e=Ue(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,115===t.charCodeAt(ur)?(r=T,ur++):(r=a,0===pr&&wr(Gt));r!==a?(97===t.charCodeAt(ur)?(n=N,ur++):(n=a,0===pr&&wr(Vt)),n===a&&(100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&wr(Rt))),n===a&&(n=null),lr=e,e=Ke(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&wr(Dt));r!==a&&(n=Tr())!==a?(lr=e,e=_e(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===S?(r=S,ur+=3):(r=a,0===pr&&wr(Pt));r!==a&&(n=Tr())!==a?(lr=e,e=ke(n)):(ur=e,e=a);return e}()),e}function xr(){var e,r,n;return e=ur,r=function(){var e;t.substr(ur,2)===$?(e=$,ur+=2):(e=a,0===pr&&wr(kt));e===a&&(t.substr(ur,2)===D?(e=D,ur+=2):(e=a,0===pr&&wr(Bt)),e===a&&(t.substr(ur,2)===P?(e=P,ur+=2):(e=a,0===pr&&wr(Lt)),e===a&&(61===t.charCodeAt(ur)?(e=F,ur++):(e=a,0===pr&&wr(zt)),e===a&&(t.substr(ur,2)===j?(e=j,ur+=2):(e=a,0===pr&&wr(Ut)),e===a&&(62===t.charCodeAt(ur)?(e=J,ur++):(e=a,0===pr&&wr(Kt)),e===a&&(60===t.charCodeAt(ur)?(e=I,ur++):(e=a,0===pr&&wr(Ht))))))));return e}(),r!==a&&(n=Tr())!==a?(lr=e,e=Xe(r,n)):(ur=e,e=a),e}function Ar(){var e,r,n,o,i,s,u,l,c,h;if((e=Nr())===a)if(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&wr(Xt)),r!==a){if(jr(),n=ur,(o=Tr())!==a){if(i=[],s=ur,u=jr(),(l=$r())!==a?(c=jr(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a),s!==a)for(;s!==a;)i.push(s),s=ur,u=jr(),(l=$r())!==a?(c=jr(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a);else i=a;i!==a?n=o=[o,i]:(ur=n,n=a)}else ur=n,n=a;n!==a?(o=jr(),41===t.charCodeAt(ur)?(i=G,ur++):(i=a,0===pr&&wr(Qt)),i!==a?(lr=e,e=Qe()):(ur=e,e=a)):(ur=e,e=a)}else ur=e,e=a;return e}function Mr(){var t,e,r,n,o,i,s,u;if(t=ur,(e=Cr())!==a){for(r=[],n=ur,o=jr(),(i=$r())!==a?(s=jr(),(u=Cr())!==a?n=o=[o,i,s,u]:(ur=n,n=a)):(ur=n,n=a);n!==a;)r.push(n),n=ur,o=jr(),(i=$r())!==a?(s=jr(),(u=Cr())!==a?n=o=[o,i,s,u]:(ur=n,n=a)):(ur=n,n=a);lr=t,t=We(e,r)}else ur=t,t=a;return t}function Cr(){var e,r,n,o;return e=function(){var e,r,n,o,i,s,u;e=ur,t.substr(ur,3)===V?(r=V,ur+=3):(r=a,0===pr&&wr(Wt));r===a&&(t.substr(ur,4)===_?(r=_,ur+=4):(r=a,0===pr&&wr(Yt)),r===a&&(t.substr(ur,3)===k?(r=k,ur+=3):(r=a,0===pr&&wr(Zt)),r===a&&(t.substr(ur,3)===B?(r=B,ur+=3):(r=a,0===pr&&wr(te)),r===a&&(t.substr(ur,5)===L?(r=L,ur+=5):(r=a,0===pr&&wr(ee)),r===a&&(t.substr(ur,3)===z?(r=z,ur+=3):(r=a,0===pr&&wr(re)),r===a&&(t.substr(ur,5)===U?(r=U,ur+=5):(r=a,0===pr&&wr(ne)),r===a&&(t.substr(ur,4)===K?(r=K,ur+=4):(r=a,0===pr&&wr(oe)),r===a&&(t.substr(ur,3)===H?(r=H,ur+=3):(r=a,0===pr&&wr(ie)),r===a&&(t.substr(ur,4)===X?(r=X,ur+=4):(r=a,0===pr&&wr(se)),r===a&&(t.substr(ur,3)===Q?(r=Q,ur+=3):(r=a,0===pr&&wr(ae))))))))))));r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&wr(Xt)),n!==a?(jr(),(o=Mr())!==a?(jr(),41===t.charCodeAt(ur)?(i=G,ur++):(i=a,0===pr&&wr(Qt)),i!==a?(lr=e,e=Ze(r,o)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a);e===a&&(e=ur,t.substr(ur,3)===W?(r=W,ur+=3):(r=a,0===pr&&wr(ue)),r===a&&(t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&wr(Dt)),r===a&&(t.substr(ur,3)===S?(r=S,ur+=3):(r=a,0===pr&&wr(Pt)))),r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&wr(Xt)),n!==a?(jr(),(o=Mr())!==a?(jr(),44===t.charCodeAt(ur)?(i=f,ur++):(i=a,0===pr&&wr(Et)),i!==a?(jr(),(s=Mr())!==a?(jr(),41===t.charCodeAt(ur)?(u=G,ur++):(u=a,0===pr&&wr(Qt)),u!==a?(lr=e,e=tr(r,o,s)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a));return e}(),e===a&&(e=Sr())===a&&(e=Tr())===a&&(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&wr(Xt)),r!==a?(jr(),(n=Mr())!==a?(jr(),41===t.charCodeAt(ur)?(o=G,ur++):(o=a,0===pr&&wr(Qt)),o!==a?(lr=e,e=Ye(r,n,o)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a),e===a&&(e=function(){var e,r,n,o,i,s,u,l,c;if(e=ur,123===t.charCodeAt(ur)?(r=h,ur++):(r=a,0===pr&&wr(wt)),r!==a)if(jr(),(n=Mr())!==a){for(o=[],i=ur,s=jr(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&wr(Et)),u!==a?(l=jr(),(c=Mr())!==a?i=s=[s,u,l,c]:(ur=i,i=a)):(ur=i,i=a);i!==a;)o.push(i),i=ur,s=jr(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&wr(Et)),u!==a?(l=jr(),(c=Mr())!==a?i=s=[s,u,l,c]:(ur=i,i=a)):(ur=i,i=a);if(i=jr(),125===t.charCodeAt(ur)?(s=p,ur++):(s=a,0===pr&&wr(St)),s!==a){for(u=[],l=Rr();l!==a;)u.push(l),l=Rr();l=Jr(),lr=e,e=De(n,o,u,l)}else ur=e,e=a}else ur=e,e=a;else ur=e,e=a;return e}())),e}function Tr(){var e,r,n,o;return e=ur,45===t.charCodeAt(ur)?ur++:0===pr&&wr(le),Or()!==a?(r=ur,dt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(ce)),n!==a&&(o=Or())!==a?r=n=[n,o]:(ur=r,r=a),r===a&&(r=null),lr=e,e=er()):(ur=e,e=a),e}function Nr(){var e,r,n,o;if(e=ur,mt.test(t.charAt(ur))?(r=t.charAt(ur),ur++):(r=a,0===pr&&wr(he)),r!==a){for(n=[],gt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(fe));o!==a;)n.push(o),gt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(fe));lr=e,e=rr()}else ur=e,e=a;return e}function Or(){var e,r,n;if(e=ur,r=[],gt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(fe)),n!==a)for(;n!==a;)r.push(n),gt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(fe));else r=a;return r!==a&&(lr=e,r=nr()),e=r}function $r(){var e,r;return e=ur,t.substr(ur,2)===Z?(r=Z,ur+=2):(r=a,0===pr&&wr(pe)),r!==a&&(lr=e,r=or()),(e=r)===a&&(42===t.charCodeAt(ur)?(e=tt,ur++):(e=a,0===pr&&wr(de)),e===a&&(94===t.charCodeAt(ur)?(e=et,ur++):(e=a,0===pr&&wr(me)),e===a&&(37===t.charCodeAt(ur)?(e=nt,ur++):(e=a,0===pr&&wr(ge)),e===a&&(47===t.charCodeAt(ur)?(e=ot,ur++):(e=a,0===pr&&wr(ye)),e===a&&(43===t.charCodeAt(ur)?(e=it,ur++):(e=a,0===pr&&wr(ve)),e===a&&(45===t.charCodeAt(ur)?(e=Y,ur++):(e=a,0===pr&&wr(le)))))))),e}function Dr(){var e;return pr++,(e=function(){var e,r,n,o,i,s;e=ur,t.substr(ur,2)===st?(r=st,ur+=2):(r=a,0===pr&&wr(we));if(r!==a){for(n=[],o=ur,i=ur,pr++,t.substr(ur,2)===at?(s=at,ur+=2):(s=a,0===pr&&wr(Ee)),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);o!==a;)n.push(o),o=ur,i=ur,pr++,t.substr(ur,2)===at?(s=at,ur+=2):(s=a,0===pr&&wr(Ee)),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);t.substr(ur,2)===at?(o=at,ur+=2):(o=a,0===pr&&wr(Ee)),o!==a?(lr=e,e=ir(n)):(ur=e,e=a)}else ur=e,e=a;if(e===a)if(e=ur,91===t.charCodeAt(ur)?(r=ut,ur++):(r=a,0===pr&&wr(Re)),r!==a){for(n=[],yt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(xe));o!==a;)n.push(o),yt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(xe));93===t.charCodeAt(ur)?(o=lt,ur++):(o=a,0===pr&&wr(Ae)),o!==a?(lr=e,e=sr(n)):(ur=e,e=a)}else ur=e,e=a;return e}())===a&&(e=function(){var e,r,n,o,i,s;e=ur,t.substr(ur,2)===ct?(r=ct,ur+=2):(r=a,0===pr&&wr(Me));r===a&&(35===t.charCodeAt(ur)?(r=ht,ur++):(r=a,0===pr&&wr(Ce)));if(r!==a){for(n=[],o=ur,i=ur,pr++,s=Pr(),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);o!==a;)n.push(o),o=ur,i=ur,pr++,s=Pr(),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);lr=e,e=ar(n)}else ur=e,e=a;return e}()),pr--,e===a&&0===pr&&wr(be),e}function Pr(){var e;return vt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&wr(Te)),e}function Fr(){var e;return pr++,bt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&wr(Oe)),pr--,e===a&&0===pr&&wr(Ne),e}function jr(){var t,e;for(t=[],e=Fr();e!==a;)t.push(e),e=Fr();return t}function Jr(){var t,e;for(pr++,t=[],(e=Fr())===a&&(e=Dr());e!==a;)t.push(e),(e=Fr())===a&&(e=Dr());return pr--,e=a,0===pr&&wr($e),t}if((r=c())!==a&&ur===t.length)return r;throw r!==a&&ur<t.length&&wr({type:"end"}),n=fr,i=hr<t.length?t.charAt(hr):null,s=hr<t.length?br(hr,hr+1):br(hr,hr),new rt(rt.buildMessage(n,i),n,i,s)}!function(t,e){function r(){this.constructor=t}r.prototype=e.prototype,t.prototype=new r}(rt,Error),rt.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var r,n=null;for(r=0;r<t.length;r++)if(t[r].source===this.location.source){n=t[r].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,i=this.location.source+":"+o.line+":"+o.column;if(n){var s=this.location.end,a=nt("",o.line.toString().length," "),u=n[o.line-1],l=(o.line===s.line?s.column:u.length+1)-o.column||1;e+="\n --\x3e "+i+"\n"+a+" |\n"+o.line+" | "+u+"\n"+a+" | "+nt("",o.column-1," ")+nt("",l,"^")}else e+="\n at "+i}return e},rt.buildMessage=function(t,e){var r={literal:function(t){return'"'+o(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?i(t[0])+"-"+i(t[1]):i(t)}));return"["+(t.inverted?"^":"")+e.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function o(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function i(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function s(t){return r[t.type](t)}return"Expected "+function(t){var e,r,n=t.map(s);if(n.sort(),n.length>0){for(e=1,r=1;e<n.length;e++)n[e-1]!==n[e]&&(n[r]=n[e],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(t)+" but "+function(t){return t?'"'+o(t)+'"':"end of input"}(e)+" found."};class Parser{static parse(t){if(!t)throw new RequiredArgumentError("notation");if("string"!=typeof t)throw new TypeError("Notation must be a string");return ot(t)}}const it=Object.freeze({BASE_64:1,JSON:0,OBJECT:2}),st=Symbol("notation"),at=Symbol("maxTotal"),ut=Symbol("minTotal"),lt=Symbol("expressions"),ct=Symbol("roll-method"),ht=Symbol("rolls"),ft=Symbol("set-rolls"),pt=Symbol("total"),dt=t=>function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return parseFloat(parseFloat(`${t}`).toFixed(e||0))}(t.calculationValue,2);class DiceRoll{constructor(t){if(!t)throw new RequiredArgumentError("notation");if(this[lt]=[],t instanceof Object&&!Array.isArray(t)){if(!t.notation)throw new RequiredArgumentError("notation");if("string"!=typeof t.notation)throw new NotationError(t.notation);t.rolls&&this[ft](t.rolls),this[st]=t.notation,this[lt]=Parser.parse(this.notation),this.hasRolls()||this.roll()}else{if("string"!=typeof t)throw new NotationError(t);this[st]=t,this[lt]=Parser.parse(this.notation),this.roll()}}get averageTotal(){return(this.maxTotal+this.minTotal)/2}get maxTotal(){if(!this.hasExpressions())return 0;if(!this[at]){const t=this[ct](h.max);this[at]=dt(t)}return this[at]}get minTotal(){if(!this.hasExpressions())return 0;if(!this[ut]){const t=this[ct](h.min);this[ut]=dt(t)}return this[ut]}get notation(){return this[st]}get output(){let t=`${this.notation}: `;return this.hasRolls()?t+=`${this[ht]} = ${this.total}`:t+="No dice rolled",t}get rolls(){return this[ht]?this[ht].results:[]}get total(){return!this[pt]&&this.hasRolls()&&(this[pt]=dt(this[ht])),this[pt]||0}export(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:it.JSON;switch(t){case it.BASE_64:return btoa(this.export(it.JSON));case it.JSON:return JSON.stringify(this);case it.OBJECT:return JSON.parse(this.export(it.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}hasExpressions(){return this[lt]&&this[lt].length>0}hasRolls(){return this.hasExpressions()&&this.rolls.length>0}roll(){return this[pt]=0,this[ht]=this[ct](),this.rolls}toJSON(){const{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:o,rolls:i,total:s}=this;return{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:o,rolls:i,total:s,type:"dice-roll"}}toString(){return this.output}static import(t){if(t){if(Z(t))return DiceRoll.import(JSON.parse(t));if(Y(t))return DiceRoll.import(atob(t));if("object"==typeof t)return new DiceRoll(t);throw new DataFormatError(t)}throw new RequiredArgumentError("data")}[ct](t){let e;t&&(e=f.engine,f.engine=t);const r=new ResultGroup(this[lt].map((t=>t instanceof StandardDice||t instanceof RollGroup?t.roll():t)).filter((t=>!!t||0===t)));return t&&(f.engine=e),r}[ft](t){if(t instanceof ResultGroup)this[ht]=t;else if(t instanceof RollResults)this[ht]=new ResultGroup([t]);else{if(!Array.isArray(t))throw new TypeError("Rolls must be a valid result object, or an array");this[ht]=new ResultGroup(t.map((t=>{if(t instanceof ResultGroup||t instanceof RollResults)return t;if(Array.isArray(t))return new RollResults(t);if("object"==typeof t){if(Array.isArray(t.results))return new ResultGroup(t.results,t.modifiers||[],t.isRollGroup||!1,"boolean"!=typeof t.useInTotal||t.useInTotal);if(Array.isArray(t.rolls))return new RollResults(t.rolls)}return t})))}}}const mt=Symbol("log");class DiceRoller{constructor(t){this[mt]=[],t&&this.import(t)}get log(){return this[mt]||[]}get output(){return this.log.join("; ")}get total(){return this.log.reduce(((t,e)=>t+e.total),0)}clearLog(){this[mt].length=0}export(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:it.JSON;switch(t){case it.BASE_64:return btoa(this.export(it.JSON));case it.JSON:return JSON.stringify(this);case it.OBJECT:return JSON.parse(this.export(it.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}import(t){if(t){if(Z(t))return this.import(JSON.parse(t));if(Y(t))return this.import(atob(t));if("object"==typeof t){let e=t.log||null;if(!t.log&&Array.isArray(t)&&t.length&&(e=t),e&&Array.isArray(e))e.forEach((t=>{this[mt].push(DiceRoll.import(t))}));else if(e)throw new TypeError("log must be an array");return this.log}throw new DataFormatError(t)}throw new RequiredArgumentError("data")}roll(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];const n=e.filter(Boolean);if(0===n.length)throw new RequiredArgumentError("notations");const o=n.map((t=>{const e=new DiceRoll(t);return this[mt].push(e),e}));return o.length>1?o:o[0]}toJSON(){const{log:t,output:e,total:r}=this;return{log:t,output:e,total:r,type:"dice-roller"}}toString(){return this.output}static import(t){const e=new DiceRoller;return e.import(t),e}}t.ComparePoint=ComparePoint,t.Dice=J,t.DiceRoll=DiceRoll,t.DiceRoller=DiceRoller,t.Exceptions=n,t.Modifiers=Q,t.NumberGenerator=p,t.Parser=Parser,t.Results=W,t.RollGroup=RollGroup,t.exportFormats=it,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mathjs"),require("random-js")):"function"==typeof define&&define.amd?define(["exports","mathjs","random-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).rpgDiceRoller={},t.math,t.Random)}(this,(function(t,e,r){"use strict";class CompareOperatorError extends TypeError{constructor(t){super(`Operator "${t}" is invalid`),TypeError.captureStackTrace&&TypeError.captureStackTrace(this,CompareOperatorError),this.name="CompareOperatorError",this.operator=t}}class DataFormatError extends Error{constructor(t){super(`Invalid data format: ${t}`),Error.captureStackTrace&&Error.captureStackTrace(this,DataFormatError),this.name="ImportError",this.data=t}}class DieActionValueError extends Error{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;super(`Die "${t}" must have more than 1 possible value to ${e||"do this action"}`),Error.captureStackTrace&&Error.captureStackTrace(this,DieActionValueError),this.name="DieActionValueError",this.action=e,this.die=t}}class NotationError extends Error{constructor(t){super(`Notation "${t}" is invalid`),Error.captureStackTrace&&Error.captureStackTrace(this,NotationError),this.name="NotationError",this.notation=t}}class RequiredArgumentError extends Error{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;super("Missing argument"+(t?` "${t}"`:"")),Error.captureStackTrace&&Error.captureStackTrace(this,RequiredArgumentError),this.argumentName=t}}var n=Object.freeze({__proto__:null,CompareOperatorError:CompareOperatorError,DataFormatError:DataFormatError,DieActionValueError:DieActionValueError,NotationError:NotationError,RequiredArgumentError:RequiredArgumentError});const o=t=>e.evaluate(t),i=t=>("number"==typeof t||"string"==typeof t)&&(!Number.isNaN(t)&&Number.isFinite(Number(t))),s=t=>{if(!i(t))return!1;const e=Number(t);return e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER},a=Symbol("engine"),u=Symbol("random"),l={range:[],next(){return this.range[1]-this.range[0]}},c={next:()=>0},h={browserCrypto:r.browserCrypto,nodeCrypto:r.nodeCrypto,MersenneTwister19937:r.MersenneTwister19937,nativeMath:r.nativeMath,min:c,max:l};const f=new class NumberGenerator{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r.nativeMath;this.engine=t||r.nativeMath}get engine(){return this[a]}set engine(t){if(t&&"function"!=typeof t.next)throw new TypeError("engine must have function `next()`");this[a]=t||r.nativeMath,this[u]=new r.Random(this[a])}integer(t,e){return this[a].range=[t,e],this[u].integer(t,e)}real(t,e){let r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return this[a].range=[t,e],this[u].real(t,e,r)}};var p=Object.freeze({__proto__:null,engines:h,generator:f});const d=Symbol("text"),m=Symbol("type");class Description{static types={MULTILINE:"multiline",INLINE:"inline"};constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.constructor.types.INLINE;this.text=t,this.type=e}get text(){return this[d]}set text(t){if("object"==typeof t)throw new TypeError("Description text is invalid");if(!t&&0!==t||""===`${t}`.trim())throw new TypeError("Description text cannot be empty");this[d]=`${t}`.trim()}get type(){return this[m]}set type(t){const e=Object.values(this.constructor.types);if("string"!=typeof t)throw new TypeError("Description type must be a string");if(!e.includes(t))throw new RangeError(`Description type must be one of; ${e.join(", ")}`);this[m]=t}toJSON(){const{text:t,type:e}=this;return{text:t,type:e}}toString(){return this.type===this.constructor.types.INLINE?`# ${this.text}`:`[${this.text}]`}}const g=Symbol("description");class HasDescription{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.description=t}get description(){return this[g]||null}set description(t){if(t||0===t)if(t instanceof Description)this[g]=t;else{if("string"!=typeof t)throw new TypeError("description must be of type Description, string or null. Received "+typeof t);this[g]=new Description(t)}else this[g]=null}toJSON(){const{description:t}=this;return{description:t}}toString(){return this.description?`${this.description}`:""}}class Modifier{static order=999;constructor(){this.order=this.constructor.order}get name(){return"modifier"}get notation(){return""}get maxIterations(){return 1e3}defaults(t){return{}}useDefaultsIfNeeded(t){Object.entries(this.defaults(t)).forEach((t=>{let[e,r]=t;void 0===this[e]&&(this[e]=r)}))}run(t,e){return this.useDefaultsIfNeeded(e),t}toJSON(){const{notation:t,name:e}=this;return{name:e,notation:t,type:"modifier"}}toString(){return this.notation}}const y={compound:"!",explode:"!","critical-failure":"__","critical-success":"**",drop:"d",max:"v",min:"^",penetrate:"p","re-roll":"r","re-roll-once":"ro","target-failure":"_","target-success":"*",unique:"u","unique-once":"uo"},v=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return[...e].reduce(((t,e)=>{let r;return r=e instanceof Modifier?e.name:e,t+(y[r]||r)}),"")},b=Symbol("calculation-value"),w=Symbol("modifiers"),E=Symbol("initial-value"),S=Symbol("use-in-total"),R=Symbol("value");class RollResult{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(i(t))this[E]=Number(t),this.modifiers=e||[],this.useInTotal=r;else{if(!t||"object"!=typeof t||Array.isArray(t))throw t===1/0?new RangeError("Result value must be a finite number"):new TypeError(`Result value is invalid: ${t}`);{const n=i(t.initialValue)?t.initialValue:t.value;if(!i(n))throw new TypeError(`Result value is invalid: ${n}`);this[E]=Number(n),i(t.value)&&Number(t.value)!==this[E]&&(this.value=t.value),i(t.calculationValue)&&parseFloat(`${t.calculationValue}`)!==this.value&&(this.calculationValue=t.calculationValue),this.modifiers=t.modifiers||e||[],this.useInTotal="boolean"==typeof t.useInTotal?t.useInTotal:r||!1}}}get calculationValue(){return i(this[b])?parseFloat(this[b]):this.value}set calculationValue(t){const e=i(t);if(t===1/0)throw new RangeError("Result calculation value must be a finite number");if(t&&!e)throw new TypeError(`Result calculation value is invalid: ${t}`);this[b]=e?parseFloat(`${t}`):null}get initialValue(){return this[E]}get modifierFlags(){return v(...this.modifiers)}get modifiers(){return this[w]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[w]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[w]=new Set}}get useInTotal(){return!!this[S]}set useInTotal(t){this[S]=!!t}get value(){return i(this[R])?this[R]:this[E]}set value(t){if(t===1/0)throw new RangeError("Result value must be a finite number");if(!i(t))throw new TypeError(`Result value is invalid: ${t}`);this[R]=Number(t)}toJSON(){const{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:n,useInTotal:o,value:i}=this;return{calculationValue:t,initialValue:e,modifierFlags:r,modifiers:[...n],type:"result",useInTotal:o,value:i}}toString(){return this.value+this.modifierFlags}}const x=Symbol("rolls");class RollResults{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.rolls=t}get length(){return this.rolls.length||0}get rolls(){return[...this[x]]}set rolls(t){if(!t||!Array.isArray(t))throw new TypeError(`rolls must be an array: ${t}`);this[x]=[],t.forEach((t=>{this.addRoll(t)}))}get value(){return this.rolls.reduce(((t,e)=>t+(e.useInTotal?e.calculationValue:0)),0)}addRoll(t){const e=t instanceof RollResult?t:new RollResult(t);this[x].push(e)}toJSON(){const{rolls:t,value:e}=this;return{rolls:t,type:"roll-results",value:e}}toString(){return`[${this.rolls.join(", ")}]`}}const A=Symbol("modifiers"),C=Symbol("qty"),M=Symbol("sides"),T=Symbol("min-value"),N=Symbol("max-value");class StandardDice extends HasDescription{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;if(super(arguments.length>5&&void 0!==arguments[5]?arguments[5]:null),!t&&0!==t)throw new RequiredArgumentError("sides");if(t===1/0)throw new RangeError("numerical sides must be finite number");if(i(t)){if(t<1||!s(t))throw new RangeError("numerical sides must be a positive finite number")}else if("string"!=typeof t)throw new TypeError("non-numerical sides must be a string");if(!i(e))throw new TypeError("qty must be a positive finite integer");if(e<1||e>999)throw new RangeError("qty must be between 1 and 999");let a=n;if(null==a)a=1;else{if(!i(a))throw new TypeError("min must a finite number");if(!s(a))throw new RangeError("min must a finite number")}if(o&&!i(o))throw new TypeError("max must a finite number");if(o&&!s(o))throw new RangeError("max must a finite number");this[C]=parseInt(`${e}`,10),this[M]=t,r&&(this.modifiers=r),this[T]=parseInt(a,10),this[N]=o?parseInt(`${o}`,10):t}get average(){return(this.min+this.max)/2}get modifiers(){return this[A]?new Map([...this[A]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[A]=e}get max(){return this[N]}get min(){return this[T]}get name(){return"standard"}get notation(){let t=`${this.qty}d${this.sides}`;return this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}get qty(){return this[C]}get sides(){return this[M]}roll(){const t=new RollResults;for(let e=0;e<this.qty;e++)t.addRoll(this.rollOnce());return(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}rollOnce(){return new RollResult(f.integer(this.min,this.max))}toJSON(){const{average:t,max:e,min:r,modifiers:n,name:o,notation:i,qty:s,sides:a}=this;return Object.assign(super.toJSON(),{average:t,max:e,min:r,modifiers:n,name:o,notation:i,qty:s,sides:a,type:"die"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}class FudgeDice extends StandardDice{constructor(){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2;if(n||0===n){if(1!==n&&2!==n)throw new RangeError("nonBlanks must be 1 or 2")}else n=2;super(n,t,e,-1,1,r)}get name(){return"fudge"}get nonBlanks(){return super.sides}get sides(){return`F.${this.nonBlanks}`}rollOnce(){let t=0;if(2===this.nonBlanks)t=f.integer(1,3)-2;else if(1===this.nonBlanks){const e=f.integer(1,6);1===e?t=-1:6===e&&(t=1)}return new RollResult(t)}}class PercentileDice extends StandardDice{constructor(){let t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(100,arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,null,null,arguments.length>3&&void 0!==arguments[3]?arguments[3]:null),this.sidesAsNumber=!!t}get name(){return"percentile"}get sides(){return this.sidesAsNumber?super.sides:"%"}}var O=Object.freeze({__proto__:null,FudgeDice:FudgeDice,PercentileDice:PercentileDice,StandardDice:StandardDice});const $=Symbol("operator"),D=Symbol("value");class ComparePoint{constructor(t,e){if(!t)throw new RequiredArgumentError("operator");if(!e&&0!==e)throw new RequiredArgumentError("value");this.operator=t,this.value=e}static isValidOperator(t){return"string"==typeof t&&/^(?:[<>!]?=|[<>]|<>)$/.test(t)}set operator(t){if(!this.constructor.isValidOperator(t))throw new CompareOperatorError(t);this[$]=t}get operator(){return this[$]}set value(t){if(!i(t))throw new TypeError("value must be a finite number");this[D]=Number(t)}get value(){return this[D]}isMatch(t){return((t,e,r)=>{const n=Number(t),o=Number(e);let i;if(Number.isNaN(n)||Number.isNaN(o))return!1;switch(r){case"=":case"==":i=n===o;break;case"<":i=n<o;break;case">":i=n>o;break;case"<=":i=n<=o;break;case">=":i=n>=o;break;case"!":case"!=":case"<>":i=n!==o;break;default:i=!1}return i})(t,this.value,this.operator)}toJSON(){const{operator:t,value:e}=this;return{operator:t,type:"compare-point",value:e}}toString(){return`${this.operator}${this.value}`}}const P=Symbol("compare-point");class ComparisonModifier extends Modifier{constructor(t){super(),t&&(this.comparePoint=t)}get comparePoint(){return this[P]}set comparePoint(t){if(!(t instanceof ComparePoint))throw new TypeError("comparePoint must be instance of ComparePoint");this[P]=t}get name(){return"comparison"}get notation(){return`${this.comparePoint||""}`}defaultComparePoint(t){return{}}defaults(t){const e=this.defaultComparePoint(t);return"object"==typeof e&&2===e.length?{comparePoint:new ComparePoint(...e)}:{}}isComparePoint(t){return!!this.comparePoint&&this.comparePoint.isMatch(t)}toJSON(){const{comparePoint:t}=this;return Object.assign(super.toJSON(),{comparePoint:t})}}class CriticalFailureModifier extends ComparisonModifier{static order=10;constructor(t){super(t)}get name(){return"critical-failure"}get notation(){return`cf${super.notation}`}defaultComparePoint(t){return["=",t.min]}run(t,e){return super.run(t,e),t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-failure"),t))),t}}class CriticalSuccessModifier extends ComparisonModifier{static order=9;constructor(t){super(t)}get name(){return"critical-success"}get notation(){return`cs${super.notation}`}defaultComparePoint(t){return["=",t.max]}run(t,e){return super.run(t,e),t.rolls.forEach((t=>(this.isComparePoint(t.value)&&t.modifiers.add("critical-success"),t))),t}}const j=Symbol("calculation-value"),F=Symbol("is-roll-group"),I=Symbol("modifiers"),J=Symbol("results"),q=Symbol("use-in-total");class ResultGroup{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];this.isRollGroup=r,this.modifiers=e,this.results=t,this.useInTotal=n}get calculationValue(){return i(this[j])?parseFloat(this[j]):this.value}set calculationValue(t){const e=i(t);if(t===1/0)throw new RangeError("Results calculation value must be a finite number");if(t&&!e)throw new TypeError(`Results calculation value is invalid: ${t}`);this[j]=e?parseFloat(`${t}`):null}get isRollGroup(){return this[F]}set isRollGroup(t){this[F]=!!t}get length(){return this.results.length||0}get modifierFlags(){return v(...this.modifiers)}get modifiers(){return this[I]}set modifiers(t){if((Array.isArray(t)||t instanceof Set)&&[...t].every((t=>"string"==typeof t)))this[I]=new Set([...t]);else{if(t||0===t)throw new TypeError(`modifiers must be a Set or array of modifier names: ${t}`);this[I]=new Set}}get results(){return[...this[J]]}set results(t){if(!t||!Array.isArray(t))throw new TypeError(`results must be an array: ${t}`);this[J]=[],t.forEach((t=>{this.addResult(t)}))}get useInTotal(){return!!this[q]}set useInTotal(t){this[q]=!!t}get value(){if(!this.results.length)return 0;const t=this.results.reduce(((t,e)=>{let r=e;return e instanceof ResultGroup?r=e.useInTotal?e.calculationValue:0:e instanceof RollResults&&(r=e.value),t+r}),"string"==typeof this.results[0]?"":0);return"string"==typeof t?o(t):t}addResult(t){let e;if(t instanceof ResultGroup||t instanceof RollResults)e=t;else{if("string"!=typeof t&&!i(t))throw new TypeError("value must be one of ResultGroup, RollResults, string, or number");e=t}this[J].push(e)}toJSON(){const{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:n,results:o,useInTotal:i,value:s}=this;return{calculationValue:t,isRollGroup:e,modifierFlags:r,modifiers:[...n],results:o,type:"result-group",useInTotal:i,value:s}}toString(){let t;return t=this.isRollGroup?`{${this.results.join(", ")}}`:this.results.join(""),this.modifierFlags&&(t=`(${t})${this.modifierFlags}`),t}}const G=Symbol("end"),V=Symbol("qty");class KeepModifier extends Modifier{static order=6;constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"h",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;super(),this.end=t,this.qty=e}get end(){return this[G]}set end(t){if("h"!==t&&"l"!==t)throw new RangeError('End must be "h" or "l"');this[G]=t}get name(){return`keep-${this.end}`}get notation(){return`k${this.end}${this.qty}`}get qty(){return this[V]}set qty(t){if(t===1/0)throw new RangeError("qty must be a finite number");if(!i(t)||t<1)throw new TypeError("qty must be a positive finite integer");this[V]=Math.floor(t)}rangeToDrop(t){return"h"===this.end?[0,t.length-this.qty]:[this.qty,t.length]}run(t,e){let r,n;return t instanceof ResultGroup?(r=t.results,n=1===r.length&&r[0]instanceof ResultGroup?r[0].results.map(((t,e)=>t instanceof RollResults?t.rolls.map(((t,r)=>({value:t.value,index:[e,r]}))):null)).flat().filter(Boolean):[...r].map(((t,e)=>({value:t.value,index:e})))):(r=t.rolls,n=[...r].map(((t,e)=>({value:t.value,index:e})))),n=n.sort(((t,e)=>t.value-e.value)).map((t=>t.index)).slice(...this.rangeToDrop(n)),n.forEach((t=>{let e;e=Array.isArray(t)?r[0].results[t[0]].rolls[t[1]]:r[t],e.modifiers.add("drop"),e.useInTotal=!1})),t}toJSON(){const{end:t,qty:e}=this;return Object.assign(super.toJSON(),{end:t,qty:e})}}class DropModifier extends KeepModifier{static order=7;constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"l",arguments.length>1&&void 0!==arguments[1]?arguments[1]:1)}get name(){return`drop-${this.end}`}get notation(){return`d${this.end}${this.qty}`}rangeToDrop(t){return"h"===this.end?[t.length-this.qty,t.length]:[0,this.qty]}}const _=Symbol("compound"),k=Symbol("penetrate");class ExplodeModifier extends ComparisonModifier{static order=3;constructor(){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],e=arguments.length>2&&void 0!==arguments[2]&&arguments[2];super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:null),this[_]=!!t,this[k]=!!e}get compound(){return this[_]}get name(){return"explode"}get notation(){return`!${this.compound?"!":""}${this.penetrate?"p":""}${super.notation}`}get penetrate(){return this[k]}defaultComparePoint(t){return["=",t.max]}run(t,e){if(super.run(t,e),e.min===e.max)throw new DieActionValueError(e,"explode");const r=t;return r.rolls=t.rolls.map((t=>{const r=[t];let n=t.value;for(let t=0;t<this.maxIterations&&this.isComparePoint(n);t++){const t=r[r.length-1],o=e.rollOnce();n=o.value,t.modifiers.add("explode"),this.penetrate&&(t.modifiers.add("penetrate"),o.value-=1),r.push(o)}return this.compound&&r.length>1?(t.value=(o=r.map((t=>t.value)),Array.isArray(o)?o.reduce(((t,e)=>t+(i(e)?parseFloat(`${e}`):0)),0):0),t.modifiers=["explode","compound"],this.penetrate&&t.modifiers.add("penetrate"),t):r;var o})).flat(),r}toJSON(){const{compound:t,penetrate:e}=this;return Object.assign(super.toJSON(),{compound:t,penetrate:e})}}const B=Symbol("max");class MaxModifier extends Modifier{static order=2;constructor(t){super(),this.max=t}get max(){return this[B]}set max(t){if(!i(t))throw new TypeError("max must be a number");this[B]=parseFloat(`${t}`)}get name(){return"max"}get notation(){return`max${this.max}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value>this.max&&(e.value=this.max,e.modifiers.add("max")),e})),r}toJSON(){const{max:t}=this;return Object.assign(super.toJSON(),{max:t})}}const L=Symbol("min");class MinModifier extends Modifier{static order=1;constructor(t){super(),this.min=t}get min(){return this[L]}set min(t){if(!i(t))throw new TypeError("min must be a number");this[L]=parseFloat(`${t}`)}get name(){return"min"}get notation(){return`min${this.min}`}run(t,e){const r=t;return r.rolls=t.rolls.map((t=>{const e=t;return t.value<this.min&&(e.value=this.min,e.modifiers.add("min")),e})),r}toJSON(){const{min:t}=this;return Object.assign(super.toJSON(),{min:t})}}const z=Symbol("once");class ReRollModifier extends ComparisonModifier{static order=4;constructor(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];super(arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),this.once=!!t}get name(){return"re-roll"}get notation(){return`r${this.once?"o":""}${super.notation}`}get once(){return!!this[z]}set once(t){this[z]=!!t}defaultComparePoint(t){return["=",t.min]}run(t,e){if(super.run(t,e),e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.map((t=>{for(let r=0;r<this.maxIterations&&this.isComparePoint(t.value);r++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("re-roll"+(this.once?"-once":"")),this.once)break}return t})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}const U=Symbol("direction");class SortingModifier extends Modifier{static order=11;constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"a";super(),this.direction=t}get direction(){return this[U]}set direction(t){if("a"!==t&&"d"!==t)throw new RangeError('Direction must be "a" (Ascending) or "d" (Descending)');this[U]=t}get name(){return"sorting"}get notation(){return`s${this.direction}`}run(t,e){let r;return r=t instanceof ResultGroup?"results":"rolls",t[r]=t[r].sort(((t,e)=>"d"===this.direction?e.value-t.value:t.value-e.value)),t instanceof ResultGroup&&(t[r]=t[r].map((t=>t instanceof ResultGroup||t instanceof RollResults?this.run(t,e):t))),t}toJSON(){const{direction:t}=this;return Object.assign(super.toJSON(),{direction:t})}}const K=Symbol("failure-cp");class TargetModifier extends ComparisonModifier{static order=8;constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;super(t),this.failureComparePoint=e}get failureComparePoint(){return this[K]}set failureComparePoint(t){if(t&&!(t instanceof ComparePoint))throw new TypeError("failure comparePoint must be instance of ComparePoint or null");this[K]=t||null}get name(){return"target"}get notation(){return`${super.notation}${this.failureComparePoint?`f${this.failureComparePoint}`:""}`}get successComparePoint(){return this.comparePoint}set successComparePoint(t){super.comparePoint=t}getStateValue(t){return this.isSuccess(t)?1:this.isFailure(t)?-1:0}isFailure(t){return!!this.failureComparePoint&&this.failureComparePoint.isMatch(t)}isNeutral(t){return!this.isSuccess(t)&&!this.isFailure(t)}isSuccess(t){return this.isComparePoint(t)}run(t,e){let r;return r=t instanceof ResultGroup?t.results:t.rolls,r.forEach((t=>{this.isSuccess(t.value)?t.modifiers.add("target-success"):this.isFailure(t.value)&&t.modifiers.add("target-failure"),t.calculationValue=this.getStateValue(t.value)})),t}toJSON(){const{failureComparePoint:t,successComparePoint:e}=this,r=super.toJSON();return delete r.comparePoint,Object.assign(r,{failureComparePoint:t,successComparePoint:e})}}const H=Symbol("once"),X=function(t,e,r){let n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];const o=r.map((t=>t.value)).indexOf(t.value);return n?o<e:o!==e};class UniqueModifier extends ComparisonModifier{static order=5;constructor(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];super(arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),this.once=!!t}get name(){return"unique"}get notation(){return`u${this.once?"o":""}${super.notation}`}get once(){return!!this[H]}set once(t){this[H]=!!t}run(t,e){if(e.min===e.max)throw new DieActionValueError(e,"re-roll");return t.rolls.forEach(((t,r,n)=>{if(0!==r)for(let o=0;o<this.maxIterations&&(!this.comparePoint||this.isComparePoint(t.value))&&X(t,r,n,!0);o++){const r=e.rollOnce();if(t.value=r.value,t.modifiers.add("unique"+(this.once?"-once":"")),this.once)break}})),t}toJSON(){const{once:t}=this;return Object.assign(super.toJSON(),{once:t})}}var Q=Object.freeze({__proto__:null,ComparisonModifier:ComparisonModifier,CriticalFailureModifier:CriticalFailureModifier,CriticalSuccessModifier:CriticalSuccessModifier,DropModifier:DropModifier,ExplodeModifier:ExplodeModifier,KeepModifier:KeepModifier,MaxModifier:MaxModifier,MinModifier:MinModifier,Modifier:Modifier,ReRollModifier:ReRollModifier,SortingModifier:SortingModifier,TargetModifier:TargetModifier,UniqueModifier:UniqueModifier}),W=Object.freeze({__proto__:null,ResultGroup:ResultGroup,RollResult:RollResult,RollResults:RollResults});const Y=t=>{try{return!(!t||btoa(atob(t))!==t)}catch(t){return!1}},Z=t=>{try{const e=!!t&&JSON.parse(t);return!(!e||"object"!=typeof e)}catch(t){return!1}},tt=Symbol("expressions"),et=Symbol("modifiers");class RollGroup extends HasDescription{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];super(arguments.length>2&&void 0!==arguments[2]?arguments[2]:null),this.expressions=t,this.modifiers=e}get expressions(){return[...this[tt]||[]]}set expressions(t){if(!t)throw new RequiredArgumentError("expressions");if(!Array.isArray(t))throw new TypeError(`expressions must be an array: ${t}`);this[tt]=[],t.forEach((e=>{if(!e||!Array.isArray(e))throw new TypeError(`Expressions must be an array of arrays: ${t}`);if(0===e.length)throw new TypeError(`Sub expressions cannot be empty: ${t}`);if(!e.every((t=>t instanceof StandardDice||"string"==typeof t||"number"==typeof t)))throw new TypeError("Sub expression items must be Dice, numbers, or strings");this[tt].push(e)}))}get modifiers(){return this[et]?new Map([...this[et]].sort(((t,e)=>t[1].order-e[1].order))):null}set modifiers(t){let e;if(t instanceof Map)e=t;else if(Array.isArray(t))e=new Map(t.map((t=>[t.name,t])));else{if("object"!=typeof t)throw new TypeError("modifiers should be a Map, array, or an Object containing Modifiers");e=new Map(Object.entries(t))}if(e.size&&[...e.entries()].some((t=>!(t[1]instanceof Modifier))))throw new TypeError("modifiers must only contain Modifier instances");this[et]=e}get notation(){let t=this.expressions.map((t=>t.reduce(((t,e)=>t+e),""))).join(", ");return t=`{${t}}`,this.modifiers&&this.modifiers.size&&(t+=[...this.modifiers.values()].reduce(((t,e)=>t+e.notation),"")),t}roll(){const t=new ResultGroup(this.expressions.map((t=>{const e=t.map((t=>t instanceof StandardDice?t.roll():t));return new ResultGroup(e)})));return t.isRollGroup=!0,(this.modifiers||[]).forEach((e=>{e.run(t,this)})),t}toJSON(){const{modifiers:t,notation:e,expressions:r}=this;return Object.assign(super.toJSON(),{expressions:r,modifiers:t,notation:e,type:"group"})}toString(){return`${this.notation}${this.description?` ${this.description}`:""}`}}function rt(t,e,r,n){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,rt.prototype),o.expected=e,o.found=r,o.location=n,o.name="SyntaxError",o}function nt(t,e,r){return r=r||" ",t.length>e?t:(e-=t.length,t+(r+=r.repeat(e)).slice(0,e))}function ot(t,e){var r,n,i,s,a={},u=(e=void 0!==e?e:{}).grammarSource,l={Main:Er},c=Er,h="{",f=",",p="}",d="d",m="d%",g="dF",y=".",v="!",b="p",w="k",E="max",S="min",R="r",x="o",A="u",C="cs",M="cf",T="s",N="a",O="f",$="!=",D="<=",P=">=",j="=",F="<>",I=">",J="<",q="(",G=")",V="abs",_="ceil",k="cos",B="exp",L="floor",z="log",U="round",K="sign",H="sin",X="sqrt",Q="tan",W="pow",Y="-",Z="**",tt="*",et="^",nt="%",ot="/",it="+",st="/*",at="*/",ut="[",lt="]",ct="//",ht="#",ft=/^[12]/,pt=/^[lh]/,dt=/^[.]/,mt=/^[1-9]/,gt=/^[0-9]/,yt=/^[^\]]/,vt=/^[\n\r\u2028\u2029]/,bt=/^[ \t\n\r]/,wt=mr("{",!1),Et=mr(",",!1),St=mr("}",!1),Rt=mr("d",!1),xt=mr("d%",!1),At=mr("dF",!1),Ct=mr(".",!1),Mt=gr(["1","2"],!1,!1),Tt=mr("!",!1),Nt=mr("p",!1),Ot=gr(["l","h"],!1,!1),$t=mr("k",!1),Dt=mr("max",!1),Pt=mr("min",!1),jt=mr("r",!1),Ft=mr("o",!1),It=mr("u",!1),Jt=mr("cs",!1),qt=mr("cf",!1),Gt=mr("s",!1),Vt=mr("a",!1),_t=mr("f",!1),kt=mr("!=",!1),Bt=mr("<=",!1),Lt=mr(">=",!1),zt=mr("=",!1),Ut=mr("<>",!1),Kt=mr(">",!1),Ht=mr("<",!1),Xt=mr("(",!1),Qt=mr(")",!1),Wt=mr("abs",!1),Yt=mr("ceil",!1),Zt=mr("cos",!1),te=mr("exp",!1),ee=mr("floor",!1),re=mr("log",!1),ne=mr("round",!1),oe=mr("sign",!1),ie=mr("sin",!1),se=mr("sqrt",!1),ae=mr("tan",!1),ue=mr("pow",!1),le=mr("-",!1),ce=gr(["."],!1,!1),he=gr([["1","9"]],!1,!1),fe=gr([["0","9"]],!1,!1),pe=mr("**",!1),de=mr("*",!1),me=mr("^",!1),ge=mr("%",!1),ye=mr("/",!1),ve=mr("+",!1),be=yr("comment"),we=mr("/*",!1),Ee=mr("*/",!1),Se={type:"any"},Re=mr("[",!1),xe=gr(["]"],!0,!1),Ae=mr("]",!1),Ce=mr("//",!1),Me=mr("#",!1),Te=gr(["\n","\r","\u2028","\u2029"],!1,!1),Ne=yr("whitespace"),Oe=gr([" ","\t","\n","\r"],!1,!1),$e=yr("whitespace or comment"),De=function(t,e,r,n){return new RollGroup([t,...e.map((t=>t[3]))],Object.assign({},...r.map((t=>({[t.name]:t})))),n.find((t=>t instanceof Description)))},Pe=function(t,e,r){return t.modifiers=Object.assign({},...e.map((t=>({[t.name]:t})))),t.description=r.find((t=>t instanceof Description)),t},je=function(t,e){return new StandardDice(e,t||1)},Fe=function(t){return new PercentileDice(t||1)},Ie=function(t,e){return new FudgeDice(e?parseInt(e[1],10):2,t||1)},Je=function(t,e,r){return new ExplodeModifier(r,!!t,!!e)},qe=function(t,e){return new TargetModifier(t,e)},Ge=function(t,e){return new DropModifier(t||"l",e)},Ve=function(t,e){return new KeepModifier(t||"h",e)},_e=function(t){return new MaxModifier(t)},ke=function(t){return new MinModifier(t)},Be=function(t,e){return new ReRollModifier(!!t,e)},Le=function(t,e){return new UniqueModifier(!!t,e)},ze=function(t){return new CriticalSuccessModifier(t)},Ue=function(t){return new CriticalFailureModifier(t)},Ke=function(t){return new SortingModifier(t||"a")},He=function(t){return t},Xe=function(t,e){return new ComparePoint(t,e)},Qe=function(t,e,r){return o(dr())},We=function(t,e){return t=Array.isArray(t)?t:[t],[...t,...e.map((t=>{let[,e,,r]=t;return[e,r]})).flat(2)]},Ye=function(t,e,r){return[t,...e,r]},Ze=function(t,e){return[`${t}(`,...e,")"]},tr=function(t,e,r){return[`${t}(`,...e,",",...r,")"]},er=function(){return parseFloat(dr())},rr=function(){return parseInt(dr(),10)},nr=function(){return parseInt(dr(),10)},or=function(){return"^"},ir=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},sr=function(t){return new Description(t.flat().join(""),Description.types.MULTILINE)},ar=function(t){return new Description(t.flat().join(""),Description.types.INLINE)},ur=0,lr=0,cr=[{line:1,column:1}],hr=0,fr=[],pr=0;if("startRule"in e){if(!(e.startRule in l))throw new Error("Can't start parsing from rule \""+e.startRule+'".');c=l[e.startRule]}function dr(){return t.substring(lr,ur)}function mr(t,e){return{type:"literal",text:t,ignoreCase:e}}function gr(t,e,r){return{type:"class",parts:t,inverted:e,ignoreCase:r}}function yr(t){return{type:"other",description:t}}function vr(e){var r,n=cr[e];if(n)return n;for(r=e-1;!cr[r];)r--;for(n={line:(n=cr[r]).line,column:n.column};r<e;)10===t.charCodeAt(r)?(n.line++,n.column=1):n.column++,r++;return cr[e]=n,n}function br(t,e,r){var n=vr(t),o=vr(e),i={source:u,start:{offset:t,line:n.line,column:n.column},end:{offset:e,line:o.line,column:o.column}};return r&&u&&"function"==typeof u.offset&&(i.start=u.offset(i.start),i.end=u.offset(i.end)),i}function wr(t){ur<hr||(ur>hr&&(hr=ur,fr=[]),fr.push(t))}function Er(){return Cr()}function Sr(){var e,r,n,o;if(e=ur,r=function(){var e,r,n,o;e=ur,r=Ar(),r===a&&(r=null);100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&wr(Rt));n!==a&&(o=Ar())!==a?(lr=e,e=je(r,o)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n;e=ur,r=Ar(),r===a&&(r=null);t.substr(ur,2)===m?(n=m,ur+=2):(n=a,0===pr&&wr(xt));n!==a?(lr=e,e=Fe(r)):(ur=e,e=a);return e}(),r===a&&(r=function(){var e,r,n,o,i,s;e=ur,r=Ar(),r===a&&(r=null);t.substr(ur,2)===g?(n=g,ur+=2):(n=a,0===pr&&wr(At));n!==a?(o=ur,46===t.charCodeAt(ur)?(i=y,ur++):(i=a,0===pr&&wr(Ct)),i!==a?(ft.test(t.charAt(ur))?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Mt)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a),o===a&&(o=null),lr=e,e=Ie(r,o)):(ur=e,e=a);return e}())),r!==a){for(n=[],o=Rr();o!==a;)n.push(o),o=Rr();o=Ir(),lr=e,e=Pe(r,n,o)}else ur=e,e=a;return e}function Rr(){var e;return(e=function(){var e,r,n,o,i;e=ur,33===t.charCodeAt(ur)?(r=v,ur++):(r=a,0===pr&&wr(Tt));r!==a?(33===t.charCodeAt(ur)?(n=v,ur++):(n=a,0===pr&&wr(Tt)),n===a&&(n=null),112===t.charCodeAt(ur)?(o=b,ur++):(o=a,0===pr&&wr(Nt)),o===a&&(o=null),(i=xr())===a&&(i=null),lr=e,e=Je(n,o,i)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,(r=xr())!==a?(n=function(){var e,r,n;e=ur,102===t.charCodeAt(ur)?(r=O,ur++):(r=a,0===pr&&wr(_t));r!==a&&(n=xr())!==a?(lr=e,e=He(n)):(ur=e,e=a);return e}(),n===a&&(n=null),lr=e,e=qe(r,n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,100===t.charCodeAt(ur)?(r=d,ur++):(r=a,0===pr&&wr(Rt));r!==a?(pt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(Ot)),n===a&&(n=null),(o=Nr())!==a?(lr=e,e=Ge(n,o)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,107===t.charCodeAt(ur)?(r=w,ur++):(r=a,0===pr&&wr($t));r!==a?(pt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(Ot)),n===a&&(n=null),(o=Nr())!==a?(lr=e,e=Ve(n,o)):(ur=e,e=a)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,114===t.charCodeAt(ur)?(r=R,ur++):(r=a,0===pr&&wr(jt));r!==a?(111===t.charCodeAt(ur)?(n=x,ur++):(n=a,0===pr&&wr(Ft)),n===a&&(n=null),(o=xr())===a&&(o=null),lr=e,e=Be(n,o)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n,o;e=ur,117===t.charCodeAt(ur)?(r=A,ur++):(r=a,0===pr&&wr(It));r!==a?(111===t.charCodeAt(ur)?(n=x,ur++):(n=a,0===pr&&wr(Ft)),n===a&&(n=null),(o=xr())===a&&(o=null),lr=e,e=Le(n,o)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===C?(r=C,ur+=2):(r=a,0===pr&&wr(Jt));r!==a?((n=xr())===a&&(n=null),lr=e,e=ze(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,2)===M?(r=M,ur+=2):(r=a,0===pr&&wr(qt));r!==a?((n=xr())===a&&(n=null),lr=e,e=Ue(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,115===t.charCodeAt(ur)?(r=T,ur++):(r=a,0===pr&&wr(Gt));r!==a?(97===t.charCodeAt(ur)?(n=N,ur++):(n=a,0===pr&&wr(Vt)),n===a&&(100===t.charCodeAt(ur)?(n=d,ur++):(n=a,0===pr&&wr(Rt))),n===a&&(n=null),lr=e,e=Ke(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&wr(Dt));r!==a&&(n=Tr())!==a?(lr=e,e=_e(n)):(ur=e,e=a);return e}())===a&&(e=function(){var e,r,n;e=ur,t.substr(ur,3)===S?(r=S,ur+=3):(r=a,0===pr&&wr(Pt));r!==a&&(n=Tr())!==a?(lr=e,e=ke(n)):(ur=e,e=a);return e}()),e}function xr(){var e,r,n;return e=ur,r=function(){var e;t.substr(ur,2)===$?(e=$,ur+=2):(e=a,0===pr&&wr(kt));e===a&&(t.substr(ur,2)===D?(e=D,ur+=2):(e=a,0===pr&&wr(Bt)),e===a&&(t.substr(ur,2)===P?(e=P,ur+=2):(e=a,0===pr&&wr(Lt)),e===a&&(61===t.charCodeAt(ur)?(e=j,ur++):(e=a,0===pr&&wr(zt)),e===a&&(t.substr(ur,2)===F?(e=F,ur+=2):(e=a,0===pr&&wr(Ut)),e===a&&(62===t.charCodeAt(ur)?(e=I,ur++):(e=a,0===pr&&wr(Kt)),e===a&&(60===t.charCodeAt(ur)?(e=J,ur++):(e=a,0===pr&&wr(Ht))))))));return e}(),r!==a&&(n=Tr())!==a?(lr=e,e=Xe(r,n)):(ur=e,e=a),e}function Ar(){var e,r,n,o,i,s,u,l,c,h;if((e=Nr())===a)if(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&wr(Xt)),r!==a){if(Fr(),n=ur,(o=Tr())!==a){if(i=[],s=ur,u=Fr(),(l=$r())!==a?(c=Fr(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a),s!==a)for(;s!==a;)i.push(s),s=ur,u=Fr(),(l=$r())!==a?(c=Fr(),(h=Tr())!==a?s=u=[u,l,c,h]:(ur=s,s=a)):(ur=s,s=a);else i=a;i!==a?n=o=[o,i]:(ur=n,n=a)}else ur=n,n=a;n!==a?(o=Fr(),41===t.charCodeAt(ur)?(i=G,ur++):(i=a,0===pr&&wr(Qt)),i!==a?(lr=e,e=Qe()):(ur=e,e=a)):(ur=e,e=a)}else ur=e,e=a;return e}function Cr(){var t,e,r,n,o,i,s,u;if(t=ur,(e=Mr())!==a){for(r=[],n=ur,o=Fr(),(i=$r())!==a?(s=Fr(),(u=Mr())!==a?n=o=[o,i,s,u]:(ur=n,n=a)):(ur=n,n=a);n!==a;)r.push(n),n=ur,o=Fr(),(i=$r())!==a?(s=Fr(),(u=Mr())!==a?n=o=[o,i,s,u]:(ur=n,n=a)):(ur=n,n=a);lr=t,t=We(e,r)}else ur=t,t=a;return t}function Mr(){var e,r,n,o;return e=function(){var e,r,n,o,i,s,u;e=ur,t.substr(ur,3)===V?(r=V,ur+=3):(r=a,0===pr&&wr(Wt));r===a&&(t.substr(ur,4)===_?(r=_,ur+=4):(r=a,0===pr&&wr(Yt)),r===a&&(t.substr(ur,3)===k?(r=k,ur+=3):(r=a,0===pr&&wr(Zt)),r===a&&(t.substr(ur,3)===B?(r=B,ur+=3):(r=a,0===pr&&wr(te)),r===a&&(t.substr(ur,5)===L?(r=L,ur+=5):(r=a,0===pr&&wr(ee)),r===a&&(t.substr(ur,3)===z?(r=z,ur+=3):(r=a,0===pr&&wr(re)),r===a&&(t.substr(ur,5)===U?(r=U,ur+=5):(r=a,0===pr&&wr(ne)),r===a&&(t.substr(ur,4)===K?(r=K,ur+=4):(r=a,0===pr&&wr(oe)),r===a&&(t.substr(ur,3)===H?(r=H,ur+=3):(r=a,0===pr&&wr(ie)),r===a&&(t.substr(ur,4)===X?(r=X,ur+=4):(r=a,0===pr&&wr(se)),r===a&&(t.substr(ur,3)===Q?(r=Q,ur+=3):(r=a,0===pr&&wr(ae))))))))))));r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&wr(Xt)),n!==a?(Fr(),(o=Cr())!==a?(Fr(),41===t.charCodeAt(ur)?(i=G,ur++):(i=a,0===pr&&wr(Qt)),i!==a?(lr=e,e=Ze(r,o)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a);e===a&&(e=ur,t.substr(ur,3)===W?(r=W,ur+=3):(r=a,0===pr&&wr(ue)),r===a&&(t.substr(ur,3)===E?(r=E,ur+=3):(r=a,0===pr&&wr(Dt)),r===a&&(t.substr(ur,3)===S?(r=S,ur+=3):(r=a,0===pr&&wr(Pt)))),r!==a?(40===t.charCodeAt(ur)?(n=q,ur++):(n=a,0===pr&&wr(Xt)),n!==a?(Fr(),(o=Cr())!==a?(Fr(),44===t.charCodeAt(ur)?(i=f,ur++):(i=a,0===pr&&wr(Et)),i!==a?(Fr(),(s=Cr())!==a?(Fr(),41===t.charCodeAt(ur)?(u=G,ur++):(u=a,0===pr&&wr(Qt)),u!==a?(lr=e,e=tr(r,o,s)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a));return e}(),e===a&&(e=Sr())===a&&(e=Tr())===a&&(e=ur,40===t.charCodeAt(ur)?(r=q,ur++):(r=a,0===pr&&wr(Xt)),r!==a?(Fr(),(n=Cr())!==a?(Fr(),41===t.charCodeAt(ur)?(o=G,ur++):(o=a,0===pr&&wr(Qt)),o!==a?(lr=e,e=Ye(r,n,o)):(ur=e,e=a)):(ur=e,e=a)):(ur=e,e=a),e===a&&(e=function(){var e,r,n,o,i,s,u,l,c;if(e=ur,123===t.charCodeAt(ur)?(r=h,ur++):(r=a,0===pr&&wr(wt)),r!==a)if(Fr(),(n=Cr())!==a){for(o=[],i=ur,s=Fr(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&wr(Et)),u!==a?(l=Fr(),(c=Cr())!==a?i=s=[s,u,l,c]:(ur=i,i=a)):(ur=i,i=a);i!==a;)o.push(i),i=ur,s=Fr(),44===t.charCodeAt(ur)?(u=f,ur++):(u=a,0===pr&&wr(Et)),u!==a?(l=Fr(),(c=Cr())!==a?i=s=[s,u,l,c]:(ur=i,i=a)):(ur=i,i=a);if(i=Fr(),125===t.charCodeAt(ur)?(s=p,ur++):(s=a,0===pr&&wr(St)),s!==a){for(u=[],l=Rr();l!==a;)u.push(l),l=Rr();l=Ir(),lr=e,e=De(n,o,u,l)}else ur=e,e=a}else ur=e,e=a;else ur=e,e=a;return e}())),e}function Tr(){var e,r,n,o;return e=ur,45===t.charCodeAt(ur)?ur++:0===pr&&wr(le),Or()!==a?(r=ur,dt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(ce)),n!==a&&(o=Or())!==a?r=n=[n,o]:(ur=r,r=a),r===a&&(r=null),lr=e,e=er()):(ur=e,e=a),e}function Nr(){var e,r,n,o;if(e=ur,mt.test(t.charAt(ur))?(r=t.charAt(ur),ur++):(r=a,0===pr&&wr(he)),r!==a){for(n=[],gt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(fe));o!==a;)n.push(o),gt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(fe));lr=e,e=rr()}else ur=e,e=a;return e}function Or(){var e,r,n;if(e=ur,r=[],gt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(fe)),n!==a)for(;n!==a;)r.push(n),gt.test(t.charAt(ur))?(n=t.charAt(ur),ur++):(n=a,0===pr&&wr(fe));else r=a;return r!==a&&(lr=e,r=nr()),e=r}function $r(){var e,r;return e=ur,t.substr(ur,2)===Z?(r=Z,ur+=2):(r=a,0===pr&&wr(pe)),r!==a&&(lr=e,r=or()),(e=r)===a&&(42===t.charCodeAt(ur)?(e=tt,ur++):(e=a,0===pr&&wr(de)),e===a&&(94===t.charCodeAt(ur)?(e=et,ur++):(e=a,0===pr&&wr(me)),e===a&&(37===t.charCodeAt(ur)?(e=nt,ur++):(e=a,0===pr&&wr(ge)),e===a&&(47===t.charCodeAt(ur)?(e=ot,ur++):(e=a,0===pr&&wr(ye)),e===a&&(43===t.charCodeAt(ur)?(e=it,ur++):(e=a,0===pr&&wr(ve)),e===a&&(45===t.charCodeAt(ur)?(e=Y,ur++):(e=a,0===pr&&wr(le)))))))),e}function Dr(){var e;return pr++,(e=function(){var e,r,n,o,i,s;e=ur,t.substr(ur,2)===st?(r=st,ur+=2):(r=a,0===pr&&wr(we));if(r!==a){for(n=[],o=ur,i=ur,pr++,t.substr(ur,2)===at?(s=at,ur+=2):(s=a,0===pr&&wr(Ee)),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);o!==a;)n.push(o),o=ur,i=ur,pr++,t.substr(ur,2)===at?(s=at,ur+=2):(s=a,0===pr&&wr(Ee)),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);t.substr(ur,2)===at?(o=at,ur+=2):(o=a,0===pr&&wr(Ee)),o!==a?(lr=e,e=ir(n)):(ur=e,e=a)}else ur=e,e=a;if(e===a)if(e=ur,91===t.charCodeAt(ur)?(r=ut,ur++):(r=a,0===pr&&wr(Re)),r!==a){for(n=[],yt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(xe));o!==a;)n.push(o),yt.test(t.charAt(ur))?(o=t.charAt(ur),ur++):(o=a,0===pr&&wr(xe));93===t.charCodeAt(ur)?(o=lt,ur++):(o=a,0===pr&&wr(Ae)),o!==a?(lr=e,e=sr(n)):(ur=e,e=a)}else ur=e,e=a;return e}())===a&&(e=function(){var e,r,n,o,i,s;e=ur,t.substr(ur,2)===ct?(r=ct,ur+=2):(r=a,0===pr&&wr(Ce));r===a&&(35===t.charCodeAt(ur)?(r=ht,ur++):(r=a,0===pr&&wr(Me)));if(r!==a){for(n=[],o=ur,i=ur,pr++,s=Pr(),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);o!==a;)n.push(o),o=ur,i=ur,pr++,s=Pr(),pr--,s===a?i=void 0:(ur=i,i=a),i!==a?(t.length>ur?(s=t.charAt(ur),ur++):(s=a,0===pr&&wr(Se)),s!==a?o=i=[i,s]:(ur=o,o=a)):(ur=o,o=a);lr=e,e=ar(n)}else ur=e,e=a;return e}()),pr--,e===a&&0===pr&&wr(be),e}function Pr(){var e;return vt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&wr(Te)),e}function jr(){var e;return pr++,bt.test(t.charAt(ur))?(e=t.charAt(ur),ur++):(e=a,0===pr&&wr(Oe)),pr--,e===a&&0===pr&&wr(Ne),e}function Fr(){var t,e;for(t=[],e=jr();e!==a;)t.push(e),e=jr();return t}function Ir(){var t,e;for(pr++,t=[],(e=jr())===a&&(e=Dr());e!==a;)t.push(e),(e=jr())===a&&(e=Dr());return pr--,e=a,0===pr&&wr($e),t}if((r=c())!==a&&ur===t.length)return r;throw r!==a&&ur<t.length&&wr({type:"end"}),n=fr,i=hr<t.length?t.charAt(hr):null,s=hr<t.length?br(hr,hr+1):br(hr,hr),new rt(rt.buildMessage(n,i),n,i,s)}!function(t,e){function r(){this.constructor=t}r.prototype=e.prototype,t.prototype=new r}(rt,Error),rt.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var r,n=null;for(r=0;r<t.length;r++)if(t[r].source===this.location.source){n=t[r].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,i=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(o):o,s=this.location.source+":"+i.line+":"+i.column;if(n){var a=this.location.end,u=nt("",i.line.toString().length," "),l=n[o.line-1],c=(o.line===a.line?a.column:l.length+1)-o.column||1;e+="\n --\x3e "+s+"\n"+u+" |\n"+i.line+" | "+l+"\n"+u+" | "+nt("",o.column-1," ")+nt("",c,"^")}else e+="\n at "+s}return e},rt.buildMessage=function(t,e){var r={literal:function(t){return'"'+o(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?i(t[0])+"-"+i(t[1]):i(t)}));return"["+(t.inverted?"^":"")+e.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function o(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function i(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function s(t){return r[t.type](t)}return"Expected "+function(t){var e,r,n=t.map(s);if(n.sort(),n.length>0){for(e=1,r=1;e<n.length;e++)n[e-1]!==n[e]&&(n[r]=n[e],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(t)+" but "+function(t){return t?'"'+o(t)+'"':"end of input"}(e)+" found."};class Parser{static parse(t){if(!t)throw new RequiredArgumentError("notation");if("string"!=typeof t)throw new TypeError("Notation must be a string");return ot(t)}}const it=Object.freeze({BASE_64:1,JSON:0,OBJECT:2}),st=Symbol("notation"),at=Symbol("maxTotal"),ut=Symbol("minTotal"),lt=Symbol("expressions"),ct=Symbol("roll-method"),ht=Symbol("rolls"),ft=Symbol("set-rolls"),pt=Symbol("total"),dt=t=>function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return parseFloat(parseFloat(`${t}`).toFixed(e||0))}(t.calculationValue,2);class DiceRoll{constructor(t){if(!t)throw new RequiredArgumentError("notation");if(this[lt]=[],t instanceof Object&&!Array.isArray(t)){if(!t.notation)throw new RequiredArgumentError("notation");if("string"!=typeof t.notation)throw new NotationError(t.notation);t.rolls&&this[ft](t.rolls),this[st]=t.notation,this[lt]=Parser.parse(this.notation),this.hasRolls()||this.roll()}else{if("string"!=typeof t)throw new NotationError(t);this[st]=t,this[lt]=Parser.parse(this.notation),this.roll()}}get averageTotal(){return(this.maxTotal+this.minTotal)/2}get maxTotal(){if(!this.hasExpressions())return 0;if(!this[at]){const t=this[ct](h.max);this[at]=dt(t)}return this[at]}get minTotal(){if(!this.hasExpressions())return 0;if(!this[ut]){const t=this[ct](h.min);this[ut]=dt(t)}return this[ut]}get notation(){return this[st]}get output(){let t=`${this.notation}: `;return this.hasRolls()?t+=`${this[ht]} = ${this.total}`:t+="No dice rolled",t}get rolls(){return this[ht]?this[ht].results:[]}get total(){return!this[pt]&&this.hasRolls()&&(this[pt]=dt(this[ht])),this[pt]||0}export(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:it.JSON;switch(t){case it.BASE_64:return btoa(this.export(it.JSON));case it.JSON:return JSON.stringify(this);case it.OBJECT:return JSON.parse(this.export(it.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}hasExpressions(){return this[lt]&&this[lt].length>0}hasRolls(){return this.hasExpressions()&&this.rolls.length>0}roll(){return this[pt]=0,this[ht]=this[ct](),this.rolls}toJSON(){const{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:o,rolls:i,total:s}=this;return{averageTotal:t,maxTotal:e,minTotal:r,notation:n,output:o,rolls:i,total:s,type:"dice-roll"}}toString(){return this.output}static import(t){if(t){if(Z(t))return DiceRoll.import(JSON.parse(t));if(Y(t))return DiceRoll.import(atob(t));if("object"==typeof t)return new DiceRoll(t);throw new DataFormatError(t)}throw new RequiredArgumentError("data")}[ct](t){let e;t&&(e=f.engine,f.engine=t);const r=new ResultGroup(this[lt].map((t=>t instanceof StandardDice||t instanceof RollGroup?t.roll():t)).filter((t=>!!t||0===t)));return t&&(f.engine=e),r}[ft](t){if(t instanceof ResultGroup)this[ht]=t;else if(t instanceof RollResults)this[ht]=new ResultGroup([t]);else{if(!Array.isArray(t))throw new TypeError("Rolls must be a valid result object, or an array");this[ht]=new ResultGroup(t.map((t=>{if(t instanceof ResultGroup||t instanceof RollResults)return t;if(Array.isArray(t))return new RollResults(t);if("object"==typeof t){if(Array.isArray(t.results))return new ResultGroup(t.results,t.modifiers||[],t.isRollGroup||!1,"boolean"!=typeof t.useInTotal||t.useInTotal);if(Array.isArray(t.rolls))return new RollResults(t.rolls)}return t})))}}}const mt=Symbol("log");class DiceRoller{constructor(t){this[mt]=[],t&&this.import(t)}get log(){return this[mt]||[]}get output(){return this.log.join("; ")}get total(){return this.log.reduce(((t,e)=>t+e.total),0)}clearLog(){this[mt].length=0}export(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:it.JSON;switch(t){case it.BASE_64:return btoa(this.export(it.JSON));case it.JSON:return JSON.stringify(this);case it.OBJECT:return JSON.parse(this.export(it.JSON));default:throw new TypeError(`Invalid export format "${t}"`)}}import(t){if(t){if(Z(t))return this.import(JSON.parse(t));if(Y(t))return this.import(atob(t));if("object"==typeof t){let e=t.log||null;if(!t.log&&Array.isArray(t)&&t.length&&(e=t),e&&Array.isArray(e))e.forEach((t=>{this[mt].push(DiceRoll.import(t))}));else if(e)throw new TypeError("log must be an array");return this.log}throw new DataFormatError(t)}throw new RequiredArgumentError("data")}roll(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];const n=e.filter(Boolean);if(0===n.length)throw new RequiredArgumentError("notations");const o=n.map((t=>{const e=new DiceRoll(t);return this[mt].push(e),e}));return o.length>1?o:o[0]}toJSON(){const{log:t,output:e,total:r}=this;return{log:t,output:e,total:r,type:"dice-roller"}}toString(){return this.output}static import(t){const e=new DiceRoller;return e.import(t),e}}t.ComparePoint=ComparePoint,t.Dice=O,t.DiceRoll=DiceRoll,t.DiceRoller=DiceRoller,t.Exceptions=n,t.Modifiers=Q,t.NumberGenerator=p,t.Parser=Parser,t.Results=W,t.RollGroup=RollGroup,t.exportFormats=it,Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -5,3 +5,3 @@ { | ||
"author": "GreenImp Media <info@greenimp.co.uk> (https://greenimp.co.uk)", | ||
"version": "5.4.1", | ||
"version": "5.5.0", | ||
"license": "MIT", | ||
@@ -65,3 +65,2 @@ "type": "module", | ||
"abab": "^2.0.6", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.24.0", | ||
@@ -71,3 +70,3 @@ "eslint-config-airbnb-base": "^15.0.0", | ||
"jest": "^29.1.2", | ||
"peggy": "^2.0.1", | ||
"peggy": "^3.0.2", | ||
"rollup": "^2.79.1", | ||
@@ -77,3 +76,3 @@ "rollup-plugin-banner": "^0.2.1", | ||
"typescript": "^4.8.4", | ||
"vuepress-jsdoc": "^4.3.0" | ||
"vuepress-jsdoc": "^5.0.0" | ||
}, | ||
@@ -89,7 +88,8 @@ "dependencies": { | ||
"build": "npm run build:dev && npm run build:prod && npm run build:declaration", | ||
"build:prepare": "npm run build:grammars && npm run lint", | ||
"build:declaration": "rm -rf types/ && tsc -p declaration.tsconfig.json && cp ./types/index.d.ts ./types/index.d.cts", | ||
"build:dev": "npm run build:grammars && npm run lint && rollup --c --environment BUILD:dev", | ||
"build:dev": "npm run build:prepare && rollup --c --environment BUILD:dev", | ||
"build:grammars": "peggy -c ./peggy.config.cjs ./src/parser/grammars/grammar.pegjs", | ||
"build:prod": "npm run build:grammars && npm run lint && rollup --c --environment BUILD:prod", | ||
"docs:build": "vuepress-jsdoc --dist ./docs --folder api --exclude=\"index.js,**/index.js,**/parser/grammars/*\" --partials=\"./docs/partials/**/*.hbs\"", | ||
"build:prod": "npm run build:prepare && rollup --c --environment BUILD:prod", | ||
"docs:build": "vuepress-jsdoc --dist ./docs --folder api --exclude=\"index.js,**/index.js,**/parser/grammars/*\" --partials=\"./docs/partials/**/*.hbs\" --readme=\"./docs/readme.md\"", | ||
"docs:watch": "npm run docs:build -- --watch", | ||
@@ -99,8 +99,8 @@ "watch": "npm run build:dev -- -w", | ||
"lint:fix": "eslint --fix src/** tests/**", | ||
"pretest": "npm run build:grammars && npm run lint", | ||
"pretest": "npm run build:prepare", | ||
"test": "jest", | ||
"test:coverage": "npm run pretest && jest --coverage", | ||
"test:watch": "npm run pretest && jest --watchAll", | ||
"test:coverage": "npm test -- --coverage", | ||
"test:watch": "npm test -- --watchAll", | ||
"prepublishOnly": "npm test && npm run build" | ||
} | ||
} |
@@ -39,2 +39,10 @@ export default ComparisonModifier; | ||
/** | ||
* Empty default compare point definition | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {null} | ||
*/ | ||
defaultComparePoint(_context: StandardDice | RollGroup): null; | ||
/** | ||
* Check whether value matches the compare point or not. | ||
@@ -41,0 +49,0 @@ * |
@@ -20,3 +20,11 @@ export default CriticalFailureModifier; | ||
constructor(comparePoint?: any); | ||
/** | ||
* The default compare point definition | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {array} | ||
*/ | ||
defaultComparePoint(_context: StandardDice | RollGroup): array; | ||
} | ||
import ComparisonModifier from "./ComparisonModifier.js"; |
@@ -20,3 +20,11 @@ export default CriticalSuccessModifier; | ||
constructor(comparePoint: ComparePoint); | ||
/** | ||
* The default compare point definition | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {array} | ||
*/ | ||
defaultComparePoint(_context: StandardDice | RollGroup): array; | ||
} | ||
import ComparisonModifier from "./ComparisonModifier.js"; |
@@ -33,2 +33,10 @@ export default ExplodeModifier; | ||
/** | ||
* The default compare point definition | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {array} | ||
*/ | ||
defaultComparePoint(_context: StandardDice | RollGroup): array; | ||
/** | ||
* Return an object for JSON serialising. | ||
@@ -35,0 +43,0 @@ * |
@@ -34,2 +34,18 @@ export default Modifier; | ||
/** | ||
* No default values present | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {object} | ||
*/ | ||
defaults(_context: StandardDice | RollGroup): object; | ||
/** | ||
* Processing default values definitions | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {void} | ||
*/ | ||
useDefaultsIfNeeded(_context: StandardDice | RollGroup): void; | ||
/** | ||
* Run the modifier on the results. | ||
@@ -36,0 +52,0 @@ * |
@@ -31,2 +31,10 @@ export default ReRollModifier; | ||
/** | ||
* The default compare point definition | ||
* | ||
* @param {StandardDice|RollGroup} _context The object that the modifier is attached to | ||
* | ||
* @returns {array} | ||
*/ | ||
defaultComparePoint(_context: StandardDice | RollGroup): array; | ||
/** | ||
* Return an object for JSON serialising. | ||
@@ -33,0 +41,0 @@ * |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
588619
17
17049