document-model.js 3.1.0 → 3.3.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.
@@ -0,0 +1,210 @@
1
+ import { z } from "zod";
2
+ //#region src/math.d.ts
3
+ declare const ExactRationalSchema: z.ZodObject<{
4
+ numerator: z.ZodString;
5
+ denominator: z.ZodString;
6
+ }, z.core.$strip>;
7
+ type ExactRational = z.infer<typeof ExactRationalSchema>;
8
+ declare const SI_BASE_DIMENSIONS: readonly ["length", "mass", "time", "electricCurrent", "thermodynamicTemperature", "amountOfSubstance", "luminousIntensity"];
9
+ type SiBaseDimension = (typeof SI_BASE_DIMENSIONS)[number];
10
+ declare const DimensionVectorSchema: z.ZodRecord<z.ZodEnum<{
11
+ time: "time";
12
+ length: "length";
13
+ mass: "mass";
14
+ electricCurrent: "electricCurrent";
15
+ thermodynamicTemperature: "thermodynamicTemperature";
16
+ amountOfSubstance: "amountOfSubstance";
17
+ luminousIntensity: "luminousIntensity";
18
+ }> & z.core.$partial, z.ZodNumber>;
19
+ type DimensionVector = z.infer<typeof DimensionVectorSchema>;
20
+ declare const MathUnitSchema: z.ZodObject<{
21
+ id: z.ZodString;
22
+ symbol: z.ZodString;
23
+ name: z.ZodOptional<z.ZodString>;
24
+ dimension: z.ZodRecord<z.ZodEnum<{
25
+ time: "time";
26
+ length: "length";
27
+ mass: "mass";
28
+ electricCurrent: "electricCurrent";
29
+ thermodynamicTemperature: "thermodynamicTemperature";
30
+ amountOfSubstance: "amountOfSubstance";
31
+ luminousIntensity: "luminousIntensity";
32
+ }> & z.core.$partial, z.ZodNumber>;
33
+ factorToSi: z.ZodObject<{
34
+ numerator: z.ZodString;
35
+ denominator: z.ZodString;
36
+ }, z.core.$strip>;
37
+ offsetToSi: z.ZodOptional<z.ZodObject<{
38
+ numerator: z.ZodString;
39
+ denominator: z.ZodString;
40
+ }, z.core.$strip>>;
41
+ context: z.ZodOptional<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ type MathUnit = z.infer<typeof MathUnitSchema>;
44
+ declare const MathNormalisationContextSchema: z.ZodObject<{
45
+ id: z.ZodString;
46
+ bases: z.ZodArray<z.ZodObject<{
47
+ unit: z.ZodString;
48
+ value: z.ZodObject<{
49
+ numerator: z.ZodString;
50
+ denominator: z.ZodString;
51
+ }, z.core.$strip>;
52
+ }, z.core.$strip>>;
53
+ }, z.core.$strip>;
54
+ type MathNormalisationContext = z.infer<typeof MathNormalisationContextSchema>;
55
+ declare const MathSymbolEntrySchema: z.ZodObject<{
56
+ glyph: z.ZodString;
57
+ scope: z.ZodString;
58
+ id: z.ZodString;
59
+ quantityKind: z.ZodOptional<z.ZodString>;
60
+ preferredUnit: z.ZodOptional<z.ZodString>;
61
+ definitionSource: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>;
63
+ type MathSymbolEntry = z.infer<typeof MathSymbolEntrySchema>;
64
+ declare const SymbolTableSchema: z.ZodObject<{
65
+ symbols: z.ZodArray<z.ZodObject<{
66
+ glyph: z.ZodString;
67
+ scope: z.ZodString;
68
+ id: z.ZodString;
69
+ quantityKind: z.ZodOptional<z.ZodString>;
70
+ preferredUnit: z.ZodOptional<z.ZodString>;
71
+ definitionSource: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strip>>;
73
+ units: z.ZodArray<z.ZodObject<{
74
+ id: z.ZodString;
75
+ symbol: z.ZodString;
76
+ name: z.ZodOptional<z.ZodString>;
77
+ dimension: z.ZodRecord<z.ZodEnum<{
78
+ time: "time";
79
+ length: "length";
80
+ mass: "mass";
81
+ electricCurrent: "electricCurrent";
82
+ thermodynamicTemperature: "thermodynamicTemperature";
83
+ amountOfSubstance: "amountOfSubstance";
84
+ luminousIntensity: "luminousIntensity";
85
+ }> & z.core.$partial, z.ZodNumber>;
86
+ factorToSi: z.ZodObject<{
87
+ numerator: z.ZodString;
88
+ denominator: z.ZodString;
89
+ }, z.core.$strip>;
90
+ offsetToSi: z.ZodOptional<z.ZodObject<{
91
+ numerator: z.ZodString;
92
+ denominator: z.ZodString;
93
+ }, z.core.$strip>>;
94
+ context: z.ZodOptional<z.ZodString>;
95
+ }, z.core.$strip>>;
96
+ contexts: z.ZodOptional<z.ZodArray<z.ZodObject<{
97
+ id: z.ZodString;
98
+ bases: z.ZodArray<z.ZodObject<{
99
+ unit: z.ZodString;
100
+ value: z.ZodObject<{
101
+ numerator: z.ZodString;
102
+ denominator: z.ZodString;
103
+ }, z.core.$strip>;
104
+ }, z.core.$strip>>;
105
+ }, z.core.$strip>>>;
106
+ }, z.core.$strip>;
107
+ type SymbolTable = z.infer<typeof SymbolTableSchema>;
108
+ declare const MathPresentationSchema: z.ZodObject<{
109
+ latex: z.ZodString;
110
+ }, z.core.$strip>;
111
+ type MathPresentation = z.infer<typeof MathPresentationSchema>;
112
+ declare const MathProvenanceSchema: z.ZodObject<{
113
+ source: z.ZodString;
114
+ pageRef: z.ZodOptional<z.ZodString>;
115
+ editTrail: z.ZodArray<z.ZodString>;
116
+ }, z.core.$strip>;
117
+ type MathProvenance = z.infer<typeof MathProvenanceSchema>;
118
+ declare const MathUncertaintySchema: z.ZodObject<{
119
+ magnitude: z.ZodObject<{
120
+ numerator: z.ZodString;
121
+ denominator: z.ZodString;
122
+ }, z.core.$strip>;
123
+ unit: z.ZodOptional<z.ZodString>;
124
+ coverageFactor: z.ZodOptional<z.ZodNumber>;
125
+ }, z.core.$strip>;
126
+ type MathUncertainty = z.infer<typeof MathUncertaintySchema>;
127
+ declare const MathNumSchema: z.ZodObject<{
128
+ numerator: z.ZodString;
129
+ denominator: z.ZodString;
130
+ kind: z.ZodLiteral<"num">;
131
+ }, z.core.$strip>;
132
+ type MathNum = z.infer<typeof MathNumSchema>;
133
+ declare const MathQtySchema: z.ZodObject<{
134
+ kind: z.ZodLiteral<"qty">;
135
+ value: z.ZodObject<{
136
+ numerator: z.ZodString;
137
+ denominator: z.ZodString;
138
+ }, z.core.$strip>;
139
+ unit: z.ZodString;
140
+ uncertainty: z.ZodOptional<z.ZodObject<{
141
+ magnitude: z.ZodObject<{
142
+ numerator: z.ZodString;
143
+ denominator: z.ZodString;
144
+ }, z.core.$strip>;
145
+ unit: z.ZodOptional<z.ZodString>;
146
+ coverageFactor: z.ZodOptional<z.ZodNumber>;
147
+ }, z.core.$strip>>;
148
+ }, z.core.$strip>;
149
+ type MathQty = z.infer<typeof MathQtySchema>;
150
+ declare const MathSymSchema: z.ZodObject<{
151
+ kind: z.ZodLiteral<"sym">;
152
+ id: z.ZodString;
153
+ }, z.core.$strip>;
154
+ type MathSym = z.infer<typeof MathSymSchema>;
155
+ declare const MathUnparsedSchema: z.ZodObject<{
156
+ kind: z.ZodLiteral<"unparsed">;
157
+ latex: z.ZodString;
158
+ }, z.core.$strip>;
159
+ type MathUnparsed = z.infer<typeof MathUnparsedSchema>;
160
+ interface MathApp {
161
+ kind: 'app';
162
+ operator: string;
163
+ args: MathExpression[];
164
+ }
165
+ interface MathSum {
166
+ kind: 'sum';
167
+ binder: string;
168
+ lower: MathExpression;
169
+ upper: MathExpression;
170
+ body: MathExpression;
171
+ }
172
+ interface MathProd {
173
+ kind: 'prod';
174
+ binder: string;
175
+ lower: MathExpression;
176
+ upper: MathExpression;
177
+ body: MathExpression;
178
+ }
179
+ interface MathMatrix {
180
+ kind: 'matrix';
181
+ rows: MathExpression[][];
182
+ }
183
+ type MathExpression = MathNum | MathQty | MathSym | MathApp | MathSum | MathProd | MathMatrix | MathUnparsed;
184
+ declare function isMathExpression(value: unknown): value is MathExpression;
185
+ declare const MathExpressionSchema: z.ZodCustom<MathExpression, MathExpression>;
186
+ declare const MathAppSchema: z.ZodObject<{
187
+ kind: z.ZodLiteral<"app">;
188
+ operator: z.ZodString;
189
+ args: z.ZodArray<z.ZodCustom<MathExpression, MathExpression>>;
190
+ }, z.core.$strip>;
191
+ declare const MathSumSchema: z.ZodObject<{
192
+ binder: z.ZodString;
193
+ lower: z.ZodCustom<MathExpression, MathExpression>;
194
+ upper: z.ZodCustom<MathExpression, MathExpression>;
195
+ body: z.ZodCustom<MathExpression, MathExpression>;
196
+ kind: z.ZodLiteral<"sum">;
197
+ }, z.core.$strip>;
198
+ declare const MathProdSchema: z.ZodObject<{
199
+ binder: z.ZodString;
200
+ lower: z.ZodCustom<MathExpression, MathExpression>;
201
+ upper: z.ZodCustom<MathExpression, MathExpression>;
202
+ body: z.ZodCustom<MathExpression, MathExpression>;
203
+ kind: z.ZodLiteral<"prod">;
204
+ }, z.core.$strip>;
205
+ declare const MathMatrixSchema: z.ZodObject<{
206
+ kind: z.ZodLiteral<"matrix">;
207
+ rows: z.ZodArray<z.ZodArray<z.ZodCustom<MathExpression, MathExpression>>>;
208
+ }, z.core.$strip>;
209
+ //#endregion
210
+ export { MathUncertaintySchema as A, MathSum as C, MathSymbolEntry as D, MathSymSchema as E, SI_BASE_DIMENSIONS as F, SiBaseDimension as I, SymbolTable as L, MathUnitSchema as M, MathUnparsed as N, MathSymbolEntrySchema as O, MathUnparsedSchema as P, SymbolTableSchema as R, MathQtySchema as S, MathSym as T, MathProd as _, MathApp as a, MathProvenanceSchema as b, MathExpressionSchema as c, MathNormalisationContext as d, MathNormalisationContextSchema as f, MathPresentationSchema as g, MathPresentation as h, ExactRationalSchema as i, MathUnit as j, MathUncertainty as k, MathMatrix as l, MathNumSchema as m, DimensionVectorSchema as n, MathAppSchema as o, MathNum as p, ExactRational as r, MathExpression as s, DimensionVector as t, MathMatrixSchema as u, MathProdSchema as v, MathSumSchema as w, MathQty as x, MathProvenance as y, isMathExpression as z };
@@ -0,0 +1,210 @@
1
+ import { z } from "zod";
2
+ //#region src/math.d.ts
3
+ declare const ExactRationalSchema: z.ZodObject<{
4
+ numerator: z.ZodString;
5
+ denominator: z.ZodString;
6
+ }, z.core.$strip>;
7
+ type ExactRational = z.infer<typeof ExactRationalSchema>;
8
+ declare const SI_BASE_DIMENSIONS: readonly ["length", "mass", "time", "electricCurrent", "thermodynamicTemperature", "amountOfSubstance", "luminousIntensity"];
9
+ type SiBaseDimension = (typeof SI_BASE_DIMENSIONS)[number];
10
+ declare const DimensionVectorSchema: z.ZodRecord<z.ZodEnum<{
11
+ time: "time";
12
+ length: "length";
13
+ mass: "mass";
14
+ electricCurrent: "electricCurrent";
15
+ thermodynamicTemperature: "thermodynamicTemperature";
16
+ amountOfSubstance: "amountOfSubstance";
17
+ luminousIntensity: "luminousIntensity";
18
+ }> & z.core.$partial, z.ZodNumber>;
19
+ type DimensionVector = z.infer<typeof DimensionVectorSchema>;
20
+ declare const MathUnitSchema: z.ZodObject<{
21
+ id: z.ZodString;
22
+ symbol: z.ZodString;
23
+ name: z.ZodOptional<z.ZodString>;
24
+ dimension: z.ZodRecord<z.ZodEnum<{
25
+ time: "time";
26
+ length: "length";
27
+ mass: "mass";
28
+ electricCurrent: "electricCurrent";
29
+ thermodynamicTemperature: "thermodynamicTemperature";
30
+ amountOfSubstance: "amountOfSubstance";
31
+ luminousIntensity: "luminousIntensity";
32
+ }> & z.core.$partial, z.ZodNumber>;
33
+ factorToSi: z.ZodObject<{
34
+ numerator: z.ZodString;
35
+ denominator: z.ZodString;
36
+ }, z.core.$strip>;
37
+ offsetToSi: z.ZodOptional<z.ZodObject<{
38
+ numerator: z.ZodString;
39
+ denominator: z.ZodString;
40
+ }, z.core.$strip>>;
41
+ context: z.ZodOptional<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ type MathUnit = z.infer<typeof MathUnitSchema>;
44
+ declare const MathNormalisationContextSchema: z.ZodObject<{
45
+ id: z.ZodString;
46
+ bases: z.ZodArray<z.ZodObject<{
47
+ unit: z.ZodString;
48
+ value: z.ZodObject<{
49
+ numerator: z.ZodString;
50
+ denominator: z.ZodString;
51
+ }, z.core.$strip>;
52
+ }, z.core.$strip>>;
53
+ }, z.core.$strip>;
54
+ type MathNormalisationContext = z.infer<typeof MathNormalisationContextSchema>;
55
+ declare const MathSymbolEntrySchema: z.ZodObject<{
56
+ glyph: z.ZodString;
57
+ scope: z.ZodString;
58
+ id: z.ZodString;
59
+ quantityKind: z.ZodOptional<z.ZodString>;
60
+ preferredUnit: z.ZodOptional<z.ZodString>;
61
+ definitionSource: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>;
63
+ type MathSymbolEntry = z.infer<typeof MathSymbolEntrySchema>;
64
+ declare const SymbolTableSchema: z.ZodObject<{
65
+ symbols: z.ZodArray<z.ZodObject<{
66
+ glyph: z.ZodString;
67
+ scope: z.ZodString;
68
+ id: z.ZodString;
69
+ quantityKind: z.ZodOptional<z.ZodString>;
70
+ preferredUnit: z.ZodOptional<z.ZodString>;
71
+ definitionSource: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strip>>;
73
+ units: z.ZodArray<z.ZodObject<{
74
+ id: z.ZodString;
75
+ symbol: z.ZodString;
76
+ name: z.ZodOptional<z.ZodString>;
77
+ dimension: z.ZodRecord<z.ZodEnum<{
78
+ time: "time";
79
+ length: "length";
80
+ mass: "mass";
81
+ electricCurrent: "electricCurrent";
82
+ thermodynamicTemperature: "thermodynamicTemperature";
83
+ amountOfSubstance: "amountOfSubstance";
84
+ luminousIntensity: "luminousIntensity";
85
+ }> & z.core.$partial, z.ZodNumber>;
86
+ factorToSi: z.ZodObject<{
87
+ numerator: z.ZodString;
88
+ denominator: z.ZodString;
89
+ }, z.core.$strip>;
90
+ offsetToSi: z.ZodOptional<z.ZodObject<{
91
+ numerator: z.ZodString;
92
+ denominator: z.ZodString;
93
+ }, z.core.$strip>>;
94
+ context: z.ZodOptional<z.ZodString>;
95
+ }, z.core.$strip>>;
96
+ contexts: z.ZodOptional<z.ZodArray<z.ZodObject<{
97
+ id: z.ZodString;
98
+ bases: z.ZodArray<z.ZodObject<{
99
+ unit: z.ZodString;
100
+ value: z.ZodObject<{
101
+ numerator: z.ZodString;
102
+ denominator: z.ZodString;
103
+ }, z.core.$strip>;
104
+ }, z.core.$strip>>;
105
+ }, z.core.$strip>>>;
106
+ }, z.core.$strip>;
107
+ type SymbolTable = z.infer<typeof SymbolTableSchema>;
108
+ declare const MathPresentationSchema: z.ZodObject<{
109
+ latex: z.ZodString;
110
+ }, z.core.$strip>;
111
+ type MathPresentation = z.infer<typeof MathPresentationSchema>;
112
+ declare const MathProvenanceSchema: z.ZodObject<{
113
+ source: z.ZodString;
114
+ pageRef: z.ZodOptional<z.ZodString>;
115
+ editTrail: z.ZodArray<z.ZodString>;
116
+ }, z.core.$strip>;
117
+ type MathProvenance = z.infer<typeof MathProvenanceSchema>;
118
+ declare const MathUncertaintySchema: z.ZodObject<{
119
+ magnitude: z.ZodObject<{
120
+ numerator: z.ZodString;
121
+ denominator: z.ZodString;
122
+ }, z.core.$strip>;
123
+ unit: z.ZodOptional<z.ZodString>;
124
+ coverageFactor: z.ZodOptional<z.ZodNumber>;
125
+ }, z.core.$strip>;
126
+ type MathUncertainty = z.infer<typeof MathUncertaintySchema>;
127
+ declare const MathNumSchema: z.ZodObject<{
128
+ numerator: z.ZodString;
129
+ denominator: z.ZodString;
130
+ kind: z.ZodLiteral<"num">;
131
+ }, z.core.$strip>;
132
+ type MathNum = z.infer<typeof MathNumSchema>;
133
+ declare const MathQtySchema: z.ZodObject<{
134
+ kind: z.ZodLiteral<"qty">;
135
+ value: z.ZodObject<{
136
+ numerator: z.ZodString;
137
+ denominator: z.ZodString;
138
+ }, z.core.$strip>;
139
+ unit: z.ZodString;
140
+ uncertainty: z.ZodOptional<z.ZodObject<{
141
+ magnitude: z.ZodObject<{
142
+ numerator: z.ZodString;
143
+ denominator: z.ZodString;
144
+ }, z.core.$strip>;
145
+ unit: z.ZodOptional<z.ZodString>;
146
+ coverageFactor: z.ZodOptional<z.ZodNumber>;
147
+ }, z.core.$strip>>;
148
+ }, z.core.$strip>;
149
+ type MathQty = z.infer<typeof MathQtySchema>;
150
+ declare const MathSymSchema: z.ZodObject<{
151
+ kind: z.ZodLiteral<"sym">;
152
+ id: z.ZodString;
153
+ }, z.core.$strip>;
154
+ type MathSym = z.infer<typeof MathSymSchema>;
155
+ declare const MathUnparsedSchema: z.ZodObject<{
156
+ kind: z.ZodLiteral<"unparsed">;
157
+ latex: z.ZodString;
158
+ }, z.core.$strip>;
159
+ type MathUnparsed = z.infer<typeof MathUnparsedSchema>;
160
+ interface MathApp {
161
+ kind: 'app';
162
+ operator: string;
163
+ args: MathExpression[];
164
+ }
165
+ interface MathSum {
166
+ kind: 'sum';
167
+ binder: string;
168
+ lower: MathExpression;
169
+ upper: MathExpression;
170
+ body: MathExpression;
171
+ }
172
+ interface MathProd {
173
+ kind: 'prod';
174
+ binder: string;
175
+ lower: MathExpression;
176
+ upper: MathExpression;
177
+ body: MathExpression;
178
+ }
179
+ interface MathMatrix {
180
+ kind: 'matrix';
181
+ rows: MathExpression[][];
182
+ }
183
+ type MathExpression = MathNum | MathQty | MathSym | MathApp | MathSum | MathProd | MathMatrix | MathUnparsed;
184
+ declare function isMathExpression(value: unknown): value is MathExpression;
185
+ declare const MathExpressionSchema: z.ZodCustom<MathExpression, MathExpression>;
186
+ declare const MathAppSchema: z.ZodObject<{
187
+ kind: z.ZodLiteral<"app">;
188
+ operator: z.ZodString;
189
+ args: z.ZodArray<z.ZodCustom<MathExpression, MathExpression>>;
190
+ }, z.core.$strip>;
191
+ declare const MathSumSchema: z.ZodObject<{
192
+ binder: z.ZodString;
193
+ lower: z.ZodCustom<MathExpression, MathExpression>;
194
+ upper: z.ZodCustom<MathExpression, MathExpression>;
195
+ body: z.ZodCustom<MathExpression, MathExpression>;
196
+ kind: z.ZodLiteral<"sum">;
197
+ }, z.core.$strip>;
198
+ declare const MathProdSchema: z.ZodObject<{
199
+ binder: z.ZodString;
200
+ lower: z.ZodCustom<MathExpression, MathExpression>;
201
+ upper: z.ZodCustom<MathExpression, MathExpression>;
202
+ body: z.ZodCustom<MathExpression, MathExpression>;
203
+ kind: z.ZodLiteral<"prod">;
204
+ }, z.core.$strip>;
205
+ declare const MathMatrixSchema: z.ZodObject<{
206
+ kind: z.ZodLiteral<"matrix">;
207
+ rows: z.ZodArray<z.ZodArray<z.ZodCustom<MathExpression, MathExpression>>>;
208
+ }, z.core.$strip>;
209
+ //#endregion
210
+ export { MathUncertaintySchema as A, MathSum as C, MathSymbolEntry as D, MathSymSchema as E, SI_BASE_DIMENSIONS as F, SiBaseDimension as I, SymbolTable as L, MathUnitSchema as M, MathUnparsed as N, MathSymbolEntrySchema as O, MathUnparsedSchema as P, SymbolTableSchema as R, MathQtySchema as S, MathSym as T, MathProd as _, MathApp as a, MathProvenanceSchema as b, MathExpressionSchema as c, MathNormalisationContext as d, MathNormalisationContextSchema as f, MathPresentationSchema as g, MathPresentation as h, ExactRationalSchema as i, MathUnit as j, MathUncertainty as k, MathMatrix as l, MathNumSchema as m, DimensionVectorSchema as n, MathAppSchema as o, MathNum as p, ExactRational as r, MathExpression as s, DimensionVector as t, MathMatrixSchema as u, MathProdSchema as v, MathSumSchema as w, MathQty as x, MathProvenance as y, isMathExpression as z };
package/dist/math.cjs ADDED
@@ -0,0 +1,152 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let zod = require("zod");
3
+ //#region src/math.ts
4
+ const CANONICAL_SIGNED_INTEGER = /^(0|-?[1-9]\d*)$/;
5
+ const CANONICAL_POSITIVE_INTEGER = /^[1-9]\d*$/;
6
+ const EXACT_RATIONAL_FIELDS = {
7
+ numerator: zod.z.string().regex(CANONICAL_SIGNED_INTEGER),
8
+ denominator: zod.z.string().regex(CANONICAL_POSITIVE_INTEGER)
9
+ };
10
+ const ExactRationalSchema = zod.z.object(EXACT_RATIONAL_FIELDS);
11
+ const SI_BASE_DIMENSIONS = [
12
+ "length",
13
+ "mass",
14
+ "time",
15
+ "electricCurrent",
16
+ "thermodynamicTemperature",
17
+ "amountOfSubstance",
18
+ "luminousIntensity"
19
+ ];
20
+ const DimensionVectorSchema = zod.z.partialRecord(zod.z.enum(SI_BASE_DIMENSIONS), zod.z.number().int());
21
+ const MathUnitSchema = zod.z.object({
22
+ id: zod.z.string(),
23
+ symbol: zod.z.string(),
24
+ name: zod.z.string().optional(),
25
+ dimension: DimensionVectorSchema,
26
+ factorToSi: ExactRationalSchema,
27
+ offsetToSi: ExactRationalSchema.optional(),
28
+ context: zod.z.string().optional()
29
+ });
30
+ const MathNormalisationContextSchema = zod.z.object({
31
+ id: zod.z.string(),
32
+ bases: zod.z.array(zod.z.object({
33
+ unit: zod.z.string(),
34
+ value: ExactRationalSchema
35
+ }))
36
+ });
37
+ const MathSymbolEntrySchema = zod.z.object({
38
+ glyph: zod.z.string(),
39
+ scope: zod.z.string(),
40
+ id: zod.z.string(),
41
+ quantityKind: zod.z.string().optional(),
42
+ preferredUnit: zod.z.string().optional(),
43
+ definitionSource: zod.z.string().optional()
44
+ });
45
+ const SymbolTableSchema = zod.z.object({
46
+ symbols: zod.z.array(MathSymbolEntrySchema),
47
+ units: zod.z.array(MathUnitSchema),
48
+ contexts: zod.z.array(MathNormalisationContextSchema).optional()
49
+ });
50
+ const MathPresentationSchema = zod.z.object({ latex: zod.z.string() });
51
+ const MathProvenanceSchema = zod.z.object({
52
+ source: zod.z.string(),
53
+ pageRef: zod.z.string().optional(),
54
+ editTrail: zod.z.array(zod.z.string())
55
+ });
56
+ const MathUncertaintySchema = zod.z.object({
57
+ magnitude: ExactRationalSchema,
58
+ unit: zod.z.string().optional(),
59
+ coverageFactor: zod.z.number().positive().optional()
60
+ });
61
+ const MathNumSchema = zod.z.object({
62
+ kind: zod.z.literal("num"),
63
+ ...EXACT_RATIONAL_FIELDS
64
+ });
65
+ const MathQtySchema = zod.z.object({
66
+ kind: zod.z.literal("qty"),
67
+ value: ExactRationalSchema,
68
+ unit: zod.z.string(),
69
+ uncertainty: MathUncertaintySchema.optional()
70
+ });
71
+ const MathSymSchema = zod.z.object({
72
+ kind: zod.z.literal("sym"),
73
+ id: zod.z.string()
74
+ });
75
+ const MathUnparsedSchema = zod.z.object({
76
+ kind: zod.z.literal("unparsed"),
77
+ latex: zod.z.string()
78
+ });
79
+ function isRecord(value) {
80
+ return typeof value === "object" && value !== null && !Array.isArray(value);
81
+ }
82
+ function isExactRational(value) {
83
+ return isRecord(value) && typeof value.numerator === "string" && CANONICAL_SIGNED_INTEGER.test(value.numerator) && typeof value.denominator === "string" && CANONICAL_POSITIVE_INTEGER.test(value.denominator);
84
+ }
85
+ function isMathUncertainty(value) {
86
+ return isRecord(value) && isExactRational(value.magnitude) && (value.unit === void 0 || typeof value.unit === "string") && (value.coverageFactor === void 0 || typeof value.coverageFactor === "number" && value.coverageFactor > 0);
87
+ }
88
+ function isMathExpression(value) {
89
+ if (!isRecord(value)) return false;
90
+ const kind = value.kind;
91
+ if (kind === "num") return typeof value.numerator === "string" && CANONICAL_SIGNED_INTEGER.test(value.numerator) && typeof value.denominator === "string" && CANONICAL_POSITIVE_INTEGER.test(value.denominator);
92
+ if (kind === "qty") return isExactRational(value.value) && typeof value.unit === "string" && (value.uncertainty === void 0 || isMathUncertainty(value.uncertainty));
93
+ if (kind === "sym") return typeof value.id === "string";
94
+ if (kind === "app") return typeof value.operator === "string" && Array.isArray(value.args) && value.args.every(isMathExpression);
95
+ if (kind === "sum" || kind === "prod") return typeof value.binder === "string" && isMathExpression(value.lower) && isMathExpression(value.upper) && isMathExpression(value.body);
96
+ if (kind === "matrix") {
97
+ if (!Array.isArray(value.rows)) return false;
98
+ const widths = /* @__PURE__ */ new Set();
99
+ for (const row of value.rows) {
100
+ if (!Array.isArray(row) || !row.every(isMathExpression)) return false;
101
+ widths.add(row.length);
102
+ }
103
+ return widths.size <= 1;
104
+ }
105
+ if (kind === "unparsed") return typeof value.latex === "string";
106
+ return false;
107
+ }
108
+ const MathExpressionSchema = zod.z.custom(isMathExpression);
109
+ const MathAppSchema = zod.z.object({
110
+ kind: zod.z.literal("app"),
111
+ operator: zod.z.string(),
112
+ args: zod.z.array(MathExpressionSchema)
113
+ });
114
+ const BINDER_SCHEMA_FIELDS = {
115
+ binder: zod.z.string(),
116
+ lower: MathExpressionSchema,
117
+ upper: MathExpressionSchema,
118
+ body: MathExpressionSchema
119
+ };
120
+ const MathSumSchema = zod.z.object({
121
+ kind: zod.z.literal("sum"),
122
+ ...BINDER_SCHEMA_FIELDS
123
+ });
124
+ const MathProdSchema = zod.z.object({
125
+ kind: zod.z.literal("prod"),
126
+ ...BINDER_SCHEMA_FIELDS
127
+ });
128
+ const MathMatrixSchema = zod.z.object({
129
+ kind: zod.z.literal("matrix"),
130
+ rows: zod.z.array(zod.z.array(MathExpressionSchema))
131
+ }).refine((matrix) => new Set(matrix.rows.map((row) => row.length)).size <= 1, { message: "matrix rows must all have the same number of columns" });
132
+ //#endregion
133
+ exports.DimensionVectorSchema = DimensionVectorSchema;
134
+ exports.ExactRationalSchema = ExactRationalSchema;
135
+ exports.MathAppSchema = MathAppSchema;
136
+ exports.MathExpressionSchema = MathExpressionSchema;
137
+ exports.MathMatrixSchema = MathMatrixSchema;
138
+ exports.MathNormalisationContextSchema = MathNormalisationContextSchema;
139
+ exports.MathNumSchema = MathNumSchema;
140
+ exports.MathPresentationSchema = MathPresentationSchema;
141
+ exports.MathProdSchema = MathProdSchema;
142
+ exports.MathProvenanceSchema = MathProvenanceSchema;
143
+ exports.MathQtySchema = MathQtySchema;
144
+ exports.MathSumSchema = MathSumSchema;
145
+ exports.MathSymSchema = MathSymSchema;
146
+ exports.MathSymbolEntrySchema = MathSymbolEntrySchema;
147
+ exports.MathUncertaintySchema = MathUncertaintySchema;
148
+ exports.MathUnitSchema = MathUnitSchema;
149
+ exports.MathUnparsedSchema = MathUnparsedSchema;
150
+ exports.SI_BASE_DIMENSIONS = SI_BASE_DIMENSIONS;
151
+ exports.SymbolTableSchema = SymbolTableSchema;
152
+ exports.isMathExpression = isMathExpression;
@@ -0,0 +1,2 @@
1
+ import { A as MathUncertaintySchema, C as MathSum, D as MathSymbolEntry, E as MathSymSchema, F as SI_BASE_DIMENSIONS, I as SiBaseDimension, L as SymbolTable, M as MathUnitSchema, N as MathUnparsed, O as MathSymbolEntrySchema, P as MathUnparsedSchema, R as SymbolTableSchema, S as MathQtySchema, T as MathSym, _ as MathProd, a as MathApp, b as MathProvenanceSchema, c as MathExpressionSchema, d as MathNormalisationContext, f as MathNormalisationContextSchema, g as MathPresentationSchema, h as MathPresentation, i as ExactRationalSchema, j as MathUnit, k as MathUncertainty, l as MathMatrix, m as MathNumSchema, n as DimensionVectorSchema, o as MathAppSchema, p as MathNum, r as ExactRational, s as MathExpression, t as DimensionVector, u as MathMatrixSchema, v as MathProdSchema, w as MathSumSchema, x as MathQty, y as MathProvenance, z as isMathExpression } from "./math-B7gZJeND.cjs";
2
+ export { DimensionVector, DimensionVectorSchema, ExactRational, ExactRationalSchema, MathApp, MathAppSchema, MathExpression, MathExpressionSchema, MathMatrix, MathMatrixSchema, MathNormalisationContext, MathNormalisationContextSchema, MathNum, MathNumSchema, MathPresentation, MathPresentationSchema, MathProd, MathProdSchema, MathProvenance, MathProvenanceSchema, MathQty, MathQtySchema, MathSum, MathSumSchema, MathSym, MathSymSchema, MathSymbolEntry, MathSymbolEntrySchema, MathUncertainty, MathUncertaintySchema, MathUnit, MathUnitSchema, MathUnparsed, MathUnparsedSchema, SI_BASE_DIMENSIONS, SiBaseDimension, SymbolTable, SymbolTableSchema, isMathExpression };
package/dist/math.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { A as MathUncertaintySchema, C as MathSum, D as MathSymbolEntry, E as MathSymSchema, F as SI_BASE_DIMENSIONS, I as SiBaseDimension, L as SymbolTable, M as MathUnitSchema, N as MathUnparsed, O as MathSymbolEntrySchema, P as MathUnparsedSchema, R as SymbolTableSchema, S as MathQtySchema, T as MathSym, _ as MathProd, a as MathApp, b as MathProvenanceSchema, c as MathExpressionSchema, d as MathNormalisationContext, f as MathNormalisationContextSchema, g as MathPresentationSchema, h as MathPresentation, i as ExactRationalSchema, j as MathUnit, k as MathUncertainty, l as MathMatrix, m as MathNumSchema, n as DimensionVectorSchema, o as MathAppSchema, p as MathNum, r as ExactRational, s as MathExpression, t as DimensionVector, u as MathMatrixSchema, v as MathProdSchema, w as MathSumSchema, x as MathQty, y as MathProvenance, z as isMathExpression } from "./math-B7gZJeND.js";
2
+ export { DimensionVector, DimensionVectorSchema, ExactRational, ExactRationalSchema, MathApp, MathAppSchema, MathExpression, MathExpressionSchema, MathMatrix, MathMatrixSchema, MathNormalisationContext, MathNormalisationContextSchema, MathNum, MathNumSchema, MathPresentation, MathPresentationSchema, MathProd, MathProdSchema, MathProvenance, MathProvenanceSchema, MathQty, MathQtySchema, MathSum, MathSumSchema, MathSym, MathSymSchema, MathSymbolEntry, MathSymbolEntrySchema, MathUncertainty, MathUncertaintySchema, MathUnit, MathUnitSchema, MathUnparsed, MathUnparsedSchema, SI_BASE_DIMENSIONS, SiBaseDimension, SymbolTable, SymbolTableSchema, isMathExpression };