MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/snap.cafsinfotech.in/node_modules/mapbox-gl/src/style-spec/visit.js
// @flow

import Reference from './reference/v8.json';
import type {StylePropertySpecification} from './style-spec.js';
import type {
    StyleSpecification,
    SourceSpecification,
    LayerSpecification,
    PropertyValueSpecification,
    DataDrivenPropertyValueSpecification
} from './types.js';

function getPropertyReference(propertyName: string): StylePropertySpecification {
    for (let i = 0; i < Reference.layout.length; i++) {
        for (const key in Reference[Reference.layout[i]]) {
            if (key === propertyName) return (Reference[Reference.layout[i]][key]: any);
        }
    }
    for (let i = 0; i < Reference.paint.length; i++) {
        for (const key in Reference[Reference.paint[i]]) {
            if (key === propertyName) return (Reference[Reference.paint[i]][key]: any);
        }
    }

    return (null: any);
}

export function eachSource(style: StyleSpecification, callback: (_: SourceSpecification) => void) {
    for (const k in style.sources) {
        callback(style.sources[k]);
    }
}

export function eachLayer(style: StyleSpecification, callback: (_: LayerSpecification) => void) {
    for (const layer of style.layers) {
        callback(layer);
    }
}

type PropertyCallback = ({
    path: [string, 'paint' | 'layout', string], // [layerid, paint/layout, property key]
    key: string,
    value: PropertyValueSpecification<mixed> | DataDrivenPropertyValueSpecification<mixed>,
    reference: StylePropertySpecification,
    set: (PropertyValueSpecification<mixed> | DataDrivenPropertyValueSpecification<mixed>) => void
}) => void;

export function eachProperty(
    style: StyleSpecification,
    options: {paint?: boolean, layout?: boolean},
    callback: PropertyCallback
) {
    function inner(layer: LayerSpecification, propertyType: 'paint' | 'layout') {
        const properties = (layer[propertyType]: any);
        if (!properties) return;
        Object.keys(properties).forEach((key) => {
            callback({
                path: [layer.id, propertyType, key],
                key,
                value: properties[key],
                reference: getPropertyReference(key),
                set(x) {
                    properties[key] = x;
                }
            });
        });
    }

    eachLayer(style, (layer) => {
        if (options.paint) {
            inner(layer, 'paint');
        }
        if (options.layout) {
            inner(layer, 'layout');
        }
    });
}