@tangram.gl/basemap-layers 0.0.0 → 10.0.0-alpha.3

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.
Files changed (139) hide show
  1. package/README.md +12 -7
  2. package/THIRD-PARTY-NOTICES.md +7 -5
  3. package/dist/geojson-task-worker.js +3166 -0
  4. package/dist/geojson-task-worker.js.map +6 -0
  5. package/dist/geojson-worker.js +1089 -7
  6. package/dist/geojson-worker.js.map +3 -3
  7. package/dist/index.cjs +9588 -2093
  8. package/dist/index.cjs.map +3 -3
  9. package/dist/index.js +9599 -2090
  10. package/dist/index.js.map +3 -3
  11. package/dist/map-style.cjs +456 -20
  12. package/dist/map-style.cjs.map +3 -3
  13. package/dist/map-style.js +456 -19
  14. package/dist/map-style.js.map +2 -2
  15. package/dist/types/basemap-error.d.ts +52 -0
  16. package/dist/types/basemap-layer.d.ts +378 -25
  17. package/dist/types/basemap-protocol.d.ts +91 -0
  18. package/dist/types/basemap-request.d.ts +73 -0
  19. package/dist/types/circle-layer.d.ts +65 -8
  20. package/dist/types/color-relief-layer.d.ts +184 -0
  21. package/dist/types/dem-pixels.d.ts +40 -0
  22. package/dist/types/feature-state.d.ts +55 -0
  23. package/dist/types/fill-extrusion-lighting-extension.d.ts +1 -2
  24. package/dist/types/fill-outline-extension.d.ts +2 -3
  25. package/dist/types/fill-pattern.d.ts +35 -3
  26. package/dist/types/fill-style-extensions.d.ts +11 -59
  27. package/dist/types/geojson-resource.d.ts +18 -0
  28. package/dist/types/geojson-source.d.ts +13 -2
  29. package/dist/types/geojson-task-handler.d.ts +2 -0
  30. package/dist/types/geojson-task.d.ts +26 -0
  31. package/dist/types/geojson-tiler.d.ts +29 -2
  32. package/dist/types/geojson-worker.d.ts +5 -1
  33. package/dist/types/globe-horizon-extension.d.ts +2 -45
  34. package/dist/types/globe-layers.d.ts +141 -45
  35. package/dist/types/globe-line-angle-extension.d.ts +20 -17
  36. package/dist/types/glyph-store.d.ts +10 -1
  37. package/dist/types/heatmap-layer.d.ts +99 -0
  38. package/dist/types/hillshade-layer.d.ts +159 -27
  39. package/dist/types/icon-text-fit.d.ts +92 -0
  40. package/dist/types/image-source-layer.d.ts +142 -0
  41. package/dist/types/index.d.ts +25 -1
  42. package/dist/types/line-blur-extension.d.ts +3 -11
  43. package/dist/types/line-dash-extension.d.ts +53 -0
  44. package/dist/types/line-gradient-extension.d.ts +69 -0
  45. package/dist/types/line-metrics.d.ts +24 -0
  46. package/dist/types/line-pattern-extension.d.ts +50 -0
  47. package/dist/types/line-shape-extension.d.ts +76 -0
  48. package/dist/types/map-style-loader.d.ts +1 -1
  49. package/dist/types/map-style.d.ts +2 -2
  50. package/dist/types/mvt-label-layer.d.ts +111 -20
  51. package/dist/types/pmtiles-source.d.ts +38 -0
  52. package/dist/types/projected-background-layer.d.ts +63 -0
  53. package/dist/types/projected-bitmap-layer.d.ts +58 -0
  54. package/dist/types/projected-tile-data.d.ts +16 -0
  55. package/dist/types/projected-tile-selection.d.ts +72 -0
  56. package/dist/types/projected-tileset.d.ts +92 -0
  57. package/dist/types/projected-viewport.d.ts +76 -0
  58. package/dist/types/raster-color-extension.d.ts +4 -7
  59. package/dist/types/raster-fade.d.ts +155 -0
  60. package/dist/types/raster-tile-fingerprint.d.ts +11 -0
  61. package/dist/types/raster-tile-loader.d.ts +80 -0
  62. package/dist/types/shader-injection-plugin.d.ts +8 -0
  63. package/dist/types/source-features.d.ts +58 -0
  64. package/dist/types/source-tiles.d.ts +32 -0
  65. package/dist/types/sprite.d.ts +37 -3
  66. package/dist/types/stretch-icon-layer.d.ts +28 -0
  67. package/dist/types/style-accessor.d.ts +50 -12
  68. package/dist/types/style-expression.d.ts +22 -2
  69. package/dist/types/style-resolver.d.ts +47 -2
  70. package/dist/types/terrain-query.d.ts +39 -0
  71. package/dist/types/zoom-load-gate.d.ts +22 -0
  72. package/dist/types/zoom-paint-extension.d.ts +80 -11
  73. package/package.json +24 -21
  74. package/src/basemap-error.ts +82 -0
  75. package/src/basemap-layer.ts +1289 -101
  76. package/src/basemap-protocol.ts +353 -0
  77. package/src/basemap-request.ts +212 -0
  78. package/src/circle-layer.ts +430 -54
  79. package/src/color-relief-layer.ts +572 -0
  80. package/src/dem-pixels.ts +174 -0
  81. package/src/feature-state.ts +164 -0
  82. package/src/fill-extrusion-lighting-extension.ts +126 -9
  83. package/src/fill-outline-extension.ts +4 -4
  84. package/src/fill-pattern.ts +87 -9
  85. package/src/fill-style-extensions.ts +114 -44
  86. package/src/geojson-resource.ts +58 -0
  87. package/src/geojson-source.ts +106 -85
  88. package/src/geojson-task-handler.ts +11 -0
  89. package/src/geojson-task-worker.ts +8 -0
  90. package/src/geojson-task.ts +34 -0
  91. package/src/geojson-tiler.ts +270 -4
  92. package/src/geojson-worker.ts +36 -6
  93. package/src/globe-horizon-extension.ts +14 -4
  94. package/src/globe-layers.ts +1905 -406
  95. package/src/globe-line-angle-extension.ts +183 -23
  96. package/src/glyph-store.ts +28 -6
  97. package/src/heatmap-layer.ts +591 -0
  98. package/src/hillshade-layer.ts +309 -88
  99. package/src/icon-text-fit.ts +358 -0
  100. package/src/image-source-layer.ts +380 -0
  101. package/src/index.ts +58 -1
  102. package/src/line-blur-extension.ts +14 -12
  103. package/src/line-dash-extension.ts +303 -0
  104. package/src/line-gradient-extension.ts +191 -0
  105. package/src/line-metrics.ts +90 -0
  106. package/src/line-pattern-extension.ts +173 -0
  107. package/src/line-shape-extension.ts +272 -0
  108. package/src/map-style-loader.ts +5 -4
  109. package/src/map-style.ts +2 -1
  110. package/src/mvt-label-layer.ts +568 -144
  111. package/src/pmtiles-source.ts +276 -0
  112. package/src/projected-background-layer.ts +202 -0
  113. package/src/projected-bitmap-layer.ts +262 -0
  114. package/src/projected-tile-data.ts +132 -0
  115. package/src/projected-tile-selection.ts +605 -0
  116. package/src/projected-tileset.ts +183 -0
  117. package/src/projected-viewport.ts +254 -0
  118. package/src/raster-color-extension.ts +43 -18
  119. package/src/raster-fade.ts +319 -0
  120. package/src/raster-tile-fingerprint.ts +31 -0
  121. package/src/raster-tile-loader.ts +211 -0
  122. package/src/shader-injection-plugin.ts +25 -0
  123. package/src/source-features.ts +170 -0
  124. package/src/source-tiles.ts +102 -0
  125. package/src/sprite.ts +122 -15
  126. package/src/stretch-icon-layer.ts +87 -0
  127. package/src/style-accessor.ts +105 -17
  128. package/src/style-expression.ts +80 -3
  129. package/src/style-resolver.ts +200 -22
  130. package/src/terrain-query.ts +86 -0
  131. package/src/text-layout.ts +2 -3
  132. package/src/zoom-load-gate.ts +57 -0
  133. package/src/zoom-paint-extension.ts +245 -47
  134. package/dist/types/arabic-shaping.d.ts +0 -7
  135. package/dist/types/bidi.d.ts +0 -8
  136. package/dist/types/polylabel.d.ts +0 -17
  137. package/src/arabic-shaping.ts +0 -366
  138. package/src/bidi.ts +0 -199
  139. package/src/polylabel.ts +0 -312
@@ -1,366 +0,0 @@
1
- // tangram-layers
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // deck.gl-community
6
- // SPDX-License-Identifier: MIT AND BSD-3-Clause AND Unicode-3.0
7
- // Copyright (c) vis.gl contributors
8
- // Copyright (c) 2023, MapLibre contributors
9
-
10
- /**
11
- * @license
12
- * Portions of this file are adapted from MapLibre GL JS v6.13.0, src/symbol/arabic_shaping.ts and the
13
- * tables its build/generate-unicode-data.ts writes to src/util/unicode_properties.g.ts,
14
- * under this license:
15
- *
16
- * Copyright (c) 2023, MapLibre contributors
17
- *
18
- * All rights reserved.
19
- *
20
- * Redistribution and use in source and binary forms, with or without modification,
21
- * are permitted provided that the following conditions are met:
22
- *
23
- * * Redistributions of source code must retain the above copyright notice,
24
- * this list of conditions and the following disclaimer.
25
- * * Redistributions in binary form must reproduce the above copyright notice,
26
- * this list of conditions and the following disclaimer in the documentation
27
- * and/or other materials provided with the distribution.
28
- * * Neither the name of MapLibre GL JS nor the names of its contributors
29
- * may be used to endorse or promote products derived from this software
30
- * without specific prior written permission.
31
- *
32
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
36
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
- */
44
-
45
- /**
46
- * @license
47
- * The joining types, presentation forms and ligatures below are derived from the Unicode
48
- * Character Database 17.0.0 (extracted/DerivedJoiningType.txt and UnicodeData.txt), under
49
- * this license:
50
- *
51
- * UNICODE LICENSE V3
52
- *
53
- * COPYRIGHT AND PERMISSION NOTICE
54
- *
55
- * Copyright © 1991-2026 Unicode, Inc.
56
- *
57
- * NOTICE TO USER: Carefully read the following legal agreement. BY
58
- * DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
59
- * SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
60
- * TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
61
- * DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
62
- *
63
- * Permission is hereby granted, free of charge, to any person obtaining a
64
- * copy of data files and any associated documentation (the "Data Files") or
65
- * software and any associated documentation (the "Software") to deal in the
66
- * Data Files or Software without restriction, including without limitation
67
- * the rights to use, copy, modify, merge, publish, distribute, and/or sell
68
- * copies of the Data Files or Software, and to permit persons to whom the
69
- * Data Files or Software are furnished to do so, provided that either (a)
70
- * this copyright and permission notice appear with all copies of the Data
71
- * Files or Software, or (b) this copyright and permission notice appear in
72
- * associated Documentation.
73
- *
74
- * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
75
- * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
77
- * THIRD PARTY RIGHTS.
78
- *
79
- * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
80
- * BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
81
- * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
82
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
83
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
84
- * FILES OR SOFTWARE.
85
- *
86
- * Except as contained in this notice, the name of a copyright holder shall
87
- * not be used in advertising or otherwise to promote the sale, use or other
88
- * dealings in these Data Files or Software without prior written
89
- * authorization of the copyright holder.
90
- */
91
-
92
- // Arabic shaping as MapLibre GL JS 6.13 does it, without a right-to-left text plugin.
93
-
94
- // The joining type of each code point, as delta-encoded base-36 `start,length` ranges per type.
95
- const ENCODED_JOINING_TYPES: Record<string, string> = {
96
- C: '18g,1;g2,3;4nb,1',
97
- D: '17k,1;5,1;1,1;1,5;4,d;1,7;1,2;z,2;8,g;i,12;1,2;9,1;1,1;1,2;14,3;2,1;28,9;3,f;2,4;1,1;2,3;2,6;7a,1;2,5;1,1;g,a;5,2;2,6;1,f',
98
- R: '17m,4;1,1;1,1;5,4;l,1;14,3;1,3;g,i;12,1;2,9;1,1;1,1;2,2;1,1;o,2;2x,3;f,2;4,1;1,2;3,2;6u,j;b,1;r,3;1,1;2,2;6,1',
99
- T: '174,b;1,1;1a,l;g,1;2t,7;2,6;2,2;1,4;bt,9;16,o;1,t;1clb,1'
100
- };
101
-
102
- /**
103
- * Each Arabic letter's Presentation Forms code points, as `[isolated, final, initial, medial]`.
104
- * A shape the letter is not written in is 0.
105
- */
106
- const PRESENTATION_FORMS: Record<number, [number, number, number, number]> = {
107
- 1569: [65152, 0, 0, 0],
108
- 1570: [65153, 65154, 0, 0],
109
- 1571: [65155, 65156, 0, 0],
110
- 1572: [65157, 65158, 0, 0],
111
- 1573: [65159, 65160, 0, 0],
112
- 1574: [65161, 65162, 65163, 65164],
113
- 1575: [65165, 65166, 0, 0],
114
- 1576: [65167, 65168, 65169, 65170],
115
- 1577: [65171, 65172, 0, 0],
116
- 1578: [65173, 65174, 65175, 65176],
117
- 1579: [65177, 65178, 65179, 65180],
118
- 1580: [65181, 65182, 65183, 65184],
119
- 1581: [65185, 65186, 65187, 65188],
120
- 1582: [65189, 65190, 65191, 65192],
121
- 1583: [65193, 65194, 0, 0],
122
- 1584: [65195, 65196, 0, 0],
123
- 1585: [65197, 65198, 0, 0],
124
- 1586: [65199, 65200, 0, 0],
125
- 1587: [65201, 65202, 65203, 65204],
126
- 1588: [65205, 65206, 65207, 65208],
127
- 1589: [65209, 65210, 65211, 65212],
128
- 1590: [65213, 65214, 65215, 65216],
129
- 1591: [65217, 65218, 65219, 65220],
130
- 1592: [65221, 65222, 65223, 65224],
131
- 1593: [65225, 65226, 65227, 65228],
132
- 1594: [65229, 65230, 65231, 65232],
133
- 1601: [65233, 65234, 65235, 65236],
134
- 1602: [65237, 65238, 65239, 65240],
135
- 1603: [65241, 65242, 65243, 65244],
136
- 1604: [65245, 65246, 65247, 65248],
137
- 1605: [65249, 65250, 65251, 65252],
138
- 1606: [65253, 65254, 65255, 65256],
139
- 1607: [65257, 65258, 65259, 65260],
140
- 1608: [65261, 65262, 0, 0],
141
- 1609: [65263, 65264, 64488, 64489],
142
- 1610: [65265, 65266, 65267, 65268],
143
- 1611: [65136, 0, 0, 65137],
144
- 1612: [65138, 0, 0, 0],
145
- 1613: [65140, 0, 0, 0],
146
- 1614: [65142, 0, 0, 65143],
147
- 1615: [65144, 0, 0, 65145],
148
- 1616: [65146, 0, 0, 65147],
149
- 1617: [65148, 0, 0, 65149],
150
- 1618: [65150, 0, 0, 65151],
151
- 1649: [64336, 64337, 0, 0],
152
- 1655: [64477, 0, 0, 0],
153
- 1657: [64358, 64359, 64360, 64361],
154
- 1658: [64350, 64351, 64352, 64353],
155
- 1659: [64338, 64339, 64340, 64341],
156
- 1662: [64342, 64343, 64344, 64345],
157
- 1663: [64354, 64355, 64356, 64357],
158
- 1664: [64346, 64347, 64348, 64349],
159
- 1667: [64374, 64375, 64376, 64377],
160
- 1668: [64370, 64371, 64372, 64373],
161
- 1670: [64378, 64379, 64380, 64381],
162
- 1671: [64382, 64383, 64384, 64385],
163
- 1672: [64392, 64393, 0, 0],
164
- 1676: [64388, 64389, 0, 0],
165
- 1677: [64386, 64387, 0, 0],
166
- 1678: [64390, 64391, 0, 0],
167
- 1681: [64396, 64397, 0, 0],
168
- 1688: [64394, 64395, 0, 0],
169
- 1700: [64362, 64363, 64364, 64365],
170
- 1702: [64366, 64367, 64368, 64369],
171
- 1705: [64398, 64399, 64400, 64401],
172
- 1709: [64467, 64468, 64469, 64470],
173
- 1711: [64402, 64403, 64404, 64405],
174
- 1713: [64410, 64411, 64412, 64413],
175
- 1715: [64406, 64407, 64408, 64409],
176
- 1722: [64414, 64415, 0, 0],
177
- 1723: [64416, 64417, 64418, 64419],
178
- 1726: [64426, 64427, 64428, 64429],
179
- 1728: [64420, 64421, 0, 0],
180
- 1729: [64422, 64423, 64424, 64425],
181
- 1733: [64480, 64481, 0, 0],
182
- 1734: [64473, 64474, 0, 0],
183
- 1735: [64471, 64472, 0, 0],
184
- 1736: [64475, 64476, 0, 0],
185
- 1737: [64482, 64483, 0, 0],
186
- 1739: [64478, 64479, 0, 0],
187
- 1740: [64508, 64509, 64510, 64511],
188
- 1744: [64484, 64485, 64486, 64487],
189
- 1746: [64430, 64431, 0, 0],
190
- 1747: [64432, 64433, 0, 0]
191
- };
192
-
193
- /** The lam-alef ligatures, keyed by the pair of letters they replace, as `[isolated, final]`. */
194
- const LIGATURES: Record<string, [number, number]> = {
195
- '\u0644\u0622': [65269, 65270],
196
- '\u0644\u0623': [65271, 65272],
197
- '\u0644\u0625': [65273, 65274],
198
- '\u0644\u0627': [65275, 65276]
199
- };
200
-
201
- /**
202
- * How a character joins to the ones beside it. `D` joins on both sides, `R` only to the character
203
- * before it, `L` only to the one after it, `C` joins without being written itself, `T` is skipped
204
- * over entirely, and `U` does not join at all.
205
- */
206
- type JoiningType = 'R' | 'L' | 'D' | 'C' | 'U' | 'T';
207
-
208
- /** Lam, the only letter written as a ligature with the letter after it. */
209
- const LAM = 0x0644;
210
-
211
- /**
212
- * The blocks Arabic is written from, and the two blocks of shapes this rewrites letters into, so
213
- * that text already shaped is looked at again.
214
- */
215
- const ARABIC = /[؀-ۿݐ-ݿࡰ-࢟ࢠ-ࣿﭐ-﷿ﹰ-]/;
216
-
217
- /** The shape a letter takes, as an index into its entry in `PRESENTATION_FORMS`. */
218
- const ISOLATED = 0;
219
- const FINAL = 1;
220
- const INITIAL = 2;
221
- const MEDIAL = 3;
222
- type Form = typeof ISOLATED | typeof FINAL | typeof INITIAL | typeof MEDIAL;
223
-
224
- /** One character of the text, with the shape the joining rules gave it. */
225
- type ShapedCharacter = {
226
- codePoint: number;
227
- type: JoiningType;
228
- form: Form | null;
229
- };
230
-
231
- /** Unpacks the delta-encoded ranges of one joining type into the code points they stand for. */
232
- function decodeRanges(encoded: string, type: JoiningType, into: Map<number, JoiningType>): void {
233
- let previousEnd = 0;
234
- for (const range of encoded.split(';')) {
235
- const [delta, length] = range.split(',').map(value => parseInt(value, 36));
236
- const start = previousEnd + delta;
237
- for (let codePoint = start; codePoint < start + length; codePoint++) {
238
- into.set(codePoint, type);
239
- }
240
- previousEnd = start + length;
241
- }
242
- }
243
-
244
- let joiningTypes: Map<number, JoiningType> | null = null;
245
-
246
- /** The joining type of a code point; anything the Unicode database gives none stands alone. */
247
- function joiningType(codePoint: number): JoiningType {
248
- if (!joiningTypes) {
249
- joiningTypes = new Map();
250
- for (const [type, encoded] of Object.entries(ENCODED_JOINING_TYPES)) {
251
- decodeRanges(encoded, type as JoiningType, joiningTypes);
252
- }
253
- }
254
- return joiningTypes.get(codePoint) ?? 'U';
255
- }
256
-
257
- /** Whether the character before this one reaches forward to touch it. */
258
- function joinsForward(type: JoiningType): boolean {
259
- return type === 'D' || type === 'L' || type === 'C';
260
- }
261
-
262
- /** Whether the character after this one reaches back to touch it. */
263
- function joinsBackward(type: JoiningType): boolean {
264
- return type === 'D' || type === 'R' || type === 'C';
265
- }
266
-
267
- /**
268
- * The shape a letter takes given what it can reach on either side. A letter that never joins is
269
- * left as it was written.
270
- */
271
- function formFor(type: JoiningType, joinedBefore: boolean, joinedAfter: boolean): Form | null {
272
- if (type === 'D') {
273
- if (joinedBefore && joinedAfter) return MEDIAL;
274
- if (joinedBefore) return FINAL;
275
- if (joinedAfter) return INITIAL;
276
- return ISOLATED;
277
- }
278
- if (type === 'R') return joinedBefore ? FINAL : ISOLATED;
279
- if (type === 'L') return joinedAfter ? INITIAL : ISOLATED;
280
- return null;
281
- }
282
-
283
- /**
284
- * Works out the shape of every letter. Transparent characters (vowel points) are looked straight
285
- * through, so a letter joins to its neighbour across them.
286
- */
287
- function assignLetterForms(characters: ShapedCharacter[]): void {
288
- const visible = characters.filter(character => character.type !== 'T');
289
- for (let i = 0; i < visible.length; i++) {
290
- const joinedBefore = i > 0 && joinsForward(visible[i - 1].type);
291
- const joinedAfter = i + 1 < visible.length && joinsBackward(visible[i + 1].type);
292
- visible[i].form = formFor(visible[i].type, joinedBefore, joinedAfter);
293
- }
294
- }
295
-
296
- /** Gives each vowel point the shape it takes over its letter: medial where the letter joins on. */
297
- function assignMarkForms(characters: ShapedCharacter[]): void {
298
- let letterJoinsForward = false;
299
- for (const character of characters) {
300
- if (character.type === 'T') {
301
- character.form = letterJoinsForward ? MEDIAL : ISOLATED;
302
- } else {
303
- letterJoinsForward = character.form === INITIAL || character.form === MEDIAL;
304
- }
305
- }
306
- }
307
-
308
- /**
309
- * Replaces each lam followed by an alef with their ligature: final when the lam joined the letter
310
- * before it, isolated otherwise. Vowel points between the two follow the ligature.
311
- */
312
- function applyLigatures(characters: ShapedCharacter[]): ShapedCharacter[] {
313
- const result: ShapedCharacter[] = [];
314
- for (let i = 0; i < characters.length; i++) {
315
- const lam = characters[i];
316
- if (lam.codePoint !== LAM) {
317
- result.push(lam);
318
- continue;
319
- }
320
- let next = i + 1;
321
- while (next < characters.length && characters[next].type === 'T') next++;
322
- const alef = characters[next];
323
- const ligature = alef && LIGATURES[String.fromCodePoint(LAM, alef.codePoint)];
324
- if (!ligature) {
325
- result.push(lam);
326
- continue;
327
- }
328
- const joinedBefore = lam.form === MEDIAL || lam.form === FINAL;
329
- result.push({codePoint: ligature[joinedBefore ? 1 : 0], type: 'R', form: ISOLATED});
330
- // One at a time: spreading a long run of marks from tile text would overflow the call stack.
331
- for (let k = i + 1; k < next; k++) {
332
- result.push(characters[k]);
333
- }
334
- i = next;
335
- }
336
- return result;
337
- }
338
-
339
- /** The presentation form of a character, or the character itself where there is none. */
340
- function toPresentationForm(character: ShapedCharacter): number {
341
- if (character.form === null) return character.codePoint;
342
- const forms = PRESENTATION_FORMS[character.codePoint];
343
- if (!forms) return character.codePoint;
344
- return forms[character.form] || forms[ISOLATED] || character.codePoint;
345
- }
346
-
347
- /**
348
- * Rewrites Arabic letters as the shape they take in their word, named by their Arabic
349
- * Presentation Forms code points (U+FB50–FDFF, U+FE70–FEFF), with lam-alef ligatures, as MapLibre
350
- * GL JS does: glyphs are drawn one code point at a time, so the contextual shape has to be chosen
351
- * before glyphs are looked up. Text with no Arabic in it is returned unchanged.
352
- */
353
- export function applyArabicShaping(text: string): string {
354
- if (!ARABIC.test(text)) {
355
- return text;
356
- }
357
- const characters = Array.from(text, character => {
358
- const codePoint = character.codePointAt(0)!;
359
- return {codePoint, type: joiningType(codePoint), form: null} as ShapedCharacter;
360
- });
361
- assignLetterForms(characters);
362
- assignMarkForms(characters);
363
- return applyLigatures(characters)
364
- .map(character => String.fromCodePoint(toPresentationForm(character)))
365
- .join('');
366
- }
package/src/bidi.ts DELETED
@@ -1,199 +0,0 @@
1
- // tangram-layers
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // deck.gl-community
6
- // SPDX-License-Identifier: MIT AND BSD-3-Clause
7
- // Copyright (c) vis.gl contributors
8
- // Copyright (c) 2023, MapLibre contributors
9
-
10
- /**
11
- * @license
12
- * Portions of this file are adapted from MapLibre GL JS v6.13.0, src/symbol/bidi.ts,
13
- * under this license:
14
- *
15
- * Copyright (c) 2023, MapLibre contributors
16
- *
17
- * All rights reserved.
18
- *
19
- * Redistribution and use in source and binary forms, with or without modification,
20
- * are permitted provided that the following conditions are met:
21
- *
22
- * * Redistributions of source code must retain the above copyright notice,
23
- * this list of conditions and the following disclaimer.
24
- * * Redistributions in binary form must reproduce the above copyright notice,
25
- * this list of conditions and the following disclaimer in the documentation
26
- * and/or other materials provided with the distribution.
27
- * * Neither the name of MapLibre GL JS nor the names of its contributors
28
- * may be used to endorse or promote products derived from this software
29
- * without specific prior written permission.
30
- *
31
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
- */
43
-
44
- // Reordering of bidirectional text as MapLibre GL JS 6.13 does it without a right-to-left text
45
- // plugin, on the same Unicode Bidirectional Algorithm implementation: the bidi-js package (MIT),
46
- // a dependency, which holds its own Unicode data.
47
- import bidiFactory, {type Bidi, type BidiCharTypeName} from 'bidi-js';
48
-
49
- let bidiInstance: Bidi | null = null;
50
-
51
- /** bidi-js, built on first use: it unpacks its Unicode data when built. */
52
- function getBidi(): Bidi {
53
- bidiInstance ||= bidiFactory();
54
- return bidiInstance;
55
- }
56
-
57
- /** Characters that steer the bidirectional algorithm, which no font draws: dropped once used. */
58
- const BIDI_CONTROLS = /[؜‎‏‪-‮⁦-⁩]/;
59
-
60
- /** Character types rule L1 resets to the paragraph's direction at the end of a line. */
61
- const NEUTRAL_AT_END_OF_LINE = new Set<BidiCharTypeName>(['WS', 'FSI', 'LRI', 'RLI', 'PDI']);
62
-
63
- /** Character types rule L1 resets wherever they appear, with the whitespace before them. */
64
- const ALWAYS_RESET = new Set<BidiCharTypeName>(['S', 'B']);
65
-
66
- /** Character types that make text need reordering: right-to-left letters and overrides. */
67
- const RIGHT_TO_LEFT = new Set<BidiCharTypeName>(['R', 'AL', 'RLE', 'RLO', 'RLI']);
68
-
69
- /** One grapheme cluster of a line, with its embedding level. */
70
- type Cluster = {text: string; level: number};
71
-
72
- let graphemeSegmenter: {segment(text: string): Iterable<{segment: string}>} | null | undefined;
73
-
74
- /**
75
- * Splits text into grapheme clusters, or code points where `Intl.Segmenter` is missing, so that a
76
- * letter and the marks written on it move together when a right-to-left run is reversed (rule L3).
77
- */
78
- function toGraphemes(text: string): string[] {
79
- if (graphemeSegmenter === undefined) {
80
- const Segmenter = (Intl as any)?.Segmenter;
81
- graphemeSegmenter = Segmenter ? new Segmenter(undefined, {granularity: 'grapheme'}) : null;
82
- }
83
- return graphemeSegmenter
84
- ? Array.from(graphemeSegmenter.segment(text), ({segment}) => segment)
85
- : Array.from(text);
86
- }
87
-
88
- /** Whether `text` has right-to-left characters, so that it needs {@link processBidirectionalText}. */
89
- export function containsRightToLeftText(text: string): boolean {
90
- // Latin text, the common case, skips the lookups.
91
- if (!/[^\u0000-ɏ]/.test(text)) {
92
- return false;
93
- }
94
- const bidi = getBidi();
95
- for (const character of text) {
96
- if (RIGHT_TO_LEFT.has(bidi.getBidiCharTypeName(character))) {
97
- return true;
98
- }
99
- }
100
- return false;
101
- }
102
-
103
- /** Rule L1: whitespace at the end of a line, and separators, take the paragraph's direction. */
104
- function resetTrailingNeutrals(clusters: Cluster[], paragraphLevel: number): void {
105
- const bidi = getBidi();
106
- let trailing = true;
107
- for (let i = clusters.length - 1; i >= 0; i--) {
108
- const type = bidi.getBidiCharTypeName(clusters[i].text[0]);
109
- if (ALWAYS_RESET.has(type)) {
110
- clusters[i].level = paragraphLevel;
111
- trailing = true;
112
- } else if (trailing && NEUTRAL_AT_END_OF_LINE.has(type)) {
113
- clusters[i].level = paragraphLevel;
114
- } else {
115
- trailing = false;
116
- }
117
- }
118
- }
119
-
120
- /**
121
- * Rule L2: from the deepest level down to the shallowest odd one, reverses every run at that level
122
- * or deeper.
123
- */
124
- function reorder(clusters: Cluster[], paragraphLevel: number): Cluster[] {
125
- let highest = paragraphLevel;
126
- let lowestOdd = Infinity;
127
- for (const {level} of clusters) {
128
- if (level > highest) highest = level;
129
- if ((level | 1) < lowestOdd) lowestOdd = level | 1;
130
- }
131
- const ordered = clusters.slice();
132
- for (let level = highest; level >= lowestOdd; level--) {
133
- for (let start = 0; start < ordered.length; start++) {
134
- if (ordered[start].level < level) continue;
135
- let end = start;
136
- while (end + 1 < ordered.length && ordered[end + 1].level >= level) end++;
137
- for (let i = start, j = end; i < j; i++, j--) {
138
- [ordered[i], ordered[j]] = [ordered[j], ordered[i]];
139
- }
140
- start = end;
141
- }
142
- }
143
- return ordered;
144
- }
145
-
146
- /** Puts the code units `[start, end)` of `text` into visual order, dropping bidi controls. */
147
- function reorderLine(
148
- text: string,
149
- levels: Uint8Array,
150
- paragraphLevel: number,
151
- start: number,
152
- end: number
153
- ): string {
154
- const bidi = getBidi();
155
- const clusters: Cluster[] = [];
156
- let index = start;
157
- for (const cluster of toGraphemes(text.slice(start, end))) {
158
- clusters.push({text: cluster, level: levels[index]});
159
- index += cluster.length;
160
- }
161
- resetTrailingNeutrals(clusters, paragraphLevel);
162
- let reordered = '';
163
- for (const cluster of reorder(clusters, paragraphLevel)) {
164
- if (BIDI_CONTROLS.test(cluster.text)) continue;
165
- // A bracket read right to left is drawn as its mirror image.
166
- reordered +=
167
- cluster.level % 2 ? (bidi.getMirroredCharacter(cluster.text) ?? cluster.text) : cluster.text;
168
- }
169
- return reordered;
170
- }
171
-
172
- /**
173
- * Puts text into the order it is drawn, broken into lines, as MapLibre GL JS does: the embedding
174
- * levels are found for the whole label, then each line is reordered on its own. A label is broken
175
- * at `lineBreakPoints` (UTF-16 code unit offsets) and wherever a paragraph ends.
176
- */
177
- export function processBidirectionalText(text: string, lineBreakPoints: number[]): string[] {
178
- const {levels, paragraphs} = getBidi().getEmbeddingLevels(text);
179
- const inside = lineBreakPoints
180
- .concat(paragraphs.map(paragraph => paragraph.start))
181
- .filter(point => point > 0 && point < text.length);
182
- const bounds = [...new Set([0, ...inside, text.length])].sort((a, b) => a - b);
183
- const lines: string[] = [];
184
- // The bounds and the paragraphs are both in text order, so one pass finds each line's paragraph
185
- // (tile text is untrusted: a label of many short lines must not cost lines times paragraphs).
186
- let paragraph = 0;
187
- for (let i = 0; i + 1 < bounds.length; i++) {
188
- const start = bounds[i];
189
- while (paragraph < paragraphs.length && paragraphs[paragraph].end < start) {
190
- paragraph++;
191
- }
192
- const paragraphLevel =
193
- paragraph < paragraphs.length && paragraphs[paragraph].start <= start
194
- ? paragraphs[paragraph].level
195
- : 0;
196
- lines.push(reorderLine(text, levels, paragraphLevel, start, bounds[i + 1]));
197
- }
198
- return lines;
199
- }