{"version":3,"file":"stops.mjs","names":[],"sources":["../../src/expression/stops.ts"],"sourcesContent":["import {RuntimeError} from './runtime_error';\n\nimport type {Expression} from './expression';\n\nexport type Stops = Array<[number, Expression]>;\n\n/**\n * Returns the index of the last stop <= input, or 0 if it doesn't exist.\n * @private\n */\nexport function findStopLessThanOrEqualTo(stops: Array, input: number, key: string) {\n const lastIndex = stops.length - 1;\n let lowerIndex = 0;\n let upperIndex = lastIndex;\n let currentIndex = 0;\n let currentValue, nextValue;\n\n while (lowerIndex <= upperIndex) {\n currentIndex = Math.floor((lowerIndex + upperIndex) / 2);\n currentValue = stops[currentIndex];\n nextValue = stops[currentIndex + 1];\n\n if (currentValue <= input) {\n if (currentIndex === lastIndex || input < nextValue) {\n // Search complete\n return currentIndex;\n }\n\n lowerIndex = currentIndex + 1;\n } else if (currentValue > input) {\n upperIndex = currentIndex - 1;\n } else {\n throw new RuntimeError('Input is not a number.', key);\n }\n }\n\n return 0;\n}\n"],"mappings":";;;;;;AAUA,SAAgB,0BAA0B,OAAsB,OAAe,KAAa;CACxF,MAAM,YAAY,MAAM,SAAS;CACjC,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,IAAI,eAAe;CACnB,IAAI,cAAc;CAElB,OAAO,cAAc,YAAY;EAC7B,eAAe,KAAK,OAAO,aAAa,cAAc,CAAC;EACvD,eAAe,MAAM;EACrB,YAAY,MAAM,eAAe;EAEjC,IAAI,gBAAgB,OAAO;GACvB,IAAI,iBAAiB,aAAa,QAAQ,WAEtC,OAAO;GAGX,aAAa,eAAe;EAChC,OAAO,IAAI,eAAe,OACtB,aAAa,eAAe;OAE5B,MAAM,IAAI,aAAa,0BAA0B,GAAG;CAE5D;CAEA,OAAO;AACX"}