@danielsimonjr/mathts-core 0.15.5 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-L5MWGOLB.js → chunk-YS7US6LQ.js} +4657 -5388
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +225 -133
- package/dist/internal.js +2 -2
- package/dist/types/si-dimension-vector.d.ts +58 -0
- package/dist/types/si-dimension-vector.d.ts.map +1 -0
- package/dist/types/unit/Unit.d.ts.map +1 -1
- package/dist/types/unit/exact-scale.d.ts +65 -0
- package/dist/types/unit/exact-scale.d.ts.map +1 -0
- package/dist/types/unit/index.d.ts +4 -0
- package/dist/types/unit/index.d.ts.map +1 -1
- package/dist/types/unit/unit-table.d.ts +100 -0
- package/dist/types/unit/unit-table.d.ts.map +1 -0
- package/dist/types/unit/unit-types.d.ts +12 -3
- package/dist/types/unit/unit-types.d.ts.map +1 -1
- package/dist/types/unit-definitions.d.ts +4 -0
- package/dist/types/unit-definitions.d.ts.map +1 -1
- package/dist/types/unit-prefixes.d.ts +4 -2
- package/dist/types/unit-prefixes.d.ts.map +1 -1
- package/dist/types/unit.d.ts +4 -0
- package/dist/types/unit.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export { addScalar, subtractScalar, multiplyScalar, divideScalar, pow, abs, fix,
|
|
|
17
17
|
export type { NumericScalar } from './arithmetic/scalar.js';
|
|
18
18
|
export { Unit, isUnit as isUnitValue, DimensionMismatchError, UnitParseError, DIMENSIONLESS, dim, } from './types/unit.js';
|
|
19
19
|
export type { Dimensions, UnitDef, UnitInstance } from './types/unit.js';
|
|
20
|
+
export { UNIT_EXACT_SCALE, PI_EXACT_SCALE, decimalExactScale, exactScaleOf, binaryExactScale, ratioExactScale, multiplyExactScales, divideExactScales, powerExactScale, addExactScales, exactScalesEqual, exactScaleToNumber, formatExactScale, readScaleExpression, NAMED_SCALES, UNIT_ROWS, UNIT_ROW_ALIASES, namedExactScale, readUnitScale, getUnitRow, unitRowExactScale, unitRowValue, unitRowExactOffset, UNIT_PREFIX_SETS, unitPrefixExactScale, getUnitPrefix, } from './types/unit.js';
|
|
21
|
+
export type { ExactScale, UnitRow, UnitBaseKey, UnitPrefixSetKey, UnitPrefix, } from './types/unit.js';
|
|
22
|
+
export { UNIT_DIMENSION_LENGTH, SI_DIMENSION_LENGTH, toSiDimensions, toSiDimensionVector, fromSiDimensions, fromSiDimensionVector, } from './types/unit.js';
|
|
23
|
+
export type { SiDimensionVector, SiDimensionOptions } from './types/unit.js';
|
|
20
24
|
export { BASE_UNITS, DERIVED_UNITS, ALL_UNITS, UNIT_ALIASES, getUnitDef, } from './types/unit-definitions.js';
|
|
21
25
|
export { SI_PREFIXES, BEST_PREFIXES, getPrefix } from './types/unit-prefixes.js';
|
|
22
26
|
export { mathTyped, createMathTSTyped, typed, create, createTypedFunction, TypeRegistry, MATHTS_TYPES, MATHTS_CONVERSIONS, isNumber, isBoolean, isString, isBigInt, isArray, isFunction, isObject, isNull, isUndefined, isMatrix, isDenseMatrix, isSparseMatrix, isUnit, initTypedWasm, isTypedWasmAvailable, registerNativeTypes, } from './typed/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,YAAY,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,OAAO,EACP,SAAS,EACT,CAAC,EACD,YAAY,EACZ,WAAW,EACX,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC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AAS,EACT,YAAY,EACZ,UAAU,GACX,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAMjF,OAAO,EAEL,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,MAAM,EACN,mBAAmB,EACnB,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAGlB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,WAAW,EAGX,QAAQ,EACR,aAAa,EACb,cAAc,EAGd,MAAM,EAGN,aAAa,EACb,oBAAoB,EAGpB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAW5B,eAAO,MAAM,OAAO,EAAE,MAAwB,CAAC;AAI/C,OAAO,EACL,WAAW,EACX,WAAW,EACX,KAAK,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,YAAY,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,WAAW,EACX,aAAa,EACb,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,OAAO,EACP,SAAS,EACT,CAAC,EACD,YAAY,EACZ,WA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AAY,EACV,aAAa,EACb,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAW5B,eAAO,MAAM,OAAO,EAAE,MAAwB,CAAC;AAI/C,OAAO,EACL,WAAW,EACX,WAAW,EACX,KAAK,EACL,WAAW,EACX,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -21,30 +21,56 @@ import {
|
|
|
21
21
|
FRACTION_ZERO,
|
|
22
22
|
Fraction,
|
|
23
23
|
I,
|
|
24
|
+
NAMED_SCALES,
|
|
25
|
+
PI_EXACT_SCALE,
|
|
26
|
+
UNIT_EXACT_SCALE,
|
|
27
|
+
UNIT_PREFIX_SETS,
|
|
28
|
+
UNIT_ROWS,
|
|
29
|
+
UNIT_ROW_ALIASES,
|
|
24
30
|
Unit,
|
|
25
31
|
UnitParseError,
|
|
26
32
|
abs,
|
|
33
|
+
addExactScales,
|
|
27
34
|
addScalar,
|
|
35
|
+
binaryExactScale,
|
|
36
|
+
decimalExactScale,
|
|
37
|
+
divideExactScales,
|
|
28
38
|
divideScalar,
|
|
29
39
|
equal,
|
|
40
|
+
exactScaleOf,
|
|
41
|
+
exactScaleToNumber,
|
|
42
|
+
exactScalesEqual,
|
|
30
43
|
factory,
|
|
31
44
|
fix,
|
|
32
45
|
format,
|
|
46
|
+
formatExactScale,
|
|
47
|
+
getUnitPrefix,
|
|
48
|
+
getUnitRow,
|
|
33
49
|
isBigInt,
|
|
34
50
|
isBigNumber,
|
|
35
51
|
isBigNumber2,
|
|
36
|
-
isComplex,
|
|
52
|
+
isComplex2 as isComplex,
|
|
37
53
|
isFraction2 as isFraction,
|
|
38
54
|
isNumeric,
|
|
39
55
|
isUnit,
|
|
56
|
+
multiplyExactScales,
|
|
40
57
|
multiplyScalar,
|
|
58
|
+
namedExactScale,
|
|
41
59
|
nearlyEqual,
|
|
42
60
|
number,
|
|
43
61
|
pow,
|
|
62
|
+
powerExactScale,
|
|
63
|
+
ratioExactScale,
|
|
64
|
+
readScaleExpression,
|
|
65
|
+
readUnitScale,
|
|
44
66
|
round,
|
|
45
67
|
sign,
|
|
46
|
-
subtractScalar
|
|
47
|
-
|
|
68
|
+
subtractScalar,
|
|
69
|
+
unitPrefixExactScale,
|
|
70
|
+
unitRowExactOffset,
|
|
71
|
+
unitRowExactScale,
|
|
72
|
+
unitRowValue
|
|
73
|
+
} from "./chunk-YS7US6LQ.js";
|
|
48
74
|
|
|
49
75
|
// src/types/matrix/Range.ts
|
|
50
76
|
var name = "Range";
|
|
@@ -530,116 +556,99 @@ var BASE_UNITS = {
|
|
|
530
556
|
mol: { multiplier: 1, dimensions: dim({ amount: 1 }), prefixable: true },
|
|
531
557
|
cd: { multiplier: 1, dimensions: dim({ luminosity: 1 }), prefixable: true }
|
|
532
558
|
};
|
|
559
|
+
function tableUnit(name2, dimensions, prefixable) {
|
|
560
|
+
const row = getUnitRow(name2);
|
|
561
|
+
if (row === void 0) throw new Error(`unit-definitions: '${name2}' is not in the unit table`);
|
|
562
|
+
const scale = readUnitScale(row.scale);
|
|
563
|
+
const def = { multiplier: exactScaleToNumber(scale), dimensions };
|
|
564
|
+
if (row.offset !== void 0) {
|
|
565
|
+
def.offset = exactScaleToNumber(multiplyExactScales(scale, readUnitScale(row.offset)));
|
|
566
|
+
}
|
|
567
|
+
if (prefixable) def.prefixable = true;
|
|
568
|
+
return def;
|
|
569
|
+
}
|
|
533
570
|
var DERIVED_UNITS = {
|
|
534
571
|
// --- Length ---------------------------------------------------------------
|
|
535
572
|
// Note: 'm' is a base unit (above), already prefixable.
|
|
536
|
-
ft:
|
|
537
|
-
foot:
|
|
538
|
-
in:
|
|
539
|
-
inch:
|
|
540
|
-
yd:
|
|
541
|
-
yard:
|
|
542
|
-
mi:
|
|
543
|
-
mile:
|
|
573
|
+
ft: tableUnit("ft", dim({ length: 1 })),
|
|
574
|
+
foot: tableUnit("foot", dim({ length: 1 })),
|
|
575
|
+
in: tableUnit("in", dim({ length: 1 })),
|
|
576
|
+
inch: tableUnit("inch", dim({ length: 1 })),
|
|
577
|
+
yd: tableUnit("yd", dim({ length: 1 })),
|
|
578
|
+
yard: tableUnit("yard", dim({ length: 1 })),
|
|
579
|
+
mi: tableUnit("mi", dim({ length: 1 })),
|
|
580
|
+
mile: tableUnit("mile", dim({ length: 1 })),
|
|
544
581
|
// --- Mass -----------------------------------------------------------------
|
|
545
582
|
// The "g" entry is gram (0.001 kg). It is prefixable, so kg/mg/µg work via
|
|
546
583
|
// prefix application on this entry rather than the base "kg".
|
|
547
|
-
g:
|
|
548
|
-
lb:
|
|
549
|
-
lbm:
|
|
550
|
-
oz:
|
|
551
|
-
ton:
|
|
584
|
+
g: tableUnit("g", dim({ mass: 1 }), true),
|
|
585
|
+
lb: tableUnit("lb", dim({ mass: 1 })),
|
|
586
|
+
lbm: tableUnit("lbm", dim({ mass: 1 })),
|
|
587
|
+
oz: tableUnit("oz", dim({ mass: 1 })),
|
|
588
|
+
ton: tableUnit("ton", dim({ mass: 1 })),
|
|
552
589
|
// US short ton
|
|
553
|
-
tonne:
|
|
590
|
+
tonne: tableUnit("tonne", dim({ mass: 1 })),
|
|
554
591
|
// metric ton
|
|
555
592
|
// --- Time -----------------------------------------------------------------
|
|
556
|
-
min:
|
|
557
|
-
h:
|
|
558
|
-
hr:
|
|
559
|
-
day:
|
|
560
|
-
week:
|
|
561
|
-
year:
|
|
593
|
+
min: tableUnit("min", dim({ time: 1 })),
|
|
594
|
+
h: tableUnit("h", dim({ time: 1 })),
|
|
595
|
+
hr: tableUnit("hr", dim({ time: 1 })),
|
|
596
|
+
day: tableUnit("day", dim({ time: 1 })),
|
|
597
|
+
week: tableUnit("week", dim({ time: 1 })),
|
|
598
|
+
year: tableUnit("year", dim({ time: 1 })),
|
|
562
599
|
// Julian year
|
|
563
600
|
// --- Temperature ----------------------------------------------------------
|
|
564
601
|
// K is the base.
|
|
565
602
|
// °C → K is offset by 273.15 (no multiplicative factor change).
|
|
566
603
|
// °F → K is more complex (offset & scale).
|
|
567
|
-
degC:
|
|
568
|
-
degF:
|
|
569
|
-
degR:
|
|
604
|
+
degC: tableUnit("degC", dim({ temperature: 1 })),
|
|
605
|
+
degF: tableUnit("degF", dim({ temperature: 1 })),
|
|
606
|
+
degR: tableUnit("degR", dim({ temperature: 1 })),
|
|
570
607
|
// Rankine
|
|
571
608
|
// --- Plane angle (dimensionless, but often treated as units) --------------
|
|
572
|
-
rad:
|
|
573
|
-
deg:
|
|
574
|
-
grad:
|
|
609
|
+
rad: tableUnit("rad", dim({}), true),
|
|
610
|
+
deg: tableUnit("deg", dim({})),
|
|
611
|
+
grad: tableUnit("grad", dim({})),
|
|
575
612
|
// --- Force ----------------------------------------------------------------
|
|
576
613
|
// N = kg·m·s^-2 = 1 kg·m·s^-2; in our base-units representation that's
|
|
577
614
|
// value=1, dim {length: 1, mass: 1, time: -2}.
|
|
578
|
-
N:
|
|
579
|
-
dyn:
|
|
580
|
-
lbf:
|
|
615
|
+
N: tableUnit("N", dim({ length: 1, mass: 1, time: -2 }), true),
|
|
616
|
+
dyn: tableUnit("dyn", dim({ length: 1, mass: 1, time: -2 })),
|
|
617
|
+
lbf: tableUnit("lbf", dim({ length: 1, mass: 1, time: -2 })),
|
|
581
618
|
// --- Energy ---------------------------------------------------------------
|
|
582
|
-
J:
|
|
583
|
-
erg:
|
|
584
|
-
cal:
|
|
585
|
-
eV: {
|
|
586
|
-
|
|
587
|
-
dimensions: dim({ length: 2, mass: 1, time: -2 }),
|
|
588
|
-
prefixable: true
|
|
589
|
-
},
|
|
590
|
-
BTU: { multiplier: 1055.05585262, dimensions: dim({ length: 2, mass: 1, time: -2 }) },
|
|
619
|
+
J: tableUnit("J", dim({ length: 2, mass: 1, time: -2 }), true),
|
|
620
|
+
erg: tableUnit("erg", dim({ length: 2, mass: 1, time: -2 })),
|
|
621
|
+
cal: tableUnit("cal", dim({ length: 2, mass: 1, time: -2 })),
|
|
622
|
+
eV: tableUnit("eV", dim({ length: 2, mass: 1, time: -2 }), true),
|
|
623
|
+
BTU: tableUnit("BTU", dim({ length: 2, mass: 1, time: -2 })),
|
|
591
624
|
// --- Power ----------------------------------------------------------------
|
|
592
|
-
W:
|
|
593
|
-
hp:
|
|
625
|
+
W: tableUnit("W", dim({ length: 2, mass: 1, time: -3 }), true),
|
|
626
|
+
hp: tableUnit("hp", dim({ length: 2, mass: 1, time: -3 })),
|
|
594
627
|
// --- Pressure -------------------------------------------------------------
|
|
595
|
-
Pa:
|
|
596
|
-
bar:
|
|
597
|
-
atm:
|
|
598
|
-
psi:
|
|
599
|
-
torr:
|
|
600
|
-
mmHg:
|
|
628
|
+
Pa: tableUnit("Pa", dim({ length: -1, mass: 1, time: -2 }), true),
|
|
629
|
+
bar: tableUnit("bar", dim({ length: -1, mass: 1, time: -2 }), true),
|
|
630
|
+
atm: tableUnit("atm", dim({ length: -1, mass: 1, time: -2 })),
|
|
631
|
+
psi: tableUnit("psi", dim({ length: -1, mass: 1, time: -2 })),
|
|
632
|
+
torr: tableUnit("torr", dim({ length: -1, mass: 1, time: -2 })),
|
|
633
|
+
mmHg: tableUnit("mmHg", dim({ length: -1, mass: 1, time: -2 })),
|
|
601
634
|
// --- Electric -------------------------------------------------------------
|
|
602
|
-
C: {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
},
|
|
607
|
-
|
|
608
|
-
multiplier: 1,
|
|
609
|
-
dimensions: dim({ length: 2, mass: 1, time: -3, current: -1 }),
|
|
610
|
-
prefixable: true
|
|
611
|
-
},
|
|
612
|
-
ohm: {
|
|
613
|
-
multiplier: 1,
|
|
614
|
-
dimensions: dim({ length: 2, mass: 1, time: -3, current: -2 }),
|
|
615
|
-
prefixable: true
|
|
616
|
-
},
|
|
617
|
-
\u03A9: {
|
|
618
|
-
multiplier: 1,
|
|
619
|
-
dimensions: dim({ length: 2, mass: 1, time: -3, current: -2 }),
|
|
620
|
-
prefixable: true
|
|
621
|
-
},
|
|
622
|
-
F: {
|
|
623
|
-
multiplier: 1,
|
|
624
|
-
dimensions: dim({ length: -2, mass: -1, time: 4, current: 2 }),
|
|
625
|
-
prefixable: true
|
|
626
|
-
},
|
|
627
|
-
H: {
|
|
628
|
-
multiplier: 1,
|
|
629
|
-
dimensions: dim({ length: 2, mass: 1, time: -2, current: -2 }),
|
|
630
|
-
prefixable: true
|
|
631
|
-
},
|
|
635
|
+
C: tableUnit("C", dim({ time: 1, current: 1 }), true),
|
|
636
|
+
V: tableUnit("V", dim({ length: 2, mass: 1, time: -3, current: -1 }), true),
|
|
637
|
+
ohm: tableUnit("ohm", dim({ length: 2, mass: 1, time: -3, current: -2 }), true),
|
|
638
|
+
\u03A9: tableUnit("ohm", dim({ length: 2, mass: 1, time: -3, current: -2 }), true),
|
|
639
|
+
F: tableUnit("F", dim({ length: -2, mass: -1, time: 4, current: 2 }), true),
|
|
640
|
+
H: tableUnit("H", dim({ length: 2, mass: 1, time: -2, current: -2 }), true),
|
|
632
641
|
// --- Frequency ------------------------------------------------------------
|
|
633
|
-
Hz:
|
|
642
|
+
Hz: tableUnit("Hz", dim({ time: -1 }), true),
|
|
634
643
|
// --- Volume ---------------------------------------------------------------
|
|
635
|
-
L:
|
|
636
|
-
l:
|
|
637
|
-
gal:
|
|
644
|
+
L: tableUnit("L", dim({ length: 3 }), true),
|
|
645
|
+
l: tableUnit("l", dim({ length: 3 }), true),
|
|
646
|
+
gal: tableUnit("gal", dim({ length: 3 })),
|
|
638
647
|
// US gallon
|
|
639
648
|
// --- Area -----------------------------------------------------------------
|
|
640
|
-
ha:
|
|
649
|
+
ha: tableUnit("hectare", dim({ length: 2 })),
|
|
641
650
|
// hectare
|
|
642
|
-
acre:
|
|
651
|
+
acre: tableUnit("acre", dim({ length: 2 }))
|
|
643
652
|
};
|
|
644
653
|
var ALL_UNITS = { ...BASE_UNITS, ...DERIVED_UNITS };
|
|
645
654
|
var UNIT_ALIASES = {
|
|
@@ -653,53 +662,104 @@ function getUnitDef(name2) {
|
|
|
653
662
|
return ALL_UNITS[name2];
|
|
654
663
|
}
|
|
655
664
|
|
|
665
|
+
// src/types/si-dimension-vector.ts
|
|
666
|
+
var UNIT_DIMENSION_LENGTH = 10;
|
|
667
|
+
var SI_DIMENSION_LENGTH = 7;
|
|
668
|
+
var EXTRA_INDEXES = [7, 8, 9];
|
|
669
|
+
function assertFinite(label, value) {
|
|
670
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
671
|
+
throw new TypeError(`${label} must be a finite number`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function assertUnitVector(vector) {
|
|
675
|
+
if (vector.length !== UNIT_DIMENSION_LENGTH) {
|
|
676
|
+
throw new TypeError(`dimension vector must have length ${UNIT_DIMENSION_LENGTH}`);
|
|
677
|
+
}
|
|
678
|
+
for (let i = 0; i < vector.length; i++) {
|
|
679
|
+
assertFinite(`dimension vector[${i}]`, vector[i]);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function rejectExtra(vector, options) {
|
|
683
|
+
if (options?.ignoreExtra) return;
|
|
684
|
+
for (const index of EXTRA_INDEXES) {
|
|
685
|
+
if (vector[index] !== 0) {
|
|
686
|
+
throw new RangeError(
|
|
687
|
+
`dimension vector has a nonzero angle, bit, or solid-angle exponent at index ${index}; pass { ignoreExtra: true } to drop it`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function toSiDimensions(vector, options) {
|
|
693
|
+
assertUnitVector(vector);
|
|
694
|
+
rejectExtra(vector, options);
|
|
695
|
+
return {
|
|
696
|
+
length: vector[1],
|
|
697
|
+
mass: vector[0],
|
|
698
|
+
time: vector[2],
|
|
699
|
+
current: vector[3],
|
|
700
|
+
temperature: vector[4],
|
|
701
|
+
amount: vector[6],
|
|
702
|
+
luminosity: vector[5]
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function toSiDimensionVector(vector, options) {
|
|
706
|
+
const d = toSiDimensions(vector, options);
|
|
707
|
+
return [d.length, d.mass, d.time, d.current, d.temperature, d.amount, d.luminosity];
|
|
708
|
+
}
|
|
709
|
+
function fromSiDimensions(dimensions) {
|
|
710
|
+
const fields = [
|
|
711
|
+
["mass", dimensions.mass],
|
|
712
|
+
["length", dimensions.length],
|
|
713
|
+
["time", dimensions.time],
|
|
714
|
+
["current", dimensions.current],
|
|
715
|
+
["temperature", dimensions.temperature],
|
|
716
|
+
["luminosity", dimensions.luminosity],
|
|
717
|
+
["amount", dimensions.amount]
|
|
718
|
+
];
|
|
719
|
+
for (const [name2, value] of fields) {
|
|
720
|
+
assertFinite(`dimensions.${name2}`, value);
|
|
721
|
+
}
|
|
722
|
+
return [
|
|
723
|
+
dimensions.mass,
|
|
724
|
+
dimensions.length,
|
|
725
|
+
dimensions.time,
|
|
726
|
+
dimensions.current,
|
|
727
|
+
dimensions.temperature,
|
|
728
|
+
dimensions.luminosity,
|
|
729
|
+
dimensions.amount,
|
|
730
|
+
0,
|
|
731
|
+
0,
|
|
732
|
+
0
|
|
733
|
+
];
|
|
734
|
+
}
|
|
735
|
+
function fromSiDimensionVector(vector) {
|
|
736
|
+
if (vector.length !== SI_DIMENSION_LENGTH) {
|
|
737
|
+
throw new TypeError(
|
|
738
|
+
`SI dimension vector must have length ${SI_DIMENSION_LENGTH} [L, M, T, I, \u0398, N, J]`
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
return fromSiDimensions({
|
|
742
|
+
length: vector[0],
|
|
743
|
+
mass: vector[1],
|
|
744
|
+
time: vector[2],
|
|
745
|
+
current: vector[3],
|
|
746
|
+
temperature: vector[4],
|
|
747
|
+
amount: vector[5],
|
|
748
|
+
luminosity: vector[6]
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
|
|
656
752
|
// src/types/unit-prefixes.ts
|
|
657
|
-
var SI_PREFIXES = {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
T: 1e12,
|
|
668
|
-
// tera
|
|
669
|
-
G: 1e9,
|
|
670
|
-
// giga
|
|
671
|
-
M: 1e6,
|
|
672
|
-
// mega
|
|
673
|
-
k: 1e3,
|
|
674
|
-
// kilo
|
|
675
|
-
h: 100,
|
|
676
|
-
// hecto
|
|
677
|
-
da: 10,
|
|
678
|
-
// deka (two-letter)
|
|
679
|
-
// Negative powers of ten
|
|
680
|
-
d: 0.1,
|
|
681
|
-
// deci
|
|
682
|
-
c: 0.01,
|
|
683
|
-
// centi
|
|
684
|
-
m: 1e-3,
|
|
685
|
-
// milli
|
|
686
|
-
u: 1e-6,
|
|
687
|
-
// micro (ASCII fallback)
|
|
688
|
-
\u00B5: 1e-6,
|
|
689
|
-
// micro (Unicode)
|
|
690
|
-
n: 1e-9,
|
|
691
|
-
// nano
|
|
692
|
-
p: 1e-12,
|
|
693
|
-
// pico
|
|
694
|
-
f: 1e-15,
|
|
695
|
-
// femto
|
|
696
|
-
a: 1e-18,
|
|
697
|
-
// atto
|
|
698
|
-
z: 1e-21,
|
|
699
|
-
// zepto
|
|
700
|
-
y: 1e-24
|
|
701
|
-
// yocto
|
|
702
|
-
};
|
|
753
|
+
var SI_PREFIXES = (() => {
|
|
754
|
+
const prefixes = {};
|
|
755
|
+
const short = UNIT_PREFIX_SETS.SHORT;
|
|
756
|
+
for (const name2 of Object.keys(short)) {
|
|
757
|
+
if (name2 === "") continue;
|
|
758
|
+
prefixes[name2] = exactScaleToNumber(unitPrefixExactScale(short[name2]));
|
|
759
|
+
}
|
|
760
|
+
prefixes["\xB5"] = prefixes.u;
|
|
761
|
+
return prefixes;
|
|
762
|
+
})();
|
|
703
763
|
var BEST_PREFIXES = [
|
|
704
764
|
"Y",
|
|
705
765
|
"Z",
|
|
@@ -1386,7 +1446,7 @@ function neumaierCumsum(xs, out) {
|
|
|
1386
1446
|
}
|
|
1387
1447
|
|
|
1388
1448
|
// src/index.ts
|
|
1389
|
-
var VERSION = "0.
|
|
1449
|
+
var VERSION = "0.17.0";
|
|
1390
1450
|
export {
|
|
1391
1451
|
ALL_UNITS,
|
|
1392
1452
|
BASE_UNITS,
|
|
@@ -1426,31 +1486,51 @@ export {
|
|
|
1426
1486
|
LOG2E,
|
|
1427
1487
|
MATHTS_CONVERSIONS,
|
|
1428
1488
|
MATHTS_TYPES,
|
|
1489
|
+
NAMED_SCALES,
|
|
1429
1490
|
PHI,
|
|
1430
1491
|
PI,
|
|
1492
|
+
PI_EXACT_SCALE,
|
|
1431
1493
|
Range,
|
|
1494
|
+
SI_DIMENSION_LENGTH,
|
|
1432
1495
|
SI_PREFIXES,
|
|
1433
1496
|
SQRT1_2,
|
|
1434
1497
|
SQRT2,
|
|
1435
1498
|
TAU,
|
|
1436
1499
|
TypeRegistry,
|
|
1437
1500
|
UNIT_ALIASES,
|
|
1501
|
+
UNIT_DIMENSION_LENGTH,
|
|
1502
|
+
UNIT_EXACT_SCALE,
|
|
1503
|
+
UNIT_PREFIX_SETS,
|
|
1504
|
+
UNIT_ROWS,
|
|
1505
|
+
UNIT_ROW_ALIASES,
|
|
1438
1506
|
Unit,
|
|
1439
1507
|
UnitParseError,
|
|
1440
1508
|
VERSION,
|
|
1441
1509
|
abs,
|
|
1510
|
+
addExactScales,
|
|
1442
1511
|
addScalar,
|
|
1512
|
+
binaryExactScale,
|
|
1443
1513
|
create,
|
|
1444
1514
|
createFactory,
|
|
1445
1515
|
createMathTSTyped,
|
|
1446
1516
|
createRangeClass,
|
|
1447
1517
|
createTypedFunction,
|
|
1518
|
+
decimalExactScale,
|
|
1448
1519
|
dim,
|
|
1520
|
+
divideExactScales,
|
|
1449
1521
|
divideScalar,
|
|
1450
1522
|
equal,
|
|
1523
|
+
exactScaleOf,
|
|
1524
|
+
exactScaleToNumber,
|
|
1525
|
+
exactScalesEqual,
|
|
1451
1526
|
fix,
|
|
1527
|
+
formatExactScale,
|
|
1528
|
+
fromSiDimensionVector,
|
|
1529
|
+
fromSiDimensions,
|
|
1452
1530
|
getPrefix,
|
|
1453
1531
|
getUnitDef,
|
|
1532
|
+
getUnitPrefix,
|
|
1533
|
+
getUnitRow,
|
|
1454
1534
|
initTypedWasm,
|
|
1455
1535
|
isArray,
|
|
1456
1536
|
isBigInt2 as isBigInt,
|
|
@@ -1474,7 +1554,9 @@ export {
|
|
|
1474
1554
|
isUnit as isUnitValue,
|
|
1475
1555
|
math,
|
|
1476
1556
|
mathTyped,
|
|
1557
|
+
multiplyExactScales,
|
|
1477
1558
|
multiplyScalar,
|
|
1559
|
+
namedExactScale,
|
|
1478
1560
|
neumaierCumsum,
|
|
1479
1561
|
neumaierSum,
|
|
1480
1562
|
norm2,
|
|
@@ -1482,11 +1564,21 @@ export {
|
|
|
1482
1564
|
pairwiseDot,
|
|
1483
1565
|
pairwiseSum,
|
|
1484
1566
|
pow,
|
|
1567
|
+
powerExactScale,
|
|
1568
|
+
ratioExactScale,
|
|
1569
|
+
readScaleExpression,
|
|
1570
|
+
readUnitScale,
|
|
1485
1571
|
registerNativeTypes,
|
|
1486
1572
|
registry,
|
|
1487
1573
|
round,
|
|
1488
1574
|
scaledDistance,
|
|
1489
1575
|
subtractScalar,
|
|
1490
1576
|
sumSquaredDeviations,
|
|
1491
|
-
|
|
1577
|
+
toSiDimensionVector,
|
|
1578
|
+
toSiDimensions,
|
|
1579
|
+
typed,
|
|
1580
|
+
unitPrefixExactScale,
|
|
1581
|
+
unitRowExactOffset,
|
|
1582
|
+
unitRowExactScale,
|
|
1583
|
+
unitRowValue
|
|
1492
1584
|
};
|
package/dist/internal.js
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
isBigNumber,
|
|
30
30
|
isBoolean,
|
|
31
31
|
isCollection,
|
|
32
|
-
|
|
32
|
+
isComplex,
|
|
33
33
|
isDate,
|
|
34
34
|
isDenseMatrix,
|
|
35
35
|
isFactory,
|
|
@@ -78,7 +78,7 @@ import {
|
|
|
78
78
|
typeOf,
|
|
79
79
|
unitDependencies,
|
|
80
80
|
warnOnce
|
|
81
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-YS7US6LQ.js";
|
|
82
82
|
|
|
83
83
|
// src/error/DimensionError.ts
|
|
84
84
|
var DimensionError = class _DimensionError extends RangeError {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert between the length-10 unit exponent vector and the 7 SI base
|
|
3
|
+
* dimensions.
|
|
4
|
+
*
|
|
5
|
+
* `Unit` stores exponents in this order (see `BASE_DIMENSIONS` in
|
|
6
|
+
* `types/unit/Unit.ts`):
|
|
7
|
+
*
|
|
8
|
+
* 0 MASS, 1 LENGTH, 2 TIME, 3 CURRENT, 4 TEMPERATURE,
|
|
9
|
+
* 5 LUMINOUS_INTENSITY, 6 AMOUNT_OF_SUBSTANCE,
|
|
10
|
+
* 7 ANGLE, 8 BIT, 9 SOLID_ANGLE
|
|
11
|
+
*
|
|
12
|
+
* The 7-vector used by dimensional analysis (BIPM base quantities, and the
|
|
13
|
+
* order UPT's Buckingham routine uses) is
|
|
14
|
+
*
|
|
15
|
+
* [L, M, T, I, Θ, N, J]
|
|
16
|
+
*
|
|
17
|
+
* Angle, bit, and solid angle have no place in that vector. Conversion
|
|
18
|
+
* throws when any of those three exponents is nonzero, unless
|
|
19
|
+
* `ignoreExtra` is set.
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
import type { Dimensions } from './unit-definitions.js';
|
|
24
|
+
/** Length of a `Unit` exponent vector. */
|
|
25
|
+
export declare const UNIT_DIMENSION_LENGTH = 10;
|
|
26
|
+
/** Length of the SI base-dimension tuple `[L, M, T, I, Θ, N, J]`. */
|
|
27
|
+
export declare const SI_DIMENSION_LENGTH = 7;
|
|
28
|
+
/**
|
|
29
|
+
* SI base-dimension tuple in the order length, mass, time, current,
|
|
30
|
+
* temperature, amount, luminosity.
|
|
31
|
+
*/
|
|
32
|
+
export type SiDimensionVector = readonly [number, number, number, number, number, number, number];
|
|
33
|
+
/** Options for {@link toSiDimensions} and {@link toSiDimensionVector}. */
|
|
34
|
+
export interface SiDimensionOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Drop nonzero angle, bit, and solid-angle exponents instead of throwing.
|
|
37
|
+
* They are not represented in the 7-vector.
|
|
38
|
+
*/
|
|
39
|
+
ignoreExtra?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Map a length-10 unit exponent vector onto the {@link Dimensions} record.
|
|
43
|
+
*/
|
|
44
|
+
export declare function toSiDimensions(vector: readonly number[], options?: SiDimensionOptions): Dimensions;
|
|
45
|
+
/**
|
|
46
|
+
* Map a length-10 unit exponent vector onto `[L, M, T, I, Θ, N, J]`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function toSiDimensionVector(vector: readonly number[], options?: SiDimensionOptions): SiDimensionVector;
|
|
49
|
+
/**
|
|
50
|
+
* Map a {@link Dimensions} record onto a length-10 unit exponent vector.
|
|
51
|
+
* Angle, bit, and solid angle are zero.
|
|
52
|
+
*/
|
|
53
|
+
export declare function fromSiDimensions(dimensions: Dimensions): number[];
|
|
54
|
+
/**
|
|
55
|
+
* Map `[L, M, T, I, Θ, N, J]` onto a length-10 unit exponent vector.
|
|
56
|
+
*/
|
|
57
|
+
export declare function fromSiDimensionVector(vector: readonly number[]): number[];
|
|
58
|
+
//# sourceMappingURL=si-dimension-vector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"si-dimension-vector.d.ts","sourceRoot":"","sources":["../../src/types/si-dimension-vector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,0CAA0C;AAC1C,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAElG,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA8BD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,UAAU,CAYZ;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,iBAAiB,CAGnB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE,CAyBjE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAezE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Unit.d.ts","sourceRoot":"","sources":["../../../src/types/unit/Unit.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAcV,eAAe,EAQhB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Unit.d.ts","sourceRoot":"","sources":["../../../src/types/unit/Unit.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAcV,eAAe,EAQhB,MAAM,iBAAiB,CAAC;AAoGzB,eAAO,MAAM,eAAe,6DA67E3B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact unit scales.
|
|
3
|
+
*
|
|
4
|
+
* A unit's scale to SI is a rational number times an integer power of π:
|
|
5
|
+
* `num / den × π^pi`. Products, quotients and integer powers stay exact, so a
|
|
6
|
+
* scale is rounded to a double once, at the end, by {@link exactScaleToNumber}.
|
|
7
|
+
* `psi` stated as `lbf/inch^2` is therefore the double nearest
|
|
8
|
+
* 0.45359237 × 9.80665 / 0.0254², not the result of three rounded float steps.
|
|
9
|
+
*
|
|
10
|
+
* A decimal literal (`'0.0254'`, `'1.602176634e-19'`) is read digit for digit.
|
|
11
|
+
* A JavaScript number is read through its shortest round-trip decimal
|
|
12
|
+
* (`String(x)`), which is the literal it was written as.
|
|
13
|
+
*
|
|
14
|
+
* Scale expressions (the form the unit table states its rows in) are factors
|
|
15
|
+
* joined by `*`, optionally followed by one `/` and the denominator's factors.
|
|
16
|
+
* Each factor is a decimal literal, `pi`, or a named scale, with an optional
|
|
17
|
+
* integer power `^n`. Everything after the first `/` is the denominator
|
|
18
|
+
* (ISO 80000-1 single-solidus reading): `a/b*c` is a/(b·c).
|
|
19
|
+
*
|
|
20
|
+
* @module @danielsimonjr/mathts-core/types/unit/exact-scale
|
|
21
|
+
*/
|
|
22
|
+
/** `num / den × π^pi`, with `den > 0`, the fraction in lowest terms, and `pi` an integer. */
|
|
23
|
+
export interface ExactScale {
|
|
24
|
+
readonly num: bigint;
|
|
25
|
+
readonly den: bigint;
|
|
26
|
+
/** The integer power of π (1 for `deg = pi/180`, -1 for the parsec, 0 for a rational scale). */
|
|
27
|
+
readonly pi: number;
|
|
28
|
+
}
|
|
29
|
+
/** The scale 1. */
|
|
30
|
+
export declare const UNIT_EXACT_SCALE: ExactScale;
|
|
31
|
+
/** π itself, as a scale. */
|
|
32
|
+
export declare const PI_EXACT_SCALE: ExactScale;
|
|
33
|
+
/** The exact value of a decimal literal, or null when `text` is not one. */
|
|
34
|
+
export declare function decimalExactScale(text: string): ExactScale | null;
|
|
35
|
+
/** The exact decimal a finite JavaScript number prints as (its shortest round-trip form). */
|
|
36
|
+
export declare function exactScaleOf(x: number): ExactScale;
|
|
37
|
+
/**
|
|
38
|
+
* The exact binary value of a finite double (`0.1` is 3602879701896397 / 2^55).
|
|
39
|
+
* This is the value a computed double holds, where {@link exactScaleOf} reads
|
|
40
|
+
* the decimal a typed number was meant as.
|
|
41
|
+
*/
|
|
42
|
+
export declare function binaryExactScale(x: number): ExactScale;
|
|
43
|
+
/** `num / den`, exactly. */
|
|
44
|
+
export declare function ratioExactScale(num: number | bigint, den?: number | bigint): ExactScale;
|
|
45
|
+
/** `a × b × …`. */
|
|
46
|
+
export declare function multiplyExactScales(...factors: readonly ExactScale[]): ExactScale;
|
|
47
|
+
/** `a / b`. */
|
|
48
|
+
export declare function divideExactScales(a: ExactScale, b: ExactScale): ExactScale;
|
|
49
|
+
/** `a ^ n` for an integer `n`. A fractional power has no exact form and throws. */
|
|
50
|
+
export declare function powerExactScale(a: ExactScale, n: number): ExactScale;
|
|
51
|
+
/** Whether two exact scales are the same number. */
|
|
52
|
+
export declare function exactScalesEqual(a: ExactScale, b: ExactScale): boolean;
|
|
53
|
+
/** `a + b`, when both carry the same power of π; null otherwise (π is transcendental). */
|
|
54
|
+
export declare function addExactScales(a: ExactScale, b: ExactScale): ExactScale | null;
|
|
55
|
+
/** The scale as a double, rounded once. */
|
|
56
|
+
export declare function exactScaleToNumber(s: ExactScale): number;
|
|
57
|
+
/** The scale as text: `num/den`, with `*pi^k` when π is a factor. For messages and tests. */
|
|
58
|
+
export declare function formatExactScale(s: ExactScale): string;
|
|
59
|
+
/**
|
|
60
|
+
* The exact value of a scale expression (`'lbf/inch^2'`, `'648000*astronomical_unit/pi'`,
|
|
61
|
+
* `'101325/760'`). `resolve` gives a name its scale and returns undefined for a
|
|
62
|
+
* name it does not know, which throws here. `pi` always means π.
|
|
63
|
+
*/
|
|
64
|
+
export declare function readScaleExpression(text: string, resolve?: (name: string) => ExactScale | undefined): ExactScale;
|
|
65
|
+
//# sourceMappingURL=exact-scale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exact-scale.d.ts","sourceRoot":"","sources":["../../../src/types/unit/exact-scale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6FAA6F;AAC7F,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAmBD,mBAAmB;AACnB,eAAO,MAAM,gBAAgB,EAAE,UAAuD,CAAC;AAEvF,4BAA4B;AAC5B,eAAO,MAAM,cAAc,EAAE,UAAuD,CAAC;AAIrF,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAajE;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAGlD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAetD;AAED,4BAA4B;AAC5B,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAE,MAAM,GAAG,MAAW,GAAG,UAAU,CAE3F;AAED,mBAAmB;AACnB,wBAAgB,mBAAmB,CAAC,GAAG,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAUjF;AAED,eAAe;AACf,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAG1E;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAKpE;AAED,oDAAoD;AACpD,wBAAgB,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