@vectoriahq/quac 0.18.0-next.1 → 0.18.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.
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export { STAC_VERSION } from './model/Stac.ts';
8
8
  export { isIconLibraryAddress, resolveFieldIconAddress } from './model/fieldIconAddress.ts';
9
9
  export { collectCollectionStyles, getDefaultStyle, styleAssetKey, GL_STYLE_MEDIA_TYPE } from './model/stacStyles.ts';
10
10
  export type { StacStyle, StyleOverrideReference } from './model/stacStyles.ts';
11
+ export { readCollectionColourAdjustment } from './model/colourAdjustment.ts';
12
+ export type { ColourAdjustment } from './model/colourAdjustment.ts';
11
13
  export { parseQgsXml } from './parse/parseQgsXml.ts';
12
14
  export { measureFactorsOf } from './parse/parseMeasurement.ts';
13
15
  export type { MeasureFactors } from './parse/parseMeasurement.ts';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
  export { STAC_VERSION } from "./model/Stac.js";
6
6
  export { isIconLibraryAddress, resolveFieldIconAddress } from "./model/fieldIconAddress.js";
7
7
  export { collectCollectionStyles, getDefaultStyle, styleAssetKey, GL_STYLE_MEDIA_TYPE } from "./model/stacStyles.js";
8
+ export { readCollectionColourAdjustment } from "./model/colourAdjustment.js";
8
9
  export { parseQgsXml } from "./parse/parseQgsXml.js";
9
10
  export { measureFactorsOf } from "./parse/parseMeasurement.js";
10
11
  export { readProjectXml } from "./parse/readProjectFile.js";
@@ -0,0 +1,25 @@
1
+ import type { StacCollection } from './Stac.ts';
2
+ /**
3
+ * The colour adjustments a Collection declares for its layer, each as its
4
+ * `quac:` field states it. A reader applies them to every pixel's red, green
5
+ * and blue values in QGIS's order: contrast, brightness, gamma, saturation.
6
+ */
7
+ export interface ColourAdjustment {
8
+ /** `quac:contrast`, from -1 to 1; 0 leaves the layer unchanged. */
9
+ contrast: number;
10
+ /** `quac:brightness`, from -1 to 1; 0 leaves the layer unchanged. */
11
+ brightness: number;
12
+ /** `quac:gamma`, from 0.1 to 10; 1 leaves the layer unchanged. */
13
+ gamma: number;
14
+ /** `quac:saturation`, from -1 to 1; 0 leaves the layer unchanged. */
15
+ saturation: number;
16
+ }
17
+ /**
18
+ * The colour adjustments a Collection declares, or null where every one of
19
+ * them leaves the layer unchanged, so a caller draws the layer as it is.
20
+ *
21
+ * A value that is not a finite number is read as stating nothing, as is a
22
+ * gamma of 0 or below, which has no meaning. A value outside its field's range
23
+ * is brought to the nearer end of it.
24
+ */
25
+ export declare function readCollectionColourAdjustment(collection: StacCollection): ColourAdjustment | null;
@@ -0,0 +1,27 @@
1
+ /** What each field reads as when the Collection states nothing, and the range a value is brought into. */
2
+ const FIELDS = {
3
+ contrast: { key: 'quac:contrast', unchanged: 0, min: -1, max: 1 },
4
+ brightness: { key: 'quac:brightness', unchanged: 0, min: -1, max: 1 },
5
+ gamma: { key: 'quac:gamma', unchanged: 1, min: 0.1, max: 10 },
6
+ saturation: { key: 'quac:saturation', unchanged: 0, min: -1, max: 1 }
7
+ };
8
+ /**
9
+ * The colour adjustments a Collection declares, or null where every one of
10
+ * them leaves the layer unchanged, so a caller draws the layer as it is.
11
+ *
12
+ * A value that is not a finite number is read as stating nothing, as is a
13
+ * gamma of 0 or below, which has no meaning. A value outside its field's range
14
+ * is brought to the nearer end of it.
15
+ */
16
+ export function readCollectionColourAdjustment(collection) {
17
+ const adjustment = {};
18
+ let changes = false;
19
+ for (const [name, field] of Object.entries(FIELDS)) {
20
+ const value = collection[field.key];
21
+ const stated = typeof value === 'number' && Number.isFinite(value) && !(name === 'gamma' && value <= 0);
22
+ adjustment[name] = stated ? Math.min(field.max, Math.max(field.min, value)) : field.unchanged;
23
+ if (adjustment[name] !== field.unchanged)
24
+ changes = true;
25
+ }
26
+ return changes ? adjustment : null;
27
+ }
@@ -518,7 +518,7 @@ function parseFieldEditRules(maplayer, note) {
518
518
  const defaultValue = parseDefaultExpression(expression, onUpdate);
519
519
  if (defaultValue)
520
520
  ruleFor(name).defaultValue = defaultValue;
521
- else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true, variables: true, coordinates: true, dates: true }))
521
+ else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true, variables: true, coordinates: true }))
522
522
  ruleFor(name).defaultExpression = { expression: expression.trim(), onUpdate };
523
523
  else
524
524
  note('default', name, expression.trim());
@@ -166,15 +166,9 @@ export declare function isQgisConditionFilter(filter: unknown): filter is {
166
166
  *
167
167
  * `format_date` is read where its pattern and any language are text written
168
168
  * into the expression, and the pattern holds no `t` (`qtDateFormat.ts`).
169
- * `now()`, or `$now`, is read as the date of `format_date` or of a function
170
- * that takes a part of a date, such as `year`. Where the caller says `dates`
171
- * (a default value), it is read as a date in three more places: as the value
172
- * of the whole expression, as a side of a comparison, and as the date an
173
- * interval is added to or taken from. A branch of `if`, `CASE` or `coalesce`
174
- * in any of those places is one too, as in
175
- * `if("condition" IS NULL, "checked", now())`. Anywhere else, such as inside
176
- * `||` or `to_string`, it would be used as text or a number, which the
177
- * evaluator does not do (`findDatedNows`).
169
+ * `now()`, or `$now`, is read only as the date of `format_date` or of a
170
+ * function that takes a part of a date, such as `year`: anywhere else it would
171
+ * be compared or added as a date, which the evaluator does not do.
178
172
  *
179
173
  * A variable other than `@parent`, such as `@cloud_useremail`, is read only
180
174
  * where the caller says `variables`: the caller then supplies each one's value
@@ -197,7 +191,6 @@ export declare function readQgisExpression(expression: string, options?: {
197
191
  lookups?: boolean;
198
192
  variables?: boolean;
199
193
  coordinates?: boolean;
200
- dates?: boolean;
201
194
  }): ExpressionNode | null;
202
195
  /**
203
196
  * A QGIS rule's condition as a GeoStyler filter: the condition's GeoStyler
@@ -312,15 +312,9 @@ export function isQgisConditionFilter(filter) {
312
312
  *
313
313
  * `format_date` is read where its pattern and any language are text written
314
314
  * into the expression, and the pattern holds no `t` (`qtDateFormat.ts`).
315
- * `now()`, or `$now`, is read as the date of `format_date` or of a function
316
- * that takes a part of a date, such as `year`. Where the caller says `dates`
317
- * (a default value), it is read as a date in three more places: as the value
318
- * of the whole expression, as a side of a comparison, and as the date an
319
- * interval is added to or taken from. A branch of `if`, `CASE` or `coalesce`
320
- * in any of those places is one too, as in
321
- * `if("condition" IS NULL, "checked", now())`. Anywhere else, such as inside
322
- * `||` or `to_string`, it would be used as text or a number, which the
323
- * evaluator does not do (`findDatedNows`).
315
+ * `now()`, or `$now`, is read only as the date of `format_date` or of a
316
+ * function that takes a part of a date, such as `year`: anywhere else it would
317
+ * be compared or added as a date, which the evaluator does not do.
324
318
  *
325
319
  * A variable other than `@parent`, such as `@cloud_useremail`, is read only
326
320
  * where the caller says `variables`: the caller then supplies each one's value
@@ -371,7 +365,7 @@ export function readQgisExpression(expression, options = {}) {
371
365
  const formatDateCalls = findCalls(parsed.node, 'format_date');
372
366
  if (!formatDateCalls.every(isReadableFormatDate))
373
367
  return null;
374
- const datedNows = new Set(findDatedNows(parsed.node, options.dates === true, options.dates === true));
368
+ const datedNows = new Set(findCalls(parsed.node, ...DATE_TAKERS).map((call) => call.args[0]));
375
369
  if (findCalls(parsed.node, 'now').some((call) => !datedNows.has(call)))
376
370
  return null;
377
371
  if (!areLookupsReadable(parsed.node, options.lookups === true))
@@ -801,46 +795,11 @@ function childNodes(node) {
801
795
  return [];
802
796
  }
803
797
  }
804
- /** Whether a node is a `+` or `-` with a `make_interval` call as its right side. */
805
- function isAddedInterval(node) {
806
- return node.kind === 'arithmetic' && (node.op === '+' || node.op === '-') && node.right.kind === 'call' && node.right.name === 'make_interval';
807
- }
808
- /**
809
- * The `now()` calls at or under a node that stand where the evaluator takes a
810
- * date (`readQgisExpression`). `dated` says whether the node itself stands in
811
- * one; `dates` is the caller's option, without which only the first argument
812
- * of a `DATE_TAKERS` call does.
813
- */
814
- function findDatedNows(node, dated, dates) {
815
- if (node.kind === 'call' && node.name === 'now')
816
- return dated ? [node] : [];
817
- return datedChildren(node, dated, dates).flatMap(([child, childDated]) => findDatedNows(child, childDated, dates));
818
- }
819
- /** The nodes directly under a node, each with whether it stands where a date is taken. */
820
- function datedChildren(node, dated, dates) {
821
- if (node.kind === 'call' && DATE_TAKERS.includes(node.name))
822
- return node.args.map((arg, index) => [arg, index === 0]);
823
- if (dates) {
824
- if (node.kind === 'compare')
825
- return [[node.left, true], [node.right, true]];
826
- if (isAddedInterval(node))
827
- return [[node.left, dated], [node.right, false]];
828
- if (node.kind === 'call' && node.name === 'if')
829
- return node.args.map((arg, index) => [arg, dated && index > 0]);
830
- if (node.kind === 'call' && node.name === 'coalesce')
831
- return node.args.map((arg) => [arg, dated]);
832
- if (node.kind === 'case') {
833
- return [
834
- ...node.whens.flatMap(({ when, then }) => [[when, false], [then, dated]]),
835
- ...(node.otherwise ? [[node.otherwise, dated]] : [])
836
- ];
837
- }
838
- }
839
- return childNodes(node).map((child) => [child, false]);
840
- }
841
798
  /** The `make_interval` calls that are the right side of a `+` or `-` at or under a node. */
842
799
  function findAddedIntervals(node) {
843
- const own = isAddedInterval(node) ? [node.right] : [];
800
+ const own = node.kind === 'arithmetic' && (node.op === '+' || node.op === '-') && node.right.kind === 'call' && node.right.name === 'make_interval'
801
+ ? [node.right]
802
+ : [];
844
803
  return [...own, ...childNodes(node).flatMap(findAddedIntervals)];
845
804
  }
846
805
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriahq/quac",
3
- "version": "0.18.0-next.1",
3
+ "version": "0.18.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Writes and reads QUAC, which adds map layer settings to STAC catalogues.",
@@ -217,6 +217,30 @@
217
217
  "minimum": 0,
218
218
  "maximum": 1
219
219
  },
220
+ "quac:contrast": {
221
+ "description": "The contrast adjustment applied to the layer as drawn, from -1 to 1: each red, green and blue value's distance from mid-grey is multiplied by (1 + contrast) squared, so -1 draws flat mid-grey. It applies to any kind of layer. A layer with no value is unchanged.",
222
+ "type": "number",
223
+ "minimum": -1,
224
+ "maximum": 1
225
+ },
226
+ "quac:brightness": {
227
+ "description": "The brightness adjustment applied to the layer as drawn, from -1 to 1: added to each red, green and blue value, on a scale where each runs from 0 to 1. It applies to any kind of layer. A layer with no value is unchanged.",
228
+ "type": "number",
229
+ "minimum": -1,
230
+ "maximum": 1
231
+ },
232
+ "quac:gamma": {
233
+ "description": "The gamma correction applied to the layer as drawn, from 0.1 to 10: each red, green and blue value, from 0 to 1, is raised to the power 1 / gamma, so a gamma above 1 lightens the mid-tones. It applies to any kind of layer. A layer with no value, or with 1, is unchanged.",
234
+ "type": "number",
235
+ "minimum": 0.1,
236
+ "maximum": 10
237
+ },
238
+ "quac:saturation": {
239
+ "description": "The saturation adjustment applied to the layer as drawn, from -1 to 1: the saturation of each colour is multiplied by 1 + saturation, so -1 draws the layer in greys. It applies to any kind of layer. A layer with no value is unchanged.",
240
+ "type": "number",
241
+ "minimum": -1,
242
+ "maximum": 1
243
+ },
220
244
  "quac:related_to": {
221
245
  "description": "The relations this Collection is the child side of, so its records hang off another Collection's features rather than being a map layer of their own. Written from a QGIS project's Relations.",
222
246
  "type": "array",