@vectoriahq/quac 0.0.0-stage → 0.1.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 (132) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +35 -2
  3. package/dist/generate/arcgisStacCatalogue.d.ts +46 -0
  4. package/dist/generate/arcgisStacCatalogue.js +189 -0
  5. package/dist/generate/externalStacCatalogue.d.ts +53 -0
  6. package/dist/generate/externalStacCatalogue.js +145 -0
  7. package/dist/generate/fileLayerCollection.d.ts +44 -0
  8. package/dist/generate/fileLayerCollection.js +72 -0
  9. package/dist/generate/folderStacCatalogue.d.ts +48 -0
  10. package/dist/generate/folderStacCatalogue.js +69 -0
  11. package/dist/generate/normalizedProject.d.ts +451 -0
  12. package/dist/generate/normalizedProject.js +925 -0
  13. package/dist/generate/ogcFeaturesStacCatalogue.d.ts +49 -0
  14. package/dist/generate/ogcFeaturesStacCatalogue.js +207 -0
  15. package/dist/generate/qmlForLayer.d.ts +17 -0
  16. package/dist/generate/qmlForLayer.js +36 -0
  17. package/dist/generate/serverLayerTree.d.ts +44 -0
  18. package/dist/generate/serverLayerTree.js +50 -0
  19. package/dist/generate/serverStacCatalogue.d.ts +84 -0
  20. package/dist/generate/serverStacCatalogue.js +327 -0
  21. package/dist/generate/stacCatalogue.d.ts +110 -0
  22. package/dist/generate/stacCatalogue.js +882 -0
  23. package/dist/generate/wfsStacCatalogue.d.ts +37 -0
  24. package/dist/generate/wfsStacCatalogue.js +127 -0
  25. package/dist/generate/wmsStacCatalogue.d.ts +46 -0
  26. package/dist/generate/wmsStacCatalogue.js +228 -0
  27. package/dist/index.d.ts +77 -0
  28. package/dist/index.js +52 -0
  29. package/dist/model/QgsProject.d.ts +722 -0
  30. package/dist/model/QgsProject.js +15 -0
  31. package/dist/model/Stac.d.ts +320 -0
  32. package/dist/model/Stac.js +16 -0
  33. package/dist/model/WmsProject.d.ts +105 -0
  34. package/dist/model/WmsProject.js +1 -0
  35. package/dist/model/arcgis.d.ts +134 -0
  36. package/dist/model/arcgis.js +1 -0
  37. package/dist/model/delimitedText.d.ts +38 -0
  38. package/dist/model/delimitedText.js +46 -0
  39. package/dist/model/featureFilter.d.ts +41 -0
  40. package/dist/model/featureFilter.js +24 -0
  41. package/dist/model/fieldIconAddress.d.ts +27 -0
  42. package/dist/model/fieldIconAddress.js +93 -0
  43. package/dist/model/ogcFeatures.d.ts +40 -0
  44. package/dist/model/ogcFeatures.js +6 -0
  45. package/dist/model/quacExtension.d.ts +28 -0
  46. package/dist/model/quacExtension.js +75 -0
  47. package/dist/model/stacAssetRoles.d.ts +33 -0
  48. package/dist/model/stacAssetRoles.js +44 -0
  49. package/dist/model/stacCollectionNotes.d.ts +21 -0
  50. package/dist/model/stacCollectionNotes.js +44 -0
  51. package/dist/model/stacHref.d.ts +56 -0
  52. package/dist/model/stacHref.js +93 -0
  53. package/dist/model/stacPmtiles.d.ts +38 -0
  54. package/dist/model/stacPmtiles.js +69 -0
  55. package/dist/model/stacSizeAndCount.d.ts +14 -0
  56. package/dist/model/stacSizeAndCount.js +20 -0
  57. package/dist/model/stacStyles.d.ts +93 -0
  58. package/dist/model/stacStyles.js +87 -0
  59. package/dist/model/stacTreeWalk.d.ts +36 -0
  60. package/dist/model/stacTreeWalk.js +76 -0
  61. package/dist/model/stacWms.d.ts +18 -0
  62. package/dist/model/stacWms.js +73 -0
  63. package/dist/model/stacWmts.d.ts +34 -0
  64. package/dist/model/stacWmts.js +90 -0
  65. package/dist/model/stacXyz.d.ts +24 -0
  66. package/dist/model/stacXyz.js +46 -0
  67. package/dist/model/wfs.d.ts +136 -0
  68. package/dist/model/wfs.js +1 -0
  69. package/dist/parse/collectLayerVisibility.d.ts +10 -0
  70. package/dist/parse/collectLayerVisibility.js +22 -0
  71. package/dist/parse/customProperties.d.ts +18 -0
  72. package/dist/parse/customProperties.js +43 -0
  73. package/dist/parse/geometrySiblings.d.ts +25 -0
  74. package/dist/parse/geometrySiblings.js +83 -0
  75. package/dist/parse/parseBrandColour.d.ts +14 -0
  76. package/dist/parse/parseBrandColour.js +25 -0
  77. package/dist/parse/parseDataDefinedEditable.d.ts +38 -0
  78. package/dist/parse/parseDataDefinedEditable.js +76 -0
  79. package/dist/parse/parseDataSource.d.ts +53 -0
  80. package/dist/parse/parseDataSource.js +484 -0
  81. package/dist/parse/parseExtent.d.ts +17 -0
  82. package/dist/parse/parseExtent.js +49 -0
  83. package/dist/parse/parseFormLayout.d.ts +26 -0
  84. package/dist/parse/parseFormLayout.js +60 -0
  85. package/dist/parse/parseGetProjectSettings.d.ts +15 -0
  86. package/dist/parse/parseGetProjectSettings.js +172 -0
  87. package/dist/parse/parseLayers.d.ts +23 -0
  88. package/dist/parse/parseLayers.js +1122 -0
  89. package/dist/parse/parseLegendTree.d.ts +20 -0
  90. package/dist/parse/parseLegendTree.js +66 -0
  91. package/dist/parse/parseMeasurement.d.ts +21 -0
  92. package/dist/parse/parseMeasurement.js +67 -0
  93. package/dist/parse/parseMergin.d.ts +19 -0
  94. package/dist/parse/parseMergin.js +51 -0
  95. package/dist/parse/parseProjectVariables.d.ts +9 -0
  96. package/dist/parse/parseProjectVariables.js +19 -0
  97. package/dist/parse/parseQfieldSync.d.ts +47 -0
  98. package/dist/parse/parseQfieldSync.js +95 -0
  99. package/dist/parse/parseQgsXml.d.ts +15 -0
  100. package/dist/parse/parseQgsXml.js +100 -0
  101. package/dist/parse/parseRelations.d.ts +19 -0
  102. package/dist/parse/parseRelations.js +64 -0
  103. package/dist/parse/parseStyle.d.ts +33 -0
  104. package/dist/parse/parseStyle.js +128 -0
  105. package/dist/parse/parseWmsPublishing.d.ts +21 -0
  106. package/dist/parse/parseWmsPublishing.js +38 -0
  107. package/dist/parse/projectProperties.d.ts +15 -0
  108. package/dist/parse/projectProperties.js +27 -0
  109. package/dist/parse/qgisExpression.d.ts +194 -0
  110. package/dist/parse/qgisExpression.js +859 -0
  111. package/dist/parse/qtDateFormat.d.ts +74 -0
  112. package/dist/parse/qtDateFormat.js +324 -0
  113. package/dist/parse/qtRegex.d.ts +67 -0
  114. package/dist/parse/qtRegex.js +397 -0
  115. package/dist/parse/readProjectFile.d.ts +7 -0
  116. package/dist/parse/readProjectFile.js +27 -0
  117. package/dist/sources/qgisServerUrl.d.ts +6 -0
  118. package/dist/sources/qgisServerUrl.js +17 -0
  119. package/dist/sources/stacDocuments.d.ts +40 -0
  120. package/dist/sources/stacDocuments.js +85 -0
  121. package/dist/sources/stacItems.d.ts +109 -0
  122. package/dist/sources/stacItems.js +287 -0
  123. package/dist/util/catalogueFileFormats.d.ts +58 -0
  124. package/dist/util/catalogueFileFormats.js +64 -0
  125. package/dist/util/devLog.d.ts +11 -0
  126. package/dist/util/devLog.js +23 -0
  127. package/dist/util/fileName.d.ts +18 -0
  128. package/dist/util/fileName.js +45 -0
  129. package/dist/util/wfsVersions.d.ts +9 -0
  130. package/dist/util/wfsVersions.js +13 -0
  131. package/package.json +47 -4
  132. package/src/schema/quac.schema.json +935 -0
@@ -0,0 +1,93 @@
1
+ import { readDataAsset } from "./stacAssetRoles.js";
2
+ /**
3
+ * How a relative asset href is spelled, and how it is read back.
4
+ *
5
+ * An href is a URI reference, not a file path, so the characters URIs reserve
6
+ * have to be escaped in it. `#` and `?` are the two that bite: both are legal
7
+ * in a file name on every service Groundwork reads, and both end the path when
8
+ * a reader takes an href apart. A folder holding `Building #3.geojson` written
9
+ * unescaped publishes `./Building #3.geojson`, which reads back as `Building `
10
+ * — a file no folder holds, so the layer is dropped.
11
+ *
12
+ * Every generator writes its relative hrefs through `encodeAssetPath`, and
13
+ * every reader takes them back through `decodeAssetPath`, so the pair is here
14
+ * rather than in any one of them.
15
+ */
16
+ /**
17
+ * Percent-encodes a relative path for use in an href, keeping `/` as the
18
+ * separator between segments.
19
+ */
20
+ export function encodeAssetPath(path) {
21
+ return stripLeadingDotSlash(path).split('/').map(encodeURIComponent).join('/');
22
+ }
23
+ /**
24
+ * The path an href addresses: its leading `./` removed and its segments
25
+ * decoded.
26
+ *
27
+ * A segment with a stray `%` is left as it stands rather than throwing —
28
+ * that is an href somebody else wrote without escaping, and the file's own name
29
+ * is the best reading available of it.
30
+ */
31
+ export function decodeAssetPath(href) {
32
+ return stripLeadingDotSlash(href).split('/').map(decodeSegment).join('/');
33
+ }
34
+ /**
35
+ * True for an href pointing to something inside the published folder, as opposed to
36
+ * an absolute address, another server, or a bare fragment. Only a relative one
37
+ * can be resolved against a folder listing.
38
+ */
39
+ export function isRelativeHref(href) {
40
+ if (!href || href.startsWith('#'))
41
+ return false;
42
+ // A scheme (`https:`, `file:`) or a protocol-relative address (`//host/…`).
43
+ return !/^[a-z][a-z0-9+.-]*:/i.test(href) && !href.startsWith('//');
44
+ }
45
+ /**
46
+ * Reads a Collection's `data` asset back as a path inside the published folder
47
+ * — the counterpart of the data asset both the QGIS project and the folder
48
+ * generators write.
49
+ *
50
+ * Returns null for an asset that is not a relative path: a WFS GetFeature URL,
51
+ * the empty href an unsupported source gets, or any absolute address. Those are
52
+ * not files in the folder, so there is nothing here to look up.
53
+ */
54
+ export function readCollectionDataPath(collection) {
55
+ const href = readDataAsset(collection)?.href;
56
+ if (!href || !isRelativeHref(href))
57
+ return null;
58
+ // Anything from the first `#` or `?` is a fragment or a query, never part of
59
+ // the path — a file whose name holds either has it escaped.
60
+ const path = decodeAssetPath(href.split('#')[0].split('?')[0]);
61
+ return path || null;
62
+ }
63
+ /**
64
+ * Reads a Collection's `data` asset as an online file: an absolute `http` or
65
+ * `https` address, such as a QGIS layer reading a file through GDAL's
66
+ * `/vsicurl/` prefix publishes. `name` is the address's last path segment.
67
+ * Null for any other href, a relative path in the folder included.
68
+ */
69
+ export function readCollectionOnlineFile(collection) {
70
+ const href = readDataAsset(collection)?.href;
71
+ if (!href || !/^https?:\/\//i.test(href))
72
+ return null;
73
+ let pathname;
74
+ try {
75
+ pathname = new URL(href).pathname;
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ const segment = pathname.split('/').pop() ?? '';
81
+ return { url: href, name: decodeSegment(segment) || segment };
82
+ }
83
+ export function stripLeadingDotSlash(path) {
84
+ return path.replace(/^\.\//, '');
85
+ }
86
+ function decodeSegment(segment) {
87
+ try {
88
+ return decodeURIComponent(segment);
89
+ }
90
+ catch {
91
+ return segment;
92
+ }
93
+ }
@@ -0,0 +1,38 @@
1
+ import type { StacCollection } from './Stac.ts';
2
+ /**
3
+ * A Collection's PMTiles rendering derivative — the vector tile archive a
4
+ * Portolan catalogue publishes alongside its GeoParquet so a client can draw
5
+ * the whole dataset without downloading it.
6
+ *
7
+ * Portolan registers it in two places, and both are read here
8
+ * (the Portolan convention): a collection-level `rel: "pmtiles"`
9
+ * link per the web-map-links extension v1.3.0, which is the normative
10
+ * registration, and an asset with the `visual` role. The two coexist and
11
+ * address the same file.
12
+ */
13
+ /** PMTiles, per Portolan's media-type registry. */
14
+ export declare const PMTILES_MEDIA_TYPE = "application/vnd.pmtiles";
15
+ /** The role marking an asset as a rendering derivative rather than the data. */
16
+ export declare const VISUAL_ROLE = "visual";
17
+ export interface StacPmtilesSource {
18
+ /** The archive's address — an absolute `http`/`https` URL. */
19
+ href: string;
20
+ /**
21
+ * Layer names inside the archive to draw, from the link's `pmtiles:layers`.
22
+ * Empty where the source declares none — web-map-links leaves the choice to
23
+ * the reader in that case, and Groundwork draws every layer the archive has.
24
+ */
25
+ layers: string[];
26
+ }
27
+ /**
28
+ * The PMTiles archive a Collection has, or null when it has none this can
29
+ * fetch.
30
+ *
31
+ * The link is read first because it is the registration Portolan requires; the
32
+ * `visual` asset is the fallback for a catalogue that publishes only that half.
33
+ * A registration whose href is not an address the tile reader can fetch is not
34
+ * a registration: it is passed over, so a Collection with an unusable link and
35
+ * a loadable data asset still loads from the data asset rather than resolving
36
+ * to a PMTiles layer that can only draw nothing.
37
+ */
38
+ export declare function readCollectionPmtiles(collection: StacCollection): StacPmtilesSource | null;
@@ -0,0 +1,69 @@
1
+ import { findAssetByRole } from "./stacAssetRoles.js";
2
+ /**
3
+ * A Collection's PMTiles rendering derivative — the vector tile archive a
4
+ * Portolan catalogue publishes alongside its GeoParquet so a client can draw
5
+ * the whole dataset without downloading it.
6
+ *
7
+ * Portolan registers it in two places, and both are read here
8
+ * (the Portolan convention): a collection-level `rel: "pmtiles"`
9
+ * link per the web-map-links extension v1.3.0, which is the normative
10
+ * registration, and an asset with the `visual` role. The two coexist and
11
+ * address the same file.
12
+ */
13
+ /** PMTiles, per Portolan's media-type registry. */
14
+ export const PMTILES_MEDIA_TYPE = 'application/vnd.pmtiles';
15
+ /** The role marking an asset as a rendering derivative rather than the data. */
16
+ export const VISUAL_ROLE = 'visual';
17
+ /**
18
+ * The PMTiles archive a Collection has, or null when it has none this can
19
+ * fetch.
20
+ *
21
+ * The link is read first because it is the registration Portolan requires; the
22
+ * `visual` asset is the fallback for a catalogue that publishes only that half.
23
+ * A registration whose href is not an address the tile reader can fetch is not
24
+ * a registration: it is passed over, so a Collection with an unusable link and
25
+ * a loadable data asset still loads from the data asset rather than resolving
26
+ * to a PMTiles layer that can only draw nothing.
27
+ */
28
+ export function readCollectionPmtiles(collection) {
29
+ const link = collection.links?.find((candidate) => candidate.rel === 'pmtiles' && isFetchableArchiveHref(candidate.href));
30
+ if (link) {
31
+ return { href: link.href, layers: readPmtilesLayers(link['pmtiles:layers']) };
32
+ }
33
+ const asset = findAssetByRole(collection, VISUAL_ROLE);
34
+ if (asset && asset.type === PMTILES_MEDIA_TYPE && isFetchableArchiveHref(asset.href)) {
35
+ return { href: asset.href, layers: [] };
36
+ }
37
+ return null;
38
+ }
39
+ /**
40
+ * True for an href the tile reader can fetch: an absolute `http` or `https`
41
+ * address.
42
+ *
43
+ * Parsing alone is not the test. `new URL` accepts any well-formed absolute
44
+ * address whatever its scheme, so `file:`, `javascript:` and a `pmtiles://`
45
+ * prefix all parse — the last being the scheme the protomaps `pmtiles`
46
+ * package's MapLibre protocol handler reads, whose `Protocol.tilev4` matches
47
+ * `pmtiles://…` (read in `node_modules/pmtiles` at 4.5.0, the version
48
+ * `ol-pmtiles` pins). web-map-links says this href is a "Link to a PMTiles
49
+ * file (usually ends with `.pmtiles`)"
50
+ * (https://github.com/stac-extensions/web-map-links § PMTiles, read
51
+ * 2026-08-12), so none of those is an address to follow here.
52
+ */
53
+ function isFetchableArchiveHref(href) {
54
+ if (!href)
55
+ return false;
56
+ try {
57
+ const { protocol } = new URL(href);
58
+ return protocol === 'https:' || protocol === 'http:';
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ }
64
+ /** The `pmtiles:layers` array, keeping only the strings a layer name can be. */
65
+ function readPmtilesLayers(value) {
66
+ if (!Array.isArray(value))
67
+ return [];
68
+ return value.filter((entry) => typeof entry === 'string' && entry.length > 0);
69
+ }
@@ -0,0 +1,14 @@
1
+ import type { StacCollection } from './Stac.ts';
2
+ /**
3
+ * A Collection's declared file size and row count: `file:size` on its `data`
4
+ * asset (File extension) and `table:row_count` on the Collection (Table
5
+ * extension). Both are what the catalogue states, not what was measured, so a
6
+ * count read here is for display and never one a load is checked against.
7
+ */
8
+ export declare const FILE_EXTENSION = "https://stac-extensions.github.io/file/v2.1.0/schema.json";
9
+ export declare const FILE_SIZE_FIELD = "file:size";
10
+ export declare const TABLE_ROW_COUNT_FIELD = "table:row_count";
11
+ /** The `data` asset's `file:size` in bytes, or null where it is absent or not a whole number above zero. */
12
+ export declare function readDataAssetFileSize(collection: StacCollection): number | null;
13
+ /** The Collection's `table:row_count`, or null where it is absent or not a whole number of zero or more. */
14
+ export declare function readCollectionRowCount(collection: StacCollection): number | null;
@@ -0,0 +1,20 @@
1
+ import { readDataAsset } from "./stacAssetRoles.js";
2
+ /**
3
+ * A Collection's declared file size and row count: `file:size` on its `data`
4
+ * asset (File extension) and `table:row_count` on the Collection (Table
5
+ * extension). Both are what the catalogue states, not what was measured, so a
6
+ * count read here is for display and never one a load is checked against.
7
+ */
8
+ export const FILE_EXTENSION = 'https://stac-extensions.github.io/file/v2.1.0/schema.json';
9
+ export const FILE_SIZE_FIELD = 'file:size';
10
+ export const TABLE_ROW_COUNT_FIELD = 'table:row_count';
11
+ /** The `data` asset's `file:size` in bytes, or null where it is absent or not a whole number above zero. */
12
+ export function readDataAssetFileSize(collection) {
13
+ const size = readDataAsset(collection)?.[FILE_SIZE_FIELD];
14
+ return Number.isSafeInteger(size) && size > 0 ? size : null;
15
+ }
16
+ /** The Collection's `table:row_count`, or null where it is absent or not a whole number of zero or more. */
17
+ export function readCollectionRowCount(collection) {
18
+ const count = collection[TABLE_ROW_COUNT_FIELD];
19
+ return Number.isSafeInteger(count) && count >= 0 ? count : null;
20
+ }
@@ -0,0 +1,93 @@
1
+ import type { StacAsset, StacCollection } from './Stac.ts';
2
+ /**
3
+ * A Collection's styles — the assets with the `style` role.
4
+ *
5
+ * One rule covers every source (`packages/quac/spec/README.md` § Styles): a basemap's
6
+ * MapLibre style documents, a QGIS layer's named styles, and a cloud folder's
7
+ * sibling style files are all style assets on their Collection, and all read
8
+ * through here. The asset's key is the style's name as its source records it,
9
+ * and its media type says what kind of style document sits behind the address.
10
+ *
11
+ * The default is the asset with the `default` role alongside `style`, not
12
+ * the one written first — see `DEFAULT_STYLE_ROLE` for why position cannot
13
+ * express it. A source that marks none falls back to the first listed.
14
+ */
15
+ export interface StacStyle {
16
+ /** The style's name, as its source records it — the asset's title. */
17
+ name: string;
18
+ /** Where the style document comes from; never the style itself. */
19
+ href: string;
20
+ /** The style document's media type, when the source declares one. */
21
+ type?: string;
22
+ /**
23
+ * True when the Collection nominates this asset as its default, by the
24
+ * `default` role. Absent means the source said nothing, never "not the
25
+ * default" — see `getDefaultStyle`.
26
+ */
27
+ isDefault?: boolean;
28
+ /**
29
+ * The field this style classifies by, when its source declared one — see
30
+ * `QUAC_CATEGORISED_FIELD`. Absent means the source said nothing, never "this
31
+ * style is not categorised": a folder's `.qml` and a catalogue written by
32
+ * somebody else both leave it out, and a reader that needs the answer there
33
+ * derives it from the converted style instead.
34
+ */
35
+ categorisedField?: string;
36
+ /**
37
+ * The style overrides to merge into this style document, in order — see
38
+ * `QUAC_STYLE_OVERRIDES`. Absent means none: the style draws as published.
39
+ */
40
+ overrides?: StyleOverrideReference[];
41
+ }
42
+ /**
43
+ * One style override: the address of a JSON document, or the document itself.
44
+ * Either holds the values to merge over the style document it is listed on.
45
+ */
46
+ export type StyleOverrideReference = string | Record<string, unknown>;
47
+ /**
48
+ * The role marking the asset a Collection nominates as its default style.
49
+ *
50
+ * The default cannot be expressed by the order the assets are written in, because
51
+ * `assets` is a JSON object and JavaScript does not enumerate one in insertion
52
+ * order: a key that looks like a whole number — a QGIS style named `2024` — is
53
+ * yielded ahead of every other key, whenever it was written. So the document
54
+ * says which asset is the default rather than implying it by position.
55
+ */
56
+ export declare const DEFAULT_STYLE_ROLE = "default";
57
+ /** MapLibre/Mapbox GL style document — a vector basemap's style. */
58
+ export declare const GL_STYLE_MEDIA_TYPE = "application/vnd.mapbox.style+json";
59
+ /**
60
+ * Every style a Collection declares.
61
+ *
62
+ * The style's name comes from the asset's `title`, falling back to its key. The
63
+ * two are the same except where a source had to disambiguate the key — see
64
+ * `styleAssetKey` — and there the title is the name the source actually gave
65
+ * the style.
66
+ *
67
+ * The order is whatever `Object.entries` yields, which is *not* the order the
68
+ * document was written in whenever a key looks like a whole number. Nothing
69
+ * should read position from this list; `getDefaultStyle` is what answers
70
+ * "which one is the default".
71
+ */
72
+ export declare function collectCollectionStyles(collection: StacCollection): StacStyle[];
73
+ /**
74
+ * A key for a style asset that does not displace one already in the set.
75
+ *
76
+ * Asset keys share one namespace per Collection, so a style whose name matches
77
+ * a key already used — `data` most of all, which every data-bearing Collection
78
+ * reserves — would otherwise overwrite it and leave the layer with no source to
79
+ * load from. The style's real name is kept on the asset's `title`, which is what
80
+ * `collectCollectionStyles` reads, so disambiguating the key changes nothing a
81
+ * person sees.
82
+ */
83
+ export declare function styleAssetKey(assets: Record<string, StacAsset>, name: string): string;
84
+ /**
85
+ * The style used when nothing narrows the choice: the one the Collection marks
86
+ * with the `default` role.
87
+ *
88
+ * Falls back to the first listed for a Collection that marks none — a document
89
+ * written by somebody else, or one of ours from before the role existed. That
90
+ * fallback has the ordering hazard `DEFAULT_STYLE_ROLE` describes, which is
91
+ * why every generator here marks its default rather than relying on it.
92
+ */
93
+ export declare function getDefaultStyle(styles: StacStyle[]): StacStyle | undefined;
@@ -0,0 +1,87 @@
1
+ /** The key a style asset stores its categorised field under. */
2
+ const QUAC_CATEGORISED_FIELD = 'quac:categorised_field';
3
+ /** The key a style asset stores its style overrides under. */
4
+ const QUAC_STYLE_OVERRIDES = 'quac:style_overrides';
5
+ function readStyleOverrides(value) {
6
+ if (!Array.isArray(value))
7
+ return [];
8
+ return value.flatMap((entry) => {
9
+ if (typeof entry === 'string')
10
+ return entry.trim() ? [entry.trim()] : [];
11
+ return typeof entry === 'object' && entry !== null && !Array.isArray(entry) ? [entry] : [];
12
+ });
13
+ }
14
+ /**
15
+ * The role marking the asset a Collection nominates as its default style.
16
+ *
17
+ * The default cannot be expressed by the order the assets are written in, because
18
+ * `assets` is a JSON object and JavaScript does not enumerate one in insertion
19
+ * order: a key that looks like a whole number — a QGIS style named `2024` — is
20
+ * yielded ahead of every other key, whenever it was written. So the document
21
+ * says which asset is the default rather than implying it by position.
22
+ */
23
+ export const DEFAULT_STYLE_ROLE = 'default';
24
+ /** MapLibre/Mapbox GL style document — a vector basemap's style. */
25
+ export const GL_STYLE_MEDIA_TYPE = 'application/vnd.mapbox.style+json';
26
+ /**
27
+ * Every style a Collection declares.
28
+ *
29
+ * The style's name comes from the asset's `title`, falling back to its key. The
30
+ * two are the same except where a source had to disambiguate the key — see
31
+ * `styleAssetKey` — and there the title is the name the source actually gave
32
+ * the style.
33
+ *
34
+ * The order is whatever `Object.entries` yields, which is *not* the order the
35
+ * document was written in whenever a key looks like a whole number. Nothing
36
+ * should read position from this list; `getDefaultStyle` is what answers
37
+ * "which one is the default".
38
+ */
39
+ export function collectCollectionStyles(collection) {
40
+ return Object.entries(collection.assets ?? {})
41
+ .filter(([, asset]) => asset.roles?.includes('style'))
42
+ .map(([key, asset]) => {
43
+ const style = { name: asset.title ?? key, href: asset.href };
44
+ if (asset.type)
45
+ style.type = asset.type;
46
+ if (asset.roles?.includes(DEFAULT_STYLE_ROLE))
47
+ style.isDefault = true;
48
+ const categorisedField = asset[QUAC_CATEGORISED_FIELD];
49
+ if (typeof categorisedField === 'string' && categorisedField.trim()) {
50
+ style.categorisedField = categorisedField.trim();
51
+ }
52
+ const overrides = readStyleOverrides(asset[QUAC_STYLE_OVERRIDES]);
53
+ if (overrides.length > 0)
54
+ style.overrides = overrides;
55
+ return style;
56
+ });
57
+ }
58
+ /**
59
+ * A key for a style asset that does not displace one already in the set.
60
+ *
61
+ * Asset keys share one namespace per Collection, so a style whose name matches
62
+ * a key already used — `data` most of all, which every data-bearing Collection
63
+ * reserves — would otherwise overwrite it and leave the layer with no source to
64
+ * load from. The style's real name is kept on the asset's `title`, which is what
65
+ * `collectCollectionStyles` reads, so disambiguating the key changes nothing a
66
+ * person sees.
67
+ */
68
+ export function styleAssetKey(assets, name) {
69
+ if (!(name in assets))
70
+ return name;
71
+ let suffix = 2;
72
+ while (`${name} (${suffix})` in assets)
73
+ suffix += 1;
74
+ return `${name} (${suffix})`;
75
+ }
76
+ /**
77
+ * The style used when nothing narrows the choice: the one the Collection marks
78
+ * with the `default` role.
79
+ *
80
+ * Falls back to the first listed for a Collection that marks none — a document
81
+ * written by somebody else, or one of ours from before the role existed. That
82
+ * fallback has the ordering hazard `DEFAULT_STYLE_ROLE` describes, which is
83
+ * why every generator here marks its default rather than relying on it.
84
+ */
85
+ export function getDefaultStyle(styles) {
86
+ return styles.find((style) => style.isDefault) ?? styles[0];
87
+ }
@@ -0,0 +1,36 @@
1
+ import type { StacCatalog, StacCollection } from './Stac.ts';
2
+ /**
3
+ * Collects every Collection in a Catalog tree, depth-first, in the order the
4
+ * source declared its layers — a Collection inside a group Catalog appears
5
+ * between the top-level Collections that surround the group.
6
+ *
7
+ * A Catalog holds its child Collections and child Catalogs in two separate
8
+ * arrays, so the interleaving is read back from the `rel: "child"` links,
9
+ * which the generator writes in source order (`./collections/{id}.json` for a
10
+ * Collection, `./catalogs/{id}/catalog.json` for a group). A child whose link
11
+ * cannot be matched — an external document with its own link shapes — is
12
+ * appended after the linked ones, so nothing is dropped and external
13
+ * catalogues degrade to "Collections first, then groups" order.
14
+ *
15
+ * Child ids are not guaranteed unique: sibling group Catalogs slugify their
16
+ * names, and two group names can collapse to the same slug ("Roads"/"roads",
17
+ * or two unnamed groups both falling back to "group"). Visits are therefore
18
+ * tracked per object, and a link claims the first still-unvisited child with
19
+ * its id — links and children are both written in source order, so colliding
20
+ * siblings pair up by position and every child is emitted exactly once.
21
+ */
22
+ export declare function collectCatalogueCollections(catalog: StacCatalog): StacCollection[];
23
+ /** One child of a Catalog: a Collection, or a group Catalog. */
24
+ export type CatalogueChild = {
25
+ kind: 'collection';
26
+ collection: StacCollection;
27
+ } | {
28
+ kind: 'catalog';
29
+ catalog: StacCatalog;
30
+ };
31
+ /**
32
+ * A Catalog's own children, Collections and group Catalogs together, in the
33
+ * order its `rel: "child"` links list them, by the rule `collectCatalogueCollections`
34
+ * describes. The basemap picker offers these as its choices.
35
+ */
36
+ export declare function listCatalogueChildren(catalog: StacCatalog): CatalogueChild[];
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Collects every Collection in a Catalog tree, depth-first, in the order the
3
+ * source declared its layers — a Collection inside a group Catalog appears
4
+ * between the top-level Collections that surround the group.
5
+ *
6
+ * A Catalog holds its child Collections and child Catalogs in two separate
7
+ * arrays, so the interleaving is read back from the `rel: "child"` links,
8
+ * which the generator writes in source order (`./collections/{id}.json` for a
9
+ * Collection, `./catalogs/{id}/catalog.json` for a group). A child whose link
10
+ * cannot be matched — an external document with its own link shapes — is
11
+ * appended after the linked ones, so nothing is dropped and external
12
+ * catalogues degrade to "Collections first, then groups" order.
13
+ *
14
+ * Child ids are not guaranteed unique: sibling group Catalogs slugify their
15
+ * names, and two group names can collapse to the same slug ("Roads"/"roads",
16
+ * or two unnamed groups both falling back to "group"). Visits are therefore
17
+ * tracked per object, and a link claims the first still-unvisited child with
18
+ * its id — links and children are both written in source order, so colliding
19
+ * siblings pair up by position and every child is emitted exactly once.
20
+ */
21
+ export function collectCatalogueCollections(catalog) {
22
+ return listCatalogueChildren(catalog).flatMap((child) => (child.kind === 'collection' ? [child.collection] : collectCatalogueCollections(child.catalog)));
23
+ }
24
+ /**
25
+ * A Catalog's own children, Collections and group Catalogs together, in the
26
+ * order its `rel: "child"` links list them, by the rule `collectCatalogueCollections`
27
+ * describes. The basemap picker offers these as its choices.
28
+ */
29
+ export function listCatalogueChildren(catalog) {
30
+ const collections = catalog.collections ?? [];
31
+ const catalogs = catalog.catalogs ?? [];
32
+ const visited = new Set();
33
+ const out = [];
34
+ for (const link of catalog.links ?? []) {
35
+ if (link.rel !== 'child')
36
+ continue;
37
+ const collectionId = matchIdFromHref(link.href, /\/collections\/(.+)\.json$/);
38
+ if (collectionId !== null) {
39
+ const collection = firstUnvisited(collections, collectionId, visited);
40
+ if (collection) {
41
+ visited.add(collection);
42
+ out.push({ kind: 'collection', collection });
43
+ continue;
44
+ }
45
+ }
46
+ const catalogId = matchIdFromHref(link.href, /\/catalogs\/(.+)\/catalog\.json$/);
47
+ if (catalogId !== null) {
48
+ const child = firstUnvisited(catalogs, catalogId, visited);
49
+ if (child) {
50
+ visited.add(child);
51
+ out.push({ kind: 'catalog', catalog: child });
52
+ }
53
+ }
54
+ }
55
+ for (const collection of collections) {
56
+ if (!visited.has(collection))
57
+ out.push({ kind: 'collection', collection });
58
+ }
59
+ for (const child of catalogs) {
60
+ if (!visited.has(child))
61
+ out.push({ kind: 'catalog', catalog: child });
62
+ }
63
+ return out;
64
+ }
65
+ function firstUnvisited(items, id, visited) {
66
+ for (const item of items) {
67
+ if (item.id === id && !visited.has(item))
68
+ return item;
69
+ }
70
+ return null;
71
+ }
72
+ // The generator writes ids into hrefs verbatim, so the match is verbatim too.
73
+ function matchIdFromHref(href, pattern) {
74
+ const match = pattern.exec(href);
75
+ return match ? match[1] : null;
76
+ }
@@ -0,0 +1,18 @@
1
+ import type { WmsDataSource } from './QgsProject.ts';
2
+ import type { StacCollection, StacLink } from './Stac.ts';
3
+ /**
4
+ * The CRS a QGIS Server layer is requested in: the map's own when the server
5
+ * offers it, so the server draws it without the app reprojecting the image.
6
+ */
7
+ export declare const PREFERRED_WMS_CRS = "EPSG:3857";
8
+ /** The CRS a WMS link asks for from the CRSs its server offers: `PREFERRED_WMS_CRS` where it is offered or none is listed, else the first. */
9
+ export declare function chooseWmsCrs(crsList: readonly string[]): string;
10
+ export declare const WEB_MAP_LINKS_EXTENSION = "https://stac-extensions.github.io/web-map-links/v1.3.0/schema.json";
11
+ export type StacWmsSource = Omit<WmsDataSource, 'raw' | 'kind'>;
12
+ /** The parameters of a WMS request, which an endpoint's address does not keep. */
13
+ export declare const WMS_REQUEST_PARAMETERS: Set<string>;
14
+ /** Removes WMS request parameters while retaining service-specific routing parameters. */
15
+ export declare function wmsEndpoint(href: string): string | null;
16
+ export declare function buildWmsLink(source: WmsDataSource): StacLink | null;
17
+ /** Reads a single WMS rendering group; array members in web-map-links are separate groups. */
18
+ export declare function readCollectionWms(collection: StacCollection): StacWmsSource | null;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The CRS a QGIS Server layer is requested in: the map's own when the server
3
+ * offers it, so the server draws it without the app reprojecting the image.
4
+ */
5
+ export const PREFERRED_WMS_CRS = 'EPSG:3857';
6
+ /** The CRS a WMS link asks for from the CRSs its server offers: `PREFERRED_WMS_CRS` where it is offered or none is listed, else the first. */
7
+ export function chooseWmsCrs(crsList) {
8
+ return crsList.length === 0 || crsList.includes(PREFERRED_WMS_CRS) ? PREFERRED_WMS_CRS : crsList[0];
9
+ }
10
+ export const WEB_MAP_LINKS_EXTENSION = 'https://stac-extensions.github.io/web-map-links/v1.3.0/schema.json';
11
+ /** The parameters of a WMS request, which an endpoint's address does not keep. */
12
+ export const WMS_REQUEST_PARAMETERS = new Set(['SERVICE', 'REQUEST', 'VERSION', 'LAYERS', 'STYLES', 'FORMAT', 'TRANSPARENT', 'CRS', 'SRS', 'BBOX', 'WIDTH', 'HEIGHT']);
13
+ /** Removes WMS request parameters while retaining service-specific routing parameters. */
14
+ export function wmsEndpoint(href) {
15
+ try {
16
+ const url = new URL(href);
17
+ if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password)
18
+ return null;
19
+ for (const key of Array.from(url.searchParams.keys())) {
20
+ if (WMS_REQUEST_PARAMETERS.has(key.toUpperCase()))
21
+ url.searchParams.delete(key);
22
+ }
23
+ url.hash = '';
24
+ return url.toString();
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ export function buildWmsLink(source) {
31
+ const href = wmsEndpoint(source.url);
32
+ if (!href)
33
+ return null;
34
+ return {
35
+ rel: 'wms', href, type: source.format,
36
+ 'wms:layers': [source.layers.join(',')],
37
+ 'wms:styles': [source.styles.join(',')],
38
+ 'wms:transparent': source.transparent,
39
+ 'wms:dimensions': source.dimensions,
40
+ 'quac:wms_crs': source.crs,
41
+ ...(source.version ? { 'quac:wms_version': source.version } : {})
42
+ };
43
+ }
44
+ /** Reads a single WMS rendering group; array members in web-map-links are separate groups. */
45
+ export function readCollectionWms(collection) {
46
+ for (const link of collection.links ?? []) {
47
+ if (link.rel !== 'wms')
48
+ continue;
49
+ const url = wmsEndpoint(link.href);
50
+ const layers = link['wms:layers'];
51
+ const styles = link['wms:styles'] ?? [];
52
+ const version = link['quac:wms_version'];
53
+ if (!url || !Array.isArray(layers) || layers.length !== 1
54
+ || typeof layers[0] !== 'string' || !layers[0].trim()
55
+ || !Array.isArray(styles) || styles.length > 1 || styles.some((value) => typeof value !== 'string')
56
+ || (version !== undefined && version !== '1.1.1' && version !== '1.3.0'))
57
+ continue;
58
+ const dimensions = link['wms:dimensions'] ?? {};
59
+ if (!dimensions || typeof dimensions !== 'object' || Array.isArray(dimensions)
60
+ || Object.values(dimensions).some((value) => typeof value !== 'string')
61
+ || Object.keys(dimensions).some((key) => WMS_REQUEST_PARAMETERS.has(key.toUpperCase())))
62
+ continue;
63
+ return {
64
+ url, layers: layers[0].split(','), styles: (styles[0] ?? '').split(','),
65
+ format: link.type ?? 'image/png',
66
+ crs: typeof link['quac:wms_crs'] === 'string' ? link['quac:wms_crs'] : 'EPSG:3857',
67
+ version: version ?? null,
68
+ transparent: link['wms:transparent'] === true,
69
+ dimensions: dimensions
70
+ };
71
+ }
72
+ return null;
73
+ }
@@ -0,0 +1,34 @@
1
+ import type { WmtsDataSource } from './QgsProject.ts';
2
+ import type { StacCollection, StacLink } from './Stac.ts';
3
+ /** A WMTS layer's settings as a `rel: "wmts"` web-map-links link holds them. */
4
+ export interface StacWmtsSource {
5
+ /** The service address, or the address of its capabilities document for REST encoding. */
6
+ url: string;
7
+ encoding: 'kvp' | 'rest';
8
+ layer: string;
9
+ /** Style identifier; empty for the layer's default style. */
10
+ style: string;
11
+ /** Null to take the layer's first tile matrix set. */
12
+ tileMatrixSet: string | null;
13
+ /** Tile image media type; null to take the layer's first. */
14
+ format: string | null;
15
+ dimensions: Record<string, string>;
16
+ }
17
+ /**
18
+ * Removes WMTS request parameters from a KVP service address while retaining
19
+ * service-specific routing parameters. A capabilities document's address is
20
+ * kept as it is. Null for anything but an `http`/`https` address with no
21
+ * credentials in it.
22
+ */
23
+ export declare function wmtsEndpoint(href: string): string | null;
24
+ /** The address the layer's capabilities document is requested from. */
25
+ export declare function wmtsCapabilitiesUrl(source: Pick<StacWmtsSource, 'url' | 'encoding'>): string;
26
+ /**
27
+ * The web-map-links v1.3.0 link for a QGIS WMTS layer. `quac:wmts_tile_matrix_set`
28
+ * and `quac:wmts_style` keep the settings the extension does not define. A KVP
29
+ * link states the tile format as its `type`; a REST link's `type` is its
30
+ * capabilities document's, and the format comes from the document.
31
+ */
32
+ export declare function buildWmtsLink(source: WmtsDataSource): StacLink | null;
33
+ /** Reads the first WMTS link naming one layer. */
34
+ export declare function readCollectionWmts(collection: StacCollection): StacWmtsSource | null;