@mark1russell7/vex-domains 0.17.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -1,4 +1,172 @@
1
1
  import { app, axes, call, defineDomain, each, evaluate, fn, let_, lit, rec, space, v, vexList } from "@mark1russell7/vex";
2
+ // src/vec2-form.ts
3
+ /**
4
+ * The form of `Vec2Domain` in a standalone module (COMPILE.MODULE.FORM). A module has no import, and a copy of the class
5
+ * is another class. Thus a vector in a module is plain data, the data of `toJSON` of a `Vec2`. Each op has the arithmetic
6
+ * of the method with its name, so it has the same bits. The test accepts a `Vec2` too, so a host can give its vectors.
7
+ */
8
+ const VEC2_FORM = {
9
+ is: (u) => typeof u === "object" && u !== null && typeof u.x === "number" && typeof u.y === "number",
10
+ fromScalar: (n) => ({
11
+ x: n,
12
+ y: n
13
+ }),
14
+ samples: () => [
15
+ {
16
+ x: 0,
17
+ y: 0
18
+ },
19
+ {
20
+ x: 1.5,
21
+ y: -2
22
+ },
23
+ {
24
+ x: 3,
25
+ y: 4
26
+ }
27
+ ],
28
+ ops: {
29
+ add: {
30
+ fn: (a, b) => ({
31
+ x: a.x + b.x,
32
+ y: a.y + b.y
33
+ }),
34
+ identity: () => ({
35
+ x: 0,
36
+ y: 0
37
+ })
38
+ },
39
+ subtract: { fn: (a, b) => ({
40
+ x: a.x - b.x,
41
+ y: a.y - b.y
42
+ }) },
43
+ multiply: {
44
+ fn: (a, b) => ({
45
+ x: a.x * b.x,
46
+ y: a.y * b.y
47
+ }),
48
+ identity: () => ({
49
+ x: 1,
50
+ y: 1
51
+ })
52
+ },
53
+ divide: { fn: (a, b) => ({
54
+ x: a.x / b.x,
55
+ y: a.y / b.y
56
+ }) },
57
+ min: { fn: (a, b) => ({
58
+ x: Math.min(a.x, b.x),
59
+ y: Math.min(a.y, b.y)
60
+ }) },
61
+ max: { fn: (a, b) => ({
62
+ x: Math.max(a.x, b.x),
63
+ y: Math.max(a.y, b.y)
64
+ }) },
65
+ scale: { fn: (a, k) => ({
66
+ x: a.x * k,
67
+ y: a.y * k
68
+ }) },
69
+ negate: { fn: (a) => ({
70
+ x: -a.x,
71
+ y: -a.y
72
+ }) },
73
+ halve: { fn: (a) => ({
74
+ x: a.x * .5,
75
+ y: a.y * .5
76
+ }) },
77
+ abs: { fn: (a) => ({
78
+ x: Math.abs(a.x),
79
+ y: Math.abs(a.y)
80
+ }) },
81
+ sign: { fn: (a) => ({
82
+ x: Math.sign(a.x),
83
+ y: Math.sign(a.y)
84
+ }) },
85
+ round: { fn: (a) => ({
86
+ x: Math.round(a.x),
87
+ y: Math.round(a.y)
88
+ }) },
89
+ floor: { fn: (a) => ({
90
+ x: Math.floor(a.x),
91
+ y: Math.floor(a.y)
92
+ }) },
93
+ ceil: { fn: (a) => ({
94
+ x: Math.ceil(a.x),
95
+ y: Math.ceil(a.y)
96
+ }) },
97
+ clamp: { fn: (a, lo, hi) => ({
98
+ x: Math.min(hi, Math.max(lo, a.x)),
99
+ y: Math.min(hi, Math.max(lo, a.y))
100
+ }) },
101
+ swap: { fn: (a) => ({
102
+ x: a.y,
103
+ y: a.x
104
+ }) },
105
+ compose: { fn: (a, main, cross) => ({
106
+ x: a.x * main + a.y * cross,
107
+ y: a.y * main + a.x * cross
108
+ }) },
109
+ select: { fn: (m, a, b) => ({
110
+ x: m.x !== 0 ? a.x : b.x,
111
+ y: m.y !== 0 ? a.y : b.y
112
+ }) },
113
+ rotate: { fn: (a, radians) => {
114
+ const c = Math.cos(radians);
115
+ const s = Math.sin(radians);
116
+ return {
117
+ x: c * a.x - s * a.y,
118
+ y: s * a.x + c * a.y
119
+ };
120
+ } },
121
+ normalize: { fn: (a) => {
122
+ const len = Math.hypot(a.x, a.y);
123
+ return len === 0 ? {
124
+ x: a.x,
125
+ y: a.y
126
+ } : {
127
+ x: a.x * (1 / len),
128
+ y: a.y * (1 / len)
129
+ };
130
+ } },
131
+ minAxis: { fn: (a) => Number.isNaN(a.x) || Number.isNaN(a.y) ? {
132
+ x: NaN,
133
+ y: NaN
134
+ } : a.x <= a.y ? {
135
+ x: 1,
136
+ y: 0
137
+ } : {
138
+ x: 0,
139
+ y: 1
140
+ } },
141
+ lerp: { fn: (a, o, t) => ({
142
+ x: a.x + (o.x - a.x) * t,
143
+ y: a.y + (o.y - a.y) * t
144
+ }) },
145
+ length: { fn: (a) => Math.hypot(a.x, a.y) },
146
+ lengthSq: { fn: (a) => a.x * a.x + a.y * a.y },
147
+ distance: { fn: (a, o) => Math.hypot(a.x - o.x, a.y - o.y) },
148
+ dot: { fn: (a, o) => a.x * o.x + a.y * o.y },
149
+ along: { fn: (a, dir) => a.x * dir.x + a.y * dir.y },
150
+ across: { fn: (a, dir) => a.x * dir.y + a.y * dir.x },
151
+ cross: { fn: (a, o) => a.x * o.y - a.y * o.x },
152
+ angle: { fn: (a) => Math.atan2(a.y, a.x) },
153
+ area: { fn: (a) => a.x * a.y },
154
+ sum: { fn: (a) => a.x + a.y },
155
+ minComponent: { fn: (a) => Math.min(a.x, a.y) },
156
+ maxComponent: { fn: (a) => Math.max(a.x, a.y) },
157
+ equals: { fn: (a, o) => a.x === o.x && a.y === o.y },
158
+ anyNonPositive: { fn: (a) => a.x <= 0 || a.y <= 0 },
159
+ allPositive: { fn: (a) => a.x > 0 && a.y > 0 },
160
+ anyNegative: { fn: (a) => a.x < 0 || a.y < 0 },
161
+ allNonNegative: { fn: (a) => a.x >= 0 && a.y >= 0 },
162
+ anyZero: { fn: (a) => a.x === 0 || a.y === 0 },
163
+ allZero: { fn: (a) => a.x === 0 && a.y === 0 },
164
+ anyLessThan: { fn: (a, n) => a.x < n || a.y < n },
165
+ allLessThan: { fn: (a, n) => a.x < n && a.y < n },
166
+ anyGreaterThan: { fn: (a, n) => a.x > n || a.y > n },
167
+ allGreaterThan: { fn: (a, n) => a.x > n && a.y > n }
168
+ }
169
+ };
2
170
  // src/vec2.ts
3
171
  /**
4
172
  * An immutable 2D vector. The methods live on the prototype, so a vector costs two numbers. Division is real
@@ -57,6 +225,10 @@ var Vec2 = class Vec2 {
57
225
  abs() {
58
226
  return new Vec2(Math.abs(this.x), Math.abs(this.y));
59
227
  }
228
+ /** The component-wise sign, as `Math.sign` gives it. A component `NaN` stays `NaN`, and the domain check gives `#NUM!`. */
229
+ sign() {
230
+ return new Vec2(Math.sign(this.x), Math.sign(this.y));
231
+ }
60
232
  round() {
61
233
  return new Vec2(Math.round(this.x), Math.round(this.y));
62
234
  }
@@ -97,6 +269,14 @@ var Vec2 = class Vec2 {
97
269
  const len = this.length();
98
270
  return len === 0 ? this : this.scale(1 / len);
99
271
  }
272
+ /**
273
+ * The unit vector of the smaller component: (1, 0) if `x <= y`, else (0, 1). The comparison uses the signed values, so
274
+ * `v.abs().minAxis()` compares sizes. A tie gives (1, 0). A component `NaN` gives `NaN` components, thus `#NUM!`.
275
+ */
276
+ minAxis() {
277
+ if (Number.isNaN(this.x) || Number.isNaN(this.y)) return new Vec2(NaN, NaN);
278
+ return this.x <= this.y ? new Vec2(1, 0) : new Vec2(0, 1);
279
+ }
100
280
  /** The linear interpolation from this vector to `o`. */
101
281
  lerp(o, t) {
102
282
  return new Vec2(this.x + (o.x - this.x) * t, this.y + (o.y - this.y) * t);
@@ -189,6 +369,7 @@ var Vec2 = class Vec2 {
189
369
  /** The domain of 2D vectors. A number argument of a component-wise op lifts to a vector with that value twice. */
190
370
  const Vec2Domain = defineDomain({
191
371
  name: "Vec2",
372
+ size: "fixed",
192
373
  is: (u) => u instanceof Vec2,
193
374
  fromScalar: (n) => Vec2.scalar(n),
194
375
  valid: (v) => Number.isFinite(v.x) && Number.isFinite(v.y),
@@ -198,6 +379,10 @@ const Vec2Domain = defineDomain({
198
379
  const [x, y] = Array.isArray(u) ? u : [];
199
380
  return new Vec2(typeof x === "number" ? x : NaN, typeof y === "number" ? y : NaN);
200
381
  },
382
+ moduleForm: {
383
+ ...VEC2_FORM,
384
+ literal: (u) => u instanceof Vec2 ? u.toJSON() : void 0
385
+ },
201
386
  ops: {
202
387
  x: {
203
388
  fn: (v) => v.x,
@@ -269,6 +454,10 @@ const Vec2Domain = defineDomain({
269
454
  params: [],
270
455
  returns: "domain"
271
456
  },
457
+ sign: {
458
+ params: [],
459
+ returns: "domain"
460
+ },
272
461
  round: {
273
462
  params: [],
274
463
  returns: "domain"
@@ -306,6 +495,10 @@ const Vec2Domain = defineDomain({
306
495
  params: [],
307
496
  returns: "domain"
308
497
  },
498
+ minAxis: {
499
+ params: [],
500
+ returns: "domain"
501
+ },
309
502
  lerp: {
310
503
  params: ["domain", "number"],
311
504
  returns: "domain"
@@ -414,6 +607,8 @@ const Vec2Domain = defineDomain({
414
607
  */
415
608
  const XYDomain = defineDomain({
416
609
  name: "XY",
610
+ size: "fixed",
611
+ fields: ["x", "y"],
417
612
  is: (u) => typeof u === "object" && u !== null && [Object.prototype, null].includes(Object.getPrototypeOf(u)) && Object.keys(u).length === 2 && typeof u.x === "number" && typeof u.y === "number",
418
613
  valid: (v) => Number.isFinite(v.x) && Number.isFinite(v.y),
419
614
  show: (v) => `(${v.x}, ${v.y})`,
@@ -534,6 +729,28 @@ const XYDomain = defineDomain({
534
729
  params: [],
535
730
  returns: "domain"
536
731
  },
732
+ sign: {
733
+ fn: (a) => ({
734
+ x: Math.sign(a.x),
735
+ y: Math.sign(a.y)
736
+ }),
737
+ params: [],
738
+ returns: "domain"
739
+ },
740
+ minAxis: {
741
+ fn: (a) => Number.isNaN(a.x) || Number.isNaN(a.y) ? {
742
+ x: NaN,
743
+ y: NaN
744
+ } : a.x <= a.y ? {
745
+ x: 1,
746
+ y: 0
747
+ } : {
748
+ x: 0,
749
+ y: 1
750
+ },
751
+ params: [],
752
+ returns: "domain"
753
+ },
537
754
  floor: {
538
755
  fn: (a) => ({
539
756
  x: Math.floor(a.x),
@@ -593,6 +810,132 @@ const XYDomain = defineDomain({
593
810
  }
594
811
  }
595
812
  });
813
+ // src/insets.ts
814
+ /**
815
+ * The domain of insets: an object with the four number fields of `Insets` and no other field. The op `insets` of
816
+ * `NumDomain` makes one, and a number argument of `add` lifts to four equal sides. `start` and `end` give plain `XY`
817
+ * values, so a module can copy them. `startVec2` and `endVec2` give `Vec2` values, and a module cannot copy them. Put
818
+ * `InsetsDomain` before `NumRecordDomain`, because a record of numbers accepts the same objects.
819
+ */
820
+ const InsetsDomain = defineDomain({
821
+ name: "Insets",
822
+ size: "fixed",
823
+ fields: [
824
+ "startX",
825
+ "startY",
826
+ "endX",
827
+ "endY"
828
+ ],
829
+ is: (u) => {
830
+ if (typeof u !== "object" || u === null || ![Object.prototype, null].includes(Object.getPrototypeOf(u)) || Object.keys(u).length !== 4) return false;
831
+ const v = u;
832
+ return typeof v.startX === "number" && typeof v.startY === "number" && typeof v.endX === "number" && typeof v.endY === "number";
833
+ },
834
+ fromScalar: (n) => ({
835
+ startX: n,
836
+ startY: n,
837
+ endX: n,
838
+ endY: n
839
+ }),
840
+ valid: (v) => Number.isFinite(v.startX) && Number.isFinite(v.startY) && Number.isFinite(v.endX) && Number.isFinite(v.endY),
841
+ show: (v) => `(${v.startX}, ${v.startY}, ${v.endX}, ${v.endY})`,
842
+ samples: () => [
843
+ {
844
+ startX: 0,
845
+ startY: 0,
846
+ endX: 0,
847
+ endY: 0
848
+ },
849
+ {
850
+ startX: 1.5,
851
+ startY: -2,
852
+ endX: 3,
853
+ endY: 4
854
+ },
855
+ {
856
+ startX: 8,
857
+ startY: 8,
858
+ endX: 8,
859
+ endY: 8
860
+ }
861
+ ],
862
+ ops: {
863
+ startX: {
864
+ fn: (a) => a.startX,
865
+ params: [],
866
+ returns: "number"
867
+ },
868
+ startY: {
869
+ fn: (a) => a.startY,
870
+ params: [],
871
+ returns: "number"
872
+ },
873
+ endX: {
874
+ fn: (a) => a.endX,
875
+ params: [],
876
+ returns: "number"
877
+ },
878
+ endY: {
879
+ fn: (a) => a.endY,
880
+ params: [],
881
+ returns: "number"
882
+ },
883
+ start: {
884
+ fn: (a) => ({
885
+ x: a.startX,
886
+ y: a.startY
887
+ }),
888
+ params: [],
889
+ returns: "domain:XY"
890
+ },
891
+ end: {
892
+ fn: (a) => ({
893
+ x: a.endX,
894
+ y: a.endY
895
+ }),
896
+ params: [],
897
+ returns: "domain:XY"
898
+ },
899
+ startVec2: {
900
+ fn: (a) => new Vec2(a.startX, a.startY),
901
+ params: [],
902
+ returns: "domain:Vec2"
903
+ },
904
+ endVec2: {
905
+ fn: (a) => new Vec2(a.endX, a.endY),
906
+ params: [],
907
+ returns: "domain:Vec2"
908
+ },
909
+ add: {
910
+ fn: (a, b) => ({
911
+ startX: a.startX + b.startX,
912
+ startY: a.startY + b.startY,
913
+ endX: a.endX + b.endX,
914
+ endY: a.endY + b.endY
915
+ }),
916
+ laws: ["commutative", "associative"],
917
+ identity: () => ({
918
+ startX: 0,
919
+ startY: 0,
920
+ endX: 0,
921
+ endY: 0
922
+ }),
923
+ liftScalar: true,
924
+ params: ["domain"],
925
+ returns: "domain"
926
+ },
927
+ scale: {
928
+ fn: (a, k) => ({
929
+ startX: a.startX * k,
930
+ startY: a.startY * k,
931
+ endX: a.endX * k,
932
+ endY: a.endY * k
933
+ }),
934
+ params: ["number"],
935
+ returns: "domain"
936
+ }
937
+ }
938
+ });
596
939
  // src/ndvector.ts
597
940
  /**
598
941
  * An immutable vector with named components. The type parameter `K` is the set of component names. Ops that
@@ -715,16 +1058,32 @@ var NDVector = class NDVector {
715
1058
  return `NDVector(${JSON.stringify(this.c)})`;
716
1059
  }
717
1060
  };
1061
+ /** The size rule of an op whose result has the keys of both vectors, each key one time (LOOP.SIZE.OPS). */
1062
+ const KEYS = {
1063
+ size: [1, 1],
1064
+ union: true
1065
+ };
1066
+ /** The size rule of an op that lifts a number to the vector `{ scalar: n }`: the keys of both, and maybe one key more. */
1067
+ const LIFTED = {
1068
+ size: [1, 1],
1069
+ union: true,
1070
+ constant: true
1071
+ };
718
1072
  const ndOps = {
719
1073
  add: {
720
1074
  laws: ["commutative", "associative"],
721
1075
  identity: () => NDVector.zero(),
722
- params: ["domain"]
1076
+ params: ["domain"],
1077
+ size: KEYS
1078
+ },
1079
+ subtract: {
1080
+ params: ["domain"],
1081
+ size: KEYS
723
1082
  },
724
- subtract: { params: ["domain"] },
725
1083
  multiply: {
726
1084
  laws: ["commutative", "associative"],
727
- params: ["domain"]
1085
+ params: ["domain"],
1086
+ size: KEYS
728
1087
  },
729
1088
  min: {
730
1089
  laws: [
@@ -732,7 +1091,8 @@ const ndOps = {
732
1091
  "associative",
733
1092
  "idempotent"
734
1093
  ],
735
- params: ["domain"]
1094
+ params: ["domain"],
1095
+ size: KEYS
736
1096
  },
737
1097
  max: {
738
1098
  laws: [
@@ -740,29 +1100,63 @@ const ndOps = {
740
1100
  "associative",
741
1101
  "idempotent"
742
1102
  ],
743
- params: ["domain"]
1103
+ params: ["domain"],
1104
+ size: KEYS
744
1105
  },
745
1106
  mergePreferNonZero: {
746
1107
  laws: ["associative", "idempotent"],
747
- params: ["domain"]
1108
+ params: ["domain"],
1109
+ size: KEYS
1110
+ },
1111
+ scale: {
1112
+ params: ["number"],
1113
+ size: { size: [1, 0] }
1114
+ },
1115
+ clamp: {
1116
+ params: ["number", "number"],
1117
+ size: { size: [
1118
+ 1,
1119
+ 0,
1120
+ 0
1121
+ ] }
748
1122
  },
749
- scale: { params: ["number"] },
750
- clamp: { params: ["number", "number"] },
751
1123
  dot: {
752
1124
  laws: ["commutative"],
753
- params: ["domain"]
1125
+ params: ["domain"],
1126
+ size: "scalar"
754
1127
  },
755
- length: {},
756
- norm1: {},
757
- normInf: {},
1128
+ length: { size: "scalar" },
1129
+ norm1: { size: "scalar" },
1130
+ normInf: { size: "scalar" },
758
1131
  equals: {
759
1132
  laws: ["commutative"],
760
- params: ["domain"]
1133
+ params: ["domain"],
1134
+ size: "scalar"
1135
+ },
1136
+ pick: { size: {
1137
+ size: [
1138
+ 1,
1139
+ 1,
1140
+ 0
1141
+ ],
1142
+ union: true
1143
+ } },
1144
+ withKeys: { size: KEYS },
1145
+ get: {
1146
+ params: ["string"],
1147
+ size: "scalar"
761
1148
  },
762
- pick: {},
763
- withKeys: {},
764
- get: { params: ["string"] },
765
- set: { params: ["string", "number"] }
1149
+ set: {
1150
+ params: ["string", "number"],
1151
+ size: {
1152
+ size: [
1153
+ 1,
1154
+ 1,
1155
+ 0
1156
+ ],
1157
+ union: true
1158
+ }
1159
+ }
766
1160
  };
767
1161
  const isNDVector = (u) => u instanceof NDVector;
768
1162
  /** The domain of named-component vectors. A number argument is an error here: use `LiftedNDVectorDomain` to lift. */
@@ -790,15 +1184,18 @@ const LiftedNDVectorDomain = defineDomain({
790
1184
  ...ndOps,
791
1185
  add: {
792
1186
  ...ndOps.add,
793
- liftScalar: true
1187
+ liftScalar: true,
1188
+ size: LIFTED
794
1189
  },
795
1190
  subtract: {
796
1191
  ...ndOps.subtract,
797
- liftScalar: true
1192
+ liftScalar: true,
1193
+ size: LIFTED
798
1194
  },
799
1195
  multiply: {
800
1196
  ...ndOps.multiply,
801
- liftScalar: true
1197
+ liftScalar: true,
1198
+ size: LIFTED
802
1199
  },
803
1200
  dot: {
804
1201
  ...ndOps.dot,
@@ -815,7 +1212,10 @@ const isNumRecord = (u) => {
815
1212
  const NumRecordDomain = defineDomain({
816
1213
  name: "NumRecord",
817
1214
  is: isNumRecord,
818
- ops: { toNDVector: { fn: (r) => new NDVector(r) } }
1215
+ ops: { toNDVector: {
1216
+ fn: (r) => new NDVector(r),
1217
+ size: { size: [1] }
1218
+ } }
819
1219
  });
820
1220
  // src/date.ts
821
1221
  const MS_PER_DAY = 864e5;
@@ -926,6 +1326,7 @@ var LocalDate = class LocalDate {
926
1326
  */
927
1327
  const DateDomain = defineDomain({
928
1328
  name: "Date",
1329
+ size: "fixed",
929
1330
  is: (u) => u instanceof LocalDate,
930
1331
  valid: (d) => Number.isSafeInteger(d.days) && Math.abs(d.days) <= 1e8,
931
1332
  show: (d) => d.toString(),
@@ -953,7 +1354,15 @@ const DateDomain = defineDomain({
953
1354
  // src/scalars.ts
954
1355
  /** The domain of numbers. A result that is not a finite number is the error `#NUM!`. */
955
1356
  const NumDomain = defineDomain({
1357
+ moduleForm: { ops: { vec2: {
1358
+ fn: (x, y) => ({
1359
+ x,
1360
+ y
1361
+ }),
1362
+ returns: "domain:Vec2"
1363
+ } } },
956
1364
  name: "Num",
1365
+ size: "fixed",
957
1366
  is: (u) => typeof u === "number",
958
1367
  primitive: "number",
959
1368
  valid: (n) => Number.isFinite(n),
@@ -964,12 +1373,14 @@ const NumDomain = defineDomain({
964
1373
  laws: ["commutative", "associative"],
965
1374
  identity: () => 0,
966
1375
  params: ["number"],
967
- returns: "number"
1376
+ returns: "number",
1377
+ monotone: ["up", "up"]
968
1378
  },
969
1379
  subtract: {
970
1380
  fn: (a, b) => a - b,
971
1381
  params: ["number"],
972
- returns: "number"
1382
+ returns: "number",
1383
+ monotone: ["up", "down"]
973
1384
  },
974
1385
  multiply: {
975
1386
  fn: (a, b) => a * b,
@@ -1001,7 +1412,8 @@ const NumDomain = defineDomain({
1001
1412
  "idempotent"
1002
1413
  ],
1003
1414
  params: ["number"],
1004
- returns: "number"
1415
+ returns: "number",
1416
+ monotone: ["up", "up"]
1005
1417
  },
1006
1418
  max: {
1007
1419
  fn: (a, b) => Math.max(a, b),
@@ -1011,12 +1423,18 @@ const NumDomain = defineDomain({
1011
1423
  "idempotent"
1012
1424
  ],
1013
1425
  params: ["number"],
1014
- returns: "number"
1426
+ returns: "number",
1427
+ monotone: ["up", "up"]
1015
1428
  },
1016
1429
  clamp: {
1017
1430
  fn: (a, lo, hi) => Math.min(hi, Math.max(lo, a)),
1018
1431
  params: ["number", "number"],
1019
- returns: "number"
1432
+ returns: "number",
1433
+ monotone: [
1434
+ "up",
1435
+ "up",
1436
+ "up"
1437
+ ]
1020
1438
  },
1021
1439
  abs: {
1022
1440
  fn: (a) => Math.abs(a),
@@ -1024,7 +1442,13 @@ const NumDomain = defineDomain({
1024
1442
  },
1025
1443
  negate: {
1026
1444
  fn: (a) => -a,
1027
- returns: "number"
1445
+ returns: "number",
1446
+ monotone: ["down"]
1447
+ },
1448
+ sign: {
1449
+ fn: (a) => Math.sign(a),
1450
+ returns: "number",
1451
+ monotone: ["up"]
1028
1452
  },
1029
1453
  sqrt: {
1030
1454
  fn: (a) => Math.sqrt(a),
@@ -1076,17 +1500,34 @@ const NumDomain = defineDomain({
1076
1500
  params: ["number"],
1077
1501
  returns: "domain:XY"
1078
1502
  },
1503
+ insets: {
1504
+ fn: (startX, startY, endX, endY) => ({
1505
+ startX,
1506
+ startY,
1507
+ endX,
1508
+ endY
1509
+ }),
1510
+ params: [
1511
+ "number",
1512
+ "number",
1513
+ "number"
1514
+ ],
1515
+ returns: "domain:Insets"
1516
+ },
1079
1517
  floor: {
1080
1518
  fn: (a) => Math.floor(a),
1081
- returns: "number"
1519
+ returns: "number",
1520
+ monotone: ["up"]
1082
1521
  },
1083
1522
  ceil: {
1084
1523
  fn: (a) => Math.ceil(a),
1085
- returns: "number"
1524
+ returns: "number",
1525
+ monotone: ["up"]
1086
1526
  },
1087
1527
  round: {
1088
1528
  fn: (a) => Math.round(a),
1089
- returns: "number"
1529
+ returns: "number",
1530
+ monotone: ["up"]
1090
1531
  },
1091
1532
  gt: {
1092
1533
  fn: (a, b) => a > b,
@@ -1119,6 +1560,7 @@ const NumDomain = defineDomain({
1119
1560
  /** The domain of booleans. For lazy logic, use the special forms `and`, `or` and `if` of the IR. */
1120
1561
  const BoolDomain = defineDomain({
1121
1562
  name: "Bool",
1563
+ size: "fixed",
1122
1564
  is: (u) => typeof u === "boolean",
1123
1565
  primitive: "boolean",
1124
1566
  show: (b) => String(b),
@@ -1132,7 +1574,8 @@ const BoolDomain = defineDomain({
1132
1574
  ],
1133
1575
  identity: () => true,
1134
1576
  params: ["boolean"],
1135
- returns: "boolean"
1577
+ returns: "boolean",
1578
+ monotone: ["up", "up"]
1136
1579
  },
1137
1580
  or: {
1138
1581
  fn: (a, b) => a || b,
@@ -1143,7 +1586,8 @@ const BoolDomain = defineDomain({
1143
1586
  ],
1144
1587
  identity: () => false,
1145
1588
  params: ["boolean"],
1146
- returns: "boolean"
1589
+ returns: "boolean",
1590
+ monotone: ["up", "up"]
1147
1591
  },
1148
1592
  xor: {
1149
1593
  fn: (a, b) => a !== b,
@@ -1154,7 +1598,8 @@ const BoolDomain = defineDomain({
1154
1598
  },
1155
1599
  not: {
1156
1600
  fn: (a) => !a,
1157
- returns: "boolean"
1601
+ returns: "boolean",
1602
+ monotone: ["down"]
1158
1603
  },
1159
1604
  eq: {
1160
1605
  fn: (a, b) => a === b,
@@ -1184,23 +1629,46 @@ const TextDomain = defineDomain({
1184
1629
  concat: {
1185
1630
  fn: (a, b) => a + textOf(b),
1186
1631
  params: ["any"],
1187
- returns: "string"
1632
+ returns: "string",
1633
+ size: { size: [1, "text"] }
1188
1634
  },
1189
1635
  length: {
1190
1636
  fn: (a) => a.length,
1191
1637
  returns: "number"
1192
1638
  },
1639
+ codePoints: {
1640
+ fn: (a) => Object.freeze({
1641
+ kind: "vex.list",
1642
+ items: Object.freeze(Array.from(a, (ch, i) => ({
1643
+ key: String(i),
1644
+ result: {
1645
+ ok: true,
1646
+ value: ch.codePointAt(0)
1647
+ }
1648
+ })))
1649
+ }),
1650
+ returns: "list:number",
1651
+ size: {
1652
+ size: [1],
1653
+ inner: [0],
1654
+ item: [0],
1655
+ keys: "position"
1656
+ }
1657
+ },
1193
1658
  upper: {
1194
1659
  fn: (a) => a.toUpperCase(),
1195
- returns: "string"
1660
+ returns: "string",
1661
+ size: { size: [1] }
1196
1662
  },
1197
1663
  lower: {
1198
1664
  fn: (a) => a.toLowerCase(),
1199
- returns: "string"
1665
+ returns: "string",
1666
+ size: { size: [1] }
1200
1667
  },
1201
1668
  trim: {
1202
1669
  fn: (a) => a.trim(),
1203
- returns: "string"
1670
+ returns: "string",
1671
+ size: { size: [1] }
1204
1672
  },
1205
1673
  contains: {
1206
1674
  fn: (a, b) => a.includes(b),
@@ -1295,6 +1763,7 @@ var Color = class Color {
1295
1763
  /** The domain of colors. */
1296
1764
  const ColorDomain = defineDomain({
1297
1765
  name: "Color",
1766
+ size: "fixed",
1298
1767
  is: (u) => u instanceof Color,
1299
1768
  fromScalar: (n) => Color.gray(n),
1300
1769
  valid: (c) => c.toArray().every((x) => Number.isFinite(x)),
@@ -1372,6 +1841,7 @@ var Angle = class Angle {
1372
1841
  /** The domain of angles. A number argument of `add` or `subtract` lifts to an angle in radians. */
1373
1842
  const AngleDomain = defineDomain({
1374
1843
  name: "Angle",
1844
+ size: "fixed",
1375
1845
  is: (u) => u instanceof Angle,
1376
1846
  fromScalar: (n) => new Angle(n),
1377
1847
  valid: (a) => Number.isFinite(a.radians),
@@ -1427,7 +1897,8 @@ const JsonDomain = defineDomain({
1427
1897
  kind: {
1428
1898
  fn: (v) => Array.isArray(v) ? "array" : typeof v,
1429
1899
  params: [],
1430
- returns: "string"
1900
+ returns: "string",
1901
+ size: "fixed"
1431
1902
  },
1432
1903
  kinds: {
1433
1904
  fn: (c) => {
@@ -1439,14 +1910,22 @@ const JsonDomain = defineDomain({
1439
1910
  throw new Error(`"kinds" found a value that is not JSON at the position ${i}`);
1440
1911
  });
1441
1912
  },
1442
- params: []
1913
+ params: [],
1914
+ size: {
1915
+ size: ["scaled"],
1916
+ keys: "position"
1917
+ }
1443
1918
  },
1444
1919
  fields: {
1445
1920
  fn: (o) => {
1446
1921
  if (typeof o !== "object" || Array.isArray(o)) throw new Error(`"fields" needs an object, not ${Array.isArray(o) ? "an array" : `a ${typeof o}`}`);
1447
1922
  return Object.keys(o);
1448
1923
  },
1449
- params: []
1924
+ params: [],
1925
+ size: {
1926
+ size: [1],
1927
+ keys: "position"
1928
+ }
1450
1929
  },
1451
1930
  field: {
1452
1931
  fn: (o, k) => {
@@ -1458,7 +1937,17 @@ const JsonDomain = defineDomain({
1458
1937
  return value;
1459
1938
  },
1460
1939
  params: ["any"],
1461
- returns: "any"
1940
+ returns: "any",
1941
+ size: {
1942
+ size: [1, 0],
1943
+ byParts: {
1944
+ size: [[1, "item"], 0],
1945
+ count: [[1, "item"], 0],
1946
+ inner: [[1, "item"], 0],
1947
+ item: [[1, "part"], 0],
1948
+ part: [[1, "part"], 0]
1949
+ }
1950
+ }
1462
1951
  },
1463
1952
  leaves: {
1464
1953
  fn: (o, depth) => {
@@ -1504,14 +1993,18 @@ const JsonDomain = defineDomain({
1504
1993
  }
1505
1994
  return Object.freeze(out);
1506
1995
  },
1507
- params: ["number"]
1996
+ params: ["number"],
1997
+ size: {
1998
+ size: ["scaled", 0],
1999
+ keys: "position"
2000
+ }
1508
2001
  }
1509
2002
  }
1510
2003
  });
1511
2004
  // src/schema.ts
1512
2005
  /**
1513
2006
  * The schema program (EXAMPLE.SCHEMA). It reads a list of JSON documents. For each field path, it gives the distinct
1514
- * kinds of the values and the number of documents with the path. The app Graph shows this schema for a sample of a collection.
2007
+ * kinds of the values and the number of documents with the path.
1515
2008
  *
1516
2009
  * The walk `leaves(d, 3)` goes into an object that is not empty at a depth under 3. It records an empty object, or an
1517
2010
  * object at the depth 3, with the kind `object`. It does not go into an array. The kind of an array is `array<k1|k2>`,
@@ -1618,13 +2111,13 @@ const MaybeDomain = defineDomain({
1618
2111
  name: "Maybe",
1619
2112
  is: (u) => u instanceof Maybe,
1620
2113
  ops: {
1621
- isTop: {},
1622
- isBottom: {},
2114
+ isTop: { size: "scalar" },
2115
+ isBottom: { size: "scalar" },
1623
2116
  map: {},
1624
2117
  chain: {},
1625
- valueOr: {}
2118
+ valueOr: { size: { size: [1, 1] } }
1626
2119
  }
1627
2120
  });
1628
- export { Angle, AngleDomain, BoolDomain, Color, ColorDomain, DateDomain, Fn, FnDomain, JsonDomain, LiftedNDVectorDomain, LocalDate, MAX_DAYS, Maybe, MaybeDomain, NDVector, NDVectorDomain, NumDomain, NumRecordDomain, SCHEMA_DOMAINS, SCHEMA_PROGRAM, TextDomain, Vec2, Vec2Domain, XYDomain, schemaOf };
2121
+ export { Angle, AngleDomain, BoolDomain, Color, ColorDomain, DateDomain, Fn, FnDomain, InsetsDomain, JsonDomain, LiftedNDVectorDomain, LocalDate, MAX_DAYS, Maybe, MaybeDomain, NDVector, NDVectorDomain, NumDomain, NumRecordDomain, SCHEMA_DOMAINS, SCHEMA_PROGRAM, TextDomain, Vec2, Vec2Domain, XYDomain, schemaOf };
1629
2122
 
1630
2123
  //# sourceMappingURL=index.js.map