@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,74 @@
1
+ /**
2
+ * QGIS's date patterns are Qt's (`QLocale::toString`, which hands them to
3
+ * `QCalendarBackend::dateTimeToString`, `src/corelib/text/qlocale.cpp`,
4
+ * `qt/qtbase@3a00b02`, read 2026-10-26). This file splits a pattern the way Qt
5
+ * does and formats a date under it for `format_date`; `fieldDateFormat.ts`
6
+ * splits stored date patterns with the same `splitQtDatePattern`.
7
+ *
8
+ * The letters are `y`, `M`, `d`, `h`, `H`, `m`, `s`, `z`, `a`/`A` (with an
9
+ * optional `p`/`P` after) and `t`. Any other character, and text in single
10
+ * quotes, is written as it stands. `t` (a time zone's name or offset) is not
11
+ * formatted, so a pattern holding it is not read.
12
+ */
13
+ /** One piece of a split pattern: a run of one letter, text in quotes, or other characters. */
14
+ export type QtPatternPiece = {
15
+ letter: string;
16
+ count: number;
17
+ } | {
18
+ quoted: string;
19
+ } | {
20
+ literal: string;
21
+ };
22
+ /**
23
+ * A pattern split into runs of the same letter, quoted text and the characters
24
+ * between (`qt_repeatCount` and `qt_readEscapedFormatString`): `''` is a quote,
25
+ * inside quotes or out, and quoted text with no closing quote runs to the end.
26
+ */
27
+ export declare function splitQtDatePattern(pattern: string): QtPatternPiece[];
28
+ /** Whether `format_date` formats a pattern: true unless it names a time zone with `t`. */
29
+ export declare function isFormattableQtDatePattern(pattern: string): boolean;
30
+ /**
31
+ * A moment and the zone it is shown in: the device's own, or a fixed offset
32
+ * from UTC in minutes. Qt shows a date-time in the zone it was read with, so
33
+ * `2026-10-26T04:30:00Z` is shown as 04:30 on any device.
34
+ */
35
+ export interface QtDateTime {
36
+ epoch: number;
37
+ offsetMinutes: number | 'local';
38
+ }
39
+ /**
40
+ * A value as QGIS's `getDateTimeValue` reads one for `format_date`
41
+ * (`src/core/expression/qgsexpressionutils.h`, `qgis/QGIS@16eddb2`, read
42
+ * 2026-10-26): a JavaScript date (`now()`) in the device's zone, or text Qt
43
+ * reads as an ISO date-time (`QDateTime::fromString` with `Qt::ISODate`,
44
+ * `qdatetime.cpp`, `qt/qtbase@3a00b02`). That is `yyyy-MM-dd`, at midnight on
45
+ * its own, or followed by `T` or a space and a time, with `Z` for UTC or an
46
+ * offset such as `+10:00`; with neither it is the device's time. Text that is
47
+ * only a time is that time on 1 January of year 1. Null for anything else,
48
+ * where QGIS reports an error.
49
+ */
50
+ export declare function readQtDateTime(value: unknown): QtDateTime | null;
51
+ /**
52
+ * A part of a date, as QGIS's `year`, `month`, `day`, `week`, `day_of_week`,
53
+ * `hour`, `minute` and `second` give it (`fcnYear` to `fcnSeconds`,
54
+ * `fcnDayOfWeek` and `fcnWeek`, `src/core/expression/qgsexpressionfunction.cpp`,
55
+ * `qgis/QGIS@16eddb2`, read 2026-10-26). The value is read as `format_date`
56
+ * reads one (`readQtDateTime`) and the part is taken in its zone. A field QGIS
57
+ * holds as a date-time reaches Groundwork as ISO text, so such text counts as a
58
+ * date-time. QGIS takes no time from a date alone and no weekday from a time
59
+ * alone, so `hour`, `minute` and `second` of `2026-10-06`, and `day_of_week` of
60
+ * `14:05`, are null, where QGIS reports an error. A time alone is read on
61
+ * 0001-01-01, so its `year`, `month`, `day` and `week` are 1. `day_of_week`
62
+ * counts from 0 for Sunday. QGIS also takes a span of time, which Groundwork never makes.
63
+ */
64
+ export declare function qtDatePart(part: string, value: unknown): number | null;
65
+ /**
66
+ * A date under a QGIS date pattern, as `format_date(datetime, format,
67
+ * language)` gives it (`fcnFormatDate`, `src/core/expression/qgsexpressionfunction.cpp`,
68
+ * `qgis/QGIS@16eddb2`, read 2026-10-26). A `Z` anywhere after the pattern's
69
+ * first character shows the moment in UTC. Month and day names, am and pm and
70
+ * the digits are in `language`; QGIS uses the computer's own language when
71
+ * none is given, and Groundwork uses `en-AU`, as `format_number` does. Null
72
+ * for a pattern holding `t` and for a language the browser cannot read.
73
+ */
74
+ export declare function formatQtDateTime(value: QtDateTime, pattern: string, language?: string | null): string | null;
@@ -0,0 +1,324 @@
1
+ /**
2
+ * QGIS's date patterns are Qt's (`QLocale::toString`, which hands them to
3
+ * `QCalendarBackend::dateTimeToString`, `src/corelib/text/qlocale.cpp`,
4
+ * `qt/qtbase@3a00b02`, read 2026-10-26). This file splits a pattern the way Qt
5
+ * does and formats a date under it for `format_date`; `fieldDateFormat.ts`
6
+ * splits stored date patterns with the same `splitQtDatePattern`.
7
+ *
8
+ * The letters are `y`, `M`, `d`, `h`, `H`, `m`, `s`, `z`, `a`/`A` (with an
9
+ * optional `p`/`P` after) and `t`. Any other character, and text in single
10
+ * quotes, is written as it stands. `t` (a time zone's name or offset) is not
11
+ * formatted, so a pattern holding it is not read.
12
+ */
13
+ /**
14
+ * A pattern split into runs of the same letter, quoted text and the characters
15
+ * between (`qt_repeatCount` and `qt_readEscapedFormatString`): `''` is a quote,
16
+ * inside quotes or out, and quoted text with no closing quote runs to the end.
17
+ */
18
+ export function splitQtDatePattern(pattern) {
19
+ const pieces = [];
20
+ const pushLiteral = (text) => {
21
+ const last = pieces[pieces.length - 1];
22
+ if (last && 'literal' in last)
23
+ last.literal += text;
24
+ else
25
+ pieces.push({ literal: text });
26
+ };
27
+ let index = 0;
28
+ while (index < pattern.length) {
29
+ const char = pattern[index];
30
+ if (char === "'") {
31
+ if (pattern[index + 1] === "'") {
32
+ pushLiteral("'");
33
+ index += 2;
34
+ continue;
35
+ }
36
+ let text = '';
37
+ index += 1;
38
+ while (index < pattern.length) {
39
+ if (pattern[index] === "'") {
40
+ if (pattern[index + 1] !== "'")
41
+ break;
42
+ text += "'";
43
+ index += 2;
44
+ }
45
+ else {
46
+ text += pattern[index];
47
+ index += 1;
48
+ }
49
+ }
50
+ index += 1;
51
+ pieces.push({ quoted: text });
52
+ }
53
+ else if (/[A-Za-z]/.test(char)) {
54
+ let end = index;
55
+ while (pattern[end] === char)
56
+ end++;
57
+ pieces.push({ letter: char, count: end - index });
58
+ index = end;
59
+ }
60
+ else {
61
+ pushLiteral(char);
62
+ index += 1;
63
+ }
64
+ }
65
+ return pieces;
66
+ }
67
+ /** Whether `format_date` formats a pattern: true unless it names a time zone with `t`. */
68
+ export function isFormattableQtDatePattern(pattern) {
69
+ return splitQtDatePattern(pattern).every((piece) => !('letter' in piece) || piece.letter !== 't');
70
+ }
71
+ /** A local date and time, from parts, for years below 100 too (which `new Date` reads as 19xx). */
72
+ function localEpoch(year, month, day, hour = 0, minute = 0, second = 0, msec = 0) {
73
+ const date = new Date(0);
74
+ date.setFullYear(year, month - 1, day);
75
+ date.setHours(hour, minute, second, msec);
76
+ return date.getTime();
77
+ }
78
+ function utcEpoch(year, month, day, hour, minute, second, msec) {
79
+ const date = new Date(0);
80
+ date.setUTCFullYear(year, month - 1, day);
81
+ date.setUTCHours(hour, minute, second, msec);
82
+ return date.getTime();
83
+ }
84
+ function isRealDate(year, month, day) {
85
+ if (month < 1 || month > 12 || day < 1)
86
+ return false;
87
+ return day <= new Date(Date.UTC(2000, month, 0)).getUTCDate() && !(month === 2 && day === 29 && !(year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)));
88
+ }
89
+ const ISO_TIME = /^(\d{2})(?::(\d{2})(?::(\d{2})(?:[.,](\d+))?)?)?$/;
90
+ const ISO_OFFSET = /^([+-])(\d{2})(?::?(\d{2}))?$/;
91
+ /** `HH`, `HH:mm`, `HH:mm:ss` or `HH:mm:ss.zzz` (`fromIsoTimeString`, `qdatetime.cpp`), with 24:00 allowed. */
92
+ function readIsoTime(text) {
93
+ const match = ISO_TIME.exec(text);
94
+ if (!match)
95
+ return null;
96
+ const [hour, minute, second] = [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)];
97
+ const msec = match[4] ? Math.round(Number(`0.${match[4]}`) * 1000) : 0;
98
+ if (hour > 24 || minute > 59 || second > 59)
99
+ return null;
100
+ if (hour === 24 && (minute || second || msec))
101
+ return null;
102
+ // A fraction that rounds up to a whole second is kept as 999, as QTime cannot hold 1000.
103
+ return { hour, minute, second, msec: Math.min(msec, 999) };
104
+ }
105
+ /**
106
+ * A value as QGIS's `getDateTimeValue` reads one for `format_date`
107
+ * (`src/core/expression/qgsexpressionutils.h`, `qgis/QGIS@16eddb2`, read
108
+ * 2026-10-26): a JavaScript date (`now()`) in the device's zone, or text Qt
109
+ * reads as an ISO date-time (`QDateTime::fromString` with `Qt::ISODate`,
110
+ * `qdatetime.cpp`, `qt/qtbase@3a00b02`). That is `yyyy-MM-dd`, at midnight on
111
+ * its own, or followed by `T` or a space and a time, with `Z` for UTC or an
112
+ * offset such as `+10:00`; with neither it is the device's time. Text that is
113
+ * only a time is that time on 1 January of year 1. Null for anything else,
114
+ * where QGIS reports an error.
115
+ */
116
+ export function readQtDateTime(value) {
117
+ if (value instanceof Date)
118
+ return Number.isNaN(value.getTime()) ? null : { epoch: value.getTime(), offsetMinutes: 'local' };
119
+ if (typeof value !== 'string')
120
+ return null;
121
+ const date = /^(\d{4})-(\d{2})-(\d{2})/.exec(value);
122
+ if (!date) {
123
+ const time = readIsoTime(value);
124
+ return time && time.hour < 24 ? { epoch: localEpoch(1, 1, 1, time.hour, time.minute, time.second, time.msec), offsetMinutes: 'local' } : null;
125
+ }
126
+ const [year, month, day] = [Number(date[1]), Number(date[2]), Number(date[3])];
127
+ if (!isRealDate(year, month, day))
128
+ return null;
129
+ if (value.length === 10)
130
+ return { epoch: localEpoch(year, month, day), offsetMinutes: 'local' };
131
+ if (!/^[Tt ]/.test(value.slice(10)))
132
+ return null;
133
+ let rest = value.slice(11);
134
+ let offsetMinutes = 'local';
135
+ if (/[Zz]$/.test(rest)) {
136
+ offsetMinutes = 0;
137
+ rest = rest.slice(0, -1);
138
+ }
139
+ else {
140
+ const sign = Math.max(rest.lastIndexOf('+'), rest.lastIndexOf('-'));
141
+ if (sign >= 0) {
142
+ const offset = ISO_OFFSET.exec(rest.slice(sign));
143
+ if (!offset)
144
+ return null;
145
+ offsetMinutes = (offset[1] === '-' ? -1 : 1) * (Number(offset[2]) * 60 + Number(offset[3] ?? 0));
146
+ rest = rest.slice(0, sign);
147
+ }
148
+ }
149
+ const time = readIsoTime(rest);
150
+ if (!time)
151
+ return null;
152
+ const epoch = offsetMinutes === 'local'
153
+ ? localEpoch(year, month, day, time.hour, time.minute, time.second, time.msec)
154
+ : utcEpoch(year, month, day, time.hour, time.minute, time.second, time.msec) - offsetMinutes * 60_000;
155
+ return { epoch, offsetMinutes };
156
+ }
157
+ /** The calendar parts of a moment as shown in its zone. */
158
+ function partsOf({ epoch, offsetMinutes }) {
159
+ const date = new Date(offsetMinutes === 'local' ? epoch : epoch + offsetMinutes * 60_000);
160
+ const utc = offsetMinutes !== 'local';
161
+ return {
162
+ year: utc ? date.getUTCFullYear() : date.getFullYear(),
163
+ month: (utc ? date.getUTCMonth() : date.getMonth()) + 1,
164
+ day: utc ? date.getUTCDate() : date.getDate(),
165
+ weekday: utc ? date.getUTCDay() : date.getDay(),
166
+ hour: utc ? date.getUTCHours() : date.getHours(),
167
+ minute: utc ? date.getUTCMinutes() : date.getMinutes(),
168
+ second: utc ? date.getUTCSeconds() : date.getSeconds(),
169
+ msec: utc ? date.getUTCMilliseconds() : date.getMilliseconds()
170
+ };
171
+ }
172
+ /** The ISO 8601 week of a date, 1 to 53, as `QDate::weekNumber` gives it: the week holding the year's first Thursday is week 1. */
173
+ function isoWeek(year, month, day) {
174
+ const date = new Date(utcEpoch(year, month, day, 12, 0, 0, 0));
175
+ date.setUTCDate(date.getUTCDate() + 3 - ((date.getUTCDay() + 6) % 7));
176
+ const thursday = date.getTime();
177
+ date.setUTCMonth(0, 1);
178
+ return Math.floor((thursday - date.getTime()) / (7 * 86_400_000)) + 1;
179
+ }
180
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
181
+ /**
182
+ * A part of a date, as QGIS's `year`, `month`, `day`, `week`, `day_of_week`,
183
+ * `hour`, `minute` and `second` give it (`fcnYear` to `fcnSeconds`,
184
+ * `fcnDayOfWeek` and `fcnWeek`, `src/core/expression/qgsexpressionfunction.cpp`,
185
+ * `qgis/QGIS@16eddb2`, read 2026-10-26). The value is read as `format_date`
186
+ * reads one (`readQtDateTime`) and the part is taken in its zone. A field QGIS
187
+ * holds as a date-time reaches Groundwork as ISO text, so such text counts as a
188
+ * date-time. QGIS takes no time from a date alone and no weekday from a time
189
+ * alone, so `hour`, `minute` and `second` of `2026-10-06`, and `day_of_week` of
190
+ * `14:05`, are null, where QGIS reports an error. A time alone is read on
191
+ * 0001-01-01, so its `year`, `month`, `day` and `week` are 1. `day_of_week`
192
+ * counts from 0 for Sunday. QGIS also takes a span of time, which Groundwork never makes.
193
+ */
194
+ export function qtDatePart(part, value) {
195
+ const moment = readQtDateTime(value);
196
+ if (!moment)
197
+ return null;
198
+ const timeOnly = typeof value === 'string' && !/^\d{4}-/.test(value);
199
+ const dateOnly = typeof value === 'string' && DATE_ONLY.test(value);
200
+ const parts = partsOf(moment);
201
+ switch (part) {
202
+ case 'year': return parts.year;
203
+ case 'month': return parts.month;
204
+ case 'day': return parts.day;
205
+ case 'week': return isoWeek(parts.year, parts.month, parts.day);
206
+ case 'day_of_week': return timeOnly ? null : parts.weekday;
207
+ case 'hour': return dateOnly ? null : parts.hour;
208
+ case 'minute': return dateOnly ? null : parts.minute;
209
+ case 'second': return dateOnly ? null : parts.second;
210
+ default: return null;
211
+ }
212
+ }
213
+ /** One named part of a date in a language: the form used inside a date (`октября`), as Qt's names are, not the standalone one. */
214
+ function namePart(locale, options, epoch, type) {
215
+ return new Intl.DateTimeFormat(locale, { timeZone: 'UTC', ...options }).formatToParts(epoch).find((part) => part.type === type)?.value ?? '';
216
+ }
217
+ /**
218
+ * A date under a QGIS date pattern, as `format_date(datetime, format,
219
+ * language)` gives it (`fcnFormatDate`, `src/core/expression/qgsexpressionfunction.cpp`,
220
+ * `qgis/QGIS@16eddb2`, read 2026-10-26). A `Z` anywhere after the pattern's
221
+ * first character shows the moment in UTC. Month and day names, am and pm and
222
+ * the digits are in `language`; QGIS uses the computer's own language when
223
+ * none is given, and Groundwork uses `en-AU`, as `format_number` does. Null
224
+ * for a pattern holding `t` and for a language the browser cannot read.
225
+ */
226
+ export function formatQtDateTime(value, pattern, language) {
227
+ if (!isFormattableQtDatePattern(pattern))
228
+ return null;
229
+ const shown = pattern.indexOf('Z') > 0 ? { ...value, offsetMinutes: 0 } : value;
230
+ const { year, month, day, weekday, hour, minute, second, msec } = partsOf(shown);
231
+ let locale;
232
+ try {
233
+ locale = Intl.getCanonicalLocales(language ? language.replace(/_/g, '-') : 'en-AU')[0] ?? 'en-AU';
234
+ }
235
+ catch {
236
+ return null;
237
+ }
238
+ const number = (count, width) => new Intl.NumberFormat(locale, { useGrouping: false, minimumIntegerDigits: width }).format(count);
239
+ const zero = number(0, 1);
240
+ // A day in the same month and weekday, read in UTC so no zone moves it.
241
+ const named = utcEpoch(2023, month, 1, 12, 0, 0, 0);
242
+ const sameWeekday = utcEpoch(2023, 1, 1 + weekday, 12, 0, 0, 0);
243
+ const dayPeriod = namePart(locale, { hour: 'numeric', hour12: true }, utcEpoch(2023, 1, 1, hour < 12 ? 9 : 15, 0, 0, 0), 'dayPeriod');
244
+ // `timeFormatContainsAP`: an `a` or `A` anywhere outside quotes makes `h` a 12-hour clock.
245
+ const pieces = splitQtDatePattern(pattern);
246
+ const twelveHour = pieces.some((piece) => 'letter' in piece && piece.letter.toLowerCase() === 'a');
247
+ let result = '';
248
+ for (const [position, piece] of pieces.entries()) {
249
+ if ('quoted' in piece) {
250
+ result += piece.quoted;
251
+ continue;
252
+ }
253
+ if ('literal' in piece) {
254
+ result += piece.literal;
255
+ continue;
256
+ }
257
+ const { letter } = piece;
258
+ let left = piece.count;
259
+ while (left > 0) {
260
+ let used = Math.min(left, letter === 'z' ? 3 : letter === 'M' || letter === 'd' ? 4 : 2);
261
+ switch (letter) {
262
+ case 'y':
263
+ used = left >= 4 ? 4 : left >= 2 ? 2 : 1;
264
+ result += used === 4 ? number(year, 4) : used === 2 ? number(year % 100, 2) : 'y';
265
+ break;
266
+ case 'M':
267
+ result += used <= 2
268
+ ? number(month, used)
269
+ : namePart(locale, { day: 'numeric', month: used === 3 ? 'short' : 'long' }, named, 'month');
270
+ break;
271
+ case 'd':
272
+ result += used <= 2
273
+ ? number(day, used)
274
+ : namePart(locale, { weekday: used === 3 ? 'short' : 'long', day: 'numeric', month: 'long' }, sameWeekday, 'weekday');
275
+ break;
276
+ case 'h': {
277
+ const clock = twelveHour ? (hour > 12 ? hour - 12 : hour === 0 ? 12 : hour) : hour;
278
+ result += number(clock, used);
279
+ break;
280
+ }
281
+ case 'H':
282
+ result += number(hour, used);
283
+ break;
284
+ case 'm':
285
+ result += number(minute, used);
286
+ break;
287
+ case 's':
288
+ result += number(second, used);
289
+ break;
290
+ case 'z': {
291
+ // Milliseconds as the fraction of a second: `zzz` keeps three digits, `z` and `zz` drop up to two trailing zeros.
292
+ let text = number(msec, 3);
293
+ if (used !== 3) {
294
+ for (let chop = 0; chop < 2 && text.endsWith(zero); chop++)
295
+ text = text.slice(0, -zero.length);
296
+ }
297
+ result += text;
298
+ break;
299
+ }
300
+ case 'a':
301
+ case 'A': {
302
+ // A `p` or `P` straight after joins the marker: `AP` is upper case, `ap` lower case, and `Ap` and `aP` as the language writes it. A lone `A` or `a` takes its own case.
303
+ const following = left === 1 ? pieces[position + 1] : undefined;
304
+ const p = following && 'letter' in following && following.letter.toLowerCase() === 'p' ? following : null;
305
+ used = 1;
306
+ if (letter === 'A' && (!p || p.letter === 'P'))
307
+ result += dayPeriod.toUpperCase();
308
+ else if (letter === 'a' && (!p || p.letter === 'p'))
309
+ result += dayPeriod.toLowerCase();
310
+ else
311
+ result += dayPeriod;
312
+ if (p)
313
+ p.count -= 1;
314
+ break;
315
+ }
316
+ default:
317
+ used = left;
318
+ result += letter.repeat(left);
319
+ }
320
+ left -= used;
321
+ }
322
+ }
323
+ return result;
324
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * QGIS hands a regular expression to Qt's `QRegularExpression`, which is PCRE2;
3
+ * Groundwork runs it as a JavaScript `RegExp`. The two engines differ in many
4
+ * corners (`pcre2pattern`, PCRE2 10.4x, read 2026-10-27), so this file reads
5
+ * only the forms listed here, written so that both give the same answer, and
6
+ * gives null for any other pattern, so the expression is not read rather than
7
+ * worked out differently.
8
+ *
9
+ * - A character, a backslash before one that is not a letter or digit, `\n`,
10
+ * `\r`, `\t`, `\f`, `\xhh` and `\x{…}`.
11
+ * - `.`, which matches anything but a line feed, `^`, and `$`, which also
12
+ * matches before a final line feed, as PCRE2 does by default.
13
+ * - `\d`, `\w`, `\s`, `\b` and their capitals. With `unicode` (QGIS's
14
+ * `regexp_` functions pass `UseUnicodePropertiesOption`,
15
+ * `src/core/expression/qgsexpressionfunction.cpp`; its `~` operator does
16
+ * not, `qgsexpressionnodeimpl.cpp`, `qgis/QGIS@16eddb2`, read 2026-10-26),
17
+ * they take in every script's digits, letters and spaces, as PCRE2's `UCP`
18
+ * does: `\w` is `\p{L}`, `\p{N}` and `_`, and `\s` is `\p{Z}` with the tab,
19
+ * line and vertical spaces. Without it they are the ASCII ones. That `\w`
20
+ * is PCRE2's before 10.43, which widens it to `\p{Mn}` and `\p{Pc}`; the
21
+ * two differ only on a combining mark or a joining mark such as ‿, where
22
+ * QGIS builds differ too, and Vectoria chose to keep the earlier one
23
+ * (2026-10-27, no reason given).
24
+ * - A class such as `[A-Z_]` or `[^\d,]`.
25
+ * - A group, `(…)` or `(?:…)`, and `|`.
26
+ * - `*`, `+`, `?`, `{n}`, `{n,}` and `{n,m}`, each also lazy with a `?` after it.
27
+ * - A lookahead, `(?=…)` or `(?!…)`, or a lookbehind, `(?<=…)` or `(?<!…)`,
28
+ * that holds no group.
29
+ * - A leading `(?i)`.
30
+ *
31
+ * Within those, these are not read either, because the engines give
32
+ * different answers:
33
+ * - a quantifier after an assertion, such as `\b?`, which PCRE2 refuses;
34
+ * - a quantifier that can repeat a group that captures, or holds a group that
35
+ * does, or a group that can match the empty text: JavaScript clears the
36
+ * inner groups at each repeat and refuses an empty pass of any group whose
37
+ * minimum is 0, and PCRE2 does neither;
38
+ * - a quantifier that can repeat a group holding a `|` or a quantifier whose
39
+ * count can vary, such as `(?:[A-Za-z]+ ?)*`: on text it fails to match,
40
+ * JavaScript can try every way to split it, where PCRE2 stops at its match
41
+ * limit and reports no match. In Node, `^(?:[A-Za-z]+ ?)*$` took 3 s on 26
42
+ * letters and a `!`, and twice as long for each letter more (2026-10-27);
43
+ * - in a lookbehind, a quantifier other than `{n}`, as PCRE2 before 10.43
44
+ * needs a lookbehind of a set length;
45
+ * - inside a class, `\b`, `\S`, and with `unicode` `\D` and `\W`, which have
46
+ * no JavaScript form there, and a `-` beside a class escape, which PCRE2
47
+ * refuses and JavaScript reads as a range;
48
+ * - for `~` with `(?i)`, `\w`, `\W`, `\b` and `\B`, which JavaScript widens
49
+ * to ſ and the Kelvin sign.
50
+ */
51
+ /**
52
+ * A PCRE2 pattern as a JavaScript `RegExp` that matches what QGIS matches, or
53
+ * null where Groundwork cannot translate it, or where the result does not
54
+ * compile. `unicode` is QGIS's `UseUnicodePropertiesOption`: on for the
55
+ * `regexp_` functions, off for `~`. The `RegExp` is shared, so a caller that
56
+ * matches globally makes its own from its `source` and `flags`.
57
+ */
58
+ export declare function compileQtRegex(pattern: string, unicode: boolean): RegExp | null;
59
+ /**
60
+ * `QString::replace` with a pattern (`src/corelib/text/qstring.cpp`,
61
+ * `qt/qtbase@3a00b02`, read 2026-10-26), which `regexp_replace` calls: every
62
+ * match is replaced, and in the replacement `\1` to `\99` stand for that group
63
+ * where the pattern has it, taking a second digit only where the pattern has
64
+ * that many groups. Any other backslash stays as written, and a group that
65
+ * took no part gives nothing.
66
+ */
67
+ export declare function replaceQtRegex(text: string, regex: RegExp, after: string): string;