@react-x11/components 0.4.0 → 0.6.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.
Files changed (248) hide show
  1. package/README.md +143 -8
  2. package/dist/charts/components.d.ts +3 -1
  3. package/dist/charts/components.d.ts.map +1 -1
  4. package/dist/charts/components.js +8 -4
  5. package/dist/charts/components.js.map +1 -1
  6. package/dist/charts/node.d.ts +13 -6
  7. package/dist/charts/node.d.ts.map +1 -1
  8. package/dist/charts/node.js +75 -24
  9. package/dist/charts/node.js.map +1 -1
  10. package/dist/charts/render.d.ts +4 -0
  11. package/dist/charts/render.d.ts.map +1 -1
  12. package/dist/charts/render.js +11 -6
  13. package/dist/charts/render.js.map +1 -1
  14. package/dist/code-editor/node.d.ts +47 -16
  15. package/dist/code-editor/node.d.ts.map +1 -1
  16. package/dist/code-editor/node.js +121 -51
  17. package/dist/code-editor/node.js.map +1 -1
  18. package/dist/flow/draw.d.ts +19 -1
  19. package/dist/flow/draw.d.ts.map +1 -1
  20. package/dist/flow/draw.js +64 -35
  21. package/dist/flow/draw.js.map +1 -1
  22. package/dist/flow/index.d.ts.map +1 -1
  23. package/dist/flow/index.js +24 -8
  24. package/dist/flow/index.js.map +1 -1
  25. package/dist/flow/model.d.ts +4 -2
  26. package/dist/flow/model.d.ts.map +1 -1
  27. package/dist/flow/model.js +4 -2
  28. package/dist/flow/model.js.map +1 -1
  29. package/dist/flow/node.d.ts +40 -9
  30. package/dist/flow/node.d.ts.map +1 -1
  31. package/dist/flow/node.js +142 -53
  32. package/dist/flow/node.js.map +1 -1
  33. package/dist/flow/types.d.ts +46 -21
  34. package/dist/flow/types.d.ts.map +1 -1
  35. package/dist/formula/index.d.ts +4 -2
  36. package/dist/formula/index.d.ts.map +1 -1
  37. package/dist/formula/index.js.map +1 -1
  38. package/dist/formula/node.d.ts +5 -1
  39. package/dist/formula/node.d.ts.map +1 -1
  40. package/dist/formula/node.js +19 -3
  41. package/dist/formula/node.js.map +1 -1
  42. package/dist/html/controls.d.ts +4 -1
  43. package/dist/html/controls.d.ts.map +1 -1
  44. package/dist/html/controls.js.map +1 -1
  45. package/dist/html/css/cascade.d.ts +11 -5
  46. package/dist/html/css/cascade.d.ts.map +1 -1
  47. package/dist/html/css/cascade.js +18 -8
  48. package/dist/html/css/cascade.js.map +1 -1
  49. package/dist/html/css/parse.d.ts +15 -10
  50. package/dist/html/css/parse.d.ts.map +1 -1
  51. package/dist/html/css/parse.js +41 -16
  52. package/dist/html/css/parse.js.map +1 -1
  53. package/dist/html/css/style.d.ts +3 -0
  54. package/dist/html/css/style.d.ts.map +1 -1
  55. package/dist/html/css/style.js +3 -1
  56. package/dist/html/css/style.js.map +1 -1
  57. package/dist/html/css/values.d.ts +14 -1
  58. package/dist/html/css/values.d.ts.map +1 -1
  59. package/dist/html/css/values.js +11 -8
  60. package/dist/html/css/values.js.map +1 -1
  61. package/dist/html/index.d.ts.map +1 -1
  62. package/dist/html/index.js +1 -0
  63. package/dist/html/index.js.map +1 -1
  64. package/dist/html/layout/boxes.d.ts +12 -5
  65. package/dist/html/layout/boxes.d.ts.map +1 -1
  66. package/dist/html/layout/boxes.js +7 -4
  67. package/dist/html/layout/boxes.js.map +1 -1
  68. package/dist/html/layout/inline.d.ts.map +1 -1
  69. package/dist/html/layout/inline.js +22 -1
  70. package/dist/html/layout/inline.js.map +1 -1
  71. package/dist/html/node.d.ts +22 -8
  72. package/dist/html/node.d.ts.map +1 -1
  73. package/dist/html/node.js +97 -15
  74. package/dist/html/node.js.map +1 -1
  75. package/dist/html/paint.d.ts +3 -0
  76. package/dist/html/paint.d.ts.map +1 -1
  77. package/dist/html/paint.js +2 -2
  78. package/dist/html/paint.js.map +1 -1
  79. package/dist/index.d.ts +8 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +21 -0
  82. package/dist/index.js.map +1 -1
  83. package/dist/maps/clip.d.ts +43 -0
  84. package/dist/maps/clip.d.ts.map +1 -0
  85. package/dist/maps/clip.js +171 -0
  86. package/dist/maps/clip.js.map +1 -0
  87. package/dist/maps/gzip.d.ts +15 -0
  88. package/dist/maps/gzip.d.ts.map +1 -0
  89. package/dist/maps/gzip.js +56 -0
  90. package/dist/maps/gzip.js.map +1 -0
  91. package/dist/maps/index.d.ts +55 -0
  92. package/dist/maps/index.d.ts.map +1 -0
  93. package/dist/maps/index.js +141 -0
  94. package/dist/maps/index.js.map +1 -0
  95. package/dist/maps/labels.d.ts +123 -0
  96. package/dist/maps/labels.d.ts.map +1 -0
  97. package/dist/maps/labels.js +323 -0
  98. package/dist/maps/labels.js.map +1 -0
  99. package/dist/maps/mvt.d.ts +244 -0
  100. package/dist/maps/mvt.d.ts.map +1 -0
  101. package/dist/maps/mvt.js +820 -0
  102. package/dist/maps/mvt.js.map +1 -0
  103. package/dist/maps/node.d.ts +278 -0
  104. package/dist/maps/node.d.ts.map +1 -0
  105. package/dist/maps/node.js +1459 -0
  106. package/dist/maps/node.js.map +1 -0
  107. package/dist/maps/overlay.d.ts +157 -0
  108. package/dist/maps/overlay.d.ts.map +1 -0
  109. package/dist/maps/overlay.js +472 -0
  110. package/dist/maps/overlay.js.map +1 -0
  111. package/dist/maps/paint.d.ts +226 -0
  112. package/dist/maps/paint.d.ts.map +1 -0
  113. package/dist/maps/paint.js +705 -0
  114. package/dist/maps/paint.js.map +1 -0
  115. package/dist/maps/proj.d.ts +281 -0
  116. package/dist/maps/proj.d.ts.map +1 -0
  117. package/dist/maps/proj.js +451 -0
  118. package/dist/maps/proj.js.map +1 -0
  119. package/dist/maps/sources.d.ts +256 -0
  120. package/dist/maps/sources.d.ts.map +1 -0
  121. package/dist/maps/sources.js +210 -0
  122. package/dist/maps/sources.js.map +1 -0
  123. package/dist/maps/style.d.ts +141 -0
  124. package/dist/maps/style.d.ts.map +1 -0
  125. package/dist/maps/style.js +147 -0
  126. package/dist/maps/style.js.map +1 -0
  127. package/dist/maps/styles.d.ts +82 -0
  128. package/dist/maps/styles.d.ts.map +1 -0
  129. package/dist/maps/styles.js +898 -0
  130. package/dist/maps/styles.js.map +1 -0
  131. package/dist/maps/tiles.d.ts +283 -0
  132. package/dist/maps/tiles.d.ts.map +1 -0
  133. package/dist/maps/tiles.js +469 -0
  134. package/dist/maps/tiles.js.map +1 -0
  135. package/dist/maps/types.d.ts +244 -0
  136. package/dist/maps/types.d.ts.map +1 -0
  137. package/dist/maps/types.js +2 -0
  138. package/dist/maps/types.js.map +1 -0
  139. package/dist/markdown/ast.d.ts +80 -6
  140. package/dist/markdown/ast.d.ts.map +1 -1
  141. package/dist/markdown/ast.js +13 -4
  142. package/dist/markdown/ast.js.map +1 -1
  143. package/dist/markdown/expressions.d.ts +27 -0
  144. package/dist/markdown/expressions.d.ts.map +1 -0
  145. package/dist/markdown/expressions.js +203 -0
  146. package/dist/markdown/expressions.js.map +1 -0
  147. package/dist/markdown/index.d.ts +61 -2
  148. package/dist/markdown/index.d.ts.map +1 -1
  149. package/dist/markdown/index.js +101 -2
  150. package/dist/markdown/index.js.map +1 -1
  151. package/dist/markdown/parse.d.ts +1 -1
  152. package/dist/markdown/parse.d.ts.map +1 -1
  153. package/dist/markdown/parse.js +163 -15
  154. package/dist/markdown/parse.js.map +1 -1
  155. package/dist/markdown/spans.d.ts.map +1 -1
  156. package/dist/markdown/spans.js +4 -0
  157. package/dist/markdown/spans.js.map +1 -1
  158. package/dist/markdown/tags.d.ts +35 -0
  159. package/dist/markdown/tags.d.ts.map +1 -0
  160. package/dist/markdown/tags.js +213 -0
  161. package/dist/markdown/tags.js.map +1 -0
  162. package/dist/reorder/hx.d.ts +18 -0
  163. package/dist/reorder/hx.d.ts.map +1 -0
  164. package/dist/reorder/hx.js +10 -0
  165. package/dist/reorder/hx.js.map +1 -0
  166. package/dist/reorder/index.d.ts +314 -0
  167. package/dist/reorder/index.d.ts.map +1 -0
  168. package/dist/reorder/index.js +1539 -0
  169. package/dist/reorder/index.js.map +1 -0
  170. package/dist/reorder/model.d.ts +107 -0
  171. package/dist/reorder/model.d.ts.map +1 -0
  172. package/dist/reorder/model.js +162 -0
  173. package/dist/reorder/model.js.map +1 -0
  174. package/dist/richtext/node.d.ts +15 -5
  175. package/dist/richtext/node.d.ts.map +1 -1
  176. package/dist/richtext/node.js +40 -11
  177. package/dist/richtext/node.js.map +1 -1
  178. package/dist/richtext/runs.d.ts +35 -13
  179. package/dist/richtext/runs.d.ts.map +1 -1
  180. package/dist/richtext/runs.js +83 -27
  181. package/dist/richtext/runs.js.map +1 -1
  182. package/dist/tabs/index.d.ts +17 -0
  183. package/dist/tabs/index.d.ts.map +1 -1
  184. package/dist/tabs/index.js +849 -186
  185. package/dist/tabs/index.js.map +1 -1
  186. package/dist/terminal/vt/fonts.d.ts +45 -15
  187. package/dist/terminal/vt/fonts.d.ts.map +1 -1
  188. package/dist/terminal/vt/fonts.js +89 -19
  189. package/dist/terminal/vt/fonts.js.map +1 -1
  190. package/dist/terminal/vt/node.d.ts +42 -0
  191. package/dist/terminal/vt/node.d.ts.map +1 -1
  192. package/dist/terminal/vt/node.js +95 -11
  193. package/dist/terminal/vt/node.js.map +1 -1
  194. package/dist/terminal/vt/renderer.d.ts.map +1 -1
  195. package/dist/terminal/vt/renderer.js +13 -3
  196. package/dist/terminal/vt/renderer.js.map +1 -1
  197. package/package.json +14 -3
  198. package/src/charts/components.ts +14 -7
  199. package/src/charts/node.ts +81 -26
  200. package/src/charts/render.ts +16 -6
  201. package/src/code-editor/node.ts +147 -53
  202. package/src/flow/draw.ts +104 -35
  203. package/src/flow/index.ts +33 -13
  204. package/src/flow/model.ts +4 -2
  205. package/src/flow/node.ts +158 -59
  206. package/src/flow/types.ts +46 -21
  207. package/src/formula/index.ts +4 -2
  208. package/src/formula/node.ts +24 -5
  209. package/src/html/controls.ts +4 -1
  210. package/src/html/css/cascade.ts +18 -7
  211. package/src/html/css/parse.ts +46 -21
  212. package/src/html/css/style.ts +6 -1
  213. package/src/html/css/values.ts +25 -9
  214. package/src/html/index.ts +1 -0
  215. package/src/html/layout/boxes.ts +19 -9
  216. package/src/html/layout/inline.ts +23 -1
  217. package/src/html/node.ts +110 -17
  218. package/src/html/paint.ts +17 -2
  219. package/src/index.ts +102 -0
  220. package/src/maps/clip.ts +184 -0
  221. package/src/maps/gzip.ts +66 -0
  222. package/src/maps/index.ts +316 -0
  223. package/src/maps/labels.ts +442 -0
  224. package/src/maps/mvt.ts +857 -0
  225. package/src/maps/node.ts +1819 -0
  226. package/src/maps/overlay.ts +639 -0
  227. package/src/maps/paint.ts +978 -0
  228. package/src/maps/proj.ts +641 -0
  229. package/src/maps/sources.ts +425 -0
  230. package/src/maps/style.ts +309 -0
  231. package/src/maps/styles.ts +1040 -0
  232. package/src/maps/tiles.ts +676 -0
  233. package/src/maps/types.ts +260 -0
  234. package/src/markdown/ast.ts +85 -9
  235. package/src/markdown/expressions.ts +223 -0
  236. package/src/markdown/index.ts +190 -5
  237. package/src/markdown/parse.ts +230 -15
  238. package/src/markdown/spans.ts +4 -0
  239. package/src/markdown/tags.ts +240 -0
  240. package/src/reorder/hx.ts +31 -0
  241. package/src/reorder/index.ts +2223 -0
  242. package/src/reorder/model.ts +232 -0
  243. package/src/richtext/node.ts +49 -14
  244. package/src/richtext/runs.ts +115 -30
  245. package/src/tabs/index.ts +1040 -204
  246. package/src/terminal/vt/fonts.ts +128 -36
  247. package/src/terminal/vt/node.ts +105 -12
  248. package/src/terminal/vt/renderer.ts +13 -3
@@ -0,0 +1,256 @@
1
+ import type { VectorTile } from './mvt.js';
2
+ import type { TileId } from './proj.js';
3
+ /** Which tile a source is being asked for. */
4
+ export interface TileRequest extends TileId {
5
+ /** The source's own id, for an application serving several from one
6
+ * loader. */
7
+ sourceId: string;
8
+ /**
9
+ * Aborted when the tile leaves the view before it arrives.
10
+ *
11
+ * **This is a real `AbortSignal`** on every runtime that has one, which
12
+ * is what makes `fetch(url, { signal })` work — `fetch` rejects anything
13
+ * that is not an instance of it (`TypeError: Expected signal … to be an
14
+ * instance of AbortSignal`), so a look-alike would fail every load.
15
+ * `undefined` on a runtime with no `AbortController`.
16
+ *
17
+ * It is *typed* structurally because `src/` compiles with no DOM lib and
18
+ * cannot name the class, which is why an application in TypeScript casts:
19
+ * `fetch(url, { signal: signal as AbortSignal })`.
20
+ */
21
+ signal: {
22
+ readonly aborted: boolean;
23
+ addEventListener?: unknown;
24
+ } | undefined;
25
+ }
26
+ /** Raw tile bytes, or pixels, or nothing. */
27
+ export type TileData =
28
+ /** Mapbox Vector Tile bytes. Gzip is unwrapped for you, so either the
29
+ * compressed or the decompressed body is fine. */
30
+ {
31
+ kind: 'vector';
32
+ data: Uint8Array;
33
+ }
34
+ /**
35
+ * Decoded pixels: straight (non-premultiplied) RGBA, rows top to bottom
36
+ * — the canvas contract, and what ntk's own `decodeImage` produces.
37
+ *
38
+ * Bytes rather than a PNG or a JPEG on purpose. Decoding an image format
39
+ * needs a codec, and this package will not grow one or assume which of
40
+ * them a provider serves; the application already has ntk's, through
41
+ * `react-x11/ntk`, and the docs page has the four-line adapter.
42
+ */
43
+ | {
44
+ kind: 'raster';
45
+ width: number;
46
+ height: number;
47
+ data: Uint8Array;
48
+ }
49
+ /** There is no tile here. An ordinary state — an ocean tile in a
50
+ * land-only pyramid, a 404 — and never an error. */
51
+ | null;
52
+ /** A tile source. */
53
+ export interface MapSource {
54
+ /** Distinguishes this source's cache entries from another's. Defaults to
55
+ * the source's position in the `sources` array. */
56
+ id?: string;
57
+ /** Fetch, or answer from a cache, or decline. May be async. */
58
+ load(request: TileRequest): TileData | Promise<TileData>;
59
+ /** The shallowest and deepest levels this source has data for. Outside
60
+ * the range the nearest level is used and scaled — "overzoom" above,
61
+ * which is how a z14 pyramid serves a z18 view. Defaults to 0 and 14. */
62
+ minZoom?: number;
63
+ maxZoom?: number;
64
+ /** Edge length of one tile in logical pixels: 512 for most vector
65
+ * pyramids, 256 for the older raster convention. */
66
+ tileSize?: number;
67
+ /**
68
+ * The attribution this source's licence requires, drawn in the corner of
69
+ * the map.
70
+ *
71
+ * Not optional in practice for open data, which is why it is a field of
72
+ * the source rather than a prop of the map: whoever chose the tiles is
73
+ * who knows what has to be said about them.
74
+ */
75
+ attribution?: string;
76
+ }
77
+ /** A source's pyramid, with the defaults filled in. */
78
+ export declare function pyramidOf(source: MapSource): {
79
+ minZoom: number;
80
+ maxZoom: number;
81
+ tileSize: number;
82
+ };
83
+ /** Substitute `{z}`, `{x}`, `{y}` — and `{s}` from `subdomains`, which the
84
+ * older raster services still shard on. */
85
+ export declare function tileUrl(template: string, tile: TileId, subdomains?: readonly string[]): string;
86
+ /** What every OpenStreetMap-derived map has to say. */
87
+ export declare const OSM_ATTRIBUTION = "\u00A9 OpenStreetMap contributors";
88
+ /** Where the OSM Foundation serves Shortbread vector tiles. */
89
+ export declare const OSM_VECTOR_URL = "https://vector.openstreetmap.org/shortbread_v1/{z}/{x}/{y}.mvt";
90
+ /** …and the classic raster layer. */
91
+ export declare const OSM_RASTER_URL = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
92
+ /** What a ready-made adapter still needs from the application. */
93
+ export interface OsmSourceOptions {
94
+ /**
95
+ * Fetch one URL. **Required**, and required on purpose — see the note at
96
+ * the top of this file. The whole of it is usually:
97
+ *
98
+ * ```ts
99
+ * fetch: async (url, signal) => {
100
+ * const response = await fetch(url, {
101
+ * signal,
102
+ * headers: { 'user-agent': 'my-app/1.0 (me@example.com)' },
103
+ * });
104
+ * if (response.status === 404) return null;
105
+ * if (!response.ok) throw new Error(`HTTP ${response.status}`);
106
+ * return new Uint8Array(await response.arrayBuffer());
107
+ * }
108
+ * ```
109
+ *
110
+ * `null` means "no tile here", which is an ordinary answer.
111
+ */
112
+ fetch: (url: string, signal: TileRequest['signal'], tile: TileId) => Promise<Uint8Array | null> | Uint8Array | null;
113
+ /** Serve from somewhere else — a mirror, a proxy, a local tile server. */
114
+ url?: string;
115
+ id?: string;
116
+ attribution?: string;
117
+ maxZoom?: number;
118
+ }
119
+ /**
120
+ * OpenStreetMap's own vector tiles, in the Shortbread schema.
121
+ *
122
+ * Pairs with {@link shortbreadStyle}, which is written against the same
123
+ * schema. z14 is the deepest level cut; a view past it overzooms, which is
124
+ * what every client does with this pyramid.
125
+ *
126
+ * **Read the OSM tile usage policy before shipping.** It asks for a
127
+ * user-agent identifying the application, and it is not a CDN for an
128
+ * application with real traffic — which is exactly why `fetch` is the
129
+ * caller's.
130
+ */
131
+ export declare function osmVectorSource(options: OsmSourceOptions): MapSource;
132
+ /**
133
+ * OpenStreetMap's raster tiles — the standard style, as `openstreetmap.org`
134
+ * draws it.
135
+ *
136
+ * `decode` is the second thing the application supplies, because a PNG
137
+ * needs a codec and this package will not grow one. ntk already has one,
138
+ * and it is already installed:
139
+ *
140
+ * ```ts
141
+ * import ntk from 'react-x11/ntk';
142
+ * const decode = (bytes) => {
143
+ * const image = (ntk as { decodeImage(b: Uint8Array): {
144
+ * width: number; height: number; data: Uint8Array } }).decodeImage(bytes);
145
+ * return { width: image.width, height: image.height, data: image.data };
146
+ * };
147
+ * ```
148
+ */
149
+ export declare function osmRasterSource(options: OsmSourceOptions & {
150
+ decode: (bytes: Uint8Array) => {
151
+ width: number;
152
+ height: number;
153
+ data: Uint8Array;
154
+ };
155
+ subdomains?: readonly string[];
156
+ }): MapSource;
157
+ /** Decode vector tile bytes. Exported so an application holding a `.mvt`
158
+ * of its own can hand the map a parsed tile through a source. */
159
+ export declare function parseVectorTile(bytes: Uint8Array): VectorTile;
160
+ /**
161
+ * What Google's Map Tiles API hands back for a session request.
162
+ *
163
+ * Written out structurally rather than imported: this package has no Google
164
+ * dependency and is not about to grow one.
165
+ */
166
+ export interface GoogleSession {
167
+ /** The token every tile request carries. */
168
+ session: string;
169
+ /** Usually 256. */
170
+ tileWidth?: number;
171
+ tileHeight?: number;
172
+ /** `'png'` or `'jpeg'`. */
173
+ imageFormat?: string;
174
+ /** Seconds since the epoch, as a string, per the API. */
175
+ expiry?: string;
176
+ }
177
+ export interface GoogleTileSourceOptions {
178
+ /**
179
+ * Fetch one tile URL. The application's, exactly as every other source
180
+ * here — see the note at the top of this file.
181
+ */
182
+ fetch: (url: string, signal: TileRequest['signal'], tile: TileId) => Promise<Uint8Array | null> | Uint8Array | null;
183
+ /**
184
+ * Create a session, by POSTing `body` as JSON to
185
+ * `https://tile.googleapis.com/v1/createSession?key=…`, and hand back
186
+ * what it answered.
187
+ *
188
+ * A separate callback from `fetch` because it is a POST with a JSON body
189
+ * and a key in the query, which the tile-fetching shape cannot express —
190
+ * and because it is where the API key lives, which is the application's
191
+ * secret and not something to hand a component.
192
+ *
193
+ * Called lazily on the first tile and again when the session expires;
194
+ * Google's are good for two weeks.
195
+ */
196
+ createSession: (body: Record<string, unknown>) => Promise<GoogleSession>;
197
+ /**
198
+ * Decode the PNG or JPEG. Google's 2D tiles are **raster** — there is no
199
+ * public vector endpoint and no published schema — so a codec is needed
200
+ * exactly as it is for `osmRasterSource`.
201
+ */
202
+ decode: (bytes: Uint8Array) => {
203
+ width: number;
204
+ height: number;
205
+ data: Uint8Array;
206
+ };
207
+ /** `'roadmap'` (the default), `'satellite'` or `'terrain'`. Satellite is
208
+ * the one thing OpenStreetMap has no answer for at all. */
209
+ mapType?: 'roadmap' | 'satellite' | 'terrain';
210
+ /** `'layerRoadmap'` over satellite or terrain, `'layerStreetview'`. */
211
+ layerTypes?: readonly string[];
212
+ /** IETF language tag and CLDR region — Google's cartography is localized
213
+ * server-side, which is the other thing you cannot do with a style. */
214
+ language?: string;
215
+ region?: string;
216
+ /** `'scaleFactor1x'`, `'scaleFactor2x'`, `'scaleFactor4x'`. */
217
+ scale?: string;
218
+ highDpi?: boolean;
219
+ id?: string;
220
+ maxZoom?: number;
221
+ /**
222
+ * What is drawn in the corner. **Do not remove it.** Google's Map Tiles
223
+ * API policies require the Google Maps logo, or the text "Google Maps"
224
+ * where space is limited, together with the data providers — and require
225
+ * that it is not obscured by anyone else's attribution. This component
226
+ * draws attribution as text, so the text form is what it can satisfy;
227
+ * a logo is an overlay of your own (`<Map>` takes `children`).
228
+ */
229
+ attribution?: string;
230
+ }
231
+ /**
232
+ * Google's Map Tiles API, as a `MapSource`.
233
+ *
234
+ * **Raster, and that is not a limitation of this adapter.** Google publishes
235
+ * no vector tile endpoint and no schema, so there is nothing for a
236
+ * `mapStyle` to name: what arrives is Google's own cartography, already
237
+ * drawn. `mapType` and `language` are the styling controls, and they are
238
+ * applied server-side when the session is created.
239
+ *
240
+ * Three things about it that differ from every other source here, and each
241
+ * is the API's rather than this package's:
242
+ *
243
+ * - **A session token comes first.** One POST, reused for every tile,
244
+ * good for two weeks, and it is what carries the display options — so
245
+ * changing `mapType` means a new session, which this handles by making a
246
+ * new source.
247
+ * - **A key is required**, and it is yours: it goes in `createSession` and
248
+ * in the tile URL, both of which are the application's callbacks.
249
+ * - **The terms restrict caching.** `<Map>` keeps parsed tiles and rendered
250
+ * surfaces in memory for the session, which is what any renderer does;
251
+ * writing tiles to disk is a different thing and the policies forbid it.
252
+ * Read them before shipping — they also govern showing Google's tiles
253
+ * beside another map's.
254
+ */
255
+ export declare function googleTileSource(options: GoogleTileSourceOptions): MapSource;
256
+ //# sourceMappingURL=sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/maps/sources.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,8CAA8C;AAC9C,MAAM,WAAW,WAAY,SAAQ,MAAM;IACzC;kBACc;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAAC;CAC/E;AAED,6CAA6C;AAC7C,MAAM,MAAM,QAAQ;AAClB;mDACmD;AACjD;IAAE,IAAI,EAAE,QAAQ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IAAI,CAAC;IACpD;;;;;;;;;;;;OAYG;IACH,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACzE;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK;QAC7B,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,UAAU,CAAC;KAClB,CAAC;IACF;gEAC4D;IAC5D,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;IAC9C,uEAAuE;IACvE,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B;4EACwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,SAAS,CAmE5E"}
@@ -0,0 +1,210 @@
1
+ // Where tiles come from — and, deliberately, not how they are fetched.
2
+ //
3
+ // **Nothing in this package makes a network request.** That is the same
4
+ // call `src/html/` makes about `onResource` and `src/desktop-calendar/`
5
+ // makes about credentials, and it is the rule rather than an omission: a
6
+ // component that quietly fetched would turn "render this map" into "make
7
+ // these requests to this company", with the map's own default deciding
8
+ // whose servers an application talks to, what its user agent says, and
9
+ // whose usage policy it is now bound by. A tile source is a function the
10
+ // application supplies, and the adapters below are the *arguments* to it —
11
+ // URL templates and a decoder — not a fetch.
12
+ //
13
+ // {@link osmVectorSource} and {@link osmRasterSource} exist because the two
14
+ // keyless, open, canonical OpenStreetMap endpoints are what make
15
+ // `<Map source={…} />` a line that works with no signup; both still take
16
+ // the application's own `load`, and both carry the attribution the licence
17
+ // requires.
18
+ import { gunzipIfNeeded } from './gzip.js';
19
+ import { parseTile } from './mvt.js';
20
+ import { DEFAULT_TILE_SIZE } from './proj.js';
21
+ /** A source's pyramid, with the defaults filled in. */
22
+ export function pyramidOf(source) {
23
+ return {
24
+ minZoom: source.minZoom ?? 0,
25
+ maxZoom: source.maxZoom ?? 14,
26
+ tileSize: source.tileSize ?? DEFAULT_TILE_SIZE,
27
+ };
28
+ }
29
+ /** Substitute `{z}`, `{x}`, `{y}` — and `{s}` from `subdomains`, which the
30
+ * older raster services still shard on. */
31
+ export function tileUrl(template, tile, subdomains) {
32
+ let url = template
33
+ .replace('{z}', String(tile.z))
34
+ .replace('{x}', String(tile.x))
35
+ .replace('{y}', String(tile.y));
36
+ if (subdomains && subdomains.length > 0) {
37
+ // Deterministic in the tile, so the same tile always goes to the same
38
+ // host and a browser-style connection cache is not defeated.
39
+ const index = (tile.x + tile.y) % subdomains.length;
40
+ url = url.replace('{s}', subdomains[index]);
41
+ }
42
+ return url;
43
+ }
44
+ /** What every OpenStreetMap-derived map has to say. */
45
+ export const OSM_ATTRIBUTION = '© OpenStreetMap contributors';
46
+ /** Where the OSM Foundation serves Shortbread vector tiles. */
47
+ export const OSM_VECTOR_URL = 'https://vector.openstreetmap.org/shortbread_v1/{z}/{x}/{y}.mvt';
48
+ /** …and the classic raster layer. */
49
+ export const OSM_RASTER_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
50
+ /**
51
+ * OpenStreetMap's own vector tiles, in the Shortbread schema.
52
+ *
53
+ * Pairs with {@link shortbreadStyle}, which is written against the same
54
+ * schema. z14 is the deepest level cut; a view past it overzooms, which is
55
+ * what every client does with this pyramid.
56
+ *
57
+ * **Read the OSM tile usage policy before shipping.** It asks for a
58
+ * user-agent identifying the application, and it is not a CDN for an
59
+ * application with real traffic — which is exactly why `fetch` is the
60
+ * caller's.
61
+ */
62
+ export function osmVectorSource(options) {
63
+ const url = options.url ?? OSM_VECTOR_URL;
64
+ return {
65
+ id: options.id ?? 'osm-vector',
66
+ minZoom: 0,
67
+ maxZoom: options.maxZoom ?? 14,
68
+ tileSize: 512,
69
+ attribution: options.attribution ?? OSM_ATTRIBUTION,
70
+ async load(request) {
71
+ const bytes = await options.fetch(tileUrl(url, request), request.signal, request);
72
+ if (!bytes || bytes.length === 0)
73
+ return null;
74
+ return { kind: 'vector', data: gunzipIfNeeded(bytes) };
75
+ },
76
+ };
77
+ }
78
+ /**
79
+ * OpenStreetMap's raster tiles — the standard style, as `openstreetmap.org`
80
+ * draws it.
81
+ *
82
+ * `decode` is the second thing the application supplies, because a PNG
83
+ * needs a codec and this package will not grow one. ntk already has one,
84
+ * and it is already installed:
85
+ *
86
+ * ```ts
87
+ * import ntk from 'react-x11/ntk';
88
+ * const decode = (bytes) => {
89
+ * const image = (ntk as { decodeImage(b: Uint8Array): {
90
+ * width: number; height: number; data: Uint8Array } }).decodeImage(bytes);
91
+ * return { width: image.width, height: image.height, data: image.data };
92
+ * };
93
+ * ```
94
+ */
95
+ export function osmRasterSource(options) {
96
+ const url = options.url ?? OSM_RASTER_URL;
97
+ return {
98
+ id: options.id ?? 'osm-raster',
99
+ minZoom: 0,
100
+ maxZoom: options.maxZoom ?? 19,
101
+ tileSize: 256,
102
+ attribution: options.attribution ?? OSM_ATTRIBUTION,
103
+ async load(request) {
104
+ const bytes = await options.fetch(tileUrl(url, request, options.subdomains), request.signal, request);
105
+ if (!bytes || bytes.length === 0)
106
+ return null;
107
+ const image = options.decode(bytes);
108
+ return {
109
+ kind: 'raster',
110
+ width: image.width,
111
+ height: image.height,
112
+ data: image.data,
113
+ };
114
+ },
115
+ };
116
+ }
117
+ /** Decode vector tile bytes. Exported so an application holding a `.mvt`
118
+ * of its own can hand the map a parsed tile through a source. */
119
+ export function parseVectorTile(bytes) {
120
+ return parseTile(gunzipIfNeeded(bytes));
121
+ }
122
+ /**
123
+ * Google's Map Tiles API, as a `MapSource`.
124
+ *
125
+ * **Raster, and that is not a limitation of this adapter.** Google publishes
126
+ * no vector tile endpoint and no schema, so there is nothing for a
127
+ * `mapStyle` to name: what arrives is Google's own cartography, already
128
+ * drawn. `mapType` and `language` are the styling controls, and they are
129
+ * applied server-side when the session is created.
130
+ *
131
+ * Three things about it that differ from every other source here, and each
132
+ * is the API's rather than this package's:
133
+ *
134
+ * - **A session token comes first.** One POST, reused for every tile,
135
+ * good for two weeks, and it is what carries the display options — so
136
+ * changing `mapType` means a new session, which this handles by making a
137
+ * new source.
138
+ * - **A key is required**, and it is yours: it goes in `createSession` and
139
+ * in the tile URL, both of which are the application's callbacks.
140
+ * - **The terms restrict caching.** `<Map>` keeps parsed tiles and rendered
141
+ * surfaces in memory for the session, which is what any renderer does;
142
+ * writing tiles to disk is a different thing and the policies forbid it.
143
+ * Read them before shipping — they also govern showing Google's tiles
144
+ * beside another map's.
145
+ */
146
+ export function googleTileSource(options) {
147
+ let session = null;
148
+ let pending = null;
149
+ let tileSize = 256;
150
+ const ensure = async () => {
151
+ const expiry = Number(session?.expiry ?? 0);
152
+ // A minute of slack, so a token does not expire between being chosen
153
+ // and being used.
154
+ if (session && (!expiry || expiry * 1000 > Date.now() + 60_000)) {
155
+ return session;
156
+ }
157
+ if (!pending) {
158
+ pending = Promise.resolve(options.createSession({
159
+ mapType: options.mapType ?? 'roadmap',
160
+ language: options.language ?? 'en-US',
161
+ region: options.region ?? 'US',
162
+ ...(options.layerTypes
163
+ ? { layerTypes: [...options.layerTypes] }
164
+ : {}),
165
+ ...(options.scale ? { scale: options.scale } : {}),
166
+ ...(options.highDpi !== undefined
167
+ ? { highDpi: options.highDpi }
168
+ : {}),
169
+ }))
170
+ .then((answer) => {
171
+ session = answer;
172
+ if (answer.tileWidth && answer.tileWidth > 0) {
173
+ tileSize = answer.tileWidth;
174
+ }
175
+ return answer;
176
+ })
177
+ .finally(() => {
178
+ pending = null;
179
+ });
180
+ }
181
+ return pending;
182
+ };
183
+ return {
184
+ id: options.id ?? `google-${options.mapType ?? 'roadmap'}`,
185
+ minZoom: 0,
186
+ // Google serves to 22, deeper than any vector pyramid here — and since
187
+ // these are finished images there is nothing to sub-tile past it.
188
+ maxZoom: options.maxZoom ?? 22,
189
+ get tileSize() {
190
+ return tileSize;
191
+ },
192
+ attribution: options.attribution ?? 'Google Maps',
193
+ async load(request) {
194
+ const token = await ensure();
195
+ const url = `https://tile.googleapis.com/v1/2dtiles/${request.z}/${request.x}/${request.y}` +
196
+ `?session=${encodeURIComponent(token.session)}`;
197
+ const bytes = await options.fetch(url, request.signal, request);
198
+ if (!bytes || bytes.length === 0)
199
+ return null;
200
+ const image = options.decode(bytes);
201
+ return {
202
+ kind: 'raster',
203
+ width: image.width,
204
+ height: image.height,
205
+ data: image.data,
206
+ };
207
+ },
208
+ };
209
+ }
210
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/maps/sources.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,yEAAyE;AACzE,yEAAyE;AACzE,uEAAuE;AACvE,uEAAuE;AACvE,yEAAyE;AACzE,2EAA2E;AAC3E,6CAA6C;AAC7C,EAAE;AACF,4EAA4E;AAC5E,iEAAiE;AACjE,yEAAyE;AACzE,2EAA2E;AAC3E,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAqE9C,uDAAuD;AACvD,MAAM,UAAU,SAAS,CAAC,MAAiB;IAKzC,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC;QAC5B,OAAO,EAAE,MAAM,CAA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C;YAChE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,141 @@
1
+ import type { FeatureValue } from './mvt.js';
2
+ import type { FeatureCursor } from './mvt.js';
3
+ /**
4
+ * A value that may vary with the zoom.
5
+ *
6
+ * A bare value is constant. `{ stops }` is a list of `[zoom, value]` pairs,
7
+ * ordered by zoom: numbers interpolate linearly between the surrounding
8
+ * pair, and anything else steps at each stop. Outside the range the nearest
9
+ * stop holds, which is what makes a two-stop ramp a sensible whole answer
10
+ * rather than something that vanishes at zoom 0.
11
+ */
12
+ export type Zoomed<T> = T | {
13
+ stops: readonly (readonly [number, T])[];
14
+ };
15
+ /** Mapbox's legacy filter syntax, which is the part of it a style here
16
+ * speaks. Compiled with {@link compileFilter}. */
17
+ export type MapFilter = readonly ['==' | '!=', string, FeatureValue] | readonly ['<' | '<=' | '>' | '>=', string, number] | readonly ['in' | '!in', string, ...FeatureValue[]] | readonly ['has' | '!has', string] | readonly ['all' | 'any' | 'none', ...MapFilter[]] | readonly ['geometry', 'point' | 'line' | 'polygon'];
18
+ interface LayerBase {
19
+ /** This layer's name in the style. Used in a `<Map>` event payload and as
20
+ * the cache key for anything derived from it. */
21
+ id: string;
22
+ /** Which source, when the map has more than one. The first source by
23
+ * default. */
24
+ source?: string;
25
+ /** Which layer of the tile — `'streets'`, `'water_polygons'`. */
26
+ sourceLayer: string;
27
+ /** The zoom range this layer draws in. A layer outside its range costs
28
+ * nothing: it is skipped before its features are touched. */
29
+ minZoom?: number;
30
+ maxZoom?: number;
31
+ filter?: MapFilter;
32
+ /** `false` keeps the layer in the style and stops drawing it — what a
33
+ * layer toggle in an application's UI switches. */
34
+ visible?: boolean;
35
+ }
36
+ /** An area. */
37
+ export interface FillLayer extends LayerBase {
38
+ type: 'fill';
39
+ color: Zoomed<string>;
40
+ opacity?: Zoomed<number>;
41
+ /** Stroked at one logical pixel around each ring, after the fill. */
42
+ outlineColor?: Zoomed<string>;
43
+ }
44
+ /** A line: a road, a river, a boundary, a route. */
45
+ export interface LineLayer extends LayerBase {
46
+ type: 'line';
47
+ color: Zoomed<string>;
48
+ /** Logical pixels. */
49
+ width: Zoomed<number>;
50
+ opacity?: Zoomed<number>;
51
+ /** A dash pattern in logical pixels. */
52
+ dash?: readonly number[];
53
+ cap?: 'butt' | 'round' | 'square';
54
+ join?: 'miter' | 'round' | 'bevel';
55
+ }
56
+ /** A point, as a disc. */
57
+ export interface CircleLayer extends LayerBase {
58
+ type: 'circle';
59
+ radius: Zoomed<number>;
60
+ color: Zoomed<string>;
61
+ opacity?: Zoomed<number>;
62
+ strokeColor?: Zoomed<string>;
63
+ strokeWidth?: Zoomed<number>;
64
+ }
65
+ /**
66
+ * A label.
67
+ *
68
+ * Symbol layers are **not** rasterized into the tile: they are collected as
69
+ * candidates, placed against every other label on screen, and drawn into
70
+ * the frame directly. Three reasons, and each of them is a bug if it is
71
+ * done the other way. Collision is global — two labels in different tiles
72
+ * overlap just as readily as two in one — so a per-tile placement produces
73
+ * a map that reads as clutter at every seam. A label baked into a tile
74
+ * surface is stretched by the fractional zoom, and text is the one thing on
75
+ * a map nobody accepts blurred. And a tile's labels would be clipped at its
76
+ * edge, which is exactly where half of them sit.
77
+ */
78
+ export interface SymbolLayer extends LayerBase {
79
+ type: 'symbol';
80
+ /** The tag to read the text from — `'name'`, or `'name:en'`. */
81
+ textField: string;
82
+ /** Logical pixels. */
83
+ textSize?: Zoomed<number>;
84
+ textColor?: Zoomed<string>;
85
+ /** Drawn under the glyphs, so a place name stays readable over a road. */
86
+ textHaloColor?: Zoomed<string>;
87
+ textHaloWidth?: Zoomed<number>;
88
+ /**
89
+ * Which label wins a collision, layer-wide. Higher wins; 0 by default,
90
+ * and the style's layer order breaks a tie.
91
+ *
92
+ * Deliberately not a per-feature expression. A schema's own importance
93
+ * field looks like the obvious input and is not usable as one: Shortbread
94
+ * carries `population`, which is 8,000,000 for London and 500 for Soho,
95
+ * so adding it to a rank that also has to order against street names
96
+ * needs a normalization nobody can guess. Splitting by `filter` — a layer
97
+ * for cities, a layer for suburbs — is exact, is what the ordering
98
+ * actually wants, and costs one more entry in a list.
99
+ */
100
+ rank?: number;
101
+ /**
102
+ * How far apart, in pixels, the same text may repeat within this layer.
103
+ * 250 by default; `0` lets it repeat as often as it fits.
104
+ *
105
+ * Not a nicety. A street is one feature **per segment** in every schema
106
+ * there is, so `street_labels` offers "Oxford Street" a dozen times over
107
+ * for one street, and a placement that only tests overlap accepts all
108
+ * twelve — they do not overlap, they are strung out along the road. The
109
+ * same is true of an administrative area whose name arrives once per
110
+ * polygon part. Repeating a long street's name across a wide view is
111
+ * wanted; repeating it four times in a hundred pixels is not, and the
112
+ * distance is where that line goes.
113
+ */
114
+ repeatDistance?: number;
115
+ }
116
+ export type MapStyleLayer = FillLayer | LineLayer | CircleLayer | SymbolLayer;
117
+ /** A whole style. */
118
+ export interface MapStyle {
119
+ /** Painted under every tile — the colour of the parts of the world that
120
+ * have no data yet, so it is what a map looks like while it loads. */
121
+ background?: string;
122
+ layers: readonly MapStyleLayer[];
123
+ /** The face labels are set in. The theme's `fontFamily` by default. */
124
+ fontFamily?: string;
125
+ }
126
+ /** A {@link Zoomed} at one zoom. Numbers interpolate, everything else
127
+ * steps. */
128
+ export declare function resolveZoomed<T>(value: Zoomed<T>, zoom: number): T;
129
+ /** A compiled filter: the shape the rasterizer calls per feature. */
130
+ export type CompiledFilter = (feature: FeatureCursor) => boolean;
131
+ /**
132
+ * Compile a filter to a closure, once.
133
+ *
134
+ * The point of compiling rather than interpreting: the operator dispatch,
135
+ * the `in`-set construction and the geometry-type mapping all happen here,
136
+ * per layer, instead of twelve thousand times per tile. A `['in', 'kind',
137
+ * …]` with forty values becomes a `Set` lookup rather than a scan.
138
+ */
139
+ export declare function compileFilter(filter: MapFilter | undefined): CompiledFilter;
140
+ export {};
141
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../src/maps/style.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;CAAE,CAAC;AAEzE;mDACmD;AACnD,MAAM,MAAM,SAAS,GACjB,SAAS,CAAC,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,GAC5C,SAAS,CAAC,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAClD,SAAS,CAAC,IAAI,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC,GAClD,SAAS,CAAC,KAAK,GAAG,MAAM,EAAE,MAAM,CAAC,GACjC,SAAS,CAAC,KAAK,GAAG,KAAK,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,GAGjD,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;AAExD,UAAU,SAAS;IACjB;sDACkD;IAClD,EAAE,EAAE,MAAM,CAAC;IACX;mBACe;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;I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