{"version":3,"file":"visit.mjs","names":["Reference"],"sources":["../src/visit.ts"],"sourcesContent":["import Reference from './reference/v8.json' with {type: 'json'};\nimport type {StylePropertySpecification} from '.';\nimport type {\n StyleSpecification,\n SourceSpecification,\n LayerSpecification,\n PropertyValueSpecification,\n DataDrivenPropertyValueSpecification\n} from './types.g';\n\nfunction getPropertyReference(propertyName: string): StylePropertySpecification | null {\n for (let i = 0; i < Reference.layout.length; i++) {\n for (const key in Reference[Reference.layout[i]]) {\n if (key === propertyName) return Reference[Reference.layout[i]][key];\n }\n }\n for (let i = 0; i < Reference.paint.length; i++) {\n for (const key in Reference[Reference.paint[i]]) {\n if (key === propertyName) return Reference[Reference.paint[i]][key];\n }\n }\n\n return null;\n}\n\nexport function eachSource(style: StyleSpecification, callback: (_: SourceSpecification) => void) {\n for (const k in style.sources) {\n callback(style.sources[k]);\n }\n}\n\nexport function eachLayer(style: StyleSpecification, callback: (_: LayerSpecification) => void) {\n for (const layer of style.layers) {\n callback(layer);\n }\n}\n\ntype PropertyCallback = (a: {\n path: [string, 'paint' | 'layout', string]; // [layerid, paint/layout, property key],\n key: string;\n value: PropertyValueSpecification | DataDrivenPropertyValueSpecification;\n reference: StylePropertySpecification | null;\n set: (\n a: PropertyValueSpecification | DataDrivenPropertyValueSpecification\n ) => void;\n}) => void;\n\nexport function eachProperty(\n style: StyleSpecification,\n options: {\n paint?: boolean;\n layout?: boolean;\n },\n callback: PropertyCallback\n) {\n function inner(layer: LayerSpecification, propertyType: 'paint' | 'layout') {\n const properties = layer[propertyType];\n if (!properties) return;\n Object.keys(properties).forEach((key) => {\n callback({\n path: [layer.id, propertyType, key],\n key,\n value: properties[key],\n reference: getPropertyReference(key),\n set(x) {\n properties[key] = x;\n }\n });\n });\n }\n\n eachLayer(style, (layer) => {\n if (options.paint) {\n inner(layer, 'paint');\n }\n if (options.layout) {\n inner(layer, 'layout');\n }\n });\n}\n"],"mappings":";;AAUA,SAAS,qBAAqB,cAAyD;CACnF,KAAK,IAAI,IAAI,GAAG,IAAIA,WAAU,OAAO,QAAQ,KACzC,KAAK,MAAM,OAAOA,WAAUA,WAAU,OAAO,KACzC,IAAI,QAAQ,cAAc,OAAOA,WAAUA,WAAU,OAAO,GAAG,CAAC;CAGxE,KAAK,IAAI,IAAI,GAAG,IAAIA,WAAU,MAAM,QAAQ,KACxC,KAAK,MAAM,OAAOA,WAAUA,WAAU,MAAM,KACxC,IAAI,QAAQ,cAAc,OAAOA,WAAUA,WAAU,MAAM,GAAG,CAAC;CAIvE,OAAO;AACX;AAEA,SAAgB,WAAW,OAA2B,UAA4C;CAC9F,KAAK,MAAM,KAAK,MAAM,SAClB,SAAS,MAAM,QAAQ,EAAE;AAEjC;AAEA,SAAgB,UAAU,OAA2B,UAA2C;CAC5F,KAAK,MAAM,SAAS,MAAM,QACtB,SAAS,KAAK;AAEtB;AAYA,SAAgB,aACZ,OACA,SAIA,UACF;CACE,SAAS,MAAM,OAA2B,cAAkC;EACxE,MAAM,aAAa,MAAM;EACzB,IAAI,CAAC,YAAY;EACjB,OAAO,KAAK,UAAU,CAAC,CAAC,SAAS,QAAQ;GACrC,SAAS;IACL,MAAM;KAAC,MAAM;KAAI;KAAc;IAAG;IAClC;IACA,OAAO,WAAW;IAClB,WAAW,qBAAqB,GAAG;IACnC,IAAI,GAAG;KACH,WAAW,OAAO;IACtB;GACJ,CAAC;EACL,CAAC;CACL;CAEA,UAAU,QAAQ,UAAU;EACxB,IAAI,QAAQ,OACR,MAAM,OAAO,OAAO;EAExB,IAAI,QAAQ,QACR,MAAM,OAAO,QAAQ;CAE7B,CAAC;AACL"}