@mark1russell7/vex-domains 0.13.4 → 0.14.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/README.md CHANGED
@@ -20,6 +20,7 @@ npm install @mark1russell7/vex @mark1russell7/vex-domains
20
20
  | `NumDomain` | numbers | `add`, `multiply`, `min`, `max`, `sqrt`, `floor`, `gt`, `vec2`, `xy`, `date` |
21
21
  | `BoolDomain` | booleans | `and`, `or`, `xor`, `not` |
22
22
  | `TextDomain` | texts | `concat`, `length`, `upper`, `lower`, `trim`, `contains` |
23
+ | `JsonDomain` | JSON data: texts, numbers, booleans, arrays and plain objects. Put it last. | `kind`, `kinds`, `fields`, `field` |
23
24
  | `ColorDomain` | `Color`: an RGB color | `mix`, `add`, `multiply`, `luminance`, `relativeLuminance`, `contrast` |
24
25
  | `AngleDomain` | `Angle`: an angle | `add`, `normalize`, `sin`, `cos`, `degrees` |
25
26
  | `FnDomain`, `MaybeDomain` | Two example domains: function wrappers and `Maybe` | `invoke`, `map`, `chain`, `valueOr` |
package/build/index.d.ts CHANGED
@@ -383,6 +383,31 @@ export declare class Angle {
383
383
  export type AngleOps = OpTable<Angle, "add" | "subtract" | "scale" | "normalize" | "toVec2" | "sin" | "cos" | "degrees", "add" | "subtract">;
384
384
  /** The domain of angles. A number argument of `add` or `subtract` lifts to an angle in radians. */
385
385
  export declare const AngleDomain: Domain<"Angle", Angle, AngleOps>;
386
+ /**
387
+ * A JSON value that `JsonDomain` accepts: a text, a finite number, a boolean, an array or a plain object. The items of
388
+ * an array and the fields of an object can be `null`.
389
+ */
390
+ export type JsonValue = string | number | boolean | readonly unknown[] | {
391
+ readonly [key: string]: unknown;
392
+ };
393
+ /** The kind of a JSON value. */
394
+ export type JsonKind = "boolean" | "number" | "string" | "array" | "object";
395
+ /** The kind of an item of an array or of a field of an object: the kind of a JSON value, or `"null"`. */
396
+ export type JsonItemKind = JsonKind | "null";
397
+ /** The ops of `JsonDomain`. */
398
+ export type JsonOps = {
399
+ readonly kind: FnOp<JsonValue, (v: JsonValue) => JsonKind>;
400
+ readonly kinds: FnOp<JsonValue, (c: JsonValue) => readonly JsonItemKind[]>;
401
+ readonly fields: FnOp<JsonValue, (o: JsonValue) => readonly string[]>;
402
+ readonly field: FnOp<JsonValue, (o: JsonValue, k: unknown) => unknown>;
403
+ };
404
+ /**
405
+ * The domain of JSON values, for example the documents of a database. Each op is a function of plain data, so a
406
+ * standalone module can copy the domain. Put `JsonDomain` last in the list of domains. Then `add`, `eq` and the other
407
+ * ops of `NumDomain`, `TextDomain` and `BoolDomain` come first. The names `keys`, `get` and `values` are list ops. A
408
+ * domain op comes before a list op on an array, so the domain does not use these names.
409
+ */
410
+ export declare const JsonDomain: Domain<"Json", JsonValue, JsonOps>;
386
411
  /** A wrapper around a function. Its op `invoke` calls the function. It shows how a domain can hold behavior. */
387
412
  export declare class Fn {
388
413
  readonly fn: (...args: never[]) => unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/vec2.ts","../src/xy.ts","../src/ndvector.ts","../src/date.ts","../src/scalars.ts","../src/text.ts","../src/color.ts","../src/angle.ts","../src/wrappers.ts"],"mappings":";;;;;qBAMa;WACF;WACA;EAET,YAAY,WAAW;;SAMhB,GAAG,WAAW,YAAY;;SAI1B,OAAO,YAAY;;kBAIV,MAAM;;kBAEN,KAAK;EAErB,IAAI,GAAG,OAAO;EAGd,SAAS,GAAG,OAAO;;EAInB,SAAS,GAAG,OAAO;;EAInB,OAAO,GAAG,OAAO;;EAIjB,IAAI,GAAG,OAAO;;EAId,IAAI,GAAG,OAAO;EAGd,MAAM,YAAY;EAGlB,UAAU;EAGV,SAAS;EAGT,OAAO;EAGP,SAAS;EAGT,SAAS;EAGT,QAAQ;EAGR,MAAM,YAAY,aAAa;EAG/B,QAAQ;;;;;EAOR,QAAQ,cAAc,gBAAgB;;;;;EAOtC,OAAO,GAAG,MAAM,GAAG,OAAO;;EAI1B,OAAO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YAAY,WAAW,WAAW,WAAW;;SAQtC,KAAK,YAAY;;kBAIR,MAAM;;EAGtB,IAAI,GAAG,QAAQ;;EAIf,SAAS,iBAAiB;;EAI1B,MAAM,aAAQ,cAAW;;EAKzB,IAAI,GAAG,OAAO,YAAY;;EAK1B;;;;;EAOA;;EAIA,SAAS,GAAG;EAKZ,OAAO,GAAG;EAGV;EAGA;;;YAMU,WAAW,QAAQ;;qBAGlB,aAAa,gBAAgB,OAAO;;qBC/EpC;WACF;EAET,YAAY;;SAKL,YAAY,cAAc;;kBAIjB,MAAM;EAEtB,IAAI,GAAG,QAAQ;EAGf,SAAS,GAAG,QAAQ;EAGpB,MAAM,YAAY;;EAIlB,aAAa;;EAMb,OAAO,kBAAa;EAGpB;EAGA;EAGA;EAGA;;;YAMU,WAAW,QAAQ;;qBAGlB,aAAa,gBAAgB,OAAO;;qBCpDpC;WACF,QAAQ;EAEjB,YAAY,QAAQ;EAGpB,UAAU;;;YAMA,QAAQ,QAAQ;;qBAGf,UAAU,aAAa,IAAI;;;;;qBAU3B,MAAM;;UAIT;SAID,IAAI,GAAG,OAAO,IAAI,MAAM;SAGxB,OAAO,cAAc,MAAM;EAGlC;EAGA;EAGA,IAAI,GAAG,IAAI,OAAO,MAAM,IAAI,MAAM;EAGlC,MAAM,GAAG,IAAI,OAAO,MAAM,MAAM,KAAK,MAAM;EAG3C,QAAQ,GAAG,UAAU,IAAI,IAAI;;;YAMnB,WAAW,QAAQ;;qBAGlB,aAAa,gBAAgB,gBAAgB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/vec2.ts","../src/xy.ts","../src/ndvector.ts","../src/date.ts","../src/scalars.ts","../src/text.ts","../src/color.ts","../src/angle.ts","../src/json.ts","../src/wrappers.ts"],"mappings":";;;;;qBAMa;WACF;WACA;EAET,YAAY,WAAW;;SAMhB,GAAG,WAAW,YAAY;;SAI1B,OAAO,YAAY;;kBAIV,MAAM;;kBAEN,KAAK;EAErB,IAAI,GAAG,OAAO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AID,IAAI,GAAG,OAAO,IAAI,MAAM;SAGxB,OAAO,cAAc,MAAM;EAGlC;EAGA;EAGA,IAAI,GAAG,IAAI,OAAO,MAAM,IAAI,MAAM;EAGlC,MAAM,GAAG,IAAI,OAAO,MAAM,MAAM,KAAK,MAAM;EAG3C,QAAQ,GAAG,UAAU,IAAI,IAAI;;;YAMnB,WAAW,QAAQ;;qBAGlB,aAAa,gBAAgB,gBAAgB"}
package/build/index.js CHANGED
@@ -1397,6 +1397,71 @@ const AngleDomain = defineDomain({
1397
1397
  degrees: {}
1398
1398
  }
1399
1399
  });
1400
+ // src/json.ts
1401
+ /**
1402
+ * The domain of JSON values, for example the documents of a database. Each op is a function of plain data, so a
1403
+ * standalone module can copy the domain. Put `JsonDomain` last in the list of domains. Then `add`, `eq` and the other
1404
+ * ops of `NumDomain`, `TextDomain` and `BoolDomain` come first. The names `keys`, `get` and `values` are list ops. A
1405
+ * domain op comes before a list op on an array, so the domain does not use these names.
1406
+ */
1407
+ const JsonDomain = defineDomain({
1408
+ name: "Json",
1409
+ is: (u) => typeof u === "string" || typeof u === "boolean" || Number.isFinite(u) || Array.isArray(u) || typeof u === "object" && u !== null && [Object.prototype, null].includes(Object.getPrototypeOf(u)) && !(u.kind === "vex.list" && Array.isArray(u.items)),
1410
+ samples: () => [
1411
+ {
1412
+ a: 1,
1413
+ b: [true, null],
1414
+ c: { d: "x" }
1415
+ },
1416
+ [
1417
+ 1,
1418
+ "x",
1419
+ null,
1420
+ [2]
1421
+ ],
1422
+ "x",
1423
+ 2,
1424
+ false
1425
+ ],
1426
+ ops: {
1427
+ kind: {
1428
+ fn: (v) => Array.isArray(v) ? "array" : typeof v,
1429
+ params: [],
1430
+ returns: "string"
1431
+ },
1432
+ kinds: {
1433
+ fn: (c) => {
1434
+ if (typeof c !== "object") throw new Error(`"kinds" needs an array or an object, not a ${typeof c}`);
1435
+ return Array.from(Array.isArray(c) ? c : Object.values(c), (x, i) => {
1436
+ if (x === null || x === void 0) return "null";
1437
+ if (Array.isArray(x)) return "array";
1438
+ if (typeof x === "string" || typeof x === "boolean" || Number.isFinite(x) || [Object.prototype, null].includes(Object.getPrototypeOf(x))) return typeof x;
1439
+ throw new Error(`"kinds" found a value that is not JSON at the position ${i}`);
1440
+ });
1441
+ },
1442
+ params: []
1443
+ },
1444
+ fields: {
1445
+ fn: (o) => {
1446
+ if (typeof o !== "object" || Array.isArray(o)) throw new Error(`"fields" needs an object, not ${Array.isArray(o) ? "an array" : `a ${typeof o}`}`);
1447
+ return Object.keys(o);
1448
+ },
1449
+ params: []
1450
+ },
1451
+ field: {
1452
+ fn: (o, k) => {
1453
+ if (typeof o !== "object" || Array.isArray(o)) throw new Error(`"field" needs an object, not ${Array.isArray(o) ? "an array" : `a ${typeof o}`}`);
1454
+ if (typeof k !== "string") throw new Error(`"field" needs a text key, not a ${typeof k}`);
1455
+ if (!Object.hasOwn(o, k)) throw new Error(`the object has no field "${k}"`);
1456
+ const value = o[k];
1457
+ if (value === null || value === void 0) throw new Error(`the field "${k}" is null`);
1458
+ return value;
1459
+ },
1460
+ params: ["any"],
1461
+ returns: "any"
1462
+ }
1463
+ }
1464
+ });
1400
1465
  // src/wrappers.ts
1401
1466
  /** A wrapper around a function. Its op `invoke` calls the function. It shows how a domain can hold behavior. */
1402
1467
  var Fn = class {
@@ -1459,6 +1524,6 @@ const MaybeDomain = defineDomain({
1459
1524
  valueOr: {}
1460
1525
  }
1461
1526
  });
1462
- export { Angle, AngleDomain, BoolDomain, Color, ColorDomain, DateDomain, Fn, FnDomain, LiftedNDVectorDomain, LocalDate, MAX_DAYS, Maybe, MaybeDomain, NDVector, NDVectorDomain, NumDomain, NumRecordDomain, TextDomain, Vec2, Vec2Domain, XYDomain };
1527
+ export { Angle, AngleDomain, BoolDomain, Color, ColorDomain, DateDomain, Fn, FnDomain, JsonDomain, LiftedNDVectorDomain, LocalDate, MAX_DAYS, Maybe, MaybeDomain, NDVector, NDVectorDomain, NumDomain, NumRecordDomain, TextDomain, Vec2, Vec2Domain, XYDomain };
1463
1528
 
1464
1529
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/vec2.ts","../src/xy.ts","../src/ndvector.ts","../src/date.ts","../src/scalars.ts","../src/text.ts","../src/color.ts","../src/angle.ts","../src/wrappers.ts"],"sourcesContent":["import { defineDomain, type Domain, type FnOp, type OpTable } from \"@mark1russell7/vex\";\n\n/**\n * An immutable 2D vector. The methods live on the prototype, so a vector costs two numbers. Division is real\n * division: a division by zero gives an infinite component, and the domain check turns it into `#NUM!`.\n */\nexport class Vec2 {\n readonly x: number;\n readonly y: number;\n\n constructor(x: number, y: number) {\n this.x = x;\n this.y = y;\n }\n\n /** This function makes a vector. */\n static of(x: number, y: number): Vec2 {\n return new Vec2(x, y);\n }\n /** This function makes a vector with the same value in both components. */\n static scalar(n: number): Vec2 {\n return new Vec2(n, n);\n }\n /** The zero vector. */\n static readonly zero: Vec2 = new Vec2(0, 0);\n /** The vector of ones. */\n static readonly one: Vec2 = new Vec2(1, 1);\n\n add(o: Vec2): Vec2 {\n return new Vec2(this.x + o.x, this.y + o.y);\n }\n subtract(o: Vec2): Vec2 {\n return new Vec2(this.x - o.x, this.y - o.y);\n }\n /** The component-wise product. */\n multiply(o: Vec2): Vec2 {\n return new Vec2(this.x * o.x, this.y * o.y);\n }\n /** The component-wise quotient. A zero component of `o` gives an infinite component. */\n divide(o: Vec2): Vec2 {\n return new Vec2(this.x / o.x, this.y / o.y);\n }\n /** The component-wise minimum. */\n min(o: Vec2): Vec2 {\n return new Vec2(Math.min(this.x, o.x), Math.min(this.y, o.y));\n }\n /** The component-wise maximum. */\n max(o: Vec2): Vec2 {\n return new Vec2(Math.max(this.x, o.x), Math.max(this.y, o.y));\n }\n scale(k: number): Vec2 {\n return new Vec2(this.x * k, this.y * k);\n }\n negate(): Vec2 {\n return new Vec2(-this.x, -this.y);\n }\n halve(): Vec2 {\n return this.scale(0.5);\n }\n abs(): Vec2 {\n return new Vec2(Math.abs(this.x), Math.abs(this.y));\n }\n round(): Vec2 {\n return new Vec2(Math.round(this.x), Math.round(this.y));\n }\n floor(): Vec2 {\n return new Vec2(Math.floor(this.x), Math.floor(this.y));\n }\n ceil(): Vec2 {\n return new Vec2(Math.ceil(this.x), Math.ceil(this.y));\n }\n clamp(lo: number, hi: number): Vec2 {\n return new Vec2(Math.min(hi, Math.max(lo, this.x)), Math.min(hi, Math.max(lo, this.y)));\n }\n swap(): Vec2 {\n return new Vec2(this.y, this.x);\n }\n /**\n * The vector with `main` along the unit axis of this vector and `cross` on the other axis: `this * main + swap(this) *\n * cross`. For the axis (1, 0) it is (main, cross), and for the axis (0, 1) it is (cross, main).\n */\n compose(main: number, cross: number): Vec2 {\n return new Vec2(this.x * main + this.y * cross, this.y * main + this.x * cross);\n }\n /**\n * The component-wise choice: a component of `a` where this mask has a component that is not 0, else the component\n * of `b`. Thus `hi.select(v.min(hi), v)` bounds each component of `v` by `hi`, and a 0 in `hi` sets no bound.\n */\n select(a: Vec2, b: Vec2): Vec2 {\n return new Vec2(this.x !== 0 ? a.x : b.x, this.y !== 0 ? a.y : b.y);\n }\n /** The vector turned by `radians`, counterclockwise. */\n rotate(radians: number): Vec2 {\n const c = Math.cos(radians);\n const s = Math.sin(radians);\n return new Vec2(c * this.x - s * this.y, s * this.x + c * this.y);\n }\n /** The vector with length 1. The zero vector stays zero. */\n normalize(): Vec2 {\n const len = this.length();\n return len === 0 ? this : this.scale(1 / len);\n }\n /** The linear interpolation from this vector to `o`. */\n lerp(o: Vec2, t: number): Vec2 {\n return new Vec2(this.x + (o.x - this.x) * t, this.y + (o.y - this.y) * t);\n }\n length(): number {\n return Math.hypot(this.x, this.y);\n }\n lengthSq(): number {\n return this.x * this.x + this.y * this.y;\n }\n distance(o: Vec2): number {\n return Math.hypot(this.x - o.x, this.y - o.y);\n }\n dot(o: Vec2): number {\n return this.x * o.x + this.y * o.y;\n }\n /** The component along the unit axis `dir`: `dot(this, dir)`. For the axis (1, 0) it is x, and for (0, 1) it is y. */\n along(dir: Vec2): number {\n return this.x * dir.x + this.y * dir.y;\n }\n /** The component on the other axis of the unit axis `dir`: `dot(this, swap(dir))`. For the axis (1, 0) it is y. */\n across(dir: Vec2): number {\n return this.x * dir.y + this.y * dir.x;\n }\n /** The z component of the 3D cross product. */\n cross(o: Vec2): number {\n return this.x * o.y - this.y * o.x;\n }\n /** The angle of the vector, in radians, from the x axis. */\n angle(): number {\n return Math.atan2(this.y, this.x);\n }\n /** The product of the components: the area of a size vector. */\n area(): number {\n return this.x * this.y;\n }\n /** The sum of the components. */\n sum(): number {\n return this.x + this.y;\n }\n minComponent(): number {\n return Math.min(this.x, this.y);\n }\n maxComponent(): number {\n return Math.max(this.x, this.y);\n }\n equals(o: Vec2): boolean {\n return this.x === o.x && this.y === o.y;\n }\n anyNonPositive(): boolean {\n return this.x <= 0 || this.y <= 0;\n }\n allPositive(): boolean {\n return this.x > 0 && this.y > 0;\n }\n anyNegative(): boolean {\n return this.x < 0 || this.y < 0;\n }\n allNonNegative(): boolean {\n return this.x >= 0 && this.y >= 0;\n }\n anyZero(): boolean {\n return this.x === 0 || this.y === 0;\n }\n allZero(): boolean {\n return this.x === 0 && this.y === 0;\n }\n anyLessThan(n: number): boolean {\n return this.x < n || this.y < n;\n }\n allLessThan(n: number): boolean {\n return this.x < n && this.y < n;\n }\n anyGreaterThan(n: number): boolean {\n return this.x > n || this.y > n;\n }\n allGreaterThan(n: number): boolean {\n return this.x > n && this.y > n;\n }\n toJSON(): { readonly x: number; readonly y: number } {\n return { x: this.x, y: this.y };\n }\n toString(): string {\n return `(${this.x}, ${this.y})`;\n }\n}\n\ntype Vec2OpNames =\n | \"add\" | \"subtract\" | \"multiply\" | \"divide\" | \"min\" | \"max\" | \"scale\" | \"negate\" | \"halve\" | \"abs\" | \"round\"\n | \"floor\" | \"ceil\" | \"clamp\" | \"swap\" | \"compose\" | \"select\" | \"rotate\" | \"normalize\" | \"lerp\" | \"length\"\n | \"lengthSq\" | \"distance\" | \"dot\" | \"along\" | \"across\" | \"cross\" | \"angle\" | \"area\" | \"sum\" | \"minComponent\"\n | \"maxComponent\" | \"equals\" | \"anyNonPositive\" | \"allPositive\" | \"anyNegative\" | \"allNonNegative\" | \"anyZero\"\n | \"allZero\" | \"anyLessThan\" | \"allLessThan\" | \"anyGreaterThan\" | \"allGreaterThan\";\n\n/** The ops of `Vec2Domain`. The ops `x` and `y` give a component. */\nexport type Vec2Ops = OpTable<Vec2, Vec2OpNames, \"add\" | \"subtract\" | \"multiply\" | \"divide\" | \"min\" | \"max\" | \"select\"> & {\n readonly x: FnOp<Vec2, (v: Vec2) => number>;\n readonly y: FnOp<Vec2, (v: Vec2) => number>;\n};\n\n/** The domain of 2D vectors. A number argument of a component-wise op lifts to a vector with that value twice. */\nexport const Vec2Domain: Domain<\"Vec2\", Vec2, Vec2Ops> = defineDomain<\"Vec2\", Vec2, Vec2Ops>({\n name: \"Vec2\",\n is: (u: unknown): u is Vec2 => u instanceof Vec2,\n fromScalar: (n: number): Vec2 => Vec2.scalar(n),\n valid: (v: Vec2): boolean => Number.isFinite(v.x) && Number.isFinite(v.y),\n show: (v: Vec2): string => v.toString(),\n encode: (v: Vec2): readonly [number, number] => [v.x, v.y],\n decode: (u: unknown): Vec2 => {\n // Stryker disable next-line ArrayDeclaration: a list with a text gives NaN components, like the empty list\n const [x, y] = Array.isArray(u) ? (u as readonly unknown[]) : [];\n return new Vec2(typeof x === \"number\" ? x : Number.NaN, typeof y === \"number\" ? y : Number.NaN);\n },\n ops: {\n // The components are fields of a vector, not methods, so these two ops are functions.\n x: { fn: (v: Vec2): number => v.x, params: [], returns: \"number\" },\n y: { fn: (v: Vec2): number => v.y, params: [], returns: \"number\" },\n add: { laws: [\"commutative\", \"associative\"], identity: () => Vec2.zero, liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n subtract: { liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n multiply: { laws: [\"commutative\", \"associative\"], identity: () => Vec2.one, liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n divide: { liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n min: { laws: [\"commutative\", \"associative\", \"idempotent\"], liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n max: { laws: [\"commutative\", \"associative\", \"idempotent\"], liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n scale: { params: [\"number\"], returns: \"domain\" },\n negate: { params: [], returns: \"domain\" },\n halve: { params: [], returns: \"domain\" },\n abs: { params: [], returns: \"domain\" },\n round: { params: [], returns: \"domain\" },\n floor: { params: [], returns: \"domain\" },\n ceil: { params: [], returns: \"domain\" },\n clamp: { params: [\"number\", \"number\"], returns: \"domain\" },\n swap: { params: [], returns: \"domain\" },\n compose: { params: [\"number\", \"number\"], returns: \"domain\" },\n select: { liftScalar: true, params: [\"domain\", \"domain\"], returns: \"domain\" },\n rotate: { params: [\"number\"], returns: \"domain\" },\n normalize: { params: [], returns: \"domain\" },\n lerp: { params: [\"domain\", \"number\"], returns: \"domain\" },\n length: { params: [], returns: \"number\" },\n lengthSq: { params: [], returns: \"number\" },\n distance: { params: [\"domain\"], returns: \"number\" },\n dot: { laws: [\"commutative\"], params: [\"domain\"], returns: \"number\" },\n along: { params: [\"domain\"], returns: \"number\" },\n across: { params: [\"domain\"], returns: \"number\" },\n cross: { params: [\"domain\"], returns: \"number\" },\n angle: { params: [], returns: \"number\" },\n area: { params: [], returns: \"number\" },\n sum: { params: [], returns: \"number\" },\n minComponent: { params: [], returns: \"number\" },\n maxComponent: { params: [], returns: \"number\" },\n equals: { laws: [\"commutative\"], params: [\"domain\"], returns: \"boolean\" },\n anyNonPositive: { params: [], returns: \"boolean\" },\n allPositive: { params: [], returns: \"boolean\" },\n anyNegative: { params: [], returns: \"boolean\" },\n allNonNegative: { params: [], returns: \"boolean\" },\n anyZero: { params: [], returns: \"boolean\" },\n allZero: { params: [], returns: \"boolean\" },\n anyLessThan: { params: [\"number\"], returns: \"boolean\" },\n allLessThan: { params: [\"number\"], returns: \"boolean\" },\n anyGreaterThan: { params: [\"number\"], returns: \"boolean\" },\n allGreaterThan: { params: [\"number\"], returns: \"boolean\" },\n },\n});\n","import { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\n\n/**\n * A 2D vector as plain data. `XYDomain` has the component-wise ops of `Vec2Domain`, but each op is a function of plain\n * data. Thus a standalone module of `@mark1russell7/vex-compiler` can copy the domain, and a 2D program can be a module.\n */\nexport interface XY {\n readonly x: number;\n readonly y: number;\n}\n\ntype XYFn2 = (a: XY, b: XY) => XY;\ntype XYFn1 = (a: XY) => XY;\ntype XYNum1 = (a: XY) => number;\n\n/** The ops of `XYDomain`. */\nexport type XYOps = {\n readonly x: FnOp<XY, XYNum1>;\n readonly y: FnOp<XY, XYNum1>;\n readonly add: FnOp<XY, XYFn2>;\n readonly subtract: FnOp<XY, XYFn2>;\n readonly multiply: FnOp<XY, XYFn2>;\n readonly divide: FnOp<XY, XYFn2>;\n readonly min: FnOp<XY, XYFn2>;\n readonly max: FnOp<XY, XYFn2>;\n readonly scale: FnOp<XY, (a: XY, k: number) => XY>;\n readonly negate: FnOp<XY, XYFn1>;\n readonly abs: FnOp<XY, XYFn1>;\n readonly floor: FnOp<XY, XYFn1>;\n readonly ceil: FnOp<XY, XYFn1>;\n readonly round: FnOp<XY, XYFn1>;\n readonly dot: FnOp<XY, (a: XY, b: XY) => number>;\n readonly length: FnOp<XY, XYNum1>;\n readonly distance: FnOp<XY, (a: XY, b: XY) => number>;\n readonly area: FnOp<XY, XYNum1>;\n readonly sum: FnOp<XY, XYNum1>;\n readonly equals: FnOp<XY, (a: XY, b: XY) => boolean>;\n};\n\n/**\n * The domain of 2D vectors as plain data: an object with the two number fields `x` and `y` and no other field. The op\n * `xy` of `NumDomain` makes one. No op lifts a number, so each op has a static site in a module. Put `XYDomain` before\n * `NumRecordDomain`, because a record of numbers accepts the same objects.\n */\nexport const XYDomain: Domain<\"XY\", XY, XYOps> = defineDomain<\"XY\", XY, XYOps>({\n name: \"XY\",\n // A plain object: its prototype is Object.prototype or null, so an instance of a class such as Vec2 is not an XY.\n is: (u: unknown): u is XY => typeof u === \"object\" && u !== null && [Object.prototype, null].includes(Object.getPrototypeOf(u) as object | null) && Object.keys(u).length === 2 && typeof (u as XY).x === \"number\" && typeof (u as XY).y === \"number\",\n valid: (v: XY): boolean => Number.isFinite(v.x) && Number.isFinite(v.y),\n show: (v: XY): string => `(${v.x}, ${v.y})`,\n samples: (): readonly XY[] => [{ x: 0, y: 0 }, { x: 1.5, y: -2 }, { x: 3, y: 4 }],\n ops: {\n x: { fn: (a: XY): number => a.x, params: [], returns: \"number\" },\n y: { fn: (a: XY): number => a.y, params: [], returns: \"number\" },\n add: { fn: (a: XY, b: XY): XY => ({ x: a.x + b.x, y: a.y + b.y }), laws: [\"commutative\", \"associative\"], identity: (): XY => ({ x: 0, y: 0 }), params: [\"domain\"], returns: \"domain\" },\n subtract: { fn: (a: XY, b: XY): XY => ({ x: a.x - b.x, y: a.y - b.y }), params: [\"domain\"], returns: \"domain\" },\n multiply: { fn: (a: XY, b: XY): XY => ({ x: a.x * b.x, y: a.y * b.y }), laws: [\"commutative\", \"associative\"], identity: (): XY => ({ x: 1, y: 1 }), params: [\"domain\"], returns: \"domain\" },\n divide: { fn: (a: XY, b: XY): XY => ({ x: a.x / b.x, y: a.y / b.y }), params: [\"domain\"], returns: \"domain\" },\n min: { fn: (a: XY, b: XY): XY => ({ x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) }), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"], returns: \"domain\" },\n max: { fn: (a: XY, b: XY): XY => ({ x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) }), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"], returns: \"domain\" },\n scale: { fn: (a: XY, k: number): XY => ({ x: a.x * k, y: a.y * k }), params: [\"number\"], returns: \"domain\" },\n negate: { fn: (a: XY): XY => ({ x: -a.x, y: -a.y }), params: [], returns: \"domain\" },\n abs: { fn: (a: XY): XY => ({ x: Math.abs(a.x), y: Math.abs(a.y) }), params: [], returns: \"domain\" },\n floor: { fn: (a: XY): XY => ({ x: Math.floor(a.x), y: Math.floor(a.y) }), params: [], returns: \"domain\" },\n ceil: { fn: (a: XY): XY => ({ x: Math.ceil(a.x), y: Math.ceil(a.y) }), params: [], returns: \"domain\" },\n round: { fn: (a: XY): XY => ({ x: Math.round(a.x), y: Math.round(a.y) }), params: [], returns: \"domain\" },\n dot: { fn: (a: XY, b: XY): number => a.x * b.x + a.y * b.y, laws: [\"commutative\"], params: [\"domain\"], returns: \"number\" },\n length: { fn: (a: XY): number => Math.hypot(a.x, a.y), params: [], returns: \"number\" },\n distance: { fn: (a: XY, b: XY): number => Math.hypot(a.x - b.x, a.y - b.y), laws: [\"commutative\"], params: [\"domain\"], returns: \"number\" },\n area: { fn: (a: XY): number => a.x * a.y, params: [], returns: \"number\" },\n sum: { fn: (a: XY): number => a.x + a.y, params: [], returns: \"number\" },\n equals: { fn: (a: XY, b: XY): boolean => a.x === b.x && a.y === b.y, laws: [\"commutative\"], params: [\"domain\"], returns: \"boolean\" },\n },\n});\n","import { defineDomain, type Domain, type FnOp, type OpTable } from \"@mark1russell7/vex\";\n\n/**\n * An immutable vector with named components. The type parameter `K` is the set of component names. Ops that\n * combine two vectors use the union of their names, and a missing component counts as 0. The constructor\n * keeps each number, also a number that is not finite: the domain check reports such a value as `#NUM!`.\n */\nexport class NDVector<K extends string = string> {\n /** The components: name to number. */\n readonly c: Readonly<Record<K, number>>;\n\n constructor(c: Readonly<Record<K, number>>) {\n this.c = Object.freeze({ ...c });\n }\n\n /** This function makes a vector from name and value pairs. */\n static of<K extends string>(entries: readonly (readonly [K, number])[]): NDVector<K> {\n const c = {} as Record<K, number>;\n for (const [k, v] of entries) c[k] = v;\n return new NDVector(c);\n }\n /** This function makes the zero vector over the names `keys`. */\n static zero<K extends string>(keys: readonly K[] = []): NDVector<K> {\n return NDVector.of(keys.map((k) => [k, 0] as const));\n }\n\n /** The names of the components. */\n keys(): readonly K[] {\n return Object.keys(this.c) as K[];\n }\n /** The value of a component, or 0 if the vector does not have it. */\n get(k: string): number {\n return Object.hasOwn(this.c, k) ? Number((this.c as Readonly<Record<string, number>>)[k]) : 0;\n }\n set<K2 extends string>(k: K2, v: number): NDVector<K | K2> {\n return new NDVector({ ...this.c, [k]: v } as Record<K | K2, number>);\n }\n map(f: (name: K, v: number) => number): NDVector<K> {\n const c = {} as Record<K, number>;\n for (const k of this.keys()) c[k] = f(k, this.get(k));\n return new NDVector(c);\n }\n /** The vector with only the names in `keys`. A zero component is dropped, unless `keepZeros` is true. */\n pick<K2 extends K>(keys: readonly K2[], keepZeros = false): NDVector<K2> {\n const c = {} as Record<K2, number>;\n for (const k of keys) {\n const v = this.get(k);\n if (keepZeros || v !== 0) c[k] = v;\n }\n return new NDVector(c);\n }\n /** The vector with the names in `keys` added. A new component is 0. */\n withKeys<K2 extends string>(keys: readonly K2[]): NDVector<K | K2> {\n const c = { ...this.c } as Record<K | K2, number>;\n for (const k of keys) if (!Object.hasOwn(c, k)) c[k] = 0;\n return new NDVector(c);\n }\n #combine<K2 extends string>(o: NDVector<K2>, f: (a: number, b: number) => number): NDVector<K | K2> {\n const c = {} as Record<K | K2, number>;\n for (const k of new Set<K | K2>([...this.keys(), ...o.keys()])) c[k] = f(this.get(k), o.get(k));\n return new NDVector(c);\n }\n add<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => a + b);\n }\n subtract<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => a - b);\n }\n /** The component-wise product. */\n multiply<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => a * b);\n }\n /** The component-wise minimum. A component that one vector does not have counts as 0. */\n min<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => Math.min(a, b));\n }\n /** The component-wise maximum. A component that one vector does not have counts as 0. */\n max<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => Math.max(a, b));\n }\n /** Of each component, the value of this vector if it is not 0, else the value of `o`. */\n mergePreferNonZero<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => (a !== 0 ? a : b));\n }\n scale(k: number): NDVector<K> {\n return this.map((_n, v) => v * k);\n }\n clamp(lo: number, hi: number): NDVector<K> {\n return this.map((_n, v) => Math.min(hi, Math.max(lo, v)));\n }\n dot(o: NDVector): number {\n let s = 0;\n for (const k of new Set<string>([...this.keys(), ...o.keys()])) s += this.get(k) * o.get(k);\n return s;\n }\n /** The L2 length. */\n length(): number {\n return Math.sqrt(this.keys().reduce((s, k) => s + this.get(k) ** 2, 0));\n }\n /** The L1 norm. */\n norm1(): number {\n return this.keys().reduce((s, k) => s + Math.abs(this.get(k)), 0);\n }\n /** The largest absolute component. */\n normInf(): number {\n return this.keys().reduce((m, k) => Math.max(m, Math.abs(this.get(k))), 0);\n }\n equals(o: NDVector): boolean {\n const keys = new Set<string>([...this.keys(), ...o.keys()]);\n for (const k of keys) if (this.get(k) !== o.get(k)) return false;\n return true;\n }\n /** True if each component is a finite number. */\n isFinite(): boolean {\n return this.keys().every((k) => Number.isFinite(this.get(k)));\n }\n toJSON(): Readonly<Record<K, number>> {\n return { ...this.c };\n }\n toString(): string {\n return `NDVector(${JSON.stringify(this.c)})`;\n }\n}\n\ntype NDOpNames =\n | \"add\" | \"subtract\" | \"multiply\" | \"min\" | \"max\" | \"mergePreferNonZero\" | \"scale\" | \"clamp\" | \"dot\" | \"length\" | \"norm1\" | \"normInf\"\n | \"equals\" | \"pick\" | \"withKeys\" | \"get\" | \"set\";\n\n/** The ops of `NDVectorDomain`. No op lifts numbers. */\nexport type NDVectorOps = OpTable<NDVector, NDOpNames>;\n\n/** The ops of `LiftedNDVectorDomain`. */\nexport type LiftedNDVectorOps = OpTable<NDVector, NDOpNames, \"add\" | \"subtract\" | \"multiply\" | \"dot\">;\n\nconst ndOps = {\n add: { laws: [\"commutative\", \"associative\"], identity: (): NDVector => NDVector.zero(), params: [\"domain\"] },\n subtract: { params: [\"domain\"] },\n multiply: { laws: [\"commutative\", \"associative\"], params: [\"domain\"] },\n min: { laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"] },\n max: { laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"] },\n mergePreferNonZero: { laws: [\"associative\", \"idempotent\"], params: [\"domain\"] },\n scale: { params: [\"number\"] },\n clamp: { params: [\"number\", \"number\"] },\n dot: { laws: [\"commutative\"], params: [\"domain\"] },\n length: {},\n norm1: {},\n normInf: {},\n equals: { laws: [\"commutative\"], params: [\"domain\"] },\n pick: {},\n withKeys: {},\n get: { params: [\"string\"] },\n set: { params: [\"string\", \"number\"] },\n} as const satisfies NDVectorOps;\n\nconst isNDVector = (u: unknown): u is NDVector => u instanceof NDVector;\n\n/** The domain of named-component vectors. A number argument is an error here: use `LiftedNDVectorDomain` to lift. */\nexport const NDVectorDomain: Domain<\"NDVector\", NDVector, NDVectorOps> = defineDomain<\"NDVector\", NDVector, NDVectorOps>({\n name: \"NDVector\",\n is: isNDVector,\n valid: (v: NDVector): boolean => v.isFinite(),\n show: (v: NDVector): string => v.toString(),\n encode: (v: NDVector): unknown => v.toJSON(),\n decode: (u: unknown): NDVector => new NDVector(u as Readonly<Record<string, number>>),\n ops: ndOps,\n});\n\n/**\n * The domain of named-component vectors with scalar lifting. A number argument of `add`, `subtract`,\n * `multiply` or `dot` becomes the vector `{ scalar: n }`. This domain is independent of `NDVectorDomain`:\n * the two can be in one program, and neither changes the other.\n */\nexport const LiftedNDVectorDomain: Domain<\"NDVector(lifted)\", NDVector, LiftedNDVectorOps> = defineDomain<\"NDVector(lifted)\", NDVector, LiftedNDVectorOps>({\n name: \"NDVector(lifted)\",\n is: isNDVector,\n fromScalar: (n: number): NDVector => new NDVector({ scalar: n }),\n valid: (v: NDVector): boolean => v.isFinite(),\n show: (v: NDVector): string => v.toString(),\n ops: {\n ...ndOps,\n add: { ...ndOps.add, liftScalar: true },\n subtract: { ...ndOps.subtract, liftScalar: true },\n multiply: { ...ndOps.multiply, liftScalar: true },\n dot: { ...ndOps.dot, liftScalar: true },\n },\n});\n\n/** A plain record whose values are finite numbers. */\nexport type NumRecord = Readonly<Record<string, number>>;\n\n/** The ops of `NumRecordDomain`. */\nexport type NumRecordOps = {\n readonly toNDVector: FnOp<NumRecord, (r: NumRecord) => NDVector>;\n};\n\nconst isNumRecord = (u: unknown): u is NumRecord => {\n if (typeof u !== \"object\" || u === null || Array.isArray(u)) return false;\n const proto: unknown = Object.getPrototypeOf(u);\n // Number.isFinite gives false for each value that is not a number.\n return (proto === Object.prototype || proto === null) && Object.values(u).every((v) => Number.isFinite(v));\n};\n\n/** The domain of plain number records. Its op `toNDVector` builds a vector from fields, for example from `rec()`. */\nexport const NumRecordDomain: Domain<\"NumRecord\", NumRecord, NumRecordOps> = defineDomain<\"NumRecord\", NumRecord, NumRecordOps>({\n name: \"NumRecord\",\n is: isNumRecord,\n ops: {\n toNDVector: { fn: (r: NumRecord): NDVector => new NDVector(r) },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\n\nconst MS_PER_DAY = 86_400_000;\n\n/** The largest distance from 1970-01-01 in days. The `Date` of JavaScript has the same range. */\nexport const MAX_DAYS = 100_000_000;\n\nconst ISO = /^([+-]?\\d{4,6})-(\\d{2})-(\\d{2})$/;\n\n/** This function gives the `Date` of JavaScript at 00:00 UTC of a day. */\nconst utc = (days: number): Date => new Date(days * MS_PER_DAY);\n\n/**\n * An immutable day of the calendar, without a time and without a time zone. It keeps the number of days since\n * 1970-01-01, so the arithmetic of days is the arithmetic of numbers. The calendar is the Gregorian calendar, also\n * before 1582.\n */\nexport class LocalDate {\n /** The number of days since 1970-01-01. */\n readonly days: number;\n\n constructor(days: number) {\n this.days = days;\n }\n\n /**\n * This function makes a date from a year, a month from 1 to 12, and a day. A month or a day outside its range rolls\n * over, like the function `DATE` of a spreadsheet. Thus month 13 is January of the next year, and day 0 is the last\n * day of the month before. A number that is not whole gives a date that is not valid.\n */\n static of(year: number, month: number, day: number): LocalDate {\n if (![year, month, day].every(Number.isSafeInteger)) return new LocalDate(Number.NaN);\n // setUTCFullYear does not change the years 0 to 99 into 1900 to 1999, but Date.UTC does.\n const d = new Date(0);\n d.setUTCFullYear(year, month - 1, day);\n return new LocalDate(Math.round(d.getTime() / MS_PER_DAY));\n }\n\n /** This function reads a date in the form `YYYY-MM-DD`. A day that does not exist, for example `2026-02-30`, gives `undefined`. */\n static parse(text: string): LocalDate | undefined {\n const m = ISO.exec(text.trim());\n if (m === null) return undefined;\n const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];\n const date = LocalDate.of(y, mo, d);\n // A month or a day outside its range rolls over into another month, so the month tells if the day exists.\n return date.month() === mo ? date : undefined;\n }\n\n /** The year. */\n year(): number {\n return utc(this.days).getUTCFullYear();\n }\n /** The month, from 1 to 12. */\n month(): number {\n return utc(this.days).getUTCMonth() + 1;\n }\n /** The day of the month, from 1 to 31. */\n day(): number {\n return utc(this.days).getUTCDate();\n }\n /** The day of the week, from 1 (Sunday) to 7 (Saturday), like `WEEKDAY` of a spreadsheet. */\n weekday(): number {\n return utc(this.days).getUTCDay() + 1;\n }\n /** The date `n` days later. A negative `n` goes back. */\n add(n: number): LocalDate {\n return new LocalDate(this.days + n);\n }\n /** The number of days from the date `x` to this date, or the date `x` days before this date. */\n subtract(x: LocalDate | number): LocalDate | number {\n return x instanceof LocalDate ? this.days - x.days : new LocalDate(this.days - x);\n }\n /**\n * The same day `n` months later, like `EDATE` of a spreadsheet. When that month is shorter, the result is its last\n * day: one month after 31 January is the last day of February.\n */\n addMonths(n: number): LocalDate {\n // LocalDate.of gives a date that is not valid for a number of months that is not whole.\n const first = LocalDate.of(this.year(), this.month() + n, 1);\n const last = LocalDate.of(first.year(), first.month() + 1, 0);\n return new LocalDate(Math.min(first.days + this.day() - 1, last.days));\n }\n /** The last day of the month `n` months later, like `EOMONTH` of a spreadsheet. */\n endOfMonth(n: number): LocalDate {\n return LocalDate.of(this.year(), this.month() + n + 1, 0);\n }\n gt(o: LocalDate): boolean {\n return this.days > o.days;\n }\n gte(o: LocalDate): boolean {\n return this.days >= o.days;\n }\n lt(o: LocalDate): boolean {\n return this.days < o.days;\n }\n lte(o: LocalDate): boolean {\n return this.days <= o.days;\n }\n eq(o: LocalDate): boolean {\n return this.days === o.days;\n }\n /** The form `YYYY-MM-DD`. A year before 0 or after 9999 has a sign and six digits, as in ISO 8601. */\n toString(): string {\n const y = this.year();\n // Stryker disable next-line EqualityOperator: the year 0 takes the first branch, so y < 0 and y <= 0 are the same in the second\n const year = y >= 0 && y <= 9999 ? String(y).padStart(4, \"0\") : `${y < 0 ? \"-\" : \"+\"}${String(Math.abs(y)).padStart(6, \"0\")}`;\n return `${year}-${String(this.month()).padStart(2, \"0\")}-${String(this.day()).padStart(2, \"0\")}`;\n }\n}\n\n/** The ops of `DateDomain`. */\nexport type DateOps = OpTable<LocalDate, \"add\" | \"subtract\" | \"addMonths\" | \"endOfMonth\" | \"year\" | \"month\" | \"day\" | \"weekday\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"eq\">;\n\n/**\n * The domain of dates. `add` takes a count of days. `subtract` takes a date, for the days between the two dates, or a\n * count of days. A valid date is a whole count of days, within `MAX_DAYS` of 1970-01-01.\n */\nexport const DateDomain: Domain<\"Date\", LocalDate, DateOps> = defineDomain<\"Date\", LocalDate, DateOps>({\n name: \"Date\",\n is: (u: unknown): u is LocalDate => u instanceof LocalDate,\n valid: (d: LocalDate): boolean => Number.isSafeInteger(d.days) && Math.abs(d.days) <= MAX_DAYS,\n show: (d: LocalDate): string => d.toString(),\n encode: (d: LocalDate): string => d.toString(),\n decode: (u: unknown): LocalDate => (typeof u === \"string\" ? LocalDate.parse(u) : undefined) ?? new LocalDate(Number.NaN),\n ops: {\n add: { params: [\"number\"] },\n subtract: { params: [\"any\"] },\n addMonths: { params: [\"number\"] },\n endOfMonth: { params: [\"number\"] },\n year: {},\n month: {},\n day: {},\n weekday: {},\n gt: { params: [\"domain\"] },\n gte: { params: [\"domain\"] },\n lt: { params: [\"domain\"] },\n lte: { params: [\"domain\"] },\n eq: { laws: [\"commutative\"], params: [\"domain\"] },\n },\n});\n","import { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\nimport { LocalDate } from \"./date.ts\";\nimport { Vec2 } from \"./vec2.ts\";\nimport type { XY } from \"./xy.ts\";\n\ntype NumFn1 = (a: number) => number;\ntype NumFn2 = (a: number, b: number) => number;\ntype NumFn3 = (a: number, b: number, c: number) => number;\ntype NumTest = (a: number, b: number) => boolean;\n\n/** The ops of `NumDomain`. */\nexport type NumOps = {\n readonly add: FnOp<number, NumFn2>;\n readonly subtract: FnOp<number, NumFn2>;\n readonly multiply: FnOp<number, NumFn2>;\n readonly divide: FnOp<number, NumFn2>;\n readonly mod: FnOp<number, NumFn2>;\n readonly pow: FnOp<number, NumFn2>;\n readonly min: FnOp<number, NumFn2>;\n readonly max: FnOp<number, NumFn2>;\n readonly clamp: FnOp<number, NumFn3>;\n readonly abs: FnOp<number, NumFn1>;\n readonly negate: FnOp<number, NumFn1>;\n readonly sqrt: FnOp<number, NumFn1>;\n readonly ln: FnOp<number, NumFn1>;\n readonly exp: FnOp<number, NumFn1>;\n readonly log10: FnOp<number, NumFn1>;\n readonly sin: FnOp<number, NumFn1>;\n readonly cos: FnOp<number, NumFn1>;\n readonly asin: FnOp<number, NumFn1>;\n readonly hypot: FnOp<number, NumFn2>;\n readonly date: FnOp<number, (year: number, month: number, day: number) => LocalDate>;\n readonly vec2: FnOp<number, (x: number, y: number) => Vec2>;\n readonly xy: FnOp<number, (x: number, y: number) => XY>;\n readonly floor: FnOp<number, NumFn1>;\n readonly ceil: FnOp<number, NumFn1>;\n readonly round: FnOp<number, NumFn1>;\n readonly gt: FnOp<number, NumTest>;\n readonly gte: FnOp<number, NumTest>;\n readonly lt: FnOp<number, NumTest>;\n readonly lte: FnOp<number, NumTest>;\n readonly eq: FnOp<number, NumTest>;\n};\n\n/** The domain of numbers. A result that is not a finite number is the error `#NUM!`. */\nexport const NumDomain: Domain<\"Num\", number, NumOps> = defineDomain<\"Num\", number, NumOps>({\n name: \"Num\",\n is: (u: unknown): u is number => typeof u === \"number\",\n primitive: \"number\",\n valid: (n: number): boolean => Number.isFinite(n),\n show: (n: number): string => String(n),\n ops: {\n add: { fn: (a: number, b: number): number => a + b, laws: [\"commutative\", \"associative\"], identity: (): number => 0, params: [\"number\"], returns: \"number\" },\n subtract: { fn: (a: number, b: number): number => a - b, params: [\"number\"], returns: \"number\" },\n multiply: { fn: (a: number, b: number): number => a * b, laws: [\"commutative\", \"associative\"], identity: (): number => 1, params: [\"number\"], returns: \"number\" },\n divide: { fn: (a: number, b: number): number => a / b, params: [\"number\"], returns: \"number\" },\n mod: { fn: (a: number, b: number): number => a % b, params: [\"number\"], returns: \"number\" },\n pow: { fn: (a: number, b: number): number => a ** b, params: [\"number\"], returns: \"number\" },\n min: { fn: (a: number, b: number): number => Math.min(a, b), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"number\"], returns: \"number\" },\n max: { fn: (a: number, b: number): number => Math.max(a, b), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"number\"], returns: \"number\" },\n clamp: { fn: (a: number, lo: number, hi: number): number => Math.min(hi, Math.max(lo, a)), params: [\"number\", \"number\"], returns: \"number\" },\n abs: { fn: (a: number): number => Math.abs(a), returns: \"number\" },\n negate: { fn: (a: number): number => -a, returns: \"number\" },\n sqrt: { fn: (a: number): number => Math.sqrt(a), returns: \"number\" },\n ln: { fn: (a: number): number => Math.log(a), returns: \"number\" },\n exp: { fn: (a: number): number => Math.exp(a), returns: \"number\" },\n log10: { fn: (a: number): number => Math.log10(a), returns: \"number\" },\n // The angles of sin, cos and asin are in radians.\n sin: { fn: (a: number): number => Math.sin(a), returns: \"number\" },\n cos: { fn: (a: number): number => Math.cos(a), returns: \"number\" },\n asin: { fn: (a: number): number => Math.asin(a), returns: \"number\" },\n hypot: { fn: (a: number, b: number): number => Math.hypot(a, b), laws: [\"commutative\"], params: [\"number\"], returns: \"number\" },\n // The year is the receiver: date(year, month, day). The result is a LocalDate, so a chain continues in DateDomain.\n date: { fn: (year: number, month: number, day: number): LocalDate => LocalDate.of(year, month, day), params: [\"number\", \"number\"] },\n // The x component is the receiver: vec2(x, y). The result is a Vec2, so a chain continues in Vec2Domain.\n vec2: { fn: (x: number, y: number): Vec2 => new Vec2(x, y), params: [\"number\"] },\n // The same as plain data, for a standalone module: xy(x, y). The result is a value of XYDomain.\n xy: { fn: (x: number, y: number): XY => ({ x, y }), params: [\"number\"], returns: \"domain:XY\" },\n floor: { fn: (a: number): number => Math.floor(a), returns: \"number\" },\n ceil: { fn: (a: number): number => Math.ceil(a), returns: \"number\" },\n round: { fn: (a: number): number => Math.round(a), returns: \"number\" },\n gt: { fn: (a: number, b: number): boolean => a > b, params: [\"number\"], returns: \"boolean\" },\n gte: { fn: (a: number, b: number): boolean => a >= b, params: [\"number\"], returns: \"boolean\" },\n lt: { fn: (a: number, b: number): boolean => a < b, params: [\"number\"], returns: \"boolean\" },\n lte: { fn: (a: number, b: number): boolean => a <= b, params: [\"number\"], returns: \"boolean\" },\n eq: { fn: (a: number, b: number): boolean => a === b, laws: [\"commutative\"], params: [\"number\"], returns: \"boolean\" },\n },\n});\n\ntype BoolFn1 = (a: boolean) => boolean;\ntype BoolFn2 = (a: boolean, b: boolean) => boolean;\n\n/** The ops of `BoolDomain`. */\nexport type BoolOps = {\n readonly and: FnOp<boolean, BoolFn2>;\n readonly or: FnOp<boolean, BoolFn2>;\n readonly xor: FnOp<boolean, BoolFn2>;\n readonly not: FnOp<boolean, BoolFn1>;\n readonly eq: FnOp<boolean, BoolFn2>;\n};\n\n/** The domain of booleans. For lazy logic, use the special forms `and`, `or` and `if` of the IR. */\nexport const BoolDomain: Domain<\"Bool\", boolean, BoolOps> = defineDomain<\"Bool\", boolean, BoolOps>({\n name: \"Bool\",\n is: (u: unknown): u is boolean => typeof u === \"boolean\",\n primitive: \"boolean\",\n show: (b: boolean): string => String(b),\n ops: {\n and: { fn: (a: boolean, b: boolean): boolean => a && b, laws: [\"commutative\", \"associative\", \"idempotent\"], identity: (): boolean => true, params: [\"boolean\"], returns: \"boolean\" },\n or: { fn: (a: boolean, b: boolean): boolean => a || b, laws: [\"commutative\", \"associative\", \"idempotent\"], identity: (): boolean => false, params: [\"boolean\"], returns: \"boolean\" },\n xor: { fn: (a: boolean, b: boolean): boolean => a !== b, laws: [\"commutative\", \"associative\"], identity: (): boolean => false, params: [\"boolean\"], returns: \"boolean\" },\n not: { fn: (a: boolean): boolean => !a, returns: \"boolean\" },\n eq: { fn: (a: boolean, b: boolean): boolean => a === b, laws: [\"commutative\"], params: [\"boolean\"], returns: \"boolean\" },\n },\n});\n","/**\n * The domain of texts. The op `concat` joins a text and a value of any kind. It is the operator `&` of a\n * spreadsheet, and of the formula language of the sheet app.\n */\nimport { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\n\ntype TextFn1 = (a: string) => string;\n\n/** The ops of `TextDomain`. */\nexport type TextOps = {\n readonly concat: FnOp<string, (a: string, b: unknown) => string>;\n readonly length: FnOp<string, (a: string) => number>;\n readonly upper: FnOp<string, TextFn1>;\n readonly lower: FnOp<string, TextFn1>;\n readonly trim: FnOp<string, TextFn1>;\n readonly contains: FnOp<string, (a: string, b: string) => boolean>;\n readonly eq: FnOp<string, (a: string, b: string) => boolean>;\n};\n\n/**\n * This function gives the text of a value for `concat`. A text stays. A plain record gives its JSON text. Another\n * value, for example a number or a `Vec2`, gives its own text.\n */\nconst textOf = (u: unknown): string => (typeof u === \"object\" && u !== null && Object.getPrototypeOf(u) === Object.prototype ? JSON.stringify(u) : String(u));\n\n/** The domain of texts. */\nexport const TextDomain: Domain<\"Text\", string, TextOps> = defineDomain<\"Text\", string, TextOps>({\n name: \"Text\",\n is: (u: unknown): u is string => typeof u === \"string\",\n primitive: \"string\",\n show: (s: string): string => JSON.stringify(s),\n ops: {\n concat: { fn: (a: string, b: unknown): string => a + textOf(b), params: [\"any\"], returns: \"string\" },\n // The length counts UTF-16 code units, like the function LEN of a spreadsheet.\n length: { fn: (a: string): number => a.length, returns: \"number\" },\n upper: { fn: (a: string): string => a.toUpperCase(), returns: \"string\" },\n lower: { fn: (a: string): string => a.toLowerCase(), returns: \"string\" },\n trim: { fn: (a: string): string => a.trim(), returns: \"string\" },\n contains: { fn: (a: string, b: string): boolean => a.includes(b), params: [\"string\"], returns: \"boolean\" },\n eq: { fn: (a: string, b: string): boolean => a === b, laws: [\"commutative\"], params: [\"string\"], returns: \"boolean\" },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\n\n/** The linear value of an sRGB channel from 0 to 255, with the sRGB transfer function of WCAG 2.1. */\nfunction linear(channel: number): number {\n const s = Math.min(1, Math.max(0, channel / 255));\n // For integer channels, the sRGB threshold 0.04045 and the WCAG threshold 0.03928 give the same result.\n return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n}\n\n/**\n * An immutable RGBA color. The channels have no fixed range: use `clamp` to limit them. `add` adds the color\n * channels and keeps the larger alpha, so `add` is commutative and associative.\n */\nexport class Color {\n readonly r: number;\n readonly g: number;\n readonly b: number;\n readonly a: number;\n\n constructor(r: number, g: number, b: number, a = 1) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n }\n\n /** This function makes a gray color with the value `n` in each channel. */\n static gray(n: number): Color {\n return new Color(n, n, n, 1);\n }\n /** The black color with alpha 0: the identity of `add`. */\n static readonly none: Color = new Color(0, 0, 0, 0);\n\n /** The channel sum. The alpha is the larger alpha. */\n add(o: Color): Color {\n return new Color(this.r + o.r, this.g + o.g, this.b + o.b, Math.max(this.a, o.a));\n }\n /** Each color channel times `factor`. The alpha does not change. */\n multiply(factor: number): Color {\n return new Color(this.r * factor, this.g * factor, this.b * factor, this.a);\n }\n /** Each color channel in the range from `lo` to `hi`. */\n clamp(lo = 0, hi = 255): Color {\n const c = (x: number): number => Math.min(hi, Math.max(lo, x));\n return new Color(c(this.r), c(this.g), c(this.b), this.a);\n }\n /** The linear mix from this color to `o`. */\n mix(o: Color, t: number): Color {\n const m = (x: number, y: number): number => x + (y - x) * t;\n return new Color(m(this.r, o.r), m(this.g, o.g), m(this.b, o.b), m(this.a, o.a));\n }\n /** The relative luminance (Rec. 709 weights) of the color channels. */\n luminance(): number {\n return 0.2126 * this.r + 0.7152 * this.g + 0.0722 * this.b;\n }\n /**\n * The relative luminance of WCAG 2.1, from 0 (black) to 1 (white). Each channel from 0 to 255 becomes a linear\n * value with the sRGB transfer function. A channel outside the range counts as the nearest end of the range.\n */\n relativeLuminance(): number {\n return 0.2126 * linear(this.r) + 0.7152 * linear(this.g) + 0.0722 * linear(this.b);\n }\n /** The contrast ratio of WCAG 2.1 between this color and `o`: 1 for equal luminance, 21 for black and white. */\n contrast(o: Color): number {\n const a = this.relativeLuminance();\n const b = o.relativeLuminance();\n return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);\n }\n equals(o: Color): boolean {\n return this.r === o.r && this.g === o.g && this.b === o.b && this.a === o.a;\n }\n toArray(): readonly [number, number, number, number] {\n return [this.r, this.g, this.b, this.a];\n }\n toString(): string {\n return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`;\n }\n}\n\n/** The ops of `ColorDomain`. */\nexport type ColorOps = OpTable<Color, \"add\" | \"multiply\" | \"clamp\" | \"mix\" | \"luminance\" | \"relativeLuminance\" | \"contrast\" | \"equals\">;\n\n/** The domain of colors. */\nexport const ColorDomain: Domain<\"Color\", Color, ColorOps> = defineDomain<\"Color\", Color, ColorOps>({\n name: \"Color\",\n is: (u: unknown): u is Color => u instanceof Color,\n fromScalar: (n: number): Color => Color.gray(n),\n valid: (c: Color): boolean => c.toArray().every((x) => Number.isFinite(x)),\n show: (c: Color): string => c.toString(),\n encode: (c: Color): readonly number[] => c.toArray(),\n decode: (u: unknown): Color => {\n const [r, g, b, a] = (Array.isArray(u) ? u : []) as readonly number[];\n return new Color(r ?? Number.NaN, g ?? Number.NaN, b ?? Number.NaN, a ?? 1);\n },\n ops: {\n add: { laws: [\"commutative\", \"associative\"], identity: (): Color => Color.none, params: [\"domain\"] },\n multiply: { params: [\"number\"] },\n clamp: { params: [\"number\", \"number\"] },\n mix: { params: [\"domain\", \"number\"] },\n luminance: {},\n relativeLuminance: {},\n contrast: { laws: [\"commutative\"], params: [\"domain\"] },\n equals: { laws: [\"commutative\"], params: [\"domain\"] },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\nimport { Vec2 } from \"./vec2.ts\";\n\n/** An immutable angle in radians. */\nexport class Angle {\n readonly radians: number;\n\n constructor(radians: number) {\n this.radians = radians;\n }\n\n /** This function makes an angle from degrees. */\n static fromDegrees(deg: number): Angle {\n return new Angle((deg * Math.PI) / 180);\n }\n /** The zero angle: the identity of `add`. */\n static readonly zero: Angle = new Angle(0);\n\n add(o: Angle): Angle {\n return new Angle(this.radians + o.radians);\n }\n subtract(o: Angle): Angle {\n return new Angle(this.radians - o.radians);\n }\n scale(k: number): Angle {\n return new Angle(this.radians * k);\n }\n /** The same angle in the range from -π (included) to π (not included). */\n normalize(): Angle {\n const twoPi = Math.PI * 2;\n // Stryker disable next-line ArithmeticOperator: x + π and x - π differ by 2π, so the result after mod 2π is the same\n return new Angle((((this.radians + Math.PI) % twoPi) + twoPi) % twoPi - Math.PI);\n }\n /** The vector with this angle and the length `length`. The result is a `Vec2`, so a chain continues in that domain. */\n toVec2(length = 1): Vec2 {\n return new Vec2(Math.cos(this.radians) * length, Math.sin(this.radians) * length);\n }\n sin(): number {\n return Math.sin(this.radians);\n }\n cos(): number {\n return Math.cos(this.radians);\n }\n degrees(): number {\n return (this.radians * 180) / Math.PI;\n }\n toString(): string {\n return `${this.radians} rad`;\n }\n}\n\n/** The ops of `AngleDomain`. */\nexport type AngleOps = OpTable<Angle, \"add\" | \"subtract\" | \"scale\" | \"normalize\" | \"toVec2\" | \"sin\" | \"cos\" | \"degrees\", \"add\" | \"subtract\">;\n\n/** The domain of angles. A number argument of `add` or `subtract` lifts to an angle in radians. */\nexport const AngleDomain: Domain<\"Angle\", Angle, AngleOps> = defineDomain<\"Angle\", Angle, AngleOps>({\n name: \"Angle\",\n is: (u: unknown): u is Angle => u instanceof Angle,\n fromScalar: (n: number): Angle => new Angle(n),\n valid: (a: Angle): boolean => Number.isFinite(a.radians),\n show: (a: Angle): string => a.toString(),\n encode: (a: Angle): number => a.radians,\n decode: (u: unknown): Angle => new Angle(typeof u === \"number\" ? u : Number.NaN),\n ops: {\n add: { laws: [\"commutative\", \"associative\"], identity: (): Angle => Angle.zero, liftScalar: true, params: [\"domain\"] },\n subtract: { liftScalar: true, params: [\"domain\"] },\n scale: { params: [\"number\"] },\n normalize: {},\n toVec2: { params: [\"number\"] },\n sin: {},\n cos: {},\n degrees: {},\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\n\n/** A wrapper around a function. Its op `invoke` calls the function. It shows how a domain can hold behavior. */\nexport class Fn {\n readonly fn: (...args: never[]) => unknown;\n\n constructor(fn: (...args: never[]) => unknown) {\n this.fn = fn;\n }\n invoke(...args: readonly unknown[]): unknown {\n return (this.fn as (...a: readonly unknown[]) => unknown)(...args);\n }\n}\n\n/** The ops of `FnDomain`. */\nexport type FnOps = OpTable<Fn, \"invoke\">;\n\n/** The domain of function wrappers. */\nexport const FnDomain: Domain<\"Fn\", Fn, FnOps> = defineDomain<\"Fn\", Fn, FnOps>({\n name: \"Fn\",\n is: (u: unknown): u is Fn => u instanceof Fn,\n ops: { invoke: {} },\n});\n\n/**\n * A value that is there (`top`) or not there (`bottom`). It shows a domain whose ops take functions. A Vex\n * program can also hold this state in its own errors, so most programs do not need this domain.\n */\nexport class Maybe<T> {\n readonly #has: boolean;\n readonly #value: T | undefined;\n\n private constructor(has: boolean, value: T | undefined) {\n this.#has = has;\n this.#value = value;\n }\n static top<T>(value: T): Maybe<T> {\n return new Maybe<T>(true, value);\n }\n static bottom<T = never>(): Maybe<T> {\n return new Maybe<T>(false, undefined);\n }\n isTop(): boolean {\n return this.#has;\n }\n isBottom(): boolean {\n return !this.#has;\n }\n map<U>(f: (value: T) => U): Maybe<U> {\n return this.#has ? Maybe.top(f(this.#value as T)) : Maybe.bottom<U>();\n }\n chain<U>(f: (value: T) => Maybe<U>): Maybe<U> {\n return this.#has ? f(this.#value as T) : Maybe.bottom<U>();\n }\n valueOr<U>(fallback: U): T | U {\n return this.#has ? (this.#value as T) : fallback;\n }\n}\n\n/** The ops of `MaybeDomain`. */\nexport type MaybeOps = OpTable<Maybe<unknown>, \"isTop\" | \"isBottom\" | \"map\" | \"chain\" | \"valueOr\">;\n\n/** The domain of `Maybe` values. */\nexport const MaybeDomain: Domain<\"Maybe\", Maybe<unknown>, MaybeOps> = defineDomain<\"Maybe\", Maybe<unknown>, MaybeOps>({\n name: \"Maybe\",\n is: (u: unknown): u is Maybe<unknown> => u instanceof Maybe,\n ops: { isTop: {}, isBottom: {}, map: {}, chain: {}, valueOr: {} },\n});\n"],"mappings":";;;;;;AAMA,IAAa,OAAb,MAAa,KAAK;CAChB;CACA;CAEA,YAAY,GAAW,GAAW;EAChC,KAAK,IAAI;EACT,KAAK,IAAI;CACX;;CAGA,OAAO,GAAG,GAAW,GAAiB;EACpC,OAAO,IAAI,KAAK,GAAG,CAAC;CACtB;;CAEA,OAAO,OAAO,GAAiB;EAC7B,OAAO,IAAI,KAAK,GAAG,CAAC;CACtB;;CAEA,OAAgB,OAAa,IAAI,KAAK,GAAG,CAAC;;CAE1C,OAAgB,MAAY,IAAI,KAAK,GAAG,CAAC;CAEzC,IAAI,GAAe;EACjB,OAAO,IAAI,KAAK,KAAK,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,C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,WAAoB;EAClB,OAAO,CAAC,KAAK;CACf;CACA,IAAO,GAA8B;EACnC,OAAO,KAAK,OAAO,MAAM,IAAI,EAAE,KAAK,MAAW,CAAC,IAAI,MAAM,OAAU;CACtE;CACA,MAAS,GAAqC;EAC5C,OAAO,KAAK,OAAO,EAAE,KAAK,MAAW,IAAI,MAAM,OAAU;CAC3D;CACA,QAAW,UAAoB;EAC7B,OAAO,KAAK,OAAQ,KAAK,SAAe;CAC1C;AACF;;AAMA,MAAa,cAAyD,aAAgD;CACpH,MAAM;CACN,KAAK,MAAoC,aAAa;CACtD,KAAK;EAAE,OAAO,CAAC;EAAG,UAAU,CAAC;EAAG,KAAK,CAAC;EAAG,OAAO,CAAC;EAAG,SAAS,CAAC;CAAE;AAClE,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/vec2.ts","../src/xy.ts","../src/ndvector.ts","../src/date.ts","../src/scalars.ts","../src/text.ts","../src/color.ts","../src/angle.ts","../src/json.ts","../src/wrappers.ts"],"sourcesContent":["import { defineDomain, type Domain, type FnOp, type OpTable } from \"@mark1russell7/vex\";\n\n/**\n * An immutable 2D vector. The methods live on the prototype, so a vector costs two numbers. Division is real\n * division: a division by zero gives an infinite component, and the domain check turns it into `#NUM!`.\n */\nexport class Vec2 {\n readonly x: number;\n readonly y: number;\n\n constructor(x: number, y: number) {\n this.x = x;\n this.y = y;\n }\n\n /** This function makes a vector. */\n static of(x: number, y: number): Vec2 {\n return new Vec2(x, y);\n }\n /** This function makes a vector with the same value in both components. */\n static scalar(n: number): Vec2 {\n return new Vec2(n, n);\n }\n /** The zero vector. */\n static readonly zero: Vec2 = new Vec2(0, 0);\n /** The vector of ones. */\n static readonly one: Vec2 = new Vec2(1, 1);\n\n add(o: Vec2): Vec2 {\n return new Vec2(this.x + o.x, this.y + o.y);\n }\n subtract(o: Vec2): Vec2 {\n return new Vec2(this.x - o.x, this.y - o.y);\n }\n /** The component-wise product. */\n multiply(o: Vec2): Vec2 {\n return new Vec2(this.x * o.x, this.y * o.y);\n }\n /** The component-wise quotient. A zero component of `o` gives an infinite component. */\n divide(o: Vec2): Vec2 {\n return new Vec2(this.x / o.x, this.y / o.y);\n }\n /** The component-wise minimum. */\n min(o: Vec2): Vec2 {\n return new Vec2(Math.min(this.x, o.x), Math.min(this.y, o.y));\n }\n /** The component-wise maximum. */\n max(o: Vec2): Vec2 {\n return new Vec2(Math.max(this.x, o.x), Math.max(this.y, o.y));\n }\n scale(k: number): Vec2 {\n return new Vec2(this.x * k, this.y * k);\n }\n negate(): Vec2 {\n return new Vec2(-this.x, -this.y);\n }\n halve(): Vec2 {\n return this.scale(0.5);\n }\n abs(): Vec2 {\n return new Vec2(Math.abs(this.x), Math.abs(this.y));\n }\n round(): Vec2 {\n return new Vec2(Math.round(this.x), Math.round(this.y));\n }\n floor(): Vec2 {\n return new Vec2(Math.floor(this.x), Math.floor(this.y));\n }\n ceil(): Vec2 {\n return new Vec2(Math.ceil(this.x), Math.ceil(this.y));\n }\n clamp(lo: number, hi: number): Vec2 {\n return new Vec2(Math.min(hi, Math.max(lo, this.x)), Math.min(hi, Math.max(lo, this.y)));\n }\n swap(): Vec2 {\n return new Vec2(this.y, this.x);\n }\n /**\n * The vector with `main` along the unit axis of this vector and `cross` on the other axis: `this * main + swap(this) *\n * cross`. For the axis (1, 0) it is (main, cross), and for the axis (0, 1) it is (cross, main).\n */\n compose(main: number, cross: number): Vec2 {\n return new Vec2(this.x * main + this.y * cross, this.y * main + this.x * cross);\n }\n /**\n * The component-wise choice: a component of `a` where this mask has a component that is not 0, else the component\n * of `b`. Thus `hi.select(v.min(hi), v)` bounds each component of `v` by `hi`, and a 0 in `hi` sets no bound.\n */\n select(a: Vec2, b: Vec2): Vec2 {\n return new Vec2(this.x !== 0 ? a.x : b.x, this.y !== 0 ? a.y : b.y);\n }\n /** The vector turned by `radians`, counterclockwise. */\n rotate(radians: number): Vec2 {\n const c = Math.cos(radians);\n const s = Math.sin(radians);\n return new Vec2(c * this.x - s * this.y, s * this.x + c * this.y);\n }\n /** The vector with length 1. The zero vector stays zero. */\n normalize(): Vec2 {\n const len = this.length();\n return len === 0 ? this : this.scale(1 / len);\n }\n /** The linear interpolation from this vector to `o`. */\n lerp(o: Vec2, t: number): Vec2 {\n return new Vec2(this.x + (o.x - this.x) * t, this.y + (o.y - this.y) * t);\n }\n length(): number {\n return Math.hypot(this.x, this.y);\n }\n lengthSq(): number {\n return this.x * this.x + this.y * this.y;\n }\n distance(o: Vec2): number {\n return Math.hypot(this.x - o.x, this.y - o.y);\n }\n dot(o: Vec2): number {\n return this.x * o.x + this.y * o.y;\n }\n /** The component along the unit axis `dir`: `dot(this, dir)`. For the axis (1, 0) it is x, and for (0, 1) it is y. */\n along(dir: Vec2): number {\n return this.x * dir.x + this.y * dir.y;\n }\n /** The component on the other axis of the unit axis `dir`: `dot(this, swap(dir))`. For the axis (1, 0) it is y. */\n across(dir: Vec2): number {\n return this.x * dir.y + this.y * dir.x;\n }\n /** The z component of the 3D cross product. */\n cross(o: Vec2): number {\n return this.x * o.y - this.y * o.x;\n }\n /** The angle of the vector, in radians, from the x axis. */\n angle(): number {\n return Math.atan2(this.y, this.x);\n }\n /** The product of the components: the area of a size vector. */\n area(): number {\n return this.x * this.y;\n }\n /** The sum of the components. */\n sum(): number {\n return this.x + this.y;\n }\n minComponent(): number {\n return Math.min(this.x, this.y);\n }\n maxComponent(): number {\n return Math.max(this.x, this.y);\n }\n equals(o: Vec2): boolean {\n return this.x === o.x && this.y === o.y;\n }\n anyNonPositive(): boolean {\n return this.x <= 0 || this.y <= 0;\n }\n allPositive(): boolean {\n return this.x > 0 && this.y > 0;\n }\n anyNegative(): boolean {\n return this.x < 0 || this.y < 0;\n }\n allNonNegative(): boolean {\n return this.x >= 0 && this.y >= 0;\n }\n anyZero(): boolean {\n return this.x === 0 || this.y === 0;\n }\n allZero(): boolean {\n return this.x === 0 && this.y === 0;\n }\n anyLessThan(n: number): boolean {\n return this.x < n || this.y < n;\n }\n allLessThan(n: number): boolean {\n return this.x < n && this.y < n;\n }\n anyGreaterThan(n: number): boolean {\n return this.x > n || this.y > n;\n }\n allGreaterThan(n: number): boolean {\n return this.x > n && this.y > n;\n }\n toJSON(): { readonly x: number; readonly y: number } {\n return { x: this.x, y: this.y };\n }\n toString(): string {\n return `(${this.x}, ${this.y})`;\n }\n}\n\ntype Vec2OpNames =\n | \"add\" | \"subtract\" | \"multiply\" | \"divide\" | \"min\" | \"max\" | \"scale\" | \"negate\" | \"halve\" | \"abs\" | \"round\"\n | \"floor\" | \"ceil\" | \"clamp\" | \"swap\" | \"compose\" | \"select\" | \"rotate\" | \"normalize\" | \"lerp\" | \"length\"\n | \"lengthSq\" | \"distance\" | \"dot\" | \"along\" | \"across\" | \"cross\" | \"angle\" | \"area\" | \"sum\" | \"minComponent\"\n | \"maxComponent\" | \"equals\" | \"anyNonPositive\" | \"allPositive\" | \"anyNegative\" | \"allNonNegative\" | \"anyZero\"\n | \"allZero\" | \"anyLessThan\" | \"allLessThan\" | \"anyGreaterThan\" | \"allGreaterThan\";\n\n/** The ops of `Vec2Domain`. The ops `x` and `y` give a component. */\nexport type Vec2Ops = OpTable<Vec2, Vec2OpNames, \"add\" | \"subtract\" | \"multiply\" | \"divide\" | \"min\" | \"max\" | \"select\"> & {\n readonly x: FnOp<Vec2, (v: Vec2) => number>;\n readonly y: FnOp<Vec2, (v: Vec2) => number>;\n};\n\n/** The domain of 2D vectors. A number argument of a component-wise op lifts to a vector with that value twice. */\nexport const Vec2Domain: Domain<\"Vec2\", Vec2, Vec2Ops> = defineDomain<\"Vec2\", Vec2, Vec2Ops>({\n name: \"Vec2\",\n is: (u: unknown): u is Vec2 => u instanceof Vec2,\n fromScalar: (n: number): Vec2 => Vec2.scalar(n),\n valid: (v: Vec2): boolean => Number.isFinite(v.x) && Number.isFinite(v.y),\n show: (v: Vec2): string => v.toString(),\n encode: (v: Vec2): readonly [number, number] => [v.x, v.y],\n decode: (u: unknown): Vec2 => {\n // Stryker disable next-line ArrayDeclaration: a list with a text gives NaN components, like the empty list\n const [x, y] = Array.isArray(u) ? (u as readonly unknown[]) : [];\n return new Vec2(typeof x === \"number\" ? x : Number.NaN, typeof y === \"number\" ? y : Number.NaN);\n },\n ops: {\n // The components are fields of a vector, not methods, so these two ops are functions.\n x: { fn: (v: Vec2): number => v.x, params: [], returns: \"number\" },\n y: { fn: (v: Vec2): number => v.y, params: [], returns: \"number\" },\n add: { laws: [\"commutative\", \"associative\"], identity: () => Vec2.zero, liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n subtract: { liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n multiply: { laws: [\"commutative\", \"associative\"], identity: () => Vec2.one, liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n divide: { liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n min: { laws: [\"commutative\", \"associative\", \"idempotent\"], liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n max: { laws: [\"commutative\", \"associative\", \"idempotent\"], liftScalar: true, params: [\"domain\"], returns: \"domain\" },\n scale: { params: [\"number\"], returns: \"domain\" },\n negate: { params: [], returns: \"domain\" },\n halve: { params: [], returns: \"domain\" },\n abs: { params: [], returns: \"domain\" },\n round: { params: [], returns: \"domain\" },\n floor: { params: [], returns: \"domain\" },\n ceil: { params: [], returns: \"domain\" },\n clamp: { params: [\"number\", \"number\"], returns: \"domain\" },\n swap: { params: [], returns: \"domain\" },\n compose: { params: [\"number\", \"number\"], returns: \"domain\" },\n select: { liftScalar: true, params: [\"domain\", \"domain\"], returns: \"domain\" },\n rotate: { params: [\"number\"], returns: \"domain\" },\n normalize: { params: [], returns: \"domain\" },\n lerp: { params: [\"domain\", \"number\"], returns: \"domain\" },\n length: { params: [], returns: \"number\" },\n lengthSq: { params: [], returns: \"number\" },\n distance: { params: [\"domain\"], returns: \"number\" },\n dot: { laws: [\"commutative\"], params: [\"domain\"], returns: \"number\" },\n along: { params: [\"domain\"], returns: \"number\" },\n across: { params: [\"domain\"], returns: \"number\" },\n cross: { params: [\"domain\"], returns: \"number\" },\n angle: { params: [], returns: \"number\" },\n area: { params: [], returns: \"number\" },\n sum: { params: [], returns: \"number\" },\n minComponent: { params: [], returns: \"number\" },\n maxComponent: { params: [], returns: \"number\" },\n equals: { laws: [\"commutative\"], params: [\"domain\"], returns: \"boolean\" },\n anyNonPositive: { params: [], returns: \"boolean\" },\n allPositive: { params: [], returns: \"boolean\" },\n anyNegative: { params: [], returns: \"boolean\" },\n allNonNegative: { params: [], returns: \"boolean\" },\n anyZero: { params: [], returns: \"boolean\" },\n allZero: { params: [], returns: \"boolean\" },\n anyLessThan: { params: [\"number\"], returns: \"boolean\" },\n allLessThan: { params: [\"number\"], returns: \"boolean\" },\n anyGreaterThan: { params: [\"number\"], returns: \"boolean\" },\n allGreaterThan: { params: [\"number\"], returns: \"boolean\" },\n },\n});\n","import { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\n\n/**\n * A 2D vector as plain data. `XYDomain` has the component-wise ops of `Vec2Domain`, but each op is a function of plain\n * data. Thus a standalone module of `@mark1russell7/vex-compiler` can copy the domain, and a 2D program can be a module.\n */\nexport interface XY {\n readonly x: number;\n readonly y: number;\n}\n\ntype XYFn2 = (a: XY, b: XY) => XY;\ntype XYFn1 = (a: XY) => XY;\ntype XYNum1 = (a: XY) => number;\n\n/** The ops of `XYDomain`. */\nexport type XYOps = {\n readonly x: FnOp<XY, XYNum1>;\n readonly y: FnOp<XY, XYNum1>;\n readonly add: FnOp<XY, XYFn2>;\n readonly subtract: FnOp<XY, XYFn2>;\n readonly multiply: FnOp<XY, XYFn2>;\n readonly divide: FnOp<XY, XYFn2>;\n readonly min: FnOp<XY, XYFn2>;\n readonly max: FnOp<XY, XYFn2>;\n readonly scale: FnOp<XY, (a: XY, k: number) => XY>;\n readonly negate: FnOp<XY, XYFn1>;\n readonly abs: FnOp<XY, XYFn1>;\n readonly floor: FnOp<XY, XYFn1>;\n readonly ceil: FnOp<XY, XYFn1>;\n readonly round: FnOp<XY, XYFn1>;\n readonly dot: FnOp<XY, (a: XY, b: XY) => number>;\n readonly length: FnOp<XY, XYNum1>;\n readonly distance: FnOp<XY, (a: XY, b: XY) => number>;\n readonly area: FnOp<XY, XYNum1>;\n readonly sum: FnOp<XY, XYNum1>;\n readonly equals: FnOp<XY, (a: XY, b: XY) => boolean>;\n};\n\n/**\n * The domain of 2D vectors as plain data: an object with the two number fields `x` and `y` and no other field. The op\n * `xy` of `NumDomain` makes one. No op lifts a number, so each op has a static site in a module. Put `XYDomain` before\n * `NumRecordDomain`, because a record of numbers accepts the same objects.\n */\nexport const XYDomain: Domain<\"XY\", XY, XYOps> = defineDomain<\"XY\", XY, XYOps>({\n name: \"XY\",\n // A plain object: its prototype is Object.prototype or null, so an instance of a class such as Vec2 is not an XY.\n is: (u: unknown): u is XY => typeof u === \"object\" && u !== null && [Object.prototype, null].includes(Object.getPrototypeOf(u) as object | null) && Object.keys(u).length === 2 && typeof (u as XY).x === \"number\" && typeof (u as XY).y === \"number\",\n valid: (v: XY): boolean => Number.isFinite(v.x) && Number.isFinite(v.y),\n show: (v: XY): string => `(${v.x}, ${v.y})`,\n samples: (): readonly XY[] => [{ x: 0, y: 0 }, { x: 1.5, y: -2 }, { x: 3, y: 4 }],\n ops: {\n x: { fn: (a: XY): number => a.x, params: [], returns: \"number\" },\n y: { fn: (a: XY): number => a.y, params: [], returns: \"number\" },\n add: { fn: (a: XY, b: XY): XY => ({ x: a.x + b.x, y: a.y + b.y }), laws: [\"commutative\", \"associative\"], identity: (): XY => ({ x: 0, y: 0 }), params: [\"domain\"], returns: \"domain\" },\n subtract: { fn: (a: XY, b: XY): XY => ({ x: a.x - b.x, y: a.y - b.y }), params: [\"domain\"], returns: \"domain\" },\n multiply: { fn: (a: XY, b: XY): XY => ({ x: a.x * b.x, y: a.y * b.y }), laws: [\"commutative\", \"associative\"], identity: (): XY => ({ x: 1, y: 1 }), params: [\"domain\"], returns: \"domain\" },\n divide: { fn: (a: XY, b: XY): XY => ({ x: a.x / b.x, y: a.y / b.y }), params: [\"domain\"], returns: \"domain\" },\n min: { fn: (a: XY, b: XY): XY => ({ x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) }), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"], returns: \"domain\" },\n max: { fn: (a: XY, b: XY): XY => ({ x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) }), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"], returns: \"domain\" },\n scale: { fn: (a: XY, k: number): XY => ({ x: a.x * k, y: a.y * k }), params: [\"number\"], returns: \"domain\" },\n negate: { fn: (a: XY): XY => ({ x: -a.x, y: -a.y }), params: [], returns: \"domain\" },\n abs: { fn: (a: XY): XY => ({ x: Math.abs(a.x), y: Math.abs(a.y) }), params: [], returns: \"domain\" },\n floor: { fn: (a: XY): XY => ({ x: Math.floor(a.x), y: Math.floor(a.y) }), params: [], returns: \"domain\" },\n ceil: { fn: (a: XY): XY => ({ x: Math.ceil(a.x), y: Math.ceil(a.y) }), params: [], returns: \"domain\" },\n round: { fn: (a: XY): XY => ({ x: Math.round(a.x), y: Math.round(a.y) }), params: [], returns: \"domain\" },\n dot: { fn: (a: XY, b: XY): number => a.x * b.x + a.y * b.y, laws: [\"commutative\"], params: [\"domain\"], returns: \"number\" },\n length: { fn: (a: XY): number => Math.hypot(a.x, a.y), params: [], returns: \"number\" },\n distance: { fn: (a: XY, b: XY): number => Math.hypot(a.x - b.x, a.y - b.y), laws: [\"commutative\"], params: [\"domain\"], returns: \"number\" },\n area: { fn: (a: XY): number => a.x * a.y, params: [], returns: \"number\" },\n sum: { fn: (a: XY): number => a.x + a.y, params: [], returns: \"number\" },\n equals: { fn: (a: XY, b: XY): boolean => a.x === b.x && a.y === b.y, laws: [\"commutative\"], params: [\"domain\"], returns: \"boolean\" },\n },\n});\n","import { defineDomain, type Domain, type FnOp, type OpTable } from \"@mark1russell7/vex\";\n\n/**\n * An immutable vector with named components. The type parameter `K` is the set of component names. Ops that\n * combine two vectors use the union of their names, and a missing component counts as 0. The constructor\n * keeps each number, also a number that is not finite: the domain check reports such a value as `#NUM!`.\n */\nexport class NDVector<K extends string = string> {\n /** The components: name to number. */\n readonly c: Readonly<Record<K, number>>;\n\n constructor(c: Readonly<Record<K, number>>) {\n this.c = Object.freeze({ ...c });\n }\n\n /** This function makes a vector from name and value pairs. */\n static of<K extends string>(entries: readonly (readonly [K, number])[]): NDVector<K> {\n const c = {} as Record<K, number>;\n for (const [k, v] of entries) c[k] = v;\n return new NDVector(c);\n }\n /** This function makes the zero vector over the names `keys`. */\n static zero<K extends string>(keys: readonly K[] = []): NDVector<K> {\n return NDVector.of(keys.map((k) => [k, 0] as const));\n }\n\n /** The names of the components. */\n keys(): readonly K[] {\n return Object.keys(this.c) as K[];\n }\n /** The value of a component, or 0 if the vector does not have it. */\n get(k: string): number {\n return Object.hasOwn(this.c, k) ? Number((this.c as Readonly<Record<string, number>>)[k]) : 0;\n }\n set<K2 extends string>(k: K2, v: number): NDVector<K | K2> {\n return new NDVector({ ...this.c, [k]: v } as Record<K | K2, number>);\n }\n map(f: (name: K, v: number) => number): NDVector<K> {\n const c = {} as Record<K, number>;\n for (const k of this.keys()) c[k] = f(k, this.get(k));\n return new NDVector(c);\n }\n /** The vector with only the names in `keys`. A zero component is dropped, unless `keepZeros` is true. */\n pick<K2 extends K>(keys: readonly K2[], keepZeros = false): NDVector<K2> {\n const c = {} as Record<K2, number>;\n for (const k of keys) {\n const v = this.get(k);\n if (keepZeros || v !== 0) c[k] = v;\n }\n return new NDVector(c);\n }\n /** The vector with the names in `keys` added. A new component is 0. */\n withKeys<K2 extends string>(keys: readonly K2[]): NDVector<K | K2> {\n const c = { ...this.c } as Record<K | K2, number>;\n for (const k of keys) if (!Object.hasOwn(c, k)) c[k] = 0;\n return new NDVector(c);\n }\n #combine<K2 extends string>(o: NDVector<K2>, f: (a: number, b: number) => number): NDVector<K | K2> {\n const c = {} as Record<K | K2, number>;\n for (const k of new Set<K | K2>([...this.keys(), ...o.keys()])) c[k] = f(this.get(k), o.get(k));\n return new NDVector(c);\n }\n add<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => a + b);\n }\n subtract<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => a - b);\n }\n /** The component-wise product. */\n multiply<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => a * b);\n }\n /** The component-wise minimum. A component that one vector does not have counts as 0. */\n min<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => Math.min(a, b));\n }\n /** The component-wise maximum. A component that one vector does not have counts as 0. */\n max<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => Math.max(a, b));\n }\n /** Of each component, the value of this vector if it is not 0, else the value of `o`. */\n mergePreferNonZero<K2 extends string>(o: NDVector<K2>): NDVector<K | K2> {\n return this.#combine(o, (a, b) => (a !== 0 ? a : b));\n }\n scale(k: number): NDVector<K> {\n return this.map((_n, v) => v * k);\n }\n clamp(lo: number, hi: number): NDVector<K> {\n return this.map((_n, v) => Math.min(hi, Math.max(lo, v)));\n }\n dot(o: NDVector): number {\n let s = 0;\n for (const k of new Set<string>([...this.keys(), ...o.keys()])) s += this.get(k) * o.get(k);\n return s;\n }\n /** The L2 length. */\n length(): number {\n return Math.sqrt(this.keys().reduce((s, k) => s + this.get(k) ** 2, 0));\n }\n /** The L1 norm. */\n norm1(): number {\n return this.keys().reduce((s, k) => s + Math.abs(this.get(k)), 0);\n }\n /** The largest absolute component. */\n normInf(): number {\n return this.keys().reduce((m, k) => Math.max(m, Math.abs(this.get(k))), 0);\n }\n equals(o: NDVector): boolean {\n const keys = new Set<string>([...this.keys(), ...o.keys()]);\n for (const k of keys) if (this.get(k) !== o.get(k)) return false;\n return true;\n }\n /** True if each component is a finite number. */\n isFinite(): boolean {\n return this.keys().every((k) => Number.isFinite(this.get(k)));\n }\n toJSON(): Readonly<Record<K, number>> {\n return { ...this.c };\n }\n toString(): string {\n return `NDVector(${JSON.stringify(this.c)})`;\n }\n}\n\ntype NDOpNames =\n | \"add\" | \"subtract\" | \"multiply\" | \"min\" | \"max\" | \"mergePreferNonZero\" | \"scale\" | \"clamp\" | \"dot\" | \"length\" | \"norm1\" | \"normInf\"\n | \"equals\" | \"pick\" | \"withKeys\" | \"get\" | \"set\";\n\n/** The ops of `NDVectorDomain`. No op lifts numbers. */\nexport type NDVectorOps = OpTable<NDVector, NDOpNames>;\n\n/** The ops of `LiftedNDVectorDomain`. */\nexport type LiftedNDVectorOps = OpTable<NDVector, NDOpNames, \"add\" | \"subtract\" | \"multiply\" | \"dot\">;\n\nconst ndOps = {\n add: { laws: [\"commutative\", \"associative\"], identity: (): NDVector => NDVector.zero(), params: [\"domain\"] },\n subtract: { params: [\"domain\"] },\n multiply: { laws: [\"commutative\", \"associative\"], params: [\"domain\"] },\n min: { laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"] },\n max: { laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"domain\"] },\n mergePreferNonZero: { laws: [\"associative\", \"idempotent\"], params: [\"domain\"] },\n scale: { params: [\"number\"] },\n clamp: { params: [\"number\", \"number\"] },\n dot: { laws: [\"commutative\"], params: [\"domain\"] },\n length: {},\n norm1: {},\n normInf: {},\n equals: { laws: [\"commutative\"], params: [\"domain\"] },\n pick: {},\n withKeys: {},\n get: { params: [\"string\"] },\n set: { params: [\"string\", \"number\"] },\n} as const satisfies NDVectorOps;\n\nconst isNDVector = (u: unknown): u is NDVector => u instanceof NDVector;\n\n/** The domain of named-component vectors. A number argument is an error here: use `LiftedNDVectorDomain` to lift. */\nexport const NDVectorDomain: Domain<\"NDVector\", NDVector, NDVectorOps> = defineDomain<\"NDVector\", NDVector, NDVectorOps>({\n name: \"NDVector\",\n is: isNDVector,\n valid: (v: NDVector): boolean => v.isFinite(),\n show: (v: NDVector): string => v.toString(),\n encode: (v: NDVector): unknown => v.toJSON(),\n decode: (u: unknown): NDVector => new NDVector(u as Readonly<Record<string, number>>),\n ops: ndOps,\n});\n\n/**\n * The domain of named-component vectors with scalar lifting. A number argument of `add`, `subtract`,\n * `multiply` or `dot` becomes the vector `{ scalar: n }`. This domain is independent of `NDVectorDomain`:\n * the two can be in one program, and neither changes the other.\n */\nexport const LiftedNDVectorDomain: Domain<\"NDVector(lifted)\", NDVector, LiftedNDVectorOps> = defineDomain<\"NDVector(lifted)\", NDVector, LiftedNDVectorOps>({\n name: \"NDVector(lifted)\",\n is: isNDVector,\n fromScalar: (n: number): NDVector => new NDVector({ scalar: n }),\n valid: (v: NDVector): boolean => v.isFinite(),\n show: (v: NDVector): string => v.toString(),\n ops: {\n ...ndOps,\n add: { ...ndOps.add, liftScalar: true },\n subtract: { ...ndOps.subtract, liftScalar: true },\n multiply: { ...ndOps.multiply, liftScalar: true },\n dot: { ...ndOps.dot, liftScalar: true },\n },\n});\n\n/** A plain record whose values are finite numbers. */\nexport type NumRecord = Readonly<Record<string, number>>;\n\n/** The ops of `NumRecordDomain`. */\nexport type NumRecordOps = {\n readonly toNDVector: FnOp<NumRecord, (r: NumRecord) => NDVector>;\n};\n\nconst isNumRecord = (u: unknown): u is NumRecord => {\n if (typeof u !== \"object\" || u === null || Array.isArray(u)) return false;\n const proto: unknown = Object.getPrototypeOf(u);\n // Number.isFinite gives false for each value that is not a number.\n return (proto === Object.prototype || proto === null) && Object.values(u).every((v) => Number.isFinite(v));\n};\n\n/** The domain of plain number records. Its op `toNDVector` builds a vector from fields, for example from `rec()`. */\nexport const NumRecordDomain: Domain<\"NumRecord\", NumRecord, NumRecordOps> = defineDomain<\"NumRecord\", NumRecord, NumRecordOps>({\n name: \"NumRecord\",\n is: isNumRecord,\n ops: {\n toNDVector: { fn: (r: NumRecord): NDVector => new NDVector(r) },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\n\nconst MS_PER_DAY = 86_400_000;\n\n/** The largest distance from 1970-01-01 in days. The `Date` of JavaScript has the same range. */\nexport const MAX_DAYS = 100_000_000;\n\nconst ISO = /^([+-]?\\d{4,6})-(\\d{2})-(\\d{2})$/;\n\n/** This function gives the `Date` of JavaScript at 00:00 UTC of a day. */\nconst utc = (days: number): Date => new Date(days * MS_PER_DAY);\n\n/**\n * An immutable day of the calendar, without a time and without a time zone. It keeps the number of days since\n * 1970-01-01, so the arithmetic of days is the arithmetic of numbers. The calendar is the Gregorian calendar, also\n * before 1582.\n */\nexport class LocalDate {\n /** The number of days since 1970-01-01. */\n readonly days: number;\n\n constructor(days: number) {\n this.days = days;\n }\n\n /**\n * This function makes a date from a year, a month from 1 to 12, and a day. A month or a day outside its range rolls\n * over, like the function `DATE` of a spreadsheet. Thus month 13 is January of the next year, and day 0 is the last\n * day of the month before. A number that is not whole gives a date that is not valid.\n */\n static of(year: number, month: number, day: number): LocalDate {\n if (![year, month, day].every(Number.isSafeInteger)) return new LocalDate(Number.NaN);\n // setUTCFullYear does not change the years 0 to 99 into 1900 to 1999, but Date.UTC does.\n const d = new Date(0);\n d.setUTCFullYear(year, month - 1, day);\n return new LocalDate(Math.round(d.getTime() / MS_PER_DAY));\n }\n\n /** This function reads a date in the form `YYYY-MM-DD`. A day that does not exist, for example `2026-02-30`, gives `undefined`. */\n static parse(text: string): LocalDate | undefined {\n const m = ISO.exec(text.trim());\n if (m === null) return undefined;\n const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];\n const date = LocalDate.of(y, mo, d);\n // A month or a day outside its range rolls over into another month, so the month tells if the day exists.\n return date.month() === mo ? date : undefined;\n }\n\n /** The year. */\n year(): number {\n return utc(this.days).getUTCFullYear();\n }\n /** The month, from 1 to 12. */\n month(): number {\n return utc(this.days).getUTCMonth() + 1;\n }\n /** The day of the month, from 1 to 31. */\n day(): number {\n return utc(this.days).getUTCDate();\n }\n /** The day of the week, from 1 (Sunday) to 7 (Saturday), like `WEEKDAY` of a spreadsheet. */\n weekday(): number {\n return utc(this.days).getUTCDay() + 1;\n }\n /** The date `n` days later. A negative `n` goes back. */\n add(n: number): LocalDate {\n return new LocalDate(this.days + n);\n }\n /** The number of days from the date `x` to this date, or the date `x` days before this date. */\n subtract(x: LocalDate | number): LocalDate | number {\n return x instanceof LocalDate ? this.days - x.days : new LocalDate(this.days - x);\n }\n /**\n * The same day `n` months later, like `EDATE` of a spreadsheet. When that month is shorter, the result is its last\n * day: one month after 31 January is the last day of February.\n */\n addMonths(n: number): LocalDate {\n // LocalDate.of gives a date that is not valid for a number of months that is not whole.\n const first = LocalDate.of(this.year(), this.month() + n, 1);\n const last = LocalDate.of(first.year(), first.month() + 1, 0);\n return new LocalDate(Math.min(first.days + this.day() - 1, last.days));\n }\n /** The last day of the month `n` months later, like `EOMONTH` of a spreadsheet. */\n endOfMonth(n: number): LocalDate {\n return LocalDate.of(this.year(), this.month() + n + 1, 0);\n }\n gt(o: LocalDate): boolean {\n return this.days > o.days;\n }\n gte(o: LocalDate): boolean {\n return this.days >= o.days;\n }\n lt(o: LocalDate): boolean {\n return this.days < o.days;\n }\n lte(o: LocalDate): boolean {\n return this.days <= o.days;\n }\n eq(o: LocalDate): boolean {\n return this.days === o.days;\n }\n /** The form `YYYY-MM-DD`. A year before 0 or after 9999 has a sign and six digits, as in ISO 8601. */\n toString(): string {\n const y = this.year();\n // Stryker disable next-line EqualityOperator: the year 0 takes the first branch, so y < 0 and y <= 0 are the same in the second\n const year = y >= 0 && y <= 9999 ? String(y).padStart(4, \"0\") : `${y < 0 ? \"-\" : \"+\"}${String(Math.abs(y)).padStart(6, \"0\")}`;\n return `${year}-${String(this.month()).padStart(2, \"0\")}-${String(this.day()).padStart(2, \"0\")}`;\n }\n}\n\n/** The ops of `DateDomain`. */\nexport type DateOps = OpTable<LocalDate, \"add\" | \"subtract\" | \"addMonths\" | \"endOfMonth\" | \"year\" | \"month\" | \"day\" | \"weekday\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"eq\">;\n\n/**\n * The domain of dates. `add` takes a count of days. `subtract` takes a date, for the days between the two dates, or a\n * count of days. A valid date is a whole count of days, within `MAX_DAYS` of 1970-01-01.\n */\nexport const DateDomain: Domain<\"Date\", LocalDate, DateOps> = defineDomain<\"Date\", LocalDate, DateOps>({\n name: \"Date\",\n is: (u: unknown): u is LocalDate => u instanceof LocalDate,\n valid: (d: LocalDate): boolean => Number.isSafeInteger(d.days) && Math.abs(d.days) <= MAX_DAYS,\n show: (d: LocalDate): string => d.toString(),\n encode: (d: LocalDate): string => d.toString(),\n decode: (u: unknown): LocalDate => (typeof u === \"string\" ? LocalDate.parse(u) : undefined) ?? new LocalDate(Number.NaN),\n ops: {\n add: { params: [\"number\"] },\n subtract: { params: [\"any\"] },\n addMonths: { params: [\"number\"] },\n endOfMonth: { params: [\"number\"] },\n year: {},\n month: {},\n day: {},\n weekday: {},\n gt: { params: [\"domain\"] },\n gte: { params: [\"domain\"] },\n lt: { params: [\"domain\"] },\n lte: { params: [\"domain\"] },\n eq: { laws: [\"commutative\"], params: [\"domain\"] },\n },\n});\n","import { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\nimport { LocalDate } from \"./date.ts\";\nimport { Vec2 } from \"./vec2.ts\";\nimport type { XY } from \"./xy.ts\";\n\ntype NumFn1 = (a: number) => number;\ntype NumFn2 = (a: number, b: number) => number;\ntype NumFn3 = (a: number, b: number, c: number) => number;\ntype NumTest = (a: number, b: number) => boolean;\n\n/** The ops of `NumDomain`. */\nexport type NumOps = {\n readonly add: FnOp<number, NumFn2>;\n readonly subtract: FnOp<number, NumFn2>;\n readonly multiply: FnOp<number, NumFn2>;\n readonly divide: FnOp<number, NumFn2>;\n readonly mod: FnOp<number, NumFn2>;\n readonly pow: FnOp<number, NumFn2>;\n readonly min: FnOp<number, NumFn2>;\n readonly max: FnOp<number, NumFn2>;\n readonly clamp: FnOp<number, NumFn3>;\n readonly abs: FnOp<number, NumFn1>;\n readonly negate: FnOp<number, NumFn1>;\n readonly sqrt: FnOp<number, NumFn1>;\n readonly ln: FnOp<number, NumFn1>;\n readonly exp: FnOp<number, NumFn1>;\n readonly log10: FnOp<number, NumFn1>;\n readonly sin: FnOp<number, NumFn1>;\n readonly cos: FnOp<number, NumFn1>;\n readonly asin: FnOp<number, NumFn1>;\n readonly hypot: FnOp<number, NumFn2>;\n readonly date: FnOp<number, (year: number, month: number, day: number) => LocalDate>;\n readonly vec2: FnOp<number, (x: number, y: number) => Vec2>;\n readonly xy: FnOp<number, (x: number, y: number) => XY>;\n readonly floor: FnOp<number, NumFn1>;\n readonly ceil: FnOp<number, NumFn1>;\n readonly round: FnOp<number, NumFn1>;\n readonly gt: FnOp<number, NumTest>;\n readonly gte: FnOp<number, NumTest>;\n readonly lt: FnOp<number, NumTest>;\n readonly lte: FnOp<number, NumTest>;\n readonly eq: FnOp<number, NumTest>;\n};\n\n/** The domain of numbers. A result that is not a finite number is the error `#NUM!`. */\nexport const NumDomain: Domain<\"Num\", number, NumOps> = defineDomain<\"Num\", number, NumOps>({\n name: \"Num\",\n is: (u: unknown): u is number => typeof u === \"number\",\n primitive: \"number\",\n valid: (n: number): boolean => Number.isFinite(n),\n show: (n: number): string => String(n),\n ops: {\n add: { fn: (a: number, b: number): number => a + b, laws: [\"commutative\", \"associative\"], identity: (): number => 0, params: [\"number\"], returns: \"number\" },\n subtract: { fn: (a: number, b: number): number => a - b, params: [\"number\"], returns: \"number\" },\n multiply: { fn: (a: number, b: number): number => a * b, laws: [\"commutative\", \"associative\"], identity: (): number => 1, params: [\"number\"], returns: \"number\" },\n divide: { fn: (a: number, b: number): number => a / b, params: [\"number\"], returns: \"number\" },\n mod: { fn: (a: number, b: number): number => a % b, params: [\"number\"], returns: \"number\" },\n pow: { fn: (a: number, b: number): number => a ** b, params: [\"number\"], returns: \"number\" },\n min: { fn: (a: number, b: number): number => Math.min(a, b), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"number\"], returns: \"number\" },\n max: { fn: (a: number, b: number): number => Math.max(a, b), laws: [\"commutative\", \"associative\", \"idempotent\"], params: [\"number\"], returns: \"number\" },\n clamp: { fn: (a: number, lo: number, hi: number): number => Math.min(hi, Math.max(lo, a)), params: [\"number\", \"number\"], returns: \"number\" },\n abs: { fn: (a: number): number => Math.abs(a), returns: \"number\" },\n negate: { fn: (a: number): number => -a, returns: \"number\" },\n sqrt: { fn: (a: number): number => Math.sqrt(a), returns: \"number\" },\n ln: { fn: (a: number): number => Math.log(a), returns: \"number\" },\n exp: { fn: (a: number): number => Math.exp(a), returns: \"number\" },\n log10: { fn: (a: number): number => Math.log10(a), returns: \"number\" },\n // The angles of sin, cos and asin are in radians.\n sin: { fn: (a: number): number => Math.sin(a), returns: \"number\" },\n cos: { fn: (a: number): number => Math.cos(a), returns: \"number\" },\n asin: { fn: (a: number): number => Math.asin(a), returns: \"number\" },\n hypot: { fn: (a: number, b: number): number => Math.hypot(a, b), laws: [\"commutative\"], params: [\"number\"], returns: \"number\" },\n // The year is the receiver: date(year, month, day). The result is a LocalDate, so a chain continues in DateDomain.\n date: { fn: (year: number, month: number, day: number): LocalDate => LocalDate.of(year, month, day), params: [\"number\", \"number\"] },\n // The x component is the receiver: vec2(x, y). The result is a Vec2, so a chain continues in Vec2Domain.\n vec2: { fn: (x: number, y: number): Vec2 => new Vec2(x, y), params: [\"number\"] },\n // The same as plain data, for a standalone module: xy(x, y). The result is a value of XYDomain.\n xy: { fn: (x: number, y: number): XY => ({ x, y }), params: [\"number\"], returns: \"domain:XY\" },\n floor: { fn: (a: number): number => Math.floor(a), returns: \"number\" },\n ceil: { fn: (a: number): number => Math.ceil(a), returns: \"number\" },\n round: { fn: (a: number): number => Math.round(a), returns: \"number\" },\n gt: { fn: (a: number, b: number): boolean => a > b, params: [\"number\"], returns: \"boolean\" },\n gte: { fn: (a: number, b: number): boolean => a >= b, params: [\"number\"], returns: \"boolean\" },\n lt: { fn: (a: number, b: number): boolean => a < b, params: [\"number\"], returns: \"boolean\" },\n lte: { fn: (a: number, b: number): boolean => a <= b, params: [\"number\"], returns: \"boolean\" },\n eq: { fn: (a: number, b: number): boolean => a === b, laws: [\"commutative\"], params: [\"number\"], returns: \"boolean\" },\n },\n});\n\ntype BoolFn1 = (a: boolean) => boolean;\ntype BoolFn2 = (a: boolean, b: boolean) => boolean;\n\n/** The ops of `BoolDomain`. */\nexport type BoolOps = {\n readonly and: FnOp<boolean, BoolFn2>;\n readonly or: FnOp<boolean, BoolFn2>;\n readonly xor: FnOp<boolean, BoolFn2>;\n readonly not: FnOp<boolean, BoolFn1>;\n readonly eq: FnOp<boolean, BoolFn2>;\n};\n\n/** The domain of booleans. For lazy logic, use the special forms `and`, `or` and `if` of the IR. */\nexport const BoolDomain: Domain<\"Bool\", boolean, BoolOps> = defineDomain<\"Bool\", boolean, BoolOps>({\n name: \"Bool\",\n is: (u: unknown): u is boolean => typeof u === \"boolean\",\n primitive: \"boolean\",\n show: (b: boolean): string => String(b),\n ops: {\n and: { fn: (a: boolean, b: boolean): boolean => a && b, laws: [\"commutative\", \"associative\", \"idempotent\"], identity: (): boolean => true, params: [\"boolean\"], returns: \"boolean\" },\n or: { fn: (a: boolean, b: boolean): boolean => a || b, laws: [\"commutative\", \"associative\", \"idempotent\"], identity: (): boolean => false, params: [\"boolean\"], returns: \"boolean\" },\n xor: { fn: (a: boolean, b: boolean): boolean => a !== b, laws: [\"commutative\", \"associative\"], identity: (): boolean => false, params: [\"boolean\"], returns: \"boolean\" },\n not: { fn: (a: boolean): boolean => !a, returns: \"boolean\" },\n eq: { fn: (a: boolean, b: boolean): boolean => a === b, laws: [\"commutative\"], params: [\"boolean\"], returns: \"boolean\" },\n },\n});\n","/**\n * The domain of texts. The op `concat` joins a text and a value of any kind. It is the operator `&` of a\n * spreadsheet, and of the formula language of the sheet app.\n */\nimport { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\n\ntype TextFn1 = (a: string) => string;\n\n/** The ops of `TextDomain`. */\nexport type TextOps = {\n readonly concat: FnOp<string, (a: string, b: unknown) => string>;\n readonly length: FnOp<string, (a: string) => number>;\n readonly upper: FnOp<string, TextFn1>;\n readonly lower: FnOp<string, TextFn1>;\n readonly trim: FnOp<string, TextFn1>;\n readonly contains: FnOp<string, (a: string, b: string) => boolean>;\n readonly eq: FnOp<string, (a: string, b: string) => boolean>;\n};\n\n/**\n * This function gives the text of a value for `concat`. A text stays. A plain record gives its JSON text. Another\n * value, for example a number or a `Vec2`, gives its own text.\n */\nconst textOf = (u: unknown): string => (typeof u === \"object\" && u !== null && Object.getPrototypeOf(u) === Object.prototype ? JSON.stringify(u) : String(u));\n\n/** The domain of texts. */\nexport const TextDomain: Domain<\"Text\", string, TextOps> = defineDomain<\"Text\", string, TextOps>({\n name: \"Text\",\n is: (u: unknown): u is string => typeof u === \"string\",\n primitive: \"string\",\n show: (s: string): string => JSON.stringify(s),\n ops: {\n concat: { fn: (a: string, b: unknown): string => a + textOf(b), params: [\"any\"], returns: \"string\" },\n // The length counts UTF-16 code units, like the function LEN of a spreadsheet.\n length: { fn: (a: string): number => a.length, returns: \"number\" },\n upper: { fn: (a: string): string => a.toUpperCase(), returns: \"string\" },\n lower: { fn: (a: string): string => a.toLowerCase(), returns: \"string\" },\n trim: { fn: (a: string): string => a.trim(), returns: \"string\" },\n contains: { fn: (a: string, b: string): boolean => a.includes(b), params: [\"string\"], returns: \"boolean\" },\n eq: { fn: (a: string, b: string): boolean => a === b, laws: [\"commutative\"], params: [\"string\"], returns: \"boolean\" },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\n\n/** The linear value of an sRGB channel from 0 to 255, with the sRGB transfer function of WCAG 2.1. */\nfunction linear(channel: number): number {\n const s = Math.min(1, Math.max(0, channel / 255));\n // For integer channels, the sRGB threshold 0.04045 and the WCAG threshold 0.03928 give the same result.\n return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n}\n\n/**\n * An immutable RGBA color. The channels have no fixed range: use `clamp` to limit them. `add` adds the color\n * channels and keeps the larger alpha, so `add` is commutative and associative.\n */\nexport class Color {\n readonly r: number;\n readonly g: number;\n readonly b: number;\n readonly a: number;\n\n constructor(r: number, g: number, b: number, a = 1) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n }\n\n /** This function makes a gray color with the value `n` in each channel. */\n static gray(n: number): Color {\n return new Color(n, n, n, 1);\n }\n /** The black color with alpha 0: the identity of `add`. */\n static readonly none: Color = new Color(0, 0, 0, 0);\n\n /** The channel sum. The alpha is the larger alpha. */\n add(o: Color): Color {\n return new Color(this.r + o.r, this.g + o.g, this.b + o.b, Math.max(this.a, o.a));\n }\n /** Each color channel times `factor`. The alpha does not change. */\n multiply(factor: number): Color {\n return new Color(this.r * factor, this.g * factor, this.b * factor, this.a);\n }\n /** Each color channel in the range from `lo` to `hi`. */\n clamp(lo = 0, hi = 255): Color {\n const c = (x: number): number => Math.min(hi, Math.max(lo, x));\n return new Color(c(this.r), c(this.g), c(this.b), this.a);\n }\n /** The linear mix from this color to `o`. */\n mix(o: Color, t: number): Color {\n const m = (x: number, y: number): number => x + (y - x) * t;\n return new Color(m(this.r, o.r), m(this.g, o.g), m(this.b, o.b), m(this.a, o.a));\n }\n /** The relative luminance (Rec. 709 weights) of the color channels. */\n luminance(): number {\n return 0.2126 * this.r + 0.7152 * this.g + 0.0722 * this.b;\n }\n /**\n * The relative luminance of WCAG 2.1, from 0 (black) to 1 (white). Each channel from 0 to 255 becomes a linear\n * value with the sRGB transfer function. A channel outside the range counts as the nearest end of the range.\n */\n relativeLuminance(): number {\n return 0.2126 * linear(this.r) + 0.7152 * linear(this.g) + 0.0722 * linear(this.b);\n }\n /** The contrast ratio of WCAG 2.1 between this color and `o`: 1 for equal luminance, 21 for black and white. */\n contrast(o: Color): number {\n const a = this.relativeLuminance();\n const b = o.relativeLuminance();\n return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);\n }\n equals(o: Color): boolean {\n return this.r === o.r && this.g === o.g && this.b === o.b && this.a === o.a;\n }\n toArray(): readonly [number, number, number, number] {\n return [this.r, this.g, this.b, this.a];\n }\n toString(): string {\n return `rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`;\n }\n}\n\n/** The ops of `ColorDomain`. */\nexport type ColorOps = OpTable<Color, \"add\" | \"multiply\" | \"clamp\" | \"mix\" | \"luminance\" | \"relativeLuminance\" | \"contrast\" | \"equals\">;\n\n/** The domain of colors. */\nexport const ColorDomain: Domain<\"Color\", Color, ColorOps> = defineDomain<\"Color\", Color, ColorOps>({\n name: \"Color\",\n is: (u: unknown): u is Color => u instanceof Color,\n fromScalar: (n: number): Color => Color.gray(n),\n valid: (c: Color): boolean => c.toArray().every((x) => Number.isFinite(x)),\n show: (c: Color): string => c.toString(),\n encode: (c: Color): readonly number[] => c.toArray(),\n decode: (u: unknown): Color => {\n const [r, g, b, a] = (Array.isArray(u) ? u : []) as readonly number[];\n return new Color(r ?? Number.NaN, g ?? Number.NaN, b ?? Number.NaN, a ?? 1);\n },\n ops: {\n add: { laws: [\"commutative\", \"associative\"], identity: (): Color => Color.none, params: [\"domain\"] },\n multiply: { params: [\"number\"] },\n clamp: { params: [\"number\", \"number\"] },\n mix: { params: [\"domain\", \"number\"] },\n luminance: {},\n relativeLuminance: {},\n contrast: { laws: [\"commutative\"], params: [\"domain\"] },\n equals: { laws: [\"commutative\"], params: [\"domain\"] },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\nimport { Vec2 } from \"./vec2.ts\";\n\n/** An immutable angle in radians. */\nexport class Angle {\n readonly radians: number;\n\n constructor(radians: number) {\n this.radians = radians;\n }\n\n /** This function makes an angle from degrees. */\n static fromDegrees(deg: number): Angle {\n return new Angle((deg * Math.PI) / 180);\n }\n /** The zero angle: the identity of `add`. */\n static readonly zero: Angle = new Angle(0);\n\n add(o: Angle): Angle {\n return new Angle(this.radians + o.radians);\n }\n subtract(o: Angle): Angle {\n return new Angle(this.radians - o.radians);\n }\n scale(k: number): Angle {\n return new Angle(this.radians * k);\n }\n /** The same angle in the range from -π (included) to π (not included). */\n normalize(): Angle {\n const twoPi = Math.PI * 2;\n // Stryker disable next-line ArithmeticOperator: x + π and x - π differ by 2π, so the result after mod 2π is the same\n return new Angle((((this.radians + Math.PI) % twoPi) + twoPi) % twoPi - Math.PI);\n }\n /** The vector with this angle and the length `length`. The result is a `Vec2`, so a chain continues in that domain. */\n toVec2(length = 1): Vec2 {\n return new Vec2(Math.cos(this.radians) * length, Math.sin(this.radians) * length);\n }\n sin(): number {\n return Math.sin(this.radians);\n }\n cos(): number {\n return Math.cos(this.radians);\n }\n degrees(): number {\n return (this.radians * 180) / Math.PI;\n }\n toString(): string {\n return `${this.radians} rad`;\n }\n}\n\n/** The ops of `AngleDomain`. */\nexport type AngleOps = OpTable<Angle, \"add\" | \"subtract\" | \"scale\" | \"normalize\" | \"toVec2\" | \"sin\" | \"cos\" | \"degrees\", \"add\" | \"subtract\">;\n\n/** The domain of angles. A number argument of `add` or `subtract` lifts to an angle in radians. */\nexport const AngleDomain: Domain<\"Angle\", Angle, AngleOps> = defineDomain<\"Angle\", Angle, AngleOps>({\n name: \"Angle\",\n is: (u: unknown): u is Angle => u instanceof Angle,\n fromScalar: (n: number): Angle => new Angle(n),\n valid: (a: Angle): boolean => Number.isFinite(a.radians),\n show: (a: Angle): string => a.toString(),\n encode: (a: Angle): number => a.radians,\n decode: (u: unknown): Angle => new Angle(typeof u === \"number\" ? u : Number.NaN),\n ops: {\n add: { laws: [\"commutative\", \"associative\"], identity: (): Angle => Angle.zero, liftScalar: true, params: [\"domain\"] },\n subtract: { liftScalar: true, params: [\"domain\"] },\n scale: { params: [\"number\"] },\n normalize: {},\n toVec2: { params: [\"number\"] },\n sin: {},\n cos: {},\n degrees: {},\n },\n});\n","import { defineDomain, type Domain, type FnOp } from \"@mark1russell7/vex\";\n\n/**\n * A JSON value that `JsonDomain` accepts: a text, a finite number, a boolean, an array or a plain object. The items of\n * an array and the fields of an object can be `null`.\n */\nexport type JsonValue = string | number | boolean | readonly unknown[] | { readonly [key: string]: unknown };\n\n/** The kind of a JSON value. */\nexport type JsonKind = \"boolean\" | \"number\" | \"string\" | \"array\" | \"object\";\n\n/** The kind of an item of an array or of a field of an object: the kind of a JSON value, or `\"null\"`. */\nexport type JsonItemKind = JsonKind | \"null\";\n\n/** The ops of `JsonDomain`. */\nexport type JsonOps = {\n readonly kind: FnOp<JsonValue, (v: JsonValue) => JsonKind>;\n readonly kinds: FnOp<JsonValue, (c: JsonValue) => readonly JsonItemKind[]>;\n readonly fields: FnOp<JsonValue, (o: JsonValue) => readonly string[]>;\n readonly field: FnOp<JsonValue, (o: JsonValue, k: unknown) => unknown>;\n};\n\n/**\n * The domain of JSON values, for example the documents of a database. Each op is a function of plain data, so a\n * standalone module can copy the domain. Put `JsonDomain` last in the list of domains. Then `add`, `eq` and the other\n * ops of `NumDomain`, `TextDomain` and `BoolDomain` come first. The names `keys`, `get` and `values` are list ops. A\n * domain op comes before a list op on an array, so the domain does not use these names.\n */\nexport const JsonDomain: Domain<\"Json\", JsonValue, JsonOps> = defineDomain<\"Json\", JsonValue, JsonOps>({\n name: \"Json\",\n // A plain object has the prototype Object.prototype or null. Thus a Vec2, a LocalDate or a Map is not a JSON value.\n // An object with the kind \"vex.list\" and an array of items is a list of Vex. The test reads no name outside itself,\n // so a module can copy it.\n is: (u: unknown): u is JsonValue =>\n typeof u === \"string\" ||\n typeof u === \"boolean\" ||\n Number.isFinite(u) ||\n Array.isArray(u) ||\n (typeof u === \"object\" &&\n u !== null &&\n [Object.prototype, null].includes(Object.getPrototypeOf(u) as object | null) &&\n !((u as { readonly kind?: unknown }).kind === \"vex.list\" && Array.isArray((u as { readonly items?: unknown }).items))),\n samples: (): readonly JsonValue[] => [{ a: 1, b: [true, null], c: { d: \"x\" } }, [1, \"x\", null, [2]], \"x\", 2, false],\n ops: {\n // Each op reads no name outside itself, so a module can copy its text.\n kind: { fn: (v: JsonValue): JsonKind => (Array.isArray(v) ? \"array\" : (typeof v as JsonKind)), params: [], returns: \"string\" },\n kinds: {\n fn: (c: JsonValue): readonly JsonItemKind[] => {\n if (typeof c !== \"object\") throw new Error(`\"kinds\" needs an array or an object, not a ${typeof c}`);\n // Array.from gives undefined for a hole, so a hole has the kind \"null\".\n return Array.from(Array.isArray(c) ? (c as readonly unknown[]) : Object.values(c), (x, i): JsonItemKind => {\n if (x === null || x === undefined) return \"null\";\n if (Array.isArray(x)) return \"array\";\n if (typeof x === \"string\" || typeof x === \"boolean\" || Number.isFinite(x) || [Object.prototype, null].includes(Object.getPrototypeOf(x) as object | null)) return typeof x as JsonKind;\n throw new Error(`\"kinds\" found a value that is not JSON at the position ${i}`);\n });\n },\n params: [],\n },\n fields: {\n fn: (o: JsonValue): readonly string[] => {\n if (typeof o !== \"object\" || Array.isArray(o)) throw new Error(`\"fields\" needs an object, not ${Array.isArray(o) ? \"an array\" : `a ${typeof o}`}`);\n return Object.keys(o);\n },\n params: [],\n },\n field: {\n fn: (o: JsonValue, k: unknown): unknown => {\n if (typeof o !== \"object\" || Array.isArray(o)) throw new Error(`\"field\" needs an object, not ${Array.isArray(o) ? \"an array\" : `a ${typeof o}`}`);\n if (typeof k !== \"string\") throw new Error(`\"field\" needs a text key, not a ${typeof k}`);\n if (!Object.hasOwn(o, k)) throw new Error(`the object has no field \"${k}\"`);\n const value = (o as Readonly<Record<string, unknown>>)[k];\n if (value === null || value === undefined) throw new Error(`the field \"${k}\" is null`);\n return value;\n },\n params: [\"any\"],\n returns: \"any\",\n },\n },\n});\n","import { defineDomain, type Domain, type OpTable } from \"@mark1russell7/vex\";\n\n/** A wrapper around a function. Its op `invoke` calls the function. It shows how a domain can hold behavior. */\nexport class Fn {\n readonly fn: (...args: never[]) => unknown;\n\n constructor(fn: (...args: never[]) => unknown) {\n this.fn = fn;\n }\n invoke(...args: readonly unknown[]): unknown {\n return (this.fn as (...a: readonly unknown[]) => unknown)(...args);\n }\n}\n\n/** The ops of `FnDomain`. */\nexport type FnOps = OpTable<Fn, \"invoke\">;\n\n/** The domain of function wrappers. */\nexport const FnDomain: Domain<\"Fn\", Fn, FnOps> = defineDomain<\"Fn\", Fn, FnOps>({\n name: \"Fn\",\n is: (u: unknown): u is Fn => u instanceof Fn,\n ops: { invoke: {} },\n});\n\n/**\n * A value that is there (`top`) or not there (`bottom`). It shows a domain whose ops take functions. A Vex\n * program can also hold this state in its own errors, so most programs do not need this domain.\n */\nexport class Maybe<T> {\n readonly #has: boolean;\n readonly #value: T | undefined;\n\n private constructor(has: boolean, value: T | undefined) {\n this.#has = has;\n this.#value = value;\n }\n static top<T>(value: T): Maybe<T> {\n return new Maybe<T>(true, value);\n }\n static bottom<T = never>(): Maybe<T> {\n return new Maybe<T>(false, undefined);\n }\n isTop(): boolean {\n return this.#has;\n }\n isBottom(): boolean {\n return !this.#has;\n }\n map<U>(f: (value: T) => U): Maybe<U> {\n return this.#has ? Maybe.top(f(this.#value as T)) : Maybe.bottom<U>();\n }\n chain<U>(f: (value: T) => Maybe<U>): Maybe<U> {\n return this.#has ? f(this.#value as T) : Maybe.bottom<U>();\n }\n valueOr<U>(fallback: U): T | U {\n return this.#has ? (this.#value as T) : fallback;\n }\n}\n\n/** The ops of `MaybeDomain`. */\nexport type MaybeOps = OpTable<Maybe<unknown>, \"isTop\" | \"isBottom\" | \"map\" | \"chain\" | \"valueOr\">;\n\n/** The domain of `Maybe` values. */\nexport const MaybeDomain: Domain<\"Maybe\", Maybe<unknown>, MaybeOps> = defineDomain<\"Maybe\", Maybe<unknown>, MaybeOps>({\n name: \"Maybe\",\n is: (u: unknown): u is Maybe<unknown> => u instanceof Maybe,\n ops: { isTop: {}, isBottom: {}, map: {}, chain: {}, valueOr: {} },\n});\n"],"mappings":";;;;;;AAMA,IAAa,OAAb,MAAa,KAAK;CAChB;CACA;CAEA,YAAY,GAAW,GAAW;EAChC,KAAK,IAAI;EACT,KAAK,IAAI;CACX;;CAGA,OAAO,GAAG,GAAW,GAAiB;EACpC,OAAO,IAAI,KAAK,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CACtD,KAAK;EAAE,OAAO,CAAC;EAAG,UAAU,CAAC;EAAG,KAAK,CAAC;EAAG,OAAO,CAAC;EAAG,SAAS,CAAC;CAAE;AAClE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/vex-domains",
4
- "version": "0.13.4",
4
+ "version": "0.14.0",
5
5
  "description": "Vex domains: 2D vectors, named-component vectors, colors, angles, numbers and booleans.",
6
6
  "keywords": [
7
7
  "vex",
@@ -52,7 +52,7 @@
52
52
  "vitest": "^5.0.3"
53
53
  },
54
54
  "dependencies": {
55
- "@mark1russell7/vex": "0.13.4"
55
+ "@mark1russell7/vex": "0.14.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Domains for Vex: 2D vectors as objects and as plain data, named-component vectors, colors, angles, numbers, booleans, texts and dates, and two
3
- * example domains (function wrappers and `Maybe`).
2
+ * Domains for Vex: 2D vectors as objects and as plain data, named-component vectors, colors, angles, numbers, booleans,
3
+ * texts, dates and JSON values. Two example domains are function wrappers and `Maybe`.
4
4
  */
5
5
  export * from "./vec2.ts";
6
6
  export * from "./xy.ts";
@@ -10,4 +10,5 @@ export * from "./text.ts";
10
10
  export * from "./color.ts";
11
11
  export * from "./angle.ts";
12
12
  export * from "./date.ts";
13
+ export * from "./json.ts";
13
14
  export * from "./wrappers.ts";
package/src/json.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { defineDomain, type Domain, type FnOp } from "@mark1russell7/vex";
2
+
3
+ /**
4
+ * A JSON value that `JsonDomain` accepts: a text, a finite number, a boolean, an array or a plain object. The items of
5
+ * an array and the fields of an object can be `null`.
6
+ */
7
+ export type JsonValue = string | number | boolean | readonly unknown[] | { readonly [key: string]: unknown };
8
+
9
+ /** The kind of a JSON value. */
10
+ export type JsonKind = "boolean" | "number" | "string" | "array" | "object";
11
+
12
+ /** The kind of an item of an array or of a field of an object: the kind of a JSON value, or `"null"`. */
13
+ export type JsonItemKind = JsonKind | "null";
14
+
15
+ /** The ops of `JsonDomain`. */
16
+ export type JsonOps = {
17
+ readonly kind: FnOp<JsonValue, (v: JsonValue) => JsonKind>;
18
+ readonly kinds: FnOp<JsonValue, (c: JsonValue) => readonly JsonItemKind[]>;
19
+ readonly fields: FnOp<JsonValue, (o: JsonValue) => readonly string[]>;
20
+ readonly field: FnOp<JsonValue, (o: JsonValue, k: unknown) => unknown>;
21
+ };
22
+
23
+ /**
24
+ * The domain of JSON values, for example the documents of a database. Each op is a function of plain data, so a
25
+ * standalone module can copy the domain. Put `JsonDomain` last in the list of domains. Then `add`, `eq` and the other
26
+ * ops of `NumDomain`, `TextDomain` and `BoolDomain` come first. The names `keys`, `get` and `values` are list ops. A
27
+ * domain op comes before a list op on an array, so the domain does not use these names.
28
+ */
29
+ export const JsonDomain: Domain<"Json", JsonValue, JsonOps> = defineDomain<"Json", JsonValue, JsonOps>({
30
+ name: "Json",
31
+ // A plain object has the prototype Object.prototype or null. Thus a Vec2, a LocalDate or a Map is not a JSON value.
32
+ // An object with the kind "vex.list" and an array of items is a list of Vex. The test reads no name outside itself,
33
+ // so a module can copy it.
34
+ is: (u: unknown): u is JsonValue =>
35
+ typeof u === "string" ||
36
+ typeof u === "boolean" ||
37
+ Number.isFinite(u) ||
38
+ Array.isArray(u) ||
39
+ (typeof u === "object" &&
40
+ u !== null &&
41
+ [Object.prototype, null].includes(Object.getPrototypeOf(u) as object | null) &&
42
+ !((u as { readonly kind?: unknown }).kind === "vex.list" && Array.isArray((u as { readonly items?: unknown }).items))),
43
+ samples: (): readonly JsonValue[] => [{ a: 1, b: [true, null], c: { d: "x" } }, [1, "x", null, [2]], "x", 2, false],
44
+ ops: {
45
+ // Each op reads no name outside itself, so a module can copy its text.
46
+ kind: { fn: (v: JsonValue): JsonKind => (Array.isArray(v) ? "array" : (typeof v as JsonKind)), params: [], returns: "string" },
47
+ kinds: {
48
+ fn: (c: JsonValue): readonly JsonItemKind[] => {
49
+ if (typeof c !== "object") throw new Error(`"kinds" needs an array or an object, not a ${typeof c}`);
50
+ // Array.from gives undefined for a hole, so a hole has the kind "null".
51
+ return Array.from(Array.isArray(c) ? (c as readonly unknown[]) : Object.values(c), (x, i): JsonItemKind => {
52
+ if (x === null || x === undefined) return "null";
53
+ if (Array.isArray(x)) return "array";
54
+ if (typeof x === "string" || typeof x === "boolean" || Number.isFinite(x) || [Object.prototype, null].includes(Object.getPrototypeOf(x) as object | null)) return typeof x as JsonKind;
55
+ throw new Error(`"kinds" found a value that is not JSON at the position ${i}`);
56
+ });
57
+ },
58
+ params: [],
59
+ },
60
+ fields: {
61
+ fn: (o: JsonValue): readonly string[] => {
62
+ if (typeof o !== "object" || Array.isArray(o)) throw new Error(`"fields" needs an object, not ${Array.isArray(o) ? "an array" : `a ${typeof o}`}`);
63
+ return Object.keys(o);
64
+ },
65
+ params: [],
66
+ },
67
+ field: {
68
+ fn: (o: JsonValue, k: unknown): unknown => {
69
+ if (typeof o !== "object" || Array.isArray(o)) throw new Error(`"field" needs an object, not ${Array.isArray(o) ? "an array" : `a ${typeof o}`}`);
70
+ if (typeof k !== "string") throw new Error(`"field" needs a text key, not a ${typeof k}`);
71
+ if (!Object.hasOwn(o, k)) throw new Error(`the object has no field "${k}"`);
72
+ const value = (o as Readonly<Record<string, unknown>>)[k];
73
+ if (value === null || value === undefined) throw new Error(`the field "${k}" is null`);
74
+ return value;
75
+ },
76
+ params: ["any"],
77
+ returns: "any",
78
+ },
79
+ },
80
+ });