@tileflow/core 0.1.0-alpha.42 → 0.1.0-alpha.43

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 (50) hide show
  1. package/README.md +50 -68
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/dist/{3d-CzLTD0RK.d.ts → 3d-CW5Ls0An.d.ts} +32 -2
  4. package/dist/3d.d.ts +1 -1
  5. package/dist/3d.js +301 -22
  6. package/dist/browser.d.ts +95 -5
  7. package/dist/browser.js +713 -45
  8. package/dist/build.d.ts +8 -4
  9. package/dist/build.js +250 -3
  10. package/dist/config-reference.json +3395 -2140
  11. package/dist/{icon-composition-B1A2udKb.d.ts → icon-composition-Bbw9umUA.d.ts} +37 -2
  12. package/dist/index.d.ts +13 -4
  13. package/dist/index.js +193 -3
  14. package/dist/{manifest-types-B0lQjabX.d.ts → manifest-types-CwjHd4qc.d.ts} +8 -0
  15. package/dist/manifest.d.ts +2 -2
  16. package/dist/native-profile.d.ts +4 -0
  17. package/dist/native-profile.js +2 -0
  18. package/dist/native.js +789 -462
  19. package/dist/runtime.d.ts +1 -1
  20. package/dist/worker/camera-tile-worker.global.js +2 -2
  21. package/package.json +4 -5
  22. package/docs/application-tile-reading.md +0 -86
  23. package/docs/authoring-model.md +0 -269
  24. package/docs/boundary-areas-and-choropleths.md +0 -230
  25. package/docs/buildings-3d.md +0 -624
  26. package/docs/camera-moves-and-tile-cache.md +0 -112
  27. package/docs/capture-scenes.md +0 -40
  28. package/docs/capture-shots.md +0 -173
  29. package/docs/cartographic-defaults.md +0 -214
  30. package/docs/compiled-style-performance.md +0 -286
  31. package/docs/data-is-separate-from-design.md +0 -610
  32. package/docs/depth-markers.md +0 -65
  33. package/docs/dynamic-style-images.md +0 -100
  34. package/docs/globe-atmosphere.md +0 -113
  35. package/docs/hosted-session-authorization.md +0 -106
  36. package/docs/map-and-terrain-examples.md +0 -156
  37. package/docs/map-emphasis.md +0 -89
  38. package/docs/native-artifact-profile.md +0 -152
  39. package/docs/native-resource-urls.md +0 -369
  40. package/docs/nautical-marks.md +0 -308
  41. package/docs/public-api-and-browser-subpath.md +0 -101
  42. package/docs/route-drawing.md +0 -191
  43. package/docs/shared-visual-primitives.md +0 -101
  44. package/docs/street-lights.md +0 -127
  45. package/docs/street-sky.md +0 -156
  46. package/docs/style-states.md +0 -73
  47. package/docs/sun-and-light.md +0 -167
  48. package/docs/theme-transitions-and-blends.md +0 -317
  49. package/docs/themes-and-module-styles.md +0 -156
  50. package/docs/trees-3d.md +0 -295
@@ -1,152 +0,0 @@
1
- # Validate native artifacts
2
-
3
- `@tileflow/core/native-profile` checks a resolved MapLibre style against the static `native-v1`
4
- artifact profile. It is a build-time entry point, separate from the dependency-free URL helpers in
5
- `@tileflow/core/native`. Install Core as described in the [package README](../README.md).
6
-
7
- This is not a mobile SDK. It does not fetch a manifest, execute a renderer, start a commercial
8
- session, or qualify Hermes, iOS or Android. A passing result establishes static artifact checks,
9
- not native pixels, data availability, Hosted access, publication or mobile product availability.
10
-
11
- ## Check a style
12
-
13
- <!-- docs:check -->
14
-
15
- ```ts
16
- import {validateTileflowNativeStyle} from '@tileflow/core/native-profile';
17
-
18
- const diagnostics = validateTileflowNativeStyle({
19
- version: 8,
20
- sources: {},
21
- layers: [{id: 'background', type: 'background', paint: {'background-color': '#ffffff'}}],
22
- });
23
-
24
- console.log(diagnostics);
25
- ```
26
-
27
- The result is an empty array for a style that passes this profile, or bounded structured errors.
28
- `assertTileflowNativeStyle()` throws `TileflowNativeCompatibilityError` for the same errors.
29
- Neither function modifies the input. Both enforce the raw input budget, even when given a style
30
- that was already prepared. Relative resources require the explicit `documentUrl` option
31
- and resolve against that declaring style; it is not inferred from a browser or Metro address.
32
-
33
- Use the [Dev artifact pipeline](https://github.com/tileflow/tileflow-sdk/blob/main/packages/dev/docs/native-artifacts.md)
34
- for authored maps. It resolves inheritance and semantic modules once, prepares icons and fonts,
35
- checks every theme and returns a complete generation. Do not call a style validator instead of
36
- preparing the referenced resources.
37
-
38
- ## Profile and metadata
39
-
40
- The exported `tileflowNativeProfile` targets MapLibre React Native 11.3.10 with Native Android 13.2.0
41
- and iOS 6.26.0. These are static compatibility targets, not a supported application dependency matrix.
42
- The application integration uses MapLibre React Native 11.5.0 with Android 13.6.1 and iOS 6.31.0.
43
- The artifact profile retains its earlier validation targets and build-record engine values, keeping
44
- prepared artifacts compatible with existing Hosted validators. New application dependencies do not
45
- expand the accepted style vocabulary.
46
-
47
- The wrapper's Style Spec version is 26.2.1. Tileflow retains its existing compiler and parser at
48
- 24.8.5: `native-v1` checks that compiler's vocabulary and the intersection of its recorded Android
49
- and iOS support. It does not expose every feature of Style Spec 26.2.1 or upgrade the web compiler.
50
-
51
- The checker reads the full `sdk-support` and expression metadata from the pinned Style Spec
52
- package's `dist/latest.json`. Its minified JavaScript exports omit that information. A missing
53
- expression-support entry, issue link or required native version newer than either selected engine
54
- is not evidence of support. The metadata source is the
55
- [pinned specification](https://github.com/maplibre/maplibre-style-spec/blob/v24.8.5/src/reference/v8.json).
56
-
57
- `tileflowNativeProfileSchema`, `tileflowNativeDiagnosticSchema`, `tileflowRendererSchema` and
58
- `tileflowNativeBuildRecordSchema` are strict canonical Zod schemas. The map authoring grammar and
59
- its generated language JSON are unchanged: renderer selection belongs to build tooling, not maps.
60
-
61
- ## Included representations and explicit rejections
62
-
63
- The profile admits fixed Mercator styles, standard vector/raster/GeoJSON/image sources, compatible
64
- hillshade and building extrusions, one effective sprite, glyph URLs and complete prepared TTF/OTF
65
- faces. Paint, layout and expression values must also pass the pinned semantic parser and native
66
- support metadata. Hillshade and building extrusions do not establish 3D terrain support.
67
-
68
- The raw style validator rejects globe or adaptive projection, terrain displacement, sky and global-state extensions,
69
- unsupported source/layer/property values, legacy stop-function objects, browser contour and PMTiles protocols, local file URLs,
70
- multiple sprite providers. The existing portable camera/view bounds are preserved; an artifact
71
- does not configure a native map instance's camera constraints. It does not silently remove
72
- an unsupported feature or replace a font. An explicit fixed-Mercator property can be omitted in the
73
- native representation because Native has no GL JS projection controller; this does not change the
74
- logical map revision.
75
-
76
- Dev's `native-lowering-v1` preparation policy explicitly converts a fixed `{type: 'globe'}`
77
- projection to Native's implicit Mercator and removes a browser `sky` before this validator runs. This is a recorded projection
78
- change, not globe support or visual equivalence. One authored map serves web and native preparation;
79
- no native-specific Streets definition is used. Preparation adapts only finite `line-cap` and
80
- `line-dasharray` decisions into constant-property layers, and replaces constant `icon-overlap` and
81
- `text-overlap` modes with their `*-allow-overlap` equivalent. Other unsupported properties have no
82
- implicit fallback. The raw validator continues to reject unlowered unsupported expressions and
83
- overlap modes. See the [preparation contract](https://github.com/tileflow/tileflow-sdk/blob/main/packages/dev/docs/native-artifacts.md)
84
- for the grammar, expansion limits and pending native visual checks. The lowering checks establish
85
- per-feature selection and cap/dash values, not global feature draw order. A copied `line-sort-key`
86
- cannot preserve ordering between simultaneous physical branches; overlapping features may produce
87
- a different composition even when every property value is retained.
88
-
89
- `native-build.json` uses strict schema version 2 and `preparationVersion: 'native-lowering-v1'`.
90
- Its `transformations` array is ordered by map/theme and binds the input/lowered style hashes,
91
- projection policy, an optional `sky: 'removed'`, physical layer spans and symbol overlap replacements. The runtime manifest remains version 1. An old v1
92
- build-record decoder must reject v2 rather than silently ignore the preparation evidence.
93
-
94
- Text must use a valid glyph template containing `{fontstack}` and `{range}`, or a complete static
95
- font stack backed by prepared faces. Native preparation maps each exact OpenType full name to its
96
- verified TTF/OTF URL. WOFF2 conversion, Unicode-range split providers, dynamic font-stack closure and
97
- implicit system-font fallback are outside this artifact profile. A fallback name without a prepared
98
- face fails instead of being silently substituted. The existing font pipeline still owns parsing,
99
- font selection, content hashes and required licenses.
100
-
101
- The `deferFontClosure` option is only for compiler preflight before font preparation. It deliberately
102
- does not prove text-provider closure. The Dev pipeline always performs the final full validation
103
- after preparation; external callers must not present a preflight result as a complete artifact check.
104
-
105
- ## Input and prepared-style budgets
106
-
107
- `tileflowNativeProfileLimits` and `validateTileflowNativeStyle()` keep untrusted compiler input at
108
- **160,000 visited JSON nodes**. Dev applies this gate before lowering. The raw validator has no
109
- option to borrow the output allowance, and preparation never retries rejected input with a larger
110
- budget. Exceeding the input bound remains `NATIVE_UNSUPPORTED_STYLE` at the root style pointer.
111
-
112
- `tileflowNativePreparedStyleLimits` and `validateTileflowNativePreparedStyle()` use a separate fixed
113
- ceiling of **540,000 nodes** for the expanded representation. The latter performs the same semantic,
114
- source, font and URL checks; it does not lower a style, relax unsupported properties or establish
115
- that the input came from a trusted build. Use it to check prepared artifact JSON, not as the entry
116
- gate for authoring. Dev uses it after lowering, after font preparation and after generation URL
117
- retargeting, before writing the output generation.
118
-
119
- Both stages use the same traversal. Each object key or array index and each value counts as a
120
- node. Both retain **8 MiB of serialized UTF-8, depth 64, 128 sources, 4,096 layers, 16 prepared font
121
- faces and 32 returned errors**. Cycles, getters, sparse arrays, non-JSON values and `toJSON` hooks
122
- remain invalid. The prepared budget changes only the node allowance; per-decision and per-layer
123
- expansion limits also remain mandatory.
124
-
125
- The measured full Streets family expands from 122,253 to 513,321 nodes for dark and from 122,163 to
126
- 513,231 for light. The 540,000-node ceiling leaves 26,679/26,769 nodes (about 5.2%) of headroom rather
127
- than multiplying the raw allowance arbitrarily. This accommodates the bounded prepared
128
- representation, not unbounded growth of custom styles. Prepared font bytes retain the existing
129
- 1 MiB per-face bound; URL, icon and sprite limits retain their owning pipelines' bounds. These are
130
- validation-work limits, not download, GPU-memory or billing limits.
131
-
132
- Allowing the larger prepared representation increases the maximum traversal and parser workload.
133
- The byte, depth, layer and decision bounds still apply; there is no caller-selected unlimited
134
- mode. The node traversal stops at its ceiling before JSON serialization and semantic parsing.
135
- These finite limits are not a latency guarantee for every machine or a substitute for admission
136
- controls in an application accepting arbitrary artifacts.
137
-
138
- ## Read diagnostics
139
-
140
- Every native diagnostic has `code`, `phase`, `severity`, `path`, `renderer`, `profile`, `message`
141
- and `suggestion`. `path` is a JSON Pointer into the style; artifact preparation prefixes it with the
142
- map and theme. Error messages do not include rejected URLs, parser details or credentials. Unsafe
143
- object-key text is represented by its ancestor pointer.
144
-
145
- - `NATIVE_UNSUPPORTED_STYLE`: incompatible style semantics or artifact shape.
146
- - `NATIVE_UNSUPPORTED_SOURCE`: incompatible source, URL or browser protocol.
147
- - `NATIVE_FONT_UNAVAILABLE`: missing or incompatible native text-provider closure.
148
- - `NATIVE_MANIFEST_REQUIRED`: no declaring document URL for relative resources.
149
- - `NATIVE_RENDERER_UNSUPPORTED`: unavailable renderer/profile or native delivery target.
150
-
151
- Dev sessions and CLI commands retain their existing diagnostic envelopes and add the native
152
- `renderer`/`profile` context. Unchanged web calls do not gain extra diagnostic fields.
@@ -1,369 +0,0 @@
1
- # Native resource URLs, sources and initial views
2
-
3
- `@tileflow/core/native` provides URL helpers, source coordination and renderer-neutral initial
4
- views for clients without a browser origin. Its published entry bundles a private WHATWG parser
5
- with IDNA processing. It does not use or replace the ambient `URL`, `TextEncoder` or `TextDecoder`,
6
- and has no renderer dependency.
7
-
8
- The synchronous URL helpers resolve references only. Tileflow manifest sources use an injected
9
- bounded acquisition adapter. None of these APIs renders maps or authorizes Hosted requests.
10
- A successful resolution is not a claim that a style or feature works on a particular native renderer.
11
- Install `@tileflow/core@alpha` as described in the [package README](../README.md); the examples use
12
- only this package's public exports.
13
-
14
- ## Resolve the manifest explicitly
15
-
16
- A native client must provide the complete manifest URL. There is no implicit
17
- `/tileflow/manifest.json`, Metro host, device address, or current application route.
18
-
19
- <!-- docs:check -->
20
-
21
- ```ts
22
- import {resolveTileflowNativeManifestUrl} from '@tileflow/core/native';
23
-
24
- const manifestUrl = resolveTileflowNativeManifestUrl(
25
- 'https://maps.example.com/tileflow/native/manifest.json',
26
- );
27
- ```
28
-
29
- The result is the validated, absolute HTTPS manifest URL; no network request is made.
30
- The default policy requires HTTPS. Both input and resolved URLs are limited to 2,048 UTF-16 code
31
- units. Empty values, leading or trailing whitespace, control characters, backslashes, fragments,
32
- malformed percent escapes, embedded credentials, and protocol-relative URLs are rejected.
33
- Local file URLs and custom renderer protocols are outside this helper's HTTP(S) contract.
34
-
35
- ## Resolve resources from their owning document
36
-
37
- Pass the URL of the document that declares the resource. A style URL is relative to its manifest;
38
- a tile URL in TileJSON is relative to that TileJSON; a font URL in a style is relative to the style.
39
- The helper uses normal URL path resolution and never guesses a deployment prefix.
40
-
41
- <!-- docs:check -->
42
-
43
- ```ts
44
- import {resolveTileflowNativeResourceUrl} from '@tileflow/core/native';
45
-
46
- const styleUrl = resolveTileflowNativeResourceUrl('styles/main/light.json', {
47
- documentUrl: 'https://maps.example.com/tileflow/native/manifest.json',
48
- });
49
-
50
- const tileUrl = resolveTileflowNativeResourceUrl('./{z}/{x}/{y}.pbf', {
51
- documentUrl: 'https://tiles.example.com/streets/tiles.json',
52
- template: 'tile',
53
- });
54
- ```
55
-
56
- `styleUrl` resolves to the `styles/main/light.json` path beneath the manifest's directory. `tileUrl`
57
- resolves to the `streets/{z}/{x}/{y}.pbf` template on the tile server; no tile coordinates are chosen.
58
-
59
- Use the actual document URL after any redirects that the application has approved. The declaring
60
- URL is validated even when the resource is already absolute. External HTTPS resources retain their
61
- own origin. The helper never adds delivery credentials or copies a parent's query parameters to a
62
- child resource.
63
-
64
- `template: 'tile'` preserves `{z}`, `{x}`, `{y}`, `{ratio}`, `{quadkey}`, `{bbox-epsg-3857}`, and
65
- `{prefix}`. `template: 'glyphs'` preserves `{fontstack}` and `{range}`. These placeholders are allowed
66
- only in the resource path or query, not the authority. They are not expanded or checked against a
67
- renderer version. Unknown, mismatched, and incomplete placeholders are rejected. Without a template
68
- option, literal braces are rejected; existing percent-encoded braces in paths and queries remain
69
- encoded literal data. Manifest and declaring-document URLs cannot contain literal placeholders.
70
- Hostname normalization must not introduce placeholders, including from percent escapes or Unicode
71
- characters that normalize to braces.
72
-
73
- ## Opt into one development origin
74
-
75
- A debug integration can explicitly permit one HTTP origin:
76
-
77
- <!-- docs:check -->
78
-
79
- ```ts
80
- import {resolveTileflowNativeManifestUrl} from '@tileflow/core/native';
81
-
82
- const manifestUrl = resolveTileflowNativeManifestUrl(
83
- 'http://192.168.1.5:8080/tileflow/manifest.json',
84
- {developmentOrigin: 'http://192.168.1.5:8080'},
85
- );
86
- ```
87
-
88
- Supply the same option when resolving that document's resources. Scheme, hostname, and port must
89
- match the selected origin after URL normalization. An exception for `localhost` does not permit
90
- `127.0.0.1`, another port, or another device. HTTPS remains allowed. The option must name an HTTP
91
- origin without a path, query, fragment, wildcard, or credentials; an optional trailing slash is
92
- accepted. Wildcards and placeholders are rejected before and after hostname normalization.
93
-
94
- Keep this option in debug-only application configuration. The helper cannot determine whether the
95
- application is a debug build, does not change iOS or Android transport settings, and does not expose
96
- a development server. The application still owns any narrowly scoped debug transport exception.
97
-
98
- ## Handle errors without logging the rejected URL
99
-
100
- Failures throw `TileflowNativeUrlError`, a `TypeError` with a stable `code` and `field`.
101
-
102
- - `NATIVE_URL_INVALID`: malformed, unsafe, unsupported-scheme, or oversized URL.
103
- - `NATIVE_URL_ABSOLUTE_REQUIRED`: a document URL is missing its explicit HTTP(S) origin.
104
- - `NATIVE_URL_HTTPS_REQUIRED`: HTTP does not match the selected development origin.
105
- - `NATIVE_URL_DEVELOPMENT_ORIGIN_INVALID`: the development exception is not one valid HTTP origin.
106
- - `NATIVE_URL_TEMPLATE_INVALID`: a template is unsupported, misplaced, or incomplete.
107
-
108
- `field` is `manifestUrl`, `documentUrl`, `resourceUrl`, or `developmentOrigin`. Error messages do not
109
- include the submitted URL or attach the original parser error. The application should preserve
110
- that boundary when reporting failures: resource URLs may contain sensitive query parameters.
111
-
112
- For JavaScript callers, missing or non-object resource options report `NATIVE_URL_INVALID` with
113
- `field: 'documentUrl'`, just like an options object without its required `documentUrl`. Non-object
114
- manifest options report `NATIVE_URL_DEVELOPMENT_ORIGIN_INVALID` with `field: 'developmentOrigin'`.
115
- Omitting manifest options or passing `undefined` remains valid and uses the default HTTPS policy.
116
- Neither function accepts `null` as an options object.
117
-
118
- This is URL policy, not an authorization or server-side request-forgery defense. Callers still own
119
- resource-origin authorization, redirect handling, response size limits, cancellation, and any
120
- network request. Do not attach a credential merely because this helper accepted a URL.
121
-
122
- ## Private parser and source builds
123
-
124
- The native entry embeds the low-level parser from `whatwg-url` 17.2.0, `tr46` 7.0.0 (Unicode 18
125
- IDNA processing) and Punycode.js 2.3.1. It exposes no URL class or parser configuration. Package
126
- consumers only install Core; the published `dist/native.js` has no external runtime imports.
127
- The parser is a development/build dependency, not an additional runtime package to install.
128
- Canonical manifest validation also embeds the existing Zod dependency; it adds no package that
129
- consumers must configure. Complete notices are included in [THIRD_PARTY_NOTICES.md](../THIRD_PARTY_NOTICES.md).
130
-
131
- A React Native URL shim can concatenate references onto a filename or append a slash to `.json`.
132
- The native helpers instead resolve against the owning document with the bundled parser, including
133
- host percent-decoding, IDNA mapping, default ports and encoded dot segments. This does not require
134
- an application-wide polyfill. The build-time native artifact validator uses the same Tileflow URL
135
- policy with its existing host parser; it does not embed the mobile parser in its own bundle.
136
-
137
- From an SDK source checkout, run the ordinary Core build, not a direct source import in a native
138
- application. `tsup.native.config.ts` builds only the native entry with `platform: 'browser'`,
139
- `target: 'es2020'`, ESM and no splitting. Its plugin redirects the two relative
140
- `./encoding` imports and the parser's two `@exodus/bytes` encoding imports to Core's private UTF-8
141
- codec. Query encoding accepts only UTF-8; the legacy encoding bootstrap has no side effects.
142
- Exodus and its legacy encoding tables are not embedded. The build rejects an
143
- unexpected dependency version, an unbound codec import or external runtime imports. It does not
144
- patch packages on disk, configure a global alias or change another entry's build.
145
-
146
- The codec uses replacement semantics for unmatched UTF-16 surrogates and invalid UTF-8 bytes and
147
- preserves BOMs, matching `TextEncoder` and non-fatal `TextDecoder('utf-8', {ignoreBOM: true})`.
148
- It processes at most 65,536 code units for encoding or 65,536 bytes for decoding per call. Private
149
- placeholder sentinels are bounded well below that ceiling; the public URL ceiling stays at 2,048
150
- code units. No parser or codec error is exposed as a cause containing the rejected URL.
151
-
152
- ## Check the built package
153
-
154
- From an installed and built SDK checkout:
155
-
156
- ```sh
157
- pnpm --filter @tileflow/core exec tsx --test test/native-runtime-url.test.ts test/native-url-provider.test.ts test/native-url-utf8.test.ts test/native-url-policy.test.ts test/native-source-view-package.test.ts
158
- ```
159
-
160
- The existing runtime regression checks the Node host and a React Native URL fixture independently.
161
- Another test copies the built native file into an empty directory and executes it with ambient URL
162
- and codec getters that throw. Neither test is a Hermes or device qualification.
163
-
164
- For size comparisons, build Core in two isolated checkouts and retain an `npm pack --json` receipt
165
- from each package directory. Pass the already-built Core directories and optional receipt paths to:
166
-
167
- ```sh
168
- node packages/core/scripts/measure-native-url.mjs /path/to/before/packages/core /path/to/after/packages/core /path/to/before-pack.json /path/to/after-pack.json
169
- ```
170
-
171
- The report separates raw native entry bytes, its runtime graph, a minified ES2020 browser consumer,
172
- gzip size, compressed tarball bytes and unpacked package bytes. It performs no installation and is
173
- not a Metro bundle, Hermes bytecode or device-memory measurement.
174
-
175
- Native acceptance must install the exact tarball in an existing iOS/Android application and run
176
- [`checkNativeUrlContract`](https://github.com/tileflow/tileflow-sdk/blob/main/packages/core/test/fixtures/native-url-contract.mjs)
177
- with the installed `@tileflow/core/native` exports, leaving the application's URL global unchanged.
178
- The [fixture procedure](https://github.com/tileflow/tileflow-sdk/blob/main/packages/core/test/fixtures/native-url-contract.md)
179
- covers the two explicit development origins without network requests. Packaged Hermes execution
180
- remains a separate qualification step; static parsing and Node tests do not establish it. URL-provider
181
- checks do not qualify source/view behavior. This entry does not render maps, create transport
182
- grants or make mobile service availability claims.
183
-
184
- ## Acquire a bounded manifest
185
-
186
- `loadTileflowNativeManifest(manifestUrl, {acquire, signal?, developmentOrigin?})` loads only the
187
- runtime manifest. The application supplies `acquire`; Core never selects an ambient `fetch` or
188
- starts a request at import time. The function returns an immutable `{manifestUrl, manifest}` result.
189
- `manifestUrl` is the validated final response URL, not a guessed application or Metro address.
190
-
191
- The acquisition adapter returns a request handle immediately. Its `response` promise resolves to
192
- `{url, status, reader}`, and its `cancel()` method must be usable before the response arrives.
193
- `url` must be the absolute final URL after redirects that the adapter has approved. Redirect and
194
- resource-origin authorization remain application responsibilities; HTTPS syntax does not authorize
195
- another origin. A missing or invalid final URL is an error, not a reason to reuse the request URL.
196
-
197
- The reader exposes `read(maximumBytes)` and `cancel()`. Each read returns either `{done: true}` or
198
- `{done: false, value: Uint8Array}` with between one and the requested number of bytes. Core requests
199
- at most 64 KiB and copies each measured chunk before requesting another. At the 1 MiB ceiling it
200
- requests one byte to distinguish EOF from overflow. Empty chunks, strings, malformed read results,
201
- and chunks that exceed the requested allowance are rejected. The adapter must release its resources
202
- at EOF; cancellation and failure also call its reader/request cancellation hooks.
203
-
204
- An adapter must enforce bounded reads at its acquisition boundary. It must not implement this
205
- interface by first calling an unlimited `response.text()`, `arrayBuffer()`, or native equivalent and
206
- then slicing the completed body. A platform without a bounded byte reader needs an appropriate
207
- acquisition adapter; this package does not supply a network bridge or a fallback buffering path.
208
- The supplied request `maximumBytes` is the canonical 1 MiB cap, not an adjustable consumer budget.
209
-
210
- Core counts actual bytes, never relies on Content-Length, and rejects overflow before JSON/schema
211
- processing. Decoding is fatal UTF-8: malformed bytes and truncated sequences fail, including those
212
- split across reads. One leading BOM is removed, matching the existing runtime reader; later BOMs
213
- remain data. The private URL codec retains its existing replacement behavior for URLs. A depth
214
- ceiling of 64 is checked before parsing JSON, and the canonical manifest schema still imposes all
215
- map/theme/font/view/identity restrictions. Canonical and resolved manifest JSON must also remain
216
- within 1 MiB; URL expansion cannot turn a small response into an unbounded result.
217
-
218
- There is one version-1 grammar, shared with `parseTileflowRuntimeManifest`. Native supplies the
219
- accepted private URL provider and byte-counting primitives to that grammar, without widening its
220
- wire fields or accepting previously rejected relative URL forms. Every theme's `styleUrl` resolves
221
- against the final manifest URL; font declarations retain the existing style-relative ownership.
222
- The loader resolves those references but does not download styles, fonts, sprites, tiles or TileJSON.
223
- Declared revisions and map/style IDs remain data, not inferred authorization or a session bootstrap.
224
-
225
- There is no implicit cache, retry, request timeout or background task. Use the adapter's bounded
226
- request policy or an external AbortSignal-compatible input for a deadline. Core does not construct
227
- an AbortController, inspect `signal.reason`, install a polyfill, or wait for a broken cancellation
228
- hook to finish. It retires an aborted operation immediately, observes late promise rejections and
229
- cancels a reader that arrives after retirement. Physical cancellation of network work still depends
230
- on the adapter honoring its cancellation methods.
231
-
232
- ## Control a source
233
-
234
- `createTileflowNativeSourceController({acquire})` coordinates a manifest-backed Tileflow source:
235
- `{map, manifestUrl, developmentOrigin?}`. The map and manifest URL are required. The optional
236
- development origin uses the exact HTTP exception described above and applies to manifest resources.
237
- It belongs to the source descriptor, while theme, color scheme and cancellation remain replacement
238
- options. Renderer discriminators and direct style inputs
239
- are not part of this public source contract; the obsolete `kind` and `style` fields are rejected.
240
- A completely unmanaged map uses upstream MapLibre directly, not another Tileflow source mode.
241
-
242
- The controller's `state` is undefined until the first `replace()`. It then publishes only `loading`,
243
- `ready`, or `error` snapshots, each with a monotonically increasing `generation`. The acquisition
244
- adapter is required at construction. Core does not mount a renderer or subscribe to device appearance.
245
-
246
- The following function expects an acquisition adapter implementing the bounded protocol above.
247
- The example URL represents an existing manifest endpoint; no network adapter is supplied here.
248
-
249
- <!-- docs:check -->
250
-
251
- ```ts
252
- import {
253
- createTileflowNativeSourceController,
254
- type TileflowNativeManifestAcquire,
255
- } from '@tileflow/core/native';
256
-
257
- export async function connectNativeManifest(acquire: TileflowNativeManifestAcquire) {
258
- const controller = createTileflowNativeSourceController({acquire});
259
- await controller.replace(
260
- {
261
- map: 'streets',
262
- manifestUrl: 'https://maps.example.com/tileflow/native/manifest.json',
263
- },
264
- {theme: 'dark'},
265
- );
266
- const state = controller.state;
267
- if (state?.status === 'ready') {
268
- console.log(state.map.name, state.theme.name, state.theme.revision);
269
- } else if (state?.status === 'error') {
270
- console.error(state.error.code, state.error.field);
271
- }
272
- return controller;
273
- }
274
- ```
275
-
276
- Narrow on `state.status` to access the resolved selection. Every `ready` snapshot retains the
277
- immutable requested `source`, final `manifestUrl`, resolved `manifest`, selected `map` and concrete
278
- `theme` as required fields. There is no renderer discriminator or direct-style state.
279
-
280
- Map/theme identity and revisions come from the manifest. Map-level `apiUrl` takes precedence over
281
- manifest-level `apiUrl`; no identity is guessed from URL paths. The map's canonical `view` is
282
- preserved as metadata. The controller does not combine camera inputs.
283
-
284
- Omitted `theme` uses `defaultTheme`; a concrete theme selects that exact declared name. `system`
285
- uses the manifest's `systemThemes` mapping only when an explicit `colorScheme: 'light' | 'dark'`
286
- is supplied. The same portable resolver owns this precedence in the existing runtime. Core never
287
- reads device appearance. A missing map, missing theme or unresolved system selection is an error;
288
- there is no first-map or first-theme fallback.
289
-
290
- `replace(source, options)` snapshots inputs and retires the prior generation. A failed replacement
291
- cannot publish the previous source as newly ready. Only the current generation can publish success
292
- or error, even when responses arrive out of order or a transport ignores cancellation. Each valid
293
- replacement reacquires its manifest. There is no hidden source cache. The promise settles when that
294
- generation completes or is retired; source failures are reported in `state`, not as rejected
295
- replacement promises. Calling it after disposal rejects with `NATIVE_SOURCE_DISPOSED`.
296
-
297
- `subscribe(listener)` synchronously receives the current snapshot, when present, and subsequent
298
- snapshots until its returned unsubscribe function is called. Observer exceptions are isolated from
299
- acquisition and from other observers. Reentrant replacement/disposal prevents remaining observers
300
- from receiving an obsolete notification. `dispose()` is idempotent: it retires active work, clears
301
- listeners and retains the last snapshot for inspection without publishing another state. No late
302
- completion or abort can notify a disposed controller.
303
-
304
- ## Resolve an initial view without a renderer
305
-
306
- `resolveTileflowNativeInitialView({view?, mapOptionsView?, manifestView?})` returns an immutable
307
- `{center, zoom, bearing, pitch}`. All three inputs are partial renderer-neutral view objects, not
308
- React Native props or MapLibre camera types. Precedence applies independently to each field:
309
- `view` > `mapOptionsView` > `manifestView` > shared runtime defaults.
310
-
311
- <!-- docs:check -->
312
-
313
- ```ts
314
- import {resolveTileflowNativeInitialView} from '@tileflow/core/native';
315
-
316
- const initialView = resolveTileflowNativeInitialView({
317
- manifestView: {center: [-3.7, 40.4], zoom: 10, bearing: 12},
318
- mapOptionsView: {zoom: 11, pitch: 30},
319
- view: {zoom: 13},
320
- });
321
- ```
322
-
323
- The result is `{center: [-3.7, 40.4], zoom: 13, bearing: 12, pitch: 30}`. With no inputs, the defaults
324
- are `{center: [0, 20], zoom: 2, bearing: 0, pitch: 0}`. Coordinates always use
325
- `[longitude, latitude]`; Core neither swaps nor wraps them.
326
-
327
- Validation reuses the manifest view grammar: longitude -180 to 180, latitude -90 to 90, zoom 0 to 24,
328
- bearing -180 to 180 and pitch 0 to 85, all finite. Supplied fields with `undefined` are omitted;
329
- `null`, out-of-range values, unknown fields, accessors and malformed tuples are errors. Every
330
- supplied level is validated, even if a higher-precedence level would override it. Invalid explicit
331
- input never silently falls back. The result owns a new frozen tuple, not a reference to an input or
332
- to the shared defaults. Failures use `NATIVE_SOURCE_INVALID` with `field: 'view'` and no caller values.
333
-
334
- The resolver is synchronous and independent of source control. Calling it again for a camera update
335
- does not load a manifest, change the selected theme or increment a source generation. It does not
336
- animate, read device appearance, install listeners or apply the result to a renderer.
337
-
338
- ## Handle source errors
339
-
340
- Source operations and initial-view resolution use `TileflowNativeSourceError` with stable `code`,
341
- `field` and `kind`. An active external abort produces `kind: 'cancelled'` and `NATIVE_SOURCE_ABORTED`;
342
- superseded or disposed work cannot publish that error into a newer generation. Acquisition,
343
- response, schema and selection failures are terminal for that generation. A later explicit
344
- `replace()` can retry. Tile-resource failures after a map is created are outside this controller
345
- and do not get classified as manifest failures. This diagnostic `kind` classifies failure, not a
346
- renderer or source mode.
347
-
348
- - `NATIVE_SOURCE_INVALID`: invalid source, view, acquisition configuration or cancellation input.
349
- - `NATIVE_SOURCE_ABORTED`, `NATIVE_SOURCE_DISPOSED`: cancellation or use after controller disposal.
350
- - `NATIVE_MANIFEST_URL_INVALID`: invalid request/final URL or development-origin policy.
351
- - `NATIVE_MANIFEST_REQUEST_FAILED`: acquisition/read failure or unsuccessful response.
352
- - `NATIVE_MANIFEST_RESPONSE_INVALID`: invalid response, reader or chunk protocol.
353
- - `NATIVE_MANIFEST_ACCESS_DENIED`, `NATIVE_MANIFEST_NOT_FOUND`: HTTP 401/403 or 404, respectively.
354
- - `NATIVE_MANIFEST_TOO_LARGE`: actual body or resolved/canonical JSON exceeds the 1 MiB cap.
355
- - `NATIVE_MANIFEST_UTF8_INVALID`, `NATIVE_MANIFEST_JSON_INVALID`: malformed UTF-8 or JSON.
356
- - `NATIVE_MANIFEST_INVALID`: invalid version-1 structure, relationships or excessive nesting.
357
- - `NATIVE_MANIFEST_RESOURCE_INVALID`: a manifest resource fails native URL policy.
358
- - `NATIVE_MAP_NOT_FOUND`, `NATIVE_THEME_INVALID`: missing map or invalid/unresolved theme selection.
359
-
360
- Fields identify only `source`, `signal`, `manifestUrl`, `response`, `body`, `map`, `theme` or `view`.
361
- Errors never carry a rejected URL, response body, credential, remote exception, schema issue list or
362
- abort reason. Successful snapshots necessarily contain resource URLs; treat them as potentially
363
- sensitive when logging. The synchronous URL helpers retain their existing `TileflowNativeUrlError`
364
- contract. A view error is thrown by the pure resolver and does not change controller state.
365
-
366
- These APIs acquire manifests and resolve view data. They do not load styles, validate their
367
- cartographic compatibility, fetch their resources, render maps, create Hosted authorization or
368
- sessions, or provide a React Native component. Source and view behavior requires its own packed
369
- Hermes checks; URL-only checks, Node tests and browser captures do not establish those results.