UNPKG

@maplibre/maplibre-gl-style-spec

Version:
1 lines 1.35 MB
{"version":3,"file":"gl-style-validate.mjs","sources":["../node_modules/minimist/index.js","../node_modules/rw/lib/rw/decode.js","../node_modules/rw/lib/rw/read-file.js","../node_modules/rw/lib/rw/read-file-sync.js","../node_modules/rw/lib/rw/encode.js","../node_modules/rw/lib/rw/write-file.js","../node_modules/rw/lib/rw/write-file-sync.js","../node_modules/rw/lib/rw/dash.js","../node_modules/rw/index.js","../src/error/validation_error.ts","../src/validate/validate_constants.ts","../src/util/extend.ts","../src/util/unbundle_jsonlint.ts","../src/expression/parsing_error.ts","../src/expression/scope.ts","../src/expression/types.ts","../src/expression/types/color_spaces.ts","../src/util/get_own.ts","../src/expression/types/parse_css_color.ts","../src/util/interpolate-primitives.ts","../src/expression/types/color.ts","../src/expression/types/collator.ts","../src/expression/types/formatted.ts","../src/expression/types/padding.ts","../src/expression/types/number_array.ts","../src/expression/types/color_array.ts","../src/expression/runtime_error.ts","../src/expression/types/variable_anchor_offset_collection.ts","../src/expression/types/resolved_image.ts","../src/expression/types/projection_definition.ts","../src/expression/values.ts","../src/expression/definitions/literal.ts","../src/expression/definitions/assertion.ts","../src/expression/definitions/coercion.ts","../src/expression/evaluation_context.ts","../src/expression/parsing_context.ts","../src/expression/definitions/let.ts","../src/expression/definitions/var.ts","../src/expression/definitions/at.ts","../src/expression/definitions/in.ts","../src/expression/definitions/index_of.ts","../src/expression/definitions/match.ts","../src/expression/definitions/case.ts","../src/expression/definitions/slice.ts","../src/expression/stops.ts","../src/expression/definitions/step.ts","../node_modules/@mapbox/unitbezier/index.js","../src/expression/definitions/interpolate.ts","../src/expression/definitions/coalesce.ts","../src/expression/definitions/comparison.ts","../src/expression/definitions/collator.ts","../src/expression/definitions/number_format.ts","../src/expression/definitions/format.ts","../src/expression/definitions/image.ts","../src/expression/definitions/length.ts","../src/util/geometry_util.ts","../src/expression/definitions/within.ts","../node_modules/tinyqueue/index.js","../src/util/classify_rings.ts","../src/util/cheap_ruler.ts","../src/expression/definitions/distance.ts","../src/expression/definitions/global_state.ts","../src/expression/definitions/index.ts","../src/expression/compound_expression.ts","../src/util/result.ts","../src/util/properties.ts","../src/util/get_type.ts","../src/function/index.ts","../src/expression/index.ts","../src/validate/validate_object.ts","../src/validate/validate_array.ts","../src/validate/validate_number.ts","../src/validate/validate_function.ts","../src/validate/validate_expression.ts","../src/validate/validate_boolean.ts","../src/validate/validate_color.ts","../src/validate/validate_enum.ts","../src/feature_filter/index.ts","../src/validate/validate_filter.ts","../src/validate/validate_property.ts","../src/validate/validate_paint_property.ts","../src/validate/validate_layout_property.ts","../src/validate/validate_layer.ts","../src/validate/validate_string.ts","../src/validate/validate_raster_dem_source.ts","../src/validate/validate_source.ts","../src/validate/validate_light.ts","../src/validate/validate_sky.ts","../src/validate/validate_terrain.ts","../src/validate/validate_formatted.ts","../src/validate/validate_image.ts","../src/validate/validate_padding.ts","../src/validate/validate_number_array.ts","../src/validate/validate_color_array.ts","../src/validate/validate_variable_anchor_offset_collection.ts","../src/validate/validate_sprite.ts","../src/validate/validate_projection.ts","../src/validate/validate_projectiondefinition.ts","../src/util/is_object_literal.ts","../src/validate/validate_state.ts","../src/validate/validate.ts","../src/validate/validate_glyphs_url.ts","../src/validate_style.min.ts","../src/error/parsing_error.ts","../src/index.ts","../node_modules/@mapbox/jsonlint-lines-primitives/lib/jsonlint.js","../src/read_style.ts","../src/validate_style.ts","../bin/gl-style-validate.ts"],"sourcesContent":["'use strict';\n\nfunction hasKey(obj, keys) {\n\tvar o = obj;\n\tkeys.slice(0, -1).forEach(function (key) {\n\t\to = o[key] || {};\n\t});\n\n\tvar key = keys[keys.length - 1];\n\treturn key in o;\n}\n\nfunction isNumber(x) {\n\tif (typeof x === 'number') { return true; }\n\tif ((/^0x[0-9a-f]+$/i).test(x)) { return true; }\n\treturn (/^[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(e[-+]?\\d+)?$/).test(x);\n}\n\nfunction isConstructorOrProto(obj, key) {\n\treturn (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';\n}\n\nmodule.exports = function (args, opts) {\n\tif (!opts) { opts = {}; }\n\n\tvar flags = {\n\t\tbools: {},\n\t\tstrings: {},\n\t\tunknownFn: null,\n\t};\n\n\tif (typeof opts.unknown === 'function') {\n\t\tflags.unknownFn = opts.unknown;\n\t}\n\n\tif (typeof opts.boolean === 'boolean' && opts.boolean) {\n\t\tflags.allBools = true;\n\t} else {\n\t\t[].concat(opts.boolean).filter(Boolean).forEach(function (key) {\n\t\t\tflags.bools[key] = true;\n\t\t});\n\t}\n\n\tvar aliases = {};\n\n\tfunction aliasIsBoolean(key) {\n\t\treturn aliases[key].some(function (x) {\n\t\t\treturn flags.bools[x];\n\t\t});\n\t}\n\n\tObject.keys(opts.alias || {}).forEach(function (key) {\n\t\taliases[key] = [].concat(opts.alias[key]);\n\t\taliases[key].forEach(function (x) {\n\t\t\taliases[x] = [key].concat(aliases[key].filter(function (y) {\n\t\t\t\treturn x !== y;\n\t\t\t}));\n\t\t});\n\t});\n\n\t[].concat(opts.string).filter(Boolean).forEach(function (key) {\n\t\tflags.strings[key] = true;\n\t\tif (aliases[key]) {\n\t\t\t[].concat(aliases[key]).forEach(function (k) {\n\t\t\t\tflags.strings[k] = true;\n\t\t\t});\n\t\t}\n\t});\n\n\tvar defaults = opts.default || {};\n\n\tvar argv = { _: [] };\n\n\tfunction argDefined(key, arg) {\n\t\treturn (flags.allBools && (/^--[^=]+$/).test(arg))\n\t\t\t|| flags.strings[key]\n\t\t\t|| flags.bools[key]\n\t\t\t|| aliases[key];\n\t}\n\n\tfunction setKey(obj, keys, value) {\n\t\tvar o = obj;\n\t\tfor (var i = 0; i < keys.length - 1; i++) {\n\t\t\tvar key = keys[i];\n\t\t\tif (isConstructorOrProto(o, key)) { return; }\n\t\t\tif (o[key] === undefined) { o[key] = {}; }\n\t\t\tif (\n\t\t\t\to[key] === Object.prototype\n\t\t\t\t|| o[key] === Number.prototype\n\t\t\t\t|| o[key] === String.prototype\n\t\t\t) {\n\t\t\t\to[key] = {};\n\t\t\t}\n\t\t\tif (o[key] === Array.prototype) { o[key] = []; }\n\t\t\to = o[key];\n\t\t}\n\n\t\tvar lastKey = keys[keys.length - 1];\n\t\tif (isConstructorOrProto(o, lastKey)) { return; }\n\t\tif (\n\t\t\to === Object.prototype\n\t\t\t|| o === Number.prototype\n\t\t\t|| o === String.prototype\n\t\t) {\n\t\t\to = {};\n\t\t}\n\t\tif (o === Array.prototype) { o = []; }\n\t\tif (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {\n\t\t\to[lastKey] = value;\n\t\t} else if (Array.isArray(o[lastKey])) {\n\t\t\to[lastKey].push(value);\n\t\t} else {\n\t\t\to[lastKey] = [o[lastKey], value];\n\t\t}\n\t}\n\n\tfunction setArg(key, val, arg) {\n\t\tif (arg && flags.unknownFn && !argDefined(key, arg)) {\n\t\t\tif (flags.unknownFn(arg) === false) { return; }\n\t\t}\n\n\t\tvar value = !flags.strings[key] && isNumber(val)\n\t\t\t? Number(val)\n\t\t\t: val;\n\t\tsetKey(argv, key.split('.'), value);\n\n\t\t(aliases[key] || []).forEach(function (x) {\n\t\t\tsetKey(argv, x.split('.'), value);\n\t\t});\n\t}\n\n\tObject.keys(flags.bools).forEach(function (key) {\n\t\tsetArg(key, defaults[key] === undefined ? false : defaults[key]);\n\t});\n\n\tvar notFlags = [];\n\n\tif (args.indexOf('--') !== -1) {\n\t\tnotFlags = args.slice(args.indexOf('--') + 1);\n\t\targs = args.slice(0, args.indexOf('--'));\n\t}\n\n\tfor (var i = 0; i < args.length; i++) {\n\t\tvar arg = args[i];\n\t\tvar key;\n\t\tvar next;\n\n\t\tif ((/^--.+=/).test(arg)) {\n\t\t\t// Using [\\s\\S] instead of . because js doesn't support the\n\t\t\t// 'dotall' regex modifier. See:\n\t\t\t// http://stackoverflow.com/a/1068308/13216\n\t\t\tvar m = arg.match(/^--([^=]+)=([\\s\\S]*)$/);\n\t\t\tkey = m[1];\n\t\t\tvar value = m[2];\n\t\t\tif (flags.bools[key]) {\n\t\t\t\tvalue = value !== 'false';\n\t\t\t}\n\t\t\tsetArg(key, value, arg);\n\t\t} else if ((/^--no-.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--no-(.+)/)[1];\n\t\t\tsetArg(key, false, arg);\n\t\t} else if ((/^--.+/).test(arg)) {\n\t\t\tkey = arg.match(/^--(.+)/)[1];\n\t\t\tnext = args[i + 1];\n\t\t\tif (\n\t\t\t\tnext !== undefined\n\t\t\t\t&& !(/^(-|--)[^-]/).test(next)\n\t\t\t\t&& !flags.bools[key]\n\t\t\t\t&& !flags.allBools\n\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t) {\n\t\t\t\tsetArg(key, next, arg);\n\t\t\t\ti += 1;\n\t\t\t} else if ((/^(true|false)$/).test(next)) {\n\t\t\t\tsetArg(key, next === 'true', arg);\n\t\t\t\ti += 1;\n\t\t\t} else {\n\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t}\n\t\t} else if ((/^-[^-]+/).test(arg)) {\n\t\t\tvar letters = arg.slice(1, -1).split('');\n\n\t\t\tvar broken = false;\n\t\t\tfor (var j = 0; j < letters.length; j++) {\n\t\t\t\tnext = arg.slice(j + 2);\n\n\t\t\t\tif (next === '-') {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {\n\t\t\t\t\tsetArg(letters[j], next.slice(1), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\t(/[A-Za-z]/).test(letters[j])\n\t\t\t\t\t&& (/-?\\d+(\\.\\d*)?(e-?\\d+)?$/).test(next)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(letters[j], next, arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tif (letters[j + 1] && letters[j + 1].match(/\\W/)) {\n\t\t\t\t\tsetArg(letters[j], arg.slice(j + 2), arg);\n\t\t\t\t\tbroken = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tkey = arg.slice(-1)[0];\n\t\t\tif (!broken && key !== '-') {\n\t\t\t\tif (\n\t\t\t\t\targs[i + 1]\n\t\t\t\t\t&& !(/^(-|--)[^-]/).test(args[i + 1])\n\t\t\t\t\t&& !flags.bools[key]\n\t\t\t\t\t&& (aliases[key] ? !aliasIsBoolean(key) : true)\n\t\t\t\t) {\n\t\t\t\t\tsetArg(key, args[i + 1], arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {\n\t\t\t\t\tsetArg(key, args[i + 1] === 'true', arg);\n\t\t\t\t\ti += 1;\n\t\t\t\t} else {\n\t\t\t\t\tsetArg(key, flags.strings[key] ? '' : true, arg);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (!flags.unknownFn || flags.unknownFn(arg) !== false) {\n\t\t\t\targv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));\n\t\t\t}\n\t\t\tif (opts.stopEarly) {\n\t\t\t\targv._.push.apply(argv._, args.slice(i + 1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tObject.keys(defaults).forEach(function (k) {\n\t\tif (!hasKey(argv, k.split('.'))) {\n\t\t\tsetKey(argv, k.split('.'), defaults[k]);\n\n\t\t\t(aliases[k] || []).forEach(function (x) {\n\t\t\t\tsetKey(argv, x.split('.'), defaults[k]);\n\t\t\t});\n\t\t}\n\t});\n\n\tif (opts['--']) {\n\t\targv['--'] = notFlags.slice();\n\t} else {\n\t\tnotFlags.forEach(function (k) {\n\t\t\targv._.push(k);\n\t\t});\n\t}\n\n\treturn argv;\n};\n","module.exports = function(options) {\n if (options) {\n if (typeof options === \"string\") return encoding(options);\n if (options.encoding !== null) return encoding(options.encoding);\n }\n return identity();\n};\n\nfunction identity() {\n var chunks = [];\n return {\n push: function(chunk) { chunks.push(chunk); },\n value: function() { return Buffer.concat(chunks); }\n };\n}\n\nfunction encoding(encoding) {\n var chunks = [];\n return {\n push: function(chunk) { chunks.push(chunk); },\n value: function() { return Buffer.concat(chunks).toString(encoding); }\n };\n}\n","var fs = require(\"fs\"),\n decode = require(\"./decode\");\n\nmodule.exports = function(path, options, callback) {\n if (arguments.length < 3) callback = options, options = null;\n\n switch (path) {\n case \"/dev/stdin\": return readStream(process.stdin, options, callback);\n }\n\n fs.stat(path, function(error, stat) {\n if (error) return callback(error);\n if (stat.isFile()) return fs.readFile(path, options, callback);\n readStream(fs.createReadStream(path, options ? {flags: options.flag || \"r\"} : {}), options, callback); // N.B. flag / flags\n });\n};\n\nfunction readStream(stream, options, callback) {\n var decoder = decode(options);\n stream.on(\"error\", callback);\n stream.on(\"data\", function(d) { decoder.push(d); });\n stream.on(\"end\", function() { callback(null, decoder.value()); });\n}\n","var fs = require(\"fs\"),\n decode = require(\"./decode\");\n\nmodule.exports = function(filename, options) {\n if (fs.statSync(filename).isFile()) {\n return fs.readFileSync(filename, options);\n } else {\n var fd = fs.openSync(filename, options && options.flag || \"r\"),\n decoder = decode(options);\n\n while (true) { // eslint-disable-line no-constant-condition\n try {\n var buffer = new Buffer(bufferSize),\n bytesRead = fs.readSync(fd, buffer, 0, bufferSize);\n } catch (e) {\n if (e.code === \"EOF\") break;\n fs.closeSync(fd);\n throw e;\n }\n if (bytesRead === 0) break;\n decoder.push(buffer.slice(0, bytesRead));\n }\n\n fs.closeSync(fd);\n return decoder.value();\n }\n};\n\nvar bufferSize = 1 << 16;\n","module.exports = function(data, options) {\n return typeof data === \"string\"\n ? new Buffer(data, typeof options === \"string\" ? options\n : options && options.encoding !== null ? options.encoding\n : \"utf8\")\n : data;\n};\n","var fs = require(\"fs\"),\n encode = require(\"./encode\");\n\nmodule.exports = function(path, data, options, callback) {\n if (arguments.length < 4) callback = options, options = null;\n\n switch (path) {\n case \"/dev/stdout\": return writeStream(process.stdout, \"write\", data, options, callback);\n case \"/dev/stderr\": return writeStream(process.stderr, \"write\", data, options, callback);\n }\n\n fs.stat(path, function(error, stat) {\n if (error && error.code !== \"ENOENT\") return callback(error);\n if (stat && stat.isFile()) return fs.writeFile(path, data, options, callback);\n writeStream(fs.createWriteStream(path, options ? {flags: options.flag || \"w\"} : {}), \"end\", data, options, callback); // N.B. flag / flags\n });\n};\n\nfunction writeStream(stream, send, data, options, callback) {\n stream.on(\"error\", function(error) { callback(error.code === \"EPIPE\" ? null : error); }); // ignore broken pipe, e.g., | head\n stream[send](encode(data, options), function(error) { callback(error && error.code === \"EPIPE\" ? null : error); });\n}\n","var fs = require(\"fs\"),\n encode = require(\"./encode\");\n\nmodule.exports = function(filename, data, options) {\n var stat;\n\n try {\n stat = fs.statSync(filename);\n } catch (error) {\n if (error.code !== \"ENOENT\") throw error;\n }\n\n if (!stat || stat.isFile()) {\n fs.writeFileSync(filename, data, options);\n } else {\n var fd = fs.openSync(filename, options && options.flag || \"w\"),\n bytesWritten = 0,\n bytesTotal = (data = encode(data, options)).length;\n\n while (bytesWritten < bytesTotal) {\n try {\n bytesWritten += fs.writeSync(fd, data, bytesWritten, bytesTotal - bytesWritten, null);\n } catch (error) {\n if (error.code === \"EPIPE\") break; // ignore broken pipe, e.g., | head\n fs.closeSync(fd);\n throw error;\n }\n }\n\n fs.closeSync(fd);\n }\n};\n","var slice = Array.prototype.slice;\n\nfunction dashify(method, file) {\n return function(path) {\n var argv = arguments;\n if (path == \"-\") (argv = slice.call(argv)).splice(0, 1, file);\n return method.apply(null, argv);\n };\n}\n\nexports.readFile = dashify(require(\"./read-file\"), \"/dev/stdin\");\nexports.readFileSync = dashify(require(\"./read-file-sync\"), \"/dev/stdin\");\nexports.writeFile = dashify(require(\"./write-file\"), \"/dev/stdout\");\nexports.writeFileSync = dashify(require(\"./write-file-sync\"), \"/dev/stdout\");\n","exports.dash = require(\"./lib/rw/dash\");\nexports.readFile = require(\"./lib/rw/read-file\");\nexports.readFileSync = require(\"./lib/rw/read-file-sync\");\nexports.writeFile = require(\"./lib/rw/write-file\");\nexports.writeFileSync = require(\"./lib/rw/write-file-sync\");\n","// Note: Do not inherit from Error. It breaks when transpiling to ES5.\n\nexport class ValidationError {\n message: string;\n identifier: string;\n line: number;\n\n constructor(key: string, value: any & {\n __line__: number;\n }, message: string, identifier?: string | null) {\n this.message = (key ? `${key}: ` : '') + message;\n if (identifier) this.identifier = identifier;\n\n if (value !== null && value !== undefined && value.__line__) {\n this.line = value.__line__;\n }\n }\n}\n","\nimport {ValidationError} from '../error/validation_error';\n\nexport function validateConstants(options) {\n const key = options.key;\n const constants = options.value;\n\n if (constants) {\n return [new ValidationError(key, constants, 'constants have been deprecated as of v8')];\n } else {\n return [];\n }\n}\n","export function extendBy(output: any, ...inputs: Array<any>) {\n for (const input of inputs) {\n for (const k in input) {\n output[k] = input[k];\n }\n }\n return output;\n}\n","// Turn jsonlint-lines-primitives objects into primitive objects\nexport function unbundle(value: unknown) {\n if (value instanceof Number || value instanceof String || value instanceof Boolean) {\n return value.valueOf();\n } else {\n return value;\n }\n}\n\nexport function deepUnbundle(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(deepUnbundle);\n } else if (value instanceof Object && !(value instanceof Number || value instanceof String || value instanceof Boolean)) {\n const unbundledValue: {[key: string]: unknown} = {};\n for (const key in value) {\n unbundledValue[key] = deepUnbundle(value[key]);\n }\n return unbundledValue;\n }\n\n return unbundle(value);\n}\n","export class ExpressionParsingError extends Error {\n key: string;\n message: string;\n constructor(key: string, message: string) {\n super(message);\n this.message = message;\n this.key = key;\n }\n}\n","import type {Expression} from './expression';\n\n/**\n * Tracks `let` bindings during expression parsing.\n * @private\n */\nexport class Scope {\n parent: Scope;\n bindings: {[_: string]: Expression};\n constructor(parent?: Scope, bindings: Array<[string, Expression]> = []) {\n this.parent = parent;\n this.bindings = {};\n for (const [name, expression] of bindings) {\n this.bindings[name] = expression;\n }\n }\n\n concat(bindings: Array<[string, Expression]>) {\n return new Scope(this, bindings);\n }\n\n get(name: string): Expression {\n if (this.bindings[name]) { return this.bindings[name]; }\n if (this.parent) { return this.parent.get(name); }\n throw new Error(`${name} not found in scope.`);\n }\n\n has(name: string): boolean {\n if (this.bindings[name]) return true;\n return this.parent ? this.parent.has(name) : false;\n }\n}\n","export type NullTypeT = {\n kind: 'null';\n};\nexport type NumberTypeT = {\n kind: 'number';\n};\nexport type StringTypeT = {\n kind: 'string';\n};\nexport type BooleanTypeT = {\n kind: 'boolean';\n};\nexport type ColorTypeT = {\n kind: 'color';\n};\nexport type ProjectionDefinitionTypeT = {\n kind: 'projectionDefinition';\n};\nexport type ObjectTypeT = {\n kind: 'object';\n};\nexport type ValueTypeT = {\n kind: 'value';\n};\nexport type ErrorTypeT = {\n kind: 'error';\n};\nexport type CollatorTypeT = {\n kind: 'collator';\n};\nexport type FormattedTypeT = {\n kind: 'formatted';\n};\nexport type PaddingTypeT = {\n kind: 'padding';\n};\nexport type NumberArrayTypeT = {\n kind: 'numberArray';\n};\nexport type ColorArrayTypeT = {\n kind: 'colorArray';\n};\nexport type ResolvedImageTypeT = {\n kind: 'resolvedImage';\n};\nexport type VariableAnchorOffsetCollectionTypeT = {\n kind: 'variableAnchorOffsetCollection';\n};\n\nexport type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';\n\nexport type Type = NullTypeT | NumberTypeT | StringTypeT | BooleanTypeT | ColorTypeT | ProjectionDefinitionTypeT | ObjectTypeT | ValueTypeT |\nArrayType | ErrorTypeT | CollatorTypeT | FormattedTypeT | PaddingTypeT | NumberArrayTypeT | ColorArrayTypeT | ResolvedImageTypeT | VariableAnchorOffsetCollectionTypeT;\n\nexport interface ArrayType<T extends Type = Type> {\n kind: 'array';\n itemType: T;\n N: number;\n}\n\nexport type NativeType = 'number' | 'string' | 'boolean' | 'null' | 'array' | 'object';\n\nexport const NullType = {kind: 'null'} as NullTypeT;\nexport const NumberType = {kind: 'number'} as NumberTypeT;\nexport const StringType = {kind: 'string'} as StringTypeT;\nexport const BooleanType = {kind: 'boolean'} as BooleanTypeT;\nexport const ColorType = {kind: 'color'} as ColorTypeT;\nexport const ProjectionDefinitionType = {kind: 'projectionDefinition'} as ProjectionDefinitionTypeT;\nexport const ObjectType = {kind: 'object'} as ObjectTypeT;\nexport const ValueType = {kind: 'value'} as ValueTypeT;\nexport const ErrorType = {kind: 'error'} as ErrorTypeT;\nexport const CollatorType = {kind: 'collator'} as CollatorTypeT;\nexport const FormattedType = {kind: 'formatted'} as FormattedTypeT;\nexport const PaddingType = {kind: 'padding'} as PaddingTypeT;\nexport const ColorArrayType = {kind: 'colorArray'} as ColorArrayTypeT;\nexport const NumberArrayType = {kind: 'numberArray'} as NumberArrayTypeT;\nexport const ResolvedImageType = {kind: 'resolvedImage'} as ResolvedImageTypeT;\nexport const VariableAnchorOffsetCollectionType = {kind: 'variableAnchorOffsetCollection'} as VariableAnchorOffsetCollectionTypeT;\n\nexport function array<T extends Type>(itemType: T, N?: number | null): ArrayType<T> {\n return {\n kind: 'array',\n itemType,\n N\n };\n}\n\nexport function typeToString(type: Type): string {\n if (type.kind === 'array') {\n const itemType = typeToString(type.itemType);\n return typeof type.N === 'number' ?\n `array<${itemType}, ${type.N}>` :\n type.itemType.kind === 'value' ? 'array' : `array<${itemType}>`;\n } else {\n return type.kind;\n }\n}\n\nconst valueMemberTypes = [\n NullType,\n NumberType,\n StringType,\n BooleanType,\n ColorType,\n ProjectionDefinitionType,\n FormattedType,\n ObjectType,\n array(ValueType),\n PaddingType,\n NumberArrayType,\n ColorArrayType,\n ResolvedImageType,\n VariableAnchorOffsetCollectionType\n];\n\n/**\n * Returns null if `t` is a subtype of `expected`; otherwise returns an\n * error message.\n * @private\n */\nexport function checkSubtype(expected: Type, t: Type): string {\n if (t.kind === 'error') {\n // Error is a subtype of every type\n return null;\n } else if (expected.kind === 'array') {\n if (t.kind === 'array' &&\n ((t.N === 0 && t.itemType.kind === 'value') || !checkSubtype(expected.itemType, t.itemType)) &&\n (typeof expected.N !== 'number' || expected.N === t.N)) {\n return null;\n }\n } else if (expected.kind === t.kind) {\n return null;\n } else if (expected.kind === 'value') {\n for (const memberType of valueMemberTypes) {\n if (!checkSubtype(memberType, t)) {\n return null;\n }\n }\n }\n\n return `Expected ${typeToString(expected)} but found ${typeToString(t)} instead.`;\n}\n\nexport function isValidType(provided: Type, allowedTypes: Array<Type>): boolean {\n return allowedTypes.some(t => t.kind === provided.kind);\n}\n\nexport function isValidNativeType(provided: any, allowedTypes: Array<NativeType>): boolean {\n return allowedTypes.some(t => {\n if (t === 'null') {\n return provided === null;\n } else if (t === 'array') {\n return Array.isArray(provided);\n } else if (t === 'object') {\n return provided && !Array.isArray(provided) && typeof provided === 'object';\n } else {\n return t === typeof provided;\n }\n });\n}\n\n/**\n * Verify whether the specified type is of the same type as the specified sample.\n *\n * @param provided Type to verify\n * @param sample Sample type to reference\n * @returns `true` if both objects are of the same type, `false` otherwise\n * @example basic types\n * if (verifyType(outputType, ValueType)) {\n * // type narrowed to:\n * outputType.kind; // 'value'\n * }\n * @example array types\n * if (verifyType(outputType, array(NumberType))) {\n * // type narrowed to:\n * outputType.kind; // 'array'\n * outputType.itemType; // NumberTypeT\n * outputType.itemType.kind; // 'number'\n * }\n */\nexport function verifyType<T extends Type>(provided: Type, sample: T): provided is T {\n if (provided.kind === 'array' && sample.kind === 'array') {\n return provided.itemType.kind === sample.itemType.kind && typeof provided.N === 'number';\n }\n return provided.kind === sample.kind;\n}\n","/**\n * @param r Red component 0..1\n * @param g Green component 0..1\n * @param b Blue component 0..1\n * @param alpha Alpha component 0..1\n */\nexport type RGBColor = [r: number, g: number, b: number, alpha: number];\n\n/**\n * @param h Hue as degrees 0..360\n * @param s Saturation as percentage 0..100\n * @param l Lightness as percentage 0..100\n * @param alpha Alpha component 0..1\n */\nexport type HSLColor = [h: number, s: number, l: number, alpha: number];\n\n/**\n * @param h Hue as degrees 0..360\n * @param c Chroma 0..~230\n * @param l Lightness as percentage 0..100\n * @param alpha Alpha component 0..1\n */\nexport type HCLColor = [h: number, c: number, l: number, alpha: number];\n\n/**\n * @param l Lightness as percentage 0..100\n * @param a A axis value -125..125\n * @param b B axis value -125..125\n * @param alpha Alpha component 0..1\n */\nexport type LABColor = [l: number, a: number, b: number, alpha: number];\n\n// See https://observablehq.com/@mbostock/lab-and-rgb\nconst Xn = 0.96422,\n Yn = 1,\n Zn = 0.82521,\n t0 = 4 / 29,\n t1 = 6 / 29,\n t2 = 3 * t1 * t1,\n t3 = t1 * t1 * t1,\n deg2rad = Math.PI / 180,\n rad2deg = 180 / Math.PI;\n\nfunction constrainAngle(angle: number): number {\n angle = angle % 360;\n if (angle < 0) {\n angle += 360;\n }\n return angle;\n}\n\nexport function rgbToLab([r, g, b, alpha]: RGBColor): LABColor {\n r = rgb2xyz(r);\n g = rgb2xyz(g);\n b = rgb2xyz(b);\n let x, z;\n const y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn);\n if (r === g && g === b) {\n x = z = y;\n } else {\n x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);\n z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);\n }\n\n const l = 116 * y - 16;\n return [(l < 0) ? 0 : l, 500 * (x - y), 200 * (y - z), alpha];\n}\n\nfunction rgb2xyz(x: number): number {\n return (x <= 0.04045) ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);\n}\n\nfunction xyz2lab(t: number): number {\n return (t > t3) ? Math.pow(t, 1 / 3) : t / t2 + t0;\n}\n\nexport function labToRgb([l, a, b, alpha]: LABColor): RGBColor {\n let y = (l + 16) / 116,\n x = isNaN(a) ? y : y + a / 500,\n z = isNaN(b) ? y : y - b / 200;\n\n y = Yn * lab2xyz(y);\n x = Xn * lab2xyz(x);\n z = Zn * lab2xyz(z);\n\n return [\n xyz2rgb(3.1338561 * x - 1.6168667 * y - 0.4906146 * z), // D50 -> sRGB\n xyz2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),\n xyz2rgb(0.0719453 * x - 0.2289914 * y + 1.4052427 * z),\n alpha,\n ];\n}\n\nfunction xyz2rgb(x: number): number {\n x = (x <= 0.00304) ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055;\n return (x < 0) ? 0 : (x > 1) ? 1 : x; // clip to 0..1 range\n}\n\nfunction lab2xyz(t: number): number {\n return (t > t1) ? t * t * t : t2 * (t - t0);\n}\n\nexport function rgbToHcl(rgbColor: RGBColor): HCLColor {\n const [l, a, b, alpha] = rgbToLab(rgbColor);\n const c = Math.sqrt(a * a + b * b);\n const h = Math.round(c * 10000) ? constrainAngle(Math.atan2(b, a) * rad2deg) : NaN;\n return [h, c, l, alpha];\n}\n\nexport function hclToRgb([h, c, l, alpha]: HCLColor): RGBColor {\n h = isNaN(h) ? 0 : h * deg2rad;\n return labToRgb([l, Math.cos(h) * c, Math.sin(h) * c, alpha]);\n}\n\n// https://drafts.csswg.org/css-color-4/#hsl-to-rgb\nexport function hslToRgb([h, s, l, alpha]: HSLColor): RGBColor {\n h = constrainAngle(h);\n s /= 100;\n l /= 100;\n\n function f(n) {\n const k = (n + h / 30) % 12;\n const a = s * Math.min(l, 1 - l);\n return l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));\n }\n\n return [f(0), f(8), f(4), alpha];\n}\n","type HasOwnPropertyFn = <TObject extends object>(obj: TObject, key: PropertyKey) => key is keyof TObject;\n\n// polyfill for Object.hasOwn\nconst hasOwnProperty: HasOwnPropertyFn =\n (Object.hasOwn as HasOwnPropertyFn) ||\n function hasOwnProperty<T extends object>(object: T, key: PropertyKey): key is keyof T {\n return Object.prototype.hasOwnProperty.call(object, key);\n };\n\nexport function getOwn<T extends object>(object: T, key: PropertyKey): T[keyof T] | undefined {\n return hasOwnProperty(object, key) ? object[key] : undefined;\n}\n","import {getOwn} from '../../util/get_own';\nimport {HSLColor, hslToRgb, RGBColor} from './color_spaces';\n\n/**\n * CSS color parser compliant with CSS Color 4 Specification.\n * Supports: named colors, `transparent` keyword, all rgb hex notations,\n * rgb(), rgba(), hsl() and hsla() functions.\n * Does not round the parsed values to integers from the range 0..255.\n *\n * Syntax:\n *\n * <alpha-value> = <number> | <percentage>\n * <hue> = <number> | <angle>\n *\n * rgb() = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? )\n * rgb() = rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )\n *\n * hsl() = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? )\n * hsl() = hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )\n *\n * Caveats:\n * - <angle> - <number> with optional `deg` suffix; `grad`, `rad`, `turn` are not supported\n * - `none` keyword is not supported\n * - comments inside rgb()/hsl() are not supported\n * - legacy color syntax rgba() is supported with an identical grammar and behavior to rgb()\n * - legacy color syntax hsla() is supported with an identical grammar and behavior to hsl()\n *\n * @param input CSS color string to parse.\n * @returns Color in sRGB color space, with `red`, `green`, `blue`\n * and `alpha` channels normalized to the range 0..1,\n * or `undefined` if the input is not a valid color string.\n */\nexport function parseCssColor(input: string): RGBColor | undefined {\n input = input.toLowerCase().trim();\n\n if (input === 'transparent') {\n return [0, 0, 0, 0];\n }\n\n // 'white', 'black', 'blue'\n const namedColorsMatch = getOwn(namedColors, input);\n if (namedColorsMatch) {\n const [r, g, b] = namedColorsMatch;\n return [r / 255, g / 255, b / 255, 1];\n }\n\n // #f0c, #f0cf, #ff00cc, #ff00ccff\n if (input.startsWith('#')) {\n const hexRegexp = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/;\n if (hexRegexp.test(input)) {\n const step = input.length < 6 ? 1 : 2;\n let i = 1;\n return [\n parseHex(input.slice(i, i += step)),\n parseHex(input.slice(i, i += step)),\n parseHex(input.slice(i, i += step)),\n parseHex(input.slice(i, i + step) || 'ff'),\n ];\n }\n }\n\n // rgb(128 0 0), rgb(50% 0% 0%), rgba(255,0,255,0.6), rgb(255 0 255 / 60%), rgb(100% 0% 100% /.6)\n if (input.startsWith('rgb')) {\n const rgbRegExp = /^rgba?\\(\\s*([\\de.+-]+)(%)?(?:\\s+|\\s*(,)\\s*)([\\de.+-]+)(%)?(?:\\s+|\\s*(,)\\s*)([\\de.+-]+)(%)?(?:\\s*([,\\/])\\s*([\\de.+-]+)(%)?)?\\s*\\)$/;\n const rgbMatch = input.match(rgbRegExp);\n if (rgbMatch) {\n const [\n _, // eslint-disable-line @typescript-eslint/no-unused-vars\n r, // <numeric>\n rp, // % (optional)\n f1, // , (optional)\n g, // <numeric>\n gp, // % (optional)\n f2, // , (optional)\n b, // <numeric>\n bp, // % (optional)\n f3, // ,|/ (optional)\n a, // <numeric> (optional)\n ap, // % (optional)\n ] = rgbMatch;\n\n const argFormat = [f1 || ' ', f2 || ' ', f3].join('');\n if (\n argFormat === ' ' ||\n argFormat === ' /' ||\n argFormat === ',,' ||\n argFormat === ',,,'\n ) {\n const valFormat = [rp, gp, bp].join('');\n const maxValue =\n (valFormat === '%%%') ? 100 :\n (valFormat === '') ? 255 : 0;\n if (maxValue) {\n const rgba: RGBColor = [\n clamp(+r / maxValue, 0, 1),\n clamp(+g / maxValue, 0, 1),\n clamp(+b / maxValue, 0, 1),\n a ? parseAlpha(+a, ap) : 1,\n ];\n if (validateNumbers(rgba)) {\n return rgba;\n }\n // invalid numbers\n }\n // values must be all numbers or all percentages\n }\n return; // comma optional syntax requires no commas at all\n }\n }\n\n // hsl(120 50% 80%), hsla(120deg,50%,80%,.9), hsl(12e1 50% 80% / 90%)\n const hslRegExp = /^hsla?\\(\\s*([\\de.+-]+)(?:deg)?(?:\\s+|\\s*(,)\\s*)([\\de.+-]+)%(?:\\s+|\\s*(,)\\s*)([\\de.+-]+)%(?:\\s*([,\\/])\\s*([\\de.+-]+)(%)?)?\\s*\\)$/;\n const hslMatch = input.match(hslRegExp);\n if (hslMatch) {\n const [\n _, // eslint-disable-line @typescript-eslint/no-unused-vars\n h, // <numeric>\n f1, // , (optional)\n s, // <numeric>\n f2, // , (optional)\n l, // <numeric>\n f3, // ,|/ (optional)\n a, // <numeric> (optional)\n ap, // % (optional)\n ] = hslMatch;\n\n const argFormat = [f1 || ' ', f2 || ' ', f3].join('');\n if (\n argFormat === ' ' ||\n argFormat === ' /' ||\n argFormat === ',,' ||\n argFormat === ',,,'\n ) {\n const hsla: HSLColor = [\n +h,\n clamp(+s, 0, 100),\n clamp(+l, 0, 100),\n a ? parseAlpha(+a, ap) : 1,\n ];\n if (validateNumbers(hsla)) {\n return hslToRgb(hsla);\n }\n // invalid numbers\n }\n // comma optional syntax requires no commas at all\n }\n}\n\nfunction parseHex(hex: string): number {\n return parseInt(hex.padEnd(2, hex), 16) / 255;\n}\n\nfunction parseAlpha(a: number, asPercentage: string | undefined): number {\n return clamp(asPercentage ? (a / 100) : a, 0, 1);\n}\n\nfunction clamp(n: number, min: number, max: number): number {\n return Math.min(Math.max(min, n), max);\n}\n\n/**\n * The regular expression for numeric values is not super specific, and it may\n * happen that it will accept a value that is not a valid number. In order to\n * detect and eliminate such values this function exists.\n *\n * @param array Array of uncertain numbers.\n * @returns `true` if the specified array contains only valid numbers, `false` otherwise.\n */\nfunction validateNumbers(array: number[]): boolean {\n return !array.some(Number.isNaN);\n}\n\n/**\n * To generate:\n * - visit {@link https://www.w3.org/TR/css-color-4/#named-colors}\n * - run in the console:\n * @example\n * copy(`{\\n${[...document.querySelector('.named-color-table tbody').children].map((tr) => `${tr.cells[2].textContent.trim()}: [${tr.cells[4].textContent.trim().split(/\\s+/).join(', ')}],`).join('\\n')}\\n}`);\n */\nconst namedColors: Record<string, [number, number, number]> = {\n aliceblue: [240, 248, 255],\n antiquewhite: [250, 235, 215],\n aqua: [0, 255, 255],\n aquamarine: [127, 255, 212],\n azure: [240, 255, 255],\n beige: [245, 245, 220],\n bisque: [255, 228, 196],\n black: [0, 0, 0],\n blanchedalmond: [255, 235, 205],\n blue: [0, 0, 255],\n blueviolet: [138, 43, 226],\n brown: [165, 42, 42],\n burlywood: [222, 184, 135],\n cadetblue: [95, 158, 160],\n chartreuse: [127, 255, 0],\n chocolate: [210, 105, 30],\n coral: [255, 127, 80],\n cornflowerblue: [100, 149, 237],\n cornsilk: [255, 248, 220],\n crimson: [220, 20, 60],\n cyan: [0, 255, 255],\n darkblue: [0, 0, 139],\n darkcyan: [0, 139, 139],\n darkgoldenrod: [184, 134, 11],\n darkgray: [169, 169, 169],\n darkgreen: [0, 100, 0],\n darkgrey: [169, 169, 169],\n darkkhaki: [189, 183, 107],\n darkmagenta: [139, 0, 139],\n darkolivegreen: [85, 107, 47],\n darkorange: [255, 140, 0],\n darkorchid: [153, 50, 204],\n darkred: [139, 0, 0],\n darksalmon: [233, 150, 122],\n darkseagreen: [143, 188, 143],\n darkslateblue: [72, 61, 139],\n darkslategray: [47, 79, 79],\n darkslategrey: [47, 79, 79],\n darkturquoise: [0, 206, 209],\n darkviolet: [148, 0, 211],\n deeppink: [255, 20, 147],\n deepskyblue: [0, 191, 255],\n dimgray: [105, 105, 105],\n dimgrey: [105, 105, 105],\n dodgerblue: [30, 144, 255],\n firebrick: [178, 34, 34],\n floralwhite: [255, 250, 240],\n forestgreen: [34, 139, 34],\n fuchsia: [255, 0, 255],\n gainsboro: [220, 220, 220],\n ghostwhite: [248, 248, 255],\n gold: [255, 215, 0],\n goldenrod: [218, 165, 32],\n gray: [128, 128, 128],\n green: [0, 128, 0],\n greenyellow: [173, 255, 47],\n grey: [128, 128, 128],\n honeydew: [240, 255, 240],\n hotpink: [255, 105, 180],\n indianred: [205, 92, 92],\n indigo: [75, 0, 130],\n ivory: [255, 255, 240],\n khaki: [240, 230, 140],\n lavender: [230, 230, 250],\n lavenderblush: [255, 240, 245],\n lawngreen: [124, 252, 0],\n lemonchiffon: [255, 250, 205],\n lightblue: [173, 216, 230],\n lightcoral: [240, 128, 128],\n lightcyan: [224, 255, 255],\n lightgoldenrodyellow: [250, 250, 210],\n lightgray: [211, 211, 211],\n lightgreen: [144, 238, 144],\n lightgrey: [211, 211, 211],\n lightpink: [255, 182, 193],\n lightsalmon: [255, 160, 122],\n lightseagreen: [32, 178, 170],\n lightskyblue: [135, 206, 250],\n lightslategray: [119, 136, 153],\n lightslategrey: [119, 136, 153],\n lightsteelblue: [176, 196, 222],\n lightyellow: [255, 255, 224],\n lime: [0, 255, 0],\n limegreen: [50, 205, 50],\n linen: [250, 240, 230],\n magenta: [255, 0, 255],\n maroon: [128, 0, 0],\n mediumaquamarine: [102, 205, 170],\n mediumblue: [0, 0, 205],\n mediumorchid: [186, 85, 211],\n mediumpurple: [147, 112, 219],\n mediumseagreen: [60, 179, 113],\n mediumslateblue: [123, 104, 238],\n mediumspringgreen: [0, 250, 154],\n mediumturquoise: [72, 209, 204],\n mediumvioletred: [199, 21, 133],\n midnightblue: [25, 25, 112],\n mintcream: [245, 255, 250],\n mistyrose: [255, 228, 225],\n moccasin: [255, 228, 181],\n navajowhite: [255, 222, 173],\n navy: [0, 0, 128],\n oldlace: [253, 245, 230],\n olive: [128, 128, 0],\n olivedrab: [107, 142, 35],\n orange: [255, 165, 0],\n orangered: [255, 69, 0],\n orchid: [218, 112, 214],\n palegoldenrod: [238, 232, 170],\n palegreen: [152, 251, 152],\n paleturquoise: [175, 238, 238],\n palevioletred: [219, 112, 147],\n papayawhip: [255, 239, 213],\n peachpuff: [255, 218, 185],\n peru: [205, 133, 63],\n pink: [255, 192, 203],\n plum: [221, 160, 221],\n powderblue: [176, 224, 230],\n purple: [128, 0, 128],\n rebeccapurple: [102, 51, 153],\n red: [255, 0, 0],\n rosybrown: [188, 143, 143],\n royalblue: [65, 105, 225],\n saddlebrown: [139, 69, 19],\n salmon: [250, 128, 114],\n sandybrown: [244, 164, 96],\n seagreen: [46, 139, 87],\n seashell: [255, 245, 238],\n sienna: [160, 82, 45],\n silver: [192, 192, 192],\n skyblue: [135, 206, 235],\n slateblue: [106, 90, 205],\n slategray: [112, 128, 144],\n slategrey: [112, 128, 144],\n snow: [255, 250, 250],\n springgreen: [0, 255, 127],\n steelblue: [70, 130, 180],\n tan: [210, 180, 140],\n teal: [0, 128, 128],\n thistle: [216, 191, 216],\n tomato: [255, 99, 71],\n turquoise: [64, 224, 208],\n violet: [238, 130, 238],\n wheat: [245, 222, 179],\n white: [255, 255, 255],\n whitesmoke: [245, 245, 245],\n yellow: [255, 255, 0],\n yellowgreen: [154, 205, 50],\n};\n","export function interpolateNumber(from: number, to: number, t: number): number {\n return from + t * (to - from);\n}\n\nexport function interpolateArray<T extends number[]>(from: T, to: T, t: number): T {\n return from.map((d, i) => {\n return interpolateNumber(d, to[i], t);\n }) as T;\n}\n","import {HCLColor, hclToRgb, LABColor, labToRgb, RGBColor, rgbToHcl, rgbToLab} from './color_spaces';\nimport {parseCssColor} from './parse_css_color';\nimport {interpolateArray, interpolateNumber} from '../../util/interpolate-primitives';\n\nexport type InterpolationColorSpace = 'rgb' | 'hcl' | 'lab';\n\n/**\n * Checks whether the specified color space is one of the supported interpolation color spaces.\n *\n * @param colorSpace Color space key to verify.\n * @returns `true` if the specified color space is one of the supported\n * interpolation color spaces, `false` otherwise\n */\nexport function isSupportedInterpolationColorSpace(colorSpace: string): colorSpace is InterpolationColorSpace {\n return colorSpace === 'rgb' || colorSpace === 'hcl' || colorSpace === 'lab';\n}\n\n/**\n * Color representation used by WebGL.\n * Defined in sRGB color space and pre-blended with alpha.\n * @private\n */\nexport class Color {\n\n readonly r: number;\n readonly g: number;\n readonly b: number;\n readonly a: number;\n\n /**\n * @param r Red component premultiplied by `alpha` 0..1\n * @param g Green component premultiplied by `alpha` 0..1\n * @param b Blue component premultiplied by `alpha` 0..1\n * @param [alpha=1] Alpha component 0..1\n * @param [premultiplied=true] Whether the `r`, `g` and `b` values have already\n * been multiplied by alpha. If `true` nothing happens if `false` then they will\n * be multiplied automatically.\n */\n constructor(r: number, g: number, b: number, alpha = 1, premultiplied = true) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = alpha;\n\n if (!premultiplied) {\n this.r *= alpha;\n this.g *= alpha;\n this.b *= alpha;\n\n if (!alpha) {\n // alpha = 0 erases completely rgb channels. This behavior is not desirable\n // if this particular color is later used in color interpolation.\n // Because of that, a reference to original color is saved.\n this.overwriteGetter('rgb', [r, g, b, alpha]);\n }\n }\n }\n\n static black = new Color(0, 0, 0, 1);\n static white = new Color(1, 1, 1, 1);\n static transparent = new Color(0, 0, 0, 0);\n static red = new Color(1, 0, 0, 1);\n\n /**\n * Parses CSS color strings and converts colors to sRGB color space if needed.\n * Officially supported color formats:\n * - keyword, e.g. 'aquamarine' or 'steelblue'\n * - hex (with 3, 4, 6 or 8 digits), e.g. '#f0f' or '#e9bebea9'\n * - rgb and rgba, e.g. 'rgb(0,240,120)' or 'rgba(0%,94%,47%,0.1)' or 'rgb(0 240 120 / .3)'\n * - hsl and hsla, e.g. 'hsl(0,0%,83%)' or 'hsla(0,0%,83%,.5)' or 'hsl(0 0% 83% / 20%)'\n *\n * @param input CSS color string to parse.\n * @returns A `Color` instance, or `undefined` if the input is not a valid color string.\n */\n static parse(input: Color | string | undefined | null): Color | undefined {\n // in zoom-and-property function input could be an instance of Color class\n if (input instanceof Color) {\n return input;\n }\n\n if (typeof input !== 'string') {\n return;\n }\n\n const rgba = parseCssColor(input);\n if (rgba) {\n return new Color(...rgba, false);\n }\n }\n\n /**\n * Used in color interpolation and by 'to-rgba' expression.\n *\n * @returns Gien color, with reversed alpha blending, in sRGB color space.\n */\n get rgb(): RGBColor {\n const {r, g, b, a} = this;\n const f = a || Infinity; // reverse alpha blending factor\n return this.overwriteGetter('rgb', [r / f, g / f, b / f, a]);\n }\n\n /**\n * Used in color interpolation.\n *\n * @returns Gien color, with reversed alpha blending, in HCL color space.\n */\n get hcl(): HCLColor {\n return this.overwriteGetter('hcl', rgbToHcl(this.rgb));\n }\n\n /**\n * Used in color interpolation.\n *\n * @returns Gien color, with reversed alpha blending, in LAB color space.\n */\n get lab(): LABColor {\n return this.overwriteGetter('lab', rgbToLab(this.rgb));\n }\n\n /**\n * Lazy getter pattern. When getter is called for the first time lazy value\n * is calculated and then overwrites getter function in given object instance.\n *\n * @example:\n * const redColor = Color.parse('red');\n * let x = redColor.hcl; // this will invoke `get hcl()`, which will calculate\n * // the value of red in HCL space and invoke this `overwriteGetter` function\n * // which in turn will set a field with a key 'hcl' in the `redColor` object.\n * // In other words it will override `get hcl()` from its `Color` prototype\n * // with its own property: hcl = [calculated red value in hcl].\n * let y = redColor.hcl; // next call will no longer invoke getter but simply\n * // return the previously calculated value\n * x === y; // true - `x` is exactly the same object as `y`\n *\n * @param getterKey Getter key\n * @param lazyValue Lazily calculated value to be memoized by current instance\n * @private\n */\n private overwriteGetter<T>(getterKey: string, lazyValue: T): T {\n Object.defineProperty(this, getterKey, {value: lazyValue});\n return lazyValue;\n }\n\n /**\n * Used by 'to-string' expression.\n *\n * @returns Serialized color in format `rgba(r,g,b,a)`\n * where r,g,b are numbers within 0..255 and alpha is number within 1..0\n *\n * @example\n * var purple = new Color.parse('purple');\n * purple.toString; // = \"rgba(128,0,128,1)\"\n * var translucentGreen = new Color.parse('rgba(26, 207, 26, .73)');\n * translucentGreen.toString(); // = \"rgba(26,207,26,0.73)\"\n */\n toString(): string {\n const [r, g, b, a] = this.rgb;\n return `rgba(${[r, g, b].map(n => Math.round(n * 255)).join(',')},${a})`;\n }\n\n static interpolate(from: Color, to: Color, t: number, spaceKey: InterpolationColorSpace = 'rgb'): Color {\n switch (spaceKey) {\n case 'rgb': {\n const [r, g, b, alpha] = interpolateArray(from.rgb, to.rgb, t);\n return new Color(r, g, b, alpha, false);\n }\n case 'hcl': {\n const [hue0, chroma0, light0, alphaF] = from.hcl;\n const [hue1, chroma1, light1, alphaT] = to.hcl;\n \n // https://github.com/gka/chroma.js/blob/cd1b3c0926c7a85cbdc3b1453b3a94006de91a92/src/interpolator/_hsx.js\n let hue, chroma;\n \n if (!isNaN(hue0) && !isNaN(hue1)) {\n let dh = hue1 - hue0;\n if (hue1 > hue0 && dh > 180) {\n dh -= 360;\n } else if (hue1 < hue0 && hue0 - hue1 > 180) {\n dh += 360;\n }\n hue = hue0 + t * dh;\n } else if (!isNaN(hue0)) {\n hue = hue0;\n if (light1 === 1 || light1 === 0) chroma = chroma0;\n } else if (!isNaN(hue1)) {\n hue = hue1;\n if (light0 === 1 || light0 === 0) chroma = chroma1;\n } else {\n hue = NaN;\n }\n \n const [r, g, b, alpha] = hclToRgb([\n hue,\n chroma ?? interpolateNumber(chroma0, chroma1, t),\n inter