@maplibre/maplibre-gl-style-spec
Version:
a specification for maplibre styles
1 lines • 637 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","sources":["../src/util/ref_properties.ts","../src/deref.ts","../src/util/deep_equal.ts","../src/diff.ts","../src/error/validation_error.ts","../src/error/parsing_error.ts","../src/util/extend.ts","../src/expression/parsing_error.ts","../src/expression/scope.ts","../src/expression/types.ts","../src/expression/types/color_spaces.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/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","../node_modules/quickselect/index.js","../src/util/classify_rings.ts","../src/util/cheap_ruler.ts","../src/expression/definitions/distance.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/feature_filter/index.ts","../src/feature_filter/convert.ts","../src/function/convert.ts","../src/visit.ts","../src/group_by_layout.ts","../src/empty.ts","../src/validate/validate_constants.ts","../src/util/unbundle_jsonlint.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/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_variable_anchor_offset_collection.ts","../src/validate/validate_sprite.ts","../src/validate/validate_projection.ts","../src/validate/validate_projectiondefinition.ts","../src/validate/validate.ts","../src/validate/validate_glyphs_url.ts","../src/validate_style.min.ts","../node_modules/json-stringify-pretty-compact/index.js","../src/format.ts","../src/migrate/v8.ts","../src/migrate/expressions.ts","../src/migrate/migrate_colors.ts","../src/migrate.ts","../src/index.ts"],"sourcesContent":["\nexport const refProperties = ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'];\n","\nimport {refProperties} from './util/ref_properties';\n\nfunction deref(layer, parent) {\n const result = {};\n\n for (const k in layer) {\n if (k !== 'ref') {\n result[k] = layer[k];\n }\n }\n\n refProperties.forEach((k) => {\n if (k in parent) {\n result[k] = parent[k];\n }\n });\n\n return result;\n}\n\n/**\n * Given an array of layers, some of which may contain `ref` properties\n * whose value is the `id` of another property, return a new array where\n * such layers have been augmented with the 'type', 'source', etc. properties\n * from the parent layer, and the `ref` property has been removed.\n *\n * The input is not modified. The output may contain references to portions\n * of the input.\n *\n * @private\n * @param {Array<Layer>} layers\n * @returns {Array<Layer>}\n */\nexport function derefLayers(layers) {\n layers = layers.slice();\n\n const map = Object.create(null);\n for (let i = 0; i < layers.length; i++) {\n map[layers[i].id] = layers[i];\n }\n\n for (let i = 0; i < layers.length; i++) {\n if ('ref' in layers[i]) {\n layers[i] = deref(layers[i], map[layers[i].ref]);\n }\n }\n\n return layers;\n}\n","/**\n * Deeply compares two object literals.\n *\n * @private\n */\n\nexport function deepEqual(a?: unknown | null, b?: unknown | null): boolean {\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!deepEqual(a[i], b[i])) return false;\n }\n return true;\n }\n if (typeof a === 'object' && a !== null && b !== null) {\n if (!(typeof b === 'object')) return false;\n const keys = Object.keys(a);\n if (keys.length !== Object.keys(b).length) return false;\n for (const key in a) {\n if (!deepEqual(a[key], b[key])) return false;\n }\n return true;\n }\n return a === b;\n}","\nimport {GeoJSONSourceSpecification, LayerSpecification, LightSpecification, ProjectionSpecification, SkySpecification, SourceSpecification, SpriteSpecification, StyleSpecification, TerrainSpecification, TransitionSpecification} from './types.g';\nimport {deepEqual} from './util/deep_equal';\n\n/**\n * Operations that can be performed by the diff.\n * Below are the operations and their arguments, the arguments should be aligned with the style methods in maplibre-gl-js.\n */\nexport type DiffOperationsMap = {\n 'setStyle': [StyleSpecification];\n 'addLayer': [LayerSpecification, string | null];\n 'removeLayer': [string];\n 'setPaintProperty': [string, string, unknown, string | null];\n 'setLayoutProperty': [string, string, unknown, string | null];\n 'setFilter': [string, unknown];\n 'addSource': [string, SourceSpecification];\n 'removeSource': [string];\n 'setGeoJSONSourceData': [string, unknown];\n 'setLayerZoomRange': [string, number, number];\n 'setLayerProperty': [string, string, unknown];\n 'setCenter': [number[]];\n 'setCenterAltitude': [number];\n 'setZoom': [number];\n 'setBearing': [number];\n 'setPitch': [number];\n 'setRoll': [number];\n 'setSprite': [SpriteSpecification];\n 'setGlyphs': [string];\n 'setTransition': [TransitionSpecification];\n 'setLight': [LightSpecification];\n 'setTerrain': [TerrainSpecification];\n 'setSky': [SkySpecification];\n 'setProjection': [ProjectionSpecification];\n}\n\nexport type DiffOperations = keyof DiffOperationsMap;\n\nexport type DiffCommand<T extends DiffOperations> = {\n command: T;\n args: DiffOperationsMap[T];\n};\n\n/**\n * The main reason for this method is to allow type check when adding a command to the array.\n * @param commands - The commands array to add to\n * @param command - The command to add\n */\nfunction addCommand<T extends DiffOperations>(commands: DiffCommand<DiffOperations>[], command: DiffCommand<T>) {\n commands.push(command);\n}\n\nfunction addSource(sourceId: string, after: {[key: string]: SourceSpecification}, commands: DiffCommand<DiffOperations>[]) {\n addCommand(commands, {command: 'addSource', args: [sourceId, after[sourceId]]});\n}\n\nfunction removeSource(sourceId: string, commands: DiffCommand<DiffOperations>[], sourcesRemoved: {[key: string]: boolean}) {\n addCommand(commands, {command: 'removeSource', args: [sourceId]});\n sourcesRemoved[sourceId] = true;\n}\n\nfunction updateSource(sourceId: string, after: {[key: string]: SourceSpecification}, commands: DiffCommand<DiffOperations>[], sourcesRemoved: {[key: string]: boolean}) {\n removeSource(sourceId, commands, sourcesRemoved);\n addSource(sourceId, after, commands);\n}\n\nfunction canUpdateGeoJSON(before: {[key: string]: SourceSpecification}, after: {[key: string]: SourceSpecification}, sourceId: string) {\n let prop;\n for (prop in before[sourceId]) {\n if (!Object.prototype.hasOwnProperty.call(before[sourceId], prop)) continue;\n if (prop !== 'data' && !deepEqual(before[sourceId][prop], after[sourceId][prop])) {\n return false;\n }\n }\n for (prop in after[sourceId]) {\n if (!Object.prototype.hasOwnProperty.call(after[sourceId], prop)) continue;\n if (prop !== 'data' && !deepEqual(before[sourceId][prop], after[sourceId][prop])) {\n return false;\n }\n }\n return true;\n}\n\nfunction diffSources(before: {[key: string]: SourceSpecification}, after: {[key: string]: SourceSpecification}, commands: DiffCommand<DiffOperations>[], sourcesRemoved: {[key: string]: boolean}) {\n before = before || {} as {[key: string]: SourceSpecification};\n after = after || {} as {[key: string]: SourceSpecification};\n\n let sourceId: string;\n\n // look for sources to remove\n for (sourceId in before) {\n if (!Object.prototype.hasOwnProperty.call(before, sourceId)) continue;\n if (!Object.prototype.hasOwnProperty.call(after, sourceId)) {\n removeSource(sourceId, commands, sourcesRemoved);\n }\n }\n\n // look for sources to add/update\n for (sourceId in after) {\n if (!Object.prototype.hasOwnProperty.call(after, sourceId)) continue;\n if (!Object.prototype.hasOwnProperty.call(before, sourceId)) {\n addSource(sourceId, after, commands);\n } else if (!deepEqual(before[sourceId], after[sourceId])) {\n if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson' && canUpdateGeoJSON(before, after, sourceId)) {\n addCommand(commands, {command: 'setGeoJSONSourceData', args: [sourceId, (after[sourceId] as GeoJSONSourceSpecification).data]});\n } else {\n // no update command, must remove then add\n updateSource(sourceId, after, commands, sourcesRemoved);\n }\n }\n }\n}\n\nfunction diffLayerPropertyChanges(before: LayerSpecification['layout'] | LayerSpecification['paint'], after:LayerSpecification['layout'] | LayerSpecification['paint'], commands: DiffCommand<DiffOperations>[], layerId: string, klass: string | null, command: 'setPaintProperty' | 'setLayoutProperty') {\n before = before || {} as LayerSpecification['layout'] | LayerSpecification['paint'];\n after = after || {} as LayerSpecification['layout'] | LayerSpecification['paint'];\n\n for (const prop in before) {\n if (!Object.prototype.hasOwnProperty.call(before, prop)) continue;\n if (!deepEqual(before[prop], after[prop])) {\n commands.push({command, args: [layerId, prop, after[prop], klass]});\n }\n }\n for (const prop in after) {\n if (!Object.prototype.hasOwnProperty.call(after, prop) || Object.prototype.hasOwnProperty.call(before, prop)) continue;\n if (!deepEqual(before[prop], after[prop])) {\n commands.push({command, args: [layerId, prop, after[prop], klass]});\n }\n }\n}\n\nfunction pluckId(layer: LayerSpecification) {\n return layer.id;\n}\nfunction indexById(group: {[key: string]: LayerSpecification}, layer: LayerSpecification) {\n group[layer.id] = layer;\n return group;\n}\n\nfunction diffLayers(before: LayerSpecification[], after: LayerSpecification[], commands: DiffCommand<DiffOperations>[]) {\n before = before || [];\n after = after || [];\n\n // order of layers by id\n const beforeOrder = before.map(pluckId);\n const afterOrder = after.map(pluckId);\n\n // index of layer by id\n const beforeIndex = before.reduce(indexById, {});\n const afterIndex = after.reduce(indexById, {});\n\n // track order of layers as if they have been mutated\n const tracker = beforeOrder.slice();\n\n // layers that have been added do not need to be diffed\n const clean = Object.create(null);\n\n let layerId: string;\n let beforeLayer: LayerSpecification & { source?: string; filter?: unknown};\n let afterLayer: LayerSpecification & { source?: string; filter?: unknown};\n let insertBeforeLayerId: string;\n let prop: string;\n\n // remove layers\n for (let i = 0, d = 0; i < beforeOrder.length; i++) {\n layerId = beforeOrder[i];\n if (!Object.prototype.hasOwnProperty.call(afterIndex, layerId)) {\n addCommand(commands, {command: 'removeLayer', args: [layerId]});\n tracker.splice(tracker.indexOf(layerId, d), 1);\n } else {\n // limit where in tracker we need to look for a match\n d++;\n }\n }\n\n // add/reorder layers\n for (let i = 0, d = 0; i < afterOrder.length; i++) {\n // work backwards as insert is before an existing layer\n layerId = afterOrder[afterOrder.length - 1 - i];\n\n if (tracker[tracker.length - 1 - i] === layerId) continue;\n\n if (Object.prototype.hasOwnProperty.call(beforeIndex, layerId)) {\n // remove the layer before we insert at the correct position\n addCommand(commands, {command: 'removeLayer', args: [layerId]});\n tracker.splice(tracker.lastIndexOf(layerId, tracker.length - d), 1);\n } else {\n // limit where in tracker we need to look for a match\n d++;\n }\n\n // add layer at correct position\n insertBeforeLayerId = tracker[tracker.length - i];\n addCommand(commands, {command: 'addLayer', args: [afterIndex[layerId], insertBeforeLayerId]});\n tracker.splice(tracker.length - i, 0, layerId);\n clean[layerId] = true;\n }\n\n // update layers\n for (let i = 0; i < afterOrder.length; i++) {\n layerId = afterOrder[i];\n beforeLayer = beforeIndex[layerId];\n afterLayer = afterIndex[layerId];\n\n // no need to update if previously added (new or moved)\n if (clean[layerId] || deepEqual(beforeLayer, afterLayer)) continue;\n\n // If source, source-layer, or type have changes, then remove the layer\n // and add it back 'from scratch'.\n if (!deepEqual(beforeLayer.source, afterLayer.source) || !deepEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !deepEqual(beforeLayer.type, afterLayer.type)) {\n addCommand(commands, {command: 'removeLayer', args: [layerId]});\n // we add the layer back at the same position it was already in, so\n // there's no need to update the `tracker`\n insertBeforeLayerId = tracker[tracker.lastIndexOf(layerId) + 1];\n addCommand(commands, {command: 'addLayer', args: [afterLayer, insertBeforeLayerId]});\n continue;\n }\n\n // layout, paint, filter, minzoom, maxzoom\n diffLayerPropertyChanges(beforeLayer.layout, afterLayer.layout, commands, layerId, null, 'setLayoutProperty');\n diffLayerPropertyChanges(beforeLayer.paint, afterLayer.paint, commands, layerId, null, 'setPaintProperty');\n if (!deepEqual(beforeLayer.filter, afterLayer.filter)) {\n addCommand(commands, {command: 'setFilter', args: [layerId, afterLayer.filter]});\n }\n if (!deepEqual(beforeLayer.minzoom, afterLayer.minzoom) || !deepEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) {\n addCommand(commands, {command: 'setLayerZoomRange', args: [layerId, afterLayer.minzoom, afterLayer.maxzoom]});\n }\n\n // handle all other layer props, including paint.*\n for (prop in beforeLayer) {\n if (!Object.prototype.hasOwnProperty.call(beforeLayer, prop)) continue;\n if (prop === 'layout' || prop === 'paint' || prop === 'filter' ||\n prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') continue;\n if (prop.indexOf('paint.') === 0) {\n diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), 'setPaintProperty');\n } else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) {\n addCommand(commands, {command: 'setLayerProperty', args: [layerId, prop, afterLayer[prop]]});\n }\n }\n for (prop in afterLayer) {\n if (!Object.prototype.hasOwnProperty.call(afterLayer, prop) || Object.prototype.hasOwnProperty.call(beforeLayer, prop)) continue;\n if (prop === 'layout' || prop === 'paint' || prop === 'filter' ||\n prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') continue;\n if (prop.indexOf('paint.') === 0) {\n diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), 'setPaintProperty');\n } else if (!deepEqual(beforeLayer[prop], afterLayer[prop])) {\n addCommand(commands, {command: 'setLayerProperty', args: [layerId, prop, afterLayer[prop]]});\n }\n }\n }\n}\n\n/**\n * Diff two stylesheet\n *\n * Creates semanticly aware diffs that can easily be applied at runtime.\n * Operations produced by the diff closely resemble the maplibre-gl-js API. Any\n * error creating the diff will fall back to the 'setStyle' operation.\n *\n * Example diff:\n * [\n * { command: 'setConstant', args: ['@water', '#0000FF'] },\n * { command: 'setPaintProperty', args: ['background', 'background-color', 'black'] }\n * ]\n *\n * @private\n * @param {*} [before] stylesheet to compare from\n * @param {*} after stylesheet to compare to\n * @returns Array list of changes\n */\nexport function diff(before: StyleSpecification, after: StyleSpecification): DiffCommand<DiffOperations>[] {\n if (!before) return [{command: 'setStyle', args: [after]}];\n\n let commands: DiffCommand<DiffOperations>[] = [];\n\n try {\n // Handle changes to top-level properties\n if (!deepEqual(before.version, after.version)) {\n return [{command: 'setStyle', args: [after]}];\n }\n if (!deepEqual(before.center, after.center)) {\n commands.push({command: 'setCenter', args: [after.center]});\n }\n if (!deepEqual(before.centerAltitude, after.centerAltitude)) {\n commands.push({command: 'setCenterAltitude', args: [after.centerAltitude]});\n }\n if (!deepEqual(before.zoom, after.zoom)) {\n commands.push({command: 'setZoom', args: [after.zoom]});\n }\n if (!deepEqual(before.bearing, after.bearing)) {\n commands.push({command: 'setBearing', args: [after.bearing]});\n }\n if (!deepEqual(before.pitch, after.pitch)) {\n commands.push({command: 'setPitch', args: [after.pitch]});\n }\n if (!deepEqual(before.roll, after.roll)) {\n commands.push({command: 'setRoll', args: [after.roll]});\n }\n if (!deepEqual(before.sprite, after.sprite)) {\n commands.push({command: 'setSprite', args: [after.sprite]});\n }\n if (!deepEqual(before.glyphs, after.glyphs)) {\n commands.push({command: 'setGlyphs', args: [after.glyphs]});\n }\n if (!deepEqual(before.transition, after.transition)) {\n commands.push({command: 'setTransition', args: [after.transition]});\n }\n if (!deepEqual(before.light, after.light)) {\n commands.push({command: 'setLight', args: [after.light]});\n }\n if (!deepEqual(before.terrain, after.terrain)) {\n commands.push({command: 'setTerrain', args: [after.terrain]});\n }\n if (!deepEqual(before.sky, after.sky)) {\n commands.push({command: 'setSky', args: [after.sky]});\n }\n if (!deepEqual(before.projection, after.projection)) {\n commands.push({command: 'setProjection', args: [after.projection]});\n }\n\n // Handle changes to `sources`\n // If a source is to be removed, we also--before the removeSource\n // command--need to remove all the style layers that depend on it.\n const sourcesRemoved = {};\n\n // First collect the {add,remove}Source commands\n const removeOrAddSourceCommands = [];\n diffSources(before.sources, after.sources, removeOrAddSourceCommands, sourcesRemoved);\n\n // Push a removeLayer command for each style layer that depends on a\n // source that's being removed.\n // Also, exclude any such layers them from the input to `diffLayers`\n // below, so that diffLayers produces the appropriate `addLayers`\n // command\n const beforeLayers = [];\n if (before.layers) {\n before.layers.forEach((layer) => {\n if ('source' in layer && sourcesRemoved[layer.source]) {\n commands.push({command: 'removeLayer', args: [layer.id]});\n } else {\n beforeLayers.push(layer);\n }\n });\n }\n commands = commands.concat(removeOrAddSourceCommands);\n\n // Handle changes to `layers`\n diffLayers(beforeLayers, after.layers, commands);\n\n } catch (e) {\n // fall back to setStyle\n console.warn('Unable to compute style diff:', e);\n commands = [{command: 'setStyle', args: [after]}];\n }\n\n return commands;\n}\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","// Note: Do not inherit from Error. It breaks when transpiling to ES5.\n\nexport class ParsingError {\n message: string;\n error: Error;\n line: number;\n\n constructor(error: Error) {\n this.error = error;\n this.message = error.message;\n const match = error.message.match(/line (\\d+)/);\n this.line = match ? parseInt(match[1], 10) : 0;\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","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 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 | 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 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 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","import {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 = 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