@americana/diplomat 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/index.d.ts +165 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +3 -3
- package/index.js +108 -171
- package/package.json +9 -9
- package/index.d.ts +0 -85
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ All localization is subject to the availability of localized names in the map da
|
|
|
33
33
|
|
|
34
34
|
## Requirements
|
|
35
35
|
|
|
36
|
-
Diplomat is compatible with applications using MapLibre GL JS v5.
|
|
36
|
+
Diplomat is compatible with applications using MapLibre GL JS v5.22.0 and above.
|
|
37
37
|
|
|
38
38
|
The stylesheet must use the newer [expression](https://maplibre.org/maplibre-style-spec/expressions/) syntax; [legacy style functions](https://maplibre.org/maplibre-style-spec/deprecations/#function) are not supported. The stylesheet’s sources must conform to [Diplomat’s schema](#schema). Several popular vector tilesets already conform to this schema, including:
|
|
39
39
|
|
|
@@ -116,7 +116,9 @@ Diplomat can manipulate any GeoJSON or vector tile source, as long as it include
|
|
|
116
116
|
|
|
117
117
|
For compatibility with the [OpenMapTiles](https://openmaptiles.org/schema/) schema, `name_en` and `name_de` are also recognized as alternatives to `name:en` and `name:de` for English and German, respectively, but only in the `transportation_name` layer. For performance reasons, Diplomat does not look for this format by default for any other language or layer.
|
|
118
118
|
|
|
119
|
-
Each of the supported properties may be set to a list of values separated by [semicolons](https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator). For example, if a place speaks both English and French, `name` should be `English Name;French Name`. Similarly, if a landmark has three equally common names in Spanish, regardless of dialect, `name:es` should be `Nombre Uno;Nombre Dos;Nombre Tres`. In the rare case that a single name contains a semicolon, it should be escaped as a double semicolon (`;;`).
|
|
119
|
+
Each of the supported properties may be set to a list of values separated by [semicolons](https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator). For example, if a place speaks both English and French, `name` should be `English Name;French Name`. Similarly, if a landmark has three equally common names in Spanish, regardless of dialect, `name:es` should be `Nombre Uno;Nombre Dos;Nombre Tres`. The list can contain an unlimited number of values. In the rare case that a single name contains a semicolon, it should be escaped as a double semicolon (`;;`).
|
|
120
|
+
|
|
121
|
+
The original underlying data source (e.g., OpenStreetMap) may follow a different set of conventions as long as the GeoJSON or vector tile source translates it to this schema.
|
|
120
122
|
|
|
121
123
|
## API
|
|
122
124
|
|
|
@@ -172,7 +174,7 @@ Example:
|
|
|
172
174
|
map.setLayoutProperty(
|
|
173
175
|
"city-labels",
|
|
174
176
|
"text-field",
|
|
175
|
-
maplibregl.Diplomat.
|
|
177
|
+
maplibregl.Diplomat.localizedNameWithLocalGloss,
|
|
176
178
|
);
|
|
177
179
|
```
|
|
178
180
|
|
|
@@ -243,7 +245,7 @@ maplibregl.Diplomat.getLocales().includes("en");
|
|
|
243
245
|
Returns an array of the language tags related to the given language tag, sorted from most specific to least specific.
|
|
244
246
|
|
|
245
247
|
Parameters:
|
|
246
|
-
|
|
248
|
+
|
|
247
249
|
- **`tag`** (`string`): The language tag that the returned language tags are related to.
|
|
248
250
|
|
|
249
251
|
Returns a sorted array of related language tags, or an empty array if `tag` is malformed.
|
|
@@ -302,7 +304,7 @@ By default, MapLibre GL JS does not support bidirectional text. Arabic, Heb
|
|
|
302
304
|
|
|
303
305
|
Diplomat performs basic language fallbacks according to the [ICU locale fallback algorithm](https://unicode-org.github.io/icu/userguide/locale/#fallback). Additionally, it implements the [Likely Subtags](https://www.unicode.org/reports/tr35/#Likely_Subtags) algorithm of Unicode Technical Standard #35, so for example requesting either `zh` or `cmn` returns a name tagged as `zh-Hans-CN`, among other variations. However, in general, it does not fall back to a related but distinct language code, such as from `sr-Cyrl` to `ru` or from `nb` to `no`. Instead, the user can [set their preferred languages](https://www.w3.org/International/questions/qa-lang-priorities) in their browser or operating system settings.
|
|
304
306
|
|
|
305
|
-
For historical reasons, [OpenStreetMap’s coverage in many
|
|
307
|
+
For historical reasons, [OpenStreetMap’s coverage in many regions](https://wiki.openstreetmap.org/wiki/Multilingual_names) encodes multiple local names separated by human-readable punctuation. Diplomat makes no attempt to guess which punctuation is part of a name and which punctuation delimits two names.
|
|
306
308
|
|
|
307
309
|
## Acknowledgments
|
|
308
310
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/** @import { DataDrivenPropertyValueSpecification as PropertyValue, ExpressionSpecification as Expression, LayerSpecification, Var } from 'maplibre-gl' */
|
|
2
|
+
/**
|
|
3
|
+
* Returns a list of languages as a comma-delimited string from the given URL hash.
|
|
4
|
+
* @param {URL | Location} url
|
|
5
|
+
*/
|
|
6
|
+
export function getLanguageFromURL(url: URL | Location): string | null;
|
|
7
|
+
/**
|
|
8
|
+
Returns an array of the language tags related to the given language tag, sorted from most specific to least specific.
|
|
9
|
+
|
|
10
|
+
@param {string} tag - The language tag that the returned language tags are related to.
|
|
11
|
+
@returns {string[]} A sorted array of related language tags, or an empty array if `tag` is malformed.
|
|
12
|
+
*/
|
|
13
|
+
export function getRelatedLanguageTags(tag: string): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns the languages that the user prefers.
|
|
16
|
+
*/
|
|
17
|
+
export function getLocales(): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Returns a `coalesce` expression that resolves to the feature's name in a
|
|
20
|
+
* language that the user prefers.
|
|
21
|
+
*
|
|
22
|
+
* @param {string[]} locales - Locales of the name fields to include.
|
|
23
|
+
* @param {object} options
|
|
24
|
+
* @param {boolean} [options.includesLegacyFields] - Whether to include the older fields
|
|
25
|
+
* that include underscores, for layers that have not transitioned to the
|
|
26
|
+
* colon syntax.
|
|
27
|
+
* @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.
|
|
28
|
+
* @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
29
|
+
* @returns {Expression}
|
|
30
|
+
*/
|
|
31
|
+
export function getLocalizedNameExpression(locales: string[], options?: {
|
|
32
|
+
includesLegacyFields?: boolean | undefined;
|
|
33
|
+
unlocalizedNameProperty?: string | undefined;
|
|
34
|
+
localizedNamePropertyFormat?: string | undefined;
|
|
35
|
+
}): Expression;
|
|
36
|
+
/**
|
|
37
|
+
* Mutates a `let` expression to have a new value for the variable by the given name, binding the variable if it isn’t already bound to any value.
|
|
38
|
+
*
|
|
39
|
+
* @param {PropertyValue<string> | undefined} letExpr - Expression to update.
|
|
40
|
+
* @param {string} variable - Name of the variable to set.
|
|
41
|
+
* @param {*} value - The variable's new value.
|
|
42
|
+
*/
|
|
43
|
+
export function updateVariable(letExpr: PropertyValue<string> | undefined, variable: string, value: any): void;
|
|
44
|
+
/**
|
|
45
|
+
* Recursively walks an expression, returning a copy of the subexpression after replacing any reference to a specific feature property with a new value in place.
|
|
46
|
+
*
|
|
47
|
+
* @param {Expression} expression - The expression to transform.
|
|
48
|
+
* @param {string} propertyName - The name of the feature property to look for.
|
|
49
|
+
* @param {*} replacement - The replacement value.
|
|
50
|
+
* @returns {Expression | undefined} The same array as `expression` if `expression` referred to `propertyName`, or `undefined` if `expression` did not refer to `propertyName`.
|
|
51
|
+
*/
|
|
52
|
+
export function replacePropertyReferences(expression: Expression, propertyName: string, replacement: any): Expression | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Transforms a layer’s `text-field` layout property so that it can be localized by `localizeLayers` later on.
|
|
55
|
+
*
|
|
56
|
+
* The transformed `text-field` property is only modified if it contains a reference to the feature property specified by `unlocalizedNameProperty`. If the layer’s `symbol-placement` layout property is set to either `line` or `line-center`, the resulting text field takes up only one line. Otherwise, the text field for a given feature may span multiple lines if its unlocalized name property is set to a list of values.
|
|
57
|
+
*
|
|
58
|
+
* @param {LayerSpecification} layer - The style layer to prepare for localization.
|
|
59
|
+
* @param {string} [unlocalizedNameProperty] - The name of the feature property that holds the unlocalized name. References to this property are replaced by a more complex expression that can be localized dynamically.
|
|
60
|
+
* @param {boolean} [glossLocalNames] - Whether to format each label as a dual language label including a local name gloss.
|
|
61
|
+
*/
|
|
62
|
+
export function prepareLayer(layer: LayerSpecification, unlocalizedNameProperty?: string, glossLocalNames?: boolean): void;
|
|
63
|
+
/**
|
|
64
|
+
* Updates localizable variables at the top level of each layer's `text-field` expression based on the given locales.
|
|
65
|
+
*
|
|
66
|
+
* @param {LayerSpecification[]} layers - The style layers to localize.
|
|
67
|
+
* @param {string[]} locales - The locales to insert into each layer.
|
|
68
|
+
* @param {object} options
|
|
69
|
+
* @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.
|
|
70
|
+
* @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
71
|
+
*/
|
|
72
|
+
export function localizeLayers(layers: LayerSpecification[], locales?: string[], options?: {
|
|
73
|
+
unlocalizedNameProperty?: string | undefined;
|
|
74
|
+
localizedNamePropertyFormat?: string | undefined;
|
|
75
|
+
}): void;
|
|
76
|
+
/**
|
|
77
|
+
* Returns an expression interpreting the given string as a list of tag values,
|
|
78
|
+
* pretty-printing the standard semicolon delimiter with the given separator.
|
|
79
|
+
*
|
|
80
|
+
* https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator
|
|
81
|
+
*
|
|
82
|
+
* The returned expression can be complex, so use it only once within a property
|
|
83
|
+
* value. To reuse the evaluated value, bind it to a variable in a let
|
|
84
|
+
* expression.
|
|
85
|
+
*
|
|
86
|
+
* @param {Expression} valueList A semicolon-delimited list of values.
|
|
87
|
+
* @param {string | Expression} separator A string to insert between each value, or an expression that
|
|
88
|
+
* evaluates to this string.
|
|
89
|
+
* @param {string | Expression} [valueToOmit]
|
|
90
|
+
* @returns {Expression}
|
|
91
|
+
*/
|
|
92
|
+
export function listValuesExpression(valueList: Expression, separator: string | Expression, valueToOmit?: string | Expression): Expression;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a table of country names in the user’s preferred language by ISO 3166-1 alpha-3 code.
|
|
95
|
+
*
|
|
96
|
+
* @param {string[]} locales - The locales for formatting the country names.
|
|
97
|
+
* @param {object} options
|
|
98
|
+
* @param {boolean} [options.uppercase] Whether to write the country names in all uppercase, respecting the locale’s case conventions.
|
|
99
|
+
*/
|
|
100
|
+
export function getLocalizedCountryNames(locales: string[], options?: {
|
|
101
|
+
uppercase?: boolean | undefined;
|
|
102
|
+
}): {
|
|
103
|
+
[k: string]: string | undefined;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Returns the global state that Diplomat needs to fully localize the style.
|
|
107
|
+
*
|
|
108
|
+
* @param {string[]} locales - The locales for formatting the country names.
|
|
109
|
+
* @param {object} options
|
|
110
|
+
* @param {boolean} [options.uppercaseCountryNames] Whether to write country names in all uppercase, respecting the locale’s case conventions.
|
|
111
|
+
*/
|
|
112
|
+
export function getGlobalStateForLocalization(locales: string[], options?: {
|
|
113
|
+
uppercaseCountryNames?: boolean | undefined;
|
|
114
|
+
}): {};
|
|
115
|
+
/**
|
|
116
|
+
* Returns an expression that converts the given country code to a human-readable name in the user's preferred language.
|
|
117
|
+
*
|
|
118
|
+
* @param {Expression} code An expression that evaluates to an ISO 3166-1 alpha-3 country code.
|
|
119
|
+
* @returns {Expression}
|
|
120
|
+
*/
|
|
121
|
+
export function getLocalizedCountryNameExpression(code: Expression): Expression;
|
|
122
|
+
/**
|
|
123
|
+
* Updates each style layer's `text-field` value to match the given locales, upgrading any unlocalizable layer along the way.
|
|
124
|
+
*
|
|
125
|
+
* This method ugprades unlocalizable layers to localized multiline or inline labels depending on the `symbol-placement` layout property. To add a dual language label to a layer, set its `text-field` layout property manually using the `localizedNameWithLocalGloss` constant.
|
|
126
|
+
*
|
|
127
|
+
* If neither `options.layers` nor `options.sourceLayers` is specified, this function makes localizable any style layer that gets the feature property specified in `options.unlocalizedNameProperty`, or `name` by default.
|
|
128
|
+
*
|
|
129
|
+
* @param {maplibregl.Map} map - The map to localize.
|
|
130
|
+
* @param {string[]} locales - The locales to insert into each layer.
|
|
131
|
+
* @param {object} options
|
|
132
|
+
* @param {string[]} [options.layers] - The style layers with these IDs will be made localizable.
|
|
133
|
+
* @param {string[]} [options.sourceLayers] - The style layers that use these source layers will be made localizable. These are source layer IDs, not style layer IDs.
|
|
134
|
+
* @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.
|
|
135
|
+
* @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
136
|
+
* @param {boolean} [options.glossLocalNames] - Whether to format each label as a dual language label including a local name gloss.
|
|
137
|
+
* @param {boolean} [options.uppercaseCountryNames] Whether to write country names in all uppercase, respecting the locale’s case conventions.
|
|
138
|
+
*/
|
|
139
|
+
export function localizeStyle(map: maplibregl.Map, locales?: string[], options?: {
|
|
140
|
+
layers?: string[] | undefined;
|
|
141
|
+
sourceLayers?: string[] | undefined;
|
|
142
|
+
unlocalizedNameProperty?: string | undefined;
|
|
143
|
+
localizedNamePropertyFormat?: string | undefined;
|
|
144
|
+
glossLocalNames?: boolean | undefined;
|
|
145
|
+
uppercaseCountryNames?: boolean | undefined;
|
|
146
|
+
}): void;
|
|
147
|
+
/**
|
|
148
|
+
* The names in the user's preferred language, each on a separate line.
|
|
149
|
+
* @type {Expression}
|
|
150
|
+
*/
|
|
151
|
+
export const localizedName: Expression;
|
|
152
|
+
/**
|
|
153
|
+
* The names in the user's preferred language, all on the same line.
|
|
154
|
+
* @type {Expression}
|
|
155
|
+
*/
|
|
156
|
+
export const localizedNameInline: Expression;
|
|
157
|
+
/**
|
|
158
|
+
* The name in the user's preferred language, followed by the name in the local
|
|
159
|
+
* language in parentheses if it differs.
|
|
160
|
+
* @type {Expression}
|
|
161
|
+
*/
|
|
162
|
+
export const localizedNameWithLocalGloss: Expression;
|
|
163
|
+
import type { ExpressionSpecification as Expression } from 'maplibre-gl';
|
|
164
|
+
import type { DataDrivenPropertyValueSpecification as PropertyValue } from 'maplibre-gl';
|
|
165
|
+
import type { LayerSpecification } from 'maplibre-gl';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(()=>{var u="diplomat";function
|
|
2
|
-
`),
|
|
3
|
-
`),["case",["==",["var",s],["get","name"],["var",
|
|
4
|
-
`),["case",
|
|
5
|
-
`,"(\u2068",{"font-scale":.8},
|
|
1
|
+
(()=>{var u="diplomat";function B(e){let t=new URLSearchParams(e.hash.substr(1)).get("language");return t===""?null:t}function v(e){return e.reduce((t,a)=>[...t,...t.map(l=>[...l,a])],[[]])}function p(e){return e.variants??e.minimize().baseName.match(/-([-\w]+)/)?.[1]}function K(e){let t;try{t=new Intl.Locale(e)}catch{return[]}let a=t.maximize(),l=[a.script,a.region,p(a),a.numberingSystem].filter(n=>n),r=v(l).map(n=>[a.language,...n].join("-"));r.push(t+""),r.push(t.baseName);let c=r.map(n=>{try{return new Intl.Locale(n)}catch{}}).filter(n=>n),i=n=>{let M=n+"",L=0;return L+=M.length??0,L+=M.split("-").length??0,L+=p(n)?.length??0,L+=M.match(/(?:-[tx]-|-u-\w\w-)\w+/)?.[0]?.length??0,L};c.sort((n,M)=>i(M)-i(n));let o=c.map(n=>n+"");return[...new Set(o)]}function S(){let a=(B(window.location)?.split(",")??navigator.languages??[navigator.language]).flatMap(l=>K(l));return[...new Set(a)]}var g="name";function m(e,t={}){return["coalesce",...[...e.flatMap(l=>{let c=(t.localizedNamePropertyFormat||"name:$1").replaceAll("$1",l),i=[c];return t.includesLegacyFields&&(l==="de"||l==="en")&&i.push(c.replaceAll(":","_")),i}),t.unlocalizedNameProperty||g].map(l=>["get",l])]}function d(e,t,a){if(!e||e[0]!=="let")return;let l=e.indexOf(t);l%2===1?e[l+1]=a:e.splice(-1,0,t,a)}var s=`${u}__localizedName`,f=`${u}__localizedCollator`,A=`${u}__diacriticInsensitiveCollator`;function I(e,t,a){if(!Array.isArray(e)||e[0]==="literal")return;if(e[0]==="get")return e.length===2&&e[1]===t?a:void 0;let l=!1;if(e.forEach((r,c)=>{if(!c)return;let i=I(r,t,a);i!==void 0&&(e[c]=i,l=!0)}),l)return e}var E=" \u2022 ";function D(e,t,a){let l=e.layout&&e.layout["text-field"];if(!l||l[0]==="let"&&l.includes(s))return;let r=e.layout&&e.layout["symbol-placement"],o=I(l,t||g,a?U:r==="line"||r==="line-center"?V:P);o!==void 0&&(e.layout["text-field"]=["let",s,"",o])}function y(e,t,a,l){if(!("layout"in e)||!("text-field"in e.layout))return;let r=e.layout["text-field"];d(r,s,e["source-layer"]==="transportation_name"?l:a),d(r,f,["collator",{"case-sensitive":!1,"diacritic-sensitive":!0,locale:t}]),d(r,A,["collator",{"case-sensitive":!1,"diacritic-sensitive":!/^en\b/.test(t),locale:t}])}function O(e,t=S(),a={}){let l=m(t,a),r=m(t,{...a,includesLegacyFields:!0});for(let c of e)y(c,t[0],l,r)}function N(e,t,a){let c=["join",["split",["join",["split",e,";;"],"\x91\uFFFC\x92"],"; "],";"],i=`${u}__values`,o=`${u}__omissionIndex`,n=`${u}__abridgedValues`;return["let",i,["split",c,";"],["let",o,a?["index-of",a,["var",i]]:-1,["let",n,["match",["var",o],-1,["join",["var",i],t],["concat",["join",["slice",["var",i],0,["var",o]],t],["case",["any",["==",["var",o],0],["==",["var",o],["-",["length",["var",i]],1]]],"",t],["join",["slice",["var",i],["+",["var",o],1]],t]]],["join",["split",["var",n],"\x91\uFFFC\x92"],";"]]]]}var P=N(["var",s],`
|
|
2
|
+
`),h=["let",s,"",P],V=N(["var",s],E),H=["let",s,"",V];function b(e,t,a){let l=" ,";return["all",["==",["slice",e,0,["length",t]],t,a],["in",["slice",["concat",e,l[0]],["length",t],["+",["length",t],1]],l]]}function z(e,t){return["concat",t,["slice",e,["length",t]]]}function x(e,t,a){let l=" ",r=`${u}__suffixStart`;return["let",r,["-",["length",e],["length",t]],["all",["==",["slice",e,["var",r]],t,a],["==",["slice",e,["-",["var",r],1],["var",r]],l]]]}function W(e,t){return["concat",["slice",e,0,["-",["length",e],["length",t]]],t]}var R=`${u}__localizedNameList`,C=`${u}__nameList`,U=["let",R,N(["var",s],`
|
|
3
|
+
`),["case",["==",["var",s],["get","name"],["var",f]],["format",["var",R]],["let",C,N(["get","name"],`
|
|
4
|
+
`),["case",b(["var",s],["get","name"],["var",A]),["format",z(["var",s],["var",C])],x(["var",s],["get","name"],["var",A]),["format",W(["var",s],["var",C])],["format",["var",R],`
|
|
5
|
+
`,"(\u2068",{"font-scale":.8},N(["get","name"],E,["var",s]),{"font-scale":.8},"\u2069)",{"font-scale":.8}]]]]],Z=["let",s,"",f,["collator",{}],A,["collator",{}],U],_={ABW:"AW",AFG:"AF",AGO:"AO",AIA:"AI",ALB:"AL",AND:"AD",ARE:"AE",ARG:"AR",ARM:"AM",ASM:"AS",ATA:"AQ",ATF:"TF",ATG:"AG",AUS:"AU",AUT:"AT",AZE:"AZ",BDI:"BI",BEL:"BE",BEN:"BJ",BFA:"BF",BGD:"BD",BGR:"BG",BHR:"BH",BHS:"BS",BIH:"BA",BLM:"BL",BLR:"BY",BLZ:"BZ",BMU:"BM",BOL:"BO",BRA:"BR",BRB:"BB",BRN:"BN",BTN:"BT",BVT:"BV",BWA:"BW",CAF:"CF",CAN:"CA",CCK:"CC",CHE:"CH",CHL:"CL",CHN:"CN",CIV:"CI",CMR:"CM",COD:"CD",COG:"CG",COK:"CK",COL:"CO",COM:"KM",CPV:"CV",CRI:"CR",CUB:"CU",CUW:"CW",CXR:"CX",CYM:"KY",CYP:"CY",CZE:"CZ",DEU:"DE",DJI:"DJ",DMA:"DM",DNK:"DK",DOM:"DO",DZA:"DZ",ECU:"EC",EGY:"EG",ERI:"ER",ESH:"EH",ESP:"ES",EST:"EE",ETH:"ET",FIN:"FI",FJI:"FJ",FLK:"FK",FRA:"FR",FRO:"FO",FSM:"FM",FXX:"FX",GAB:"GA",GBR:"GB",GEO:"GE",GGY:"GG",GHA:"GH",GIB:"GI",GIN:"GN",GLP:"GP",GMB:"GM",GNB:"GW",GNQ:"GQ",GRC:"GR",GRD:"GD",GRL:"GL",GTM:"GT",GUF:"GF",GUM:"GU",GUY:"GY",HKG:"HK",HMD:"HM",HND:"HN",HRV:"HR",HTI:"HT",HUN:"HU",IDN:"ID",IMN:"IM",IND:"IN",IOT:"IO",IRL:"IE",IRN:"IR",IRQ:"IQ",ISL:"IS",ISR:"IL",ITA:"IT",JAM:"JM",JEY:"JE",JOR:"JO",JPN:"JP",KAZ:"KZ",KEN:"KE",KGZ:"KG",KHM:"KH",KIR:"KI",KNA:"KN",KOR:"KR",KWT:"KW",LAO:"LA",LBN:"LB",LBR:"LR",LBY:"LY",LCA:"LC",LIE:"LI",LKA:"LK",LSO:"LS",LTU:"LT",LUX:"LU",LVA:"LV",MAC:"MO",MAF:"MF",MAR:"MA",MCO:"MC",MDA:"MD",MDG:"MG",MDV:"MV",MEX:"MX",MHL:"MH",MKD:"MK",MLI:"ML",MLT:"MT",MMR:"MM",MNE:"ME",MNG:"MN",MNP:"MP",MOZ:"MZ",MRT:"MR",MSR:"MS",MTQ:"MQ",MUS:"MU",MWI:"MW",MYS:"MY",MYT:"YT",NAM:"NA",NCL:"NC",NER:"NE",NFK:"NF",NGA:"NG",NIC:"NI",NIU:"NU",NLD:"NL",NOR:"NO",NPL:"NP",NRU:"NR",NZL:"NZ",OMN:"OM",PAK:"PK",PAN:"PA",PCN:"PN",PER:"PE",PHL:"PH",PLW:"PW",PNG:"PG",POL:"PL",PRI:"PR",PRK:"KP",PRT:"PT",PRY:"PY",PSE:"PS",PYF:"PF",QAT:"QA",REU:"RE",ROU:"RO",RUS:"RU",RWA:"RW",SAU:"SA",SDN:"SD",SEN:"SN",SGP:"SG",SGS:"GS",SHN:"SH",SJM:"SJ",SLB:"SB",SLE:"SL",SLV:"SV",SMR:"SM",SOM:"SO",SPM:"PM",SRB:"RS",SSD:"SS",STP:"ST",SUR:"SR",SVK:"SK",SVN:"SI",SWE:"SE",SWZ:"SZ",SXM:"SX",SYC:"SC",SYR:"SY",TCA:"TC",TCD:"TD",TGO:"TG",THA:"TH",TJK:"TJ",TKL:"TK",TKM:"TM",TLS:"TL",TON:"TO",TTO:"TT",TUN:"TN",TUR:"TR",TUV:"TV",TWN:"TW",TZA:"TZ",UGA:"UG",UKR:"UA",UMI:"UM",URY:"UY",USA:"US",UZB:"UZ",VAT:"VA",VCT:"VC",VEN:"VE",VGB:"VG",VIR:"VI",VNM:"VN",VUT:"VU",WLF:"WF",WSM:"WS",YEM:"YE",ZAF:"ZA",ZMB:"ZM",ZWE:"ZW"},G=`${u}__countryNamesByCode`;function F(e,t={}){let a=new Intl.DisplayNames(e,{type:"region",fallback:"none"});return Object.fromEntries(Object.entries(_).map(l=>{let r=a.of(l[1]);return r&&t?.uppercase&&(r=r.toLocaleUpperCase(e).replaceAll(" "," ")),[l[0],r]}))}function Y(e,t={}){let a={};return a[G]=F(e,{uppercase:t?.uppercaseCountryNames}),a}function w(e){return["let","code",e,["coalesce",["get",["var","code"],["coalesce",["global-state",G],["literal",{}]]],["concat","(",["var","code"],")"]]]}function T(e,t=S(),a={}){let l=e.getStyle(),r=m(t,a),c=m(t,{...a,includesLegacyFields:!0});for(let o of l.layers){let n=o["source-layer"];(!a.layers&&!a.sourceLayers||a.layers?.includes(o.id)||n&&a.sourceLayers?.includes(n))&&D(o,a?.unlocalizedNameProperty,a?.glossLocalNames),y(o,t[0],r,c)}let i=F(t,{uppercase:a?.uppercaseCountryNames});e.setGlobalStateProperty(G,i),e.setStyle(l)}typeof window<"u"&&(window.Diplomat={getGlobalStateForLocalization:Y,getLanguageFromURL:B,getLocales:S,getLocalizedCountryNameExpression:w,listValuesExpression:N,localizeLayers:O,localizeStyle:T,localizedName:h,localizedNameInline:H,localizedNameWithLocalGloss:Z},"maplibregl"in window&&(maplibregl.Diplomat=window.Diplomat,maplibregl.Map.prototype.localizeStyle=function(e=S(),t={}){T(this,e,t)}));})();
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../index.js"],
|
|
4
|
-
"sourcesContent": ["/// A prefix that uniquely identifies this plugin, prepended onto the name of any variable generated by this plugin.\nconst variablePrefix = \"diplomat\";\n\n/**\n * Returns a list of languages as a comma-delimited string from the given URL hash.\n */\nexport function getLanguageFromURL(url) {\n let language = new URLSearchParams(url.hash.substr(1)).get(\"language\");\n return language === \"\" ? null : language;\n}\n\n/**\n Returns the powerset of the given array.\n */\nfunction powerset(array) {\n return array.reduce(\n (accum, value) => [...accum, ...accum.map((pick) => [...pick, value])],\n [[]],\n );\n}\n\n/**\n Compatibility shim for `Intl.Locale.prototype.variants`.\n */\nfunction getVariants(locale) {\n return locale.variants ?? locale.minimize().baseName.match(/-([-\\w]+)/)?.[1];\n}\n\n/**\n Returns an array of the language tags related to the given language tag, sorted from most specific to least specific.\n \n @param {string} tag - The language tag that the returned language tags are related to.\n @returns {[string]} A sorted array of related language tags, or an empty array if `tag` is malformed.\n */\nexport function getRelatedLanguageTags(tag) {\n let locale;\n try {\n locale = new Intl.Locale(tag);\n } catch {\n return [];\n }\n\n let maximized = locale.maximize();\n // The subtags and extensions used in OSM name:*=* subkeys.\n let quals = [\n maximized.script,\n maximized.region,\n getVariants(maximized),\n maximized.numberingSystem,\n ].filter((q) => q);\n // Get all the combinations of components and convert them to language tags.\n let tags = powerset(quals).map((quals) =>\n [maximized.language, ...quals].join(\"-\"),\n );\n\n // Add the original language tag, in case maximizing it dropped miscellaneous extensions.\n tags.push(locale + \"\");\n tags.push(locale.baseName);\n\n // Validate each of the language tags.\n let locales = tags\n .map((tag) => {\n try {\n return new Intl.Locale(tag);\n } catch {}\n })\n .filter((l) => l);\n\n // Sort the locales from most specific to least specific.\n let scoreLocale = (locale) => {\n let tag = locale + \"\";\n let score = 0;\n score += tag.length ?? 0;\n score += tag.split(\"-\").length ?? 0;\n // Prioritize variants, which are more specific than script and region.\n score += getVariants(locale)?.length ?? 0;\n // Prioritize extensions, which Intl.Locale.prototype.maximize can\u2019t maximize.\n score += tag.match(/(?:-[tx]-|-u-\\w\\w-)\\w+/)?.[0]?.length ?? 0;\n return score;\n };\n locales.sort((a, b) => scoreLocale(b) - scoreLocale(a));\n\n let validTags = locales.map((l) => l + \"\");\n return [...new Set(validTags)];\n}\n\n/**\n * Returns the languages that the user prefers.\n */\nexport function getLocales() {\n // Check the language \"parameter\" in the hash.\n let parameter = getLanguageFromURL(window.location)?.split(\",\");\n // Fall back to the user's language preference.\n let userLocales = parameter ?? navigator.languages ?? [navigator.language];\n // Get a full fallback list.\n let tags = userLocales.flatMap((l) => getRelatedLanguageTags(l));\n\n return [...new Set(tags)];\n}\n\nconst defaultUnlocalizedNameProperty = \"name\";\n\n/**\n * Returns a `coalesce` expression that resolves to the feature's name in a\n * language that the user prefers.\n *\n * @param {[string]} locales - Locales of the name fields to include.\n * @param {boolean} options.includesLegacyFields - Whether to include the older fields\n * that include underscores, for layers that have not transitioned to the\n * colon syntax.\n * @param {string} options.unlocalizedNameProperty - The name of the property holding the unlocalized name.\n * @param {string} options.localizedNamePropertyFormat - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.\n */\nexport function getLocalizedNameExpression(locales, options = {}) {\n let nameFields = [\n ...locales.flatMap((l) => {\n let localizedNamePropertyFormat =\n options.localizedNamePropertyFormat || `name:$1`;\n let localizedNameProperty = localizedNamePropertyFormat.replaceAll(\n \"$1\",\n l,\n );\n let fields = [localizedNameProperty];\n // transportation_label uses an underscore instead of a colon.\n // https://github.com/openmaptiles/openmaptiles/issues/769\n if (options.includesLegacyFields && (l === \"de\" || l === \"en\")) {\n fields.push(localizedNameProperty.replaceAll(\":\", \"_\"));\n }\n return fields;\n }),\n options.unlocalizedNameProperty || defaultUnlocalizedNameProperty,\n ];\n return [\"coalesce\", ...nameFields.map((f) => [\"get\", f])];\n}\n\n/**\n * Mutates a `let` expression to have a new value for the variable by the given name, binding the variable if it isn\u2019t already bound to any value.\n *\n * @param {array} letExpr - Expression to update.\n * @param {string} variable - Name of the variable to set.\n * @param {*} value - The variable's new value.\n */\nexport function updateVariable(letExpr, variable, value) {\n if (!letExpr || letExpr[0] !== \"let\") return;\n\n let variableNameIndex = letExpr.indexOf(variable);\n if (variableNameIndex % 2 === 1) {\n letExpr[variableNameIndex + 1] = value;\n } else {\n letExpr.splice(-1, 0, variable, value);\n }\n}\n\nconst localizedNameVariable = `${variablePrefix}__localizedName`;\nconst localizedCollatorVariable = `${variablePrefix}__localizedCollator`;\nconst diacriticInsensitiveCollatorVariable = `${variablePrefix}__diacriticInsensitiveCollator`;\n\n/**\n * Recursively walks an expression, returning a copy of the subexpression after replacing any reference to a specific feature property with a new value in place.\n *\n * @param {array} expression - The expression to transform.\n * @param {string} propertyName - The name of the feature property to look for.\n * @param {*} replacement - The replacement value.\n * @returns {array} The same array as `expression` if `expression` referred to `propertyName`, or `undefined` if `expression` did not refer to `propertyName`.\n */\nexport function replacePropertyReferences(\n expression,\n propertyName,\n replacement,\n) {\n if (!Array.isArray(expression) || expression[0] === \"literal\") return;\n if (expression[0] === \"get\") {\n if (expression.length === 2 && expression[1] === propertyName) {\n return replacement;\n }\n return;\n }\n let didReplace = false;\n expression.forEach((arg, idx) => {\n if (!idx) return; // operator can never be a property reference\n let newValue = replacePropertyReferences(arg, propertyName, replacement);\n if (newValue !== undefined) {\n expression[idx] = newValue;\n didReplace = true;\n }\n });\n if (didReplace) return expression;\n}\n\n/**\n * The separator to use in inline contexts.\n */\nconst inlineSeparator = \" \\u2022 \";\n\n/**\n * Transforms a layer\u2019s `text-field` layout property so that it can be localized by `localizeLayers` later on.\n *\n * The transformed `text-field` property is only modified if it contains a reference to the feature property specified by `unlocalizedNameProperty`. If the layer\u2019s `symbol-placement` layout property is set to either `line` or `line-center`, the resulting text field takes up only one line. Otherwise, the text field for a given feature may span multiple lines if its unlocalized name property is set to a list of values.\n *\n * @param {object} layer - The style layer to prepare for localization.\n * @param {string} unlocalizedNameProperty - The name of the feature property that holds the unlocalized name. References to this property are replaced by a more complex expression that can be localized dynamically.\n * @param {boolean} glossLocalNames - Whether to format each label as a dual language label including a local name gloss.\n */\nexport function prepareLayer(layer, unlocalizedNameProperty, glossLocalNames) {\n let textField = layer.layout && layer.layout[\"text-field\"];\n if (\n !textField ||\n (textField[0] === \"let\" && textField.includes(localizedNameVariable))\n ) {\n return;\n }\n\n let symbolPlacement = layer.layout && layer.layout[\"symbol-placement\"];\n let isInline =\n symbolPlacement === \"line\" || symbolPlacement === \"line-center\";\n let listValues = glossLocalNames\n ? localizedNameWithLocalGlossCore\n : isInline\n ? localizedNameInlineCore\n : localizedNameCore;\n let newTextField = replacePropertyReferences(\n textField,\n unlocalizedNameProperty || defaultUnlocalizedNameProperty,\n listValues,\n );\n if (newTextField !== undefined) {\n layer.layout[\"text-field\"] = [\n \"let\",\n localizedNameVariable,\n \"\",\n newTextField,\n ];\n }\n}\n\n/**\n * Updates localizable variables at the top level of the layer's `text-field` expression based on the given locales.\n *\n * @param {object} layer - The style layer to localize.\n * @param {string} collationLocale - The locale for string comparison purposes.\n * @param {array} localizedNameExpression - An expression that produces a localized name.\n * @param {array} legacyLocalizedNameExpression - An expression that produces a localized name based on legacy properties in OpenMapTiles.\n */\nfunction localizeLayer(\n layer,\n collationLocale,\n localizedNameExpression,\n legacyLocalizedNameExpression,\n) {\n if (!(\"layout\" in layer) || !(\"text-field\" in layer.layout)) return;\n\n let textField = layer.layout[\"text-field\"];\n\n updateVariable(\n textField,\n localizedNameVariable,\n // https://github.com/openmaptiles/openmaptiles/issues/769\n layer[\"source-layer\"] === \"transportation_name\"\n ? legacyLocalizedNameExpression\n : localizedNameExpression,\n );\n\n updateVariable(textField, localizedCollatorVariable, [\n \"collator\",\n {\n \"case-sensitive\": false,\n \"diacritic-sensitive\": true,\n locale: collationLocale,\n },\n ]);\n\n // Only perform diacritic folding in English. English normally uses few diacritics except when labeling foreign place names on maps.\n updateVariable(textField, diacriticInsensitiveCollatorVariable, [\n \"collator\",\n {\n \"case-sensitive\": false,\n \"diacritic-sensitive\": !/^en\\b/.test(collationLocale),\n locale: collationLocale,\n },\n ]);\n}\n\n/**\n * Updates localizable variables at the top level of each layer's `text-field` expression based on the given locales.\n *\n * @param {[object]} layers - The style layers to localize.\n * @param {[string]} locales - The locales to insert into each layer.\n * @param {string} options.unlocalizedNameProperty - The name of the property holding the unlocalized name.\n * @param {string} options.localizedNamePropertyFormat - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.\n */\nexport function localizeLayers(layers, locales = getLocales(), options = {}) {\n let localizedNameExpression = getLocalizedNameExpression(locales, options);\n let legacyLocalizedNameExpression = getLocalizedNameExpression(locales, {\n ...options,\n includesLegacyFields: true,\n });\n for (let layer of layers) {\n localizeLayer(\n layer,\n locales[0],\n localizedNameExpression,\n legacyLocalizedNameExpression,\n );\n }\n}\n\n/**\n * Recursively scans a semicolon-delimited value list, replacing a finite number\n * of semicolons with a separator, starting from the given index.\n *\n * This expression nests recursively by the maximum number of replacements. Take\n * special care to minimize this limit, which exponentially increases the length\n * of a property value in JSON. Excessive nesting causes acute performance\n * problems when loading the style.\n *\n * The returned expression can be complex, so use it only once within a property\n * value. To reuse the evaluated value, bind it to a variable in a let\n * expression.\n *\n * @param list The overall string expression to search within.\n * @param separator A string to insert after the value, or an expression that\n * evaluates to this string.\n * @param listStart A zero-based index into the list at which the search begins.\n * @param numReplacements The maximum number of replacements remaining.\n */\nfunction listValueExpression(\n list,\n separator,\n valueToOmit,\n listStart,\n numReplacements,\n) {\n let asIs = [\"slice\", list, listStart];\n if (numReplacements <= 0) {\n return asIs;\n }\n\n let iteration = numReplacements;\n let rawSeparator = \";\";\n let needleStartVariable = `${variablePrefix}__needleStart${iteration}`;\n let needleEndVariable = `${variablePrefix}__needleEnd${iteration}`;\n let valueVariable = `${variablePrefix}__value${iteration}`;\n let lookaheadVariable = `${variablePrefix}__lookahead${iteration}`;\n let nextListStartVariable = `${variablePrefix}__nextListStart${iteration}`;\n return [\n \"let\",\n needleStartVariable,\n [\"index-of\", rawSeparator, list, listStart],\n [\n \"case\",\n [\">=\", [\"var\", needleStartVariable], 0],\n // Found a semicolon.\n [\n \"let\",\n valueVariable,\n [\"slice\", list, listStart, [\"var\", needleStartVariable]],\n needleEndVariable,\n [\"+\", [\"var\", needleStartVariable], rawSeparator.length],\n [\n \"concat\",\n // Start with everything before the semicolon unless it's the value to\n // omit.\n [\n \"case\",\n [\"==\", [\"var\", valueVariable], valueToOmit],\n \"\",\n [\"var\", valueVariable],\n ],\n [\n \"let\",\n lookaheadVariable,\n // Look ahead by one character.\n [\n \"slice\",\n list,\n [\"var\", needleEndVariable],\n [\"+\", [\"var\", needleEndVariable], rawSeparator.length],\n ],\n [\n \"let\",\n // Skip past the current value and semicolon for any subsequent\n // searches.\n nextListStartVariable,\n [\n \"+\",\n [\"var\", needleEndVariable],\n // Also skip past any escaped semicolon or space padding.\n [\n \"match\",\n [\"var\", lookaheadVariable],\n [rawSeparator, \" \"],\n rawSeparator.length,\n 0,\n ],\n ],\n [\n \"case\",\n // If the only remaining value is the value to omit, stop\n // scanning.\n [\n \"==\",\n [\"slice\", list, [\"var\", nextListStartVariable]],\n valueToOmit,\n ],\n \"\",\n [\n \"concat\",\n [\n \"case\",\n // If the lookahead character is another semicolon, append\n // an unescaped semicolon.\n [\"==\", [\"var\", lookaheadVariable], rawSeparator],\n rawSeparator,\n // Otherwise, if the value is the value to omit, do nothing.\n [\"==\", [\"var\", valueVariable], valueToOmit],\n \"\",\n // Otherwise, append the passed-in separator.\n separator,\n ],\n // Recurse for the next value in the value list.\n listValueExpression(\n list,\n separator,\n valueToOmit,\n [\"var\", nextListStartVariable],\n numReplacements - 1,\n ),\n ],\n ],\n ],\n ],\n ],\n ],\n // No semicolons left in the string, so stop looking and append the value as is.\n asIs,\n ],\n ];\n}\n\n/**\n * Maximum number of values in a semicolon-delimited list of values.\n *\n * Increasing this constant deepens recursion for replacing delimiters in the\n * list, potentially affecting style loading performance.\n */\nconst maxValueListLength = 3;\n\n/**\n * Returns an expression interpreting the given string as a list of tag values,\n * pretty-printing the standard semicolon delimiter with the given separator.\n *\n * https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator\n *\n * The returned expression can be complex, so use it only once within a property\n * value. To reuse the evaluated value, bind it to a variable in a let\n * expression.\n *\n * @param valueList A semicolon-delimited list of values.\n * @param separator A string to insert between each value, or an expression that\n * evaluates to this string.\n */\nexport function listValuesExpression(valueList, separator, valueToOmit) {\n let maxSeparators = maxValueListLength - 1;\n let valueListVariable = `${variablePrefix}__valueList`;\n let valueToOmitVariable = `${variablePrefix}__valueToOmit`;\n return [\n \"let\",\n valueListVariable,\n valueList,\n valueToOmitVariable,\n valueToOmit || \";\",\n listValueExpression(\n [\"var\", valueListVariable],\n separator,\n [\"var\", valueToOmitVariable],\n 0,\n maxSeparators,\n ),\n ];\n}\n\nconst localizedNameCore = listValuesExpression(\n [\"var\", localizedNameVariable],\n \"\\n\",\n);\n\n/**\n * The names in the user's preferred language, each on a separate line.\n */\nexport const localizedName = [\n \"let\",\n localizedNameVariable,\n \"\",\n localizedNameCore,\n];\n\nconst localizedNameInlineCore = listValuesExpression(\n [\"var\", localizedNameVariable],\n inlineSeparator,\n);\n\n/**\n * The names in the user's preferred language, all on the same line.\n */\nexport const localizedNameInline = [\n \"let\",\n localizedNameVariable,\n \"\",\n localizedNameInlineCore,\n];\n\n/**\n * Returns an expression that tests whether the target has the given prefix,\n * respecting word boundaries.\n */\nfunction startsWithExpression(target, candidatePrefix, collator) {\n // \"Quebec City\" vs. \"Qu\u00E9bec\", \"Washington, D.C.\" vs. \"Washington\"\n let wordBoundaries = \" ,\";\n return [\n \"all\",\n [\n \"==\",\n [\"slice\", target, 0, [\"length\", candidatePrefix]],\n candidatePrefix,\n collator,\n ],\n [\n \"in\",\n [\n \"slice\",\n // Pad the target in case the prefix matches exactly.\n // \"Montreal \" vs. \"Montr\u00E9al\"\n [\"concat\", target, wordBoundaries[0]],\n [\"length\", candidatePrefix],\n [\"+\", [\"length\", candidatePrefix], 1],\n ],\n wordBoundaries,\n ],\n ];\n}\n\nfunction overwritePrefixExpression(target, newPrefix) {\n return [\"concat\", newPrefix, [\"slice\", target, [\"length\", newPrefix]]];\n}\n\n/**\n * Returns an expression that tests whether the target has the given suffix,\n * respecting word boundaries.\n */\nfunction endsWithExpression(target, candidateSuffix, collator) {\n let wordBoundary = \" \";\n let suffixStartVariable = `${variablePrefix}__suffixStart`;\n return [\n \"let\",\n suffixStartVariable,\n [\"-\", [\"length\", target], [\"length\", candidateSuffix]],\n [\n \"all\",\n [\n \"==\",\n [\"slice\", target, [\"var\", suffixStartVariable]],\n candidateSuffix,\n collator,\n ],\n [\n \"==\",\n [\n \"slice\",\n target,\n [\"-\", [\"var\", suffixStartVariable], 1],\n [\"var\", suffixStartVariable],\n ],\n wordBoundary,\n ],\n ],\n ];\n}\n\nfunction overwriteSuffixExpression(target, newSuffix) {\n return [\n \"concat\",\n [\"slice\", target, 0, [\"-\", [\"length\", target], [\"length\", newSuffix]]],\n newSuffix,\n ];\n}\n\nconst localizedNameListVariable = `${variablePrefix}__localizedNameList`;\nconst nameListVariable = `${variablePrefix}__nameList`;\n\nconst localizedNameWithLocalGlossCore = [\n \"let\",\n localizedNameListVariable,\n listValuesExpression([\"var\", localizedNameVariable], \"\\n\"),\n [\n \"case\",\n // If the name in the preferred and local languages match exactly...\n [\n \"==\",\n [\"var\", localizedNameVariable],\n [\"get\", \"name\"],\n [\"var\", localizedCollatorVariable],\n ],\n // ...just pick one.\n [\"format\", [\"var\", localizedNameListVariable]],\n [\n \"let\",\n nameListVariable,\n listValuesExpression([\"get\", \"name\"], \"\\n\"),\n [\n \"case\",\n // If the name in the preferred language is the same as the name in the\n // local language except for the omission of diacritics and/or the addition\n // of a suffix (e.g., \"City\" in English)...\n startsWithExpression(\n [\"var\", localizedNameVariable],\n [\"get\", \"name\"],\n [\"var\", diacriticInsensitiveCollatorVariable],\n ),\n // ...then replace the common prefix with the local name.\n [\n \"format\",\n overwritePrefixExpression(\n [\"var\", localizedNameVariable],\n [\"var\", nameListVariable],\n ),\n ],\n // If the name in the preferred language is the same as the name in the\n // local language except for the omission of diacritics and/or the addition\n // of a prefix (e.g., \"City of\" in English or \"Ciudad de\" in Spanish)...\n endsWithExpression(\n [\"var\", localizedNameVariable],\n [\"get\", \"name\"],\n [\"var\", diacriticInsensitiveCollatorVariable],\n ),\n // ...then replace the common suffix with the local name.\n [\n \"format\",\n overwriteSuffixExpression(\n [\"var\", localizedNameVariable],\n [\"var\", nameListVariable],\n ),\n ],\n // Otherwise, gloss the name in the local language if it differs from the\n // localized name.\n [\n \"format\",\n [\"var\", localizedNameListVariable],\n \"\\n\",\n \"(\\u2068\",\n { \"font-scale\": 0.8 },\n listValuesExpression([\"get\", \"name\"], inlineSeparator, [\n \"var\",\n localizedNameVariable,\n ]),\n { \"font-scale\": 0.8 },\n \"\\u2069)\",\n { \"font-scale\": 0.8 },\n ],\n ],\n ],\n ],\n];\n\n/**\n * The name in the user's preferred language, followed by the name in the local\n * language in parentheses if it differs.\n */\nexport const localizedNameWithLocalGloss = [\n \"let\",\n localizedNameVariable,\n \"\",\n localizedCollatorVariable,\n [\"collator\", {}],\n diacriticInsensitiveCollatorVariable,\n [\"collator\", {}],\n localizedNameWithLocalGlossCore,\n];\n\n/**\n * ISO 3166-1 alpha-2 country codes by ISO 3166-1 alpha-3 code.\n *\n * Source: https://www.cia.gov/the-world-factbook/references/country-data-codes/\n */\nconst iso3166_1_alpha_2_by_3 = {\n ABW: \"AW\",\n AFG: \"AF\",\n AGO: \"AO\",\n AIA: \"AI\",\n ALB: \"AL\",\n AND: \"AD\",\n ARE: \"AE\",\n ARG: \"AR\",\n ARM: \"AM\",\n ASM: \"AS\",\n ATA: \"AQ\",\n ATF: \"TF\",\n ATG: \"AG\",\n AUS: \"AU\",\n AUT: \"AT\",\n AZE: \"AZ\",\n BDI: \"BI\",\n BEL: \"BE\",\n BEN: \"BJ\",\n BFA: \"BF\",\n BGD: \"BD\",\n BGR: \"BG\",\n BHR: \"BH\",\n BHS: \"BS\",\n BIH: \"BA\",\n BLM: \"BL\",\n BLR: \"BY\",\n BLZ: \"BZ\",\n BMU: \"BM\",\n BOL: \"BO\",\n BRA: \"BR\",\n BRB: \"BB\",\n BRN: \"BN\",\n BTN: \"BT\",\n BVT: \"BV\",\n BWA: \"BW\",\n CAF: \"CF\",\n CAN: \"CA\",\n CCK: \"CC\",\n CHE: \"CH\",\n CHL: \"CL\",\n CHN: \"CN\",\n CIV: \"CI\",\n CMR: \"CM\",\n COD: \"CD\",\n COG: \"CG\",\n COK: \"CK\",\n COL: \"CO\",\n COM: \"KM\",\n CPV: \"CV\",\n CRI: \"CR\",\n CUB: \"CU\",\n CUW: \"CW\",\n CXR: \"CX\",\n CYM: \"KY\",\n CYP: \"CY\",\n CZE: \"CZ\",\n DEU: \"DE\",\n DJI: \"DJ\",\n DMA: \"DM\",\n DNK: \"DK\",\n DOM: \"DO\",\n DZA: \"DZ\",\n ECU: \"EC\",\n EGY: \"EG\",\n ERI: \"ER\",\n ESH: \"EH\",\n ESP: \"ES\",\n EST: \"EE\",\n ETH: \"ET\",\n FIN: \"FI\",\n FJI: \"FJ\",\n FLK: \"FK\",\n FRA: \"FR\",\n FRO: \"FO\",\n FSM: \"FM\",\n FXX: \"FX\",\n GAB: \"GA\",\n GBR: \"GB\",\n GEO: \"GE\",\n GGY: \"GG\",\n GHA: \"GH\",\n GIB: \"GI\",\n GIN: \"GN\",\n GLP: \"GP\",\n GMB: \"GM\",\n GNB: \"GW\",\n GNQ: \"GQ\",\n GRC: \"GR\",\n GRD: \"GD\",\n GRL: \"GL\",\n GTM: \"GT\",\n GUF: \"GF\",\n GUM: \"GU\",\n GUY: \"GY\",\n HKG: \"HK\",\n HMD: \"HM\",\n HND: \"HN\",\n HRV: \"HR\",\n HTI: \"HT\",\n HUN: \"HU\",\n IDN: \"ID\",\n IMN: \"IM\",\n IND: \"IN\",\n IOT: \"IO\",\n IRL: \"IE\",\n IRN: \"IR\",\n IRQ: \"IQ\",\n ISL: \"IS\",\n ISR: \"IL\",\n ITA: \"IT\",\n JAM: \"JM\",\n JEY: \"JE\",\n JOR: \"JO\",\n JPN: \"JP\",\n KAZ: \"KZ\",\n KEN: \"KE\",\n KGZ: \"KG\",\n KHM: \"KH\",\n KIR: \"KI\",\n KNA: \"KN\",\n KOR: \"KR\",\n KWT: \"KW\",\n LAO: \"LA\",\n LBN: \"LB\",\n LBR: \"LR\",\n LBY: \"LY\",\n LCA: \"LC\",\n LIE: \"LI\",\n LKA: \"LK\",\n LSO: \"LS\",\n LTU: \"LT\",\n LUX: \"LU\",\n LVA: \"LV\",\n MAC: \"MO\",\n MAF: \"MF\",\n MAR: \"MA\",\n MCO: \"MC\",\n MDA: \"MD\",\n MDG: \"MG\",\n MDV: \"MV\",\n MEX: \"MX\",\n MHL: \"MH\",\n MKD: \"MK\",\n MLI: \"ML\",\n MLT: \"MT\",\n MMR: \"MM\",\n MNE: \"ME\",\n MNG: \"MN\",\n MNP: \"MP\",\n MOZ: \"MZ\",\n MRT: \"MR\",\n MSR: \"MS\",\n MTQ: \"MQ\",\n MUS: \"MU\",\n MWI: \"MW\",\n MYS: \"MY\",\n MYT: \"YT\",\n NAM: \"NA\",\n NCL: \"NC\",\n NER: \"NE\",\n NFK: \"NF\",\n NGA: \"NG\",\n NIC: \"NI\",\n NIU: \"NU\",\n NLD: \"NL\",\n NOR: \"NO\",\n NPL: \"NP\",\n NRU: \"NR\",\n NZL: \"NZ\",\n OMN: \"OM\",\n PAK: \"PK\",\n PAN: \"PA\",\n PCN: \"PN\",\n PER: \"PE\",\n PHL: \"PH\",\n PLW: \"PW\",\n PNG: \"PG\",\n POL: \"PL\",\n PRI: \"PR\",\n PRK: \"KP\",\n PRT: \"PT\",\n PRY: \"PY\",\n PSE: \"PS\",\n PYF: \"PF\",\n QAT: \"QA\",\n REU: \"RE\",\n ROU: \"RO\",\n RUS: \"RU\",\n RWA: \"RW\",\n SAU: \"SA\",\n SDN: \"SD\",\n SEN: \"SN\",\n SGP: \"SG\",\n SGS: \"GS\",\n SHN: \"SH\",\n SJM: \"SJ\",\n SLB: \"SB\",\n SLE: \"SL\",\n SLV: \"SV\",\n SMR: \"SM\",\n SOM: \"SO\",\n SPM: \"PM\",\n SRB: \"RS\",\n SSD: \"SS\",\n STP: \"ST\",\n SUR: \"SR\",\n SVK: \"SK\",\n SVN: \"SI\",\n SWE: \"SE\",\n SWZ: \"SZ\",\n SXM: \"SX\",\n SYC: \"SC\",\n SYR: \"SY\",\n TCA: \"TC\",\n TCD: \"TD\",\n TGO: \"TG\",\n THA: \"TH\",\n TJK: \"TJ\",\n TKL: \"TK\",\n TKM: \"TM\",\n TLS: \"TL\",\n TON: \"TO\",\n TTO: \"TT\",\n TUN: \"TN\",\n TUR: \"TR\",\n TUV: \"TV\",\n TWN: \"TW\",\n TZA: \"TZ\",\n UGA: \"UG\",\n UKR: \"UA\",\n UMI: \"UM\",\n URY: \"UY\",\n USA: \"US\",\n UZB: \"UZ\",\n VAT: \"VA\",\n VCT: \"VC\",\n VEN: \"VE\",\n VGB: \"VG\",\n VIR: \"VI\",\n VNM: \"VN\",\n VUT: \"VU\",\n WLF: \"WF\",\n WSM: \"WS\",\n YEM: \"YE\",\n ZAF: \"ZA\",\n ZMB: \"ZM\",\n ZWE: \"ZW\",\n};\n\nconst countryNamesByCodeVariable = `${variablePrefix}__countryNamesByCode`;\n\n/**\n * Returns a table of country names in the user\u2019s preferred language by ISO 3166-1 alpha-3 code.\n *\n * @param {[string]} locales - The locales for formatting the country names.\n * @param {boolean} options.uppercase Whether to write the country names in all uppercase, respecting the locale\u2019s case conventions.\n */\nexport function getLocalizedCountryNames(locales, options = {}) {\n let countryNames = new Intl.DisplayNames(locales, {\n type: \"region\",\n fallback: \"none\",\n });\n return Object.fromEntries(\n Object.entries(iso3166_1_alpha_2_by_3).map((e) => {\n let name = countryNames.of(e[1]);\n if (name && options?.uppercase) {\n // Neither the upcase expression operator nor the text-transform layout property is locale-aware, so uppercase the name upfront.\n name = name\n .toLocaleUpperCase(locales)\n // Word boundaries are less discernible in uppercase text, so pad each word by an additional space.\n .replaceAll(\" \", \" \");\n }\n return [e[0], name];\n }),\n );\n}\n\n/**\n * Returns the global state that Diplomat needs to fully localize the style.\n *\n * @param {[string]} locales - The locales for formatting the country names.\n * @param {boolean} options.uppercaseCountryNames Whether to write country names in all uppercase, respecting the locale\u2019s case conventions.\n */\nexport function getGlobalStateForLocalization(locales, options = {}) {\n let state = {};\n state[countryNamesByCodeVariable] = getLocalizedCountryNames(locales, {\n uppercase: options?.uppercaseCountryNames,\n });\n return state;\n}\n\n/**\n * Returns an expression that converts the given country code to a human-readable name in the user's preferred language.\n *\n * @param {array} code An expression that evaluates to an ISO 3166-1 alpha-3 country code.\n */\nexport function getLocalizedCountryNameExpression(code) {\n return [\n \"let\",\n \"code\",\n code,\n [\n \"coalesce\",\n [\n \"get\",\n [\"var\", \"code\"],\n [\n \"coalesce\",\n [\"global-state\", countryNamesByCodeVariable],\n [\"literal\", {}],\n ],\n ],\n // Fall back to the country code in parentheses.\n [\"concat\", \"(\", [\"var\", \"code\"], \")\"],\n ],\n ];\n}\n\n/**\n * Updates each style layer's `text-field` value to match the given locales, upgrading any unlocalizable layer along the way.\n *\n * This method ugprades unlocalizable layers to localized multiline or inline labels depending on the `symbol-placement` layout property. To add a dual language label to a layer, set its `text-field` layout property manually using the `localizedNameWithLocalGloss` constant.\n *\n * If neither `options.layers` nor `options.sourceLayers` is specified, this function makes localizable any style layer that gets the feature property specified in `options.unlocalizedNameProperty`, or `name` by default.\n *\n * @param {maplibregl.Map} map - The map to localize.\n * @param {[string]} locales - The locales to insert into each layer.\n * @param {[string]} options.layers - The style layers with these IDs will be made localizable.\n * @param {[string]} options.sourceLayers - The style layers that use these source layers will be made localizable. These are source layer IDs, not style layer IDs.\n * @param {string} options.unlocalizedNameProperty - The name of the property holding the unlocalized name.\n * @param {string} options.localizedNamePropertyFormat - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.\n * @param {boolean} options.glossLocalNames - Whether to format each label as a dual language label including a local name gloss.\n * @param {boolean} options.uppercaseCountryNames Whether to write country names in all uppercase, respecting the locale\u2019s case conventions.\n */\nexport function localizeStyle(map, locales = getLocales(), options = {}) {\n let style = map.getStyle();\n\n let localizedNameExpression = getLocalizedNameExpression(locales, options);\n let legacyLocalizedNameExpression = getLocalizedNameExpression(locales, {\n ...options,\n includesLegacyFields: true,\n });\n\n for (let layer of style.layers) {\n let sourceLayer = layer[\"source-layer\"];\n if (\n (!options.layers && !options.sourceLayers) ||\n options.layers?.includes(layer.id) ||\n (sourceLayer && options.sourceLayers?.includes(sourceLayer))\n ) {\n prepareLayer(\n layer,\n options?.unlocalizedNameProperty,\n options?.glossLocalNames,\n );\n }\n localizeLayer(\n layer,\n locales[0],\n localizedNameExpression,\n legacyLocalizedNameExpression,\n );\n }\n\n let countryNames = getLocalizedCountryNames(locales, {\n uppercase: options?.uppercaseCountryNames,\n });\n map.setGlobalStateProperty(countryNamesByCodeVariable, countryNames);\n\n map.setStyle(style);\n}\n\nif (typeof window !== \"undefined\") {\n window.Diplomat = {\n getGlobalStateForLocalization,\n getLanguageFromURL,\n getLocales,\n getLocalizedCountryNameExpression,\n listValuesExpression,\n localizeLayers,\n localizeStyle,\n localizedName,\n localizedNameInline,\n localizedNameWithLocalGloss,\n };\n if (\"maplibregl\" in window) {\n maplibregl.Diplomat = window.Diplomat;\n\n maplibregl.Map.prototype.localizeStyle = function (\n locales = getLocales(),\n options = {},\n ) {\n localizeStyle(this, locales, options);\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "MACA,IAAMA,EAAiB,WAKhB,SAASC,EAAmBC,EAAK,CACtC,IAAIC,EAAW,IAAI,gBAAgBD,EAAI,KAAK,OAAO,CAAC,CAAC,EAAE,IAAI,UAAU,EACrE,OAAOC,IAAa,GAAK,KAAOA,CAClC,CAKA,SAASC,EAASC,EAAO,CACvB,OAAOA,EAAM,OACX,CAACC,EAAOC,IAAU,CAAC,GAAGD,EAAO,GAAGA,EAAM,IAAKE,GAA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AC1B,CACF,EAGA,CACE,SACA,CAAC,MAAOD,CAAyB,EACjC;AAAA,EACA,UACA,CAAE,aAAc,EAAI,EACpBpB,EAAqB,CAAC,MAAO,MAAM,EAAGhC,EAAiB,CACrD,MACAX,CACF,CAAC,EACD,CAAE,aAAc,EAAI,EACpB,UACA,CAAE,aAAc,EAAI,CACtB,CACF,CACF,CACF,CACF,EAMaiE,EAA8B,CACzC,MACAjE,EACA,GACAC,EACA,CAAC,WAAY,CAAC,CAAC,EACfC,EACA,CAAC,WAAY,CAAC,CAAC,EACfiB,CACF,EAOM+C,EAAyB,CAC7B,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,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,CACL,MACA,OACAA,EACA,CACE,WACA,CACE,MACA,CAAC,MAAO,MAAM,EACd,CACE,WACA,CAAC,eAAgBR,CAA0B,EAC3C,CAAC,UAAW,CAAC,CAAC,CAChB,CACF,EAEA,CAAC,SAAU,IAAK,CAAC,MAAO,MAAM,EAAG,GAAG,CACtC,CACF,CACF,CAkBO,SAASS,EAAcC,EAAK/F,EAAUO,EAAW,EAAGG,EAAU,CAAC,EAAG,CACvE,IAAIsF,EAAQD,EAAI,SAAS,EAErBrD,EAA0BjC,EAA2BT,EAASU,CAAO,EACrEiC,EAAgClC,EAA2BT,EAAS,CACtE,GAAGU,EACH,qBAAsB,EACxB,CAAC,EAED,QAASqB,KAASiE,EAAM,OAAQ,CAC9B,IAAIC,EAAclE,EAAM,cAAc,GAEnC,CAACrB,EAAQ,QAAU,CAACA,EAAQ,cAC7BA,EAAQ,QAAQ,SAASqB,EAAM,EAAE,GAChCkE,GAAevF,EAAQ,cAAc,SAASuF,CAAW,IAE1DnE,EACEC,EACArB,GAAS,wBACTA,GAAS,eACX,EAEF8B,EACET,EACA/B,EAAQ,CAAC,EACT0C,EACAC,CACF,CACF,CAEA,IAAI4C,EAAeD,EAAyBtF,EAAS,CACnD,UAAWU,GAAS,qBACtB,CAAC,EACDqF,EAAI,uBAAuBV,EAA4BE,CAAY,EAEnEQ,EAAI,SAASC,CAAK,CACpB,CAEI,OAAO,OAAW,MACpB,OAAO,SAAW,CAChB,8BAAAN,EACA,mBAAA1G,EACA,WAAAuB,EACA,kCAAAqF,EACA,qBAAA/B,EACA,eAAAjB,EACA,cAAAkD,EACA,cAAA5B,EACA,oBAAAC,EACA,4BAAAgB,CACF,EACI,eAAgB,SAClB,WAAW,SAAW,OAAO,SAE7B,WAAW,IAAI,UAAU,cAAgB,SACvCnF,EAAUO,EAAW,EACrBG,EAAU,CAAC,EACX,CACAoF,EAAc,KAAM9F,EAASU,CAAO,CACtC",
|
|
6
|
-
"names": ["variablePrefix", "getLanguageFromURL", "url", "language", "powerset", "array", "accum", "value", "pick", "getVariants", "locale", "getRelatedLanguageTags", "tag", "maximized", "quals", "q", "tags", "locales", "l", "scoreLocale", "score", "a", "b", "validTags", "getLocales", "defaultUnlocalizedNameProperty", "getLocalizedNameExpression", "options", "localizedNameProperty", "fields", "f", "updateVariable", "letExpr", "variable", "variableNameIndex", "localizedNameVariable", "localizedCollatorVariable", "diacriticInsensitiveCollatorVariable", "replacePropertyReferences", "expression", "propertyName", "replacement", "didReplace", "arg", "idx", "newValue", "inlineSeparator", "prepareLayer", "layer", "unlocalizedNameProperty", "glossLocalNames", "textField", "symbolPlacement", "newTextField", "localizedNameWithLocalGlossCore", "localizedNameInlineCore", "localizedNameCore", "localizeLayer", "collationLocale", "localizedNameExpression", "legacyLocalizedNameExpression", "localizeLayers", "layers", "
|
|
4
|
+
"sourcesContent": ["/// A prefix that uniquely identifies this plugin, prepended onto the name of any variable generated by this plugin.\nconst variablePrefix = \"diplomat\";\n\n/** @import { DataDrivenPropertyValueSpecification as PropertyValue, ExpressionSpecification as Expression, LayerSpecification, Var } from 'maplibre-gl' */\n\n/**\n * Returns a list of languages as a comma-delimited string from the given URL hash.\n * @param {URL | Location} url\n */\nexport function getLanguageFromURL(url) {\n let language = new URLSearchParams(url.hash.substr(1)).get(\"language\");\n return language === \"\" ? null : language;\n}\n\n/**\n Returns the powerset of the given array.\n */\nfunction powerset(array) {\n return array.reduce(\n (accum, value) => [...accum, ...accum.map((pick) => [...pick, value])],\n [[]],\n );\n}\n\n/**\n Compatibility shim for `Intl.Locale.prototype.variants`.\n */\nfunction getVariants(locale) {\n return locale.variants ?? locale.minimize().baseName.match(/-([-\\w]+)/)?.[1];\n}\n\n/**\n Returns an array of the language tags related to the given language tag, sorted from most specific to least specific.\n \n @param {string} tag - The language tag that the returned language tags are related to.\n @returns {string[]} A sorted array of related language tags, or an empty array if `tag` is malformed.\n */\nexport function getRelatedLanguageTags(tag) {\n let locale;\n try {\n locale = new Intl.Locale(tag);\n } catch {\n return [];\n }\n\n let maximized = locale.maximize();\n // The subtags and extensions used in OSM name:*=* subkeys.\n let quals = [\n maximized.script,\n maximized.region,\n getVariants(maximized),\n maximized.numberingSystem,\n ].filter((q) => q);\n // Get all the combinations of components and convert them to language tags.\n let tags = powerset(quals).map((quals) =>\n [maximized.language, ...quals].join(\"-\"),\n );\n\n // Add the original language tag, in case maximizing it dropped miscellaneous extensions.\n tags.push(locale + \"\");\n tags.push(locale.baseName);\n\n // Validate each of the language tags.\n let locales = tags\n .map((tag) => {\n try {\n return new Intl.Locale(tag);\n } catch {}\n })\n .filter((l) => l);\n\n // Sort the locales from most specific to least specific.\n let scoreLocale = (locale) => {\n let tag = locale + \"\";\n let score = 0;\n score += tag.length ?? 0;\n score += tag.split(\"-\").length ?? 0;\n // Prioritize variants, which are more specific than script and region.\n score += getVariants(locale)?.length ?? 0;\n // Prioritize extensions, which Intl.Locale.prototype.maximize can\u2019t maximize.\n score += tag.match(/(?:-[tx]-|-u-\\w\\w-)\\w+/)?.[0]?.length ?? 0;\n return score;\n };\n locales.sort((a, b) => scoreLocale(b) - scoreLocale(a));\n\n let validTags = locales.map((l) => l + \"\");\n return [...new Set(validTags)];\n}\n\n/**\n * Returns the languages that the user prefers.\n */\nexport function getLocales() {\n // Check the language \"parameter\" in the hash.\n let parameter = getLanguageFromURL(window.location)?.split(\",\");\n // Fall back to the user's language preference.\n let userLocales = parameter ?? navigator.languages ?? [navigator.language];\n // Get a full fallback list.\n let tags = userLocales.flatMap((l) => getRelatedLanguageTags(l));\n\n return [...new Set(tags)];\n}\n\nconst defaultUnlocalizedNameProperty = \"name\";\n\n/**\n * Returns a `coalesce` expression that resolves to the feature's name in a\n * language that the user prefers.\n *\n * @param {string[]} locales - Locales of the name fields to include.\n * @param {object} options\n * @param {boolean} [options.includesLegacyFields] - Whether to include the older fields\n * that include underscores, for layers that have not transitioned to the\n * colon syntax.\n * @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.\n * @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.\n * @returns {Expression}\n */\nexport function getLocalizedNameExpression(locales, options = {}) {\n let nameFields = [\n ...locales.flatMap((l) => {\n let localizedNamePropertyFormat =\n options.localizedNamePropertyFormat || `name:$1`;\n let localizedNameProperty = localizedNamePropertyFormat.replaceAll(\n \"$1\",\n l,\n );\n let fields = [localizedNameProperty];\n // transportation_label uses an underscore instead of a colon.\n // https://github.com/openmaptiles/openmaptiles/issues/769\n if (options.includesLegacyFields && (l === \"de\" || l === \"en\")) {\n fields.push(localizedNameProperty.replaceAll(\":\", \"_\"));\n }\n return fields;\n }),\n options.unlocalizedNameProperty || defaultUnlocalizedNameProperty,\n ];\n return [\"coalesce\", ...nameFields.map((f) => [\"get\", f])];\n}\n\n/**\n * Mutates a `let` expression to have a new value for the variable by the given name, binding the variable if it isn\u2019t already bound to any value.\n *\n * @param {PropertyValue<string> | undefined} letExpr - Expression to update.\n * @param {string} variable - Name of the variable to set.\n * @param {*} value - The variable's new value.\n */\nexport function updateVariable(letExpr, variable, value) {\n if (!letExpr || letExpr[0] !== \"let\") return;\n\n let variableNameIndex = letExpr.indexOf(variable);\n if (variableNameIndex % 2 === 1) {\n letExpr[variableNameIndex + 1] = value;\n } else {\n letExpr.splice(-1, 0, variable, value);\n }\n}\n\nconst localizedNameVariable = `${variablePrefix}__localizedName`;\nconst localizedCollatorVariable = `${variablePrefix}__localizedCollator`;\nconst diacriticInsensitiveCollatorVariable = `${variablePrefix}__diacriticInsensitiveCollator`;\n\n/**\n * Recursively walks an expression, returning a copy of the subexpression after replacing any reference to a specific feature property with a new value in place.\n *\n * @param {Expression} expression - The expression to transform.\n * @param {string} propertyName - The name of the feature property to look for.\n * @param {*} replacement - The replacement value.\n * @returns {Expression | undefined} The same array as `expression` if `expression` referred to `propertyName`, or `undefined` if `expression` did not refer to `propertyName`.\n */\nexport function replacePropertyReferences(\n expression,\n propertyName,\n replacement,\n) {\n if (!Array.isArray(expression) || expression[0] === \"literal\") return;\n if (expression[0] === \"get\") {\n if (expression.length === 2 && expression[1] === propertyName) {\n return replacement;\n }\n return;\n }\n let didReplace = false;\n expression.forEach((arg, idx) => {\n if (!idx) return; // operator can never be a property reference\n let newValue = replacePropertyReferences(arg, propertyName, replacement);\n if (newValue !== undefined) {\n expression[idx] = newValue;\n didReplace = true;\n }\n });\n if (didReplace) return expression;\n}\n\n/**\n * The separator to use in inline contexts.\n */\nconst inlineSeparator = \" \\u2022 \";\n\n/**\n * Transforms a layer\u2019s `text-field` layout property so that it can be localized by `localizeLayers` later on.\n *\n * The transformed `text-field` property is only modified if it contains a reference to the feature property specified by `unlocalizedNameProperty`. If the layer\u2019s `symbol-placement` layout property is set to either `line` or `line-center`, the resulting text field takes up only one line. Otherwise, the text field for a given feature may span multiple lines if its unlocalized name property is set to a list of values.\n *\n * @param {LayerSpecification} layer - The style layer to prepare for localization.\n * @param {string} [unlocalizedNameProperty] - The name of the feature property that holds the unlocalized name. References to this property are replaced by a more complex expression that can be localized dynamically.\n * @param {boolean} [glossLocalNames] - Whether to format each label as a dual language label including a local name gloss.\n */\nexport function prepareLayer(layer, unlocalizedNameProperty, glossLocalNames) {\n let textField = layer.layout && layer.layout[\"text-field\"];\n if (\n !textField ||\n (textField[0] === \"let\" && textField.includes(localizedNameVariable))\n ) {\n return;\n }\n\n let symbolPlacement = layer.layout && layer.layout[\"symbol-placement\"];\n let isInline =\n symbolPlacement === \"line\" || symbolPlacement === \"line-center\";\n let listValues = glossLocalNames\n ? localizedNameWithLocalGlossCore\n : isInline\n ? localizedNameInlineCore\n : localizedNameCore;\n let newTextField = replacePropertyReferences(\n textField,\n unlocalizedNameProperty || defaultUnlocalizedNameProperty,\n listValues,\n );\n if (newTextField !== undefined) {\n layer.layout[\"text-field\"] = [\n \"let\",\n localizedNameVariable,\n \"\",\n newTextField,\n ];\n }\n}\n\n/**\n * Updates localizable variables at the top level of the layer's `text-field` expression based on the given locales.\n *\n * @param {LayerSpecification} layer - The style layer to localize.\n * @param {string} collationLocale - The locale for string comparison purposes.\n * @param {Expression} localizedNameExpression - An expression that produces a localized name.\n * @param {Expression} legacyLocalizedNameExpression - An expression that produces a localized name based on legacy properties in OpenMapTiles.\n */\nfunction localizeLayer(\n layer,\n collationLocale,\n localizedNameExpression,\n legacyLocalizedNameExpression,\n) {\n if (!(\"layout\" in layer) || !(\"text-field\" in layer.layout)) return;\n\n let textField = layer.layout[\"text-field\"];\n\n updateVariable(\n textField,\n localizedNameVariable,\n // https://github.com/openmaptiles/openmaptiles/issues/769\n layer[\"source-layer\"] === \"transportation_name\"\n ? legacyLocalizedNameExpression\n : localizedNameExpression,\n );\n\n updateVariable(textField, localizedCollatorVariable, [\n \"collator\",\n {\n \"case-sensitive\": false,\n \"diacritic-sensitive\": true,\n locale: collationLocale,\n },\n ]);\n\n // Only perform diacritic folding in English. English normally uses few diacritics except when labeling foreign place names on maps.\n updateVariable(textField, diacriticInsensitiveCollatorVariable, [\n \"collator\",\n {\n \"case-sensitive\": false,\n \"diacritic-sensitive\": !/^en\\b/.test(collationLocale),\n locale: collationLocale,\n },\n ]);\n}\n\n/**\n * Updates localizable variables at the top level of each layer's `text-field` expression based on the given locales.\n *\n * @param {LayerSpecification[]} layers - The style layers to localize.\n * @param {string[]} locales - The locales to insert into each layer.\n * @param {object} options\n * @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.\n * @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.\n */\nexport function localizeLayers(layers, locales = getLocales(), options = {}) {\n let localizedNameExpression = getLocalizedNameExpression(locales, options);\n let legacyLocalizedNameExpression = getLocalizedNameExpression(locales, {\n ...options,\n includesLegacyFields: true,\n });\n for (let layer of layers) {\n localizeLayer(\n layer,\n locales[0],\n localizedNameExpression,\n legacyLocalizedNameExpression,\n );\n }\n}\n\n/**\n * Returns an expression interpreting the given string as a list of tag values,\n * pretty-printing the standard semicolon delimiter with the given separator.\n *\n * https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator\n *\n * The returned expression can be complex, so use it only once within a property\n * value. To reuse the evaluated value, bind it to a variable in a let\n * expression.\n *\n * @param {Expression} valueList A semicolon-delimited list of values.\n * @param {string | Expression} separator A string to insert between each value, or an expression that\n * evaluates to this string.\n * @param {string | Expression} [valueToOmit]\n * @returns {Expression}\n */\nexport function listValuesExpression(valueList, separator, valueToOmit) {\n // Replace the ;; escape sequence with a placeholder sequence unlikely to\n // legitimately occur inside a value or separator.\n const objReplacementChar = \"\\x91\\ufffc\\x92\"; // https://overpass-turbo.eu/s/1pJx\n let escapedValueList = [\n \"join\",\n [\"split\", valueList, \";;\"],\n objReplacementChar,\n ];\n\n // Collapse any space following the delimiter.\n let collapsedValueList = [\"join\", [\"split\", escapedValueList, \"; \"], \";\"];\n\n let valuesVariable = `${variablePrefix}__values`;\n let omissionIndexVariable = `${variablePrefix}__omissionIndex`;\n let abridgedValuesVariable = `${variablePrefix}__abridgedValues`;\n return [\n \"let\",\n valuesVariable,\n [\"split\", collapsedValueList, \";\"],\n [\n \"let\",\n omissionIndexVariable,\n valueToOmit ? [\"index-of\", valueToOmit, [\"var\", valuesVariable]] : -1,\n [\n \"let\",\n abridgedValuesVariable,\n [\n \"match\",\n [\"var\", omissionIndexVariable],\n -1,\n // Nothing to elide.\n [\"join\", [\"var\", valuesVariable], separator],\n // Produce the items before and after the omission index, eliding the value at that index.\n [\n \"concat\",\n [\n \"join\",\n [\n \"slice\",\n [\"var\", valuesVariable],\n 0,\n [\"var\", omissionIndexVariable],\n ],\n separator,\n ],\n // Leave only a separator in place of the omitted item, unless it\u2019s at either end of the list.\n [\n \"case\",\n [\n \"any\",\n [\"==\", [\"var\", omissionIndexVariable], 0],\n [\n \"==\",\n [\"var\", omissionIndexVariable],\n [\"-\", [\"length\", [\"var\", valuesVariable]], 1],\n ],\n ],\n \"\",\n separator,\n ],\n [\n \"join\",\n [\n \"slice\",\n [\"var\", valuesVariable],\n [\"+\", [\"var\", omissionIndexVariable], 1],\n ],\n separator,\n ],\n ],\n ],\n // Unescape any escaped semicolons.\n [\n \"join\",\n [\"split\", [\"var\", abridgedValuesVariable], objReplacementChar],\n \";\",\n ],\n ],\n ],\n ];\n}\n\nconst localizedNameCore = listValuesExpression(\n [\"var\", localizedNameVariable],\n \"\\n\",\n);\n\n/**\n * The names in the user's preferred language, each on a separate line.\n * @type {Expression}\n */\nexport const localizedName = [\n \"let\",\n localizedNameVariable,\n \"\",\n localizedNameCore,\n];\n\nconst localizedNameInlineCore = listValuesExpression(\n [\"var\", localizedNameVariable],\n inlineSeparator,\n);\n\n/**\n * The names in the user's preferred language, all on the same line.\n * @type {Expression}\n */\nexport const localizedNameInline = [\n \"let\",\n localizedNameVariable,\n \"\",\n localizedNameInlineCore,\n];\n\n/**\n * Returns an expression that tests whether the target has the given prefix,\n * respecting word boundaries.\n */\nfunction startsWithExpression(target, candidatePrefix, collator) {\n // \"Quebec City\" vs. \"Qu\u00E9bec\", \"Washington, D.C.\" vs. \"Washington\"\n let wordBoundaries = \" ,\";\n return [\n \"all\",\n [\n \"==\",\n [\"slice\", target, 0, [\"length\", candidatePrefix]],\n candidatePrefix,\n collator,\n ],\n [\n \"in\",\n [\n \"slice\",\n // Pad the target in case the prefix matches exactly.\n // \"Montreal \" vs. \"Montr\u00E9al\"\n [\"concat\", target, wordBoundaries[0]],\n [\"length\", candidatePrefix],\n [\"+\", [\"length\", candidatePrefix], 1],\n ],\n wordBoundaries,\n ],\n ];\n}\n\nfunction overwritePrefixExpression(target, newPrefix) {\n return [\"concat\", newPrefix, [\"slice\", target, [\"length\", newPrefix]]];\n}\n\n/**\n * Returns an expression that tests whether the target has the given suffix,\n * respecting word boundaries.\n */\nfunction endsWithExpression(target, candidateSuffix, collator) {\n let wordBoundary = \" \";\n let suffixStartVariable = `${variablePrefix}__suffixStart`;\n return [\n \"let\",\n suffixStartVariable,\n [\"-\", [\"length\", target], [\"length\", candidateSuffix]],\n [\n \"all\",\n [\n \"==\",\n [\"slice\", target, [\"var\", suffixStartVariable]],\n candidateSuffix,\n collator,\n ],\n [\n \"==\",\n [\n \"slice\",\n target,\n [\"-\", [\"var\", suffixStartVariable], 1],\n [\"var\", suffixStartVariable],\n ],\n wordBoundary,\n ],\n ],\n ];\n}\n\nfunction overwriteSuffixExpression(target, newSuffix) {\n return [\n \"concat\",\n [\"slice\", target, 0, [\"-\", [\"length\", target], [\"length\", newSuffix]]],\n newSuffix,\n ];\n}\n\nconst localizedNameListVariable = `${variablePrefix}__localizedNameList`;\nconst nameListVariable = `${variablePrefix}__nameList`;\n\nconst localizedNameWithLocalGlossCore = [\n \"let\",\n localizedNameListVariable,\n listValuesExpression([\"var\", localizedNameVariable], \"\\n\"),\n [\n \"case\",\n // If the name in the preferred and local languages match exactly...\n [\n \"==\",\n [\"var\", localizedNameVariable],\n [\"get\", \"name\"],\n [\"var\", localizedCollatorVariable],\n ],\n // ...just pick one.\n [\"format\", [\"var\", localizedNameListVariable]],\n [\n \"let\",\n nameListVariable,\n listValuesExpression([\"get\", \"name\"], \"\\n\"),\n [\n \"case\",\n // If the name in the preferred language is the same as the name in the\n // local language except for the omission of diacritics and/or the addition\n // of a suffix (e.g., \"City\" in English)...\n startsWithExpression(\n [\"var\", localizedNameVariable],\n [\"get\", \"name\"],\n [\"var\", diacriticInsensitiveCollatorVariable],\n ),\n // ...then replace the common prefix with the local name.\n [\n \"format\",\n overwritePrefixExpression(\n [\"var\", localizedNameVariable],\n [\"var\", nameListVariable],\n ),\n ],\n // If the name in the preferred language is the same as the name in the\n // local language except for the omission of diacritics and/or the addition\n // of a prefix (e.g., \"City of\" in English or \"Ciudad de\" in Spanish)...\n endsWithExpression(\n [\"var\", localizedNameVariable],\n [\"get\", \"name\"],\n [\"var\", diacriticInsensitiveCollatorVariable],\n ),\n // ...then replace the common suffix with the local name.\n [\n \"format\",\n overwriteSuffixExpression(\n [\"var\", localizedNameVariable],\n [\"var\", nameListVariable],\n ),\n ],\n // Otherwise, gloss the name in the local language if it differs from the\n // localized name.\n [\n \"format\",\n [\"var\", localizedNameListVariable],\n \"\\n\",\n \"(\\u2068\",\n { \"font-scale\": 0.8 },\n listValuesExpression([\"get\", \"name\"], inlineSeparator, [\n \"var\",\n localizedNameVariable,\n ]),\n { \"font-scale\": 0.8 },\n \"\\u2069)\",\n { \"font-scale\": 0.8 },\n ],\n ],\n ],\n ],\n];\n\n/**\n * The name in the user's preferred language, followed by the name in the local\n * language in parentheses if it differs.\n * @type {Expression}\n */\nexport const localizedNameWithLocalGloss = [\n \"let\",\n localizedNameVariable,\n \"\",\n localizedCollatorVariable,\n [\"collator\", {}],\n diacriticInsensitiveCollatorVariable,\n [\"collator\", {}],\n localizedNameWithLocalGlossCore,\n];\n\n/**\n * ISO 3166-1 alpha-2 country codes by ISO 3166-1 alpha-3 code.\n *\n * Source: https://www.cia.gov/the-world-factbook/references/country-data-codes/\n */\nconst iso3166_1_alpha_2_by_3 = {\n ABW: \"AW\",\n AFG: \"AF\",\n AGO: \"AO\",\n AIA: \"AI\",\n ALB: \"AL\",\n AND: \"AD\",\n ARE: \"AE\",\n ARG: \"AR\",\n ARM: \"AM\",\n ASM: \"AS\",\n ATA: \"AQ\",\n ATF: \"TF\",\n ATG: \"AG\",\n AUS: \"AU\",\n AUT: \"AT\",\n AZE: \"AZ\",\n BDI: \"BI\",\n BEL: \"BE\",\n BEN: \"BJ\",\n BFA: \"BF\",\n BGD: \"BD\",\n BGR: \"BG\",\n BHR: \"BH\",\n BHS: \"BS\",\n BIH: \"BA\",\n BLM: \"BL\",\n BLR: \"BY\",\n BLZ: \"BZ\",\n BMU: \"BM\",\n BOL: \"BO\",\n BRA: \"BR\",\n BRB: \"BB\",\n BRN: \"BN\",\n BTN: \"BT\",\n BVT: \"BV\",\n BWA: \"BW\",\n CAF: \"CF\",\n CAN: \"CA\",\n CCK: \"CC\",\n CHE: \"CH\",\n CHL: \"CL\",\n CHN: \"CN\",\n CIV: \"CI\",\n CMR: \"CM\",\n COD: \"CD\",\n COG: \"CG\",\n COK: \"CK\",\n COL: \"CO\",\n COM: \"KM\",\n CPV: \"CV\",\n CRI: \"CR\",\n CUB: \"CU\",\n CUW: \"CW\",\n CXR: \"CX\",\n CYM: \"KY\",\n CYP: \"CY\",\n CZE: \"CZ\",\n DEU: \"DE\",\n DJI: \"DJ\",\n DMA: \"DM\",\n DNK: \"DK\",\n DOM: \"DO\",\n DZA: \"DZ\",\n ECU: \"EC\",\n EGY: \"EG\",\n ERI: \"ER\",\n ESH: \"EH\",\n ESP: \"ES\",\n EST: \"EE\",\n ETH: \"ET\",\n FIN: \"FI\",\n FJI: \"FJ\",\n FLK: \"FK\",\n FRA: \"FR\",\n FRO: \"FO\",\n FSM: \"FM\",\n FXX: \"FX\",\n GAB: \"GA\",\n GBR: \"GB\",\n GEO: \"GE\",\n GGY: \"GG\",\n GHA: \"GH\",\n GIB: \"GI\",\n GIN: \"GN\",\n GLP: \"GP\",\n GMB: \"GM\",\n GNB: \"GW\",\n GNQ: \"GQ\",\n GRC: \"GR\",\n GRD: \"GD\",\n GRL: \"GL\",\n GTM: \"GT\",\n GUF: \"GF\",\n GUM: \"GU\",\n GUY: \"GY\",\n HKG: \"HK\",\n HMD: \"HM\",\n HND: \"HN\",\n HRV: \"HR\",\n HTI: \"HT\",\n HUN: \"HU\",\n IDN: \"ID\",\n IMN: \"IM\",\n IND: \"IN\",\n IOT: \"IO\",\n IRL: \"IE\",\n IRN: \"IR\",\n IRQ: \"IQ\",\n ISL: \"IS\",\n ISR: \"IL\",\n ITA: \"IT\",\n JAM: \"JM\",\n JEY: \"JE\",\n JOR: \"JO\",\n JPN: \"JP\",\n KAZ: \"KZ\",\n KEN: \"KE\",\n KGZ: \"KG\",\n KHM: \"KH\",\n KIR: \"KI\",\n KNA: \"KN\",\n KOR: \"KR\",\n KWT: \"KW\",\n LAO: \"LA\",\n LBN: \"LB\",\n LBR: \"LR\",\n LBY: \"LY\",\n LCA: \"LC\",\n LIE: \"LI\",\n LKA: \"LK\",\n LSO: \"LS\",\n LTU: \"LT\",\n LUX: \"LU\",\n LVA: \"LV\",\n MAC: \"MO\",\n MAF: \"MF\",\n MAR: \"MA\",\n MCO: \"MC\",\n MDA: \"MD\",\n MDG: \"MG\",\n MDV: \"MV\",\n MEX: \"MX\",\n MHL: \"MH\",\n MKD: \"MK\",\n MLI: \"ML\",\n MLT: \"MT\",\n MMR: \"MM\",\n MNE: \"ME\",\n MNG: \"MN\",\n MNP: \"MP\",\n MOZ: \"MZ\",\n MRT: \"MR\",\n MSR: \"MS\",\n MTQ: \"MQ\",\n MUS: \"MU\",\n MWI: \"MW\",\n MYS: \"MY\",\n MYT: \"YT\",\n NAM: \"NA\",\n NCL: \"NC\",\n NER: \"NE\",\n NFK: \"NF\",\n NGA: \"NG\",\n NIC: \"NI\",\n NIU: \"NU\",\n NLD: \"NL\",\n NOR: \"NO\",\n NPL: \"NP\",\n NRU: \"NR\",\n NZL: \"NZ\",\n OMN: \"OM\",\n PAK: \"PK\",\n PAN: \"PA\",\n PCN: \"PN\",\n PER: \"PE\",\n PHL: \"PH\",\n PLW: \"PW\",\n PNG: \"PG\",\n POL: \"PL\",\n PRI: \"PR\",\n PRK: \"KP\",\n PRT: \"PT\",\n PRY: \"PY\",\n PSE: \"PS\",\n PYF: \"PF\",\n QAT: \"QA\",\n REU: \"RE\",\n ROU: \"RO\",\n RUS: \"RU\",\n RWA: \"RW\",\n SAU: \"SA\",\n SDN: \"SD\",\n SEN: \"SN\",\n SGP: \"SG\",\n SGS: \"GS\",\n SHN: \"SH\",\n SJM: \"SJ\",\n SLB: \"SB\",\n SLE: \"SL\",\n SLV: \"SV\",\n SMR: \"SM\",\n SOM: \"SO\",\n SPM: \"PM\",\n SRB: \"RS\",\n SSD: \"SS\",\n STP: \"ST\",\n SUR: \"SR\",\n SVK: \"SK\",\n SVN: \"SI\",\n SWE: \"SE\",\n SWZ: \"SZ\",\n SXM: \"SX\",\n SYC: \"SC\",\n SYR: \"SY\",\n TCA: \"TC\",\n TCD: \"TD\",\n TGO: \"TG\",\n THA: \"TH\",\n TJK: \"TJ\",\n TKL: \"TK\",\n TKM: \"TM\",\n TLS: \"TL\",\n TON: \"TO\",\n TTO: \"TT\",\n TUN: \"TN\",\n TUR: \"TR\",\n TUV: \"TV\",\n TWN: \"TW\",\n TZA: \"TZ\",\n UGA: \"UG\",\n UKR: \"UA\",\n UMI: \"UM\",\n URY: \"UY\",\n USA: \"US\",\n UZB: \"UZ\",\n VAT: \"VA\",\n VCT: \"VC\",\n VEN: \"VE\",\n VGB: \"VG\",\n VIR: \"VI\",\n VNM: \"VN\",\n VUT: \"VU\",\n WLF: \"WF\",\n WSM: \"WS\",\n YEM: \"YE\",\n ZAF: \"ZA\",\n ZMB: \"ZM\",\n ZWE: \"ZW\",\n};\n\nconst countryNamesByCodeVariable = `${variablePrefix}__countryNamesByCode`;\n\n/**\n * Returns a table of country names in the user\u2019s preferred language by ISO 3166-1 alpha-3 code.\n *\n * @param {string[]} locales - The locales for formatting the country names.\n * @param {object} options\n * @param {boolean} [options.uppercase] Whether to write the country names in all uppercase, respecting the locale\u2019s case conventions.\n */\nexport function getLocalizedCountryNames(locales, options = {}) {\n let countryNames = new Intl.DisplayNames(locales, {\n type: \"region\",\n fallback: \"none\",\n });\n return Object.fromEntries(\n Object.entries(iso3166_1_alpha_2_by_3).map((e) => {\n let name = countryNames.of(e[1]);\n if (name && options?.uppercase) {\n // Neither the upcase expression operator nor the text-transform layout property is locale-aware, so uppercase the name upfront.\n name = name\n .toLocaleUpperCase(locales)\n // Word boundaries are less discernible in uppercase text, so pad each word by an additional space.\n .replaceAll(\" \", \" \");\n }\n return [e[0], name];\n }),\n );\n}\n\n/**\n * Returns the global state that Diplomat needs to fully localize the style.\n *\n * @param {string[]} locales - The locales for formatting the country names.\n * @param {object} options\n * @param {boolean} [options.uppercaseCountryNames] Whether to write country names in all uppercase, respecting the locale\u2019s case conventions.\n */\nexport function getGlobalStateForLocalization(locales, options = {}) {\n let state = {};\n state[countryNamesByCodeVariable] = getLocalizedCountryNames(locales, {\n uppercase: options?.uppercaseCountryNames,\n });\n return state;\n}\n\n/**\n * Returns an expression that converts the given country code to a human-readable name in the user's preferred language.\n *\n * @param {Expression} code An expression that evaluates to an ISO 3166-1 alpha-3 country code.\n * @returns {Expression}\n */\nexport function getLocalizedCountryNameExpression(code) {\n return [\n \"let\",\n \"code\",\n code,\n [\n \"coalesce\",\n [\n \"get\",\n [\"var\", \"code\"],\n [\n \"coalesce\",\n [\"global-state\", countryNamesByCodeVariable],\n [\"literal\", {}],\n ],\n ],\n // Fall back to the country code in parentheses.\n [\"concat\", \"(\", [\"var\", \"code\"], \")\"],\n ],\n ];\n}\n\n/**\n * Updates each style layer's `text-field` value to match the given locales, upgrading any unlocalizable layer along the way.\n *\n * This method ugprades unlocalizable layers to localized multiline or inline labels depending on the `symbol-placement` layout property. To add a dual language label to a layer, set its `text-field` layout property manually using the `localizedNameWithLocalGloss` constant.\n *\n * If neither `options.layers` nor `options.sourceLayers` is specified, this function makes localizable any style layer that gets the feature property specified in `options.unlocalizedNameProperty`, or `name` by default.\n *\n * @param {maplibregl.Map} map - The map to localize.\n * @param {string[]} locales - The locales to insert into each layer.\n * @param {object} options\n * @param {string[]} [options.layers] - The style layers with these IDs will be made localizable.\n * @param {string[]} [options.sourceLayers] - The style layers that use these source layers will be made localizable. These are source layer IDs, not style layer IDs.\n * @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.\n * @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.\n * @param {boolean} [options.glossLocalNames] - Whether to format each label as a dual language label including a local name gloss.\n * @param {boolean} [options.uppercaseCountryNames] Whether to write country names in all uppercase, respecting the locale\u2019s case conventions.\n */\nexport function localizeStyle(map, locales = getLocales(), options = {}) {\n let style = map.getStyle();\n\n let localizedNameExpression = getLocalizedNameExpression(locales, options);\n let legacyLocalizedNameExpression = getLocalizedNameExpression(locales, {\n ...options,\n includesLegacyFields: true,\n });\n\n for (let layer of style.layers) {\n let sourceLayer = layer[\"source-layer\"];\n if (\n (!options.layers && !options.sourceLayers) ||\n options.layers?.includes(layer.id) ||\n (sourceLayer && options.sourceLayers?.includes(sourceLayer))\n ) {\n prepareLayer(\n layer,\n options?.unlocalizedNameProperty,\n options?.glossLocalNames,\n );\n }\n localizeLayer(\n layer,\n locales[0],\n localizedNameExpression,\n legacyLocalizedNameExpression,\n );\n }\n\n let countryNames = getLocalizedCountryNames(locales, {\n uppercase: options?.uppercaseCountryNames,\n });\n map.setGlobalStateProperty(countryNamesByCodeVariable, countryNames);\n\n map.setStyle(style);\n}\n\nif (typeof window !== \"undefined\") {\n window.Diplomat = {\n getGlobalStateForLocalization,\n getLanguageFromURL,\n getLocales,\n getLocalizedCountryNameExpression,\n listValuesExpression,\n localizeLayers,\n localizeStyle,\n localizedName,\n localizedNameInline,\n localizedNameWithLocalGloss,\n };\n if (\"maplibregl\" in window) {\n maplibregl.Diplomat = window.Diplomat;\n\n maplibregl.Map.prototype.localizeStyle = function (\n locales = getLocales(),\n options = {},\n ) {\n localizeStyle(this, locales, options);\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "MACA,IAAMA,EAAiB,WAQhB,SAASC,EAAmBC,EAAK,CACtC,IAAIC,EAAW,IAAI,gBAAgBD,EAAI,KAAK,OAAO,CAAC,CAAC,EAAE,IAAI,UAAU,EACrE,OAAOC,IAAa,GAAK,KAAOA,CAClC,CAKA,SAASC,EAASC,EAAO,CACvB,OAAOA,EAAM,OACX,CAACC,EAAOC,IAAU,CAAC,GAAGD,EAAO,GAAGA,EAAM,IAAKE,GAAS,CAAC,GAAGA,EAAMD,CAAK,CAAC,CAAC,EACrE,CAAC,CAAC,CAAC,CACL,CACF,CAKA,SAASE,EAAYC,EAAQ,CAC3B,OAAOA,EAAO,UAAYA,EAAO,SAAS,EAAE,SAAS,MAAM,WAAW,IAAI,CAAC,CAC7E,CAQO,SAASC,EAAuBC,EAAK,CAC1C,IAAIF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,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IA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AAO,SAAW,CAChB,8BAAAN,EACA,mBAAA9F,EACA,WAAAuB,EACA,kCAAAyE,EACA,qBAAAlC,EACA,eAAAF,EACA,cAAAsC,EACA,cAAA5B,EACA,oBAAAC,EACA,4BAAAgB,CACF,EACI,eAAgB,SAClB,WAAW,SAAW,OAAO,SAE7B,WAAW,IAAI,UAAU,cAAgB,SACvCvE,EAAUO,EAAW,EACrBG,EAAU,CAAC,EACX,CACAwE,EAAc,KAAMlF,EAASU,CAAO,CACtC",
|
|
6
|
+
"names": ["variablePrefix", "getLanguageFromURL", "url", "language", "powerset", "array", "accum", "value", "pick", "getVariants", "locale", "getRelatedLanguageTags", "tag", "maximized", "quals", "q", "tags", "locales", "l", "scoreLocale", "score", "a", "b", "validTags", "getLocales", "defaultUnlocalizedNameProperty", "getLocalizedNameExpression", "options", "localizedNameProperty", "fields", "f", "updateVariable", "letExpr", "variable", "variableNameIndex", "localizedNameVariable", "localizedCollatorVariable", "diacriticInsensitiveCollatorVariable", "replacePropertyReferences", "expression", "propertyName", "replacement", "didReplace", "arg", "idx", "newValue", "inlineSeparator", "prepareLayer", "layer", "unlocalizedNameProperty", "glossLocalNames", "textField", "symbolPlacement", "newTextField", "localizedNameWithLocalGlossCore", "localizedNameInlineCore", "localizedNameCore", "localizeLayer", "collationLocale", "localizedNameExpression", "legacyLocalizedNameExpression", "localizeLayers", "layers", "listValuesExpression", "valueList", "separator", "valueToOmit", "collapsedValueList", "valuesVariable", "omissionIndexVariable", "abridgedValuesVariable", "localizedName", "localizedNameInline", "startsWithExpression", "target", "candidatePrefix", "collator", "wordBoundaries", "overwritePrefixExpression", "newPrefix", "endsWithExpression", "candidateSuffix", "wordBoundary", "suffixStartVariable", "overwriteSuffixExpression", "newSuffix", "localizedNameListVariable", "nameListVariable", "localizedNameWithLocalGloss", "iso3166_1_alpha_2_by_3", "countryNamesByCodeVariable", "getLocalizedCountryNames", "countryNames", "e", "name", "getGlobalStateForLocalization", "state", "getLocalizedCountryNameExpression", "code", "localizeStyle", "map", "style", "sourceLayer"]
|
|
7
7
|
}
|
package/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/// A prefix that uniquely identifies this plugin, prepended onto the name of any variable generated by this plugin.
|
|
2
2
|
const variablePrefix = "diplomat";
|
|
3
3
|
|
|
4
|
+
/** @import { DataDrivenPropertyValueSpecification as PropertyValue, ExpressionSpecification as Expression, LayerSpecification, Var } from 'maplibre-gl' */
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Returns a list of languages as a comma-delimited string from the given URL hash.
|
|
8
|
+
* @param {URL | Location} url
|
|
6
9
|
*/
|
|
7
10
|
export function getLanguageFromURL(url) {
|
|
8
11
|
let language = new URLSearchParams(url.hash.substr(1)).get("language");
|
|
@@ -30,7 +33,7 @@ function getVariants(locale) {
|
|
|
30
33
|
Returns an array of the language tags related to the given language tag, sorted from most specific to least specific.
|
|
31
34
|
|
|
32
35
|
@param {string} tag - The language tag that the returned language tags are related to.
|
|
33
|
-
@returns {[
|
|
36
|
+
@returns {string[]} A sorted array of related language tags, or an empty array if `tag` is malformed.
|
|
34
37
|
*/
|
|
35
38
|
export function getRelatedLanguageTags(tag) {
|
|
36
39
|
let locale;
|
|
@@ -104,12 +107,14 @@ const defaultUnlocalizedNameProperty = "name";
|
|
|
104
107
|
* Returns a `coalesce` expression that resolves to the feature's name in a
|
|
105
108
|
* language that the user prefers.
|
|
106
109
|
*
|
|
107
|
-
* @param {[
|
|
108
|
-
* @param {
|
|
110
|
+
* @param {string[]} locales - Locales of the name fields to include.
|
|
111
|
+
* @param {object} options
|
|
112
|
+
* @param {boolean} [options.includesLegacyFields] - Whether to include the older fields
|
|
109
113
|
* that include underscores, for layers that have not transitioned to the
|
|
110
114
|
* colon syntax.
|
|
111
|
-
* @param {string} options.unlocalizedNameProperty - The name of the property holding the unlocalized name.
|
|
112
|
-
* @param {string} options.localizedNamePropertyFormat - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
115
|
+
* @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.
|
|
116
|
+
* @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
117
|
+
* @returns {Expression}
|
|
113
118
|
*/
|
|
114
119
|
export function getLocalizedNameExpression(locales, options = {}) {
|
|
115
120
|
let nameFields = [
|
|
@@ -136,7 +141,7 @@ export function getLocalizedNameExpression(locales, options = {}) {
|
|
|
136
141
|
/**
|
|
137
142
|
* Mutates a `let` expression to have a new value for the variable by the given name, binding the variable if it isn’t already bound to any value.
|
|
138
143
|
*
|
|
139
|
-
* @param {
|
|
144
|
+
* @param {PropertyValue<string> | undefined} letExpr - Expression to update.
|
|
140
145
|
* @param {string} variable - Name of the variable to set.
|
|
141
146
|
* @param {*} value - The variable's new value.
|
|
142
147
|
*/
|
|
@@ -158,10 +163,10 @@ const diacriticInsensitiveCollatorVariable = `${variablePrefix}__diacriticInsens
|
|
|
158
163
|
/**
|
|
159
164
|
* Recursively walks an expression, returning a copy of the subexpression after replacing any reference to a specific feature property with a new value in place.
|
|
160
165
|
*
|
|
161
|
-
* @param {
|
|
166
|
+
* @param {Expression} expression - The expression to transform.
|
|
162
167
|
* @param {string} propertyName - The name of the feature property to look for.
|
|
163
168
|
* @param {*} replacement - The replacement value.
|
|
164
|
-
* @returns {
|
|
169
|
+
* @returns {Expression | undefined} The same array as `expression` if `expression` referred to `propertyName`, or `undefined` if `expression` did not refer to `propertyName`.
|
|
165
170
|
*/
|
|
166
171
|
export function replacePropertyReferences(
|
|
167
172
|
expression,
|
|
@@ -197,9 +202,9 @@ const inlineSeparator = " \u2022 ";
|
|
|
197
202
|
*
|
|
198
203
|
* The transformed `text-field` property is only modified if it contains a reference to the feature property specified by `unlocalizedNameProperty`. If the layer’s `symbol-placement` layout property is set to either `line` or `line-center`, the resulting text field takes up only one line. Otherwise, the text field for a given feature may span multiple lines if its unlocalized name property is set to a list of values.
|
|
199
204
|
*
|
|
200
|
-
* @param {
|
|
201
|
-
* @param {string} unlocalizedNameProperty - The name of the feature property that holds the unlocalized name. References to this property are replaced by a more complex expression that can be localized dynamically.
|
|
202
|
-
* @param {boolean} glossLocalNames - Whether to format each label as a dual language label including a local name gloss.
|
|
205
|
+
* @param {LayerSpecification} layer - The style layer to prepare for localization.
|
|
206
|
+
* @param {string} [unlocalizedNameProperty] - The name of the feature property that holds the unlocalized name. References to this property are replaced by a more complex expression that can be localized dynamically.
|
|
207
|
+
* @param {boolean} [glossLocalNames] - Whether to format each label as a dual language label including a local name gloss.
|
|
203
208
|
*/
|
|
204
209
|
export function prepareLayer(layer, unlocalizedNameProperty, glossLocalNames) {
|
|
205
210
|
let textField = layer.layout && layer.layout["text-field"];
|
|
@@ -236,10 +241,10 @@ export function prepareLayer(layer, unlocalizedNameProperty, glossLocalNames) {
|
|
|
236
241
|
/**
|
|
237
242
|
* Updates localizable variables at the top level of the layer's `text-field` expression based on the given locales.
|
|
238
243
|
*
|
|
239
|
-
* @param {
|
|
244
|
+
* @param {LayerSpecification} layer - The style layer to localize.
|
|
240
245
|
* @param {string} collationLocale - The locale for string comparison purposes.
|
|
241
|
-
* @param {
|
|
242
|
-
* @param {
|
|
246
|
+
* @param {Expression} localizedNameExpression - An expression that produces a localized name.
|
|
247
|
+
* @param {Expression} legacyLocalizedNameExpression - An expression that produces a localized name based on legacy properties in OpenMapTiles.
|
|
243
248
|
*/
|
|
244
249
|
function localizeLayer(
|
|
245
250
|
layer,
|
|
@@ -283,10 +288,11 @@ function localizeLayer(
|
|
|
283
288
|
/**
|
|
284
289
|
* Updates localizable variables at the top level of each layer's `text-field` expression based on the given locales.
|
|
285
290
|
*
|
|
286
|
-
* @param {[
|
|
287
|
-
* @param {[
|
|
288
|
-
* @param {
|
|
289
|
-
* @param {string} options.
|
|
291
|
+
* @param {LayerSpecification[]} layers - The style layers to localize.
|
|
292
|
+
* @param {string[]} locales - The locales to insert into each layer.
|
|
293
|
+
* @param {object} options
|
|
294
|
+
* @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.
|
|
295
|
+
* @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
290
296
|
*/
|
|
291
297
|
export function localizeLayers(layers, locales = getLocales(), options = {}) {
|
|
292
298
|
let localizedNameExpression = getLocalizedNameExpression(locales, options);
|
|
@@ -305,180 +311,104 @@ export function localizeLayers(layers, locales = getLocales(), options = {}) {
|
|
|
305
311
|
}
|
|
306
312
|
|
|
307
313
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
314
|
+
* Returns an expression interpreting the given string as a list of tag values,
|
|
315
|
+
* pretty-printing the standard semicolon delimiter with the given separator.
|
|
310
316
|
*
|
|
311
|
-
*
|
|
312
|
-
* special care to minimize this limit, which exponentially increases the length
|
|
313
|
-
* of a property value in JSON. Excessive nesting causes acute performance
|
|
314
|
-
* problems when loading the style.
|
|
317
|
+
* https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator
|
|
315
318
|
*
|
|
316
319
|
* The returned expression can be complex, so use it only once within a property
|
|
317
320
|
* value. To reuse the evaluated value, bind it to a variable in a let
|
|
318
321
|
* expression.
|
|
319
322
|
*
|
|
320
|
-
* @param
|
|
321
|
-
* @param separator A string to insert
|
|
323
|
+
* @param {Expression} valueList A semicolon-delimited list of values.
|
|
324
|
+
* @param {string | Expression} separator A string to insert between each value, or an expression that
|
|
322
325
|
* evaluates to this string.
|
|
323
|
-
* @param
|
|
324
|
-
* @
|
|
326
|
+
* @param {string | Expression} [valueToOmit]
|
|
327
|
+
* @returns {Expression}
|
|
325
328
|
*/
|
|
326
|
-
function
|
|
327
|
-
|
|
328
|
-
separator
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
329
|
+
export function listValuesExpression(valueList, separator, valueToOmit) {
|
|
330
|
+
// Replace the ;; escape sequence with a placeholder sequence unlikely to
|
|
331
|
+
// legitimately occur inside a value or separator.
|
|
332
|
+
const objReplacementChar = "\x91\ufffc\x92"; // https://overpass-turbo.eu/s/1pJx
|
|
333
|
+
let escapedValueList = [
|
|
334
|
+
"join",
|
|
335
|
+
["split", valueList, ";;"],
|
|
336
|
+
objReplacementChar,
|
|
337
|
+
];
|
|
338
|
+
|
|
339
|
+
// Collapse any space following the delimiter.
|
|
340
|
+
let collapsedValueList = ["join", ["split", escapedValueList, "; "], ";"];
|
|
337
341
|
|
|
338
|
-
let
|
|
339
|
-
let
|
|
340
|
-
let
|
|
341
|
-
let needleEndVariable = `${variablePrefix}__needleEnd${iteration}`;
|
|
342
|
-
let valueVariable = `${variablePrefix}__value${iteration}`;
|
|
343
|
-
let lookaheadVariable = `${variablePrefix}__lookahead${iteration}`;
|
|
344
|
-
let nextListStartVariable = `${variablePrefix}__nextListStart${iteration}`;
|
|
342
|
+
let valuesVariable = `${variablePrefix}__values`;
|
|
343
|
+
let omissionIndexVariable = `${variablePrefix}__omissionIndex`;
|
|
344
|
+
let abridgedValuesVariable = `${variablePrefix}__abridgedValues`;
|
|
345
345
|
return [
|
|
346
346
|
"let",
|
|
347
|
-
|
|
348
|
-
["
|
|
347
|
+
valuesVariable,
|
|
348
|
+
["split", collapsedValueList, ";"],
|
|
349
349
|
[
|
|
350
|
-
"
|
|
351
|
-
|
|
352
|
-
|
|
350
|
+
"let",
|
|
351
|
+
omissionIndexVariable,
|
|
352
|
+
valueToOmit ? ["index-of", valueToOmit, ["var", valuesVariable]] : -1,
|
|
353
353
|
[
|
|
354
354
|
"let",
|
|
355
|
-
|
|
356
|
-
["slice", list, listStart, ["var", needleStartVariable]],
|
|
357
|
-
needleEndVariable,
|
|
358
|
-
["+", ["var", needleStartVariable], rawSeparator.length],
|
|
355
|
+
abridgedValuesVariable,
|
|
359
356
|
[
|
|
360
|
-
"
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
"",
|
|
367
|
-
["var", valueVariable],
|
|
368
|
-
],
|
|
357
|
+
"match",
|
|
358
|
+
["var", omissionIndexVariable],
|
|
359
|
+
-1,
|
|
360
|
+
// Nothing to elide.
|
|
361
|
+
["join", ["var", valuesVariable], separator],
|
|
362
|
+
// Produce the items before and after the omission index, eliding the value at that index.
|
|
369
363
|
[
|
|
370
|
-
"
|
|
371
|
-
lookaheadVariable,
|
|
372
|
-
// Look ahead by one character.
|
|
364
|
+
"concat",
|
|
373
365
|
[
|
|
374
|
-
"
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
366
|
+
"join",
|
|
367
|
+
[
|
|
368
|
+
"slice",
|
|
369
|
+
["var", valuesVariable],
|
|
370
|
+
0,
|
|
371
|
+
["var", omissionIndexVariable],
|
|
372
|
+
],
|
|
373
|
+
separator,
|
|
378
374
|
],
|
|
375
|
+
// Leave only a separator in place of the omitted item, unless it’s at either end of the list.
|
|
379
376
|
[
|
|
380
|
-
"
|
|
381
|
-
// Skip past the current value and semicolon for any subsequent
|
|
382
|
-
// searches.
|
|
383
|
-
nextListStartVariable,
|
|
377
|
+
"case",
|
|
384
378
|
[
|
|
385
|
-
"
|
|
386
|
-
["var",
|
|
387
|
-
// Also skip past any escaped semicolon or space padding.
|
|
379
|
+
"any",
|
|
380
|
+
["==", ["var", omissionIndexVariable], 0],
|
|
388
381
|
[
|
|
389
|
-
"
|
|
390
|
-
["var",
|
|
391
|
-
[
|
|
392
|
-
rawSeparator.length,
|
|
393
|
-
0,
|
|
382
|
+
"==",
|
|
383
|
+
["var", omissionIndexVariable],
|
|
384
|
+
["-", ["length", ["var", valuesVariable]], 1],
|
|
394
385
|
],
|
|
395
386
|
],
|
|
387
|
+
"",
|
|
388
|
+
separator,
|
|
389
|
+
],
|
|
390
|
+
[
|
|
391
|
+
"join",
|
|
396
392
|
[
|
|
397
|
-
"
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
[
|
|
401
|
-
"==",
|
|
402
|
-
["slice", list, ["var", nextListStartVariable]],
|
|
403
|
-
valueToOmit,
|
|
404
|
-
],
|
|
405
|
-
"",
|
|
406
|
-
[
|
|
407
|
-
"concat",
|
|
408
|
-
[
|
|
409
|
-
"case",
|
|
410
|
-
// If the lookahead character is another semicolon, append
|
|
411
|
-
// an unescaped semicolon.
|
|
412
|
-
["==", ["var", lookaheadVariable], rawSeparator],
|
|
413
|
-
rawSeparator,
|
|
414
|
-
// Otherwise, if the value is the value to omit, do nothing.
|
|
415
|
-
["==", ["var", valueVariable], valueToOmit],
|
|
416
|
-
"",
|
|
417
|
-
// Otherwise, append the passed-in separator.
|
|
418
|
-
separator,
|
|
419
|
-
],
|
|
420
|
-
// Recurse for the next value in the value list.
|
|
421
|
-
listValueExpression(
|
|
422
|
-
list,
|
|
423
|
-
separator,
|
|
424
|
-
valueToOmit,
|
|
425
|
-
["var", nextListStartVariable],
|
|
426
|
-
numReplacements - 1,
|
|
427
|
-
),
|
|
428
|
-
],
|
|
393
|
+
"slice",
|
|
394
|
+
["var", valuesVariable],
|
|
395
|
+
["+", ["var", omissionIndexVariable], 1],
|
|
429
396
|
],
|
|
397
|
+
separator,
|
|
430
398
|
],
|
|
431
399
|
],
|
|
432
400
|
],
|
|
401
|
+
// Unescape any escaped semicolons.
|
|
402
|
+
[
|
|
403
|
+
"join",
|
|
404
|
+
["split", ["var", abridgedValuesVariable], objReplacementChar],
|
|
405
|
+
";",
|
|
406
|
+
],
|
|
433
407
|
],
|
|
434
|
-
// No semicolons left in the string, so stop looking and append the value as is.
|
|
435
|
-
asIs,
|
|
436
408
|
],
|
|
437
409
|
];
|
|
438
410
|
}
|
|
439
411
|
|
|
440
|
-
/**
|
|
441
|
-
* Maximum number of values in a semicolon-delimited list of values.
|
|
442
|
-
*
|
|
443
|
-
* Increasing this constant deepens recursion for replacing delimiters in the
|
|
444
|
-
* list, potentially affecting style loading performance.
|
|
445
|
-
*/
|
|
446
|
-
const maxValueListLength = 3;
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Returns an expression interpreting the given string as a list of tag values,
|
|
450
|
-
* pretty-printing the standard semicolon delimiter with the given separator.
|
|
451
|
-
*
|
|
452
|
-
* https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator
|
|
453
|
-
*
|
|
454
|
-
* The returned expression can be complex, so use it only once within a property
|
|
455
|
-
* value. To reuse the evaluated value, bind it to a variable in a let
|
|
456
|
-
* expression.
|
|
457
|
-
*
|
|
458
|
-
* @param valueList A semicolon-delimited list of values.
|
|
459
|
-
* @param separator A string to insert between each value, or an expression that
|
|
460
|
-
* evaluates to this string.
|
|
461
|
-
*/
|
|
462
|
-
export function listValuesExpression(valueList, separator, valueToOmit) {
|
|
463
|
-
let maxSeparators = maxValueListLength - 1;
|
|
464
|
-
let valueListVariable = `${variablePrefix}__valueList`;
|
|
465
|
-
let valueToOmitVariable = `${variablePrefix}__valueToOmit`;
|
|
466
|
-
return [
|
|
467
|
-
"let",
|
|
468
|
-
valueListVariable,
|
|
469
|
-
valueList,
|
|
470
|
-
valueToOmitVariable,
|
|
471
|
-
valueToOmit || ";",
|
|
472
|
-
listValueExpression(
|
|
473
|
-
["var", valueListVariable],
|
|
474
|
-
separator,
|
|
475
|
-
["var", valueToOmitVariable],
|
|
476
|
-
0,
|
|
477
|
-
maxSeparators,
|
|
478
|
-
),
|
|
479
|
-
];
|
|
480
|
-
}
|
|
481
|
-
|
|
482
412
|
const localizedNameCore = listValuesExpression(
|
|
483
413
|
["var", localizedNameVariable],
|
|
484
414
|
"\n",
|
|
@@ -486,6 +416,7 @@ const localizedNameCore = listValuesExpression(
|
|
|
486
416
|
|
|
487
417
|
/**
|
|
488
418
|
* The names in the user's preferred language, each on a separate line.
|
|
419
|
+
* @type {Expression}
|
|
489
420
|
*/
|
|
490
421
|
export const localizedName = [
|
|
491
422
|
"let",
|
|
@@ -501,6 +432,7 @@ const localizedNameInlineCore = listValuesExpression(
|
|
|
501
432
|
|
|
502
433
|
/**
|
|
503
434
|
* The names in the user's preferred language, all on the same line.
|
|
435
|
+
* @type {Expression}
|
|
504
436
|
*/
|
|
505
437
|
export const localizedNameInline = [
|
|
506
438
|
"let",
|
|
@@ -664,6 +596,7 @@ const localizedNameWithLocalGlossCore = [
|
|
|
664
596
|
/**
|
|
665
597
|
* The name in the user's preferred language, followed by the name in the local
|
|
666
598
|
* language in parentheses if it differs.
|
|
599
|
+
* @type {Expression}
|
|
667
600
|
*/
|
|
668
601
|
export const localizedNameWithLocalGloss = [
|
|
669
602
|
"let",
|
|
@@ -937,8 +870,9 @@ const countryNamesByCodeVariable = `${variablePrefix}__countryNamesByCode`;
|
|
|
937
870
|
/**
|
|
938
871
|
* Returns a table of country names in the user’s preferred language by ISO 3166-1 alpha-3 code.
|
|
939
872
|
*
|
|
940
|
-
* @param {[
|
|
941
|
-
* @param {
|
|
873
|
+
* @param {string[]} locales - The locales for formatting the country names.
|
|
874
|
+
* @param {object} options
|
|
875
|
+
* @param {boolean} [options.uppercase] Whether to write the country names in all uppercase, respecting the locale’s case conventions.
|
|
942
876
|
*/
|
|
943
877
|
export function getLocalizedCountryNames(locales, options = {}) {
|
|
944
878
|
let countryNames = new Intl.DisplayNames(locales, {
|
|
@@ -963,8 +897,9 @@ export function getLocalizedCountryNames(locales, options = {}) {
|
|
|
963
897
|
/**
|
|
964
898
|
* Returns the global state that Diplomat needs to fully localize the style.
|
|
965
899
|
*
|
|
966
|
-
* @param {[
|
|
967
|
-
* @param {
|
|
900
|
+
* @param {string[]} locales - The locales for formatting the country names.
|
|
901
|
+
* @param {object} options
|
|
902
|
+
* @param {boolean} [options.uppercaseCountryNames] Whether to write country names in all uppercase, respecting the locale’s case conventions.
|
|
968
903
|
*/
|
|
969
904
|
export function getGlobalStateForLocalization(locales, options = {}) {
|
|
970
905
|
let state = {};
|
|
@@ -977,7 +912,8 @@ export function getGlobalStateForLocalization(locales, options = {}) {
|
|
|
977
912
|
/**
|
|
978
913
|
* Returns an expression that converts the given country code to a human-readable name in the user's preferred language.
|
|
979
914
|
*
|
|
980
|
-
* @param {
|
|
915
|
+
* @param {Expression} code An expression that evaluates to an ISO 3166-1 alpha-3 country code.
|
|
916
|
+
* @returns {Expression}
|
|
981
917
|
*/
|
|
982
918
|
export function getLocalizedCountryNameExpression(code) {
|
|
983
919
|
return [
|
|
@@ -1009,13 +945,14 @@ export function getLocalizedCountryNameExpression(code) {
|
|
|
1009
945
|
* If neither `options.layers` nor `options.sourceLayers` is specified, this function makes localizable any style layer that gets the feature property specified in `options.unlocalizedNameProperty`, or `name` by default.
|
|
1010
946
|
*
|
|
1011
947
|
* @param {maplibregl.Map} map - The map to localize.
|
|
1012
|
-
* @param {[
|
|
1013
|
-
* @param {
|
|
1014
|
-
* @param {[
|
|
1015
|
-
* @param {string} options.
|
|
1016
|
-
* @param {string} options.
|
|
1017
|
-
* @param {
|
|
1018
|
-
* @param {boolean} options.
|
|
948
|
+
* @param {string[]} locales - The locales to insert into each layer.
|
|
949
|
+
* @param {object} options
|
|
950
|
+
* @param {string[]} [options.layers] - The style layers with these IDs will be made localizable.
|
|
951
|
+
* @param {string[]} [options.sourceLayers] - The style layers that use these source layers will be made localizable. These are source layer IDs, not style layer IDs.
|
|
952
|
+
* @param {string} [options.unlocalizedNameProperty] - The name of the property holding the unlocalized name.
|
|
953
|
+
* @param {string} [options.localizedNamePropertyFormat] - The format of properties holding localized names, where `$1` is replaced by an IETF language tag.
|
|
954
|
+
* @param {boolean} [options.glossLocalNames] - Whether to format each label as a dual language label including a local name gloss.
|
|
955
|
+
* @param {boolean} [options.uppercaseCountryNames] Whether to write country names in all uppercase, respecting the locale’s case conventions.
|
|
1019
956
|
*/
|
|
1020
957
|
export function localizeStyle(map, locales = getLocales(), options = {}) {
|
|
1021
958
|
let style = map.getStyle();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@americana/diplomat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Internationalization plugin for MapLibre GL JS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maplibre-gl-js",
|
|
@@ -29,27 +29,27 @@
|
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist/",
|
|
32
|
-
"docs/"
|
|
33
|
-
"index.d.ts"
|
|
32
|
+
"docs/"
|
|
34
33
|
],
|
|
35
34
|
"type": "module",
|
|
36
35
|
"main": "index.js",
|
|
37
|
-
"types": "index.d.ts",
|
|
36
|
+
"types": "dist/index.d.ts",
|
|
38
37
|
"scripts": {
|
|
39
|
-
"build": "esbuild index.js --bundle --minify --sourcemap --outdir=dist",
|
|
38
|
+
"build": "tsc && esbuild index.js --bundle --minify --sourcemap --outdir=dist",
|
|
40
39
|
"clean": "shx rm -rf dist build",
|
|
41
40
|
"format": "prettier --write --list-different .",
|
|
42
41
|
"start": "shx cp -r example dist && open 'http://127.0.0.1:8000/example/#map=4/40.5/-94&language=got' && esbuild index.js --bundle --outdir=dist --servedir=dist --watch",
|
|
43
42
|
"test": "node --import ./test/setup.mjs --test 'index.spec.mjs'"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
|
-
"maplibre-gl": "^5.
|
|
45
|
+
"maplibre-gl": "^5.22.0"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@maplibre/maplibre-gl-style-spec": "^24.
|
|
50
|
-
"esbuild": "0.
|
|
48
|
+
"@maplibre/maplibre-gl-style-spec": "^24.8.1",
|
|
49
|
+
"esbuild": "0.28.0",
|
|
51
50
|
"open": "^11.0.0",
|
|
52
51
|
"prettier": "^3.6.2",
|
|
53
|
-
"shx": "^0.4.0"
|
|
52
|
+
"shx": "^0.4.0",
|
|
53
|
+
"typescript": "^6.0.2"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/index.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
declare module "@americana/diplomat" {
|
|
2
|
-
import type { Map as MaplibreMap, StyleLayer } from "maplibre-gl";
|
|
3
|
-
|
|
4
|
-
// MapLibre types expressions as `any`
|
|
5
|
-
type Expression = any;
|
|
6
|
-
|
|
7
|
-
export function getLanguageFromURL(url: URL): string | null;
|
|
8
|
-
|
|
9
|
-
export function getRelatedLanguageTags(tag: string): string[];
|
|
10
|
-
|
|
11
|
-
export function getLocales(): string[];
|
|
12
|
-
|
|
13
|
-
export function getLocalizedNameExpression(
|
|
14
|
-
locales: string[],
|
|
15
|
-
options?: {
|
|
16
|
-
includesLegacyFields?: boolean;
|
|
17
|
-
unlocalizedNameProperty?: string;
|
|
18
|
-
localizedNamePropertyFormat?: string;
|
|
19
|
-
},
|
|
20
|
-
): Expression;
|
|
21
|
-
|
|
22
|
-
export function updateVariable(
|
|
23
|
-
letExpr: Expression,
|
|
24
|
-
variable: string,
|
|
25
|
-
value: any,
|
|
26
|
-
): void;
|
|
27
|
-
|
|
28
|
-
export function replacePropertyReferences(
|
|
29
|
-
expression: Expression,
|
|
30
|
-
propertyName: string,
|
|
31
|
-
replacement: any,
|
|
32
|
-
): Expression | undefined;
|
|
33
|
-
|
|
34
|
-
export function listValuesExpression(
|
|
35
|
-
valueList: Expression,
|
|
36
|
-
separator: string | Expression,
|
|
37
|
-
valueToOmit?: Expression,
|
|
38
|
-
): Expression;
|
|
39
|
-
|
|
40
|
-
export function prepareLayer(
|
|
41
|
-
layer: StyleLayer,
|
|
42
|
-
unlocalizedNameProperty?: string,
|
|
43
|
-
glossLocalNames?: boolean,
|
|
44
|
-
): void;
|
|
45
|
-
|
|
46
|
-
export function localizeLayers(
|
|
47
|
-
layers: StyleLayer[],
|
|
48
|
-
locales?: string[],
|
|
49
|
-
options?: {
|
|
50
|
-
unlocalizedNameProperty?: string;
|
|
51
|
-
localizedNamePropertyFormat?: string;
|
|
52
|
-
},
|
|
53
|
-
): void;
|
|
54
|
-
|
|
55
|
-
export function getLocalizedCountryNames(
|
|
56
|
-
locales: string[],
|
|
57
|
-
options?: { uppercase?: boolean },
|
|
58
|
-
): Record<string, string | undefined>;
|
|
59
|
-
|
|
60
|
-
export function getGlobalStateForLocalization(
|
|
61
|
-
locales: string[],
|
|
62
|
-
options?: { uppercaseCountryNames?: boolean },
|
|
63
|
-
): Record<string, any>;
|
|
64
|
-
|
|
65
|
-
export function getLocalizedCountryNameExpression(
|
|
66
|
-
code: Expression,
|
|
67
|
-
): Expression;
|
|
68
|
-
|
|
69
|
-
export function localizeStyle(
|
|
70
|
-
map: MaplibreMap,
|
|
71
|
-
locales?: string[],
|
|
72
|
-
options?: {
|
|
73
|
-
layers?: string[];
|
|
74
|
-
sourceLayers?: string[];
|
|
75
|
-
unlocalizedNameProperty?: string;
|
|
76
|
-
localizedNamePropertyFormat?: string;
|
|
77
|
-
glossLocalNames?: boolean;
|
|
78
|
-
uppercaseCountryNames?: boolean;
|
|
79
|
-
},
|
|
80
|
-
): void;
|
|
81
|
-
|
|
82
|
-
export const localizedName: Expression;
|
|
83
|
-
export const localizedNameInline: Expression;
|
|
84
|
-
export const localizedNameWithLocalGloss: Expression;
|
|
85
|
-
}
|