{"version":3,"file":"values.mjs","names":[],"sources":["../../src/expression/values.ts"],"sourcesContent":["import {Color} from './types/color';\nimport {Collator} from './types/collator';\nimport {Formatted} from './types/formatted';\nimport {Padding} from './types/padding';\nimport {NumberArray} from './types/number_array';\nimport {ColorArray} from './types/color_array';\nimport {VariableAnchorOffsetCollection} from './types/variable_anchor_offset_collection';\nimport {ResolvedImage} from './types/resolved_image';\nimport {ProjectionDefinition} from './types/projection_definition';\nimport {\n NullType,\n NumberType,\n StringType,\n BooleanType,\n ColorType,\n ObjectType,\n ValueType,\n CollatorType,\n FormattedType,\n ResolvedImageType,\n array,\n PaddingType,\n NumberArrayType,\n ColorArrayType,\n VariableAnchorOffsetCollectionType,\n ProjectionDefinitionType\n} from './types';\n\nimport type {Type} from './types';\n\nexport function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): string | null {\n if (\n !(\n typeof r === 'number' &&\n r >= 0 &&\n r <= 255 &&\n typeof g === 'number' &&\n g >= 0 &&\n g <= 255 &&\n typeof b === 'number' &&\n b >= 0 &&\n b <= 255\n )\n ) {\n const value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];\n return `Invalid rgba value [${value.join(', ')}]: 'r', 'g', and 'b' must be between 0 and 255.`;\n }\n\n if (!(typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1))) {\n return `Invalid rgba value [${[r, g, b, a].join(', ')}]: 'a' must be between 0 and 1.`;\n }\n\n return null;\n}\n\nexport type Value =\n | null\n | string\n | boolean\n | number\n | Color\n | ProjectionDefinition\n | Collator\n | Formatted\n | Padding\n | NumberArray\n | ColorArray\n | ResolvedImage\n | VariableAnchorOffsetCollection\n | ReadonlyArray\n | {\n readonly [x: string]: Value;\n };\n\nexport function isValue(mixed: unknown): boolean {\n if (\n mixed === null ||\n typeof mixed === 'string' ||\n typeof mixed === 'boolean' ||\n typeof mixed === 'number' ||\n mixed instanceof ProjectionDefinition ||\n mixed instanceof Color ||\n mixed instanceof Collator ||\n mixed instanceof Formatted ||\n mixed instanceof Padding ||\n mixed instanceof NumberArray ||\n mixed instanceof ColorArray ||\n mixed instanceof VariableAnchorOffsetCollection ||\n mixed instanceof ResolvedImage\n ) {\n return true;\n } else if (Array.isArray(mixed)) {\n for (const item of mixed) {\n if (!isValue(item)) {\n return false;\n }\n }\n return true;\n } else if (typeof mixed === 'object') {\n for (const key in mixed) {\n if (!isValue(mixed[key])) {\n return false;\n }\n }\n return true;\n } else {\n return false;\n }\n}\n\nexport function typeOf(value: Value): Type {\n if (value === null) {\n return NullType;\n } else if (typeof value === 'string') {\n return StringType;\n } else if (typeof value === 'boolean') {\n return BooleanType;\n } else if (typeof value === 'number') {\n return NumberType;\n } else if (value instanceof Color) {\n return ColorType;\n } else if (value instanceof ProjectionDefinition) {\n return ProjectionDefinitionType;\n } else if (value instanceof Collator) {\n return CollatorType;\n } else if (value instanceof Formatted) {\n return FormattedType;\n } else if (value instanceof Padding) {\n return PaddingType;\n } else if (value instanceof NumberArray) {\n return NumberArrayType;\n } else if (value instanceof ColorArray) {\n return ColorArrayType;\n } else if (value instanceof VariableAnchorOffsetCollection) {\n return VariableAnchorOffsetCollectionType;\n } else if (value instanceof ResolvedImage) {\n return ResolvedImageType;\n } else if (Array.isArray(value)) {\n const length = value.length;\n let itemType: Type | typeof undefined;\n\n for (const item of value) {\n const t = typeOf(item);\n if (!itemType) {\n itemType = t;\n } else if (itemType === t) {\n continue;\n } else {\n itemType = ValueType;\n break;\n }\n }\n\n return array(itemType || ValueType, length);\n } else {\n return ObjectType;\n }\n}\n\nexport function valueToString(value: Value) {\n const type = typeof value;\n if (value === null) {\n return '';\n } else if (type === 'string' || type === 'number' || type === 'boolean') {\n return String(value);\n } else if (\n value instanceof Color ||\n value instanceof ProjectionDefinition ||\n value instanceof Formatted ||\n value instanceof Padding ||\n value instanceof NumberArray ||\n value instanceof ColorArray ||\n value instanceof VariableAnchorOffsetCollection ||\n value instanceof ResolvedImage\n ) {\n return value.toString();\n } else {\n return JSON.stringify(value);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