{"version":3,"file":"index.mjs","names":[],"sources":["../../src/expression/index.ts"],"sourcesContent":["import {ExpressionParsingError} from './parsing_error';\nimport {ParsingContext} from './parsing_context';\nimport {EvaluationContext} from './evaluation_context';\nimport {\n    CompoundExpression,\n    isFeatureConstant,\n    isGlobalPropertyConstant,\n    isStateConstant,\n    isExpressionConstant\n} from './compound_expression';\nimport {Step} from './definitions/step';\nimport {Interpolate} from './definitions/interpolate';\nimport {Coalesce} from './definitions/coalesce';\nimport {Let} from './definitions/let';\nimport {expressions} from './definitions';\nimport {Color} from './types/color';\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 {ProjectionDefinition} from './types/projection_definition';\nimport {GlobalState} from './definitions/global_state';\nimport {RuntimeError} from './runtime_error';\nimport {success, error} from '../util/result';\nimport {\n    supportsPropertyExpression,\n    supportsZoomExpression,\n    supportsInterpolation\n} from '../util/properties';\nimport {\n    ColorType,\n    StringType,\n    NumberType,\n    BooleanType,\n    ValueType,\n    FormattedType,\n    PaddingType,\n    ResolvedImageType,\n    VariableAnchorOffsetCollectionType,\n    array,\n    type Type,\n    type EvaluationKind,\n    ProjectionDefinitionType,\n    NumberArrayType,\n    ColorArrayType\n} from './types';\nimport {ICanonicalTileID} from '../tiles_and_coordinates';\nimport {isFunction, createFunction} from '../function';\n\nimport type {Value} from './values';\nimport type {Expression} from './expression';\nimport type {StylePropertySpecification} from '..';\nimport type {Result} from '../util/result';\nimport type {InterpolationType} from './definitions/interpolate';\nimport type {FormattedSection} from './types/formatted';\nimport type {Point2D} from '../point2d';\nimport type {StyleFunction} from '../function';\nimport type {\n    PaddingSpecification,\n    NumberArraySpecification,\n    ColorArraySpecification,\n    PropertyValueSpecification,\n    VariableAnchorOffsetCollectionSpecification\n} from '../types.g';\n\nexport type Feature = {\n    readonly type:\n        | 0\n        | 1\n        | 2\n        | 3\n        | 'Unknown'\n        | 'Point'\n        | 'MultiPoint'\n        | 'LineString'\n        | 'MultiLineString'\n        | 'Polygon'\n        | 'MultiPolygon';\n    readonly id?: any;\n    readonly properties: {[_: string]: any};\n    readonly patterns?: {\n        [_: string]: {\n            min: string;\n            mid: string;\n            max: string;\n        };\n    };\n    readonly dashes?: {\n        [_: string]: {\n            min: string;\n            mid: string;\n            max: string;\n        };\n    };\n    readonly geometry?: Array<Array<Point2D>>;\n};\n\nexport type FeatureState = {[_: string]: any};\n\nexport type GlobalProperties = Readonly<{\n    zoom: number;\n    heatmapDensity?: number;\n    elevation?: number;\n    lineProgress?: number;\n    isSupportedScript?: (_: string) => boolean;\n    accumulated?: Value;\n    globalState?: Record<string, any>;\n}>;\n\nexport class StyleExpression {\n    expression: Expression;\n\n    _evaluator: EvaluationContext;\n    _defaultValue: Value;\n    _warningHistory: {[key: string]: boolean};\n    _enumValues: {[_: string]: any};\n    readonly _globalState: Record<string, any>;\n    readonly _rootKey: string;\n\n    constructor(\n        expression: Expression,\n        rootKey: string,\n        propertySpec?: StylePropertySpecification | null,\n        globalState?: Record<string, any>\n    ) {\n        this.expression = expression;\n        this._warningHistory = {};\n        this._evaluator = new EvaluationContext();\n        this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;\n        this._enumValues =\n            propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;\n        this._globalState = globalState;\n        this._rootKey = rootKey;\n    }\n\n    evaluateWithoutErrorHandling(\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ): any {\n        if (this._globalState) {\n            globals = addGlobalState(globals, this._globalState);\n        }\n        this._evaluator.globals = globals;\n        this._evaluator.feature = feature;\n        this._evaluator.featureState = featureState;\n        this._evaluator.canonical = canonical;\n        this._evaluator.availableImages = availableImages || null;\n        this._evaluator.formattedSection = formattedSection;\n\n        return this.expression.evaluate(this._evaluator);\n    }\n\n    evaluate(\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ): any {\n        if (this._globalState) {\n            globals = addGlobalState(globals, this._globalState);\n        }\n        this._evaluator.globals = globals;\n        this._evaluator.feature = feature || null;\n        this._evaluator.featureState = featureState || null;\n        this._evaluator.canonical = canonical;\n        this._evaluator.availableImages = availableImages || null;\n        this._evaluator.formattedSection = formattedSection || null;\n\n        try {\n            const val = this.expression.evaluate(this._evaluator);\n            if (val === null || val === undefined || (typeof val === 'number' && val !== val)) {\n                return this._defaultValue;\n            }\n            if (this._enumValues && !(val in this._enumValues)) {\n                throw new RuntimeError(\n                    `Expected value to be one of ${Object.keys(this._enumValues)\n                        .map((v) => JSON.stringify(v))\n                        .join(', ')}, but found ${JSON.stringify(val)} instead.`,\n                    ''\n                );\n            }\n            return val;\n        } catch (e) {\n            // A non-RuntimeError throw has no location, so treat it as the root ('').\n            const path = e instanceof RuntimeError ? e.path : '';\n            const dedupKey = `${path}|${e.message}`;\n            if (!this._warningHistory[dedupKey]) {\n                this._warningHistory[dedupKey] = true;\n                if (typeof console !== 'undefined') {\n                    console.warn(\n                        formatRuntimeWarning(this._rootKey, path, e.message, this._defaultValue)\n                    );\n                }\n            }\n            return this._defaultValue;\n        }\n    }\n}\n\n/**\n * Builds the warning logged when an expression or legacy function fails at\n * evaluation: a `rootKey + index path` location prefix, plus the fallback\n * value being used.\n * @param rootKey Caller-supplied location of the expression in the style JSON\n * @param path Index path of the throwing sub-expression ('' for the root)\n * @param message The error message from the failed evaluation\n * @param defaultValue The value being fallen back to\n * @returns The formatted warning string\n */\nfunction formatRuntimeWarning(\n    rootKey: string,\n    path: string,\n    message: string,\n    defaultValue: Value\n): string {\n    const fallback = defaultValue == null ? '' : ` Falling back to ${String(defaultValue)}.`;\n    return `${rootKey}${path}: ${message}${fallback}`;\n}\n\n/**\n * Rejects a missing or empty root key. The location prefix is what makes\n * runtime warnings actionable, so callers must always supply one; failing\n * here surfaces the programmer error at style load instead of producing\n * unattributable warnings at render time.\n * @param rootKey The root key to check\n */\nfunction assertRootKey(rootKey: string): void {\n    if (!rootKey) {\n        throw new Error(\n            'rootKey must identify the location of the expression in the style JSON, e.g. \"layers[3].paint.line-width\".'\n        );\n    }\n}\n\nexport function isExpression(expression: unknown) {\n    return (\n        Array.isArray(expression) &&\n        expression.length > 0 &&\n        typeof expression[0] === 'string' &&\n        expression[0] in expressions\n    );\n}\n\n/**\n * Parse and typecheck the given style spec JSON expression.  If\n * options.defaultValue is provided, then the resulting StyleExpression's\n * `evaluate()` method will handle errors by logging a warning (once per\n * message) and returning the default value.  Otherwise, it will throw\n * evaluation errors.\n *\n * @private\n */\nexport function createExpression(\n    expression: unknown,\n    rootKey: string,\n    propertySpec?: StylePropertySpecification | null,\n    globalState?: Record<string, any>\n): Result<StyleExpression, Array<ExpressionParsingError>> {\n    assertRootKey(rootKey);\n    const parser = new ParsingContext(\n        expressions,\n        isExpressionConstant,\n        [],\n        propertySpec ? getExpectedType(propertySpec) : undefined\n    );\n\n    // For string-valued properties, coerce to string at the top level rather than asserting.\n    const parsed = parser.parse(\n        expression,\n        undefined,\n        undefined,\n        undefined,\n        propertySpec && propertySpec.type === 'string' ? {typeAnnotation: 'coerce'} : undefined\n    );\n\n    if (!parsed) {\n        return error(parser.errors);\n    }\n\n    return success(new StyleExpression(parsed, rootKey, propertySpec, globalState));\n}\n\nexport class ZoomConstantExpression<Kind extends EvaluationKind> {\n    kind: Kind;\n    isStateDependent: boolean;\n    globalStateRefs: Set<string>;\n    _styleExpression: StyleExpression;\n    readonly _globalState: Record<string, any>;\n\n    constructor(kind: Kind, expression: StyleExpression, globalState?: Record<string, any>) {\n        this.kind = kind;\n        this._styleExpression = expression;\n        this.isStateDependent =\n            kind !== ('constant' as EvaluationKind) && !isStateConstant(expression.expression);\n        this.globalStateRefs = findGlobalStateRefs(expression.expression);\n        this._globalState = globalState;\n    }\n\n    evaluateWithoutErrorHandling(\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ): any {\n        if (this._globalState) {\n            globals = addGlobalState(globals, this._globalState);\n        }\n        return this._styleExpression.evaluateWithoutErrorHandling(\n            globals,\n            feature,\n            featureState,\n            canonical,\n            availableImages,\n            formattedSection\n        );\n    }\n\n    evaluate(\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ): any {\n        if (this._globalState) {\n            globals = addGlobalState(globals, this._globalState);\n        }\n        return this._styleExpression.evaluate(\n            globals,\n            feature,\n            featureState,\n            canonical,\n            availableImages,\n            formattedSection\n        );\n    }\n}\n\nexport class ZoomDependentExpression<Kind extends EvaluationKind> {\n    kind: Kind;\n    zoomStops: Array<number>;\n    isStateDependent: boolean;\n    globalStateRefs: Set<string>;\n    _styleExpression: StyleExpression;\n    interpolationType: InterpolationType;\n    readonly _globalState: Record<string, any>;\n\n    constructor(\n        kind: Kind,\n        expression: StyleExpression,\n        zoomStops: Array<number>,\n        interpolationType?: InterpolationType,\n        globalState?: Record<string, any>\n    ) {\n        this.kind = kind;\n        this.zoomStops = zoomStops;\n        this._styleExpression = expression;\n        this.isStateDependent =\n            kind !== ('camera' as EvaluationKind) && !isStateConstant(expression.expression);\n        this.globalStateRefs = findGlobalStateRefs(expression.expression);\n        this.interpolationType = interpolationType;\n        this._globalState = globalState;\n    }\n\n    evaluateWithoutErrorHandling(\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ): any {\n        if (this._globalState) {\n            globals = addGlobalState(globals, this._globalState);\n        }\n        return this._styleExpression.evaluateWithoutErrorHandling(\n            globals,\n            feature,\n            featureState,\n            canonical,\n            availableImages,\n            formattedSection\n        );\n    }\n\n    evaluate(\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ): any {\n        if (this._globalState) {\n            globals = addGlobalState(globals, this._globalState);\n        }\n        return this._styleExpression.evaluate(\n            globals,\n            feature,\n            featureState,\n            canonical,\n            availableImages,\n            formattedSection\n        );\n    }\n\n    interpolationFactor(input: number, lower: number, upper: number): number {\n        if (this.interpolationType) {\n            return Interpolate.interpolationFactor(this.interpolationType, input, lower, upper);\n        } else {\n            return 0;\n        }\n    }\n}\n\nexport function isZoomExpression(\n    expression: any\n): expression is ZoomConstantExpression<'source'> | ZoomDependentExpression<'source'> {\n    return (expression as ZoomConstantExpression<'source'>)._styleExpression !== undefined;\n}\n\nexport type ConstantExpression = {\n    kind: 'constant';\n    globalStateRefs: Set<string>;\n    readonly _globalState: Record<string, any>;\n    readonly evaluate: (\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>\n    ) => any;\n};\n\nexport type SourceExpression = {\n    kind: 'source';\n    isStateDependent: boolean;\n    globalStateRefs: Set<string>;\n    readonly _globalState: Record<string, any>;\n    readonly evaluate: (\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ) => any;\n};\n\nexport type CameraExpression = {\n    kind: 'camera';\n    globalStateRefs: Set<string>;\n    readonly _globalState: Record<string, any>;\n    readonly evaluate: (\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>\n    ) => any;\n    readonly interpolationFactor: (input: number, lower: number, upper: number) => number;\n    zoomStops: Array<number>;\n    interpolationType: InterpolationType;\n};\n\nexport type CompositeExpression = {\n    kind: 'composite';\n    isStateDependent: boolean;\n    globalStateRefs: Set<string>;\n    readonly _globalState: Record<string, any>;\n    readonly evaluate: (\n        globals: GlobalProperties,\n        feature?: Feature,\n        featureState?: FeatureState,\n        canonical?: ICanonicalTileID,\n        availableImages?: Array<string>,\n        formattedSection?: FormattedSection\n    ) => any;\n    readonly interpolationFactor: (input: number, lower: number, upper: number) => number;\n    zoomStops: Array<number>;\n    interpolationType: InterpolationType;\n};\n\nexport type StylePropertyExpression =\n    | ConstantExpression\n    | SourceExpression\n    | CameraExpression\n    | CompositeExpression;\n\nexport function createPropertyExpression(\n    expressionInput: unknown,\n    rootKey: string,\n    propertySpec: StylePropertySpecification,\n    globalState?: Record<string, any>\n): Result<StylePropertyExpression, Array<ExpressionParsingError>> {\n    const expression = createExpression(expressionInput, rootKey, propertySpec, globalState);\n    if (expression.result === 'error') {\n        return expression;\n    }\n\n    const parsed = expression.value.expression;\n\n    const isFeatureConstantResult = isFeatureConstant(parsed);\n    if (!isFeatureConstantResult && !supportsPropertyExpression(propertySpec)) {\n        return error([new ExpressionParsingError('', 'data expressions not supported')]);\n    }\n\n    const isZoomConstant = isGlobalPropertyConstant(parsed, ['zoom']);\n    if (!isZoomConstant && !supportsZoomExpression(propertySpec)) {\n        return error([new ExpressionParsingError('', 'zoom expressions not supported')]);\n    }\n\n    const zoomCurve = findZoomCurve(parsed);\n    if (!zoomCurve && !isZoomConstant) {\n        return error([\n            new ExpressionParsingError(\n                '',\n                '\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression.'\n            )\n        ]);\n    } else if (zoomCurve instanceof ExpressionParsingError) {\n        return error([zoomCurve]);\n    } else if (zoomCurve instanceof Interpolate && !supportsInterpolation(propertySpec)) {\n        return error([\n            new ExpressionParsingError(\n                '',\n                '\"interpolate\" expressions cannot be used with this property'\n            )\n        ]);\n    }\n\n    if (!zoomCurve) {\n        return success(\n            isFeatureConstantResult\n                ? (new ZoomConstantExpression(\n                      'constant',\n                      expression.value,\n                      globalState\n                  ) as ConstantExpression)\n                : (new ZoomConstantExpression(\n                      'source',\n                      expression.value,\n                      globalState\n                  ) as SourceExpression)\n        );\n    }\n\n    const interpolationType =\n        zoomCurve instanceof Interpolate ? zoomCurve.interpolation : undefined;\n\n    return success(\n        isFeatureConstantResult\n            ? (new ZoomDependentExpression(\n                  'camera',\n                  expression.value,\n                  zoomCurve.labels,\n                  interpolationType,\n                  globalState\n              ) as CameraExpression)\n            : (new ZoomDependentExpression(\n                  'composite',\n                  expression.value,\n                  zoomCurve.labels,\n                  interpolationType,\n                  globalState\n              ) as CompositeExpression)\n    );\n}\n\n// serialization wrapper for old-style stop functions normalized to the\n// expression interface\nexport class StylePropertyFunction<T> {\n    _parameters: PropertyValueSpecification<T>;\n    _specification: StylePropertySpecification;\n    readonly _rootKey: string;\n    readonly _defaultValue: Value;\n    _warningHistory: {[key: string]: boolean};\n    _innerEvaluate: (globals: GlobalProperties, feature?: Feature) => any;\n\n    kind: StyleFunction['kind'];\n    interpolationFactor: (input: number, lower: number, upper: number) => number;\n    zoomStops: Array<number>;\n    interpolationType: InterpolationType | null;\n    isStateDependent: boolean = false; // Legacy functions cannot reference feature state or global state, so these are constant.\n    globalStateRefs: Set<string> = new Set<string>();\n    readonly _globalState: Record<string, any> = null;\n\n    constructor(\n        parameters: PropertyValueSpecification<T>,\n        rootKey: string,\n        specification: StylePropertySpecification\n    ) {\n        assertRootKey(rootKey);\n        this._parameters = parameters;\n        this._specification = specification;\n        this._rootKey = rootKey;\n        this._defaultValue = getDefaultValue(specification);\n        this._warningHistory = {};\n\n        const fn = createFunction(this._parameters, this._specification);\n        this.kind = fn.kind;\n        this.interpolationFactor = fn.interpolationFactor;\n        this.zoomStops = fn.zoomStops;\n        this.interpolationType = fn.interpolationType;\n        this._innerEvaluate = fn.evaluate;\n    }\n\n    /**\n     * Evaluates the legacy function, handling a runtime throw (e.g. interpolating\n     * mismatched value types) by warning with the property location and falling\n     * back to the spec default, mirroring {@link StyleExpression.evaluate}.\n     * @param globals Global evaluation properties (e.g. zoom)\n     * @param feature The feature being evaluated, if any\n     * @returns The function result, or the spec default if evaluation throws\n     */\n    evaluate(globals: GlobalProperties, feature?: Feature): any {\n        try {\n            return this._innerEvaluate(globals, feature);\n        } catch (e) {\n            const message = e instanceof Error ? e.message : String(e);\n            // Legacy functions have no parser index path, so the location is '' (root).\n            const dedupKey = `|${message}`;\n            if (!this._warningHistory[dedupKey]) {\n                this._warningHistory[dedupKey] = true;\n                if (typeof console !== 'undefined') {\n                    console.warn(\n                        formatRuntimeWarning(this._rootKey, '', message, this._defaultValue)\n                    );\n                }\n            }\n            return this._defaultValue;\n        }\n    }\n\n    static deserialize<T>(serialized: {\n        _parameters: PropertyValueSpecification<T>;\n        _specification: StylePropertySpecification;\n        _rootKey: string;\n    }) {\n        return new StylePropertyFunction(\n            serialized._parameters,\n            serialized._rootKey,\n            serialized._specification\n        ) as StylePropertyFunction<T>;\n    }\n\n    static serialize<T>(input: StylePropertyFunction<T>) {\n        return {\n            _parameters: input._parameters,\n            _specification: input._specification,\n            _rootKey: input._rootKey\n        };\n    }\n}\n\nexport function normalizePropertyExpression<T>(\n    value: PropertyValueSpecification<T>,\n    rootKey: string,\n    specification: StylePropertySpecification,\n    globalState?: Record<string, any>\n): StylePropertyExpression {\n    if (isFunction(value)) {\n        return new StylePropertyFunction(value, rootKey, specification);\n    } else if (isExpression(value)) {\n        const expression = createPropertyExpression(value, rootKey, specification, globalState);\n        if (expression.result === 'error') {\n            // this should have been caught in validation\n            throw new Error(expression.value.map((err) => `${err.key}: ${err.message}`).join(', '));\n        }\n        return expression.value;\n    } else {\n        let constant: any = value;\n        if (specification.type === 'color' && typeof value === 'string') {\n            constant = Color.parse(value);\n        } else if (\n            specification.type === 'padding' &&\n            (typeof value === 'number' || Array.isArray(value))\n        ) {\n            constant = Padding.parse(value as PaddingSpecification);\n        } else if (\n            specification.type === 'numberArray' &&\n            (typeof value === 'number' || Array.isArray(value))\n        ) {\n            constant = NumberArray.parse(value as NumberArraySpecification);\n        } else if (\n            specification.type === 'colorArray' &&\n            (typeof value === 'string' || Array.isArray(value))\n        ) {\n            constant = ColorArray.parse(value as ColorArraySpecification);\n        } else if (\n            specification.type === 'variableAnchorOffsetCollection' &&\n            Array.isArray(value)\n        ) {\n            constant = VariableAnchorOffsetCollection.parse(\n                value as VariableAnchorOffsetCollectionSpecification\n            );\n        } else if (specification.type === 'projectionDefinition' && typeof value === 'string') {\n            constant = ProjectionDefinition.parse(value);\n        }\n        return {\n            globalStateRefs: new Set<string>(),\n            _globalState: null,\n            kind: 'constant',\n            evaluate: () => constant\n        };\n    }\n}\n\ntype ZoomCurveResult = Step | Interpolate | ExpressionParsingError | null;\n\n// Zoom-dependent expressions may only use [\"zoom\"] as the input to a top-level \"step\" or \"interpolate\"\n// expression (collectively referred to as a \"curve\"). The curve may be wrapped in one or more \"let\" or\n// \"coalesce\" expressions.\n// A `Let`'s result and a `Coalesce`'s arguments are searched twice: directly, and again through `eachChild`.\n// `seen` lets the second search reuse the first result, which keeps nested `let` and `coalesce` expressions linear.\nfunction findZoomCurve(\n    expression: Expression,\n    seen: Map<Expression, ZoomCurveResult> = new Map()\n): ZoomCurveResult {\n    if (seen.has(expression)) {\n        return seen.get(expression);\n    }\n    let result = null;\n    if (expression instanceof Let) {\n        result = findZoomCurve(expression.result, seen);\n    } else if (expression instanceof Coalesce) {\n        for (const arg of expression.args) {\n            result = findZoomCurve(arg, seen);\n            if (result) {\n                break;\n            }\n        }\n    } else if (\n        (expression instanceof Step || expression instanceof Interpolate) &&\n        expression.input instanceof CompoundExpression &&\n        expression.input.name === 'zoom'\n    ) {\n        result = expression;\n    }\n\n    if (result instanceof ExpressionParsingError) {\n        seen.set(expression, result);\n        return result;\n    }\n\n    expression.eachChild((child) => {\n        const childResult = findZoomCurve(child, seen);\n        if (childResult instanceof ExpressionParsingError) {\n            result = childResult;\n        } else if (!result && childResult) {\n            result = new ExpressionParsingError(\n                '',\n                '\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression.'\n            );\n        } else if (result && childResult && result !== childResult) {\n            result = new ExpressionParsingError(\n                '',\n                'Only one zoom-based \"step\" or \"interpolate\" subexpression may be used in an expression.'\n            );\n        }\n    });\n\n    seen.set(expression, result);\n    return result;\n}\n\nexport function findGlobalStateRefs(\n    expression: Expression,\n    results = new Set<string>()\n): Set<string> {\n    if (expression instanceof GlobalState) {\n        results.add(expression.key);\n    }\n\n    expression.eachChild((childExpression) => {\n        findGlobalStateRefs(childExpression, results);\n    });\n    return results;\n}\n\nfunction getExpectedType(spec: StylePropertySpecification): Type {\n    const types = {\n        color: ColorType,\n        string: StringType,\n        number: NumberType,\n        enum: StringType,\n        boolean: BooleanType,\n        formatted: FormattedType,\n        padding: PaddingType,\n        numberArray: NumberArrayType,\n        colorArray: ColorArrayType,\n        projectionDefinition: ProjectionDefinitionType,\n        resolvedImage: ResolvedImageType,\n        variableAnchorOffsetCollection: VariableAnchorOffsetCollectionType\n    };\n\n    if (spec.type === 'array') {\n        return array(types[spec.value] || ValueType, spec.length);\n    }\n\n    return types[spec.type];\n}\n\nfunction getDefaultValue(spec: StylePropertySpecification): Value {\n    if (spec.type === 'color' && isFunction(spec.default)) {\n        // Special case for heatmap-color: it uses the 'default:' to define a\n        // default color ramp, but createExpression expects a simple value to fall\n        // back to in case of runtime errors\n        return new Color(0, 0, 0, 0);\n    }\n    switch (spec.type) {\n        case 'color':\n            return Color.parse(spec.default) || null;\n        case 'padding':\n            return Padding.parse(spec.default) || null;\n        case 'numberArray':\n            return NumberArray.parse(spec.default) || null;\n        case 'colorArray':\n            return ColorArray.parse(spec.default) || null;\n        case 'variableAnchorOffsetCollection':\n            return VariableAnchorOffsetCollection.parse(spec.default) || null;\n        case 'projectionDefinition':\n            return ProjectionDefinition.parse(spec.default) || null;\n        default:\n            return spec.default === undefined ? null : spec.default;\n    }\n}\n\nfunction addGlobalState(\n    globals: GlobalProperties,\n    globalState: Record<string, any>\n): GlobalProperties {\n    const {zoom, heatmapDensity, elevation, lineProgress, isSupportedScript, accumulated} =\n        globals ?? {};\n    return {\n        zoom,\n        heatmapDensity,\n        elevation,\n        lineProgress,\n        isSupportedScript,\n        accumulated,\n        globalState\n    };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6GA,IAAa,kBAAb,MAA6B;CAUzB,YACI,YACA,SACA,cACA,aACF;EACE,KAAK,aAAa;EAClB,KAAK,kBAAkB,CAAC;EACxB,KAAK,aAAa,IAAI,kBAAkB;EACxC,KAAK,gBAAgB,eAAe,gBAAgB,YAAY,IAAI;EACpE,KAAK,cACD,gBAAgB,aAAa,SAAS,SAAS,aAAa,SAAS;EACzE,KAAK,eAAe;EACpB,KAAK,WAAW;CACpB;CAEA,6BACI,SACA,SACA,cACA,WACA,iBACA,kBACG;EACH,IAAI,KAAK,cACL,UAAU,eAAe,SAAS,KAAK,YAAY;EAEvD,KAAK,WAAW,UAAU;EAC1B,KAAK,WAAW,UAAU;EAC1B,KAAK,WAAW,eAAe;EAC/B,KAAK,WAAW,YAAY;EAC5B,KAAK,WAAW,kBAAkB,mBAAmB;EACrD,KAAK,WAAW,mBAAmB;EAEnC,OAAO,KAAK,WAAW,SAAS,KAAK,UAAU;CACnD;CAEA,SACI,SACA,SACA,cACA,WACA,iBACA,kBACG;EACH,IAAI,KAAK,cACL,UAAU,eAAe,SAAS,KAAK,YAAY;EAEvD,KAAK,WAAW,UAAU;EAC1B,KAAK,WAAW,UAAU,WAAW;EACrC,KAAK,WAAW,eAAe,gBAAgB;EAC/C,KAAK,WAAW,YAAY;EAC5B,KAAK,WAAW,kBAAkB,mBAAmB;EACrD,KAAK,WAAW,mBAAmB,oBAAoB;EAEvD,IAAI;GACA,MAAM,MAAM,KAAK,WAAW,SAAS,KAAK,UAAU;GACpD,IAAI,QAAQ,QAAQ,QAAQ,KAAA,KAAc,OAAO,QAAQ,YAAY,QAAQ,KACzE,OAAO,KAAK;GAEhB,IAAI,KAAK,eAAe,EAAE,OAAO,KAAK,cACl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