web-music-score 0.0.1 → 6.0.0-pre.1
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/CHANGELOG.md +200 -0
- package/LICENSE +62 -1
- package/README.md +46 -2
- package/dist/audio/index.d.ts +50 -0
- package/dist/audio/index.js +1858 -0
- package/dist/audio/index.mjs +92 -0
- package/dist/audio-cg/index.d.ts +21 -0
- package/dist/audio-cg/index.js +17568 -0
- package/dist/audio-cg/index.mjs +90 -0
- package/dist/audio-synth/index.d.ts +15 -0
- package/dist/audio-synth/index.js +18497 -0
- package/dist/audio-synth/index.mjs +63 -0
- package/dist/chunk-A7C2G7OG.mjs +101 -0
- package/dist/chunk-GNT3ECDB.mjs +267 -0
- package/dist/chunk-LO4NI4AU.mjs +18381 -0
- package/dist/chunk-PW2SO6EZ.mjs +37 -0
- package/dist/chunk-VHB57TXT.mjs +11 -0
- package/dist/chunk-X7BMJX7E.mjs +3867 -0
- package/dist/core/index.d.ts +31 -0
- package/dist/core/index.js +74 -0
- package/dist/core/index.mjs +22 -0
- package/dist/iife/audio-cg.global.js +220 -0
- package/dist/iife/index.global.js +228 -0
- package/dist/instrument-DS-9C6_8.d.ts +44 -0
- package/dist/music-objects-DLmp5uL6.d.ts +2398 -0
- package/dist/note-RVXvpfyV.d.ts +306 -0
- package/dist/pieces/index.d.ts +46 -0
- package/dist/pieces/index.js +79 -0
- package/dist/pieces/index.mjs +50 -0
- package/dist/react-ui/index.d.ts +86 -0
- package/dist/react-ui/index.js +132 -0
- package/dist/react-ui/index.mjs +96 -0
- package/dist/scale-B1M10_fu.d.ts +230 -0
- package/dist/score/index.d.ts +466 -0
- package/dist/score/index.js +13964 -0
- package/dist/score/index.mjs +10092 -0
- package/dist/tempo-D-JF-8b_.d.ts +409 -0
- package/dist/theory/index.d.ts +78 -0
- package/dist/theory/index.js +4842 -0
- package/dist/theory/index.mjs +1986 -0
- package/package.json +131 -3
- package/workspace.code-workspace +0 -9
|
@@ -0,0 +1,4842 @@
|
|
|
1
|
+
/* WebMusicScore v6.0.0-pre.1 | (c) 2023-2025 Stefan Brockmann | MIT License | Includes: Tone.js (MIT License), Color Name to Code (MIT License) */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3);
|
|
25
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
26
|
+
var __await = function(promise, isYieldStar) {
|
|
27
|
+
this[0] = promise;
|
|
28
|
+
this[1] = isYieldStar;
|
|
29
|
+
};
|
|
30
|
+
var __yieldStar = (value) => {
|
|
31
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
32
|
+
if (obj == null) {
|
|
33
|
+
obj = value[__knownSymbol("iterator")]();
|
|
34
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
35
|
+
} else {
|
|
36
|
+
obj = obj.call(value);
|
|
37
|
+
method = (k) => it[k] = (v) => {
|
|
38
|
+
if (isAwait) {
|
|
39
|
+
isAwait = false;
|
|
40
|
+
if (k === "throw") throw v;
|
|
41
|
+
return v;
|
|
42
|
+
}
|
|
43
|
+
isAwait = true;
|
|
44
|
+
return {
|
|
45
|
+
done: false,
|
|
46
|
+
value: new __await(new Promise((resolve) => {
|
|
47
|
+
var x = obj[k](v);
|
|
48
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
49
|
+
resolve(x);
|
|
50
|
+
}), 1)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
55
|
+
throw x;
|
|
56
|
+
}, "return" in obj && method("return"), it;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/theory/index.ts
|
|
60
|
+
var theory_exports = {};
|
|
61
|
+
__export(theory_exports, {
|
|
62
|
+
AccidentalType: () => AccidentalType,
|
|
63
|
+
BeamGrouping: () => BeamGrouping,
|
|
64
|
+
Chord: () => Chord,
|
|
65
|
+
DefaultGuitarNoteLabel: () => DefaultGuitarNoteLabel,
|
|
66
|
+
DefaultPitchNotation: () => DefaultPitchNotation,
|
|
67
|
+
DefaultTuningName: () => DefaultTuningName,
|
|
68
|
+
GuitarNoteLabel: () => GuitarNoteLabel,
|
|
69
|
+
GuitarNoteLabelList: () => GuitarNoteLabelList,
|
|
70
|
+
Interval: () => Interval,
|
|
71
|
+
KeySignature: () => KeySignature,
|
|
72
|
+
Mode: () => Mode,
|
|
73
|
+
Note: () => Note,
|
|
74
|
+
NoteLength: () => NoteLength,
|
|
75
|
+
NoteLengthProps: () => NoteLengthProps,
|
|
76
|
+
PitchNotation: () => PitchNotation,
|
|
77
|
+
PitchNotationList: () => PitchNotationList,
|
|
78
|
+
RhythmProps: () => RhythmProps,
|
|
79
|
+
Scale: () => Scale,
|
|
80
|
+
ScaleFactory: () => ScaleFactory,
|
|
81
|
+
ScaleType: () => ScaleType,
|
|
82
|
+
SymbolSet: () => SymbolSet,
|
|
83
|
+
TimeSignature: () => TimeSignature,
|
|
84
|
+
TimeSignatures: () => TimeSignatures,
|
|
85
|
+
TuningNameList: () => TuningNameList,
|
|
86
|
+
Tuplet: () => Tuplet,
|
|
87
|
+
alterTempoSpeed: () => alterTempoSpeed,
|
|
88
|
+
getDefaultKeySignature: () => getDefaultKeySignature,
|
|
89
|
+
getDefaultScale: () => getDefaultScale,
|
|
90
|
+
getDefaultTempo: () => getDefaultTempo,
|
|
91
|
+
getDefaultTimeSignature: () => getDefaultTimeSignature,
|
|
92
|
+
getPitchNotationName: () => getPitchNotationName,
|
|
93
|
+
getScale: () => getScale,
|
|
94
|
+
getScaleFactory: () => getScaleFactory,
|
|
95
|
+
getScaleFactoryList: () => getScaleFactoryList,
|
|
96
|
+
getTempoString: () => getTempoString,
|
|
97
|
+
getTuningStrings: () => getTuningStrings,
|
|
98
|
+
isNoteLength: () => isNoteLength,
|
|
99
|
+
isTupletRatio: () => isTupletRatio,
|
|
100
|
+
validateGuitarNoteLabel: () => validateGuitarNoteLabel,
|
|
101
|
+
validateIntervalQuality: () => validateIntervalQuality,
|
|
102
|
+
validateNoteLength: () => validateNoteLength,
|
|
103
|
+
validatePitchNotation: () => validatePitchNotation,
|
|
104
|
+
validateScaleType: () => validateScaleType,
|
|
105
|
+
validateTuningName: () => validateTuningName,
|
|
106
|
+
validateTupletRatio: () => validateTupletRatio
|
|
107
|
+
});
|
|
108
|
+
module.exports = __toCommonJS(theory_exports);
|
|
109
|
+
|
|
110
|
+
// node_modules/@tspro/ts-utils-lib/dist/index.mjs
|
|
111
|
+
var __defProp2 = Object.defineProperty;
|
|
112
|
+
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
113
|
+
var __export2 = (target, all) => {
|
|
114
|
+
for (var name in all)
|
|
115
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
116
|
+
};
|
|
117
|
+
var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
118
|
+
var assert_exports = {};
|
|
119
|
+
__export2(assert_exports, {
|
|
120
|
+
assert: () => assert,
|
|
121
|
+
doesNotThrow: () => doesNotThrow2,
|
|
122
|
+
doesThrow: () => doesThrow2,
|
|
123
|
+
fail: () => fail,
|
|
124
|
+
isArray: () => isArray2,
|
|
125
|
+
isArrayOrUndefined: () => isArrayOrUndefined2,
|
|
126
|
+
isBigInt: () => isBigInt2,
|
|
127
|
+
isBoolean: () => isBoolean2,
|
|
128
|
+
isBooleanOrUndefined: () => isBooleanOrUndefined2,
|
|
129
|
+
isDeepEqual: () => isDeepEqual2,
|
|
130
|
+
isDefined: () => isDefined2,
|
|
131
|
+
isEmptyArray: () => isEmptyArray2,
|
|
132
|
+
isEmptyArrayOrUndefined: () => isEmptyArrayOrUndefined2,
|
|
133
|
+
isEmptyObject: () => isEmptyObject2,
|
|
134
|
+
isEmptyString: () => isEmptyString2,
|
|
135
|
+
isEmptyStringOrUndefined: () => isEmptyStringOrUndefined2,
|
|
136
|
+
isEnumValue: () => isEnumValue2,
|
|
137
|
+
isEnumValueOrUndefined: () => isEnumValueOrUndefined2,
|
|
138
|
+
isEven: () => isEven2,
|
|
139
|
+
isFalse: () => isFalse2,
|
|
140
|
+
isFalseOrUndefined: () => isFalseOrUndefined2,
|
|
141
|
+
isFinite: () => isFinite3,
|
|
142
|
+
isFloat: () => isFloat2,
|
|
143
|
+
isFunction: () => isFunction2,
|
|
144
|
+
isFunctionOrUndefined: () => isFunctionOrUndefined2,
|
|
145
|
+
isIncluded: () => isIncluded2,
|
|
146
|
+
isIndex: () => isIndex2,
|
|
147
|
+
isInfinity: () => isInfinity2,
|
|
148
|
+
isInteger: () => isInteger2,
|
|
149
|
+
isIntegerBetween: () => isIntegerBetween2,
|
|
150
|
+
isIntegerBetweenExclusive: () => isIntegerBetweenExclusive2,
|
|
151
|
+
isIntegerEq: () => isIntegerEq2,
|
|
152
|
+
isIntegerGt: () => isIntegerGt2,
|
|
153
|
+
isIntegerGte: () => isIntegerGte2,
|
|
154
|
+
isIntegerLt: () => isIntegerLt2,
|
|
155
|
+
isIntegerLte: () => isIntegerLte2,
|
|
156
|
+
isIntegerOrUndefined: () => isIntegerOrUndefined2,
|
|
157
|
+
isMultipleOf: () => isMultipleOf2,
|
|
158
|
+
isNaNValue: () => isNaNValue2,
|
|
159
|
+
isNeg: () => isNeg2,
|
|
160
|
+
isNegInfinity: () => isNegInfinity2,
|
|
161
|
+
isNegZero: () => isNegZero2,
|
|
162
|
+
isNonEmptyArray: () => isNonEmptyArray2,
|
|
163
|
+
isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined2,
|
|
164
|
+
isNonEmptyString: () => isNonEmptyString2,
|
|
165
|
+
isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined2,
|
|
166
|
+
isNonNeg: () => isNonNeg2,
|
|
167
|
+
isNonNull: () => isNonNull2,
|
|
168
|
+
isNonPos: () => isNonPos2,
|
|
169
|
+
isNull: () => isNull2,
|
|
170
|
+
isNullish: () => isNullish2,
|
|
171
|
+
isNumber: () => isNumber2,
|
|
172
|
+
isNumberBetween: () => isNumberBetween2,
|
|
173
|
+
isNumberBetweenExclusive: () => isNumberBetweenExclusive2,
|
|
174
|
+
isNumberEq: () => isNumberEq2,
|
|
175
|
+
isNumberGt: () => isNumberGt2,
|
|
176
|
+
isNumberGte: () => isNumberGte2,
|
|
177
|
+
isNumberLt: () => isNumberLt2,
|
|
178
|
+
isNumberLte: () => isNumberLte2,
|
|
179
|
+
isNumberOrUndefined: () => isNumberOrUndefined2,
|
|
180
|
+
isNumericString: () => isNumericString2,
|
|
181
|
+
isObject: () => isObject2,
|
|
182
|
+
isObjectOrUndefined: () => isObjectOrUndefined2,
|
|
183
|
+
isOdd: () => isOdd2,
|
|
184
|
+
isPlainObject: () => isPlainObject2,
|
|
185
|
+
isPos: () => isPos2,
|
|
186
|
+
isPosInfinity: () => isPosInfinity2,
|
|
187
|
+
isPosZero: () => isPosZero2,
|
|
188
|
+
isPowerOfTwo: () => isPowerOfTwo2,
|
|
189
|
+
isSafeInteger: () => isSafeInteger2,
|
|
190
|
+
isSafeNumber: () => isSafeNumber2,
|
|
191
|
+
isStrictEqual: () => isStrictEqual2,
|
|
192
|
+
isString: () => isString2,
|
|
193
|
+
isStringOrUndefined: () => isStringOrUndefined2,
|
|
194
|
+
isTrue: () => isTrue2,
|
|
195
|
+
isTrueOrUndefined: () => isTrueOrUndefined2,
|
|
196
|
+
isTypedObject: () => isTypedObject2,
|
|
197
|
+
isUndefined: () => isUndefined2,
|
|
198
|
+
isZero: () => isZero2,
|
|
199
|
+
require: () => require2,
|
|
200
|
+
requireDefined: () => requireDefined,
|
|
201
|
+
requireElement: () => requireElement,
|
|
202
|
+
setErrorClass: () => setErrorClass
|
|
203
|
+
});
|
|
204
|
+
var str_exports = {};
|
|
205
|
+
__export2(str_exports, {
|
|
206
|
+
charCount: () => charCount,
|
|
207
|
+
chunkString: () => chunkString,
|
|
208
|
+
insertAt: () => insertAt,
|
|
209
|
+
isString: () => isString,
|
|
210
|
+
makeSentenceFromPascal: () => makeSentenceFromPascal,
|
|
211
|
+
removeAt: () => removeAt,
|
|
212
|
+
repeatString: () => repeatString,
|
|
213
|
+
replaceAt: () => replaceAt,
|
|
214
|
+
splitByCaps: () => splitByCaps,
|
|
215
|
+
splitByChars: () => splitByChars,
|
|
216
|
+
splitByStrings: () => splitByStrings,
|
|
217
|
+
stringify: () => stringify,
|
|
218
|
+
toCharArray: () => toCharArray
|
|
219
|
+
});
|
|
220
|
+
var obj_exports = {};
|
|
221
|
+
__export2(obj_exports, {
|
|
222
|
+
deepEqual: () => deepEqual,
|
|
223
|
+
getCtorName: () => getCtorName,
|
|
224
|
+
hasProperties: () => hasProperties,
|
|
225
|
+
isObject: () => isObject
|
|
226
|
+
});
|
|
227
|
+
var guard_exports = {};
|
|
228
|
+
__export2(guard_exports, {
|
|
229
|
+
doesNotThrow: () => doesNotThrow,
|
|
230
|
+
doesThrow: () => doesThrow,
|
|
231
|
+
isArray: () => isArray,
|
|
232
|
+
isArrayOrUndefined: () => isArrayOrUndefined,
|
|
233
|
+
isBigInt: () => isBigInt,
|
|
234
|
+
isBoolean: () => isBoolean,
|
|
235
|
+
isBooleanOrUndefined: () => isBooleanOrUndefined,
|
|
236
|
+
isDeepEqual: () => isDeepEqual,
|
|
237
|
+
isDefined: () => isDefined,
|
|
238
|
+
isEmptyArray: () => isEmptyArray,
|
|
239
|
+
isEmptyArrayOrUndefined: () => isEmptyArrayOrUndefined,
|
|
240
|
+
isEmptyObject: () => isEmptyObject,
|
|
241
|
+
isEmptyString: () => isEmptyString,
|
|
242
|
+
isEmptyStringOrUndefined: () => isEmptyStringOrUndefined,
|
|
243
|
+
isEnumValue: () => isEnumValue,
|
|
244
|
+
isEnumValueOrUndefined: () => isEnumValueOrUndefined,
|
|
245
|
+
isEven: () => isEven,
|
|
246
|
+
isFalse: () => isFalse,
|
|
247
|
+
isFalseOrUndefined: () => isFalseOrUndefined,
|
|
248
|
+
isFinite: () => isFinite2,
|
|
249
|
+
isFloat: () => isFloat,
|
|
250
|
+
isFunction: () => isFunction,
|
|
251
|
+
isFunctionOrUndefined: () => isFunctionOrUndefined,
|
|
252
|
+
isIncluded: () => isIncluded,
|
|
253
|
+
isIndex: () => isIndex,
|
|
254
|
+
isInfinity: () => isInfinity,
|
|
255
|
+
isInteger: () => isInteger,
|
|
256
|
+
isIntegerBetween: () => isIntegerBetween,
|
|
257
|
+
isIntegerBetweenExclusive: () => isIntegerBetweenExclusive,
|
|
258
|
+
isIntegerEq: () => isIntegerEq,
|
|
259
|
+
isIntegerGt: () => isIntegerGt,
|
|
260
|
+
isIntegerGte: () => isIntegerGte,
|
|
261
|
+
isIntegerLt: () => isIntegerLt,
|
|
262
|
+
isIntegerLte: () => isIntegerLte,
|
|
263
|
+
isIntegerOrUndefined: () => isIntegerOrUndefined,
|
|
264
|
+
isMultipleOf: () => isMultipleOf,
|
|
265
|
+
isNaNValue: () => isNaNValue,
|
|
266
|
+
isNeg: () => isNeg,
|
|
267
|
+
isNegInfinity: () => isNegInfinity,
|
|
268
|
+
isNegZero: () => isNegZero,
|
|
269
|
+
isNonEmptyArray: () => isNonEmptyArray,
|
|
270
|
+
isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
|
|
271
|
+
isNonEmptyString: () => isNonEmptyString,
|
|
272
|
+
isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
|
|
273
|
+
isNonNeg: () => isNonNeg,
|
|
274
|
+
isNonNull: () => isNonNull,
|
|
275
|
+
isNonPos: () => isNonPos,
|
|
276
|
+
isNull: () => isNull,
|
|
277
|
+
isNullish: () => isNullish,
|
|
278
|
+
isNumber: () => isNumber,
|
|
279
|
+
isNumberBetween: () => isNumberBetween,
|
|
280
|
+
isNumberBetweenExclusive: () => isNumberBetweenExclusive,
|
|
281
|
+
isNumberEq: () => isNumberEq,
|
|
282
|
+
isNumberGt: () => isNumberGt,
|
|
283
|
+
isNumberGte: () => isNumberGte,
|
|
284
|
+
isNumberLt: () => isNumberLt,
|
|
285
|
+
isNumberLte: () => isNumberLte,
|
|
286
|
+
isNumberOrUndefined: () => isNumberOrUndefined,
|
|
287
|
+
isNumericString: () => isNumericString,
|
|
288
|
+
isObject: () => isObject,
|
|
289
|
+
isObjectOrUndefined: () => isObjectOrUndefined,
|
|
290
|
+
isOdd: () => isOdd,
|
|
291
|
+
isPlainObject: () => isPlainObject,
|
|
292
|
+
isPos: () => isPos,
|
|
293
|
+
isPosInfinity: () => isPosInfinity,
|
|
294
|
+
isPosZero: () => isPosZero,
|
|
295
|
+
isPowerOfTwo: () => isPowerOfTwo,
|
|
296
|
+
isSafeInteger: () => isSafeInteger,
|
|
297
|
+
isSafeNumber: () => isSafeNumber,
|
|
298
|
+
isStrictEqual: () => isStrictEqual,
|
|
299
|
+
isString: () => isString,
|
|
300
|
+
isStringOrUndefined: () => isStringOrUndefined,
|
|
301
|
+
isTrue: () => isTrue,
|
|
302
|
+
isTrueOrUndefined: () => isTrueOrUndefined,
|
|
303
|
+
isTypedObject: () => isTypedObject,
|
|
304
|
+
isUndefined: () => isUndefined,
|
|
305
|
+
isZero: () => isZero,
|
|
306
|
+
tryOr: () => tryOr
|
|
307
|
+
});
|
|
308
|
+
var enum_exports = {};
|
|
309
|
+
__export2(enum_exports, {
|
|
310
|
+
forEachEnum: () => forEachEnum,
|
|
311
|
+
getEnumEntries: () => getEnumEntries,
|
|
312
|
+
getEnumKey: () => getEnumKey,
|
|
313
|
+
getEnumKeys: () => getEnumKeys,
|
|
314
|
+
getEnumValues: () => getEnumValues
|
|
315
|
+
});
|
|
316
|
+
function getEnumKeys(e) {
|
|
317
|
+
return Object.keys(e).filter((k) => isNaN(Number(k)));
|
|
318
|
+
}
|
|
319
|
+
function getEnumValues(e) {
|
|
320
|
+
return getEnumKeys(e).map((k) => e[k]);
|
|
321
|
+
}
|
|
322
|
+
function getEnumEntries(e) {
|
|
323
|
+
return getEnumKeys(e).map((k) => [k, e[k]]);
|
|
324
|
+
}
|
|
325
|
+
function getEnumKey(e, value) {
|
|
326
|
+
return getEnumKeys(e).find((k) => e[k] === value);
|
|
327
|
+
}
|
|
328
|
+
function forEachEnum(e, callback) {
|
|
329
|
+
for (const [k, v] of getEnumEntries(e)) callback(k, v);
|
|
330
|
+
}
|
|
331
|
+
function isStrictEqual(val1, val2) {
|
|
332
|
+
return val1 === val2;
|
|
333
|
+
}
|
|
334
|
+
function isDeepEqual(val1, val2) {
|
|
335
|
+
return deepEqual(val1, val2);
|
|
336
|
+
}
|
|
337
|
+
function isUndefined(val) {
|
|
338
|
+
return val === void 0;
|
|
339
|
+
}
|
|
340
|
+
function isNull(val) {
|
|
341
|
+
return val === null;
|
|
342
|
+
}
|
|
343
|
+
function isNullish(val) {
|
|
344
|
+
return val === void 0 || val === null;
|
|
345
|
+
}
|
|
346
|
+
function isDefined(val) {
|
|
347
|
+
return val !== void 0;
|
|
348
|
+
}
|
|
349
|
+
function isNonNull(val) {
|
|
350
|
+
return val !== null;
|
|
351
|
+
}
|
|
352
|
+
function isObject(val) {
|
|
353
|
+
return typeof val === "object" && val !== null && !isArray(val);
|
|
354
|
+
}
|
|
355
|
+
function isEmptyObject(val) {
|
|
356
|
+
return isObject(val) && Object.keys(val).length === 0;
|
|
357
|
+
}
|
|
358
|
+
function isObjectOrUndefined(val) {
|
|
359
|
+
return val === void 0 || isObject(val);
|
|
360
|
+
}
|
|
361
|
+
function isPlainObject(val) {
|
|
362
|
+
if (!isObject(val)) return false;
|
|
363
|
+
const proto = Object.getPrototypeOf(val);
|
|
364
|
+
return proto === Object.prototype || proto === null;
|
|
365
|
+
}
|
|
366
|
+
function isTypedObject(val, keys) {
|
|
367
|
+
return isObject(val) && keys.every((k) => k in val);
|
|
368
|
+
}
|
|
369
|
+
function isSet(val) {
|
|
370
|
+
return val instanceof Set;
|
|
371
|
+
}
|
|
372
|
+
function isArray(arr) {
|
|
373
|
+
return !!arr && Object.prototype.toString.call(arr) === "[object Array]";
|
|
374
|
+
}
|
|
375
|
+
function isArrayOrUndefined(arr) {
|
|
376
|
+
return arr === void 0 || isArray(arr);
|
|
377
|
+
}
|
|
378
|
+
function isEmptyArray(arr) {
|
|
379
|
+
return isArray(arr) && arr.length === 0;
|
|
380
|
+
}
|
|
381
|
+
function isNonEmptyArray(arr) {
|
|
382
|
+
return isArray(arr) && arr.length > 0;
|
|
383
|
+
}
|
|
384
|
+
function isEmptyArrayOrUndefined(arr) {
|
|
385
|
+
return isArray(arr) && arr.length === 0 || arr === void 0;
|
|
386
|
+
}
|
|
387
|
+
function isNonEmptyArrayOrUndefined(arr) {
|
|
388
|
+
return isArray(arr) && arr.length > 0 || arr === void 0;
|
|
389
|
+
}
|
|
390
|
+
function isString(val) {
|
|
391
|
+
return typeof val === "string";
|
|
392
|
+
}
|
|
393
|
+
function isEmptyString(val) {
|
|
394
|
+
return typeof val === "string" && val.length === 0;
|
|
395
|
+
}
|
|
396
|
+
function isNonEmptyString(val) {
|
|
397
|
+
return typeof val === "string" && val.length > 0;
|
|
398
|
+
}
|
|
399
|
+
function isStringOrUndefined(val) {
|
|
400
|
+
return val === void 0 || typeof val === "string";
|
|
401
|
+
}
|
|
402
|
+
function isEmptyStringOrUndefined(val) {
|
|
403
|
+
return typeof val === "string" && val.length === 0 || val === void 0;
|
|
404
|
+
}
|
|
405
|
+
function isNonEmptyStringOrUndefined(val) {
|
|
406
|
+
return typeof val === "string" && val.length > 0 || val === void 0;
|
|
407
|
+
}
|
|
408
|
+
function isBoolean(val) {
|
|
409
|
+
return typeof val === "boolean";
|
|
410
|
+
}
|
|
411
|
+
function isBooleanOrUndefined(val) {
|
|
412
|
+
return val === void 0 || typeof val === "boolean";
|
|
413
|
+
}
|
|
414
|
+
function isTrue(val) {
|
|
415
|
+
return val === true;
|
|
416
|
+
}
|
|
417
|
+
function isTrueOrUndefined(val) {
|
|
418
|
+
return val === true || val === void 0;
|
|
419
|
+
}
|
|
420
|
+
function isFalse(val) {
|
|
421
|
+
return val === false;
|
|
422
|
+
}
|
|
423
|
+
function isFalseOrUndefined(val) {
|
|
424
|
+
return val === false || val === void 0;
|
|
425
|
+
}
|
|
426
|
+
function isFunction(val) {
|
|
427
|
+
return typeof val === "function";
|
|
428
|
+
}
|
|
429
|
+
function isFunctionOrUndefined(val) {
|
|
430
|
+
return val === void 0 || typeof val === "function";
|
|
431
|
+
}
|
|
432
|
+
function isEnumValue(val, enumObj) {
|
|
433
|
+
return getEnumValues(enumObj).some((v) => v === val);
|
|
434
|
+
}
|
|
435
|
+
function isEnumValueOrUndefined(val, enumObj) {
|
|
436
|
+
return val === void 0 || getEnumValues(enumObj).some((v) => v === val);
|
|
437
|
+
}
|
|
438
|
+
function isNumericString(val) {
|
|
439
|
+
if (typeof val !== "string" || val.trim() === "") return false;
|
|
440
|
+
const n = +val;
|
|
441
|
+
return Number.isFinite(n);
|
|
442
|
+
}
|
|
443
|
+
function isBigInt(val) {
|
|
444
|
+
return typeof val === "bigint";
|
|
445
|
+
}
|
|
446
|
+
function isNumber(val) {
|
|
447
|
+
return typeof val === "number";
|
|
448
|
+
}
|
|
449
|
+
function isSafeNumber(val) {
|
|
450
|
+
return isNumber(val) && Number.isSafeInteger(val);
|
|
451
|
+
}
|
|
452
|
+
function isNumberOrUndefined(val) {
|
|
453
|
+
return typeof val === "number" || val === void 0;
|
|
454
|
+
}
|
|
455
|
+
function isNumberEq(val, ref) {
|
|
456
|
+
return isNumber(val) && val === ref;
|
|
457
|
+
}
|
|
458
|
+
function isNumberGt(val, ref) {
|
|
459
|
+
return isNumber(val) && isNumber(ref) && val > ref;
|
|
460
|
+
}
|
|
461
|
+
function isNumberGte(val, ref) {
|
|
462
|
+
return isNumber(val) && isNumber(ref) && val >= ref;
|
|
463
|
+
}
|
|
464
|
+
function isNumberLt(val, ref) {
|
|
465
|
+
return isNumber(val) && isNumber(ref) && val < ref;
|
|
466
|
+
}
|
|
467
|
+
function isNumberLte(val, ref) {
|
|
468
|
+
return isNumber(val) && isNumber(ref) && val <= ref;
|
|
469
|
+
}
|
|
470
|
+
function isNumberBetween(val, min, max) {
|
|
471
|
+
return isNumber(val) && isNumber(min) && isNumber(max) && val >= min && val <= max;
|
|
472
|
+
}
|
|
473
|
+
function isNumberBetweenExclusive(val, min, max) {
|
|
474
|
+
return isNumber(val) && isNumber(min) && isNumber(max) && val > min && val < max;
|
|
475
|
+
}
|
|
476
|
+
function isFinite2(val) {
|
|
477
|
+
return typeof val === "number" && Number.isFinite(val);
|
|
478
|
+
}
|
|
479
|
+
function isFloat(val) {
|
|
480
|
+
return isFinite2(val) && !isInteger(val);
|
|
481
|
+
}
|
|
482
|
+
function isInteger(val) {
|
|
483
|
+
return typeof val === "number" && isFinite2(val) && val === Math.trunc(val);
|
|
484
|
+
}
|
|
485
|
+
function isSafeInteger(val) {
|
|
486
|
+
return isInteger(val) && Number.isSafeInteger(val);
|
|
487
|
+
}
|
|
488
|
+
function isIntegerOrUndefined(val) {
|
|
489
|
+
return typeof val === "number" && isFinite2(val) && val === Math.trunc(val) || val === void 0;
|
|
490
|
+
}
|
|
491
|
+
function isIntegerEq(val, ref) {
|
|
492
|
+
return isInteger(val) && val === ref;
|
|
493
|
+
}
|
|
494
|
+
function isIntegerGt(val, ref) {
|
|
495
|
+
return isInteger(val) && isNumber(ref) && val > ref;
|
|
496
|
+
}
|
|
497
|
+
function isIntegerGte(val, ref) {
|
|
498
|
+
return isInteger(val) && isNumber(ref) && val >= ref;
|
|
499
|
+
}
|
|
500
|
+
function isIntegerLt(val, ref) {
|
|
501
|
+
return isInteger(val) && isNumber(ref) && val < ref;
|
|
502
|
+
}
|
|
503
|
+
function isIntegerLte(val, ref) {
|
|
504
|
+
return isInteger(val) && isNumber(ref) && val <= ref;
|
|
505
|
+
}
|
|
506
|
+
function isIntegerBetween(val, min, max) {
|
|
507
|
+
return isInteger(val) && isNumber(min) && isNumber(max) && val >= min && val <= max;
|
|
508
|
+
}
|
|
509
|
+
function isIntegerBetweenExclusive(val, min, max) {
|
|
510
|
+
return isInteger(val) && isNumber(min) && isNumber(max) && val > min && val < max;
|
|
511
|
+
}
|
|
512
|
+
function isNaNValue(val) {
|
|
513
|
+
return typeof val === "number" && Number.isNaN(val);
|
|
514
|
+
}
|
|
515
|
+
function isInfinity(val) {
|
|
516
|
+
return val === Infinity || val === -Infinity;
|
|
517
|
+
}
|
|
518
|
+
function isPosInfinity(val) {
|
|
519
|
+
return val === Infinity;
|
|
520
|
+
}
|
|
521
|
+
function isNegInfinity(val) {
|
|
522
|
+
return val === -Infinity;
|
|
523
|
+
}
|
|
524
|
+
function isPos(val) {
|
|
525
|
+
return typeof val === "number" && val > 0;
|
|
526
|
+
}
|
|
527
|
+
function isNeg(val) {
|
|
528
|
+
return typeof val === "number" && val < 0;
|
|
529
|
+
}
|
|
530
|
+
function isNonPos(val) {
|
|
531
|
+
return typeof val === "number" && val <= 0;
|
|
532
|
+
}
|
|
533
|
+
function isNonNeg(val) {
|
|
534
|
+
return typeof val === "number" && val >= 0;
|
|
535
|
+
}
|
|
536
|
+
function isZero(val) {
|
|
537
|
+
return typeof val === "number" && val === 0;
|
|
538
|
+
}
|
|
539
|
+
function isPosZero(val) {
|
|
540
|
+
return typeof val === "number" && val === 0 && 1 / val === Infinity;
|
|
541
|
+
}
|
|
542
|
+
function isNegZero(val) {
|
|
543
|
+
return typeof val === "number" && val === 0 && 1 / val === -Infinity;
|
|
544
|
+
}
|
|
545
|
+
function isOdd(val) {
|
|
546
|
+
return isInteger(val) && Math.abs(val) % 2 === 1;
|
|
547
|
+
}
|
|
548
|
+
function isEven(val) {
|
|
549
|
+
return isInteger(val) && val % 2 === 0;
|
|
550
|
+
}
|
|
551
|
+
function isMultipleOf(val, base) {
|
|
552
|
+
return typeof val === "number" && typeof base === "number" && val % base === 0;
|
|
553
|
+
}
|
|
554
|
+
function isPowerOfTwo(val) {
|
|
555
|
+
return isInteger(val) && val > 0 && (val & val - 1) === 0;
|
|
556
|
+
}
|
|
557
|
+
function isIncluded(val, container) {
|
|
558
|
+
if (isArray(container)) {
|
|
559
|
+
return container.includes(val);
|
|
560
|
+
}
|
|
561
|
+
if (isSet(container)) {
|
|
562
|
+
return container.has(val);
|
|
563
|
+
}
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
function isIndex(index, array) {
|
|
567
|
+
return isArray(array) ? isIntegerBetween(index, 0, array.length - 1) : isIntegerGte(index, 0);
|
|
568
|
+
}
|
|
569
|
+
function doesThrow(throwTestFn) {
|
|
570
|
+
try {
|
|
571
|
+
throwTestFn();
|
|
572
|
+
return false;
|
|
573
|
+
} catch (err) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function doesNotThrow(throwTestFn) {
|
|
578
|
+
try {
|
|
579
|
+
throwTestFn();
|
|
580
|
+
return true;
|
|
581
|
+
} catch (err) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function tryOr(tryFn, orVal) {
|
|
586
|
+
try {
|
|
587
|
+
return tryFn();
|
|
588
|
+
} catch (err) {
|
|
589
|
+
return isFunction(orVal) ? orVal() : orVal;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function hasProperties(obj, props) {
|
|
593
|
+
return isObject(obj) && props.every((p) => p in obj);
|
|
594
|
+
}
|
|
595
|
+
function deepEqual(a, b) {
|
|
596
|
+
if (a === b) return true;
|
|
597
|
+
if (a === null || b === null) return false;
|
|
598
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
599
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
600
|
+
if (a.length !== b.length) return false;
|
|
601
|
+
return a.every((val, i) => deepEqual(val, b[i]));
|
|
602
|
+
}
|
|
603
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
604
|
+
const keysA = Object.keys(a);
|
|
605
|
+
const keysB = Object.keys(b);
|
|
606
|
+
if (keysA.length !== keysB.length) return false;
|
|
607
|
+
for (const key of keysA) {
|
|
608
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
609
|
+
if (!deepEqual(a[key], b[key])) return false;
|
|
610
|
+
}
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
613
|
+
function getCtorName(obj) {
|
|
614
|
+
if (obj === null) return "null";
|
|
615
|
+
if (isArray(obj)) return "Array";
|
|
616
|
+
if (typeof obj !== "object") return typeof obj;
|
|
617
|
+
const tag = Object.prototype.toString.call(obj).slice(8, -1);
|
|
618
|
+
return tag || "Object";
|
|
619
|
+
}
|
|
620
|
+
function toCharArray(str2) {
|
|
621
|
+
return str2.split("");
|
|
622
|
+
}
|
|
623
|
+
function repeatString(repeatString2, repeatCount) {
|
|
624
|
+
if (!isInteger(repeatCount) || repeatCount < 0) {
|
|
625
|
+
throw new Error("repeatStr: Invalid repeatCount = " + repeatCount);
|
|
626
|
+
}
|
|
627
|
+
return new Array(repeatCount + 1).join(repeatString2);
|
|
628
|
+
}
|
|
629
|
+
function chunkString(str2, chunkSize) {
|
|
630
|
+
if (!isInteger(chunkSize) || chunkSize < 1) {
|
|
631
|
+
throw new Error("chunckString: Invalid chuckSize = " + chunkSize);
|
|
632
|
+
}
|
|
633
|
+
let result = [];
|
|
634
|
+
for (let i = 0; i < str2.length; i += chunkSize) {
|
|
635
|
+
result.push(str2.slice(i, i + chunkSize));
|
|
636
|
+
}
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
function replaceAt(str2, pos, removeCount, insert) {
|
|
640
|
+
if (!isInteger(removeCount) || removeCount < 0) {
|
|
641
|
+
throw new Error("replaceAt: Invalid removeCount = " + removeCount);
|
|
642
|
+
} else if (!isInteger(pos) || pos < 0 || pos + removeCount > str2.length) {
|
|
643
|
+
throw new Error("replaceAt: Invalid pos = " + pos + ", removeCount = " + removeCount + ", str.length = " + str2.length);
|
|
644
|
+
} else {
|
|
645
|
+
return str2.substring(0, pos) + insert + str2.substring(pos + removeCount);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function insertAt(str2, pos, insertStr) {
|
|
649
|
+
return replaceAt(str2, pos, 0, insertStr);
|
|
650
|
+
}
|
|
651
|
+
function removeAt(str2, pos, removeCount) {
|
|
652
|
+
return replaceAt(str2, pos, removeCount, "");
|
|
653
|
+
}
|
|
654
|
+
function charCount(str2, ch) {
|
|
655
|
+
if (ch.length !== 1 || str2.length === 0) return 0;
|
|
656
|
+
let count = 0;
|
|
657
|
+
for (let i = 0; i < str2.length; i++) {
|
|
658
|
+
if (str2[i] === ch) count++;
|
|
659
|
+
}
|
|
660
|
+
return count;
|
|
661
|
+
}
|
|
662
|
+
function makeSentenceFromPascal(PascalString) {
|
|
663
|
+
if (PascalString === "") {
|
|
664
|
+
return "";
|
|
665
|
+
}
|
|
666
|
+
let word = PascalString.charAt(0);
|
|
667
|
+
let sentence = "";
|
|
668
|
+
const addWord = () => {
|
|
669
|
+
if (word !== "") {
|
|
670
|
+
if (sentence === "") {
|
|
671
|
+
sentence += word.charAt(0).toUpperCase() + word.substring(1);
|
|
672
|
+
} else {
|
|
673
|
+
sentence += " " + word;
|
|
674
|
+
}
|
|
675
|
+
word = "";
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
const isLetterAndCapital = (c) => {
|
|
679
|
+
return c.toUpperCase() !== c.toLowerCase() && c === c.toUpperCase();
|
|
680
|
+
};
|
|
681
|
+
for (let i = 1; i < PascalString.length; i++) {
|
|
682
|
+
let c = PascalString.charAt(i);
|
|
683
|
+
if (isLetterAndCapital(c)) {
|
|
684
|
+
addWord();
|
|
685
|
+
}
|
|
686
|
+
word += c.toLowerCase();
|
|
687
|
+
}
|
|
688
|
+
addWord();
|
|
689
|
+
return sentence;
|
|
690
|
+
}
|
|
691
|
+
function stringify(value, maxDepth = 5, seen = /* @__PURE__ */ new WeakSet()) {
|
|
692
|
+
if (value === null) return "null";
|
|
693
|
+
if (value === void 0) return "undefined";
|
|
694
|
+
const t = typeof value;
|
|
695
|
+
switch (t) {
|
|
696
|
+
case "boolean":
|
|
697
|
+
return value ? "true" : "false";
|
|
698
|
+
case "number":
|
|
699
|
+
if (isNaNValue(value)) return "NaN";
|
|
700
|
+
if (!isFinite2(value))
|
|
701
|
+
return value < 0 ? "-Infinity" : "Infinity";
|
|
702
|
+
return value.toString();
|
|
703
|
+
case "bigint":
|
|
704
|
+
return `${value}n`;
|
|
705
|
+
case "string":
|
|
706
|
+
return `"${value}"`;
|
|
707
|
+
case "symbol":
|
|
708
|
+
return value.description ? `Symbol(${value.description})` : "Symbol()";
|
|
709
|
+
case "function":
|
|
710
|
+
return `[Function${value.name ? ` ${value.name}` : ""}]`;
|
|
711
|
+
}
|
|
712
|
+
if (seen.has(value))
|
|
713
|
+
return "[Circular]";
|
|
714
|
+
if (maxDepth <= 0)
|
|
715
|
+
return "[Depth limit]";
|
|
716
|
+
maxDepth--;
|
|
717
|
+
seen.add(value);
|
|
718
|
+
const strfy = (v) => stringify(v, maxDepth, seen);
|
|
719
|
+
if (isArray(value)) {
|
|
720
|
+
const inner = value.map((v) => strfy(v)).join(", ");
|
|
721
|
+
return inner.length === 0 ? "[ ]" : `[ ${inner} ]`;
|
|
722
|
+
}
|
|
723
|
+
if (ArrayBuffer.isView(value)) {
|
|
724
|
+
if (value instanceof DataView)
|
|
725
|
+
return `DataView(${value.byteLength})`;
|
|
726
|
+
const inner = Array.from(value).map((v) => strfy(v)).join(", ");
|
|
727
|
+
return `${value.constructor.name}[ ${inner} ]`;
|
|
728
|
+
}
|
|
729
|
+
if (value instanceof ArrayBuffer)
|
|
730
|
+
return `ArrayBuffer(${value.byteLength})`;
|
|
731
|
+
if (value instanceof Map) {
|
|
732
|
+
const entries = Array.from(value.entries()).map(([k, v]) => `${strfy(k)} => ${strfy(v)}`).join(", ");
|
|
733
|
+
return entries.length === 0 ? `Map(${value.size}){ }` : `Map(${value.size}){ ${entries} }`;
|
|
734
|
+
}
|
|
735
|
+
if (value instanceof Set) {
|
|
736
|
+
const entries = Array.from(value.values()).map((v) => strfy(v)).join(", ");
|
|
737
|
+
return entries.length === 0 ? `Set(${value.size}){ }` : `Set(${value.size}){ ${entries} }`;
|
|
738
|
+
}
|
|
739
|
+
if (value instanceof WeakMap)
|
|
740
|
+
return "WeakMap{ ? }";
|
|
741
|
+
if (value instanceof WeakSet)
|
|
742
|
+
return "WeakSet{ ? }";
|
|
743
|
+
if (value instanceof Date)
|
|
744
|
+
return `Date("${value.toISOString()}")`;
|
|
745
|
+
if (value instanceof RegExp)
|
|
746
|
+
return value.toString();
|
|
747
|
+
if (value instanceof Error)
|
|
748
|
+
return `${value.name}("${value.message}")`;
|
|
749
|
+
if (value instanceof Promise)
|
|
750
|
+
return "Promise{ ? }";
|
|
751
|
+
if (value instanceof URL)
|
|
752
|
+
return `URL("${value.href}")`;
|
|
753
|
+
if (value instanceof URLSearchParams)
|
|
754
|
+
return `URLSearchParams("${value.toString()}")`;
|
|
755
|
+
if (value === Math) return "Math";
|
|
756
|
+
if (value === JSON) return "JSON";
|
|
757
|
+
if (value === Reflect) return "Reflect";
|
|
758
|
+
if (value === Intl) return "Intl";
|
|
759
|
+
const hasCustomToString = typeof (value == null ? void 0 : value.toString) === "function" && value.toString !== Object.prototype.toString;
|
|
760
|
+
if (hasCustomToString) {
|
|
761
|
+
try {
|
|
762
|
+
const str2 = value.toString();
|
|
763
|
+
if (!/^\[object .+\]$/.test(str2)) return str2;
|
|
764
|
+
} catch (e) {
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (t === "object") {
|
|
768
|
+
const ctorName = getCtorName(value);
|
|
769
|
+
const entries = Object.entries(value).map(
|
|
770
|
+
([key, val]) => `${strfy(key)}: ${strfy(val)}`
|
|
771
|
+
);
|
|
772
|
+
if (entries.length === 0) return `${ctorName}{ }`;
|
|
773
|
+
return `${ctorName}{ ${entries.join(", ")} }`;
|
|
774
|
+
}
|
|
775
|
+
return String(value);
|
|
776
|
+
}
|
|
777
|
+
function splitByCaps(str2) {
|
|
778
|
+
return str2.split(/(?=[A-Z])/).filter((x) => !!x);
|
|
779
|
+
}
|
|
780
|
+
function splitByStrings(str2, ...splitters) {
|
|
781
|
+
if (splitters.length === 0) return [str2];
|
|
782
|
+
const escaped = splitters.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
783
|
+
const regex = new RegExp(escaped.join("|"), "g");
|
|
784
|
+
return str2.split(regex);
|
|
785
|
+
}
|
|
786
|
+
function splitByChars(str2, splitters) {
|
|
787
|
+
return splitByStrings(str2, ...splitters.split(""));
|
|
788
|
+
}
|
|
789
|
+
var fmt = stringify;
|
|
790
|
+
var errorConstructor = Error;
|
|
791
|
+
function setErrorClass(errorClass) {
|
|
792
|
+
errorConstructor = errorClass != null ? errorClass : Error;
|
|
793
|
+
}
|
|
794
|
+
function _fail(...msgs) {
|
|
795
|
+
let msg = msgs.join(", ");
|
|
796
|
+
throw new errorConstructor("Assertion Failed!" + (msg === "" ? "" : " " + msg));
|
|
797
|
+
}
|
|
798
|
+
function assert(condition, msg) {
|
|
799
|
+
if (!condition) {
|
|
800
|
+
_fail(msg);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
function require2(val, msg) {
|
|
804
|
+
if (val == null) {
|
|
805
|
+
_fail(`Expected ${fmt(val)} not to be nullish`, msg);
|
|
806
|
+
}
|
|
807
|
+
return val;
|
|
808
|
+
}
|
|
809
|
+
function requireDefined(val, msg) {
|
|
810
|
+
if (val === void 0) {
|
|
811
|
+
_fail(`Expected ${fmt(val)} not to be undefined`, msg);
|
|
812
|
+
}
|
|
813
|
+
return val;
|
|
814
|
+
}
|
|
815
|
+
function requireElement(index, array, msg) {
|
|
816
|
+
if (!guard_exports.isIndex(index, array))
|
|
817
|
+
_fail(`Expected ${index} to be index for array ${fmt(array)}`, msg);
|
|
818
|
+
return array[index];
|
|
819
|
+
}
|
|
820
|
+
function fail(msg) {
|
|
821
|
+
_fail(msg);
|
|
822
|
+
}
|
|
823
|
+
function isStrictEqual2(val1, val2, msg) {
|
|
824
|
+
if (!guard_exports.isStrictEqual(val1, val2))
|
|
825
|
+
_fail(`Expected ${fmt(val1)} to ne strict equal to ${val2}`, msg);
|
|
826
|
+
return val1;
|
|
827
|
+
}
|
|
828
|
+
function isDeepEqual2(val1, val2, msg) {
|
|
829
|
+
if (!guard_exports.isDeepEqual(val1, val2))
|
|
830
|
+
_fail(`Expected ${fmt(val1)} to deep equal with ${fmt(val2)}`, msg);
|
|
831
|
+
return val1;
|
|
832
|
+
}
|
|
833
|
+
function isUndefined2(val, msg) {
|
|
834
|
+
if (!guard_exports.isUndefined(val))
|
|
835
|
+
_fail(`Expected ${fmt(val)} to be undefined`, msg);
|
|
836
|
+
return val;
|
|
837
|
+
}
|
|
838
|
+
function isNull2(val, msg) {
|
|
839
|
+
if (!guard_exports.isNull(val))
|
|
840
|
+
_fail(`Expected ${fmt(val)} to be null`, msg);
|
|
841
|
+
return val;
|
|
842
|
+
}
|
|
843
|
+
function isNullish2(val, msg) {
|
|
844
|
+
if (!guard_exports.isNullish(val))
|
|
845
|
+
_fail(`Expected ${fmt(val)} to be null or undefined`, msg);
|
|
846
|
+
return val;
|
|
847
|
+
}
|
|
848
|
+
function isDefined2(val, msg) {
|
|
849
|
+
if (!guard_exports.isDefined(val)) {
|
|
850
|
+
_fail(`Expected ${fmt(val)} to be defined`, msg);
|
|
851
|
+
}
|
|
852
|
+
return val;
|
|
853
|
+
}
|
|
854
|
+
function isNonNull2(val, msg) {
|
|
855
|
+
if (!guard_exports.isNonNull(val)) {
|
|
856
|
+
_fail(`Expected ${fmt(val)} to be defined`, msg);
|
|
857
|
+
}
|
|
858
|
+
return val;
|
|
859
|
+
}
|
|
860
|
+
function isObject2(val, msg) {
|
|
861
|
+
if (!guard_exports.isObject(val))
|
|
862
|
+
_fail(`Expected ${fmt(val)} to be object`, msg);
|
|
863
|
+
return val;
|
|
864
|
+
}
|
|
865
|
+
function isEmptyObject2(val, msg) {
|
|
866
|
+
if (!guard_exports.isEmptyObject(val))
|
|
867
|
+
_fail(`Expected ${fmt(val)} to be empty object`, msg);
|
|
868
|
+
return val;
|
|
869
|
+
}
|
|
870
|
+
function isPlainObject2(val, msg) {
|
|
871
|
+
if (!guard_exports.isPlainObject(val))
|
|
872
|
+
_fail(`Expected ${fmt(val)} to be plain object`, msg);
|
|
873
|
+
return val;
|
|
874
|
+
}
|
|
875
|
+
function isObjectOrUndefined2(val, msg) {
|
|
876
|
+
if (!guard_exports.isObjectOrUndefined(val))
|
|
877
|
+
_fail(`Expected ${fmt(val)} to be object or undefined`, msg);
|
|
878
|
+
return val;
|
|
879
|
+
}
|
|
880
|
+
function isTypedObject2(val, keys, msg) {
|
|
881
|
+
if (!guard_exports.isTypedObject(val, keys))
|
|
882
|
+
_fail(`Expected ${fmt(val)} to have keys ${fmt(keys)}`, msg);
|
|
883
|
+
return val;
|
|
884
|
+
}
|
|
885
|
+
function isArray2(val, msg) {
|
|
886
|
+
if (!guard_exports.isArray(val))
|
|
887
|
+
_fail(`Expected ${fmt(val)} to be array`, msg);
|
|
888
|
+
return val;
|
|
889
|
+
}
|
|
890
|
+
function isArrayOrUndefined2(val, msg) {
|
|
891
|
+
if (!guard_exports.isArrayOrUndefined(val))
|
|
892
|
+
_fail(`Expected ${fmt(val)} to be array or undefined`, msg);
|
|
893
|
+
return true;
|
|
894
|
+
}
|
|
895
|
+
function isEmptyArray2(val, msg) {
|
|
896
|
+
if (!guard_exports.isEmptyArray(val))
|
|
897
|
+
_fail(`Expected ${fmt(val)} to be empty array`, msg);
|
|
898
|
+
}
|
|
899
|
+
function isNonEmptyArray2(val, msg) {
|
|
900
|
+
if (!guard_exports.isNonEmptyArray(val))
|
|
901
|
+
_fail(`Expected ${fmt(val)} to be non-empty array`, msg);
|
|
902
|
+
}
|
|
903
|
+
function isEmptyArrayOrUndefined2(val, msg) {
|
|
904
|
+
if (!guard_exports.isEmptyArrayOrUndefined(val))
|
|
905
|
+
_fail(`Expected ${fmt(val)} to be empty array or undefined`, msg);
|
|
906
|
+
}
|
|
907
|
+
function isNonEmptyArrayOrUndefined2(val, msg) {
|
|
908
|
+
if (!guard_exports.isNonEmptyArrayOrUndefined(val))
|
|
909
|
+
_fail(`Expected ${fmt(val)} to be non-empty array or undefined`, msg);
|
|
910
|
+
}
|
|
911
|
+
function isString2(val, msg) {
|
|
912
|
+
if (!guard_exports.isString(val))
|
|
913
|
+
_fail(`Expected ${fmt(val)} to be string`, msg);
|
|
914
|
+
return val;
|
|
915
|
+
}
|
|
916
|
+
function isEmptyString2(val, msg) {
|
|
917
|
+
if (!guard_exports.isEmptyString(val))
|
|
918
|
+
_fail(`Expected ${fmt(val)} to be empty string`, msg);
|
|
919
|
+
return val;
|
|
920
|
+
}
|
|
921
|
+
function isNonEmptyString2(val, msg) {
|
|
922
|
+
if (!guard_exports.isNonEmptyString(val))
|
|
923
|
+
_fail(`Expected ${fmt(val)} to be non-empty string`, msg);
|
|
924
|
+
return val;
|
|
925
|
+
}
|
|
926
|
+
function isStringOrUndefined2(val, msg) {
|
|
927
|
+
if (!guard_exports.isStringOrUndefined(val))
|
|
928
|
+
_fail(`Expected ${fmt(val)} to be string or undefined`, msg);
|
|
929
|
+
return val;
|
|
930
|
+
}
|
|
931
|
+
function isEmptyStringOrUndefined2(val, msg) {
|
|
932
|
+
if (!guard_exports.isEmptyStringOrUndefined(val))
|
|
933
|
+
_fail(`Expected ${fmt(val)} to be empty string or undefined`, msg);
|
|
934
|
+
return val;
|
|
935
|
+
}
|
|
936
|
+
function isNonEmptyStringOrUndefined2(val, msg) {
|
|
937
|
+
if (!guard_exports.isNonEmptyStringOrUndefined(val))
|
|
938
|
+
_fail(`Expected ${fmt(val)} to be non-empty string or undefined`, msg);
|
|
939
|
+
return val;
|
|
940
|
+
}
|
|
941
|
+
function isBoolean2(val, msg) {
|
|
942
|
+
if (!guard_exports.isBoolean(val))
|
|
943
|
+
_fail(`Expected ${fmt(val)} to be boolean`, msg);
|
|
944
|
+
return val;
|
|
945
|
+
}
|
|
946
|
+
function isBooleanOrUndefined2(val, msg) {
|
|
947
|
+
if (!guard_exports.isBooleanOrUndefined(val))
|
|
948
|
+
_fail(`Expected ${fmt(val)} to be boolean or undefined`, msg);
|
|
949
|
+
return val;
|
|
950
|
+
}
|
|
951
|
+
function isTrue2(val, msg) {
|
|
952
|
+
if (!guard_exports.isTrue(val))
|
|
953
|
+
_fail(`Expected ${fmt(val)} to be true`, msg);
|
|
954
|
+
return val;
|
|
955
|
+
}
|
|
956
|
+
function isTrueOrUndefined2(val, msg) {
|
|
957
|
+
if (!guard_exports.isTrueOrUndefined(val))
|
|
958
|
+
_fail(`Expected ${fmt(val)} to be true or undefined`, msg);
|
|
959
|
+
return val;
|
|
960
|
+
}
|
|
961
|
+
function isFalse2(val, msg) {
|
|
962
|
+
if (!guard_exports.isFalse(val))
|
|
963
|
+
_fail(`Expected ${fmt(val)} to be false`, msg);
|
|
964
|
+
return val;
|
|
965
|
+
}
|
|
966
|
+
function isFalseOrUndefined2(val, msg) {
|
|
967
|
+
if (!guard_exports.isFalseOrUndefined(val))
|
|
968
|
+
_fail(`Expected ${fmt(val)} to be false or undefined`, msg);
|
|
969
|
+
return val;
|
|
970
|
+
}
|
|
971
|
+
function isFunction2(val, msg) {
|
|
972
|
+
if (!guard_exports.isFunction(val))
|
|
973
|
+
_fail(`Expected ${fmt(val)} to be function`, msg);
|
|
974
|
+
return val;
|
|
975
|
+
}
|
|
976
|
+
function isFunctionOrUndefined2(val, msg) {
|
|
977
|
+
if (!guard_exports.isFunctionOrUndefined(val))
|
|
978
|
+
_fail(`Expected ${fmt(val)} to be function or undefined`, msg);
|
|
979
|
+
return val;
|
|
980
|
+
}
|
|
981
|
+
function isEnumValue2(val, enumObject, msg) {
|
|
982
|
+
if (!guard_exports.isEnumValue(val, enumObject))
|
|
983
|
+
_fail(`Expected ${fmt(val)} to be enum val`, msg);
|
|
984
|
+
return val;
|
|
985
|
+
}
|
|
986
|
+
function isEnumValueOrUndefined2(val, enumObject, msg) {
|
|
987
|
+
if (!guard_exports.isEnumValueOrUndefined(val, enumObject))
|
|
988
|
+
_fail(`Expected ${fmt(val)} to be enum val or undefined`, msg);
|
|
989
|
+
return val;
|
|
990
|
+
}
|
|
991
|
+
function isNumericString2(val, msg) {
|
|
992
|
+
if (!guard_exports.isNumericString(val))
|
|
993
|
+
_fail(`Expected ${fmt(val)} to be numeric string`, msg);
|
|
994
|
+
return val;
|
|
995
|
+
}
|
|
996
|
+
function isBigInt2(val, msg) {
|
|
997
|
+
if (!guard_exports.isBigInt(val))
|
|
998
|
+
_fail(`Expected ${fmt(val)} to be BigInt`, msg);
|
|
999
|
+
return val;
|
|
1000
|
+
}
|
|
1001
|
+
function isNumber2(val, msg) {
|
|
1002
|
+
if (!guard_exports.isNumber(val))
|
|
1003
|
+
_fail(`Expected ${fmt(val)} to be number`, msg);
|
|
1004
|
+
return val;
|
|
1005
|
+
}
|
|
1006
|
+
function isSafeNumber2(val, msg) {
|
|
1007
|
+
if (!guard_exports.isSafeNumber(val))
|
|
1008
|
+
_fail(`Expected ${fmt(val)} to be safe number`, msg);
|
|
1009
|
+
return val;
|
|
1010
|
+
}
|
|
1011
|
+
function isNumberOrUndefined2(val, msg) {
|
|
1012
|
+
if (!guard_exports.isNumberOrUndefined(val))
|
|
1013
|
+
_fail(`Expected ${fmt(val)} to be number or undefined`, msg);
|
|
1014
|
+
return val;
|
|
1015
|
+
}
|
|
1016
|
+
function isNumberEq2(val, ref, msg) {
|
|
1017
|
+
if (!guard_exports.isNumberEq(val, ref))
|
|
1018
|
+
_fail(`Expected ${fmt(val)} to be number equal to ${fmt(ref)}`, msg);
|
|
1019
|
+
return val;
|
|
1020
|
+
}
|
|
1021
|
+
function isNumberGt2(val, ref, msg) {
|
|
1022
|
+
if (!guard_exports.isNumberGt(val, ref))
|
|
1023
|
+
_fail(`Expected ${fmt(val)} to be number > ${fmt(ref)}`, msg);
|
|
1024
|
+
return val;
|
|
1025
|
+
}
|
|
1026
|
+
function isNumberGte2(val, ref, msg) {
|
|
1027
|
+
if (!guard_exports.isNumberGte(val, ref))
|
|
1028
|
+
_fail(`Expected ${fmt(val)} to be number >= ${fmt(ref)}`, msg);
|
|
1029
|
+
return val;
|
|
1030
|
+
}
|
|
1031
|
+
function isNumberLt2(val, ref, msg) {
|
|
1032
|
+
if (!guard_exports.isNumberLt(val, ref))
|
|
1033
|
+
_fail(`Expected ${fmt(val)} to be number < ${fmt(ref)}`, msg);
|
|
1034
|
+
return val;
|
|
1035
|
+
}
|
|
1036
|
+
function isNumberLte2(val, ref, msg) {
|
|
1037
|
+
if (!guard_exports.isNumberLte(val, ref))
|
|
1038
|
+
_fail(`Expected ${fmt(val)} to be number <= ${fmt(ref)}`, msg);
|
|
1039
|
+
return val;
|
|
1040
|
+
}
|
|
1041
|
+
function isNumberBetween2(val, min, max, msg) {
|
|
1042
|
+
if (!guard_exports.isNumberBetween(val, min, max))
|
|
1043
|
+
_fail(`Expected number ${fmt(min)} <= ${fmt(val)} <= ${fmt(max)}`, msg);
|
|
1044
|
+
return val;
|
|
1045
|
+
}
|
|
1046
|
+
function isNumberBetweenExclusive2(val, min, max, msg) {
|
|
1047
|
+
if (!guard_exports.isNumberBetweenExclusive(val, min, max))
|
|
1048
|
+
_fail(`Expected number ${fmt(min)} < ${fmt(val)} < ${fmt(max)}`, msg);
|
|
1049
|
+
return val;
|
|
1050
|
+
}
|
|
1051
|
+
function isFinite3(val, msg) {
|
|
1052
|
+
if (!guard_exports.isFinite(val))
|
|
1053
|
+
_fail(`Expected ${fmt(val)} to be finite`, msg);
|
|
1054
|
+
return val;
|
|
1055
|
+
}
|
|
1056
|
+
function isFloat2(val, msg) {
|
|
1057
|
+
if (!guard_exports.isFloat(val))
|
|
1058
|
+
_fail(`Expected ${fmt(val)} to be float`, msg);
|
|
1059
|
+
return val;
|
|
1060
|
+
}
|
|
1061
|
+
function isInteger2(val, msg) {
|
|
1062
|
+
if (!guard_exports.isInteger(val))
|
|
1063
|
+
_fail(`Expected ${fmt(val)} to be integer`, msg);
|
|
1064
|
+
return val;
|
|
1065
|
+
}
|
|
1066
|
+
function isSafeInteger2(val, msg) {
|
|
1067
|
+
if (!guard_exports.isSafeInteger(val))
|
|
1068
|
+
_fail(`Expected ${fmt(val)} to be safe integer`, msg);
|
|
1069
|
+
return val;
|
|
1070
|
+
}
|
|
1071
|
+
function isIntegerOrUndefined2(val, msg) {
|
|
1072
|
+
if (!guard_exports.isIntegerOrUndefined(val))
|
|
1073
|
+
_fail(`Expected ${fmt(val)} to be integer or undefined`, msg);
|
|
1074
|
+
return val;
|
|
1075
|
+
}
|
|
1076
|
+
function isIntegerEq2(val, ref, msg) {
|
|
1077
|
+
if (!guard_exports.isIntegerEq(val, ref))
|
|
1078
|
+
_fail(`Expected ${fmt(val)} to be integer equal to ${fmt(ref)}`, msg);
|
|
1079
|
+
return val;
|
|
1080
|
+
}
|
|
1081
|
+
function isIntegerGt2(val, ref, msg) {
|
|
1082
|
+
if (!guard_exports.isIntegerGt(val, ref))
|
|
1083
|
+
_fail(`Expected ${fmt(val)} to be integer > ${fmt(ref)}`, msg);
|
|
1084
|
+
return val;
|
|
1085
|
+
}
|
|
1086
|
+
function isIntegerGte2(val, ref, msg) {
|
|
1087
|
+
if (!guard_exports.isIntegerGte(val, ref))
|
|
1088
|
+
_fail(`Expected ${fmt(val)} to be integer >= ${fmt(ref)}`, msg);
|
|
1089
|
+
return val;
|
|
1090
|
+
}
|
|
1091
|
+
function isIntegerLt2(val, ref, msg) {
|
|
1092
|
+
if (!guard_exports.isIntegerLt(val, ref))
|
|
1093
|
+
_fail(`Expected ${fmt(val)} to be integer < ${fmt(ref)}`, msg);
|
|
1094
|
+
return val;
|
|
1095
|
+
}
|
|
1096
|
+
function isIntegerLte2(val, ref, msg) {
|
|
1097
|
+
if (!guard_exports.isIntegerLte(val, ref))
|
|
1098
|
+
_fail(`Expected ${fmt(val)} to be integer <= ${fmt(ref)}`, msg);
|
|
1099
|
+
return val;
|
|
1100
|
+
}
|
|
1101
|
+
function isIntegerBetween2(val, min, max, msg) {
|
|
1102
|
+
if (!guard_exports.isIntegerBetween(val, min, max))
|
|
1103
|
+
_fail(`Expected integer ${fmt(min)} <= ${fmt(val)} <= ${fmt(max)}`, msg);
|
|
1104
|
+
return val;
|
|
1105
|
+
}
|
|
1106
|
+
function isIntegerBetweenExclusive2(val, min, max, msg) {
|
|
1107
|
+
if (!guard_exports.isIntegerBetweenExclusive(val, min, max))
|
|
1108
|
+
_fail(`Expected integer ${fmt(min)} < ${fmt(val)} < ${fmt(max)}`, msg);
|
|
1109
|
+
return val;
|
|
1110
|
+
}
|
|
1111
|
+
function isNaNValue2(val, msg) {
|
|
1112
|
+
if (!guard_exports.isNaNValue(val))
|
|
1113
|
+
_fail(`Expected ${fmt(val)} to be NaN`, msg);
|
|
1114
|
+
return NaN;
|
|
1115
|
+
}
|
|
1116
|
+
function isInfinity2(val, msg) {
|
|
1117
|
+
if (!guard_exports.isInfinity(val))
|
|
1118
|
+
_fail(`Expected ${fmt(val)} to be +-Infinity`, msg);
|
|
1119
|
+
return val;
|
|
1120
|
+
}
|
|
1121
|
+
function isPosInfinity2(val, msg) {
|
|
1122
|
+
if (!guard_exports.isPosInfinity(val))
|
|
1123
|
+
_fail(`Expected ${fmt(val)} to be +Infinity`, msg);
|
|
1124
|
+
return val;
|
|
1125
|
+
}
|
|
1126
|
+
function isNegInfinity2(val, msg) {
|
|
1127
|
+
if (!guard_exports.isNegInfinity(val))
|
|
1128
|
+
_fail(`Expected ${fmt(val)} to be -Infinity`, msg);
|
|
1129
|
+
return val;
|
|
1130
|
+
}
|
|
1131
|
+
function isPos2(val, msg) {
|
|
1132
|
+
if (!guard_exports.isPos(val))
|
|
1133
|
+
_fail(`Expected ${fmt(val)} to be positive (> 0)`, msg);
|
|
1134
|
+
return val;
|
|
1135
|
+
}
|
|
1136
|
+
function isNeg2(val, msg) {
|
|
1137
|
+
if (!guard_exports.isNeg(val))
|
|
1138
|
+
_fail(`Expected ${fmt(val)} to be negative (< 0)`, msg);
|
|
1139
|
+
return val;
|
|
1140
|
+
}
|
|
1141
|
+
function isNonPos2(val, msg) {
|
|
1142
|
+
if (!guard_exports.isNonPos(val))
|
|
1143
|
+
_fail(`Expected ${fmt(val)} to be non-positive (<= 0)`, msg);
|
|
1144
|
+
return val;
|
|
1145
|
+
}
|
|
1146
|
+
function isNonNeg2(val, msg) {
|
|
1147
|
+
if (!guard_exports.isNonNeg(val))
|
|
1148
|
+
_fail(`Expected ${fmt(val)} to be non-negative (>= 0)`, msg);
|
|
1149
|
+
return val;
|
|
1150
|
+
}
|
|
1151
|
+
function isZero2(val, msg) {
|
|
1152
|
+
if (!guard_exports.isZero(val))
|
|
1153
|
+
_fail(`Expected ${fmt(val)} to be 0`, msg);
|
|
1154
|
+
return val;
|
|
1155
|
+
}
|
|
1156
|
+
function isPosZero2(val, msg) {
|
|
1157
|
+
if (!guard_exports.isPosZero(val))
|
|
1158
|
+
_fail(`Expected ${fmt(val)} to be +0`, msg);
|
|
1159
|
+
return val;
|
|
1160
|
+
}
|
|
1161
|
+
function isNegZero2(val, msg) {
|
|
1162
|
+
if (!guard_exports.isNegZero(val))
|
|
1163
|
+
_fail(`Expected ${fmt(val)} to be -0`, msg);
|
|
1164
|
+
return val;
|
|
1165
|
+
}
|
|
1166
|
+
function isOdd2(val, msg) {
|
|
1167
|
+
if (!guard_exports.isOdd(val))
|
|
1168
|
+
_fail(`Expected ${fmt(val)} to odd`, msg);
|
|
1169
|
+
return val;
|
|
1170
|
+
}
|
|
1171
|
+
function isEven2(val, msg) {
|
|
1172
|
+
if (!guard_exports.isEven(val))
|
|
1173
|
+
_fail(`Expected ${fmt(val)} to even`, msg);
|
|
1174
|
+
return val;
|
|
1175
|
+
}
|
|
1176
|
+
function isMultipleOf2(val, base, msg) {
|
|
1177
|
+
if (!guard_exports.isMultipleOf(val, base))
|
|
1178
|
+
_fail(`Expected ${fmt(val)} to be divisble bu ${fmt(base)}`, msg);
|
|
1179
|
+
return val;
|
|
1180
|
+
}
|
|
1181
|
+
function isPowerOfTwo2(val, msg) {
|
|
1182
|
+
if (!guard_exports.isPowerOfTwo(val))
|
|
1183
|
+
_fail(`Expected ${fmt(val)} to be power of two`, msg);
|
|
1184
|
+
return val;
|
|
1185
|
+
}
|
|
1186
|
+
function isIncluded2(val, arr, msg) {
|
|
1187
|
+
if (!guard_exports.isIncluded(val, arr))
|
|
1188
|
+
_fail(`Expected ${fmt(val)} to be included in ${fmt(arr)}`, msg);
|
|
1189
|
+
return val;
|
|
1190
|
+
}
|
|
1191
|
+
function isIndex2(...args) {
|
|
1192
|
+
const index = args.shift();
|
|
1193
|
+
const msg = guard_exports.isString(args[args.length - 1]) ? args.pop() : void 0;
|
|
1194
|
+
const arr = guard_exports.isArray(args[0]) ? args.shift() : void 0;
|
|
1195
|
+
if (!guard_exports.isIndex(index, arr)) {
|
|
1196
|
+
if (arr === void 0)
|
|
1197
|
+
_fail(`Expected ${index} to be index`, msg);
|
|
1198
|
+
else
|
|
1199
|
+
_fail(`Expected ${index} to be index for ${fmt(arr)}`, msg);
|
|
1200
|
+
}
|
|
1201
|
+
return index;
|
|
1202
|
+
}
|
|
1203
|
+
function doesThrow2(throwTestFn, msg) {
|
|
1204
|
+
if (!guard_exports.doesThrow(throwTestFn))
|
|
1205
|
+
_fail(`Expected to throw`, msg);
|
|
1206
|
+
return true;
|
|
1207
|
+
}
|
|
1208
|
+
function doesNotThrow2(throwTestFn, msg) {
|
|
1209
|
+
if (!guard_exports.doesNotThrow(throwTestFn))
|
|
1210
|
+
_fail(`Expected to throw`, msg);
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
var cookies_exports = {};
|
|
1214
|
+
__export2(cookies_exports, {
|
|
1215
|
+
accept: () => accept,
|
|
1216
|
+
decline: () => decline,
|
|
1217
|
+
erase: () => erase,
|
|
1218
|
+
eraseAll: () => eraseAll,
|
|
1219
|
+
isConsentPending: () => isConsentPending,
|
|
1220
|
+
read: () => read,
|
|
1221
|
+
readBool: () => readBool,
|
|
1222
|
+
readInt: () => readInt,
|
|
1223
|
+
save: () => save,
|
|
1224
|
+
setExpireDays: () => setExpireDays
|
|
1225
|
+
});
|
|
1226
|
+
var ConsentCookieName = "ConsentCookie";
|
|
1227
|
+
var _consent;
|
|
1228
|
+
var _expires;
|
|
1229
|
+
var str = _read(ConsentCookieName);
|
|
1230
|
+
_consent = str === "accept" || str === "decline" ? str : void 0;
|
|
1231
|
+
function _getCookieList() {
|
|
1232
|
+
if (typeof document === "undefined")
|
|
1233
|
+
return [];
|
|
1234
|
+
let s = document.cookie;
|
|
1235
|
+
return s.split(";").map((c) => c.trim());
|
|
1236
|
+
}
|
|
1237
|
+
function _save(name, value) {
|
|
1238
|
+
let cookie = name + "=" + value.toString() + ";sameSite=Lax;";
|
|
1239
|
+
if (_expires) {
|
|
1240
|
+
cookie += "expires=" + _expires.toUTCString() + ";";
|
|
1241
|
+
}
|
|
1242
|
+
if (typeof document !== "undefined")
|
|
1243
|
+
document.cookie = cookie;
|
|
1244
|
+
return value;
|
|
1245
|
+
}
|
|
1246
|
+
function _read(name, defaultValue) {
|
|
1247
|
+
let str2 = _getCookieList().find((c) => c.startsWith(name + "="));
|
|
1248
|
+
return str2 === void 0 ? defaultValue : str2.substring(name.length + 1);
|
|
1249
|
+
}
|
|
1250
|
+
function _erase(name) {
|
|
1251
|
+
if (typeof document !== "undefined")
|
|
1252
|
+
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
|
|
1253
|
+
}
|
|
1254
|
+
function setExpireDays(days) {
|
|
1255
|
+
_expires = /* @__PURE__ */ new Date();
|
|
1256
|
+
_expires.setDate(_expires.getDate() + days);
|
|
1257
|
+
}
|
|
1258
|
+
function isConsentPending() {
|
|
1259
|
+
return _consent === void 0;
|
|
1260
|
+
}
|
|
1261
|
+
function accept() {
|
|
1262
|
+
_consent = "accept";
|
|
1263
|
+
_save(ConsentCookieName, _consent);
|
|
1264
|
+
}
|
|
1265
|
+
function decline() {
|
|
1266
|
+
_consent = "decline";
|
|
1267
|
+
_save(ConsentCookieName, _consent);
|
|
1268
|
+
}
|
|
1269
|
+
function save(name, value) {
|
|
1270
|
+
if (_consent === "accept")
|
|
1271
|
+
_save(name, value);
|
|
1272
|
+
return value;
|
|
1273
|
+
}
|
|
1274
|
+
function read(name, defaultValue) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
if (_consent === "accept")
|
|
1277
|
+
return (_a = _read(name, defaultValue)) != null ? _a : defaultValue;
|
|
1278
|
+
else
|
|
1279
|
+
return defaultValue;
|
|
1280
|
+
}
|
|
1281
|
+
function readInt(name, defaultValue) {
|
|
1282
|
+
if (_consent === "accept") {
|
|
1283
|
+
let str2 = _read(name);
|
|
1284
|
+
return str2 === void 0 ? defaultValue : parseInt(str2);
|
|
1285
|
+
} else {
|
|
1286
|
+
return defaultValue;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
function readBool(name, defaultValue) {
|
|
1290
|
+
if (_consent === "accept") {
|
|
1291
|
+
let str2 = _read(name);
|
|
1292
|
+
return str2 === void 0 ? defaultValue : /true|1/i.test(str2);
|
|
1293
|
+
} else {
|
|
1294
|
+
return defaultValue;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
function erase(name) {
|
|
1298
|
+
if (_consent === "accept" || name === ConsentCookieName)
|
|
1299
|
+
_erase(name);
|
|
1300
|
+
}
|
|
1301
|
+
function eraseAll() {
|
|
1302
|
+
if (typeof document !== "undefined")
|
|
1303
|
+
document.cookie.split(";").forEach((c) => erase(c.trim().split("=")[0]));
|
|
1304
|
+
}
|
|
1305
|
+
var device_exports = {};
|
|
1306
|
+
__export2(device_exports, {
|
|
1307
|
+
DPI: () => DPI,
|
|
1308
|
+
FontSize: () => FontSize,
|
|
1309
|
+
HostAddress: () => HostAddress,
|
|
1310
|
+
IsMobileDevice: () => IsMobileDevice,
|
|
1311
|
+
IsTouchDevice: () => IsTouchDevice,
|
|
1312
|
+
PxPerMm: () => PxPerMm,
|
|
1313
|
+
ScrollbarWidth: () => ScrollbarWidth,
|
|
1314
|
+
mmToPx: () => mmToPx,
|
|
1315
|
+
pxToMm: () => pxToMm,
|
|
1316
|
+
toPx: () => toPx
|
|
1317
|
+
});
|
|
1318
|
+
function getDPI() {
|
|
1319
|
+
try {
|
|
1320
|
+
let el = document.createElement("div");
|
|
1321
|
+
el.style.width = "1in";
|
|
1322
|
+
document.body.appendChild(el);
|
|
1323
|
+
let dpi = el.offsetWidth;
|
|
1324
|
+
el.remove();
|
|
1325
|
+
return dpi || 96;
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
return 96;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
function getScrollBarWidth() {
|
|
1331
|
+
try {
|
|
1332
|
+
let outer = document.createElement("div");
|
|
1333
|
+
outer.style.visibility = "hidden";
|
|
1334
|
+
outer.style.width = "100px";
|
|
1335
|
+
document.body.appendChild(outer);
|
|
1336
|
+
let widthNoScroll = outer.offsetWidth;
|
|
1337
|
+
outer.style.overflow = "scroll";
|
|
1338
|
+
let inner = document.createElement("div");
|
|
1339
|
+
inner.style.width = "100%";
|
|
1340
|
+
outer.appendChild(inner);
|
|
1341
|
+
let widthWithScroll = inner.offsetWidth;
|
|
1342
|
+
if (outer.parentNode) {
|
|
1343
|
+
outer.parentNode.removeChild(outer);
|
|
1344
|
+
}
|
|
1345
|
+
return widthNoScroll - widthWithScroll;
|
|
1346
|
+
} catch (e) {
|
|
1347
|
+
return 0;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
function getSystemFontSize() {
|
|
1351
|
+
try {
|
|
1352
|
+
let tmpDiv = document.createElement("div");
|
|
1353
|
+
tmpDiv.style.cssText = "display:inline-block; padding:0; line-height:1; position:absolute; visibility:hidden; font-size:1em";
|
|
1354
|
+
tmpDiv.appendChild(document.createTextNode("M"));
|
|
1355
|
+
document.body.appendChild(tmpDiv);
|
|
1356
|
+
let fontsize = tmpDiv.offsetHeight;
|
|
1357
|
+
document.body.removeChild(tmpDiv);
|
|
1358
|
+
return fontsize;
|
|
1359
|
+
} catch (e) {
|
|
1360
|
+
return 16;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function getIsTouchDevice() {
|
|
1364
|
+
if (typeof window === "undefined")
|
|
1365
|
+
return false;
|
|
1366
|
+
if ("ontouchstart" in window || "DocumentTouch" in window || "createTouch" in document && "createTouchList" in document)
|
|
1367
|
+
return true;
|
|
1368
|
+
var prefixes = " -webkit- -moz- -o- -ms- ".split(" ");
|
|
1369
|
+
var mq = function(query2) {
|
|
1370
|
+
return window.matchMedia(query2).matches;
|
|
1371
|
+
};
|
|
1372
|
+
var query = ["(", prefixes.join("touch-enabled),("), "heartz", ")"].join("");
|
|
1373
|
+
return mq(query);
|
|
1374
|
+
}
|
|
1375
|
+
function getIsMobileDevice() {
|
|
1376
|
+
let a = navigator.userAgent || navigator.vendor || window.opera;
|
|
1377
|
+
return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4));
|
|
1378
|
+
}
|
|
1379
|
+
function getHostAddress() {
|
|
1380
|
+
if (typeof location === "undefined" || !location.host) {
|
|
1381
|
+
return "localhost";
|
|
1382
|
+
}
|
|
1383
|
+
return `${location.protocol}//${location.host}`;
|
|
1384
|
+
}
|
|
1385
|
+
var UnitRegExp = /^(mm|cm|in|inch|px|em)$/;
|
|
1386
|
+
var ValueUnitRegExp = /^([0-9\\.]+)(.*)$/;
|
|
1387
|
+
var DPI = getDPI();
|
|
1388
|
+
var PxPerMm = DPI / 25.4;
|
|
1389
|
+
var ScrollbarWidth = getScrollBarWidth();
|
|
1390
|
+
var FontSize = getSystemFontSize();
|
|
1391
|
+
var IsTouchDevice = getIsTouchDevice();
|
|
1392
|
+
var IsMobileDevice = getIsMobileDevice();
|
|
1393
|
+
var HostAddress = getHostAddress();
|
|
1394
|
+
function pxToMm(px) {
|
|
1395
|
+
return px / PxPerMm;
|
|
1396
|
+
}
|
|
1397
|
+
function mmToPx(mm) {
|
|
1398
|
+
return mm * PxPerMm;
|
|
1399
|
+
}
|
|
1400
|
+
function toPx(input) {
|
|
1401
|
+
if (typeof input === "number") {
|
|
1402
|
+
return input;
|
|
1403
|
+
}
|
|
1404
|
+
let value = NaN;
|
|
1405
|
+
let unit = void 0;
|
|
1406
|
+
let match = input.toString().match(ValueUnitRegExp);
|
|
1407
|
+
if (match && match[1]) {
|
|
1408
|
+
value = parseFloat(match[1]);
|
|
1409
|
+
let unitStr = match[2] ? match[2].toLowerCase() : "undefined";
|
|
1410
|
+
let unitStrOk = UnitRegExp.test(unitStr);
|
|
1411
|
+
unit = unitStrOk ? unitStr : void 0;
|
|
1412
|
+
if (!unit) {
|
|
1413
|
+
console.log("Unknown unit '" + unitStr + "' => using 'px'.");
|
|
1414
|
+
}
|
|
1415
|
+
} else {
|
|
1416
|
+
value = parseFloat(input);
|
|
1417
|
+
}
|
|
1418
|
+
assert_exports.isFinite(value, "value in function toPx");
|
|
1419
|
+
switch (unit) {
|
|
1420
|
+
case "mm":
|
|
1421
|
+
return mmToPx(value);
|
|
1422
|
+
case "cm":
|
|
1423
|
+
return mmToPx(value) * 10;
|
|
1424
|
+
case "in":
|
|
1425
|
+
case "inch":
|
|
1426
|
+
return mmToPx(value) * 25.4;
|
|
1427
|
+
case "em":
|
|
1428
|
+
return FontSize * value;
|
|
1429
|
+
default:
|
|
1430
|
+
case "px":
|
|
1431
|
+
return value;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
var utils_exports = {};
|
|
1435
|
+
__export2(utils_exports, {
|
|
1436
|
+
Arr: () => arr_exports,
|
|
1437
|
+
Dom: () => dom_exports,
|
|
1438
|
+
Enum: () => enum_exports,
|
|
1439
|
+
Math: () => math_exports,
|
|
1440
|
+
Obj: () => obj_exports,
|
|
1441
|
+
Str: () => str_exports
|
|
1442
|
+
});
|
|
1443
|
+
var arr_exports = {};
|
|
1444
|
+
__export2(arr_exports, {
|
|
1445
|
+
arrayContains: () => arrayContains,
|
|
1446
|
+
chunckArray: () => chunckArray,
|
|
1447
|
+
duplicate: () => duplicate,
|
|
1448
|
+
fillArray: () => fillArray,
|
|
1449
|
+
getRangeArray: () => getRangeArray,
|
|
1450
|
+
getSequenceArray: () => getSequenceArray,
|
|
1451
|
+
isArray: () => isArray,
|
|
1452
|
+
mapRangeArray: () => mapRangeArray,
|
|
1453
|
+
mapSequenceArray: () => mapSequenceArray,
|
|
1454
|
+
removeDuplicates: () => removeDuplicates,
|
|
1455
|
+
toArray: () => toArray
|
|
1456
|
+
});
|
|
1457
|
+
function toArray(a) {
|
|
1458
|
+
return isArray(a) ? a : [a];
|
|
1459
|
+
}
|
|
1460
|
+
function duplicate(a) {
|
|
1461
|
+
var _a;
|
|
1462
|
+
return (_a = a == null ? void 0 : a.slice()) != null ? _a : [];
|
|
1463
|
+
}
|
|
1464
|
+
function removeDuplicates(arr, compareFn) {
|
|
1465
|
+
return compareFn !== void 0 ? arr.filter((a, id, self) => id === self.findIndex((b) => compareFn(a, b))) : arr.filter((a, id, self) => id === self.indexOf(a));
|
|
1466
|
+
}
|
|
1467
|
+
function fillArray(fillValue, fillCount) {
|
|
1468
|
+
if (!isInteger(fillCount) || fillCount < 0) {
|
|
1469
|
+
throw new Error("fillArray: Invalid fillCount = " + fillCount);
|
|
1470
|
+
}
|
|
1471
|
+
return new Array(fillCount).fill(fillValue);
|
|
1472
|
+
}
|
|
1473
|
+
function mapSequenceArray(len, fn) {
|
|
1474
|
+
if (!isInteger(len) || len < 0) {
|
|
1475
|
+
throw new Error("mapSequenceArray: Invalid len = " + len);
|
|
1476
|
+
}
|
|
1477
|
+
let arr = new Array(len);
|
|
1478
|
+
for (let i = 0; i < len; i++) {
|
|
1479
|
+
arr[i] = fn(i);
|
|
1480
|
+
}
|
|
1481
|
+
return arr;
|
|
1482
|
+
}
|
|
1483
|
+
function getSequenceArray(len) {
|
|
1484
|
+
return mapSequenceArray(len, (i) => i);
|
|
1485
|
+
}
|
|
1486
|
+
function mapRangeArray(start, end, fn) {
|
|
1487
|
+
if (!isInteger(start)) {
|
|
1488
|
+
throw new Error("mapRangeArray: Invalid start = " + end);
|
|
1489
|
+
}
|
|
1490
|
+
if (!isInteger(end)) {
|
|
1491
|
+
throw new Error("mapRangeArray: Invalid end = " + end);
|
|
1492
|
+
}
|
|
1493
|
+
let len = Math.abs(end - start) + 1;
|
|
1494
|
+
let arr = new Array(len);
|
|
1495
|
+
for (let i = 0, s = start, inc = Math.sign(end - start); i < len; s += inc, i++) {
|
|
1496
|
+
arr[i] = fn(s);
|
|
1497
|
+
}
|
|
1498
|
+
return arr;
|
|
1499
|
+
}
|
|
1500
|
+
function getRangeArray(start, end) {
|
|
1501
|
+
return mapRangeArray(start, end, (i) => i);
|
|
1502
|
+
}
|
|
1503
|
+
function arrayContains(arg, item) {
|
|
1504
|
+
return arg.indexOf(item) >= 0;
|
|
1505
|
+
}
|
|
1506
|
+
function chunckArray(arr, chunckSize) {
|
|
1507
|
+
if (!isInteger(chunckSize) || chunckSize < 1) {
|
|
1508
|
+
throw new Error("chunckArray: Invalid chunckSize = " + chunckSize);
|
|
1509
|
+
}
|
|
1510
|
+
let result = [];
|
|
1511
|
+
for (let i = 0; i < arr.length; i += chunckSize) {
|
|
1512
|
+
result.push(arr.slice(i, i + chunckSize));
|
|
1513
|
+
}
|
|
1514
|
+
return result;
|
|
1515
|
+
}
|
|
1516
|
+
var dom_exports = {};
|
|
1517
|
+
__export2(dom_exports, {
|
|
1518
|
+
addClass: () => addClass,
|
|
1519
|
+
appendTo: () => appendTo,
|
|
1520
|
+
getButton: () => getButton,
|
|
1521
|
+
getCanvas: () => getCanvas,
|
|
1522
|
+
getCanvasTextWidth: () => getCanvasTextWidth,
|
|
1523
|
+
getDimension: () => getDimension,
|
|
1524
|
+
getHeight: () => getHeight,
|
|
1525
|
+
getOffset: () => getOffset,
|
|
1526
|
+
getPadding: () => getPadding,
|
|
1527
|
+
getWidth: () => getWidth,
|
|
1528
|
+
hasClass: () => hasClass,
|
|
1529
|
+
removeClass: () => removeClass,
|
|
1530
|
+
removeFromParent: () => removeFromParent,
|
|
1531
|
+
setHeight: () => setHeight,
|
|
1532
|
+
setOffset: () => setOffset,
|
|
1533
|
+
setRect: () => setRect,
|
|
1534
|
+
setVisibility: () => setVisibility,
|
|
1535
|
+
setWidth: () => setWidth,
|
|
1536
|
+
styleLayoutChanged: () => styleLayoutChanged
|
|
1537
|
+
});
|
|
1538
|
+
function _getElemById(id) {
|
|
1539
|
+
var _a;
|
|
1540
|
+
return typeof document === "undefined" ? void 0 : (_a = document.getElementById(id)) != null ? _a : void 0;
|
|
1541
|
+
}
|
|
1542
|
+
function toPx2(value) {
|
|
1543
|
+
return value === void 0 ? void 0 : device_exports.toPx(value);
|
|
1544
|
+
}
|
|
1545
|
+
function hasClass(el, className) {
|
|
1546
|
+
if (className.length === 0) {
|
|
1547
|
+
return false;
|
|
1548
|
+
} else if (el.classList) {
|
|
1549
|
+
return el.classList.contains(className);
|
|
1550
|
+
} else {
|
|
1551
|
+
return !!el.className.match(new RegExp("(\\s|^)" + className + "(\\s|$)"));
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
function addClass(el, className) {
|
|
1555
|
+
if (className.length === 0) {
|
|
1556
|
+
return;
|
|
1557
|
+
} else if (el.classList) {
|
|
1558
|
+
el.classList.add(className);
|
|
1559
|
+
} else if (!hasClass(el, className)) {
|
|
1560
|
+
el.className += " " + className;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
function removeClass(el, className) {
|
|
1564
|
+
if (className.length === 0) {
|
|
1565
|
+
return;
|
|
1566
|
+
} else if (el.classList) {
|
|
1567
|
+
el.classList.remove(className);
|
|
1568
|
+
} else if (hasClass(el, className)) {
|
|
1569
|
+
var reg = new RegExp("(\\s|^)" + className + "(\\s|$)");
|
|
1570
|
+
el.className = el.className.replace(reg, " ");
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
function setOffset(el, left, top, unit = "px") {
|
|
1574
|
+
el.style.left = left + unit;
|
|
1575
|
+
el.style.top = top + unit;
|
|
1576
|
+
}
|
|
1577
|
+
function getOffset(el) {
|
|
1578
|
+
let { left, top } = el.getBoundingClientRect();
|
|
1579
|
+
if (typeof window !== "undefined") {
|
|
1580
|
+
left += window.pageXOffset;
|
|
1581
|
+
top += window.pageYOffset;
|
|
1582
|
+
}
|
|
1583
|
+
if (typeof document !== "undefined") {
|
|
1584
|
+
let de = document.documentElement;
|
|
1585
|
+
left -= de.clientLeft;
|
|
1586
|
+
top -= de.clientTop;
|
|
1587
|
+
}
|
|
1588
|
+
return { left, top };
|
|
1589
|
+
}
|
|
1590
|
+
function getWidth(el) {
|
|
1591
|
+
if (el instanceof Window) {
|
|
1592
|
+
return el.innerWidth;
|
|
1593
|
+
} else {
|
|
1594
|
+
let w = parseFloat(getComputedStyle(el, null).width.replace("px", ""));
|
|
1595
|
+
return isNaN(w) ? 0 : w;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
function setWidth(el, val) {
|
|
1599
|
+
el.style.width = val + "px";
|
|
1600
|
+
}
|
|
1601
|
+
function getHeight(el) {
|
|
1602
|
+
if (el instanceof Window) {
|
|
1603
|
+
return el.innerHeight;
|
|
1604
|
+
} else {
|
|
1605
|
+
let h = parseFloat(getComputedStyle(el, null).height.replace("px", ""));
|
|
1606
|
+
return isNaN(h) ? 0 : h;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
function setHeight(el, val) {
|
|
1610
|
+
el.style.height = val + "px";
|
|
1611
|
+
}
|
|
1612
|
+
function appendTo(el, to) {
|
|
1613
|
+
to.appendChild(el);
|
|
1614
|
+
}
|
|
1615
|
+
function removeFromParent(el) {
|
|
1616
|
+
el.remove();
|
|
1617
|
+
}
|
|
1618
|
+
function setVisibility(el, visible) {
|
|
1619
|
+
el.style.display = visible ? "block" : "none";
|
|
1620
|
+
}
|
|
1621
|
+
function setRect(el, left, top, width, height, unit = "px") {
|
|
1622
|
+
el.style.left = left + unit;
|
|
1623
|
+
el.style.top = top + unit;
|
|
1624
|
+
el.style.width = width + unit;
|
|
1625
|
+
el.style.height = height + unit;
|
|
1626
|
+
}
|
|
1627
|
+
function getButton(btn) {
|
|
1628
|
+
let el = typeof btn === "string" ? _getElemById(btn) : btn;
|
|
1629
|
+
return el instanceof HTMLButtonElement ? el : void 0;
|
|
1630
|
+
}
|
|
1631
|
+
function getCanvas(canvas2) {
|
|
1632
|
+
let el = typeof canvas2 === "string" ? _getElemById(canvas2) : canvas2;
|
|
1633
|
+
return el instanceof HTMLCanvasElement ? el : void 0;
|
|
1634
|
+
}
|
|
1635
|
+
function getPadding(style) {
|
|
1636
|
+
var _a;
|
|
1637
|
+
if (!style) {
|
|
1638
|
+
return { top: 0, right: 0, bottom: 0, left: 0 };
|
|
1639
|
+
}
|
|
1640
|
+
let top = toPx2(style.paddingTop);
|
|
1641
|
+
let right = toPx2(style.paddingRight);
|
|
1642
|
+
let bottom = toPx2(style.paddingBottom);
|
|
1643
|
+
let left = toPx2(style.paddingLeft);
|
|
1644
|
+
let padding = ((_a = style.padding) != null ? _a : "").toString().split(" ").filter((s) => s.length > 0);
|
|
1645
|
+
switch (padding.length) {
|
|
1646
|
+
case 0:
|
|
1647
|
+
break;
|
|
1648
|
+
case 1:
|
|
1649
|
+
top != null ? top : top = toPx2(padding[0]);
|
|
1650
|
+
right != null ? right : right = toPx2(padding[0]);
|
|
1651
|
+
bottom != null ? bottom : bottom = toPx2(padding[0]);
|
|
1652
|
+
left != null ? left : left = toPx2(padding[0]);
|
|
1653
|
+
break;
|
|
1654
|
+
case 2:
|
|
1655
|
+
top != null ? top : top = toPx2(padding[0]);
|
|
1656
|
+
right != null ? right : right = toPx2(padding[1]);
|
|
1657
|
+
bottom != null ? bottom : bottom = toPx2(padding[0]);
|
|
1658
|
+
left != null ? left : left = toPx2(padding[1]);
|
|
1659
|
+
break;
|
|
1660
|
+
case 3:
|
|
1661
|
+
top != null ? top : top = toPx2(padding[0]);
|
|
1662
|
+
right != null ? right : right = toPx2(padding[1]);
|
|
1663
|
+
bottom != null ? bottom : bottom = toPx2(padding[2]);
|
|
1664
|
+
left != null ? left : left = toPx2(padding[1]);
|
|
1665
|
+
break;
|
|
1666
|
+
case 4:
|
|
1667
|
+
default:
|
|
1668
|
+
top != null ? top : top = toPx2(padding[0]);
|
|
1669
|
+
right != null ? right : right = toPx2(padding[1]);
|
|
1670
|
+
bottom != null ? bottom : bottom = toPx2(padding[2]);
|
|
1671
|
+
left != null ? left : left = toPx2(padding[3]);
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
top != null ? top : top = 0;
|
|
1675
|
+
right != null ? right : right = 0;
|
|
1676
|
+
bottom != null ? bottom : bottom = 0;
|
|
1677
|
+
left != null ? left : left = 0;
|
|
1678
|
+
return { top, right, bottom, left };
|
|
1679
|
+
}
|
|
1680
|
+
function getDimension(style) {
|
|
1681
|
+
let left = toPx2(style == null ? void 0 : style.left);
|
|
1682
|
+
let right = toPx2(style == null ? void 0 : style.right);
|
|
1683
|
+
let top = toPx2(style == null ? void 0 : style.top);
|
|
1684
|
+
let bottom = toPx2(style == null ? void 0 : style.bottom);
|
|
1685
|
+
let width = toPx2(style == null ? void 0 : style.width);
|
|
1686
|
+
let height = toPx2(style == null ? void 0 : style.height);
|
|
1687
|
+
if (width === void 0 && left !== void 0 && right !== void 0) {
|
|
1688
|
+
width = right - left;
|
|
1689
|
+
}
|
|
1690
|
+
if (height === void 0 && top !== void 0 && bottom !== void 0) {
|
|
1691
|
+
height = bottom - top;
|
|
1692
|
+
}
|
|
1693
|
+
return { left, top, width, height };
|
|
1694
|
+
}
|
|
1695
|
+
function styleLayoutChanged(style1, style2) {
|
|
1696
|
+
if (!style1 && !style2) {
|
|
1697
|
+
return false;
|
|
1698
|
+
} else if (!style1 || !style2) {
|
|
1699
|
+
return true;
|
|
1700
|
+
} else {
|
|
1701
|
+
return style1.left !== style2.left || style1.top !== style2.top || style1.right !== style2.right || style1.bottom !== style2.bottom || style1.width !== style2.width || style1.height !== style2.height;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
var canvas;
|
|
1705
|
+
function getCanvasTextWidth(text, font) {
|
|
1706
|
+
if (!canvas && typeof document !== "undefined")
|
|
1707
|
+
canvas = document.createElement("canvas");
|
|
1708
|
+
let ctx = canvas == null ? void 0 : canvas.getContext("2d");
|
|
1709
|
+
if (!ctx)
|
|
1710
|
+
return 0;
|
|
1711
|
+
ctx.font = font;
|
|
1712
|
+
return ctx.measureText(text).width;
|
|
1713
|
+
}
|
|
1714
|
+
var math_exports = {};
|
|
1715
|
+
__export2(math_exports, {
|
|
1716
|
+
avg: () => avg,
|
|
1717
|
+
calcNormal: () => calcNormal,
|
|
1718
|
+
clamp: () => clamp,
|
|
1719
|
+
cmp: () => cmp,
|
|
1720
|
+
interpolateCoord: () => interpolateCoord,
|
|
1721
|
+
interpolateY: () => interpolateY,
|
|
1722
|
+
isInteger: () => isInteger,
|
|
1723
|
+
isNumber: () => isNumber,
|
|
1724
|
+
linearToDecibels: () => linearToDecibels,
|
|
1725
|
+
mod: () => mod,
|
|
1726
|
+
romanize: () => romanize,
|
|
1727
|
+
sum: () => sum,
|
|
1728
|
+
toOrdinalNumber: () => toOrdinalNumber
|
|
1729
|
+
});
|
|
1730
|
+
function linearToDecibels(linearVolume) {
|
|
1731
|
+
if (!isFinite(linearVolume)) {
|
|
1732
|
+
throw new Error("linearToDecibel: Invalid linearVolume = " + linearVolume);
|
|
1733
|
+
} else if (linearVolume <= 0) {
|
|
1734
|
+
return -Infinity;
|
|
1735
|
+
} else {
|
|
1736
|
+
return 20 * Math.log10(linearVolume);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function mod(m, n) {
|
|
1740
|
+
return (m % n + n) % n;
|
|
1741
|
+
}
|
|
1742
|
+
function romanize(n) {
|
|
1743
|
+
if (!isInteger(n) || n < 0) {
|
|
1744
|
+
throw new Error("romanize: Invalid n = " + n);
|
|
1745
|
+
}
|
|
1746
|
+
var digits = String(+n).split("");
|
|
1747
|
+
var key = [
|
|
1748
|
+
"",
|
|
1749
|
+
"C",
|
|
1750
|
+
"CC",
|
|
1751
|
+
"CCC",
|
|
1752
|
+
"CD",
|
|
1753
|
+
"D",
|
|
1754
|
+
"DC",
|
|
1755
|
+
"DCC",
|
|
1756
|
+
"DCCC",
|
|
1757
|
+
"CM",
|
|
1758
|
+
"",
|
|
1759
|
+
"X",
|
|
1760
|
+
"XX",
|
|
1761
|
+
"XXX",
|
|
1762
|
+
"XL",
|
|
1763
|
+
"L",
|
|
1764
|
+
"LX",
|
|
1765
|
+
"LXX",
|
|
1766
|
+
"LXXX",
|
|
1767
|
+
"XC",
|
|
1768
|
+
"",
|
|
1769
|
+
"I",
|
|
1770
|
+
"II",
|
|
1771
|
+
"III",
|
|
1772
|
+
"IV",
|
|
1773
|
+
"V",
|
|
1774
|
+
"VI",
|
|
1775
|
+
"VII",
|
|
1776
|
+
"VIII",
|
|
1777
|
+
"IX"
|
|
1778
|
+
];
|
|
1779
|
+
var roman = "", i = 3;
|
|
1780
|
+
while (i--) roman = (key[+digits.pop() + i * 10] || "") + roman;
|
|
1781
|
+
return Array(+digits.join("") + 1).join("M") + roman;
|
|
1782
|
+
}
|
|
1783
|
+
function toOrdinalNumber(n) {
|
|
1784
|
+
if (!isInteger(n)) {
|
|
1785
|
+
throw new Error("toOrdinalNumber: Invalid n = " + n);
|
|
1786
|
+
}
|
|
1787
|
+
const nStr = n.toString();
|
|
1788
|
+
const lastDigit = Number(nStr.charAt(nStr.length - 1));
|
|
1789
|
+
if (n === 1 || n >= 20 && lastDigit === 1) {
|
|
1790
|
+
return nStr + "st";
|
|
1791
|
+
} else if (n === 2 || n >= 20 && lastDigit === 2) {
|
|
1792
|
+
return nStr + "nd";
|
|
1793
|
+
} else if (n === 3 || n >= 20 && lastDigit === 3) {
|
|
1794
|
+
return nStr + "rd";
|
|
1795
|
+
} else {
|
|
1796
|
+
return nStr + "th";
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
function interpolateCoord(startX, startY, endX, endY, t) {
|
|
1800
|
+
return {
|
|
1801
|
+
x: startX + (endX - startX) * t,
|
|
1802
|
+
y: startY + (endY - startY) * t
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
function interpolateY(startX, startY, endX, endY, x) {
|
|
1806
|
+
let t = (x - startX) / (endX - startX);
|
|
1807
|
+
return startY + (endY - startY) * t;
|
|
1808
|
+
}
|
|
1809
|
+
function clamp(num, min, max) {
|
|
1810
|
+
return Math.min(Math.max(num, min), max);
|
|
1811
|
+
}
|
|
1812
|
+
function calcNormal(x1, y1, x2, y2) {
|
|
1813
|
+
let dx = x2 - x1;
|
|
1814
|
+
let dy = y2 - y1;
|
|
1815
|
+
let nx = -dy;
|
|
1816
|
+
let ny = dx;
|
|
1817
|
+
let len = Math.sqrt(nx * nx + ny * ny);
|
|
1818
|
+
if (len > 0) {
|
|
1819
|
+
nx /= len;
|
|
1820
|
+
ny /= len;
|
|
1821
|
+
} else {
|
|
1822
|
+
nx = 0;
|
|
1823
|
+
ny = 1;
|
|
1824
|
+
}
|
|
1825
|
+
return { nx, ny };
|
|
1826
|
+
}
|
|
1827
|
+
function sum(arr) {
|
|
1828
|
+
return arr.reduce((prev, cur) => cur + prev, 0);
|
|
1829
|
+
}
|
|
1830
|
+
function avg(...values) {
|
|
1831
|
+
return sum(values) / values.length;
|
|
1832
|
+
}
|
|
1833
|
+
function cmp(a, b) {
|
|
1834
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
1835
|
+
}
|
|
1836
|
+
var DefaultEqualityFn = (a, b) => a === b;
|
|
1837
|
+
var BaseContainer = class {
|
|
1838
|
+
};
|
|
1839
|
+
var LRUCache = class extends BaseContainer {
|
|
1840
|
+
// Maximum key length.
|
|
1841
|
+
constructor(maxSize, maxKeyLength = Infinity) {
|
|
1842
|
+
super();
|
|
1843
|
+
__publicField2(this, "cache");
|
|
1844
|
+
__publicField2(this, "next");
|
|
1845
|
+
__publicField2(this, "prev");
|
|
1846
|
+
__publicField2(this, "head");
|
|
1847
|
+
__publicField2(this, "tail");
|
|
1848
|
+
__publicField2(this, "capacity");
|
|
1849
|
+
__publicField2(this, "size");
|
|
1850
|
+
__publicField2(this, "maxKeyLength");
|
|
1851
|
+
this.cache = /* @__PURE__ */ Object.create(null);
|
|
1852
|
+
this.next = /* @__PURE__ */ Object.create(null);
|
|
1853
|
+
this.prev = /* @__PURE__ */ Object.create(null);
|
|
1854
|
+
this.head = null;
|
|
1855
|
+
this.tail = null;
|
|
1856
|
+
this.capacity = maxSize;
|
|
1857
|
+
this.size = 0;
|
|
1858
|
+
this.maxKeyLength = maxKeyLength;
|
|
1859
|
+
}
|
|
1860
|
+
// Retrieves a value from the cache
|
|
1861
|
+
get(key) {
|
|
1862
|
+
if (key.length > this.maxKeyLength) return void 0;
|
|
1863
|
+
if (this.cache[key] !== void 0) {
|
|
1864
|
+
this.touch(key);
|
|
1865
|
+
return this.cache[key];
|
|
1866
|
+
}
|
|
1867
|
+
return void 0;
|
|
1868
|
+
}
|
|
1869
|
+
set(key, value) {
|
|
1870
|
+
if (key.length > this.maxKeyLength) {
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
if (this.cache[key] !== void 0) {
|
|
1874
|
+
this.cache[key] = value;
|
|
1875
|
+
this.touch(key);
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
if (this.size >= this.capacity) {
|
|
1879
|
+
this.evict();
|
|
1880
|
+
}
|
|
1881
|
+
this.cache[key] = value;
|
|
1882
|
+
this.addToTail(key);
|
|
1883
|
+
this.size++;
|
|
1884
|
+
}
|
|
1885
|
+
// Marks a key as most recently used
|
|
1886
|
+
touch(key) {
|
|
1887
|
+
if (this.tail === key) return;
|
|
1888
|
+
this.removeKey(key);
|
|
1889
|
+
this.addToTail(key);
|
|
1890
|
+
}
|
|
1891
|
+
// Evicts the least recently used item (at the head)
|
|
1892
|
+
evict() {
|
|
1893
|
+
if (this.head !== null) {
|
|
1894
|
+
const oldestKey = this.head;
|
|
1895
|
+
this.removeKey(oldestKey);
|
|
1896
|
+
delete this.cache[oldestKey];
|
|
1897
|
+
this.size--;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
// Removes a key from the linked list
|
|
1901
|
+
removeKey(key) {
|
|
1902
|
+
const prevKey = this.prev[key];
|
|
1903
|
+
const nextKey = this.next[key];
|
|
1904
|
+
if (prevKey !== void 0) {
|
|
1905
|
+
this.next[prevKey] = nextKey;
|
|
1906
|
+
} else {
|
|
1907
|
+
this.head = nextKey != null ? nextKey : null;
|
|
1908
|
+
}
|
|
1909
|
+
if (nextKey !== void 0) {
|
|
1910
|
+
this.prev[nextKey] = prevKey;
|
|
1911
|
+
} else {
|
|
1912
|
+
this.tail = prevKey != null ? prevKey : null;
|
|
1913
|
+
}
|
|
1914
|
+
delete this.prev[key];
|
|
1915
|
+
delete this.next[key];
|
|
1916
|
+
}
|
|
1917
|
+
// Adds a key to the tail (most recently used position)
|
|
1918
|
+
addToTail(key) {
|
|
1919
|
+
if (this.tail !== null) {
|
|
1920
|
+
this.next[this.tail] = key;
|
|
1921
|
+
this.prev[key] = this.tail;
|
|
1922
|
+
} else {
|
|
1923
|
+
this.head = key;
|
|
1924
|
+
}
|
|
1925
|
+
this.tail = key;
|
|
1926
|
+
}
|
|
1927
|
+
*keys() {
|
|
1928
|
+
for (let key = this.head; key != null; key = this.next[key])
|
|
1929
|
+
yield key;
|
|
1930
|
+
}
|
|
1931
|
+
*values() {
|
|
1932
|
+
for (let key = this.head; key != null; key = this.next[key])
|
|
1933
|
+
yield this.cache[key];
|
|
1934
|
+
}
|
|
1935
|
+
*entries() {
|
|
1936
|
+
for (let key = this.head; key != null; key = this.next[key])
|
|
1937
|
+
yield [key, this.cache[key]];
|
|
1938
|
+
}
|
|
1939
|
+
*[Symbol.iterator]() {
|
|
1940
|
+
yield* __yieldStar(this.entries());
|
|
1941
|
+
}
|
|
1942
|
+
toString() {
|
|
1943
|
+
const entries = [...this.entries()];
|
|
1944
|
+
return entries.length === 0 ? `LRUCache(0){ }` : `LRUCache(${entries.length}){ ${entries.map((e) => `${stringify(e[0])}: ${stringify(e[1])}`).join(", ")} }`;
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
var IndexArray = class _IndexArray extends BaseContainer {
|
|
1948
|
+
constructor(entries) {
|
|
1949
|
+
super();
|
|
1950
|
+
__publicField2(this, "posVal");
|
|
1951
|
+
__publicField2(this, "hasPos");
|
|
1952
|
+
__publicField2(this, "valCount");
|
|
1953
|
+
if (entries instanceof _IndexArray) {
|
|
1954
|
+
this.posVal = entries.posVal.slice();
|
|
1955
|
+
this.hasPos = entries.hasPos.slice();
|
|
1956
|
+
this.valCount = entries.valCount;
|
|
1957
|
+
} else {
|
|
1958
|
+
this.posVal = [];
|
|
1959
|
+
this.hasPos = [];
|
|
1960
|
+
this.valCount = 0;
|
|
1961
|
+
if (entries) {
|
|
1962
|
+
for (const [id, value] of entries) {
|
|
1963
|
+
this.set(id, value);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
static validateIndex(id) {
|
|
1969
|
+
if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
|
|
1970
|
+
return id;
|
|
1971
|
+
}
|
|
1972
|
+
get posLen() {
|
|
1973
|
+
return this.hasPos.length;
|
|
1974
|
+
}
|
|
1975
|
+
get size() {
|
|
1976
|
+
return this.valCount;
|
|
1977
|
+
}
|
|
1978
|
+
get length() {
|
|
1979
|
+
return this.hasPos.length;
|
|
1980
|
+
}
|
|
1981
|
+
trimRight() {
|
|
1982
|
+
let newLength = this.length;
|
|
1983
|
+
while (newLength > 0 && this.hasPos[newLength - 1] !== true) newLength--;
|
|
1984
|
+
if (newLength < this.length) this.posVal.length = this.hasPos.length = newLength;
|
|
1985
|
+
}
|
|
1986
|
+
isEmpty() {
|
|
1987
|
+
return this.size === 0;
|
|
1988
|
+
}
|
|
1989
|
+
has(id) {
|
|
1990
|
+
_IndexArray.validateIndex(id);
|
|
1991
|
+
return this.hasPos[id] === true;
|
|
1992
|
+
}
|
|
1993
|
+
set(id, value) {
|
|
1994
|
+
_IndexArray.validateIndex(id);
|
|
1995
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1996
|
+
this.posVal[id] = value;
|
|
1997
|
+
this.hasPos[id] = true;
|
|
1998
|
+
}
|
|
1999
|
+
get(id) {
|
|
2000
|
+
_IndexArray.validateIndex(id);
|
|
2001
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
2002
|
+
}
|
|
2003
|
+
getOrDefault(id, defaultValue) {
|
|
2004
|
+
var _a;
|
|
2005
|
+
return (_a = this.get(id)) != null ? _a : defaultValue;
|
|
2006
|
+
}
|
|
2007
|
+
getOrCreate(id, creatorOrValue) {
|
|
2008
|
+
if (!this.has(id)) {
|
|
2009
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
2010
|
+
this.set(id, value);
|
|
2011
|
+
return value;
|
|
2012
|
+
}
|
|
2013
|
+
return this.get(id);
|
|
2014
|
+
}
|
|
2015
|
+
delete(id) {
|
|
2016
|
+
_IndexArray.validateIndex(id);
|
|
2017
|
+
if (!this.hasPos[id]) return false;
|
|
2018
|
+
this.posVal[id] = void 0;
|
|
2019
|
+
this.hasPos[id] = false;
|
|
2020
|
+
this.valCount--;
|
|
2021
|
+
this.trimRight();
|
|
2022
|
+
return true;
|
|
2023
|
+
}
|
|
2024
|
+
clear() {
|
|
2025
|
+
this.posVal = [];
|
|
2026
|
+
this.hasPos = [];
|
|
2027
|
+
this.valCount = 0;
|
|
2028
|
+
}
|
|
2029
|
+
forEach(callbackfn, thisArg) {
|
|
2030
|
+
for (const [id, value] of this.entries()) {
|
|
2031
|
+
callbackfn.call(thisArg, value, id, this);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
*indices() {
|
|
2035
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
2036
|
+
if (this.hasPos[id]) yield id;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
*values() {
|
|
2040
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
2041
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
*entries() {
|
|
2045
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
2046
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
indicesArray() {
|
|
2050
|
+
return [...this.indices()];
|
|
2051
|
+
}
|
|
2052
|
+
valuesArray() {
|
|
2053
|
+
return [...this.values()];
|
|
2054
|
+
}
|
|
2055
|
+
entriesArray() {
|
|
2056
|
+
return [...this.entries()];
|
|
2057
|
+
}
|
|
2058
|
+
*kvKeys() {
|
|
2059
|
+
for (const id of this.indices()) {
|
|
2060
|
+
yield [id];
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
*kvValues() {
|
|
2064
|
+
for (const value of this.values()) {
|
|
2065
|
+
yield value;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
*kvEntries() {
|
|
2069
|
+
for (const [id, value] of this.entries()) {
|
|
2070
|
+
yield [[id], value];
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
*[Symbol.iterator]() {
|
|
2074
|
+
yield* __yieldStar(this.entries());
|
|
2075
|
+
}
|
|
2076
|
+
clone() {
|
|
2077
|
+
return new _IndexArray(this);
|
|
2078
|
+
}
|
|
2079
|
+
merge(other, conflictResolver) {
|
|
2080
|
+
for (const [id, value] of other.entries()) {
|
|
2081
|
+
if (this.has(id) && conflictResolver) {
|
|
2082
|
+
this.set(id, conflictResolver(this.get(id), value, id));
|
|
2083
|
+
} else {
|
|
2084
|
+
this.set(id, value);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
return this;
|
|
2088
|
+
}
|
|
2089
|
+
some(fn) {
|
|
2090
|
+
for (const [id, value] of this.entries()) {
|
|
2091
|
+
if (fn(value, id)) return true;
|
|
2092
|
+
}
|
|
2093
|
+
return false;
|
|
2094
|
+
}
|
|
2095
|
+
every(fn) {
|
|
2096
|
+
for (const [id, value] of this.entries()) {
|
|
2097
|
+
if (!fn(value, id)) return false;
|
|
2098
|
+
}
|
|
2099
|
+
return true;
|
|
2100
|
+
}
|
|
2101
|
+
filter(predicate) {
|
|
2102
|
+
const result = new this.constructor();
|
|
2103
|
+
for (const [id, value] of this.entries()) {
|
|
2104
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
2105
|
+
}
|
|
2106
|
+
return result;
|
|
2107
|
+
}
|
|
2108
|
+
reduce(fn, init) {
|
|
2109
|
+
let iterator = this.entries();
|
|
2110
|
+
let first = iterator.next();
|
|
2111
|
+
if (first.done) {
|
|
2112
|
+
if (arguments.length < 2) {
|
|
2113
|
+
throw new TypeError("Reduce of empty IndexArray with no initial value!");
|
|
2114
|
+
}
|
|
2115
|
+
return init;
|
|
2116
|
+
}
|
|
2117
|
+
let acc;
|
|
2118
|
+
let start;
|
|
2119
|
+
if (arguments.length < 2) {
|
|
2120
|
+
acc = first.value[1];
|
|
2121
|
+
start = iterator.next();
|
|
2122
|
+
} else {
|
|
2123
|
+
acc = init;
|
|
2124
|
+
start = first;
|
|
2125
|
+
}
|
|
2126
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2127
|
+
const [id, value] = current.value;
|
|
2128
|
+
acc = fn(acc, value, id);
|
|
2129
|
+
}
|
|
2130
|
+
return acc;
|
|
2131
|
+
}
|
|
2132
|
+
mapToArray(fn) {
|
|
2133
|
+
let result = [];
|
|
2134
|
+
for (const [id, value] of this.entries()) {
|
|
2135
|
+
result.push(fn(value, id));
|
|
2136
|
+
}
|
|
2137
|
+
return result;
|
|
2138
|
+
}
|
|
2139
|
+
map(fn) {
|
|
2140
|
+
let result = new _IndexArray();
|
|
2141
|
+
for (const [id, value] of this.entries()) {
|
|
2142
|
+
result.set(id, fn(value, id));
|
|
2143
|
+
}
|
|
2144
|
+
return result;
|
|
2145
|
+
}
|
|
2146
|
+
equals(other, eq) {
|
|
2147
|
+
if (this.size !== other.size) return false;
|
|
2148
|
+
eq != null ? eq : eq = (a, b) => a === b;
|
|
2149
|
+
const posLen = Math.max(this.posLen, other.posLen);
|
|
2150
|
+
for (let i = 0; i < posLen; ++i) {
|
|
2151
|
+
const hasA = this.hasPos[i];
|
|
2152
|
+
const hasB = other.hasPos[i];
|
|
2153
|
+
if (hasA !== hasB) return false;
|
|
2154
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
2155
|
+
}
|
|
2156
|
+
return true;
|
|
2157
|
+
}
|
|
2158
|
+
toArray() {
|
|
2159
|
+
return this.valuesArray();
|
|
2160
|
+
}
|
|
2161
|
+
toString() {
|
|
2162
|
+
let isRegularArray = true;
|
|
2163
|
+
for (let i = 0; i < this.hasPos.length && isRegularArray; i++)
|
|
2164
|
+
if (!this.hasPos[i]) isRegularArray = false;
|
|
2165
|
+
if (isRegularArray)
|
|
2166
|
+
return stringify(this.posVal.slice(0, this.hasPos.length));
|
|
2167
|
+
const entries = this.entriesArray().map(([id, v]) => `${stringify(id)}: ${stringify(v)}`).join(", ");
|
|
2168
|
+
return entries.length === 0 ? `[ ]` : `[ ${entries} ]`;
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
var SignedIndexArray = class _SignedIndexArray extends BaseContainer {
|
|
2172
|
+
constructor(entries) {
|
|
2173
|
+
super();
|
|
2174
|
+
__publicField2(this, "posVal");
|
|
2175
|
+
__publicField2(this, "hasPos");
|
|
2176
|
+
__publicField2(this, "negVal");
|
|
2177
|
+
__publicField2(this, "hasNeg");
|
|
2178
|
+
__publicField2(this, "valCount");
|
|
2179
|
+
if (entries instanceof _SignedIndexArray) {
|
|
2180
|
+
this.negVal = entries.negVal.slice();
|
|
2181
|
+
this.hasNeg = entries.hasNeg.slice();
|
|
2182
|
+
this.posVal = entries.posVal.slice();
|
|
2183
|
+
this.hasPos = entries.hasPos.slice();
|
|
2184
|
+
this.valCount = entries.valCount;
|
|
2185
|
+
} else {
|
|
2186
|
+
this.negVal = [];
|
|
2187
|
+
this.hasNeg = [];
|
|
2188
|
+
this.posVal = [];
|
|
2189
|
+
this.hasPos = [];
|
|
2190
|
+
this.valCount = 0;
|
|
2191
|
+
if (entries) {
|
|
2192
|
+
for (const [id, value] of entries) {
|
|
2193
|
+
this.set(id, value);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
static toNegIndex(id) {
|
|
2199
|
+
return -id - 1;
|
|
2200
|
+
}
|
|
2201
|
+
static validateIndex(id) {
|
|
2202
|
+
if (!isInteger(id)) throw new Error(`Invalid index ${id} - must be an integer!`);
|
|
2203
|
+
return id;
|
|
2204
|
+
}
|
|
2205
|
+
get size() {
|
|
2206
|
+
return this.valCount;
|
|
2207
|
+
}
|
|
2208
|
+
isEmpty() {
|
|
2209
|
+
return this.size === 0;
|
|
2210
|
+
}
|
|
2211
|
+
get posLen() {
|
|
2212
|
+
return this.hasPos.length;
|
|
2213
|
+
}
|
|
2214
|
+
get negLen() {
|
|
2215
|
+
return this.hasNeg.length;
|
|
2216
|
+
}
|
|
2217
|
+
has(id) {
|
|
2218
|
+
_SignedIndexArray.validateIndex(id);
|
|
2219
|
+
if (id >= 0) {
|
|
2220
|
+
return this.hasPos[id] === true;
|
|
2221
|
+
} else {
|
|
2222
|
+
return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
set(id, value) {
|
|
2226
|
+
_SignedIndexArray.validateIndex(id);
|
|
2227
|
+
if (id >= 0) {
|
|
2228
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
2229
|
+
this.posVal[id] = value;
|
|
2230
|
+
this.hasPos[id] = true;
|
|
2231
|
+
} else {
|
|
2232
|
+
let negId = _SignedIndexArray.toNegIndex(id);
|
|
2233
|
+
if (this.hasNeg[negId] !== true) this.valCount++;
|
|
2234
|
+
this.negVal[negId] = value;
|
|
2235
|
+
this.hasNeg[negId] = true;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
get(id) {
|
|
2239
|
+
_SignedIndexArray.validateIndex(id);
|
|
2240
|
+
if (id >= 0) {
|
|
2241
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
2242
|
+
} else {
|
|
2243
|
+
let negId = _SignedIndexArray.toNegIndex(id);
|
|
2244
|
+
return this.hasNeg[negId] ? this.negVal[negId] : void 0;
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
getOrDefault(id, defaultValue) {
|
|
2248
|
+
var _a;
|
|
2249
|
+
return (_a = this.get(id)) != null ? _a : defaultValue;
|
|
2250
|
+
}
|
|
2251
|
+
getOrCreate(id, creatorOrValue) {
|
|
2252
|
+
if (!this.has(id)) {
|
|
2253
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
2254
|
+
this.set(id, value);
|
|
2255
|
+
return value;
|
|
2256
|
+
}
|
|
2257
|
+
return this.get(id);
|
|
2258
|
+
}
|
|
2259
|
+
delete(id) {
|
|
2260
|
+
_SignedIndexArray.validateIndex(id);
|
|
2261
|
+
const isPos3 = id >= 0;
|
|
2262
|
+
const arr = isPos3 ? this.posVal : this.negVal;
|
|
2263
|
+
const has = isPos3 ? this.hasPos : this.hasNeg;
|
|
2264
|
+
const idx = isPos3 ? id : _SignedIndexArray.toNegIndex(id);
|
|
2265
|
+
if (!has[idx]) return false;
|
|
2266
|
+
arr[idx] = void 0;
|
|
2267
|
+
has[idx] = false;
|
|
2268
|
+
this.valCount--;
|
|
2269
|
+
return true;
|
|
2270
|
+
}
|
|
2271
|
+
clear() {
|
|
2272
|
+
this.negVal = [];
|
|
2273
|
+
this.hasNeg = [];
|
|
2274
|
+
this.posVal = [];
|
|
2275
|
+
this.hasPos = [];
|
|
2276
|
+
this.valCount = 0;
|
|
2277
|
+
}
|
|
2278
|
+
forEach(callbackfn, thisArg) {
|
|
2279
|
+
for (const [id, value] of this.entries()) {
|
|
2280
|
+
callbackfn.call(thisArg, value, id, this);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
*indices() {
|
|
2284
|
+
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
2285
|
+
if (this.hasNeg[id]) yield _SignedIndexArray.toNegIndex(id);
|
|
2286
|
+
}
|
|
2287
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
2288
|
+
if (this.hasPos[id]) yield id;
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
*values() {
|
|
2292
|
+
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
2293
|
+
if (this.hasNeg[id]) yield this.negVal[id];
|
|
2294
|
+
}
|
|
2295
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
2296
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
*entries() {
|
|
2300
|
+
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
2301
|
+
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negVal[id]];
|
|
2302
|
+
}
|
|
2303
|
+
for (let id = 0; id < this.posLen; id++) {
|
|
2304
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
indicesArray() {
|
|
2308
|
+
return [...this.indices()];
|
|
2309
|
+
}
|
|
2310
|
+
valuesArray() {
|
|
2311
|
+
return [...this.values()];
|
|
2312
|
+
}
|
|
2313
|
+
entriesArray() {
|
|
2314
|
+
return [...this.entries()];
|
|
2315
|
+
}
|
|
2316
|
+
*kvKeys() {
|
|
2317
|
+
for (const id of this.indices()) {
|
|
2318
|
+
yield [id];
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
*kvValues() {
|
|
2322
|
+
for (const value of this.values()) {
|
|
2323
|
+
yield value;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
*kvEntries() {
|
|
2327
|
+
for (const [id, value] of this.entries()) {
|
|
2328
|
+
yield [[id], value];
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
*[Symbol.iterator]() {
|
|
2332
|
+
yield* __yieldStar(this.entries());
|
|
2333
|
+
}
|
|
2334
|
+
clone() {
|
|
2335
|
+
return new _SignedIndexArray(this);
|
|
2336
|
+
}
|
|
2337
|
+
merge(other, conflictResolver) {
|
|
2338
|
+
for (const [id, value] of other.entries()) {
|
|
2339
|
+
if (this.has(id) && conflictResolver) {
|
|
2340
|
+
this.set(id, conflictResolver(this.get(id), value, id));
|
|
2341
|
+
} else {
|
|
2342
|
+
this.set(id, value);
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
return this;
|
|
2346
|
+
}
|
|
2347
|
+
some(fn) {
|
|
2348
|
+
for (const [id, value] of this.entries()) {
|
|
2349
|
+
if (fn(value, id)) return true;
|
|
2350
|
+
}
|
|
2351
|
+
return false;
|
|
2352
|
+
}
|
|
2353
|
+
every(fn) {
|
|
2354
|
+
for (const [id, value] of this.entries()) {
|
|
2355
|
+
if (!fn(value, id)) return false;
|
|
2356
|
+
}
|
|
2357
|
+
return true;
|
|
2358
|
+
}
|
|
2359
|
+
filter(predicate) {
|
|
2360
|
+
const result = new this.constructor();
|
|
2361
|
+
for (const [id, value] of this.entries()) {
|
|
2362
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
2363
|
+
}
|
|
2364
|
+
return result;
|
|
2365
|
+
}
|
|
2366
|
+
reduce(fn, init) {
|
|
2367
|
+
let iterator = this.entries();
|
|
2368
|
+
let first = iterator.next();
|
|
2369
|
+
if (first.done) {
|
|
2370
|
+
if (arguments.length < 2) {
|
|
2371
|
+
throw new TypeError("Reduce of empty SignedIndexArray with no initial value!");
|
|
2372
|
+
}
|
|
2373
|
+
return init;
|
|
2374
|
+
}
|
|
2375
|
+
let acc;
|
|
2376
|
+
let start;
|
|
2377
|
+
if (arguments.length < 2) {
|
|
2378
|
+
acc = first.value[1];
|
|
2379
|
+
start = iterator.next();
|
|
2380
|
+
} else {
|
|
2381
|
+
acc = init;
|
|
2382
|
+
start = first;
|
|
2383
|
+
}
|
|
2384
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2385
|
+
const [id, value] = current.value;
|
|
2386
|
+
acc = fn(acc, value, id);
|
|
2387
|
+
}
|
|
2388
|
+
return acc;
|
|
2389
|
+
}
|
|
2390
|
+
mapToArray(fn) {
|
|
2391
|
+
let result = [];
|
|
2392
|
+
for (const [id, value] of this.entries()) {
|
|
2393
|
+
result.push(fn(value, id));
|
|
2394
|
+
}
|
|
2395
|
+
return result;
|
|
2396
|
+
}
|
|
2397
|
+
map(fn) {
|
|
2398
|
+
let result = new _SignedIndexArray();
|
|
2399
|
+
for (const [id, value] of this.entries()) {
|
|
2400
|
+
result.set(id, fn(value, id));
|
|
2401
|
+
}
|
|
2402
|
+
return result;
|
|
2403
|
+
}
|
|
2404
|
+
equals(other, eq) {
|
|
2405
|
+
if (this.size !== other.size) return false;
|
|
2406
|
+
eq != null ? eq : eq = (a, b) => a === b;
|
|
2407
|
+
const posLen = Math.max(this.posLen, other.posLen);
|
|
2408
|
+
for (let i = 0; i < posLen; ++i) {
|
|
2409
|
+
const hasA = this.hasPos[i];
|
|
2410
|
+
const hasB = other.hasPos[i];
|
|
2411
|
+
if (hasA !== hasB) return false;
|
|
2412
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
2413
|
+
}
|
|
2414
|
+
const negLen = Math.max(this.negLen, other.negLen);
|
|
2415
|
+
for (let i = 0; i < negLen; ++i) {
|
|
2416
|
+
const hasA = this.hasNeg[i];
|
|
2417
|
+
const hasB = other.hasNeg[i];
|
|
2418
|
+
if (hasA !== hasB) return false;
|
|
2419
|
+
if (hasA && !eq(this.negVal[i], other.negVal[i])) return false;
|
|
2420
|
+
}
|
|
2421
|
+
return true;
|
|
2422
|
+
}
|
|
2423
|
+
toArray() {
|
|
2424
|
+
return this.valuesArray();
|
|
2425
|
+
}
|
|
2426
|
+
toString() {
|
|
2427
|
+
let isRegularArray = this.hasNeg.length === 0;
|
|
2428
|
+
for (let i = 0; i < this.hasPos.length && isRegularArray; i++)
|
|
2429
|
+
if (!this.hasPos[i]) isRegularArray = false;
|
|
2430
|
+
if (isRegularArray)
|
|
2431
|
+
return stringify(this.posVal.slice(0, this.hasPos.length));
|
|
2432
|
+
const entries = this.entriesArray().map(([id, v]) => `${stringify(id)}: ${stringify(v)}`).join(", ");
|
|
2433
|
+
return entries.length === 0 ? `[ ]` : `[ ${entries} ]`;
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
var UniMap = class _UniMap extends BaseContainer {
|
|
2437
|
+
constructor(...args) {
|
|
2438
|
+
super();
|
|
2439
|
+
__publicField2(this, "map");
|
|
2440
|
+
__publicField2(this, "keyEquals");
|
|
2441
|
+
const maybeEquals = args.at(-1);
|
|
2442
|
+
this.keyEquals = isFunction(maybeEquals) ? args.pop() : DefaultEqualityFn;
|
|
2443
|
+
const entries = args[0];
|
|
2444
|
+
this.map = new Map(entries);
|
|
2445
|
+
}
|
|
2446
|
+
static createDeep(arg) {
|
|
2447
|
+
return arg ? new _UniMap(arg, isDeepEqual) : new _UniMap(isDeepEqual);
|
|
2448
|
+
}
|
|
2449
|
+
has(key) {
|
|
2450
|
+
if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
|
|
2451
|
+
return this.map.has(key);
|
|
2452
|
+
for (const [k, v] of this.map)
|
|
2453
|
+
if (this.keyEquals(k, key))
|
|
2454
|
+
return true;
|
|
2455
|
+
return false;
|
|
2456
|
+
}
|
|
2457
|
+
set(key, value) {
|
|
2458
|
+
if (this.keyEquals === DefaultEqualityFn || this.map.has(key)) {
|
|
2459
|
+
this.map.set(key, value);
|
|
2460
|
+
return value;
|
|
2461
|
+
}
|
|
2462
|
+
for (const key2 of this.map.keys())
|
|
2463
|
+
if (this.keyEquals(key2, key)) {
|
|
2464
|
+
this.map.set(key2, value);
|
|
2465
|
+
return value;
|
|
2466
|
+
}
|
|
2467
|
+
this.map.set(key, value);
|
|
2468
|
+
return value;
|
|
2469
|
+
}
|
|
2470
|
+
get(key) {
|
|
2471
|
+
if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
|
|
2472
|
+
return this.map.get(key);
|
|
2473
|
+
for (const [k, v] of this.map)
|
|
2474
|
+
if (this.keyEquals(k, key))
|
|
2475
|
+
return v;
|
|
2476
|
+
return void 0;
|
|
2477
|
+
}
|
|
2478
|
+
delete(key) {
|
|
2479
|
+
if (this.keyEquals === DefaultEqualityFn || this.map.has(key))
|
|
2480
|
+
return this.map.delete(key);
|
|
2481
|
+
for (const k of this.map.keys())
|
|
2482
|
+
if (this.keyEquals(k, key))
|
|
2483
|
+
return this.map.delete(k);
|
|
2484
|
+
return this.map.delete(key);
|
|
2485
|
+
}
|
|
2486
|
+
getOrDefault(key, defaultValue) {
|
|
2487
|
+
var _a;
|
|
2488
|
+
return (_a = this.get(key)) != null ? _a : defaultValue;
|
|
2489
|
+
}
|
|
2490
|
+
getOrCreate(key, creatorOrValue) {
|
|
2491
|
+
if (!this.has(key)) {
|
|
2492
|
+
const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
|
|
2493
|
+
return this.set(key, value);
|
|
2494
|
+
}
|
|
2495
|
+
return this.get(key);
|
|
2496
|
+
}
|
|
2497
|
+
clear() {
|
|
2498
|
+
this.map.clear();
|
|
2499
|
+
}
|
|
2500
|
+
get size() {
|
|
2501
|
+
return this.map.size;
|
|
2502
|
+
}
|
|
2503
|
+
isEmpty() {
|
|
2504
|
+
return this.size === 0;
|
|
2505
|
+
}
|
|
2506
|
+
forEach(callbackfn, thisArg) {
|
|
2507
|
+
this.map.forEach((value, key) => callbackfn.call(thisArg, value, key, this));
|
|
2508
|
+
}
|
|
2509
|
+
*keys() {
|
|
2510
|
+
yield* __yieldStar(this.map.keys());
|
|
2511
|
+
}
|
|
2512
|
+
*values() {
|
|
2513
|
+
yield* __yieldStar(this.map.values());
|
|
2514
|
+
}
|
|
2515
|
+
*entries() {
|
|
2516
|
+
for (const [key, value] of this.map)
|
|
2517
|
+
yield [key, value];
|
|
2518
|
+
}
|
|
2519
|
+
keysArray() {
|
|
2520
|
+
return [...this.keys()];
|
|
2521
|
+
}
|
|
2522
|
+
valuesArray() {
|
|
2523
|
+
return [...this.values()];
|
|
2524
|
+
}
|
|
2525
|
+
entriesArray() {
|
|
2526
|
+
return [...this.entries()];
|
|
2527
|
+
}
|
|
2528
|
+
*kvKeys() {
|
|
2529
|
+
for (const key of this.keys()) {
|
|
2530
|
+
yield [key];
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
*kvValues() {
|
|
2534
|
+
for (const el of this.values()) {
|
|
2535
|
+
yield el;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
*kvEntries() {
|
|
2539
|
+
for (const [key, el] of this.entries()) {
|
|
2540
|
+
yield [[key], el];
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
*[Symbol.iterator]() {
|
|
2544
|
+
yield* __yieldStar(this.entries());
|
|
2545
|
+
}
|
|
2546
|
+
clone() {
|
|
2547
|
+
return new _UniMap(this, this.keyEquals);
|
|
2548
|
+
}
|
|
2549
|
+
merge(other, conflictResolver) {
|
|
2550
|
+
for (const [key, value] of other.entries()) {
|
|
2551
|
+
if (this.has(key) && conflictResolver) {
|
|
2552
|
+
this.set(key, conflictResolver(this.get(key), value, key));
|
|
2553
|
+
} else {
|
|
2554
|
+
this.set(key, value);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
return this;
|
|
2558
|
+
}
|
|
2559
|
+
some(fn) {
|
|
2560
|
+
for (const [key, value] of this.map) {
|
|
2561
|
+
if (fn(value, key)) return true;
|
|
2562
|
+
}
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
every(fn) {
|
|
2566
|
+
for (const [key, value] of this.map) {
|
|
2567
|
+
if (!fn(value, key)) return false;
|
|
2568
|
+
}
|
|
2569
|
+
return true;
|
|
2570
|
+
}
|
|
2571
|
+
filter(predicate) {
|
|
2572
|
+
const result = new this.constructor();
|
|
2573
|
+
for (const [key, value] of this.map) {
|
|
2574
|
+
if (predicate(value, key, this)) result.set(key, value);
|
|
2575
|
+
}
|
|
2576
|
+
return result;
|
|
2577
|
+
}
|
|
2578
|
+
reduce(fn, init) {
|
|
2579
|
+
let iterator = this.entries();
|
|
2580
|
+
let first = iterator.next();
|
|
2581
|
+
if (first.done) {
|
|
2582
|
+
if (arguments.length < 2) {
|
|
2583
|
+
throw new TypeError("Reduce of empty UniMap with no initial value!");
|
|
2584
|
+
}
|
|
2585
|
+
return init;
|
|
2586
|
+
}
|
|
2587
|
+
let acc;
|
|
2588
|
+
let start;
|
|
2589
|
+
if (arguments.length < 2) {
|
|
2590
|
+
acc = first.value[1];
|
|
2591
|
+
start = iterator.next();
|
|
2592
|
+
} else {
|
|
2593
|
+
acc = init;
|
|
2594
|
+
start = first;
|
|
2595
|
+
}
|
|
2596
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2597
|
+
const [key, value] = current.value;
|
|
2598
|
+
acc = fn(acc, value, key);
|
|
2599
|
+
}
|
|
2600
|
+
return acc;
|
|
2601
|
+
}
|
|
2602
|
+
mapEntries(fn) {
|
|
2603
|
+
let result = [];
|
|
2604
|
+
for (const [key, value] of this.map) {
|
|
2605
|
+
result.push(fn(value, key));
|
|
2606
|
+
}
|
|
2607
|
+
return result;
|
|
2608
|
+
}
|
|
2609
|
+
mapValues(fn) {
|
|
2610
|
+
let result = new _UniMap();
|
|
2611
|
+
for (const [key, value] of this.map) {
|
|
2612
|
+
result.set(key, fn(value, key));
|
|
2613
|
+
}
|
|
2614
|
+
return result;
|
|
2615
|
+
}
|
|
2616
|
+
toMap() {
|
|
2617
|
+
return new Map(this.map);
|
|
2618
|
+
}
|
|
2619
|
+
toString() {
|
|
2620
|
+
const entries = [...this.map].map(([k, v]) => `${stringify(k)} => ${stringify(v)}`).join(", ");
|
|
2621
|
+
return entries.length === 0 ? `Map(${this.size}){ }` : `Map(${this.size}){ ${entries} }`;
|
|
2622
|
+
}
|
|
2623
|
+
};
|
|
2624
|
+
|
|
2625
|
+
// src/theory/types.ts
|
|
2626
|
+
var import_core = require("web-music-score/core");
|
|
2627
|
+
var SymbolSet = /* @__PURE__ */ ((SymbolSet2) => {
|
|
2628
|
+
SymbolSet2[SymbolSet2["Ascii"] = 0] = "Ascii";
|
|
2629
|
+
SymbolSet2[SymbolSet2["Unicode"] = 1] = "Unicode";
|
|
2630
|
+
return SymbolSet2;
|
|
2631
|
+
})(SymbolSet || {});
|
|
2632
|
+
var PitchNotation = /* @__PURE__ */ ((PitchNotation2) => {
|
|
2633
|
+
PitchNotation2[PitchNotation2["Scientific"] = 0] = "Scientific";
|
|
2634
|
+
PitchNotation2[PitchNotation2["Helmholtz"] = 1] = "Helmholtz";
|
|
2635
|
+
return PitchNotation2;
|
|
2636
|
+
})(PitchNotation || {});
|
|
2637
|
+
var PitchNotationList = utils_exports.Enum.getEnumValues(PitchNotation);
|
|
2638
|
+
var DefaultPitchNotation = 0 /* Scientific */;
|
|
2639
|
+
function validatePitchNotation(pn) {
|
|
2640
|
+
if (guard_exports.isEnumValue(pn, PitchNotation)) {
|
|
2641
|
+
return pn;
|
|
2642
|
+
} else {
|
|
2643
|
+
throw new import_core.MusicError(import_core.MusicErrorType.InvalidArg, `Invalid pitchNotation: ${pn}`);
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
function getPitchNotationName(pn) {
|
|
2647
|
+
return PitchNotation[validatePitchNotation(pn)];
|
|
2648
|
+
}
|
|
2649
|
+
var GuitarNoteLabel = /* @__PURE__ */ ((GuitarNoteLabel2) => {
|
|
2650
|
+
GuitarNoteLabel2["Default"] = "Default";
|
|
2651
|
+
GuitarNoteLabel2["OmitOctave"] = "Omit Octave";
|
|
2652
|
+
GuitarNoteLabel2["Interval"] = "Interval";
|
|
2653
|
+
return GuitarNoteLabel2;
|
|
2654
|
+
})(GuitarNoteLabel || {});
|
|
2655
|
+
var DefaultGuitarNoteLabel = "Default" /* Default */;
|
|
2656
|
+
var GuitarNoteLabelList = utils_exports.Enum.getEnumValues(GuitarNoteLabel);
|
|
2657
|
+
function validateGuitarNoteLabel(label) {
|
|
2658
|
+
if (guard_exports.isEnumValue(label, GuitarNoteLabel)) {
|
|
2659
|
+
return label;
|
|
2660
|
+
} else {
|
|
2661
|
+
throw new import_core.MusicError(import_core.MusicErrorType.Timesignature, `Invalid guitarNoteLabel: ${label}`);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
// src/theory/note.ts
|
|
2666
|
+
var import_core2 = require("web-music-score/core");
|
|
2667
|
+
function mod2(n, m) {
|
|
2668
|
+
return (n % m + m) % m;
|
|
2669
|
+
}
|
|
2670
|
+
var C0_chromaticId = 12;
|
|
2671
|
+
var C0_diatonicId = 7;
|
|
2672
|
+
var AccidentalAsciiSymbolMap = /* @__PURE__ */ new Map([[-2, "bb"], [-1, "b"], [0, ""], [1, "#"], [2, "x"]]);
|
|
2673
|
+
var AccidentalUnicodeSymbolMap = /* @__PURE__ */ new Map([[-2, "\u{1D12B}"], [-1, "\u266D"], [0, ""], [1, "\u266F"], [2, "\u{1D12A}"]]);
|
|
2674
|
+
var AccidentalMap = /* @__PURE__ */ new Map([["", 0], ["bb", -2], ["b", -1], ["#", 1], ["x", 2], ["\u{1D12B}", -2], ["\u266D", -1], ["\u266F", 1], ["\u{1D12A}", 2]]);
|
|
2675
|
+
var NoteLetters = ["C", "D", "E", "F", "G", "A", "B"];
|
|
2676
|
+
var DiatonicToChromaticMap = [0, 2, 4, 5, 7, 9, 11];
|
|
2677
|
+
var NoteNameRegex = /^([A-G])((?:bb|𝄫|♭|b|#|♯|x|𝄪)?)?(-?\d+)?$/;
|
|
2678
|
+
var _Note = class _Note {
|
|
2679
|
+
constructor(arg, accidental, octave) {
|
|
2680
|
+
/** Diatonic class */
|
|
2681
|
+
__publicField(this, "diatonicClass");
|
|
2682
|
+
/** Accidental. */
|
|
2683
|
+
__publicField(this, "accidental");
|
|
2684
|
+
/** Octave. */
|
|
2685
|
+
__publicField(this, "octave");
|
|
2686
|
+
if (typeof arg === "number" && typeof accidental === "number" && octave === void 0) {
|
|
2687
|
+
_Note.validateDiatonicId(arg);
|
|
2688
|
+
this.diatonicClass = _Note.getDiatonicClass(arg);
|
|
2689
|
+
this.accidental = _Note.validateAccidental(accidental);
|
|
2690
|
+
this.octave = _Note.getOctaveFromDiatonicId(arg);
|
|
2691
|
+
} else if (typeof arg === "number" && typeof accidental === "number" && typeof octave === "number") {
|
|
2692
|
+
this.diatonicClass = _Note.validateDiatonicClass(arg);
|
|
2693
|
+
this.accidental = _Note.validateAccidental(accidental);
|
|
2694
|
+
this.octave = _Note.validateOctave(octave);
|
|
2695
|
+
} else if (typeof arg === "string" && typeof accidental === "number" && typeof octave === "number") {
|
|
2696
|
+
this.diatonicClass = _Note.getDiatonicClass(arg);
|
|
2697
|
+
this.accidental = _Note.validateAccidental(accidental);
|
|
2698
|
+
this.octave = _Note.validateOctave(octave);
|
|
2699
|
+
} else {
|
|
2700
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid args: ${arg}, ${accidental}, ${octave}`);
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
/** Diatonic id getter. */
|
|
2704
|
+
get diatonicId() {
|
|
2705
|
+
return _Note.getDiatonicIdInOctave(this.diatonicClass, this.octave);
|
|
2706
|
+
}
|
|
2707
|
+
/** Chromatic id getter. */
|
|
2708
|
+
get chromaticId() {
|
|
2709
|
+
return _Note.getChromaticIdInOctave(DiatonicToChromaticMap[this.diatonicClass] + this.accidental, this.octave);
|
|
2710
|
+
}
|
|
2711
|
+
/** Midi number getter (implemented same as chromatic id). */
|
|
2712
|
+
get midiNumber() {
|
|
2713
|
+
return this.chromaticId;
|
|
2714
|
+
}
|
|
2715
|
+
/** Chromatic class getter. */
|
|
2716
|
+
get chromaticClass() {
|
|
2717
|
+
return _Note.getChromaticClass(DiatonicToChromaticMap[this.diatonicClass] + this.accidental);
|
|
2718
|
+
}
|
|
2719
|
+
/** Note letter getter. */
|
|
2720
|
+
get noteLetter() {
|
|
2721
|
+
return NoteLetters[this.diatonicClass];
|
|
2722
|
+
}
|
|
2723
|
+
/**
|
|
2724
|
+
* Format note to string presentation.
|
|
2725
|
+
* @param pitchNotation - Pitchy notation.
|
|
2726
|
+
* @param symbolSet - Symbol set.
|
|
2727
|
+
* @returns - String presentation of note.
|
|
2728
|
+
*/
|
|
2729
|
+
format(pitchNotation, symbolSet) {
|
|
2730
|
+
let { noteLetter, octave } = this;
|
|
2731
|
+
let accidentalSymbol = _Note.getAccidentalSymbol(this.accidental, symbolSet);
|
|
2732
|
+
if (pitchNotation === 1 /* Helmholtz */) {
|
|
2733
|
+
if (octave >= 3) {
|
|
2734
|
+
return noteLetter.toLowerCase() + accidentalSymbol + "\u2032".repeat(octave - 3);
|
|
2735
|
+
} else {
|
|
2736
|
+
return noteLetter.toUpperCase() + accidentalSymbol + "\u0375".repeat(2 - octave);
|
|
2737
|
+
}
|
|
2738
|
+
} else {
|
|
2739
|
+
return noteLetter + accidentalSymbol + octave;
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* Format note to string presentation without octave number.
|
|
2744
|
+
* @param symbolSet - Symbol set.
|
|
2745
|
+
* @returns - String presentation of note without octave number.
|
|
2746
|
+
*/
|
|
2747
|
+
formatOmitOctave(symbolSet) {
|
|
2748
|
+
let noteLetter = NoteLetters[this.diatonicClass];
|
|
2749
|
+
let accidental = _Note.getAccidentalSymbol(this.accidental, symbolSet);
|
|
2750
|
+
return noteLetter + accidental;
|
|
2751
|
+
}
|
|
2752
|
+
/**
|
|
2753
|
+
* Get note.
|
|
2754
|
+
* @param noteName - Note name (e.g. "C4").
|
|
2755
|
+
* @returns - Note.
|
|
2756
|
+
*/
|
|
2757
|
+
static getNote(noteName) {
|
|
2758
|
+
return this.noteCache.getOrCreate(noteName, () => {
|
|
2759
|
+
let p = _Note.parseNote(noteName);
|
|
2760
|
+
if (!p)
|
|
2761
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid note "${noteName}".`);
|
|
2762
|
+
if (p.octave === void 0)
|
|
2763
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid note "${noteName}" (missing octave).`);
|
|
2764
|
+
return new _Note(p.noteLetter, p.accidental, p.octave);
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
/**
|
|
2768
|
+
* Test if given note name valid.
|
|
2769
|
+
* @param noteName - Note name.
|
|
2770
|
+
* @returns - True/false.
|
|
2771
|
+
*/
|
|
2772
|
+
static isNote(noteName) {
|
|
2773
|
+
let p = _Note.parseNote(noteName);
|
|
2774
|
+
return p !== void 0 && p.octave !== void 0;
|
|
2775
|
+
}
|
|
2776
|
+
/**
|
|
2777
|
+
* Validate given note name.
|
|
2778
|
+
* @param noteName - Note name.
|
|
2779
|
+
* @returns - True or throws.
|
|
2780
|
+
*/
|
|
2781
|
+
static validateNote(noteName) {
|
|
2782
|
+
if (this.isNote(noteName)) return true;
|
|
2783
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid note "${noteName}"`);
|
|
2784
|
+
}
|
|
2785
|
+
/**
|
|
2786
|
+
* Get chromatic note. There are number of alternatives, this function uses simple logic to choose one.
|
|
2787
|
+
* @param chromaticId - Chromatic id.
|
|
2788
|
+
* @returns - Note.
|
|
2789
|
+
*/
|
|
2790
|
+
static getChromaticNote(chromaticId) {
|
|
2791
|
+
return this.chromaticNoteCache.getOrCreate(chromaticId, () => {
|
|
2792
|
+
const NoteNameList = ["C/B#", "C#/Db", "D", "D#/Eb", "E/Fb", "F/E#", "F#/Gb", "G", "G#/Ab", "A", "A#/Bb", "B/Cb"];
|
|
2793
|
+
let noteName = NoteNameList[_Note.getChromaticClass(chromaticId)].split("/")[0] + _Note.getOctaveFromChromaticId(chromaticId);
|
|
2794
|
+
return _Note.getNote(noteName);
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
static getDiatonicClass(arg) {
|
|
2798
|
+
if (typeof arg === "number") {
|
|
2799
|
+
return mod2(arg, 7);
|
|
2800
|
+
} else if (typeof arg === "string" && arg.length > 0) {
|
|
2801
|
+
return NoteLetters.indexOf(_Note.validateNoteLetter(arg[0]));
|
|
2802
|
+
} else {
|
|
2803
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid arg: ${arg}`);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
/**
|
|
2807
|
+
* Get octave from diatonic id.
|
|
2808
|
+
* @param diatonicId - Diatonic id.
|
|
2809
|
+
* @returns - Octave.
|
|
2810
|
+
*/
|
|
2811
|
+
static getOctaveFromDiatonicId(diatonicId) {
|
|
2812
|
+
return Math.floor((diatonicId - C0_diatonicId) / 7);
|
|
2813
|
+
}
|
|
2814
|
+
/**
|
|
2815
|
+
* Get diatonic id in given octave (transposes diatonic id to given octave).
|
|
2816
|
+
* @param diatonicId - Original diatonic id.
|
|
2817
|
+
* @param octave - Octave.
|
|
2818
|
+
* @returns - Transposed diatonic id.
|
|
2819
|
+
*/
|
|
2820
|
+
static getDiatonicIdInOctave(diatonicId, octave) {
|
|
2821
|
+
return _Note.getDiatonicClass(diatonicId) + octave * 7 + C0_diatonicId;
|
|
2822
|
+
}
|
|
2823
|
+
/**
|
|
2824
|
+
* Get chromatic class from chromatic id.
|
|
2825
|
+
* @param chromaticId - Chromatic id.
|
|
2826
|
+
* @returns - Chromatic class.
|
|
2827
|
+
*/
|
|
2828
|
+
static getChromaticClass(chromaticId) {
|
|
2829
|
+
return mod2(chromaticId, 12);
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Get octave from chromatic id.
|
|
2833
|
+
* @param chromaticId - Chromatic id.
|
|
2834
|
+
* @returns - Octave.
|
|
2835
|
+
*/
|
|
2836
|
+
static getOctaveFromChromaticId(chromaticId) {
|
|
2837
|
+
return Math.floor((chromaticId - C0_chromaticId) / 12);
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Get chromatic id in given octave (transposes chromatic id to given octave).
|
|
2841
|
+
* @param chromaticId - Original chromatic id.
|
|
2842
|
+
* @param octave - Octave.
|
|
2843
|
+
* @returns - Transpose chromatic id.
|
|
2844
|
+
*/
|
|
2845
|
+
static getChromaticIdInOctave(chromaticId, octave) {
|
|
2846
|
+
return _Note.getChromaticClass(chromaticId) + octave * 12 + C0_chromaticId;
|
|
2847
|
+
}
|
|
2848
|
+
/**
|
|
2849
|
+
* Test if given two notes are equal.
|
|
2850
|
+
* @param a - Note a.
|
|
2851
|
+
* @param b - Note b.
|
|
2852
|
+
* @returns - True/false.
|
|
2853
|
+
*/
|
|
2854
|
+
static equals(a, b) {
|
|
2855
|
+
if (a == null && b == null) {
|
|
2856
|
+
return true;
|
|
2857
|
+
} else if (a == null || b == null) {
|
|
2858
|
+
return false;
|
|
2859
|
+
} else {
|
|
2860
|
+
return a === b || a.diatonicId === b.diatonicId && a.accidental === b.accidental;
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* Replace accidental symbols in given string to givn symbol set (ascii/unicode).
|
|
2865
|
+
* @param str - String to replace.
|
|
2866
|
+
* @param symbolSet - Symbol set.
|
|
2867
|
+
* @returns - String with updated accidental symbols.
|
|
2868
|
+
*/
|
|
2869
|
+
static replaceAccidentalSymbols(str2, symbolSet) {
|
|
2870
|
+
if (symbolSet === 1 /* Unicode */) {
|
|
2871
|
+
return str2.replace("bb", "\u{1D12B}").replace("b", "\u266D").replace("#", "\u266F").replace("x", "\u{1D12A}");
|
|
2872
|
+
} else {
|
|
2873
|
+
return str2.replace("\u{1D12B}", "bb").replace("\u266D", "b").replace("\u266F", "#").replace("\u{1D12A}", "x");
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
/**
|
|
2877
|
+
* Test if given string is valid note name.
|
|
2878
|
+
* @param noteName - Note name to validate.
|
|
2879
|
+
* @returns - True/false.
|
|
2880
|
+
*/
|
|
2881
|
+
static isValidNoteName(noteName) {
|
|
2882
|
+
return NoteNameRegex.test(noteName);
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Parse note name string to note props.
|
|
2886
|
+
* @param noteName - Note name to parse.
|
|
2887
|
+
* @returns - Parsed note props or undefined if parsing error.
|
|
2888
|
+
*/
|
|
2889
|
+
static parseNote(noteName) {
|
|
2890
|
+
var _a;
|
|
2891
|
+
let m = NoteNameRegex.exec(noteName);
|
|
2892
|
+
if (!m) {
|
|
2893
|
+
return void 0;
|
|
2894
|
+
}
|
|
2895
|
+
let noteLetter = _Note.validateNoteLetter(m[1]);
|
|
2896
|
+
let accidentalStr = m[2];
|
|
2897
|
+
let accidental = _Note.validateAccidental((_a = AccidentalMap.get(accidentalStr)) != null ? _a : 0);
|
|
2898
|
+
let octaveStr = m[3];
|
|
2899
|
+
let octave = octaveStr ? _Note.validateOctave(+octaveStr) : void 0;
|
|
2900
|
+
return { noteLetter, accidental, octave };
|
|
2901
|
+
}
|
|
2902
|
+
/**
|
|
2903
|
+
* Get scientific note name from given note name.
|
|
2904
|
+
* @param noteName - Note name.
|
|
2905
|
+
* @param symbolSet - Symbol set (ascii/unicode) for scientific note name.
|
|
2906
|
+
* @returns - Scientific note name.
|
|
2907
|
+
*/
|
|
2908
|
+
static getScientificNoteName(noteName, symbolSet) {
|
|
2909
|
+
let p = _Note.parseNote(noteName);
|
|
2910
|
+
if (!p) {
|
|
2911
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid noteName: ${noteName}`);
|
|
2912
|
+
}
|
|
2913
|
+
let { noteLetter, accidental, octave } = p;
|
|
2914
|
+
return noteLetter + _Note.getAccidentalSymbol(accidental, symbolSet) + (octave != null ? octave : "");
|
|
2915
|
+
}
|
|
2916
|
+
/**
|
|
2917
|
+
* Get symbol of given accidental in given symbol set (ascii/unicide).
|
|
2918
|
+
* @param accidental - Accidental.
|
|
2919
|
+
* @param symbolsSet - Symbol set.
|
|
2920
|
+
* @returns - Accidental symbol or undefined (invalid accidental).
|
|
2921
|
+
*/
|
|
2922
|
+
static getAccidentalSymbol(accidental, symbolsSet) {
|
|
2923
|
+
return symbolsSet === 1 /* Unicode */ ? AccidentalUnicodeSymbolMap.get(accidental) : AccidentalAsciiSymbolMap.get(accidental);
|
|
2924
|
+
}
|
|
2925
|
+
/**
|
|
2926
|
+
* Get accidental value from given accidental symbol.
|
|
2927
|
+
* @param accidentalSymbol - Accidental symbol (e.g. "#").
|
|
2928
|
+
* @returns - Accidental vlaue.
|
|
2929
|
+
*/
|
|
2930
|
+
static getAccidental(accidentalSymbol) {
|
|
2931
|
+
let accidental = AccidentalMap.get(accidentalSymbol);
|
|
2932
|
+
if (accidental === void 0) {
|
|
2933
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid accidental: ${accidentalSymbol}`);
|
|
2934
|
+
}
|
|
2935
|
+
return accidental;
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Get note letter from given diatonic id.
|
|
2939
|
+
* @param diatonicId - Diatonic id.
|
|
2940
|
+
* @returns - Note letter.
|
|
2941
|
+
*/
|
|
2942
|
+
static getNoteLetter(diatonicId) {
|
|
2943
|
+
return NoteLetters[_Note.getDiatonicClass(diatonicId)];
|
|
2944
|
+
}
|
|
2945
|
+
/**
|
|
2946
|
+
* Find next lowest possible diatonic id that is above given bottom level.
|
|
2947
|
+
* @param diatonicId - Diatonic id to begin with.
|
|
2948
|
+
* @param bottomDiatonicId - Bottom diatonic id.
|
|
2949
|
+
* @param addOctaveIfEqual - If true then add one octave if diatonic id would equal to bottom diatonic id.
|
|
2950
|
+
* @returns - Diatonic id.
|
|
2951
|
+
*/
|
|
2952
|
+
static findNextDiatonicIdAbove(diatonicId, bottomDiatonicId, addOctaveIfEqual) {
|
|
2953
|
+
let diatonicClass = _Note.getDiatonicClass(diatonicId);
|
|
2954
|
+
let bottomDiatonicClass = _Note.getDiatonicClass(bottomDiatonicId);
|
|
2955
|
+
let addOctave = addOctaveIfEqual ? diatonicClass <= bottomDiatonicClass ? 1 : 0 : diatonicClass < bottomDiatonicClass ? 1 : 0;
|
|
2956
|
+
return _Note.getDiatonicIdInOctave(diatonicClass, _Note.getOctaveFromDiatonicId(bottomDiatonicId) + addOctave);
|
|
2957
|
+
}
|
|
2958
|
+
/**
|
|
2959
|
+
* Validate if given argument is diatonic id.
|
|
2960
|
+
* @param diatonicId - Diatonic id to validate.
|
|
2961
|
+
* @returns - Valid diatonic id or throws.
|
|
2962
|
+
*/
|
|
2963
|
+
static validateDiatonicId(diatonicId) {
|
|
2964
|
+
if (guard_exports.isInteger(diatonicId)) {
|
|
2965
|
+
return diatonicId;
|
|
2966
|
+
} else {
|
|
2967
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid diatonicId: ${diatonicId}`);
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
/**
|
|
2971
|
+
* Validate if given argument is diatonic class.
|
|
2972
|
+
* @param diatonicClass - Diatonic class to validate.
|
|
2973
|
+
* @returns - Valid diatonic class or throws.
|
|
2974
|
+
*/
|
|
2975
|
+
static validateDiatonicClass(diatonicClass) {
|
|
2976
|
+
if (guard_exports.isIntegerBetween(diatonicClass, 0, 6)) {
|
|
2977
|
+
return diatonicClass;
|
|
2978
|
+
} else {
|
|
2979
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid diatonicClass: ${diatonicClass}`);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
/**
|
|
2983
|
+
* Validate if given argument is chromatic id.
|
|
2984
|
+
* @param chromaticId - Chromatic id to validate.
|
|
2985
|
+
* @returns - Valid chromatic id, or throws.
|
|
2986
|
+
*/
|
|
2987
|
+
static validateChromaticId(chromaticId) {
|
|
2988
|
+
if (guard_exports.isInteger(chromaticId)) {
|
|
2989
|
+
return chromaticId;
|
|
2990
|
+
} else {
|
|
2991
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid chromaticId: ${chromaticId}`);
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
/**
|
|
2995
|
+
* Validate if given argument is chromatic class.
|
|
2996
|
+
* @param chromaticClass - Chromatic class to validate.
|
|
2997
|
+
* @returns - Valid chromatic class, or throws.
|
|
2998
|
+
*/
|
|
2999
|
+
static validatechromaticClass(chromaticClass) {
|
|
3000
|
+
if (guard_exports.isIntegerBetween(chromaticClass, 0, 11)) {
|
|
3001
|
+
return chromaticClass;
|
|
3002
|
+
} else {
|
|
3003
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid chromaticClass: ${chromaticClass}`);
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
/**
|
|
3007
|
+
* Validate if given argument if note letter.
|
|
3008
|
+
* @param noteLetter - Note letter to validate.
|
|
3009
|
+
* @returns - Valid note letter or throws.
|
|
3010
|
+
*/
|
|
3011
|
+
static validateNoteLetter(noteLetter) {
|
|
3012
|
+
if (NoteLetters.some((n) => n === noteLetter)) {
|
|
3013
|
+
return noteLetter;
|
|
3014
|
+
} else {
|
|
3015
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid note: ${noteLetter}`);
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
/**
|
|
3019
|
+
* Validate if given argument is octave.
|
|
3020
|
+
* @param octave - Octave to validate.
|
|
3021
|
+
* @returns - Valid octave or throws.
|
|
3022
|
+
*/
|
|
3023
|
+
static validateOctave(octave) {
|
|
3024
|
+
if (guard_exports.isInteger(octave)) {
|
|
3025
|
+
return octave;
|
|
3026
|
+
} else {
|
|
3027
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid octave: ${octave}`);
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
/**
|
|
3031
|
+
* Validate if given argument is valid accidental.
|
|
3032
|
+
* @param acc - Accidental to validate.
|
|
3033
|
+
* @returns - Valid accidental or thorws.
|
|
3034
|
+
*/
|
|
3035
|
+
static validateAccidental(acc) {
|
|
3036
|
+
if (guard_exports.isIntegerBetween(acc, -2, 2)) {
|
|
3037
|
+
return acc;
|
|
3038
|
+
} else {
|
|
3039
|
+
throw new import_core2.MusicError(import_core2.MusicErrorType.Note, `Invalid accidental: ${acc}`);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
/**
|
|
3043
|
+
* Sort notes by diatonicId in ascending order.
|
|
3044
|
+
* @param notes - Array of notes.
|
|
3045
|
+
* @returns Sorted array of notes.
|
|
3046
|
+
*/
|
|
3047
|
+
static sort(notes) {
|
|
3048
|
+
return notes.slice().sort(_Note.compareFunc);
|
|
3049
|
+
}
|
|
3050
|
+
/**
|
|
3051
|
+
* Remove duplicate notes.
|
|
3052
|
+
* @param notes - Array of notes.
|
|
3053
|
+
* @returns Sorted set of notes.
|
|
3054
|
+
*/
|
|
3055
|
+
static removeDuplicates(notes) {
|
|
3056
|
+
let uniqueSet = [];
|
|
3057
|
+
notes.forEach((note) => {
|
|
3058
|
+
if (uniqueSet.find((n) => _Note.equals(note, n)) === void 0) {
|
|
3059
|
+
uniqueSet.push(note);
|
|
3060
|
+
}
|
|
3061
|
+
});
|
|
3062
|
+
return uniqueSet;
|
|
3063
|
+
}
|
|
3064
|
+
/**
|
|
3065
|
+
* Function to compare two notes using diatonic id and accidental properties of notes.
|
|
3066
|
+
* @param a - Note a.
|
|
3067
|
+
* @param b - Note b.
|
|
3068
|
+
* @returns - -1, 0 or 1.
|
|
3069
|
+
*/
|
|
3070
|
+
static compareFunc(a, b) {
|
|
3071
|
+
if (a.diatonicId < b.diatonicId) {
|
|
3072
|
+
return -1;
|
|
3073
|
+
} else if (a.diatonicId > b.diatonicId) {
|
|
3074
|
+
return 1;
|
|
3075
|
+
} else {
|
|
3076
|
+
if (a.accidental < b.accidental) {
|
|
3077
|
+
return -1;
|
|
3078
|
+
} else if (a.accidental > b.accidental) {
|
|
3079
|
+
return 1;
|
|
3080
|
+
} else {
|
|
3081
|
+
return 0;
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
};
|
|
3086
|
+
__publicField(_Note, "noteCache", new UniMap());
|
|
3087
|
+
__publicField(_Note, "chromaticNoteCache", new UniMap());
|
|
3088
|
+
var Note = _Note;
|
|
3089
|
+
|
|
3090
|
+
// src/theory/key-signature.ts
|
|
3091
|
+
var import_core3 = require("web-music-score/core");
|
|
3092
|
+
function getAccidental(chromaticId, diatonicId) {
|
|
3093
|
+
let a = Note.getChromaticClass(chromaticId) - new Note(diatonicId, 0).chromaticClass;
|
|
3094
|
+
while (a > 2) {
|
|
3095
|
+
a -= 12;
|
|
3096
|
+
}
|
|
3097
|
+
while (a < -2) {
|
|
3098
|
+
a += 12;
|
|
3099
|
+
}
|
|
3100
|
+
return Note.validateAccidental(a);
|
|
3101
|
+
}
|
|
3102
|
+
var DegreeRule = /^(bb?|b?|#?|x?)([0-9]*)$/;
|
|
3103
|
+
function parseDegree(degree) {
|
|
3104
|
+
var _a, _b;
|
|
3105
|
+
let m = DegreeRule.exec("" + degree);
|
|
3106
|
+
if (!m) {
|
|
3107
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, `Invalid degree: ${degree}`);
|
|
3108
|
+
}
|
|
3109
|
+
let acc = (_b = Note.getAccidental((_a = m[1]) != null ? _a : "")) != null ? _b : 0;
|
|
3110
|
+
let deg = +m[2];
|
|
3111
|
+
if (!guard_exports.isInteger(acc) || acc < -2 || acc > 2 || !guard_exports.isInteger(deg) || deg < 1) {
|
|
3112
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, `Invalid degree: ${degree}`);
|
|
3113
|
+
} else {
|
|
3114
|
+
return { deg, acc };
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
var Mode = /* @__PURE__ */ ((Mode2) => {
|
|
3118
|
+
Mode2[Mode2["Ionian"] = 1] = "Ionian";
|
|
3119
|
+
Mode2[Mode2["Dorian"] = 2] = "Dorian";
|
|
3120
|
+
Mode2[Mode2["Phrygian"] = 3] = "Phrygian";
|
|
3121
|
+
Mode2[Mode2["Lydian"] = 4] = "Lydian";
|
|
3122
|
+
Mode2[Mode2["Mixolydian"] = 5] = "Mixolydian";
|
|
3123
|
+
Mode2[Mode2["Aeolian"] = 6] = "Aeolian";
|
|
3124
|
+
Mode2[Mode2["Locrian"] = 7] = "Locrian";
|
|
3125
|
+
return Mode2;
|
|
3126
|
+
})(Mode || {});
|
|
3127
|
+
var AccidentalType = /* @__PURE__ */ ((AccidentalType2) => {
|
|
3128
|
+
AccidentalType2[AccidentalType2["Natural"] = 0] = "Natural";
|
|
3129
|
+
AccidentalType2[AccidentalType2["Flats"] = 1] = "Flats";
|
|
3130
|
+
AccidentalType2[AccidentalType2["Sharps"] = 2] = "Sharps";
|
|
3131
|
+
return AccidentalType2;
|
|
3132
|
+
})(AccidentalType || {});
|
|
3133
|
+
function getDefaultKeySignature() {
|
|
3134
|
+
return getScale("C", "Major" /* Major */);
|
|
3135
|
+
}
|
|
3136
|
+
var _KeySignature = class _KeySignature {
|
|
3137
|
+
/**
|
|
3138
|
+
* @param tonic - Tonic/root note.
|
|
3139
|
+
* @param mode - Mode: Ionian/Major = 1, Dorian = 2, ..., Locrian = 7
|
|
3140
|
+
*/
|
|
3141
|
+
constructor(tonic, mode) {
|
|
3142
|
+
this.tonic = tonic;
|
|
3143
|
+
this.mode = mode;
|
|
3144
|
+
__publicField(this, "naturalScaleNotes");
|
|
3145
|
+
__publicField(this, "accidentalByDiatonicClass");
|
|
3146
|
+
__publicField(this, "orderedAccidentedNotes");
|
|
3147
|
+
if (!guard_exports.isEnumValue(mode, Mode)) {
|
|
3148
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, `Invalid mode: ${mode}`);
|
|
3149
|
+
}
|
|
3150
|
+
let intervals = [2, 2, 1, 2, 2, 2, 1];
|
|
3151
|
+
for (let i = 1; i < mode; i++) {
|
|
3152
|
+
intervals.push(intervals.shift());
|
|
3153
|
+
}
|
|
3154
|
+
this.naturalScaleNotes = [];
|
|
3155
|
+
this.accidentalByDiatonicClass = [];
|
|
3156
|
+
let diatonicId = Note.getDiatonicClass(tonic[0]);
|
|
3157
|
+
let chromaticId = Note.getNote(tonic + "0").chromaticId;
|
|
3158
|
+
for (let id = 0; id < 7; diatonicId++, chromaticId += intervals[id], id++) {
|
|
3159
|
+
let note = new Note(Note.getDiatonicClass(diatonicId), getAccidental(chromaticId, diatonicId));
|
|
3160
|
+
if (Math.abs(note.accidental) >= 2) {
|
|
3161
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, "Key signature contains double accidental.");
|
|
3162
|
+
}
|
|
3163
|
+
this.naturalScaleNotes[id] = note;
|
|
3164
|
+
this.accidentalByDiatonicClass[note.diatonicClass] = note.accidental;
|
|
3165
|
+
}
|
|
3166
|
+
let sharps = this.naturalScaleNotes.filter((n) => n.accidental > 0).sort((a, b) => {
|
|
3167
|
+
let ai = _KeySignature.OrderOfSharps.indexOf(a.noteLetter);
|
|
3168
|
+
let bi = _KeySignature.OrderOfSharps.indexOf(b.noteLetter);
|
|
3169
|
+
if (ai === -1 || bi === -1) {
|
|
3170
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, "Unexpected note in key signature.");
|
|
3171
|
+
}
|
|
3172
|
+
return ai - bi;
|
|
3173
|
+
});
|
|
3174
|
+
let flats = this.naturalScaleNotes.filter((n) => n.accidental < 0).sort((a, b) => {
|
|
3175
|
+
let ai = _KeySignature.OrderOfFlats.indexOf(a.noteLetter);
|
|
3176
|
+
let bi = _KeySignature.OrderOfFlats.indexOf(b.noteLetter);
|
|
3177
|
+
if (ai === -1 || bi === -1) {
|
|
3178
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, "Unexpected note in key signature.");
|
|
3179
|
+
}
|
|
3180
|
+
return ai - bi;
|
|
3181
|
+
});
|
|
3182
|
+
if (sharps.length !== 0 && flats.length !== 0) {
|
|
3183
|
+
throw new import_core3.MusicError(import_core3.MusicErrorType.KeySignature, "Key Signature has both sharps and flats.");
|
|
3184
|
+
}
|
|
3185
|
+
this.orderedAccidentedNotes = flats.length > 0 ? flats : sharps;
|
|
3186
|
+
}
|
|
3187
|
+
/**
|
|
3188
|
+
* Get accidental type sharps, flats, or natural (without accidentals).
|
|
3189
|
+
* @returns - Accidental type.
|
|
3190
|
+
*/
|
|
3191
|
+
getAccidentalType() {
|
|
3192
|
+
if (this.orderedAccidentedNotes.length === 0) {
|
|
3193
|
+
return 0 /* Natural */;
|
|
3194
|
+
} else if (this.orderedAccidentedNotes[0].accidental < 0) {
|
|
3195
|
+
return 1 /* Flats */;
|
|
3196
|
+
} else {
|
|
3197
|
+
return 2 /* Sharps */;
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
/**
|
|
3201
|
+
* Get natural scale notes of this key signature, natural scale has 7 steps (e.g. Major scale: W, W, H, W, W, W, H).
|
|
3202
|
+
* @returns - Array of notes.
|
|
3203
|
+
*/
|
|
3204
|
+
getNaturalScaleNotes() {
|
|
3205
|
+
return this.naturalScaleNotes;
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Get accidental for given diatonic id.
|
|
3209
|
+
* @param diatonicId - Diatonic id.
|
|
3210
|
+
* @returns - Accidental -2, -1, 0, 1 or 2.
|
|
3211
|
+
*/
|
|
3212
|
+
getAccidental(diatonicId) {
|
|
3213
|
+
var _a;
|
|
3214
|
+
return (_a = this.accidentalByDiatonicClass[Note.getDiatonicClass(diatonicId)]) != null ? _a : 0;
|
|
3215
|
+
}
|
|
3216
|
+
/**
|
|
3217
|
+
* Get number of accidentals this key signature has.
|
|
3218
|
+
* @returns - Number of accidentals.
|
|
3219
|
+
*/
|
|
3220
|
+
getNumAccidentals() {
|
|
3221
|
+
return this.orderedAccidentedNotes.length;
|
|
3222
|
+
}
|
|
3223
|
+
/**
|
|
3224
|
+
* Get accidental notes in correct order.
|
|
3225
|
+
* @returns - Array of accidental notes.
|
|
3226
|
+
*/
|
|
3227
|
+
getOrderedAccidentalNotes() {
|
|
3228
|
+
return this.orderedAccidentedNotes;
|
|
3229
|
+
}
|
|
3230
|
+
/**
|
|
3231
|
+
* Get note of key signature by degree value.
|
|
3232
|
+
* @param degree - Degree number in range [1, 7] or string e.g "b5" or "#4".
|
|
3233
|
+
* @returns - Note.
|
|
3234
|
+
*/
|
|
3235
|
+
getNoteByDegree(degree) {
|
|
3236
|
+
let { deg, acc } = parseDegree(degree);
|
|
3237
|
+
if (acc === 0) {
|
|
3238
|
+
return this.naturalScaleNotes[(deg - 1) % 7];
|
|
3239
|
+
} else {
|
|
3240
|
+
let note = this.naturalScaleNotes[(deg - 1) % 7];
|
|
3241
|
+
return new Note(note.diatonicId, note.accidental + acc);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
/**
|
|
3245
|
+
* Test equality of given key signatures.
|
|
3246
|
+
* @param a - Key signature a.
|
|
3247
|
+
* @param b - Key signature b.
|
|
3248
|
+
* @returns - True/false.
|
|
3249
|
+
*/
|
|
3250
|
+
static equals(a, b) {
|
|
3251
|
+
if (a == null && b == null) {
|
|
3252
|
+
return true;
|
|
3253
|
+
} else if (a == null || b == null) {
|
|
3254
|
+
return false;
|
|
3255
|
+
} else {
|
|
3256
|
+
return a === b || a.tonic === b.tonic && a.mode === b.mode;
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
};
|
|
3260
|
+
__publicField(_KeySignature, "OrderOfSharps", "FCGDAEB");
|
|
3261
|
+
__publicField(_KeySignature, "OrderOfFlats", "BEADGCF");
|
|
3262
|
+
var KeySignature = _KeySignature;
|
|
3263
|
+
|
|
3264
|
+
// src/theory/interval.ts
|
|
3265
|
+
var import_core4 = require("web-music-score/core");
|
|
3266
|
+
var IntervalQualityAbbrMap = new UniMap([
|
|
3267
|
+
["Major", "M"],
|
|
3268
|
+
["minor", "m"],
|
|
3269
|
+
["Perfect", "P"],
|
|
3270
|
+
["diminished", "d"],
|
|
3271
|
+
["Augmented", "A"],
|
|
3272
|
+
["doubly diminished", "dd"],
|
|
3273
|
+
["Doubly Augmented", "AA"]
|
|
3274
|
+
]);
|
|
3275
|
+
var IntervalQualities = {
|
|
3276
|
+
"1": {
|
|
3277
|
+
// Unison
|
|
3278
|
+
"0": "Perfect",
|
|
3279
|
+
"1": "Augmented",
|
|
3280
|
+
"-1": "diminished",
|
|
3281
|
+
"2": "Doubly Augmented",
|
|
3282
|
+
"-2": "doubly diminished"
|
|
3283
|
+
},
|
|
3284
|
+
"2": {
|
|
3285
|
+
// Second
|
|
3286
|
+
"2": "Major",
|
|
3287
|
+
"1": "minor",
|
|
3288
|
+
"3": "Augmented",
|
|
3289
|
+
"0": "diminished",
|
|
3290
|
+
"4": "Doubly Augmented",
|
|
3291
|
+
"-1": "doubly diminished"
|
|
3292
|
+
},
|
|
3293
|
+
"3": {
|
|
3294
|
+
// Third
|
|
3295
|
+
"4": "Major",
|
|
3296
|
+
"3": "minor",
|
|
3297
|
+
"5": "Augmented",
|
|
3298
|
+
"2": "diminished",
|
|
3299
|
+
"6": "Doubly Augmented",
|
|
3300
|
+
"1": "doubly diminished"
|
|
3301
|
+
},
|
|
3302
|
+
"4": {
|
|
3303
|
+
// Fourth
|
|
3304
|
+
"5": "Perfect",
|
|
3305
|
+
"6": "Augmented",
|
|
3306
|
+
"4": "diminished",
|
|
3307
|
+
"7": "Doubly Augmented",
|
|
3308
|
+
"3": "doubly diminished"
|
|
3309
|
+
},
|
|
3310
|
+
"5": {
|
|
3311
|
+
// Fifth
|
|
3312
|
+
"7": "Perfect",
|
|
3313
|
+
"8": "Augmented",
|
|
3314
|
+
"6": "diminished",
|
|
3315
|
+
"9": "Doubly Augmented",
|
|
3316
|
+
"5": "doubly diminished"
|
|
3317
|
+
},
|
|
3318
|
+
"6": {
|
|
3319
|
+
// Sixth
|
|
3320
|
+
"9": "Major",
|
|
3321
|
+
"8": "minor",
|
|
3322
|
+
"10": "Augmented",
|
|
3323
|
+
"7": "diminished",
|
|
3324
|
+
"11": "Doubly Augmented",
|
|
3325
|
+
"6": "doubly diminished"
|
|
3326
|
+
},
|
|
3327
|
+
"7": {
|
|
3328
|
+
// Seventh
|
|
3329
|
+
"11": "Major",
|
|
3330
|
+
"10": "minor",
|
|
3331
|
+
"12": "Augmented",
|
|
3332
|
+
"9": "diminished",
|
|
3333
|
+
"13": "Doubly Augmented",
|
|
3334
|
+
"8": "doubly diminished"
|
|
3335
|
+
},
|
|
3336
|
+
"8": {
|
|
3337
|
+
// Octave
|
|
3338
|
+
"12": "Perfect",
|
|
3339
|
+
"13": "Augmented",
|
|
3340
|
+
"11": "diminished",
|
|
3341
|
+
"14": "Doubly Augmented",
|
|
3342
|
+
"10": "doubly diminished"
|
|
3343
|
+
}
|
|
3344
|
+
};
|
|
3345
|
+
function getIntervalQuality(diatonicInterval, chromaticInterval) {
|
|
3346
|
+
while (diatonicInterval < 1) {
|
|
3347
|
+
diatonicInterval += 7;
|
|
3348
|
+
chromaticInterval += 12;
|
|
3349
|
+
}
|
|
3350
|
+
while (diatonicInterval > 8) {
|
|
3351
|
+
diatonicInterval -= 7;
|
|
3352
|
+
chromaticInterval -= 12;
|
|
3353
|
+
}
|
|
3354
|
+
const qualities = IntervalQualities[diatonicInterval];
|
|
3355
|
+
if (qualities) {
|
|
3356
|
+
return qualities[chromaticInterval];
|
|
3357
|
+
} else {
|
|
3358
|
+
return void 0;
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
function validateIntervalQuality(q) {
|
|
3362
|
+
if (!(q === "Perfect" || q === "Major" || q === "minor" || q === "Augmented" || q === "diminished" || q === "Doubly Augmented" || q === "doubly diminished")) {
|
|
3363
|
+
throw new import_core4.MusicError(import_core4.MusicErrorType.InvalidArg, `Invalid interval quality: ${q}`);
|
|
3364
|
+
} else {
|
|
3365
|
+
return q;
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
function formatQuantity(q) {
|
|
3369
|
+
if (!guard_exports.isIntegerGte(q, 1)) {
|
|
3370
|
+
throw new import_core4.MusicError(import_core4.MusicErrorType.InvalidArg, `Invalid interval quantity: ${q}`);
|
|
3371
|
+
} else {
|
|
3372
|
+
return utils_exports.Math.toOrdinalNumber(q);
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
var InvalidIntervalException = class extends Error {
|
|
3376
|
+
constructor(msg) {
|
|
3377
|
+
super(msg);
|
|
3378
|
+
this.msg = msg;
|
|
3379
|
+
this.name = "InvalidInterval";
|
|
3380
|
+
}
|
|
3381
|
+
};
|
|
3382
|
+
var Interval = class _Interval {
|
|
3383
|
+
constructor(note1, note2) {
|
|
3384
|
+
this.note1 = note1;
|
|
3385
|
+
this.note2 = note2;
|
|
3386
|
+
/** Interval direction. */
|
|
3387
|
+
__publicField(this, "direction");
|
|
3388
|
+
/** Number of semitones. */
|
|
3389
|
+
__publicField(this, "semitones");
|
|
3390
|
+
/** Interval quantity. */
|
|
3391
|
+
__publicField(this, "quantity");
|
|
3392
|
+
/** Interval quality. */
|
|
3393
|
+
__publicField(this, "quality");
|
|
3394
|
+
if (note2.diatonicId >= note1.diatonicId) {
|
|
3395
|
+
this.direction = note2.diatonicId === note1.diatonicId ? "Unison" : "Ascending";
|
|
3396
|
+
this.quantity = note2.diatonicId - note1.diatonicId + 1;
|
|
3397
|
+
this.semitones = note2.chromaticId - note1.chromaticId;
|
|
3398
|
+
} else {
|
|
3399
|
+
this.direction = "Descending";
|
|
3400
|
+
this.quantity = note1.diatonicId - note2.diatonicId + 1;
|
|
3401
|
+
this.semitones = note1.chromaticId - note2.chromaticId;
|
|
3402
|
+
}
|
|
3403
|
+
let quality = getIntervalQuality(this.quantity, this.semitones);
|
|
3404
|
+
if (quality) {
|
|
3405
|
+
this.quality = quality;
|
|
3406
|
+
} else {
|
|
3407
|
+
throw new InvalidIntervalException("Unknown interval quality");
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
/**
|
|
3411
|
+
* Get interval between given two notes.
|
|
3412
|
+
* @param note1 - First note.
|
|
3413
|
+
* @param note2 - Second note.
|
|
3414
|
+
* @returns - Interval if valid, or undefined.
|
|
3415
|
+
*/
|
|
3416
|
+
static get(note1, note2) {
|
|
3417
|
+
try {
|
|
3418
|
+
return new _Interval(note1, note2);
|
|
3419
|
+
} catch (err) {
|
|
3420
|
+
if (err instanceof InvalidIntervalException) {
|
|
3421
|
+
return void 0;
|
|
3422
|
+
} else {
|
|
3423
|
+
throw err;
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
/**
|
|
3428
|
+
* Get string presentation of interval (e.g. "Descending Major 2").
|
|
3429
|
+
* @returns - Interval string.
|
|
3430
|
+
*/
|
|
3431
|
+
toString() {
|
|
3432
|
+
let direction = this.direction === "Unison" ? "" : this.direction + " ";
|
|
3433
|
+
let quality = this.quality + " ";
|
|
3434
|
+
let quantity = this.direction === "Unison" ? "Unison" : formatQuantity(this.quantity);
|
|
3435
|
+
return direction + quality + quantity;
|
|
3436
|
+
}
|
|
3437
|
+
/**
|
|
3438
|
+
* Get abbrevated string presentation of interval (e.g. "↓M2").
|
|
3439
|
+
* @returns - Interval abbrevated string.
|
|
3440
|
+
*/
|
|
3441
|
+
toAbbrString() {
|
|
3442
|
+
let direction = this.direction === "Descending" ? "\u2193" : "";
|
|
3443
|
+
let quality = IntervalQualityAbbrMap.getOrDefault(this.quality, "?");
|
|
3444
|
+
let quantity = this.quantity;
|
|
3445
|
+
return direction + quality + quantity;
|
|
3446
|
+
}
|
|
3447
|
+
};
|
|
3448
|
+
|
|
3449
|
+
// src/theory/scale.ts
|
|
3450
|
+
var import_core5 = require("web-music-score/core");
|
|
3451
|
+
function getNaturalDiatonicId(chromaticId) {
|
|
3452
|
+
let diatonicClass = Note.getDiatonicClass("CCDDEFFGGAAB"[Note.getChromaticClass(chromaticId)]);
|
|
3453
|
+
let octave = Note.getOctaveFromChromaticId(chromaticId);
|
|
3454
|
+
return Note.getDiatonicIdInOctave(diatonicClass, octave);
|
|
3455
|
+
}
|
|
3456
|
+
var FullTonicList = [
|
|
3457
|
+
"Cb",
|
|
3458
|
+
"C",
|
|
3459
|
+
"C#",
|
|
3460
|
+
"Db",
|
|
3461
|
+
"D",
|
|
3462
|
+
"D#",
|
|
3463
|
+
"Eb",
|
|
3464
|
+
"E",
|
|
3465
|
+
"E#",
|
|
3466
|
+
"Fb",
|
|
3467
|
+
"F",
|
|
3468
|
+
"F#",
|
|
3469
|
+
"Gb",
|
|
3470
|
+
"G",
|
|
3471
|
+
"G#",
|
|
3472
|
+
"Ab",
|
|
3473
|
+
"A",
|
|
3474
|
+
"A#",
|
|
3475
|
+
"Bb",
|
|
3476
|
+
"B",
|
|
3477
|
+
"B#"
|
|
3478
|
+
];
|
|
3479
|
+
var ScaleType = /* @__PURE__ */ ((ScaleType2) => {
|
|
3480
|
+
ScaleType2["Major"] = "Major";
|
|
3481
|
+
ScaleType2["NaturalMinor"] = "Natural Minor";
|
|
3482
|
+
ScaleType2["HarmonicMinor"] = "Harmonic Minor";
|
|
3483
|
+
ScaleType2["Ionian"] = "Ionian";
|
|
3484
|
+
ScaleType2["Dorian"] = "Dorian";
|
|
3485
|
+
ScaleType2["Phrygian"] = "Phrygian";
|
|
3486
|
+
ScaleType2["Lydian"] = "Lydian";
|
|
3487
|
+
ScaleType2["Mixolydian"] = "Mixolydian";
|
|
3488
|
+
ScaleType2["Aeolian"] = "Aeolian";
|
|
3489
|
+
ScaleType2["Locrian"] = "Locrian";
|
|
3490
|
+
ScaleType2["MajorPentatonic"] = "Major Pentatonic";
|
|
3491
|
+
ScaleType2["MinorPentatonic"] = "Minor Pentatonic";
|
|
3492
|
+
ScaleType2["MajorHexatonicBlues"] = "Major Hexatonic Blues";
|
|
3493
|
+
ScaleType2["MinorHexatonicBlues"] = "Minor Hexatonic Blues";
|
|
3494
|
+
ScaleType2["HeptatonicBlues"] = "Heptatonic Blues";
|
|
3495
|
+
return ScaleType2;
|
|
3496
|
+
})(ScaleType || {});
|
|
3497
|
+
function getMode(scaleType) {
|
|
3498
|
+
switch (scaleType) {
|
|
3499
|
+
case "Major" /* Major */:
|
|
3500
|
+
return 1;
|
|
3501
|
+
case "Natural Minor" /* NaturalMinor */:
|
|
3502
|
+
return 6;
|
|
3503
|
+
case "Harmonic Minor" /* HarmonicMinor */:
|
|
3504
|
+
return 6;
|
|
3505
|
+
case "Ionian" /* Ionian */:
|
|
3506
|
+
return 1;
|
|
3507
|
+
case "Dorian" /* Dorian */:
|
|
3508
|
+
return 2;
|
|
3509
|
+
case "Phrygian" /* Phrygian */:
|
|
3510
|
+
return 3;
|
|
3511
|
+
case "Lydian" /* Lydian */:
|
|
3512
|
+
return 4;
|
|
3513
|
+
case "Mixolydian" /* Mixolydian */:
|
|
3514
|
+
return 5;
|
|
3515
|
+
case "Aeolian" /* Aeolian */:
|
|
3516
|
+
return 6;
|
|
3517
|
+
case "Locrian" /* Locrian */:
|
|
3518
|
+
return 7;
|
|
3519
|
+
case "Major Pentatonic" /* MajorPentatonic */:
|
|
3520
|
+
return 1;
|
|
3521
|
+
case "Minor Pentatonic" /* MinorPentatonic */:
|
|
3522
|
+
return 6;
|
|
3523
|
+
case "Major Hexatonic Blues" /* MajorHexatonicBlues */:
|
|
3524
|
+
return 1;
|
|
3525
|
+
case "Minor Hexatonic Blues" /* MinorHexatonicBlues */:
|
|
3526
|
+
return 6;
|
|
3527
|
+
case "Heptatonic Blues" /* HeptatonicBlues */:
|
|
3528
|
+
return 1;
|
|
3529
|
+
default:
|
|
3530
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Invalid scaleType: ${scaleType}`);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
var Scale = class extends KeySignature {
|
|
3534
|
+
/**
|
|
3535
|
+
* Create nev scale object instance.
|
|
3536
|
+
* @param tonic - Tonic (e.g. "C" in "C Major").
|
|
3537
|
+
* @param scaleType - Scale typo ("e.g. "Major" in "C Major").
|
|
3538
|
+
*/
|
|
3539
|
+
constructor(tonic, scaleType) {
|
|
3540
|
+
super(tonic, getMode(scaleType));
|
|
3541
|
+
this.tonic = tonic;
|
|
3542
|
+
this.scaleType = scaleType;
|
|
3543
|
+
/** Degrees of scale notes. */
|
|
3544
|
+
__publicField(this, "scaleDegrees");
|
|
3545
|
+
/** Scale notes. */
|
|
3546
|
+
__publicField(this, "scaleNotes");
|
|
3547
|
+
/** Degrees (or undefined) of chromatic classes. */
|
|
3548
|
+
__publicField(this, "chromaticClassDegree");
|
|
3549
|
+
__publicField(this, "preferredChromaticIdNoteCache", new SignedIndexArray());
|
|
3550
|
+
switch (scaleType) {
|
|
3551
|
+
case "Harmonic Minor" /* HarmonicMinor */:
|
|
3552
|
+
this.scaleDegrees = [1, 2, 3, 4, 5, 6, "#7"];
|
|
3553
|
+
break;
|
|
3554
|
+
case "Major Pentatonic" /* MajorPentatonic */:
|
|
3555
|
+
this.scaleDegrees = [1, 2, 3, 5, 6];
|
|
3556
|
+
break;
|
|
3557
|
+
case "Minor Pentatonic" /* MinorPentatonic */:
|
|
3558
|
+
this.scaleDegrees = [1, 3, 4, 5, 7];
|
|
3559
|
+
break;
|
|
3560
|
+
case "Major Hexatonic Blues" /* MajorHexatonicBlues */:
|
|
3561
|
+
this.scaleDegrees = [1, 2, "b3", 3, 5, 6];
|
|
3562
|
+
break;
|
|
3563
|
+
case "Minor Hexatonic Blues" /* MinorHexatonicBlues */:
|
|
3564
|
+
this.scaleDegrees = [1, 3, 4, "b5", 5, 7];
|
|
3565
|
+
break;
|
|
3566
|
+
case "Heptatonic Blues" /* HeptatonicBlues */:
|
|
3567
|
+
this.scaleDegrees = [1, 2, "b3", 4, "b5", 6, "b7"];
|
|
3568
|
+
break;
|
|
3569
|
+
default:
|
|
3570
|
+
this.scaleDegrees = [1, 2, 3, 4, 5, 6, 7];
|
|
3571
|
+
break;
|
|
3572
|
+
}
|
|
3573
|
+
this.scaleNotes = this.scaleDegrees.map((d) => this.getNoteByDegree(d));
|
|
3574
|
+
this.chromaticClassDegree = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map((chromaticClass) => {
|
|
3575
|
+
let id = this.scaleNotes.findIndex((scaleNote) => scaleNote.chromaticClass === chromaticClass);
|
|
3576
|
+
return id >= 0 ? this.scaleDegrees[id] : void 0;
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3579
|
+
/**
|
|
3580
|
+
* Compare if two scales equals.
|
|
3581
|
+
* @param a - Scale a.
|
|
3582
|
+
* @param b - Scale b.
|
|
3583
|
+
* @returns - Boolean equality of given scales.
|
|
3584
|
+
*/
|
|
3585
|
+
static equals(a, b) {
|
|
3586
|
+
if (a == null && b == null) {
|
|
3587
|
+
return true;
|
|
3588
|
+
} else if (a == null || b == null) {
|
|
3589
|
+
return false;
|
|
3590
|
+
} else {
|
|
3591
|
+
return a === b || a.getScaleName() === b.getScaleName();
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
/**
|
|
3595
|
+
* Get scale name.
|
|
3596
|
+
* @param symbolSet - Symbol set to format scale name in ascii or unicode.
|
|
3597
|
+
* @returns - Scale name string.
|
|
3598
|
+
*/
|
|
3599
|
+
getScaleName(symbolSet) {
|
|
3600
|
+
switch (symbolSet) {
|
|
3601
|
+
case 1 /* Unicode */:
|
|
3602
|
+
return Note.getScientificNoteName(this.tonic, symbolSet) + " " + this.scaleType;
|
|
3603
|
+
default:
|
|
3604
|
+
return this.tonic + " " + this.scaleType;
|
|
3605
|
+
}
|
|
3606
|
+
}
|
|
3607
|
+
/**
|
|
3608
|
+
* Get scale notes.
|
|
3609
|
+
* @param bottomNote - Computed scale notes begin no lower than this note.
|
|
3610
|
+
* @param numOctaves - How many octaves?
|
|
3611
|
+
* @returns - Array of scale notes.
|
|
3612
|
+
*/
|
|
3613
|
+
getScaleNotes(bottomNote, numOctaves) {
|
|
3614
|
+
if (!guard_exports.isIntegerGte(numOctaves, 1)) {
|
|
3615
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Invalid numOctaves: ${numOctaves}`);
|
|
3616
|
+
}
|
|
3617
|
+
let scaleNoteList = [];
|
|
3618
|
+
for (let o = 1; o <= numOctaves; o++) {
|
|
3619
|
+
scaleNoteList = [...scaleNoteList, ...this.scaleNotes];
|
|
3620
|
+
}
|
|
3621
|
+
scaleNoteList.push(this.scaleNotes[0]);
|
|
3622
|
+
let diatonicId = Note.getNote(bottomNote).diatonicId;
|
|
3623
|
+
return scaleNoteList.map((note) => {
|
|
3624
|
+
diatonicId = Note.findNextDiatonicIdAbove(note.diatonicId, diatonicId, false);
|
|
3625
|
+
return new Note(diatonicId, note.accidental);
|
|
3626
|
+
});
|
|
3627
|
+
}
|
|
3628
|
+
/**
|
|
3629
|
+
* Get scale overview (e.g. "C - D - E - F - G - A - B" for "C Major" scale).
|
|
3630
|
+
* @returns - Scale overview string.
|
|
3631
|
+
*/
|
|
3632
|
+
getScaleOverview() {
|
|
3633
|
+
return this.getScaleNotes("C4", 1).map((note) => note.formatOmitOctave(1 /* Unicode */)).join(" - ");
|
|
3634
|
+
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Get scale steps, array of 1 (half step) and 2 (whole step), (e.g. [2, 2, 1, 2, 2, 2, 1] for Major scale).
|
|
3637
|
+
* @returns - Array of scale steps.
|
|
3638
|
+
*/
|
|
3639
|
+
getScaleSteps() {
|
|
3640
|
+
let chromaticIds = this.getScaleNotes("C4", 1).map((note) => note.chromaticId);
|
|
3641
|
+
let steps = [];
|
|
3642
|
+
for (let i = 0; i < chromaticIds.length - 1; i++) {
|
|
3643
|
+
steps.push(utils_exports.Math.mod(chromaticIds[i + 1] - chromaticIds[i], 12));
|
|
3644
|
+
}
|
|
3645
|
+
return steps;
|
|
3646
|
+
}
|
|
3647
|
+
/**
|
|
3648
|
+
* Get scale steps string presentation, array of "H" (half step) and "W" (whole step), (e.g. ["W", "W", "H", "W", "W", "W", "H"] for Major scale).
|
|
3649
|
+
* @returns - Array of scale steps string presentation.
|
|
3650
|
+
*/
|
|
3651
|
+
getScaleStringSteps() {
|
|
3652
|
+
return this.getScaleSteps().map((step) => step === 1 ? "H" : step === 2 ? "W" : step.toString() + "H");
|
|
3653
|
+
}
|
|
3654
|
+
/**
|
|
3655
|
+
* Test if given note is scale note.
|
|
3656
|
+
* @param note - Note to test.
|
|
3657
|
+
* @returns - True/false.
|
|
3658
|
+
*/
|
|
3659
|
+
isScaleNote(note) {
|
|
3660
|
+
return this.chromaticClassDegree[note.chromaticClass] !== void 0;
|
|
3661
|
+
}
|
|
3662
|
+
/**
|
|
3663
|
+
* Test if given note is scale root note.
|
|
3664
|
+
* @param note - Note to test.
|
|
3665
|
+
* @returns - True/false.
|
|
3666
|
+
*/
|
|
3667
|
+
isScaleRootNote(note) {
|
|
3668
|
+
return String(this.chromaticClassDegree[note.chromaticClass]) === "1";
|
|
3669
|
+
}
|
|
3670
|
+
/**
|
|
3671
|
+
* Get interval value between scale root note and given note.
|
|
3672
|
+
* @param note - Note.
|
|
3673
|
+
* @returns - Interval.
|
|
3674
|
+
*/
|
|
3675
|
+
getIntervalFromRootNote(note) {
|
|
3676
|
+
let rootNote = this.getScaleNotes("C0", 1)[0];
|
|
3677
|
+
while (note.chromaticId >= rootNote.chromaticId + 12) {
|
|
3678
|
+
note = new Note(note.diatonicClass, note.accidental, note.octave - 1);
|
|
3679
|
+
}
|
|
3680
|
+
if (note.chromaticId < rootNote.chromaticId) {
|
|
3681
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Note is below rootNote.`);
|
|
3682
|
+
}
|
|
3683
|
+
let interval = Interval.get(rootNote, note);
|
|
3684
|
+
if (interval === void 0) {
|
|
3685
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Interval is undefined.`);
|
|
3686
|
+
} else {
|
|
3687
|
+
return interval;
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
// Can it be negative case?
|
|
3691
|
+
/**
|
|
3692
|
+
* Get preferred chromatic note from given chromatic id.
|
|
3693
|
+
* @param chromaticId - Chromatic id.
|
|
3694
|
+
* @returns - Note.
|
|
3695
|
+
*/
|
|
3696
|
+
getPreferredChromaticNote(chromaticId) {
|
|
3697
|
+
Note.validateChromaticId(chromaticId);
|
|
3698
|
+
let note = this.preferredChromaticIdNoteCache.get(chromaticId);
|
|
3699
|
+
if (note) {
|
|
3700
|
+
return note;
|
|
3701
|
+
}
|
|
3702
|
+
let octave = Note.getOctaveFromChromaticId(chromaticId);
|
|
3703
|
+
let scaleNotes = this.scaleNotes.map((accNote) => {
|
|
3704
|
+
if (accNote.noteLetter === "C" && accNote.accidental < 0) {
|
|
3705
|
+
return new Note(accNote.diatonicClass, accNote.accidental, octave + 1);
|
|
3706
|
+
} else if (accNote.noteLetter === "B" && accNote.accidental > 0) {
|
|
3707
|
+
return new Note(accNote.diatonicClass, accNote.accidental, octave - 1);
|
|
3708
|
+
} else {
|
|
3709
|
+
return new Note(accNote.diatonicClass, accNote.accidental, octave);
|
|
3710
|
+
}
|
|
3711
|
+
});
|
|
3712
|
+
note = scaleNotes.find((note2) => Note.getChromaticClass(chromaticId) === note2.chromaticClass);
|
|
3713
|
+
if (note) {
|
|
3714
|
+
this.preferredChromaticIdNoteCache.set(chromaticId, note);
|
|
3715
|
+
return note;
|
|
3716
|
+
}
|
|
3717
|
+
let diatonicIdMid = getNaturalDiatonicId(chromaticId);
|
|
3718
|
+
let diatonicIdStart = diatonicIdMid - 2;
|
|
3719
|
+
let diatonicIdEnd = diatonicIdMid + 2;
|
|
3720
|
+
let preferFlat = this.getAccidentalType() === 1 /* Flats */;
|
|
3721
|
+
let preferredAccs = preferFlat ? [0, -1, 1, -2, 2] : [0, 1, -1, 2, -2];
|
|
3722
|
+
for (let ai = 0; ai < preferredAccs.length; ai++) {
|
|
3723
|
+
let acc = preferredAccs[ai];
|
|
3724
|
+
for (let diatonicId = Math.max(0, diatonicIdStart); diatonicId <= diatonicIdEnd; diatonicId++) {
|
|
3725
|
+
note = new Note(diatonicId, acc);
|
|
3726
|
+
if (chromaticId === note.chromaticId) {
|
|
3727
|
+
this.preferredChromaticIdNoteCache.set(chromaticId, note);
|
|
3728
|
+
return note;
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
note = Note.getChromaticNote(chromaticId);
|
|
3733
|
+
this.preferredChromaticIdNoteCache.set(chromaticId, note);
|
|
3734
|
+
return note;
|
|
3735
|
+
}
|
|
3736
|
+
};
|
|
3737
|
+
var ScaleFactory = class {
|
|
3738
|
+
/**
|
|
3739
|
+
* Create new scale factory object instance.
|
|
3740
|
+
* @param type - Scale type.
|
|
3741
|
+
*/
|
|
3742
|
+
constructor(type) {
|
|
3743
|
+
this.type = type;
|
|
3744
|
+
__publicField(this, "tonicList", []);
|
|
3745
|
+
__publicField(this, "scaleMap", /* @__PURE__ */ new Map());
|
|
3746
|
+
let naturalScales = [];
|
|
3747
|
+
let sharpScales = [];
|
|
3748
|
+
let flatScales = [];
|
|
3749
|
+
FullTonicList.forEach((tonic) => {
|
|
3750
|
+
try {
|
|
3751
|
+
let scale = new Scale(tonic, this.type);
|
|
3752
|
+
switch (scale.getAccidentalType()) {
|
|
3753
|
+
case 0 /* Natural */:
|
|
3754
|
+
naturalScales.push(scale);
|
|
3755
|
+
break;
|
|
3756
|
+
case 2 /* Sharps */:
|
|
3757
|
+
if (tonic.endsWith("b")) {
|
|
3758
|
+
return;
|
|
3759
|
+
} else {
|
|
3760
|
+
sharpScales.push(scale);
|
|
3761
|
+
break;
|
|
3762
|
+
}
|
|
3763
|
+
case 1 /* Flats */:
|
|
3764
|
+
if (tonic.endsWith("#")) {
|
|
3765
|
+
return;
|
|
3766
|
+
} else {
|
|
3767
|
+
flatScales.push(scale);
|
|
3768
|
+
break;
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
this.scaleMap.set(tonic, scale);
|
|
3772
|
+
} catch (err) {
|
|
3773
|
+
}
|
|
3774
|
+
});
|
|
3775
|
+
if (naturalScales.length === 0) {
|
|
3776
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Expected natural scale.`);
|
|
3777
|
+
}
|
|
3778
|
+
const SortByAccidentalCountFunc = (a, b) => a.getNumAccidentals() - b.getNumAccidentals();
|
|
3779
|
+
this.tonicList = [
|
|
3780
|
+
...naturalScales.sort(SortByAccidentalCountFunc).map((scale) => scale.tonic),
|
|
3781
|
+
"- Sharps -",
|
|
3782
|
+
...sharpScales.sort(SortByAccidentalCountFunc).map((scale) => scale.tonic),
|
|
3783
|
+
"- Flats -",
|
|
3784
|
+
...flatScales.sort(SortByAccidentalCountFunc).map((scale) => scale.tonic)
|
|
3785
|
+
];
|
|
3786
|
+
}
|
|
3787
|
+
/**
|
|
3788
|
+
* Get list of tonics (e.g. "C", "C#", ... for Major scale type).
|
|
3789
|
+
* @returns - Array of tonics.
|
|
3790
|
+
*/
|
|
3791
|
+
getTonicList() {
|
|
3792
|
+
return this.tonicList;
|
|
3793
|
+
}
|
|
3794
|
+
/**
|
|
3795
|
+
* Get default tonic.
|
|
3796
|
+
* @returns - Default tonic.
|
|
3797
|
+
*/
|
|
3798
|
+
getDefaultTonic() {
|
|
3799
|
+
return this.tonicList[0];
|
|
3800
|
+
}
|
|
3801
|
+
/**
|
|
3802
|
+
* Get scale type.
|
|
3803
|
+
* @returns - SCale type.
|
|
3804
|
+
*/
|
|
3805
|
+
getType() {
|
|
3806
|
+
return this.type;
|
|
3807
|
+
}
|
|
3808
|
+
/**
|
|
3809
|
+
* Get scale by given tonic.
|
|
3810
|
+
* @param tonic - Tonic (e.g. "C").
|
|
3811
|
+
* @returns - Scale.
|
|
3812
|
+
*/
|
|
3813
|
+
getScale(tonic) {
|
|
3814
|
+
let scale = this.scaleMap.get(tonic);
|
|
3815
|
+
if (!scale) {
|
|
3816
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Invalid scale: ${tonic} ${this.type}`);
|
|
3817
|
+
} else {
|
|
3818
|
+
return scale;
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
/**
|
|
3822
|
+
* Test if this scale factory has scale for given tonic value.
|
|
3823
|
+
* @param tonic - Tonic.
|
|
3824
|
+
* @returns - True/false.
|
|
3825
|
+
*/
|
|
3826
|
+
hasScale(tonic) {
|
|
3827
|
+
return this.scaleMap.get(tonic) !== void 0;
|
|
3828
|
+
}
|
|
3829
|
+
};
|
|
3830
|
+
var ScaleFactoryList = [
|
|
3831
|
+
new ScaleFactory("Major" /* Major */),
|
|
3832
|
+
new ScaleFactory("Natural Minor" /* NaturalMinor */),
|
|
3833
|
+
new ScaleFactory("Harmonic Minor" /* HarmonicMinor */),
|
|
3834
|
+
"- Modes -",
|
|
3835
|
+
new ScaleFactory("Ionian" /* Ionian */),
|
|
3836
|
+
new ScaleFactory("Dorian" /* Dorian */),
|
|
3837
|
+
new ScaleFactory("Phrygian" /* Phrygian */),
|
|
3838
|
+
new ScaleFactory("Lydian" /* Lydian */),
|
|
3839
|
+
new ScaleFactory("Mixolydian" /* Mixolydian */),
|
|
3840
|
+
new ScaleFactory("Aeolian" /* Aeolian */),
|
|
3841
|
+
new ScaleFactory("Locrian" /* Locrian */),
|
|
3842
|
+
"- Pentatonic -",
|
|
3843
|
+
new ScaleFactory("Major Pentatonic" /* MajorPentatonic */),
|
|
3844
|
+
new ScaleFactory("Minor Pentatonic" /* MinorPentatonic */),
|
|
3845
|
+
"- Blues -",
|
|
3846
|
+
new ScaleFactory("Major Hexatonic Blues" /* MajorHexatonicBlues */),
|
|
3847
|
+
new ScaleFactory("Minor Hexatonic Blues" /* MinorHexatonicBlues */),
|
|
3848
|
+
new ScaleFactory("Heptatonic Blues" /* HeptatonicBlues */)
|
|
3849
|
+
];
|
|
3850
|
+
function getScaleFactoryList() {
|
|
3851
|
+
return ScaleFactoryList;
|
|
3852
|
+
}
|
|
3853
|
+
var ScaleFactoryMap = new UniMap();
|
|
3854
|
+
ScaleFactoryList.forEach((factory) => {
|
|
3855
|
+
if (factory instanceof ScaleFactory) {
|
|
3856
|
+
ScaleFactoryMap.set(factory.getType(), factory);
|
|
3857
|
+
}
|
|
3858
|
+
});
|
|
3859
|
+
function getScaleFactory(scaleType) {
|
|
3860
|
+
let f = ScaleFactoryMap.get(scaleType);
|
|
3861
|
+
if (!f) {
|
|
3862
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Invalid scaleType: ${scaleType}`);
|
|
3863
|
+
} else {
|
|
3864
|
+
return f;
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
function validateScaleType(scaleType) {
|
|
3868
|
+
if (guard_exports.isEnumValue(scaleType, ScaleType)) {
|
|
3869
|
+
return scaleType;
|
|
3870
|
+
} else {
|
|
3871
|
+
throw new import_core5.MusicError(import_core5.MusicErrorType.Scale, `Invalid scaleType: "${scaleType}"`);
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
function getScale(arg0, arg1) {
|
|
3875
|
+
let tonic;
|
|
3876
|
+
let scaleType;
|
|
3877
|
+
if (arg1 !== void 0) {
|
|
3878
|
+
tonic = arg0;
|
|
3879
|
+
scaleType = validateScaleType(arg1);
|
|
3880
|
+
} else {
|
|
3881
|
+
tonic = arg0.split(" ")[0];
|
|
3882
|
+
scaleType = validateScaleType(arg0.substring(tonic.length + 1));
|
|
3883
|
+
}
|
|
3884
|
+
return getScaleFactory(scaleType).getScale(tonic);
|
|
3885
|
+
}
|
|
3886
|
+
var DefaultScale = getScale("C", "Major" /* Major */);
|
|
3887
|
+
function getDefaultScale() {
|
|
3888
|
+
return DefaultScale;
|
|
3889
|
+
}
|
|
3890
|
+
|
|
3891
|
+
// src/theory/chord.ts
|
|
3892
|
+
var import_core6 = require("web-music-score/core");
|
|
3893
|
+
var isEqualNote = (n1, n2) => n1.chromaticClass === n2.chromaticClass;
|
|
3894
|
+
var OkayRootNoteList = [
|
|
3895
|
+
"C",
|
|
3896
|
+
"C#",
|
|
3897
|
+
"Db",
|
|
3898
|
+
// Same id, first one always gets found
|
|
3899
|
+
"D",
|
|
3900
|
+
"Eb",
|
|
3901
|
+
"E",
|
|
3902
|
+
"F",
|
|
3903
|
+
"F#",
|
|
3904
|
+
"Gb",
|
|
3905
|
+
"G",
|
|
3906
|
+
"Ab",
|
|
3907
|
+
"A",
|
|
3908
|
+
"Bb",
|
|
3909
|
+
"B",
|
|
3910
|
+
"Cb"
|
|
3911
|
+
].map((noteName) => Note.getNote(noteName + "0"));
|
|
3912
|
+
var okayRootNoteCache = new IndexArray();
|
|
3913
|
+
function getOkayRootNote(wantedRootNote) {
|
|
3914
|
+
return okayRootNoteCache.getOrCreate(wantedRootNote.chromaticClass, () => {
|
|
3915
|
+
let rootNote = OkayRootNoteList.find((note) => isEqualNote(note, wantedRootNote));
|
|
3916
|
+
if (!rootNote) {
|
|
3917
|
+
throw new import_core6.MusicError(import_core6.MusicErrorType.InvalidArg, `Invalid chord root note: ${wantedRootNote.formatOmitOctave(1 /* Unicode */)}`);
|
|
3918
|
+
}
|
|
3919
|
+
return rootNote;
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
function getChordNoteByDegree(chordRootNote, degree) {
|
|
3923
|
+
let chordRootNoteStr = chordRootNote.formatOmitOctave(0 /* Ascii */);
|
|
3924
|
+
let ks = getScale(chordRootNoteStr, "Major" /* Major */);
|
|
3925
|
+
return ks.getNoteByDegree(degree);
|
|
3926
|
+
}
|
|
3927
|
+
function removeNoteDuplicates(notes) {
|
|
3928
|
+
return utils_exports.Arr.removeDuplicates(notes, isEqualNote);
|
|
3929
|
+
}
|
|
3930
|
+
var ChordInfoList = [
|
|
3931
|
+
// Power chord
|
|
3932
|
+
{ name: "5", degrees: [1, 5] },
|
|
3933
|
+
// Triads
|
|
3934
|
+
{ name: "", degrees: [1, 3, 5] },
|
|
3935
|
+
{ name: "m", degrees: [1, "b3", 5] },
|
|
3936
|
+
{ name: "dim", degrees: [1, "b3", "b5"] },
|
|
3937
|
+
{ name: "aug", degrees: [1, 3, "#5"] },
|
|
3938
|
+
{ name: "sus2", degrees: [1, 2, 5] },
|
|
3939
|
+
{ name: "sus4", degrees: [1, 4, 5] },
|
|
3940
|
+
// Four-part chords
|
|
3941
|
+
{ name: "6", degrees: [1, 3, 5, 6] },
|
|
3942
|
+
{ name: "m6", degrees: [1, "b3", 5, 6] },
|
|
3943
|
+
{ name: "m(maj7)", degrees: [1, "b3", 5, 7] },
|
|
3944
|
+
{ name: "7", degrees: [1, 3, 5, "b7"] },
|
|
3945
|
+
{ name: "7\u266D5", degrees: [1, 3, "b5", "b7"] },
|
|
3946
|
+
{ name: "7\u266F5", degrees: [1, 3, "#5", "b7"] },
|
|
3947
|
+
{ name: "7sus2", degrees: [1, 2, 5, "b7"] },
|
|
3948
|
+
{ name: "7sus4", degrees: [1, 4, 5, "b7"] },
|
|
3949
|
+
{ name: "dim7", degrees: [1, "b3", "b5", "bb7"] },
|
|
3950
|
+
{ name: "maj7", degrees: [1, 3, 5, 7] },
|
|
3951
|
+
{ name: "maj7\u266D5", degrees: [1, 3, "b5", 7] },
|
|
3952
|
+
{ name: "maj7\u266F5", degrees: [1, 3, "#5", 7] },
|
|
3953
|
+
{ name: "m7", degrees: [1, "b3", 5, "b7"] },
|
|
3954
|
+
{ name: "m7\u266D5", degrees: [1, "b3", "b5", "b7"] },
|
|
3955
|
+
{ name: "m7\u266F5", degrees: [1, "b3", "#5", "b7"] },
|
|
3956
|
+
// Five-part chords
|
|
3957
|
+
{ name: "9", degrees: [1, 3, 5, "b7", 9] },
|
|
3958
|
+
{ name: "m9", degrees: [1, "b3", 5, "b7", 9] },
|
|
3959
|
+
{ name: "7\u266F9", degrees: [1, 3, 5, "b7", "#9"] },
|
|
3960
|
+
{ name: "7\u266D9", degrees: [1, 3, 5, "b7", "b9"] },
|
|
3961
|
+
// Six-part chords
|
|
3962
|
+
{ name: "11", degrees: [1, 3, 5, "b7", 9, 11] },
|
|
3963
|
+
{ name: "m11", degrees: [1, "b3", 5, "b7", 9, 11] },
|
|
3964
|
+
// Seven-part chords
|
|
3965
|
+
{ name: "13", degrees: [1, 3, 5, "b7", 9, 11, 13] },
|
|
3966
|
+
{ name: "m13", degrees: [1, "b3", 5, "b7", 9, 11, 13] }
|
|
3967
|
+
];
|
|
3968
|
+
function canOmitDegree(chordInfo, degree) {
|
|
3969
|
+
if (chordInfo.degrees.every((c) => c !== degree)) {
|
|
3970
|
+
return true;
|
|
3971
|
+
}
|
|
3972
|
+
return chordInfo.degrees.length >= 4 && degree === 5 || // Four (and higher) part chord can exclude 5th degree
|
|
3973
|
+
chordInfo.degrees.length >= 6 && degree === 9 || // Six (and higher) part chord can exclude 9th degree
|
|
3974
|
+
chordInfo.degrees.length >= 7 && degree === 11;
|
|
3975
|
+
}
|
|
3976
|
+
var InvalidChordException = class extends Error {
|
|
3977
|
+
constructor(msg) {
|
|
3978
|
+
super(msg);
|
|
3979
|
+
this.msg = msg;
|
|
3980
|
+
this.name = "InvalidChordException";
|
|
3981
|
+
}
|
|
3982
|
+
};
|
|
3983
|
+
var Chord = class _Chord {
|
|
3984
|
+
constructor(chordInfo, chordNotes, rootNote, bassNote) {
|
|
3985
|
+
this.chordInfo = chordInfo;
|
|
3986
|
+
this.rootNote = rootNote;
|
|
3987
|
+
/** Chord name. */
|
|
3988
|
+
__publicField(this, "name");
|
|
3989
|
+
/** Notes of this chord. */
|
|
3990
|
+
__publicField(this, "notes");
|
|
3991
|
+
/** Notes that are omitted in this chord (partial chord). */
|
|
3992
|
+
__publicField(this, "omitNotes");
|
|
3993
|
+
/** Bass note if not chord root note (e.g. "B" in "C/B"). */
|
|
3994
|
+
__publicField(this, "slashBassNote");
|
|
3995
|
+
this.name = chordInfo.name;
|
|
3996
|
+
let notesLeft = chordNotes.slice();
|
|
3997
|
+
let outOfChordBass = !notesLeft.some((note) => isEqualNote(note, bassNote));
|
|
3998
|
+
if (outOfChordBass) {
|
|
3999
|
+
notesLeft.push(bassNote);
|
|
4000
|
+
}
|
|
4001
|
+
this.notes = new Array(this.chordInfo.degrees.length);
|
|
4002
|
+
this.omitNotes = new Array(this.chordInfo.degrees.length);
|
|
4003
|
+
for (let i = 0; i < chordInfo.degrees.length; i++) {
|
|
4004
|
+
let degree = chordInfo.degrees[i];
|
|
4005
|
+
let degreeNote = this.notes[i] = getChordNoteByDegree(this.rootNote, degree);
|
|
4006
|
+
let noteIndex = notesLeft.findIndex((note) => isEqualNote(note, degreeNote));
|
|
4007
|
+
if (noteIndex >= 0) {
|
|
4008
|
+
this.omitNotes[i] = false;
|
|
4009
|
+
notesLeft.splice(noteIndex, 1);
|
|
4010
|
+
} else if (canOmitDegree(chordInfo, degree)) {
|
|
4011
|
+
this.omitNotes[i] = true;
|
|
4012
|
+
} else {
|
|
4013
|
+
throw new InvalidChordException("Missing chord note!");
|
|
4014
|
+
}
|
|
4015
|
+
if (isEqualNote(bassNote, degreeNote)) {
|
|
4016
|
+
bassNote = degreeNote;
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
if (notesLeft.length > 0) {
|
|
4020
|
+
if (notesLeft.every((note) => isEqualNote(note, bassNote))) {
|
|
4021
|
+
this.slashBassNote = bassNote;
|
|
4022
|
+
} else {
|
|
4023
|
+
throw new InvalidChordException("Got some extra notes that are not bass note!");
|
|
4024
|
+
}
|
|
4025
|
+
} else {
|
|
4026
|
+
this.slashBassNote = isEqualNote(bassNote, this.rootNote) ? void 0 : bassNote;
|
|
4027
|
+
}
|
|
4028
|
+
if (chordInfo.name === "5" && this.slashBassNote) {
|
|
4029
|
+
throw new InvalidChordException("Power chord no bass note allowed!");
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
/**
|
|
4033
|
+
* Get all chords that can be made up with given notes.
|
|
4034
|
+
* @param notes - Array of notes.
|
|
4035
|
+
* @returns - Array of chords.
|
|
4036
|
+
*/
|
|
4037
|
+
static getChords(notes) {
|
|
4038
|
+
let chords = [];
|
|
4039
|
+
let chordNotes = Note.sort(notes);
|
|
4040
|
+
let bassNote = chordNotes[0];
|
|
4041
|
+
let uniqueNotes = removeNoteDuplicates(chordNotes);
|
|
4042
|
+
for (let inversion = 0; inversion < uniqueNotes.length; inversion++) {
|
|
4043
|
+
let rootNote = getOkayRootNote(uniqueNotes[inversion]);
|
|
4044
|
+
ChordInfoList.forEach((chordInfo) => {
|
|
4045
|
+
try {
|
|
4046
|
+
let newChord = new _Chord(chordInfo, uniqueNotes, rootNote, bassNote);
|
|
4047
|
+
let replaceIndex = chords.findIndex((chord) => chord.replaceWith(newChord));
|
|
4048
|
+
if (replaceIndex >= 0) {
|
|
4049
|
+
chords[replaceIndex] = newChord;
|
|
4050
|
+
} else {
|
|
4051
|
+
chords.push(newChord);
|
|
4052
|
+
}
|
|
4053
|
+
} catch (err) {
|
|
4054
|
+
if (!(err instanceof InvalidChordException)) {
|
|
4055
|
+
throw err;
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
});
|
|
4059
|
+
}
|
|
4060
|
+
return chords;
|
|
4061
|
+
}
|
|
4062
|
+
replaceWith(arg) {
|
|
4063
|
+
if (arg.notes.length < this.notes.length) {
|
|
4064
|
+
return false;
|
|
4065
|
+
} else if (arg.slashBassNote && this.slashBassNote && !isEqualNote(arg.slashBassNote, this.slashBassNote) || arg.slashBassNote && !this.slashBassNote || !arg.slashBassNote && this.slashBassNote) {
|
|
4066
|
+
return false;
|
|
4067
|
+
}
|
|
4068
|
+
for (let i = 0; i < this.notes.length; i++) {
|
|
4069
|
+
if (!isEqualNote(arg.notes[i], this.notes[i]) || arg.omitNotes[i] !== this.omitNotes[i]) {
|
|
4070
|
+
return false;
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
return true;
|
|
4074
|
+
}
|
|
4075
|
+
/**
|
|
4076
|
+
* Get chord string presentation.
|
|
4077
|
+
* @returns Chord string presentation (e.g. "C/B").
|
|
4078
|
+
*/
|
|
4079
|
+
toString() {
|
|
4080
|
+
let symbolSet = 1 /* Unicode */;
|
|
4081
|
+
let rootNoteStr = this.rootNote.formatOmitOctave(symbolSet);
|
|
4082
|
+
let slashBassStr = this.slashBassNote ? "/" + this.slashBassNote.formatOmitOctave(symbolSet) : "";
|
|
4083
|
+
return rootNoteStr + this.name + slashBassStr;
|
|
4084
|
+
}
|
|
4085
|
+
/**
|
|
4086
|
+
* Get degree notation string (e.g. "E - 1(C) - 3(E) - 5(G)").
|
|
4087
|
+
* @returns Degree notation string.
|
|
4088
|
+
*/
|
|
4089
|
+
getDegreeNotationString() {
|
|
4090
|
+
let symbolSet = 1 /* Unicode */;
|
|
4091
|
+
let bassNoteStr = this.slashBassNote ? this.slashBassNote.formatOmitOctave(symbolSet) + " - " : "";
|
|
4092
|
+
let degreeNoteStr = this.omitNotes.map((omitNote, i) => {
|
|
4093
|
+
return this.getDegreeStr(i) + "(" + (omitNote ? "-" : this.getNoteStr(i)) + ")";
|
|
4094
|
+
}).join(" - ");
|
|
4095
|
+
return bassNoteStr + degreeNoteStr;
|
|
4096
|
+
}
|
|
4097
|
+
/**
|
|
4098
|
+
* Get string presentation of omitted degrees (e.g. "Omits 5(G), 9(D)").
|
|
4099
|
+
* @returns - String presentation of omitted degrees.
|
|
4100
|
+
*/
|
|
4101
|
+
getOmittedDegreesString() {
|
|
4102
|
+
let omittedStrList = this.omitNotes.map((omit, i) => {
|
|
4103
|
+
return omit ? this.getDegreeStr(i) + "(" + this.getNoteStr(i) + ")" : void 0;
|
|
4104
|
+
}).filter((str2) => str2 !== void 0);
|
|
4105
|
+
return omittedStrList.length > 0 ? "Omits " + omittedStrList.join(", ") : "";
|
|
4106
|
+
}
|
|
4107
|
+
/**
|
|
4108
|
+
* Degree index for given degree index (e.g. "3").
|
|
4109
|
+
* @param i - Chord degree index (e.g. 0 is first note degree of chord).
|
|
4110
|
+
* @returns Degree string.
|
|
4111
|
+
*/
|
|
4112
|
+
getDegreeStr(i) {
|
|
4113
|
+
return Note.replaceAccidentalSymbols("" + this.chordInfo.degrees[i], 1 /* Unicode */);
|
|
4114
|
+
}
|
|
4115
|
+
/**
|
|
4116
|
+
* Get note name for given degree index (e.g. "E").
|
|
4117
|
+
* @param i - Chord degree index (e.g. 0 is first note degree of chord).
|
|
4118
|
+
* @returns - Note name string.
|
|
4119
|
+
*/
|
|
4120
|
+
getNoteStr(i) {
|
|
4121
|
+
return this.notes[i].formatOmitOctave(1 /* Unicode */);
|
|
4122
|
+
}
|
|
4123
|
+
};
|
|
4124
|
+
|
|
4125
|
+
// src/theory/assets/tunings.json
|
|
4126
|
+
var tunings_default = {
|
|
4127
|
+
list: [
|
|
4128
|
+
{
|
|
4129
|
+
name: "Standard",
|
|
4130
|
+
strings: [
|
|
4131
|
+
"E2",
|
|
4132
|
+
"A2",
|
|
4133
|
+
"D3",
|
|
4134
|
+
"G3",
|
|
4135
|
+
"B3",
|
|
4136
|
+
"E4"
|
|
4137
|
+
]
|
|
4138
|
+
},
|
|
4139
|
+
{
|
|
4140
|
+
name: "B Standard",
|
|
4141
|
+
strings: [
|
|
4142
|
+
"B1",
|
|
4143
|
+
"E2",
|
|
4144
|
+
"A2",
|
|
4145
|
+
"D3",
|
|
4146
|
+
"F#3",
|
|
4147
|
+
"B3"
|
|
4148
|
+
]
|
|
4149
|
+
},
|
|
4150
|
+
{
|
|
4151
|
+
name: "C Standard",
|
|
4152
|
+
strings: [
|
|
4153
|
+
"C2",
|
|
4154
|
+
"F2",
|
|
4155
|
+
"A#2",
|
|
4156
|
+
"D#3",
|
|
4157
|
+
"G3",
|
|
4158
|
+
"C4"
|
|
4159
|
+
]
|
|
4160
|
+
},
|
|
4161
|
+
{
|
|
4162
|
+
name: "D Modal",
|
|
4163
|
+
strings: [
|
|
4164
|
+
"D2",
|
|
4165
|
+
"A2",
|
|
4166
|
+
"D3",
|
|
4167
|
+
"G3",
|
|
4168
|
+
"A3",
|
|
4169
|
+
"D4"
|
|
4170
|
+
]
|
|
4171
|
+
},
|
|
4172
|
+
{
|
|
4173
|
+
name: "D Standard",
|
|
4174
|
+
strings: [
|
|
4175
|
+
"D2",
|
|
4176
|
+
"G2",
|
|
4177
|
+
"C3",
|
|
4178
|
+
"F3",
|
|
4179
|
+
"A3",
|
|
4180
|
+
"D4"
|
|
4181
|
+
]
|
|
4182
|
+
},
|
|
4183
|
+
{
|
|
4184
|
+
name: "D# Standard",
|
|
4185
|
+
strings: [
|
|
4186
|
+
"D#2",
|
|
4187
|
+
"G#2",
|
|
4188
|
+
"C#3",
|
|
4189
|
+
"F#3",
|
|
4190
|
+
"A#3",
|
|
4191
|
+
"D#4"
|
|
4192
|
+
]
|
|
4193
|
+
},
|
|
4194
|
+
{
|
|
4195
|
+
name: "Double Drop D",
|
|
4196
|
+
strings: [
|
|
4197
|
+
"D2",
|
|
4198
|
+
"A2",
|
|
4199
|
+
"D3",
|
|
4200
|
+
"G3",
|
|
4201
|
+
"B3",
|
|
4202
|
+
"D4"
|
|
4203
|
+
]
|
|
4204
|
+
},
|
|
4205
|
+
{
|
|
4206
|
+
name: "Drop B",
|
|
4207
|
+
strings: [
|
|
4208
|
+
"B1",
|
|
4209
|
+
"F#2",
|
|
4210
|
+
"B2",
|
|
4211
|
+
"E3",
|
|
4212
|
+
"G#3",
|
|
4213
|
+
"C#4"
|
|
4214
|
+
]
|
|
4215
|
+
},
|
|
4216
|
+
{
|
|
4217
|
+
name: "Drop C",
|
|
4218
|
+
strings: [
|
|
4219
|
+
"C2",
|
|
4220
|
+
"G2",
|
|
4221
|
+
"C3",
|
|
4222
|
+
"F3",
|
|
4223
|
+
"A3",
|
|
4224
|
+
"D4"
|
|
4225
|
+
]
|
|
4226
|
+
},
|
|
4227
|
+
{
|
|
4228
|
+
name: "Drop D",
|
|
4229
|
+
strings: [
|
|
4230
|
+
"D2",
|
|
4231
|
+
"A2",
|
|
4232
|
+
"D3",
|
|
4233
|
+
"G3",
|
|
4234
|
+
"B3",
|
|
4235
|
+
"E4"
|
|
4236
|
+
]
|
|
4237
|
+
},
|
|
4238
|
+
{
|
|
4239
|
+
name: "Low C",
|
|
4240
|
+
strings: [
|
|
4241
|
+
"C2",
|
|
4242
|
+
"G2",
|
|
4243
|
+
"D3",
|
|
4244
|
+
"G3",
|
|
4245
|
+
"A3",
|
|
4246
|
+
"D4"
|
|
4247
|
+
]
|
|
4248
|
+
},
|
|
4249
|
+
{
|
|
4250
|
+
name: "New Standard",
|
|
4251
|
+
strings: [
|
|
4252
|
+
"C2",
|
|
4253
|
+
"G2",
|
|
4254
|
+
"D3",
|
|
4255
|
+
"A3",
|
|
4256
|
+
"E4",
|
|
4257
|
+
"G4"
|
|
4258
|
+
]
|
|
4259
|
+
},
|
|
4260
|
+
{
|
|
4261
|
+
name: "Open A",
|
|
4262
|
+
strings: [
|
|
4263
|
+
"E2",
|
|
4264
|
+
"A2",
|
|
4265
|
+
"C#3",
|
|
4266
|
+
"E3",
|
|
4267
|
+
"A3",
|
|
4268
|
+
"E4"
|
|
4269
|
+
]
|
|
4270
|
+
},
|
|
4271
|
+
{
|
|
4272
|
+
name: "Open A Minor",
|
|
4273
|
+
strings: [
|
|
4274
|
+
"E2",
|
|
4275
|
+
"A2",
|
|
4276
|
+
"E3",
|
|
4277
|
+
"A3",
|
|
4278
|
+
"C4",
|
|
4279
|
+
"E4"
|
|
4280
|
+
]
|
|
4281
|
+
},
|
|
4282
|
+
{
|
|
4283
|
+
name: "Open C",
|
|
4284
|
+
strings: [
|
|
4285
|
+
"C2",
|
|
4286
|
+
"G2",
|
|
4287
|
+
"C3",
|
|
4288
|
+
"G3",
|
|
4289
|
+
"C4",
|
|
4290
|
+
"E4"
|
|
4291
|
+
]
|
|
4292
|
+
},
|
|
4293
|
+
{
|
|
4294
|
+
name: "Open C Minor",
|
|
4295
|
+
strings: [
|
|
4296
|
+
"C2",
|
|
4297
|
+
"G2",
|
|
4298
|
+
"C3",
|
|
4299
|
+
"G3",
|
|
4300
|
+
"C4",
|
|
4301
|
+
"D#4"
|
|
4302
|
+
]
|
|
4303
|
+
},
|
|
4304
|
+
{
|
|
4305
|
+
name: "Open D",
|
|
4306
|
+
strings: [
|
|
4307
|
+
"D2",
|
|
4308
|
+
"A2",
|
|
4309
|
+
"D3",
|
|
4310
|
+
"F#3",
|
|
4311
|
+
"A3",
|
|
4312
|
+
"D4"
|
|
4313
|
+
]
|
|
4314
|
+
},
|
|
4315
|
+
{
|
|
4316
|
+
name: "Open D Minor",
|
|
4317
|
+
strings: [
|
|
4318
|
+
"D2",
|
|
4319
|
+
"A2",
|
|
4320
|
+
"D3",
|
|
4321
|
+
"F3",
|
|
4322
|
+
"A3",
|
|
4323
|
+
"D4"
|
|
4324
|
+
]
|
|
4325
|
+
},
|
|
4326
|
+
{
|
|
4327
|
+
name: "Open E",
|
|
4328
|
+
strings: [
|
|
4329
|
+
"E2",
|
|
4330
|
+
"B2",
|
|
4331
|
+
"E3",
|
|
4332
|
+
"G#3",
|
|
4333
|
+
"B3",
|
|
4334
|
+
"E4"
|
|
4335
|
+
]
|
|
4336
|
+
},
|
|
4337
|
+
{
|
|
4338
|
+
name: "Open E Minor",
|
|
4339
|
+
strings: [
|
|
4340
|
+
"E2",
|
|
4341
|
+
"B2",
|
|
4342
|
+
"E3",
|
|
4343
|
+
"G3",
|
|
4344
|
+
"B3",
|
|
4345
|
+
"E4"
|
|
4346
|
+
]
|
|
4347
|
+
},
|
|
4348
|
+
{
|
|
4349
|
+
name: "Open G",
|
|
4350
|
+
strings: [
|
|
4351
|
+
"D2",
|
|
4352
|
+
"G2",
|
|
4353
|
+
"D3",
|
|
4354
|
+
"G3",
|
|
4355
|
+
"B3",
|
|
4356
|
+
"D4"
|
|
4357
|
+
]
|
|
4358
|
+
},
|
|
4359
|
+
{
|
|
4360
|
+
name: "Open G Minor",
|
|
4361
|
+
strings: [
|
|
4362
|
+
"D2",
|
|
4363
|
+
"G2",
|
|
4364
|
+
"D3",
|
|
4365
|
+
"G3",
|
|
4366
|
+
"A#3",
|
|
4367
|
+
"D4"
|
|
4368
|
+
]
|
|
4369
|
+
}
|
|
4370
|
+
]
|
|
4371
|
+
};
|
|
4372
|
+
|
|
4373
|
+
// src/theory/guitar.ts
|
|
4374
|
+
var import_core7 = require("web-music-score/core");
|
|
4375
|
+
var TuningNameList = tunings_default.list.map((data) => data.name);
|
|
4376
|
+
var DefaultTuningName = TuningNameList[0];
|
|
4377
|
+
function validateTuningName(tuningName) {
|
|
4378
|
+
if (TuningNameList.indexOf(tuningName) < 0) {
|
|
4379
|
+
throw new import_core7.MusicError(import_core7.MusicErrorType.InvalidArg, `Invalid tuning name: ${tuningName}`);
|
|
4380
|
+
} else {
|
|
4381
|
+
return tuningName;
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
var TuningStringsCache = new LRUCache(100);
|
|
4385
|
+
function getTuningStrings(tuningName) {
|
|
4386
|
+
let tuningStrings = TuningStringsCache.get(tuningName);
|
|
4387
|
+
if (!tuningStrings) {
|
|
4388
|
+
let tuningData = tunings_default.list.find((data) => data.name === tuningName);
|
|
4389
|
+
if (!tuningData) {
|
|
4390
|
+
throw new import_core7.MusicError(import_core7.MusicErrorType.InvalidArg, `Invalid tuningName: ${tuningName}`);
|
|
4391
|
+
}
|
|
4392
|
+
tuningStrings = tuningData.strings.slice().reverse().map((noteName) => Note.getNote(noteName));
|
|
4393
|
+
if (!guard_exports.isIntegerEq(tuningStrings.length, 6)) {
|
|
4394
|
+
throw new import_core7.MusicError(import_core7.MusicErrorType.Unknown, `Tuning has ${tuningStrings.length} strings.`);
|
|
4395
|
+
}
|
|
4396
|
+
TuningStringsCache.set(tuningName, tuningStrings);
|
|
4397
|
+
}
|
|
4398
|
+
return tuningStrings;
|
|
4399
|
+
}
|
|
4400
|
+
|
|
4401
|
+
// src/theory/rhythm.ts
|
|
4402
|
+
var import_core8 = require("web-music-score/core");
|
|
4403
|
+
var MaxTupletRatioValue = 12;
|
|
4404
|
+
var TicksMultiplier = 12 * 11 * 9 * 7 * 5;
|
|
4405
|
+
var NoteLength = /* @__PURE__ */ ((NoteLength3) => {
|
|
4406
|
+
NoteLength3["Whole"] = "1n";
|
|
4407
|
+
NoteLength3["WholeTriplet"] = "1t";
|
|
4408
|
+
NoteLength3["WholeDot"] = "1.";
|
|
4409
|
+
NoteLength3["Whole2Dots"] = "1..";
|
|
4410
|
+
NoteLength3["Whole3Dots"] = "1...";
|
|
4411
|
+
NoteLength3["Whole4Dots"] = "1....";
|
|
4412
|
+
NoteLength3["Whole5Dots"] = "1.....";
|
|
4413
|
+
NoteLength3["Whole6Dots"] = "1......";
|
|
4414
|
+
NoteLength3["Half"] = "2n";
|
|
4415
|
+
NoteLength3["HalfTriplet"] = "2t";
|
|
4416
|
+
NoteLength3["HalfDot"] = "2.";
|
|
4417
|
+
NoteLength3["Half2Dots"] = "2..";
|
|
4418
|
+
NoteLength3["Half3Dots"] = "2...";
|
|
4419
|
+
NoteLength3["Half4Dots"] = "2....";
|
|
4420
|
+
NoteLength3["Half5Dots"] = "2.....";
|
|
4421
|
+
NoteLength3["Quarter"] = "4n";
|
|
4422
|
+
NoteLength3["QuarterTriplet"] = "4t";
|
|
4423
|
+
NoteLength3["QuarterDot"] = "4.";
|
|
4424
|
+
NoteLength3["Quarter2Dots"] = "4..";
|
|
4425
|
+
NoteLength3["Quarter3Dots"] = "4...";
|
|
4426
|
+
NoteLength3["Quarter4Dots"] = "4....";
|
|
4427
|
+
NoteLength3["Eighth"] = "8n";
|
|
4428
|
+
NoteLength3["EighthTriplet"] = "8t";
|
|
4429
|
+
NoteLength3["EighthDot"] = "8.";
|
|
4430
|
+
NoteLength3["Eighth2Dots"] = "8..";
|
|
4431
|
+
NoteLength3["Eighth3Dots"] = "8...";
|
|
4432
|
+
NoteLength3["Sixteenth"] = "16n";
|
|
4433
|
+
NoteLength3["SixteenthTriplet"] = "16t";
|
|
4434
|
+
NoteLength3["SixteenthDot"] = "16.";
|
|
4435
|
+
NoteLength3["Sixteenth2Dots"] = "16..";
|
|
4436
|
+
NoteLength3["ThirtySecond"] = "32n";
|
|
4437
|
+
NoteLength3["ThirtySecondTriplet"] = "32t";
|
|
4438
|
+
NoteLength3["ThirtySecondDot"] = "32.";
|
|
4439
|
+
NoteLength3["SixtyFourth"] = "64n";
|
|
4440
|
+
NoteLength3["SixtyFourthTriplet"] = "64t";
|
|
4441
|
+
return NoteLength3;
|
|
4442
|
+
})(NoteLength || {});
|
|
4443
|
+
function isNoteLength(noteLength) {
|
|
4444
|
+
return guard_exports.isEnumValue(noteLength, NoteLength);
|
|
4445
|
+
}
|
|
4446
|
+
function validateNoteLength(noteLength) {
|
|
4447
|
+
if (isNoteLength(noteLength)) {
|
|
4448
|
+
return noteLength;
|
|
4449
|
+
} else {
|
|
4450
|
+
throw new import_core8.MusicError(import_core8.MusicErrorType.InvalidArg, `Invalid noteLength: ${noteLength}`);
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
var _NoteLengthProps = class _NoteLengthProps {
|
|
4454
|
+
constructor(noteLength) {
|
|
4455
|
+
/** Note length. */
|
|
4456
|
+
__publicField(this, "noteLength");
|
|
4457
|
+
/** Note size (whole=1, half=2, quarter=4, ...). */
|
|
4458
|
+
__publicField(this, "noteSize");
|
|
4459
|
+
/** Number of ticks (not altered by isTriplet). */
|
|
4460
|
+
__publicField(this, "ticks");
|
|
4461
|
+
/** Flag count. */
|
|
4462
|
+
__publicField(this, "flagCount");
|
|
4463
|
+
/** Dot count. */
|
|
4464
|
+
__publicField(this, "dotCount");
|
|
4465
|
+
/** Max dot count. */
|
|
4466
|
+
__publicField(this, "maxDotCount");
|
|
4467
|
+
/** Is triplet? */
|
|
4468
|
+
__publicField(this, "isTriplet");
|
|
4469
|
+
/** Has note stem. */
|
|
4470
|
+
__publicField(this, "hasStem");
|
|
4471
|
+
/** Is note head solid (black)? */
|
|
4472
|
+
__publicField(this, "isSolid");
|
|
4473
|
+
this.noteLength = validateNoteLength(noteLength);
|
|
4474
|
+
this.noteSize = parseInt(noteLength);
|
|
4475
|
+
this.isTriplet = noteLength.endsWith("t");
|
|
4476
|
+
this.maxDotCount = this.isTriplet ? 0 : Math.floor(Math.log2(_NoteLengthProps.ShortestNoteSize / this.noteSize));
|
|
4477
|
+
this.dotCount = utils_exports.Str.charCount(noteLength, ".");
|
|
4478
|
+
this.flagCount = this.noteSize > 4 ? Math.floor(Math.log2(this.noteSize / 4)) : 0;
|
|
4479
|
+
this.ticks = TicksMultiplier * _NoteLengthProps.ShortestNoteSize / this.noteSize;
|
|
4480
|
+
this.hasStem = this.noteSize > 1;
|
|
4481
|
+
this.isSolid = this.noteSize > 2;
|
|
4482
|
+
if (this.dotCount > this.maxDotCount) {
|
|
4483
|
+
throw new import_core8.MusicError(import_core8.MusicErrorType.Note, `dotCount ${this.dotCount} > maxDotCount ${this.maxDotCount}, for noteLength "${this.noteLength}".`);
|
|
4484
|
+
} else if (this.isTriplet && this.dotCount > 0) {
|
|
4485
|
+
throw new import_core8.MusicError(import_core8.MusicErrorType.Note, `noteLength "${this.noteLength}" is both triplet and dotted!`);
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
/**
|
|
4489
|
+
* Get note length props.
|
|
4490
|
+
* @param noteLength - Note length.
|
|
4491
|
+
* @returns - Note length props.
|
|
4492
|
+
*/
|
|
4493
|
+
static get(noteLength) {
|
|
4494
|
+
return this.cache.getOrCreate(noteLength, () => new _NoteLengthProps(noteLength));
|
|
4495
|
+
}
|
|
4496
|
+
/**
|
|
4497
|
+
* Create note length props.
|
|
4498
|
+
* @param noteLength - Note length or note size.
|
|
4499
|
+
* @param dotCount - Dot count.
|
|
4500
|
+
* @returns - Note length props.
|
|
4501
|
+
*/
|
|
4502
|
+
static create(noteLength, dotCount = 0) {
|
|
4503
|
+
let noteSize = typeof noteLength === "number" ? noteLength : this.get(noteLength).noteSize;
|
|
4504
|
+
return this.get(noteSize + (guard_exports.isIntegerGte(dotCount, 1) ? ".".repeat(dotCount) : "n"));
|
|
4505
|
+
}
|
|
4506
|
+
/**
|
|
4507
|
+
* Compare note lengths/sizes. Whole (1) > half (2) > quarter (4), etc.
|
|
4508
|
+
* Ignores possible triplet property of note length.
|
|
4509
|
+
* @param a - NoteLengthProps, NoteLength/Str or noteSize
|
|
4510
|
+
* @param b - NoteLengthProps, NoteLength/Str or noteSize
|
|
4511
|
+
* @returns - -1: a < b, 0: a === b, +1: a > b (note length/size comparisons)
|
|
4512
|
+
*/
|
|
4513
|
+
static cmp(a, b) {
|
|
4514
|
+
let aNoteSize = a instanceof _NoteLengthProps ? a.noteSize : typeof a === "number" ? a : _NoteLengthProps.get(a).noteSize;
|
|
4515
|
+
let bNoteSize = b instanceof _NoteLengthProps ? b.noteSize : typeof b === "number" ? b : _NoteLengthProps.get(b).noteSize;
|
|
4516
|
+
return utils_exports.Math.cmp(bNoteSize, aNoteSize);
|
|
4517
|
+
}
|
|
4518
|
+
/**
|
|
4519
|
+
* Compare note lengths/sizes for equality.
|
|
4520
|
+
* Ignores possible triplet property of note length.
|
|
4521
|
+
* @param a - NoteLengthProps, NoteLength/Str or noteSize
|
|
4522
|
+
* @param b - NoteLengthProps, NoteLength/Str or noteSize
|
|
4523
|
+
* @returns - true: a === b, false: a !== b (note length/size comparisons)
|
|
4524
|
+
*/
|
|
4525
|
+
static equals(a, b) {
|
|
4526
|
+
let aNoteSize = a instanceof _NoteLengthProps ? a.noteSize : typeof a === "number" ? a : _NoteLengthProps.get(a).noteSize;
|
|
4527
|
+
let bNoteSize = b instanceof _NoteLengthProps ? b.noteSize : typeof b === "number" ? b : _NoteLengthProps.get(b).noteSize;
|
|
4528
|
+
return aNoteSize === bNoteSize;
|
|
4529
|
+
}
|
|
4530
|
+
};
|
|
4531
|
+
/** Longest note size (e.g. 1 = whole note). */
|
|
4532
|
+
__publicField(_NoteLengthProps, "LongestNoteSize", Math.min(...utils_exports.Enum.getEnumValues(NoteLength).map((noteLength) => parseInt(noteLength))));
|
|
4533
|
+
/** Shortest note size (e.g. 64 = sixtyfourth note). */
|
|
4534
|
+
__publicField(_NoteLengthProps, "ShortestNoteSize", Math.max(...utils_exports.Enum.getEnumValues(NoteLength).map((noteLength) => parseInt(noteLength))));
|
|
4535
|
+
__publicField(_NoteLengthProps, "cache", new UniMap());
|
|
4536
|
+
var NoteLengthProps = _NoteLengthProps;
|
|
4537
|
+
function isTupletRatio(tupletRatio) {
|
|
4538
|
+
return guard_exports.isObject(tupletRatio) && guard_exports.isIntegerBetween(tupletRatio.parts, 2, MaxTupletRatioValue) && guard_exports.isIntegerBetween(tupletRatio.inTimeOf, 2, MaxTupletRatioValue);
|
|
4539
|
+
}
|
|
4540
|
+
function validateTupletRatio(tupletRatio) {
|
|
4541
|
+
if (isTupletRatio(tupletRatio)) {
|
|
4542
|
+
return tupletRatio;
|
|
4543
|
+
} else {
|
|
4544
|
+
throw new import_core8.MusicError(import_core8.MusicErrorType.Note, `Invalid tupletRatio ${JSON.stringify(tupletRatio)}`);
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
var Tuplet = {
|
|
4548
|
+
/** Duplet: 2 in the time of 3 */
|
|
4549
|
+
Duplet: { parts: 2, inTimeOf: 3 },
|
|
4550
|
+
/** Triplet: 3 in the time of 2 */
|
|
4551
|
+
Triplet: { parts: 3, inTimeOf: 2 },
|
|
4552
|
+
/** Quadruplet: 4 in the time of 3 */
|
|
4553
|
+
Quadruplet: { parts: 4, inTimeOf: 3 }
|
|
4554
|
+
};
|
|
4555
|
+
var _RhythmProps = class _RhythmProps {
|
|
4556
|
+
constructor(noteLength, dotCount, tupletRatio) {
|
|
4557
|
+
/** Note length. */
|
|
4558
|
+
__publicField(this, "noteLength");
|
|
4559
|
+
/** Note size (whole=1, half=2, quarter=4, ...). */
|
|
4560
|
+
__publicField(this, "noteSize");
|
|
4561
|
+
/** Dot count. */
|
|
4562
|
+
__publicField(this, "dotCount");
|
|
4563
|
+
/** Tuplet ratio. */
|
|
4564
|
+
__publicField(this, "tupletRatio");
|
|
4565
|
+
/** Number of ticks. */
|
|
4566
|
+
__publicField(this, "ticks");
|
|
4567
|
+
/** Flag count. */
|
|
4568
|
+
__publicField(this, "flagCount");
|
|
4569
|
+
/** Has note stem. */
|
|
4570
|
+
__publicField(this, "hasStem");
|
|
4571
|
+
/** Is note head solid (black)? */
|
|
4572
|
+
__publicField(this, "isSolidNoteHead");
|
|
4573
|
+
this.noteLength = validateNoteLength(noteLength);
|
|
4574
|
+
let p = NoteLengthProps.get(noteLength);
|
|
4575
|
+
this.noteSize = p.noteSize;
|
|
4576
|
+
this.ticks = p.ticks;
|
|
4577
|
+
this.flagCount = p.flagCount;
|
|
4578
|
+
this.dotCount = dotCount != null ? dotCount : p.dotCount;
|
|
4579
|
+
this.hasStem = p.hasStem;
|
|
4580
|
+
this.isSolidNoteHead = p.isSolid;
|
|
4581
|
+
if (guard_exports.isObject(tupletRatio)) {
|
|
4582
|
+
this.tupletRatio = validateTupletRatio(tupletRatio);
|
|
4583
|
+
} else if (p.isTriplet) {
|
|
4584
|
+
this.tupletRatio = Tuplet.Triplet;
|
|
4585
|
+
} else {
|
|
4586
|
+
this.tupletRatio = void 0;
|
|
4587
|
+
}
|
|
4588
|
+
if (this.dotCount > 0 && this.tupletRatio !== void 0) {
|
|
4589
|
+
throw new import_core8.MusicError(import_core8.MusicErrorType.Note, `Note cannot be both dotted and tuplet!`);
|
|
4590
|
+
} else if (this.dotCount > p.maxDotCount) {
|
|
4591
|
+
throw new import_core8.MusicError(import_core8.MusicErrorType.Note, `Too big dot count ${this.dotCount} for note length ${this.noteLength}.`);
|
|
4592
|
+
}
|
|
4593
|
+
for (let add = this.ticks / 2, i = 1; i <= this.dotCount; i++, add /= 2) {
|
|
4594
|
+
this.ticks += add;
|
|
4595
|
+
}
|
|
4596
|
+
if (this.tupletRatio) {
|
|
4597
|
+
this.ticks *= this.tupletRatio.inTimeOf / this.tupletRatio.parts;
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
/**
|
|
4601
|
+
* Get string presentation of rhythm props.
|
|
4602
|
+
* @returns - String presentation.
|
|
4603
|
+
*/
|
|
4604
|
+
toString() {
|
|
4605
|
+
let sym = _RhythmProps.NoteSymbolMap.get(this.noteSize);
|
|
4606
|
+
let dots = ".".repeat(this.dotCount);
|
|
4607
|
+
return sym ? sym + dots : "" + this.noteSize + (dots.length > 0 ? dots : "n");
|
|
4608
|
+
}
|
|
4609
|
+
/**
|
|
4610
|
+
* Get rhythm props with given arguments.
|
|
4611
|
+
* @param noteLength - Note length.
|
|
4612
|
+
* @param dotCount - Dot count.
|
|
4613
|
+
* @param tupletRatio - Tuplet ratio.
|
|
4614
|
+
* @returns - Rhythm props.
|
|
4615
|
+
*/
|
|
4616
|
+
static get(noteLength, dotCount, tupletRatio) {
|
|
4617
|
+
if (dotCount !== void 0 || tupletRatio !== void 0) {
|
|
4618
|
+
return new _RhythmProps(noteLength, dotCount, tupletRatio);
|
|
4619
|
+
} else {
|
|
4620
|
+
return this.cache.getOrCreate(noteLength, () => new _RhythmProps(noteLength));
|
|
4621
|
+
}
|
|
4622
|
+
}
|
|
4623
|
+
/**
|
|
4624
|
+
* Compare duration of rhythm props.
|
|
4625
|
+
* @param a - RhythmProps
|
|
4626
|
+
* @param b - RhythmProps
|
|
4627
|
+
* @returns - -1: a < b, 0: a === b, +1: a > b (duration comparisons)
|
|
4628
|
+
*/
|
|
4629
|
+
static cmp(a, b) {
|
|
4630
|
+
return utils_exports.Math.cmp(a.ticks, b.ticks);
|
|
4631
|
+
}
|
|
4632
|
+
/**
|
|
4633
|
+
* Compare duration equality of rhythm props.
|
|
4634
|
+
* @param a - RhythmProps
|
|
4635
|
+
* @param b - RhythmProps
|
|
4636
|
+
* @returns - true: a === b, false: a !== b (duration comparisons)
|
|
4637
|
+
*/
|
|
4638
|
+
static equals(a, b) {
|
|
4639
|
+
return a.ticks === b.ticks;
|
|
4640
|
+
}
|
|
4641
|
+
};
|
|
4642
|
+
__publicField(_RhythmProps, "NoteSymbolMap", new IndexArray([[1, "\u{1D15D}"], [2, "\u{1D15E}"], [4, "\u{1D15F}"], [8, "\u{1D160}"], [16, "\u{1D161}"], [32, "\u{1D162}"], [64, "\u{1D163}"], [128, "\u{1D164}"]]));
|
|
4643
|
+
__publicField(_RhythmProps, "cache", new UniMap());
|
|
4644
|
+
var RhythmProps = _RhythmProps;
|
|
4645
|
+
|
|
4646
|
+
// src/theory/time-signature.ts
|
|
4647
|
+
var import_core9 = require("web-music-score/core");
|
|
4648
|
+
var TimeSignatures = /* @__PURE__ */ ((TimeSignatures2) => {
|
|
4649
|
+
TimeSignatures2["_2_4"] = "2/4";
|
|
4650
|
+
TimeSignatures2["_3_4"] = "3/4";
|
|
4651
|
+
TimeSignatures2["_4_4"] = "4/4";
|
|
4652
|
+
TimeSignatures2["_3_8"] = "3/8";
|
|
4653
|
+
TimeSignatures2["_5_8"] = "5/8";
|
|
4654
|
+
TimeSignatures2["_6_8"] = "6/8";
|
|
4655
|
+
TimeSignatures2["_7_8"] = "7/8";
|
|
4656
|
+
TimeSignatures2["_9_8"] = "9/8";
|
|
4657
|
+
TimeSignatures2["_12_8"] = "12/8";
|
|
4658
|
+
return TimeSignatures2;
|
|
4659
|
+
})(TimeSignatures || {});
|
|
4660
|
+
var BeamGrouping = /* @__PURE__ */ ((BeamGrouping2) => {
|
|
4661
|
+
BeamGrouping2["_2_3"] = "2-3";
|
|
4662
|
+
BeamGrouping2["_3_2"] = "3-2";
|
|
4663
|
+
BeamGrouping2["_2_2_3"] = "2-2-3";
|
|
4664
|
+
BeamGrouping2["_3_2_2"] = "3-2-2";
|
|
4665
|
+
return BeamGrouping2;
|
|
4666
|
+
})(BeamGrouping || {});
|
|
4667
|
+
var TimeSignature = class {
|
|
4668
|
+
constructor(...args) {
|
|
4669
|
+
/** Number of beats in measure, upper value (e.g. "3" in "3/4"). */
|
|
4670
|
+
__publicField(this, "beatCount");
|
|
4671
|
+
/** Beat size of time signature, lower value (e.g. "4" in "3/4"). */
|
|
4672
|
+
__publicField(this, "beatSize");
|
|
4673
|
+
/** Beat length. */
|
|
4674
|
+
__publicField(this, "beatLength");
|
|
4675
|
+
/** Number of ticks in measure. */
|
|
4676
|
+
__publicField(this, "measureTicks");
|
|
4677
|
+
/** Beam groups (e.g. [[2], [2]] or [[2, 2], [2, 2]] (first try as [[4], [4]])). */
|
|
4678
|
+
__publicField(this, "beamGroupSizes", []);
|
|
4679
|
+
let beamGrouping;
|
|
4680
|
+
if (guard_exports.isEnumValue(args[0], TimeSignatures)) {
|
|
4681
|
+
let parts = args[0].split("/");
|
|
4682
|
+
this.beatCount = +parts[0];
|
|
4683
|
+
this.beatSize = +parts[1];
|
|
4684
|
+
if (guard_exports.isEnumValue(args[1], BeamGrouping)) {
|
|
4685
|
+
beamGrouping = args[1];
|
|
4686
|
+
}
|
|
4687
|
+
} else if (guard_exports.isIntegerGte(args[0], 2) && guard_exports.isIntegerGte(args[1], 2)) {
|
|
4688
|
+
this.beatCount = args[0];
|
|
4689
|
+
this.beatSize = args[1];
|
|
4690
|
+
if (guard_exports.isEnumValue(args[2], BeamGrouping)) {
|
|
4691
|
+
beamGrouping = args[2];
|
|
4692
|
+
}
|
|
4693
|
+
} else {
|
|
4694
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Invalid args: ${args}`);
|
|
4695
|
+
}
|
|
4696
|
+
if (!guard_exports.isIntegerGte(this.beatCount, 1)) {
|
|
4697
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Invalid beatCount: ${this.beatCount}`);
|
|
4698
|
+
} else if (!guard_exports.isIntegerGte(this.beatSize, 1)) {
|
|
4699
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Invalid beatSize: ${this.beatSize}`);
|
|
4700
|
+
}
|
|
4701
|
+
let { noteLength, ticks } = NoteLengthProps.create(this.beatSize);
|
|
4702
|
+
this.beatLength = noteLength;
|
|
4703
|
+
this.measureTicks = this.beatCount * ticks;
|
|
4704
|
+
if (this.is(2, 4)) {
|
|
4705
|
+
this.beamGroupSizes = [[2], [2]];
|
|
4706
|
+
} else if (this.is(3, 4)) {
|
|
4707
|
+
this.beamGroupSizes = [[2], [2], [2]];
|
|
4708
|
+
} else if (this.is(4, 4)) {
|
|
4709
|
+
this.beamGroupSizes = [[2, 2], [2, 2]];
|
|
4710
|
+
} else if (this.is(3, 8)) {
|
|
4711
|
+
this.beamGroupSizes = [[3]];
|
|
4712
|
+
} else if (this.is(5, 8)) {
|
|
4713
|
+
if (!guard_exports.isUndefined(beamGrouping) && beamGrouping !== "2-3" /* _2_3 */ && beamGrouping !== "3-2" /* _3_2 */) {
|
|
4714
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Invalid beam grouping "${beamGrouping}" for time signature "${this.toString()}".`);
|
|
4715
|
+
} else {
|
|
4716
|
+
this.beamGroupSizes = beamGrouping === "3-2" /* _3_2 */ ? [[3], [2]] : [[2], [3]];
|
|
4717
|
+
beamGrouping = void 0;
|
|
4718
|
+
}
|
|
4719
|
+
} else if (this.is(6, 8)) {
|
|
4720
|
+
this.beamGroupSizes = [[3], [3]];
|
|
4721
|
+
} else if (this.is(7, 8)) {
|
|
4722
|
+
if (!guard_exports.isUndefined(beamGrouping) && beamGrouping !== "2-2-3" /* _2_2_3 */ && beamGrouping !== "3-2-2" /* _3_2_2 */) {
|
|
4723
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Invalid beam grouping "${beamGrouping}" for time signature "${this.toString()}".`);
|
|
4724
|
+
} else {
|
|
4725
|
+
this.beamGroupSizes = beamGrouping === "3-2-2" /* _3_2_2 */ ? [[3], [2], [2]] : [[2], [2], [3]];
|
|
4726
|
+
beamGrouping = void 0;
|
|
4727
|
+
}
|
|
4728
|
+
} else if (this.is(9, 8)) {
|
|
4729
|
+
this.beamGroupSizes = [[3], [3], [3]];
|
|
4730
|
+
} else if (this.is(12, 8)) {
|
|
4731
|
+
this.beamGroupSizes = [[3], [3], [3], [3]];
|
|
4732
|
+
}
|
|
4733
|
+
if (this.beamGroupSizes.length === 0) {
|
|
4734
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Unimplemented time signature "${this.toString()}".`);
|
|
4735
|
+
} else if (beamGrouping !== void 0) {
|
|
4736
|
+
throw new import_core9.MusicError(import_core9.MusicErrorType.Timesignature, `Invalid beam grouping "${beamGrouping}" for time signature "${this.toString()}".`);
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
/**
|
|
4740
|
+
* Test whether this time signature has given beat count and size.
|
|
4741
|
+
* @param beatCount - Beat count.
|
|
4742
|
+
* @param beatSize - Beat size.
|
|
4743
|
+
* @returns - Boolean whether this time signature match given beat count and size.
|
|
4744
|
+
*/
|
|
4745
|
+
is(beatCount, beatSize) {
|
|
4746
|
+
return this.beatCount === beatCount && this.beatSize === beatSize;
|
|
4747
|
+
}
|
|
4748
|
+
/**
|
|
4749
|
+
* Get string representation of this time signature (e.g. "3/4").
|
|
4750
|
+
* @returns - String representation.
|
|
4751
|
+
*/
|
|
4752
|
+
toString() {
|
|
4753
|
+
return this.beatCount + "/" + this.beatSize;
|
|
4754
|
+
}
|
|
4755
|
+
};
|
|
4756
|
+
var defaultTimeSignature;
|
|
4757
|
+
function getDefaultTimeSignature() {
|
|
4758
|
+
if (!defaultTimeSignature) {
|
|
4759
|
+
defaultTimeSignature = new TimeSignature(4, 4);
|
|
4760
|
+
}
|
|
4761
|
+
return defaultTimeSignature;
|
|
4762
|
+
}
|
|
4763
|
+
|
|
4764
|
+
// src/theory/tempo.ts
|
|
4765
|
+
var defaultTempo;
|
|
4766
|
+
function getDefaultTempo() {
|
|
4767
|
+
if (!defaultTempo) {
|
|
4768
|
+
defaultTempo = { beatsPerMinute: 120, options: { beatLength: "4n" /* Quarter */, dotCount: 0 } };
|
|
4769
|
+
}
|
|
4770
|
+
return defaultTempo;
|
|
4771
|
+
}
|
|
4772
|
+
function getTempoString(tempo) {
|
|
4773
|
+
return RhythmProps.get(tempo.options.beatLength, tempo.options.dotCount).toString() + "=" + tempo.beatsPerMinute;
|
|
4774
|
+
}
|
|
4775
|
+
function alterTempoSpeed(tempo, speed) {
|
|
4776
|
+
return {
|
|
4777
|
+
beatsPerMinute: tempo.beatsPerMinute * speed,
|
|
4778
|
+
options: { beatLength: tempo.options.beatLength, dotCount: tempo.options.dotCount }
|
|
4779
|
+
};
|
|
4780
|
+
}
|
|
4781
|
+
|
|
4782
|
+
// src/theory/index.ts
|
|
4783
|
+
var import_core10 = require("web-music-score/core");
|
|
4784
|
+
(0, import_core10.init)();
|
|
4785
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4786
|
+
0 && (module.exports = {
|
|
4787
|
+
AccidentalType,
|
|
4788
|
+
BeamGrouping,
|
|
4789
|
+
Chord,
|
|
4790
|
+
DefaultGuitarNoteLabel,
|
|
4791
|
+
DefaultPitchNotation,
|
|
4792
|
+
DefaultTuningName,
|
|
4793
|
+
GuitarNoteLabel,
|
|
4794
|
+
GuitarNoteLabelList,
|
|
4795
|
+
Interval,
|
|
4796
|
+
KeySignature,
|
|
4797
|
+
Mode,
|
|
4798
|
+
Note,
|
|
4799
|
+
NoteLength,
|
|
4800
|
+
NoteLengthProps,
|
|
4801
|
+
PitchNotation,
|
|
4802
|
+
PitchNotationList,
|
|
4803
|
+
RhythmProps,
|
|
4804
|
+
Scale,
|
|
4805
|
+
ScaleFactory,
|
|
4806
|
+
ScaleType,
|
|
4807
|
+
SymbolSet,
|
|
4808
|
+
TimeSignature,
|
|
4809
|
+
TimeSignatures,
|
|
4810
|
+
TuningNameList,
|
|
4811
|
+
Tuplet,
|
|
4812
|
+
alterTempoSpeed,
|
|
4813
|
+
getDefaultKeySignature,
|
|
4814
|
+
getDefaultScale,
|
|
4815
|
+
getDefaultTempo,
|
|
4816
|
+
getDefaultTimeSignature,
|
|
4817
|
+
getPitchNotationName,
|
|
4818
|
+
getScale,
|
|
4819
|
+
getScaleFactory,
|
|
4820
|
+
getScaleFactoryList,
|
|
4821
|
+
getTempoString,
|
|
4822
|
+
getTuningStrings,
|
|
4823
|
+
isNoteLength,
|
|
4824
|
+
isTupletRatio,
|
|
4825
|
+
validateGuitarNoteLabel,
|
|
4826
|
+
validateIntervalQuality,
|
|
4827
|
+
validateNoteLength,
|
|
4828
|
+
validatePitchNotation,
|
|
4829
|
+
validateScaleType,
|
|
4830
|
+
validateTuningName,
|
|
4831
|
+
validateTupletRatio
|
|
4832
|
+
});
|
|
4833
|
+
/*! Bundled license information:
|
|
4834
|
+
|
|
4835
|
+
@tspro/ts-utils-lib/dist/index.mjs:
|
|
4836
|
+
(*!
|
|
4837
|
+
* TsUtilsLib v2.2.1 (esm)
|
|
4838
|
+
* (c) 2023-2025 PahkaSoft
|
|
4839
|
+
* Licensed under the MIT License
|
|
4840
|
+
*)
|
|
4841
|
+
*/
|
|
4842
|
+
//# sourceMappingURL=index.js.map
|